Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[PATCH] sysctl: allow a zero ctl_name in the middle of a sysctl table

Since it is becoming clear that there are just enough users of the binary
sysctl interface that completely removing the binary interface from the kernel
will not be an option for foreseeable future, we need to find a way to address
the sysctl maintenance issues.

The basic problem is that sysctl requires one central authority to allocate
sysctl numbers, or else conflicts and ABI breakage occur. The proc interface
to sysctl does not have that problem, as names are not densely allocated.

By not terminating a sysctl table until I have neither a ctl_name nor a
procname, it becomes simple to add sysctl entries that don't show up in the
binary sysctl interface. Which allows people to avoid allocating a binary
sysctl value when not needed.

I have audited the kernel code and in my reading I have not found a single
sysctl table that wasn't terminated by a completely zero filled entry. So
this change in behavior should not affect anything.

I think this mechanism eases the pain enough that combined with a little
disciple we can solve the reoccurring sysctl ABI breakage.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Acked-by: Alan Cox <alan@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Eric W. Biederman and committed by
Linus Torvalds
d99f160a 0e009be8

+11 -6
+6 -3
include/linux/sysctl.h
··· 961 961 /* 962 962 * Register a set of sysctl names by calling register_sysctl_table 963 963 * with an initialised array of ctl_table's. An entry with zero 964 - * ctl_name terminates the table. table->de will be set up by the 965 - * registration and need not be initialised in advance. 964 + * ctl_name and NULL procname terminates the table. table->de will be 965 + * set up by the registration and need not be initialised in advance. 966 966 * 967 967 * sysctl names can be mirrored automatically under /proc/sys. The 968 968 * procname supplied controls /proc naming. ··· 973 973 * Leaf nodes in the sysctl tree will be represented by a single file 974 974 * under /proc; non-leaf nodes will be represented by directories. A 975 975 * null procname disables /proc mirroring at this node. 976 - * 976 + * 977 + * sysctl entries with a zero ctl_name will not be available through 978 + * the binary sysctl interface. 979 + * 977 980 * sysctl(2) can automatically manage read and write requests through 978 981 * the sysctl table. The data and maxlen fields of the ctl_table 979 982 * struct enable minimal validation of the values being written to be
+5 -3
kernel/sysctl.c
··· 1315 1315 return -ENOTDIR; 1316 1316 if (get_user(n, name)) 1317 1317 return -EFAULT; 1318 - for ( ; table->ctl_name; table++) { 1318 + for ( ; table->ctl_name || table->procname; table++) { 1319 + if (!table->ctl_name) 1320 + continue; 1319 1321 if (n == table->ctl_name || table->ctl_name == CTL_ANY) { 1320 1322 int error; 1321 1323 if (table->child) { ··· 1534 1532 int len; 1535 1533 mode_t mode; 1536 1534 1537 - for (; table->ctl_name; table++) { 1535 + for (; table->ctl_name || table->procname; table++) { 1538 1536 /* Can't do anything without a proc name. */ 1539 1537 if (!table->procname) 1540 1538 continue; ··· 1581 1579 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root) 1582 1580 { 1583 1581 struct proc_dir_entry *de; 1584 - for (; table->ctl_name; table++) { 1582 + for (; table->ctl_name || table->procname; table++) { 1585 1583 if (!(de = table->de)) 1586 1584 continue; 1587 1585 if (de->mode & S_IFDIR) {