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/compaction.h>
41 #include <linux/hugetlb.h>
42 #include <linux/initrd.h>
43 #include <linux/key.h>
44 #include <linux/times.h>
45 #include <linux/limits.h>
46 #include <linux/dcache.h>
47 #include <linux/dnotify.h>
48 #include <linux/syscalls.h>
49 #include <linux/vmstat.h>
50 #include <linux/nfs_fs.h>
51 #include <linux/acpi.h>
52 #include <linux/reboot.h>
53 #include <linux/ftrace.h>
54 #include <linux/perf_event.h>
55 #include <linux/kprobes.h>
56 #include <linux/pipe_fs_i.h>
57 #include <linux/oom.h>
59 #include <asm/uaccess.h>
60 #include <asm/processor.h>
64 #include <asm/stacktrace.h>
67 #ifdef CONFIG_BSD_PROCESS_ACCT
68 #include <linux/acct.h>
70 #ifdef CONFIG_RT_MUTEXES
71 #include <linux/rtmutex.h>
73 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
74 #include <linux/lockdep.h>
76 #ifdef CONFIG_CHR_DEV_SG
80 #ifdef CONFIG_LOCKUP_DETECTOR
81 #include <linux/nmi.h>
85 #if defined(CONFIG_SYSCTL)
87 /* External variables not in a header file. */
88 extern int sysctl_overcommit_memory;
89 extern int sysctl_overcommit_ratio;
90 extern int max_threads;
91 extern int core_uses_pid;
92 extern int suid_dumpable;
93 extern char core_pattern[];
94 extern unsigned int core_pipe_limit;
96 extern int min_free_kbytes;
97 extern int pid_max_min, pid_max_max;
98 extern int sysctl_drop_caches;
99 extern int percpu_pagelist_fraction;
100 extern int compat_log;
101 extern int latencytop_enabled;
102 extern int sysctl_nr_open_min, sysctl_nr_open_max;
104 extern int sysctl_nr_trim_pages;
107 extern int blk_iopoll_enabled;
110 /* Constants used for minimum and maximum */
111 #ifdef CONFIG_LOCKUP_DETECTOR
112 static int sixty = 60;
113 static int neg_one = -1;
117 static int __maybe_unused one = 1;
118 static int __maybe_unused two = 2;
119 static unsigned long one_ul = 1;
120 static int one_hundred = 100;
122 static int ten_thousand = 10000;
125 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
126 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
128 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
129 static int maxolduid = 65535;
130 static int minolduid;
131 static int min_percpu_pagelist_fract = 8;
133 static int ngroups_max = NGROUPS_MAX;
135 #ifdef CONFIG_INOTIFY_USER
136 #include <linux/inotify.h>
139 #include <asm/system.h>
142 #ifdef CONFIG_SPARC64
143 extern int sysctl_tsb_ratio;
147 extern int pwrsw_enabled;
148 extern int unaligned_enabled;
152 #ifdef CONFIG_MATHEMU
153 extern int sysctl_ieee_emulation_warnings;
155 extern int sysctl_userprocess_debug;
156 extern int spin_retry;
160 extern int no_unaligned_warning;
161 extern int unaligned_dump_stack;
164 #ifdef CONFIG_PROC_SYSCTL
165 static int proc_do_cad_pid(struct ctl_table *table, int write,
166 void __user *buffer, size_t *lenp, loff_t *ppos);
167 static int proc_taint(struct ctl_table *table, int write,
168 void __user *buffer, size_t *lenp, loff_t *ppos);
171 #ifdef CONFIG_MAGIC_SYSRQ
172 static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
174 static int sysrq_sysctl_handler(ctl_table *table, int write,
175 void __user *buffer, size_t *lenp,
180 error = proc_dointvec(table, write, buffer, lenp, ppos);
185 sysrq_toggle_support(__sysrq_enabled);
192 static struct ctl_table root_table[];
193 static struct ctl_table_root sysctl_table_root;
194 static struct ctl_table_header root_table_header = {
196 .ctl_table = root_table,
197 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
198 .root = &sysctl_table_root,
199 .set = &sysctl_table_root.default_set,
201 static struct ctl_table_root sysctl_table_root = {
202 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
203 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
206 static struct ctl_table kern_table[];
207 static struct ctl_table vm_table[];
208 static struct ctl_table fs_table[];
209 static struct ctl_table debug_table[];
210 static struct ctl_table dev_table[];
211 extern struct ctl_table random_table[];
213 extern struct ctl_table epoll_table[];
216 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
217 int sysctl_legacy_va_layout;
220 /* The default sysctl tables: */
222 static struct ctl_table root_table[] = {
224 .procname = "kernel",
241 .child = debug_table,
249 * NOTE: do not add new entries to this table unless you have read
250 * Documentation/sysctl/ctl_unnumbered.txt
255 #ifdef CONFIG_SCHED_DEBUG
256 static int min_sched_granularity_ns = 100000; /* 100 usecs */
257 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
258 static int min_wakeup_granularity_ns; /* 0 usecs */
259 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
260 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
261 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
264 #ifdef CONFIG_COMPACTION
265 static int min_extfrag_threshold;
266 static int max_extfrag_threshold = 1000;
269 static struct ctl_table kern_table[] = {
271 .procname = "sched_child_runs_first",
272 .data = &sysctl_sched_child_runs_first,
273 .maxlen = sizeof(unsigned int),
275 .proc_handler = proc_dointvec,
277 #ifdef CONFIG_SCHED_DEBUG
279 .procname = "sched_min_granularity_ns",
280 .data = &sysctl_sched_min_granularity,
281 .maxlen = sizeof(unsigned int),
283 .proc_handler = sched_proc_update_handler,
284 .extra1 = &min_sched_granularity_ns,
285 .extra2 = &max_sched_granularity_ns,
288 .procname = "sched_latency_ns",
289 .data = &sysctl_sched_latency,
290 .maxlen = sizeof(unsigned int),
292 .proc_handler = sched_proc_update_handler,
293 .extra1 = &min_sched_granularity_ns,
294 .extra2 = &max_sched_granularity_ns,
297 .procname = "sched_wakeup_granularity_ns",
298 .data = &sysctl_sched_wakeup_granularity,
299 .maxlen = sizeof(unsigned int),
301 .proc_handler = sched_proc_update_handler,
302 .extra1 = &min_wakeup_granularity_ns,
303 .extra2 = &max_wakeup_granularity_ns,
306 .procname = "sched_tunable_scaling",
307 .data = &sysctl_sched_tunable_scaling,
308 .maxlen = sizeof(enum sched_tunable_scaling),
310 .proc_handler = sched_proc_update_handler,
311 .extra1 = &min_sched_tunable_scaling,
312 .extra2 = &max_sched_tunable_scaling,
315 .procname = "sched_migration_cost",
316 .data = &sysctl_sched_migration_cost,
317 .maxlen = sizeof(unsigned int),
319 .proc_handler = proc_dointvec,
322 .procname = "sched_nr_migrate",
323 .data = &sysctl_sched_nr_migrate,
324 .maxlen = sizeof(unsigned int),
326 .proc_handler = proc_dointvec,
329 .procname = "sched_time_avg",
330 .data = &sysctl_sched_time_avg,
331 .maxlen = sizeof(unsigned int),
333 .proc_handler = proc_dointvec,
336 .procname = "sched_shares_window",
337 .data = &sysctl_sched_shares_window,
338 .maxlen = sizeof(unsigned int),
340 .proc_handler = proc_dointvec,
343 .procname = "timer_migration",
344 .data = &sysctl_timer_migration,
345 .maxlen = sizeof(unsigned int),
347 .proc_handler = proc_dointvec_minmax,
353 .procname = "sched_rt_period_us",
354 .data = &sysctl_sched_rt_period,
355 .maxlen = sizeof(unsigned int),
357 .proc_handler = sched_rt_handler,
360 .procname = "sched_rt_runtime_us",
361 .data = &sysctl_sched_rt_runtime,
362 .maxlen = sizeof(int),
364 .proc_handler = sched_rt_handler,
367 .procname = "sched_compat_yield",
368 .data = &sysctl_sched_compat_yield,
369 .maxlen = sizeof(unsigned int),
371 .proc_handler = proc_dointvec,
373 #ifdef CONFIG_PROVE_LOCKING
375 .procname = "prove_locking",
376 .data = &prove_locking,
377 .maxlen = sizeof(int),
379 .proc_handler = proc_dointvec,
382 #ifdef CONFIG_LOCK_STAT
384 .procname = "lock_stat",
386 .maxlen = sizeof(int),
388 .proc_handler = proc_dointvec,
393 .data = &panic_timeout,
394 .maxlen = sizeof(int),
396 .proc_handler = proc_dointvec,
399 .procname = "core_uses_pid",
400 .data = &core_uses_pid,
401 .maxlen = sizeof(int),
403 .proc_handler = proc_dointvec,
406 .procname = "core_pattern",
407 .data = core_pattern,
408 .maxlen = CORENAME_MAX_SIZE,
410 .proc_handler = proc_dostring,
413 .procname = "core_pipe_limit",
414 .data = &core_pipe_limit,
415 .maxlen = sizeof(unsigned int),
417 .proc_handler = proc_dointvec,
419 #ifdef CONFIG_PROC_SYSCTL
421 .procname = "tainted",
422 .maxlen = sizeof(long),
424 .proc_handler = proc_taint,
427 #ifdef CONFIG_LATENCYTOP
429 .procname = "latencytop",
430 .data = &latencytop_enabled,
431 .maxlen = sizeof(int),
433 .proc_handler = proc_dointvec,
436 #ifdef CONFIG_BLK_DEV_INITRD
438 .procname = "real-root-dev",
439 .data = &real_root_dev,
440 .maxlen = sizeof(int),
442 .proc_handler = proc_dointvec,
446 .procname = "print-fatal-signals",
447 .data = &print_fatal_signals,
448 .maxlen = sizeof(int),
450 .proc_handler = proc_dointvec,
454 .procname = "reboot-cmd",
455 .data = reboot_command,
458 .proc_handler = proc_dostring,
461 .procname = "stop-a",
462 .data = &stop_a_enabled,
463 .maxlen = sizeof (int),
465 .proc_handler = proc_dointvec,
468 .procname = "scons-poweroff",
469 .data = &scons_pwroff,
470 .maxlen = sizeof (int),
472 .proc_handler = proc_dointvec,
475 #ifdef CONFIG_SPARC64
477 .procname = "tsb-ratio",
478 .data = &sysctl_tsb_ratio,
479 .maxlen = sizeof (int),
481 .proc_handler = proc_dointvec,
486 .procname = "soft-power",
487 .data = &pwrsw_enabled,
488 .maxlen = sizeof (int),
490 .proc_handler = proc_dointvec,
493 .procname = "unaligned-trap",
494 .data = &unaligned_enabled,
495 .maxlen = sizeof (int),
497 .proc_handler = proc_dointvec,
501 .procname = "ctrl-alt-del",
503 .maxlen = sizeof(int),
505 .proc_handler = proc_dointvec,
507 #ifdef CONFIG_FUNCTION_TRACER
509 .procname = "ftrace_enabled",
510 .data = &ftrace_enabled,
511 .maxlen = sizeof(int),
513 .proc_handler = ftrace_enable_sysctl,
516 #ifdef CONFIG_STACK_TRACER
518 .procname = "stack_tracer_enabled",
519 .data = &stack_tracer_enabled,
520 .maxlen = sizeof(int),
522 .proc_handler = stack_trace_sysctl,
525 #ifdef CONFIG_TRACING
527 .procname = "ftrace_dump_on_oops",
528 .data = &ftrace_dump_on_oops,
529 .maxlen = sizeof(int),
531 .proc_handler = proc_dointvec,
534 #ifdef CONFIG_MODULES
536 .procname = "modprobe",
537 .data = &modprobe_path,
538 .maxlen = KMOD_PATH_LEN,
540 .proc_handler = proc_dostring,
543 .procname = "modules_disabled",
544 .data = &modules_disabled,
545 .maxlen = sizeof(int),
547 /* only handle a transition from default "0" to "1" */
548 .proc_handler = proc_dointvec_minmax,
553 #ifdef CONFIG_HOTPLUG
555 .procname = "hotplug",
556 .data = &uevent_helper,
557 .maxlen = UEVENT_HELPER_PATH_LEN,
559 .proc_handler = proc_dostring,
562 #ifdef CONFIG_CHR_DEV_SG
564 .procname = "sg-big-buff",
565 .data = &sg_big_buff,
566 .maxlen = sizeof (int),
568 .proc_handler = proc_dointvec,
571 #ifdef CONFIG_BSD_PROCESS_ACCT
575 .maxlen = 3*sizeof(int),
577 .proc_handler = proc_dointvec,
580 #ifdef CONFIG_MAGIC_SYSRQ
583 .data = &__sysrq_enabled,
584 .maxlen = sizeof (int),
586 .proc_handler = sysrq_sysctl_handler,
589 #ifdef CONFIG_PROC_SYSCTL
591 .procname = "cad_pid",
593 .maxlen = sizeof (int),
595 .proc_handler = proc_do_cad_pid,
599 .procname = "threads-max",
600 .data = &max_threads,
601 .maxlen = sizeof(int),
603 .proc_handler = proc_dointvec,
606 .procname = "random",
608 .child = random_table,
611 .procname = "overflowuid",
612 .data = &overflowuid,
613 .maxlen = sizeof(int),
615 .proc_handler = proc_dointvec_minmax,
616 .extra1 = &minolduid,
617 .extra2 = &maxolduid,
620 .procname = "overflowgid",
621 .data = &overflowgid,
622 .maxlen = sizeof(int),
624 .proc_handler = proc_dointvec_minmax,
625 .extra1 = &minolduid,
626 .extra2 = &maxolduid,
629 #ifdef CONFIG_MATHEMU
631 .procname = "ieee_emulation_warnings",
632 .data = &sysctl_ieee_emulation_warnings,
633 .maxlen = sizeof(int),
635 .proc_handler = proc_dointvec,
639 .procname = "userprocess_debug",
640 .data = &show_unhandled_signals,
641 .maxlen = sizeof(int),
643 .proc_handler = proc_dointvec,
647 .procname = "pid_max",
649 .maxlen = sizeof (int),
651 .proc_handler = proc_dointvec_minmax,
652 .extra1 = &pid_max_min,
653 .extra2 = &pid_max_max,
656 .procname = "panic_on_oops",
657 .data = &panic_on_oops,
658 .maxlen = sizeof(int),
660 .proc_handler = proc_dointvec,
662 #if defined CONFIG_PRINTK
664 .procname = "printk",
665 .data = &console_loglevel,
666 .maxlen = 4*sizeof(int),
668 .proc_handler = proc_dointvec,
671 .procname = "printk_ratelimit",
672 .data = &printk_ratelimit_state.interval,
673 .maxlen = sizeof(int),
675 .proc_handler = proc_dointvec_jiffies,
678 .procname = "printk_ratelimit_burst",
679 .data = &printk_ratelimit_state.burst,
680 .maxlen = sizeof(int),
682 .proc_handler = proc_dointvec,
685 .procname = "printk_delay",
686 .data = &printk_delay_msec,
687 .maxlen = sizeof(int),
689 .proc_handler = proc_dointvec_minmax,
691 .extra2 = &ten_thousand,
694 .procname = "dmesg_restrict",
695 .data = &dmesg_restrict,
696 .maxlen = sizeof(int),
698 .proc_handler = proc_dointvec_minmax,
704 .procname = "ngroups_max",
705 .data = &ngroups_max,
706 .maxlen = sizeof (int),
708 .proc_handler = proc_dointvec,
710 #if defined(CONFIG_LOCKUP_DETECTOR)
712 .procname = "watchdog",
713 .data = &watchdog_enabled,
714 .maxlen = sizeof (int),
716 .proc_handler = proc_dowatchdog_enabled,
719 .procname = "watchdog_thresh",
720 .data = &softlockup_thresh,
721 .maxlen = sizeof(int),
723 .proc_handler = proc_dowatchdog_thresh,
728 .procname = "softlockup_panic",
729 .data = &softlockup_panic,
730 .maxlen = sizeof(int),
732 .proc_handler = proc_dointvec_minmax,
737 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
739 .procname = "unknown_nmi_panic",
740 .data = &unknown_nmi_panic,
741 .maxlen = sizeof (int),
743 .proc_handler = proc_dointvec,
746 .procname = "nmi_watchdog",
747 .data = &nmi_watchdog_enabled,
748 .maxlen = sizeof (int),
750 .proc_handler = proc_nmi_enabled,
753 #if defined(CONFIG_X86)
755 .procname = "panic_on_unrecovered_nmi",
756 .data = &panic_on_unrecovered_nmi,
757 .maxlen = sizeof(int),
759 .proc_handler = proc_dointvec,
762 .procname = "panic_on_io_nmi",
763 .data = &panic_on_io_nmi,
764 .maxlen = sizeof(int),
766 .proc_handler = proc_dointvec,
769 .procname = "bootloader_type",
770 .data = &bootloader_type,
771 .maxlen = sizeof (int),
773 .proc_handler = proc_dointvec,
776 .procname = "bootloader_version",
777 .data = &bootloader_version,
778 .maxlen = sizeof (int),
780 .proc_handler = proc_dointvec,
783 .procname = "kstack_depth_to_print",
784 .data = &kstack_depth_to_print,
785 .maxlen = sizeof(int),
787 .proc_handler = proc_dointvec,
790 .procname = "io_delay_type",
791 .data = &io_delay_type,
792 .maxlen = sizeof(int),
794 .proc_handler = proc_dointvec,
797 #if defined(CONFIG_MMU)
799 .procname = "randomize_va_space",
800 .data = &randomize_va_space,
801 .maxlen = sizeof(int),
803 .proc_handler = proc_dointvec,
806 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
808 .procname = "spin_retry",
810 .maxlen = sizeof (int),
812 .proc_handler = proc_dointvec,
815 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
817 .procname = "acpi_video_flags",
818 .data = &acpi_realmode_flags,
819 .maxlen = sizeof (unsigned long),
821 .proc_handler = proc_doulongvec_minmax,
826 .procname = "ignore-unaligned-usertrap",
827 .data = &no_unaligned_warning,
828 .maxlen = sizeof (int),
830 .proc_handler = proc_dointvec,
833 .procname = "unaligned-dump-stack",
834 .data = &unaligned_dump_stack,
835 .maxlen = sizeof (int),
837 .proc_handler = proc_dointvec,
840 #ifdef CONFIG_DETECT_HUNG_TASK
842 .procname = "hung_task_panic",
843 .data = &sysctl_hung_task_panic,
844 .maxlen = sizeof(int),
846 .proc_handler = proc_dointvec_minmax,
851 .procname = "hung_task_check_count",
852 .data = &sysctl_hung_task_check_count,
853 .maxlen = sizeof(unsigned long),
855 .proc_handler = proc_doulongvec_minmax,
858 .procname = "hung_task_timeout_secs",
859 .data = &sysctl_hung_task_timeout_secs,
860 .maxlen = sizeof(unsigned long),
862 .proc_handler = proc_dohung_task_timeout_secs,
865 .procname = "hung_task_warnings",
866 .data = &sysctl_hung_task_warnings,
867 .maxlen = sizeof(unsigned long),
869 .proc_handler = proc_doulongvec_minmax,
874 .procname = "compat-log",
876 .maxlen = sizeof (int),
878 .proc_handler = proc_dointvec,
881 #ifdef CONFIG_RT_MUTEXES
883 .procname = "max_lock_depth",
884 .data = &max_lock_depth,
885 .maxlen = sizeof(int),
887 .proc_handler = proc_dointvec,
891 .procname = "poweroff_cmd",
892 .data = &poweroff_cmd,
893 .maxlen = POWEROFF_CMD_PATH_LEN,
895 .proc_handler = proc_dostring,
901 .child = key_sysctls,
904 #ifdef CONFIG_RCU_TORTURE_TEST
906 .procname = "rcutorture_runnable",
907 .data = &rcutorture_runnable,
908 .maxlen = sizeof(int),
910 .proc_handler = proc_dointvec,
913 #ifdef CONFIG_PERF_EVENTS
915 .procname = "perf_event_paranoid",
916 .data = &sysctl_perf_event_paranoid,
917 .maxlen = sizeof(sysctl_perf_event_paranoid),
919 .proc_handler = proc_dointvec,
922 .procname = "perf_event_mlock_kb",
923 .data = &sysctl_perf_event_mlock,
924 .maxlen = sizeof(sysctl_perf_event_mlock),
926 .proc_handler = proc_dointvec,
929 .procname = "perf_event_max_sample_rate",
930 .data = &sysctl_perf_event_sample_rate,
931 .maxlen = sizeof(sysctl_perf_event_sample_rate),
933 .proc_handler = proc_dointvec,
936 #ifdef CONFIG_KMEMCHECK
938 .procname = "kmemcheck",
939 .data = &kmemcheck_enabled,
940 .maxlen = sizeof(int),
942 .proc_handler = proc_dointvec,
947 .procname = "blk_iopoll",
948 .data = &blk_iopoll_enabled,
949 .maxlen = sizeof(int),
951 .proc_handler = proc_dointvec,
955 * NOTE: do not add new entries to this table unless you have read
956 * Documentation/sysctl/ctl_unnumbered.txt
961 static struct ctl_table vm_table[] = {
963 .procname = "overcommit_memory",
964 .data = &sysctl_overcommit_memory,
965 .maxlen = sizeof(sysctl_overcommit_memory),
967 .proc_handler = proc_dointvec,
970 .procname = "panic_on_oom",
971 .data = &sysctl_panic_on_oom,
972 .maxlen = sizeof(sysctl_panic_on_oom),
974 .proc_handler = proc_dointvec,
977 .procname = "oom_kill_allocating_task",
978 .data = &sysctl_oom_kill_allocating_task,
979 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
981 .proc_handler = proc_dointvec,
984 .procname = "oom_dump_tasks",
985 .data = &sysctl_oom_dump_tasks,
986 .maxlen = sizeof(sysctl_oom_dump_tasks),
988 .proc_handler = proc_dointvec,
991 .procname = "overcommit_ratio",
992 .data = &sysctl_overcommit_ratio,
993 .maxlen = sizeof(sysctl_overcommit_ratio),
995 .proc_handler = proc_dointvec,
998 .procname = "page-cluster",
999 .data = &page_cluster,
1000 .maxlen = sizeof(int),
1002 .proc_handler = proc_dointvec,
1005 .procname = "dirty_background_ratio",
1006 .data = &dirty_background_ratio,
1007 .maxlen = sizeof(dirty_background_ratio),
1009 .proc_handler = dirty_background_ratio_handler,
1011 .extra2 = &one_hundred,
1014 .procname = "dirty_background_bytes",
1015 .data = &dirty_background_bytes,
1016 .maxlen = sizeof(dirty_background_bytes),
1018 .proc_handler = dirty_background_bytes_handler,
1022 .procname = "dirty_ratio",
1023 .data = &vm_dirty_ratio,
1024 .maxlen = sizeof(vm_dirty_ratio),
1026 .proc_handler = dirty_ratio_handler,
1028 .extra2 = &one_hundred,
1031 .procname = "dirty_bytes",
1032 .data = &vm_dirty_bytes,
1033 .maxlen = sizeof(vm_dirty_bytes),
1035 .proc_handler = dirty_bytes_handler,
1036 .extra1 = &dirty_bytes_min,
1039 .procname = "dirty_writeback_centisecs",
1040 .data = &dirty_writeback_interval,
1041 .maxlen = sizeof(dirty_writeback_interval),
1043 .proc_handler = dirty_writeback_centisecs_handler,
1046 .procname = "dirty_expire_centisecs",
1047 .data = &dirty_expire_interval,
1048 .maxlen = sizeof(dirty_expire_interval),
1050 .proc_handler = proc_dointvec,
1053 .procname = "nr_pdflush_threads",
1054 .data = &nr_pdflush_threads,
1055 .maxlen = sizeof nr_pdflush_threads,
1056 .mode = 0444 /* read-only*/,
1057 .proc_handler = proc_dointvec,
1060 .procname = "swappiness",
1061 .data = &vm_swappiness,
1062 .maxlen = sizeof(vm_swappiness),
1064 .proc_handler = proc_dointvec_minmax,
1066 .extra2 = &one_hundred,
1068 #ifdef CONFIG_HUGETLB_PAGE
1070 .procname = "nr_hugepages",
1072 .maxlen = sizeof(unsigned long),
1074 .proc_handler = hugetlb_sysctl_handler,
1075 .extra1 = (void *)&hugetlb_zero,
1076 .extra2 = (void *)&hugetlb_infinity,
1080 .procname = "nr_hugepages_mempolicy",
1082 .maxlen = sizeof(unsigned long),
1084 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1085 .extra1 = (void *)&hugetlb_zero,
1086 .extra2 = (void *)&hugetlb_infinity,
1090 .procname = "hugetlb_shm_group",
1091 .data = &sysctl_hugetlb_shm_group,
1092 .maxlen = sizeof(gid_t),
1094 .proc_handler = proc_dointvec,
1097 .procname = "hugepages_treat_as_movable",
1098 .data = &hugepages_treat_as_movable,
1099 .maxlen = sizeof(int),
1101 .proc_handler = hugetlb_treat_movable_handler,
1104 .procname = "nr_overcommit_hugepages",
1106 .maxlen = sizeof(unsigned long),
1108 .proc_handler = hugetlb_overcommit_handler,
1109 .extra1 = (void *)&hugetlb_zero,
1110 .extra2 = (void *)&hugetlb_infinity,
1114 .procname = "lowmem_reserve_ratio",
1115 .data = &sysctl_lowmem_reserve_ratio,
1116 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1118 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1121 .procname = "drop_caches",
1122 .data = &sysctl_drop_caches,
1123 .maxlen = sizeof(int),
1125 .proc_handler = drop_caches_sysctl_handler,
1127 #ifdef CONFIG_COMPACTION
1129 .procname = "compact_memory",
1130 .data = &sysctl_compact_memory,
1131 .maxlen = sizeof(int),
1133 .proc_handler = sysctl_compaction_handler,
1136 .procname = "extfrag_threshold",
1137 .data = &sysctl_extfrag_threshold,
1138 .maxlen = sizeof(int),
1140 .proc_handler = sysctl_extfrag_handler,
1141 .extra1 = &min_extfrag_threshold,
1142 .extra2 = &max_extfrag_threshold,
1145 #endif /* CONFIG_COMPACTION */
1147 .procname = "min_free_kbytes",
1148 .data = &min_free_kbytes,
1149 .maxlen = sizeof(min_free_kbytes),
1151 .proc_handler = min_free_kbytes_sysctl_handler,
1155 .procname = "percpu_pagelist_fraction",
1156 .data = &percpu_pagelist_fraction,
1157 .maxlen = sizeof(percpu_pagelist_fraction),
1159 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1160 .extra1 = &min_percpu_pagelist_fract,
1164 .procname = "max_map_count",
1165 .data = &sysctl_max_map_count,
1166 .maxlen = sizeof(sysctl_max_map_count),
1168 .proc_handler = proc_dointvec_minmax,
1173 .procname = "nr_trim_pages",
1174 .data = &sysctl_nr_trim_pages,
1175 .maxlen = sizeof(sysctl_nr_trim_pages),
1177 .proc_handler = proc_dointvec_minmax,
1182 .procname = "laptop_mode",
1183 .data = &laptop_mode,
1184 .maxlen = sizeof(laptop_mode),
1186 .proc_handler = proc_dointvec_jiffies,
1189 .procname = "block_dump",
1190 .data = &block_dump,
1191 .maxlen = sizeof(block_dump),
1193 .proc_handler = proc_dointvec,
1197 .procname = "vfs_cache_pressure",
1198 .data = &sysctl_vfs_cache_pressure,
1199 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1201 .proc_handler = proc_dointvec,
1204 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1206 .procname = "legacy_va_layout",
1207 .data = &sysctl_legacy_va_layout,
1208 .maxlen = sizeof(sysctl_legacy_va_layout),
1210 .proc_handler = proc_dointvec,
1216 .procname = "zone_reclaim_mode",
1217 .data = &zone_reclaim_mode,
1218 .maxlen = sizeof(zone_reclaim_mode),
1220 .proc_handler = proc_dointvec,
1224 .procname = "min_unmapped_ratio",
1225 .data = &sysctl_min_unmapped_ratio,
1226 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1228 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1230 .extra2 = &one_hundred,
1233 .procname = "min_slab_ratio",
1234 .data = &sysctl_min_slab_ratio,
1235 .maxlen = sizeof(sysctl_min_slab_ratio),
1237 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1239 .extra2 = &one_hundred,
1244 .procname = "stat_interval",
1245 .data = &sysctl_stat_interval,
1246 .maxlen = sizeof(sysctl_stat_interval),
1248 .proc_handler = proc_dointvec_jiffies,
1253 .procname = "mmap_min_addr",
1254 .data = &dac_mmap_min_addr,
1255 .maxlen = sizeof(unsigned long),
1257 .proc_handler = mmap_min_addr_handler,
1262 .procname = "numa_zonelist_order",
1263 .data = &numa_zonelist_order,
1264 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1266 .proc_handler = numa_zonelist_order_handler,
1269 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1270 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1272 .procname = "vdso_enabled",
1273 .data = &vdso_enabled,
1274 .maxlen = sizeof(vdso_enabled),
1276 .proc_handler = proc_dointvec,
1280 #ifdef CONFIG_HIGHMEM
1282 .procname = "highmem_is_dirtyable",
1283 .data = &vm_highmem_is_dirtyable,
1284 .maxlen = sizeof(vm_highmem_is_dirtyable),
1286 .proc_handler = proc_dointvec_minmax,
1292 .procname = "scan_unevictable_pages",
1293 .data = &scan_unevictable_pages,
1294 .maxlen = sizeof(scan_unevictable_pages),
1296 .proc_handler = scan_unevictable_handler,
1298 #ifdef CONFIG_MEMORY_FAILURE
1300 .procname = "memory_failure_early_kill",
1301 .data = &sysctl_memory_failure_early_kill,
1302 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1304 .proc_handler = proc_dointvec_minmax,
1309 .procname = "memory_failure_recovery",
1310 .data = &sysctl_memory_failure_recovery,
1311 .maxlen = sizeof(sysctl_memory_failure_recovery),
1313 .proc_handler = proc_dointvec_minmax,
1320 * NOTE: do not add new entries to this table unless you have read
1321 * Documentation/sysctl/ctl_unnumbered.txt
1326 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1327 static struct ctl_table binfmt_misc_table[] = {
1332 static struct ctl_table fs_table[] = {
1334 .procname = "inode-nr",
1335 .data = &inodes_stat,
1336 .maxlen = 2*sizeof(int),
1338 .proc_handler = proc_nr_inodes,
1341 .procname = "inode-state",
1342 .data = &inodes_stat,
1343 .maxlen = 7*sizeof(int),
1345 .proc_handler = proc_nr_inodes,
1348 .procname = "file-nr",
1349 .data = &files_stat,
1350 .maxlen = sizeof(files_stat),
1352 .proc_handler = proc_nr_files,
1355 .procname = "file-max",
1356 .data = &files_stat.max_files,
1357 .maxlen = sizeof(files_stat.max_files),
1359 .proc_handler = proc_doulongvec_minmax,
1362 .procname = "nr_open",
1363 .data = &sysctl_nr_open,
1364 .maxlen = sizeof(int),
1366 .proc_handler = proc_dointvec_minmax,
1367 .extra1 = &sysctl_nr_open_min,
1368 .extra2 = &sysctl_nr_open_max,
1371 .procname = "dentry-state",
1372 .data = &dentry_stat,
1373 .maxlen = 6*sizeof(int),
1375 .proc_handler = proc_nr_dentry,
1378 .procname = "overflowuid",
1379 .data = &fs_overflowuid,
1380 .maxlen = sizeof(int),
1382 .proc_handler = proc_dointvec_minmax,
1383 .extra1 = &minolduid,
1384 .extra2 = &maxolduid,
1387 .procname = "overflowgid",
1388 .data = &fs_overflowgid,
1389 .maxlen = sizeof(int),
1391 .proc_handler = proc_dointvec_minmax,
1392 .extra1 = &minolduid,
1393 .extra2 = &maxolduid,
1395 #ifdef CONFIG_FILE_LOCKING
1397 .procname = "leases-enable",
1398 .data = &leases_enable,
1399 .maxlen = sizeof(int),
1401 .proc_handler = proc_dointvec,
1404 #ifdef CONFIG_DNOTIFY
1406 .procname = "dir-notify-enable",
1407 .data = &dir_notify_enable,
1408 .maxlen = sizeof(int),
1410 .proc_handler = proc_dointvec,
1414 #ifdef CONFIG_FILE_LOCKING
1416 .procname = "lease-break-time",
1417 .data = &lease_break_time,
1418 .maxlen = sizeof(int),
1420 .proc_handler = proc_dointvec,
1425 .procname = "aio-nr",
1427 .maxlen = sizeof(aio_nr),
1429 .proc_handler = proc_doulongvec_minmax,
1432 .procname = "aio-max-nr",
1433 .data = &aio_max_nr,
1434 .maxlen = sizeof(aio_max_nr),
1436 .proc_handler = proc_doulongvec_minmax,
1438 #endif /* CONFIG_AIO */
1439 #ifdef CONFIG_INOTIFY_USER
1441 .procname = "inotify",
1443 .child = inotify_table,
1448 .procname = "epoll",
1450 .child = epoll_table,
1455 .procname = "suid_dumpable",
1456 .data = &suid_dumpable,
1457 .maxlen = sizeof(int),
1459 .proc_handler = proc_dointvec_minmax,
1463 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1465 .procname = "binfmt_misc",
1467 .child = binfmt_misc_table,
1471 .procname = "pipe-max-size",
1472 .data = &pipe_max_size,
1473 .maxlen = sizeof(int),
1475 .proc_handler = &pipe_proc_fn,
1476 .extra1 = &pipe_min_size,
1479 * NOTE: do not add new entries to this table unless you have read
1480 * Documentation/sysctl/ctl_unnumbered.txt
1485 static struct ctl_table debug_table[] = {
1486 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1487 defined(CONFIG_S390)
1489 .procname = "exception-trace",
1490 .data = &show_unhandled_signals,
1491 .maxlen = sizeof(int),
1493 .proc_handler = proc_dointvec
1496 #if defined(CONFIG_OPTPROBES)
1498 .procname = "kprobes-optimization",
1499 .data = &sysctl_kprobes_optimization,
1500 .maxlen = sizeof(int),
1502 .proc_handler = proc_kprobes_optimization_handler,
1510 static struct ctl_table dev_table[] = {
1514 static DEFINE_SPINLOCK(sysctl_lock);
1516 /* called under sysctl_lock */
1517 static int use_table(struct ctl_table_header *p)
1519 if (unlikely(p->unregistering))
1525 /* called under sysctl_lock */
1526 static void unuse_table(struct ctl_table_header *p)
1529 if (unlikely(p->unregistering))
1530 complete(p->unregistering);
1533 /* called under sysctl_lock, will reacquire if has to wait */
1534 static void start_unregistering(struct ctl_table_header *p)
1537 * if p->used is 0, nobody will ever touch that entry again;
1538 * we'll eliminate all paths to it before dropping sysctl_lock
1540 if (unlikely(p->used)) {
1541 struct completion wait;
1542 init_completion(&wait);
1543 p->unregistering = &wait;
1544 spin_unlock(&sysctl_lock);
1545 wait_for_completion(&wait);
1546 spin_lock(&sysctl_lock);
1548 /* anything non-NULL; we'll never dereference it */
1549 p->unregistering = ERR_PTR(-EINVAL);
1552 * do not remove from the list until nobody holds it; walking the
1553 * list in do_sysctl() relies on that.
1555 list_del_init(&p->ctl_entry);
1558 void sysctl_head_get(struct ctl_table_header *head)
1560 spin_lock(&sysctl_lock);
1562 spin_unlock(&sysctl_lock);
1565 void sysctl_head_put(struct ctl_table_header *head)
1567 spin_lock(&sysctl_lock);
1570 spin_unlock(&sysctl_lock);
1573 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1577 spin_lock(&sysctl_lock);
1578 if (!use_table(head))
1579 head = ERR_PTR(-ENOENT);
1580 spin_unlock(&sysctl_lock);
1584 void sysctl_head_finish(struct ctl_table_header *head)
1588 spin_lock(&sysctl_lock);
1590 spin_unlock(&sysctl_lock);
1593 static struct ctl_table_set *
1594 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1596 struct ctl_table_set *set = &root->default_set;
1598 set = root->lookup(root, namespaces);
1602 static struct list_head *
1603 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1605 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1609 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1610 struct ctl_table_header *prev)
1612 struct ctl_table_root *root;
1613 struct list_head *header_list;
1614 struct ctl_table_header *head;
1615 struct list_head *tmp;
1617 spin_lock(&sysctl_lock);
1620 tmp = &prev->ctl_entry;
1624 tmp = &root_table_header.ctl_entry;
1626 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1628 if (!use_table(head))
1630 spin_unlock(&sysctl_lock);
1635 header_list = lookup_header_list(root, namespaces);
1636 if (tmp != header_list)
1640 root = list_entry(root->root_list.next,
1641 struct ctl_table_root, root_list);
1642 if (root == &sysctl_table_root)
1644 header_list = lookup_header_list(root, namespaces);
1645 } while (list_empty(header_list));
1646 tmp = header_list->next;
1649 spin_unlock(&sysctl_lock);
1653 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1655 return __sysctl_head_next(current->nsproxy, prev);
1658 void register_sysctl_root(struct ctl_table_root *root)
1660 spin_lock(&sysctl_lock);
1661 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1662 spin_unlock(&sysctl_lock);
1666 * sysctl_perm does NOT grant the superuser all rights automatically, because
1667 * some sysctl variables are readonly even to root.
1670 static int test_perm(int mode, int op)
1672 if (!current_euid())
1674 else if (in_egroup_p(0))
1676 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1681 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1686 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1690 if (root->permissions)
1691 mode = root->permissions(root, current->nsproxy, table);
1695 return test_perm(mode, op);
1698 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1700 for (; table->procname; table++) {
1701 table->parent = parent;
1703 sysctl_set_parent(table, table->child);
1707 static __init int sysctl_init(void)
1709 sysctl_set_parent(NULL, root_table);
1710 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1711 sysctl_check_table(current->nsproxy, root_table);
1716 core_initcall(sysctl_init);
1718 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1719 struct ctl_table *table)
1721 struct ctl_table *p;
1722 const char *s = branch->procname;
1724 /* branch should have named subdirectory as its first element */
1725 if (!s || !branch->child)
1728 /* ... and nothing else */
1729 if (branch[1].procname)
1732 /* table should contain subdirectory with the same name */
1733 for (p = table; p->procname; p++) {
1736 if (p->procname && strcmp(p->procname, s) == 0)
1742 /* see if attaching q to p would be an improvement */
1743 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1745 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1746 struct ctl_table *next;
1748 int not_in_parent = !p->attached_by;
1750 while ((next = is_branch_in(by, to)) != NULL) {
1751 if (by == q->attached_by)
1753 if (to == p->attached_by)
1759 if (is_better && not_in_parent) {
1760 q->attached_by = by;
1761 q->attached_to = to;
1767 * __register_sysctl_paths - register a sysctl hierarchy
1768 * @root: List of sysctl headers to register on
1769 * @namespaces: Data to compute which lists of sysctl entries are visible
1770 * @path: The path to the directory the sysctl table is in.
1771 * @table: the top-level table structure
1773 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1774 * array. A completely 0 filled entry terminates the table.
1776 * The members of the &struct ctl_table structure are used as follows:
1778 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1779 * enter a sysctl file
1781 * data - a pointer to data for use by proc_handler
1783 * maxlen - the maximum size in bytes of the data
1785 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1787 * child - a pointer to the child sysctl table if this entry is a directory, or
1790 * proc_handler - the text handler routine (described below)
1792 * de - for internal use by the sysctl routines
1794 * extra1, extra2 - extra pointers usable by the proc handler routines
1796 * Leaf nodes in the sysctl tree will be represented by a single file
1797 * under /proc; non-leaf nodes will be represented by directories.
1799 * sysctl(2) can automatically manage read and write requests through
1800 * the sysctl table. The data and maxlen fields of the ctl_table
1801 * struct enable minimal validation of the values being written to be
1802 * performed, and the mode field allows minimal authentication.
1804 * There must be a proc_handler routine for any terminal nodes
1805 * mirrored under /proc/sys (non-terminals are handled by a built-in
1806 * directory handler). Several default handlers are available to
1807 * cover common cases -
1809 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1810 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1811 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1813 * It is the handler's job to read the input buffer from user memory
1814 * and process it. The handler should return 0 on success.
1816 * This routine returns %NULL on a failure to register, and a pointer
1817 * to the table header on success.
1819 struct ctl_table_header *__register_sysctl_paths(
1820 struct ctl_table_root *root,
1821 struct nsproxy *namespaces,
1822 const struct ctl_path *path, struct ctl_table *table)
1824 struct ctl_table_header *header;
1825 struct ctl_table *new, **prevp;
1826 unsigned int n, npath;
1827 struct ctl_table_set *set;
1829 /* Count the path components */
1830 for (npath = 0; path[npath].procname; ++npath)
1834 * For each path component, allocate a 2-element ctl_table array.
1835 * The first array element will be filled with the sysctl entry
1836 * for this, the second will be the sentinel (procname == 0).
1838 * We allocate everything in one go so that we don't have to
1839 * worry about freeing additional memory in unregister_sysctl_table.
1841 header = kzalloc(sizeof(struct ctl_table_header) +
1842 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1846 new = (struct ctl_table *) (header + 1);
1848 /* Now connect the dots */
1849 prevp = &header->ctl_table;
1850 for (n = 0; n < npath; ++n, ++path) {
1851 /* Copy the procname */
1852 new->procname = path->procname;
1856 prevp = &new->child;
1861 header->ctl_table_arg = table;
1863 INIT_LIST_HEAD(&header->ctl_entry);
1865 header->unregistering = NULL;
1866 header->root = root;
1867 sysctl_set_parent(NULL, header->ctl_table);
1869 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1870 if (sysctl_check_table(namespaces, header->ctl_table)) {
1875 spin_lock(&sysctl_lock);
1876 header->set = lookup_header_set(root, namespaces);
1877 header->attached_by = header->ctl_table;
1878 header->attached_to = root_table;
1879 header->parent = &root_table_header;
1880 for (set = header->set; set; set = set->parent) {
1881 struct ctl_table_header *p;
1882 list_for_each_entry(p, &set->list, ctl_entry) {
1883 if (p->unregistering)
1885 try_attach(p, header);
1888 header->parent->count++;
1889 list_add_tail(&header->ctl_entry, &header->set->list);
1890 spin_unlock(&sysctl_lock);
1896 * register_sysctl_table_path - register a sysctl table hierarchy
1897 * @path: The path to the directory the sysctl table is in.
1898 * @table: the top-level table structure
1900 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1901 * array. A completely 0 filled entry terminates the table.
1903 * See __register_sysctl_paths for more details.
1905 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1906 struct ctl_table *table)
1908 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1913 * register_sysctl_table - register a sysctl table hierarchy
1914 * @table: the top-level table structure
1916 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1917 * array. A completely 0 filled entry terminates the table.
1919 * See register_sysctl_paths for more details.
1921 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1923 static const struct ctl_path null_path[] = { {} };
1925 return register_sysctl_paths(null_path, table);
1929 * unregister_sysctl_table - unregister a sysctl table hierarchy
1930 * @header: the header returned from register_sysctl_table
1932 * Unregisters the sysctl table and all children. proc entries may not
1933 * actually be removed until they are no longer used by anyone.
1935 void unregister_sysctl_table(struct ctl_table_header * header)
1942 spin_lock(&sysctl_lock);
1943 start_unregistering(header);
1944 if (!--header->parent->count) {
1946 kfree(header->parent);
1948 if (!--header->count)
1950 spin_unlock(&sysctl_lock);
1953 int sysctl_is_seen(struct ctl_table_header *p)
1955 struct ctl_table_set *set = p->set;
1957 spin_lock(&sysctl_lock);
1958 if (p->unregistering)
1960 else if (!set->is_seen)
1963 res = set->is_seen(set);
1964 spin_unlock(&sysctl_lock);
1968 void setup_sysctl_set(struct ctl_table_set *p,
1969 struct ctl_table_set *parent,
1970 int (*is_seen)(struct ctl_table_set *))
1972 INIT_LIST_HEAD(&p->list);
1973 p->parent = parent ? parent : &sysctl_table_root.default_set;
1974 p->is_seen = is_seen;
1977 #else /* !CONFIG_SYSCTL */
1978 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1983 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1984 struct ctl_table *table)
1989 void unregister_sysctl_table(struct ctl_table_header * table)
1993 void setup_sysctl_set(struct ctl_table_set *p,
1994 struct ctl_table_set *parent,
1995 int (*is_seen)(struct ctl_table_set *))
1999 void sysctl_head_put(struct ctl_table_header *head)
2003 #endif /* CONFIG_SYSCTL */
2009 #ifdef CONFIG_PROC_SYSCTL
2011 static int _proc_do_string(void* data, int maxlen, int write,
2012 void __user *buffer,
2013 size_t *lenp, loff_t *ppos)
2019 if (!data || !maxlen || !*lenp) {
2027 while (len < *lenp) {
2028 if (get_user(c, p++))
2030 if (c == 0 || c == '\n')
2036 if(copy_from_user(data, buffer, len))
2038 ((char *) data)[len] = 0;
2056 if(copy_to_user(buffer, data, len))
2059 if(put_user('\n', ((char __user *) buffer) + len))
2070 * proc_dostring - read a string sysctl
2071 * @table: the sysctl table
2072 * @write: %TRUE if this is a write to the sysctl file
2073 * @buffer: the user buffer
2074 * @lenp: the size of the user buffer
2075 * @ppos: file position
2077 * Reads/writes a string from/to the user buffer. If the kernel
2078 * buffer provided is not large enough to hold the string, the
2079 * string is truncated. The copied string is %NULL-terminated.
2080 * If the string is being read by the user process, it is copied
2081 * and a newline '\n' is added. It is truncated if the buffer is
2084 * Returns 0 on success.
2086 int proc_dostring(struct ctl_table *table, int write,
2087 void __user *buffer, size_t *lenp, loff_t *ppos)
2089 return _proc_do_string(table->data, table->maxlen, write,
2090 buffer, lenp, ppos);
2093 static size_t proc_skip_spaces(char **buf)
2096 char *tmp = skip_spaces(*buf);
2102 static void proc_skip_char(char **buf, size_t *size, const char v)
2112 #define TMPBUFLEN 22
2114 * proc_get_long - reads an ASCII formatted integer from a user buffer
2116 * @buf: a kernel buffer
2117 * @size: size of the kernel buffer
2118 * @val: this is where the number will be stored
2119 * @neg: set to %TRUE if number is negative
2120 * @perm_tr: a vector which contains the allowed trailers
2121 * @perm_tr_len: size of the perm_tr vector
2122 * @tr: pointer to store the trailer character
2124 * In case of success %0 is returned and @buf and @size are updated with
2125 * the amount of bytes read. If @tr is non-NULL and a trailing
2126 * character exists (size is non-zero after returning from this
2127 * function), @tr is updated with the trailing character.
2129 static int proc_get_long(char **buf, size_t *size,
2130 unsigned long *val, bool *neg,
2131 const char *perm_tr, unsigned perm_tr_len, char *tr)
2134 char *p, tmp[TMPBUFLEN];
2140 if (len > TMPBUFLEN - 1)
2141 len = TMPBUFLEN - 1;
2143 memcpy(tmp, *buf, len);
2147 if (*p == '-' && *size > 1) {
2155 *val = simple_strtoul(p, &p, 0);
2159 /* We don't know if the next char is whitespace thus we may accept
2160 * invalid integers (e.g. 1234...a) or two integers instead of one
2161 * (e.g. 123...1). So lets not allow such large numbers. */
2162 if (len == TMPBUFLEN - 1)
2165 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2168 if (tr && (len < *size))
2178 * proc_put_long - converts an integer to a decimal ASCII formatted string
2180 * @buf: the user buffer
2181 * @size: the size of the user buffer
2182 * @val: the integer to be converted
2183 * @neg: sign of the number, %TRUE for negative
2185 * In case of success %0 is returned and @buf and @size are updated with
2186 * the amount of bytes written.
2188 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2192 char tmp[TMPBUFLEN], *p = tmp;
2194 sprintf(p, "%s%lu", neg ? "-" : "", val);
2198 if (copy_to_user(*buf, tmp, len))
2206 static int proc_put_char(void __user **buf, size_t *size, char c)
2209 char __user **buffer = (char __user **)buf;
2210 if (put_user(c, *buffer))
2212 (*size)--, (*buffer)++;
2218 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2220 int write, void *data)
2223 *valp = *negp ? -*lvalp : *lvalp;
2228 *lvalp = (unsigned long)-val;
2231 *lvalp = (unsigned long)val;
2237 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2239 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2240 int write, void __user *buffer,
2241 size_t *lenp, loff_t *ppos,
2242 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2243 int write, void *data),
2246 int *i, vleft, first = 1, err = 0;
2247 unsigned long page = 0;
2251 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2256 i = (int *) tbl_data;
2257 vleft = table->maxlen / sizeof(*i);
2261 conv = do_proc_dointvec_conv;
2264 if (left > PAGE_SIZE - 1)
2265 left = PAGE_SIZE - 1;
2266 page = __get_free_page(GFP_TEMPORARY);
2267 kbuf = (char *) page;
2270 if (copy_from_user(kbuf, buffer, left)) {
2277 for (; left && vleft--; i++, first=0) {
2282 left -= proc_skip_spaces(&kbuf);
2286 err = proc_get_long(&kbuf, &left, &lval, &neg,
2288 sizeof(proc_wspace_sep), NULL);
2291 if (conv(&neg, &lval, i, 1, data)) {
2296 if (conv(&neg, &lval, i, 0, data)) {
2301 err = proc_put_char(&buffer, &left, '\t');
2304 err = proc_put_long(&buffer, &left, lval, neg);
2310 if (!write && !first && left && !err)
2311 err = proc_put_char(&buffer, &left, '\n');
2312 if (write && !err && left)
2313 left -= proc_skip_spaces(&kbuf);
2318 return err ? : -EINVAL;
2325 static int do_proc_dointvec(struct ctl_table *table, int write,
2326 void __user *buffer, size_t *lenp, loff_t *ppos,
2327 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2328 int write, void *data),
2331 return __do_proc_dointvec(table->data, table, write,
2332 buffer, lenp, ppos, conv, data);
2336 * proc_dointvec - read a vector of integers
2337 * @table: the sysctl table
2338 * @write: %TRUE if this is a write to the sysctl file
2339 * @buffer: the user buffer
2340 * @lenp: the size of the user buffer
2341 * @ppos: file position
2343 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2344 * values from/to the user buffer, treated as an ASCII string.
2346 * Returns 0 on success.
2348 int proc_dointvec(struct ctl_table *table, int write,
2349 void __user *buffer, size_t *lenp, loff_t *ppos)
2351 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2356 * Taint values can only be increased
2357 * This means we can safely use a temporary.
2359 static int proc_taint(struct ctl_table *table, int write,
2360 void __user *buffer, size_t *lenp, loff_t *ppos)
2363 unsigned long tmptaint = get_taint();
2366 if (write && !capable(CAP_SYS_ADMIN))
2371 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2377 * Poor man's atomic or. Not worth adding a primitive
2378 * to everyone's atomic.h for this
2381 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2382 if ((tmptaint >> i) & 1)
2390 struct do_proc_dointvec_minmax_conv_param {
2395 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2397 int write, void *data)
2399 struct do_proc_dointvec_minmax_conv_param *param = data;
2401 int val = *negp ? -*lvalp : *lvalp;
2402 if ((param->min && *param->min > val) ||
2403 (param->max && *param->max < val))
2410 *lvalp = (unsigned long)-val;
2413 *lvalp = (unsigned long)val;
2420 * proc_dointvec_minmax - read a vector of integers with min/max values
2421 * @table: the sysctl table
2422 * @write: %TRUE if this is a write to the sysctl file
2423 * @buffer: the user buffer
2424 * @lenp: the size of the user buffer
2425 * @ppos: file position
2427 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2428 * values from/to the user buffer, treated as an ASCII string.
2430 * This routine will ensure the values are within the range specified by
2431 * table->extra1 (min) and table->extra2 (max).
2433 * Returns 0 on success.
2435 int proc_dointvec_minmax(struct ctl_table *table, int write,
2436 void __user *buffer, size_t *lenp, loff_t *ppos)
2438 struct do_proc_dointvec_minmax_conv_param param = {
2439 .min = (int *) table->extra1,
2440 .max = (int *) table->extra2,
2442 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2443 do_proc_dointvec_minmax_conv, ¶m);
2446 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2447 void __user *buffer,
2448 size_t *lenp, loff_t *ppos,
2449 unsigned long convmul,
2450 unsigned long convdiv)
2452 unsigned long *i, *min, *max;
2453 int vleft, first = 1, err = 0;
2454 unsigned long page = 0;
2458 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2463 i = (unsigned long *) data;
2464 min = (unsigned long *) table->extra1;
2465 max = (unsigned long *) table->extra2;
2466 vleft = table->maxlen / sizeof(unsigned long);
2470 if (left > PAGE_SIZE - 1)
2471 left = PAGE_SIZE - 1;
2472 page = __get_free_page(GFP_TEMPORARY);
2473 kbuf = (char *) page;
2476 if (copy_from_user(kbuf, buffer, left)) {
2483 for (; left && vleft--; i++, first = 0) {
2489 left -= proc_skip_spaces(&kbuf);
2491 err = proc_get_long(&kbuf, &left, &val, &neg,
2493 sizeof(proc_wspace_sep), NULL);
2498 if ((min && val < *min) || (max && val > *max))
2502 val = convdiv * (*i) / convmul;
2504 err = proc_put_char(&buffer, &left, '\t');
2505 err = proc_put_long(&buffer, &left, val, false);
2511 if (!write && !first && left && !err)
2512 err = proc_put_char(&buffer, &left, '\n');
2514 left -= proc_skip_spaces(&kbuf);
2519 return err ? : -EINVAL;
2526 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2527 void __user *buffer,
2528 size_t *lenp, loff_t *ppos,
2529 unsigned long convmul,
2530 unsigned long convdiv)
2532 return __do_proc_doulongvec_minmax(table->data, table, write,
2533 buffer, lenp, ppos, convmul, convdiv);
2537 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2538 * @table: the sysctl table
2539 * @write: %TRUE if this is a write to the sysctl file
2540 * @buffer: the user buffer
2541 * @lenp: the size of the user buffer
2542 * @ppos: file position
2544 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2545 * values from/to the user buffer, treated as an ASCII string.
2547 * This routine will ensure the values are within the range specified by
2548 * table->extra1 (min) and table->extra2 (max).
2550 * Returns 0 on success.
2552 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2553 void __user *buffer, size_t *lenp, loff_t *ppos)
2555 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2559 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2560 * @table: the sysctl table
2561 * @write: %TRUE if this is a write to the sysctl file
2562 * @buffer: the user buffer
2563 * @lenp: the size of the user buffer
2564 * @ppos: file position
2566 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2567 * values from/to the user buffer, treated as an ASCII string. The values
2568 * are treated as milliseconds, and converted to jiffies when they are stored.
2570 * This routine will ensure the values are within the range specified by
2571 * table->extra1 (min) and table->extra2 (max).
2573 * Returns 0 on success.
2575 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2576 void __user *buffer,
2577 size_t *lenp, loff_t *ppos)
2579 return do_proc_doulongvec_minmax(table, write, buffer,
2580 lenp, ppos, HZ, 1000l);
2584 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2586 int write, void *data)
2589 if (*lvalp > LONG_MAX / HZ)
2591 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2597 lval = (unsigned long)-val;
2600 lval = (unsigned long)val;
2607 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2609 int write, void *data)
2612 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2614 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2620 lval = (unsigned long)-val;
2623 lval = (unsigned long)val;
2625 *lvalp = jiffies_to_clock_t(lval);
2630 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2632 int write, void *data)
2635 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2641 lval = (unsigned long)-val;
2644 lval = (unsigned long)val;
2646 *lvalp = jiffies_to_msecs(lval);
2652 * proc_dointvec_jiffies - read a vector of integers as seconds
2653 * @table: the sysctl table
2654 * @write: %TRUE if this is a write to the sysctl file
2655 * @buffer: the user buffer
2656 * @lenp: the size of the user buffer
2657 * @ppos: file position
2659 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2660 * values from/to the user buffer, treated as an ASCII string.
2661 * The values read are assumed to be in seconds, and are converted into
2664 * Returns 0 on success.
2666 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2667 void __user *buffer, size_t *lenp, loff_t *ppos)
2669 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2670 do_proc_dointvec_jiffies_conv,NULL);
2674 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2675 * @table: the sysctl table
2676 * @write: %TRUE if this is a write to the sysctl file
2677 * @buffer: the user buffer
2678 * @lenp: the size of the user buffer
2679 * @ppos: pointer to the file position
2681 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2682 * values from/to the user buffer, treated as an ASCII string.
2683 * The values read are assumed to be in 1/USER_HZ seconds, and
2684 * are converted into jiffies.
2686 * Returns 0 on success.
2688 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2689 void __user *buffer, size_t *lenp, loff_t *ppos)
2691 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2692 do_proc_dointvec_userhz_jiffies_conv,NULL);
2696 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2697 * @table: the sysctl table
2698 * @write: %TRUE if this is a write to the sysctl file
2699 * @buffer: the user buffer
2700 * @lenp: the size of the user buffer
2701 * @ppos: file position
2702 * @ppos: the current position in the file
2704 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2705 * values from/to the user buffer, treated as an ASCII string.
2706 * The values read are assumed to be in 1/1000 seconds, and
2707 * are converted into jiffies.
2709 * Returns 0 on success.
2711 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2712 void __user *buffer, size_t *lenp, loff_t *ppos)
2714 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2715 do_proc_dointvec_ms_jiffies_conv, NULL);
2718 static int proc_do_cad_pid(struct ctl_table *table, int write,
2719 void __user *buffer, size_t *lenp, loff_t *ppos)
2721 struct pid *new_pid;
2725 tmp = pid_vnr(cad_pid);
2727 r = __do_proc_dointvec(&tmp, table, write, buffer,
2728 lenp, ppos, NULL, NULL);
2732 new_pid = find_get_pid(tmp);
2736 put_pid(xchg(&cad_pid, new_pid));
2741 * proc_do_large_bitmap - read/write from/to a large bitmap
2742 * @table: the sysctl table
2743 * @write: %TRUE if this is a write to the sysctl file
2744 * @buffer: the user buffer
2745 * @lenp: the size of the user buffer
2746 * @ppos: file position
2748 * The bitmap is stored at table->data and the bitmap length (in bits)
2751 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2752 * large bitmaps may be represented in a compact manner. Writing into
2753 * the file will clear the bitmap then update it with the given input.
2755 * Returns 0 on success.
2757 int proc_do_large_bitmap(struct ctl_table *table, int write,
2758 void __user *buffer, size_t *lenp, loff_t *ppos)
2762 size_t left = *lenp;
2763 unsigned long bitmap_len = table->maxlen;
2764 unsigned long *bitmap = (unsigned long *) table->data;
2765 unsigned long *tmp_bitmap = NULL;
2766 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2768 if (!bitmap_len || !left || (*ppos && !write)) {
2774 unsigned long page = 0;
2777 if (left > PAGE_SIZE - 1)
2778 left = PAGE_SIZE - 1;
2780 page = __get_free_page(GFP_TEMPORARY);
2781 kbuf = (char *) page;
2784 if (copy_from_user(kbuf, buffer, left)) {
2790 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2796 proc_skip_char(&kbuf, &left, '\n');
2797 while (!err && left) {
2798 unsigned long val_a, val_b;
2801 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2805 if (val_a >= bitmap_len || neg) {
2817 err = proc_get_long(&kbuf, &left, &val_b,
2818 &neg, tr_b, sizeof(tr_b),
2822 if (val_b >= bitmap_len || neg ||
2833 while (val_a <= val_b)
2834 set_bit(val_a++, tmp_bitmap);
2837 proc_skip_char(&kbuf, &left, '\n');
2841 unsigned long bit_a, bit_b = 0;
2844 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2845 if (bit_a >= bitmap_len)
2847 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2851 err = proc_put_char(&buffer, &left, ',');
2855 err = proc_put_long(&buffer, &left, bit_a, false);
2858 if (bit_a != bit_b) {
2859 err = proc_put_char(&buffer, &left, '-');
2862 err = proc_put_long(&buffer, &left, bit_b, false);
2870 err = proc_put_char(&buffer, &left, '\n');
2876 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2878 memcpy(bitmap, tmp_bitmap,
2879 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2891 #else /* CONFIG_PROC_FS */
2893 int proc_dostring(struct ctl_table *table, int write,
2894 void __user *buffer, size_t *lenp, loff_t *ppos)
2899 int proc_dointvec(struct ctl_table *table, int write,
2900 void __user *buffer, size_t *lenp, loff_t *ppos)
2905 int proc_dointvec_minmax(struct ctl_table *table, int write,
2906 void __user *buffer, size_t *lenp, loff_t *ppos)
2911 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2912 void __user *buffer, size_t *lenp, loff_t *ppos)
2917 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2918 void __user *buffer, size_t *lenp, loff_t *ppos)
2923 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2924 void __user *buffer, size_t *lenp, loff_t *ppos)
2929 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2930 void __user *buffer, size_t *lenp, loff_t *ppos)
2935 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2936 void __user *buffer,
2937 size_t *lenp, loff_t *ppos)
2943 #endif /* CONFIG_PROC_FS */
2946 * No sense putting this after each symbol definition, twice,
2947 * exception granted :-)
2949 EXPORT_SYMBOL(proc_dointvec);
2950 EXPORT_SYMBOL(proc_dointvec_jiffies);
2951 EXPORT_SYMBOL(proc_dointvec_minmax);
2952 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2953 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2954 EXPORT_SYMBOL(proc_dostring);
2955 EXPORT_SYMBOL(proc_doulongvec_minmax);
2956 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2957 EXPORT_SYMBOL(register_sysctl_table);
2958 EXPORT_SYMBOL(register_sysctl_paths);
2959 EXPORT_SYMBOL(unregister_sysctl_table);