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