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
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
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>
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/kmemcheck.h>
31 #include <linux/init.h>
32 #include <linux/kernel.h>
33 #include <linux/kobject.h>
34 #include <linux/net.h>
35 #include <linux/sysrq.h>
36 #include <linux/highuid.h>
37 #include <linux/writeback.h>
38 #include <linux/ratelimit.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>
51 #include <linux/slow-work.h>
52 #include <linux/perf_event.h>
54 #include <asm/uaccess.h>
55 #include <asm/processor.h>
59 #include <asm/stacktrace.h>
63 #ifdef CONFIG_NMI_WATCHDOG
64 #include <linux/nmi.h>
68 #if defined(CONFIG_SYSCTL)
70 /* External variables not in a header file. */
72 extern int print_fatal_signals;
73 extern int sysctl_overcommit_memory;
74 extern int sysctl_overcommit_ratio;
75 extern int sysctl_panic_on_oom;
76 extern int sysctl_oom_kill_allocating_task;
77 extern int sysctl_oom_dump_tasks;
78 extern int max_threads;
79 extern int core_uses_pid;
80 extern int suid_dumpable;
81 extern char core_pattern[];
82 extern unsigned int core_pipe_limit;
84 extern int min_free_kbytes;
85 extern int pid_max_min, pid_max_max;
86 extern int sysctl_drop_caches;
87 extern int percpu_pagelist_fraction;
88 extern int compat_log;
89 extern int latencytop_enabled;
90 extern int sysctl_nr_open_min, sysctl_nr_open_max;
92 extern int sysctl_nr_trim_pages;
94 #ifdef CONFIG_RCU_TORTURE_TEST
95 extern int rcutorture_runnable;
96 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
98 extern int blk_iopoll_enabled;
101 /* Constants used for minimum and maximum */
102 #ifdef CONFIG_DETECT_SOFTLOCKUP
103 static int sixty = 60;
104 static int neg_one = -1;
108 static int __maybe_unused one = 1;
109 static int __maybe_unused two = 2;
110 static unsigned long one_ul = 1;
111 static int one_hundred = 100;
113 static int ten_thousand = 10000;
116 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
117 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
119 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
120 static int maxolduid = 65535;
121 static int minolduid;
122 static int min_percpu_pagelist_fract = 8;
124 static int ngroups_max = NGROUPS_MAX;
126 #ifdef CONFIG_MODULES
127 extern char modprobe_path[];
128 extern int modules_disabled;
130 #ifdef CONFIG_CHR_DEV_SG
131 extern int sg_big_buff;
135 #include <asm/system.h>
138 #ifdef CONFIG_SPARC64
139 extern int sysctl_tsb_ratio;
143 extern int pwrsw_enabled;
144 extern int unaligned_enabled;
148 #ifdef CONFIG_MATHEMU
149 extern int sysctl_ieee_emulation_warnings;
151 extern int sysctl_userprocess_debug;
152 extern int spin_retry;
155 #ifdef CONFIG_BSD_PROCESS_ACCT
156 extern int acct_parm[];
160 extern int no_unaligned_warning;
161 extern int unaligned_dump_stack;
164 extern struct ratelimit_state printk_ratelimit_state;
166 #ifdef CONFIG_RT_MUTEXES
167 extern int max_lock_depth;
170 #ifdef CONFIG_PROC_SYSCTL
171 static int proc_do_cad_pid(struct ctl_table *table, int write,
172 void __user *buffer, size_t *lenp, loff_t *ppos);
173 static int proc_taint(struct ctl_table *table, int write,
174 void __user *buffer, size_t *lenp, loff_t *ppos);
177 static struct ctl_table root_table[];
178 static struct ctl_table_root sysctl_table_root;
179 static struct ctl_table_header root_table_header = {
181 .ctl_table = root_table,
182 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
183 .root = &sysctl_table_root,
184 .set = &sysctl_table_root.default_set,
186 static struct ctl_table_root sysctl_table_root = {
187 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
188 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
191 static struct ctl_table kern_table[];
192 static struct ctl_table vm_table[];
193 static struct ctl_table fs_table[];
194 static struct ctl_table debug_table[];
195 static struct ctl_table dev_table[];
196 extern struct ctl_table random_table[];
197 #ifdef CONFIG_INOTIFY_USER
198 extern struct ctl_table inotify_table[];
201 extern struct ctl_table epoll_table[];
204 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
205 int sysctl_legacy_va_layout;
208 extern int prove_locking;
209 extern int lock_stat;
211 /* The default sysctl tables: */
213 static struct ctl_table root_table[] = {
215 .procname = "kernel",
232 .child = debug_table,
240 * NOTE: do not add new entries to this table unless you have read
241 * Documentation/sysctl/ctl_unnumbered.txt
246 #ifdef CONFIG_SCHED_DEBUG
247 static int min_sched_granularity_ns = 100000; /* 100 usecs */
248 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
249 static int min_wakeup_granularity_ns; /* 0 usecs */
250 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
251 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
252 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
253 static int min_sched_shares_ratelimit = 100000; /* 100 usec */
254 static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
257 static struct ctl_table kern_table[] = {
259 .procname = "sched_child_runs_first",
260 .data = &sysctl_sched_child_runs_first,
261 .maxlen = sizeof(unsigned int),
263 .proc_handler = proc_dointvec,
265 #ifdef CONFIG_SCHED_DEBUG
267 .procname = "sched_min_granularity_ns",
268 .data = &sysctl_sched_min_granularity,
269 .maxlen = sizeof(unsigned int),
271 .proc_handler = sched_proc_update_handler,
272 .extra1 = &min_sched_granularity_ns,
273 .extra2 = &max_sched_granularity_ns,
276 .procname = "sched_latency_ns",
277 .data = &sysctl_sched_latency,
278 .maxlen = sizeof(unsigned int),
280 .proc_handler = sched_proc_update_handler,
281 .extra1 = &min_sched_granularity_ns,
282 .extra2 = &max_sched_granularity_ns,
285 .procname = "sched_wakeup_granularity_ns",
286 .data = &sysctl_sched_wakeup_granularity,
287 .maxlen = sizeof(unsigned int),
289 .proc_handler = sched_proc_update_handler,
290 .extra1 = &min_wakeup_granularity_ns,
291 .extra2 = &max_wakeup_granularity_ns,
294 .procname = "sched_shares_ratelimit",
295 .data = &sysctl_sched_shares_ratelimit,
296 .maxlen = sizeof(unsigned int),
298 .proc_handler = sched_proc_update_handler,
299 .extra1 = &min_sched_shares_ratelimit,
300 .extra2 = &max_sched_shares_ratelimit,
303 .procname = "sched_tunable_scaling",
304 .data = &sysctl_sched_tunable_scaling,
305 .maxlen = sizeof(enum sched_tunable_scaling),
307 .proc_handler = sched_proc_update_handler,
308 .extra1 = &min_sched_tunable_scaling,
309 .extra2 = &max_sched_tunable_scaling,
312 .procname = "sched_shares_thresh",
313 .data = &sysctl_sched_shares_thresh,
314 .maxlen = sizeof(unsigned int),
316 .proc_handler = proc_dointvec_minmax,
320 .procname = "sched_migration_cost",
321 .data = &sysctl_sched_migration_cost,
322 .maxlen = sizeof(unsigned int),
324 .proc_handler = proc_dointvec,
327 .procname = "sched_nr_migrate",
328 .data = &sysctl_sched_nr_migrate,
329 .maxlen = sizeof(unsigned int),
331 .proc_handler = proc_dointvec,
334 .procname = "sched_time_avg",
335 .data = &sysctl_sched_time_avg,
336 .maxlen = sizeof(unsigned int),
338 .proc_handler = proc_dointvec,
341 .procname = "timer_migration",
342 .data = &sysctl_timer_migration,
343 .maxlen = sizeof(unsigned int),
345 .proc_handler = proc_dointvec_minmax,
351 .procname = "sched_rt_period_us",
352 .data = &sysctl_sched_rt_period,
353 .maxlen = sizeof(unsigned int),
355 .proc_handler = sched_rt_handler,
358 .procname = "sched_rt_runtime_us",
359 .data = &sysctl_sched_rt_runtime,
360 .maxlen = sizeof(int),
362 .proc_handler = sched_rt_handler,
365 .procname = "sched_compat_yield",
366 .data = &sysctl_sched_compat_yield,
367 .maxlen = sizeof(unsigned int),
369 .proc_handler = proc_dointvec,
371 #ifdef CONFIG_PROVE_LOCKING
373 .procname = "prove_locking",
374 .data = &prove_locking,
375 .maxlen = sizeof(int),
377 .proc_handler = proc_dointvec,
380 #ifdef CONFIG_LOCK_STAT
382 .procname = "lock_stat",
384 .maxlen = sizeof(int),
386 .proc_handler = proc_dointvec,
391 .data = &panic_timeout,
392 .maxlen = sizeof(int),
394 .proc_handler = proc_dointvec,
397 .procname = "core_uses_pid",
398 .data = &core_uses_pid,
399 .maxlen = sizeof(int),
401 .proc_handler = proc_dointvec,
404 .procname = "core_pattern",
405 .data = core_pattern,
406 .maxlen = CORENAME_MAX_SIZE,
408 .proc_handler = proc_dostring,
411 .procname = "core_pipe_limit",
412 .data = &core_pipe_limit,
413 .maxlen = sizeof(unsigned int),
415 .proc_handler = proc_dointvec,
417 #ifdef CONFIG_PROC_SYSCTL
419 .procname = "tainted",
420 .maxlen = sizeof(long),
422 .proc_handler = proc_taint,
425 #ifdef CONFIG_LATENCYTOP
427 .procname = "latencytop",
428 .data = &latencytop_enabled,
429 .maxlen = sizeof(int),
431 .proc_handler = proc_dointvec,
434 #ifdef CONFIG_BLK_DEV_INITRD
436 .procname = "real-root-dev",
437 .data = &real_root_dev,
438 .maxlen = sizeof(int),
440 .proc_handler = proc_dointvec,
444 .procname = "print-fatal-signals",
445 .data = &print_fatal_signals,
446 .maxlen = sizeof(int),
448 .proc_handler = proc_dointvec,
452 .procname = "reboot-cmd",
453 .data = reboot_command,
456 .proc_handler = proc_dostring,
459 .procname = "stop-a",
460 .data = &stop_a_enabled,
461 .maxlen = sizeof (int),
463 .proc_handler = proc_dointvec,
466 .procname = "scons-poweroff",
467 .data = &scons_pwroff,
468 .maxlen = sizeof (int),
470 .proc_handler = proc_dointvec,
473 #ifdef CONFIG_SPARC64
475 .procname = "tsb-ratio",
476 .data = &sysctl_tsb_ratio,
477 .maxlen = sizeof (int),
479 .proc_handler = proc_dointvec,
484 .procname = "soft-power",
485 .data = &pwrsw_enabled,
486 .maxlen = sizeof (int),
488 .proc_handler = proc_dointvec,
491 .procname = "unaligned-trap",
492 .data = &unaligned_enabled,
493 .maxlen = sizeof (int),
495 .proc_handler = proc_dointvec,
499 .procname = "ctrl-alt-del",
501 .maxlen = sizeof(int),
503 .proc_handler = proc_dointvec,
505 #ifdef CONFIG_FUNCTION_TRACER
507 .procname = "ftrace_enabled",
508 .data = &ftrace_enabled,
509 .maxlen = sizeof(int),
511 .proc_handler = ftrace_enable_sysctl,
514 #ifdef CONFIG_STACK_TRACER
516 .procname = "stack_tracer_enabled",
517 .data = &stack_tracer_enabled,
518 .maxlen = sizeof(int),
520 .proc_handler = stack_trace_sysctl,
523 #ifdef CONFIG_TRACING
525 .procname = "ftrace_dump_on_oops",
526 .data = &ftrace_dump_on_oops,
527 .maxlen = sizeof(int),
529 .proc_handler = proc_dointvec,
532 #ifdef CONFIG_MODULES
534 .procname = "modprobe",
535 .data = &modprobe_path,
536 .maxlen = KMOD_PATH_LEN,
538 .proc_handler = proc_dostring,
541 .procname = "modules_disabled",
542 .data = &modules_disabled,
543 .maxlen = sizeof(int),
545 /* only handle a transition from default "0" to "1" */
546 .proc_handler = proc_dointvec_minmax,
551 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
553 .procname = "hotplug",
554 .data = &uevent_helper,
555 .maxlen = UEVENT_HELPER_PATH_LEN,
557 .proc_handler = proc_dostring,
560 #ifdef CONFIG_CHR_DEV_SG
562 .procname = "sg-big-buff",
563 .data = &sg_big_buff,
564 .maxlen = sizeof (int),
566 .proc_handler = proc_dointvec,
569 #ifdef CONFIG_BSD_PROCESS_ACCT
573 .maxlen = 3*sizeof(int),
575 .proc_handler = proc_dointvec,
578 #ifdef CONFIG_MAGIC_SYSRQ
581 .data = &__sysrq_enabled,
582 .maxlen = sizeof (int),
584 .proc_handler = proc_dointvec,
587 #ifdef CONFIG_PROC_SYSCTL
589 .procname = "cad_pid",
591 .maxlen = sizeof (int),
593 .proc_handler = proc_do_cad_pid,
597 .procname = "threads-max",
598 .data = &max_threads,
599 .maxlen = sizeof(int),
601 .proc_handler = proc_dointvec,
604 .procname = "random",
606 .child = random_table,
609 .procname = "overflowuid",
610 .data = &overflowuid,
611 .maxlen = sizeof(int),
613 .proc_handler = proc_dointvec_minmax,
614 .extra1 = &minolduid,
615 .extra2 = &maxolduid,
618 .procname = "overflowgid",
619 .data = &overflowgid,
620 .maxlen = sizeof(int),
622 .proc_handler = proc_dointvec_minmax,
623 .extra1 = &minolduid,
624 .extra2 = &maxolduid,
627 #ifdef CONFIG_MATHEMU
629 .procname = "ieee_emulation_warnings",
630 .data = &sysctl_ieee_emulation_warnings,
631 .maxlen = sizeof(int),
633 .proc_handler = proc_dointvec,
637 .procname = "userprocess_debug",
638 .data = &sysctl_userprocess_debug,
639 .maxlen = sizeof(int),
641 .proc_handler = proc_dointvec,
645 .procname = "pid_max",
647 .maxlen = sizeof (int),
649 .proc_handler = proc_dointvec_minmax,
650 .extra1 = &pid_max_min,
651 .extra2 = &pid_max_max,
654 .procname = "panic_on_oops",
655 .data = &panic_on_oops,
656 .maxlen = sizeof(int),
658 .proc_handler = proc_dointvec,
660 #if defined CONFIG_PRINTK
662 .procname = "printk",
663 .data = &console_loglevel,
664 .maxlen = 4*sizeof(int),
666 .proc_handler = proc_dointvec,
669 .procname = "printk_ratelimit",
670 .data = &printk_ratelimit_state.interval,
671 .maxlen = sizeof(int),
673 .proc_handler = proc_dointvec_jiffies,
676 .procname = "printk_ratelimit_burst",
677 .data = &printk_ratelimit_state.burst,
678 .maxlen = sizeof(int),
680 .proc_handler = proc_dointvec,
683 .procname = "printk_delay",
684 .data = &printk_delay_msec,
685 .maxlen = sizeof(int),
687 .proc_handler = proc_dointvec_minmax,
689 .extra2 = &ten_thousand,
693 .procname = "ngroups_max",
694 .data = &ngroups_max,
695 .maxlen = sizeof (int),
697 .proc_handler = proc_dointvec,
699 #if defined(CONFIG_NMI_WATCHDOG)
701 .procname = "nmi_watchdog",
702 .data = &nmi_watchdog_enabled,
703 .maxlen = sizeof (int),
705 .proc_handler = proc_nmi_enabled,
708 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_NMI_WATCHDOG)
710 .procname = "unknown_nmi_panic",
711 .data = &unknown_nmi_panic,
712 .maxlen = sizeof (int),
714 .proc_handler = proc_dointvec,
717 .procname = "nmi_watchdog",
718 .data = &nmi_watchdog_enabled,
719 .maxlen = sizeof (int),
721 .proc_handler = proc_nmi_enabled,
724 #if defined(CONFIG_X86)
726 .procname = "panic_on_unrecovered_nmi",
727 .data = &panic_on_unrecovered_nmi,
728 .maxlen = sizeof(int),
730 .proc_handler = proc_dointvec,
733 .procname = "panic_on_io_nmi",
734 .data = &panic_on_io_nmi,
735 .maxlen = sizeof(int),
737 .proc_handler = proc_dointvec,
740 .procname = "bootloader_type",
741 .data = &bootloader_type,
742 .maxlen = sizeof (int),
744 .proc_handler = proc_dointvec,
747 .procname = "bootloader_version",
748 .data = &bootloader_version,
749 .maxlen = sizeof (int),
751 .proc_handler = proc_dointvec,
754 .procname = "kstack_depth_to_print",
755 .data = &kstack_depth_to_print,
756 .maxlen = sizeof(int),
758 .proc_handler = proc_dointvec,
761 .procname = "io_delay_type",
762 .data = &io_delay_type,
763 .maxlen = sizeof(int),
765 .proc_handler = proc_dointvec,
768 #if defined(CONFIG_MMU)
770 .procname = "randomize_va_space",
771 .data = &randomize_va_space,
772 .maxlen = sizeof(int),
774 .proc_handler = proc_dointvec,
777 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
779 .procname = "spin_retry",
781 .maxlen = sizeof (int),
783 .proc_handler = proc_dointvec,
786 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
788 .procname = "acpi_video_flags",
789 .data = &acpi_realmode_flags,
790 .maxlen = sizeof (unsigned long),
792 .proc_handler = proc_doulongvec_minmax,
797 .procname = "ignore-unaligned-usertrap",
798 .data = &no_unaligned_warning,
799 .maxlen = sizeof (int),
801 .proc_handler = proc_dointvec,
804 .procname = "unaligned-dump-stack",
805 .data = &unaligned_dump_stack,
806 .maxlen = sizeof (int),
808 .proc_handler = proc_dointvec,
811 #ifdef CONFIG_DETECT_SOFTLOCKUP
813 .procname = "softlockup_panic",
814 .data = &softlockup_panic,
815 .maxlen = sizeof(int),
817 .proc_handler = proc_dointvec_minmax,
822 .procname = "softlockup_thresh",
823 .data = &softlockup_thresh,
824 .maxlen = sizeof(int),
826 .proc_handler = proc_dosoftlockup_thresh,
831 #ifdef CONFIG_DETECT_HUNG_TASK
833 .procname = "hung_task_panic",
834 .data = &sysctl_hung_task_panic,
835 .maxlen = sizeof(int),
837 .proc_handler = proc_dointvec_minmax,
842 .procname = "hung_task_check_count",
843 .data = &sysctl_hung_task_check_count,
844 .maxlen = sizeof(unsigned long),
846 .proc_handler = proc_doulongvec_minmax,
849 .procname = "hung_task_timeout_secs",
850 .data = &sysctl_hung_task_timeout_secs,
851 .maxlen = sizeof(unsigned long),
853 .proc_handler = proc_dohung_task_timeout_secs,
856 .procname = "hung_task_warnings",
857 .data = &sysctl_hung_task_warnings,
858 .maxlen = sizeof(unsigned long),
860 .proc_handler = proc_doulongvec_minmax,
865 .procname = "compat-log",
867 .maxlen = sizeof (int),
869 .proc_handler = proc_dointvec,
872 #ifdef CONFIG_RT_MUTEXES
874 .procname = "max_lock_depth",
875 .data = &max_lock_depth,
876 .maxlen = sizeof(int),
878 .proc_handler = proc_dointvec,
882 .procname = "poweroff_cmd",
883 .data = &poweroff_cmd,
884 .maxlen = POWEROFF_CMD_PATH_LEN,
886 .proc_handler = proc_dostring,
892 .child = key_sysctls,
895 #ifdef CONFIG_RCU_TORTURE_TEST
897 .procname = "rcutorture_runnable",
898 .data = &rcutorture_runnable,
899 .maxlen = sizeof(int),
901 .proc_handler = proc_dointvec,
904 #ifdef CONFIG_SLOW_WORK
906 .procname = "slow-work",
908 .child = slow_work_sysctls,
911 #ifdef CONFIG_PERF_EVENTS
913 .procname = "perf_event_paranoid",
914 .data = &sysctl_perf_event_paranoid,
915 .maxlen = sizeof(sysctl_perf_event_paranoid),
917 .proc_handler = proc_dointvec,
920 .procname = "perf_event_mlock_kb",
921 .data = &sysctl_perf_event_mlock,
922 .maxlen = sizeof(sysctl_perf_event_mlock),
924 .proc_handler = proc_dointvec,
927 .procname = "perf_event_max_sample_rate",
928 .data = &sysctl_perf_event_sample_rate,
929 .maxlen = sizeof(sysctl_perf_event_sample_rate),
931 .proc_handler = proc_dointvec,
934 #ifdef CONFIG_KMEMCHECK
936 .procname = "kmemcheck",
937 .data = &kmemcheck_enabled,
938 .maxlen = sizeof(int),
940 .proc_handler = proc_dointvec,
945 .procname = "blk_iopoll",
946 .data = &blk_iopoll_enabled,
947 .maxlen = sizeof(int),
949 .proc_handler = proc_dointvec,
953 * NOTE: do not add new entries to this table unless you have read
954 * Documentation/sysctl/ctl_unnumbered.txt
959 static struct ctl_table vm_table[] = {
961 .procname = "overcommit_memory",
962 .data = &sysctl_overcommit_memory,
963 .maxlen = sizeof(sysctl_overcommit_memory),
965 .proc_handler = proc_dointvec,
968 .procname = "panic_on_oom",
969 .data = &sysctl_panic_on_oom,
970 .maxlen = sizeof(sysctl_panic_on_oom),
972 .proc_handler = proc_dointvec,
975 .procname = "oom_kill_allocating_task",
976 .data = &sysctl_oom_kill_allocating_task,
977 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
979 .proc_handler = proc_dointvec,
982 .procname = "oom_dump_tasks",
983 .data = &sysctl_oom_dump_tasks,
984 .maxlen = sizeof(sysctl_oom_dump_tasks),
986 .proc_handler = proc_dointvec,
989 .procname = "overcommit_ratio",
990 .data = &sysctl_overcommit_ratio,
991 .maxlen = sizeof(sysctl_overcommit_ratio),
993 .proc_handler = proc_dointvec,
996 .procname = "page-cluster",
997 .data = &page_cluster,
998 .maxlen = sizeof(int),
1000 .proc_handler = proc_dointvec,
1003 .procname = "dirty_background_ratio",
1004 .data = &dirty_background_ratio,
1005 .maxlen = sizeof(dirty_background_ratio),
1007 .proc_handler = dirty_background_ratio_handler,
1009 .extra2 = &one_hundred,
1012 .procname = "dirty_background_bytes",
1013 .data = &dirty_background_bytes,
1014 .maxlen = sizeof(dirty_background_bytes),
1016 .proc_handler = dirty_background_bytes_handler,
1020 .procname = "dirty_ratio",
1021 .data = &vm_dirty_ratio,
1022 .maxlen = sizeof(vm_dirty_ratio),
1024 .proc_handler = dirty_ratio_handler,
1026 .extra2 = &one_hundred,
1029 .procname = "dirty_bytes",
1030 .data = &vm_dirty_bytes,
1031 .maxlen = sizeof(vm_dirty_bytes),
1033 .proc_handler = dirty_bytes_handler,
1034 .extra1 = &dirty_bytes_min,
1037 .procname = "dirty_writeback_centisecs",
1038 .data = &dirty_writeback_interval,
1039 .maxlen = sizeof(dirty_writeback_interval),
1041 .proc_handler = dirty_writeback_centisecs_handler,
1044 .procname = "dirty_expire_centisecs",
1045 .data = &dirty_expire_interval,
1046 .maxlen = sizeof(dirty_expire_interval),
1048 .proc_handler = proc_dointvec,
1051 .procname = "nr_pdflush_threads",
1052 .data = &nr_pdflush_threads,
1053 .maxlen = sizeof nr_pdflush_threads,
1054 .mode = 0444 /* read-only*/,
1055 .proc_handler = proc_dointvec,
1058 .procname = "swappiness",
1059 .data = &vm_swappiness,
1060 .maxlen = sizeof(vm_swappiness),
1062 .proc_handler = proc_dointvec_minmax,
1064 .extra2 = &one_hundred,
1066 #ifdef CONFIG_HUGETLB_PAGE
1068 .procname = "nr_hugepages",
1070 .maxlen = sizeof(unsigned long),
1072 .proc_handler = hugetlb_sysctl_handler,
1073 .extra1 = (void *)&hugetlb_zero,
1074 .extra2 = (void *)&hugetlb_infinity,
1078 .procname = "nr_hugepages_mempolicy",
1080 .maxlen = sizeof(unsigned long),
1082 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1083 .extra1 = (void *)&hugetlb_zero,
1084 .extra2 = (void *)&hugetlb_infinity,
1088 .procname = "hugetlb_shm_group",
1089 .data = &sysctl_hugetlb_shm_group,
1090 .maxlen = sizeof(gid_t),
1092 .proc_handler = proc_dointvec,
1095 .procname = "hugepages_treat_as_movable",
1096 .data = &hugepages_treat_as_movable,
1097 .maxlen = sizeof(int),
1099 .proc_handler = hugetlb_treat_movable_handler,
1102 .procname = "nr_overcommit_hugepages",
1104 .maxlen = sizeof(unsigned long),
1106 .proc_handler = hugetlb_overcommit_handler,
1107 .extra1 = (void *)&hugetlb_zero,
1108 .extra2 = (void *)&hugetlb_infinity,
1112 .procname = "lowmem_reserve_ratio",
1113 .data = &sysctl_lowmem_reserve_ratio,
1114 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1116 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1119 .procname = "drop_caches",
1120 .data = &sysctl_drop_caches,
1121 .maxlen = sizeof(int),
1123 .proc_handler = drop_caches_sysctl_handler,
1126 .procname = "min_free_kbytes",
1127 .data = &min_free_kbytes,
1128 .maxlen = sizeof(min_free_kbytes),
1130 .proc_handler = min_free_kbytes_sysctl_handler,
1134 .procname = "percpu_pagelist_fraction",
1135 .data = &percpu_pagelist_fraction,
1136 .maxlen = sizeof(percpu_pagelist_fraction),
1138 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1139 .extra1 = &min_percpu_pagelist_fract,
1143 .procname = "max_map_count",
1144 .data = &sysctl_max_map_count,
1145 .maxlen = sizeof(sysctl_max_map_count),
1147 .proc_handler = proc_dointvec_minmax,
1152 .procname = "nr_trim_pages",
1153 .data = &sysctl_nr_trim_pages,
1154 .maxlen = sizeof(sysctl_nr_trim_pages),
1156 .proc_handler = proc_dointvec_minmax,
1161 .procname = "laptop_mode",
1162 .data = &laptop_mode,
1163 .maxlen = sizeof(laptop_mode),
1165 .proc_handler = proc_dointvec_jiffies,
1168 .procname = "block_dump",
1169 .data = &block_dump,
1170 .maxlen = sizeof(block_dump),
1172 .proc_handler = proc_dointvec,
1176 .procname = "vfs_cache_pressure",
1177 .data = &sysctl_vfs_cache_pressure,
1178 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1180 .proc_handler = proc_dointvec,
1183 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1185 .procname = "legacy_va_layout",
1186 .data = &sysctl_legacy_va_layout,
1187 .maxlen = sizeof(sysctl_legacy_va_layout),
1189 .proc_handler = proc_dointvec,
1195 .procname = "zone_reclaim_mode",
1196 .data = &zone_reclaim_mode,
1197 .maxlen = sizeof(zone_reclaim_mode),
1199 .proc_handler = proc_dointvec,
1203 .procname = "min_unmapped_ratio",
1204 .data = &sysctl_min_unmapped_ratio,
1205 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1207 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1209 .extra2 = &one_hundred,
1212 .procname = "min_slab_ratio",
1213 .data = &sysctl_min_slab_ratio,
1214 .maxlen = sizeof(sysctl_min_slab_ratio),
1216 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1218 .extra2 = &one_hundred,
1223 .procname = "stat_interval",
1224 .data = &sysctl_stat_interval,
1225 .maxlen = sizeof(sysctl_stat_interval),
1227 .proc_handler = proc_dointvec_jiffies,
1232 .procname = "mmap_min_addr",
1233 .data = &dac_mmap_min_addr,
1234 .maxlen = sizeof(unsigned long),
1236 .proc_handler = mmap_min_addr_handler,
1241 .procname = "numa_zonelist_order",
1242 .data = &numa_zonelist_order,
1243 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1245 .proc_handler = numa_zonelist_order_handler,
1248 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1249 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1251 .procname = "vdso_enabled",
1252 .data = &vdso_enabled,
1253 .maxlen = sizeof(vdso_enabled),
1255 .proc_handler = proc_dointvec,
1259 #ifdef CONFIG_HIGHMEM
1261 .procname = "highmem_is_dirtyable",
1262 .data = &vm_highmem_is_dirtyable,
1263 .maxlen = sizeof(vm_highmem_is_dirtyable),
1265 .proc_handler = proc_dointvec_minmax,
1271 .procname = "scan_unevictable_pages",
1272 .data = &scan_unevictable_pages,
1273 .maxlen = sizeof(scan_unevictable_pages),
1275 .proc_handler = scan_unevictable_handler,
1277 #ifdef CONFIG_MEMORY_FAILURE
1279 .procname = "memory_failure_early_kill",
1280 .data = &sysctl_memory_failure_early_kill,
1281 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1283 .proc_handler = proc_dointvec_minmax,
1288 .procname = "memory_failure_recovery",
1289 .data = &sysctl_memory_failure_recovery,
1290 .maxlen = sizeof(sysctl_memory_failure_recovery),
1292 .proc_handler = proc_dointvec_minmax,
1299 * NOTE: do not add new entries to this table unless you have read
1300 * Documentation/sysctl/ctl_unnumbered.txt
1305 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1306 static struct ctl_table binfmt_misc_table[] = {
1311 static struct ctl_table fs_table[] = {
1313 .procname = "inode-nr",
1314 .data = &inodes_stat,
1315 .maxlen = 2*sizeof(int),
1317 .proc_handler = proc_dointvec,
1320 .procname = "inode-state",
1321 .data = &inodes_stat,
1322 .maxlen = 7*sizeof(int),
1324 .proc_handler = proc_dointvec,
1327 .procname = "file-nr",
1328 .data = &files_stat,
1329 .maxlen = 3*sizeof(int),
1331 .proc_handler = proc_nr_files,
1334 .procname = "file-max",
1335 .data = &files_stat.max_files,
1336 .maxlen = sizeof(int),
1338 .proc_handler = proc_dointvec,
1341 .procname = "nr_open",
1342 .data = &sysctl_nr_open,
1343 .maxlen = sizeof(int),
1345 .proc_handler = proc_dointvec_minmax,
1346 .extra1 = &sysctl_nr_open_min,
1347 .extra2 = &sysctl_nr_open_max,
1350 .procname = "dentry-state",
1351 .data = &dentry_stat,
1352 .maxlen = 6*sizeof(int),
1354 .proc_handler = proc_dointvec,
1357 .procname = "overflowuid",
1358 .data = &fs_overflowuid,
1359 .maxlen = sizeof(int),
1361 .proc_handler = proc_dointvec_minmax,
1362 .extra1 = &minolduid,
1363 .extra2 = &maxolduid,
1366 .procname = "overflowgid",
1367 .data = &fs_overflowgid,
1368 .maxlen = sizeof(int),
1370 .proc_handler = proc_dointvec_minmax,
1371 .extra1 = &minolduid,
1372 .extra2 = &maxolduid,
1374 #ifdef CONFIG_FILE_LOCKING
1376 .procname = "leases-enable",
1377 .data = &leases_enable,
1378 .maxlen = sizeof(int),
1380 .proc_handler = proc_dointvec,
1383 #ifdef CONFIG_DNOTIFY
1385 .procname = "dir-notify-enable",
1386 .data = &dir_notify_enable,
1387 .maxlen = sizeof(int),
1389 .proc_handler = proc_dointvec,
1393 #ifdef CONFIG_FILE_LOCKING
1395 .procname = "lease-break-time",
1396 .data = &lease_break_time,
1397 .maxlen = sizeof(int),
1399 .proc_handler = proc_dointvec,
1404 .procname = "aio-nr",
1406 .maxlen = sizeof(aio_nr),
1408 .proc_handler = proc_doulongvec_minmax,
1411 .procname = "aio-max-nr",
1412 .data = &aio_max_nr,
1413 .maxlen = sizeof(aio_max_nr),
1415 .proc_handler = proc_doulongvec_minmax,
1417 #endif /* CONFIG_AIO */
1418 #ifdef CONFIG_INOTIFY_USER
1420 .procname = "inotify",
1422 .child = inotify_table,
1427 .procname = "epoll",
1429 .child = epoll_table,
1434 .procname = "suid_dumpable",
1435 .data = &suid_dumpable,
1436 .maxlen = sizeof(int),
1438 .proc_handler = proc_dointvec_minmax,
1442 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1444 .procname = "binfmt_misc",
1446 .child = binfmt_misc_table,
1450 * NOTE: do not add new entries to this table unless you have read
1451 * Documentation/sysctl/ctl_unnumbered.txt
1456 static struct ctl_table debug_table[] = {
1457 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1459 .procname = "exception-trace",
1460 .data = &show_unhandled_signals,
1461 .maxlen = sizeof(int),
1463 .proc_handler = proc_dointvec
1469 static struct ctl_table dev_table[] = {
1473 static DEFINE_SPINLOCK(sysctl_lock);
1475 /* called under sysctl_lock */
1476 static int use_table(struct ctl_table_header *p)
1478 if (unlikely(p->unregistering))
1484 /* called under sysctl_lock */
1485 static void unuse_table(struct ctl_table_header *p)
1488 if (unlikely(p->unregistering))
1489 complete(p->unregistering);
1492 /* called under sysctl_lock, will reacquire if has to wait */
1493 static void start_unregistering(struct ctl_table_header *p)
1496 * if p->used is 0, nobody will ever touch that entry again;
1497 * we'll eliminate all paths to it before dropping sysctl_lock
1499 if (unlikely(p->used)) {
1500 struct completion wait;
1501 init_completion(&wait);
1502 p->unregistering = &wait;
1503 spin_unlock(&sysctl_lock);
1504 wait_for_completion(&wait);
1505 spin_lock(&sysctl_lock);
1507 /* anything non-NULL; we'll never dereference it */
1508 p->unregistering = ERR_PTR(-EINVAL);
1511 * do not remove from the list until nobody holds it; walking the
1512 * list in do_sysctl() relies on that.
1514 list_del_init(&p->ctl_entry);
1517 void sysctl_head_get(struct ctl_table_header *head)
1519 spin_lock(&sysctl_lock);
1521 spin_unlock(&sysctl_lock);
1524 void sysctl_head_put(struct ctl_table_header *head)
1526 spin_lock(&sysctl_lock);
1529 spin_unlock(&sysctl_lock);
1532 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1536 spin_lock(&sysctl_lock);
1537 if (!use_table(head))
1538 head = ERR_PTR(-ENOENT);
1539 spin_unlock(&sysctl_lock);
1543 void sysctl_head_finish(struct ctl_table_header *head)
1547 spin_lock(&sysctl_lock);
1549 spin_unlock(&sysctl_lock);
1552 static struct ctl_table_set *
1553 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1555 struct ctl_table_set *set = &root->default_set;
1557 set = root->lookup(root, namespaces);
1561 static struct list_head *
1562 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1564 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1568 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1569 struct ctl_table_header *prev)
1571 struct ctl_table_root *root;
1572 struct list_head *header_list;
1573 struct ctl_table_header *head;
1574 struct list_head *tmp;
1576 spin_lock(&sysctl_lock);
1579 tmp = &prev->ctl_entry;
1583 tmp = &root_table_header.ctl_entry;
1585 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1587 if (!use_table(head))
1589 spin_unlock(&sysctl_lock);
1594 header_list = lookup_header_list(root, namespaces);
1595 if (tmp != header_list)
1599 root = list_entry(root->root_list.next,
1600 struct ctl_table_root, root_list);
1601 if (root == &sysctl_table_root)
1603 header_list = lookup_header_list(root, namespaces);
1604 } while (list_empty(header_list));
1605 tmp = header_list->next;
1608 spin_unlock(&sysctl_lock);
1612 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1614 return __sysctl_head_next(current->nsproxy, prev);
1617 void register_sysctl_root(struct ctl_table_root *root)
1619 spin_lock(&sysctl_lock);
1620 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1621 spin_unlock(&sysctl_lock);
1625 * sysctl_perm does NOT grant the superuser all rights automatically, because
1626 * some sysctl variables are readonly even to root.
1629 static int test_perm(int mode, int op)
1631 if (!current_euid())
1633 else if (in_egroup_p(0))
1635 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1640 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1645 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1649 if (root->permissions)
1650 mode = root->permissions(root, current->nsproxy, table);
1654 return test_perm(mode, op);
1657 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1659 for (; table->procname; table++) {
1660 table->parent = parent;
1662 sysctl_set_parent(table, table->child);
1666 static __init int sysctl_init(void)
1668 sysctl_set_parent(NULL, root_table);
1669 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1672 err = sysctl_check_table(current->nsproxy, root_table);
1678 core_initcall(sysctl_init);
1680 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1681 struct ctl_table *table)
1683 struct ctl_table *p;
1684 const char *s = branch->procname;
1686 /* branch should have named subdirectory as its first element */
1687 if (!s || !branch->child)
1690 /* ... and nothing else */
1691 if (branch[1].procname)
1694 /* table should contain subdirectory with the same name */
1695 for (p = table; p->procname; p++) {
1698 if (p->procname && strcmp(p->procname, s) == 0)
1704 /* see if attaching q to p would be an improvement */
1705 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1707 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1708 struct ctl_table *next;
1710 int not_in_parent = !p->attached_by;
1712 while ((next = is_branch_in(by, to)) != NULL) {
1713 if (by == q->attached_by)
1715 if (to == p->attached_by)
1721 if (is_better && not_in_parent) {
1722 q->attached_by = by;
1723 q->attached_to = to;
1729 * __register_sysctl_paths - register a sysctl hierarchy
1730 * @root: List of sysctl headers to register on
1731 * @namespaces: Data to compute which lists of sysctl entries are visible
1732 * @path: The path to the directory the sysctl table is in.
1733 * @table: the top-level table structure
1735 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1736 * array. A completely 0 filled entry terminates the table.
1738 * The members of the &struct ctl_table structure are used as follows:
1740 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1741 * enter a sysctl file
1743 * data - a pointer to data for use by proc_handler
1745 * maxlen - the maximum size in bytes of the data
1747 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1749 * child - a pointer to the child sysctl table if this entry is a directory, or
1752 * proc_handler - the text handler routine (described below)
1754 * de - for internal use by the sysctl routines
1756 * extra1, extra2 - extra pointers usable by the proc handler routines
1758 * Leaf nodes in the sysctl tree will be represented by a single file
1759 * under /proc; non-leaf nodes will be represented by directories.
1761 * sysctl(2) can automatically manage read and write requests through
1762 * the sysctl table. The data and maxlen fields of the ctl_table
1763 * struct enable minimal validation of the values being written to be
1764 * performed, and the mode field allows minimal authentication.
1766 * There must be a proc_handler routine for any terminal nodes
1767 * mirrored under /proc/sys (non-terminals are handled by a built-in
1768 * directory handler). Several default handlers are available to
1769 * cover common cases -
1771 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1772 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1773 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1775 * It is the handler's job to read the input buffer from user memory
1776 * and process it. The handler should return 0 on success.
1778 * This routine returns %NULL on a failure to register, and a pointer
1779 * to the table header on success.
1781 struct ctl_table_header *__register_sysctl_paths(
1782 struct ctl_table_root *root,
1783 struct nsproxy *namespaces,
1784 const struct ctl_path *path, struct ctl_table *table)
1786 struct ctl_table_header *header;
1787 struct ctl_table *new, **prevp;
1788 unsigned int n, npath;
1789 struct ctl_table_set *set;
1791 /* Count the path components */
1792 for (npath = 0; path[npath].procname; ++npath)
1796 * For each path component, allocate a 2-element ctl_table array.
1797 * The first array element will be filled with the sysctl entry
1798 * for this, the second will be the sentinel (procname == 0).
1800 * We allocate everything in one go so that we don't have to
1801 * worry about freeing additional memory in unregister_sysctl_table.
1803 header = kzalloc(sizeof(struct ctl_table_header) +
1804 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1808 new = (struct ctl_table *) (header + 1);
1810 /* Now connect the dots */
1811 prevp = &header->ctl_table;
1812 for (n = 0; n < npath; ++n, ++path) {
1813 /* Copy the procname */
1814 new->procname = path->procname;
1818 prevp = &new->child;
1823 header->ctl_table_arg = table;
1825 INIT_LIST_HEAD(&header->ctl_entry);
1827 header->unregistering = NULL;
1828 header->root = root;
1829 sysctl_set_parent(NULL, header->ctl_table);
1831 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1832 if (sysctl_check_table(namespaces, header->ctl_table)) {
1837 spin_lock(&sysctl_lock);
1838 header->set = lookup_header_set(root, namespaces);
1839 header->attached_by = header->ctl_table;
1840 header->attached_to = root_table;
1841 header->parent = &root_table_header;
1842 for (set = header->set; set; set = set->parent) {
1843 struct ctl_table_header *p;
1844 list_for_each_entry(p, &set->list, ctl_entry) {
1845 if (p->unregistering)
1847 try_attach(p, header);
1850 header->parent->count++;
1851 list_add_tail(&header->ctl_entry, &header->set->list);
1852 spin_unlock(&sysctl_lock);
1858 * register_sysctl_table_path - register a sysctl table hierarchy
1859 * @path: The path to the directory the sysctl table is in.
1860 * @table: the top-level table structure
1862 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1863 * array. A completely 0 filled entry terminates the table.
1865 * See __register_sysctl_paths for more details.
1867 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1868 struct ctl_table *table)
1870 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1875 * register_sysctl_table - register a sysctl table hierarchy
1876 * @table: the top-level table structure
1878 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1879 * array. A completely 0 filled entry terminates the table.
1881 * See register_sysctl_paths for more details.
1883 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1885 static const struct ctl_path null_path[] = { {} };
1887 return register_sysctl_paths(null_path, table);
1891 * unregister_sysctl_table - unregister a sysctl table hierarchy
1892 * @header: the header returned from register_sysctl_table
1894 * Unregisters the sysctl table and all children. proc entries may not
1895 * actually be removed until they are no longer used by anyone.
1897 void unregister_sysctl_table(struct ctl_table_header * header)
1904 spin_lock(&sysctl_lock);
1905 start_unregistering(header);
1906 if (!--header->parent->count) {
1908 kfree(header->parent);
1910 if (!--header->count)
1912 spin_unlock(&sysctl_lock);
1915 int sysctl_is_seen(struct ctl_table_header *p)
1917 struct ctl_table_set *set = p->set;
1919 spin_lock(&sysctl_lock);
1920 if (p->unregistering)
1922 else if (!set->is_seen)
1925 res = set->is_seen(set);
1926 spin_unlock(&sysctl_lock);
1930 void setup_sysctl_set(struct ctl_table_set *p,
1931 struct ctl_table_set *parent,
1932 int (*is_seen)(struct ctl_table_set *))
1934 INIT_LIST_HEAD(&p->list);
1935 p->parent = parent ? parent : &sysctl_table_root.default_set;
1936 p->is_seen = is_seen;
1939 #else /* !CONFIG_SYSCTL */
1940 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1945 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1946 struct ctl_table *table)
1951 void unregister_sysctl_table(struct ctl_table_header * table)
1955 void setup_sysctl_set(struct ctl_table_set *p,
1956 struct ctl_table_set *parent,
1957 int (*is_seen)(struct ctl_table_set *))
1961 void sysctl_head_put(struct ctl_table_header *head)
1965 #endif /* CONFIG_SYSCTL */
1971 #ifdef CONFIG_PROC_SYSCTL
1973 static int _proc_do_string(void* data, int maxlen, int write,
1974 void __user *buffer,
1975 size_t *lenp, loff_t *ppos)
1981 if (!data || !maxlen || !*lenp) {
1989 while (len < *lenp) {
1990 if (get_user(c, p++))
1992 if (c == 0 || c == '\n')
1998 if(copy_from_user(data, buffer, len))
2000 ((char *) data)[len] = 0;
2018 if(copy_to_user(buffer, data, len))
2021 if(put_user('\n', ((char __user *) buffer) + len))
2032 * proc_dostring - read a string sysctl
2033 * @table: the sysctl table
2034 * @write: %TRUE if this is a write to the sysctl file
2035 * @buffer: the user buffer
2036 * @lenp: the size of the user buffer
2037 * @ppos: file position
2039 * Reads/writes a string from/to the user buffer. If the kernel
2040 * buffer provided is not large enough to hold the string, the
2041 * string is truncated. The copied string is %NULL-terminated.
2042 * If the string is being read by the user process, it is copied
2043 * and a newline '\n' is added. It is truncated if the buffer is
2046 * Returns 0 on success.
2048 int proc_dostring(struct ctl_table *table, int write,
2049 void __user *buffer, size_t *lenp, loff_t *ppos)
2051 return _proc_do_string(table->data, table->maxlen, write,
2052 buffer, lenp, ppos);
2056 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2058 int write, void *data)
2061 *valp = *negp ? -*lvalp : *lvalp;
2066 *lvalp = (unsigned long)-val;
2069 *lvalp = (unsigned long)val;
2075 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2076 int write, void __user *buffer,
2077 size_t *lenp, loff_t *ppos,
2078 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2079 int write, void *data),
2082 #define TMPBUFLEN 21
2083 int *i, vleft, first = 1, neg;
2087 char buf[TMPBUFLEN], *p;
2088 char __user *s = buffer;
2090 if (!tbl_data || !table->maxlen || !*lenp ||
2091 (*ppos && !write)) {
2096 i = (int *) tbl_data;
2097 vleft = table->maxlen / sizeof(*i);
2101 conv = do_proc_dointvec_conv;
2103 for (; left && vleft--; i++, first=0) {
2118 if (len > sizeof(buf) - 1)
2119 len = sizeof(buf) - 1;
2120 if (copy_from_user(buf, s, len))
2124 if (*p == '-' && left > 1) {
2128 if (*p < '0' || *p > '9')
2131 lval = simple_strtoul(p, &p, 0);
2134 if ((len < left) && *p && !isspace(*p))
2139 if (conv(&neg, &lval, i, 1, data))
2146 if (conv(&neg, &lval, i, 0, data))
2149 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2153 if(copy_to_user(s, buf, len))
2160 if (!write && !first && left) {
2161 if(put_user('\n', s))
2168 if (get_user(c, s++))
2183 static int do_proc_dointvec(struct ctl_table *table, int write,
2184 void __user *buffer, size_t *lenp, loff_t *ppos,
2185 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2186 int write, void *data),
2189 return __do_proc_dointvec(table->data, table, write,
2190 buffer, lenp, ppos, conv, data);
2194 * proc_dointvec - read a vector of integers
2195 * @table: the sysctl table
2196 * @write: %TRUE if this is a write to the sysctl file
2197 * @buffer: the user buffer
2198 * @lenp: the size of the user buffer
2199 * @ppos: file position
2201 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2202 * values from/to the user buffer, treated as an ASCII string.
2204 * Returns 0 on success.
2206 int proc_dointvec(struct ctl_table *table, int write,
2207 void __user *buffer, size_t *lenp, loff_t *ppos)
2209 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2214 * Taint values can only be increased
2215 * This means we can safely use a temporary.
2217 static int proc_taint(struct ctl_table *table, int write,
2218 void __user *buffer, size_t *lenp, loff_t *ppos)
2221 unsigned long tmptaint = get_taint();
2224 if (write && !capable(CAP_SYS_ADMIN))
2229 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2235 * Poor man's atomic or. Not worth adding a primitive
2236 * to everyone's atomic.h for this
2239 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2240 if ((tmptaint >> i) & 1)
2248 struct do_proc_dointvec_minmax_conv_param {
2253 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2255 int write, void *data)
2257 struct do_proc_dointvec_minmax_conv_param *param = data;
2259 int val = *negp ? -*lvalp : *lvalp;
2260 if ((param->min && *param->min > val) ||
2261 (param->max && *param->max < val))
2268 *lvalp = (unsigned long)-val;
2271 *lvalp = (unsigned long)val;
2278 * proc_dointvec_minmax - read a vector of integers with min/max values
2279 * @table: the sysctl table
2280 * @write: %TRUE if this is a write to the sysctl file
2281 * @buffer: the user buffer
2282 * @lenp: the size of the user buffer
2283 * @ppos: file position
2285 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2286 * values from/to the user buffer, treated as an ASCII string.
2288 * This routine will ensure the values are within the range specified by
2289 * table->extra1 (min) and table->extra2 (max).
2291 * Returns 0 on success.
2293 int proc_dointvec_minmax(struct ctl_table *table, int write,
2294 void __user *buffer, size_t *lenp, loff_t *ppos)
2296 struct do_proc_dointvec_minmax_conv_param param = {
2297 .min = (int *) table->extra1,
2298 .max = (int *) table->extra2,
2300 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2301 do_proc_dointvec_minmax_conv, ¶m);
2304 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2305 void __user *buffer,
2306 size_t *lenp, loff_t *ppos,
2307 unsigned long convmul,
2308 unsigned long convdiv)
2310 #define TMPBUFLEN 21
2311 unsigned long *i, *min, *max, val;
2312 int vleft, first=1, neg;
2314 char buf[TMPBUFLEN], *p;
2315 char __user *s = buffer;
2317 if (!data || !table->maxlen || !*lenp ||
2318 (*ppos && !write)) {
2323 i = (unsigned long *) data;
2324 min = (unsigned long *) table->extra1;
2325 max = (unsigned long *) table->extra2;
2326 vleft = table->maxlen / sizeof(unsigned long);
2329 for (; left && vleft--; i++, min++, max++, first=0) {
2344 if (len > TMPBUFLEN-1)
2346 if (copy_from_user(buf, s, len))
2350 if (*p == '-' && left > 1) {
2354 if (*p < '0' || *p > '9')
2356 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2358 if ((len < left) && *p && !isspace(*p))
2367 if ((min && val < *min) || (max && val > *max))
2374 sprintf(p, "%lu", convdiv * (*i) / convmul);
2378 if(copy_to_user(s, buf, len))
2385 if (!write && !first && left) {
2386 if(put_user('\n', s))
2393 if (get_user(c, s++))
2408 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2409 void __user *buffer,
2410 size_t *lenp, loff_t *ppos,
2411 unsigned long convmul,
2412 unsigned long convdiv)
2414 return __do_proc_doulongvec_minmax(table->data, table, write,
2415 buffer, lenp, ppos, convmul, convdiv);
2419 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2420 * @table: the sysctl table
2421 * @write: %TRUE if this is a write to the sysctl file
2422 * @buffer: the user buffer
2423 * @lenp: the size of the user buffer
2424 * @ppos: file position
2426 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2427 * values from/to the user buffer, treated as an ASCII string.
2429 * This routine will ensure the values are within the range specified by
2430 * table->extra1 (min) and table->extra2 (max).
2432 * Returns 0 on success.
2434 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2435 void __user *buffer, size_t *lenp, loff_t *ppos)
2437 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2441 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2442 * @table: the sysctl table
2443 * @write: %TRUE if this is a write to the sysctl file
2444 * @buffer: the user buffer
2445 * @lenp: the size of the user buffer
2446 * @ppos: file position
2448 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2449 * values from/to the user buffer, treated as an ASCII string. The values
2450 * are treated as milliseconds, and converted to jiffies when they are stored.
2452 * This routine will ensure the values are within the range specified by
2453 * table->extra1 (min) and table->extra2 (max).
2455 * Returns 0 on success.
2457 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2458 void __user *buffer,
2459 size_t *lenp, loff_t *ppos)
2461 return do_proc_doulongvec_minmax(table, write, buffer,
2462 lenp, ppos, HZ, 1000l);
2466 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2468 int write, void *data)
2471 if (*lvalp > LONG_MAX / HZ)
2473 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2479 lval = (unsigned long)-val;
2482 lval = (unsigned long)val;
2489 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2491 int write, void *data)
2494 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2496 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2502 lval = (unsigned long)-val;
2505 lval = (unsigned long)val;
2507 *lvalp = jiffies_to_clock_t(lval);
2512 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2514 int write, void *data)
2517 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2523 lval = (unsigned long)-val;
2526 lval = (unsigned long)val;
2528 *lvalp = jiffies_to_msecs(lval);
2534 * proc_dointvec_jiffies - read a vector of integers as seconds
2535 * @table: the sysctl table
2536 * @write: %TRUE if this is a write to the sysctl file
2537 * @buffer: the user buffer
2538 * @lenp: the size of the user buffer
2539 * @ppos: file position
2541 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2542 * values from/to the user buffer, treated as an ASCII string.
2543 * The values read are assumed to be in seconds, and are converted into
2546 * Returns 0 on success.
2548 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2549 void __user *buffer, size_t *lenp, loff_t *ppos)
2551 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2552 do_proc_dointvec_jiffies_conv,NULL);
2556 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2557 * @table: the sysctl table
2558 * @write: %TRUE if this is a write to the sysctl file
2559 * @buffer: the user buffer
2560 * @lenp: the size of the user buffer
2561 * @ppos: pointer to the file position
2563 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2564 * values from/to the user buffer, treated as an ASCII string.
2565 * The values read are assumed to be in 1/USER_HZ seconds, and
2566 * are converted into jiffies.
2568 * Returns 0 on success.
2570 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2571 void __user *buffer, size_t *lenp, loff_t *ppos)
2573 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2574 do_proc_dointvec_userhz_jiffies_conv,NULL);
2578 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2579 * @table: the sysctl table
2580 * @write: %TRUE if this is a write to the sysctl file
2581 * @buffer: the user buffer
2582 * @lenp: the size of the user buffer
2583 * @ppos: file position
2584 * @ppos: the current position in the file
2586 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2587 * values from/to the user buffer, treated as an ASCII string.
2588 * The values read are assumed to be in 1/1000 seconds, and
2589 * are converted into jiffies.
2591 * Returns 0 on success.
2593 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2594 void __user *buffer, size_t *lenp, loff_t *ppos)
2596 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2597 do_proc_dointvec_ms_jiffies_conv, NULL);
2600 static int proc_do_cad_pid(struct ctl_table *table, int write,
2601 void __user *buffer, size_t *lenp, loff_t *ppos)
2603 struct pid *new_pid;
2607 tmp = pid_vnr(cad_pid);
2609 r = __do_proc_dointvec(&tmp, table, write, buffer,
2610 lenp, ppos, NULL, NULL);
2614 new_pid = find_get_pid(tmp);
2618 put_pid(xchg(&cad_pid, new_pid));
2622 #else /* CONFIG_PROC_FS */
2624 int proc_dostring(struct ctl_table *table, int write,
2625 void __user *buffer, size_t *lenp, loff_t *ppos)
2630 int proc_dointvec(struct ctl_table *table, int write,
2631 void __user *buffer, size_t *lenp, loff_t *ppos)
2636 int proc_dointvec_minmax(struct ctl_table *table, int write,
2637 void __user *buffer, size_t *lenp, loff_t *ppos)
2642 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2643 void __user *buffer, size_t *lenp, loff_t *ppos)
2648 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2649 void __user *buffer, size_t *lenp, loff_t *ppos)
2654 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2655 void __user *buffer, size_t *lenp, loff_t *ppos)
2660 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2661 void __user *buffer, size_t *lenp, loff_t *ppos)
2666 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2667 void __user *buffer,
2668 size_t *lenp, loff_t *ppos)
2674 #endif /* CONFIG_PROC_FS */
2677 * No sense putting this after each symbol definition, twice,
2678 * exception granted :-)
2680 EXPORT_SYMBOL(proc_dointvec);
2681 EXPORT_SYMBOL(proc_dointvec_jiffies);
2682 EXPORT_SYMBOL(proc_dointvec_minmax);
2683 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2684 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2685 EXPORT_SYMBOL(proc_dostring);
2686 EXPORT_SYMBOL(proc_doulongvec_minmax);
2687 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2688 EXPORT_SYMBOL(register_sysctl_table);
2689 EXPORT_SYMBOL(register_sysctl_paths);
2690 EXPORT_SYMBOL(unregister_sysctl_table);