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/signal.h>
27 #include <linux/proc_fs.h>
28 #include <linux/security.h>
29 #include <linux/ctype.h>
30 #include <linux/kmemcheck.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/ratelimit.h>
40 #include <linux/hugetlb.h>
41 #include <linux/initrd.h>
42 #include <linux/key.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/vmstat.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/acpi.h>
50 #include <linux/reboot.h>
51 #include <linux/ftrace.h>
52 #include <linux/slow-work.h>
53 #include <linux/perf_event.h>
54 #include <linux/kprobes.h>
56 #include <asm/uaccess.h>
57 #include <asm/processor.h>
61 #include <asm/stacktrace.h>
64 #ifdef CONFIG_CHR_DEV_SG
69 #if defined(CONFIG_SYSCTL)
71 /* External variables not in a header file. */
72 extern int sysctl_overcommit_memory;
73 extern int sysctl_overcommit_ratio;
74 extern int sysctl_panic_on_oom;
75 extern int sysctl_oom_kill_allocating_task;
76 extern int sysctl_oom_dump_tasks;
77 extern int max_threads;
78 extern int core_uses_pid;
79 extern int suid_dumpable;
80 extern char core_pattern[];
81 extern unsigned int core_pipe_limit;
83 extern int min_free_kbytes;
84 extern int pid_max_min, pid_max_max;
85 extern int sysctl_drop_caches;
86 extern int percpu_pagelist_fraction;
87 extern int compat_log;
88 extern int latencytop_enabled;
89 extern int sysctl_nr_open_min, sysctl_nr_open_max;
91 extern int sysctl_nr_trim_pages;
94 extern int blk_iopoll_enabled;
97 /* Constants used for minimum and maximum */
98 #ifdef CONFIG_DETECT_SOFTLOCKUP
99 static int sixty = 60;
100 static int neg_one = -1;
104 static int __maybe_unused one = 1;
105 static int __maybe_unused two = 2;
106 static unsigned long one_ul = 1;
107 static int one_hundred = 100;
109 static int ten_thousand = 10000;
112 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
113 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
115 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
116 static int maxolduid = 65535;
117 static int minolduid;
118 static int min_percpu_pagelist_fract = 8;
120 static int ngroups_max = NGROUPS_MAX;
123 #include <asm/system.h>
126 #ifdef CONFIG_SPARC64
127 extern int sysctl_tsb_ratio;
131 extern int pwrsw_enabled;
132 extern int unaligned_enabled;
136 #ifdef CONFIG_MATHEMU
137 extern int sysctl_ieee_emulation_warnings;
139 extern int sysctl_userprocess_debug;
140 extern int spin_retry;
143 #ifdef CONFIG_BSD_PROCESS_ACCT
144 extern int acct_parm[];
148 extern int no_unaligned_warning;
149 extern int unaligned_dump_stack;
152 extern struct ratelimit_state printk_ratelimit_state;
154 #ifdef CONFIG_RT_MUTEXES
155 extern int max_lock_depth;
158 #ifdef CONFIG_PROC_SYSCTL
159 static int proc_do_cad_pid(struct ctl_table *table, int write,
160 void __user *buffer, size_t *lenp, loff_t *ppos);
161 static int proc_taint(struct ctl_table *table, int write,
162 void __user *buffer, size_t *lenp, loff_t *ppos);
165 static struct ctl_table root_table[];
166 static struct ctl_table_root sysctl_table_root;
167 static struct ctl_table_header root_table_header = {
169 .ctl_table = root_table,
170 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
171 .root = &sysctl_table_root,
172 .set = &sysctl_table_root.default_set,
174 static struct ctl_table_root sysctl_table_root = {
175 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
176 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
179 static struct ctl_table kern_table[];
180 static struct ctl_table vm_table[];
181 static struct ctl_table fs_table[];
182 static struct ctl_table debug_table[];
183 static struct ctl_table dev_table[];
184 extern struct ctl_table random_table[];
185 #ifdef CONFIG_INOTIFY_USER
186 extern struct ctl_table inotify_table[];
189 extern struct ctl_table epoll_table[];
192 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
193 int sysctl_legacy_va_layout;
196 extern int prove_locking;
197 extern int lock_stat;
199 /* The default sysctl tables: */
201 static struct ctl_table root_table[] = {
203 .procname = "kernel",
220 .child = debug_table,
228 * NOTE: do not add new entries to this table unless you have read
229 * Documentation/sysctl/ctl_unnumbered.txt
234 #ifdef CONFIG_SCHED_DEBUG
235 static int min_sched_granularity_ns = 100000; /* 100 usecs */
236 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
237 static int min_wakeup_granularity_ns; /* 0 usecs */
238 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
239 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
240 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
241 static int min_sched_shares_ratelimit = 100000; /* 100 usec */
242 static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
245 static struct ctl_table kern_table[] = {
247 .procname = "sched_child_runs_first",
248 .data = &sysctl_sched_child_runs_first,
249 .maxlen = sizeof(unsigned int),
251 .proc_handler = proc_dointvec,
253 #ifdef CONFIG_SCHED_DEBUG
255 .procname = "sched_min_granularity_ns",
256 .data = &sysctl_sched_min_granularity,
257 .maxlen = sizeof(unsigned int),
259 .proc_handler = sched_proc_update_handler,
260 .extra1 = &min_sched_granularity_ns,
261 .extra2 = &max_sched_granularity_ns,
264 .procname = "sched_latency_ns",
265 .data = &sysctl_sched_latency,
266 .maxlen = sizeof(unsigned int),
268 .proc_handler = sched_proc_update_handler,
269 .extra1 = &min_sched_granularity_ns,
270 .extra2 = &max_sched_granularity_ns,
273 .procname = "sched_wakeup_granularity_ns",
274 .data = &sysctl_sched_wakeup_granularity,
275 .maxlen = sizeof(unsigned int),
277 .proc_handler = sched_proc_update_handler,
278 .extra1 = &min_wakeup_granularity_ns,
279 .extra2 = &max_wakeup_granularity_ns,
282 .procname = "sched_shares_ratelimit",
283 .data = &sysctl_sched_shares_ratelimit,
284 .maxlen = sizeof(unsigned int),
286 .proc_handler = sched_proc_update_handler,
287 .extra1 = &min_sched_shares_ratelimit,
288 .extra2 = &max_sched_shares_ratelimit,
291 .procname = "sched_tunable_scaling",
292 .data = &sysctl_sched_tunable_scaling,
293 .maxlen = sizeof(enum sched_tunable_scaling),
295 .proc_handler = sched_proc_update_handler,
296 .extra1 = &min_sched_tunable_scaling,
297 .extra2 = &max_sched_tunable_scaling,
300 .procname = "sched_shares_thresh",
301 .data = &sysctl_sched_shares_thresh,
302 .maxlen = sizeof(unsigned int),
304 .proc_handler = proc_dointvec_minmax,
308 .procname = "sched_migration_cost",
309 .data = &sysctl_sched_migration_cost,
310 .maxlen = sizeof(unsigned int),
312 .proc_handler = proc_dointvec,
315 .procname = "sched_nr_migrate",
316 .data = &sysctl_sched_nr_migrate,
317 .maxlen = sizeof(unsigned int),
319 .proc_handler = proc_dointvec,
322 .procname = "sched_time_avg",
323 .data = &sysctl_sched_time_avg,
324 .maxlen = sizeof(unsigned int),
326 .proc_handler = proc_dointvec,
329 .procname = "timer_migration",
330 .data = &sysctl_timer_migration,
331 .maxlen = sizeof(unsigned int),
333 .proc_handler = proc_dointvec_minmax,
339 .procname = "sched_rt_period_us",
340 .data = &sysctl_sched_rt_period,
341 .maxlen = sizeof(unsigned int),
343 .proc_handler = sched_rt_handler,
346 .procname = "sched_rt_runtime_us",
347 .data = &sysctl_sched_rt_runtime,
348 .maxlen = sizeof(int),
350 .proc_handler = sched_rt_handler,
353 .procname = "sched_compat_yield",
354 .data = &sysctl_sched_compat_yield,
355 .maxlen = sizeof(unsigned int),
357 .proc_handler = proc_dointvec,
359 #ifdef CONFIG_PROVE_LOCKING
361 .procname = "prove_locking",
362 .data = &prove_locking,
363 .maxlen = sizeof(int),
365 .proc_handler = proc_dointvec,
368 #ifdef CONFIG_LOCK_STAT
370 .procname = "lock_stat",
372 .maxlen = sizeof(int),
374 .proc_handler = proc_dointvec,
379 .data = &panic_timeout,
380 .maxlen = sizeof(int),
382 .proc_handler = proc_dointvec,
385 .procname = "core_uses_pid",
386 .data = &core_uses_pid,
387 .maxlen = sizeof(int),
389 .proc_handler = proc_dointvec,
392 .procname = "core_pattern",
393 .data = core_pattern,
394 .maxlen = CORENAME_MAX_SIZE,
396 .proc_handler = proc_dostring,
399 .procname = "core_pipe_limit",
400 .data = &core_pipe_limit,
401 .maxlen = sizeof(unsigned int),
403 .proc_handler = proc_dointvec,
405 #ifdef CONFIG_PROC_SYSCTL
407 .procname = "tainted",
408 .maxlen = sizeof(long),
410 .proc_handler = proc_taint,
413 #ifdef CONFIG_LATENCYTOP
415 .procname = "latencytop",
416 .data = &latencytop_enabled,
417 .maxlen = sizeof(int),
419 .proc_handler = proc_dointvec,
422 #ifdef CONFIG_BLK_DEV_INITRD
424 .procname = "real-root-dev",
425 .data = &real_root_dev,
426 .maxlen = sizeof(int),
428 .proc_handler = proc_dointvec,
432 .procname = "print-fatal-signals",
433 .data = &print_fatal_signals,
434 .maxlen = sizeof(int),
436 .proc_handler = proc_dointvec,
440 .procname = "reboot-cmd",
441 .data = reboot_command,
444 .proc_handler = proc_dostring,
447 .procname = "stop-a",
448 .data = &stop_a_enabled,
449 .maxlen = sizeof (int),
451 .proc_handler = proc_dointvec,
454 .procname = "scons-poweroff",
455 .data = &scons_pwroff,
456 .maxlen = sizeof (int),
458 .proc_handler = proc_dointvec,
461 #ifdef CONFIG_SPARC64
463 .procname = "tsb-ratio",
464 .data = &sysctl_tsb_ratio,
465 .maxlen = sizeof (int),
467 .proc_handler = proc_dointvec,
472 .procname = "soft-power",
473 .data = &pwrsw_enabled,
474 .maxlen = sizeof (int),
476 .proc_handler = proc_dointvec,
479 .procname = "unaligned-trap",
480 .data = &unaligned_enabled,
481 .maxlen = sizeof (int),
483 .proc_handler = proc_dointvec,
487 .procname = "ctrl-alt-del",
489 .maxlen = sizeof(int),
491 .proc_handler = proc_dointvec,
493 #ifdef CONFIG_FUNCTION_TRACER
495 .procname = "ftrace_enabled",
496 .data = &ftrace_enabled,
497 .maxlen = sizeof(int),
499 .proc_handler = ftrace_enable_sysctl,
502 #ifdef CONFIG_STACK_TRACER
504 .procname = "stack_tracer_enabled",
505 .data = &stack_tracer_enabled,
506 .maxlen = sizeof(int),
508 .proc_handler = stack_trace_sysctl,
511 #ifdef CONFIG_TRACING
513 .procname = "ftrace_dump_on_oops",
514 .data = &ftrace_dump_on_oops,
515 .maxlen = sizeof(int),
517 .proc_handler = proc_dointvec,
520 #ifdef CONFIG_MODULES
522 .procname = "modprobe",
523 .data = &modprobe_path,
524 .maxlen = KMOD_PATH_LEN,
526 .proc_handler = proc_dostring,
529 .procname = "modules_disabled",
530 .data = &modules_disabled,
531 .maxlen = sizeof(int),
533 /* only handle a transition from default "0" to "1" */
534 .proc_handler = proc_dointvec_minmax,
539 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
541 .procname = "hotplug",
542 .data = &uevent_helper,
543 .maxlen = UEVENT_HELPER_PATH_LEN,
545 .proc_handler = proc_dostring,
548 #ifdef CONFIG_CHR_DEV_SG
550 .procname = "sg-big-buff",
551 .data = &sg_big_buff,
552 .maxlen = sizeof (int),
554 .proc_handler = proc_dointvec,
557 #ifdef CONFIG_BSD_PROCESS_ACCT
561 .maxlen = 3*sizeof(int),
563 .proc_handler = proc_dointvec,
566 #ifdef CONFIG_MAGIC_SYSRQ
569 .data = &__sysrq_enabled,
570 .maxlen = sizeof (int),
572 .proc_handler = proc_dointvec,
575 #ifdef CONFIG_PROC_SYSCTL
577 .procname = "cad_pid",
579 .maxlen = sizeof (int),
581 .proc_handler = proc_do_cad_pid,
585 .procname = "threads-max",
586 .data = &max_threads,
587 .maxlen = sizeof(int),
589 .proc_handler = proc_dointvec,
592 .procname = "random",
594 .child = random_table,
597 .procname = "overflowuid",
598 .data = &overflowuid,
599 .maxlen = sizeof(int),
601 .proc_handler = proc_dointvec_minmax,
602 .extra1 = &minolduid,
603 .extra2 = &maxolduid,
606 .procname = "overflowgid",
607 .data = &overflowgid,
608 .maxlen = sizeof(int),
610 .proc_handler = proc_dointvec_minmax,
611 .extra1 = &minolduid,
612 .extra2 = &maxolduid,
615 #ifdef CONFIG_MATHEMU
617 .procname = "ieee_emulation_warnings",
618 .data = &sysctl_ieee_emulation_warnings,
619 .maxlen = sizeof(int),
621 .proc_handler = proc_dointvec,
625 .procname = "userprocess_debug",
626 .data = &sysctl_userprocess_debug,
627 .maxlen = sizeof(int),
629 .proc_handler = proc_dointvec,
633 .procname = "pid_max",
635 .maxlen = sizeof (int),
637 .proc_handler = proc_dointvec_minmax,
638 .extra1 = &pid_max_min,
639 .extra2 = &pid_max_max,
642 .procname = "panic_on_oops",
643 .data = &panic_on_oops,
644 .maxlen = sizeof(int),
646 .proc_handler = proc_dointvec,
648 #if defined CONFIG_PRINTK
650 .procname = "printk",
651 .data = &console_loglevel,
652 .maxlen = 4*sizeof(int),
654 .proc_handler = proc_dointvec,
657 .procname = "printk_ratelimit",
658 .data = &printk_ratelimit_state.interval,
659 .maxlen = sizeof(int),
661 .proc_handler = proc_dointvec_jiffies,
664 .procname = "printk_ratelimit_burst",
665 .data = &printk_ratelimit_state.burst,
666 .maxlen = sizeof(int),
668 .proc_handler = proc_dointvec,
671 .procname = "printk_delay",
672 .data = &printk_delay_msec,
673 .maxlen = sizeof(int),
675 .proc_handler = proc_dointvec_minmax,
677 .extra2 = &ten_thousand,
681 .procname = "ngroups_max",
682 .data = &ngroups_max,
683 .maxlen = sizeof (int),
685 .proc_handler = proc_dointvec,
687 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
689 .procname = "unknown_nmi_panic",
690 .data = &unknown_nmi_panic,
691 .maxlen = sizeof (int),
693 .proc_handler = proc_dointvec,
696 .procname = "nmi_watchdog",
697 .data = &nmi_watchdog_enabled,
698 .maxlen = sizeof (int),
700 .proc_handler = proc_nmi_enabled,
703 #if defined(CONFIG_X86)
705 .procname = "panic_on_unrecovered_nmi",
706 .data = &panic_on_unrecovered_nmi,
707 .maxlen = sizeof(int),
709 .proc_handler = proc_dointvec,
712 .procname = "panic_on_io_nmi",
713 .data = &panic_on_io_nmi,
714 .maxlen = sizeof(int),
716 .proc_handler = proc_dointvec,
719 .procname = "bootloader_type",
720 .data = &bootloader_type,
721 .maxlen = sizeof (int),
723 .proc_handler = proc_dointvec,
726 .procname = "bootloader_version",
727 .data = &bootloader_version,
728 .maxlen = sizeof (int),
730 .proc_handler = proc_dointvec,
733 .procname = "kstack_depth_to_print",
734 .data = &kstack_depth_to_print,
735 .maxlen = sizeof(int),
737 .proc_handler = proc_dointvec,
740 .procname = "io_delay_type",
741 .data = &io_delay_type,
742 .maxlen = sizeof(int),
744 .proc_handler = proc_dointvec,
747 #if defined(CONFIG_MMU)
749 .procname = "randomize_va_space",
750 .data = &randomize_va_space,
751 .maxlen = sizeof(int),
753 .proc_handler = proc_dointvec,
756 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
758 .procname = "spin_retry",
760 .maxlen = sizeof (int),
762 .proc_handler = proc_dointvec,
765 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
767 .procname = "acpi_video_flags",
768 .data = &acpi_realmode_flags,
769 .maxlen = sizeof (unsigned long),
771 .proc_handler = proc_doulongvec_minmax,
776 .procname = "ignore-unaligned-usertrap",
777 .data = &no_unaligned_warning,
778 .maxlen = sizeof (int),
780 .proc_handler = proc_dointvec,
783 .procname = "unaligned-dump-stack",
784 .data = &unaligned_dump_stack,
785 .maxlen = sizeof (int),
787 .proc_handler = proc_dointvec,
790 #ifdef CONFIG_DETECT_SOFTLOCKUP
792 .procname = "softlockup_panic",
793 .data = &softlockup_panic,
794 .maxlen = sizeof(int),
796 .proc_handler = proc_dointvec_minmax,
801 .procname = "softlockup_thresh",
802 .data = &softlockup_thresh,
803 .maxlen = sizeof(int),
805 .proc_handler = proc_dosoftlockup_thresh,
810 #ifdef CONFIG_DETECT_HUNG_TASK
812 .procname = "hung_task_panic",
813 .data = &sysctl_hung_task_panic,
814 .maxlen = sizeof(int),
816 .proc_handler = proc_dointvec_minmax,
821 .procname = "hung_task_check_count",
822 .data = &sysctl_hung_task_check_count,
823 .maxlen = sizeof(unsigned long),
825 .proc_handler = proc_doulongvec_minmax,
828 .procname = "hung_task_timeout_secs",
829 .data = &sysctl_hung_task_timeout_secs,
830 .maxlen = sizeof(unsigned long),
832 .proc_handler = proc_dohung_task_timeout_secs,
835 .procname = "hung_task_warnings",
836 .data = &sysctl_hung_task_warnings,
837 .maxlen = sizeof(unsigned long),
839 .proc_handler = proc_doulongvec_minmax,
844 .procname = "compat-log",
846 .maxlen = sizeof (int),
848 .proc_handler = proc_dointvec,
851 #ifdef CONFIG_RT_MUTEXES
853 .procname = "max_lock_depth",
854 .data = &max_lock_depth,
855 .maxlen = sizeof(int),
857 .proc_handler = proc_dointvec,
861 .procname = "poweroff_cmd",
862 .data = &poweroff_cmd,
863 .maxlen = POWEROFF_CMD_PATH_LEN,
865 .proc_handler = proc_dostring,
871 .child = key_sysctls,
874 #ifdef CONFIG_RCU_TORTURE_TEST
876 .procname = "rcutorture_runnable",
877 .data = &rcutorture_runnable,
878 .maxlen = sizeof(int),
880 .proc_handler = proc_dointvec,
883 #ifdef CONFIG_SLOW_WORK
885 .procname = "slow-work",
887 .child = slow_work_sysctls,
890 #ifdef CONFIG_PERF_EVENTS
892 .procname = "perf_event_paranoid",
893 .data = &sysctl_perf_event_paranoid,
894 .maxlen = sizeof(sysctl_perf_event_paranoid),
896 .proc_handler = proc_dointvec,
899 .procname = "perf_event_mlock_kb",
900 .data = &sysctl_perf_event_mlock,
901 .maxlen = sizeof(sysctl_perf_event_mlock),
903 .proc_handler = proc_dointvec,
906 .procname = "perf_event_max_sample_rate",
907 .data = &sysctl_perf_event_sample_rate,
908 .maxlen = sizeof(sysctl_perf_event_sample_rate),
910 .proc_handler = proc_dointvec,
913 #ifdef CONFIG_KMEMCHECK
915 .procname = "kmemcheck",
916 .data = &kmemcheck_enabled,
917 .maxlen = sizeof(int),
919 .proc_handler = proc_dointvec,
924 .procname = "blk_iopoll",
925 .data = &blk_iopoll_enabled,
926 .maxlen = sizeof(int),
928 .proc_handler = proc_dointvec,
932 * NOTE: do not add new entries to this table unless you have read
933 * Documentation/sysctl/ctl_unnumbered.txt
938 static struct ctl_table vm_table[] = {
940 .procname = "overcommit_memory",
941 .data = &sysctl_overcommit_memory,
942 .maxlen = sizeof(sysctl_overcommit_memory),
944 .proc_handler = proc_dointvec,
947 .procname = "panic_on_oom",
948 .data = &sysctl_panic_on_oom,
949 .maxlen = sizeof(sysctl_panic_on_oom),
951 .proc_handler = proc_dointvec,
954 .procname = "oom_kill_allocating_task",
955 .data = &sysctl_oom_kill_allocating_task,
956 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
958 .proc_handler = proc_dointvec,
961 .procname = "oom_dump_tasks",
962 .data = &sysctl_oom_dump_tasks,
963 .maxlen = sizeof(sysctl_oom_dump_tasks),
965 .proc_handler = proc_dointvec,
968 .procname = "overcommit_ratio",
969 .data = &sysctl_overcommit_ratio,
970 .maxlen = sizeof(sysctl_overcommit_ratio),
972 .proc_handler = proc_dointvec,
975 .procname = "page-cluster",
976 .data = &page_cluster,
977 .maxlen = sizeof(int),
979 .proc_handler = proc_dointvec,
982 .procname = "dirty_background_ratio",
983 .data = &dirty_background_ratio,
984 .maxlen = sizeof(dirty_background_ratio),
986 .proc_handler = dirty_background_ratio_handler,
988 .extra2 = &one_hundred,
991 .procname = "dirty_background_bytes",
992 .data = &dirty_background_bytes,
993 .maxlen = sizeof(dirty_background_bytes),
995 .proc_handler = dirty_background_bytes_handler,
999 .procname = "dirty_ratio",
1000 .data = &vm_dirty_ratio,
1001 .maxlen = sizeof(vm_dirty_ratio),
1003 .proc_handler = dirty_ratio_handler,
1005 .extra2 = &one_hundred,
1008 .procname = "dirty_bytes",
1009 .data = &vm_dirty_bytes,
1010 .maxlen = sizeof(vm_dirty_bytes),
1012 .proc_handler = dirty_bytes_handler,
1013 .extra1 = &dirty_bytes_min,
1016 .procname = "dirty_writeback_centisecs",
1017 .data = &dirty_writeback_interval,
1018 .maxlen = sizeof(dirty_writeback_interval),
1020 .proc_handler = dirty_writeback_centisecs_handler,
1023 .procname = "dirty_expire_centisecs",
1024 .data = &dirty_expire_interval,
1025 .maxlen = sizeof(dirty_expire_interval),
1027 .proc_handler = proc_dointvec,
1030 .procname = "nr_pdflush_threads",
1031 .data = &nr_pdflush_threads,
1032 .maxlen = sizeof nr_pdflush_threads,
1033 .mode = 0444 /* read-only*/,
1034 .proc_handler = proc_dointvec,
1037 .procname = "swappiness",
1038 .data = &vm_swappiness,
1039 .maxlen = sizeof(vm_swappiness),
1041 .proc_handler = proc_dointvec_minmax,
1043 .extra2 = &one_hundred,
1045 #ifdef CONFIG_HUGETLB_PAGE
1047 .procname = "nr_hugepages",
1049 .maxlen = sizeof(unsigned long),
1051 .proc_handler = hugetlb_sysctl_handler,
1052 .extra1 = (void *)&hugetlb_zero,
1053 .extra2 = (void *)&hugetlb_infinity,
1057 .procname = "nr_hugepages_mempolicy",
1059 .maxlen = sizeof(unsigned long),
1061 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1062 .extra1 = (void *)&hugetlb_zero,
1063 .extra2 = (void *)&hugetlb_infinity,
1067 .procname = "hugetlb_shm_group",
1068 .data = &sysctl_hugetlb_shm_group,
1069 .maxlen = sizeof(gid_t),
1071 .proc_handler = proc_dointvec,
1074 .procname = "hugepages_treat_as_movable",
1075 .data = &hugepages_treat_as_movable,
1076 .maxlen = sizeof(int),
1078 .proc_handler = hugetlb_treat_movable_handler,
1081 .procname = "nr_overcommit_hugepages",
1083 .maxlen = sizeof(unsigned long),
1085 .proc_handler = hugetlb_overcommit_handler,
1086 .extra1 = (void *)&hugetlb_zero,
1087 .extra2 = (void *)&hugetlb_infinity,
1091 .procname = "lowmem_reserve_ratio",
1092 .data = &sysctl_lowmem_reserve_ratio,
1093 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1095 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1098 .procname = "drop_caches",
1099 .data = &sysctl_drop_caches,
1100 .maxlen = sizeof(int),
1102 .proc_handler = drop_caches_sysctl_handler,
1105 .procname = "min_free_kbytes",
1106 .data = &min_free_kbytes,
1107 .maxlen = sizeof(min_free_kbytes),
1109 .proc_handler = min_free_kbytes_sysctl_handler,
1113 .procname = "percpu_pagelist_fraction",
1114 .data = &percpu_pagelist_fraction,
1115 .maxlen = sizeof(percpu_pagelist_fraction),
1117 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1118 .extra1 = &min_percpu_pagelist_fract,
1122 .procname = "max_map_count",
1123 .data = &sysctl_max_map_count,
1124 .maxlen = sizeof(sysctl_max_map_count),
1126 .proc_handler = proc_dointvec_minmax,
1131 .procname = "nr_trim_pages",
1132 .data = &sysctl_nr_trim_pages,
1133 .maxlen = sizeof(sysctl_nr_trim_pages),
1135 .proc_handler = proc_dointvec_minmax,
1140 .procname = "laptop_mode",
1141 .data = &laptop_mode,
1142 .maxlen = sizeof(laptop_mode),
1144 .proc_handler = proc_dointvec_jiffies,
1147 .procname = "block_dump",
1148 .data = &block_dump,
1149 .maxlen = sizeof(block_dump),
1151 .proc_handler = proc_dointvec,
1155 .procname = "vfs_cache_pressure",
1156 .data = &sysctl_vfs_cache_pressure,
1157 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1159 .proc_handler = proc_dointvec,
1162 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1164 .procname = "legacy_va_layout",
1165 .data = &sysctl_legacy_va_layout,
1166 .maxlen = sizeof(sysctl_legacy_va_layout),
1168 .proc_handler = proc_dointvec,
1174 .procname = "zone_reclaim_mode",
1175 .data = &zone_reclaim_mode,
1176 .maxlen = sizeof(zone_reclaim_mode),
1178 .proc_handler = proc_dointvec,
1182 .procname = "min_unmapped_ratio",
1183 .data = &sysctl_min_unmapped_ratio,
1184 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1186 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1188 .extra2 = &one_hundred,
1191 .procname = "min_slab_ratio",
1192 .data = &sysctl_min_slab_ratio,
1193 .maxlen = sizeof(sysctl_min_slab_ratio),
1195 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1197 .extra2 = &one_hundred,
1202 .procname = "stat_interval",
1203 .data = &sysctl_stat_interval,
1204 .maxlen = sizeof(sysctl_stat_interval),
1206 .proc_handler = proc_dointvec_jiffies,
1211 .procname = "mmap_min_addr",
1212 .data = &dac_mmap_min_addr,
1213 .maxlen = sizeof(unsigned long),
1215 .proc_handler = mmap_min_addr_handler,
1220 .procname = "numa_zonelist_order",
1221 .data = &numa_zonelist_order,
1222 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1224 .proc_handler = numa_zonelist_order_handler,
1227 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1228 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1230 .procname = "vdso_enabled",
1231 .data = &vdso_enabled,
1232 .maxlen = sizeof(vdso_enabled),
1234 .proc_handler = proc_dointvec,
1238 #ifdef CONFIG_HIGHMEM
1240 .procname = "highmem_is_dirtyable",
1241 .data = &vm_highmem_is_dirtyable,
1242 .maxlen = sizeof(vm_highmem_is_dirtyable),
1244 .proc_handler = proc_dointvec_minmax,
1250 .procname = "scan_unevictable_pages",
1251 .data = &scan_unevictable_pages,
1252 .maxlen = sizeof(scan_unevictable_pages),
1254 .proc_handler = scan_unevictable_handler,
1256 #ifdef CONFIG_MEMORY_FAILURE
1258 .procname = "memory_failure_early_kill",
1259 .data = &sysctl_memory_failure_early_kill,
1260 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1262 .proc_handler = proc_dointvec_minmax,
1267 .procname = "memory_failure_recovery",
1268 .data = &sysctl_memory_failure_recovery,
1269 .maxlen = sizeof(sysctl_memory_failure_recovery),
1271 .proc_handler = proc_dointvec_minmax,
1278 * NOTE: do not add new entries to this table unless you have read
1279 * Documentation/sysctl/ctl_unnumbered.txt
1284 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1285 static struct ctl_table binfmt_misc_table[] = {
1290 static struct ctl_table fs_table[] = {
1292 .procname = "inode-nr",
1293 .data = &inodes_stat,
1294 .maxlen = 2*sizeof(int),
1296 .proc_handler = proc_dointvec,
1299 .procname = "inode-state",
1300 .data = &inodes_stat,
1301 .maxlen = 7*sizeof(int),
1303 .proc_handler = proc_dointvec,
1306 .procname = "file-nr",
1307 .data = &files_stat,
1308 .maxlen = 3*sizeof(int),
1310 .proc_handler = proc_nr_files,
1313 .procname = "file-max",
1314 .data = &files_stat.max_files,
1315 .maxlen = sizeof(int),
1317 .proc_handler = proc_dointvec,
1320 .procname = "nr_open",
1321 .data = &sysctl_nr_open,
1322 .maxlen = sizeof(int),
1324 .proc_handler = proc_dointvec_minmax,
1325 .extra1 = &sysctl_nr_open_min,
1326 .extra2 = &sysctl_nr_open_max,
1329 .procname = "dentry-state",
1330 .data = &dentry_stat,
1331 .maxlen = 6*sizeof(int),
1333 .proc_handler = proc_dointvec,
1336 .procname = "overflowuid",
1337 .data = &fs_overflowuid,
1338 .maxlen = sizeof(int),
1340 .proc_handler = proc_dointvec_minmax,
1341 .extra1 = &minolduid,
1342 .extra2 = &maxolduid,
1345 .procname = "overflowgid",
1346 .data = &fs_overflowgid,
1347 .maxlen = sizeof(int),
1349 .proc_handler = proc_dointvec_minmax,
1350 .extra1 = &minolduid,
1351 .extra2 = &maxolduid,
1353 #ifdef CONFIG_FILE_LOCKING
1355 .procname = "leases-enable",
1356 .data = &leases_enable,
1357 .maxlen = sizeof(int),
1359 .proc_handler = proc_dointvec,
1362 #ifdef CONFIG_DNOTIFY
1364 .procname = "dir-notify-enable",
1365 .data = &dir_notify_enable,
1366 .maxlen = sizeof(int),
1368 .proc_handler = proc_dointvec,
1372 #ifdef CONFIG_FILE_LOCKING
1374 .procname = "lease-break-time",
1375 .data = &lease_break_time,
1376 .maxlen = sizeof(int),
1378 .proc_handler = proc_dointvec,
1383 .procname = "aio-nr",
1385 .maxlen = sizeof(aio_nr),
1387 .proc_handler = proc_doulongvec_minmax,
1390 .procname = "aio-max-nr",
1391 .data = &aio_max_nr,
1392 .maxlen = sizeof(aio_max_nr),
1394 .proc_handler = proc_doulongvec_minmax,
1396 #endif /* CONFIG_AIO */
1397 #ifdef CONFIG_INOTIFY_USER
1399 .procname = "inotify",
1401 .child = inotify_table,
1406 .procname = "epoll",
1408 .child = epoll_table,
1413 .procname = "suid_dumpable",
1414 .data = &suid_dumpable,
1415 .maxlen = sizeof(int),
1417 .proc_handler = proc_dointvec_minmax,
1421 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1423 .procname = "binfmt_misc",
1425 .child = binfmt_misc_table,
1429 * NOTE: do not add new entries to this table unless you have read
1430 * Documentation/sysctl/ctl_unnumbered.txt
1435 static struct ctl_table debug_table[] = {
1436 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
1438 .procname = "exception-trace",
1439 .data = &show_unhandled_signals,
1440 .maxlen = sizeof(int),
1442 .proc_handler = proc_dointvec
1445 #if defined(CONFIG_OPTPROBES)
1447 .procname = "kprobes-optimization",
1448 .data = &sysctl_kprobes_optimization,
1449 .maxlen = sizeof(int),
1451 .proc_handler = proc_kprobes_optimization_handler,
1459 static struct ctl_table dev_table[] = {
1463 static DEFINE_SPINLOCK(sysctl_lock);
1465 /* called under sysctl_lock */
1466 static int use_table(struct ctl_table_header *p)
1468 if (unlikely(p->unregistering))
1474 /* called under sysctl_lock */
1475 static void unuse_table(struct ctl_table_header *p)
1478 if (unlikely(p->unregistering))
1479 complete(p->unregistering);
1482 /* called under sysctl_lock, will reacquire if has to wait */
1483 static void start_unregistering(struct ctl_table_header *p)
1486 * if p->used is 0, nobody will ever touch that entry again;
1487 * we'll eliminate all paths to it before dropping sysctl_lock
1489 if (unlikely(p->used)) {
1490 struct completion wait;
1491 init_completion(&wait);
1492 p->unregistering = &wait;
1493 spin_unlock(&sysctl_lock);
1494 wait_for_completion(&wait);
1495 spin_lock(&sysctl_lock);
1497 /* anything non-NULL; we'll never dereference it */
1498 p->unregistering = ERR_PTR(-EINVAL);
1501 * do not remove from the list until nobody holds it; walking the
1502 * list in do_sysctl() relies on that.
1504 list_del_init(&p->ctl_entry);
1507 void sysctl_head_get(struct ctl_table_header *head)
1509 spin_lock(&sysctl_lock);
1511 spin_unlock(&sysctl_lock);
1514 void sysctl_head_put(struct ctl_table_header *head)
1516 spin_lock(&sysctl_lock);
1519 spin_unlock(&sysctl_lock);
1522 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1526 spin_lock(&sysctl_lock);
1527 if (!use_table(head))
1528 head = ERR_PTR(-ENOENT);
1529 spin_unlock(&sysctl_lock);
1533 void sysctl_head_finish(struct ctl_table_header *head)
1537 spin_lock(&sysctl_lock);
1539 spin_unlock(&sysctl_lock);
1542 static struct ctl_table_set *
1543 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1545 struct ctl_table_set *set = &root->default_set;
1547 set = root->lookup(root, namespaces);
1551 static struct list_head *
1552 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1554 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1558 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1559 struct ctl_table_header *prev)
1561 struct ctl_table_root *root;
1562 struct list_head *header_list;
1563 struct ctl_table_header *head;
1564 struct list_head *tmp;
1566 spin_lock(&sysctl_lock);
1569 tmp = &prev->ctl_entry;
1573 tmp = &root_table_header.ctl_entry;
1575 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1577 if (!use_table(head))
1579 spin_unlock(&sysctl_lock);
1584 header_list = lookup_header_list(root, namespaces);
1585 if (tmp != header_list)
1589 root = list_entry(root->root_list.next,
1590 struct ctl_table_root, root_list);
1591 if (root == &sysctl_table_root)
1593 header_list = lookup_header_list(root, namespaces);
1594 } while (list_empty(header_list));
1595 tmp = header_list->next;
1598 spin_unlock(&sysctl_lock);
1602 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1604 return __sysctl_head_next(current->nsproxy, prev);
1607 void register_sysctl_root(struct ctl_table_root *root)
1609 spin_lock(&sysctl_lock);
1610 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1611 spin_unlock(&sysctl_lock);
1615 * sysctl_perm does NOT grant the superuser all rights automatically, because
1616 * some sysctl variables are readonly even to root.
1619 static int test_perm(int mode, int op)
1621 if (!current_euid())
1623 else if (in_egroup_p(0))
1625 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1630 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1635 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1639 if (root->permissions)
1640 mode = root->permissions(root, current->nsproxy, table);
1644 return test_perm(mode, op);
1647 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1649 for (; table->procname; table++) {
1650 table->parent = parent;
1652 sysctl_set_parent(table, table->child);
1656 static __init int sysctl_init(void)
1658 sysctl_set_parent(NULL, root_table);
1659 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1662 err = sysctl_check_table(current->nsproxy, root_table);
1668 core_initcall(sysctl_init);
1670 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1671 struct ctl_table *table)
1673 struct ctl_table *p;
1674 const char *s = branch->procname;
1676 /* branch should have named subdirectory as its first element */
1677 if (!s || !branch->child)
1680 /* ... and nothing else */
1681 if (branch[1].procname)
1684 /* table should contain subdirectory with the same name */
1685 for (p = table; p->procname; p++) {
1688 if (p->procname && strcmp(p->procname, s) == 0)
1694 /* see if attaching q to p would be an improvement */
1695 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1697 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1698 struct ctl_table *next;
1700 int not_in_parent = !p->attached_by;
1702 while ((next = is_branch_in(by, to)) != NULL) {
1703 if (by == q->attached_by)
1705 if (to == p->attached_by)
1711 if (is_better && not_in_parent) {
1712 q->attached_by = by;
1713 q->attached_to = to;
1719 * __register_sysctl_paths - register a sysctl hierarchy
1720 * @root: List of sysctl headers to register on
1721 * @namespaces: Data to compute which lists of sysctl entries are visible
1722 * @path: The path to the directory the sysctl table is in.
1723 * @table: the top-level table structure
1725 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1726 * array. A completely 0 filled entry terminates the table.
1728 * The members of the &struct ctl_table structure are used as follows:
1730 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1731 * enter a sysctl file
1733 * data - a pointer to data for use by proc_handler
1735 * maxlen - the maximum size in bytes of the data
1737 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1739 * child - a pointer to the child sysctl table if this entry is a directory, or
1742 * proc_handler - the text handler routine (described below)
1744 * de - for internal use by the sysctl routines
1746 * extra1, extra2 - extra pointers usable by the proc handler routines
1748 * Leaf nodes in the sysctl tree will be represented by a single file
1749 * under /proc; non-leaf nodes will be represented by directories.
1751 * sysctl(2) can automatically manage read and write requests through
1752 * the sysctl table. The data and maxlen fields of the ctl_table
1753 * struct enable minimal validation of the values being written to be
1754 * performed, and the mode field allows minimal authentication.
1756 * There must be a proc_handler routine for any terminal nodes
1757 * mirrored under /proc/sys (non-terminals are handled by a built-in
1758 * directory handler). Several default handlers are available to
1759 * cover common cases -
1761 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1762 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1763 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1765 * It is the handler's job to read the input buffer from user memory
1766 * and process it. The handler should return 0 on success.
1768 * This routine returns %NULL on a failure to register, and a pointer
1769 * to the table header on success.
1771 struct ctl_table_header *__register_sysctl_paths(
1772 struct ctl_table_root *root,
1773 struct nsproxy *namespaces,
1774 const struct ctl_path *path, struct ctl_table *table)
1776 struct ctl_table_header *header;
1777 struct ctl_table *new, **prevp;
1778 unsigned int n, npath;
1779 struct ctl_table_set *set;
1781 /* Count the path components */
1782 for (npath = 0; path[npath].procname; ++npath)
1786 * For each path component, allocate a 2-element ctl_table array.
1787 * The first array element will be filled with the sysctl entry
1788 * for this, the second will be the sentinel (procname == 0).
1790 * We allocate everything in one go so that we don't have to
1791 * worry about freeing additional memory in unregister_sysctl_table.
1793 header = kzalloc(sizeof(struct ctl_table_header) +
1794 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1798 new = (struct ctl_table *) (header + 1);
1800 /* Now connect the dots */
1801 prevp = &header->ctl_table;
1802 for (n = 0; n < npath; ++n, ++path) {
1803 /* Copy the procname */
1804 new->procname = path->procname;
1808 prevp = &new->child;
1813 header->ctl_table_arg = table;
1815 INIT_LIST_HEAD(&header->ctl_entry);
1817 header->unregistering = NULL;
1818 header->root = root;
1819 sysctl_set_parent(NULL, header->ctl_table);
1821 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1822 if (sysctl_check_table(namespaces, header->ctl_table)) {
1827 spin_lock(&sysctl_lock);
1828 header->set = lookup_header_set(root, namespaces);
1829 header->attached_by = header->ctl_table;
1830 header->attached_to = root_table;
1831 header->parent = &root_table_header;
1832 for (set = header->set; set; set = set->parent) {
1833 struct ctl_table_header *p;
1834 list_for_each_entry(p, &set->list, ctl_entry) {
1835 if (p->unregistering)
1837 try_attach(p, header);
1840 header->parent->count++;
1841 list_add_tail(&header->ctl_entry, &header->set->list);
1842 spin_unlock(&sysctl_lock);
1848 * register_sysctl_table_path - register a sysctl table hierarchy
1849 * @path: The path to the directory the sysctl table is in.
1850 * @table: the top-level table structure
1852 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1853 * array. A completely 0 filled entry terminates the table.
1855 * See __register_sysctl_paths for more details.
1857 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1858 struct ctl_table *table)
1860 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1865 * register_sysctl_table - register a sysctl table hierarchy
1866 * @table: the top-level table structure
1868 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1869 * array. A completely 0 filled entry terminates the table.
1871 * See register_sysctl_paths for more details.
1873 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1875 static const struct ctl_path null_path[] = { {} };
1877 return register_sysctl_paths(null_path, table);
1881 * unregister_sysctl_table - unregister a sysctl table hierarchy
1882 * @header: the header returned from register_sysctl_table
1884 * Unregisters the sysctl table and all children. proc entries may not
1885 * actually be removed until they are no longer used by anyone.
1887 void unregister_sysctl_table(struct ctl_table_header * header)
1894 spin_lock(&sysctl_lock);
1895 start_unregistering(header);
1896 if (!--header->parent->count) {
1898 kfree(header->parent);
1900 if (!--header->count)
1902 spin_unlock(&sysctl_lock);
1905 int sysctl_is_seen(struct ctl_table_header *p)
1907 struct ctl_table_set *set = p->set;
1909 spin_lock(&sysctl_lock);
1910 if (p->unregistering)
1912 else if (!set->is_seen)
1915 res = set->is_seen(set);
1916 spin_unlock(&sysctl_lock);
1920 void setup_sysctl_set(struct ctl_table_set *p,
1921 struct ctl_table_set *parent,
1922 int (*is_seen)(struct ctl_table_set *))
1924 INIT_LIST_HEAD(&p->list);
1925 p->parent = parent ? parent : &sysctl_table_root.default_set;
1926 p->is_seen = is_seen;
1929 #else /* !CONFIG_SYSCTL */
1930 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1935 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1936 struct ctl_table *table)
1941 void unregister_sysctl_table(struct ctl_table_header * table)
1945 void setup_sysctl_set(struct ctl_table_set *p,
1946 struct ctl_table_set *parent,
1947 int (*is_seen)(struct ctl_table_set *))
1951 void sysctl_head_put(struct ctl_table_header *head)
1955 #endif /* CONFIG_SYSCTL */
1961 #ifdef CONFIG_PROC_SYSCTL
1963 static int _proc_do_string(void* data, int maxlen, int write,
1964 void __user *buffer,
1965 size_t *lenp, loff_t *ppos)
1971 if (!data || !maxlen || !*lenp) {
1979 while (len < *lenp) {
1980 if (get_user(c, p++))
1982 if (c == 0 || c == '\n')
1988 if(copy_from_user(data, buffer, len))
1990 ((char *) data)[len] = 0;
2008 if(copy_to_user(buffer, data, len))
2011 if(put_user('\n', ((char __user *) buffer) + len))
2022 * proc_dostring - read a string sysctl
2023 * @table: the sysctl table
2024 * @write: %TRUE if this is a write to the sysctl file
2025 * @buffer: the user buffer
2026 * @lenp: the size of the user buffer
2027 * @ppos: file position
2029 * Reads/writes a string from/to the user buffer. If the kernel
2030 * buffer provided is not large enough to hold the string, the
2031 * string is truncated. The copied string is %NULL-terminated.
2032 * If the string is being read by the user process, it is copied
2033 * and a newline '\n' is added. It is truncated if the buffer is
2036 * Returns 0 on success.
2038 int proc_dostring(struct ctl_table *table, int write,
2039 void __user *buffer, size_t *lenp, loff_t *ppos)
2041 return _proc_do_string(table->data, table->maxlen, write,
2042 buffer, lenp, ppos);
2046 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2048 int write, void *data)
2051 *valp = *negp ? -*lvalp : *lvalp;
2056 *lvalp = (unsigned long)-val;
2059 *lvalp = (unsigned long)val;
2065 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2066 int write, void __user *buffer,
2067 size_t *lenp, loff_t *ppos,
2068 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2069 int write, void *data),
2072 #define TMPBUFLEN 21
2073 int *i, vleft, first = 1, neg;
2077 char buf[TMPBUFLEN], *p;
2078 char __user *s = buffer;
2080 if (!tbl_data || !table->maxlen || !*lenp ||
2081 (*ppos && !write)) {
2086 i = (int *) tbl_data;
2087 vleft = table->maxlen / sizeof(*i);
2091 conv = do_proc_dointvec_conv;
2093 for (; left && vleft--; i++, first=0) {
2108 if (len > sizeof(buf) - 1)
2109 len = sizeof(buf) - 1;
2110 if (copy_from_user(buf, s, len))
2114 if (*p == '-' && left > 1) {
2118 if (*p < '0' || *p > '9')
2121 lval = simple_strtoul(p, &p, 0);
2124 if ((len < left) && *p && !isspace(*p))
2129 if (conv(&neg, &lval, i, 1, data))
2136 if (conv(&neg, &lval, i, 0, data))
2139 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2143 if(copy_to_user(s, buf, len))
2150 if (!write && !first && left) {
2151 if(put_user('\n', s))
2158 if (get_user(c, s++))
2173 static int do_proc_dointvec(struct ctl_table *table, int write,
2174 void __user *buffer, size_t *lenp, loff_t *ppos,
2175 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2176 int write, void *data),
2179 return __do_proc_dointvec(table->data, table, write,
2180 buffer, lenp, ppos, conv, data);
2184 * proc_dointvec - read a vector of integers
2185 * @table: the sysctl table
2186 * @write: %TRUE if this is a write to the sysctl file
2187 * @buffer: the user buffer
2188 * @lenp: the size of the user buffer
2189 * @ppos: file position
2191 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2192 * values from/to the user buffer, treated as an ASCII string.
2194 * Returns 0 on success.
2196 int proc_dointvec(struct ctl_table *table, int write,
2197 void __user *buffer, size_t *lenp, loff_t *ppos)
2199 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2204 * Taint values can only be increased
2205 * This means we can safely use a temporary.
2207 static int proc_taint(struct ctl_table *table, int write,
2208 void __user *buffer, size_t *lenp, loff_t *ppos)
2211 unsigned long tmptaint = get_taint();
2214 if (write && !capable(CAP_SYS_ADMIN))
2219 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2225 * Poor man's atomic or. Not worth adding a primitive
2226 * to everyone's atomic.h for this
2229 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2230 if ((tmptaint >> i) & 1)
2238 struct do_proc_dointvec_minmax_conv_param {
2243 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2245 int write, void *data)
2247 struct do_proc_dointvec_minmax_conv_param *param = data;
2249 int val = *negp ? -*lvalp : *lvalp;
2250 if ((param->min && *param->min > val) ||
2251 (param->max && *param->max < val))
2258 *lvalp = (unsigned long)-val;
2261 *lvalp = (unsigned long)val;
2268 * proc_dointvec_minmax - read a vector of integers with min/max values
2269 * @table: the sysctl table
2270 * @write: %TRUE if this is a write to the sysctl file
2271 * @buffer: the user buffer
2272 * @lenp: the size of the user buffer
2273 * @ppos: file position
2275 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2276 * values from/to the user buffer, treated as an ASCII string.
2278 * This routine will ensure the values are within the range specified by
2279 * table->extra1 (min) and table->extra2 (max).
2281 * Returns 0 on success.
2283 int proc_dointvec_minmax(struct ctl_table *table, int write,
2284 void __user *buffer, size_t *lenp, loff_t *ppos)
2286 struct do_proc_dointvec_minmax_conv_param param = {
2287 .min = (int *) table->extra1,
2288 .max = (int *) table->extra2,
2290 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2291 do_proc_dointvec_minmax_conv, ¶m);
2294 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2295 void __user *buffer,
2296 size_t *lenp, loff_t *ppos,
2297 unsigned long convmul,
2298 unsigned long convdiv)
2300 #define TMPBUFLEN 21
2301 unsigned long *i, *min, *max, val;
2302 int vleft, first=1, neg;
2304 char buf[TMPBUFLEN], *p;
2305 char __user *s = buffer;
2307 if (!data || !table->maxlen || !*lenp ||
2308 (*ppos && !write)) {
2313 i = (unsigned long *) data;
2314 min = (unsigned long *) table->extra1;
2315 max = (unsigned long *) table->extra2;
2316 vleft = table->maxlen / sizeof(unsigned long);
2319 for (; left && vleft--; i++, min++, max++, first=0) {
2334 if (len > TMPBUFLEN-1)
2336 if (copy_from_user(buf, s, len))
2340 if (*p == '-' && left > 1) {
2344 if (*p < '0' || *p > '9')
2346 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2348 if ((len < left) && *p && !isspace(*p))
2357 if ((min && val < *min) || (max && val > *max))
2364 sprintf(p, "%lu", convdiv * (*i) / convmul);
2368 if(copy_to_user(s, buf, len))
2375 if (!write && !first && left) {
2376 if(put_user('\n', s))
2383 if (get_user(c, s++))
2398 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2399 void __user *buffer,
2400 size_t *lenp, loff_t *ppos,
2401 unsigned long convmul,
2402 unsigned long convdiv)
2404 return __do_proc_doulongvec_minmax(table->data, table, write,
2405 buffer, lenp, ppos, convmul, convdiv);
2409 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2410 * @table: the sysctl table
2411 * @write: %TRUE if this is a write to the sysctl file
2412 * @buffer: the user buffer
2413 * @lenp: the size of the user buffer
2414 * @ppos: file position
2416 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2417 * values from/to the user buffer, treated as an ASCII string.
2419 * This routine will ensure the values are within the range specified by
2420 * table->extra1 (min) and table->extra2 (max).
2422 * Returns 0 on success.
2424 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2425 void __user *buffer, size_t *lenp, loff_t *ppos)
2427 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2431 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2432 * @table: the sysctl table
2433 * @write: %TRUE if this is a write to the sysctl file
2434 * @buffer: the user buffer
2435 * @lenp: the size of the user buffer
2436 * @ppos: file position
2438 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2439 * values from/to the user buffer, treated as an ASCII string. The values
2440 * are treated as milliseconds, and converted to jiffies when they are stored.
2442 * This routine will ensure the values are within the range specified by
2443 * table->extra1 (min) and table->extra2 (max).
2445 * Returns 0 on success.
2447 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2448 void __user *buffer,
2449 size_t *lenp, loff_t *ppos)
2451 return do_proc_doulongvec_minmax(table, write, buffer,
2452 lenp, ppos, HZ, 1000l);
2456 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2458 int write, void *data)
2461 if (*lvalp > LONG_MAX / HZ)
2463 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2469 lval = (unsigned long)-val;
2472 lval = (unsigned long)val;
2479 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2481 int write, void *data)
2484 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2486 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2492 lval = (unsigned long)-val;
2495 lval = (unsigned long)val;
2497 *lvalp = jiffies_to_clock_t(lval);
2502 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2504 int write, void *data)
2507 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2513 lval = (unsigned long)-val;
2516 lval = (unsigned long)val;
2518 *lvalp = jiffies_to_msecs(lval);
2524 * proc_dointvec_jiffies - read a vector of integers as seconds
2525 * @table: the sysctl table
2526 * @write: %TRUE if this is a write to the sysctl file
2527 * @buffer: the user buffer
2528 * @lenp: the size of the user buffer
2529 * @ppos: file position
2531 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2532 * values from/to the user buffer, treated as an ASCII string.
2533 * The values read are assumed to be in seconds, and are converted into
2536 * Returns 0 on success.
2538 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2539 void __user *buffer, size_t *lenp, loff_t *ppos)
2541 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2542 do_proc_dointvec_jiffies_conv,NULL);
2546 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2547 * @table: the sysctl table
2548 * @write: %TRUE if this is a write to the sysctl file
2549 * @buffer: the user buffer
2550 * @lenp: the size of the user buffer
2551 * @ppos: pointer to the file position
2553 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2554 * values from/to the user buffer, treated as an ASCII string.
2555 * The values read are assumed to be in 1/USER_HZ seconds, and
2556 * are converted into jiffies.
2558 * Returns 0 on success.
2560 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2561 void __user *buffer, size_t *lenp, loff_t *ppos)
2563 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2564 do_proc_dointvec_userhz_jiffies_conv,NULL);
2568 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2569 * @table: the sysctl table
2570 * @write: %TRUE if this is a write to the sysctl file
2571 * @buffer: the user buffer
2572 * @lenp: the size of the user buffer
2573 * @ppos: file position
2574 * @ppos: the current position in the file
2576 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2577 * values from/to the user buffer, treated as an ASCII string.
2578 * The values read are assumed to be in 1/1000 seconds, and
2579 * are converted into jiffies.
2581 * Returns 0 on success.
2583 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2584 void __user *buffer, size_t *lenp, loff_t *ppos)
2586 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2587 do_proc_dointvec_ms_jiffies_conv, NULL);
2590 static int proc_do_cad_pid(struct ctl_table *table, int write,
2591 void __user *buffer, size_t *lenp, loff_t *ppos)
2593 struct pid *new_pid;
2597 tmp = pid_vnr(cad_pid);
2599 r = __do_proc_dointvec(&tmp, table, write, buffer,
2600 lenp, ppos, NULL, NULL);
2604 new_pid = find_get_pid(tmp);
2608 put_pid(xchg(&cad_pid, new_pid));
2612 #else /* CONFIG_PROC_FS */
2614 int proc_dostring(struct ctl_table *table, int write,
2615 void __user *buffer, size_t *lenp, loff_t *ppos)
2620 int proc_dointvec(struct ctl_table *table, int write,
2621 void __user *buffer, size_t *lenp, loff_t *ppos)
2626 int proc_dointvec_minmax(struct ctl_table *table, int write,
2627 void __user *buffer, size_t *lenp, loff_t *ppos)
2632 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2633 void __user *buffer, size_t *lenp, loff_t *ppos)
2638 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2639 void __user *buffer, size_t *lenp, loff_t *ppos)
2644 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2645 void __user *buffer, size_t *lenp, loff_t *ppos)
2650 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2651 void __user *buffer, size_t *lenp, loff_t *ppos)
2656 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2657 void __user *buffer,
2658 size_t *lenp, loff_t *ppos)
2664 #endif /* CONFIG_PROC_FS */
2667 * No sense putting this after each symbol definition, twice,
2668 * exception granted :-)
2670 EXPORT_SYMBOL(proc_dointvec);
2671 EXPORT_SYMBOL(proc_dointvec_jiffies);
2672 EXPORT_SYMBOL(proc_dointvec_minmax);
2673 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2674 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2675 EXPORT_SYMBOL(proc_dostring);
2676 EXPORT_SYMBOL(proc_doulongvec_minmax);
2677 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2678 EXPORT_SYMBOL(register_sysctl_table);
2679 EXPORT_SYMBOL(register_sysctl_paths);
2680 EXPORT_SYMBOL(unregister_sysctl_table);