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 static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
175 static int sysrq_sysctl_handler(ctl_table *table, int write,
176 void __user *buffer, size_t *lenp,
181 error = proc_dointvec(table, write, buffer, lenp, ppos);
186 sysrq_toggle_support(__sysrq_enabled);
193 static struct ctl_table root_table[];
194 static struct ctl_table_root sysctl_table_root;
195 static struct ctl_table_header root_table_header = {
197 .ctl_table = root_table,
198 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
199 .root = &sysctl_table_root,
200 .set = &sysctl_table_root.default_set,
202 static struct ctl_table_root sysctl_table_root = {
203 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
204 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
207 static struct ctl_table kern_table[];
208 static struct ctl_table vm_table[];
209 static struct ctl_table fs_table[];
210 static struct ctl_table debug_table[];
211 static struct ctl_table dev_table[];
212 extern struct ctl_table random_table[];
214 extern struct ctl_table epoll_table[];
217 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
218 int sysctl_legacy_va_layout;
221 /* The default sysctl tables: */
223 static struct ctl_table root_table[] = {
225 .procname = "kernel",
242 .child = debug_table,
250 * NOTE: do not add new entries to this table unless you have read
251 * Documentation/sysctl/ctl_unnumbered.txt
256 #ifdef CONFIG_SCHED_DEBUG
257 static int min_sched_granularity_ns = 100000; /* 100 usecs */
258 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
259 static int min_wakeup_granularity_ns; /* 0 usecs */
260 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
261 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
262 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
265 #ifdef CONFIG_COMPACTION
266 static int min_extfrag_threshold;
267 static int max_extfrag_threshold = 1000;
270 static struct ctl_table kern_table[] = {
272 .procname = "sched_child_runs_first",
273 .data = &sysctl_sched_child_runs_first,
274 .maxlen = sizeof(unsigned int),
276 .proc_handler = proc_dointvec,
278 #ifdef CONFIG_SCHED_DEBUG
280 .procname = "sched_min_granularity_ns",
281 .data = &sysctl_sched_min_granularity,
282 .maxlen = sizeof(unsigned int),
284 .proc_handler = sched_proc_update_handler,
285 .extra1 = &min_sched_granularity_ns,
286 .extra2 = &max_sched_granularity_ns,
289 .procname = "sched_latency_ns",
290 .data = &sysctl_sched_latency,
291 .maxlen = sizeof(unsigned int),
293 .proc_handler = sched_proc_update_handler,
294 .extra1 = &min_sched_granularity_ns,
295 .extra2 = &max_sched_granularity_ns,
298 .procname = "sched_wakeup_granularity_ns",
299 .data = &sysctl_sched_wakeup_granularity,
300 .maxlen = sizeof(unsigned int),
302 .proc_handler = sched_proc_update_handler,
303 .extra1 = &min_wakeup_granularity_ns,
304 .extra2 = &max_wakeup_granularity_ns,
307 .procname = "sched_tunable_scaling",
308 .data = &sysctl_sched_tunable_scaling,
309 .maxlen = sizeof(enum sched_tunable_scaling),
311 .proc_handler = sched_proc_update_handler,
312 .extra1 = &min_sched_tunable_scaling,
313 .extra2 = &max_sched_tunable_scaling,
316 .procname = "sched_migration_cost",
317 .data = &sysctl_sched_migration_cost,
318 .maxlen = sizeof(unsigned int),
320 .proc_handler = proc_dointvec,
323 .procname = "sched_nr_migrate",
324 .data = &sysctl_sched_nr_migrate,
325 .maxlen = sizeof(unsigned int),
327 .proc_handler = proc_dointvec,
330 .procname = "sched_time_avg",
331 .data = &sysctl_sched_time_avg,
332 .maxlen = sizeof(unsigned int),
334 .proc_handler = proc_dointvec,
337 .procname = "sched_shares_window",
338 .data = &sysctl_sched_shares_window,
339 .maxlen = sizeof(unsigned int),
341 .proc_handler = proc_dointvec,
344 .procname = "timer_migration",
345 .data = &sysctl_timer_migration,
346 .maxlen = sizeof(unsigned int),
348 .proc_handler = proc_dointvec_minmax,
354 .procname = "sched_rt_period_us",
355 .data = &sysctl_sched_rt_period,
356 .maxlen = sizeof(unsigned int),
358 .proc_handler = sched_rt_handler,
361 .procname = "sched_rt_runtime_us",
362 .data = &sysctl_sched_rt_runtime,
363 .maxlen = sizeof(int),
365 .proc_handler = sched_rt_handler,
368 .procname = "sched_compat_yield",
369 .data = &sysctl_sched_compat_yield,
370 .maxlen = sizeof(unsigned int),
372 .proc_handler = proc_dointvec,
374 #ifdef CONFIG_SCHED_AUTOGROUP
376 .procname = "sched_autogroup_enabled",
377 .data = &sysctl_sched_autogroup_enabled,
378 .maxlen = sizeof(unsigned int),
380 .proc_handler = proc_dointvec,
385 #ifdef CONFIG_PROVE_LOCKING
387 .procname = "prove_locking",
388 .data = &prove_locking,
389 .maxlen = sizeof(int),
391 .proc_handler = proc_dointvec,
394 #ifdef CONFIG_LOCK_STAT
396 .procname = "lock_stat",
398 .maxlen = sizeof(int),
400 .proc_handler = proc_dointvec,
405 .data = &panic_timeout,
406 .maxlen = sizeof(int),
408 .proc_handler = proc_dointvec,
411 .procname = "core_uses_pid",
412 .data = &core_uses_pid,
413 .maxlen = sizeof(int),
415 .proc_handler = proc_dointvec,
418 .procname = "core_pattern",
419 .data = core_pattern,
420 .maxlen = CORENAME_MAX_SIZE,
422 .proc_handler = proc_dostring,
425 .procname = "core_pipe_limit",
426 .data = &core_pipe_limit,
427 .maxlen = sizeof(unsigned int),
429 .proc_handler = proc_dointvec,
431 #ifdef CONFIG_PROC_SYSCTL
433 .procname = "tainted",
434 .maxlen = sizeof(long),
436 .proc_handler = proc_taint,
439 #ifdef CONFIG_LATENCYTOP
441 .procname = "latencytop",
442 .data = &latencytop_enabled,
443 .maxlen = sizeof(int),
445 .proc_handler = proc_dointvec,
448 #ifdef CONFIG_BLK_DEV_INITRD
450 .procname = "real-root-dev",
451 .data = &real_root_dev,
452 .maxlen = sizeof(int),
454 .proc_handler = proc_dointvec,
458 .procname = "print-fatal-signals",
459 .data = &print_fatal_signals,
460 .maxlen = sizeof(int),
462 .proc_handler = proc_dointvec,
466 .procname = "reboot-cmd",
467 .data = reboot_command,
470 .proc_handler = proc_dostring,
473 .procname = "stop-a",
474 .data = &stop_a_enabled,
475 .maxlen = sizeof (int),
477 .proc_handler = proc_dointvec,
480 .procname = "scons-poweroff",
481 .data = &scons_pwroff,
482 .maxlen = sizeof (int),
484 .proc_handler = proc_dointvec,
487 #ifdef CONFIG_SPARC64
489 .procname = "tsb-ratio",
490 .data = &sysctl_tsb_ratio,
491 .maxlen = sizeof (int),
493 .proc_handler = proc_dointvec,
498 .procname = "soft-power",
499 .data = &pwrsw_enabled,
500 .maxlen = sizeof (int),
502 .proc_handler = proc_dointvec,
505 .procname = "unaligned-trap",
506 .data = &unaligned_enabled,
507 .maxlen = sizeof (int),
509 .proc_handler = proc_dointvec,
513 .procname = "ctrl-alt-del",
515 .maxlen = sizeof(int),
517 .proc_handler = proc_dointvec,
519 #ifdef CONFIG_FUNCTION_TRACER
521 .procname = "ftrace_enabled",
522 .data = &ftrace_enabled,
523 .maxlen = sizeof(int),
525 .proc_handler = ftrace_enable_sysctl,
528 #ifdef CONFIG_STACK_TRACER
530 .procname = "stack_tracer_enabled",
531 .data = &stack_tracer_enabled,
532 .maxlen = sizeof(int),
534 .proc_handler = stack_trace_sysctl,
537 #ifdef CONFIG_TRACING
539 .procname = "ftrace_dump_on_oops",
540 .data = &ftrace_dump_on_oops,
541 .maxlen = sizeof(int),
543 .proc_handler = proc_dointvec,
546 #ifdef CONFIG_MODULES
548 .procname = "modprobe",
549 .data = &modprobe_path,
550 .maxlen = KMOD_PATH_LEN,
552 .proc_handler = proc_dostring,
555 .procname = "modules_disabled",
556 .data = &modules_disabled,
557 .maxlen = sizeof(int),
559 /* only handle a transition from default "0" to "1" */
560 .proc_handler = proc_dointvec_minmax,
565 #ifdef CONFIG_HOTPLUG
567 .procname = "hotplug",
568 .data = &uevent_helper,
569 .maxlen = UEVENT_HELPER_PATH_LEN,
571 .proc_handler = proc_dostring,
574 #ifdef CONFIG_CHR_DEV_SG
576 .procname = "sg-big-buff",
577 .data = &sg_big_buff,
578 .maxlen = sizeof (int),
580 .proc_handler = proc_dointvec,
583 #ifdef CONFIG_BSD_PROCESS_ACCT
587 .maxlen = 3*sizeof(int),
589 .proc_handler = proc_dointvec,
592 #ifdef CONFIG_MAGIC_SYSRQ
595 .data = &__sysrq_enabled,
596 .maxlen = sizeof (int),
598 .proc_handler = sysrq_sysctl_handler,
601 #ifdef CONFIG_PROC_SYSCTL
603 .procname = "cad_pid",
605 .maxlen = sizeof (int),
607 .proc_handler = proc_do_cad_pid,
611 .procname = "threads-max",
612 .data = &max_threads,
613 .maxlen = sizeof(int),
615 .proc_handler = proc_dointvec,
618 .procname = "random",
620 .child = random_table,
623 .procname = "overflowuid",
624 .data = &overflowuid,
625 .maxlen = sizeof(int),
627 .proc_handler = proc_dointvec_minmax,
628 .extra1 = &minolduid,
629 .extra2 = &maxolduid,
632 .procname = "overflowgid",
633 .data = &overflowgid,
634 .maxlen = sizeof(int),
636 .proc_handler = proc_dointvec_minmax,
637 .extra1 = &minolduid,
638 .extra2 = &maxolduid,
641 #ifdef CONFIG_MATHEMU
643 .procname = "ieee_emulation_warnings",
644 .data = &sysctl_ieee_emulation_warnings,
645 .maxlen = sizeof(int),
647 .proc_handler = proc_dointvec,
651 .procname = "userprocess_debug",
652 .data = &show_unhandled_signals,
653 .maxlen = sizeof(int),
655 .proc_handler = proc_dointvec,
659 .procname = "pid_max",
661 .maxlen = sizeof (int),
663 .proc_handler = proc_dointvec_minmax,
664 .extra1 = &pid_max_min,
665 .extra2 = &pid_max_max,
668 .procname = "panic_on_oops",
669 .data = &panic_on_oops,
670 .maxlen = sizeof(int),
672 .proc_handler = proc_dointvec,
674 #if defined CONFIG_PRINTK
676 .procname = "printk",
677 .data = &console_loglevel,
678 .maxlen = 4*sizeof(int),
680 .proc_handler = proc_dointvec,
683 .procname = "printk_ratelimit",
684 .data = &printk_ratelimit_state.interval,
685 .maxlen = sizeof(int),
687 .proc_handler = proc_dointvec_jiffies,
690 .procname = "printk_ratelimit_burst",
691 .data = &printk_ratelimit_state.burst,
692 .maxlen = sizeof(int),
694 .proc_handler = proc_dointvec,
697 .procname = "printk_delay",
698 .data = &printk_delay_msec,
699 .maxlen = sizeof(int),
701 .proc_handler = proc_dointvec_minmax,
703 .extra2 = &ten_thousand,
706 .procname = "dmesg_restrict",
707 .data = &dmesg_restrict,
708 .maxlen = sizeof(int),
710 .proc_handler = proc_dointvec_minmax,
715 .procname = "kptr_restrict",
716 .data = &kptr_restrict,
717 .maxlen = sizeof(int),
719 .proc_handler = proc_dointvec_minmax,
725 .procname = "ngroups_max",
726 .data = &ngroups_max,
727 .maxlen = sizeof (int),
729 .proc_handler = proc_dointvec,
731 #if defined(CONFIG_LOCKUP_DETECTOR)
733 .procname = "watchdog",
734 .data = &watchdog_enabled,
735 .maxlen = sizeof (int),
737 .proc_handler = proc_dowatchdog_enabled,
740 .procname = "watchdog_thresh",
741 .data = &softlockup_thresh,
742 .maxlen = sizeof(int),
744 .proc_handler = proc_dowatchdog_thresh,
749 .procname = "softlockup_panic",
750 .data = &softlockup_panic,
751 .maxlen = sizeof(int),
753 .proc_handler = proc_dointvec_minmax,
758 .procname = "nmi_watchdog",
759 .data = &watchdog_enabled,
760 .maxlen = sizeof (int),
762 .proc_handler = proc_dowatchdog_enabled,
765 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
767 .procname = "unknown_nmi_panic",
768 .data = &unknown_nmi_panic,
769 .maxlen = sizeof (int),
771 .proc_handler = proc_dointvec,
774 #if defined(CONFIG_X86)
776 .procname = "panic_on_unrecovered_nmi",
777 .data = &panic_on_unrecovered_nmi,
778 .maxlen = sizeof(int),
780 .proc_handler = proc_dointvec,
783 .procname = "panic_on_io_nmi",
784 .data = &panic_on_io_nmi,
785 .maxlen = sizeof(int),
787 .proc_handler = proc_dointvec,
790 .procname = "bootloader_type",
791 .data = &bootloader_type,
792 .maxlen = sizeof (int),
794 .proc_handler = proc_dointvec,
797 .procname = "bootloader_version",
798 .data = &bootloader_version,
799 .maxlen = sizeof (int),
801 .proc_handler = proc_dointvec,
804 .procname = "kstack_depth_to_print",
805 .data = &kstack_depth_to_print,
806 .maxlen = sizeof(int),
808 .proc_handler = proc_dointvec,
811 .procname = "io_delay_type",
812 .data = &io_delay_type,
813 .maxlen = sizeof(int),
815 .proc_handler = proc_dointvec,
818 #if defined(CONFIG_MMU)
820 .procname = "randomize_va_space",
821 .data = &randomize_va_space,
822 .maxlen = sizeof(int),
824 .proc_handler = proc_dointvec,
827 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
829 .procname = "spin_retry",
831 .maxlen = sizeof (int),
833 .proc_handler = proc_dointvec,
836 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
838 .procname = "acpi_video_flags",
839 .data = &acpi_realmode_flags,
840 .maxlen = sizeof (unsigned long),
842 .proc_handler = proc_doulongvec_minmax,
847 .procname = "ignore-unaligned-usertrap",
848 .data = &no_unaligned_warning,
849 .maxlen = sizeof (int),
851 .proc_handler = proc_dointvec,
854 .procname = "unaligned-dump-stack",
855 .data = &unaligned_dump_stack,
856 .maxlen = sizeof (int),
858 .proc_handler = proc_dointvec,
861 #ifdef CONFIG_DETECT_HUNG_TASK
863 .procname = "hung_task_panic",
864 .data = &sysctl_hung_task_panic,
865 .maxlen = sizeof(int),
867 .proc_handler = proc_dointvec_minmax,
872 .procname = "hung_task_check_count",
873 .data = &sysctl_hung_task_check_count,
874 .maxlen = sizeof(unsigned long),
876 .proc_handler = proc_doulongvec_minmax,
879 .procname = "hung_task_timeout_secs",
880 .data = &sysctl_hung_task_timeout_secs,
881 .maxlen = sizeof(unsigned long),
883 .proc_handler = proc_dohung_task_timeout_secs,
886 .procname = "hung_task_warnings",
887 .data = &sysctl_hung_task_warnings,
888 .maxlen = sizeof(unsigned long),
890 .proc_handler = proc_doulongvec_minmax,
895 .procname = "compat-log",
897 .maxlen = sizeof (int),
899 .proc_handler = proc_dointvec,
902 #ifdef CONFIG_RT_MUTEXES
904 .procname = "max_lock_depth",
905 .data = &max_lock_depth,
906 .maxlen = sizeof(int),
908 .proc_handler = proc_dointvec,
912 .procname = "poweroff_cmd",
913 .data = &poweroff_cmd,
914 .maxlen = POWEROFF_CMD_PATH_LEN,
916 .proc_handler = proc_dostring,
922 .child = key_sysctls,
925 #ifdef CONFIG_RCU_TORTURE_TEST
927 .procname = "rcutorture_runnable",
928 .data = &rcutorture_runnable,
929 .maxlen = sizeof(int),
931 .proc_handler = proc_dointvec,
934 #ifdef CONFIG_PERF_EVENTS
936 .procname = "perf_event_paranoid",
937 .data = &sysctl_perf_event_paranoid,
938 .maxlen = sizeof(sysctl_perf_event_paranoid),
940 .proc_handler = proc_dointvec,
943 .procname = "perf_event_mlock_kb",
944 .data = &sysctl_perf_event_mlock,
945 .maxlen = sizeof(sysctl_perf_event_mlock),
947 .proc_handler = proc_dointvec,
950 .procname = "perf_event_max_sample_rate",
951 .data = &sysctl_perf_event_sample_rate,
952 .maxlen = sizeof(sysctl_perf_event_sample_rate),
954 .proc_handler = proc_dointvec,
957 #ifdef CONFIG_KMEMCHECK
959 .procname = "kmemcheck",
960 .data = &kmemcheck_enabled,
961 .maxlen = sizeof(int),
963 .proc_handler = proc_dointvec,
968 .procname = "blk_iopoll",
969 .data = &blk_iopoll_enabled,
970 .maxlen = sizeof(int),
972 .proc_handler = proc_dointvec,
976 * NOTE: do not add new entries to this table unless you have read
977 * Documentation/sysctl/ctl_unnumbered.txt
982 static struct ctl_table vm_table[] = {
984 .procname = "overcommit_memory",
985 .data = &sysctl_overcommit_memory,
986 .maxlen = sizeof(sysctl_overcommit_memory),
988 .proc_handler = proc_dointvec,
991 .procname = "panic_on_oom",
992 .data = &sysctl_panic_on_oom,
993 .maxlen = sizeof(sysctl_panic_on_oom),
995 .proc_handler = proc_dointvec,
998 .procname = "oom_kill_allocating_task",
999 .data = &sysctl_oom_kill_allocating_task,
1000 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1002 .proc_handler = proc_dointvec,
1005 .procname = "oom_dump_tasks",
1006 .data = &sysctl_oom_dump_tasks,
1007 .maxlen = sizeof(sysctl_oom_dump_tasks),
1009 .proc_handler = proc_dointvec,
1012 .procname = "overcommit_ratio",
1013 .data = &sysctl_overcommit_ratio,
1014 .maxlen = sizeof(sysctl_overcommit_ratio),
1016 .proc_handler = proc_dointvec,
1019 .procname = "page-cluster",
1020 .data = &page_cluster,
1021 .maxlen = sizeof(int),
1023 .proc_handler = proc_dointvec,
1026 .procname = "dirty_background_ratio",
1027 .data = &dirty_background_ratio,
1028 .maxlen = sizeof(dirty_background_ratio),
1030 .proc_handler = dirty_background_ratio_handler,
1032 .extra2 = &one_hundred,
1035 .procname = "dirty_background_bytes",
1036 .data = &dirty_background_bytes,
1037 .maxlen = sizeof(dirty_background_bytes),
1039 .proc_handler = dirty_background_bytes_handler,
1043 .procname = "dirty_ratio",
1044 .data = &vm_dirty_ratio,
1045 .maxlen = sizeof(vm_dirty_ratio),
1047 .proc_handler = dirty_ratio_handler,
1049 .extra2 = &one_hundred,
1052 .procname = "dirty_bytes",
1053 .data = &vm_dirty_bytes,
1054 .maxlen = sizeof(vm_dirty_bytes),
1056 .proc_handler = dirty_bytes_handler,
1057 .extra1 = &dirty_bytes_min,
1060 .procname = "dirty_writeback_centisecs",
1061 .data = &dirty_writeback_interval,
1062 .maxlen = sizeof(dirty_writeback_interval),
1064 .proc_handler = dirty_writeback_centisecs_handler,
1067 .procname = "dirty_expire_centisecs",
1068 .data = &dirty_expire_interval,
1069 .maxlen = sizeof(dirty_expire_interval),
1071 .proc_handler = proc_dointvec,
1074 .procname = "nr_pdflush_threads",
1075 .data = &nr_pdflush_threads,
1076 .maxlen = sizeof nr_pdflush_threads,
1077 .mode = 0444 /* read-only*/,
1078 .proc_handler = proc_dointvec,
1081 .procname = "swappiness",
1082 .data = &vm_swappiness,
1083 .maxlen = sizeof(vm_swappiness),
1085 .proc_handler = proc_dointvec_minmax,
1087 .extra2 = &one_hundred,
1089 #ifdef CONFIG_HUGETLB_PAGE
1091 .procname = "nr_hugepages",
1093 .maxlen = sizeof(unsigned long),
1095 .proc_handler = hugetlb_sysctl_handler,
1096 .extra1 = (void *)&hugetlb_zero,
1097 .extra2 = (void *)&hugetlb_infinity,
1101 .procname = "nr_hugepages_mempolicy",
1103 .maxlen = sizeof(unsigned long),
1105 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1106 .extra1 = (void *)&hugetlb_zero,
1107 .extra2 = (void *)&hugetlb_infinity,
1111 .procname = "hugetlb_shm_group",
1112 .data = &sysctl_hugetlb_shm_group,
1113 .maxlen = sizeof(gid_t),
1115 .proc_handler = proc_dointvec,
1118 .procname = "hugepages_treat_as_movable",
1119 .data = &hugepages_treat_as_movable,
1120 .maxlen = sizeof(int),
1122 .proc_handler = hugetlb_treat_movable_handler,
1125 .procname = "nr_overcommit_hugepages",
1127 .maxlen = sizeof(unsigned long),
1129 .proc_handler = hugetlb_overcommit_handler,
1130 .extra1 = (void *)&hugetlb_zero,
1131 .extra2 = (void *)&hugetlb_infinity,
1135 .procname = "lowmem_reserve_ratio",
1136 .data = &sysctl_lowmem_reserve_ratio,
1137 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1139 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1142 .procname = "drop_caches",
1143 .data = &sysctl_drop_caches,
1144 .maxlen = sizeof(int),
1146 .proc_handler = drop_caches_sysctl_handler,
1148 #ifdef CONFIG_COMPACTION
1150 .procname = "compact_memory",
1151 .data = &sysctl_compact_memory,
1152 .maxlen = sizeof(int),
1154 .proc_handler = sysctl_compaction_handler,
1157 .procname = "extfrag_threshold",
1158 .data = &sysctl_extfrag_threshold,
1159 .maxlen = sizeof(int),
1161 .proc_handler = sysctl_extfrag_handler,
1162 .extra1 = &min_extfrag_threshold,
1163 .extra2 = &max_extfrag_threshold,
1166 #endif /* CONFIG_COMPACTION */
1168 .procname = "min_free_kbytes",
1169 .data = &min_free_kbytes,
1170 .maxlen = sizeof(min_free_kbytes),
1172 .proc_handler = min_free_kbytes_sysctl_handler,
1176 .procname = "percpu_pagelist_fraction",
1177 .data = &percpu_pagelist_fraction,
1178 .maxlen = sizeof(percpu_pagelist_fraction),
1180 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1181 .extra1 = &min_percpu_pagelist_fract,
1185 .procname = "max_map_count",
1186 .data = &sysctl_max_map_count,
1187 .maxlen = sizeof(sysctl_max_map_count),
1189 .proc_handler = proc_dointvec_minmax,
1194 .procname = "nr_trim_pages",
1195 .data = &sysctl_nr_trim_pages,
1196 .maxlen = sizeof(sysctl_nr_trim_pages),
1198 .proc_handler = proc_dointvec_minmax,
1203 .procname = "laptop_mode",
1204 .data = &laptop_mode,
1205 .maxlen = sizeof(laptop_mode),
1207 .proc_handler = proc_dointvec_jiffies,
1210 .procname = "block_dump",
1211 .data = &block_dump,
1212 .maxlen = sizeof(block_dump),
1214 .proc_handler = proc_dointvec,
1218 .procname = "vfs_cache_pressure",
1219 .data = &sysctl_vfs_cache_pressure,
1220 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1222 .proc_handler = proc_dointvec,
1225 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1227 .procname = "legacy_va_layout",
1228 .data = &sysctl_legacy_va_layout,
1229 .maxlen = sizeof(sysctl_legacy_va_layout),
1231 .proc_handler = proc_dointvec,
1237 .procname = "zone_reclaim_mode",
1238 .data = &zone_reclaim_mode,
1239 .maxlen = sizeof(zone_reclaim_mode),
1241 .proc_handler = proc_dointvec,
1245 .procname = "min_unmapped_ratio",
1246 .data = &sysctl_min_unmapped_ratio,
1247 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1249 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1251 .extra2 = &one_hundred,
1254 .procname = "min_slab_ratio",
1255 .data = &sysctl_min_slab_ratio,
1256 .maxlen = sizeof(sysctl_min_slab_ratio),
1258 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1260 .extra2 = &one_hundred,
1265 .procname = "stat_interval",
1266 .data = &sysctl_stat_interval,
1267 .maxlen = sizeof(sysctl_stat_interval),
1269 .proc_handler = proc_dointvec_jiffies,
1274 .procname = "mmap_min_addr",
1275 .data = &dac_mmap_min_addr,
1276 .maxlen = sizeof(unsigned long),
1278 .proc_handler = mmap_min_addr_handler,
1283 .procname = "numa_zonelist_order",
1284 .data = &numa_zonelist_order,
1285 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1287 .proc_handler = numa_zonelist_order_handler,
1290 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1291 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1293 .procname = "vdso_enabled",
1294 .data = &vdso_enabled,
1295 .maxlen = sizeof(vdso_enabled),
1297 .proc_handler = proc_dointvec,
1301 #ifdef CONFIG_HIGHMEM
1303 .procname = "highmem_is_dirtyable",
1304 .data = &vm_highmem_is_dirtyable,
1305 .maxlen = sizeof(vm_highmem_is_dirtyable),
1307 .proc_handler = proc_dointvec_minmax,
1313 .procname = "scan_unevictable_pages",
1314 .data = &scan_unevictable_pages,
1315 .maxlen = sizeof(scan_unevictable_pages),
1317 .proc_handler = scan_unevictable_handler,
1319 #ifdef CONFIG_MEMORY_FAILURE
1321 .procname = "memory_failure_early_kill",
1322 .data = &sysctl_memory_failure_early_kill,
1323 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1325 .proc_handler = proc_dointvec_minmax,
1330 .procname = "memory_failure_recovery",
1331 .data = &sysctl_memory_failure_recovery,
1332 .maxlen = sizeof(sysctl_memory_failure_recovery),
1334 .proc_handler = proc_dointvec_minmax,
1341 * NOTE: do not add new entries to this table unless you have read
1342 * Documentation/sysctl/ctl_unnumbered.txt
1347 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1348 static struct ctl_table binfmt_misc_table[] = {
1353 static struct ctl_table fs_table[] = {
1355 .procname = "inode-nr",
1356 .data = &inodes_stat,
1357 .maxlen = 2*sizeof(int),
1359 .proc_handler = proc_nr_inodes,
1362 .procname = "inode-state",
1363 .data = &inodes_stat,
1364 .maxlen = 7*sizeof(int),
1366 .proc_handler = proc_nr_inodes,
1369 .procname = "file-nr",
1370 .data = &files_stat,
1371 .maxlen = sizeof(files_stat),
1373 .proc_handler = proc_nr_files,
1376 .procname = "file-max",
1377 .data = &files_stat.max_files,
1378 .maxlen = sizeof(files_stat.max_files),
1380 .proc_handler = proc_doulongvec_minmax,
1383 .procname = "nr_open",
1384 .data = &sysctl_nr_open,
1385 .maxlen = sizeof(int),
1387 .proc_handler = proc_dointvec_minmax,
1388 .extra1 = &sysctl_nr_open_min,
1389 .extra2 = &sysctl_nr_open_max,
1392 .procname = "dentry-state",
1393 .data = &dentry_stat,
1394 .maxlen = 6*sizeof(int),
1396 .proc_handler = proc_nr_dentry,
1399 .procname = "overflowuid",
1400 .data = &fs_overflowuid,
1401 .maxlen = sizeof(int),
1403 .proc_handler = proc_dointvec_minmax,
1404 .extra1 = &minolduid,
1405 .extra2 = &maxolduid,
1408 .procname = "overflowgid",
1409 .data = &fs_overflowgid,
1410 .maxlen = sizeof(int),
1412 .proc_handler = proc_dointvec_minmax,
1413 .extra1 = &minolduid,
1414 .extra2 = &maxolduid,
1416 #ifdef CONFIG_FILE_LOCKING
1418 .procname = "leases-enable",
1419 .data = &leases_enable,
1420 .maxlen = sizeof(int),
1422 .proc_handler = proc_dointvec,
1425 #ifdef CONFIG_DNOTIFY
1427 .procname = "dir-notify-enable",
1428 .data = &dir_notify_enable,
1429 .maxlen = sizeof(int),
1431 .proc_handler = proc_dointvec,
1435 #ifdef CONFIG_FILE_LOCKING
1437 .procname = "lease-break-time",
1438 .data = &lease_break_time,
1439 .maxlen = sizeof(int),
1441 .proc_handler = proc_dointvec,
1446 .procname = "aio-nr",
1448 .maxlen = sizeof(aio_nr),
1450 .proc_handler = proc_doulongvec_minmax,
1453 .procname = "aio-max-nr",
1454 .data = &aio_max_nr,
1455 .maxlen = sizeof(aio_max_nr),
1457 .proc_handler = proc_doulongvec_minmax,
1459 #endif /* CONFIG_AIO */
1460 #ifdef CONFIG_INOTIFY_USER
1462 .procname = "inotify",
1464 .child = inotify_table,
1469 .procname = "epoll",
1471 .child = epoll_table,
1476 .procname = "suid_dumpable",
1477 .data = &suid_dumpable,
1478 .maxlen = sizeof(int),
1480 .proc_handler = proc_dointvec_minmax,
1484 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1486 .procname = "binfmt_misc",
1488 .child = binfmt_misc_table,
1492 .procname = "pipe-max-size",
1493 .data = &pipe_max_size,
1494 .maxlen = sizeof(int),
1496 .proc_handler = &pipe_proc_fn,
1497 .extra1 = &pipe_min_size,
1500 * NOTE: do not add new entries to this table unless you have read
1501 * Documentation/sysctl/ctl_unnumbered.txt
1506 static struct ctl_table debug_table[] = {
1507 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1508 defined(CONFIG_S390)
1510 .procname = "exception-trace",
1511 .data = &show_unhandled_signals,
1512 .maxlen = sizeof(int),
1514 .proc_handler = proc_dointvec
1517 #if defined(CONFIG_OPTPROBES)
1519 .procname = "kprobes-optimization",
1520 .data = &sysctl_kprobes_optimization,
1521 .maxlen = sizeof(int),
1523 .proc_handler = proc_kprobes_optimization_handler,
1531 static struct ctl_table dev_table[] = {
1535 static DEFINE_SPINLOCK(sysctl_lock);
1537 /* called under sysctl_lock */
1538 static int use_table(struct ctl_table_header *p)
1540 if (unlikely(p->unregistering))
1546 /* called under sysctl_lock */
1547 static void unuse_table(struct ctl_table_header *p)
1550 if (unlikely(p->unregistering))
1551 complete(p->unregistering);
1554 /* called under sysctl_lock, will reacquire if has to wait */
1555 static void start_unregistering(struct ctl_table_header *p)
1558 * if p->used is 0, nobody will ever touch that entry again;
1559 * we'll eliminate all paths to it before dropping sysctl_lock
1561 if (unlikely(p->used)) {
1562 struct completion wait;
1563 init_completion(&wait);
1564 p->unregistering = &wait;
1565 spin_unlock(&sysctl_lock);
1566 wait_for_completion(&wait);
1567 spin_lock(&sysctl_lock);
1569 /* anything non-NULL; we'll never dereference it */
1570 p->unregistering = ERR_PTR(-EINVAL);
1573 * do not remove from the list until nobody holds it; walking the
1574 * list in do_sysctl() relies on that.
1576 list_del_init(&p->ctl_entry);
1579 void sysctl_head_get(struct ctl_table_header *head)
1581 spin_lock(&sysctl_lock);
1583 spin_unlock(&sysctl_lock);
1586 void sysctl_head_put(struct ctl_table_header *head)
1588 spin_lock(&sysctl_lock);
1591 spin_unlock(&sysctl_lock);
1594 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1598 spin_lock(&sysctl_lock);
1599 if (!use_table(head))
1600 head = ERR_PTR(-ENOENT);
1601 spin_unlock(&sysctl_lock);
1605 void sysctl_head_finish(struct ctl_table_header *head)
1609 spin_lock(&sysctl_lock);
1611 spin_unlock(&sysctl_lock);
1614 static struct ctl_table_set *
1615 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1617 struct ctl_table_set *set = &root->default_set;
1619 set = root->lookup(root, namespaces);
1623 static struct list_head *
1624 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1626 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1630 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1631 struct ctl_table_header *prev)
1633 struct ctl_table_root *root;
1634 struct list_head *header_list;
1635 struct ctl_table_header *head;
1636 struct list_head *tmp;
1638 spin_lock(&sysctl_lock);
1641 tmp = &prev->ctl_entry;
1645 tmp = &root_table_header.ctl_entry;
1647 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1649 if (!use_table(head))
1651 spin_unlock(&sysctl_lock);
1656 header_list = lookup_header_list(root, namespaces);
1657 if (tmp != header_list)
1661 root = list_entry(root->root_list.next,
1662 struct ctl_table_root, root_list);
1663 if (root == &sysctl_table_root)
1665 header_list = lookup_header_list(root, namespaces);
1666 } while (list_empty(header_list));
1667 tmp = header_list->next;
1670 spin_unlock(&sysctl_lock);
1674 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1676 return __sysctl_head_next(current->nsproxy, prev);
1679 void register_sysctl_root(struct ctl_table_root *root)
1681 spin_lock(&sysctl_lock);
1682 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1683 spin_unlock(&sysctl_lock);
1687 * sysctl_perm does NOT grant the superuser all rights automatically, because
1688 * some sysctl variables are readonly even to root.
1691 static int test_perm(int mode, int op)
1693 if (!current_euid())
1695 else if (in_egroup_p(0))
1697 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1702 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1707 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1711 if (root->permissions)
1712 mode = root->permissions(root, current->nsproxy, table);
1716 return test_perm(mode, op);
1719 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1721 for (; table->procname; table++) {
1722 table->parent = parent;
1724 sysctl_set_parent(table, table->child);
1728 static __init int sysctl_init(void)
1730 sysctl_set_parent(NULL, root_table);
1731 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1732 sysctl_check_table(current->nsproxy, root_table);
1737 core_initcall(sysctl_init);
1739 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1740 struct ctl_table *table)
1742 struct ctl_table *p;
1743 const char *s = branch->procname;
1745 /* branch should have named subdirectory as its first element */
1746 if (!s || !branch->child)
1749 /* ... and nothing else */
1750 if (branch[1].procname)
1753 /* table should contain subdirectory with the same name */
1754 for (p = table; p->procname; p++) {
1757 if (p->procname && strcmp(p->procname, s) == 0)
1763 /* see if attaching q to p would be an improvement */
1764 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1766 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1767 struct ctl_table *next;
1769 int not_in_parent = !p->attached_by;
1771 while ((next = is_branch_in(by, to)) != NULL) {
1772 if (by == q->attached_by)
1774 if (to == p->attached_by)
1780 if (is_better && not_in_parent) {
1781 q->attached_by = by;
1782 q->attached_to = to;
1788 * __register_sysctl_paths - register a sysctl hierarchy
1789 * @root: List of sysctl headers to register on
1790 * @namespaces: Data to compute which lists of sysctl entries are visible
1791 * @path: The path to the directory the sysctl table is in.
1792 * @table: the top-level table structure
1794 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1795 * array. A completely 0 filled entry terminates the table.
1797 * The members of the &struct ctl_table structure are used as follows:
1799 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1800 * enter a sysctl file
1802 * data - a pointer to data for use by proc_handler
1804 * maxlen - the maximum size in bytes of the data
1806 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1808 * child - a pointer to the child sysctl table if this entry is a directory, or
1811 * proc_handler - the text handler routine (described below)
1813 * de - for internal use by the sysctl routines
1815 * extra1, extra2 - extra pointers usable by the proc handler routines
1817 * Leaf nodes in the sysctl tree will be represented by a single file
1818 * under /proc; non-leaf nodes will be represented by directories.
1820 * sysctl(2) can automatically manage read and write requests through
1821 * the sysctl table. The data and maxlen fields of the ctl_table
1822 * struct enable minimal validation of the values being written to be
1823 * performed, and the mode field allows minimal authentication.
1825 * There must be a proc_handler routine for any terminal nodes
1826 * mirrored under /proc/sys (non-terminals are handled by a built-in
1827 * directory handler). Several default handlers are available to
1828 * cover common cases -
1830 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1831 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1832 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1834 * It is the handler's job to read the input buffer from user memory
1835 * and process it. The handler should return 0 on success.
1837 * This routine returns %NULL on a failure to register, and a pointer
1838 * to the table header on success.
1840 struct ctl_table_header *__register_sysctl_paths(
1841 struct ctl_table_root *root,
1842 struct nsproxy *namespaces,
1843 const struct ctl_path *path, struct ctl_table *table)
1845 struct ctl_table_header *header;
1846 struct ctl_table *new, **prevp;
1847 unsigned int n, npath;
1848 struct ctl_table_set *set;
1850 /* Count the path components */
1851 for (npath = 0; path[npath].procname; ++npath)
1855 * For each path component, allocate a 2-element ctl_table array.
1856 * The first array element will be filled with the sysctl entry
1857 * for this, the second will be the sentinel (procname == 0).
1859 * We allocate everything in one go so that we don't have to
1860 * worry about freeing additional memory in unregister_sysctl_table.
1862 header = kzalloc(sizeof(struct ctl_table_header) +
1863 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1867 new = (struct ctl_table *) (header + 1);
1869 /* Now connect the dots */
1870 prevp = &header->ctl_table;
1871 for (n = 0; n < npath; ++n, ++path) {
1872 /* Copy the procname */
1873 new->procname = path->procname;
1877 prevp = &new->child;
1882 header->ctl_table_arg = table;
1884 INIT_LIST_HEAD(&header->ctl_entry);
1886 header->unregistering = NULL;
1887 header->root = root;
1888 sysctl_set_parent(NULL, header->ctl_table);
1890 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1891 if (sysctl_check_table(namespaces, header->ctl_table)) {
1896 spin_lock(&sysctl_lock);
1897 header->set = lookup_header_set(root, namespaces);
1898 header->attached_by = header->ctl_table;
1899 header->attached_to = root_table;
1900 header->parent = &root_table_header;
1901 for (set = header->set; set; set = set->parent) {
1902 struct ctl_table_header *p;
1903 list_for_each_entry(p, &set->list, ctl_entry) {
1904 if (p->unregistering)
1906 try_attach(p, header);
1909 header->parent->count++;
1910 list_add_tail(&header->ctl_entry, &header->set->list);
1911 spin_unlock(&sysctl_lock);
1917 * register_sysctl_table_path - register a sysctl table hierarchy
1918 * @path: The path to the directory the sysctl table is in.
1919 * @table: the top-level table structure
1921 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1922 * array. A completely 0 filled entry terminates the table.
1924 * See __register_sysctl_paths for more details.
1926 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1927 struct ctl_table *table)
1929 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1934 * register_sysctl_table - register a sysctl table hierarchy
1935 * @table: the top-level table structure
1937 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1938 * array. A completely 0 filled entry terminates the table.
1940 * See register_sysctl_paths for more details.
1942 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1944 static const struct ctl_path null_path[] = { {} };
1946 return register_sysctl_paths(null_path, table);
1950 * unregister_sysctl_table - unregister a sysctl table hierarchy
1951 * @header: the header returned from register_sysctl_table
1953 * Unregisters the sysctl table and all children. proc entries may not
1954 * actually be removed until they are no longer used by anyone.
1956 void unregister_sysctl_table(struct ctl_table_header * header)
1963 spin_lock(&sysctl_lock);
1964 start_unregistering(header);
1965 if (!--header->parent->count) {
1967 kfree(header->parent);
1969 if (!--header->count)
1971 spin_unlock(&sysctl_lock);
1974 int sysctl_is_seen(struct ctl_table_header *p)
1976 struct ctl_table_set *set = p->set;
1978 spin_lock(&sysctl_lock);
1979 if (p->unregistering)
1981 else if (!set->is_seen)
1984 res = set->is_seen(set);
1985 spin_unlock(&sysctl_lock);
1989 void setup_sysctl_set(struct ctl_table_set *p,
1990 struct ctl_table_set *parent,
1991 int (*is_seen)(struct ctl_table_set *))
1993 INIT_LIST_HEAD(&p->list);
1994 p->parent = parent ? parent : &sysctl_table_root.default_set;
1995 p->is_seen = is_seen;
1998 #else /* !CONFIG_SYSCTL */
1999 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2004 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2005 struct ctl_table *table)
2010 void unregister_sysctl_table(struct ctl_table_header * table)
2014 void setup_sysctl_set(struct ctl_table_set *p,
2015 struct ctl_table_set *parent,
2016 int (*is_seen)(struct ctl_table_set *))
2020 void sysctl_head_put(struct ctl_table_header *head)
2024 #endif /* CONFIG_SYSCTL */
2030 #ifdef CONFIG_PROC_SYSCTL
2032 static int _proc_do_string(void* data, int maxlen, int write,
2033 void __user *buffer,
2034 size_t *lenp, loff_t *ppos)
2040 if (!data || !maxlen || !*lenp) {
2048 while (len < *lenp) {
2049 if (get_user(c, p++))
2051 if (c == 0 || c == '\n')
2057 if(copy_from_user(data, buffer, len))
2059 ((char *) data)[len] = 0;
2077 if(copy_to_user(buffer, data, len))
2080 if(put_user('\n', ((char __user *) buffer) + len))
2091 * proc_dostring - read a string sysctl
2092 * @table: the sysctl table
2093 * @write: %TRUE if this is a write to the sysctl file
2094 * @buffer: the user buffer
2095 * @lenp: the size of the user buffer
2096 * @ppos: file position
2098 * Reads/writes a string from/to the user buffer. If the kernel
2099 * buffer provided is not large enough to hold the string, the
2100 * string is truncated. The copied string is %NULL-terminated.
2101 * If the string is being read by the user process, it is copied
2102 * and a newline '\n' is added. It is truncated if the buffer is
2105 * Returns 0 on success.
2107 int proc_dostring(struct ctl_table *table, int write,
2108 void __user *buffer, size_t *lenp, loff_t *ppos)
2110 return _proc_do_string(table->data, table->maxlen, write,
2111 buffer, lenp, ppos);
2114 static size_t proc_skip_spaces(char **buf)
2117 char *tmp = skip_spaces(*buf);
2123 static void proc_skip_char(char **buf, size_t *size, const char v)
2133 #define TMPBUFLEN 22
2135 * proc_get_long - reads an ASCII formatted integer from a user buffer
2137 * @buf: a kernel buffer
2138 * @size: size of the kernel buffer
2139 * @val: this is where the number will be stored
2140 * @neg: set to %TRUE if number is negative
2141 * @perm_tr: a vector which contains the allowed trailers
2142 * @perm_tr_len: size of the perm_tr vector
2143 * @tr: pointer to store the trailer character
2145 * In case of success %0 is returned and @buf and @size are updated with
2146 * the amount of bytes read. If @tr is non-NULL and a trailing
2147 * character exists (size is non-zero after returning from this
2148 * function), @tr is updated with the trailing character.
2150 static int proc_get_long(char **buf, size_t *size,
2151 unsigned long *val, bool *neg,
2152 const char *perm_tr, unsigned perm_tr_len, char *tr)
2155 char *p, tmp[TMPBUFLEN];
2161 if (len > TMPBUFLEN - 1)
2162 len = TMPBUFLEN - 1;
2164 memcpy(tmp, *buf, len);
2168 if (*p == '-' && *size > 1) {
2176 *val = simple_strtoul(p, &p, 0);
2180 /* We don't know if the next char is whitespace thus we may accept
2181 * invalid integers (e.g. 1234...a) or two integers instead of one
2182 * (e.g. 123...1). So lets not allow such large numbers. */
2183 if (len == TMPBUFLEN - 1)
2186 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2189 if (tr && (len < *size))
2199 * proc_put_long - converts an integer to a decimal ASCII formatted string
2201 * @buf: the user buffer
2202 * @size: the size of the user buffer
2203 * @val: the integer to be converted
2204 * @neg: sign of the number, %TRUE for negative
2206 * In case of success %0 is returned and @buf and @size are updated with
2207 * the amount of bytes written.
2209 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2213 char tmp[TMPBUFLEN], *p = tmp;
2215 sprintf(p, "%s%lu", neg ? "-" : "", val);
2219 if (copy_to_user(*buf, tmp, len))
2227 static int proc_put_char(void __user **buf, size_t *size, char c)
2230 char __user **buffer = (char __user **)buf;
2231 if (put_user(c, *buffer))
2233 (*size)--, (*buffer)++;
2239 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2241 int write, void *data)
2244 *valp = *negp ? -*lvalp : *lvalp;
2249 *lvalp = (unsigned long)-val;
2252 *lvalp = (unsigned long)val;
2258 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2260 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2261 int write, void __user *buffer,
2262 size_t *lenp, loff_t *ppos,
2263 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2264 int write, void *data),
2267 int *i, vleft, first = 1, err = 0;
2268 unsigned long page = 0;
2272 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2277 i = (int *) tbl_data;
2278 vleft = table->maxlen / sizeof(*i);
2282 conv = do_proc_dointvec_conv;
2285 if (left > PAGE_SIZE - 1)
2286 left = PAGE_SIZE - 1;
2287 page = __get_free_page(GFP_TEMPORARY);
2288 kbuf = (char *) page;
2291 if (copy_from_user(kbuf, buffer, left)) {
2298 for (; left && vleft--; i++, first=0) {
2303 left -= proc_skip_spaces(&kbuf);
2307 err = proc_get_long(&kbuf, &left, &lval, &neg,
2309 sizeof(proc_wspace_sep), NULL);
2312 if (conv(&neg, &lval, i, 1, data)) {
2317 if (conv(&neg, &lval, i, 0, data)) {
2322 err = proc_put_char(&buffer, &left, '\t');
2325 err = proc_put_long(&buffer, &left, lval, neg);
2331 if (!write && !first && left && !err)
2332 err = proc_put_char(&buffer, &left, '\n');
2333 if (write && !err && left)
2334 left -= proc_skip_spaces(&kbuf);
2339 return err ? : -EINVAL;
2346 static int do_proc_dointvec(struct ctl_table *table, int write,
2347 void __user *buffer, size_t *lenp, loff_t *ppos,
2348 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2349 int write, void *data),
2352 return __do_proc_dointvec(table->data, table, write,
2353 buffer, lenp, ppos, conv, data);
2357 * proc_dointvec - read a vector of integers
2358 * @table: the sysctl table
2359 * @write: %TRUE if this is a write to the sysctl file
2360 * @buffer: the user buffer
2361 * @lenp: the size of the user buffer
2362 * @ppos: file position
2364 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2365 * values from/to the user buffer, treated as an ASCII string.
2367 * Returns 0 on success.
2369 int proc_dointvec(struct ctl_table *table, int write,
2370 void __user *buffer, size_t *lenp, loff_t *ppos)
2372 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2377 * Taint values can only be increased
2378 * This means we can safely use a temporary.
2380 static int proc_taint(struct ctl_table *table, int write,
2381 void __user *buffer, size_t *lenp, loff_t *ppos)
2384 unsigned long tmptaint = get_taint();
2387 if (write && !capable(CAP_SYS_ADMIN))
2392 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2398 * Poor man's atomic or. Not worth adding a primitive
2399 * to everyone's atomic.h for this
2402 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2403 if ((tmptaint >> i) & 1)
2411 struct do_proc_dointvec_minmax_conv_param {
2416 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2418 int write, void *data)
2420 struct do_proc_dointvec_minmax_conv_param *param = data;
2422 int val = *negp ? -*lvalp : *lvalp;
2423 if ((param->min && *param->min > val) ||
2424 (param->max && *param->max < val))
2431 *lvalp = (unsigned long)-val;
2434 *lvalp = (unsigned long)val;
2441 * proc_dointvec_minmax - read a vector of integers with min/max values
2442 * @table: the sysctl table
2443 * @write: %TRUE if this is a write to the sysctl file
2444 * @buffer: the user buffer
2445 * @lenp: the size of the user buffer
2446 * @ppos: file position
2448 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2449 * values from/to the user buffer, treated as an ASCII string.
2451 * This routine will ensure the values are within the range specified by
2452 * table->extra1 (min) and table->extra2 (max).
2454 * Returns 0 on success.
2456 int proc_dointvec_minmax(struct ctl_table *table, int write,
2457 void __user *buffer, size_t *lenp, loff_t *ppos)
2459 struct do_proc_dointvec_minmax_conv_param param = {
2460 .min = (int *) table->extra1,
2461 .max = (int *) table->extra2,
2463 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2464 do_proc_dointvec_minmax_conv, ¶m);
2467 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2468 void __user *buffer,
2469 size_t *lenp, loff_t *ppos,
2470 unsigned long convmul,
2471 unsigned long convdiv)
2473 unsigned long *i, *min, *max;
2474 int vleft, first = 1, err = 0;
2475 unsigned long page = 0;
2479 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2484 i = (unsigned long *) data;
2485 min = (unsigned long *) table->extra1;
2486 max = (unsigned long *) table->extra2;
2487 vleft = table->maxlen / sizeof(unsigned long);
2491 if (left > PAGE_SIZE - 1)
2492 left = PAGE_SIZE - 1;
2493 page = __get_free_page(GFP_TEMPORARY);
2494 kbuf = (char *) page;
2497 if (copy_from_user(kbuf, buffer, left)) {
2504 for (; left && vleft--; i++, first = 0) {
2510 left -= proc_skip_spaces(&kbuf);
2512 err = proc_get_long(&kbuf, &left, &val, &neg,
2514 sizeof(proc_wspace_sep), NULL);
2519 if ((min && val < *min) || (max && val > *max))
2523 val = convdiv * (*i) / convmul;
2525 err = proc_put_char(&buffer, &left, '\t');
2526 err = proc_put_long(&buffer, &left, val, false);
2532 if (!write && !first && left && !err)
2533 err = proc_put_char(&buffer, &left, '\n');
2535 left -= proc_skip_spaces(&kbuf);
2540 return err ? : -EINVAL;
2547 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2548 void __user *buffer,
2549 size_t *lenp, loff_t *ppos,
2550 unsigned long convmul,
2551 unsigned long convdiv)
2553 return __do_proc_doulongvec_minmax(table->data, table, write,
2554 buffer, lenp, ppos, convmul, convdiv);
2558 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2559 * @table: the sysctl table
2560 * @write: %TRUE if this is a write to the sysctl file
2561 * @buffer: the user buffer
2562 * @lenp: the size of the user buffer
2563 * @ppos: file position
2565 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2566 * values from/to the user buffer, treated as an ASCII string.
2568 * This routine will ensure the values are within the range specified by
2569 * table->extra1 (min) and table->extra2 (max).
2571 * Returns 0 on success.
2573 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2574 void __user *buffer, size_t *lenp, loff_t *ppos)
2576 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2580 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2581 * @table: the sysctl table
2582 * @write: %TRUE if this is a write to the sysctl file
2583 * @buffer: the user buffer
2584 * @lenp: the size of the user buffer
2585 * @ppos: file position
2587 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2588 * values from/to the user buffer, treated as an ASCII string. The values
2589 * are treated as milliseconds, and converted to jiffies when they are stored.
2591 * This routine will ensure the values are within the range specified by
2592 * table->extra1 (min) and table->extra2 (max).
2594 * Returns 0 on success.
2596 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2597 void __user *buffer,
2598 size_t *lenp, loff_t *ppos)
2600 return do_proc_doulongvec_minmax(table, write, buffer,
2601 lenp, ppos, HZ, 1000l);
2605 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2607 int write, void *data)
2610 if (*lvalp > LONG_MAX / HZ)
2612 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2618 lval = (unsigned long)-val;
2621 lval = (unsigned long)val;
2628 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2630 int write, void *data)
2633 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2635 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2641 lval = (unsigned long)-val;
2644 lval = (unsigned long)val;
2646 *lvalp = jiffies_to_clock_t(lval);
2651 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2653 int write, void *data)
2656 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2662 lval = (unsigned long)-val;
2665 lval = (unsigned long)val;
2667 *lvalp = jiffies_to_msecs(lval);
2673 * proc_dointvec_jiffies - read a vector of integers as seconds
2674 * @table: the sysctl table
2675 * @write: %TRUE if this is a write to the sysctl file
2676 * @buffer: the user buffer
2677 * @lenp: the size of the user buffer
2678 * @ppos: file position
2680 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2681 * values from/to the user buffer, treated as an ASCII string.
2682 * The values read are assumed to be in seconds, and are converted into
2685 * Returns 0 on success.
2687 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2688 void __user *buffer, size_t *lenp, loff_t *ppos)
2690 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2691 do_proc_dointvec_jiffies_conv,NULL);
2695 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2696 * @table: the sysctl table
2697 * @write: %TRUE if this is a write to the sysctl file
2698 * @buffer: the user buffer
2699 * @lenp: the size of the user buffer
2700 * @ppos: pointer to the file position
2702 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2703 * values from/to the user buffer, treated as an ASCII string.
2704 * The values read are assumed to be in 1/USER_HZ seconds, and
2705 * are converted into jiffies.
2707 * Returns 0 on success.
2709 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2710 void __user *buffer, size_t *lenp, loff_t *ppos)
2712 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2713 do_proc_dointvec_userhz_jiffies_conv,NULL);
2717 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2718 * @table: the sysctl table
2719 * @write: %TRUE if this is a write to the sysctl file
2720 * @buffer: the user buffer
2721 * @lenp: the size of the user buffer
2722 * @ppos: file position
2723 * @ppos: the current position in the file
2725 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2726 * values from/to the user buffer, treated as an ASCII string.
2727 * The values read are assumed to be in 1/1000 seconds, and
2728 * are converted into jiffies.
2730 * Returns 0 on success.
2732 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2733 void __user *buffer, size_t *lenp, loff_t *ppos)
2735 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2736 do_proc_dointvec_ms_jiffies_conv, NULL);
2739 static int proc_do_cad_pid(struct ctl_table *table, int write,
2740 void __user *buffer, size_t *lenp, loff_t *ppos)
2742 struct pid *new_pid;
2746 tmp = pid_vnr(cad_pid);
2748 r = __do_proc_dointvec(&tmp, table, write, buffer,
2749 lenp, ppos, NULL, NULL);
2753 new_pid = find_get_pid(tmp);
2757 put_pid(xchg(&cad_pid, new_pid));
2762 * proc_do_large_bitmap - read/write from/to a large bitmap
2763 * @table: the sysctl table
2764 * @write: %TRUE if this is a write to the sysctl file
2765 * @buffer: the user buffer
2766 * @lenp: the size of the user buffer
2767 * @ppos: file position
2769 * The bitmap is stored at table->data and the bitmap length (in bits)
2772 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2773 * large bitmaps may be represented in a compact manner. Writing into
2774 * the file will clear the bitmap then update it with the given input.
2776 * Returns 0 on success.
2778 int proc_do_large_bitmap(struct ctl_table *table, int write,
2779 void __user *buffer, size_t *lenp, loff_t *ppos)
2783 size_t left = *lenp;
2784 unsigned long bitmap_len = table->maxlen;
2785 unsigned long *bitmap = (unsigned long *) table->data;
2786 unsigned long *tmp_bitmap = NULL;
2787 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2789 if (!bitmap_len || !left || (*ppos && !write)) {
2795 unsigned long page = 0;
2798 if (left > PAGE_SIZE - 1)
2799 left = PAGE_SIZE - 1;
2801 page = __get_free_page(GFP_TEMPORARY);
2802 kbuf = (char *) page;
2805 if (copy_from_user(kbuf, buffer, left)) {
2811 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2817 proc_skip_char(&kbuf, &left, '\n');
2818 while (!err && left) {
2819 unsigned long val_a, val_b;
2822 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2826 if (val_a >= bitmap_len || neg) {
2838 err = proc_get_long(&kbuf, &left, &val_b,
2839 &neg, tr_b, sizeof(tr_b),
2843 if (val_b >= bitmap_len || neg ||
2854 while (val_a <= val_b)
2855 set_bit(val_a++, tmp_bitmap);
2858 proc_skip_char(&kbuf, &left, '\n');
2862 unsigned long bit_a, bit_b = 0;
2865 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2866 if (bit_a >= bitmap_len)
2868 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2872 err = proc_put_char(&buffer, &left, ',');
2876 err = proc_put_long(&buffer, &left, bit_a, false);
2879 if (bit_a != bit_b) {
2880 err = proc_put_char(&buffer, &left, '-');
2883 err = proc_put_long(&buffer, &left, bit_b, false);
2891 err = proc_put_char(&buffer, &left, '\n');
2897 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2899 memcpy(bitmap, tmp_bitmap,
2900 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2912 #else /* CONFIG_PROC_SYSCTL */
2914 int proc_dostring(struct ctl_table *table, int write,
2915 void __user *buffer, size_t *lenp, loff_t *ppos)
2920 int proc_dointvec(struct ctl_table *table, int write,
2921 void __user *buffer, size_t *lenp, loff_t *ppos)
2926 int proc_dointvec_minmax(struct ctl_table *table, int write,
2927 void __user *buffer, size_t *lenp, loff_t *ppos)
2932 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2933 void __user *buffer, size_t *lenp, loff_t *ppos)
2938 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2939 void __user *buffer, size_t *lenp, loff_t *ppos)
2944 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2945 void __user *buffer, size_t *lenp, loff_t *ppos)
2950 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2951 void __user *buffer, size_t *lenp, loff_t *ppos)
2956 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2957 void __user *buffer,
2958 size_t *lenp, loff_t *ppos)
2964 #endif /* CONFIG_PROC_SYSCTL */
2967 * No sense putting this after each symbol definition, twice,
2968 * exception granted :-)
2970 EXPORT_SYMBOL(proc_dointvec);
2971 EXPORT_SYMBOL(proc_dointvec_jiffies);
2972 EXPORT_SYMBOL(proc_dointvec_minmax);
2973 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2974 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2975 EXPORT_SYMBOL(proc_dostring);
2976 EXPORT_SYMBOL(proc_doulongvec_minmax);
2977 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2978 EXPORT_SYMBOL(register_sysctl_table);
2979 EXPORT_SYMBOL(register_sysctl_paths);
2980 EXPORT_SYMBOL(unregister_sysctl_table);