aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2007-10-18 06:05:54 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-18 17:37:23 -0400
commitfc6cd25b738c2369d7ed3a6ef2ca248b51fcd2d4 (patch)
treebd3708eac72edf06097a8a2ed72c3a3fea0b0998 /kernel
parentf429cd37a21b8efc825bdbb22db7f033564cbc98 (diff)
sysctl: Error on bad sysctl tables
After going through the kernels sysctl tables several times it has become clear that code review and testing is just not effective in prevent problematic sysctl tables from being used in the stable kernel. I certainly can't seem to fix the problems as fast as they are introduced. Therefore this patch adds sysctl_check_table which is called when a sysctl table is registered and checks to see if we have a problematic sysctl table. The biggest part of the code is the table of valid binary sysctl entries, but since we have frozen our set of binary sysctls this table should not need to change, and it makes it much easier to detect when someone unintentionally adds a new binary sysctl value. As best as I can determine all of the several hundred errors spewed on boot up now are legitimate. [bunk@kernel.org: kernel/sysctl_check.c must #include <linux/string.h>] Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Cc: Alexey Dobriyan <adobriyan@sw.ru> Signed-off-by: Adrian Bunk <bunk@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/Makefile2
-rw-r--r--kernel/sysctl.c6
-rw-r--r--kernel/sysctl_check.c1556
3 files changed, 1563 insertions, 1 deletions
diff --git a/kernel/Makefile b/kernel/Makefile
index 2a999836ca18..d63fbb18798a 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -9,7 +9,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \
9 rcupdate.o extable.o params.o posix-timers.o \ 9 rcupdate.o extable.o params.o posix-timers.o \
10 kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ 10 kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
11 hrtimer.o rwsem.o latency.o nsproxy.o srcu.o die_notifier.o \ 11 hrtimer.o rwsem.o latency.o nsproxy.o srcu.o die_notifier.o \
12 utsname.o 12 utsname.o sysctl_check.o
13 13
14obj-$(CONFIG_STACKTRACE) += stacktrace.o 14obj-$(CONFIG_STACKTRACE) += stacktrace.o
15obj-y += time/ 15obj-y += time/
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index c7150af631b5..62e53a0de4a3 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -1461,7 +1461,9 @@ static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1461 1461
1462static __init int sysctl_init(void) 1462static __init int sysctl_init(void)
1463{ 1463{
1464 int err;
1464 sysctl_set_parent(NULL, root_table); 1465 sysctl_set_parent(NULL, root_table);
1466 err = sysctl_check_table(root_table);
1465 return 0; 1467 return 0;
1466} 1468}
1467 1469
@@ -1546,6 +1548,10 @@ struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1546 tmp->used = 0; 1548 tmp->used = 0;
1547 tmp->unregistering = NULL; 1549 tmp->unregistering = NULL;
1548 sysctl_set_parent(NULL, table); 1550 sysctl_set_parent(NULL, table);
1551 if (sysctl_check_table(tmp->ctl_table)) {
1552 kfree(tmp);
1553 return NULL;
1554 }
1549 spin_lock(&sysctl_lock); 1555 spin_lock(&sysctl_lock);
1550 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry); 1556 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1551 spin_unlock(&sysctl_lock); 1557 spin_unlock(&sysctl_lock);
diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
new file mode 100644
index 000000000000..8bce52cc06d4
--- /dev/null
+++ b/kernel/sysctl_check.c
@@ -0,0 +1,1556 @@
1#include <linux/stat.h>
2#include <linux/sysctl.h>
3#include "../arch/s390/appldata/appldata.h"
4#include "../fs/xfs/linux-2.6/xfs_sysctl.h"
5#include <linux/sunrpc/debug.h>
6#include <linux/string.h>
7#include <net/ip_vs.h>
8
9struct trans_ctl_table {
10 int ctl_name;
11 const char *procname;
12 struct trans_ctl_table *child;
13};
14
15static struct trans_ctl_table trans_random_table[] = {
16 { RANDOM_POOLSIZE, "poolsize" },
17 { RANDOM_ENTROPY_COUNT, "entropy_avail" },
18 { RANDOM_READ_THRESH, "read_wakeup_threshold" },
19 { RANDOM_WRITE_THRESH, "write_wakeup_threshold" },
20 { RANDOM_BOOT_ID, "boot_id" },
21 { RANDOM_UUID, "uuid" },
22 {}
23};
24
25static struct trans_ctl_table trans_pty_table[] = {
26 { PTY_MAX, "max" },
27 { PTY_NR, "nr" },
28 {}
29};
30
31static struct trans_ctl_table trans_kern_table[] = {
32 { KERN_OSTYPE, "ostype" },
33 { KERN_OSRELEASE, "osrelease" },
34 /* KERN_OSREV not used */
35 { KERN_VERSION, "version" },
36 /* KERN_SECUREMASK not used */
37 /* KERN_PROF not used */
38 { KERN_NODENAME, "hostname" },
39 { KERN_DOMAINNAME, "domainname" },
40
41 { KERN_CAP_BSET, "cap-bound" },
42 { KERN_PANIC, "panic" },
43 { KERN_REALROOTDEV, "real-root-dev" },
44
45 { KERN_SPARC_REBOOT, "reboot-cmd" },
46 { KERN_CTLALTDEL, "ctrl-alt-del" },
47 { KERN_PRINTK, "printk" },
48
49 /* KERN_NAMETRANS not used */
50 /* KERN_PPC_HTABRECLAIM not used */
51 /* KERN_PPC_ZEROPAGED not used */
52 { KERN_PPC_POWERSAVE_NAP, "powersave-nap" },
53
54 { KERN_MODPROBE, "modprobe" },
55 { KERN_SG_BIG_BUFF, "sg-big-buff" },
56 { KERN_ACCT, "acct" },
57 { KERN_PPC_L2CR, "l2cr" },
58
59 /* KERN_RTSIGNR not used */
60 /* KERN_RTSIGMAX not used */
61
62 { KERN_SHMMAX, "shmmax" },
63 { KERN_MSGMAX, "msgmax" },
64 { KERN_MSGMNB, "msgmnb" },
65 /* KERN_MSGPOOL not used*/
66 { KERN_SYSRQ, "sysrq" },
67 { KERN_MAX_THREADS, "threads-max" },
68 { KERN_RANDOM, "random", trans_random_table },
69 { KERN_SHMALL, "shmall" },
70 { KERN_MSGMNI, "msgmni" },
71 { KERN_SEM, "sem" },
72 { KERN_SPARC_STOP_A, "stop-a" },
73 { KERN_SHMMNI, "shmmni" },
74
75 { KERN_OVERFLOWUID, "overflowuid" },
76 { KERN_OVERFLOWGID, "overflowgid" },
77
78 { KERN_HOTPLUG, "hotplug", },
79 { KERN_IEEE_EMULATION_WARNINGS, "ieee_emulation_warnings" },
80
81 { KERN_S390_USER_DEBUG_LOGGING, "userprocess_debug" },
82 { KERN_CORE_USES_PID, "core_uses_pid" },
83 { KERN_TAINTED, "tainted" },
84 { KERN_CADPID, "cad_pid" },
85 { KERN_PIDMAX, "pid_max" },
86 { KERN_CORE_PATTERN, "core_pattern" },
87 { KERN_PANIC_ON_OOPS, "panic_on_oops" },
88 { KERN_HPPA_PWRSW, "soft-power" },
89 { KERN_HPPA_UNALIGNED, "unaligned-trap" },
90
91 { KERN_PRINTK_RATELIMIT, "printk_ratelimit" },
92 { KERN_PRINTK_RATELIMIT_BURST, "printk_ratelimit_burst" },
93
94 { KERN_PTY, "pty", trans_pty_table },
95 { KERN_NGROUPS_MAX, "ngroups_max" },
96 { KERN_SPARC_SCONS_PWROFF, "scons_poweroff" },
97 { KERN_HZ_TIMER, "hz_timer" },
98 { KERN_UNKNOWN_NMI_PANIC, "unknown_nmi_panic" },
99 { KERN_BOOTLOADER_TYPE, "bootloader_type" },
100 { KERN_RANDOMIZE, "randomize_va_space" },
101
102 { KERN_SPIN_RETRY, "spin_retry" },
103 { KERN_ACPI_VIDEO_FLAGS, "acpi_video_flags" },
104 { KERN_IA64_UNALIGNED, "ignore-unaligned-usertrap" },
105 { KERN_COMPAT_LOG, "compat-log" },
106 { KERN_MAX_LOCK_DEPTH, "max_lock_depth" },
107 { KERN_NMI_WATCHDOG, "nmi_watchdog" },
108 { KERN_PANIC_ON_NMI, "panic_on_unrecovered_nmi" },
109 {}
110};
111
112static struct trans_ctl_table trans_vm_table[] = {
113 { VM_OVERCOMMIT_MEMORY, "overcommit_memory" },
114 { VM_PAGE_CLUSTER, "page-cluster" },
115 { VM_DIRTY_BACKGROUND, "dirty_background_ratio" },
116 { VM_DIRTY_RATIO, "dirty_ratio" },
117 { VM_DIRTY_WB_CS, "dirty_writeback_centisecs" },
118 { VM_DIRTY_EXPIRE_CS, "dirty_expire_centisecs" },
119 { VM_NR_PDFLUSH_THREADS, "nr_pdflush_threads" },
120 { VM_OVERCOMMIT_RATIO, "overcommit_ratio" },
121 /* VM_PAGEBUF unused */
122 { VM_HUGETLB_PAGES, "nr_hugepages" },
123 { VM_SWAPPINESS, "swappiness" },
124 { VM_LOWMEM_RESERVE_RATIO, "lowmem_reserve_ratio" },
125 { VM_MIN_FREE_KBYTES, "min_free_kbytes" },
126 { VM_MAX_MAP_COUNT, "max_map_count" },
127 { VM_LAPTOP_MODE, "laptop_mode" },
128 { VM_BLOCK_DUMP, "block_dump" },
129 { VM_HUGETLB_GROUP, "hugetlb_shm_group" },
130 { VM_VFS_CACHE_PRESSURE, "vfs_cache_pressure" },
131 { VM_LEGACY_VA_LAYOUT, "legacy_va_layout" },
132 /* VM_SWAP_TOKEN_TIMEOUT unused */
133 { VM_DROP_PAGECACHE, "drop_caches" },
134 { VM_PERCPU_PAGELIST_FRACTION, "percpu_pagelist_fraction" },
135 { VM_ZONE_RECLAIM_MODE, "zone_reclaim_mode" },
136 { VM_MIN_UNMAPPED, "min_unmapped_ratio" },
137 { VM_PANIC_ON_OOM, "panic_on_oom" },
138 { VM_VDSO_ENABLED, "vdso_enabled" },
139 { VM_MIN_SLAB, "min_slab_ratio" },
140 { VM_CMM_PAGES, "cmm_pages" },
141 { VM_CMM_TIMED_PAGES, "cmm_timed_pages" },
142 { VM_CMM_TIMEOUT, "cmm_timeout" },
143
144 {}