Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * sysctl.c: General linux system control interface | |
3 | * | |
4 | * Begun 24 March 1995, Stephen Tweedie | |
5 | * Added /proc support, Dec 1995 | |
6 | * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas. | |
7 | * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver. | |
8 | * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver. | |
9 | * Dynamic registration fixes, Stephen Tweedie. | |
10 | * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn. | |
11 | * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris | |
12 | * Horn. | |
13 | * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer. | |
14 | * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer. | |
15 | * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill | |
16 | * Wendling. | |
17 | * The list_for_each() macro wasn't appropriate for the sysctl loop. | |
18 | * Removed it and replaced it with older style, 03/23/00, Bill Wendling | |
19 | */ | |
20 | ||
1da177e4 LT |
21 | #include <linux/module.h> |
22 | #include <linux/mm.h> | |
23 | #include <linux/swap.h> | |
24 | #include <linux/slab.h> | |
25 | #include <linux/sysctl.h> | |
26 | #include <linux/proc_fs.h> | |
72c2d582 | 27 | #include <linux/security.h> |
1da177e4 LT |
28 | #include <linux/ctype.h> |
29 | #include <linux/utsname.h> | |
1da177e4 | 30 | #include <linux/smp_lock.h> |
62239ac2 | 31 | #include <linux/fs.h> |
1da177e4 LT |
32 | #include <linux/init.h> |
33 | #include <linux/kernel.h> | |
0296b228 | 34 | #include <linux/kobject.h> |
20380731 | 35 | #include <linux/net.h> |
1da177e4 LT |
36 | #include <linux/sysrq.h> |
37 | #include <linux/highuid.h> | |
38 | #include <linux/writeback.h> | |
39 | #include <linux/hugetlb.h> | |
1da177e4 | 40 | #include <linux/initrd.h> |
0b77f5bf | 41 | #include <linux/key.h> |
1da177e4 LT |
42 | #include <linux/times.h> |
43 | #include <linux/limits.h> | |
44 | #include <linux/dcache.h> | |
45 | #include <linux/syscalls.h> | |
c748e134 | 46 | #include <linux/vmstat.h> |
c255d844 PM |
47 | #include <linux/nfs_fs.h> |
48 | #include <linux/acpi.h> | |
10a0a8d4 | 49 | #include <linux/reboot.h> |
b0fc494f | 50 | #include <linux/ftrace.h> |
1da177e4 LT |
51 | |
52 | #include <asm/uaccess.h> | |
53 | #include <asm/processor.h> | |
54 | ||
29cbc78b AK |
55 | #ifdef CONFIG_X86 |
56 | #include <asm/nmi.h> | |
0741f4d2 | 57 | #include <asm/stacktrace.h> |
6e7c4025 | 58 | #include <asm/io.h> |
29cbc78b AK |
59 | #endif |
60 | ||
7058cb02 EB |
61 | static int deprecated_sysctl_warning(struct __sysctl_args *args); |
62 | ||
1da177e4 LT |
63 | #if defined(CONFIG_SYSCTL) |
64 | ||
65 | /* External variables not in a header file. */ | |
66 | extern int C_A_D; | |
45807a1d | 67 | extern int print_fatal_signals; |
1da177e4 LT |
68 | extern int sysctl_overcommit_memory; |
69 | extern int sysctl_overcommit_ratio; | |
fadd8fbd | 70 | extern int sysctl_panic_on_oom; |
fe071d7e | 71 | extern int sysctl_oom_kill_allocating_task; |
fef1bdd6 | 72 | extern int sysctl_oom_dump_tasks; |
1da177e4 | 73 | extern int max_threads; |
1da177e4 | 74 | extern int core_uses_pid; |
d6e71144 | 75 | extern int suid_dumpable; |
1da177e4 | 76 | extern char core_pattern[]; |
1da177e4 LT |
77 | extern int pid_max; |
78 | extern int min_free_kbytes; | |
1da177e4 | 79 | extern int pid_max_min, pid_max_max; |
9d0243bc | 80 | extern int sysctl_drop_caches; |
8ad4b1fb | 81 | extern int percpu_pagelist_fraction; |
bebfa101 | 82 | extern int compat_log; |
9745512c | 83 | extern int latencytop_enabled; |
eceea0b3 | 84 | extern int sysctl_nr_open_min, sysctl_nr_open_max; |
dd8632a1 PM |
85 | #ifndef CONFIG_MMU |
86 | extern int sysctl_nr_trim_pages; | |
87 | #endif | |
31a72bce PM |
88 | #ifdef CONFIG_RCU_TORTURE_TEST |
89 | extern int rcutorture_runnable; | |
90 | #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */ | |
1da177e4 | 91 | |
c4f3b63f | 92 | /* Constants used for minimum and maximum */ |
195cf453 | 93 | #ifdef CONFIG_DETECT_SOFTLOCKUP |
c4f3b63f | 94 | static int sixty = 60; |
9383d967 | 95 | static int neg_one = -1; |
c4f3b63f RT |
96 | #endif |
97 | ||
c4f3b63f | 98 | static int zero; |
2da02997 | 99 | static int one = 1; |
8e654fba | 100 | static int two = 2; |
fc3501d4 | 101 | static unsigned long one_ul = 1; |
c4f3b63f RT |
102 | static int one_hundred = 100; |
103 | ||
1da177e4 LT |
104 | /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */ |
105 | static int maxolduid = 65535; | |
106 | static int minolduid; | |
8ad4b1fb | 107 | static int min_percpu_pagelist_fract = 8; |
1da177e4 LT |
108 | |
109 | static int ngroups_max = NGROUPS_MAX; | |
110 | ||
a1ef5adb | 111 | #ifdef CONFIG_MODULES |
1da177e4 LT |
112 | extern char modprobe_path[]; |
113 | #endif | |
1da177e4 LT |
114 | #ifdef CONFIG_CHR_DEV_SG |
115 | extern int sg_big_buff; | |
116 | #endif | |
1da177e4 | 117 | |
72c57ed5 | 118 | #ifdef CONFIG_SPARC |
17f04fbb | 119 | #include <asm/system.h> |
1da177e4 LT |
120 | #endif |
121 | ||
0871420f DM |
122 | #ifdef CONFIG_SPARC64 |
123 | extern int sysctl_tsb_ratio; | |
124 | #endif | |
125 | ||
1da177e4 LT |
126 | #ifdef __hppa__ |
127 | extern int pwrsw_enabled; | |
128 | extern int unaligned_enabled; | |
129 | #endif | |
130 | ||
347a8dc3 | 131 | #ifdef CONFIG_S390 |
1da177e4 LT |
132 | #ifdef CONFIG_MATHEMU |
133 | extern int sysctl_ieee_emulation_warnings; | |
134 | #endif | |
135 | extern int sysctl_userprocess_debug; | |
951f22d5 | 136 | extern int spin_retry; |
1da177e4 LT |
137 | #endif |
138 | ||
1da177e4 LT |
139 | #ifdef CONFIG_BSD_PROCESS_ACCT |
140 | extern int acct_parm[]; | |
141 | #endif | |
142 | ||
d2b176ed JS |
143 | #ifdef CONFIG_IA64 |
144 | extern int no_unaligned_warning; | |
88fc241f | 145 | extern int unaligned_dump_stack; |
d2b176ed JS |
146 | #endif |
147 | ||
23f78d4a IM |
148 | #ifdef CONFIG_RT_MUTEXES |
149 | extern int max_lock_depth; | |
150 | #endif | |
151 | ||
d6f8ff73 | 152 | #ifdef CONFIG_PROC_SYSCTL |
d8217f07 | 153 | static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp, |
9ec52099 | 154 | void __user *buffer, size_t *lenp, loff_t *ppos); |
25ddbb18 | 155 | static int proc_taint(struct ctl_table *table, int write, struct file *filp, |
34f5a398 | 156 | void __user *buffer, size_t *lenp, loff_t *ppos); |
d6f8ff73 | 157 | #endif |
9ec52099 | 158 | |
d8217f07 | 159 | static struct ctl_table root_table[]; |
e51b6ba0 EB |
160 | static struct ctl_table_root sysctl_table_root; |
161 | static struct ctl_table_header root_table_header = { | |
b380b0d4 | 162 | .count = 1, |
e51b6ba0 | 163 | .ctl_table = root_table, |
73455092 | 164 | .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list), |
e51b6ba0 | 165 | .root = &sysctl_table_root, |
73455092 | 166 | .set = &sysctl_table_root.default_set, |
e51b6ba0 EB |
167 | }; |
168 | static struct ctl_table_root sysctl_table_root = { | |
169 | .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list), | |
73455092 | 170 | .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry), |
e51b6ba0 | 171 | }; |
1da177e4 | 172 | |
d8217f07 EB |
173 | static struct ctl_table kern_table[]; |
174 | static struct ctl_table vm_table[]; | |
175 | static struct ctl_table fs_table[]; | |
176 | static struct ctl_table debug_table[]; | |
177 | static struct ctl_table dev_table[]; | |
178 | extern struct ctl_table random_table[]; | |
2d9048e2 | 179 | #ifdef CONFIG_INOTIFY_USER |
d8217f07 | 180 | extern struct ctl_table inotify_table[]; |
0399cb08 | 181 | #endif |
7ef9964e DL |
182 | #ifdef CONFIG_EPOLL |
183 | extern struct ctl_table epoll_table[]; | |
184 | #endif | |
1da177e4 LT |
185 | |
186 | #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT | |
187 | int sysctl_legacy_va_layout; | |
188 | #endif | |
189 | ||
f20786ff PZ |
190 | extern int prove_locking; |
191 | extern int lock_stat; | |
9bc9a6bd | 192 | |
1da177e4 LT |
193 | /* The default sysctl tables: */ |
194 | ||
d8217f07 | 195 | static struct ctl_table root_table[] = { |
1da177e4 LT |
196 | { |
197 | .ctl_name = CTL_KERN, | |
198 | .procname = "kernel", | |
199 | .mode = 0555, | |
200 | .child = kern_table, | |
201 | }, | |
202 | { | |
203 | .ctl_name = CTL_VM, | |
204 | .procname = "vm", | |
205 | .mode = 0555, | |
206 | .child = vm_table, | |
207 | }, | |
1da177e4 LT |
208 | { |
209 | .ctl_name = CTL_FS, | |
210 | .procname = "fs", | |
211 | .mode = 0555, | |
212 | .child = fs_table, | |
213 | }, | |
214 | { | |
215 | .ctl_name = CTL_DEBUG, | |
216 | .procname = "debug", | |
217 | .mode = 0555, | |
218 | .child = debug_table, | |
219 | }, | |
220 | { | |
221 | .ctl_name = CTL_DEV, | |
222 | .procname = "dev", | |
223 | .mode = 0555, | |
224 | .child = dev_table, | |
225 | }, | |
2be7fe07 AM |
226 | /* |
227 | * NOTE: do not add new entries to this table unless you have read | |
228 | * Documentation/sysctl/ctl_unnumbered.txt | |
229 | */ | |
1da177e4 LT |
230 | { .ctl_name = 0 } |
231 | }; | |
232 | ||
77e54a1f | 233 | #ifdef CONFIG_SCHED_DEBUG |
73c4efd2 ED |
234 | static int min_sched_granularity_ns = 100000; /* 100 usecs */ |
235 | static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */ | |
236 | static int min_wakeup_granularity_ns; /* 0 usecs */ | |
237 | static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */ | |
77e54a1f IM |
238 | #endif |
239 | ||
d8217f07 | 240 | static struct ctl_table kern_table[] = { |
77e54a1f IM |
241 | #ifdef CONFIG_SCHED_DEBUG |
242 | { | |
243 | .ctl_name = CTL_UNNUMBERED, | |
b2be5e96 PZ |
244 | .procname = "sched_min_granularity_ns", |
245 | .data = &sysctl_sched_min_granularity, | |
77e54a1f IM |
246 | .maxlen = sizeof(unsigned int), |
247 | .mode = 0644, | |
b2be5e96 PZ |
248 | .proc_handler = &sched_nr_latency_handler, |
249 | .strategy = &sysctl_intvec, | |
250 | .extra1 = &min_sched_granularity_ns, | |
251 | .extra2 = &max_sched_granularity_ns, | |
77e54a1f | 252 | }, |
21805085 PZ |
253 | { |
254 | .ctl_name = CTL_UNNUMBERED, | |
255 | .procname = "sched_latency_ns", | |
256 | .data = &sysctl_sched_latency, | |
257 | .maxlen = sizeof(unsigned int), | |
258 | .mode = 0644, | |
b2be5e96 | 259 | .proc_handler = &sched_nr_latency_handler, |
21805085 PZ |
260 | .strategy = &sysctl_intvec, |
261 | .extra1 = &min_sched_granularity_ns, | |
262 | .extra2 = &max_sched_granularity_ns, | |
263 | }, | |
77e54a1f IM |
264 | { |
265 | .ctl_name = CTL_UNNUMBERED, | |
266 | .procname = "sched_wakeup_granularity_ns", | |
267 | .data = &sysctl_sched_wakeup_granularity, | |
268 | .maxlen = sizeof(unsigned int), | |
269 | .mode = 0644, | |
270 | .proc_handler = &proc_dointvec_minmax, | |
271 | .strategy = &sysctl_intvec, | |
77e54a1f IM |
272 | .extra1 = &min_wakeup_granularity_ns, |
273 | .extra2 = &max_wakeup_granularity_ns, | |
274 | }, | |
2398f2c6 PZ |
275 | { |
276 | .ctl_name = CTL_UNNUMBERED, | |
277 | .procname = "sched_shares_ratelimit", | |
278 | .data = &sysctl_sched_shares_ratelimit, | |
279 | .maxlen = sizeof(unsigned int), | |
280 | .mode = 0644, | |
281 | .proc_handler = &proc_dointvec, | |
282 | }, | |
ffda12a1 PZ |
283 | { |
284 | .ctl_name = CTL_UNNUMBERED, | |
285 | .procname = "sched_shares_thresh", | |
286 | .data = &sysctl_sched_shares_thresh, | |
287 | .maxlen = sizeof(unsigned int), | |
288 | .mode = 0644, | |
289 | .proc_handler = &proc_dointvec_minmax, | |
290 | .strategy = &sysctl_intvec, | |
291 | .extra1 = &zero, | |
292 | }, | |
77e54a1f IM |
293 | { |
294 | .ctl_name = CTL_UNNUMBERED, | |
295 | .procname = "sched_child_runs_first", | |
296 | .data = &sysctl_sched_child_runs_first, | |
297 | .maxlen = sizeof(unsigned int), | |
298 | .mode = 0644, | |
299 | .proc_handler = &proc_dointvec, | |
300 | }, | |
1fc84aaa PZ |
301 | { |
302 | .ctl_name = CTL_UNNUMBERED, | |
303 | .procname = "sched_features", | |
304 | .data = &sysctl_sched_features, | |
305 | .maxlen = sizeof(unsigned int), | |
306 | .mode = 0644, | |
307 | .proc_handler = &proc_dointvec, | |
308 | }, | |
da84d961 IM |
309 | { |
310 | .ctl_name = CTL_UNNUMBERED, | |
311 | .procname = "sched_migration_cost", | |
312 | .data = &sysctl_sched_migration_cost, | |
313 | .maxlen = sizeof(unsigned int), | |
314 | .mode = 0644, | |
315 | .proc_handler = &proc_dointvec, | |
316 | }, | |
b82d9fdd PZ |
317 | { |
318 | .ctl_name = CTL_UNNUMBERED, | |
319 | .procname = "sched_nr_migrate", | |
320 | .data = &sysctl_sched_nr_migrate, | |
321 | .maxlen = sizeof(unsigned int), | |
fa85ae24 PZ |
322 | .mode = 0644, |
323 | .proc_handler = &proc_dointvec, | |
324 | }, | |
1fc84aaa | 325 | #endif |
9f0c1e56 PZ |
326 | { |
327 | .ctl_name = CTL_UNNUMBERED, | |
328 | .procname = "sched_rt_period_us", | |
329 | .data = &sysctl_sched_rt_period, | |
330 | .maxlen = sizeof(unsigned int), | |
331 | .mode = 0644, | |
d0b27fa7 | 332 | .proc_handler = &sched_rt_handler, |
9f0c1e56 PZ |
333 | }, |
334 | { | |
335 | .ctl_name = CTL_UNNUMBERED, | |
336 | .procname = "sched_rt_runtime_us", | |
337 | .data = &sysctl_sched_rt_runtime, | |
338 | .maxlen = sizeof(int), | |
339 | .mode = 0644, | |
d0b27fa7 | 340 | .proc_handler = &sched_rt_handler, |
9f0c1e56 | 341 | }, |
1799e35d IM |
342 | { |
343 | .ctl_name = CTL_UNNUMBERED, | |
344 | .procname = "sched_compat_yield", | |
345 | .data = &sysctl_sched_compat_yield, | |
346 | .maxlen = sizeof(unsigned int), | |
347 | .mode = 0644, | |
348 | .proc_handler = &proc_dointvec, | |
349 | }, | |
f20786ff PZ |
350 | #ifdef CONFIG_PROVE_LOCKING |
351 | { | |
352 | .ctl_name = CTL_UNNUMBERED, | |
353 | .procname = "prove_locking", | |
354 | .data = &prove_locking, | |
355 | .maxlen = sizeof(int), | |
356 | .mode = 0644, | |
357 | .proc_handler = &proc_dointvec, | |
358 | }, | |
359 | #endif | |
360 | #ifdef CONFIG_LOCK_STAT | |
361 | { | |
362 | .ctl_name = CTL_UNNUMBERED, | |
363 | .procname = "lock_stat", | |
364 | .data = &lock_stat, | |
365 | .maxlen = sizeof(int), | |
366 | .mode = 0644, | |
367 | .proc_handler = &proc_dointvec, | |
368 | }, | |
77e54a1f | 369 | #endif |
1da177e4 LT |
370 | { |
371 | .ctl_name = KERN_PANIC, | |
372 | .procname = "panic", | |
373 | .data = &panic_timeout, | |
374 | .maxlen = sizeof(int), | |
375 | .mode = 0644, | |
376 | .proc_handler = &proc_dointvec, | |
377 | }, | |
378 | { | |
379 | .ctl_name = KERN_CORE_USES_PID, | |
380 | .procname = "core_uses_pid", | |
381 | .data = &core_uses_pid, | |
382 | .maxlen = sizeof(int), | |
383 | .mode = 0644, | |
384 | .proc_handler = &proc_dointvec, | |
385 | }, | |
386 | { | |
387 | .ctl_name = KERN_CORE_PATTERN, | |
388 | .procname = "core_pattern", | |
389 | .data = core_pattern, | |
71ce92f3 | 390 | .maxlen = CORENAME_MAX_SIZE, |
1da177e4 LT |
391 | .mode = 0644, |
392 | .proc_handler = &proc_dostring, | |
393 | .strategy = &sysctl_string, | |
394 | }, | |
34f5a398 | 395 | #ifdef CONFIG_PROC_SYSCTL |
1da177e4 | 396 | { |
1da177e4 | 397 | .procname = "tainted", |
25ddbb18 | 398 | .maxlen = sizeof(long), |
34f5a398 | 399 | .mode = 0644, |
25ddbb18 | 400 | .proc_handler = &proc_taint, |
1da177e4 | 401 | }, |
34f5a398 | 402 | #endif |
9745512c AV |
403 | #ifdef CONFIG_LATENCYTOP |
404 | { | |
405 | .procname = "latencytop", | |
406 | .data = &latencytop_enabled, | |
407 | .maxlen = sizeof(int), | |
408 | .mode = 0644, | |
409 | .proc_handler = &proc_dointvec, | |
410 | }, | |
411 | #endif | |
1da177e4 LT |
412 | #ifdef CONFIG_BLK_DEV_INITRD |
413 | { | |
414 | .ctl_name = KERN_REALROOTDEV, | |
415 | .procname = "real-root-dev", | |
416 | .data = &real_root_dev, | |
417 | .maxlen = sizeof(int), | |
418 | .mode = 0644, | |
419 | .proc_handler = &proc_dointvec, | |
420 | }, | |
421 | #endif | |
45807a1d IM |
422 | { |
423 | .ctl_name = CTL_UNNUMBERED, | |
424 | .procname = "print-fatal-signals", | |
425 | .data = &print_fatal_signals, | |
426 | .maxlen = sizeof(int), | |
427 | .mode = 0644, | |
428 | .proc_handler = &proc_dointvec, | |
429 | }, | |
72c57ed5 | 430 | #ifdef CONFIG_SPARC |
1da177e4 LT |
431 | { |
432 | .ctl_name = KERN_SPARC_REBOOT, | |
433 | .procname = "reboot-cmd", | |
434 | .data = reboot_command, | |
435 | .maxlen = 256, | |
436 | .mode = 0644, | |
437 | .proc_handler = &proc_dostring, | |
438 | .strategy = &sysctl_string, | |
439 | }, | |
440 | { | |
441 | .ctl_name = KERN_SPARC_STOP_A, | |
442 | .procname = "stop-a", | |
443 | .data = &stop_a_enabled, | |
444 | .maxlen = sizeof (int), | |
445 | .mode = 0644, | |
446 | .proc_handler = &proc_dointvec, | |
447 | }, | |
448 | { | |
449 | .ctl_name = KERN_SPARC_SCONS_PWROFF, | |
450 | .procname = "scons-poweroff", | |
451 | .data = &scons_pwroff, | |
452 | .maxlen = sizeof (int), | |
453 | .mode = 0644, | |
454 | .proc_handler = &proc_dointvec, | |
455 | }, | |
456 | #endif | |
0871420f DM |
457 | #ifdef CONFIG_SPARC64 |
458 | { | |
459 | .ctl_name = CTL_UNNUMBERED, | |
460 | .procname = "tsb-ratio", | |
461 | .data = &sysctl_tsb_ratio, | |
462 | .maxlen = sizeof (int), | |
463 | .mode = 0644, | |
464 | .proc_handler = &proc_dointvec, | |
465 | }, | |
466 | #endif | |
1da177e4 LT |
467 | #ifdef __hppa__ |
468 | { | |
469 | .ctl_name = KERN_HPPA_PWRSW, | |
470 | .procname = "soft-power", | |
471 | .data = &pwrsw_enabled, | |
472 | .maxlen = sizeof (int), | |
473 | .mode = 0644, | |
474 | .proc_handler = &proc_dointvec, | |
475 | }, | |
476 | { | |
477 | .ctl_name = KERN_HPPA_UNALIGNED, | |
478 | .procname = "unaligned-trap", | |
479 | .data = &unaligned_enabled, | |
480 | .maxlen = sizeof (int), | |
481 | .mode = 0644, | |
482 | .proc_handler = &proc_dointvec, | |
483 | }, | |
484 | #endif | |
485 | { | |
486 | .ctl_name = KERN_CTLALTDEL, | |
487 | .procname = "ctrl-alt-del", | |
488 | .data = &C_A_D, | |
489 | .maxlen = sizeof(int), | |
490 | .mode = 0644, | |
491 | .proc_handler = &proc_dointvec, | |
492 | }, | |
606576ce | 493 | #ifdef CONFIG_FUNCTION_TRACER |
b0fc494f SR |
494 | { |
495 | .ctl_name = CTL_UNNUMBERED, | |
496 | .procname = "ftrace_enabled", | |
497 | .data = &ftrace_enabled, | |
498 | .maxlen = sizeof(int), | |
499 | .mode = 0644, | |
500 | .proc_handler = &ftrace_enable_sysctl, | |
501 | }, | |
502 | #endif | |
f38f1d2a SR |
503 | #ifdef CONFIG_STACK_TRACER |
504 | { | |
505 | .ctl_name = CTL_UNNUMBERED, | |
506 | .procname = "stack_tracer_enabled", | |
507 | .data = &stack_tracer_enabled, | |
508 | .maxlen = sizeof(int), | |
509 | .mode = 0644, | |
510 | .proc_handler = &stack_trace_sysctl, | |
511 | }, | |
512 | #endif | |
944ac425 SR |
513 | #ifdef CONFIG_TRACING |
514 | { | |
515 | .ctl_name = CTL_UNNUMBERED, | |
3299b4dd | 516 | .procname = "ftrace_dump_on_oops", |
944ac425 SR |
517 | .data = &ftrace_dump_on_oops, |
518 | .maxlen = sizeof(int), | |
519 | .mode = 0644, | |
520 | .proc_handler = &proc_dointvec, | |
521 | }, | |
522 | #endif | |
a1ef5adb | 523 | #ifdef CONFIG_MODULES |
1da177e4 LT |
524 | { |
525 | .ctl_name = KERN_MODPROBE, | |
526 | .procname = "modprobe", | |
527 | .data = &modprobe_path, | |
528 | .maxlen = KMOD_PATH_LEN, | |
529 | .mode = 0644, | |
530 | .proc_handler = &proc_dostring, | |
531 | .strategy = &sysctl_string, | |
532 | }, | |
533 | #endif | |
57ae2508 | 534 | #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) |
1da177e4 LT |
535 | { |
536 | .ctl_name = KERN_HOTPLUG, | |
537 | .procname = "hotplug", | |
312c004d KS |
538 | .data = &uevent_helper, |
539 | .maxlen = UEVENT_HELPER_PATH_LEN, | |
1da177e4 LT |
540 | .mode = 0644, |
541 | .proc_handler = &proc_dostring, | |
542 | .strategy = &sysctl_string, | |
543 | }, | |
544 | #endif | |
545 | #ifdef CONFIG_CHR_DEV_SG | |
546 | { | |
547 | .ctl_name = KERN_SG_BIG_BUFF, | |
548 | .procname = "sg-big-buff", | |
549 | .data = &sg_big_buff, | |
550 | .maxlen = sizeof (int), | |
551 | .mode = 0444, | |
552 | .proc_handler = &proc_dointvec, | |
553 | }, | |
554 | #endif | |
555 | #ifdef CONFIG_BSD_PROCESS_ACCT | |
556 | { | |
557 | .ctl_name = KERN_ACCT, | |
558 | .procname = "acct", | |
559 | .data = &acct_parm, | |
560 | .maxlen = 3*sizeof(int), | |
561 | .mode = 0644, | |
562 | .proc_handler = &proc_dointvec, | |
563 | }, | |
564 | #endif | |
1da177e4 LT |
565 | #ifdef CONFIG_MAGIC_SYSRQ |
566 | { | |
567 | .ctl_name = KERN_SYSRQ, | |
568 | .procname = "sysrq", | |
5d6f647f | 569 | .data = &__sysrq_enabled, |
1da177e4 LT |
570 | .maxlen = sizeof (int), |
571 | .mode = 0644, | |
572 | .proc_handler = &proc_dointvec, | |
573 | }, | |
574 | #endif | |
d6f8ff73 | 575 | #ifdef CONFIG_PROC_SYSCTL |
1da177e4 | 576 | { |
1da177e4 | 577 | .procname = "cad_pid", |
9ec52099 | 578 | .data = NULL, |
1da177e4 LT |
579 | .maxlen = sizeof (int), |
580 | .mode = 0600, | |
9ec52099 | 581 | .proc_handler = &proc_do_cad_pid, |
1da177e4 | 582 | }, |
d6f8ff73 | 583 | #endif |
1da177e4 LT |
584 | { |
585 | .ctl_name = KERN_MAX_THREADS, | |
586 | .procname = "threads-max", | |
587 | .data = &max_threads, | |
588 | .maxlen = sizeof(int), | |
589 | .mode = 0644, | |
590 | .proc_handler = &proc_dointvec, | |
591 | }, | |
592 | { | |
593 | .ctl_name = KERN_RANDOM, | |
594 | .procname = "random", | |
595 | .mode = 0555, | |
596 | .child = random_table, | |
597 | }, | |
1da177e4 LT |
598 | { |
599 | .ctl_name = KERN_OVERFLOWUID, | |
600 | .procname = "overflowuid", | |
601 | .data = &overflowuid, | |
602 | .maxlen = sizeof(int), | |
603 | .mode = 0644, | |
604 | .proc_handler = &proc_dointvec_minmax, | |
605 | .strategy = &sysctl_intvec, | |
606 | .extra1 = &minolduid, | |
607 | .extra2 = &maxolduid, | |
608 | }, | |
609 | { | |
610 | .ctl_name = KERN_OVERFLOWGID, | |
611 | .procname = "overflowgid", | |
612 | .data = &overflowgid, | |
613 | .maxlen = sizeof(int), | |
614 | .mode = 0644, | |
615 | .proc_handler = &proc_dointvec_minmax, | |
616 | .strategy = &sysctl_intvec, | |
617 | .extra1 = &minolduid, | |
618 | .extra2 = &maxolduid, | |
619 | }, | |
347a8dc3 | 620 | #ifdef CONFIG_S390 |
1da177e4 LT |
621 | #ifdef CONFIG_MATHEMU |
622 | { | |
623 | .ctl_name = KERN_IEEE_EMULATION_WARNINGS, | |
624 | .procname = "ieee_emulation_warnings", | |
625 | .data = &sysctl_ieee_emulation_warnings, | |
626 | .maxlen = sizeof(int), | |
627 | .mode = 0644, | |
628 | .proc_handler = &proc_dointvec, | |
629 | }, | |
1da177e4 LT |
630 | #endif |
631 | { | |
632 | .ctl_name = KERN_S390_USER_DEBUG_LOGGING, | |
633 | .procname = "userprocess_debug", | |
634 | .data = &sysctl_userprocess_debug, | |
635 | .maxlen = sizeof(int), | |
636 | .mode = 0644, | |
637 | .proc_handler = &proc_dointvec, | |
638 | }, | |
639 | #endif | |
640 | { | |
641 | .ctl_name = KERN_PIDMAX, | |
642 | .procname = "pid_max", | |
643 | .data = &pid_max, | |
644 | .maxlen = sizeof (int), | |
645 | .mode = 0644, | |
646 | .proc_handler = &proc_dointvec_minmax, | |
647 | .strategy = sysctl_intvec, | |
648 | .extra1 = &pid_max_min, | |
649 | .extra2 = &pid_max_max, | |
650 | }, | |
651 | { | |
652 | .ctl_name = KERN_PANIC_ON_OOPS, | |
653 | .procname = "panic_on_oops", | |
654 | .data = &panic_on_oops, | |
655 | .maxlen = sizeof(int), | |
656 | .mode = 0644, | |
657 | .proc_handler = &proc_dointvec, | |
658 | }, | |
7ef3d2fd JP |
659 | #if defined CONFIG_PRINTK |
660 | { | |
661 | .ctl_name = KERN_PRINTK, | |
662 | .procname = "printk", | |
663 | .data = &console_loglevel, | |
664 | .maxlen = 4*sizeof(int), | |
665 | .mode = 0644, | |
666 | .proc_handler = &proc_dointvec, | |
667 | }, | |
1da177e4 LT |
668 | { |
669 | .ctl_name = KERN_PRINTK_RATELIMIT, | |
670 | .procname = "printk_ratelimit", | |
717115e1 | 671 | .data = &printk_ratelimit_state.interval, |
1da177e4 LT |
672 | .maxlen = sizeof(int), |
673 | .mode = 0644, | |
674 | .proc_handler = &proc_dointvec_jiffies, | |
675 | .strategy = &sysctl_jiffies, | |
676 | }, | |
677 | { | |
678 | .ctl_name = KERN_PRINTK_RATELIMIT_BURST, | |
679 | .procname = "printk_ratelimit_burst", | |
717115e1 | 680 | .data = &printk_ratelimit_state.burst, |
1da177e4 LT |
681 | .maxlen = sizeof(int), |
682 | .mode = 0644, | |
683 | .proc_handler = &proc_dointvec, | |
684 | }, | |
7ef3d2fd | 685 | #endif |
1da177e4 LT |
686 | { |
687 | .ctl_name = KERN_NGROUPS_MAX, | |
688 | .procname = "ngroups_max", | |
689 | .data = &ngroups_max, | |
690 | .maxlen = sizeof (int), | |
691 | .mode = 0444, | |
692 | .proc_handler = &proc_dointvec, | |
693 | }, | |
694 | #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) | |
695 | { | |
696 | .ctl_name = KERN_UNKNOWN_NMI_PANIC, | |
697 | .procname = "unknown_nmi_panic", | |
698 | .data = &unknown_nmi_panic, | |
699 | .maxlen = sizeof (int), | |
700 | .mode = 0644, | |
2fbe7b25 | 701 | .proc_handler = &proc_dointvec, |
1da177e4 | 702 | }, |
407984f1 | 703 | { |
407984f1 DZ |
704 | .procname = "nmi_watchdog", |
705 | .data = &nmi_watchdog_enabled, | |
706 | .maxlen = sizeof (int), | |
707 | .mode = 0644, | |
708 | .proc_handler = &proc_nmi_enabled, | |
1da177e4 LT |
709 | }, |
710 | #endif | |
711 | #if defined(CONFIG_X86) | |
8da5adda DZ |
712 | { |
713 | .ctl_name = KERN_PANIC_ON_NMI, | |
714 | .procname = "panic_on_unrecovered_nmi", | |
715 | .data = &panic_on_unrecovered_nmi, | |
716 | .maxlen = sizeof(int), | |
717 | .mode = 0644, | |
718 | .proc_handler = &proc_dointvec, | |
719 | }, | |
1da177e4 LT |
720 | { |
721 | .ctl_name = KERN_BOOTLOADER_TYPE, | |
722 | .procname = "bootloader_type", | |
723 | .data = &bootloader_type, | |
724 | .maxlen = sizeof (int), | |
725 | .mode = 0444, | |
726 | .proc_handler = &proc_dointvec, | |
727 | }, | |
0741f4d2 CE |
728 | { |
729 | .ctl_name = CTL_UNNUMBERED, | |
730 | .procname = "kstack_depth_to_print", | |
731 | .data = &kstack_depth_to_print, | |
732 | .maxlen = sizeof(int), | |
733 | .mode = 0644, | |
734 | .proc_handler = &proc_dointvec, | |
735 | }, | |
6e7c4025 IM |
736 | { |
737 | .ctl_name = CTL_UNNUMBERED, | |
738 | .procname = "io_delay_type", | |
739 | .data = &io_delay_type, | |
740 | .maxlen = sizeof(int), | |
741 | .mode = 0644, | |
742 | .proc_handler = &proc_dointvec, | |
743 | }, | |
1da177e4 | 744 | #endif |
7a9166e3 | 745 | #if defined(CONFIG_MMU) |
1da177e4 LT |
746 | { |
747 | .ctl_name = KERN_RANDOMIZE, | |
748 | .procname = "randomize_va_space", | |
749 | .data = &randomize_va_space, | |
750 | .maxlen = sizeof(int), | |
751 | .mode = 0644, | |
752 | .proc_handler = &proc_dointvec, | |
753 | }, | |
7a9166e3 | 754 | #endif |
0152fb37 | 755 | #if defined(CONFIG_S390) && defined(CONFIG_SMP) |
951f22d5 MS |
756 | { |
757 | .ctl_name = KERN_SPIN_RETRY, | |
758 | .procname = "spin_retry", | |
759 | .data = &spin_retry, | |
760 | .maxlen = sizeof (int), | |
761 | .mode = 0644, | |
762 | .proc_handler = &proc_dointvec, | |
763 | }, | |
c255d844 | 764 | #endif |
673d5b43 | 765 | #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) |
c255d844 | 766 | { |
c255d844 | 767 | .procname = "acpi_video_flags", |
77afcf78 | 768 | .data = &acpi_realmode_flags, |
c255d844 PM |
769 | .maxlen = sizeof (unsigned long), |
770 | .mode = 0644, | |
7f99f06f | 771 | .proc_handler = &proc_doulongvec_minmax, |
c255d844 | 772 | }, |
d2b176ed JS |
773 | #endif |
774 | #ifdef CONFIG_IA64 | |
775 | { | |
776 | .ctl_name = KERN_IA64_UNALIGNED, | |
777 | .procname = "ignore-unaligned-usertrap", | |
778 | .data = &no_unaligned_warning, | |
779 | .maxlen = sizeof (int), | |
780 | .mode = 0644, | |
781 | .proc_handler = &proc_dointvec, | |
782 | }, | |
88fc241f DC |
783 | { |
784 | .ctl_name = CTL_UNNUMBERED, | |
785 | .procname = "unaligned-dump-stack", | |
786 | .data = &unaligned_dump_stack, | |
787 | .maxlen = sizeof (int), | |
788 | .mode = 0644, | |
789 | .proc_handler = &proc_dointvec, | |
790 | }, | |
bebfa101 | 791 | #endif |
c4f3b63f | 792 | #ifdef CONFIG_DETECT_SOFTLOCKUP |
9c44bc03 IM |
793 | { |
794 | .ctl_name = CTL_UNNUMBERED, | |
795 | .procname = "softlockup_panic", | |
796 | .data = &softlockup_panic, | |
797 | .maxlen = sizeof(int), | |
798 | .mode = 0644, | |
4dca10a9 | 799 | .proc_handler = &proc_dointvec_minmax, |
9c44bc03 IM |
800 | .strategy = &sysctl_intvec, |
801 | .extra1 = &zero, | |
802 | .extra2 = &one, | |
803 | }, | |
c4f3b63f RT |
804 | { |
805 | .ctl_name = CTL_UNNUMBERED, | |
806 | .procname = "softlockup_thresh", | |
807 | .data = &softlockup_thresh, | |
9383d967 | 808 | .maxlen = sizeof(int), |
c4f3b63f | 809 | .mode = 0644, |
baf48f65 | 810 | .proc_handler = &proc_dosoftlockup_thresh, |
c4f3b63f | 811 | .strategy = &sysctl_intvec, |
9383d967 | 812 | .extra1 = &neg_one, |
c4f3b63f RT |
813 | .extra2 = &sixty, |
814 | }, | |
82a1fcb9 IM |
815 | { |
816 | .ctl_name = CTL_UNNUMBERED, | |
817 | .procname = "hung_task_check_count", | |
818 | .data = &sysctl_hung_task_check_count, | |
90739081 | 819 | .maxlen = sizeof(unsigned long), |
82a1fcb9 | 820 | .mode = 0644, |
90739081 | 821 | .proc_handler = &proc_doulongvec_minmax, |
82a1fcb9 IM |
822 | .strategy = &sysctl_intvec, |
823 | }, | |
824 | { | |
825 | .ctl_name = CTL_UNNUMBERED, | |
826 | .procname = "hung_task_timeout_secs", | |
827 | .data = &sysctl_hung_task_timeout_secs, | |
90739081 | 828 | .maxlen = sizeof(unsigned long), |
82a1fcb9 | 829 | .mode = 0644, |
90739081 | 830 | .proc_handler = &proc_doulongvec_minmax, |
82a1fcb9 IM |
831 | .strategy = &sysctl_intvec, |
832 | }, | |
833 | { | |
834 | .ctl_name = CTL_UNNUMBERED, | |
835 | .procname = "hung_task_warnings", | |
836 | .data = &sysctl_hung_task_warnings, | |
90739081 | 837 | .maxlen = sizeof(unsigned long), |
82a1fcb9 | 838 | .mode = 0644, |
90739081 | 839 | .proc_handler = &proc_doulongvec_minmax, |
82a1fcb9 IM |
840 | .strategy = &sysctl_intvec, |
841 | }, | |
c4f3b63f | 842 | #endif |
bebfa101 AK |
843 | #ifdef CONFIG_COMPAT |
844 | { | |
845 | .ctl_name = KERN_COMPAT_LOG, | |
846 | .procname = "compat-log", | |
847 | .data = &compat_log, | |
848 | .maxlen = sizeof (int), | |
849 | .mode = 0644, | |
850 | .proc_handler = &proc_dointvec, | |
851 | }, | |
951f22d5 | 852 | #endif |
23f78d4a IM |
853 | #ifdef CONFIG_RT_MUTEXES |
854 | { | |
855 | .ctl_name = KERN_MAX_LOCK_DEPTH, | |
856 | .procname = "max_lock_depth", | |
857 | .data = &max_lock_depth, | |
858 | .maxlen = sizeof(int), | |
859 | .mode = 0644, | |
860 | .proc_handler = &proc_dointvec, | |
861 | }, | |
5096add8 | 862 | #endif |
10a0a8d4 JF |
863 | { |
864 | .ctl_name = CTL_UNNUMBERED, | |
865 | .procname = "poweroff_cmd", | |
866 | .data = &poweroff_cmd, | |
867 | .maxlen = POWEROFF_CMD_PATH_LEN, | |
868 | .mode = 0644, | |
869 | .proc_handler = &proc_dostring, | |
870 | .strategy = &sysctl_string, | |
871 | }, | |
0b77f5bf DH |
872 | #ifdef CONFIG_KEYS |
873 | { | |
874 | .ctl_name = CTL_UNNUMBERED, | |
875 | .procname = "keys", | |
876 | .mode = 0555, | |
877 | .child = key_sysctls, | |
878 | }, | |
879 | #endif | |
31a72bce PM |
880 | #ifdef CONFIG_RCU_TORTURE_TEST |
881 | { | |
882 | .ctl_name = CTL_UNNUMBERED, | |
883 | .procname = "rcutorture_runnable", | |
884 | .data = &rcutorture_runnable, | |
885 | .maxlen = sizeof(int), | |
886 | .mode = 0644, | |
887 | .proc_handler = &proc_dointvec, | |
888 | }, | |
889 | #endif | |
af936a16 LS |
890 | #ifdef CONFIG_UNEVICTABLE_LRU |
891 | { | |
892 | .ctl_name = CTL_UNNUMBERED, | |
893 | .procname = "scan_unevictable_pages", | |
894 | .data = &scan_unevictable_pages, | |
895 | .maxlen = sizeof(scan_unevictable_pages), | |
896 | .mode = 0644, | |
897 | .proc_handler = &scan_unevictable_handler, | |
898 | }, | |
899 | #endif | |
ed2c12f3 AM |
900 | /* |
901 | * NOTE: do not add new entries to this table unless you have read | |
902 | * Documentation/sysctl/ctl_unnumbered.txt | |
903 | */ | |
1da177e4 LT |
904 | { .ctl_name = 0 } |
905 | }; | |
906 | ||
d8217f07 | 907 | static struct ctl_table vm_table[] = { |
1da177e4 LT |
908 | { |
909 | .ctl_name = VM_OVERCOMMIT_MEMORY, | |
910 | .procname = "overcommit_memory", | |
911 | .data = &sysctl_overcommit_memory, | |
912 | .maxlen = sizeof(sysctl_overcommit_memory), | |
913 | .mode = 0644, | |
914 | .proc_handler = &proc_dointvec, | |
915 | }, | |
fadd8fbd KH |
916 | { |
917 | .ctl_name = VM_PANIC_ON_OOM, | |
918 | .procname = "panic_on_oom", | |
919 | .data = &sysctl_panic_on_oom, | |
920 | .maxlen = sizeof(sysctl_panic_on_oom), | |
921 | .mode = 0644, | |
922 | .proc_handler = &proc_dointvec, | |
923 | }, | |
fe071d7e DR |
924 | { |
925 | .ctl_name = CTL_UNNUMBERED, | |
926 | .procname = "oom_kill_allocating_task", | |
927 | .data = &sysctl_oom_kill_allocating_task, | |
928 | .maxlen = sizeof(sysctl_oom_kill_allocating_task), | |
929 | .mode = 0644, | |
930 | .proc_handler = &proc_dointvec, | |
931 | }, | |
fef1bdd6 DR |
932 | { |
933 | .ctl_name = CTL_UNNUMBERED, | |
934 | .procname = "oom_dump_tasks", | |
935 | .data = &sysctl_oom_dump_tasks, | |
936 | .maxlen = sizeof(sysctl_oom_dump_tasks), | |
937 | .mode = 0644, | |
938 | .proc_handler = &proc_dointvec, | |
939 | }, | |
1da177e4 LT |
940 | { |
941 | .ctl_name = VM_OVERCOMMIT_RATIO, | |
942 | .procname = "overcommit_ratio", | |
943 | .data = &sysctl_overcommit_ratio, | |
944 | .maxlen = sizeof(sysctl_overcommit_ratio), | |
945 | .mode = 0644, | |
946 | .proc_handler = &proc_dointvec, | |
947 | }, | |
948 | { | |
949 | .ctl_name = VM_PAGE_CLUSTER, | |
950 | .procname = "page-cluster", | |
951 | .data = &page_cluster, | |
952 | .maxlen = sizeof(int), | |
953 | .mode = 0644, | |
954 | .proc_handler = &proc_dointvec, | |
955 | }, | |
956 | { | |
957 | .ctl_name = VM_DIRTY_BACKGROUND, | |
958 | .procname = "dirty_background_ratio", | |
959 | .data = &dirty_background_ratio, | |
960 | .maxlen = sizeof(dirty_background_ratio), | |
961 | .mode = 0644, | |
2da02997 | 962 | .proc_handler = &dirty_background_ratio_handler, |
1da177e4 LT |
963 | .strategy = &sysctl_intvec, |
964 | .extra1 = &zero, | |
965 | .extra2 = &one_hundred, | |
966 | }, | |
2da02997 DR |
967 | { |
968 | .ctl_name = CTL_UNNUMBERED, | |
969 | .procname = "dirty_background_bytes", | |
970 | .data = &dirty_background_bytes, | |
971 | .maxlen = sizeof(dirty_background_bytes), | |
972 | .mode = 0644, | |
973 | .proc_handler = &dirty_background_bytes_handler, | |
974 | .strategy = &sysctl_intvec, | |
fc3501d4 | 975 | .extra1 = &one_ul, |
2da02997 | 976 | }, |
1da177e4 LT |
977 | { |
978 | .ctl_name = VM_DIRTY_RATIO, | |
979 | .procname = "dirty_ratio", | |
980 | .data = &vm_dirty_ratio, | |
981 | .maxlen = sizeof(vm_dirty_ratio), | |
982 | .mode = 0644, | |
04fbfdc1 | 983 | .proc_handler = &dirty_ratio_handler, |
1da177e4 LT |
984 | .strategy = &sysctl_intvec, |
985 | .extra1 = &zero, | |
986 | .extra2 = &one_hundred, | |
987 | }, | |
2da02997 DR |
988 | { |
989 | .ctl_name = CTL_UNNUMBERED, | |
990 | .procname = "dirty_bytes", | |
991 | .data = &vm_dirty_bytes, | |
992 | .maxlen = sizeof(vm_dirty_bytes), | |
993 | .mode = 0644, | |
994 | .proc_handler = &dirty_bytes_handler, | |
995 | .strategy = &sysctl_intvec, | |
fc3501d4 | 996 | .extra1 = &one_ul, |
2da02997 | 997 | }, |
1da177e4 | 998 | { |
1da177e4 | 999 | .procname = "dirty_writeback_centisecs", |
f6ef9438 BS |
1000 | .data = &dirty_writeback_interval, |
1001 | .maxlen = sizeof(dirty_writeback_interval), | |
1da177e4 LT |
1002 | .mode = 0644, |
1003 | .proc_handler = &dirty_writeback_centisecs_handler, | |
1004 | }, | |
1005 | { | |
1da177e4 | 1006 | .procname = "dirty_expire_centisecs", |
f6ef9438 BS |
1007 | .data = &dirty_expire_interval, |
1008 | .maxlen = sizeof(dirty_expire_interval), | |
1da177e4 | 1009 | .mode = 0644, |
704503d8 | 1010 | .proc_handler = &proc_dointvec, |
1da177e4 LT |
1011 | }, |
1012 | { | |
1013 | .ctl_name = VM_NR_PDFLUSH_THREADS, | |
1014 | .procname = "nr_pdflush_threads", | |
1015 | .data = &nr_pdflush_threads, | |
1016 | .maxlen = sizeof nr_pdflush_threads, | |
1017 | .mode = 0444 /* read-only*/, | |
1018 | .proc_handler = &proc_dointvec, | |
1019 | }, | |
1020 | { | |
1021 | .ctl_name = VM_SWAPPINESS, | |
1022 | .procname = "swappiness", | |
1023 | .data = &vm_swappiness, | |
1024 | .maxlen = sizeof(vm_swappiness), | |
1025 | .mode = 0644, | |
1026 | .proc_handler = &proc_dointvec_minmax, | |
1027 | .strategy = &sysctl_intvec, | |
1028 | .extra1 = &zero, | |
1029 | .extra2 = &one_hundred, | |
1030 | }, | |
1031 | #ifdef CONFIG_HUGETLB_PAGE | |
1032 | { | |
1da177e4 | 1033 | .procname = "nr_hugepages", |
e5ff2159 | 1034 | .data = NULL, |
1da177e4 LT |
1035 | .maxlen = sizeof(unsigned long), |
1036 | .mode = 0644, | |
1037 | .proc_handler = &hugetlb_sysctl_handler, | |
1038 | .extra1 = (void *)&hugetlb_zero, | |
1039 | .extra2 = (void *)&hugetlb_infinity, | |
1040 | }, | |
1041 | { | |
1042 | .ctl_name = VM_HUGETLB_GROUP, | |
1043 | .procname = "hugetlb_shm_group", | |
1044 | .data = &sysctl_hugetlb_shm_group, | |
1045 | .maxlen = sizeof(gid_t), | |
1046 | .mode = 0644, | |
1047 | .proc_handler = &proc_dointvec, | |
1048 | }, | |
396faf03 MG |
1049 | { |
1050 | .ctl_name = CTL_UNNUMBERED, | |
1051 | .procname = "hugepages_treat_as_movable", | |
1052 | .data = &hugepages_treat_as_movable, | |
1053 | .maxlen = sizeof(int), | |
1054 | .mode = 0644, | |
1055 | .proc_handler = &hugetlb_treat_movable_handler, | |
1056 | }, | |
d1c3fb1f NA |
1057 | { |
1058 | .ctl_name = CTL_UNNUMBERED, | |
1059 | .procname = "nr_overcommit_hugepages", | |
e5ff2159 AK |
1060 | .data = NULL, |
1061 | .maxlen = sizeof(unsigned long), | |
d1c3fb1f | 1062 | .mode = 0644, |
a3d0c6aa | 1063 | .proc_handler = &hugetlb_overcommit_handler, |
e5ff2159 AK |
1064 | .extra1 = (void *)&hugetlb_zero, |
1065 | .extra2 = (void *)&hugetlb_infinity, | |
d1c3fb1f | 1066 | }, |
1da177e4 LT |
1067 | #endif |
1068 | { | |
1069 | .ctl_name = VM_LOWMEM_RESERVE_RATIO, | |
1070 | .procname = "lowmem_reserve_ratio", | |
1071 | .data = &sysctl_lowmem_reserve_ratio, | |
1072 | .maxlen = sizeof(sysctl_lowmem_reserve_ratio), | |
1073 | .mode = 0644, | |
1074 | .proc_handler = &lowmem_reserve_ratio_sysctl_handler, | |
1075 | .strategy = &sysctl_intvec, | |
1076 | }, | |
9d0243bc AM |
1077 | { |
1078 | .ctl_name = VM_DROP_PAGECACHE, | |
1079 | .procname = "drop_caches", | |
1080 | .data = &sysctl_drop_caches, | |
1081 | .maxlen = sizeof(int), | |
1082 | .mode = 0644, | |
1083 | .proc_handler = drop_caches_sysctl_handler, | |
1084 | .strategy = &sysctl_intvec, | |
1085 | }, | |
1da177e4 LT |
1086 | { |
1087 | .ctl_name = VM_MIN_FREE_KBYTES, | |
1088 | .procname = "min_free_kbytes", | |
1089 | .data = &min_free_kbytes, | |
1090 | .maxlen = sizeof(min_free_kbytes), | |
1091 | .mode = 0644, | |
1092 | .proc_handler = &min_free_kbytes_sysctl_handler, | |
1093 | .strategy = &sysctl_intvec, | |
1094 | .extra1 = &zero, | |
1095 | }, | |
8ad4b1fb RS |
1096 | { |
1097 | .ctl_name = VM_PERCPU_PAGELIST_FRACTION, | |
1098 | .procname = "percpu_pagelist_fraction", | |
1099 | .data = &percpu_pagelist_fraction, | |
1100 | .maxlen = sizeof(percpu_pagelist_fraction), | |
1101 | .mode = 0644, | |
1102 | .proc_handler = &percpu_pagelist_fraction_sysctl_handler, | |
1103 | .strategy = &sysctl_intvec, | |
1104 | .extra1 = &min_percpu_pagelist_fract, | |
1105 | }, | |
1da177e4 LT |
1106 | #ifdef CONFIG_MMU |
1107 | { | |
1108 | .ctl_name = VM_MAX_MAP_COUNT, | |
1109 | .procname = "max_map_count", | |
1110 | .data = &sysctl_max_map_count, | |
1111 | .maxlen = sizeof(sysctl_max_map_count), | |
1112 | .mode = 0644, | |
1113 | .proc_handler = &proc_dointvec | |
1114 | }, | |
dd8632a1 PM |
1115 | #else |
1116 | { | |
1117 | .ctl_name = CTL_UNNUMBERED, | |
1118 | .procname = "nr_trim_pages", | |
1119 | .data = &sysctl_nr_trim_pages, | |
1120 | .maxlen = sizeof(sysctl_nr_trim_pages), | |
1121 | .mode = 0644, | |
1122 | .proc_handler = &proc_dointvec_minmax, | |
1123 | .strategy = &sysctl_intvec, | |
1124 | .extra1 = &zero, | |
1125 | }, | |
1da177e4 LT |
1126 | #endif |
1127 | { | |
1128 | .ctl_name = VM_LAPTOP_MODE, | |
1129 | .procname = "laptop_mode", | |
1130 | .data = &laptop_mode, | |
1131 | .maxlen = sizeof(laptop_mode), | |
1132 | .mode = 0644, | |
ed5b43f1 BS |
1133 | .proc_handler = &proc_dointvec_jiffies, |
1134 | .strategy = &sysctl_jiffies, | |
1da177e4 LT |
1135 | }, |
1136 | { | |
1137 | .ctl_name = VM_BLOCK_DUMP, | |
1138 | .procname = "block_dump", | |
1139 | .data = &block_dump, | |
1140 | .maxlen = sizeof(block_dump), | |
1141 | .mode = 0644, | |
1142 | .proc_handler = &proc_dointvec, | |
1143 | .strategy = &sysctl_intvec, | |
1144 | .extra1 = &zero, | |
1145 | }, | |
1146 | { | |
1147 | .ctl_name = VM_VFS_CACHE_PRESSURE, | |
1148 | .procname = "vfs_cache_pressure", | |
1149 | .data = &sysctl_vfs_cache_pressure, | |
1150 | .maxlen = sizeof(sysctl_vfs_cache_pressure), | |
1151 | .mode = 0644, | |
1152 | .proc_handler = &proc_dointvec, | |
1153 | .strategy = &sysctl_intvec, | |
1154 | .extra1 = &zero, | |
1155 | }, | |
1156 | #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT | |
1157 | { | |
1158 | .ctl_name = VM_LEGACY_VA_LAYOUT, | |
1159 | .procname = "legacy_va_layout", | |
1160 | .data = &sysctl_legacy_va_layout, | |
1161 | .maxlen = sizeof(sysctl_legacy_va_layout), | |
1162 | .mode = 0644, | |
1163 | .proc_handler = &proc_dointvec, | |
1164 | .strategy = &sysctl_intvec, | |
1165 | .extra1 = &zero, | |
1166 | }, | |
1167 | #endif | |
1743660b CL |
1168 | #ifdef CONFIG_NUMA |
1169 | { | |
1170 | .ctl_name = VM_ZONE_RECLAIM_MODE, | |
1171 | .procname = "zone_reclaim_mode", | |
1172 | .data = &zone_reclaim_mode, | |
1173 | .maxlen = sizeof(zone_reclaim_mode), | |
1174 | .mode = 0644, | |
1175 | .proc_handler = &proc_dointvec, | |
c84db23c CL |
1176 | .strategy = &sysctl_intvec, |
1177 | .extra1 = &zero, | |
1743660b | 1178 | }, |
9614634f CL |
1179 | { |
1180 | .ctl_name = VM_MIN_UNMAPPED, | |
1181 | .procname = "min_unmapped_ratio", | |
1182 | .data = &sysctl_min_unmapped_ratio, | |
1183 | .maxlen = sizeof(sysctl_min_unmapped_ratio), | |
1184 | .mode = 0644, | |
1185 | .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler, | |
1186 | .strategy = &sysctl_intvec, | |
1187 | .extra1 = &zero, | |
1188 | .extra2 = &one_hundred, | |
1189 | }, | |
0ff38490 CL |
1190 | { |
1191 | .ctl_name = VM_MIN_SLAB, | |
1192 | .procname = "min_slab_ratio", | |
1193 | .data = &sysctl_min_slab_ratio, | |
1194 | .maxlen = sizeof(sysctl_min_slab_ratio), | |
1195 | .mode = 0644, | |
1196 | .proc_handler = &sysctl_min_slab_ratio_sysctl_handler, | |
1197 | .strategy = &sysctl_intvec, | |
1198 | .extra1 = &zero, | |
1199 | .extra2 = &one_hundred, | |
1200 | }, | |
e6e5494c | 1201 | #endif |
77461ab3 CL |
1202 | #ifdef CONFIG_SMP |
1203 | { | |
1204 | .ctl_name = CTL_UNNUMBERED, | |
1205 | .procname = "stat_interval", | |
1206 | .data = &sysctl_stat_interval, | |
1207 | .maxlen = sizeof(sysctl_stat_interval), | |
1208 | .mode = 0644, | |
1209 | .proc_handler = &proc_dointvec_jiffies, | |
1210 | .strategy = &sysctl_jiffies, | |
1211 | }, | |
1212 | #endif | |
ed032189 EP |
1213 | #ifdef CONFIG_SECURITY |
1214 | { | |
1215 | .ctl_name = CTL_UNNUMBERED, | |
1216 | .procname = "mmap_min_addr", | |
1217 | .data = &mmap_min_addr, | |
1218 | .maxlen = sizeof(unsigned long), | |
1219 | .mode = 0644, | |
1220 | .proc_handler = &proc_doulongvec_minmax, | |
1221 | }, | |
8daec965 | 1222 | #endif |
f0c0b2b8 KH |
1223 | #ifdef CONFIG_NUMA |
1224 | { | |
1225 | .ctl_name = CTL_UNNUMBERED, | |
1226 | .procname = "numa_zonelist_order", | |
1227 | .data = &numa_zonelist_order, | |
1228 | .maxlen = NUMA_ZONELIST_ORDER_LEN, | |
1229 | .mode = 0644, | |
1230 | .proc_handler = &numa_zonelist_order_handler, | |
1231 | .strategy = &sysctl_string, | |
1232 | }, | |
1233 | #endif | |
2b8232ce | 1234 | #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \ |
5c36e657 | 1235 | (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) |
e6e5494c IM |
1236 | { |
1237 | .ctl_name = VM_VDSO_ENABLED, | |
1238 | .procname = "vdso_enabled", | |
1239 | .data = &vdso_enabled, | |
1240 | .maxlen = sizeof(vdso_enabled), | |
1241 | .mode = 0644, | |
1242 | .proc_handler = &proc_dointvec, | |
1243 | .strategy = &sysctl_intvec, | |
1244 | .extra1 = &zero, | |
1245 | }, | |
1da177e4 | 1246 | #endif |
195cf453 BG |
1247 | #ifdef CONFIG_HIGHMEM |
1248 | { | |
1249 | .ctl_name = CTL_UNNUMBERED, | |
1250 | .procname = "highmem_is_dirtyable", | |
1251 | .data = &vm_highmem_is_dirtyable, | |
1252 | .maxlen = sizeof(vm_highmem_is_dirtyable), | |
1253 | .mode = 0644, | |
1254 | .proc_handler = &proc_dointvec_minmax, | |
1255 | .strategy = &sysctl_intvec, | |
1256 | .extra1 = &zero, | |
1257 | .extra2 = &one, | |
1258 | }, | |
1259 | #endif | |
2be7fe07 AM |
1260 | /* |
1261 | * NOTE: do not add new entries to this table unless you have read | |
1262 | * Documentation/sysctl/ctl_unnumbered.txt | |
1263 | */ | |
1da177e4 LT |
1264 | { .ctl_name = 0 } |
1265 | }; | |
1266 | ||
2abc26fc | 1267 | #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) |
d8217f07 | 1268 | static struct ctl_table binfmt_misc_table[] = { |
2abc26fc EB |
1269 | { .ctl_name = 0 } |
1270 | }; | |
1271 | #endif | |
1272 | ||
d8217f07 | 1273 | static struct ctl_table fs_table[] = { |
1da177e4 LT |
1274 | { |
1275 | .ctl_name = FS_NRINODE, | |
1276 | .procname = "inode-nr", | |
1277 | .data = &inodes_stat, | |
1278 | .maxlen = 2*sizeof(int), | |
1279 | .mode = 0444, | |
1280 | .proc_handler = &proc_dointvec, | |
1281 | }, | |
1282 | { | |
1283 | .ctl_name = FS_STATINODE, | |
1284 | .procname = "inode-state", | |
1285 | .data = &inodes_stat, | |
1286 | .maxlen = 7*sizeof(int), | |
1287 | .mode = 0444, | |
1288 | .proc_handler = &proc_dointvec, | |
1289 | }, | |
1290 | { | |
1da177e4 LT |
1291 | .procname = "file-nr", |
1292 | .data = &files_stat, | |
1293 | .maxlen = 3*sizeof(int), | |
1294 | .mode = 0444, | |
529bf6be | 1295 | .proc_handler = &proc_nr_files, |
1da177e4 LT |
1296 | }, |
1297 | { | |
1298 | .ctl_name = FS_MAXFILE, | |
1299 | .procname = "file-max", | |
1300 | .data = &files_stat.max_files, | |
1301 | .maxlen = sizeof(int), | |
1302 | .mode = 0644, | |
1303 | .proc_handler = &proc_dointvec, | |
1304 | }, | |
9cfe015a ED |
1305 | { |
1306 | .ctl_name = CTL_UNNUMBERED, | |
1307 | .procname = "nr_open", | |
1308 | .data = &sysctl_nr_open, | |
1309 | .maxlen = sizeof(int), | |
1310 | .mode = 0644, | |
eceea0b3 AV |
1311 | .proc_handler = &proc_dointvec_minmax, |
1312 | .extra1 = &sysctl_nr_open_min, | |
1313 | .extra2 = &sysctl_nr_open_max, | |
9cfe015a | 1314 | }, |
1da177e4 LT |
1315 | { |
1316 | .ctl_name = FS_DENTRY, | |
1317 | .procname = "dentry-state", | |
1318 | .data = &dentry_stat, | |
1319 | .maxlen = 6*sizeof(int), | |
1320 | .mode = 0444, | |
1321 | .proc_handler = &proc_dointvec, | |
1322 | }, | |
1323 | { | |
1324 | .ctl_name = FS_OVERFLOWUID, | |
1325 | .procname = "overflowuid", | |
1326 | .data = &fs_overflowuid, | |
1327 | .maxlen = sizeof(int), | |
1328 | .mode = 0644, | |
1329 | .proc_handler = &proc_dointvec_minmax, | |
1330 | .strategy = &sysctl_intvec, | |
1331 | .extra1 = &minolduid, | |
1332 | .extra2 = &maxolduid, | |
1333 | }, | |
1334 | { | |
1335 | .ctl_name = FS_OVERFLOWGID, | |
1336 | .procname = "overflowgid", | |
1337 | .data = &fs_overflowgid, | |
1338 | .maxlen = sizeof(int), | |
1339 | .mode = 0644, | |
1340 | .proc_handler = &proc_dointvec_minmax, | |
1341 | .strategy = &sysctl_intvec, | |
1342 | .extra1 = &minolduid, | |
1343 | .extra2 = &maxolduid, | |
1344 | }, | |
bfcd17a6 | 1345 | #ifdef CONFIG_FILE_LOCKING |
1da177e4 LT |
1346 | { |
1347 | .ctl_name = FS_LEASES, | |
1348 | .procname = "leases-enable", | |
1349 | .data = &leases_enable, | |
1350 | .maxlen = sizeof(int), | |
1351 | .mode = 0644, | |
1352 | .proc_handler = &proc_dointvec, | |
1353 | }, | |
bfcd17a6 | 1354 | #endif |
1da177e4 LT |
1355 | #ifdef CONFIG_DNOTIFY |
1356 | { | |
1357 | .ctl_name = FS_DIR_NOTIFY, | |
1358 | .procname = "dir-notify-enable", | |
1359 | .data = &dir_notify_enable, | |
1360 | .maxlen = sizeof(int), | |
1361 | .mode = 0644, | |
1362 | .proc_handler = &proc_dointvec, | |
1363 | }, | |
1364 | #endif | |
1365 | #ifdef CONFIG_MMU | |
bfcd17a6 | 1366 | #ifdef CONFIG_FILE_LOCKING |
1da177e4 LT |
1367 | { |
1368 | .ctl_name = FS_LEASE_TIME, | |
1369 | .procname = "lease-break-time", | |
1370 | .data = &lease_break_time, | |
1371 | .maxlen = sizeof(int), | |
1372 | .mode = 0644, | |
8e654fba | 1373 | .proc_handler = &proc_dointvec, |
1da177e4 | 1374 | }, |
bfcd17a6 | 1375 | #endif |
ebf3f09c | 1376 | #ifdef CONFIG_AIO |
1da177e4 | 1377 | { |
1da177e4 LT |
1378 | .procname = "aio-nr", |
1379 | .data = &aio_nr, | |
1380 | .maxlen = sizeof(aio_nr), | |
1381 | .mode = 0444, | |
d55b5fda | 1382 | .proc_handler = &proc_doulongvec_minmax, |
1da177e4 LT |
1383 | }, |
1384 | { | |
1da177e4 LT |
1385 | .procname = "aio-max-nr", |
1386 | .data = &aio_max_nr, | |
1387 | .maxlen = sizeof(aio_max_nr), | |
1388 | .mode = 0644, | |
d55b5fda | 1389 | .proc_handler = &proc_doulongvec_minmax, |
1da177e4 | 1390 | }, |
ebf3f09c | 1391 | #endif /* CONFIG_AIO */ |
2d9048e2 | 1392 | #ifdef CONFIG_INOTIFY_USER |
0399cb08 RL |
1393 | { |
1394 | .ctl_name = FS_INOTIFY, | |
1395 | .procname = "inotify", | |
1396 | .mode = 0555, | |
1397 | .child = inotify_table, | |
1398 | }, | |
1399 | #endif | |
7ef9964e DL |
1400 | #ifdef CONFIG_EPOLL |
1401 | { | |
1402 | .procname = "epoll", | |
1403 | .mode = 0555, | |
1404 | .child = epoll_table, | |
1405 | }, | |
1406 | #endif | |
1da177e4 | 1407 | #endif |
d6e71144 AC |
1408 | { |
1409 | .ctl_name = KERN_SETUID_DUMPABLE, | |
1410 | .procname = "suid_dumpable", | |
1411 | .data = &suid_dumpable, | |
1412 | .maxlen = sizeof(int), | |
1413 | .mode = 0644, | |
8e654fba MW |
1414 | .proc_handler = &proc_dointvec_minmax, |
1415 | .strategy = &sysctl_intvec, | |
1416 | .extra1 = &zero, | |
1417 | .extra2 = &two, | |
d6e71144 | 1418 | }, |
2abc26fc EB |
1419 | #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE) |
1420 | { | |
1421 | .ctl_name = CTL_UNNUMBERED, | |
1422 | .procname = "binfmt_misc", | |
1423 | .mode = 0555, | |
1424 | .child = binfmt_misc_table, | |
1425 | }, | |
1426 | #endif | |
2be7fe07 AM |
1427 | /* |
1428 | * NOTE: do not add new entries to this table unless you have read | |
1429 | * Documentation/sysctl/ctl_unnumbered.txt | |
2be7fe07 | 1430 | */ |
1da177e4 LT |
1431 | { .ctl_name = 0 } |
1432 | }; | |
1433 | ||
d8217f07 | 1434 | static struct ctl_table debug_table[] = { |
d0c3d534 | 1435 | #if defined(CONFIG_X86) || defined(CONFIG_PPC) |
abd4f750 MAS |
1436 | { |
1437 | .ctl_name = CTL_UNNUMBERED, | |
1438 | .procname = "exception-trace", | |
1439 | .data = &show_unhandled_signals, | |
1440 | .maxlen = sizeof(int), | |
1441 | .mode = 0644, | |
1442 | .proc_handler = proc_dointvec | |
1443 | }, | |
1444 | #endif | |
1da177e4 LT |
1445 | { .ctl_name = 0 } |
1446 | }; | |
1447 | ||
d8217f07 | 1448 | static struct ctl_table dev_table[] = { |
1da177e4 | 1449 | { .ctl_name = 0 } |
0eeca283 | 1450 | }; |
1da177e4 | 1451 | |
330d57fb AV |
1452 | static DEFINE_SPINLOCK(sysctl_lock); |
1453 | ||
1454 | /* called under sysctl_lock */ | |
1455 | static int use_table(struct ctl_table_header *p) | |
1456 | { | |
1457 | if (unlikely(p->unregistering)) | |
1458 | return 0; | |
1459 | p->used++; | |
1460 | return 1; | |
1461 | } | |
1462 | ||
1463 | /* called under sysctl_lock */ | |
1464 | static void unuse_table(struct ctl_table_header *p) | |
1465 | { | |
1466 | if (!--p->used) | |
1467 | if (unlikely(p->unregistering)) | |
1468 | complete(p->unregistering); | |
1469 | } | |
1470 | ||
1471 | /* called under sysctl_lock, will reacquire if has to wait */ | |
1472 | static void start_unregistering(struct ctl_table_header *p) | |
1473 | { | |
1474 | /* | |
1475 | * if p->used is 0, nobody will ever touch that entry again; | |
1476 | * we'll eliminate all paths to it before dropping sysctl_lock | |
1477 | */ | |
1478 | if (unlikely(p->used)) { | |
1479 | struct completion wait; | |
1480 | init_completion(&wait); | |
1481 | p->unregistering = &wait; | |
1482 | spin_unlock(&sysctl_lock); | |
1483 | wait_for_completion(&wait); | |
1484 | spin_lock(&sysctl_lock); | |
f7e6ced4 AV |
1485 | } else { |
1486 | /* anything non-NULL; we'll never dereference it */ | |
1487 | p->unregistering = ERR_PTR(-EINVAL); | |
330d57fb AV |
1488 | } |
1489 | /* | |
1490 | * do not remove from the list until nobody holds it; walking the | |
1491 | * list in do_sysctl() relies on that. | |
1492 | */ | |
1493 | list_del_init(&p->ctl_entry); | |
1494 | } | |
1495 | ||
f7e6ced4 AV |
1496 | void sysctl_head_get(struct ctl_table_header *head) |
1497 | { | |
1498 | spin_lock(&sysctl_lock); | |
1499 | head->count++; | |
1500 | spin_unlock(&sysctl_lock); | |
1501 | } | |
1502 | ||
1503 | void sysctl_head_put(struct ctl_table_header *head) | |
1504 | { | |
1505 | spin_lock(&sysctl_lock); | |
1506 | if (!--head->count) | |
1507 | kfree(head); | |
1508 | spin_unlock(&sysctl_lock); | |
1509 | } | |
1510 | ||
1511 | struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head) | |
1512 | { | |
1513 | if (!head) | |
1514 | BUG(); | |
1515 | spin_lock(&sysctl_lock); | |
1516 | if (!use_table(head)) | |
1517 | head = ERR_PTR(-ENOENT); | |
1518 | spin_unlock(&sysctl_lock); | |
1519 | return head; | |
1520 | } | |
1521 | ||
805b5d5e EB |
1522 | void sysctl_head_finish(struct ctl_table_header *head) |
1523 | { | |
1524 | if (!head) | |
1525 | return; | |
1526 | spin_lock(&sysctl_lock); | |
1527 | unuse_table(head); | |
1528 | spin_unlock(&sysctl_lock); | |
1529 | } | |
1530 | ||
73455092 AV |
1531 | static struct ctl_table_set * |
1532 | lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces) | |
1533 | { | |
1534 | struct ctl_table_set *set = &root->default_set; | |
1535 | if (root->lookup) | |
1536 | set = root->lookup(root, namespaces); | |
1537 | return set; | |
1538 | } | |
1539 | ||
e51b6ba0 EB |
1540 | static struct list_head * |
1541 | lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces) | |
805b5d5e | 1542 | { |
73455092 AV |
1543 | struct ctl_table_set *set = lookup_header_set(root, namespaces); |
1544 | return &set->list; | |
e51b6ba0 EB |
1545 | } |
1546 | ||
1547 | struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces, | |
1548 | struct ctl_table_header *prev) | |
1549 | { | |
1550 | struct ctl_table_root *root; | |
1551 | struct list_head *header_list; | |
805b5d5e EB |
1552 | struct ctl_table_header *head; |
1553 | struct list_head *tmp; | |
e51b6ba0 | 1554 | |
805b5d5e EB |
1555 | spin_lock(&sysctl_lock); |
1556 | if (prev) { | |
e51b6ba0 | 1557 | head = prev; |
805b5d5e EB |
1558 | tmp = &prev->ctl_entry; |
1559 | unuse_table(prev); | |
1560 | goto next; | |
1561 | } | |
1562 | tmp = &root_table_header.ctl_entry; | |
1563 | for (;;) { | |
1564 | head = list_entry(tmp, struct ctl_table_header, ctl_entry); | |
1565 | ||
1566 | if (!use_table(head)) | |
1567 | goto next; | |
1568 | spin_unlock(&sysctl_lock); | |
1569 | return head; | |
1570 | next: | |
e51b6ba0 | 1571 | root = head->root; |
805b5d5e | 1572 | tmp = tmp->next; |
e51b6ba0 EB |
1573 | header_list = lookup_header_list(root, namespaces); |
1574 | if (tmp != header_list) | |
1575 | continue; | |
1576 | ||
1577 | do { | |
1578 | root = list_entry(root->root_list.next, | |
1579 | struct ctl_table_root, root_list); | |
1580 | if (root == &sysctl_table_root) | |
1581 | goto out; | |
1582 | header_list = lookup_header_list(root, namespaces); | |
1583 | } while (list_empty(header_list)); | |
1584 | tmp = header_list->next; | |
805b5d5e | 1585 | } |
e51b6ba0 | 1586 | out: |
805b5d5e EB |
1587 | spin_unlock(&sysctl_lock); |
1588 | return NULL; | |
1589 | } | |
1590 | ||
e51b6ba0 EB |
1591 | struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev) |
1592 | { | |
1593 | return __sysctl_head_next(current->nsproxy, prev); | |
1594 | } | |
1595 | ||
1596 | void register_sysctl_root(struct ctl_table_root *root) | |
1597 | { | |
1598 | spin_lock(&sysctl_lock); | |
1599 | list_add_tail(&root->root_list, &sysctl_table_root.root_list); | |
1600 | spin_unlock(&sysctl_lock); | |
1601 | } | |
1602 | ||
b89a8171 | 1603 | #ifdef CONFIG_SYSCTL_SYSCALL |
2c4c7155 | 1604 | /* Perform the actual read/write of a sysctl table entry. */ |
d7321cd6 PE |
1605 | static int do_sysctl_strategy(struct ctl_table_root *root, |
1606 | struct ctl_table *table, | |
2c4c7155 PE |
1607 | void __user *oldval, size_t __user *oldlenp, |
1608 | void __user *newval, size_t newlen) | |
1609 | { | |
1610 | int op = 0, rc; | |
1611 | ||
1612 | if (oldval) | |
e6305c43 | 1613 | op |= MAY_READ; |
2c4c7155 | 1614 | if (newval) |
e6305c43 | 1615 | op |= MAY_WRITE; |
d7321cd6 | 1616 | if (sysctl_perm(root, table, op)) |
2c4c7155 PE |
1617 | return -EPERM; |
1618 | ||
1619 | if (table->strategy) { | |
f221e726 | 1620 | rc = table->strategy(table, oldval, oldlenp, newval, newlen); |
2c4c7155 PE |
1621 | if (rc < 0) |
1622 | return rc; | |
1623 | if (rc > 0) | |
1624 | return 0; | |
1625 | } | |
1626 | ||
1627 | /* If there is no strategy routine, or if the strategy returns | |
1628 | * zero, proceed with automatic r/w */ | |
1629 | if (table->data && table->maxlen) { | |
f221e726 | 1630 | rc = sysctl_data(table, oldval, oldlenp, newval, newlen); |
2c4c7155 PE |
1631 | if (rc < 0) |
1632 | return rc; | |
1633 | } | |
1634 | return 0; | |
1635 | } | |
1636 | ||
1637 | static int parse_table(int __user *name, int nlen, | |
1638 | void __user *oldval, size_t __user *oldlenp, | |
1639 | void __user *newval, size_t newlen, | |
d7321cd6 | 1640 | struct ctl_table_root *root, |
2c4c7155 PE |
1641 | struct ctl_table *table) |
1642 | { | |
1643 | int n; | |
1644 | repeat: | |
1645 | if (!nlen) | |
1646 | return -ENOTDIR; | |
1647 | if (get_user(n, name)) | |
1648 | return -EFAULT; | |
1649 | for ( ; table->ctl_name || table->procname; table++) { | |
1650 | if (!table->ctl_name) | |
1651 | continue; | |
1652 | if (n == table->ctl_name) { | |
1653 | int error; | |
1654 | if (table->child) { | |
e6305c43 | 1655 | if (sysctl_perm(root, table, MAY_EXEC)) |
2c4c7155 PE |
1656 | return -EPERM; |
1657 | name++; | |
1658 | nlen--; | |
1659 | table = table->child; | |
1660 | goto repeat; | |
1661 | } | |
f221e726 | 1662 | error = do_sysctl_strategy(root, table, |
2c4c7155 PE |
1663 | oldval, oldlenp, |
1664 | newval, newlen); | |
1665 | return error; | |
1666 | } | |
1667 | } | |
1668 | return -ENOTDIR; | |
1669 | } | |
1670 | ||
1da177e4 LT |
1671 | int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp, |
1672 | void __user *newval, size_t newlen) | |
1673 | { | |
805b5d5e | 1674 | struct ctl_table_header *head; |
330d57fb | 1675 | int error = -ENOTDIR; |
1da177e4 LT |
1676 | |
1677 | if (nlen <= 0 || nlen >= CTL_MAXNAME) | |
1678 | return -ENOTDIR; | |
1679 | if (oldval) { | |
1680 | int old_len; | |
1681 | if (!oldlenp || get_user(old_len, oldlenp)) | |
1682 | return -EFAULT; | |
1683 | } | |
330d57fb | 1684 | |
805b5d5e EB |
1685 | for (head = sysctl_head_next(NULL); head; |
1686 | head = sysctl_head_next(head)) { | |
330d57fb | 1687 | error = parse_table(name, nlen, oldval, oldlenp, |
d7321cd6 PE |
1688 | newval, newlen, |
1689 | head->root, head->ctl_table); | |
805b5d5e EB |
1690 | if (error != -ENOTDIR) { |
1691 | sysctl_head_finish(head); | |
330d57fb | 1692 | break; |
805b5d5e EB |
1693 | } |
1694 | } | |
330d57fb | 1695 | return error; |
1da177e4 LT |
1696 | } |
1697 | ||
1e7bfb21 | 1698 | SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args) |
1da177e4 LT |
1699 | { |
1700 | struct __sysctl_args tmp; | |
1701 | int error; | |
1702 | ||
1703 | if (copy_from_user(&tmp, args, sizeof(tmp))) | |
1704 | return -EFAULT; | |
1705 | ||
7058cb02 EB |
1706 | error = deprecated_sysctl_warning(&tmp); |
1707 | if (error) | |
1708 | goto out; | |
1709 | ||
1da177e4 LT |
1710 | lock_kernel(); |
1711 | error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp, | |
1712 | tmp.newval, tmp.newlen); | |
1713 | unlock_kernel(); | |
7058cb02 | 1714 | out: |
1da177e4 LT |
1715 | return error; |
1716 | } | |
b89a8171 | 1717 | #endif /* CONFIG_SYSCTL_SYSCALL */ |
1da177e4 LT |
1718 | |
1719 | /* | |
1ff007eb | 1720 | * sysctl_perm does NOT grant the superuser all rights automatically, because |
1da177e4 LT |
1721 | * some sysctl variables are readonly even to root. |
1722 | */ | |
1723 | ||
1724 | static int test_perm(int mode, int op) | |
1725 | { | |
76aac0e9 | 1726 | if (!current_euid()) |
1da177e4 LT |
1727 | mode >>= 6; |
1728 | else if (in_egroup_p(0)) | |
1729 | mode >>= 3; | |
e6305c43 | 1730 | if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0) |
1da177e4 LT |
1731 | return 0; |
1732 | return -EACCES; | |
1733 | } | |
1734 | ||
d7321cd6 | 1735 | int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op) |
1da177e4 LT |
1736 | { |
1737 | int error; | |
d7321cd6 PE |
1738 | int mode; |
1739 | ||
e6305c43 | 1740 | error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC)); |
1da177e4 LT |
1741 | if (error) |
1742 | return error; | |
d7321cd6 PE |
1743 | |
1744 | if (root->permissions) | |
1745 | mode = root->permissions(root, current->nsproxy, table); | |
1746 | else | |
1747 | mode = table->mode; | |
1748 | ||
1749 | return test_perm(mode, op); | |
1da177e4 LT |
1750 | } |
1751 | ||
d912b0cc EB |
1752 | static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table) |
1753 | { | |
1754 | for (; table->ctl_name || table->procname; table++) { | |
1755 | table->parent = parent; | |
1756 | if (table->child) | |
1757 | sysctl_set_parent(table, table->child); | |
1758 | } | |
1759 | } | |
1760 | ||
1761 | static __init int sysctl_init(void) | |
1762 | { | |
1763 | sysctl_set_parent(NULL, root_table); | |
88f458e4 HS |
1764 | #ifdef CONFIG_SYSCTL_SYSCALL_CHECK |
1765 | { | |
1766 | int err; | |
1767 | err = sysctl_check_table(current->nsproxy, root_table); | |
1768 | } | |
1769 | #endif | |
d912b0cc EB |
1770 | return 0; |
1771 | } | |
1772 | ||
1773 | core_initcall(sysctl_init); | |
1774 | ||
bfbcf034 AV |
1775 | static struct ctl_table *is_branch_in(struct ctl_table *branch, |
1776 | struct ctl_table *table) | |
ae7edecc AV |
1777 | { |
1778 | struct ctl_table *p; | |
1779 | const char *s = branch->procname; | |
1780 | ||
1781 | /* branch should have named subdirectory as its first element */ | |
1782 | if (!s || !branch->child) | |
bfbcf034 | 1783 | return NULL; |
ae7edecc AV |
1784 | |
1785 | /* ... and nothing else */ | |
1786 | if (branch[1].procname || branch[1].ctl_name) | |
bfbcf034 | 1787 | return NULL; |
ae7edecc AV |
1788 | |
1789 | /* table should contain subdirectory with the same name */ | |
1790 | for (p = table; p->procname || p->ctl_name; p++) { | |
1791 | if (!p->child) | |
1792 | continue; | |
1793 | if (p->procname && strcmp(p->procname, s) == 0) | |
bfbcf034 | 1794 | return p; |
ae7edecc | 1795 | } |
bfbcf034 | 1796 | return NULL; |
ae7edecc AV |
1797 | } |
1798 | ||
1799 | /* see if attaching q to p would be an improvement */ | |
1800 | static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q) | |
1801 | { | |
1802 | struct ctl_table *to = p->ctl_table, *by = q->ctl_table; | |
bfbcf034 | 1803 | struct ctl_table *next; |
ae7edecc AV |
1804 | int is_better = 0; |
1805 | int not_in_parent = !p->attached_by; | |
1806 | ||
bfbcf034 | 1807 | while ((next = is_branch_in(by, to)) != NULL) { |
ae7edecc AV |
1808 | if (by == q->attached_by) |
1809 | is_better = 1; | |
1810 | if (to == p->attached_by) | |
1811 | not_in_parent = 1; | |
1812 | by = by->child; | |
bfbcf034 | 1813 | to = next->child; |
ae7edecc AV |
1814 | } |
1815 | ||
1816 | if (is_better && not_in_parent) { | |
1817 | q->attached_by = by; | |
1818 | q->attached_to = to; | |
1819 | q->parent = p; | |
1820 | } | |
1821 | } | |
1822 | ||
1da177e4 | 1823 | /** |
e51b6ba0 EB |
1824 | * __register_sysctl_paths - register a sysctl hierarchy |
1825 | * @root: List of sysctl headers to register on | |
1826 | * @namespaces: Data to compute which lists of sysctl entries are visible | |
29e796fd | 1827 | * @path: The path to the directory the sysctl table is in. |
1da177e4 | 1828 | * @table: the top-level table structure |
1da177e4 LT |
1829 | * |
1830 | * Register a sysctl table hierarchy. @table should be a filled in ctl_table | |
29e796fd | 1831 | * array. A completely 0 filled entry terminates the table. |
1da177e4 | 1832 | * |
d8217f07 | 1833 | * The members of the &struct ctl_table structure are used as follows: |
1da177e4 LT |
1834 | * |
1835 | * ctl_name - This is the numeric sysctl value used by sysctl(2). The number | |
1836 | * must be unique within that level of sysctl | |
1837 | * | |
1838 | * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not | |
1839 | * enter a sysctl file | |
1840 | * | |
1841 | * data - a pointer to data for use by proc_handler | |
1842 | * | |
1843 | * maxlen - the maximum size in bytes of the data | |
1844 | * | |
1845 | * mode - the file permissions for the /proc/sys file, and for sysctl(2) | |
1846 | * | |
1847 | * child - a pointer to the child sysctl table if this entry is a directory, or | |
1848 | * %NULL. | |
1849 | * | |
1850 | * proc_handler - the text handler routine (described below) | |
1851 | * | |
1852 | * strategy - the strategy routine (described below) | |
1853 | * | |
1854 | * de - for internal use by the sysctl routines | |
1855 | * | |
1856 | * extra1, extra2 - extra pointers usable by the proc handler routines | |
1857 | * | |
1858 | * Leaf nodes in the sysctl tree will be represented by a single file | |
1859 | * under /proc; non-leaf nodes will be represented by directories. | |
1860 | * | |
1861 | * sysctl(2) can automatically manage read and write requests through | |
1862 | * the sysctl table. The data and maxlen fields of the ctl_table | |
1863 | * struct enable minimal validation of the values being written to be | |
1864 | * performed, and the mode field allows minimal authentication. | |
1865 | * | |
1866 | * More sophisticated management can be enabled by the provision of a | |
1867 | * strategy routine with the table entry. This will be called before | |
1868 | * any automatic read or write of the data is performed. | |
1869 | * | |
1870 | * The strategy routine may return | |
1871 | * | |
1872 | * < 0 - Error occurred (error is passed to user process) | |
1873 | * | |
1874 | * 0 - OK - proceed with automatic read or write. | |
1875 | * | |
1876 | * > 0 - OK - read or write has been done by the strategy routine, so | |
1877 | * return immediately. | |
1878 | * | |
1879 | * There must be a proc_handler routine for any terminal nodes | |
1880 | * mirrored under /proc/sys (non-terminals are handled by a built-in | |
1881 | * directory handler). Several default handlers are available to | |
1882 | * cover common cases - | |
1883 | * | |
1884 | * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(), | |
1885 | * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), | |
1886 | * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax() | |
1887 | * | |
1888 | * It is the handler's job to read the input buffer from user memory | |
1889 | * and process it. The handler should return 0 on success. | |
1890 | * | |
1891 | * This routine returns %NULL on a failure to register, and a pointer | |
1892 | * to the table header on success. | |
1893 | */ | |
e51b6ba0 EB |
1894 | struct ctl_table_header *__register_sysctl_paths( |
1895 | struct ctl_table_root *root, | |
1896 | struct nsproxy *namespaces, | |
1897 | const struct ctl_path *path, struct ctl_table *table) | |
1da177e4 | 1898 | { |
29e796fd EB |
1899 | struct ctl_table_header *header; |
1900 | struct ctl_table *new, **prevp; | |
1901 | unsigned int n, npath; | |
ae7edecc | 1902 | struct ctl_table_set *set; |
29e796fd EB |
1903 | |
1904 | /* Count the path components */ | |
1905 | for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath) | |
1906 | ; | |
1907 | ||
1908 | /* | |
1909 | * For each path component, allocate a 2-element ctl_table array. | |
1910 | * The first array element will be filled with the sysctl entry | |
1911 | * for this, the second will be the sentinel (ctl_name == 0). | |
1912 | * | |
1913 | * We allocate everything in one go so that we don't have to | |
1914 | * worry about freeing additional memory in unregister_sysctl_table. | |
1915 | */ | |
1916 | header = kzalloc(sizeof(struct ctl_table_header) + | |
1917 | (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL); | |
1918 | if (!header) | |
1da177e4 | 1919 | return NULL; |
29e796fd EB |
1920 | |
1921 | new = (struct ctl_table *) (header + 1); | |
1922 | ||
1923 | /* Now connect the dots */ | |
1924 | prevp = &header->ctl_table; | |
1925 | for (n = 0; n < npath; ++n, ++path) { | |
1926 | /* Copy the procname */ | |
1927 | new->procname = path->procname; | |
1928 | new->ctl_name = path->ctl_name; | |
1929 | new->mode = 0555; | |
1930 | ||
1931 | *prevp = new; | |
1932 | prevp = &new->child; | |
1933 | ||
1934 | new += 2; | |
1935 | } | |
1936 | *prevp = table; | |
23eb06de | 1937 | header->ctl_table_arg = table; |
29e796fd EB |
1938 | |
1939 | INIT_LIST_HEAD(&header->ctl_entry); | |
1940 | header->used = 0; | |
1941 | header->unregistering = NULL; | |
e51b6ba0 | 1942 | header->root = root; |
29e796fd | 1943 | sysctl_set_parent(NULL, header->ctl_table); |
f7e6ced4 | 1944 | header->count = 1; |
88f458e4 | 1945 | #ifdef CONFIG_SYSCTL_SYSCALL_CHECK |
e51b6ba0 | 1946 | if (sysctl_check_table(namespaces, header->ctl_table)) { |
29e796fd | 1947 | kfree(header); |
fc6cd25b EB |
1948 | return NULL; |
1949 | } | |
88f458e4 | 1950 | #endif |
330d57fb | 1951 | spin_lock(&sysctl_lock); |
73455092 | 1952 | header->set = lookup_header_set(root, namespaces); |
ae7edecc AV |
1953 | header->attached_by = header->ctl_table; |
1954 | header->attached_to = root_table; | |
1955 | header->parent = &root_table_header; | |
1956 | for (set = header->set; set; set = set->parent) { | |
1957 | struct ctl_table_header *p; | |
1958 | list_for_each_entry(p, &set->list, ctl_entry) { | |
1959 | if (p->unregistering) | |
1960 | continue; | |
1961 | try_attach(p, header); | |
1962 | } | |
1963 | } | |
1964 | header->parent->count++; | |
73455092 | 1965 | list_add_tail(&header->ctl_entry, &header->set->list); |
330d57fb | 1966 | spin_unlock(&sysctl_lock); |
29e796fd EB |
1967 | |
1968 | return header; | |
1969 | } | |
1970 | ||
e51b6ba0 EB |
1971 | /** |
1972 | * register_sysctl_table_path - register a sysctl table hierarchy | |
1973 | * @path: The path to the directory the sysctl table is in. | |
1974 | * @table: the top-level table structure | |
1975 | * | |
1976 | * Register a sysctl table hierarchy. @table should be a filled in ctl_table | |
1977 | * array. A completely 0 filled entry terminates the table. | |
1978 | * | |
1979 | * See __register_sysctl_paths for more details. | |
1980 | */ | |
1981 | struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, | |
1982 | struct ctl_table *table) | |
1983 | { | |
1984 | return __register_sysctl_paths(&sysctl_table_root, current->nsproxy, | |
1985 | path, table); | |
1986 | } | |
1987 | ||
29e796fd EB |
1988 | /** |
1989 | * register_sysctl_table - register a sysctl table hierarchy | |
1990 | * @table: the top-level table structure | |
1991 | * | |
1992 | * Register a sysctl table hierarchy. @table should be a filled in ctl_table | |
1993 | * array. A completely 0 filled entry terminates the table. | |
1994 | * | |
1995 | * See register_sysctl_paths for more details. | |
1996 | */ | |
1997 | struct ctl_table_header *register_sysctl_table(struct ctl_table *table) | |
1998 | { | |
1999 | static const struct ctl_path null_path[] = { {} }; | |
2000 | ||
2001 | return register_sysctl_paths(null_path, table); | |
1da177e4 LT |
2002 | } |
2003 | ||
2004 | /** | |
2005 | * unregister_sysctl_table - unregister a sysctl table hierarchy | |
2006 | * @header: the header returned from register_sysctl_table | |
2007 | * | |
2008 | * Unregisters the sysctl table and all children. proc entries may not | |
2009 | * actually be removed until they are no longer used by anyone. | |
2010 | */ | |
2011 | void unregister_sysctl_table(struct ctl_table_header * header) | |
2012 | { | |
330d57fb | 2013 | might_sleep(); |
f1dad166 PE |
2014 | |
2015 | if (header == NULL) | |
2016 | return; | |
2017 | ||
330d57fb AV |
2018 | spin_lock(&sysctl_lock); |
2019 | start_unregistering(header); | |
ae7edecc AV |
2020 | if (!--header->parent->count) { |
2021 | WARN_ON(1); | |
2022 | kfree(header->parent); | |
2023 | } | |
f7e6ced4 AV |
2024 | if (!--header->count) |
2025 | kfree(header); | |
330d57fb | 2026 | spin_unlock(&sysctl_lock); |
1da177e4 LT |
2027 | } |
2028 | ||
9043476f AV |
2029 | int sysctl_is_seen(struct ctl_table_header *p) |
2030 | { | |
2031 | struct ctl_table_set *set = p->set; | |
2032 | int res; | |
2033 | spin_lock(&sysctl_lock); | |
2034 | if (p->unregistering) | |
2035 | res = 0; | |
2036 | else if (!set->is_seen) | |
2037 | res = 1; | |
2038 | else | |
2039 | res = set->is_seen(set); | |
2040 | spin_unlock(&sysctl_lock); | |
2041 | return res; | |
2042 | } | |
2043 | ||
73455092 AV |
2044 | void setup_sysctl_set(struct ctl_table_set *p, |
2045 | struct ctl_table_set *parent, | |
2046 | int (*is_seen)(struct ctl_table_set *)) | |
2047 | { | |
2048 | INIT_LIST_HEAD(&p->list); | |
2049 | p->parent = parent ? parent : &sysctl_table_root.default_set; | |
2050 | p->is_seen = is_seen; | |
2051 | } | |
2052 | ||
b89a8171 | 2053 | #else /* !CONFIG_SYSCTL */ |
d8217f07 | 2054 | struct ctl_table_header *register_sysctl_table(struct ctl_table * table) |
b89a8171 EB |
2055 | { |
2056 | return NULL; | |
2057 | } | |
2058 | ||
29e796fd EB |
2059 | struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, |
2060 | struct ctl_table *table) | |
2061 | { | |
2062 | return NULL; | |
2063 | } | |
2064 | ||
b89a8171 EB |
2065 | void unregister_sysctl_table(struct ctl_table_header * table) |
2066 | { | |
2067 | } | |
2068 | ||
73455092 AV |
2069 | void setup_sysctl_set(struct ctl_table_set *p, |
2070 | struct ctl_table_set *parent, | |
2071 | int (*is_seen)(struct ctl_table_set *)) | |
2072 | { | |
2073 | } | |
2074 | ||
f7e6ced4 AV |
2075 | void sysctl_head_put(struct ctl_table_header *head) |
2076 | { | |
2077 | } | |
2078 | ||
b89a8171 EB |
2079 | #endif /* CONFIG_SYSCTL */ |
2080 | ||
1da177e4 LT |
2081 | /* |
2082 | * /proc/sys support | |
2083 | */ | |
2084 | ||
b89a8171 | 2085 | #ifdef CONFIG_PROC_SYSCTL |
1da177e4 | 2086 | |
b1ba4ddd AB |
2087 | static int _proc_do_string(void* data, int maxlen, int write, |
2088 | struct file *filp, void __user *buffer, | |
2089 | size_t *lenp, loff_t *ppos) | |
1da177e4 LT |
2090 | { |
2091 | size_t len; | |
2092 | char __user *p; | |
2093 | char c; | |
8d060877 ON |
2094 | |
2095 | if (!data || !maxlen || !*lenp) { | |
1da177e4 LT |
2096 | *lenp = 0; |
2097 | return 0; | |
2098 | } | |
8d060877 | 2099 | |
1da177e4 LT |
2100 | if (write) { |
2101 | len = 0; | |
2102 | p = buffer; | |
2103 | while (len < *lenp) { | |
2104 | if (get_user(c, p++)) | |
2105 | return -EFAULT; | |
2106 | if (c == 0 || c == '\n') | |
2107 | break; | |
2108 | len++; | |
2109 | } | |
f5dd3d6f SV |
2110 | if (len >= maxlen) |
2111 | len = maxlen-1; | |
2112 | if(copy_from_user(data, buffer, len)) | |
1da177e4 | 2113 | return -EFAULT; |
f5dd3d6f | 2114 | ((char *) data)[len] = 0; |
1da177e4 LT |
2115 | *ppos += *lenp; |
2116 | } else { | |
f5dd3d6f SV |
2117 | len = strlen(data); |
2118 | if (len > maxlen) | |
2119 | len = maxlen; | |
8d060877 ON |
2120 | |
2121 | if (*ppos > len) { | |
2122 | *lenp = 0; | |
2123 | return 0; | |
2124 | } | |
2125 | ||
2126 | data += *ppos; | |
2127 | len -= *ppos; | |
2128 | ||
1da177e4 LT |
2129 | if (len > *lenp) |
2130 | len = *lenp; | |
2131 | if (len) | |
f5dd3d6f | 2132 | if(copy_to_user(buffer, data, len)) |
1da177e4 LT |
2133 | return -EFAULT; |
2134 | if (len < *lenp) { | |
2135 | if(put_user('\n', ((char __user *) buffer) + len)) | |
2136 | return -EFAULT; | |
2137 | len++; | |
2138 | } | |
2139 | *lenp = len; | |
2140 | *ppos += len; | |
2141 | } | |
2142 | return 0; | |
2143 | } | |
2144 | ||
f5dd3d6f SV |
2145 | /** |
2146 | * proc_dostring - read a string sysctl | |
2147 | * @table: the sysctl table | |
2148 | * @write: %TRUE if this is a write to the sysctl file | |
2149 | * @filp: the file structure | |
2150 | * @buffer: the user buffer | |
2151 | * @lenp: the size of the user buffer | |
2152 | * @ppos: file position | |
2153 | * | |
2154 | * Reads/writes a string from/to the user buffer. If the kernel | |
2155 | * buffer provided is not large enough to hold the string, the | |
2156 | * string is truncated. The copied string is %NULL-terminated. | |
2157 | * If the string is being read by the user process, it is copied | |
2158 | * and a newline '\n' is added. It is truncated if the buffer is | |
2159 | * not large enough. | |
2160 | * | |
2161 | * Returns 0 on success. | |
2162 | */ | |
d8217f07 | 2163 | int proc_dostring(struct ctl_table *table, int write, struct file *filp, |
f5dd3d6f SV |
2164 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2165 | { | |
2166 | return _proc_do_string(table->data, table->maxlen, write, filp, | |
2167 | buffer, lenp, ppos); | |
2168 | } | |
2169 | ||
1da177e4 LT |
2170 | |
2171 | static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp, | |
2172 | int *valp, | |
2173 | int write, void *data) | |
2174 | { | |
2175 | if (write) { | |
2176 | *valp = *negp ? -*lvalp : *lvalp; | |
2177 | } else { | |
2178 | int val = *valp; | |
2179 | if (val < 0) { | |
2180 | *negp = -1; | |
2181 | *lvalp = (unsigned long)-val; | |
2182 | } else { | |
2183 | *negp = 0; | |
2184 | *lvalp = (unsigned long)val; | |
2185 | } | |
2186 | } | |
2187 | return 0; | |
2188 | } | |
2189 | ||
d8217f07 | 2190 | static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, |
fcfbd547 KK |
2191 | int write, struct file *filp, void __user *buffer, |
2192 | size_t *lenp, loff_t *ppos, | |
1da177e4 LT |
2193 | int (*conv)(int *negp, unsigned long *lvalp, int *valp, |
2194 | int write, void *data), | |
2195 | void *data) | |
2196 | { | |
2197 | #define TMPBUFLEN 21 | |
2198 | int *i, vleft, first=1, neg, val; | |
2199 | unsigned long lval; | |
2200 | size_t left, len; | |
2201 | ||
2202 | char buf[TMPBUFLEN], *p; | |
2203 | char __user *s = buffer; | |
2204 | ||
fcfbd547 | 2205 | if (!tbl_data || !table->maxlen || !*lenp || |
1da177e4 LT |
2206 | (*ppos && !write)) { |
2207 | *lenp = 0; | |
2208 | return 0; | |
2209 | } | |
2210 | ||
fcfbd547 | 2211 | i = (int *) tbl_data; |
1da177e4 LT |
2212 | vleft = table->maxlen / sizeof(*i); |
2213 | left = *lenp; | |
2214 | ||
2215 | if (!conv) | |
2216 | conv = do_proc_dointvec_conv; | |
2217 | ||
2218 | for (; left && vleft--; i++, first=0) { | |
2219 | if (write) { | |
2220 | while (left) { | |
2221 | char c; | |
2222 | if (get_user(c, s)) | |
2223 | return -EFAULT; | |
2224 | if (!isspace(c)) | |
2225 | break; | |
2226 | left--; | |
2227 | s++; | |
2228 | } | |
2229 | if (!left) | |
2230 | break; | |
2231 | neg = 0; | |
2232 | len = left; | |
2233 | if (len > sizeof(buf) - 1) | |
2234 | len = sizeof(buf) - 1; | |
2235 | if (copy_from_user(buf, s, len)) | |
2236 | return -EFAULT; | |
2237 | buf[len] = 0; | |
2238 | p = buf; | |
2239 | if (*p == '-' && left > 1) { | |
2240 | neg = 1; | |
bd9b0bac | 2241 | p++; |
1da177e4 LT |
2242 | } |
2243 | if (*p < '0' || *p > '9') | |
2244 | break; | |
2245 | ||
2246 | lval = simple_strtoul(p, &p, 0); | |
2247 | ||
2248 | len = p-buf; | |
2249 | if ((len < left) && *p && !isspace(*p)) | |
2250 | break; | |
2251 | if (neg) | |
2252 | val = -val; | |
2253 | s += len; | |
2254 | left -= len; | |
2255 | ||
2256 | if (conv(&neg, &lval, i, 1, data)) | |
2257 | break; | |
2258 | } else { | |
2259 | p = buf; | |
2260 | if (!first) | |
2261 | *p++ = '\t'; | |
2262 | ||
2263 | if (conv(&neg, &lval, i, 0, data)) | |
2264 | break; | |
2265 | ||
2266 | sprintf(p, "%s%lu", neg ? "-" : "", lval); | |
2267 | len = strlen(buf); | |
2268 | if (len > left) | |
2269 | len = left; | |
2270 | if(copy_to_user(s, buf, len)) | |
2271 | return -EFAULT; | |
2272 | left -= len; | |
2273 | s += len; | |
2274 | } | |
2275 | } | |
2276 | ||
2277 | if (!write && !first && left) { | |
2278 | if(put_user('\n', s)) | |
2279 | return -EFAULT; | |
2280 | left--, s++; | |
2281 | } | |
2282 | if (write) { | |
2283 | while (left) { | |
2284 | char c; | |
2285 | if (get_user(c, s++)) | |
2286 | return -EFAULT; | |
2287 | if (!isspace(c)) | |
2288 | break; | |
2289 | left--; | |
2290 | } | |
2291 | } | |
2292 | if (write && first) | |
2293 | return -EINVAL; | |
2294 | *lenp -= left; | |
2295 | *ppos += *lenp; | |
2296 | return 0; | |
2297 | #undef TMPBUFLEN | |
2298 | } | |
2299 | ||
d8217f07 | 2300 | static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp, |
fcfbd547 KK |
2301 | void __user *buffer, size_t *lenp, loff_t *ppos, |
2302 | int (*conv)(int *negp, unsigned long *lvalp, int *valp, | |
2303 | int write, void *data), | |
2304 | void *data) | |
2305 | { | |
2306 | return __do_proc_dointvec(table->data, table, write, filp, | |
2307 | buffer, lenp, ppos, conv, data); | |
2308 | } | |
2309 | ||
1da177e4 LT |
2310 | /** |
2311 | * proc_dointvec - read a vector of integers | |
2312 | * @table: the sysctl table | |
2313 | * @write: %TRUE if this is a write to the sysctl file | |
2314 | * @filp: the file structure | |
2315 | * @buffer: the user buffer | |
2316 | * @lenp: the size of the user buffer | |
2317 | * @ppos: file position | |
2318 | * | |
2319 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
2320 | * values from/to the user buffer, treated as an ASCII string. | |
2321 | * | |
2322 | * Returns 0 on success. | |
2323 | */ | |
d8217f07 | 2324 | int proc_dointvec(struct ctl_table *table, int write, struct file *filp, |
1da177e4 LT |
2325 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2326 | { | |
2327 | return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, | |
2328 | NULL,NULL); | |
2329 | } | |
2330 | ||
34f5a398 | 2331 | /* |
25ddbb18 AK |
2332 | * Taint values can only be increased |
2333 | * This means we can safely use a temporary. | |
34f5a398 | 2334 | */ |
25ddbb18 | 2335 | static int proc_taint(struct ctl_table *table, int write, struct file *filp, |
34f5a398 TT |
2336 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2337 | { | |
25ddbb18 AK |
2338 | struct ctl_table t; |
2339 | unsigned long tmptaint = get_taint(); | |
2340 | int err; | |
34f5a398 | 2341 | |
91fcd412 | 2342 | if (write && !capable(CAP_SYS_ADMIN)) |
34f5a398 TT |
2343 | return -EPERM; |
2344 | ||
25ddbb18 AK |
2345 | t = *table; |
2346 | t.data = &tmptaint; | |
2347 | err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos); | |
2348 | if (err < 0) | |
2349 | return err; | |
2350 | ||
2351 | if (write) { | |
2352 | /* | |
2353 | * Poor man's atomic or. Not worth adding a primitive | |
2354 | * to everyone's atomic.h for this | |
2355 | */ | |
2356 | int i; | |
2357 | for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) { | |
2358 | if ((tmptaint >> i) & 1) | |
2359 | add_taint(i); | |
2360 | } | |
2361 | } | |
2362 | ||
2363 | return err; | |
34f5a398 TT |
2364 | } |
2365 | ||
1da177e4 LT |
2366 | struct do_proc_dointvec_minmax_conv_param { |
2367 | int *min; | |
2368 | int *max; | |
2369 | }; | |
2370 | ||
2371 | static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, | |
2372 | int *valp, | |
2373 | int write, void *data) | |
2374 | { | |
2375 | struct do_proc_dointvec_minmax_conv_param *param = data; | |
2376 | if (write) { | |
2377 | int val = *negp ? -*lvalp : *lvalp; | |
2378 | if ((param->min && *param->min > val) || | |
2379 | (param->max && *param->max < val)) | |
2380 | return -EINVAL; | |
2381 | *valp = val; | |
2382 | } else { | |
2383 | int val = *valp; | |
2384 | if (val < 0) { | |
2385 | *negp = -1; | |
2386 | *lvalp = (unsigned long)-val; | |
2387 | } else { | |
2388 | *negp = 0; | |
2389 | *lvalp = (unsigned long)val; | |
2390 | } | |
2391 | } | |
2392 | return 0; | |
2393 | } | |
2394 | ||
2395 | /** | |
2396 | * proc_dointvec_minmax - read a vector of integers with min/max values | |
2397 | * @table: the sysctl table | |
2398 | * @write: %TRUE if this is a write to the sysctl file | |
2399 | * @filp: the file structure | |
2400 | * @buffer: the user buffer | |
2401 | * @lenp: the size of the user buffer | |
2402 | * @ppos: file position | |
2403 | * | |
2404 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
2405 | * values from/to the user buffer, treated as an ASCII string. | |
2406 | * | |
2407 | * This routine will ensure the values are within the range specified by | |
2408 | * table->extra1 (min) and table->extra2 (max). | |
2409 | * | |
2410 | * Returns 0 on success. | |
2411 | */ | |
d8217f07 | 2412 | int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp, |
1da177e4 LT |
2413 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2414 | { | |
2415 | struct do_proc_dointvec_minmax_conv_param param = { | |
2416 | .min = (int *) table->extra1, | |
2417 | .max = (int *) table->extra2, | |
2418 | }; | |
2419 | return do_proc_dointvec(table, write, filp, buffer, lenp, ppos, | |
2420 | do_proc_dointvec_minmax_conv, ¶m); | |
2421 | } | |
2422 | ||
d8217f07 | 2423 | static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write, |
1da177e4 LT |
2424 | struct file *filp, |
2425 | void __user *buffer, | |
2426 | size_t *lenp, loff_t *ppos, | |
2427 | unsigned long convmul, | |
2428 | unsigned long convdiv) | |
2429 | { | |
2430 | #define TMPBUFLEN 21 | |
2431 | unsigned long *i, *min, *max, val; | |
2432 | int vleft, first=1, neg; | |
2433 | size_t len, left; | |
2434 | char buf[TMPBUFLEN], *p; | |
2435 | char __user *s = buffer; | |
2436 | ||
fcfbd547 | 2437 | if (!data || !table->maxlen || !*lenp || |
1da177e4 LT |
2438 | (*ppos && !write)) { |
2439 | *lenp = 0; | |
2440 | return 0; | |
2441 | } | |
2442 | ||
fcfbd547 | 2443 | i = (unsigned long *) data; |
1da177e4 LT |
2444 | min = (unsigned long *) table->extra1; |
2445 | max = (unsigned long *) table->extra2; | |
2446 | vleft = table->maxlen / sizeof(unsigned long); | |
2447 | left = *lenp; | |
2448 | ||
2449 | for (; left && vleft--; i++, min++, max++, first=0) { | |
2450 | if (write) { | |
2451 | while (left) { | |
2452 | char c; | |
2453 | if (get_user(c, s)) | |
2454 | return -EFAULT; | |
2455 | if (!isspace(c)) | |
2456 | break; | |
2457 | left--; | |
2458 | s++; | |
2459 | } | |
2460 | if (!left) | |
2461 | break; | |
2462 | neg = 0; | |
2463 | len = left; | |
2464 | if (len > TMPBUFLEN-1) | |
2465 | len = TMPBUFLEN-1; | |
2466 | if (copy_from_user(buf, s, len)) | |
2467 | return -EFAULT; | |
2468 | buf[len] = 0; | |
2469 | p = buf; | |
2470 | if (*p == '-' && left > 1) { | |
2471 | neg = 1; | |
bd9b0bac | 2472 | p++; |
1da177e4 LT |
2473 | } |
2474 | if (*p < '0' || *p > '9') | |
2475 | break; | |
2476 | val = simple_strtoul(p, &p, 0) * convmul / convdiv ; | |
2477 | len = p-buf; | |
2478 | if ((len < left) && *p && !isspace(*p)) | |
2479 | break; | |
2480 | if (neg) | |
2481 | val = -val; | |
2482 | s += len; | |
2483 | left -= len; | |
2484 | ||
2485 | if(neg) | |
2486 | continue; | |
2487 | if ((min && val < *min) || (max && val > *max)) | |
2488 | continue; | |
2489 | *i = val; | |
2490 | } else { | |
2491 | p = buf; | |
2492 | if (!first) | |
2493 | *p++ = '\t'; | |
2494 | sprintf(p, "%lu", convdiv * (*i) / convmul); | |
2495 | len = strlen(buf); | |
2496 | if (len > left) | |
2497 | len = left; | |
2498 | if(copy_to_user(s, buf, len)) | |
2499 | return -EFAULT; | |
2500 | left -= len; | |
2501 | s += len; | |
2502 | } | |
2503 | } | |
2504 | ||
2505 | if (!write && !first && left) { | |
2506 | if(put_user('\n', s)) | |
2507 | return -EFAULT; | |
2508 | left--, s++; | |
2509 | } | |
2510 | if (write) { | |
2511 | while (left) { | |
2512 | char c; | |
2513 | if (get_user(c, s++)) | |
2514 | return -EFAULT; | |
2515 | if (!isspace(c)) | |
2516 | break; | |
2517 | left--; | |
2518 | } | |
2519 | } | |
2520 | if (write && first) | |
2521 | return -EINVAL; | |
2522 | *lenp -= left; | |
2523 | *ppos += *lenp; | |
2524 | return 0; | |
2525 | #undef TMPBUFLEN | |
2526 | } | |
2527 | ||
d8217f07 | 2528 | static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, |
fcfbd547 KK |
2529 | struct file *filp, |
2530 | void __user *buffer, | |
2531 | size_t *lenp, loff_t *ppos, | |
2532 | unsigned long convmul, | |
2533 | unsigned long convdiv) | |
2534 | { | |
2535 | return __do_proc_doulongvec_minmax(table->data, table, write, | |
2536 | filp, buffer, lenp, ppos, convmul, convdiv); | |
2537 | } | |
2538 | ||
1da177e4 LT |
2539 | /** |
2540 | * proc_doulongvec_minmax - read a vector of long integers with min/max values | |
2541 | * @table: the sysctl table | |
2542 | * @write: %TRUE if this is a write to the sysctl file | |
2543 | * @filp: the file structure | |
2544 | * @buffer: the user buffer | |
2545 | * @lenp: the size of the user buffer | |
2546 | * @ppos: file position | |
2547 | * | |
2548 | * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long | |
2549 | * values from/to the user buffer, treated as an ASCII string. | |
2550 | * | |
2551 | * This routine will ensure the values are within the range specified by | |
2552 | * table->extra1 (min) and table->extra2 (max). | |
2553 | * | |
2554 | * Returns 0 on success. | |
2555 | */ | |
d8217f07 | 2556 | int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp, |
1da177e4 LT |
2557 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2558 | { | |
2559 | return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l); | |
2560 | } | |
2561 | ||
2562 | /** | |
2563 | * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values | |
2564 | * @table: the sysctl table | |
2565 | * @write: %TRUE if this is a write to the sysctl file | |
2566 | * @filp: the file structure | |
2567 | * @buffer: the user buffer | |
2568 | * @lenp: the size of the user buffer | |
2569 | * @ppos: file position | |
2570 | * | |
2571 | * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long | |
2572 | * values from/to the user buffer, treated as an ASCII string. The values | |
2573 | * are treated as milliseconds, and converted to jiffies when they are stored. | |
2574 | * | |
2575 | * This routine will ensure the values are within the range specified by | |
2576 | * table->extra1 (min) and table->extra2 (max). | |
2577 | * | |
2578 | * Returns 0 on success. | |
2579 | */ | |
d8217f07 | 2580 | int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, |
1da177e4 LT |
2581 | struct file *filp, |
2582 | void __user *buffer, | |
2583 | size_t *lenp, loff_t *ppos) | |
2584 | { | |
2585 | return do_proc_doulongvec_minmax(table, write, filp, buffer, | |
2586 | lenp, ppos, HZ, 1000l); | |
2587 | } | |
2588 | ||
2589 | ||
2590 | static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp, | |
2591 | int *valp, | |
2592 | int write, void *data) | |
2593 | { | |
2594 | if (write) { | |
cba9f33d BS |
2595 | if (*lvalp > LONG_MAX / HZ) |
2596 | return 1; | |
1da177e4 LT |
2597 | *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ); |
2598 | } else { | |
2599 | int val = *valp; | |
2600 | unsigned long lval; | |
2601 | if (val < 0) { | |
2602 | *negp = -1; | |
2603 | lval = (unsigned long)-val; | |
2604 | } else { | |
2605 | *negp = 0; | |
2606 | lval = (unsigned long)val; | |
2607 | } | |
2608 | *lvalp = lval / HZ; | |
2609 | } | |
2610 | return 0; | |
2611 | } | |
2612 | ||
2613 | static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp, | |
2614 | int *valp, | |
2615 | int write, void *data) | |
2616 | { | |
2617 | if (write) { | |
cba9f33d BS |
2618 | if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) |
2619 | return 1; | |
1da177e4 LT |
2620 | *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); |
2621 | } else { | |
2622 | int val = *valp; | |
2623 | unsigned long lval; | |
2624 | if (val < 0) { | |
2625 | *negp = -1; | |
2626 | lval = (unsigned long)-val; | |
2627 | } else { | |
2628 | *negp = 0; | |
2629 | lval = (unsigned long)val; | |
2630 | } | |
2631 | *lvalp = jiffies_to_clock_t(lval); | |
2632 | } | |
2633 | return 0; | |
2634 | } | |
2635 | ||
2636 | static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp, | |
2637 | int *valp, | |
2638 | int write, void *data) | |
2639 | { | |
2640 | if (write) { | |
2641 | *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); | |
2642 | } else { | |
2643 | int val = *valp; | |
2644 | unsigned long lval; | |
2645 | if (val < 0) { | |
2646 | *negp = -1; | |
2647 | lval = (unsigned long)-val; | |
2648 | } else { | |
2649 | *negp = 0; | |
2650 | lval = (unsigned long)val; | |
2651 | } | |
2652 | *lvalp = jiffies_to_msecs(lval); | |
2653 | } | |
2654 | return 0; | |
2655 | } | |
2656 | ||
2657 | /** | |
2658 | * proc_dointvec_jiffies - read a vector of integers as seconds | |
2659 | * @table: the sysctl table | |
2660 | * @write: %TRUE if this is a write to the sysctl file | |
2661 | * @filp: the file structure | |
2662 | * @buffer: the user buffer | |
2663 | * @lenp: the size of the user buffer | |
2664 | * @ppos: file position | |
2665 | * | |
2666 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
2667 | * values from/to the user buffer, treated as an ASCII string. | |
2668 | * The values read are assumed to be in seconds, and are converted into | |
2669 | * jiffies. | |
2670 | * | |
2671 | * Returns 0 on success. | |
2672 | */ | |
d8217f07 | 2673 | int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp, |
1da177e4 LT |
2674 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2675 | { | |
2676 | return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, | |
2677 | do_proc_dointvec_jiffies_conv,NULL); | |
2678 | } | |
2679 | ||
2680 | /** | |
2681 | * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds | |
2682 | * @table: the sysctl table | |
2683 | * @write: %TRUE if this is a write to the sysctl file | |
2684 | * @filp: the file structure | |
2685 | * @buffer: the user buffer | |
2686 | * @lenp: the size of the user buffer | |
1e5d5331 | 2687 | * @ppos: pointer to the file position |
1da177e4 LT |
2688 | * |
2689 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
2690 | * values from/to the user buffer, treated as an ASCII string. | |
2691 | * The values read are assumed to be in 1/USER_HZ seconds, and | |
2692 | * are converted into jiffies. | |
2693 | * | |
2694 | * Returns 0 on success. | |
2695 | */ | |
d8217f07 | 2696 | int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp, |
1da177e4 LT |
2697 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2698 | { | |
2699 | return do_proc_dointvec(table,write,filp,buffer,lenp,ppos, | |
2700 | do_proc_dointvec_userhz_jiffies_conv,NULL); | |
2701 | } | |
2702 | ||
2703 | /** | |
2704 | * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds | |
2705 | * @table: the sysctl table | |
2706 | * @write: %TRUE if this is a write to the sysctl file | |
2707 | * @filp: the file structure | |
2708 | * @buffer: the user buffer | |
2709 | * @lenp: the size of the user buffer | |
67be2dd1 MW |
2710 | * @ppos: file position |
2711 | * @ppos: the current position in the file | |
1da177e4 LT |
2712 | * |
2713 | * Reads/writes up to table->maxlen/sizeof(unsigned int) integer | |
2714 | * values from/to the user buffer, treated as an ASCII string. | |
2715 | * The values read are assumed to be in 1/1000 seconds, and | |
2716 | * are converted into jiffies. | |
2717 | * | |
2718 | * Returns 0 on success. | |
2719 | */ | |
d8217f07 | 2720 | int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp, |
1da177e4 LT |
2721 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2722 | { | |
2723 | return do_proc_dointvec(table, write, filp, buffer, lenp, ppos, | |
2724 | do_proc_dointvec_ms_jiffies_conv, NULL); | |
2725 | } | |
2726 | ||
d8217f07 | 2727 | static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp, |
9ec52099 CLG |
2728 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2729 | { | |
2730 | struct pid *new_pid; | |
2731 | pid_t tmp; | |
2732 | int r; | |
2733 | ||
6c5f3e7b | 2734 | tmp = pid_vnr(cad_pid); |
9ec52099 CLG |
2735 | |
2736 | r = __do_proc_dointvec(&tmp, table, write, filp, buffer, | |
2737 | lenp, ppos, NULL, NULL); | |
2738 | if (r || !write) | |
2739 | return r; | |
2740 | ||
2741 | new_pid = find_get_pid(tmp); | |
2742 | if (!new_pid) | |
2743 | return -ESRCH; | |
2744 | ||
2745 | put_pid(xchg(&cad_pid, new_pid)); | |
2746 | return 0; | |
2747 | } | |
2748 | ||
1da177e4 LT |
2749 | #else /* CONFIG_PROC_FS */ |
2750 | ||
d8217f07 | 2751 | int proc_dostring(struct ctl_table *table, int write, struct file *filp, |
1da177e4 LT |
2752 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2753 | { | |
2754 | return -ENOSYS; | |
2755 | } | |
2756 | ||
d8217f07 | 2757 | int proc_dointvec(struct ctl_table *table, int write, struct file *filp, |
1da177e4 | 2758 | void __user *buffer, size_t *lenp, loff_t *ppos) |
1da177e4 LT |
2759 | { |
2760 | return -ENOSYS; | |
2761 | } | |
2762 | ||
d8217f07 | 2763 | int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp, |
1da177e4 LT |
2764 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2765 | { | |
2766 | return -ENOSYS; | |
2767 | } | |
2768 | ||
d8217f07 | 2769 | int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp, |
1da177e4 LT |
2770 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2771 | { | |
2772 | return -ENOSYS; | |
2773 | } | |
2774 | ||
d8217f07 | 2775 | int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp, |
1da177e4 LT |
2776 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2777 | { | |
2778 | return -ENOSYS; | |
2779 | } | |
2780 | ||
d8217f07 | 2781 | int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp, |
1da177e4 LT |
2782 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2783 | { | |
2784 | return -ENOSYS; | |
2785 | } | |
2786 | ||
d8217f07 | 2787 | int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp, |
1da177e4 LT |
2788 | void __user *buffer, size_t *lenp, loff_t *ppos) |
2789 | { | |
2790 | return -ENOSYS; | |
2791 | } | |
2792 | ||
d8217f07 | 2793 | int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, |
1da177e4 LT |
2794 | struct file *filp, |
2795 | void __user *buffer, | |
2796 | size_t *lenp, loff_t *ppos) | |
2797 | { | |
2798 | return -ENOSYS; | |
2799 | } | |
2800 | ||
2801 | ||
2802 | #endif /* CONFIG_PROC_FS */ | |
2803 | ||
2804 | ||
b89a8171 | 2805 | #ifdef CONFIG_SYSCTL_SYSCALL |
1da177e4 LT |
2806 | /* |
2807 | * General sysctl support routines | |
2808 | */ | |
2809 | ||
49a0c458 | 2810 | /* The generic sysctl data routine (used if no strategy routine supplied) */ |
f221e726 | 2811 | int sysctl_data(struct ctl_table *table, |
49a0c458 EB |
2812 | void __user *oldval, size_t __user *oldlenp, |
2813 | void __user *newval, size_t newlen) | |
2814 | { | |
2815 | size_t len; | |
2816 | ||
2817 | /* Get out of I don't have a variable */ | |
2818 | if (!table->data || !table->maxlen) | |
2819 | return -ENOTDIR; | |
2820 | ||
2821 | if (oldval && oldlenp) { | |
2822 | if (get_user(len, oldlenp)) | |
2823 | return -EFAULT; | |
2824 | if (len) { | |
2825 | if (len > table->maxlen) | |
2826 | len = table->maxlen; | |
2827 | if (copy_to_user(oldval, table->data, len)) | |
2828 | return -EFAULT; | |
2829 | if (put_user(len, oldlenp)) | |
2830 | return -EFAULT; | |
2831 | } | |
2832 | } | |
2833 | ||
2834 | if (newval && newlen) { | |
2835 | if (newlen > table->maxlen) | |
2836 | newlen = table->maxlen; | |
2837 | ||
2838 | if (copy_from_user(table->data, newval, newlen)) | |
2839 | return -EFAULT; | |
2840 | } | |
2841 | return 1; | |
2842 | } | |
2843 | ||
1da177e4 | 2844 | /* The generic string strategy routine: */ |
f221e726 | 2845 | int sysctl_string(struct ctl_table *table, |
1da177e4 | 2846 | void __user *oldval, size_t __user *oldlenp, |
1f29bcd7 | 2847 | void __user *newval, size_t newlen) |
1da177e4 | 2848 | { |
1da177e4 LT |
2849 | if (!table->data || !table->maxlen) |
2850 | return -ENOTDIR; | |
2851 | ||
2852 | if (oldval && oldlenp) { | |
de9e007d LT |
2853 | size_t bufsize; |
2854 | if (get_user(bufsize, oldlenp)) | |
1da177e4 | 2855 | return -EFAULT; |
de9e007d LT |
2856 | if (bufsize) { |
2857 | size_t len = strlen(table->data), copied; | |
2858 | ||
2859 | /* This shouldn't trigger for a well-formed sysctl */ | |
2860 | if (len > table->maxlen) | |
1da177e4 | 2861 | len = table->maxlen; |
de9e007d LT |
2862 | |
2863 | /* Copy up to a max of bufsize-1 bytes of the string */ | |
2864 | copied = (len >= bufsize) ? bufsize - 1 : len; | |
2865 | ||
2866 | if (copy_to_user(oldval, table->data, copied) || | |
2867 | put_user(0, (char __user *)(oldval + copied))) | |
1da177e4 | 2868 | return -EFAULT; |
de9e007d | 2869 | if (put_user(len, oldlenp)) |
1da177e4 LT |
2870 | return -EFAULT; |
2871 | } | |
2872 | } | |
2873 | if (newval && newlen) { | |
de9e007d | 2874 | size_t len = newlen; |
1da177e4 LT |
2875 | if (len > table->maxlen) |
2876 | len = table->maxlen; | |
2877 | if(copy_from_user(table->data, newval, len)) | |
2878 | return -EFAULT; | |
2879 | if (len == table->maxlen) | |
2880 | len--; | |
2881 | ((char *) table->data)[len] = 0; | |
2882 | } | |
82c9df82 | 2883 | return 1; |
1da177e4 LT |
2884 | } |
2885 | ||
2886 | /* | |
2887 | * This function makes sure that all of the integers in the vector | |
2888 | * are between the minimum and maximum values given in the arrays | |
2889 | * table->extra1 and table->extra2, respectively. | |
2890 | */ | |
f221e726 | 2891 | int sysctl_intvec(struct ctl_table *table, |
1da177e4 | 2892 | void __user *oldval, size_t __user *oldlenp, |
1f29bcd7 | 2893 | void __user *newval, size_t newlen) |
1da177e4 LT |
2894 | { |
2895 | ||
2896 | if (newval && newlen) { | |
2897 | int __user *vec = (int __user *) newval; | |
2898 | int *min = (int *) table->extra1; | |
2899 | int *max = (int *) table->extra2; | |
2900 | size_t length; | |
2901 | int i; | |
2902 | ||
2903 | if (newlen % sizeof(int) != 0) | |
2904 | return -EINVAL; | |
2905 | ||
2906 | if (!table->extra1 && !table->extra2) | |
2907 | return 0; | |
2908 | ||
2909 | if (newlen > table->maxlen) | |
2910 | newlen = table->maxlen; | |
2911 | length = newlen / sizeof(int); | |
2912 | ||
2913 | for (i = 0; i < length; i++) { | |
2914 | int value; | |
2915 | if (get_user(value, vec + i)) | |
2916 | return -EFAULT; | |
2917 | if (min && value < min[i]) | |
2918 | return -EINVAL; | |
2919 | if (max && value > max[i]) | |
2920 | return -EINVAL; | |
2921 | } | |
2922 | } | |
2923 | return 0; | |
2924 | } | |
2925 | ||
2926 | /* Strategy function to convert jiffies to seconds */ | |
f221e726 | 2927 | int sysctl_jiffies(struct ctl_table *table, |
1da177e4 | 2928 | void __user *oldval, size_t __user *oldlenp, |
1f29bcd7 | 2929 | void __user *newval, size_t newlen) |
1da177e4 | 2930 | { |
3ee75ac3 | 2931 | if (oldval && oldlenp) { |
1da177e4 | 2932 | size_t olen; |
3ee75ac3 AD |
2933 | |
2934 | if (get_user(olen, oldlenp)) | |
2935 | return -EFAULT; | |
2936 | if (olen) { | |
2937 | int val; | |
2938 | ||
2939 | if (olen < sizeof(int)) | |
2940 | return -EINVAL; | |
2941 | ||
2942 | val = *(int *)(table->data) / HZ; | |
2943 | if (put_user(val, (int __user *)oldval)) | |
2944 | return -EFAULT; | |
2945 | if (put_user(sizeof(int), oldlenp)) | |
1da177e4 | 2946 | return -EFAULT; |
1da177e4 | 2947 | } |
1da177e4 LT |
2948 | } |
2949 | if (newval && newlen) { | |
2950 | int new; | |
2951 | if (newlen != sizeof(int)) | |
2952 | return -EINVAL; | |
2953 | if (get_user(new, (int __user *)newval)) | |
2954 | return -EFAULT; | |
2955 | *(int *)(table->data) = new*HZ; | |
2956 | } | |
2957 | return 1; | |
2958 | } | |
2959 | ||
2960 | /* Strategy function to convert jiffies to seconds */ | |
f221e726 | 2961 | int sysctl_ms_jiffies(struct ctl_table *table, |
1da177e4 | 2962 | void __user *oldval, size_t __user *oldlenp, |
1f29bcd7 | 2963 | void __user *newval, size_t newlen) |
1da177e4 | 2964 | { |
3ee75ac3 | 2965 | if (oldval && oldlenp) { |
1da177e4 | 2966 | size_t olen; |
3ee75ac3 AD |
2967 | |
2968 | if (get_user(olen, oldlenp)) | |
2969 | return -EFAULT; | |
2970 | if (olen) { | |
2971 | int val; | |
2972 | ||
2973 | if (olen < sizeof(int)) | |
2974 | return -EINVAL; | |
2975 | ||
2976 | val = jiffies_to_msecs(*(int *)(table->data)); | |
2977 | if (put_user(val, (int __user *)oldval)) | |
2978 | return -EFAULT; | |
2979 | if (put_user(sizeof(int), oldlenp)) | |
1da177e4 | 2980 | return -EFAULT; |
1da177e4 | 2981 | } |
1da177e4 LT |
2982 | } |
2983 | if (newval && newlen) { | |
2984 | int new; | |
2985 | if (newlen != sizeof(int)) | |
2986 | return -EINVAL; | |
2987 | if (get_user(new, (int __user *)newval)) | |
2988 | return -EFAULT; | |
2989 | *(int *)(table->data) = msecs_to_jiffies(new); | |
2990 | } | |
2991 | return 1; | |
2992 | } | |
2993 | ||
c4b8b769 | 2994 | |
c4b8b769 | 2995 | |
b89a8171 | 2996 | #else /* CONFIG_SYSCTL_SYSCALL */ |
1da177e4 LT |
2997 | |
2998 | ||
1e7bfb21 | 2999 | SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args) |
1da177e4 | 3000 | { |
0e009be8 | 3001 | struct __sysctl_args tmp; |
7058cb02 | 3002 | int error; |
0e009be8 | 3003 | |
0e009be8 EB |
3004 | if (copy_from_user(&tmp, args, sizeof(tmp))) |
3005 | return -EFAULT; | |
0e009be8 | 3006 | |
7058cb02 | 3007 | error = deprecated_sysctl_warning(&tmp); |
b89a8171 | 3008 | |
7058cb02 EB |
3009 | /* If no error reading the parameters then just -ENOSYS ... */ |
3010 | if (!error) | |
3011 | error = -ENOSYS; | |
3012 | ||
3013 | return error; | |
1da177e4 LT |
3014 | } |
3015 | ||
f221e726 | 3016 | int sysctl_data(struct ctl_table *table, |
49a0c458 EB |
3017 | void __user *oldval, size_t __user *oldlenp, |
3018 | void __user *newval, size_t newlen) | |
3019 | { | |
3020 | return -ENOSYS; | |
3021 | } | |
3022 | ||
f221e726 | 3023 | int sysctl_string(struct ctl_table *table, |
1da177e4 | 3024 | void __user *oldval, size_t __user *oldlenp, |
1f29bcd7 | 3025 | void __user *newval, size_t newlen) |
1da177e4 LT |
3026 | { |
3027 | return -ENOSYS; | |
3028 | } | |
3029 | ||
f221e726 | 3030 | int sysctl_intvec(struct ctl_table *table, |
1da177e4 | 3031 | void __user *oldval, size_t __user *oldlenp, |
1f29bcd7 | 3032 | void __user *newval, size_t newlen) |
1da177e4 LT |
3033 | { |
3034 | return -ENOSYS; | |
3035 | } | |
3036 | ||
f221e726 | 3037 | int sysctl_jiffies(struct ctl_table *table, |
1da177e4 | 3038 | void __user *oldval, size_t __user *oldlenp, |
1f29bcd7 | 3039 | void __user *newval, size_t newlen) |
1da177e4 LT |
3040 | { |
3041 | return -ENOSYS; | |
3042 | } | |
3043 | ||
f221e726 | 3044 | int sysctl_ms_jiffies(struct ctl_table *table, |
1da177e4 | 3045 | void __user *oldval, size_t __user *oldlenp, |
1f29bcd7 | 3046 | void __user *newval, size_t newlen) |
1da177e4 LT |
3047 | { |
3048 | return -ENOSYS; | |
3049 | } | |
3050 | ||
b89a8171 | 3051 | #endif /* CONFIG_SYSCTL_SYSCALL */ |
1da177e4 | 3052 | |
7058cb02 EB |
3053 | static int deprecated_sysctl_warning(struct __sysctl_args *args) |
3054 | { | |
3055 | static int msg_count; | |
3056 | int name[CTL_MAXNAME]; | |
3057 | int i; | |
3058 | ||
6fc48af8 TH |
3059 | /* Check args->nlen. */ |
3060 | if (args->nlen < 0 || args->nlen > CTL_MAXNAME) | |
3061 | return -ENOTDIR; | |
3062 | ||
7058cb02 EB |
3063 | /* Read in the sysctl name for better debug message logging */ |
3064 | for (i = 0; i < args->nlen; i++) | |
3065 | if (get_user(name[i], args->name + i)) | |
3066 | return -EFAULT; | |
3067 | ||
3068 | /* Ignore accesses to kernel.version */ | |
3069 | if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION)) | |
3070 | return 0; | |
3071 | ||
3072 | if (msg_count < 5) { | |
3073 | msg_count++; | |
3074 | printk(KERN_INFO | |
3075 | "warning: process `%s' used the deprecated sysctl " | |
3076 | "system call with ", current->comm); | |
3077 | for (i = 0; i < args->nlen; i++) | |
3078 | printk("%d.", name[i]); | |
3079 | printk("\n"); | |
3080 | } | |
3081 | return 0; | |
3082 | } | |
3083 | ||
1da177e4 LT |
3084 | /* |
3085 | * No sense putting this after each symbol definition, twice, | |
3086 | * exception granted :-) | |
3087 | */ | |
3088 | EXPORT_SYMBOL(proc_dointvec); | |
3089 | EXPORT_SYMBOL(proc_dointvec_jiffies); | |
3090 | EXPORT_SYMBOL(proc_dointvec_minmax); | |
3091 | EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); | |
3092 | EXPORT_SYMBOL(proc_dointvec_ms_jiffies); | |
3093 | EXPORT_SYMBOL(proc_dostring); | |
3094 | EXPORT_SYMBOL(proc_doulongvec_minmax); | |
3095 | EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); | |
3096 | EXPORT_SYMBOL(register_sysctl_table); | |
29e796fd | 3097 | EXPORT_SYMBOL(register_sysctl_paths); |
1da177e4 LT |
3098 | EXPORT_SYMBOL(sysctl_intvec); |
3099 | EXPORT_SYMBOL(sysctl_jiffies); | |
3100 | EXPORT_SYMBOL(sysctl_ms_jiffies); | |
3101 | EXPORT_SYMBOL(sysctl_string); | |
49a0c458 | 3102 | EXPORT_SYMBOL(sysctl_data); |
1da177e4 | 3103 | EXPORT_SYMBOL(unregister_sysctl_table); |