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/syscalls.h>
48 #include <linux/vmstat.h>
49 #include <linux/nfs_fs.h>
50 #include <linux/acpi.h>
51 #include <linux/reboot.h>
52 #include <linux/ftrace.h>
53 #include <linux/slow-work.h>
54 #include <linux/perf_event.h>
55 #include <linux/kprobes.h>
56 #include <linux/pipe_fs_i.h>
58 #include <asm/uaccess.h>
59 #include <asm/processor.h>
63 #include <asm/stacktrace.h>
66 #ifdef CONFIG_BSD_PROCESS_ACCT
67 #include <linux/acct.h>
69 #ifdef CONFIG_RT_MUTEXES
70 #include <linux/rtmutex.h>
72 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
73 #include <linux/lockdep.h>
75 #ifdef CONFIG_CHR_DEV_SG
80 #if defined(CONFIG_SYSCTL)
82 /* External variables not in a header file. */
83 extern int sysctl_overcommit_memory;
84 extern int sysctl_overcommit_ratio;
85 extern int sysctl_panic_on_oom;
86 extern int sysctl_oom_kill_allocating_task;
87 extern int sysctl_oom_dump_tasks;
88 extern int max_threads;
89 extern int core_uses_pid;
90 extern int suid_dumpable;
91 extern char core_pattern[];
92 extern unsigned int core_pipe_limit;
94 extern int min_free_kbytes;
95 extern int pid_max_min, pid_max_max;
96 extern int sysctl_drop_caches;
97 extern int percpu_pagelist_fraction;
98 extern int compat_log;
99 extern int latencytop_enabled;
100 extern int sysctl_nr_open_min, sysctl_nr_open_max;
102 extern int sysctl_nr_trim_pages;
105 extern int blk_iopoll_enabled;
108 /* Constants used for minimum and maximum */
109 #ifdef CONFIG_DETECT_SOFTLOCKUP
110 static int sixty = 60;
111 static int neg_one = -1;
115 static int __maybe_unused one = 1;
116 static int __maybe_unused two = 2;
117 static unsigned long one_ul = 1;
118 static int one_hundred = 100;
120 static int ten_thousand = 10000;
123 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
124 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
126 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
127 static int maxolduid = 65535;
128 static int minolduid;
129 static int min_percpu_pagelist_fract = 8;
131 static int ngroups_max = NGROUPS_MAX;
134 #include <asm/system.h>
137 #ifdef CONFIG_SPARC64
138 extern int sysctl_tsb_ratio;
142 extern int pwrsw_enabled;
143 extern int unaligned_enabled;
147 #ifdef CONFIG_MATHEMU
148 extern int sysctl_ieee_emulation_warnings;
150 extern int sysctl_userprocess_debug;
151 extern int spin_retry;
155 extern int no_unaligned_warning;
156 extern int unaligned_dump_stack;
159 extern struct ratelimit_state printk_ratelimit_state;
161 #ifdef CONFIG_PROC_SYSCTL
162 static int proc_do_cad_pid(struct ctl_table *table, int write,
163 void __user *buffer, size_t *lenp, loff_t *ppos);
164 static int proc_taint(struct ctl_table *table, int write,
165 void __user *buffer, size_t *lenp, loff_t *ppos);
168 #ifdef CONFIG_MAGIC_SYSRQ
169 static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
171 static int sysrq_sysctl_handler(ctl_table *table, int write,
172 void __user *buffer, size_t *lenp,
177 error = proc_dointvec(table, write, buffer, lenp, ppos);
182 sysrq_toggle_support(__sysrq_enabled);
189 static struct ctl_table root_table[];
190 static struct ctl_table_root sysctl_table_root;
191 static struct ctl_table_header root_table_header = {
193 .ctl_table = root_table,
194 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
195 .root = &sysctl_table_root,
196 .set = &sysctl_table_root.default_set,
198 static struct ctl_table_root sysctl_table_root = {
199 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
200 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
203 static struct ctl_table kern_table[];
204 static struct ctl_table vm_table[];
205 static struct ctl_table fs_table[];
206 static struct ctl_table debug_table[];
207 static struct ctl_table dev_table[];
208 extern struct ctl_table random_table[];
209 #ifdef CONFIG_INOTIFY_USER
210 extern struct ctl_table inotify_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 static struct ctl_table kern_table[] = {
268 .procname = "sched_child_runs_first",
269 .data = &sysctl_sched_child_runs_first,
270 .maxlen = sizeof(unsigned int),
272 .proc_handler = proc_dointvec,
274 #ifdef CONFIG_SCHED_DEBUG
276 .procname = "sched_min_granularity_ns",
277 .data = &sysctl_sched_min_granularity,
278 .maxlen = sizeof(unsigned int),
280 .proc_handler = sched_proc_update_handler,
281 .extra1 = &min_sched_granularity_ns,
282 .extra2 = &max_sched_granularity_ns,
285 .procname = "sched_latency_ns",
286 .data = &sysctl_sched_latency,
287 .maxlen = sizeof(unsigned int),
289 .proc_handler = sched_proc_update_handler,
290 .extra1 = &min_sched_granularity_ns,
291 .extra2 = &max_sched_granularity_ns,
294 .procname = "sched_wakeup_granularity_ns",
295 .data = &sysctl_sched_wakeup_granularity,
296 .maxlen = sizeof(unsigned int),
298 .proc_handler = sched_proc_update_handler,
299 .extra1 = &min_wakeup_granularity_ns,
300 .extra2 = &max_wakeup_granularity_ns,
303 .procname = "sched_shares_ratelimit",
304 .data = &sysctl_sched_shares_ratelimit,
305 .maxlen = sizeof(unsigned int),
307 .proc_handler = sched_proc_update_handler,
308 .extra1 = &min_sched_shares_ratelimit,
309 .extra2 = &max_sched_shares_ratelimit,
312 .procname = "sched_tunable_scaling",
313 .data = &sysctl_sched_tunable_scaling,
314 .maxlen = sizeof(enum sched_tunable_scaling),
316 .proc_handler = sched_proc_update_handler,
317 .extra1 = &min_sched_tunable_scaling,
318 .extra2 = &max_sched_tunable_scaling,
321 .procname = "sched_shares_thresh",
322 .data = &sysctl_sched_shares_thresh,
323 .maxlen = sizeof(unsigned int),
325 .proc_handler = proc_dointvec_minmax,
329 .procname = "sched_migration_cost",
330 .data = &sysctl_sched_migration_cost,
331 .maxlen = sizeof(unsigned int),
333 .proc_handler = proc_dointvec,
336 .procname = "sched_nr_migrate",
337 .data = &sysctl_sched_nr_migrate,
338 .maxlen = sizeof(unsigned int),
340 .proc_handler = proc_dointvec,
343 .procname = "sched_time_avg",
344 .data = &sysctl_sched_time_avg,
345 .maxlen = sizeof(unsigned int),
347 .proc_handler = proc_dointvec,
350 .procname = "timer_migration",
351 .data = &sysctl_timer_migration,
352 .maxlen = sizeof(unsigned int),
354 .proc_handler = proc_dointvec_minmax,
360 .procname = "sched_rt_period_us",
361 .data = &sysctl_sched_rt_period,
362 .maxlen = sizeof(unsigned int),
364 .proc_handler = sched_rt_handler,
367 .procname = "sched_rt_runtime_us",
368 .data = &sysctl_sched_rt_runtime,
369 .maxlen = sizeof(int),
371 .proc_handler = sched_rt_handler,
374 .procname = "sched_compat_yield",
375 .data = &sysctl_sched_compat_yield,
376 .maxlen = sizeof(unsigned int),
378 .proc_handler = proc_dointvec,
380 #ifdef CONFIG_PROVE_LOCKING
382 .procname = "prove_locking",
383 .data = &prove_locking,
384 .maxlen = sizeof(int),
386 .proc_handler = proc_dointvec,
389 #ifdef CONFIG_LOCK_STAT
391 .procname = "lock_stat",
393 .maxlen = sizeof(int),
395 .proc_handler = proc_dointvec,
400 .data = &panic_timeout,
401 .maxlen = sizeof(int),
403 .proc_handler = proc_dointvec,
406 .procname = "core_uses_pid",
407 .data = &core_uses_pid,
408 .maxlen = sizeof(int),
410 .proc_handler = proc_dointvec,
413 .procname = "core_pattern",
414 .data = core_pattern,
415 .maxlen = CORENAME_MAX_SIZE,
417 .proc_handler = proc_dostring,
420 .procname = "core_pipe_limit",
421 .data = &core_pipe_limit,
422 .maxlen = sizeof(unsigned int),
424 .proc_handler = proc_dointvec,
426 #ifdef CONFIG_PROC_SYSCTL
428 .procname = "tainted",
429 .maxlen = sizeof(long),
431 .proc_handler = proc_taint,
434 #ifdef CONFIG_LATENCYTOP
436 .procname = "latencytop",
437 .data = &latencytop_enabled,
438 .maxlen = sizeof(int),
440 .proc_handler = proc_dointvec,
443 #ifdef CONFIG_BLK_DEV_INITRD
445 .procname = "real-root-dev",
446 .data = &real_root_dev,
447 .maxlen = sizeof(int),
449 .proc_handler = proc_dointvec,
453 .procname = "print-fatal-signals",
454 .data = &print_fatal_signals,
455 .maxlen = sizeof(int),
457 .proc_handler = proc_dointvec,
461 .procname = "reboot-cmd",
462 .data = reboot_command,
465 .proc_handler = proc_dostring,
468 .procname = "stop-a",
469 .data = &stop_a_enabled,
470 .maxlen = sizeof (int),
472 .proc_handler = proc_dointvec,
475 .procname = "scons-poweroff",
476 .data = &scons_pwroff,
477 .maxlen = sizeof (int),
479 .proc_handler = proc_dointvec,
482 #ifdef CONFIG_SPARC64
484 .procname = "tsb-ratio",
485 .data = &sysctl_tsb_ratio,
486 .maxlen = sizeof (int),
488 .proc_handler = proc_dointvec,
493 .procname = "soft-power",
494 .data = &pwrsw_enabled,
495 .maxlen = sizeof (int),
497 .proc_handler = proc_dointvec,
500 .procname = "unaligned-trap",
501 .data = &unaligned_enabled,
502 .maxlen = sizeof (int),
504 .proc_handler = proc_dointvec,
508 .procname = "ctrl-alt-del",
510 .maxlen = sizeof(int),
512 .proc_handler = proc_dointvec,
514 #ifdef CONFIG_FUNCTION_TRACER
516 .procname = "ftrace_enabled",
517 .data = &ftrace_enabled,
518 .maxlen = sizeof(int),
520 .proc_handler = ftrace_enable_sysctl,
523 #ifdef CONFIG_STACK_TRACER
525 .procname = "stack_tracer_enabled",
526 .data = &stack_tracer_enabled,
527 .maxlen = sizeof(int),
529 .proc_handler = stack_trace_sysctl,
532 #ifdef CONFIG_TRACING
534 .procname = "ftrace_dump_on_oops",
535 .data = &ftrace_dump_on_oops,
536 .maxlen = sizeof(int),
538 .proc_handler = proc_dointvec,
541 #ifdef CONFIG_MODULES
543 .procname = "modprobe",
544 .data = &modprobe_path,
545 .maxlen = KMOD_PATH_LEN,
547 .proc_handler = proc_dostring,
550 .procname = "modules_disabled",
551 .data = &modules_disabled,
552 .maxlen = sizeof(int),
554 /* only handle a transition from default "0" to "1" */
555 .proc_handler = proc_dointvec_minmax,
560 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
562 .procname = "hotplug",
563 .data = &uevent_helper,
564 .maxlen = UEVENT_HELPER_PATH_LEN,
566 .proc_handler = proc_dostring,
569 #ifdef CONFIG_CHR_DEV_SG
571 .procname = "sg-big-buff",
572 .data = &sg_big_buff,
573 .maxlen = sizeof (int),
575 .proc_handler = proc_dointvec,
578 #ifdef CONFIG_BSD_PROCESS_ACCT
582 .maxlen = 3*sizeof(int),
584 .proc_handler = proc_dointvec,
587 #ifdef CONFIG_MAGIC_SYSRQ
590 .data = &__sysrq_enabled,
591 .maxlen = sizeof (int),
593 .proc_handler = sysrq_sysctl_handler,
596 #ifdef CONFIG_PROC_SYSCTL
598 .procname = "cad_pid",
600 .maxlen = sizeof (int),
602 .proc_handler = proc_do_cad_pid,
606 .procname = "threads-max",
607 .data = &max_threads,
608 .maxlen = sizeof(int),
610 .proc_handler = proc_dointvec,
613 .procname = "random",
615 .child = random_table,
618 .procname = "overflowuid",
619 .data = &overflowuid,
620 .maxlen = sizeof(int),
622 .proc_handler = proc_dointvec_minmax,
623 .extra1 = &minolduid,
624 .extra2 = &maxolduid,
627 .procname = "overflowgid",
628 .data = &overflowgid,
629 .maxlen = sizeof(int),
631 .proc_handler = proc_dointvec_minmax,
632 .extra1 = &minolduid,
633 .extra2 = &maxolduid,
636 #ifdef CONFIG_MATHEMU
638 .procname = "ieee_emulation_warnings",
639 .data = &sysctl_ieee_emulation_warnings,
640 .maxlen = sizeof(int),
642 .proc_handler = proc_dointvec,
646 .procname = "userprocess_debug",
647 .data = &show_unhandled_signals,
648 .maxlen = sizeof(int),
650 .proc_handler = proc_dointvec,
654 .procname = "pid_max",
656 .maxlen = sizeof (int),
658 .proc_handler = proc_dointvec_minmax,
659 .extra1 = &pid_max_min,
660 .extra2 = &pid_max_max,
663 .procname = "panic_on_oops",
664 .data = &panic_on_oops,
665 .maxlen = sizeof(int),
667 .proc_handler = proc_dointvec,
669 #if defined CONFIG_PRINTK
671 .procname = "printk",
672 .data = &console_loglevel,
673 .maxlen = 4*sizeof(int),
675 .proc_handler = proc_dointvec,
678 .procname = "printk_ratelimit",
679 .data = &printk_ratelimit_state.interval,
680 .maxlen = sizeof(int),
682 .proc_handler = proc_dointvec_jiffies,
685 .procname = "printk_ratelimit_burst",
686 .data = &printk_ratelimit_state.burst,
687 .maxlen = sizeof(int),
689 .proc_handler = proc_dointvec,
692 .procname = "printk_delay",
693 .data = &printk_delay_msec,
694 .maxlen = sizeof(int),
696 .proc_handler = proc_dointvec_minmax,
698 .extra2 = &ten_thousand,
702 .procname = "ngroups_max",
703 .data = &ngroups_max,
704 .maxlen = sizeof (int),
706 .proc_handler = proc_dointvec,
708 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
710 .procname = "unknown_nmi_panic",
711 .data = &unknown_nmi_panic,
712 .maxlen = sizeof (int),
714 .proc_handler = proc_dointvec,
717 .procname = "nmi_watchdog",
718 .data = &nmi_watchdog_enabled,
719 .maxlen = sizeof (int),
721 .proc_handler = proc_nmi_enabled,
724 #if defined(CONFIG_X86)
726 .procname = "panic_on_unrecovered_nmi",
727 .data = &panic_on_unrecovered_nmi,
728 .maxlen = sizeof(int),
730 .proc_handler = proc_dointvec,
733 .procname = "panic_on_io_nmi",
734 .data = &panic_on_io_nmi,
735 .maxlen = sizeof(int),
737 .proc_handler = proc_dointvec,
740 .procname = "bootloader_type",
741 .data = &bootloader_type,
742 .maxlen = sizeof (int),
744 .proc_handler = proc_dointvec,
747 .procname = "bootloader_version",
748 .data = &bootloader_version,
749 .maxlen = sizeof (int),
751 .proc_handler = proc_dointvec,
754 .procname = "kstack_depth_to_print",
755 .data = &kstack_depth_to_print,
756 .maxlen = sizeof(int),
758 .proc_handler = proc_dointvec,
761 .procname = "io_delay_type",
762 .data = &io_delay_type,
763 .maxlen = sizeof(int),
765 .proc_handler = proc_dointvec,
768 #if defined(CONFIG_MMU)
770 .procname = "randomize_va_space",
771 .data = &randomize_va_space,
772 .maxlen = sizeof(int),
774 .proc_handler = proc_dointvec,
777 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
779 .procname = "spin_retry",
781 .maxlen = sizeof (int),
783 .proc_handler = proc_dointvec,
786 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
788 .procname = "acpi_video_flags",
789 .data = &acpi_realmode_flags,
790 .maxlen = sizeof (unsigned long),
792 .proc_handler = proc_doulongvec_minmax,
797 .procname = "ignore-unaligned-usertrap",
798 .data = &no_unaligned_warning,
799 .maxlen = sizeof (int),
801 .proc_handler = proc_dointvec,
804 .procname = "unaligned-dump-stack",
805 .data = &unaligned_dump_stack,
806 .maxlen = sizeof (int),
808 .proc_handler = proc_dointvec,
811 #ifdef CONFIG_DETECT_SOFTLOCKUP
813 .procname = "softlockup_panic",
814 .data = &softlockup_panic,
815 .maxlen = sizeof(int),
817 .proc_handler = proc_dointvec_minmax,
822 .procname = "softlockup_thresh",
823 .data = &softlockup_thresh,
824 .maxlen = sizeof(int),
826 .proc_handler = proc_dosoftlockup_thresh,
831 #ifdef CONFIG_DETECT_HUNG_TASK
833 .procname = "hung_task_panic",
834 .data = &sysctl_hung_task_panic,
835 .maxlen = sizeof(int),
837 .proc_handler = proc_dointvec_minmax,
842 .procname = "hung_task_check_count",
843 .data = &sysctl_hung_task_check_count,
844 .maxlen = sizeof(unsigned long),
846 .proc_handler = proc_doulongvec_minmax,
849 .procname = "hung_task_timeout_secs",
850 .data = &sysctl_hung_task_timeout_secs,
851 .maxlen = sizeof(unsigned long),
853 .proc_handler = proc_dohung_task_timeout_secs,
856 .procname = "hung_task_warnings",
857 .data = &sysctl_hung_task_warnings,
858 .maxlen = sizeof(unsigned long),
860 .proc_handler = proc_doulongvec_minmax,
865 .procname = "compat-log",
867 .maxlen = sizeof (int),
869 .proc_handler = proc_dointvec,
872 #ifdef CONFIG_RT_MUTEXES
874 .procname = "max_lock_depth",
875 .data = &max_lock_depth,
876 .maxlen = sizeof(int),
878 .proc_handler = proc_dointvec,
882 .procname = "poweroff_cmd",
883 .data = &poweroff_cmd,
884 .maxlen = POWEROFF_CMD_PATH_LEN,
886 .proc_handler = proc_dostring,
892 .child = key_sysctls,
895 #ifdef CONFIG_RCU_TORTURE_TEST
897 .procname = "rcutorture_runnable",
898 .data = &rcutorture_runnable,
899 .maxlen = sizeof(int),
901 .proc_handler = proc_dointvec,
904 #ifdef CONFIG_SLOW_WORK
906 .procname = "slow-work",
908 .child = slow_work_sysctls,
911 #ifdef CONFIG_PERF_EVENTS
913 .procname = "perf_event_paranoid",
914 .data = &sysctl_perf_event_paranoid,
915 .maxlen = sizeof(sysctl_perf_event_paranoid),
917 .proc_handler = proc_dointvec,
920 .procname = "perf_event_mlock_kb",
921 .data = &sysctl_perf_event_mlock,
922 .maxlen = sizeof(sysctl_perf_event_mlock),
924 .proc_handler = proc_dointvec,
927 .procname = "perf_event_max_sample_rate",
928 .data = &sysctl_perf_event_sample_rate,
929 .maxlen = sizeof(sysctl_perf_event_sample_rate),
931 .proc_handler = proc_dointvec,
934 #ifdef CONFIG_KMEMCHECK
936 .procname = "kmemcheck",
937 .data = &kmemcheck_enabled,
938 .maxlen = sizeof(int),
940 .proc_handler = proc_dointvec,
945 .procname = "blk_iopoll",
946 .data = &blk_iopoll_enabled,
947 .maxlen = sizeof(int),
949 .proc_handler = proc_dointvec,
953 * NOTE: do not add new entries to this table unless you have read
954 * Documentation/sysctl/ctl_unnumbered.txt
959 static struct ctl_table vm_table[] = {
961 .procname = "overcommit_memory",
962 .data = &sysctl_overcommit_memory,
963 .maxlen = sizeof(sysctl_overcommit_memory),
965 .proc_handler = proc_dointvec,
968 .procname = "panic_on_oom",
969 .data = &sysctl_panic_on_oom,
970 .maxlen = sizeof(sysctl_panic_on_oom),
972 .proc_handler = proc_dointvec,
975 .procname = "oom_kill_allocating_task",
976 .data = &sysctl_oom_kill_allocating_task,
977 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
979 .proc_handler = proc_dointvec,
982 .procname = "oom_dump_tasks",
983 .data = &sysctl_oom_dump_tasks,
984 .maxlen = sizeof(sysctl_oom_dump_tasks),
986 .proc_handler = proc_dointvec,
989 .procname = "overcommit_ratio",
990 .data = &sysctl_overcommit_ratio,
991 .maxlen = sizeof(sysctl_overcommit_ratio),
993 .proc_handler = proc_dointvec,
996 .procname = "page-cluster",
997 .data = &page_cluster,
998 .maxlen = sizeof(int),
1000 .proc_handler = proc_dointvec,
1003 .procname = "dirty_background_ratio",
1004 .data = &dirty_background_ratio,
1005 .maxlen = sizeof(dirty_background_ratio),
1007 .proc_handler = dirty_background_ratio_handler,
1009 .extra2 = &one_hundred,
1012 .procname = "dirty_background_bytes",
1013 .data = &dirty_background_bytes,
1014 .maxlen = sizeof(dirty_background_bytes),
1016 .proc_handler = dirty_background_bytes_handler,
1020 .procname = "dirty_ratio",
1021 .data = &vm_dirty_ratio,
1022 .maxlen = sizeof(vm_dirty_ratio),
1024 .proc_handler = dirty_ratio_handler,
1026 .extra2 = &one_hundred,
1029 .procname = "dirty_bytes",
1030 .data = &vm_dirty_bytes,
1031 .maxlen = sizeof(vm_dirty_bytes),
1033 .proc_handler = dirty_bytes_handler,
1034 .extra1 = &dirty_bytes_min,
1037 .procname = "dirty_writeback_centisecs",
1038 .data = &dirty_writeback_interval,
1039 .maxlen = sizeof(dirty_writeback_interval),
1041 .proc_handler = dirty_writeback_centisecs_handler,
1044 .procname = "dirty_expire_centisecs",
1045 .data = &dirty_expire_interval,
1046 .maxlen = sizeof(dirty_expire_interval),
1048 .proc_handler = proc_dointvec,
1051 .procname = "nr_pdflush_threads",
1052 .data = &nr_pdflush_threads,
1053 .maxlen = sizeof nr_pdflush_threads,
1054 .mode = 0444 /* read-only*/,
1055 .proc_handler = proc_dointvec,
1058 .procname = "swappiness",
1059 .data = &vm_swappiness,
1060 .maxlen = sizeof(vm_swappiness),
1062 .proc_handler = proc_dointvec_minmax,
1064 .extra2 = &one_hundred,
1066 #ifdef CONFIG_HUGETLB_PAGE
1068 .procname = "nr_hugepages",
1070 .maxlen = sizeof(unsigned long),
1072 .proc_handler = hugetlb_sysctl_handler,
1073 .extra1 = (void *)&hugetlb_zero,
1074 .extra2 = (void *)&hugetlb_infinity,
1078 .procname = "nr_hugepages_mempolicy",
1080 .maxlen = sizeof(unsigned long),
1082 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1083 .extra1 = (void *)&hugetlb_zero,
1084 .extra2 = (void *)&hugetlb_infinity,
1088 .procname = "hugetlb_shm_group",
1089 .data = &sysctl_hugetlb_shm_group,
1090 .maxlen = sizeof(gid_t),
1092 .proc_handler = proc_dointvec,
1095 .procname = "hugepages_treat_as_movable",
1096 .data = &hugepages_treat_as_movable,
1097 .maxlen = sizeof(int),
1099 .proc_handler = hugetlb_treat_movable_handler,
1102 .procname = "nr_overcommit_hugepages",
1104 .maxlen = sizeof(unsigned long),
1106 .proc_handler = hugetlb_overcommit_handler,
1107 .extra1 = (void *)&hugetlb_zero,
1108 .extra2 = (void *)&hugetlb_infinity,
1112 .procname = "lowmem_reserve_ratio",
1113 .data = &sysctl_lowmem_reserve_ratio,
1114 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1116 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1119 .procname = "drop_caches",
1120 .data = &sysctl_drop_caches,
1121 .maxlen = sizeof(int),
1123 .proc_handler = drop_caches_sysctl_handler,
1125 #ifdef CONFIG_COMPACTION
1127 .procname = "compact_memory",
1128 .data = &sysctl_compact_memory,
1129 .maxlen = sizeof(int),
1131 .proc_handler = sysctl_compaction_handler,
1133 #endif /* CONFIG_COMPACTION */
1135 .procname = "min_free_kbytes",
1136 .data = &min_free_kbytes,
1137 .maxlen = sizeof(min_free_kbytes),
1139 .proc_handler = min_free_kbytes_sysctl_handler,
1143 .procname = "percpu_pagelist_fraction",
1144 .data = &percpu_pagelist_fraction,
1145 .maxlen = sizeof(percpu_pagelist_fraction),
1147 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1148 .extra1 = &min_percpu_pagelist_fract,
1152 .procname = "max_map_count",
1153 .data = &sysctl_max_map_count,
1154 .maxlen = sizeof(sysctl_max_map_count),
1156 .proc_handler = proc_dointvec_minmax,
1161 .procname = "nr_trim_pages",
1162 .data = &sysctl_nr_trim_pages,
1163 .maxlen = sizeof(sysctl_nr_trim_pages),
1165 .proc_handler = proc_dointvec_minmax,
1170 .procname = "laptop_mode",
1171 .data = &laptop_mode,
1172 .maxlen = sizeof(laptop_mode),
1174 .proc_handler = proc_dointvec_jiffies,
1177 .procname = "block_dump",
1178 .data = &block_dump,
1179 .maxlen = sizeof(block_dump),
1181 .proc_handler = proc_dointvec,
1185 .procname = "vfs_cache_pressure",
1186 .data = &sysctl_vfs_cache_pressure,
1187 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1189 .proc_handler = proc_dointvec,
1192 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1194 .procname = "legacy_va_layout",
1195 .data = &sysctl_legacy_va_layout,
1196 .maxlen = sizeof(sysctl_legacy_va_layout),
1198 .proc_handler = proc_dointvec,
1204 .procname = "zone_reclaim_mode",
1205 .data = &zone_reclaim_mode,
1206 .maxlen = sizeof(zone_reclaim_mode),
1208 .proc_handler = proc_dointvec,
1212 .procname = "min_unmapped_ratio",
1213 .data = &sysctl_min_unmapped_ratio,
1214 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1216 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1218 .extra2 = &one_hundred,
1221 .procname = "min_slab_ratio",
1222 .data = &sysctl_min_slab_ratio,
1223 .maxlen = sizeof(sysctl_min_slab_ratio),
1225 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1227 .extra2 = &one_hundred,
1232 .procname = "stat_interval",
1233 .data = &sysctl_stat_interval,
1234 .maxlen = sizeof(sysctl_stat_interval),
1236 .proc_handler = proc_dointvec_jiffies,
1241 .procname = "mmap_min_addr",
1242 .data = &dac_mmap_min_addr,
1243 .maxlen = sizeof(unsigned long),
1245 .proc_handler = mmap_min_addr_handler,
1250 .procname = "numa_zonelist_order",
1251 .data = &numa_zonelist_order,
1252 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1254 .proc_handler = numa_zonelist_order_handler,
1257 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1258 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1260 .procname = "vdso_enabled",
1261 .data = &vdso_enabled,
1262 .maxlen = sizeof(vdso_enabled),
1264 .proc_handler = proc_dointvec,
1268 #ifdef CONFIG_HIGHMEM
1270 .procname = "highmem_is_dirtyable",
1271 .data = &vm_highmem_is_dirtyable,
1272 .maxlen = sizeof(vm_highmem_is_dirtyable),
1274 .proc_handler = proc_dointvec_minmax,
1280 .procname = "scan_unevictable_pages",
1281 .data = &scan_unevictable_pages,
1282 .maxlen = sizeof(scan_unevictable_pages),
1284 .proc_handler = scan_unevictable_handler,
1286 #ifdef CONFIG_MEMORY_FAILURE
1288 .procname = "memory_failure_early_kill",
1289 .data = &sysctl_memory_failure_early_kill,
1290 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1292 .proc_handler = proc_dointvec_minmax,
1297 .procname = "memory_failure_recovery",
1298 .data = &sysctl_memory_failure_recovery,
1299 .maxlen = sizeof(sysctl_memory_failure_recovery),
1301 .proc_handler = proc_dointvec_minmax,
1308 * NOTE: do not add new entries to this table unless you have read
1309 * Documentation/sysctl/ctl_unnumbered.txt
1314 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1315 static struct ctl_table binfmt_misc_table[] = {
1320 static struct ctl_table fs_table[] = {
1322 .procname = "inode-nr",
1323 .data = &inodes_stat,
1324 .maxlen = 2*sizeof(int),
1326 .proc_handler = proc_dointvec,
1329 .procname = "inode-state",
1330 .data = &inodes_stat,
1331 .maxlen = 7*sizeof(int),
1333 .proc_handler = proc_dointvec,
1336 .procname = "file-nr",
1337 .data = &files_stat,
1338 .maxlen = 3*sizeof(int),
1340 .proc_handler = proc_nr_files,
1343 .procname = "file-max",
1344 .data = &files_stat.max_files,
1345 .maxlen = sizeof(int),
1347 .proc_handler = proc_dointvec,
1350 .procname = "nr_open",
1351 .data = &sysctl_nr_open,
1352 .maxlen = sizeof(int),
1354 .proc_handler = proc_dointvec_minmax,
1355 .extra1 = &sysctl_nr_open_min,
1356 .extra2 = &sysctl_nr_open_max,
1359 .procname = "dentry-state",
1360 .data = &dentry_stat,
1361 .maxlen = 6*sizeof(int),
1363 .proc_handler = proc_dointvec,
1366 .procname = "overflowuid",
1367 .data = &fs_overflowuid,
1368 .maxlen = sizeof(int),
1370 .proc_handler = proc_dointvec_minmax,
1371 .extra1 = &minolduid,
1372 .extra2 = &maxolduid,
1375 .procname = "overflowgid",
1376 .data = &fs_overflowgid,
1377 .maxlen = sizeof(int),
1379 .proc_handler = proc_dointvec_minmax,
1380 .extra1 = &minolduid,
1381 .extra2 = &maxolduid,
1383 #ifdef CONFIG_FILE_LOCKING
1385 .procname = "leases-enable",
1386 .data = &leases_enable,
1387 .maxlen = sizeof(int),
1389 .proc_handler = proc_dointvec,
1392 #ifdef CONFIG_DNOTIFY
1394 .procname = "dir-notify-enable",
1395 .data = &dir_notify_enable,
1396 .maxlen = sizeof(int),
1398 .proc_handler = proc_dointvec,
1402 #ifdef CONFIG_FILE_LOCKING
1404 .procname = "lease-break-time",
1405 .data = &lease_break_time,
1406 .maxlen = sizeof(int),
1408 .proc_handler = proc_dointvec,
1413 .procname = "aio-nr",
1415 .maxlen = sizeof(aio_nr),
1417 .proc_handler = proc_doulongvec_minmax,
1420 .procname = "aio-max-nr",
1421 .data = &aio_max_nr,
1422 .maxlen = sizeof(aio_max_nr),
1424 .proc_handler = proc_doulongvec_minmax,
1426 #endif /* CONFIG_AIO */
1427 #ifdef CONFIG_INOTIFY_USER
1429 .procname = "inotify",
1431 .child = inotify_table,
1436 .procname = "epoll",
1438 .child = epoll_table,
1443 .procname = "suid_dumpable",
1444 .data = &suid_dumpable,
1445 .maxlen = sizeof(int),
1447 .proc_handler = proc_dointvec_minmax,
1451 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1453 .procname = "binfmt_misc",
1455 .child = binfmt_misc_table,
1459 .procname = "pipe-max-pages",
1460 .data = &pipe_max_pages,
1461 .maxlen = sizeof(int),
1463 .proc_handler = &proc_dointvec_minmax,
1467 * NOTE: do not add new entries to this table unless you have read
1468 * Documentation/sysctl/ctl_unnumbered.txt
1473 static struct ctl_table debug_table[] = {
1474 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1475 defined(CONFIG_S390)
1477 .procname = "exception-trace",
1478 .data = &show_unhandled_signals,
1479 .maxlen = sizeof(int),
1481 .proc_handler = proc_dointvec
1484 #if defined(CONFIG_OPTPROBES)
1486 .procname = "kprobes-optimization",
1487 .data = &sysctl_kprobes_optimization,
1488 .maxlen = sizeof(int),
1490 .proc_handler = proc_kprobes_optimization_handler,
1498 static struct ctl_table dev_table[] = {
1502 static DEFINE_SPINLOCK(sysctl_lock);
1504 /* called under sysctl_lock */
1505 static int use_table(struct ctl_table_header *p)
1507 if (unlikely(p->unregistering))
1513 /* called under sysctl_lock */
1514 static void unuse_table(struct ctl_table_header *p)
1517 if (unlikely(p->unregistering))
1518 complete(p->unregistering);
1521 /* called under sysctl_lock, will reacquire if has to wait */
1522 static void start_unregistering(struct ctl_table_header *p)
1525 * if p->used is 0, nobody will ever touch that entry again;
1526 * we'll eliminate all paths to it before dropping sysctl_lock
1528 if (unlikely(p->used)) {
1529 struct completion wait;
1530 init_completion(&wait);
1531 p->unregistering = &wait;
1532 spin_unlock(&sysctl_lock);
1533 wait_for_completion(&wait);
1534 spin_lock(&sysctl_lock);
1536 /* anything non-NULL; we'll never dereference it */
1537 p->unregistering = ERR_PTR(-EINVAL);
1540 * do not remove from the list until nobody holds it; walking the
1541 * list in do_sysctl() relies on that.
1543 list_del_init(&p->ctl_entry);
1546 void sysctl_head_get(struct ctl_table_header *head)
1548 spin_lock(&sysctl_lock);
1550 spin_unlock(&sysctl_lock);
1553 void sysctl_head_put(struct ctl_table_header *head)
1555 spin_lock(&sysctl_lock);
1558 spin_unlock(&sysctl_lock);
1561 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1565 spin_lock(&sysctl_lock);
1566 if (!use_table(head))
1567 head = ERR_PTR(-ENOENT);
1568 spin_unlock(&sysctl_lock);
1572 void sysctl_head_finish(struct ctl_table_header *head)
1576 spin_lock(&sysctl_lock);
1578 spin_unlock(&sysctl_lock);
1581 static struct ctl_table_set *
1582 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1584 struct ctl_table_set *set = &root->default_set;
1586 set = root->lookup(root, namespaces);
1590 static struct list_head *
1591 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1593 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1597 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1598 struct ctl_table_header *prev)
1600 struct ctl_table_root *root;
1601 struct list_head *header_list;
1602 struct ctl_table_header *head;
1603 struct list_head *tmp;
1605 spin_lock(&sysctl_lock);
1608 tmp = &prev->ctl_entry;
1612 tmp = &root_table_header.ctl_entry;
1614 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1616 if (!use_table(head))
1618 spin_unlock(&sysctl_lock);
1623 header_list = lookup_header_list(root, namespaces);
1624 if (tmp != header_list)
1628 root = list_entry(root->root_list.next,
1629 struct ctl_table_root, root_list);
1630 if (root == &sysctl_table_root)
1632 header_list = lookup_header_list(root, namespaces);
1633 } while (list_empty(header_list));
1634 tmp = header_list->next;
1637 spin_unlock(&sysctl_lock);
1641 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1643 return __sysctl_head_next(current->nsproxy, prev);
1646 void register_sysctl_root(struct ctl_table_root *root)
1648 spin_lock(&sysctl_lock);
1649 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1650 spin_unlock(&sysctl_lock);
1654 * sysctl_perm does NOT grant the superuser all rights automatically, because
1655 * some sysctl variables are readonly even to root.
1658 static int test_perm(int mode, int op)
1660 if (!current_euid())
1662 else if (in_egroup_p(0))
1664 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1669 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1674 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1678 if (root->permissions)
1679 mode = root->permissions(root, current->nsproxy, table);
1683 return test_perm(mode, op);
1686 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1688 for (; table->procname; table++) {
1689 table->parent = parent;
1691 sysctl_set_parent(table, table->child);
1695 static __init int sysctl_init(void)
1697 sysctl_set_parent(NULL, root_table);
1698 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1701 err = sysctl_check_table(current->nsproxy, root_table);
1707 core_initcall(sysctl_init);
1709 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1710 struct ctl_table *table)
1712 struct ctl_table *p;
1713 const char *s = branch->procname;
1715 /* branch should have named subdirectory as its first element */
1716 if (!s || !branch->child)
1719 /* ... and nothing else */
1720 if (branch[1].procname)
1723 /* table should contain subdirectory with the same name */
1724 for (p = table; p->procname; p++) {
1727 if (p->procname && strcmp(p->procname, s) == 0)
1733 /* see if attaching q to p would be an improvement */
1734 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1736 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1737 struct ctl_table *next;
1739 int not_in_parent = !p->attached_by;
1741 while ((next = is_branch_in(by, to)) != NULL) {
1742 if (by == q->attached_by)
1744 if (to == p->attached_by)
1750 if (is_better && not_in_parent) {
1751 q->attached_by = by;
1752 q->attached_to = to;
1758 * __register_sysctl_paths - register a sysctl hierarchy
1759 * @root: List of sysctl headers to register on
1760 * @namespaces: Data to compute which lists of sysctl entries are visible
1761 * @path: The path to the directory the sysctl table is in.
1762 * @table: the top-level table structure
1764 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1765 * array. A completely 0 filled entry terminates the table.
1767 * The members of the &struct ctl_table structure are used as follows:
1769 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1770 * enter a sysctl file
1772 * data - a pointer to data for use by proc_handler
1774 * maxlen - the maximum size in bytes of the data
1776 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1778 * child - a pointer to the child sysctl table if this entry is a directory, or
1781 * proc_handler - the text handler routine (described below)
1783 * de - for internal use by the sysctl routines
1785 * extra1, extra2 - extra pointers usable by the proc handler routines
1787 * Leaf nodes in the sysctl tree will be represented by a single file
1788 * under /proc; non-leaf nodes will be represented by directories.
1790 * sysctl(2) can automatically manage read and write requests through
1791 * the sysctl table. The data and maxlen fields of the ctl_table
1792 * struct enable minimal validation of the values being written to be
1793 * performed, and the mode field allows minimal authentication.
1795 * There must be a proc_handler routine for any terminal nodes
1796 * mirrored under /proc/sys (non-terminals are handled by a built-in
1797 * directory handler). Several default handlers are available to
1798 * cover common cases -
1800 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1801 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1802 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1804 * It is the handler's job to read the input buffer from user memory
1805 * and process it. The handler should return 0 on success.
1807 * This routine returns %NULL on a failure to register, and a pointer
1808 * to the table header on success.
1810 struct ctl_table_header *__register_sysctl_paths(
1811 struct ctl_table_root *root,
1812 struct nsproxy *namespaces,
1813 const struct ctl_path *path, struct ctl_table *table)
1815 struct ctl_table_header *header;
1816 struct ctl_table *new, **prevp;
1817 unsigned int n, npath;
1818 struct ctl_table_set *set;
1820 /* Count the path components */
1821 for (npath = 0; path[npath].procname; ++npath)
1825 * For each path component, allocate a 2-element ctl_table array.
1826 * The first array element will be filled with the sysctl entry
1827 * for this, the second will be the sentinel (procname == 0).
1829 * We allocate everything in one go so that we don't have to
1830 * worry about freeing additional memory in unregister_sysctl_table.
1832 header = kzalloc(sizeof(struct ctl_table_header) +
1833 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1837 new = (struct ctl_table *) (header + 1);
1839 /* Now connect the dots */
1840 prevp = &header->ctl_table;
1841 for (n = 0; n < npath; ++n, ++path) {
1842 /* Copy the procname */
1843 new->procname = path->procname;
1847 prevp = &new->child;
1852 header->ctl_table_arg = table;
1854 INIT_LIST_HEAD(&header->ctl_entry);
1856 header->unregistering = NULL;
1857 header->root = root;
1858 sysctl_set_parent(NULL, header->ctl_table);
1860 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1861 if (sysctl_check_table(namespaces, header->ctl_table)) {
1866 spin_lock(&sysctl_lock);
1867 header->set = lookup_header_set(root, namespaces);
1868 header->attached_by = header->ctl_table;
1869 header->attached_to = root_table;
1870 header->parent = &root_table_header;
1871 for (set = header->set; set; set = set->parent) {
1872 struct ctl_table_header *p;
1873 list_for_each_entry(p, &set->list, ctl_entry) {
1874 if (p->unregistering)
1876 try_attach(p, header);
1879 header->parent->count++;
1880 list_add_tail(&header->ctl_entry, &header->set->list);
1881 spin_unlock(&sysctl_lock);
1887 * register_sysctl_table_path - register a sysctl table hierarchy
1888 * @path: The path to the directory the sysctl table is in.
1889 * @table: the top-level table structure
1891 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1892 * array. A completely 0 filled entry terminates the table.
1894 * See __register_sysctl_paths for more details.
1896 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1897 struct ctl_table *table)
1899 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1904 * register_sysctl_table - register a sysctl table hierarchy
1905 * @table: the top-level table structure
1907 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1908 * array. A completely 0 filled entry terminates the table.
1910 * See register_sysctl_paths for more details.
1912 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1914 static const struct ctl_path null_path[] = { {} };
1916 return register_sysctl_paths(null_path, table);
1920 * unregister_sysctl_table - unregister a sysctl table hierarchy
1921 * @header: the header returned from register_sysctl_table
1923 * Unregisters the sysctl table and all children. proc entries may not
1924 * actually be removed until they are no longer used by anyone.
1926 void unregister_sysctl_table(struct ctl_table_header * header)
1933 spin_lock(&sysctl_lock);
1934 start_unregistering(header);
1935 if (!--header->parent->count) {
1937 kfree(header->parent);
1939 if (!--header->count)
1941 spin_unlock(&sysctl_lock);
1944 int sysctl_is_seen(struct ctl_table_header *p)
1946 struct ctl_table_set *set = p->set;
1948 spin_lock(&sysctl_lock);
1949 if (p->unregistering)
1951 else if (!set->is_seen)
1954 res = set->is_seen(set);
1955 spin_unlock(&sysctl_lock);
1959 void setup_sysctl_set(struct ctl_table_set *p,
1960 struct ctl_table_set *parent,
1961 int (*is_seen)(struct ctl_table_set *))
1963 INIT_LIST_HEAD(&p->list);
1964 p->parent = parent ? parent : &sysctl_table_root.default_set;
1965 p->is_seen = is_seen;
1968 #else /* !CONFIG_SYSCTL */
1969 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1974 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1975 struct ctl_table *table)
1980 void unregister_sysctl_table(struct ctl_table_header * table)
1984 void setup_sysctl_set(struct ctl_table_set *p,
1985 struct ctl_table_set *parent,
1986 int (*is_seen)(struct ctl_table_set *))
1990 void sysctl_head_put(struct ctl_table_header *head)
1994 #endif /* CONFIG_SYSCTL */
2000 #ifdef CONFIG_PROC_SYSCTL
2002 static int _proc_do_string(void* data, int maxlen, int write,
2003 void __user *buffer,
2004 size_t *lenp, loff_t *ppos)
2010 if (!data || !maxlen || !*lenp) {
2018 while (len < *lenp) {
2019 if (get_user(c, p++))
2021 if (c == 0 || c == '\n')
2027 if(copy_from_user(data, buffer, len))
2029 ((char *) data)[len] = 0;
2047 if(copy_to_user(buffer, data, len))
2050 if(put_user('\n', ((char __user *) buffer) + len))
2061 * proc_dostring - read a string sysctl
2062 * @table: the sysctl table
2063 * @write: %TRUE if this is a write to the sysctl file
2064 * @buffer: the user buffer
2065 * @lenp: the size of the user buffer
2066 * @ppos: file position
2068 * Reads/writes a string from/to the user buffer. If the kernel
2069 * buffer provided is not large enough to hold the string, the
2070 * string is truncated. The copied string is %NULL-terminated.
2071 * If the string is being read by the user process, it is copied
2072 * and a newline '\n' is added. It is truncated if the buffer is
2075 * Returns 0 on success.
2077 int proc_dostring(struct ctl_table *table, int write,
2078 void __user *buffer, size_t *lenp, loff_t *ppos)
2080 return _proc_do_string(table->data, table->maxlen, write,
2081 buffer, lenp, ppos);
2084 static size_t proc_skip_spaces(char **buf)
2087 char *tmp = skip_spaces(*buf);
2093 static void proc_skip_char(char **buf, size_t *size, const char v)
2103 #define TMPBUFLEN 22
2105 * proc_get_long - reads an ASCII formatted integer from a user buffer
2107 * @buf: a kernel buffer
2108 * @size: size of the kernel buffer
2109 * @val: this is where the number will be stored
2110 * @neg: set to %TRUE if number is negative
2111 * @perm_tr: a vector which contains the allowed trailers
2112 * @perm_tr_len: size of the perm_tr vector
2113 * @tr: pointer to store the trailer character
2115 * In case of success %0 is returned and @buf and @size are updated with
2116 * the amount of bytes read. If @tr is non-NULL and a trailing
2117 * character exists (size is non-zero after returning from this
2118 * function), @tr is updated with the trailing character.
2120 static int proc_get_long(char **buf, size_t *size,
2121 unsigned long *val, bool *neg,
2122 const char *perm_tr, unsigned perm_tr_len, char *tr)
2125 char *p, tmp[TMPBUFLEN];
2131 if (len > TMPBUFLEN - 1)
2132 len = TMPBUFLEN - 1;
2134 memcpy(tmp, *buf, len);
2138 if (*p == '-' && *size > 1) {
2146 *val = simple_strtoul(p, &p, 0);
2150 /* We don't know if the next char is whitespace thus we may accept
2151 * invalid integers (e.g. 1234...a) or two integers instead of one
2152 * (e.g. 123...1). So lets not allow such large numbers. */
2153 if (len == TMPBUFLEN - 1)
2156 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2159 if (tr && (len < *size))
2169 * proc_put_long - converts an integer to a decimal ASCII formatted string
2171 * @buf: the user buffer
2172 * @size: the size of the user buffer
2173 * @val: the integer to be converted
2174 * @neg: sign of the number, %TRUE for negative
2176 * In case of success %0 is returned and @buf and @size are updated with
2177 * the amount of bytes written.
2179 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2183 char tmp[TMPBUFLEN], *p = tmp;
2185 sprintf(p, "%s%lu", neg ? "-" : "", val);
2189 if (copy_to_user(*buf, tmp, len))
2197 static int proc_put_char(void __user **buf, size_t *size, char c)
2200 char __user **buffer = (char __user **)buf;
2201 if (put_user(c, *buffer))
2203 (*size)--, (*buffer)++;
2209 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2211 int write, void *data)
2214 *valp = *negp ? -*lvalp : *lvalp;
2219 *lvalp = (unsigned long)-val;
2222 *lvalp = (unsigned long)val;
2228 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2230 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2231 int write, void __user *buffer,
2232 size_t *lenp, loff_t *ppos,
2233 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2234 int write, void *data),
2237 int *i, vleft, first = 1, err = 0;
2238 unsigned long page = 0;
2242 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2247 i = (int *) tbl_data;
2248 vleft = table->maxlen / sizeof(*i);
2252 conv = do_proc_dointvec_conv;
2255 if (left > PAGE_SIZE - 1)
2256 left = PAGE_SIZE - 1;
2257 page = __get_free_page(GFP_TEMPORARY);
2258 kbuf = (char *) page;
2261 if (copy_from_user(kbuf, buffer, left)) {
2268 for (; left && vleft--; i++, first=0) {
2273 left -= proc_skip_spaces(&kbuf);
2275 err = proc_get_long(&kbuf, &left, &lval, &neg,
2277 sizeof(proc_wspace_sep), NULL);
2280 if (conv(&neg, &lval, i, 1, data)) {
2285 if (conv(&neg, &lval, i, 0, data)) {
2290 err = proc_put_char(&buffer, &left, '\t');
2293 err = proc_put_long(&buffer, &left, lval, neg);
2299 if (!write && !first && left && !err)
2300 err = proc_put_char(&buffer, &left, '\n');
2302 left -= proc_skip_spaces(&kbuf);
2307 return err ? : -EINVAL;
2314 static int do_proc_dointvec(struct ctl_table *table, int write,
2315 void __user *buffer, size_t *lenp, loff_t *ppos,
2316 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2317 int write, void *data),
2320 return __do_proc_dointvec(table->data, table, write,
2321 buffer, lenp, ppos, conv, data);
2325 * proc_dointvec - read a vector of integers
2326 * @table: the sysctl table
2327 * @write: %TRUE if this is a write to the sysctl file
2328 * @buffer: the user buffer
2329 * @lenp: the size of the user buffer
2330 * @ppos: file position
2332 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2333 * values from/to the user buffer, treated as an ASCII string.
2335 * Returns 0 on success.
2337 int proc_dointvec(struct ctl_table *table, int write,
2338 void __user *buffer, size_t *lenp, loff_t *ppos)
2340 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2345 * Taint values can only be increased
2346 * This means we can safely use a temporary.
2348 static int proc_taint(struct ctl_table *table, int write,
2349 void __user *buffer, size_t *lenp, loff_t *ppos)
2352 unsigned long tmptaint = get_taint();
2355 if (write && !capable(CAP_SYS_ADMIN))
2360 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2366 * Poor man's atomic or. Not worth adding a primitive
2367 * to everyone's atomic.h for this
2370 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2371 if ((tmptaint >> i) & 1)
2379 struct do_proc_dointvec_minmax_conv_param {
2384 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2386 int write, void *data)
2388 struct do_proc_dointvec_minmax_conv_param *param = data;
2390 int val = *negp ? -*lvalp : *lvalp;
2391 if ((param->min && *param->min > val) ||
2392 (param->max && *param->max < val))
2399 *lvalp = (unsigned long)-val;
2402 *lvalp = (unsigned long)val;
2409 * proc_dointvec_minmax - read a vector of integers with min/max values
2410 * @table: the sysctl table
2411 * @write: %TRUE if this is a write to the sysctl file
2412 * @buffer: the user buffer
2413 * @lenp: the size of the user buffer
2414 * @ppos: file position
2416 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2417 * values from/to the user buffer, treated as an ASCII string.
2419 * This routine will ensure the values are within the range specified by
2420 * table->extra1 (min) and table->extra2 (max).
2422 * Returns 0 on success.
2424 int proc_dointvec_minmax(struct ctl_table *table, int write,
2425 void __user *buffer, size_t *lenp, loff_t *ppos)
2427 struct do_proc_dointvec_minmax_conv_param param = {
2428 .min = (int *) table->extra1,
2429 .max = (int *) table->extra2,
2431 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2432 do_proc_dointvec_minmax_conv, ¶m);
2435 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2436 void __user *buffer,
2437 size_t *lenp, loff_t *ppos,
2438 unsigned long convmul,
2439 unsigned long convdiv)
2441 unsigned long *i, *min, *max;
2442 int vleft, first = 1, err = 0;
2443 unsigned long page = 0;
2447 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2452 i = (unsigned long *) data;
2453 min = (unsigned long *) table->extra1;
2454 max = (unsigned long *) table->extra2;
2455 vleft = table->maxlen / sizeof(unsigned long);
2459 if (left > PAGE_SIZE - 1)
2460 left = PAGE_SIZE - 1;
2461 page = __get_free_page(GFP_TEMPORARY);
2462 kbuf = (char *) page;
2465 if (copy_from_user(kbuf, buffer, left)) {
2472 for (; left && vleft--; i++, min++, max++, first=0) {
2478 left -= proc_skip_spaces(&kbuf);
2480 err = proc_get_long(&kbuf, &left, &val, &neg,
2482 sizeof(proc_wspace_sep), NULL);
2487 if ((min && val < *min) || (max && val > *max))
2491 val = convdiv * (*i) / convmul;
2493 err = proc_put_char(&buffer, &left, '\t');
2494 err = proc_put_long(&buffer, &left, val, false);
2500 if (!write && !first && left && !err)
2501 err = proc_put_char(&buffer, &left, '\n');
2503 left -= proc_skip_spaces(&kbuf);
2508 return err ? : -EINVAL;
2515 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2516 void __user *buffer,
2517 size_t *lenp, loff_t *ppos,
2518 unsigned long convmul,
2519 unsigned long convdiv)
2521 return __do_proc_doulongvec_minmax(table->data, table, write,
2522 buffer, lenp, ppos, convmul, convdiv);
2526 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2527 * @table: the sysctl table
2528 * @write: %TRUE if this is a write to the sysctl file
2529 * @buffer: the user buffer
2530 * @lenp: the size of the user buffer
2531 * @ppos: file position
2533 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2534 * values from/to the user buffer, treated as an ASCII string.
2536 * This routine will ensure the values are within the range specified by
2537 * table->extra1 (min) and table->extra2 (max).
2539 * Returns 0 on success.
2541 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2542 void __user *buffer, size_t *lenp, loff_t *ppos)
2544 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2548 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2549 * @table: the sysctl table
2550 * @write: %TRUE if this is a write to the sysctl file
2551 * @buffer: the user buffer
2552 * @lenp: the size of the user buffer
2553 * @ppos: file position
2555 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2556 * values from/to the user buffer, treated as an ASCII string. The values
2557 * are treated as milliseconds, and converted to jiffies when they are stored.
2559 * This routine will ensure the values are within the range specified by
2560 * table->extra1 (min) and table->extra2 (max).
2562 * Returns 0 on success.
2564 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2565 void __user *buffer,
2566 size_t *lenp, loff_t *ppos)
2568 return do_proc_doulongvec_minmax(table, write, buffer,
2569 lenp, ppos, HZ, 1000l);
2573 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2575 int write, void *data)
2578 if (*lvalp > LONG_MAX / HZ)
2580 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2586 lval = (unsigned long)-val;
2589 lval = (unsigned long)val;
2596 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2598 int write, void *data)
2601 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2603 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2609 lval = (unsigned long)-val;
2612 lval = (unsigned long)val;
2614 *lvalp = jiffies_to_clock_t(lval);
2619 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2621 int write, void *data)
2624 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2630 lval = (unsigned long)-val;
2633 lval = (unsigned long)val;
2635 *lvalp = jiffies_to_msecs(lval);
2641 * proc_dointvec_jiffies - read a vector of integers as seconds
2642 * @table: the sysctl table
2643 * @write: %TRUE if this is a write to the sysctl file
2644 * @buffer: the user buffer
2645 * @lenp: the size of the user buffer
2646 * @ppos: file position
2648 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2649 * values from/to the user buffer, treated as an ASCII string.
2650 * The values read are assumed to be in seconds, and are converted into
2653 * Returns 0 on success.
2655 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2656 void __user *buffer, size_t *lenp, loff_t *ppos)
2658 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2659 do_proc_dointvec_jiffies_conv,NULL);
2663 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2664 * @table: the sysctl table
2665 * @write: %TRUE if this is a write to the sysctl file
2666 * @buffer: the user buffer
2667 * @lenp: the size of the user buffer
2668 * @ppos: pointer to the file position
2670 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2671 * values from/to the user buffer, treated as an ASCII string.
2672 * The values read are assumed to be in 1/USER_HZ seconds, and
2673 * are converted into jiffies.
2675 * Returns 0 on success.
2677 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2678 void __user *buffer, size_t *lenp, loff_t *ppos)
2680 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2681 do_proc_dointvec_userhz_jiffies_conv,NULL);
2685 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2686 * @table: the sysctl table
2687 * @write: %TRUE if this is a write to the sysctl file
2688 * @buffer: the user buffer
2689 * @lenp: the size of the user buffer
2690 * @ppos: file position
2691 * @ppos: the current position in the file
2693 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2694 * values from/to the user buffer, treated as an ASCII string.
2695 * The values read are assumed to be in 1/1000 seconds, and
2696 * are converted into jiffies.
2698 * Returns 0 on success.
2700 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2701 void __user *buffer, size_t *lenp, loff_t *ppos)
2703 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2704 do_proc_dointvec_ms_jiffies_conv, NULL);
2707 static int proc_do_cad_pid(struct ctl_table *table, int write,
2708 void __user *buffer, size_t *lenp, loff_t *ppos)
2710 struct pid *new_pid;
2714 tmp = pid_vnr(cad_pid);
2716 r = __do_proc_dointvec(&tmp, table, write, buffer,
2717 lenp, ppos, NULL, NULL);
2721 new_pid = find_get_pid(tmp);
2725 put_pid(xchg(&cad_pid, new_pid));
2730 * proc_do_large_bitmap - read/write from/to a large bitmap
2731 * @table: the sysctl table
2732 * @write: %TRUE if this is a write to the sysctl file
2733 * @buffer: the user buffer
2734 * @lenp: the size of the user buffer
2735 * @ppos: file position
2737 * The bitmap is stored at table->data and the bitmap length (in bits)
2740 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2741 * large bitmaps may be represented in a compact manner. Writing into
2742 * the file will clear the bitmap then update it with the given input.
2744 * Returns 0 on success.
2746 int proc_do_large_bitmap(struct ctl_table *table, int write,
2747 void __user *buffer, size_t *lenp, loff_t *ppos)
2751 size_t left = *lenp;
2752 unsigned long bitmap_len = table->maxlen;
2753 unsigned long *bitmap = (unsigned long *) table->data;
2754 unsigned long *tmp_bitmap = NULL;
2755 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2757 if (!bitmap_len || !left || (*ppos && !write)) {
2763 unsigned long page = 0;
2766 if (left > PAGE_SIZE - 1)
2767 left = PAGE_SIZE - 1;
2769 page = __get_free_page(GFP_TEMPORARY);
2770 kbuf = (char *) page;
2773 if (copy_from_user(kbuf, buffer, left)) {
2779 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2785 proc_skip_char(&kbuf, &left, '\n');
2786 while (!err && left) {
2787 unsigned long val_a, val_b;
2790 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2794 if (val_a >= bitmap_len || neg) {
2806 err = proc_get_long(&kbuf, &left, &val_b,
2807 &neg, tr_b, sizeof(tr_b),
2811 if (val_b >= bitmap_len || neg ||
2822 while (val_a <= val_b)
2823 set_bit(val_a++, tmp_bitmap);
2826 proc_skip_char(&kbuf, &left, '\n');
2830 unsigned long bit_a, bit_b = 0;
2833 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2834 if (bit_a >= bitmap_len)
2836 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2840 err = proc_put_char(&buffer, &left, ',');
2844 err = proc_put_long(&buffer, &left, bit_a, false);
2847 if (bit_a != bit_b) {
2848 err = proc_put_char(&buffer, &left, '-');
2851 err = proc_put_long(&buffer, &left, bit_b, false);
2859 err = proc_put_char(&buffer, &left, '\n');
2865 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2867 memcpy(bitmap, tmp_bitmap,
2868 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2880 #else /* CONFIG_PROC_FS */
2882 int proc_dostring(struct ctl_table *table, int write,
2883 void __user *buffer, size_t *lenp, loff_t *ppos)
2888 int proc_dointvec(struct ctl_table *table, int write,
2889 void __user *buffer, size_t *lenp, loff_t *ppos)
2894 int proc_dointvec_minmax(struct ctl_table *table, int write,
2895 void __user *buffer, size_t *lenp, loff_t *ppos)
2900 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2901 void __user *buffer, size_t *lenp, loff_t *ppos)
2906 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2907 void __user *buffer, size_t *lenp, loff_t *ppos)
2912 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2913 void __user *buffer, size_t *lenp, loff_t *ppos)
2918 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2919 void __user *buffer, size_t *lenp, loff_t *ppos)
2924 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2925 void __user *buffer,
2926 size_t *lenp, loff_t *ppos)
2932 #endif /* CONFIG_PROC_FS */
2935 * No sense putting this after each symbol definition, twice,
2936 * exception granted :-)
2938 EXPORT_SYMBOL(proc_dointvec);
2939 EXPORT_SYMBOL(proc_dointvec_jiffies);
2940 EXPORT_SYMBOL(proc_dointvec_minmax);
2941 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2942 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2943 EXPORT_SYMBOL(proc_dostring);
2944 EXPORT_SYMBOL(proc_doulongvec_minmax);
2945 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2946 EXPORT_SYMBOL(register_sysctl_table);
2947 EXPORT_SYMBOL(register_sysctl_paths);
2948 EXPORT_SYMBOL(unregister_sysctl_table);