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;
262 static int min_sched_shares_ratelimit = 100000; /* 100 usec */
263 static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
266 #ifdef CONFIG_COMPACTION
267 static int min_extfrag_threshold;
268 static int max_extfrag_threshold = 1000;
271 static struct ctl_table kern_table[] = {
273 .procname = "sched_child_runs_first",
274 .data = &sysctl_sched_child_runs_first,
275 .maxlen = sizeof(unsigned int),
277 .proc_handler = proc_dointvec,
279 #ifdef CONFIG_SCHED_DEBUG
281 .procname = "sched_min_granularity_ns",
282 .data = &sysctl_sched_min_granularity,
283 .maxlen = sizeof(unsigned int),
285 .proc_handler = sched_proc_update_handler,
286 .extra1 = &min_sched_granularity_ns,
287 .extra2 = &max_sched_granularity_ns,
290 .procname = "sched_latency_ns",
291 .data = &sysctl_sched_latency,
292 .maxlen = sizeof(unsigned int),
294 .proc_handler = sched_proc_update_handler,
295 .extra1 = &min_sched_granularity_ns,
296 .extra2 = &max_sched_granularity_ns,
299 .procname = "sched_wakeup_granularity_ns",
300 .data = &sysctl_sched_wakeup_granularity,
301 .maxlen = sizeof(unsigned int),
303 .proc_handler = sched_proc_update_handler,
304 .extra1 = &min_wakeup_granularity_ns,
305 .extra2 = &max_wakeup_granularity_ns,
308 .procname = "sched_shares_ratelimit",
309 .data = &sysctl_sched_shares_ratelimit,
310 .maxlen = sizeof(unsigned int),
312 .proc_handler = sched_proc_update_handler,
313 .extra1 = &min_sched_shares_ratelimit,
314 .extra2 = &max_sched_shares_ratelimit,
317 .procname = "sched_tunable_scaling",
318 .data = &sysctl_sched_tunable_scaling,
319 .maxlen = sizeof(enum sched_tunable_scaling),
321 .proc_handler = sched_proc_update_handler,
322 .extra1 = &min_sched_tunable_scaling,
323 .extra2 = &max_sched_tunable_scaling,
326 .procname = "sched_shares_thresh",
327 .data = &sysctl_sched_shares_thresh,
328 .maxlen = sizeof(unsigned int),
330 .proc_handler = proc_dointvec_minmax,
334 .procname = "sched_migration_cost",
335 .data = &sysctl_sched_migration_cost,
336 .maxlen = sizeof(unsigned int),
338 .proc_handler = proc_dointvec,
341 .procname = "sched_nr_migrate",
342 .data = &sysctl_sched_nr_migrate,
343 .maxlen = sizeof(unsigned int),
345 .proc_handler = proc_dointvec,
348 .procname = "sched_time_avg",
349 .data = &sysctl_sched_time_avg,
350 .maxlen = sizeof(unsigned int),
352 .proc_handler = proc_dointvec,
355 .procname = "timer_migration",
356 .data = &sysctl_timer_migration,
357 .maxlen = sizeof(unsigned int),
359 .proc_handler = proc_dointvec_minmax,
365 .procname = "sched_rt_period_us",
366 .data = &sysctl_sched_rt_period,
367 .maxlen = sizeof(unsigned int),
369 .proc_handler = sched_rt_handler,
372 .procname = "sched_rt_runtime_us",
373 .data = &sysctl_sched_rt_runtime,
374 .maxlen = sizeof(int),
376 .proc_handler = sched_rt_handler,
379 .procname = "sched_compat_yield",
380 .data = &sysctl_sched_compat_yield,
381 .maxlen = sizeof(unsigned int),
383 .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,
707 .procname = "dmesg_restrict",
708 .data = &dmesg_restrict,
709 .maxlen = sizeof(int),
711 .proc_handler = proc_dointvec_minmax,
716 .procname = "ngroups_max",
717 .data = &ngroups_max,
718 .maxlen = sizeof (int),
720 .proc_handler = proc_dointvec,
722 #if defined(CONFIG_LOCKUP_DETECTOR)
724 .procname = "watchdog",
725 .data = &watchdog_enabled,
726 .maxlen = sizeof (int),
728 .proc_handler = proc_dowatchdog_enabled,
731 .procname = "watchdog_thresh",
732 .data = &softlockup_thresh,
733 .maxlen = sizeof(int),
735 .proc_handler = proc_dowatchdog_thresh,
740 .procname = "softlockup_panic",
741 .data = &softlockup_panic,
742 .maxlen = sizeof(int),
744 .proc_handler = proc_dointvec_minmax,
749 #if defined(CONFIG_X86)
751 .procname = "panic_on_unrecovered_nmi",
752 .data = &panic_on_unrecovered_nmi,
753 .maxlen = sizeof(int),
755 .proc_handler = proc_dointvec,
758 .procname = "panic_on_io_nmi",
759 .data = &panic_on_io_nmi,
760 .maxlen = sizeof(int),
762 .proc_handler = proc_dointvec,
765 .procname = "bootloader_type",
766 .data = &bootloader_type,
767 .maxlen = sizeof (int),
769 .proc_handler = proc_dointvec,
772 .procname = "bootloader_version",
773 .data = &bootloader_version,
774 .maxlen = sizeof (int),
776 .proc_handler = proc_dointvec,
779 .procname = "kstack_depth_to_print",
780 .data = &kstack_depth_to_print,
781 .maxlen = sizeof(int),
783 .proc_handler = proc_dointvec,
786 .procname = "io_delay_type",
787 .data = &io_delay_type,
788 .maxlen = sizeof(int),
790 .proc_handler = proc_dointvec,
793 #if defined(CONFIG_MMU)
795 .procname = "randomize_va_space",
796 .data = &randomize_va_space,
797 .maxlen = sizeof(int),
799 .proc_handler = proc_dointvec,
802 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
804 .procname = "spin_retry",
806 .maxlen = sizeof (int),
808 .proc_handler = proc_dointvec,
811 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
813 .procname = "acpi_video_flags",
814 .data = &acpi_realmode_flags,
815 .maxlen = sizeof (unsigned long),
817 .proc_handler = proc_doulongvec_minmax,
822 .procname = "ignore-unaligned-usertrap",
823 .data = &no_unaligned_warning,
824 .maxlen = sizeof (int),
826 .proc_handler = proc_dointvec,
829 .procname = "unaligned-dump-stack",
830 .data = &unaligned_dump_stack,
831 .maxlen = sizeof (int),
833 .proc_handler = proc_dointvec,
836 #ifdef CONFIG_DETECT_HUNG_TASK
838 .procname = "hung_task_panic",
839 .data = &sysctl_hung_task_panic,
840 .maxlen = sizeof(int),
842 .proc_handler = proc_dointvec_minmax,
847 .procname = "hung_task_check_count",
848 .data = &sysctl_hung_task_check_count,
849 .maxlen = sizeof(unsigned long),
851 .proc_handler = proc_doulongvec_minmax,
854 .procname = "hung_task_timeout_secs",
855 .data = &sysctl_hung_task_timeout_secs,
856 .maxlen = sizeof(unsigned long),
858 .proc_handler = proc_dohung_task_timeout_secs,
861 .procname = "hung_task_warnings",
862 .data = &sysctl_hung_task_warnings,
863 .maxlen = sizeof(unsigned long),
865 .proc_handler = proc_doulongvec_minmax,
870 .procname = "compat-log",
872 .maxlen = sizeof (int),
874 .proc_handler = proc_dointvec,
877 #ifdef CONFIG_RT_MUTEXES
879 .procname = "max_lock_depth",
880 .data = &max_lock_depth,
881 .maxlen = sizeof(int),
883 .proc_handler = proc_dointvec,
887 .procname = "poweroff_cmd",
888 .data = &poweroff_cmd,
889 .maxlen = POWEROFF_CMD_PATH_LEN,
891 .proc_handler = proc_dostring,
897 .child = key_sysctls,
900 #ifdef CONFIG_RCU_TORTURE_TEST
902 .procname = "rcutorture_runnable",
903 .data = &rcutorture_runnable,
904 .maxlen = sizeof(int),
906 .proc_handler = proc_dointvec,
909 #ifdef CONFIG_PERF_EVENTS
911 .procname = "perf_event_paranoid",
912 .data = &sysctl_perf_event_paranoid,
913 .maxlen = sizeof(sysctl_perf_event_paranoid),
915 .proc_handler = proc_dointvec,
918 .procname = "perf_event_mlock_kb",
919 .data = &sysctl_perf_event_mlock,
920 .maxlen = sizeof(sysctl_perf_event_mlock),
922 .proc_handler = proc_dointvec,
925 .procname = "perf_event_max_sample_rate",
926 .data = &sysctl_perf_event_sample_rate,
927 .maxlen = sizeof(sysctl_perf_event_sample_rate),
929 .proc_handler = proc_dointvec,
932 #ifdef CONFIG_KMEMCHECK
934 .procname = "kmemcheck",
935 .data = &kmemcheck_enabled,
936 .maxlen = sizeof(int),
938 .proc_handler = proc_dointvec,
943 .procname = "blk_iopoll",
944 .data = &blk_iopoll_enabled,
945 .maxlen = sizeof(int),
947 .proc_handler = proc_dointvec,
951 * NOTE: do not add new entries to this table unless you have read
952 * Documentation/sysctl/ctl_unnumbered.txt
957 static struct ctl_table vm_table[] = {
959 .procname = "overcommit_memory",
960 .data = &sysctl_overcommit_memory,
961 .maxlen = sizeof(sysctl_overcommit_memory),
963 .proc_handler = proc_dointvec,
966 .procname = "panic_on_oom",
967 .data = &sysctl_panic_on_oom,
968 .maxlen = sizeof(sysctl_panic_on_oom),
970 .proc_handler = proc_dointvec,
973 .procname = "oom_kill_allocating_task",
974 .data = &sysctl_oom_kill_allocating_task,
975 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
977 .proc_handler = proc_dointvec,
980 .procname = "oom_dump_tasks",
981 .data = &sysctl_oom_dump_tasks,
982 .maxlen = sizeof(sysctl_oom_dump_tasks),
984 .proc_handler = proc_dointvec,
987 .procname = "overcommit_ratio",
988 .data = &sysctl_overcommit_ratio,
989 .maxlen = sizeof(sysctl_overcommit_ratio),
991 .proc_handler = proc_dointvec,
994 .procname = "page-cluster",
995 .data = &page_cluster,
996 .maxlen = sizeof(int),
998 .proc_handler = proc_dointvec,
1001 .procname = "dirty_background_ratio",
1002 .data = &dirty_background_ratio,
1003 .maxlen = sizeof(dirty_background_ratio),
1005 .proc_handler = dirty_background_ratio_handler,
1007 .extra2 = &one_hundred,
1010 .procname = "dirty_background_bytes",
1011 .data = &dirty_background_bytes,
1012 .maxlen = sizeof(dirty_background_bytes),
1014 .proc_handler = dirty_background_bytes_handler,
1018 .procname = "dirty_ratio",
1019 .data = &vm_dirty_ratio,
1020 .maxlen = sizeof(vm_dirty_ratio),
1022 .proc_handler = dirty_ratio_handler,
1024 .extra2 = &one_hundred,
1027 .procname = "dirty_bytes",
1028 .data = &vm_dirty_bytes,
1029 .maxlen = sizeof(vm_dirty_bytes),
1031 .proc_handler = dirty_bytes_handler,
1032 .extra1 = &dirty_bytes_min,
1035 .procname = "dirty_writeback_centisecs",
1036 .data = &dirty_writeback_interval,
1037 .maxlen = sizeof(dirty_writeback_interval),
1039 .proc_handler = dirty_writeback_centisecs_handler,
1042 .procname = "dirty_expire_centisecs",
1043 .data = &dirty_expire_interval,
1044 .maxlen = sizeof(dirty_expire_interval),
1046 .proc_handler = proc_dointvec,
1049 .procname = "nr_pdflush_threads",
1050 .data = &nr_pdflush_threads,
1051 .maxlen = sizeof nr_pdflush_threads,
1052 .mode = 0444 /* read-only*/,
1053 .proc_handler = proc_dointvec,
1056 .procname = "swappiness",
1057 .data = &vm_swappiness,
1058 .maxlen = sizeof(vm_swappiness),
1060 .proc_handler = proc_dointvec_minmax,
1062 .extra2 = &one_hundred,
1064 #ifdef CONFIG_HUGETLB_PAGE
1066 .procname = "nr_hugepages",
1068 .maxlen = sizeof(unsigned long),
1070 .proc_handler = hugetlb_sysctl_handler,
1071 .extra1 = (void *)&hugetlb_zero,
1072 .extra2 = (void *)&hugetlb_infinity,
1076 .procname = "nr_hugepages_mempolicy",
1078 .maxlen = sizeof(unsigned long),
1080 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1081 .extra1 = (void *)&hugetlb_zero,
1082 .extra2 = (void *)&hugetlb_infinity,
1086 .procname = "hugetlb_shm_group",
1087 .data = &sysctl_hugetlb_shm_group,
1088 .maxlen = sizeof(gid_t),
1090 .proc_handler = proc_dointvec,
1093 .procname = "hugepages_treat_as_movable",
1094 .data = &hugepages_treat_as_movable,
1095 .maxlen = sizeof(int),
1097 .proc_handler = hugetlb_treat_movable_handler,
1100 .procname = "nr_overcommit_hugepages",
1102 .maxlen = sizeof(unsigned long),
1104 .proc_handler = hugetlb_overcommit_handler,
1105 .extra1 = (void *)&hugetlb_zero,
1106 .extra2 = (void *)&hugetlb_infinity,
1110 .procname = "lowmem_reserve_ratio",
1111 .data = &sysctl_lowmem_reserve_ratio,
1112 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1114 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1117 .procname = "drop_caches",
1118 .data = &sysctl_drop_caches,
1119 .maxlen = sizeof(int),
1121 .proc_handler = drop_caches_sysctl_handler,
1123 #ifdef CONFIG_COMPACTION
1125 .procname = "compact_memory",
1126 .data = &sysctl_compact_memory,
1127 .maxlen = sizeof(int),
1129 .proc_handler = sysctl_compaction_handler,
1132 .procname = "extfrag_threshold",
1133 .data = &sysctl_extfrag_threshold,
1134 .maxlen = sizeof(int),
1136 .proc_handler = sysctl_extfrag_handler,
1137 .extra1 = &min_extfrag_threshold,
1138 .extra2 = &max_extfrag_threshold,
1141 #endif /* CONFIG_COMPACTION */
1143 .procname = "min_free_kbytes",
1144 .data = &min_free_kbytes,
1145 .maxlen = sizeof(min_free_kbytes),
1147 .proc_handler = min_free_kbytes_sysctl_handler,
1151 .procname = "percpu_pagelist_fraction",
1152 .data = &percpu_pagelist_fraction,
1153 .maxlen = sizeof(percpu_pagelist_fraction),
1155 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1156 .extra1 = &min_percpu_pagelist_fract,
1160 .procname = "max_map_count",
1161 .data = &sysctl_max_map_count,
1162 .maxlen = sizeof(sysctl_max_map_count),
1164 .proc_handler = proc_dointvec_minmax,
1169 .procname = "nr_trim_pages",
1170 .data = &sysctl_nr_trim_pages,
1171 .maxlen = sizeof(sysctl_nr_trim_pages),
1173 .proc_handler = proc_dointvec_minmax,
1178 .procname = "laptop_mode",
1179 .data = &laptop_mode,
1180 .maxlen = sizeof(laptop_mode),
1182 .proc_handler = proc_dointvec_jiffies,
1185 .procname = "block_dump",
1186 .data = &block_dump,
1187 .maxlen = sizeof(block_dump),
1189 .proc_handler = proc_dointvec,
1193 .procname = "vfs_cache_pressure",
1194 .data = &sysctl_vfs_cache_pressure,
1195 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1197 .proc_handler = proc_dointvec,
1200 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1202 .procname = "legacy_va_layout",
1203 .data = &sysctl_legacy_va_layout,
1204 .maxlen = sizeof(sysctl_legacy_va_layout),
1206 .proc_handler = proc_dointvec,
1212 .procname = "zone_reclaim_mode",
1213 .data = &zone_reclaim_mode,
1214 .maxlen = sizeof(zone_reclaim_mode),
1216 .proc_handler = proc_dointvec,
1220 .procname = "min_unmapped_ratio",
1221 .data = &sysctl_min_unmapped_ratio,
1222 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1224 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1226 .extra2 = &one_hundred,
1229 .procname = "min_slab_ratio",
1230 .data = &sysctl_min_slab_ratio,
1231 .maxlen = sizeof(sysctl_min_slab_ratio),
1233 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1235 .extra2 = &one_hundred,
1240 .procname = "stat_interval",
1241 .data = &sysctl_stat_interval,
1242 .maxlen = sizeof(sysctl_stat_interval),
1244 .proc_handler = proc_dointvec_jiffies,
1249 .procname = "mmap_min_addr",
1250 .data = &dac_mmap_min_addr,
1251 .maxlen = sizeof(unsigned long),
1253 .proc_handler = mmap_min_addr_handler,
1258 .procname = "numa_zonelist_order",
1259 .data = &numa_zonelist_order,
1260 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1262 .proc_handler = numa_zonelist_order_handler,
1265 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1266 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1268 .procname = "vdso_enabled",
1269 .data = &vdso_enabled,
1270 .maxlen = sizeof(vdso_enabled),
1272 .proc_handler = proc_dointvec,
1276 #ifdef CONFIG_HIGHMEM
1278 .procname = "highmem_is_dirtyable",
1279 .data = &vm_highmem_is_dirtyable,
1280 .maxlen = sizeof(vm_highmem_is_dirtyable),
1282 .proc_handler = proc_dointvec_minmax,
1288 .procname = "scan_unevictable_pages",
1289 .data = &scan_unevictable_pages,
1290 .maxlen = sizeof(scan_unevictable_pages),
1292 .proc_handler = scan_unevictable_handler,
1294 #ifdef CONFIG_MEMORY_FAILURE
1296 .procname = "memory_failure_early_kill",
1297 .data = &sysctl_memory_failure_early_kill,
1298 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1300 .proc_handler = proc_dointvec_minmax,
1305 .procname = "memory_failure_recovery",
1306 .data = &sysctl_memory_failure_recovery,
1307 .maxlen = sizeof(sysctl_memory_failure_recovery),
1309 .proc_handler = proc_dointvec_minmax,
1316 * NOTE: do not add new entries to this table unless you have read
1317 * Documentation/sysctl/ctl_unnumbered.txt
1322 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1323 static struct ctl_table binfmt_misc_table[] = {
1328 static struct ctl_table fs_table[] = {
1330 .procname = "inode-nr",
1331 .data = &inodes_stat,
1332 .maxlen = 2*sizeof(int),
1334 .proc_handler = proc_nr_inodes,
1337 .procname = "inode-state",
1338 .data = &inodes_stat,
1339 .maxlen = 7*sizeof(int),
1341 .proc_handler = proc_nr_inodes,
1344 .procname = "file-nr",
1345 .data = &files_stat,
1346 .maxlen = sizeof(files_stat),
1348 .proc_handler = proc_nr_files,
1351 .procname = "file-max",
1352 .data = &files_stat.max_files,
1353 .maxlen = sizeof(files_stat.max_files),
1355 .proc_handler = proc_doulongvec_minmax,
1358 .procname = "nr_open",
1359 .data = &sysctl_nr_open,
1360 .maxlen = sizeof(int),
1362 .proc_handler = proc_dointvec_minmax,
1363 .extra1 = &sysctl_nr_open_min,
1364 .extra2 = &sysctl_nr_open_max,
1367 .procname = "dentry-state",
1368 .data = &dentry_stat,
1369 .maxlen = 6*sizeof(int),
1371 .proc_handler = proc_nr_dentry,
1374 .procname = "overflowuid",
1375 .data = &fs_overflowuid,
1376 .maxlen = sizeof(int),
1378 .proc_handler = proc_dointvec_minmax,
1379 .extra1 = &minolduid,
1380 .extra2 = &maxolduid,
1383 .procname = "overflowgid",
1384 .data = &fs_overflowgid,
1385 .maxlen = sizeof(int),
1387 .proc_handler = proc_dointvec_minmax,
1388 .extra1 = &minolduid,
1389 .extra2 = &maxolduid,
1391 #ifdef CONFIG_FILE_LOCKING
1393 .procname = "leases-enable",
1394 .data = &leases_enable,
1395 .maxlen = sizeof(int),
1397 .proc_handler = proc_dointvec,
1400 #ifdef CONFIG_DNOTIFY
1402 .procname = "dir-notify-enable",
1403 .data = &dir_notify_enable,
1404 .maxlen = sizeof(int),
1406 .proc_handler = proc_dointvec,
1410 #ifdef CONFIG_FILE_LOCKING
1412 .procname = "lease-break-time",
1413 .data = &lease_break_time,
1414 .maxlen = sizeof(int),
1416 .proc_handler = proc_dointvec,
1421 .procname = "aio-nr",
1423 .maxlen = sizeof(aio_nr),
1425 .proc_handler = proc_doulongvec_minmax,
1428 .procname = "aio-max-nr",
1429 .data = &aio_max_nr,
1430 .maxlen = sizeof(aio_max_nr),
1432 .proc_handler = proc_doulongvec_minmax,
1434 #endif /* CONFIG_AIO */
1435 #ifdef CONFIG_INOTIFY_USER
1437 .procname = "inotify",
1439 .child = inotify_table,
1444 .procname = "epoll",
1446 .child = epoll_table,
1451 .procname = "suid_dumpable",
1452 .data = &suid_dumpable,
1453 .maxlen = sizeof(int),
1455 .proc_handler = proc_dointvec_minmax,
1459 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1461 .procname = "binfmt_misc",
1463 .child = binfmt_misc_table,
1467 .procname = "pipe-max-size",
1468 .data = &pipe_max_size,
1469 .maxlen = sizeof(int),
1471 .proc_handler = &pipe_proc_fn,
1472 .extra1 = &pipe_min_size,
1475 * NOTE: do not add new entries to this table unless you have read
1476 * Documentation/sysctl/ctl_unnumbered.txt
1481 static struct ctl_table debug_table[] = {
1482 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1483 defined(CONFIG_S390)
1485 .procname = "exception-trace",
1486 .data = &show_unhandled_signals,
1487 .maxlen = sizeof(int),
1489 .proc_handler = proc_dointvec
1492 #if defined(CONFIG_OPTPROBES)
1494 .procname = "kprobes-optimization",
1495 .data = &sysctl_kprobes_optimization,
1496 .maxlen = sizeof(int),
1498 .proc_handler = proc_kprobes_optimization_handler,
1506 static struct ctl_table dev_table[] = {
1510 static DEFINE_SPINLOCK(sysctl_lock);
1512 /* called under sysctl_lock */
1513 static int use_table(struct ctl_table_header *p)
1515 if (unlikely(p->unregistering))
1521 /* called under sysctl_lock */
1522 static void unuse_table(struct ctl_table_header *p)
1525 if (unlikely(p->unregistering))
1526 complete(p->unregistering);
1529 /* called under sysctl_lock, will reacquire if has to wait */
1530 static void start_unregistering(struct ctl_table_header *p)
1533 * if p->used is 0, nobody will ever touch that entry again;
1534 * we'll eliminate all paths to it before dropping sysctl_lock
1536 if (unlikely(p->used)) {
1537 struct completion wait;
1538 init_completion(&wait);
1539 p->unregistering = &wait;
1540 spin_unlock(&sysctl_lock);
1541 wait_for_completion(&wait);
1542 spin_lock(&sysctl_lock);
1544 /* anything non-NULL; we'll never dereference it */
1545 p->unregistering = ERR_PTR(-EINVAL);
1548 * do not remove from the list until nobody holds it; walking the
1549 * list in do_sysctl() relies on that.
1551 list_del_init(&p->ctl_entry);
1554 void sysctl_head_get(struct ctl_table_header *head)
1556 spin_lock(&sysctl_lock);
1558 spin_unlock(&sysctl_lock);
1561 void sysctl_head_put(struct ctl_table_header *head)
1563 spin_lock(&sysctl_lock);
1566 spin_unlock(&sysctl_lock);
1569 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1573 spin_lock(&sysctl_lock);
1574 if (!use_table(head))
1575 head = ERR_PTR(-ENOENT);
1576 spin_unlock(&sysctl_lock);
1580 void sysctl_head_finish(struct ctl_table_header *head)
1584 spin_lock(&sysctl_lock);
1586 spin_unlock(&sysctl_lock);
1589 static struct ctl_table_set *
1590 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1592 struct ctl_table_set *set = &root->default_set;
1594 set = root->lookup(root, namespaces);
1598 static struct list_head *
1599 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1601 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1605 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1606 struct ctl_table_header *prev)
1608 struct ctl_table_root *root;
1609 struct list_head *header_list;
1610 struct ctl_table_header *head;
1611 struct list_head *tmp;
1613 spin_lock(&sysctl_lock);
1616 tmp = &prev->ctl_entry;
1620 tmp = &root_table_header.ctl_entry;
1622 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1624 if (!use_table(head))
1626 spin_unlock(&sysctl_lock);
1631 header_list = lookup_header_list(root, namespaces);
1632 if (tmp != header_list)
1636 root = list_entry(root->root_list.next,
1637 struct ctl_table_root, root_list);
1638 if (root == &sysctl_table_root)
1640 header_list = lookup_header_list(root, namespaces);
1641 } while (list_empty(header_list));
1642 tmp = header_list->next;
1645 spin_unlock(&sysctl_lock);
1649 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1651 return __sysctl_head_next(current->nsproxy, prev);
1654 void register_sysctl_root(struct ctl_table_root *root)
1656 spin_lock(&sysctl_lock);
1657 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1658 spin_unlock(&sysctl_lock);
1662 * sysctl_perm does NOT grant the superuser all rights automatically, because
1663 * some sysctl variables are readonly even to root.
1666 static int test_perm(int mode, int op)
1668 if (!current_euid())
1670 else if (in_egroup_p(0))
1672 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1677 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1682 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1686 if (root->permissions)
1687 mode = root->permissions(root, current->nsproxy, table);
1691 return test_perm(mode, op);
1694 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1696 for (; table->procname; table++) {
1697 table->parent = parent;
1699 sysctl_set_parent(table, table->child);
1703 static __init int sysctl_init(void)
1705 sysctl_set_parent(NULL, root_table);
1706 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1707 sysctl_check_table(current->nsproxy, root_table);
1712 core_initcall(sysctl_init);
1714 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1715 struct ctl_table *table)
1717 struct ctl_table *p;
1718 const char *s = branch->procname;
1720 /* branch should have named subdirectory as its first element */
1721 if (!s || !branch->child)
1724 /* ... and nothing else */
1725 if (branch[1].procname)
1728 /* table should contain subdirectory with the same name */
1729 for (p = table; p->procname; p++) {
1732 if (p->procname && strcmp(p->procname, s) == 0)
1738 /* see if attaching q to p would be an improvement */
1739 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1741 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1742 struct ctl_table *next;
1744 int not_in_parent = !p->attached_by;
1746 while ((next = is_branch_in(by, to)) != NULL) {
1747 if (by == q->attached_by)
1749 if (to == p->attached_by)
1755 if (is_better && not_in_parent) {
1756 q->attached_by = by;
1757 q->attached_to = to;
1763 * __register_sysctl_paths - register a sysctl hierarchy
1764 * @root: List of sysctl headers to register on
1765 * @namespaces: Data to compute which lists of sysctl entries are visible
1766 * @path: The path to the directory the sysctl table is in.
1767 * @table: the top-level table structure
1769 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1770 * array. A completely 0 filled entry terminates the table.
1772 * The members of the &struct ctl_table structure are used as follows:
1774 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1775 * enter a sysctl file
1777 * data - a pointer to data for use by proc_handler
1779 * maxlen - the maximum size in bytes of the data
1781 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1783 * child - a pointer to the child sysctl table if this entry is a directory, or
1786 * proc_handler - the text handler routine (described below)
1788 * de - for internal use by the sysctl routines
1790 * extra1, extra2 - extra pointers usable by the proc handler routines
1792 * Leaf nodes in the sysctl tree will be represented by a single file
1793 * under /proc; non-leaf nodes will be represented by directories.
1795 * sysctl(2) can automatically manage read and write requests through
1796 * the sysctl table. The data and maxlen fields of the ctl_table
1797 * struct enable minimal validation of the values being written to be
1798 * performed, and the mode field allows minimal authentication.
1800 * There must be a proc_handler routine for any terminal nodes
1801 * mirrored under /proc/sys (non-terminals are handled by a built-in
1802 * directory handler). Several default handlers are available to
1803 * cover common cases -
1805 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1806 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1807 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1809 * It is the handler's job to read the input buffer from user memory
1810 * and process it. The handler should return 0 on success.
1812 * This routine returns %NULL on a failure to register, and a pointer
1813 * to the table header on success.
1815 struct ctl_table_header *__register_sysctl_paths(
1816 struct ctl_table_root *root,
1817 struct nsproxy *namespaces,
1818 const struct ctl_path *path, struct ctl_table *table)
1820 struct ctl_table_header *header;
1821 struct ctl_table *new, **prevp;
1822 unsigned int n, npath;
1823 struct ctl_table_set *set;
1825 /* Count the path components */
1826 for (npath = 0; path[npath].procname; ++npath)
1830 * For each path component, allocate a 2-element ctl_table array.
1831 * The first array element will be filled with the sysctl entry
1832 * for this, the second will be the sentinel (procname == 0).
1834 * We allocate everything in one go so that we don't have to
1835 * worry about freeing additional memory in unregister_sysctl_table.
1837 header = kzalloc(sizeof(struct ctl_table_header) +
1838 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1842 new = (struct ctl_table *) (header + 1);
1844 /* Now connect the dots */
1845 prevp = &header->ctl_table;
1846 for (n = 0; n < npath; ++n, ++path) {
1847 /* Copy the procname */
1848 new->procname = path->procname;
1852 prevp = &new->child;
1857 header->ctl_table_arg = table;
1859 INIT_LIST_HEAD(&header->ctl_entry);
1861 header->unregistering = NULL;
1862 header->root = root;
1863 sysctl_set_parent(NULL, header->ctl_table);
1865 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1866 if (sysctl_check_table(namespaces, header->ctl_table)) {
1871 spin_lock(&sysctl_lock);
1872 header->set = lookup_header_set(root, namespaces);
1873 header->attached_by = header->ctl_table;
1874 header->attached_to = root_table;
1875 header->parent = &root_table_header;
1876 for (set = header->set; set; set = set->parent) {
1877 struct ctl_table_header *p;
1878 list_for_each_entry(p, &set->list, ctl_entry) {
1879 if (p->unregistering)
1881 try_attach(p, header);
1884 header->parent->count++;
1885 list_add_tail(&header->ctl_entry, &header->set->list);
1886 spin_unlock(&sysctl_lock);
1892 * register_sysctl_table_path - register a sysctl table hierarchy
1893 * @path: The path to the directory the sysctl table is in.
1894 * @table: the top-level table structure
1896 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1897 * array. A completely 0 filled entry terminates the table.
1899 * See __register_sysctl_paths for more details.
1901 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1902 struct ctl_table *table)
1904 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1909 * register_sysctl_table - register a sysctl table hierarchy
1910 * @table: the top-level table structure
1912 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1913 * array. A completely 0 filled entry terminates the table.
1915 * See register_sysctl_paths for more details.
1917 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1919 static const struct ctl_path null_path[] = { {} };
1921 return register_sysctl_paths(null_path, table);
1925 * unregister_sysctl_table - unregister a sysctl table hierarchy
1926 * @header: the header returned from register_sysctl_table
1928 * Unregisters the sysctl table and all children. proc entries may not
1929 * actually be removed until they are no longer used by anyone.
1931 void unregister_sysctl_table(struct ctl_table_header * header)
1938 spin_lock(&sysctl_lock);
1939 start_unregistering(header);
1940 if (!--header->parent->count) {
1942 kfree(header->parent);
1944 if (!--header->count)
1946 spin_unlock(&sysctl_lock);
1949 int sysctl_is_seen(struct ctl_table_header *p)
1951 struct ctl_table_set *set = p->set;
1953 spin_lock(&sysctl_lock);
1954 if (p->unregistering)
1956 else if (!set->is_seen)
1959 res = set->is_seen(set);
1960 spin_unlock(&sysctl_lock);
1964 void setup_sysctl_set(struct ctl_table_set *p,
1965 struct ctl_table_set *parent,
1966 int (*is_seen)(struct ctl_table_set *))
1968 INIT_LIST_HEAD(&p->list);
1969 p->parent = parent ? parent : &sysctl_table_root.default_set;
1970 p->is_seen = is_seen;
1973 #else /* !CONFIG_SYSCTL */
1974 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1979 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1980 struct ctl_table *table)
1985 void unregister_sysctl_table(struct ctl_table_header * table)
1989 void setup_sysctl_set(struct ctl_table_set *p,
1990 struct ctl_table_set *parent,
1991 int (*is_seen)(struct ctl_table_set *))
1995 void sysctl_head_put(struct ctl_table_header *head)
1999 #endif /* CONFIG_SYSCTL */
2005 #ifdef CONFIG_PROC_SYSCTL
2007 static int _proc_do_string(void* data, int maxlen, int write,
2008 void __user *buffer,
2009 size_t *lenp, loff_t *ppos)
2015 if (!data || !maxlen || !*lenp) {
2023 while (len < *lenp) {
2024 if (get_user(c, p++))
2026 if (c == 0 || c == '\n')
2032 if(copy_from_user(data, buffer, len))
2034 ((char *) data)[len] = 0;
2052 if(copy_to_user(buffer, data, len))
2055 if(put_user('\n', ((char __user *) buffer) + len))
2066 * proc_dostring - read a string sysctl
2067 * @table: the sysctl table
2068 * @write: %TRUE if this is a write to the sysctl file
2069 * @buffer: the user buffer
2070 * @lenp: the size of the user buffer
2071 * @ppos: file position
2073 * Reads/writes a string from/to the user buffer. If the kernel
2074 * buffer provided is not large enough to hold the string, the
2075 * string is truncated. The copied string is %NULL-terminated.
2076 * If the string is being read by the user process, it is copied
2077 * and a newline '\n' is added. It is truncated if the buffer is
2080 * Returns 0 on success.
2082 int proc_dostring(struct ctl_table *table, int write,
2083 void __user *buffer, size_t *lenp, loff_t *ppos)
2085 return _proc_do_string(table->data, table->maxlen, write,
2086 buffer, lenp, ppos);
2089 static size_t proc_skip_spaces(char **buf)
2092 char *tmp = skip_spaces(*buf);
2098 static void proc_skip_char(char **buf, size_t *size, const char v)
2108 #define TMPBUFLEN 22
2110 * proc_get_long - reads an ASCII formatted integer from a user buffer
2112 * @buf: a kernel buffer
2113 * @size: size of the kernel buffer
2114 * @val: this is where the number will be stored
2115 * @neg: set to %TRUE if number is negative
2116 * @perm_tr: a vector which contains the allowed trailers
2117 * @perm_tr_len: size of the perm_tr vector
2118 * @tr: pointer to store the trailer character
2120 * In case of success %0 is returned and @buf and @size are updated with
2121 * the amount of bytes read. If @tr is non-NULL and a trailing
2122 * character exists (size is non-zero after returning from this
2123 * function), @tr is updated with the trailing character.
2125 static int proc_get_long(char **buf, size_t *size,
2126 unsigned long *val, bool *neg,
2127 const char *perm_tr, unsigned perm_tr_len, char *tr)
2130 char *p, tmp[TMPBUFLEN];
2136 if (len > TMPBUFLEN - 1)
2137 len = TMPBUFLEN - 1;
2139 memcpy(tmp, *buf, len);
2143 if (*p == '-' && *size > 1) {
2151 *val = simple_strtoul(p, &p, 0);
2155 /* We don't know if the next char is whitespace thus we may accept
2156 * invalid integers (e.g. 1234...a) or two integers instead of one
2157 * (e.g. 123...1). So lets not allow such large numbers. */
2158 if (len == TMPBUFLEN - 1)
2161 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2164 if (tr && (len < *size))
2174 * proc_put_long - converts an integer to a decimal ASCII formatted string
2176 * @buf: the user buffer
2177 * @size: the size of the user buffer
2178 * @val: the integer to be converted
2179 * @neg: sign of the number, %TRUE for negative
2181 * In case of success %0 is returned and @buf and @size are updated with
2182 * the amount of bytes written.
2184 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2188 char tmp[TMPBUFLEN], *p = tmp;
2190 sprintf(p, "%s%lu", neg ? "-" : "", val);
2194 if (copy_to_user(*buf, tmp, len))
2202 static int proc_put_char(void __user **buf, size_t *size, char c)
2205 char __user **buffer = (char __user **)buf;
2206 if (put_user(c, *buffer))
2208 (*size)--, (*buffer)++;
2214 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2216 int write, void *data)
2219 *valp = *negp ? -*lvalp : *lvalp;
2224 *lvalp = (unsigned long)-val;
2227 *lvalp = (unsigned long)val;
2233 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2235 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2236 int write, void __user *buffer,
2237 size_t *lenp, loff_t *ppos,
2238 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2239 int write, void *data),
2242 int *i, vleft, first = 1, err = 0;
2243 unsigned long page = 0;
2247 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2252 i = (int *) tbl_data;
2253 vleft = table->maxlen / sizeof(*i);
2257 conv = do_proc_dointvec_conv;
2260 if (left > PAGE_SIZE - 1)
2261 left = PAGE_SIZE - 1;
2262 page = __get_free_page(GFP_TEMPORARY);
2263 kbuf = (char *) page;
2266 if (copy_from_user(kbuf, buffer, left)) {
2273 for (; left && vleft--; i++, first=0) {
2278 left -= proc_skip_spaces(&kbuf);
2282 err = proc_get_long(&kbuf, &left, &lval, &neg,
2284 sizeof(proc_wspace_sep), NULL);
2287 if (conv(&neg, &lval, i, 1, data)) {
2292 if (conv(&neg, &lval, i, 0, data)) {
2297 err = proc_put_char(&buffer, &left, '\t');
2300 err = proc_put_long(&buffer, &left, lval, neg);
2306 if (!write && !first && left && !err)
2307 err = proc_put_char(&buffer, &left, '\n');
2308 if (write && !err && left)
2309 left -= proc_skip_spaces(&kbuf);
2314 return err ? : -EINVAL;
2321 static int do_proc_dointvec(struct ctl_table *table, int write,
2322 void __user *buffer, size_t *lenp, loff_t *ppos,
2323 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2324 int write, void *data),
2327 return __do_proc_dointvec(table->data, table, write,
2328 buffer, lenp, ppos, conv, data);
2332 * proc_dointvec - read a vector of integers
2333 * @table: the sysctl table
2334 * @write: %TRUE if this is a write to the sysctl file
2335 * @buffer: the user buffer
2336 * @lenp: the size of the user buffer
2337 * @ppos: file position
2339 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2340 * values from/to the user buffer, treated as an ASCII string.
2342 * Returns 0 on success.
2344 int proc_dointvec(struct ctl_table *table, int write,
2345 void __user *buffer, size_t *lenp, loff_t *ppos)
2347 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2352 * Taint values can only be increased
2353 * This means we can safely use a temporary.
2355 static int proc_taint(struct ctl_table *table, int write,
2356 void __user *buffer, size_t *lenp, loff_t *ppos)
2359 unsigned long tmptaint = get_taint();
2362 if (write && !capable(CAP_SYS_ADMIN))
2367 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2373 * Poor man's atomic or. Not worth adding a primitive
2374 * to everyone's atomic.h for this
2377 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2378 if ((tmptaint >> i) & 1)
2386 struct do_proc_dointvec_minmax_conv_param {
2391 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2393 int write, void *data)
2395 struct do_proc_dointvec_minmax_conv_param *param = data;
2397 int val = *negp ? -*lvalp : *lvalp;
2398 if ((param->min && *param->min > val) ||
2399 (param->max && *param->max < val))
2406 *lvalp = (unsigned long)-val;
2409 *lvalp = (unsigned long)val;
2416 * proc_dointvec_minmax - read a vector of integers with min/max values
2417 * @table: the sysctl table
2418 * @write: %TRUE if this is a write to the sysctl file
2419 * @buffer: the user buffer
2420 * @lenp: the size of the user buffer
2421 * @ppos: file position
2423 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2424 * values from/to the user buffer, treated as an ASCII string.
2426 * This routine will ensure the values are within the range specified by
2427 * table->extra1 (min) and table->extra2 (max).
2429 * Returns 0 on success.
2431 int proc_dointvec_minmax(struct ctl_table *table, int write,
2432 void __user *buffer, size_t *lenp, loff_t *ppos)
2434 struct do_proc_dointvec_minmax_conv_param param = {
2435 .min = (int *) table->extra1,
2436 .max = (int *) table->extra2,
2438 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2439 do_proc_dointvec_minmax_conv, ¶m);
2442 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2443 void __user *buffer,
2444 size_t *lenp, loff_t *ppos,
2445 unsigned long convmul,
2446 unsigned long convdiv)
2448 unsigned long *i, *min, *max;
2449 int vleft, first = 1, err = 0;
2450 unsigned long page = 0;
2454 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2459 i = (unsigned long *) data;
2460 min = (unsigned long *) table->extra1;
2461 max = (unsigned long *) table->extra2;
2462 vleft = table->maxlen / sizeof(unsigned long);
2466 if (left > PAGE_SIZE - 1)
2467 left = PAGE_SIZE - 1;
2468 page = __get_free_page(GFP_TEMPORARY);
2469 kbuf = (char *) page;
2472 if (copy_from_user(kbuf, buffer, left)) {
2479 for (; left && vleft--; i++, first = 0) {
2485 left -= proc_skip_spaces(&kbuf);
2487 err = proc_get_long(&kbuf, &left, &val, &neg,
2489 sizeof(proc_wspace_sep), NULL);
2494 if ((min && val < *min) || (max && val > *max))
2498 val = convdiv * (*i) / convmul;
2500 err = proc_put_char(&buffer, &left, '\t');
2501 err = proc_put_long(&buffer, &left, val, false);
2507 if (!write && !first && left && !err)
2508 err = proc_put_char(&buffer, &left, '\n');
2510 left -= proc_skip_spaces(&kbuf);
2515 return err ? : -EINVAL;
2522 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2523 void __user *buffer,
2524 size_t *lenp, loff_t *ppos,
2525 unsigned long convmul,
2526 unsigned long convdiv)
2528 return __do_proc_doulongvec_minmax(table->data, table, write,
2529 buffer, lenp, ppos, convmul, convdiv);
2533 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2534 * @table: the sysctl table
2535 * @write: %TRUE if this is a write to the sysctl file
2536 * @buffer: the user buffer
2537 * @lenp: the size of the user buffer
2538 * @ppos: file position
2540 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2541 * values from/to the user buffer, treated as an ASCII string.
2543 * This routine will ensure the values are within the range specified by
2544 * table->extra1 (min) and table->extra2 (max).
2546 * Returns 0 on success.
2548 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2549 void __user *buffer, size_t *lenp, loff_t *ppos)
2551 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2555 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2556 * @table: the sysctl table
2557 * @write: %TRUE if this is a write to the sysctl file
2558 * @buffer: the user buffer
2559 * @lenp: the size of the user buffer
2560 * @ppos: file position
2562 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2563 * values from/to the user buffer, treated as an ASCII string. The values
2564 * are treated as milliseconds, and converted to jiffies when they are stored.
2566 * This routine will ensure the values are within the range specified by
2567 * table->extra1 (min) and table->extra2 (max).
2569 * Returns 0 on success.
2571 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2572 void __user *buffer,
2573 size_t *lenp, loff_t *ppos)
2575 return do_proc_doulongvec_minmax(table, write, buffer,
2576 lenp, ppos, HZ, 1000l);
2580 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2582 int write, void *data)
2585 if (*lvalp > LONG_MAX / HZ)
2587 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2593 lval = (unsigned long)-val;
2596 lval = (unsigned long)val;
2603 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2605 int write, void *data)
2608 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2610 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2616 lval = (unsigned long)-val;
2619 lval = (unsigned long)val;
2621 *lvalp = jiffies_to_clock_t(lval);
2626 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2628 int write, void *data)
2631 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2637 lval = (unsigned long)-val;
2640 lval = (unsigned long)val;
2642 *lvalp = jiffies_to_msecs(lval);
2648 * proc_dointvec_jiffies - read a vector of integers as seconds
2649 * @table: the sysctl table
2650 * @write: %TRUE if this is a write to the sysctl file
2651 * @buffer: the user buffer
2652 * @lenp: the size of the user buffer
2653 * @ppos: file position
2655 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2656 * values from/to the user buffer, treated as an ASCII string.
2657 * The values read are assumed to be in seconds, and are converted into
2660 * Returns 0 on success.
2662 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2663 void __user *buffer, size_t *lenp, loff_t *ppos)
2665 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2666 do_proc_dointvec_jiffies_conv,NULL);
2670 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2671 * @table: the sysctl table
2672 * @write: %TRUE if this is a write to the sysctl file
2673 * @buffer: the user buffer
2674 * @lenp: the size of the user buffer
2675 * @ppos: pointer to the file position
2677 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2678 * values from/to the user buffer, treated as an ASCII string.
2679 * The values read are assumed to be in 1/USER_HZ seconds, and
2680 * are converted into jiffies.
2682 * Returns 0 on success.
2684 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2685 void __user *buffer, size_t *lenp, loff_t *ppos)
2687 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2688 do_proc_dointvec_userhz_jiffies_conv,NULL);
2692 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2693 * @table: the sysctl table
2694 * @write: %TRUE if this is a write to the sysctl file
2695 * @buffer: the user buffer
2696 * @lenp: the size of the user buffer
2697 * @ppos: file position
2698 * @ppos: the current position in the file
2700 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2701 * values from/to the user buffer, treated as an ASCII string.
2702 * The values read are assumed to be in 1/1000 seconds, and
2703 * are converted into jiffies.
2705 * Returns 0 on success.
2707 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2708 void __user *buffer, size_t *lenp, loff_t *ppos)
2710 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2711 do_proc_dointvec_ms_jiffies_conv, NULL);
2714 static int proc_do_cad_pid(struct ctl_table *table, int write,
2715 void __user *buffer, size_t *lenp, loff_t *ppos)
2717 struct pid *new_pid;
2721 tmp = pid_vnr(cad_pid);
2723 r = __do_proc_dointvec(&tmp, table, write, buffer,
2724 lenp, ppos, NULL, NULL);
2728 new_pid = find_get_pid(tmp);
2732 put_pid(xchg(&cad_pid, new_pid));
2737 * proc_do_large_bitmap - read/write from/to a large bitmap
2738 * @table: the sysctl table
2739 * @write: %TRUE if this is a write to the sysctl file
2740 * @buffer: the user buffer
2741 * @lenp: the size of the user buffer
2742 * @ppos: file position
2744 * The bitmap is stored at table->data and the bitmap length (in bits)
2747 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2748 * large bitmaps may be represented in a compact manner. Writing into
2749 * the file will clear the bitmap then update it with the given input.
2751 * Returns 0 on success.
2753 int proc_do_large_bitmap(struct ctl_table *table, int write,
2754 void __user *buffer, size_t *lenp, loff_t *ppos)
2758 size_t left = *lenp;
2759 unsigned long bitmap_len = table->maxlen;
2760 unsigned long *bitmap = (unsigned long *) table->data;
2761 unsigned long *tmp_bitmap = NULL;
2762 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2764 if (!bitmap_len || !left || (*ppos && !write)) {
2770 unsigned long page = 0;
2773 if (left > PAGE_SIZE - 1)
2774 left = PAGE_SIZE - 1;
2776 page = __get_free_page(GFP_TEMPORARY);
2777 kbuf = (char *) page;
2780 if (copy_from_user(kbuf, buffer, left)) {
2786 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2792 proc_skip_char(&kbuf, &left, '\n');
2793 while (!err && left) {
2794 unsigned long val_a, val_b;
2797 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2801 if (val_a >= bitmap_len || neg) {
2813 err = proc_get_long(&kbuf, &left, &val_b,
2814 &neg, tr_b, sizeof(tr_b),
2818 if (val_b >= bitmap_len || neg ||
2829 while (val_a <= val_b)
2830 set_bit(val_a++, tmp_bitmap);
2833 proc_skip_char(&kbuf, &left, '\n');
2837 unsigned long bit_a, bit_b = 0;
2840 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2841 if (bit_a >= bitmap_len)
2843 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2847 err = proc_put_char(&buffer, &left, ',');
2851 err = proc_put_long(&buffer, &left, bit_a, false);
2854 if (bit_a != bit_b) {
2855 err = proc_put_char(&buffer, &left, '-');
2858 err = proc_put_long(&buffer, &left, bit_b, false);
2866 err = proc_put_char(&buffer, &left, '\n');
2872 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2874 memcpy(bitmap, tmp_bitmap,
2875 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2887 #else /* CONFIG_PROC_FS */
2889 int proc_dostring(struct ctl_table *table, int write,
2890 void __user *buffer, size_t *lenp, loff_t *ppos)
2895 int proc_dointvec(struct ctl_table *table, int write,
2896 void __user *buffer, size_t *lenp, loff_t *ppos)
2901 int proc_dointvec_minmax(struct ctl_table *table, int write,
2902 void __user *buffer, size_t *lenp, loff_t *ppos)
2907 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2908 void __user *buffer, size_t *lenp, loff_t *ppos)
2913 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2914 void __user *buffer, size_t *lenp, loff_t *ppos)
2919 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2920 void __user *buffer, size_t *lenp, loff_t *ppos)
2925 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2926 void __user *buffer, size_t *lenp, loff_t *ppos)
2931 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2932 void __user *buffer,
2933 size_t *lenp, loff_t *ppos)
2939 #endif /* CONFIG_PROC_FS */
2942 * No sense putting this after each symbol definition, twice,
2943 * exception granted :-)
2945 EXPORT_SYMBOL(proc_dointvec);
2946 EXPORT_SYMBOL(proc_dointvec_jiffies);
2947 EXPORT_SYMBOL(proc_dointvec_minmax);
2948 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2949 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2950 EXPORT_SYMBOL(proc_dostring);
2951 EXPORT_SYMBOL(proc_doulongvec_minmax);
2952 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2953 EXPORT_SYMBOL(register_sysctl_table);
2954 EXPORT_SYMBOL(register_sysctl_paths);
2955 EXPORT_SYMBOL(unregister_sysctl_table);