Merge branch 'wmi-fix' into release-2.6.27
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / kernel / sysctl.c
blobfe47133472758853b039c47ac9390e5eadd34bed
1 /*
2 * sysctl.c: General linux system control interface
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
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>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
31 #include <linux/fs.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
52 #include <asm/uaccess.h>
53 #include <asm/processor.h>
55 #ifdef CONFIG_X86
56 #include <asm/nmi.h>
57 #include <asm/stacktrace.h>
58 #include <asm/io.h>
59 #endif
61 static int deprecated_sysctl_warning(struct __sysctl_args *args);
63 #if defined(CONFIG_SYSCTL)
65 /* External variables not in a header file. */
66 extern int C_A_D;
67 extern int print_fatal_signals;
68 extern int sysctl_overcommit_memory;
69 extern int sysctl_overcommit_ratio;
70 extern int sysctl_panic_on_oom;
71 extern int sysctl_oom_kill_allocating_task;
72 extern int sysctl_oom_dump_tasks;
73 extern int max_threads;
74 extern int core_uses_pid;
75 extern int suid_dumpable;
76 extern char core_pattern[];
77 extern int pid_max;
78 extern int min_free_kbytes;
79 extern int pid_max_min, pid_max_max;
80 extern int sysctl_drop_caches;
81 extern int percpu_pagelist_fraction;
82 extern int compat_log;
83 extern int maps_protect;
84 extern int latencytop_enabled;
85 extern int sysctl_nr_open_min, sysctl_nr_open_max;
86 #ifdef CONFIG_RCU_TORTURE_TEST
87 extern int rcutorture_runnable;
88 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
90 /* Constants used for minimum and maximum */
91 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
92 static int one = 1;
93 #endif
95 #ifdef CONFIG_DETECT_SOFTLOCKUP
96 static int sixty = 60;
97 static int neg_one = -1;
98 #endif
100 #ifdef CONFIG_MMU
101 static int two = 2;
102 #endif
104 static int zero;
105 static int one_hundred = 100;
107 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
108 static int maxolduid = 65535;
109 static int minolduid;
110 static int min_percpu_pagelist_fract = 8;
112 static int ngroups_max = NGROUPS_MAX;
114 #ifdef CONFIG_MODULES
115 extern char modprobe_path[];
116 #endif
117 #ifdef CONFIG_CHR_DEV_SG
118 extern int sg_big_buff;
119 #endif
121 #ifdef __sparc__
122 extern char reboot_command [];
123 extern int stop_a_enabled;
124 extern int scons_pwroff;
125 #endif
127 #ifdef __hppa__
128 extern int pwrsw_enabled;
129 extern int unaligned_enabled;
130 #endif
132 #ifdef CONFIG_S390
133 #ifdef CONFIG_MATHEMU
134 extern int sysctl_ieee_emulation_warnings;
135 #endif
136 extern int sysctl_userprocess_debug;
137 extern int spin_retry;
138 #endif
140 #ifdef CONFIG_BSD_PROCESS_ACCT
141 extern int acct_parm[];
142 #endif
144 #ifdef CONFIG_IA64
145 extern int no_unaligned_warning;
146 #endif
148 #ifdef CONFIG_RT_MUTEXES
149 extern int max_lock_depth;
150 #endif
152 #ifdef CONFIG_PROC_SYSCTL
153 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
154 void __user *buffer, size_t *lenp, loff_t *ppos);
155 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
156 void __user *buffer, size_t *lenp, loff_t *ppos);
157 #endif
159 static struct ctl_table root_table[];
160 static struct ctl_table_root sysctl_table_root;
161 static struct ctl_table_header root_table_header = {
162 .ctl_table = root_table,
163 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
164 .root = &sysctl_table_root,
165 .set = &sysctl_table_root.default_set,
167 static struct ctl_table_root sysctl_table_root = {
168 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
169 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
172 static struct ctl_table kern_table[];
173 static struct ctl_table vm_table[];
174 static struct ctl_table fs_table[];
175 static struct ctl_table debug_table[];
176 static struct ctl_table dev_table[];
177 extern struct ctl_table random_table[];
178 #ifdef CONFIG_INOTIFY_USER
179 extern struct ctl_table inotify_table[];
180 #endif
182 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
183 int sysctl_legacy_va_layout;
184 #endif
186 extern int prove_locking;
187 extern int lock_stat;
189 /* The default sysctl tables: */
191 static struct ctl_table root_table[] = {
193 .ctl_name = CTL_KERN,
194 .procname = "kernel",
195 .mode = 0555,
196 .child = kern_table,
199 .ctl_name = CTL_VM,
200 .procname = "vm",
201 .mode = 0555,
202 .child = vm_table,
205 .ctl_name = CTL_FS,
206 .procname = "fs",
207 .mode = 0555,
208 .child = fs_table,
211 .ctl_name = CTL_DEBUG,
212 .procname = "debug",
213 .mode = 0555,
214 .child = debug_table,
217 .ctl_name = CTL_DEV,
218 .procname = "dev",
219 .mode = 0555,
220 .child = dev_table,
223 * NOTE: do not add new entries to this table unless you have read
224 * Documentation/sysctl/ctl_unnumbered.txt
226 { .ctl_name = 0 }
229 #ifdef CONFIG_SCHED_DEBUG
230 static int min_sched_granularity_ns = 100000; /* 100 usecs */
231 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
232 static int min_wakeup_granularity_ns; /* 0 usecs */
233 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
234 #endif
236 static struct ctl_table kern_table[] = {
237 #ifdef CONFIG_SCHED_DEBUG
239 .ctl_name = CTL_UNNUMBERED,
240 .procname = "sched_min_granularity_ns",
241 .data = &sysctl_sched_min_granularity,
242 .maxlen = sizeof(unsigned int),
243 .mode = 0644,
244 .proc_handler = &sched_nr_latency_handler,
245 .strategy = &sysctl_intvec,
246 .extra1 = &min_sched_granularity_ns,
247 .extra2 = &max_sched_granularity_ns,
250 .ctl_name = CTL_UNNUMBERED,
251 .procname = "sched_latency_ns",
252 .data = &sysctl_sched_latency,
253 .maxlen = sizeof(unsigned int),
254 .mode = 0644,
255 .proc_handler = &sched_nr_latency_handler,
256 .strategy = &sysctl_intvec,
257 .extra1 = &min_sched_granularity_ns,
258 .extra2 = &max_sched_granularity_ns,
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,
268 .extra1 = &min_wakeup_granularity_ns,
269 .extra2 = &max_wakeup_granularity_ns,
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,
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,
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,
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,
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "sched_nr_migrate",
306 .data = &sysctl_sched_nr_migrate,
307 .maxlen = sizeof(unsigned int),
308 .mode = 0644,
309 .proc_handler = &proc_dointvec,
311 #endif
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,
318 .proc_handler = &sched_rt_handler,
321 .ctl_name = CTL_UNNUMBERED,
322 .procname = "sched_rt_runtime_us",
323 .data = &sysctl_sched_rt_runtime,
324 .maxlen = sizeof(int),
325 .mode = 0644,
326 .proc_handler = &sched_rt_handler,
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,
336 #ifdef CONFIG_PROVE_LOCKING
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,
345 #endif
346 #ifdef CONFIG_LOCK_STAT
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,
355 #endif
357 .ctl_name = KERN_PANIC,
358 .procname = "panic",
359 .data = &panic_timeout,
360 .maxlen = sizeof(int),
361 .mode = 0644,
362 .proc_handler = &proc_dointvec,
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,
373 .ctl_name = KERN_CORE_PATTERN,
374 .procname = "core_pattern",
375 .data = core_pattern,
376 .maxlen = CORENAME_MAX_SIZE,
377 .mode = 0644,
378 .proc_handler = &proc_dostring,
379 .strategy = &sysctl_string,
381 #ifdef CONFIG_PROC_SYSCTL
383 .procname = "tainted",
384 .data = &tainted,
385 .maxlen = sizeof(int),
386 .mode = 0644,
387 .proc_handler = &proc_dointvec_taint,
389 #endif
390 #ifdef CONFIG_LATENCYTOP
392 .procname = "latencytop",
393 .data = &latencytop_enabled,
394 .maxlen = sizeof(int),
395 .mode = 0644,
396 .proc_handler = &proc_dointvec,
398 #endif
399 #ifdef CONFIG_BLK_DEV_INITRD
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,
408 #endif
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,
417 #ifdef __sparc__
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,
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,
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,
443 #endif
444 #ifdef __hppa__
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,
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,
461 #endif
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,
470 #ifdef CONFIG_FTRACE
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,
479 #endif
480 #ifdef CONFIG_MODULES
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,
490 #endif
491 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
493 .ctl_name = KERN_HOTPLUG,
494 .procname = "hotplug",
495 .data = &uevent_helper,
496 .maxlen = UEVENT_HELPER_PATH_LEN,
497 .mode = 0644,
498 .proc_handler = &proc_dostring,
499 .strategy = &sysctl_string,
501 #endif
502 #ifdef CONFIG_CHR_DEV_SG
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,
511 #endif
512 #ifdef CONFIG_BSD_PROCESS_ACCT
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,
521 #endif
522 #ifdef CONFIG_MAGIC_SYSRQ
524 .ctl_name = KERN_SYSRQ,
525 .procname = "sysrq",
526 .data = &__sysrq_enabled,
527 .maxlen = sizeof (int),
528 .mode = 0644,
529 .proc_handler = &proc_dointvec,
531 #endif
532 #ifdef CONFIG_PROC_SYSCTL
534 .procname = "cad_pid",
535 .data = NULL,
536 .maxlen = sizeof (int),
537 .mode = 0600,
538 .proc_handler = &proc_do_cad_pid,
540 #endif
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,
550 .ctl_name = KERN_RANDOM,
551 .procname = "random",
552 .mode = 0555,
553 .child = random_table,
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,
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,
577 #ifdef CONFIG_S390
578 #ifdef CONFIG_MATHEMU
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,
587 #endif
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,
596 #endif
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,
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,
616 #if defined CONFIG_PRINTK
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,
626 .ctl_name = KERN_PRINTK_RATELIMIT,
627 .procname = "printk_ratelimit",
628 .data = &printk_ratelimit_state.interval,
629 .maxlen = sizeof(int),
630 .mode = 0644,
631 .proc_handler = &proc_dointvec_jiffies,
632 .strategy = &sysctl_jiffies,
635 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
636 .procname = "printk_ratelimit_burst",
637 .data = &printk_ratelimit_state.burst,
638 .maxlen = sizeof(int),
639 .mode = 0644,
640 .proc_handler = &proc_dointvec,
642 #endif
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,
651 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
653 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
654 .procname = "unknown_nmi_panic",
655 .data = &unknown_nmi_panic,
656 .maxlen = sizeof (int),
657 .mode = 0644,
658 .proc_handler = &proc_dointvec,
661 .procname = "nmi_watchdog",
662 .data = &nmi_watchdog_enabled,
663 .maxlen = sizeof (int),
664 .mode = 0644,
665 .proc_handler = &proc_nmi_enabled,
667 #endif
668 #if defined(CONFIG_X86)
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,
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,
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,
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,
701 #endif
702 #if defined(CONFIG_MMU)
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,
711 #endif
712 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
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,
721 #endif
722 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
724 .procname = "acpi_video_flags",
725 .data = &acpi_realmode_flags,
726 .maxlen = sizeof (unsigned long),
727 .mode = 0644,
728 .proc_handler = &proc_doulongvec_minmax,
730 #endif
731 #ifdef CONFIG_IA64
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,
740 #endif
741 #ifdef CONFIG_DETECT_SOFTLOCKUP
743 .ctl_name = CTL_UNNUMBERED,
744 .procname = "softlockup_panic",
745 .data = &softlockup_panic,
746 .maxlen = sizeof(int),
747 .mode = 0644,
748 .proc_handler = &proc_dointvec_minmax,
749 .strategy = &sysctl_intvec,
750 .extra1 = &zero,
751 .extra2 = &one,
754 .ctl_name = CTL_UNNUMBERED,
755 .procname = "softlockup_thresh",
756 .data = &softlockup_thresh,
757 .maxlen = sizeof(int),
758 .mode = 0644,
759 .proc_handler = &proc_dointvec_minmax,
760 .strategy = &sysctl_intvec,
761 .extra1 = &neg_one,
762 .extra2 = &sixty,
765 .ctl_name = CTL_UNNUMBERED,
766 .procname = "hung_task_check_count",
767 .data = &sysctl_hung_task_check_count,
768 .maxlen = sizeof(unsigned long),
769 .mode = 0644,
770 .proc_handler = &proc_doulongvec_minmax,
771 .strategy = &sysctl_intvec,
774 .ctl_name = CTL_UNNUMBERED,
775 .procname = "hung_task_timeout_secs",
776 .data = &sysctl_hung_task_timeout_secs,
777 .maxlen = sizeof(unsigned long),
778 .mode = 0644,
779 .proc_handler = &proc_doulongvec_minmax,
780 .strategy = &sysctl_intvec,
783 .ctl_name = CTL_UNNUMBERED,
784 .procname = "hung_task_warnings",
785 .data = &sysctl_hung_task_warnings,
786 .maxlen = sizeof(unsigned long),
787 .mode = 0644,
788 .proc_handler = &proc_doulongvec_minmax,
789 .strategy = &sysctl_intvec,
791 #endif
792 #ifdef CONFIG_COMPAT
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,
801 #endif
802 #ifdef CONFIG_RT_MUTEXES
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,
811 #endif
812 #ifdef CONFIG_PROC_FS
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,
821 #endif
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,
831 #ifdef CONFIG_KEYS
833 .ctl_name = CTL_UNNUMBERED,
834 .procname = "keys",
835 .mode = 0555,
836 .child = key_sysctls,
838 #endif
839 #ifdef CONFIG_RCU_TORTURE_TEST
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,
848 #endif
850 * NOTE: do not add new entries to this table unless you have read
851 * Documentation/sysctl/ctl_unnumbered.txt
853 { .ctl_name = 0 }
856 static struct ctl_table vm_table[] = {
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,
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,
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,
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,
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,
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,
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,
917 .ctl_name = VM_DIRTY_RATIO,
918 .procname = "dirty_ratio",
919 .data = &vm_dirty_ratio,
920 .maxlen = sizeof(vm_dirty_ratio),
921 .mode = 0644,
922 .proc_handler = &dirty_ratio_handler,
923 .strategy = &sysctl_intvec,
924 .extra1 = &zero,
925 .extra2 = &one_hundred,
928 .procname = "dirty_writeback_centisecs",
929 .data = &dirty_writeback_interval,
930 .maxlen = sizeof(dirty_writeback_interval),
931 .mode = 0644,
932 .proc_handler = &dirty_writeback_centisecs_handler,
935 .procname = "dirty_expire_centisecs",
936 .data = &dirty_expire_interval,
937 .maxlen = sizeof(dirty_expire_interval),
938 .mode = 0644,
939 .proc_handler = &proc_dointvec_userhz_jiffies,
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,
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,
960 #ifdef CONFIG_HUGETLB_PAGE
962 .procname = "nr_hugepages",
963 .data = NULL,
964 .maxlen = sizeof(unsigned long),
965 .mode = 0644,
966 .proc_handler = &hugetlb_sysctl_handler,
967 .extra1 = (void *)&hugetlb_zero,
968 .extra2 = (void *)&hugetlb_infinity,
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,
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,
987 .ctl_name = CTL_UNNUMBERED,
988 .procname = "nr_overcommit_hugepages",
989 .data = NULL,
990 .maxlen = sizeof(unsigned long),
991 .mode = 0644,
992 .proc_handler = &hugetlb_overcommit_handler,
993 .extra1 = (void *)&hugetlb_zero,
994 .extra2 = (void *)&hugetlb_infinity,
996 #endif
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,
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,
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,
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,
1035 #ifdef CONFIG_MMU
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
1044 #endif
1046 .ctl_name = VM_LAPTOP_MODE,
1047 .procname = "laptop_mode",
1048 .data = &laptop_mode,
1049 .maxlen = sizeof(laptop_mode),
1050 .mode = 0644,
1051 .proc_handler = &proc_dointvec_jiffies,
1052 .strategy = &sysctl_jiffies,
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,
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,
1074 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
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,
1085 #endif
1086 #ifdef CONFIG_NUMA
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,
1094 .strategy = &sysctl_intvec,
1095 .extra1 = &zero,
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,
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,
1119 #endif
1120 #ifdef CONFIG_SMP
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,
1130 #endif
1131 #ifdef CONFIG_SECURITY
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,
1140 #endif
1141 #ifdef CONFIG_NUMA
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,
1151 #endif
1152 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1153 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
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,
1164 #endif
1165 #ifdef CONFIG_HIGHMEM
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,
1177 #endif
1179 * NOTE: do not add new entries to this table unless you have read
1180 * Documentation/sysctl/ctl_unnumbered.txt
1182 { .ctl_name = 0 }
1185 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1186 static struct ctl_table binfmt_misc_table[] = {
1187 { .ctl_name = 0 }
1189 #endif
1191 static struct ctl_table fs_table[] = {
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,
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,
1209 .procname = "file-nr",
1210 .data = &files_stat,
1211 .maxlen = 3*sizeof(int),
1212 .mode = 0444,
1213 .proc_handler = &proc_nr_files,
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,
1224 .ctl_name = CTL_UNNUMBERED,
1225 .procname = "nr_open",
1226 .data = &sysctl_nr_open,
1227 .maxlen = sizeof(int),
1228 .mode = 0644,
1229 .proc_handler = &proc_dointvec_minmax,
1230 .extra1 = &sysctl_nr_open_min,
1231 .extra2 = &sysctl_nr_open_max,
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,
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,
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,
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,
1271 #ifdef CONFIG_DNOTIFY
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,
1280 #endif
1281 #ifdef CONFIG_MMU
1283 .ctl_name = FS_LEASE_TIME,
1284 .procname = "lease-break-time",
1285 .data = &lease_break_time,
1286 .maxlen = sizeof(int),
1287 .mode = 0644,
1288 .proc_handler = &proc_dointvec_minmax,
1289 .strategy = &sysctl_intvec,
1290 .extra1 = &zero,
1291 .extra2 = &two,
1294 .procname = "aio-nr",
1295 .data = &aio_nr,
1296 .maxlen = sizeof(aio_nr),
1297 .mode = 0444,
1298 .proc_handler = &proc_doulongvec_minmax,
1301 .procname = "aio-max-nr",
1302 .data = &aio_max_nr,
1303 .maxlen = sizeof(aio_max_nr),
1304 .mode = 0644,
1305 .proc_handler = &proc_doulongvec_minmax,
1307 #ifdef CONFIG_INOTIFY_USER
1309 .ctl_name = FS_INOTIFY,
1310 .procname = "inotify",
1311 .mode = 0555,
1312 .child = inotify_table,
1314 #endif
1315 #endif
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,
1324 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1326 .ctl_name = CTL_UNNUMBERED,
1327 .procname = "binfmt_misc",
1328 .mode = 0555,
1329 .child = binfmt_misc_table,
1331 #endif
1333 * NOTE: do not add new entries to this table unless you have read
1334 * Documentation/sysctl/ctl_unnumbered.txt
1336 { .ctl_name = 0 }
1339 static struct ctl_table debug_table[] = {
1340 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
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
1349 #endif
1350 { .ctl_name = 0 }
1353 static struct ctl_table dev_table[] = {
1354 { .ctl_name = 0 }
1357 static DEFINE_SPINLOCK(sysctl_lock);
1359 /* called under sysctl_lock */
1360 static int use_table(struct ctl_table_header *p)
1362 if (unlikely(p->unregistering))
1363 return 0;
1364 p->used++;
1365 return 1;
1368 /* called under sysctl_lock */
1369 static void unuse_table(struct ctl_table_header *p)
1371 if (!--p->used)
1372 if (unlikely(p->unregistering))
1373 complete(p->unregistering);
1376 /* called under sysctl_lock, will reacquire if has to wait */
1377 static void start_unregistering(struct ctl_table_header *p)
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
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);
1390 } else {
1391 /* anything non-NULL; we'll never dereference it */
1392 p->unregistering = ERR_PTR(-EINVAL);
1395 * do not remove from the list until nobody holds it; walking the
1396 * list in do_sysctl() relies on that.
1398 list_del_init(&p->ctl_entry);
1401 void sysctl_head_get(struct ctl_table_header *head)
1403 spin_lock(&sysctl_lock);
1404 head->count++;
1405 spin_unlock(&sysctl_lock);
1408 void sysctl_head_put(struct ctl_table_header *head)
1410 spin_lock(&sysctl_lock);
1411 if (!--head->count)
1412 kfree(head);
1413 spin_unlock(&sysctl_lock);
1416 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
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;
1427 void sysctl_head_finish(struct ctl_table_header *head)
1429 if (!head)
1430 return;
1431 spin_lock(&sysctl_lock);
1432 unuse_table(head);
1433 spin_unlock(&sysctl_lock);
1436 static struct ctl_table_set *
1437 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1439 struct ctl_table_set *set = &root->default_set;
1440 if (root->lookup)
1441 set = root->lookup(root, namespaces);
1442 return set;
1445 static struct list_head *
1446 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1448 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1449 return &set->list;
1452 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1453 struct ctl_table_header *prev)
1455 struct ctl_table_root *root;
1456 struct list_head *header_list;
1457 struct ctl_table_header *head;
1458 struct list_head *tmp;
1460 spin_lock(&sysctl_lock);
1461 if (prev) {
1462 head = prev;
1463 tmp = &prev->ctl_entry;
1464 unuse_table(prev);
1465 goto next;
1467 tmp = &root_table_header.ctl_entry;
1468 for (;;) {
1469 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1471 if (!use_table(head))
1472 goto next;
1473 spin_unlock(&sysctl_lock);
1474 return head;
1475 next:
1476 root = head->root;
1477 tmp = tmp->next;
1478 header_list = lookup_header_list(root, namespaces);
1479 if (tmp != header_list)
1480 continue;
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;
1491 out:
1492 spin_unlock(&sysctl_lock);
1493 return NULL;
1496 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1498 return __sysctl_head_next(current->nsproxy, prev);
1501 void register_sysctl_root(struct ctl_table_root *root)
1503 spin_lock(&sysctl_lock);
1504 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1505 spin_unlock(&sysctl_lock);
1508 #ifdef CONFIG_SYSCTL_SYSCALL
1509 /* Perform the actual read/write of a sysctl table entry. */
1510 static int do_sysctl_strategy(struct ctl_table_root *root,
1511 struct ctl_table *table,
1512 int __user *name, int nlen,
1513 void __user *oldval, size_t __user *oldlenp,
1514 void __user *newval, size_t newlen)
1516 int op = 0, rc;
1518 if (oldval)
1519 op |= MAY_READ;
1520 if (newval)
1521 op |= MAY_WRITE;
1522 if (sysctl_perm(root, table, op))
1523 return -EPERM;
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;
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;
1542 return 0;
1545 static int parse_table(int __user *name, int nlen,
1546 void __user *oldval, size_t __user *oldlenp,
1547 void __user *newval, size_t newlen,
1548 struct ctl_table_root *root,
1549 struct ctl_table *table)
1551 int n;
1552 repeat:
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) {
1563 if (sysctl_perm(root, table, MAY_EXEC))
1564 return -EPERM;
1565 name++;
1566 nlen--;
1567 table = table->child;
1568 goto repeat;
1570 error = do_sysctl_strategy(root, table, name, nlen,
1571 oldval, oldlenp,
1572 newval, newlen);
1573 return error;
1576 return -ENOTDIR;
1579 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1580 void __user *newval, size_t newlen)
1582 struct ctl_table_header *head;
1583 int error = -ENOTDIR;
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;
1593 for (head = sysctl_head_next(NULL); head;
1594 head = sysctl_head_next(head)) {
1595 error = parse_table(name, nlen, oldval, oldlenp,
1596 newval, newlen,
1597 head->root, head->ctl_table);
1598 if (error != -ENOTDIR) {
1599 sysctl_head_finish(head);
1600 break;
1603 return error;
1606 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1608 struct __sysctl_args tmp;
1609 int error;
1611 if (copy_from_user(&tmp, args, sizeof(tmp)))
1612 return -EFAULT;
1614 error = deprecated_sysctl_warning(&tmp);
1615 if (error)
1616 goto out;
1618 lock_kernel();
1619 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1620 tmp.newval, tmp.newlen);
1621 unlock_kernel();
1622 out:
1623 return error;
1625 #endif /* CONFIG_SYSCTL_SYSCALL */
1628 * sysctl_perm does NOT grant the superuser all rights automatically, because
1629 * some sysctl variables are readonly even to root.
1632 static int test_perm(int mode, int op)
1634 if (!current->euid)
1635 mode >>= 6;
1636 else if (in_egroup_p(0))
1637 mode >>= 3;
1638 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1639 return 0;
1640 return -EACCES;
1643 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1645 int error;
1646 int mode;
1648 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1649 if (error)
1650 return error;
1652 if (root->permissions)
1653 mode = root->permissions(root, current->nsproxy, table);
1654 else
1655 mode = table->mode;
1657 return test_perm(mode, op);
1660 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1662 for (; table->ctl_name || table->procname; table++) {
1663 table->parent = parent;
1664 if (table->child)
1665 sysctl_set_parent(table, table->child);
1669 static __init int sysctl_init(void)
1671 sysctl_set_parent(NULL, root_table);
1672 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1674 int err;
1675 err = sysctl_check_table(current->nsproxy, root_table);
1677 #endif
1678 return 0;
1681 core_initcall(sysctl_init);
1683 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1684 struct ctl_table *table)
1686 struct ctl_table *p;
1687 const char *s = branch->procname;
1689 /* branch should have named subdirectory as its first element */
1690 if (!s || !branch->child)
1691 return NULL;
1693 /* ... and nothing else */
1694 if (branch[1].procname || branch[1].ctl_name)
1695 return NULL;
1697 /* table should contain subdirectory with the same name */
1698 for (p = table; p->procname || p->ctl_name; p++) {
1699 if (!p->child)
1700 continue;
1701 if (p->procname && strcmp(p->procname, s) == 0)
1702 return p;
1704 return NULL;
1707 /* see if attaching q to p would be an improvement */
1708 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1710 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1711 struct ctl_table *next;
1712 int is_better = 0;
1713 int not_in_parent = !p->attached_by;
1715 while ((next = is_branch_in(by, to)) != NULL) {
1716 if (by == q->attached_by)
1717 is_better = 1;
1718 if (to == p->attached_by)
1719 not_in_parent = 1;
1720 by = by->child;
1721 to = next->child;
1724 if (is_better && not_in_parent) {
1725 q->attached_by = by;
1726 q->attached_to = to;
1727 q->parent = p;
1732 * __register_sysctl_paths - register a sysctl hierarchy
1733 * @root: List of sysctl headers to register on
1734 * @namespaces: Data to compute which lists of sysctl entries are visible
1735 * @path: The path to the directory the sysctl table is in.
1736 * @table: the top-level table structure
1738 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1739 * array. A completely 0 filled entry terminates the table.
1741 * The members of the &struct ctl_table structure are used as follows:
1743 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1744 * must be unique within that level of sysctl
1746 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1747 * enter a sysctl file
1749 * data - a pointer to data for use by proc_handler
1751 * maxlen - the maximum size in bytes of the data
1753 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1755 * child - a pointer to the child sysctl table if this entry is a directory, or
1756 * %NULL.
1758 * proc_handler - the text handler routine (described below)
1760 * strategy - the strategy routine (described below)
1762 * de - for internal use by the sysctl routines
1764 * extra1, extra2 - extra pointers usable by the proc handler routines
1766 * Leaf nodes in the sysctl tree will be represented by a single file
1767 * under /proc; non-leaf nodes will be represented by directories.
1769 * sysctl(2) can automatically manage read and write requests through
1770 * the sysctl table. The data and maxlen fields of the ctl_table
1771 * struct enable minimal validation of the values being written to be
1772 * performed, and the mode field allows minimal authentication.
1774 * More sophisticated management can be enabled by the provision of a
1775 * strategy routine with the table entry. This will be called before
1776 * any automatic read or write of the data is performed.
1778 * The strategy routine may return
1780 * < 0 - Error occurred (error is passed to user process)
1782 * 0 - OK - proceed with automatic read or write.
1784 * > 0 - OK - read or write has been done by the strategy routine, so
1785 * return immediately.
1787 * There must be a proc_handler routine for any terminal nodes
1788 * mirrored under /proc/sys (non-terminals are handled by a built-in
1789 * directory handler). Several default handlers are available to
1790 * cover common cases -
1792 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1793 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1794 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1796 * It is the handler's job to read the input buffer from user memory
1797 * and process it. The handler should return 0 on success.
1799 * This routine returns %NULL on a failure to register, and a pointer
1800 * to the table header on success.
1802 struct ctl_table_header *__register_sysctl_paths(
1803 struct ctl_table_root *root,
1804 struct nsproxy *namespaces,
1805 const struct ctl_path *path, struct ctl_table *table)
1807 struct ctl_table_header *header;
1808 struct ctl_table *new, **prevp;
1809 unsigned int n, npath;
1810 struct ctl_table_set *set;
1812 /* Count the path components */
1813 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1817 * For each path component, allocate a 2-element ctl_table array.
1818 * The first array element will be filled with the sysctl entry
1819 * for this, the second will be the sentinel (ctl_name == 0).
1821 * We allocate everything in one go so that we don't have to
1822 * worry about freeing additional memory in unregister_sysctl_table.
1824 header = kzalloc(sizeof(struct ctl_table_header) +
1825 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1826 if (!header)
1827 return NULL;
1829 new = (struct ctl_table *) (header + 1);
1831 /* Now connect the dots */
1832 prevp = &header->ctl_table;
1833 for (n = 0; n < npath; ++n, ++path) {
1834 /* Copy the procname */
1835 new->procname = path->procname;
1836 new->ctl_name = path->ctl_name;
1837 new->mode = 0555;
1839 *prevp = new;
1840 prevp = &new->child;
1842 new += 2;
1844 *prevp = table;
1845 header->ctl_table_arg = table;
1847 INIT_LIST_HEAD(&header->ctl_entry);
1848 header->used = 0;
1849 header->unregistering = NULL;
1850 header->root = root;
1851 sysctl_set_parent(NULL, header->ctl_table);
1852 header->count = 1;
1853 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1854 if (sysctl_check_table(namespaces, header->ctl_table)) {
1855 kfree(header);
1856 return NULL;
1858 #endif
1859 spin_lock(&sysctl_lock);
1860 header->set = lookup_header_set(root, namespaces);
1861 header->attached_by = header->ctl_table;
1862 header->attached_to = root_table;
1863 header->parent = &root_table_header;
1864 for (set = header->set; set; set = set->parent) {
1865 struct ctl_table_header *p;
1866 list_for_each_entry(p, &set->list, ctl_entry) {
1867 if (p->unregistering)
1868 continue;
1869 try_attach(p, header);
1872 header->parent->count++;
1873 list_add_tail(&header->ctl_entry, &header->set->list);
1874 spin_unlock(&sysctl_lock);
1876 return header;
1880 * register_sysctl_table_path - register a sysctl table hierarchy
1881 * @path: The path to the directory the sysctl table is in.
1882 * @table: the top-level table structure
1884 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1885 * array. A completely 0 filled entry terminates the table.
1887 * See __register_sysctl_paths for more details.
1889 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1890 struct ctl_table *table)
1892 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1893 path, table);
1897 * register_sysctl_table - register a sysctl table hierarchy
1898 * @table: the top-level table structure
1900 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1901 * array. A completely 0 filled entry terminates the table.
1903 * See register_sysctl_paths for more details.
1905 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1907 static const struct ctl_path null_path[] = { {} };
1909 return register_sysctl_paths(null_path, table);
1913 * unregister_sysctl_table - unregister a sysctl table hierarchy
1914 * @header: the header returned from register_sysctl_table
1916 * Unregisters the sysctl table and all children. proc entries may not
1917 * actually be removed until they are no longer used by anyone.
1919 void unregister_sysctl_table(struct ctl_table_header * header)
1921 might_sleep();
1923 if (header == NULL)
1924 return;
1926 spin_lock(&sysctl_lock);
1927 start_unregistering(header);
1928 if (!--header->parent->count) {
1929 WARN_ON(1);
1930 kfree(header->parent);
1932 if (!--header->count)
1933 kfree(header);
1934 spin_unlock(&sysctl_lock);
1937 int sysctl_is_seen(struct ctl_table_header *p)
1939 struct ctl_table_set *set = p->set;
1940 int res;
1941 spin_lock(&sysctl_lock);
1942 if (p->unregistering)
1943 res = 0;
1944 else if (!set->is_seen)
1945 res = 1;
1946 else
1947 res = set->is_seen(set);
1948 spin_unlock(&sysctl_lock);
1949 return res;
1952 void setup_sysctl_set(struct ctl_table_set *p,
1953 struct ctl_table_set *parent,
1954 int (*is_seen)(struct ctl_table_set *))
1956 INIT_LIST_HEAD(&p->list);
1957 p->parent = parent ? parent : &sysctl_table_root.default_set;
1958 p->is_seen = is_seen;
1961 #else /* !CONFIG_SYSCTL */
1962 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1964 return NULL;
1967 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1968 struct ctl_table *table)
1970 return NULL;
1973 void unregister_sysctl_table(struct ctl_table_header * table)
1977 void setup_sysctl_set(struct ctl_table_set *p,
1978 struct ctl_table_set *parent,
1979 int (*is_seen)(struct ctl_table_set *))
1983 void sysctl_head_put(struct ctl_table_header *head)
1987 #endif /* CONFIG_SYSCTL */
1990 * /proc/sys support
1993 #ifdef CONFIG_PROC_SYSCTL
1995 static int _proc_do_string(void* data, int maxlen, int write,
1996 struct file *filp, void __user *buffer,
1997 size_t *lenp, loff_t *ppos)
1999 size_t len;
2000 char __user *p;
2001 char c;
2003 if (!data || !maxlen || !*lenp) {
2004 *lenp = 0;
2005 return 0;
2008 if (write) {
2009 len = 0;
2010 p = buffer;
2011 while (len < *lenp) {
2012 if (get_user(c, p++))
2013 return -EFAULT;
2014 if (c == 0 || c == '\n')
2015 break;
2016 len++;
2018 if (len >= maxlen)
2019 len = maxlen-1;
2020 if(copy_from_user(data, buffer, len))
2021 return -EFAULT;
2022 ((char *) data)[len] = 0;
2023 *ppos += *lenp;
2024 } else {
2025 len = strlen(data);
2026 if (len > maxlen)
2027 len = maxlen;
2029 if (*ppos > len) {
2030 *lenp = 0;
2031 return 0;
2034 data += *ppos;
2035 len -= *ppos;
2037 if (len > *lenp)
2038 len = *lenp;
2039 if (len)
2040 if(copy_to_user(buffer, data, len))
2041 return -EFAULT;
2042 if (len < *lenp) {
2043 if(put_user('\n', ((char __user *) buffer) + len))
2044 return -EFAULT;
2045 len++;
2047 *lenp = len;
2048 *ppos += len;
2050 return 0;
2054 * proc_dostring - read a string sysctl
2055 * @table: the sysctl table
2056 * @write: %TRUE if this is a write to the sysctl file
2057 * @filp: the file structure
2058 * @buffer: the user buffer
2059 * @lenp: the size of the user buffer
2060 * @ppos: file position
2062 * Reads/writes a string from/to the user buffer. If the kernel
2063 * buffer provided is not large enough to hold the string, the
2064 * string is truncated. The copied string is %NULL-terminated.
2065 * If the string is being read by the user process, it is copied
2066 * and a newline '\n' is added. It is truncated if the buffer is
2067 * not large enough.
2069 * Returns 0 on success.
2071 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2072 void __user *buffer, size_t *lenp, loff_t *ppos)
2074 return _proc_do_string(table->data, table->maxlen, write, filp,
2075 buffer, lenp, ppos);
2079 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2080 int *valp,
2081 int write, void *data)
2083 if (write) {
2084 *valp = *negp ? -*lvalp : *lvalp;
2085 } else {
2086 int val = *valp;
2087 if (val < 0) {
2088 *negp = -1;
2089 *lvalp = (unsigned long)-val;
2090 } else {
2091 *negp = 0;
2092 *lvalp = (unsigned long)val;
2095 return 0;
2098 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2099 int write, struct file *filp, void __user *buffer,
2100 size_t *lenp, loff_t *ppos,
2101 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2102 int write, void *data),
2103 void *data)
2105 #define TMPBUFLEN 21
2106 int *i, vleft, first=1, neg, val;
2107 unsigned long lval;
2108 size_t left, len;
2110 char buf[TMPBUFLEN], *p;
2111 char __user *s = buffer;
2113 if (!tbl_data || !table->maxlen || !*lenp ||
2114 (*ppos && !write)) {
2115 *lenp = 0;
2116 return 0;
2119 i = (int *) tbl_data;
2120 vleft = table->maxlen / sizeof(*i);
2121 left = *lenp;
2123 if (!conv)
2124 conv = do_proc_dointvec_conv;
2126 for (; left && vleft--; i++, first=0) {
2127 if (write) {
2128 while (left) {
2129 char c;
2130 if (get_user(c, s))
2131 return -EFAULT;
2132 if (!isspace(c))
2133 break;
2134 left--;
2135 s++;
2137 if (!left)
2138 break;
2139 neg = 0;
2140 len = left;
2141 if (len > sizeof(buf) - 1)
2142 len = sizeof(buf) - 1;
2143 if (copy_from_user(buf, s, len))
2144 return -EFAULT;
2145 buf[len] = 0;
2146 p = buf;
2147 if (*p == '-' && left > 1) {
2148 neg = 1;
2149 p++;
2151 if (*p < '0' || *p > '9')
2152 break;
2154 lval = simple_strtoul(p, &p, 0);
2156 len = p-buf;
2157 if ((len < left) && *p && !isspace(*p))
2158 break;
2159 if (neg)
2160 val = -val;
2161 s += len;
2162 left -= len;
2164 if (conv(&neg, &lval, i, 1, data))
2165 break;
2166 } else {
2167 p = buf;
2168 if (!first)
2169 *p++ = '\t';
2171 if (conv(&neg, &lval, i, 0, data))
2172 break;
2174 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2175 len = strlen(buf);
2176 if (len > left)
2177 len = left;
2178 if(copy_to_user(s, buf, len))
2179 return -EFAULT;
2180 left -= len;
2181 s += len;
2185 if (!write && !first && left) {
2186 if(put_user('\n', s))
2187 return -EFAULT;
2188 left--, s++;
2190 if (write) {
2191 while (left) {
2192 char c;
2193 if (get_user(c, s++))
2194 return -EFAULT;
2195 if (!isspace(c))
2196 break;
2197 left--;
2200 if (write && first)
2201 return -EINVAL;
2202 *lenp -= left;
2203 *ppos += *lenp;
2204 return 0;
2205 #undef TMPBUFLEN
2208 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2209 void __user *buffer, size_t *lenp, loff_t *ppos,
2210 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2211 int write, void *data),
2212 void *data)
2214 return __do_proc_dointvec(table->data, table, write, filp,
2215 buffer, lenp, ppos, conv, data);
2219 * proc_dointvec - read a vector of integers
2220 * @table: the sysctl table
2221 * @write: %TRUE if this is a write to the sysctl file
2222 * @filp: the file structure
2223 * @buffer: the user buffer
2224 * @lenp: the size of the user buffer
2225 * @ppos: file position
2227 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2228 * values from/to the user buffer, treated as an ASCII string.
2230 * Returns 0 on success.
2232 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2233 void __user *buffer, size_t *lenp, loff_t *ppos)
2235 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2236 NULL,NULL);
2239 #define OP_SET 0
2240 #define OP_AND 1
2241 #define OP_OR 2
2243 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2244 int *valp,
2245 int write, void *data)
2247 int op = *(int *)data;
2248 if (write) {
2249 int val = *negp ? -*lvalp : *lvalp;
2250 switch(op) {
2251 case OP_SET: *valp = val; break;
2252 case OP_AND: *valp &= val; break;
2253 case OP_OR: *valp |= val; break;
2255 } else {
2256 int val = *valp;
2257 if (val < 0) {
2258 *negp = -1;
2259 *lvalp = (unsigned long)-val;
2260 } else {
2261 *negp = 0;
2262 *lvalp = (unsigned long)val;
2265 return 0;
2269 * Taint values can only be increased
2271 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
2272 void __user *buffer, size_t *lenp, loff_t *ppos)
2274 int op;
2276 if (write && !capable(CAP_SYS_ADMIN))
2277 return -EPERM;
2279 op = OP_OR;
2280 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2281 do_proc_dointvec_bset_conv,&op);
2284 struct do_proc_dointvec_minmax_conv_param {
2285 int *min;
2286 int *max;
2289 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2290 int *valp,
2291 int write, void *data)
2293 struct do_proc_dointvec_minmax_conv_param *param = data;
2294 if (write) {
2295 int val = *negp ? -*lvalp : *lvalp;
2296 if ((param->min && *param->min > val) ||
2297 (param->max && *param->max < val))
2298 return -EINVAL;
2299 *valp = val;
2300 } else {
2301 int val = *valp;
2302 if (val < 0) {
2303 *negp = -1;
2304 *lvalp = (unsigned long)-val;
2305 } else {
2306 *negp = 0;
2307 *lvalp = (unsigned long)val;
2310 return 0;
2314 * proc_dointvec_minmax - read a vector of integers with min/max values
2315 * @table: the sysctl table
2316 * @write: %TRUE if this is a write to the sysctl file
2317 * @filp: the file structure
2318 * @buffer: the user buffer
2319 * @lenp: the size of the user buffer
2320 * @ppos: file position
2322 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2323 * values from/to the user buffer, treated as an ASCII string.
2325 * This routine will ensure the values are within the range specified by
2326 * table->extra1 (min) and table->extra2 (max).
2328 * Returns 0 on success.
2330 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2331 void __user *buffer, size_t *lenp, loff_t *ppos)
2333 struct do_proc_dointvec_minmax_conv_param param = {
2334 .min = (int *) table->extra1,
2335 .max = (int *) table->extra2,
2337 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2338 do_proc_dointvec_minmax_conv, &param);
2341 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2342 struct file *filp,
2343 void __user *buffer,
2344 size_t *lenp, loff_t *ppos,
2345 unsigned long convmul,
2346 unsigned long convdiv)
2348 #define TMPBUFLEN 21
2349 unsigned long *i, *min, *max, val;
2350 int vleft, first=1, neg;
2351 size_t len, left;
2352 char buf[TMPBUFLEN], *p;
2353 char __user *s = buffer;
2355 if (!data || !table->maxlen || !*lenp ||
2356 (*ppos && !write)) {
2357 *lenp = 0;
2358 return 0;
2361 i = (unsigned long *) data;
2362 min = (unsigned long *) table->extra1;
2363 max = (unsigned long *) table->extra2;
2364 vleft = table->maxlen / sizeof(unsigned long);
2365 left = *lenp;
2367 for (; left && vleft--; i++, min++, max++, first=0) {
2368 if (write) {
2369 while (left) {
2370 char c;
2371 if (get_user(c, s))
2372 return -EFAULT;
2373 if (!isspace(c))
2374 break;
2375 left--;
2376 s++;
2378 if (!left)
2379 break;
2380 neg = 0;
2381 len = left;
2382 if (len > TMPBUFLEN-1)
2383 len = TMPBUFLEN-1;
2384 if (copy_from_user(buf, s, len))
2385 return -EFAULT;
2386 buf[len] = 0;
2387 p = buf;
2388 if (*p == '-' && left > 1) {
2389 neg = 1;
2390 p++;
2392 if (*p < '0' || *p > '9')
2393 break;
2394 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2395 len = p-buf;
2396 if ((len < left) && *p && !isspace(*p))
2397 break;
2398 if (neg)
2399 val = -val;
2400 s += len;
2401 left -= len;
2403 if(neg)
2404 continue;
2405 if ((min && val < *min) || (max && val > *max))
2406 continue;
2407 *i = val;
2408 } else {
2409 p = buf;
2410 if (!first)
2411 *p++ = '\t';
2412 sprintf(p, "%lu", convdiv * (*i) / convmul);
2413 len = strlen(buf);
2414 if (len > left)
2415 len = left;
2416 if(copy_to_user(s, buf, len))
2417 return -EFAULT;
2418 left -= len;
2419 s += len;
2423 if (!write && !first && left) {
2424 if(put_user('\n', s))
2425 return -EFAULT;
2426 left--, s++;
2428 if (write) {
2429 while (left) {
2430 char c;
2431 if (get_user(c, s++))
2432 return -EFAULT;
2433 if (!isspace(c))
2434 break;
2435 left--;
2438 if (write && first)
2439 return -EINVAL;
2440 *lenp -= left;
2441 *ppos += *lenp;
2442 return 0;
2443 #undef TMPBUFLEN
2446 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2447 struct file *filp,
2448 void __user *buffer,
2449 size_t *lenp, loff_t *ppos,
2450 unsigned long convmul,
2451 unsigned long convdiv)
2453 return __do_proc_doulongvec_minmax(table->data, table, write,
2454 filp, buffer, lenp, ppos, convmul, convdiv);
2458 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2459 * @table: the sysctl table
2460 * @write: %TRUE if this is a write to the sysctl file
2461 * @filp: the file structure
2462 * @buffer: the user buffer
2463 * @lenp: the size of the user buffer
2464 * @ppos: file position
2466 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2467 * values from/to the user buffer, treated as an ASCII string.
2469 * This routine will ensure the values are within the range specified by
2470 * table->extra1 (min) and table->extra2 (max).
2472 * Returns 0 on success.
2474 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2475 void __user *buffer, size_t *lenp, loff_t *ppos)
2477 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2481 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2482 * @table: the sysctl table
2483 * @write: %TRUE if this is a write to the sysctl file
2484 * @filp: the file structure
2485 * @buffer: the user buffer
2486 * @lenp: the size of the user buffer
2487 * @ppos: file position
2489 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2490 * values from/to the user buffer, treated as an ASCII string. The values
2491 * are treated as milliseconds, and converted to jiffies when they are stored.
2493 * This routine will ensure the values are within the range specified by
2494 * table->extra1 (min) and table->extra2 (max).
2496 * Returns 0 on success.
2498 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2499 struct file *filp,
2500 void __user *buffer,
2501 size_t *lenp, loff_t *ppos)
2503 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2504 lenp, ppos, HZ, 1000l);
2508 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2509 int *valp,
2510 int write, void *data)
2512 if (write) {
2513 if (*lvalp > LONG_MAX / HZ)
2514 return 1;
2515 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2516 } else {
2517 int val = *valp;
2518 unsigned long lval;
2519 if (val < 0) {
2520 *negp = -1;
2521 lval = (unsigned long)-val;
2522 } else {
2523 *negp = 0;
2524 lval = (unsigned long)val;
2526 *lvalp = lval / HZ;
2528 return 0;
2531 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2532 int *valp,
2533 int write, void *data)
2535 if (write) {
2536 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2537 return 1;
2538 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2539 } else {
2540 int val = *valp;
2541 unsigned long lval;
2542 if (val < 0) {
2543 *negp = -1;
2544 lval = (unsigned long)-val;
2545 } else {
2546 *negp = 0;
2547 lval = (unsigned long)val;
2549 *lvalp = jiffies_to_clock_t(lval);
2551 return 0;
2554 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2555 int *valp,
2556 int write, void *data)
2558 if (write) {
2559 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2560 } else {
2561 int val = *valp;
2562 unsigned long lval;
2563 if (val < 0) {
2564 *negp = -1;
2565 lval = (unsigned long)-val;
2566 } else {
2567 *negp = 0;
2568 lval = (unsigned long)val;
2570 *lvalp = jiffies_to_msecs(lval);
2572 return 0;
2576 * proc_dointvec_jiffies - read a vector of integers as seconds
2577 * @table: the sysctl table
2578 * @write: %TRUE if this is a write to the sysctl file
2579 * @filp: the file structure
2580 * @buffer: the user buffer
2581 * @lenp: the size of the user buffer
2582 * @ppos: file position
2584 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2585 * values from/to the user buffer, treated as an ASCII string.
2586 * The values read are assumed to be in seconds, and are converted into
2587 * jiffies.
2589 * Returns 0 on success.
2591 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2592 void __user *buffer, size_t *lenp, loff_t *ppos)
2594 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2595 do_proc_dointvec_jiffies_conv,NULL);
2599 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2600 * @table: the sysctl table
2601 * @write: %TRUE if this is a write to the sysctl file
2602 * @filp: the file structure
2603 * @buffer: the user buffer
2604 * @lenp: the size of the user buffer
2605 * @ppos: pointer to the file position
2607 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2608 * values from/to the user buffer, treated as an ASCII string.
2609 * The values read are assumed to be in 1/USER_HZ seconds, and
2610 * are converted into jiffies.
2612 * Returns 0 on success.
2614 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2615 void __user *buffer, size_t *lenp, loff_t *ppos)
2617 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2618 do_proc_dointvec_userhz_jiffies_conv,NULL);
2622 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2623 * @table: the sysctl table
2624 * @write: %TRUE if this is a write to the sysctl file
2625 * @filp: the file structure
2626 * @buffer: the user buffer
2627 * @lenp: the size of the user buffer
2628 * @ppos: file position
2629 * @ppos: the current position in the file
2631 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2632 * values from/to the user buffer, treated as an ASCII string.
2633 * The values read are assumed to be in 1/1000 seconds, and
2634 * are converted into jiffies.
2636 * Returns 0 on success.
2638 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2639 void __user *buffer, size_t *lenp, loff_t *ppos)
2641 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2642 do_proc_dointvec_ms_jiffies_conv, NULL);
2645 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2646 void __user *buffer, size_t *lenp, loff_t *ppos)
2648 struct pid *new_pid;
2649 pid_t tmp;
2650 int r;
2652 tmp = pid_vnr(cad_pid);
2654 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2655 lenp, ppos, NULL, NULL);
2656 if (r || !write)
2657 return r;
2659 new_pid = find_get_pid(tmp);
2660 if (!new_pid)
2661 return -ESRCH;
2663 put_pid(xchg(&cad_pid, new_pid));
2664 return 0;
2667 #else /* CONFIG_PROC_FS */
2669 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2670 void __user *buffer, size_t *lenp, loff_t *ppos)
2672 return -ENOSYS;
2675 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2676 void __user *buffer, size_t *lenp, loff_t *ppos)
2678 return -ENOSYS;
2681 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2682 void __user *buffer, size_t *lenp, loff_t *ppos)
2684 return -ENOSYS;
2687 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2688 void __user *buffer, size_t *lenp, loff_t *ppos)
2690 return -ENOSYS;
2693 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2694 void __user *buffer, size_t *lenp, loff_t *ppos)
2696 return -ENOSYS;
2699 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2700 void __user *buffer, size_t *lenp, loff_t *ppos)
2702 return -ENOSYS;
2705 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2706 void __user *buffer, size_t *lenp, loff_t *ppos)
2708 return -ENOSYS;
2711 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2712 struct file *filp,
2713 void __user *buffer,
2714 size_t *lenp, loff_t *ppos)
2716 return -ENOSYS;
2720 #endif /* CONFIG_PROC_FS */
2723 #ifdef CONFIG_SYSCTL_SYSCALL
2725 * General sysctl support routines
2728 /* The generic sysctl data routine (used if no strategy routine supplied) */
2729 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2730 void __user *oldval, size_t __user *oldlenp,
2731 void __user *newval, size_t newlen)
2733 size_t len;
2735 /* Get out of I don't have a variable */
2736 if (!table->data || !table->maxlen)
2737 return -ENOTDIR;
2739 if (oldval && oldlenp) {
2740 if (get_user(len, oldlenp))
2741 return -EFAULT;
2742 if (len) {
2743 if (len > table->maxlen)
2744 len = table->maxlen;
2745 if (copy_to_user(oldval, table->data, len))
2746 return -EFAULT;
2747 if (put_user(len, oldlenp))
2748 return -EFAULT;
2752 if (newval && newlen) {
2753 if (newlen > table->maxlen)
2754 newlen = table->maxlen;
2756 if (copy_from_user(table->data, newval, newlen))
2757 return -EFAULT;
2759 return 1;
2762 /* The generic string strategy routine: */
2763 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2764 void __user *oldval, size_t __user *oldlenp,
2765 void __user *newval, size_t newlen)
2767 if (!table->data || !table->maxlen)
2768 return -ENOTDIR;
2770 if (oldval && oldlenp) {
2771 size_t bufsize;
2772 if (get_user(bufsize, oldlenp))
2773 return -EFAULT;
2774 if (bufsize) {
2775 size_t len = strlen(table->data), copied;
2777 /* This shouldn't trigger for a well-formed sysctl */
2778 if (len > table->maxlen)
2779 len = table->maxlen;
2781 /* Copy up to a max of bufsize-1 bytes of the string */
2782 copied = (len >= bufsize) ? bufsize - 1 : len;
2784 if (copy_to_user(oldval, table->data, copied) ||
2785 put_user(0, (char __user *)(oldval + copied)))
2786 return -EFAULT;
2787 if (put_user(len, oldlenp))
2788 return -EFAULT;
2791 if (newval && newlen) {
2792 size_t len = newlen;
2793 if (len > table->maxlen)
2794 len = table->maxlen;
2795 if(copy_from_user(table->data, newval, len))
2796 return -EFAULT;
2797 if (len == table->maxlen)
2798 len--;
2799 ((char *) table->data)[len] = 0;
2801 return 1;
2805 * This function makes sure that all of the integers in the vector
2806 * are between the minimum and maximum values given in the arrays
2807 * table->extra1 and table->extra2, respectively.
2809 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2810 void __user *oldval, size_t __user *oldlenp,
2811 void __user *newval, size_t newlen)
2814 if (newval && newlen) {
2815 int __user *vec = (int __user *) newval;
2816 int *min = (int *) table->extra1;
2817 int *max = (int *) table->extra2;
2818 size_t length;
2819 int i;
2821 if (newlen % sizeof(int) != 0)
2822 return -EINVAL;
2824 if (!table->extra1 && !table->extra2)
2825 return 0;
2827 if (newlen > table->maxlen)
2828 newlen = table->maxlen;
2829 length = newlen / sizeof(int);
2831 for (i = 0; i < length; i++) {
2832 int value;
2833 if (get_user(value, vec + i))
2834 return -EFAULT;
2835 if (min && value < min[i])
2836 return -EINVAL;
2837 if (max && value > max[i])
2838 return -EINVAL;
2841 return 0;
2844 /* Strategy function to convert jiffies to seconds */
2845 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2846 void __user *oldval, size_t __user *oldlenp,
2847 void __user *newval, size_t newlen)
2849 if (oldval && oldlenp) {
2850 size_t olen;
2852 if (get_user(olen, oldlenp))
2853 return -EFAULT;
2854 if (olen) {
2855 int val;
2857 if (olen < sizeof(int))
2858 return -EINVAL;
2860 val = *(int *)(table->data) / HZ;
2861 if (put_user(val, (int __user *)oldval))
2862 return -EFAULT;
2863 if (put_user(sizeof(int), oldlenp))
2864 return -EFAULT;
2867 if (newval && newlen) {
2868 int new;
2869 if (newlen != sizeof(int))
2870 return -EINVAL;
2871 if (get_user(new, (int __user *)newval))
2872 return -EFAULT;
2873 *(int *)(table->data) = new*HZ;
2875 return 1;
2878 /* Strategy function to convert jiffies to seconds */
2879 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2880 void __user *oldval, size_t __user *oldlenp,
2881 void __user *newval, size_t newlen)
2883 if (oldval && oldlenp) {
2884 size_t olen;
2886 if (get_user(olen, oldlenp))
2887 return -EFAULT;
2888 if (olen) {
2889 int val;
2891 if (olen < sizeof(int))
2892 return -EINVAL;
2894 val = jiffies_to_msecs(*(int *)(table->data));
2895 if (put_user(val, (int __user *)oldval))
2896 return -EFAULT;
2897 if (put_user(sizeof(int), oldlenp))
2898 return -EFAULT;
2901 if (newval && newlen) {
2902 int new;
2903 if (newlen != sizeof(int))
2904 return -EINVAL;
2905 if (get_user(new, (int __user *)newval))
2906 return -EFAULT;
2907 *(int *)(table->data) = msecs_to_jiffies(new);
2909 return 1;
2914 #else /* CONFIG_SYSCTL_SYSCALL */
2917 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2919 struct __sysctl_args tmp;
2920 int error;
2922 if (copy_from_user(&tmp, args, sizeof(tmp)))
2923 return -EFAULT;
2925 error = deprecated_sysctl_warning(&tmp);
2927 /* If no error reading the parameters then just -ENOSYS ... */
2928 if (!error)
2929 error = -ENOSYS;
2931 return error;
2934 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2935 void __user *oldval, size_t __user *oldlenp,
2936 void __user *newval, size_t newlen)
2938 return -ENOSYS;
2941 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2942 void __user *oldval, size_t __user *oldlenp,
2943 void __user *newval, size_t newlen)
2945 return -ENOSYS;
2948 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2949 void __user *oldval, size_t __user *oldlenp,
2950 void __user *newval, size_t newlen)
2952 return -ENOSYS;
2955 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2956 void __user *oldval, size_t __user *oldlenp,
2957 void __user *newval, size_t newlen)
2959 return -ENOSYS;
2962 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2963 void __user *oldval, size_t __user *oldlenp,
2964 void __user *newval, size_t newlen)
2966 return -ENOSYS;
2969 #endif /* CONFIG_SYSCTL_SYSCALL */
2971 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2973 static int msg_count;
2974 int name[CTL_MAXNAME];
2975 int i;
2977 /* Check args->nlen. */
2978 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2979 return -ENOTDIR;
2981 /* Read in the sysctl name for better debug message logging */
2982 for (i = 0; i < args->nlen; i++)
2983 if (get_user(name[i], args->name + i))
2984 return -EFAULT;
2986 /* Ignore accesses to kernel.version */
2987 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2988 return 0;
2990 if (msg_count < 5) {
2991 msg_count++;
2992 printk(KERN_INFO
2993 "warning: process `%s' used the deprecated sysctl "
2994 "system call with ", current->comm);
2995 for (i = 0; i < args->nlen; i++)
2996 printk("%d.", name[i]);
2997 printk("\n");
2999 return 0;
3003 * No sense putting this after each symbol definition, twice,
3004 * exception granted :-)
3006 EXPORT_SYMBOL(proc_dointvec);
3007 EXPORT_SYMBOL(proc_dointvec_jiffies);
3008 EXPORT_SYMBOL(proc_dointvec_minmax);
3009 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3010 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3011 EXPORT_SYMBOL(proc_dostring);
3012 EXPORT_SYMBOL(proc_doulongvec_minmax);
3013 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3014 EXPORT_SYMBOL(register_sysctl_table);
3015 EXPORT_SYMBOL(register_sysctl_paths);
3016 EXPORT_SYMBOL(sysctl_intvec);
3017 EXPORT_SYMBOL(sysctl_jiffies);
3018 EXPORT_SYMBOL(sysctl_ms_jiffies);
3019 EXPORT_SYMBOL(sysctl_string);
3020 EXPORT_SYMBOL(sysctl_data);
3021 EXPORT_SYMBOL(unregister_sysctl_table);