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/perf_event.h>
54 #include <linux/kprobes.h>
55 #include <linux/pipe_fs_i.h>
57 #include <asm/uaccess.h>
58 #include <asm/processor.h>
62 #include <asm/stacktrace.h>
65 #ifdef CONFIG_BSD_PROCESS_ACCT
66 #include <linux/acct.h>
68 #ifdef CONFIG_RT_MUTEXES
69 #include <linux/rtmutex.h>
71 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
72 #include <linux/lockdep.h>
74 #ifdef CONFIG_CHR_DEV_SG
78 #ifdef CONFIG_LOCKUP_DETECTOR
79 #include <linux/nmi.h>
83 #if defined(CONFIG_SYSCTL)
85 /* External variables not in a header file. */
86 extern int sysctl_overcommit_memory;
87 extern int sysctl_overcommit_ratio;
88 extern int sysctl_panic_on_oom;
89 extern int sysctl_oom_kill_allocating_task;
90 extern int sysctl_oom_dump_tasks;
91 extern int max_threads;
92 extern int core_uses_pid;
93 extern int suid_dumpable;
94 extern char core_pattern[];
95 extern unsigned int core_pipe_limit;
97 extern int min_free_kbytes;
98 extern int pid_max_min, pid_max_max;
99 extern int sysctl_drop_caches;
100 extern int percpu_pagelist_fraction;
101 extern int compat_log;
102 extern int latencytop_enabled;
103 extern int sysctl_nr_open_min, sysctl_nr_open_max;
105 extern int sysctl_nr_trim_pages;
108 extern int blk_iopoll_enabled;
111 /* Constants used for minimum and maximum */
112 #ifdef CONFIG_LOCKUP_DETECTOR
113 static int sixty = 60;
114 static int neg_one = -1;
118 static int __maybe_unused one = 1;
119 static int __maybe_unused two = 2;
120 static unsigned long one_ul = 1;
121 static int one_hundred = 100;
123 static int ten_thousand = 10000;
126 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
127 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
129 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
130 static int maxolduid = 65535;
131 static int minolduid;
132 static int min_percpu_pagelist_fract = 8;
134 static int ngroups_max = NGROUPS_MAX;
137 #include <asm/system.h>
140 #ifdef CONFIG_SPARC64
141 extern int sysctl_tsb_ratio;
145 extern int pwrsw_enabled;
146 extern int unaligned_enabled;
150 #ifdef CONFIG_MATHEMU
151 extern int sysctl_ieee_emulation_warnings;
153 extern int sysctl_userprocess_debug;
154 extern int spin_retry;
158 extern int no_unaligned_warning;
159 extern int unaligned_dump_stack;
162 extern struct ratelimit_state printk_ratelimit_state;
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[];
212 #ifdef CONFIG_INOTIFY_USER
213 extern struct ctl_table inotify_table[];
216 extern struct ctl_table epoll_table[];
219 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
220 int sysctl_legacy_va_layout;
223 /* The default sysctl tables: */
225 static struct ctl_table root_table[] = {
227 .procname = "kernel",
244 .child = debug_table,
252 * NOTE: do not add new entries to this table unless you have read
253 * Documentation/sysctl/ctl_unnumbered.txt
258 #ifdef CONFIG_SCHED_DEBUG
259 static int min_sched_granularity_ns = 100000; /* 100 usecs */
260 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
261 static int min_wakeup_granularity_ns; /* 0 usecs */
262 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
263 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
264 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
265 static int min_sched_shares_ratelimit = 100000; /* 100 usec */
266 static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
269 #ifdef CONFIG_COMPACTION
270 static int min_extfrag_threshold;
271 static int max_extfrag_threshold = 1000;
274 static struct ctl_table kern_table[] = {
276 .procname = "sched_child_runs_first",
277 .data = &sysctl_sched_child_runs_first,
278 .maxlen = sizeof(unsigned int),
280 .proc_handler = proc_dointvec,
282 #ifdef CONFIG_SCHED_DEBUG
284 .procname = "sched_min_granularity_ns",
285 .data = &sysctl_sched_min_granularity,
286 .maxlen = sizeof(unsigned int),
288 .proc_handler = sched_proc_update_handler,
289 .extra1 = &min_sched_granularity_ns,
290 .extra2 = &max_sched_granularity_ns,
293 .procname = "sched_latency_ns",
294 .data = &sysctl_sched_latency,
295 .maxlen = sizeof(unsigned int),
297 .proc_handler = sched_proc_update_handler,
298 .extra1 = &min_sched_granularity_ns,
299 .extra2 = &max_sched_granularity_ns,
302 .procname = "sched_wakeup_granularity_ns",
303 .data = &sysctl_sched_wakeup_granularity,
304 .maxlen = sizeof(unsigned int),
306 .proc_handler = sched_proc_update_handler,
307 .extra1 = &min_wakeup_granularity_ns,
308 .extra2 = &max_wakeup_granularity_ns,
311 .procname = "sched_shares_ratelimit",
312 .data = &sysctl_sched_shares_ratelimit,
313 .maxlen = sizeof(unsigned int),
315 .proc_handler = sched_proc_update_handler,
316 .extra1 = &min_sched_shares_ratelimit,
317 .extra2 = &max_sched_shares_ratelimit,
320 .procname = "sched_tunable_scaling",
321 .data = &sysctl_sched_tunable_scaling,
322 .maxlen = sizeof(enum sched_tunable_scaling),
324 .proc_handler = sched_proc_update_handler,
325 .extra1 = &min_sched_tunable_scaling,
326 .extra2 = &max_sched_tunable_scaling,
329 .procname = "sched_shares_thresh",
330 .data = &sysctl_sched_shares_thresh,
331 .maxlen = sizeof(unsigned int),
333 .proc_handler = proc_dointvec_minmax,
337 .procname = "sched_migration_cost",
338 .data = &sysctl_sched_migration_cost,
339 .maxlen = sizeof(unsigned int),
341 .proc_handler = proc_dointvec,
344 .procname = "sched_nr_migrate",
345 .data = &sysctl_sched_nr_migrate,
346 .maxlen = sizeof(unsigned int),
348 .proc_handler = proc_dointvec,
351 .procname = "sched_time_avg",
352 .data = &sysctl_sched_time_avg,
353 .maxlen = sizeof(unsigned int),
355 .proc_handler = proc_dointvec,
358 .procname = "timer_migration",
359 .data = &sysctl_timer_migration,
360 .maxlen = sizeof(unsigned int),
362 .proc_handler = proc_dointvec_minmax,
368 .procname = "sched_rt_period_us",
369 .data = &sysctl_sched_rt_period,
370 .maxlen = sizeof(unsigned int),
372 .proc_handler = sched_rt_handler,
375 .procname = "sched_rt_runtime_us",
376 .data = &sysctl_sched_rt_runtime,
377 .maxlen = sizeof(int),
379 .proc_handler = sched_rt_handler,
382 .procname = "sched_compat_yield",
383 .data = &sysctl_sched_compat_yield,
384 .maxlen = sizeof(unsigned int),
386 .proc_handler = proc_dointvec,
388 #ifdef CONFIG_PROVE_LOCKING
390 .procname = "prove_locking",
391 .data = &prove_locking,
392 .maxlen = sizeof(int),
394 .proc_handler = proc_dointvec,
397 #ifdef CONFIG_LOCK_STAT
399 .procname = "lock_stat",
401 .maxlen = sizeof(int),
403 .proc_handler = proc_dointvec,
408 .data = &panic_timeout,
409 .maxlen = sizeof(int),
411 .proc_handler = proc_dointvec,
414 .procname = "core_uses_pid",
415 .data = &core_uses_pid,
416 .maxlen = sizeof(int),
418 .proc_handler = proc_dointvec,
421 .procname = "core_pattern",
422 .data = core_pattern,
423 .maxlen = CORENAME_MAX_SIZE,
425 .proc_handler = proc_dostring,
428 .procname = "core_pipe_limit",
429 .data = &core_pipe_limit,
430 .maxlen = sizeof(unsigned int),
432 .proc_handler = proc_dointvec,
434 #ifdef CONFIG_PROC_SYSCTL
436 .procname = "tainted",
437 .maxlen = sizeof(long),
439 .proc_handler = proc_taint,
442 #ifdef CONFIG_LATENCYTOP
444 .procname = "latencytop",
445 .data = &latencytop_enabled,
446 .maxlen = sizeof(int),
448 .proc_handler = proc_dointvec,
451 #ifdef CONFIG_BLK_DEV_INITRD
453 .procname = "real-root-dev",
454 .data = &real_root_dev,
455 .maxlen = sizeof(int),
457 .proc_handler = proc_dointvec,
461 .procname = "print-fatal-signals",
462 .data = &print_fatal_signals,
463 .maxlen = sizeof(int),
465 .proc_handler = proc_dointvec,
469 .procname = "reboot-cmd",
470 .data = reboot_command,
473 .proc_handler = proc_dostring,
476 .procname = "stop-a",
477 .data = &stop_a_enabled,
478 .maxlen = sizeof (int),
480 .proc_handler = proc_dointvec,
483 .procname = "scons-poweroff",
484 .data = &scons_pwroff,
485 .maxlen = sizeof (int),
487 .proc_handler = proc_dointvec,
490 #ifdef CONFIG_SPARC64
492 .procname = "tsb-ratio",
493 .data = &sysctl_tsb_ratio,
494 .maxlen = sizeof (int),
496 .proc_handler = proc_dointvec,
501 .procname = "soft-power",
502 .data = &pwrsw_enabled,
503 .maxlen = sizeof (int),
505 .proc_handler = proc_dointvec,
508 .procname = "unaligned-trap",
509 .data = &unaligned_enabled,
510 .maxlen = sizeof (int),
512 .proc_handler = proc_dointvec,
516 .procname = "ctrl-alt-del",
518 .maxlen = sizeof(int),
520 .proc_handler = proc_dointvec,
522 #ifdef CONFIG_FUNCTION_TRACER
524 .procname = "ftrace_enabled",
525 .data = &ftrace_enabled,
526 .maxlen = sizeof(int),
528 .proc_handler = ftrace_enable_sysctl,
531 #ifdef CONFIG_STACK_TRACER
533 .procname = "stack_tracer_enabled",
534 .data = &stack_tracer_enabled,
535 .maxlen = sizeof(int),
537 .proc_handler = stack_trace_sysctl,
540 #ifdef CONFIG_TRACING
542 .procname = "ftrace_dump_on_oops",
543 .data = &ftrace_dump_on_oops,
544 .maxlen = sizeof(int),
546 .proc_handler = proc_dointvec,
549 #ifdef CONFIG_MODULES
551 .procname = "modprobe",
552 .data = &modprobe_path,
553 .maxlen = KMOD_PATH_LEN,
555 .proc_handler = proc_dostring,
558 .procname = "modules_disabled",
559 .data = &modules_disabled,
560 .maxlen = sizeof(int),
562 /* only handle a transition from default "0" to "1" */
563 .proc_handler = proc_dointvec_minmax,
568 #ifdef CONFIG_HOTPLUG
570 .procname = "hotplug",
571 .data = &uevent_helper,
572 .maxlen = UEVENT_HELPER_PATH_LEN,
574 .proc_handler = proc_dostring,
577 #ifdef CONFIG_CHR_DEV_SG
579 .procname = "sg-big-buff",
580 .data = &sg_big_buff,
581 .maxlen = sizeof (int),
583 .proc_handler = proc_dointvec,
586 #ifdef CONFIG_BSD_PROCESS_ACCT
590 .maxlen = 3*sizeof(int),
592 .proc_handler = proc_dointvec,
595 #ifdef CONFIG_MAGIC_SYSRQ
598 .data = &__sysrq_enabled,
599 .maxlen = sizeof (int),
601 .proc_handler = sysrq_sysctl_handler,
604 #ifdef CONFIG_PROC_SYSCTL
606 .procname = "cad_pid",
608 .maxlen = sizeof (int),
610 .proc_handler = proc_do_cad_pid,
614 .procname = "threads-max",
615 .data = &max_threads,
616 .maxlen = sizeof(int),
618 .proc_handler = proc_dointvec,
621 .procname = "random",
623 .child = random_table,
626 .procname = "overflowuid",
627 .data = &overflowuid,
628 .maxlen = sizeof(int),
630 .proc_handler = proc_dointvec_minmax,
631 .extra1 = &minolduid,
632 .extra2 = &maxolduid,
635 .procname = "overflowgid",
636 .data = &overflowgid,
637 .maxlen = sizeof(int),
639 .proc_handler = proc_dointvec_minmax,
640 .extra1 = &minolduid,
641 .extra2 = &maxolduid,
644 #ifdef CONFIG_MATHEMU
646 .procname = "ieee_emulation_warnings",
647 .data = &sysctl_ieee_emulation_warnings,
648 .maxlen = sizeof(int),
650 .proc_handler = proc_dointvec,
654 .procname = "userprocess_debug",
655 .data = &show_unhandled_signals,
656 .maxlen = sizeof(int),
658 .proc_handler = proc_dointvec,
662 .procname = "pid_max",
664 .maxlen = sizeof (int),
666 .proc_handler = proc_dointvec_minmax,
667 .extra1 = &pid_max_min,
668 .extra2 = &pid_max_max,
671 .procname = "panic_on_oops",
672 .data = &panic_on_oops,
673 .maxlen = sizeof(int),
675 .proc_handler = proc_dointvec,
677 #if defined CONFIG_PRINTK
679 .procname = "printk",
680 .data = &console_loglevel,
681 .maxlen = 4*sizeof(int),
683 .proc_handler = proc_dointvec,
686 .procname = "printk_ratelimit",
687 .data = &printk_ratelimit_state.interval,
688 .maxlen = sizeof(int),
690 .proc_handler = proc_dointvec_jiffies,
693 .procname = "printk_ratelimit_burst",
694 .data = &printk_ratelimit_state.burst,
695 .maxlen = sizeof(int),
697 .proc_handler = proc_dointvec,
700 .procname = "printk_delay",
701 .data = &printk_delay_msec,
702 .maxlen = sizeof(int),
704 .proc_handler = proc_dointvec_minmax,
706 .extra2 = &ten_thousand,
710 .procname = "ngroups_max",
711 .data = &ngroups_max,
712 .maxlen = sizeof (int),
714 .proc_handler = proc_dointvec,
716 #if defined(CONFIG_LOCKUP_DETECTOR)
718 .procname = "watchdog",
719 .data = &watchdog_enabled,
720 .maxlen = sizeof (int),
722 .proc_handler = proc_dowatchdog_enabled,
725 .procname = "watchdog_thresh",
726 .data = &softlockup_thresh,
727 .maxlen = sizeof(int),
729 .proc_handler = proc_dowatchdog_thresh,
734 .procname = "softlockup_panic",
735 .data = &softlockup_panic,
736 .maxlen = sizeof(int),
738 .proc_handler = proc_dointvec_minmax,
743 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
745 .procname = "unknown_nmi_panic",
746 .data = &unknown_nmi_panic,
747 .maxlen = sizeof (int),
749 .proc_handler = proc_dointvec,
752 .procname = "nmi_watchdog",
753 .data = &nmi_watchdog_enabled,
754 .maxlen = sizeof (int),
756 .proc_handler = proc_nmi_enabled,
759 #if defined(CONFIG_X86)
761 .procname = "panic_on_unrecovered_nmi",
762 .data = &panic_on_unrecovered_nmi,
763 .maxlen = sizeof(int),
765 .proc_handler = proc_dointvec,
768 .procname = "panic_on_io_nmi",
769 .data = &panic_on_io_nmi,
770 .maxlen = sizeof(int),
772 .proc_handler = proc_dointvec,
775 .procname = "bootloader_type",
776 .data = &bootloader_type,
777 .maxlen = sizeof (int),
779 .proc_handler = proc_dointvec,
782 .procname = "bootloader_version",
783 .data = &bootloader_version,
784 .maxlen = sizeof (int),
786 .proc_handler = proc_dointvec,
789 .procname = "kstack_depth_to_print",
790 .data = &kstack_depth_to_print,
791 .maxlen = sizeof(int),
793 .proc_handler = proc_dointvec,
796 .procname = "io_delay_type",
797 .data = &io_delay_type,
798 .maxlen = sizeof(int),
800 .proc_handler = proc_dointvec,
803 #if defined(CONFIG_MMU)
805 .procname = "randomize_va_space",
806 .data = &randomize_va_space,
807 .maxlen = sizeof(int),
809 .proc_handler = proc_dointvec,
812 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
814 .procname = "spin_retry",
816 .maxlen = sizeof (int),
818 .proc_handler = proc_dointvec,
821 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
823 .procname = "acpi_video_flags",
824 .data = &acpi_realmode_flags,
825 .maxlen = sizeof (unsigned long),
827 .proc_handler = proc_doulongvec_minmax,
832 .procname = "ignore-unaligned-usertrap",
833 .data = &no_unaligned_warning,
834 .maxlen = sizeof (int),
836 .proc_handler = proc_dointvec,
839 .procname = "unaligned-dump-stack",
840 .data = &unaligned_dump_stack,
841 .maxlen = sizeof (int),
843 .proc_handler = proc_dointvec,
846 #ifdef CONFIG_DETECT_HUNG_TASK
848 .procname = "hung_task_panic",
849 .data = &sysctl_hung_task_panic,
850 .maxlen = sizeof(int),
852 .proc_handler = proc_dointvec_minmax,
857 .procname = "hung_task_check_count",
858 .data = &sysctl_hung_task_check_count,
859 .maxlen = sizeof(unsigned long),
861 .proc_handler = proc_doulongvec_minmax,
864 .procname = "hung_task_timeout_secs",
865 .data = &sysctl_hung_task_timeout_secs,
866 .maxlen = sizeof(unsigned long),
868 .proc_handler = proc_dohung_task_timeout_secs,
871 .procname = "hung_task_warnings",
872 .data = &sysctl_hung_task_warnings,
873 .maxlen = sizeof(unsigned long),
875 .proc_handler = proc_doulongvec_minmax,
880 .procname = "compat-log",
882 .maxlen = sizeof (int),
884 .proc_handler = proc_dointvec,
887 #ifdef CONFIG_RT_MUTEXES
889 .procname = "max_lock_depth",
890 .data = &max_lock_depth,
891 .maxlen = sizeof(int),
893 .proc_handler = proc_dointvec,
897 .procname = "poweroff_cmd",
898 .data = &poweroff_cmd,
899 .maxlen = POWEROFF_CMD_PATH_LEN,
901 .proc_handler = proc_dostring,
907 .child = key_sysctls,
910 #ifdef CONFIG_RCU_TORTURE_TEST
912 .procname = "rcutorture_runnable",
913 .data = &rcutorture_runnable,
914 .maxlen = sizeof(int),
916 .proc_handler = proc_dointvec,
919 #ifdef CONFIG_PERF_EVENTS
921 .procname = "perf_event_paranoid",
922 .data = &sysctl_perf_event_paranoid,
923 .maxlen = sizeof(sysctl_perf_event_paranoid),
925 .proc_handler = proc_dointvec,
928 .procname = "perf_event_mlock_kb",
929 .data = &sysctl_perf_event_mlock,
930 .maxlen = sizeof(sysctl_perf_event_mlock),
932 .proc_handler = proc_dointvec,
935 .procname = "perf_event_max_sample_rate",
936 .data = &sysctl_perf_event_sample_rate,
937 .maxlen = sizeof(sysctl_perf_event_sample_rate),
939 .proc_handler = proc_dointvec,
942 #ifdef CONFIG_KMEMCHECK
944 .procname = "kmemcheck",
945 .data = &kmemcheck_enabled,
946 .maxlen = sizeof(int),
948 .proc_handler = proc_dointvec,
953 .procname = "blk_iopoll",
954 .data = &blk_iopoll_enabled,
955 .maxlen = sizeof(int),
957 .proc_handler = proc_dointvec,
961 * NOTE: do not add new entries to this table unless you have read
962 * Documentation/sysctl/ctl_unnumbered.txt
967 static struct ctl_table vm_table[] = {
969 .procname = "overcommit_memory",
970 .data = &sysctl_overcommit_memory,
971 .maxlen = sizeof(sysctl_overcommit_memory),
973 .proc_handler = proc_dointvec,
976 .procname = "panic_on_oom",
977 .data = &sysctl_panic_on_oom,
978 .maxlen = sizeof(sysctl_panic_on_oom),
980 .proc_handler = proc_dointvec,
983 .procname = "oom_kill_allocating_task",
984 .data = &sysctl_oom_kill_allocating_task,
985 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
987 .proc_handler = proc_dointvec,
990 .procname = "oom_dump_tasks",
991 .data = &sysctl_oom_dump_tasks,
992 .maxlen = sizeof(sysctl_oom_dump_tasks),
994 .proc_handler = proc_dointvec,
997 .procname = "overcommit_ratio",
998 .data = &sysctl_overcommit_ratio,
999 .maxlen = sizeof(sysctl_overcommit_ratio),
1001 .proc_handler = proc_dointvec,
1004 .procname = "page-cluster",
1005 .data = &page_cluster,
1006 .maxlen = sizeof(int),
1008 .proc_handler = proc_dointvec,
1011 .procname = "dirty_background_ratio",
1012 .data = &dirty_background_ratio,
1013 .maxlen = sizeof(dirty_background_ratio),
1015 .proc_handler = dirty_background_ratio_handler,
1017 .extra2 = &one_hundred,
1020 .procname = "dirty_background_bytes",
1021 .data = &dirty_background_bytes,
1022 .maxlen = sizeof(dirty_background_bytes),
1024 .proc_handler = dirty_background_bytes_handler,
1028 .procname = "dirty_ratio",
1029 .data = &vm_dirty_ratio,
1030 .maxlen = sizeof(vm_dirty_ratio),
1032 .proc_handler = dirty_ratio_handler,
1034 .extra2 = &one_hundred,
1037 .procname = "dirty_bytes",
1038 .data = &vm_dirty_bytes,
1039 .maxlen = sizeof(vm_dirty_bytes),
1041 .proc_handler = dirty_bytes_handler,
1042 .extra1 = &dirty_bytes_min,
1045 .procname = "dirty_writeback_centisecs",
1046 .data = &dirty_writeback_interval,
1047 .maxlen = sizeof(dirty_writeback_interval),
1049 .proc_handler = dirty_writeback_centisecs_handler,
1052 .procname = "dirty_expire_centisecs",
1053 .data = &dirty_expire_interval,
1054 .maxlen = sizeof(dirty_expire_interval),
1056 .proc_handler = proc_dointvec,
1059 .procname = "nr_pdflush_threads",
1060 .data = &nr_pdflush_threads,
1061 .maxlen = sizeof nr_pdflush_threads,
1062 .mode = 0444 /* read-only*/,
1063 .proc_handler = proc_dointvec,
1066 .procname = "swappiness",
1067 .data = &vm_swappiness,
1068 .maxlen = sizeof(vm_swappiness),
1070 .proc_handler = proc_dointvec_minmax,
1072 .extra2 = &one_hundred,
1074 #ifdef CONFIG_HUGETLB_PAGE
1076 .procname = "nr_hugepages",
1078 .maxlen = sizeof(unsigned long),
1080 .proc_handler = hugetlb_sysctl_handler,
1081 .extra1 = (void *)&hugetlb_zero,
1082 .extra2 = (void *)&hugetlb_infinity,
1086 .procname = "nr_hugepages_mempolicy",
1088 .maxlen = sizeof(unsigned long),
1090 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1091 .extra1 = (void *)&hugetlb_zero,
1092 .extra2 = (void *)&hugetlb_infinity,
1096 .procname = "hugetlb_shm_group",
1097 .data = &sysctl_hugetlb_shm_group,
1098 .maxlen = sizeof(gid_t),
1100 .proc_handler = proc_dointvec,
1103 .procname = "hugepages_treat_as_movable",
1104 .data = &hugepages_treat_as_movable,
1105 .maxlen = sizeof(int),
1107 .proc_handler = hugetlb_treat_movable_handler,
1110 .procname = "nr_overcommit_hugepages",
1112 .maxlen = sizeof(unsigned long),
1114 .proc_handler = hugetlb_overcommit_handler,
1115 .extra1 = (void *)&hugetlb_zero,
1116 .extra2 = (void *)&hugetlb_infinity,
1120 .procname = "lowmem_reserve_ratio",
1121 .data = &sysctl_lowmem_reserve_ratio,
1122 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1124 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1127 .procname = "drop_caches",
1128 .data = &sysctl_drop_caches,
1129 .maxlen = sizeof(int),
1131 .proc_handler = drop_caches_sysctl_handler,
1133 #ifdef CONFIG_COMPACTION
1135 .procname = "compact_memory",
1136 .data = &sysctl_compact_memory,
1137 .maxlen = sizeof(int),
1139 .proc_handler = sysctl_compaction_handler,
1142 .procname = "extfrag_threshold",
1143 .data = &sysctl_extfrag_threshold,
1144 .maxlen = sizeof(int),
1146 .proc_handler = sysctl_extfrag_handler,
1147 .extra1 = &min_extfrag_threshold,
1148 .extra2 = &max_extfrag_threshold,
1151 #endif /* CONFIG_COMPACTION */
1153 .procname = "min_free_kbytes",
1154 .data = &min_free_kbytes,
1155 .maxlen = sizeof(min_free_kbytes),
1157 .proc_handler = min_free_kbytes_sysctl_handler,
1161 .procname = "percpu_pagelist_fraction",
1162 .data = &percpu_pagelist_fraction,
1163 .maxlen = sizeof(percpu_pagelist_fraction),
1165 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1166 .extra1 = &min_percpu_pagelist_fract,
1170 .procname = "max_map_count",
1171 .data = &sysctl_max_map_count,
1172 .maxlen = sizeof(sysctl_max_map_count),
1174 .proc_handler = proc_dointvec_minmax,
1179 .procname = "nr_trim_pages",
1180 .data = &sysctl_nr_trim_pages,
1181 .maxlen = sizeof(sysctl_nr_trim_pages),
1183 .proc_handler = proc_dointvec_minmax,
1188 .procname = "laptop_mode",
1189 .data = &laptop_mode,
1190 .maxlen = sizeof(laptop_mode),
1192 .proc_handler = proc_dointvec_jiffies,
1195 .procname = "block_dump",
1196 .data = &block_dump,
1197 .maxlen = sizeof(block_dump),
1199 .proc_handler = proc_dointvec,
1203 .procname = "vfs_cache_pressure",
1204 .data = &sysctl_vfs_cache_pressure,
1205 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1207 .proc_handler = proc_dointvec,
1210 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1212 .procname = "legacy_va_layout",
1213 .data = &sysctl_legacy_va_layout,
1214 .maxlen = sizeof(sysctl_legacy_va_layout),
1216 .proc_handler = proc_dointvec,
1222 .procname = "zone_reclaim_mode",
1223 .data = &zone_reclaim_mode,
1224 .maxlen = sizeof(zone_reclaim_mode),
1226 .proc_handler = proc_dointvec,
1230 .procname = "min_unmapped_ratio",
1231 .data = &sysctl_min_unmapped_ratio,
1232 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1234 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1236 .extra2 = &one_hundred,
1239 .procname = "min_slab_ratio",
1240 .data = &sysctl_min_slab_ratio,
1241 .maxlen = sizeof(sysctl_min_slab_ratio),
1243 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1245 .extra2 = &one_hundred,
1250 .procname = "stat_interval",
1251 .data = &sysctl_stat_interval,
1252 .maxlen = sizeof(sysctl_stat_interval),
1254 .proc_handler = proc_dointvec_jiffies,
1259 .procname = "mmap_min_addr",
1260 .data = &dac_mmap_min_addr,
1261 .maxlen = sizeof(unsigned long),
1263 .proc_handler = mmap_min_addr_handler,
1268 .procname = "numa_zonelist_order",
1269 .data = &numa_zonelist_order,
1270 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1272 .proc_handler = numa_zonelist_order_handler,
1275 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1276 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1278 .procname = "vdso_enabled",
1279 .data = &vdso_enabled,
1280 .maxlen = sizeof(vdso_enabled),
1282 .proc_handler = proc_dointvec,
1286 #ifdef CONFIG_HIGHMEM
1288 .procname = "highmem_is_dirtyable",
1289 .data = &vm_highmem_is_dirtyable,
1290 .maxlen = sizeof(vm_highmem_is_dirtyable),
1292 .proc_handler = proc_dointvec_minmax,
1298 .procname = "scan_unevictable_pages",
1299 .data = &scan_unevictable_pages,
1300 .maxlen = sizeof(scan_unevictable_pages),
1302 .proc_handler = scan_unevictable_handler,
1304 #ifdef CONFIG_MEMORY_FAILURE
1306 .procname = "memory_failure_early_kill",
1307 .data = &sysctl_memory_failure_early_kill,
1308 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1310 .proc_handler = proc_dointvec_minmax,
1315 .procname = "memory_failure_recovery",
1316 .data = &sysctl_memory_failure_recovery,
1317 .maxlen = sizeof(sysctl_memory_failure_recovery),
1319 .proc_handler = proc_dointvec_minmax,
1326 * NOTE: do not add new entries to this table unless you have read
1327 * Documentation/sysctl/ctl_unnumbered.txt
1332 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1333 static struct ctl_table binfmt_misc_table[] = {
1338 static struct ctl_table fs_table[] = {
1340 .procname = "inode-nr",
1341 .data = &inodes_stat,
1342 .maxlen = 2*sizeof(int),
1344 .proc_handler = proc_dointvec,
1347 .procname = "inode-state",
1348 .data = &inodes_stat,
1349 .maxlen = 7*sizeof(int),
1351 .proc_handler = proc_dointvec,
1354 .procname = "file-nr",
1355 .data = &files_stat,
1356 .maxlen = 3*sizeof(int),
1358 .proc_handler = proc_nr_files,
1361 .procname = "file-max",
1362 .data = &files_stat.max_files,
1363 .maxlen = sizeof(int),
1365 .proc_handler = proc_dointvec,
1368 .procname = "nr_open",
1369 .data = &sysctl_nr_open,
1370 .maxlen = sizeof(int),
1372 .proc_handler = proc_dointvec_minmax,
1373 .extra1 = &sysctl_nr_open_min,
1374 .extra2 = &sysctl_nr_open_max,
1377 .procname = "dentry-state",
1378 .data = &dentry_stat,
1379 .maxlen = 6*sizeof(int),
1381 .proc_handler = proc_dointvec,
1384 .procname = "overflowuid",
1385 .data = &fs_overflowuid,
1386 .maxlen = sizeof(int),
1388 .proc_handler = proc_dointvec_minmax,
1389 .extra1 = &minolduid,
1390 .extra2 = &maxolduid,
1393 .procname = "overflowgid",
1394 .data = &fs_overflowgid,
1395 .maxlen = sizeof(int),
1397 .proc_handler = proc_dointvec_minmax,
1398 .extra1 = &minolduid,
1399 .extra2 = &maxolduid,
1401 #ifdef CONFIG_FILE_LOCKING
1403 .procname = "leases-enable",
1404 .data = &leases_enable,
1405 .maxlen = sizeof(int),
1407 .proc_handler = proc_dointvec,
1410 #ifdef CONFIG_DNOTIFY
1412 .procname = "dir-notify-enable",
1413 .data = &dir_notify_enable,
1414 .maxlen = sizeof(int),
1416 .proc_handler = proc_dointvec,
1420 #ifdef CONFIG_FILE_LOCKING
1422 .procname = "lease-break-time",
1423 .data = &lease_break_time,
1424 .maxlen = sizeof(int),
1426 .proc_handler = proc_dointvec,
1431 .procname = "aio-nr",
1433 .maxlen = sizeof(aio_nr),
1435 .proc_handler = proc_doulongvec_minmax,
1438 .procname = "aio-max-nr",
1439 .data = &aio_max_nr,
1440 .maxlen = sizeof(aio_max_nr),
1442 .proc_handler = proc_doulongvec_minmax,
1444 #endif /* CONFIG_AIO */
1445 #ifdef CONFIG_INOTIFY_USER
1447 .procname = "inotify",
1449 .child = inotify_table,
1454 .procname = "epoll",
1456 .child = epoll_table,
1461 .procname = "suid_dumpable",
1462 .data = &suid_dumpable,
1463 .maxlen = sizeof(int),
1465 .proc_handler = proc_dointvec_minmax,
1469 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1471 .procname = "binfmt_misc",
1473 .child = binfmt_misc_table,
1477 .procname = "pipe-max-size",
1478 .data = &pipe_max_size,
1479 .maxlen = sizeof(int),
1481 .proc_handler = &pipe_proc_fn,
1482 .extra1 = &pipe_min_size,
1485 * NOTE: do not add new entries to this table unless you have read
1486 * Documentation/sysctl/ctl_unnumbered.txt
1491 static struct ctl_table debug_table[] = {
1492 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1493 defined(CONFIG_S390)
1495 .procname = "exception-trace",
1496 .data = &show_unhandled_signals,
1497 .maxlen = sizeof(int),
1499 .proc_handler = proc_dointvec
1502 #if defined(CONFIG_OPTPROBES)
1504 .procname = "kprobes-optimization",
1505 .data = &sysctl_kprobes_optimization,
1506 .maxlen = sizeof(int),
1508 .proc_handler = proc_kprobes_optimization_handler,
1516 static struct ctl_table dev_table[] = {
1520 static DEFINE_SPINLOCK(sysctl_lock);
1522 /* called under sysctl_lock */
1523 static int use_table(struct ctl_table_header *p)
1525 if (unlikely(p->unregistering))
1531 /* called under sysctl_lock */
1532 static void unuse_table(struct ctl_table_header *p)
1535 if (unlikely(p->unregistering))
1536 complete(p->unregistering);
1539 /* called under sysctl_lock, will reacquire if has to wait */
1540 static void start_unregistering(struct ctl_table_header *p)
1543 * if p->used is 0, nobody will ever touch that entry again;
1544 * we'll eliminate all paths to it before dropping sysctl_lock
1546 if (unlikely(p->used)) {
1547 struct completion wait;
1548 init_completion(&wait);
1549 p->unregistering = &wait;
1550 spin_unlock(&sysctl_lock);
1551 wait_for_completion(&wait);
1552 spin_lock(&sysctl_lock);
1554 /* anything non-NULL; we'll never dereference it */
1555 p->unregistering = ERR_PTR(-EINVAL);
1558 * do not remove from the list until nobody holds it; walking the
1559 * list in do_sysctl() relies on that.
1561 list_del_init(&p->ctl_entry);
1564 void sysctl_head_get(struct ctl_table_header *head)
1566 spin_lock(&sysctl_lock);
1568 spin_unlock(&sysctl_lock);
1571 void sysctl_head_put(struct ctl_table_header *head)
1573 spin_lock(&sysctl_lock);
1576 spin_unlock(&sysctl_lock);
1579 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1583 spin_lock(&sysctl_lock);
1584 if (!use_table(head))
1585 head = ERR_PTR(-ENOENT);
1586 spin_unlock(&sysctl_lock);
1590 void sysctl_head_finish(struct ctl_table_header *head)
1594 spin_lock(&sysctl_lock);
1596 spin_unlock(&sysctl_lock);
1599 static struct ctl_table_set *
1600 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1602 struct ctl_table_set *set = &root->default_set;
1604 set = root->lookup(root, namespaces);
1608 static struct list_head *
1609 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1611 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1615 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1616 struct ctl_table_header *prev)
1618 struct ctl_table_root *root;
1619 struct list_head *header_list;
1620 struct ctl_table_header *head;
1621 struct list_head *tmp;
1623 spin_lock(&sysctl_lock);
1626 tmp = &prev->ctl_entry;
1630 tmp = &root_table_header.ctl_entry;
1632 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1634 if (!use_table(head))
1636 spin_unlock(&sysctl_lock);
1641 header_list = lookup_header_list(root, namespaces);
1642 if (tmp != header_list)
1646 root = list_entry(root->root_list.next,
1647 struct ctl_table_root, root_list);
1648 if (root == &sysctl_table_root)
1650 header_list = lookup_header_list(root, namespaces);
1651 } while (list_empty(header_list));
1652 tmp = header_list->next;
1655 spin_unlock(&sysctl_lock);
1659 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1661 return __sysctl_head_next(current->nsproxy, prev);
1664 void register_sysctl_root(struct ctl_table_root *root)
1666 spin_lock(&sysctl_lock);
1667 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1668 spin_unlock(&sysctl_lock);
1672 * sysctl_perm does NOT grant the superuser all rights automatically, because
1673 * some sysctl variables are readonly even to root.
1676 static int test_perm(int mode, int op)
1678 if (!current_euid())
1680 else if (in_egroup_p(0))
1682 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1687 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1692 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1696 if (root->permissions)
1697 mode = root->permissions(root, current->nsproxy, table);
1701 return test_perm(mode, op);
1704 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1706 for (; table->procname; table++) {
1707 table->parent = parent;
1709 sysctl_set_parent(table, table->child);
1713 static __init int sysctl_init(void)
1715 sysctl_set_parent(NULL, root_table);
1716 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1719 err = sysctl_check_table(current->nsproxy, root_table);
1725 core_initcall(sysctl_init);
1727 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1728 struct ctl_table *table)
1730 struct ctl_table *p;
1731 const char *s = branch->procname;
1733 /* branch should have named subdirectory as its first element */
1734 if (!s || !branch->child)
1737 /* ... and nothing else */
1738 if (branch[1].procname)
1741 /* table should contain subdirectory with the same name */
1742 for (p = table; p->procname; p++) {
1745 if (p->procname && strcmp(p->procname, s) == 0)
1751 /* see if attaching q to p would be an improvement */
1752 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1754 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1755 struct ctl_table *next;
1757 int not_in_parent = !p->attached_by;
1759 while ((next = is_branch_in(by, to)) != NULL) {
1760 if (by == q->attached_by)
1762 if (to == p->attached_by)
1768 if (is_better && not_in_parent) {
1769 q->attached_by = by;
1770 q->attached_to = to;
1776 * __register_sysctl_paths - register a sysctl hierarchy
1777 * @root: List of sysctl headers to register on
1778 * @namespaces: Data to compute which lists of sysctl entries are visible
1779 * @path: The path to the directory the sysctl table is in.
1780 * @table: the top-level table structure
1782 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1783 * array. A completely 0 filled entry terminates the table.
1785 * The members of the &struct ctl_table structure are used as follows:
1787 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1788 * enter a sysctl file
1790 * data - a pointer to data for use by proc_handler
1792 * maxlen - the maximum size in bytes of the data
1794 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1796 * child - a pointer to the child sysctl table if this entry is a directory, or
1799 * proc_handler - the text handler routine (described below)
1801 * de - for internal use by the sysctl routines
1803 * extra1, extra2 - extra pointers usable by the proc handler routines
1805 * Leaf nodes in the sysctl tree will be represented by a single file
1806 * under /proc; non-leaf nodes will be represented by directories.
1808 * sysctl(2) can automatically manage read and write requests through
1809 * the sysctl table. The data and maxlen fields of the ctl_table
1810 * struct enable minimal validation of the values being written to be
1811 * performed, and the mode field allows minimal authentication.
1813 * There must be a proc_handler routine for any terminal nodes
1814 * mirrored under /proc/sys (non-terminals are handled by a built-in
1815 * directory handler). Several default handlers are available to
1816 * cover common cases -
1818 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1819 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1820 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1822 * It is the handler's job to read the input buffer from user memory
1823 * and process it. The handler should return 0 on success.
1825 * This routine returns %NULL on a failure to register, and a pointer
1826 * to the table header on success.
1828 struct ctl_table_header *__register_sysctl_paths(
1829 struct ctl_table_root *root,
1830 struct nsproxy *namespaces,
1831 const struct ctl_path *path, struct ctl_table *table)
1833 struct ctl_table_header *header;
1834 struct ctl_table *new, **prevp;
1835 unsigned int n, npath;
1836 struct ctl_table_set *set;
1838 /* Count the path components */
1839 for (npath = 0; path[npath].procname; ++npath)
1843 * For each path component, allocate a 2-element ctl_table array.
1844 * The first array element will be filled with the sysctl entry
1845 * for this, the second will be the sentinel (procname == 0).
1847 * We allocate everything in one go so that we don't have to
1848 * worry about freeing additional memory in unregister_sysctl_table.
1850 header = kzalloc(sizeof(struct ctl_table_header) +
1851 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1855 new = (struct ctl_table *) (header + 1);
1857 /* Now connect the dots */
1858 prevp = &header->ctl_table;
1859 for (n = 0; n < npath; ++n, ++path) {
1860 /* Copy the procname */
1861 new->procname = path->procname;
1865 prevp = &new->child;
1870 header->ctl_table_arg = table;
1872 INIT_LIST_HEAD(&header->ctl_entry);
1874 header->unregistering = NULL;
1875 header->root = root;
1876 sysctl_set_parent(NULL, header->ctl_table);
1878 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1879 if (sysctl_check_table(namespaces, header->ctl_table)) {
1884 spin_lock(&sysctl_lock);
1885 header->set = lookup_header_set(root, namespaces);
1886 header->attached_by = header->ctl_table;
1887 header->attached_to = root_table;
1888 header->parent = &root_table_header;
1889 for (set = header->set; set; set = set->parent) {
1890 struct ctl_table_header *p;
1891 list_for_each_entry(p, &set->list, ctl_entry) {
1892 if (p->unregistering)
1894 try_attach(p, header);
1897 header->parent->count++;
1898 list_add_tail(&header->ctl_entry, &header->set->list);
1899 spin_unlock(&sysctl_lock);
1905 * register_sysctl_table_path - register a sysctl table hierarchy
1906 * @path: The path to the directory the sysctl table is in.
1907 * @table: the top-level table structure
1909 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1910 * array. A completely 0 filled entry terminates the table.
1912 * See __register_sysctl_paths for more details.
1914 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1915 struct ctl_table *table)
1917 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1922 * register_sysctl_table - register a sysctl table hierarchy
1923 * @table: the top-level table structure
1925 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1926 * array. A completely 0 filled entry terminates the table.
1928 * See register_sysctl_paths for more details.
1930 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1932 static const struct ctl_path null_path[] = { {} };
1934 return register_sysctl_paths(null_path, table);
1938 * unregister_sysctl_table - unregister a sysctl table hierarchy
1939 * @header: the header returned from register_sysctl_table
1941 * Unregisters the sysctl table and all children. proc entries may not
1942 * actually be removed until they are no longer used by anyone.
1944 void unregister_sysctl_table(struct ctl_table_header * header)
1951 spin_lock(&sysctl_lock);
1952 start_unregistering(header);
1953 if (!--header->parent->count) {
1955 kfree(header->parent);
1957 if (!--header->count)
1959 spin_unlock(&sysctl_lock);
1962 int sysctl_is_seen(struct ctl_table_header *p)
1964 struct ctl_table_set *set = p->set;
1966 spin_lock(&sysctl_lock);
1967 if (p->unregistering)
1969 else if (!set->is_seen)
1972 res = set->is_seen(set);
1973 spin_unlock(&sysctl_lock);
1977 void setup_sysctl_set(struct ctl_table_set *p,
1978 struct ctl_table_set *parent,
1979 int (*is_seen)(struct ctl_table_set *))
1981 INIT_LIST_HEAD(&p->list);
1982 p->parent = parent ? parent : &sysctl_table_root.default_set;
1983 p->is_seen = is_seen;
1986 #else /* !CONFIG_SYSCTL */
1987 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1992 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1993 struct ctl_table *table)
1998 void unregister_sysctl_table(struct ctl_table_header * table)
2002 void setup_sysctl_set(struct ctl_table_set *p,
2003 struct ctl_table_set *parent,
2004 int (*is_seen)(struct ctl_table_set *))
2008 void sysctl_head_put(struct ctl_table_header *head)
2012 #endif /* CONFIG_SYSCTL */
2018 #ifdef CONFIG_PROC_SYSCTL
2020 static int _proc_do_string(void* data, int maxlen, int write,
2021 void __user *buffer,
2022 size_t *lenp, loff_t *ppos)
2028 if (!data || !maxlen || !*lenp) {
2036 while (len < *lenp) {
2037 if (get_user(c, p++))
2039 if (c == 0 || c == '\n')
2045 if(copy_from_user(data, buffer, len))
2047 ((char *) data)[len] = 0;
2065 if(copy_to_user(buffer, data, len))
2068 if(put_user('\n', ((char __user *) buffer) + len))
2079 * proc_dostring - read a string sysctl
2080 * @table: the sysctl table
2081 * @write: %TRUE if this is a write to the sysctl file
2082 * @buffer: the user buffer
2083 * @lenp: the size of the user buffer
2084 * @ppos: file position
2086 * Reads/writes a string from/to the user buffer. If the kernel
2087 * buffer provided is not large enough to hold the string, the
2088 * string is truncated. The copied string is %NULL-terminated.
2089 * If the string is being read by the user process, it is copied
2090 * and a newline '\n' is added. It is truncated if the buffer is
2093 * Returns 0 on success.
2095 int proc_dostring(struct ctl_table *table, int write,
2096 void __user *buffer, size_t *lenp, loff_t *ppos)
2098 return _proc_do_string(table->data, table->maxlen, write,
2099 buffer, lenp, ppos);
2102 static size_t proc_skip_spaces(char **buf)
2105 char *tmp = skip_spaces(*buf);
2111 static void proc_skip_char(char **buf, size_t *size, const char v)
2121 #define TMPBUFLEN 22
2123 * proc_get_long - reads an ASCII formatted integer from a user buffer
2125 * @buf: a kernel buffer
2126 * @size: size of the kernel buffer
2127 * @val: this is where the number will be stored
2128 * @neg: set to %TRUE if number is negative
2129 * @perm_tr: a vector which contains the allowed trailers
2130 * @perm_tr_len: size of the perm_tr vector
2131 * @tr: pointer to store the trailer character
2133 * In case of success %0 is returned and @buf and @size are updated with
2134 * the amount of bytes read. If @tr is non-NULL and a trailing
2135 * character exists (size is non-zero after returning from this
2136 * function), @tr is updated with the trailing character.
2138 static int proc_get_long(char **buf, size_t *size,
2139 unsigned long *val, bool *neg,
2140 const char *perm_tr, unsigned perm_tr_len, char *tr)
2143 char *p, tmp[TMPBUFLEN];
2149 if (len > TMPBUFLEN - 1)
2150 len = TMPBUFLEN - 1;
2152 memcpy(tmp, *buf, len);
2156 if (*p == '-' && *size > 1) {
2164 *val = simple_strtoul(p, &p, 0);
2168 /* We don't know if the next char is whitespace thus we may accept
2169 * invalid integers (e.g. 1234...a) or two integers instead of one
2170 * (e.g. 123...1). So lets not allow such large numbers. */
2171 if (len == TMPBUFLEN - 1)
2174 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2177 if (tr && (len < *size))
2187 * proc_put_long - converts an integer to a decimal ASCII formatted string
2189 * @buf: the user buffer
2190 * @size: the size of the user buffer
2191 * @val: the integer to be converted
2192 * @neg: sign of the number, %TRUE for negative
2194 * In case of success %0 is returned and @buf and @size are updated with
2195 * the amount of bytes written.
2197 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2201 char tmp[TMPBUFLEN], *p = tmp;
2203 sprintf(p, "%s%lu", neg ? "-" : "", val);
2207 if (copy_to_user(*buf, tmp, len))
2215 static int proc_put_char(void __user **buf, size_t *size, char c)
2218 char __user **buffer = (char __user **)buf;
2219 if (put_user(c, *buffer))
2221 (*size)--, (*buffer)++;
2227 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2229 int write, void *data)
2232 *valp = *negp ? -*lvalp : *lvalp;
2237 *lvalp = (unsigned long)-val;
2240 *lvalp = (unsigned long)val;
2246 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2248 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2249 int write, void __user *buffer,
2250 size_t *lenp, loff_t *ppos,
2251 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2252 int write, void *data),
2255 int *i, vleft, first = 1, err = 0;
2256 unsigned long page = 0;
2260 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2265 i = (int *) tbl_data;
2266 vleft = table->maxlen / sizeof(*i);
2270 conv = do_proc_dointvec_conv;
2273 if (left > PAGE_SIZE - 1)
2274 left = PAGE_SIZE - 1;
2275 page = __get_free_page(GFP_TEMPORARY);
2276 kbuf = (char *) page;
2279 if (copy_from_user(kbuf, buffer, left)) {
2286 for (; left && vleft--; i++, first=0) {
2291 left -= proc_skip_spaces(&kbuf);
2295 err = proc_get_long(&kbuf, &left, &lval, &neg,
2297 sizeof(proc_wspace_sep), NULL);
2300 if (conv(&neg, &lval, i, 1, data)) {
2305 if (conv(&neg, &lval, i, 0, data)) {
2310 err = proc_put_char(&buffer, &left, '\t');
2313 err = proc_put_long(&buffer, &left, lval, neg);
2319 if (!write && !first && left && !err)
2320 err = proc_put_char(&buffer, &left, '\n');
2321 if (write && !err && left)
2322 left -= proc_skip_spaces(&kbuf);
2327 return err ? : -EINVAL;
2334 static int do_proc_dointvec(struct ctl_table *table, int write,
2335 void __user *buffer, size_t *lenp, loff_t *ppos,
2336 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2337 int write, void *data),
2340 return __do_proc_dointvec(table->data, table, write,
2341 buffer, lenp, ppos, conv, data);
2345 * proc_dointvec - read a vector of integers
2346 * @table: the sysctl table
2347 * @write: %TRUE if this is a write to the sysctl file
2348 * @buffer: the user buffer
2349 * @lenp: the size of the user buffer
2350 * @ppos: file position
2352 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2353 * values from/to the user buffer, treated as an ASCII string.
2355 * Returns 0 on success.
2357 int proc_dointvec(struct ctl_table *table, int write,
2358 void __user *buffer, size_t *lenp, loff_t *ppos)
2360 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2365 * Taint values can only be increased
2366 * This means we can safely use a temporary.
2368 static int proc_taint(struct ctl_table *table, int write,
2369 void __user *buffer, size_t *lenp, loff_t *ppos)
2372 unsigned long tmptaint = get_taint();
2375 if (write && !capable(CAP_SYS_ADMIN))
2380 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2386 * Poor man's atomic or. Not worth adding a primitive
2387 * to everyone's atomic.h for this
2390 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2391 if ((tmptaint >> i) & 1)
2399 struct do_proc_dointvec_minmax_conv_param {
2404 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2406 int write, void *data)
2408 struct do_proc_dointvec_minmax_conv_param *param = data;
2410 int val = *negp ? -*lvalp : *lvalp;
2411 if ((param->min && *param->min > val) ||
2412 (param->max && *param->max < val))
2419 *lvalp = (unsigned long)-val;
2422 *lvalp = (unsigned long)val;
2429 * proc_dointvec_minmax - read a vector of integers with min/max values
2430 * @table: the sysctl table
2431 * @write: %TRUE if this is a write to the sysctl file
2432 * @buffer: the user buffer
2433 * @lenp: the size of the user buffer
2434 * @ppos: file position
2436 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2437 * values from/to the user buffer, treated as an ASCII string.
2439 * This routine will ensure the values are within the range specified by
2440 * table->extra1 (min) and table->extra2 (max).
2442 * Returns 0 on success.
2444 int proc_dointvec_minmax(struct ctl_table *table, int write,
2445 void __user *buffer, size_t *lenp, loff_t *ppos)
2447 struct do_proc_dointvec_minmax_conv_param param = {
2448 .min = (int *) table->extra1,
2449 .max = (int *) table->extra2,
2451 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2452 do_proc_dointvec_minmax_conv, ¶m);
2455 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2456 void __user *buffer,
2457 size_t *lenp, loff_t *ppos,
2458 unsigned long convmul,
2459 unsigned long convdiv)
2461 unsigned long *i, *min, *max;
2462 int vleft, first = 1, err = 0;
2463 unsigned long page = 0;
2467 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2472 i = (unsigned long *) data;
2473 min = (unsigned long *) table->extra1;
2474 max = (unsigned long *) table->extra2;
2475 vleft = table->maxlen / sizeof(unsigned long);
2479 if (left > PAGE_SIZE - 1)
2480 left = PAGE_SIZE - 1;
2481 page = __get_free_page(GFP_TEMPORARY);
2482 kbuf = (char *) page;
2485 if (copy_from_user(kbuf, buffer, left)) {
2492 for (; left && vleft--; i++, min++, max++, first=0) {
2498 left -= proc_skip_spaces(&kbuf);
2500 err = proc_get_long(&kbuf, &left, &val, &neg,
2502 sizeof(proc_wspace_sep), NULL);
2507 if ((min && val < *min) || (max && val > *max))
2511 val = convdiv * (*i) / convmul;
2513 err = proc_put_char(&buffer, &left, '\t');
2514 err = proc_put_long(&buffer, &left, val, false);
2520 if (!write && !first && left && !err)
2521 err = proc_put_char(&buffer, &left, '\n');
2523 left -= proc_skip_spaces(&kbuf);
2528 return err ? : -EINVAL;
2535 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2536 void __user *buffer,
2537 size_t *lenp, loff_t *ppos,
2538 unsigned long convmul,
2539 unsigned long convdiv)
2541 return __do_proc_doulongvec_minmax(table->data, table, write,
2542 buffer, lenp, ppos, convmul, convdiv);
2546 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2547 * @table: the sysctl table
2548 * @write: %TRUE if this is a write to the sysctl file
2549 * @buffer: the user buffer
2550 * @lenp: the size of the user buffer
2551 * @ppos: file position
2553 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2554 * values from/to the user buffer, treated as an ASCII string.
2556 * This routine will ensure the values are within the range specified by
2557 * table->extra1 (min) and table->extra2 (max).
2559 * Returns 0 on success.
2561 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2562 void __user *buffer, size_t *lenp, loff_t *ppos)
2564 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2568 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2569 * @table: the sysctl table
2570 * @write: %TRUE if this is a write to the sysctl file
2571 * @buffer: the user buffer
2572 * @lenp: the size of the user buffer
2573 * @ppos: file position
2575 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2576 * values from/to the user buffer, treated as an ASCII string. The values
2577 * are treated as milliseconds, and converted to jiffies when they are stored.
2579 * This routine will ensure the values are within the range specified by
2580 * table->extra1 (min) and table->extra2 (max).
2582 * Returns 0 on success.
2584 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2585 void __user *buffer,
2586 size_t *lenp, loff_t *ppos)
2588 return do_proc_doulongvec_minmax(table, write, buffer,
2589 lenp, ppos, HZ, 1000l);
2593 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2595 int write, void *data)
2598 if (*lvalp > LONG_MAX / HZ)
2600 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2606 lval = (unsigned long)-val;
2609 lval = (unsigned long)val;
2616 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2618 int write, void *data)
2621 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2623 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2629 lval = (unsigned long)-val;
2632 lval = (unsigned long)val;
2634 *lvalp = jiffies_to_clock_t(lval);
2639 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2641 int write, void *data)
2644 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2650 lval = (unsigned long)-val;
2653 lval = (unsigned long)val;
2655 *lvalp = jiffies_to_msecs(lval);
2661 * proc_dointvec_jiffies - read a vector of integers as seconds
2662 * @table: the sysctl table
2663 * @write: %TRUE if this is a write to the sysctl file
2664 * @buffer: the user buffer
2665 * @lenp: the size of the user buffer
2666 * @ppos: file position
2668 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2669 * values from/to the user buffer, treated as an ASCII string.
2670 * The values read are assumed to be in seconds, and are converted into
2673 * Returns 0 on success.
2675 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2676 void __user *buffer, size_t *lenp, loff_t *ppos)
2678 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2679 do_proc_dointvec_jiffies_conv,NULL);
2683 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2684 * @table: the sysctl table
2685 * @write: %TRUE if this is a write to the sysctl file
2686 * @buffer: the user buffer
2687 * @lenp: the size of the user buffer
2688 * @ppos: pointer to the file position
2690 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2691 * values from/to the user buffer, treated as an ASCII string.
2692 * The values read are assumed to be in 1/USER_HZ seconds, and
2693 * are converted into jiffies.
2695 * Returns 0 on success.
2697 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2698 void __user *buffer, size_t *lenp, loff_t *ppos)
2700 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2701 do_proc_dointvec_userhz_jiffies_conv,NULL);
2705 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2706 * @table: the sysctl table
2707 * @write: %TRUE if this is a write to the sysctl file
2708 * @buffer: the user buffer
2709 * @lenp: the size of the user buffer
2710 * @ppos: file position
2711 * @ppos: the current position in the file
2713 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2714 * values from/to the user buffer, treated as an ASCII string.
2715 * The values read are assumed to be in 1/1000 seconds, and
2716 * are converted into jiffies.
2718 * Returns 0 on success.
2720 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2721 void __user *buffer, size_t *lenp, loff_t *ppos)
2723 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2724 do_proc_dointvec_ms_jiffies_conv, NULL);
2727 static int proc_do_cad_pid(struct ctl_table *table, int write,
2728 void __user *buffer, size_t *lenp, loff_t *ppos)
2730 struct pid *new_pid;
2734 tmp = pid_vnr(cad_pid);
2736 r = __do_proc_dointvec(&tmp, table, write, buffer,
2737 lenp, ppos, NULL, NULL);
2741 new_pid = find_get_pid(tmp);
2745 put_pid(xchg(&cad_pid, new_pid));
2750 * proc_do_large_bitmap - read/write from/to a large bitmap
2751 * @table: the sysctl table
2752 * @write: %TRUE if this is a write to the sysctl file
2753 * @buffer: the user buffer
2754 * @lenp: the size of the user buffer
2755 * @ppos: file position
2757 * The bitmap is stored at table->data and the bitmap length (in bits)
2760 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2761 * large bitmaps may be represented in a compact manner. Writing into
2762 * the file will clear the bitmap then update it with the given input.
2764 * Returns 0 on success.
2766 int proc_do_large_bitmap(struct ctl_table *table, int write,
2767 void __user *buffer, size_t *lenp, loff_t *ppos)
2771 size_t left = *lenp;
2772 unsigned long bitmap_len = table->maxlen;
2773 unsigned long *bitmap = (unsigned long *) table->data;
2774 unsigned long *tmp_bitmap = NULL;
2775 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2777 if (!bitmap_len || !left || (*ppos && !write)) {
2783 unsigned long page = 0;
2786 if (left > PAGE_SIZE - 1)
2787 left = PAGE_SIZE - 1;
2789 page = __get_free_page(GFP_TEMPORARY);
2790 kbuf = (char *) page;
2793 if (copy_from_user(kbuf, buffer, left)) {
2799 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2805 proc_skip_char(&kbuf, &left, '\n');
2806 while (!err && left) {
2807 unsigned long val_a, val_b;
2810 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2814 if (val_a >= bitmap_len || neg) {
2826 err = proc_get_long(&kbuf, &left, &val_b,
2827 &neg, tr_b, sizeof(tr_b),
2831 if (val_b >= bitmap_len || neg ||
2842 while (val_a <= val_b)
2843 set_bit(val_a++, tmp_bitmap);
2846 proc_skip_char(&kbuf, &left, '\n');
2850 unsigned long bit_a, bit_b = 0;
2853 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2854 if (bit_a >= bitmap_len)
2856 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2860 err = proc_put_char(&buffer, &left, ',');
2864 err = proc_put_long(&buffer, &left, bit_a, false);
2867 if (bit_a != bit_b) {
2868 err = proc_put_char(&buffer, &left, '-');
2871 err = proc_put_long(&buffer, &left, bit_b, false);
2879 err = proc_put_char(&buffer, &left, '\n');
2885 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2887 memcpy(bitmap, tmp_bitmap,
2888 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2900 #else /* CONFIG_PROC_FS */
2902 int proc_dostring(struct ctl_table *table, int write,
2903 void __user *buffer, size_t *lenp, loff_t *ppos)
2908 int proc_dointvec(struct ctl_table *table, int write,
2909 void __user *buffer, size_t *lenp, loff_t *ppos)
2914 int proc_dointvec_minmax(struct ctl_table *table, int write,
2915 void __user *buffer, size_t *lenp, loff_t *ppos)
2920 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2921 void __user *buffer, size_t *lenp, loff_t *ppos)
2926 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2927 void __user *buffer, size_t *lenp, loff_t *ppos)
2932 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2933 void __user *buffer, size_t *lenp, loff_t *ppos)
2938 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2939 void __user *buffer, size_t *lenp, loff_t *ppos)
2944 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2945 void __user *buffer,
2946 size_t *lenp, loff_t *ppos)
2952 #endif /* CONFIG_PROC_FS */
2955 * No sense putting this after each symbol definition, twice,
2956 * exception granted :-)
2958 EXPORT_SYMBOL(proc_dointvec);
2959 EXPORT_SYMBOL(proc_dointvec_jiffies);
2960 EXPORT_SYMBOL(proc_dointvec_minmax);
2961 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2962 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2963 EXPORT_SYMBOL(proc_dostring);
2964 EXPORT_SYMBOL(proc_doulongvec_minmax);
2965 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2966 EXPORT_SYMBOL(register_sysctl_table);
2967 EXPORT_SYMBOL(register_sysctl_paths);
2968 EXPORT_SYMBOL(unregister_sysctl_table);