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/printk.h>
28 #include <linux/proc_fs.h>
29 #include <linux/security.h>
30 #include <linux/ctype.h>
31 #include <linux/kmemcheck.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/ratelimit.h>
41 #include <linux/compaction.h>
42 #include <linux/hugetlb.h>
43 #include <linux/initrd.h>
44 #include <linux/key.h>
45 #include <linux/times.h>
46 #include <linux/limits.h>
47 #include <linux/dcache.h>
48 #include <linux/dnotify.h>
49 #include <linux/syscalls.h>
50 #include <linux/vmstat.h>
51 #include <linux/nfs_fs.h>
52 #include <linux/acpi.h>
53 #include <linux/reboot.h>
54 #include <linux/ftrace.h>
55 #include <linux/perf_event.h>
56 #include <linux/kprobes.h>
57 #include <linux/pipe_fs_i.h>
58 #include <linux/oom.h>
60 #include <asm/uaccess.h>
61 #include <asm/processor.h>
65 #include <asm/stacktrace.h>
68 #ifdef CONFIG_BSD_PROCESS_ACCT
69 #include <linux/acct.h>
71 #ifdef CONFIG_RT_MUTEXES
72 #include <linux/rtmutex.h>
74 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
75 #include <linux/lockdep.h>
77 #ifdef CONFIG_CHR_DEV_SG
81 #ifdef CONFIG_LOCKUP_DETECTOR
82 #include <linux/nmi.h>
86 #if defined(CONFIG_SYSCTL)
88 /* External variables not in a header file. */
89 extern int sysctl_overcommit_memory;
90 extern int sysctl_overcommit_ratio;
91 extern int max_threads;
92 extern int core_uses_pid;
93 extern int suid_dumpable;
94 extern char core_pattern[];
95 extern unsigned int core_pipe_limit;
97 extern int min_free_kbytes;
98 extern int pid_max_min, pid_max_max;
99 extern int sysctl_drop_caches;
100 extern int percpu_pagelist_fraction;
101 extern int compat_log;
102 extern int latencytop_enabled;
103 extern int sysctl_nr_open_min, sysctl_nr_open_max;
105 extern int sysctl_nr_trim_pages;
108 extern int blk_iopoll_enabled;
111 /* Constants used for minimum and maximum */
112 #ifdef CONFIG_LOCKUP_DETECTOR
113 static int sixty = 60;
114 static int neg_one = -1;
118 static int __maybe_unused one = 1;
119 static int __maybe_unused two = 2;
120 static unsigned long one_ul = 1;
121 static int one_hundred = 100;
123 static int ten_thousand = 10000;
126 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
127 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
129 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
130 static int maxolduid = 65535;
131 static int minolduid;
132 static int min_percpu_pagelist_fract = 8;
134 static int ngroups_max = NGROUPS_MAX;
136 #ifdef CONFIG_INOTIFY_USER
137 #include <linux/inotify.h>
140 #include <asm/system.h>
143 #ifdef CONFIG_SPARC64
144 extern int sysctl_tsb_ratio;
148 extern int pwrsw_enabled;
149 extern int unaligned_enabled;
153 #ifdef CONFIG_MATHEMU
154 extern int sysctl_ieee_emulation_warnings;
156 extern int sysctl_userprocess_debug;
157 extern int spin_retry;
161 extern int no_unaligned_warning;
162 extern int unaligned_dump_stack;
165 #ifdef CONFIG_PROC_SYSCTL
166 static int proc_do_cad_pid(struct ctl_table *table, int write,
167 void __user *buffer, size_t *lenp, loff_t *ppos);
168 static int proc_taint(struct ctl_table *table, int write,
169 void __user *buffer, size_t *lenp, loff_t *ppos);
172 #ifdef CONFIG_MAGIC_SYSRQ
173 /* Note: sysrq code uses it's own private copy */
174 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
176 static int sysrq_sysctl_handler(ctl_table *table, int write,
177 void __user *buffer, size_t *lenp,
182 error = proc_dointvec(table, write, buffer, lenp, ppos);
187 sysrq_toggle_support(__sysrq_enabled);
194 static struct ctl_table root_table[];
195 static struct ctl_table_root sysctl_table_root;
196 static struct ctl_table_header root_table_header = {
198 .ctl_table = root_table,
199 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}},
200 .root = &sysctl_table_root,
201 .set = &sysctl_table_root.default_set,
203 static struct ctl_table_root sysctl_table_root = {
204 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
205 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
208 static struct ctl_table kern_table[];
209 static struct ctl_table vm_table[];
210 static struct ctl_table fs_table[];
211 static struct ctl_table debug_table[];
212 static struct ctl_table dev_table[];
213 extern struct ctl_table random_table[];
215 extern struct ctl_table epoll_table[];
218 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
219 int sysctl_legacy_va_layout;
222 /* The default sysctl tables: */
224 static struct ctl_table root_table[] = {
226 .procname = "kernel",
243 .child = debug_table,
253 #ifdef CONFIG_SCHED_DEBUG
254 static int min_sched_granularity_ns = 100000; /* 100 usecs */
255 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
256 static int min_wakeup_granularity_ns; /* 0 usecs */
257 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
258 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
259 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
262 #ifdef CONFIG_COMPACTION
263 static int min_extfrag_threshold;
264 static int max_extfrag_threshold = 1000;
267 static struct ctl_table kern_table[] = {
269 .procname = "sched_child_runs_first",
270 .data = &sysctl_sched_child_runs_first,
271 .maxlen = sizeof(unsigned int),
273 .proc_handler = proc_dointvec,
275 #ifdef CONFIG_SCHED_DEBUG
277 .procname = "sched_min_granularity_ns",
278 .data = &sysctl_sched_min_granularity,
279 .maxlen = sizeof(unsigned int),
281 .proc_handler = sched_proc_update_handler,
282 .extra1 = &min_sched_granularity_ns,
283 .extra2 = &max_sched_granularity_ns,
286 .procname = "sched_latency_ns",
287 .data = &sysctl_sched_latency,
288 .maxlen = sizeof(unsigned int),
290 .proc_handler = sched_proc_update_handler,
291 .extra1 = &min_sched_granularity_ns,
292 .extra2 = &max_sched_granularity_ns,
295 .procname = "sched_wakeup_granularity_ns",
296 .data = &sysctl_sched_wakeup_granularity,
297 .maxlen = sizeof(unsigned int),
299 .proc_handler = sched_proc_update_handler,
300 .extra1 = &min_wakeup_granularity_ns,
301 .extra2 = &max_wakeup_granularity_ns,
304 .procname = "sched_tunable_scaling",
305 .data = &sysctl_sched_tunable_scaling,
306 .maxlen = sizeof(enum sched_tunable_scaling),
308 .proc_handler = sched_proc_update_handler,
309 .extra1 = &min_sched_tunable_scaling,
310 .extra2 = &max_sched_tunable_scaling,
313 .procname = "sched_migration_cost",
314 .data = &sysctl_sched_migration_cost,
315 .maxlen = sizeof(unsigned int),
317 .proc_handler = proc_dointvec,
320 .procname = "sched_nr_migrate",
321 .data = &sysctl_sched_nr_migrate,
322 .maxlen = sizeof(unsigned int),
324 .proc_handler = proc_dointvec,
327 .procname = "sched_time_avg",
328 .data = &sysctl_sched_time_avg,
329 .maxlen = sizeof(unsigned int),
331 .proc_handler = proc_dointvec,
334 .procname = "sched_shares_window",
335 .data = &sysctl_sched_shares_window,
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_SCHED_AUTOGROUP
373 .procname = "sched_autogroup_enabled",
374 .data = &sysctl_sched_autogroup_enabled,
375 .maxlen = sizeof(unsigned int),
377 .proc_handler = proc_dointvec,
382 #ifdef CONFIG_PROVE_LOCKING
384 .procname = "prove_locking",
385 .data = &prove_locking,
386 .maxlen = sizeof(int),
388 .proc_handler = proc_dointvec,
391 #ifdef CONFIG_LOCK_STAT
393 .procname = "lock_stat",
395 .maxlen = sizeof(int),
397 .proc_handler = proc_dointvec,
402 .data = &panic_timeout,
403 .maxlen = sizeof(int),
405 .proc_handler = proc_dointvec,
408 .procname = "core_uses_pid",
409 .data = &core_uses_pid,
410 .maxlen = sizeof(int),
412 .proc_handler = proc_dointvec,
415 .procname = "core_pattern",
416 .data = core_pattern,
417 .maxlen = CORENAME_MAX_SIZE,
419 .proc_handler = proc_dostring,
422 .procname = "core_pipe_limit",
423 .data = &core_pipe_limit,
424 .maxlen = sizeof(unsigned int),
426 .proc_handler = proc_dointvec,
428 #ifdef CONFIG_PROC_SYSCTL
430 .procname = "tainted",
431 .maxlen = sizeof(long),
433 .proc_handler = proc_taint,
436 #ifdef CONFIG_LATENCYTOP
438 .procname = "latencytop",
439 .data = &latencytop_enabled,
440 .maxlen = sizeof(int),
442 .proc_handler = proc_dointvec,
445 #ifdef CONFIG_BLK_DEV_INITRD
447 .procname = "real-root-dev",
448 .data = &real_root_dev,
449 .maxlen = sizeof(int),
451 .proc_handler = proc_dointvec,
455 .procname = "print-fatal-signals",
456 .data = &print_fatal_signals,
457 .maxlen = sizeof(int),
459 .proc_handler = proc_dointvec,
463 .procname = "reboot-cmd",
464 .data = reboot_command,
467 .proc_handler = proc_dostring,
470 .procname = "stop-a",
471 .data = &stop_a_enabled,
472 .maxlen = sizeof (int),
474 .proc_handler = proc_dointvec,
477 .procname = "scons-poweroff",
478 .data = &scons_pwroff,
479 .maxlen = sizeof (int),
481 .proc_handler = proc_dointvec,
484 #ifdef CONFIG_SPARC64
486 .procname = "tsb-ratio",
487 .data = &sysctl_tsb_ratio,
488 .maxlen = sizeof (int),
490 .proc_handler = proc_dointvec,
495 .procname = "soft-power",
496 .data = &pwrsw_enabled,
497 .maxlen = sizeof (int),
499 .proc_handler = proc_dointvec,
502 .procname = "unaligned-trap",
503 .data = &unaligned_enabled,
504 .maxlen = sizeof (int),
506 .proc_handler = proc_dointvec,
510 .procname = "ctrl-alt-del",
512 .maxlen = sizeof(int),
514 .proc_handler = proc_dointvec,
516 #ifdef CONFIG_FUNCTION_TRACER
518 .procname = "ftrace_enabled",
519 .data = &ftrace_enabled,
520 .maxlen = sizeof(int),
522 .proc_handler = ftrace_enable_sysctl,
525 #ifdef CONFIG_STACK_TRACER
527 .procname = "stack_tracer_enabled",
528 .data = &stack_tracer_enabled,
529 .maxlen = sizeof(int),
531 .proc_handler = stack_trace_sysctl,
534 #ifdef CONFIG_TRACING
536 .procname = "ftrace_dump_on_oops",
537 .data = &ftrace_dump_on_oops,
538 .maxlen = sizeof(int),
540 .proc_handler = proc_dointvec,
543 #ifdef CONFIG_MODULES
545 .procname = "modprobe",
546 .data = &modprobe_path,
547 .maxlen = KMOD_PATH_LEN,
549 .proc_handler = proc_dostring,
552 .procname = "modules_disabled",
553 .data = &modules_disabled,
554 .maxlen = sizeof(int),
556 /* only handle a transition from default "0" to "1" */
557 .proc_handler = proc_dointvec_minmax,
562 #ifdef CONFIG_HOTPLUG
564 .procname = "hotplug",
565 .data = &uevent_helper,
566 .maxlen = UEVENT_HELPER_PATH_LEN,
568 .proc_handler = proc_dostring,
571 #ifdef CONFIG_CHR_DEV_SG
573 .procname = "sg-big-buff",
574 .data = &sg_big_buff,
575 .maxlen = sizeof (int),
577 .proc_handler = proc_dointvec,
580 #ifdef CONFIG_BSD_PROCESS_ACCT
584 .maxlen = 3*sizeof(int),
586 .proc_handler = proc_dointvec,
589 #ifdef CONFIG_MAGIC_SYSRQ
592 .data = &__sysrq_enabled,
593 .maxlen = sizeof (int),
595 .proc_handler = sysrq_sysctl_handler,
598 #ifdef CONFIG_PROC_SYSCTL
600 .procname = "cad_pid",
602 .maxlen = sizeof (int),
604 .proc_handler = proc_do_cad_pid,
608 .procname = "threads-max",
609 .data = &max_threads,
610 .maxlen = sizeof(int),
612 .proc_handler = proc_dointvec,
615 .procname = "random",
617 .child = random_table,
620 .procname = "overflowuid",
621 .data = &overflowuid,
622 .maxlen = sizeof(int),
624 .proc_handler = proc_dointvec_minmax,
625 .extra1 = &minolduid,
626 .extra2 = &maxolduid,
629 .procname = "overflowgid",
630 .data = &overflowgid,
631 .maxlen = sizeof(int),
633 .proc_handler = proc_dointvec_minmax,
634 .extra1 = &minolduid,
635 .extra2 = &maxolduid,
638 #ifdef CONFIG_MATHEMU
640 .procname = "ieee_emulation_warnings",
641 .data = &sysctl_ieee_emulation_warnings,
642 .maxlen = sizeof(int),
644 .proc_handler = proc_dointvec,
648 .procname = "userprocess_debug",
649 .data = &show_unhandled_signals,
650 .maxlen = sizeof(int),
652 .proc_handler = proc_dointvec,
656 .procname = "pid_max",
658 .maxlen = sizeof (int),
660 .proc_handler = proc_dointvec_minmax,
661 .extra1 = &pid_max_min,
662 .extra2 = &pid_max_max,
665 .procname = "panic_on_oops",
666 .data = &panic_on_oops,
667 .maxlen = sizeof(int),
669 .proc_handler = proc_dointvec,
671 #if defined CONFIG_PRINTK
673 .procname = "printk",
674 .data = &console_loglevel,
675 .maxlen = 4*sizeof(int),
677 .proc_handler = proc_dointvec,
680 .procname = "printk_ratelimit",
681 .data = &printk_ratelimit_state.interval,
682 .maxlen = sizeof(int),
684 .proc_handler = proc_dointvec_jiffies,
687 .procname = "printk_ratelimit_burst",
688 .data = &printk_ratelimit_state.burst,
689 .maxlen = sizeof(int),
691 .proc_handler = proc_dointvec,
694 .procname = "printk_delay",
695 .data = &printk_delay_msec,
696 .maxlen = sizeof(int),
698 .proc_handler = proc_dointvec_minmax,
700 .extra2 = &ten_thousand,
703 .procname = "dmesg_restrict",
704 .data = &dmesg_restrict,
705 .maxlen = sizeof(int),
707 .proc_handler = proc_dointvec_minmax,
712 .procname = "kptr_restrict",
713 .data = &kptr_restrict,
714 .maxlen = sizeof(int),
716 .proc_handler = proc_dointvec_minmax,
722 .procname = "ngroups_max",
723 .data = &ngroups_max,
724 .maxlen = sizeof (int),
726 .proc_handler = proc_dointvec,
728 #if defined(CONFIG_LOCKUP_DETECTOR)
730 .procname = "watchdog",
731 .data = &watchdog_enabled,
732 .maxlen = sizeof (int),
734 .proc_handler = proc_dowatchdog_enabled,
737 .procname = "watchdog_thresh",
738 .data = &softlockup_thresh,
739 .maxlen = sizeof(int),
741 .proc_handler = proc_dowatchdog_thresh,
746 .procname = "softlockup_panic",
747 .data = &softlockup_panic,
748 .maxlen = sizeof(int),
750 .proc_handler = proc_dointvec_minmax,
755 .procname = "nmi_watchdog",
756 .data = &watchdog_enabled,
757 .maxlen = sizeof (int),
759 .proc_handler = proc_dowatchdog_enabled,
762 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
764 .procname = "unknown_nmi_panic",
765 .data = &unknown_nmi_panic,
766 .maxlen = sizeof (int),
768 .proc_handler = proc_dointvec,
771 #if defined(CONFIG_X86)
773 .procname = "panic_on_unrecovered_nmi",
774 .data = &panic_on_unrecovered_nmi,
775 .maxlen = sizeof(int),
777 .proc_handler = proc_dointvec,
780 .procname = "panic_on_io_nmi",
781 .data = &panic_on_io_nmi,
782 .maxlen = sizeof(int),
784 .proc_handler = proc_dointvec,
787 .procname = "bootloader_type",
788 .data = &bootloader_type,
789 .maxlen = sizeof (int),
791 .proc_handler = proc_dointvec,
794 .procname = "bootloader_version",
795 .data = &bootloader_version,
796 .maxlen = sizeof (int),
798 .proc_handler = proc_dointvec,
801 .procname = "kstack_depth_to_print",
802 .data = &kstack_depth_to_print,
803 .maxlen = sizeof(int),
805 .proc_handler = proc_dointvec,
808 .procname = "io_delay_type",
809 .data = &io_delay_type,
810 .maxlen = sizeof(int),
812 .proc_handler = proc_dointvec,
815 #if defined(CONFIG_MMU)
817 .procname = "randomize_va_space",
818 .data = &randomize_va_space,
819 .maxlen = sizeof(int),
821 .proc_handler = proc_dointvec,
824 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
826 .procname = "spin_retry",
828 .maxlen = sizeof (int),
830 .proc_handler = proc_dointvec,
833 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
835 .procname = "acpi_video_flags",
836 .data = &acpi_realmode_flags,
837 .maxlen = sizeof (unsigned long),
839 .proc_handler = proc_doulongvec_minmax,
844 .procname = "ignore-unaligned-usertrap",
845 .data = &no_unaligned_warning,
846 .maxlen = sizeof (int),
848 .proc_handler = proc_dointvec,
851 .procname = "unaligned-dump-stack",
852 .data = &unaligned_dump_stack,
853 .maxlen = sizeof (int),
855 .proc_handler = proc_dointvec,
858 #ifdef CONFIG_DETECT_HUNG_TASK
860 .procname = "hung_task_panic",
861 .data = &sysctl_hung_task_panic,
862 .maxlen = sizeof(int),
864 .proc_handler = proc_dointvec_minmax,
869 .procname = "hung_task_check_count",
870 .data = &sysctl_hung_task_check_count,
871 .maxlen = sizeof(unsigned long),
873 .proc_handler = proc_doulongvec_minmax,
876 .procname = "hung_task_timeout_secs",
877 .data = &sysctl_hung_task_timeout_secs,
878 .maxlen = sizeof(unsigned long),
880 .proc_handler = proc_dohung_task_timeout_secs,
883 .procname = "hung_task_warnings",
884 .data = &sysctl_hung_task_warnings,
885 .maxlen = sizeof(unsigned long),
887 .proc_handler = proc_doulongvec_minmax,
892 .procname = "compat-log",
894 .maxlen = sizeof (int),
896 .proc_handler = proc_dointvec,
899 #ifdef CONFIG_RT_MUTEXES
901 .procname = "max_lock_depth",
902 .data = &max_lock_depth,
903 .maxlen = sizeof(int),
905 .proc_handler = proc_dointvec,
909 .procname = "poweroff_cmd",
910 .data = &poweroff_cmd,
911 .maxlen = POWEROFF_CMD_PATH_LEN,
913 .proc_handler = proc_dostring,
919 .child = key_sysctls,
922 #ifdef CONFIG_RCU_TORTURE_TEST
924 .procname = "rcutorture_runnable",
925 .data = &rcutorture_runnable,
926 .maxlen = sizeof(int),
928 .proc_handler = proc_dointvec,
931 #ifdef CONFIG_PERF_EVENTS
933 .procname = "perf_event_paranoid",
934 .data = &sysctl_perf_event_paranoid,
935 .maxlen = sizeof(sysctl_perf_event_paranoid),
937 .proc_handler = proc_dointvec,
940 .procname = "perf_event_mlock_kb",
941 .data = &sysctl_perf_event_mlock,
942 .maxlen = sizeof(sysctl_perf_event_mlock),
944 .proc_handler = proc_dointvec,
947 .procname = "perf_event_max_sample_rate",
948 .data = &sysctl_perf_event_sample_rate,
949 .maxlen = sizeof(sysctl_perf_event_sample_rate),
951 .proc_handler = proc_dointvec,
954 #ifdef CONFIG_KMEMCHECK
956 .procname = "kmemcheck",
957 .data = &kmemcheck_enabled,
958 .maxlen = sizeof(int),
960 .proc_handler = proc_dointvec,
965 .procname = "blk_iopoll",
966 .data = &blk_iopoll_enabled,
967 .maxlen = sizeof(int),
969 .proc_handler = proc_dointvec,
975 static struct ctl_table vm_table[] = {
977 .procname = "overcommit_memory",
978 .data = &sysctl_overcommit_memory,
979 .maxlen = sizeof(sysctl_overcommit_memory),
981 .proc_handler = proc_dointvec,
984 .procname = "panic_on_oom",
985 .data = &sysctl_panic_on_oom,
986 .maxlen = sizeof(sysctl_panic_on_oom),
988 .proc_handler = proc_dointvec,
991 .procname = "oom_kill_allocating_task",
992 .data = &sysctl_oom_kill_allocating_task,
993 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
995 .proc_handler = proc_dointvec,
998 .procname = "oom_dump_tasks",
999 .data = &sysctl_oom_dump_tasks,
1000 .maxlen = sizeof(sysctl_oom_dump_tasks),
1002 .proc_handler = proc_dointvec,
1005 .procname = "overcommit_ratio",
1006 .data = &sysctl_overcommit_ratio,
1007 .maxlen = sizeof(sysctl_overcommit_ratio),
1009 .proc_handler = proc_dointvec,
1012 .procname = "page-cluster",
1013 .data = &page_cluster,
1014 .maxlen = sizeof(int),
1016 .proc_handler = proc_dointvec,
1019 .procname = "dirty_background_ratio",
1020 .data = &dirty_background_ratio,
1021 .maxlen = sizeof(dirty_background_ratio),
1023 .proc_handler = dirty_background_ratio_handler,
1025 .extra2 = &one_hundred,
1028 .procname = "dirty_background_bytes",
1029 .data = &dirty_background_bytes,
1030 .maxlen = sizeof(dirty_background_bytes),
1032 .proc_handler = dirty_background_bytes_handler,
1036 .procname = "dirty_ratio",
1037 .data = &vm_dirty_ratio,
1038 .maxlen = sizeof(vm_dirty_ratio),
1040 .proc_handler = dirty_ratio_handler,
1042 .extra2 = &one_hundred,
1045 .procname = "dirty_bytes",
1046 .data = &vm_dirty_bytes,
1047 .maxlen = sizeof(vm_dirty_bytes),
1049 .proc_handler = dirty_bytes_handler,
1050 .extra1 = &dirty_bytes_min,
1053 .procname = "dirty_writeback_centisecs",
1054 .data = &dirty_writeback_interval,
1055 .maxlen = sizeof(dirty_writeback_interval),
1057 .proc_handler = dirty_writeback_centisecs_handler,
1060 .procname = "dirty_expire_centisecs",
1061 .data = &dirty_expire_interval,
1062 .maxlen = sizeof(dirty_expire_interval),
1064 .proc_handler = proc_dointvec,
1067 .procname = "nr_pdflush_threads",
1068 .data = &nr_pdflush_threads,
1069 .maxlen = sizeof nr_pdflush_threads,
1070 .mode = 0444 /* read-only*/,
1071 .proc_handler = proc_dointvec,
1074 .procname = "swappiness",
1075 .data = &vm_swappiness,
1076 .maxlen = sizeof(vm_swappiness),
1078 .proc_handler = proc_dointvec_minmax,
1080 .extra2 = &one_hundred,
1082 #ifdef CONFIG_HUGETLB_PAGE
1084 .procname = "nr_hugepages",
1086 .maxlen = sizeof(unsigned long),
1088 .proc_handler = hugetlb_sysctl_handler,
1089 .extra1 = (void *)&hugetlb_zero,
1090 .extra2 = (void *)&hugetlb_infinity,
1094 .procname = "nr_hugepages_mempolicy",
1096 .maxlen = sizeof(unsigned long),
1098 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1099 .extra1 = (void *)&hugetlb_zero,
1100 .extra2 = (void *)&hugetlb_infinity,
1104 .procname = "hugetlb_shm_group",
1105 .data = &sysctl_hugetlb_shm_group,
1106 .maxlen = sizeof(gid_t),
1108 .proc_handler = proc_dointvec,
1111 .procname = "hugepages_treat_as_movable",
1112 .data = &hugepages_treat_as_movable,
1113 .maxlen = sizeof(int),
1115 .proc_handler = hugetlb_treat_movable_handler,
1118 .procname = "nr_overcommit_hugepages",
1120 .maxlen = sizeof(unsigned long),
1122 .proc_handler = hugetlb_overcommit_handler,
1123 .extra1 = (void *)&hugetlb_zero,
1124 .extra2 = (void *)&hugetlb_infinity,
1128 .procname = "lowmem_reserve_ratio",
1129 .data = &sysctl_lowmem_reserve_ratio,
1130 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1132 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1135 .procname = "drop_caches",
1136 .data = &sysctl_drop_caches,
1137 .maxlen = sizeof(int),
1139 .proc_handler = drop_caches_sysctl_handler,
1141 #ifdef CONFIG_COMPACTION
1143 .procname = "compact_memory",
1144 .data = &sysctl_compact_memory,
1145 .maxlen = sizeof(int),
1147 .proc_handler = sysctl_compaction_handler,
1150 .procname = "extfrag_threshold",
1151 .data = &sysctl_extfrag_threshold,
1152 .maxlen = sizeof(int),
1154 .proc_handler = sysctl_extfrag_handler,
1155 .extra1 = &min_extfrag_threshold,
1156 .extra2 = &max_extfrag_threshold,
1159 #endif /* CONFIG_COMPACTION */
1161 .procname = "min_free_kbytes",
1162 .data = &min_free_kbytes,
1163 .maxlen = sizeof(min_free_kbytes),
1165 .proc_handler = min_free_kbytes_sysctl_handler,
1169 .procname = "percpu_pagelist_fraction",
1170 .data = &percpu_pagelist_fraction,
1171 .maxlen = sizeof(percpu_pagelist_fraction),
1173 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1174 .extra1 = &min_percpu_pagelist_fract,
1178 .procname = "max_map_count",
1179 .data = &sysctl_max_map_count,
1180 .maxlen = sizeof(sysctl_max_map_count),
1182 .proc_handler = proc_dointvec_minmax,
1187 .procname = "nr_trim_pages",
1188 .data = &sysctl_nr_trim_pages,
1189 .maxlen = sizeof(sysctl_nr_trim_pages),
1191 .proc_handler = proc_dointvec_minmax,
1196 .procname = "laptop_mode",
1197 .data = &laptop_mode,
1198 .maxlen = sizeof(laptop_mode),
1200 .proc_handler = proc_dointvec_jiffies,
1203 .procname = "block_dump",
1204 .data = &block_dump,
1205 .maxlen = sizeof(block_dump),
1207 .proc_handler = proc_dointvec,
1211 .procname = "vfs_cache_pressure",
1212 .data = &sysctl_vfs_cache_pressure,
1213 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1215 .proc_handler = proc_dointvec,
1218 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1220 .procname = "legacy_va_layout",
1221 .data = &sysctl_legacy_va_layout,
1222 .maxlen = sizeof(sysctl_legacy_va_layout),
1224 .proc_handler = proc_dointvec,
1230 .procname = "zone_reclaim_mode",
1231 .data = &zone_reclaim_mode,
1232 .maxlen = sizeof(zone_reclaim_mode),
1234 .proc_handler = proc_dointvec,
1238 .procname = "min_unmapped_ratio",
1239 .data = &sysctl_min_unmapped_ratio,
1240 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1242 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1244 .extra2 = &one_hundred,
1247 .procname = "min_slab_ratio",
1248 .data = &sysctl_min_slab_ratio,
1249 .maxlen = sizeof(sysctl_min_slab_ratio),
1251 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1253 .extra2 = &one_hundred,
1258 .procname = "stat_interval",
1259 .data = &sysctl_stat_interval,
1260 .maxlen = sizeof(sysctl_stat_interval),
1262 .proc_handler = proc_dointvec_jiffies,
1267 .procname = "mmap_min_addr",
1268 .data = &dac_mmap_min_addr,
1269 .maxlen = sizeof(unsigned long),
1271 .proc_handler = mmap_min_addr_handler,
1276 .procname = "numa_zonelist_order",
1277 .data = &numa_zonelist_order,
1278 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1280 .proc_handler = numa_zonelist_order_handler,
1283 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1284 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1286 .procname = "vdso_enabled",
1287 .data = &vdso_enabled,
1288 .maxlen = sizeof(vdso_enabled),
1290 .proc_handler = proc_dointvec,
1294 #ifdef CONFIG_HIGHMEM
1296 .procname = "highmem_is_dirtyable",
1297 .data = &vm_highmem_is_dirtyable,
1298 .maxlen = sizeof(vm_highmem_is_dirtyable),
1300 .proc_handler = proc_dointvec_minmax,
1306 .procname = "scan_unevictable_pages",
1307 .data = &scan_unevictable_pages,
1308 .maxlen = sizeof(scan_unevictable_pages),
1310 .proc_handler = scan_unevictable_handler,
1312 #ifdef CONFIG_MEMORY_FAILURE
1314 .procname = "memory_failure_early_kill",
1315 .data = &sysctl_memory_failure_early_kill,
1316 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1318 .proc_handler = proc_dointvec_minmax,
1323 .procname = "memory_failure_recovery",
1324 .data = &sysctl_memory_failure_recovery,
1325 .maxlen = sizeof(sysctl_memory_failure_recovery),
1327 .proc_handler = proc_dointvec_minmax,
1335 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1336 static struct ctl_table binfmt_misc_table[] = {
1341 static struct ctl_table fs_table[] = {
1343 .procname = "inode-nr",
1344 .data = &inodes_stat,
1345 .maxlen = 2*sizeof(int),
1347 .proc_handler = proc_nr_inodes,
1350 .procname = "inode-state",
1351 .data = &inodes_stat,
1352 .maxlen = 7*sizeof(int),
1354 .proc_handler = proc_nr_inodes,
1357 .procname = "file-nr",
1358 .data = &files_stat,
1359 .maxlen = sizeof(files_stat),
1361 .proc_handler = proc_nr_files,
1364 .procname = "file-max",
1365 .data = &files_stat.max_files,
1366 .maxlen = sizeof(files_stat.max_files),
1368 .proc_handler = proc_doulongvec_minmax,
1371 .procname = "nr_open",
1372 .data = &sysctl_nr_open,
1373 .maxlen = sizeof(int),
1375 .proc_handler = proc_dointvec_minmax,
1376 .extra1 = &sysctl_nr_open_min,
1377 .extra2 = &sysctl_nr_open_max,
1380 .procname = "dentry-state",
1381 .data = &dentry_stat,
1382 .maxlen = 6*sizeof(int),
1384 .proc_handler = proc_nr_dentry,
1387 .procname = "overflowuid",
1388 .data = &fs_overflowuid,
1389 .maxlen = sizeof(int),
1391 .proc_handler = proc_dointvec_minmax,
1392 .extra1 = &minolduid,
1393 .extra2 = &maxolduid,
1396 .procname = "overflowgid",
1397 .data = &fs_overflowgid,
1398 .maxlen = sizeof(int),
1400 .proc_handler = proc_dointvec_minmax,
1401 .extra1 = &minolduid,
1402 .extra2 = &maxolduid,
1404 #ifdef CONFIG_FILE_LOCKING
1406 .procname = "leases-enable",
1407 .data = &leases_enable,
1408 .maxlen = sizeof(int),
1410 .proc_handler = proc_dointvec,
1413 #ifdef CONFIG_DNOTIFY
1415 .procname = "dir-notify-enable",
1416 .data = &dir_notify_enable,
1417 .maxlen = sizeof(int),
1419 .proc_handler = proc_dointvec,
1423 #ifdef CONFIG_FILE_LOCKING
1425 .procname = "lease-break-time",
1426 .data = &lease_break_time,
1427 .maxlen = sizeof(int),
1429 .proc_handler = proc_dointvec,
1434 .procname = "aio-nr",
1436 .maxlen = sizeof(aio_nr),
1438 .proc_handler = proc_doulongvec_minmax,
1441 .procname = "aio-max-nr",
1442 .data = &aio_max_nr,
1443 .maxlen = sizeof(aio_max_nr),
1445 .proc_handler = proc_doulongvec_minmax,
1447 #endif /* CONFIG_AIO */
1448 #ifdef CONFIG_INOTIFY_USER
1450 .procname = "inotify",
1452 .child = inotify_table,
1457 .procname = "epoll",
1459 .child = epoll_table,
1464 .procname = "suid_dumpable",
1465 .data = &suid_dumpable,
1466 .maxlen = sizeof(int),
1468 .proc_handler = proc_dointvec_minmax,
1472 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1474 .procname = "binfmt_misc",
1476 .child = binfmt_misc_table,
1480 .procname = "pipe-max-size",
1481 .data = &pipe_max_size,
1482 .maxlen = sizeof(int),
1484 .proc_handler = &pipe_proc_fn,
1485 .extra1 = &pipe_min_size,
1490 static struct ctl_table debug_table[] = {
1491 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1492 defined(CONFIG_S390)
1494 .procname = "exception-trace",
1495 .data = &show_unhandled_signals,
1496 .maxlen = sizeof(int),
1498 .proc_handler = proc_dointvec
1501 #if defined(CONFIG_OPTPROBES)
1503 .procname = "kprobes-optimization",
1504 .data = &sysctl_kprobes_optimization,
1505 .maxlen = sizeof(int),
1507 .proc_handler = proc_kprobes_optimization_handler,
1515 static struct ctl_table dev_table[] = {
1519 static DEFINE_SPINLOCK(sysctl_lock);
1521 /* called under sysctl_lock */
1522 static int use_table(struct ctl_table_header *p)
1524 if (unlikely(p->unregistering))
1530 /* called under sysctl_lock */
1531 static void unuse_table(struct ctl_table_header *p)
1534 if (unlikely(p->unregistering))
1535 complete(p->unregistering);
1538 /* called under sysctl_lock, will reacquire if has to wait */
1539 static void start_unregistering(struct ctl_table_header *p)
1542 * if p->used is 0, nobody will ever touch that entry again;
1543 * we'll eliminate all paths to it before dropping sysctl_lock
1545 if (unlikely(p->used)) {
1546 struct completion wait;
1547 init_completion(&wait);
1548 p->unregistering = &wait;
1549 spin_unlock(&sysctl_lock);
1550 wait_for_completion(&wait);
1551 spin_lock(&sysctl_lock);
1553 /* anything non-NULL; we'll never dereference it */
1554 p->unregistering = ERR_PTR(-EINVAL);
1557 * do not remove from the list until nobody holds it; walking the
1558 * list in do_sysctl() relies on that.
1560 list_del_init(&p->ctl_entry);
1563 void sysctl_head_get(struct ctl_table_header *head)
1565 spin_lock(&sysctl_lock);
1567 spin_unlock(&sysctl_lock);
1570 static void free_head(struct rcu_head *rcu)
1572 kfree(container_of(rcu, struct ctl_table_header, rcu));
1575 void sysctl_head_put(struct ctl_table_header *head)
1577 spin_lock(&sysctl_lock);
1579 call_rcu(&head->rcu, free_head);
1580 spin_unlock(&sysctl_lock);
1583 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1587 spin_lock(&sysctl_lock);
1588 if (!use_table(head))
1589 head = ERR_PTR(-ENOENT);
1590 spin_unlock(&sysctl_lock);
1594 void sysctl_head_finish(struct ctl_table_header *head)
1598 spin_lock(&sysctl_lock);
1600 spin_unlock(&sysctl_lock);
1603 static struct ctl_table_set *
1604 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1606 struct ctl_table_set *set = &root->default_set;
1608 set = root->lookup(root, namespaces);
1612 static struct list_head *
1613 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1615 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1619 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1620 struct ctl_table_header *prev)
1622 struct ctl_table_root *root;
1623 struct list_head *header_list;
1624 struct ctl_table_header *head;
1625 struct list_head *tmp;
1627 spin_lock(&sysctl_lock);
1630 tmp = &prev->ctl_entry;
1634 tmp = &root_table_header.ctl_entry;
1636 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1638 if (!use_table(head))
1640 spin_unlock(&sysctl_lock);
1645 header_list = lookup_header_list(root, namespaces);
1646 if (tmp != header_list)
1650 root = list_entry(root->root_list.next,
1651 struct ctl_table_root, root_list);
1652 if (root == &sysctl_table_root)
1654 header_list = lookup_header_list(root, namespaces);
1655 } while (list_empty(header_list));
1656 tmp = header_list->next;
1659 spin_unlock(&sysctl_lock);
1663 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1665 return __sysctl_head_next(current->nsproxy, prev);
1668 void register_sysctl_root(struct ctl_table_root *root)
1670 spin_lock(&sysctl_lock);
1671 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1672 spin_unlock(&sysctl_lock);
1676 * sysctl_perm does NOT grant the superuser all rights automatically, because
1677 * some sysctl variables are readonly even to root.
1680 static int test_perm(int mode, int op)
1682 if (!current_euid())
1684 else if (in_egroup_p(0))
1686 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1691 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1696 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1700 if (root->permissions)
1701 mode = root->permissions(root, current->nsproxy, table);
1705 return test_perm(mode, op);
1708 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1710 for (; table->procname; table++) {
1711 table->parent = parent;
1713 sysctl_set_parent(table, table->child);
1717 static __init int sysctl_init(void)
1719 sysctl_set_parent(NULL, root_table);
1720 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1721 sysctl_check_table(current->nsproxy, root_table);
1726 core_initcall(sysctl_init);
1728 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1729 struct ctl_table *table)
1731 struct ctl_table *p;
1732 const char *s = branch->procname;
1734 /* branch should have named subdirectory as its first element */
1735 if (!s || !branch->child)
1738 /* ... and nothing else */
1739 if (branch[1].procname)
1742 /* table should contain subdirectory with the same name */
1743 for (p = table; p->procname; p++) {
1746 if (p->procname && strcmp(p->procname, s) == 0)
1752 /* see if attaching q to p would be an improvement */
1753 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1755 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1756 struct ctl_table *next;
1758 int not_in_parent = !p->attached_by;
1760 while ((next = is_branch_in(by, to)) != NULL) {
1761 if (by == q->attached_by)
1763 if (to == p->attached_by)
1769 if (is_better && not_in_parent) {
1770 q->attached_by = by;
1771 q->attached_to = to;
1777 * __register_sysctl_paths - register a sysctl hierarchy
1778 * @root: List of sysctl headers to register on
1779 * @namespaces: Data to compute which lists of sysctl entries are visible
1780 * @path: The path to the directory the sysctl table is in.
1781 * @table: the top-level table structure
1783 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1784 * array. A completely 0 filled entry terminates the table.
1786 * The members of the &struct ctl_table structure are used as follows:
1788 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1789 * enter a sysctl file
1791 * data - a pointer to data for use by proc_handler
1793 * maxlen - the maximum size in bytes of the data
1795 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1797 * child - a pointer to the child sysctl table if this entry is a directory, or
1800 * proc_handler - the text handler routine (described below)
1802 * de - for internal use by the sysctl routines
1804 * extra1, extra2 - extra pointers usable by the proc handler routines
1806 * Leaf nodes in the sysctl tree will be represented by a single file
1807 * under /proc; non-leaf nodes will be represented by directories.
1809 * sysctl(2) can automatically manage read and write requests through
1810 * the sysctl table. The data and maxlen fields of the ctl_table
1811 * struct enable minimal validation of the values being written to be
1812 * performed, and the mode field allows minimal authentication.
1814 * There must be a proc_handler routine for any terminal nodes
1815 * mirrored under /proc/sys (non-terminals are handled by a built-in
1816 * directory handler). Several default handlers are available to
1817 * cover common cases -
1819 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1820 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1821 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1823 * It is the handler's job to read the input buffer from user memory
1824 * and process it. The handler should return 0 on success.
1826 * This routine returns %NULL on a failure to register, and a pointer
1827 * to the table header on success.
1829 struct ctl_table_header *__register_sysctl_paths(
1830 struct ctl_table_root *root,
1831 struct nsproxy *namespaces,
1832 const struct ctl_path *path, struct ctl_table *table)
1834 struct ctl_table_header *header;
1835 struct ctl_table *new, **prevp;
1836 unsigned int n, npath;
1837 struct ctl_table_set *set;
1839 /* Count the path components */
1840 for (npath = 0; path[npath].procname; ++npath)
1844 * For each path component, allocate a 2-element ctl_table array.
1845 * The first array element will be filled with the sysctl entry
1846 * for this, the second will be the sentinel (procname == 0).
1848 * We allocate everything in one go so that we don't have to
1849 * worry about freeing additional memory in unregister_sysctl_table.
1851 header = kzalloc(sizeof(struct ctl_table_header) +
1852 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1856 new = (struct ctl_table *) (header + 1);
1858 /* Now connect the dots */
1859 prevp = &header->ctl_table;
1860 for (n = 0; n < npath; ++n, ++path) {
1861 /* Copy the procname */
1862 new->procname = path->procname;
1866 prevp = &new->child;
1871 header->ctl_table_arg = table;
1873 INIT_LIST_HEAD(&header->ctl_entry);
1875 header->unregistering = NULL;
1876 header->root = root;
1877 sysctl_set_parent(NULL, header->ctl_table);
1879 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1880 if (sysctl_check_table(namespaces, header->ctl_table)) {
1885 spin_lock(&sysctl_lock);
1886 header->set = lookup_header_set(root, namespaces);
1887 header->attached_by = header->ctl_table;
1888 header->attached_to = root_table;
1889 header->parent = &root_table_header;
1890 for (set = header->set; set; set = set->parent) {
1891 struct ctl_table_header *p;
1892 list_for_each_entry(p, &set->list, ctl_entry) {
1893 if (p->unregistering)
1895 try_attach(p, header);
1898 header->parent->count++;
1899 list_add_tail(&header->ctl_entry, &header->set->list);
1900 spin_unlock(&sysctl_lock);
1906 * register_sysctl_table_path - register a sysctl table hierarchy
1907 * @path: The path to the directory the sysctl table is in.
1908 * @table: the top-level table structure
1910 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1911 * array. A completely 0 filled entry terminates the table.
1913 * See __register_sysctl_paths for more details.
1915 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1916 struct ctl_table *table)
1918 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1923 * register_sysctl_table - register a sysctl table hierarchy
1924 * @table: the top-level table structure
1926 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1927 * array. A completely 0 filled entry terminates the table.
1929 * See register_sysctl_paths for more details.
1931 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1933 static const struct ctl_path null_path[] = { {} };
1935 return register_sysctl_paths(null_path, table);
1939 * unregister_sysctl_table - unregister a sysctl table hierarchy
1940 * @header: the header returned from register_sysctl_table
1942 * Unregisters the sysctl table and all children. proc entries may not
1943 * actually be removed until they are no longer used by anyone.
1945 void unregister_sysctl_table(struct ctl_table_header * header)
1952 spin_lock(&sysctl_lock);
1953 start_unregistering(header);
1954 if (!--header->parent->count) {
1956 call_rcu(&header->parent->rcu, free_head);
1958 if (!--header->count)
1959 call_rcu(&header->rcu, free_head);
1960 spin_unlock(&sysctl_lock);
1963 int sysctl_is_seen(struct ctl_table_header *p)
1965 struct ctl_table_set *set = p->set;
1967 spin_lock(&sysctl_lock);
1968 if (p->unregistering)
1970 else if (!set->is_seen)
1973 res = set->is_seen(set);
1974 spin_unlock(&sysctl_lock);
1978 void setup_sysctl_set(struct ctl_table_set *p,
1979 struct ctl_table_set *parent,
1980 int (*is_seen)(struct ctl_table_set *))
1982 INIT_LIST_HEAD(&p->list);
1983 p->parent = parent ? parent : &sysctl_table_root.default_set;
1984 p->is_seen = is_seen;
1987 #else /* !CONFIG_SYSCTL */
1988 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1993 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1994 struct ctl_table *table)
1999 void unregister_sysctl_table(struct ctl_table_header * table)
2003 void setup_sysctl_set(struct ctl_table_set *p,
2004 struct ctl_table_set *parent,
2005 int (*is_seen)(struct ctl_table_set *))
2009 void sysctl_head_put(struct ctl_table_header *head)
2013 #endif /* CONFIG_SYSCTL */
2019 #ifdef CONFIG_PROC_SYSCTL
2021 static int _proc_do_string(void* data, int maxlen, int write,
2022 void __user *buffer,
2023 size_t *lenp, loff_t *ppos)
2029 if (!data || !maxlen || !*lenp) {
2037 while (len < *lenp) {
2038 if (get_user(c, p++))
2040 if (c == 0 || c == '\n')
2046 if(copy_from_user(data, buffer, len))
2048 ((char *) data)[len] = 0;
2066 if(copy_to_user(buffer, data, len))
2069 if(put_user('\n', ((char __user *) buffer) + len))
2080 * proc_dostring - read a string sysctl
2081 * @table: the sysctl table
2082 * @write: %TRUE if this is a write to the sysctl file
2083 * @buffer: the user buffer
2084 * @lenp: the size of the user buffer
2085 * @ppos: file position
2087 * Reads/writes a string from/to the user buffer. If the kernel
2088 * buffer provided is not large enough to hold the string, the
2089 * string is truncated. The copied string is %NULL-terminated.
2090 * If the string is being read by the user process, it is copied
2091 * and a newline '\n' is added. It is truncated if the buffer is
2094 * Returns 0 on success.
2096 int proc_dostring(struct ctl_table *table, int write,
2097 void __user *buffer, size_t *lenp, loff_t *ppos)
2099 return _proc_do_string(table->data, table->maxlen, write,
2100 buffer, lenp, ppos);
2103 static size_t proc_skip_spaces(char **buf)
2106 char *tmp = skip_spaces(*buf);
2112 static void proc_skip_char(char **buf, size_t *size, const char v)
2122 #define TMPBUFLEN 22
2124 * proc_get_long - reads an ASCII formatted integer from a user buffer
2126 * @buf: a kernel buffer
2127 * @size: size of the kernel buffer
2128 * @val: this is where the number will be stored
2129 * @neg: set to %TRUE if number is negative
2130 * @perm_tr: a vector which contains the allowed trailers
2131 * @perm_tr_len: size of the perm_tr vector
2132 * @tr: pointer to store the trailer character
2134 * In case of success %0 is returned and @buf and @size are updated with
2135 * the amount of bytes read. If @tr is non-NULL and a trailing
2136 * character exists (size is non-zero after returning from this
2137 * function), @tr is updated with the trailing character.
2139 static int proc_get_long(char **buf, size_t *size,
2140 unsigned long *val, bool *neg,
2141 const char *perm_tr, unsigned perm_tr_len, char *tr)
2144 char *p, tmp[TMPBUFLEN];
2150 if (len > TMPBUFLEN - 1)
2151 len = TMPBUFLEN - 1;
2153 memcpy(tmp, *buf, len);
2157 if (*p == '-' && *size > 1) {
2165 *val = simple_strtoul(p, &p, 0);
2169 /* We don't know if the next char is whitespace thus we may accept
2170 * invalid integers (e.g. 1234...a) or two integers instead of one
2171 * (e.g. 123...1). So lets not allow such large numbers. */
2172 if (len == TMPBUFLEN - 1)
2175 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2178 if (tr && (len < *size))
2188 * proc_put_long - converts an integer to a decimal ASCII formatted string
2190 * @buf: the user buffer
2191 * @size: the size of the user buffer
2192 * @val: the integer to be converted
2193 * @neg: sign of the number, %TRUE for negative
2195 * In case of success %0 is returned and @buf and @size are updated with
2196 * the amount of bytes written.
2198 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2202 char tmp[TMPBUFLEN], *p = tmp;
2204 sprintf(p, "%s%lu", neg ? "-" : "", val);
2208 if (copy_to_user(*buf, tmp, len))
2216 static int proc_put_char(void __user **buf, size_t *size, char c)
2219 char __user **buffer = (char __user **)buf;
2220 if (put_user(c, *buffer))
2222 (*size)--, (*buffer)++;
2228 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2230 int write, void *data)
2233 *valp = *negp ? -*lvalp : *lvalp;
2238 *lvalp = (unsigned long)-val;
2241 *lvalp = (unsigned long)val;
2247 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2249 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2250 int write, void __user *buffer,
2251 size_t *lenp, loff_t *ppos,
2252 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2253 int write, void *data),
2256 int *i, vleft, first = 1, err = 0;
2257 unsigned long page = 0;
2261 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2266 i = (int *) tbl_data;
2267 vleft = table->maxlen / sizeof(*i);
2271 conv = do_proc_dointvec_conv;
2274 if (left > PAGE_SIZE - 1)
2275 left = PAGE_SIZE - 1;
2276 page = __get_free_page(GFP_TEMPORARY);
2277 kbuf = (char *) page;
2280 if (copy_from_user(kbuf, buffer, left)) {
2287 for (; left && vleft--; i++, first=0) {
2292 left -= proc_skip_spaces(&kbuf);
2296 err = proc_get_long(&kbuf, &left, &lval, &neg,
2298 sizeof(proc_wspace_sep), NULL);
2301 if (conv(&neg, &lval, i, 1, data)) {
2306 if (conv(&neg, &lval, i, 0, data)) {
2311 err = proc_put_char(&buffer, &left, '\t');
2314 err = proc_put_long(&buffer, &left, lval, neg);
2320 if (!write && !first && left && !err)
2321 err = proc_put_char(&buffer, &left, '\n');
2322 if (write && !err && left)
2323 left -= proc_skip_spaces(&kbuf);
2328 return err ? : -EINVAL;
2335 static int do_proc_dointvec(struct ctl_table *table, int write,
2336 void __user *buffer, size_t *lenp, loff_t *ppos,
2337 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2338 int write, void *data),
2341 return __do_proc_dointvec(table->data, table, write,
2342 buffer, lenp, ppos, conv, data);
2346 * proc_dointvec - read a vector of integers
2347 * @table: the sysctl table
2348 * @write: %TRUE if this is a write to the sysctl file
2349 * @buffer: the user buffer
2350 * @lenp: the size of the user buffer
2351 * @ppos: file position
2353 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2354 * values from/to the user buffer, treated as an ASCII string.
2356 * Returns 0 on success.
2358 int proc_dointvec(struct ctl_table *table, int write,
2359 void __user *buffer, size_t *lenp, loff_t *ppos)
2361 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2366 * Taint values can only be increased
2367 * This means we can safely use a temporary.
2369 static int proc_taint(struct ctl_table *table, int write,
2370 void __user *buffer, size_t *lenp, loff_t *ppos)
2373 unsigned long tmptaint = get_taint();
2376 if (write && !capable(CAP_SYS_ADMIN))
2381 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2387 * Poor man's atomic or. Not worth adding a primitive
2388 * to everyone's atomic.h for this
2391 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2392 if ((tmptaint >> i) & 1)
2400 struct do_proc_dointvec_minmax_conv_param {
2405 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2407 int write, void *data)
2409 struct do_proc_dointvec_minmax_conv_param *param = data;
2411 int val = *negp ? -*lvalp : *lvalp;
2412 if ((param->min && *param->min > val) ||
2413 (param->max && *param->max < val))
2420 *lvalp = (unsigned long)-val;
2423 *lvalp = (unsigned long)val;
2430 * proc_dointvec_minmax - read a vector of integers with min/max values
2431 * @table: the sysctl table
2432 * @write: %TRUE if this is a write to the sysctl file
2433 * @buffer: the user buffer
2434 * @lenp: the size of the user buffer
2435 * @ppos: file position
2437 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2438 * values from/to the user buffer, treated as an ASCII string.
2440 * This routine will ensure the values are within the range specified by
2441 * table->extra1 (min) and table->extra2 (max).
2443 * Returns 0 on success.
2445 int proc_dointvec_minmax(struct ctl_table *table, int write,
2446 void __user *buffer, size_t *lenp, loff_t *ppos)
2448 struct do_proc_dointvec_minmax_conv_param param = {
2449 .min = (int *) table->extra1,
2450 .max = (int *) table->extra2,
2452 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2453 do_proc_dointvec_minmax_conv, ¶m);
2456 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2457 void __user *buffer,
2458 size_t *lenp, loff_t *ppos,
2459 unsigned long convmul,
2460 unsigned long convdiv)
2462 unsigned long *i, *min, *max;
2463 int vleft, first = 1, err = 0;
2464 unsigned long page = 0;
2468 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2473 i = (unsigned long *) data;
2474 min = (unsigned long *) table->extra1;
2475 max = (unsigned long *) table->extra2;
2476 vleft = table->maxlen / sizeof(unsigned long);
2480 if (left > PAGE_SIZE - 1)
2481 left = PAGE_SIZE - 1;
2482 page = __get_free_page(GFP_TEMPORARY);
2483 kbuf = (char *) page;
2486 if (copy_from_user(kbuf, buffer, left)) {
2493 for (; left && vleft--; i++, first = 0) {
2499 left -= proc_skip_spaces(&kbuf);
2501 err = proc_get_long(&kbuf, &left, &val, &neg,
2503 sizeof(proc_wspace_sep), NULL);
2508 if ((min && val < *min) || (max && val > *max))
2512 val = convdiv * (*i) / convmul;
2514 err = proc_put_char(&buffer, &left, '\t');
2515 err = proc_put_long(&buffer, &left, val, false);
2521 if (!write && !first && left && !err)
2522 err = proc_put_char(&buffer, &left, '\n');
2524 left -= proc_skip_spaces(&kbuf);
2529 return err ? : -EINVAL;
2536 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2537 void __user *buffer,
2538 size_t *lenp, loff_t *ppos,
2539 unsigned long convmul,
2540 unsigned long convdiv)
2542 return __do_proc_doulongvec_minmax(table->data, table, write,
2543 buffer, lenp, ppos, convmul, convdiv);
2547 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2548 * @table: the sysctl table
2549 * @write: %TRUE if this is a write to the sysctl file
2550 * @buffer: the user buffer
2551 * @lenp: the size of the user buffer
2552 * @ppos: file position
2554 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2555 * values from/to the user buffer, treated as an ASCII string.
2557 * This routine will ensure the values are within the range specified by
2558 * table->extra1 (min) and table->extra2 (max).
2560 * Returns 0 on success.
2562 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2563 void __user *buffer, size_t *lenp, loff_t *ppos)
2565 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2569 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2570 * @table: the sysctl table
2571 * @write: %TRUE if this is a write to the sysctl file
2572 * @buffer: the user buffer
2573 * @lenp: the size of the user buffer
2574 * @ppos: file position
2576 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2577 * values from/to the user buffer, treated as an ASCII string. The values
2578 * are treated as milliseconds, and converted to jiffies when they are stored.
2580 * This routine will ensure the values are within the range specified by
2581 * table->extra1 (min) and table->extra2 (max).
2583 * Returns 0 on success.
2585 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2586 void __user *buffer,
2587 size_t *lenp, loff_t *ppos)
2589 return do_proc_doulongvec_minmax(table, write, buffer,
2590 lenp, ppos, HZ, 1000l);
2594 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2596 int write, void *data)
2599 if (*lvalp > LONG_MAX / HZ)
2601 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2607 lval = (unsigned long)-val;
2610 lval = (unsigned long)val;
2617 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2619 int write, void *data)
2622 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2624 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2630 lval = (unsigned long)-val;
2633 lval = (unsigned long)val;
2635 *lvalp = jiffies_to_clock_t(lval);
2640 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2642 int write, void *data)
2645 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2651 lval = (unsigned long)-val;
2654 lval = (unsigned long)val;
2656 *lvalp = jiffies_to_msecs(lval);
2662 * proc_dointvec_jiffies - read a vector of integers as seconds
2663 * @table: the sysctl table
2664 * @write: %TRUE if this is a write to the sysctl file
2665 * @buffer: the user buffer
2666 * @lenp: the size of the user buffer
2667 * @ppos: file position
2669 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2670 * values from/to the user buffer, treated as an ASCII string.
2671 * The values read are assumed to be in seconds, and are converted into
2674 * Returns 0 on success.
2676 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2677 void __user *buffer, size_t *lenp, loff_t *ppos)
2679 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2680 do_proc_dointvec_jiffies_conv,NULL);
2684 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2685 * @table: the sysctl table
2686 * @write: %TRUE if this is a write to the sysctl file
2687 * @buffer: the user buffer
2688 * @lenp: the size of the user buffer
2689 * @ppos: pointer to the file position
2691 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2692 * values from/to the user buffer, treated as an ASCII string.
2693 * The values read are assumed to be in 1/USER_HZ seconds, and
2694 * are converted into jiffies.
2696 * Returns 0 on success.
2698 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2699 void __user *buffer, size_t *lenp, loff_t *ppos)
2701 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2702 do_proc_dointvec_userhz_jiffies_conv,NULL);
2706 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2707 * @table: the sysctl table
2708 * @write: %TRUE if this is a write to the sysctl file
2709 * @buffer: the user buffer
2710 * @lenp: the size of the user buffer
2711 * @ppos: file position
2712 * @ppos: the current position in the file
2714 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2715 * values from/to the user buffer, treated as an ASCII string.
2716 * The values read are assumed to be in 1/1000 seconds, and
2717 * are converted into jiffies.
2719 * Returns 0 on success.
2721 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2722 void __user *buffer, size_t *lenp, loff_t *ppos)
2724 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2725 do_proc_dointvec_ms_jiffies_conv, NULL);
2728 static int proc_do_cad_pid(struct ctl_table *table, int write,
2729 void __user *buffer, size_t *lenp, loff_t *ppos)
2731 struct pid *new_pid;
2735 tmp = pid_vnr(cad_pid);
2737 r = __do_proc_dointvec(&tmp, table, write, buffer,
2738 lenp, ppos, NULL, NULL);
2742 new_pid = find_get_pid(tmp);
2746 put_pid(xchg(&cad_pid, new_pid));
2751 * proc_do_large_bitmap - read/write from/to a large bitmap
2752 * @table: the sysctl table
2753 * @write: %TRUE if this is a write to the sysctl file
2754 * @buffer: the user buffer
2755 * @lenp: the size of the user buffer
2756 * @ppos: file position
2758 * The bitmap is stored at table->data and the bitmap length (in bits)
2761 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2762 * large bitmaps may be represented in a compact manner. Writing into
2763 * the file will clear the bitmap then update it with the given input.
2765 * Returns 0 on success.
2767 int proc_do_large_bitmap(struct ctl_table *table, int write,
2768 void __user *buffer, size_t *lenp, loff_t *ppos)
2772 size_t left = *lenp;
2773 unsigned long bitmap_len = table->maxlen;
2774 unsigned long *bitmap = (unsigned long *) table->data;
2775 unsigned long *tmp_bitmap = NULL;
2776 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2778 if (!bitmap_len || !left || (*ppos && !write)) {
2784 unsigned long page = 0;
2787 if (left > PAGE_SIZE - 1)
2788 left = PAGE_SIZE - 1;
2790 page = __get_free_page(GFP_TEMPORARY);
2791 kbuf = (char *) page;
2794 if (copy_from_user(kbuf, buffer, left)) {
2800 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2806 proc_skip_char(&kbuf, &left, '\n');
2807 while (!err && left) {
2808 unsigned long val_a, val_b;
2811 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2815 if (val_a >= bitmap_len || neg) {
2827 err = proc_get_long(&kbuf, &left, &val_b,
2828 &neg, tr_b, sizeof(tr_b),
2832 if (val_b >= bitmap_len || neg ||
2843 while (val_a <= val_b)
2844 set_bit(val_a++, tmp_bitmap);
2847 proc_skip_char(&kbuf, &left, '\n');
2851 unsigned long bit_a, bit_b = 0;
2854 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2855 if (bit_a >= bitmap_len)
2857 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2861 err = proc_put_char(&buffer, &left, ',');
2865 err = proc_put_long(&buffer, &left, bit_a, false);
2868 if (bit_a != bit_b) {
2869 err = proc_put_char(&buffer, &left, '-');
2872 err = proc_put_long(&buffer, &left, bit_b, false);
2880 err = proc_put_char(&buffer, &left, '\n');
2886 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2888 memcpy(bitmap, tmp_bitmap,
2889 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2901 #else /* CONFIG_PROC_SYSCTL */
2903 int proc_dostring(struct ctl_table *table, int write,
2904 void __user *buffer, size_t *lenp, loff_t *ppos)
2909 int proc_dointvec(struct ctl_table *table, int write,
2910 void __user *buffer, size_t *lenp, loff_t *ppos)
2915 int proc_dointvec_minmax(struct ctl_table *table, int write,
2916 void __user *buffer, size_t *lenp, loff_t *ppos)
2921 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2922 void __user *buffer, size_t *lenp, loff_t *ppos)
2927 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2928 void __user *buffer, size_t *lenp, loff_t *ppos)
2933 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2934 void __user *buffer, size_t *lenp, loff_t *ppos)
2939 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2940 void __user *buffer, size_t *lenp, loff_t *ppos)
2945 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2946 void __user *buffer,
2947 size_t *lenp, loff_t *ppos)
2953 #endif /* CONFIG_PROC_SYSCTL */
2956 * No sense putting this after each symbol definition, twice,
2957 * exception granted :-)
2959 EXPORT_SYMBOL(proc_dointvec);
2960 EXPORT_SYMBOL(proc_dointvec_jiffies);
2961 EXPORT_SYMBOL(proc_dointvec_minmax);
2962 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2963 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2964 EXPORT_SYMBOL(proc_dostring);
2965 EXPORT_SYMBOL(proc_doulongvec_minmax);
2966 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2967 EXPORT_SYMBOL(register_sysctl_table);
2968 EXPORT_SYMBOL(register_sysctl_paths);
2969 EXPORT_SYMBOL(unregister_sysctl_table);