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/hugetlb.h>
41 #include <linux/initrd.h>
42 #include <linux/key.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/vmstat.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/acpi.h>
50 #include <linux/reboot.h>
51 #include <linux/ftrace.h>
52 #include <linux/slow-work.h>
53 #include <linux/perf_event.h>
54 #include <linux/kprobes.h>
56 #include <asm/uaccess.h>
57 #include <asm/processor.h>
61 #include <asm/stacktrace.h>
64 #ifdef CONFIG_BSD_PROCESS_ACCT
65 #include <linux/acct.h>
67 #ifdef CONFIG_RT_MUTEXES
68 #include <linux/rtmutex.h>
70 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
71 #include <linux/lockdep.h>
73 #ifdef CONFIG_CHR_DEV_SG
78 #if defined(CONFIG_SYSCTL)
80 /* External variables not in a header file. */
81 extern int sysctl_overcommit_memory;
82 extern int sysctl_overcommit_ratio;
83 extern int sysctl_panic_on_oom;
84 extern int sysctl_oom_kill_allocating_task;
85 extern int sysctl_oom_dump_tasks;
86 extern int max_threads;
87 extern int core_uses_pid;
88 extern int suid_dumpable;
89 extern char core_pattern[];
90 extern unsigned int core_pipe_limit;
92 extern int min_free_kbytes;
93 extern int pid_max_min, pid_max_max;
94 extern int sysctl_drop_caches;
95 extern int percpu_pagelist_fraction;
96 extern int compat_log;
97 extern int latencytop_enabled;
98 extern int sysctl_nr_open_min, sysctl_nr_open_max;
100 extern int sysctl_nr_trim_pages;
103 extern int blk_iopoll_enabled;
106 /* Constants used for minimum and maximum */
107 #ifdef CONFIG_DETECT_SOFTLOCKUP
108 static int sixty = 60;
109 static int neg_one = -1;
113 static int __maybe_unused one = 1;
114 static int __maybe_unused two = 2;
115 static unsigned long one_ul = 1;
116 static int one_hundred = 100;
118 static int ten_thousand = 10000;
121 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
122 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
124 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
125 static int maxolduid = 65535;
126 static int minolduid;
127 static int min_percpu_pagelist_fract = 8;
129 static int ngroups_max = NGROUPS_MAX;
132 #include <asm/system.h>
135 #ifdef CONFIG_SPARC64
136 extern int sysctl_tsb_ratio;
140 extern int pwrsw_enabled;
141 extern int unaligned_enabled;
145 #ifdef CONFIG_MATHEMU
146 extern int sysctl_ieee_emulation_warnings;
148 extern int sysctl_userprocess_debug;
149 extern int spin_retry;
153 extern int no_unaligned_warning;
154 extern int unaligned_dump_stack;
157 extern struct ratelimit_state printk_ratelimit_state;
159 #ifdef CONFIG_PROC_SYSCTL
160 static int proc_do_cad_pid(struct ctl_table *table, int write,
161 void __user *buffer, size_t *lenp, loff_t *ppos);
162 static int proc_taint(struct ctl_table *table, int write,
163 void __user *buffer, size_t *lenp, loff_t *ppos);
166 #ifdef CONFIG_MAGIC_SYSRQ
167 static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
169 static int sysrq_sysctl_handler(ctl_table *table, int write,
170 void __user *buffer, size_t *lenp,
175 error = proc_dointvec(table, write, buffer, lenp, ppos);
180 sysrq_toggle_support(__sysrq_enabled);
187 static struct ctl_table root_table[];
188 static struct ctl_table_root sysctl_table_root;
189 static struct ctl_table_header root_table_header = {
191 .ctl_table = root_table,
192 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
193 .root = &sysctl_table_root,
194 .set = &sysctl_table_root.default_set,
196 static struct ctl_table_root sysctl_table_root = {
197 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
198 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
201 static struct ctl_table kern_table[];
202 static struct ctl_table vm_table[];
203 static struct ctl_table fs_table[];
204 static struct ctl_table debug_table[];
205 static struct ctl_table dev_table[];
206 extern struct ctl_table random_table[];
207 #ifdef CONFIG_INOTIFY_USER
208 extern struct ctl_table inotify_table[];
211 extern struct ctl_table epoll_table[];
214 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
215 int sysctl_legacy_va_layout;
218 /* The default sysctl tables: */
220 static struct ctl_table root_table[] = {
222 .procname = "kernel",
239 .child = debug_table,
247 * NOTE: do not add new entries to this table unless you have read
248 * Documentation/sysctl/ctl_unnumbered.txt
253 #ifdef CONFIG_SCHED_DEBUG
254 static int min_sched_granularity_ns = 100000; /* 100 usecs */
255 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
256 static int min_wakeup_granularity_ns; /* 0 usecs */
257 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
258 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
259 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
260 static int min_sched_shares_ratelimit = 100000; /* 100 usec */
261 static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
264 static struct ctl_table kern_table[] = {
266 .procname = "sched_child_runs_first",
267 .data = &sysctl_sched_child_runs_first,
268 .maxlen = sizeof(unsigned int),
270 .proc_handler = proc_dointvec,
272 #ifdef CONFIG_SCHED_DEBUG
274 .procname = "sched_min_granularity_ns",
275 .data = &sysctl_sched_min_granularity,
276 .maxlen = sizeof(unsigned int),
278 .proc_handler = sched_proc_update_handler,
279 .extra1 = &min_sched_granularity_ns,
280 .extra2 = &max_sched_granularity_ns,
283 .procname = "sched_latency_ns",
284 .data = &sysctl_sched_latency,
285 .maxlen = sizeof(unsigned int),
287 .proc_handler = sched_proc_update_handler,
288 .extra1 = &min_sched_granularity_ns,
289 .extra2 = &max_sched_granularity_ns,
292 .procname = "sched_wakeup_granularity_ns",
293 .data = &sysctl_sched_wakeup_granularity,
294 .maxlen = sizeof(unsigned int),
296 .proc_handler = sched_proc_update_handler,
297 .extra1 = &min_wakeup_granularity_ns,
298 .extra2 = &max_wakeup_granularity_ns,
301 .procname = "sched_shares_ratelimit",
302 .data = &sysctl_sched_shares_ratelimit,
303 .maxlen = sizeof(unsigned int),
305 .proc_handler = sched_proc_update_handler,
306 .extra1 = &min_sched_shares_ratelimit,
307 .extra2 = &max_sched_shares_ratelimit,
310 .procname = "sched_tunable_scaling",
311 .data = &sysctl_sched_tunable_scaling,
312 .maxlen = sizeof(enum sched_tunable_scaling),
314 .proc_handler = sched_proc_update_handler,
315 .extra1 = &min_sched_tunable_scaling,
316 .extra2 = &max_sched_tunable_scaling,
319 .procname = "sched_shares_thresh",
320 .data = &sysctl_sched_shares_thresh,
321 .maxlen = sizeof(unsigned int),
323 .proc_handler = proc_dointvec_minmax,
327 .procname = "sched_migration_cost",
328 .data = &sysctl_sched_migration_cost,
329 .maxlen = sizeof(unsigned int),
331 .proc_handler = proc_dointvec,
334 .procname = "sched_nr_migrate",
335 .data = &sysctl_sched_nr_migrate,
336 .maxlen = sizeof(unsigned int),
338 .proc_handler = proc_dointvec,
341 .procname = "sched_time_avg",
342 .data = &sysctl_sched_time_avg,
343 .maxlen = sizeof(unsigned int),
345 .proc_handler = proc_dointvec,
348 .procname = "timer_migration",
349 .data = &sysctl_timer_migration,
350 .maxlen = sizeof(unsigned int),
352 .proc_handler = proc_dointvec_minmax,
358 .procname = "sched_rt_period_us",
359 .data = &sysctl_sched_rt_period,
360 .maxlen = sizeof(unsigned int),
362 .proc_handler = sched_rt_handler,
365 .procname = "sched_rt_runtime_us",
366 .data = &sysctl_sched_rt_runtime,
367 .maxlen = sizeof(int),
369 .proc_handler = sched_rt_handler,
372 .procname = "sched_compat_yield",
373 .data = &sysctl_sched_compat_yield,
374 .maxlen = sizeof(unsigned int),
376 .proc_handler = proc_dointvec,
378 #ifdef CONFIG_PROVE_LOCKING
380 .procname = "prove_locking",
381 .data = &prove_locking,
382 .maxlen = sizeof(int),
384 .proc_handler = proc_dointvec,
387 #ifdef CONFIG_LOCK_STAT
389 .procname = "lock_stat",
391 .maxlen = sizeof(int),
393 .proc_handler = proc_dointvec,
398 .data = &panic_timeout,
399 .maxlen = sizeof(int),
401 .proc_handler = proc_dointvec,
404 .procname = "core_uses_pid",
405 .data = &core_uses_pid,
406 .maxlen = sizeof(int),
408 .proc_handler = proc_dointvec,
411 .procname = "core_pattern",
412 .data = core_pattern,
413 .maxlen = CORENAME_MAX_SIZE,
415 .proc_handler = proc_dostring,
418 .procname = "core_pipe_limit",
419 .data = &core_pipe_limit,
420 .maxlen = sizeof(unsigned int),
422 .proc_handler = proc_dointvec,
424 #ifdef CONFIG_PROC_SYSCTL
426 .procname = "tainted",
427 .maxlen = sizeof(long),
429 .proc_handler = proc_taint,
432 #ifdef CONFIG_LATENCYTOP
434 .procname = "latencytop",
435 .data = &latencytop_enabled,
436 .maxlen = sizeof(int),
438 .proc_handler = proc_dointvec,
441 #ifdef CONFIG_BLK_DEV_INITRD
443 .procname = "real-root-dev",
444 .data = &real_root_dev,
445 .maxlen = sizeof(int),
447 .proc_handler = proc_dointvec,
451 .procname = "print-fatal-signals",
452 .data = &print_fatal_signals,
453 .maxlen = sizeof(int),
455 .proc_handler = proc_dointvec,
459 .procname = "reboot-cmd",
460 .data = reboot_command,
463 .proc_handler = proc_dostring,
466 .procname = "stop-a",
467 .data = &stop_a_enabled,
468 .maxlen = sizeof (int),
470 .proc_handler = proc_dointvec,
473 .procname = "scons-poweroff",
474 .data = &scons_pwroff,
475 .maxlen = sizeof (int),
477 .proc_handler = proc_dointvec,
480 #ifdef CONFIG_SPARC64
482 .procname = "tsb-ratio",
483 .data = &sysctl_tsb_ratio,
484 .maxlen = sizeof (int),
486 .proc_handler = proc_dointvec,
491 .procname = "soft-power",
492 .data = &pwrsw_enabled,
493 .maxlen = sizeof (int),
495 .proc_handler = proc_dointvec,
498 .procname = "unaligned-trap",
499 .data = &unaligned_enabled,
500 .maxlen = sizeof (int),
502 .proc_handler = proc_dointvec,
506 .procname = "ctrl-alt-del",
508 .maxlen = sizeof(int),
510 .proc_handler = proc_dointvec,
512 #ifdef CONFIG_FUNCTION_TRACER
514 .procname = "ftrace_enabled",
515 .data = &ftrace_enabled,
516 .maxlen = sizeof(int),
518 .proc_handler = ftrace_enable_sysctl,
521 #ifdef CONFIG_STACK_TRACER
523 .procname = "stack_tracer_enabled",
524 .data = &stack_tracer_enabled,
525 .maxlen = sizeof(int),
527 .proc_handler = stack_trace_sysctl,
530 #ifdef CONFIG_TRACING
532 .procname = "ftrace_dump_on_oops",
533 .data = &ftrace_dump_on_oops,
534 .maxlen = sizeof(int),
536 .proc_handler = proc_dointvec,
539 #ifdef CONFIG_MODULES
541 .procname = "modprobe",
542 .data = &modprobe_path,
543 .maxlen = KMOD_PATH_LEN,
545 .proc_handler = proc_dostring,
548 .procname = "modules_disabled",
549 .data = &modules_disabled,
550 .maxlen = sizeof(int),
552 /* only handle a transition from default "0" to "1" */
553 .proc_handler = proc_dointvec_minmax,
558 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
560 .procname = "hotplug",
561 .data = &uevent_helper,
562 .maxlen = UEVENT_HELPER_PATH_LEN,
564 .proc_handler = proc_dostring,
567 #ifdef CONFIG_CHR_DEV_SG
569 .procname = "sg-big-buff",
570 .data = &sg_big_buff,
571 .maxlen = sizeof (int),
573 .proc_handler = proc_dointvec,
576 #ifdef CONFIG_BSD_PROCESS_ACCT
580 .maxlen = 3*sizeof(int),
582 .proc_handler = proc_dointvec,
585 #ifdef CONFIG_MAGIC_SYSRQ
588 .data = &__sysrq_enabled,
589 .maxlen = sizeof (int),
591 .proc_handler = sysrq_sysctl_handler,
594 #ifdef CONFIG_PROC_SYSCTL
596 .procname = "cad_pid",
598 .maxlen = sizeof (int),
600 .proc_handler = proc_do_cad_pid,
604 .procname = "threads-max",
605 .data = &max_threads,
606 .maxlen = sizeof(int),
608 .proc_handler = proc_dointvec,
611 .procname = "random",
613 .child = random_table,
616 .procname = "overflowuid",
617 .data = &overflowuid,
618 .maxlen = sizeof(int),
620 .proc_handler = proc_dointvec_minmax,
621 .extra1 = &minolduid,
622 .extra2 = &maxolduid,
625 .procname = "overflowgid",
626 .data = &overflowgid,
627 .maxlen = sizeof(int),
629 .proc_handler = proc_dointvec_minmax,
630 .extra1 = &minolduid,
631 .extra2 = &maxolduid,
634 #ifdef CONFIG_MATHEMU
636 .procname = "ieee_emulation_warnings",
637 .data = &sysctl_ieee_emulation_warnings,
638 .maxlen = sizeof(int),
640 .proc_handler = proc_dointvec,
644 .procname = "userprocess_debug",
645 .data = &sysctl_userprocess_debug,
646 .maxlen = sizeof(int),
648 .proc_handler = proc_dointvec,
652 .procname = "pid_max",
654 .maxlen = sizeof (int),
656 .proc_handler = proc_dointvec_minmax,
657 .extra1 = &pid_max_min,
658 .extra2 = &pid_max_max,
661 .procname = "panic_on_oops",
662 .data = &panic_on_oops,
663 .maxlen = sizeof(int),
665 .proc_handler = proc_dointvec,
667 #if defined CONFIG_PRINTK
669 .procname = "printk",
670 .data = &console_loglevel,
671 .maxlen = 4*sizeof(int),
673 .proc_handler = proc_dointvec,
676 .procname = "printk_ratelimit",
677 .data = &printk_ratelimit_state.interval,
678 .maxlen = sizeof(int),
680 .proc_handler = proc_dointvec_jiffies,
683 .procname = "printk_ratelimit_burst",
684 .data = &printk_ratelimit_state.burst,
685 .maxlen = sizeof(int),
687 .proc_handler = proc_dointvec,
690 .procname = "printk_delay",
691 .data = &printk_delay_msec,
692 .maxlen = sizeof(int),
694 .proc_handler = proc_dointvec_minmax,
696 .extra2 = &ten_thousand,
700 .procname = "ngroups_max",
701 .data = &ngroups_max,
702 .maxlen = sizeof (int),
704 .proc_handler = proc_dointvec,
706 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
708 .procname = "unknown_nmi_panic",
709 .data = &unknown_nmi_panic,
710 .maxlen = sizeof (int),
712 .proc_handler = proc_dointvec,
715 .procname = "nmi_watchdog",
716 .data = &nmi_watchdog_enabled,
717 .maxlen = sizeof (int),
719 .proc_handler = proc_nmi_enabled,
722 #if defined(CONFIG_X86)
724 .procname = "panic_on_unrecovered_nmi",
725 .data = &panic_on_unrecovered_nmi,
726 .maxlen = sizeof(int),
728 .proc_handler = proc_dointvec,
731 .procname = "panic_on_io_nmi",
732 .data = &panic_on_io_nmi,
733 .maxlen = sizeof(int),
735 .proc_handler = proc_dointvec,
738 .procname = "bootloader_type",
739 .data = &bootloader_type,
740 .maxlen = sizeof (int),
742 .proc_handler = proc_dointvec,
745 .procname = "bootloader_version",
746 .data = &bootloader_version,
747 .maxlen = sizeof (int),
749 .proc_handler = proc_dointvec,
752 .procname = "kstack_depth_to_print",
753 .data = &kstack_depth_to_print,
754 .maxlen = sizeof(int),
756 .proc_handler = proc_dointvec,
759 .procname = "io_delay_type",
760 .data = &io_delay_type,
761 .maxlen = sizeof(int),
763 .proc_handler = proc_dointvec,
766 #if defined(CONFIG_MMU)
768 .procname = "randomize_va_space",
769 .data = &randomize_va_space,
770 .maxlen = sizeof(int),
772 .proc_handler = proc_dointvec,
775 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
777 .procname = "spin_retry",
779 .maxlen = sizeof (int),
781 .proc_handler = proc_dointvec,
784 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
786 .procname = "acpi_video_flags",
787 .data = &acpi_realmode_flags,
788 .maxlen = sizeof (unsigned long),
790 .proc_handler = proc_doulongvec_minmax,
795 .procname = "ignore-unaligned-usertrap",
796 .data = &no_unaligned_warning,
797 .maxlen = sizeof (int),
799 .proc_handler = proc_dointvec,
802 .procname = "unaligned-dump-stack",
803 .data = &unaligned_dump_stack,
804 .maxlen = sizeof (int),
806 .proc_handler = proc_dointvec,
809 #ifdef CONFIG_DETECT_SOFTLOCKUP
811 .procname = "softlockup_panic",
812 .data = &softlockup_panic,
813 .maxlen = sizeof(int),
815 .proc_handler = proc_dointvec_minmax,
820 .procname = "softlockup_thresh",
821 .data = &softlockup_thresh,
822 .maxlen = sizeof(int),
824 .proc_handler = proc_dosoftlockup_thresh,
829 #ifdef CONFIG_DETECT_HUNG_TASK
831 .procname = "hung_task_panic",
832 .data = &sysctl_hung_task_panic,
833 .maxlen = sizeof(int),
835 .proc_handler = proc_dointvec_minmax,
840 .procname = "hung_task_check_count",
841 .data = &sysctl_hung_task_check_count,
842 .maxlen = sizeof(unsigned long),
844 .proc_handler = proc_doulongvec_minmax,
847 .procname = "hung_task_timeout_secs",
848 .data = &sysctl_hung_task_timeout_secs,
849 .maxlen = sizeof(unsigned long),
851 .proc_handler = proc_dohung_task_timeout_secs,
854 .procname = "hung_task_warnings",
855 .data = &sysctl_hung_task_warnings,
856 .maxlen = sizeof(unsigned long),
858 .proc_handler = proc_doulongvec_minmax,
863 .procname = "compat-log",
865 .maxlen = sizeof (int),
867 .proc_handler = proc_dointvec,
870 #ifdef CONFIG_RT_MUTEXES
872 .procname = "max_lock_depth",
873 .data = &max_lock_depth,
874 .maxlen = sizeof(int),
876 .proc_handler = proc_dointvec,
880 .procname = "poweroff_cmd",
881 .data = &poweroff_cmd,
882 .maxlen = POWEROFF_CMD_PATH_LEN,
884 .proc_handler = proc_dostring,
890 .child = key_sysctls,
893 #ifdef CONFIG_RCU_TORTURE_TEST
895 .procname = "rcutorture_runnable",
896 .data = &rcutorture_runnable,
897 .maxlen = sizeof(int),
899 .proc_handler = proc_dointvec,
902 #ifdef CONFIG_SLOW_WORK
904 .procname = "slow-work",
906 .child = slow_work_sysctls,
909 #ifdef CONFIG_PERF_EVENTS
911 .procname = "perf_event_paranoid",
912 .data = &sysctl_perf_event_paranoid,
913 .maxlen = sizeof(sysctl_perf_event_paranoid),
915 .proc_handler = proc_dointvec,
918 .procname = "perf_event_mlock_kb",
919 .data = &sysctl_perf_event_mlock,
920 .maxlen = sizeof(sysctl_perf_event_mlock),
922 .proc_handler = proc_dointvec,
925 .procname = "perf_event_max_sample_rate",
926 .data = &sysctl_perf_event_sample_rate,
927 .maxlen = sizeof(sysctl_perf_event_sample_rate),
929 .proc_handler = proc_dointvec,
932 #ifdef CONFIG_KMEMCHECK
934 .procname = "kmemcheck",
935 .data = &kmemcheck_enabled,
936 .maxlen = sizeof(int),
938 .proc_handler = proc_dointvec,
943 .procname = "blk_iopoll",
944 .data = &blk_iopoll_enabled,
945 .maxlen = sizeof(int),
947 .proc_handler = proc_dointvec,
951 * NOTE: do not add new entries to this table unless you have read
952 * Documentation/sysctl/ctl_unnumbered.txt
957 static struct ctl_table vm_table[] = {
959 .procname = "overcommit_memory",
960 .data = &sysctl_overcommit_memory,
961 .maxlen = sizeof(sysctl_overcommit_memory),
963 .proc_handler = proc_dointvec,
966 .procname = "panic_on_oom",
967 .data = &sysctl_panic_on_oom,
968 .maxlen = sizeof(sysctl_panic_on_oom),
970 .proc_handler = proc_dointvec,
973 .procname = "oom_kill_allocating_task",
974 .data = &sysctl_oom_kill_allocating_task,
975 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
977 .proc_handler = proc_dointvec,
980 .procname = "oom_dump_tasks",
981 .data = &sysctl_oom_dump_tasks,
982 .maxlen = sizeof(sysctl_oom_dump_tasks),
984 .proc_handler = proc_dointvec,
987 .procname = "overcommit_ratio",
988 .data = &sysctl_overcommit_ratio,
989 .maxlen = sizeof(sysctl_overcommit_ratio),
991 .proc_handler = proc_dointvec,
994 .procname = "page-cluster",
995 .data = &page_cluster,
996 .maxlen = sizeof(int),
998 .proc_handler = proc_dointvec,
1001 .procname = "dirty_background_ratio",
1002 .data = &dirty_background_ratio,
1003 .maxlen = sizeof(dirty_background_ratio),
1005 .proc_handler = dirty_background_ratio_handler,
1007 .extra2 = &one_hundred,
1010 .procname = "dirty_background_bytes",
1011 .data = &dirty_background_bytes,
1012 .maxlen = sizeof(dirty_background_bytes),
1014 .proc_handler = dirty_background_bytes_handler,
1018 .procname = "dirty_ratio",
1019 .data = &vm_dirty_ratio,
1020 .maxlen = sizeof(vm_dirty_ratio),
1022 .proc_handler = dirty_ratio_handler,
1024 .extra2 = &one_hundred,
1027 .procname = "dirty_bytes",
1028 .data = &vm_dirty_bytes,
1029 .maxlen = sizeof(vm_dirty_bytes),
1031 .proc_handler = dirty_bytes_handler,
1032 .extra1 = &dirty_bytes_min,
1035 .procname = "dirty_writeback_centisecs",
1036 .data = &dirty_writeback_interval,
1037 .maxlen = sizeof(dirty_writeback_interval),
1039 .proc_handler = dirty_writeback_centisecs_handler,
1042 .procname = "dirty_expire_centisecs",
1043 .data = &dirty_expire_interval,
1044 .maxlen = sizeof(dirty_expire_interval),
1046 .proc_handler = proc_dointvec,
1049 .procname = "nr_pdflush_threads",
1050 .data = &nr_pdflush_threads,
1051 .maxlen = sizeof nr_pdflush_threads,
1052 .mode = 0444 /* read-only*/,
1053 .proc_handler = proc_dointvec,
1056 .procname = "swappiness",
1057 .data = &vm_swappiness,
1058 .maxlen = sizeof(vm_swappiness),
1060 .proc_handler = proc_dointvec_minmax,
1062 .extra2 = &one_hundred,
1064 #ifdef CONFIG_HUGETLB_PAGE
1066 .procname = "nr_hugepages",
1068 .maxlen = sizeof(unsigned long),
1070 .proc_handler = hugetlb_sysctl_handler,
1071 .extra1 = (void *)&hugetlb_zero,
1072 .extra2 = (void *)&hugetlb_infinity,
1076 .procname = "nr_hugepages_mempolicy",
1078 .maxlen = sizeof(unsigned long),
1080 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1081 .extra1 = (void *)&hugetlb_zero,
1082 .extra2 = (void *)&hugetlb_infinity,
1086 .procname = "hugetlb_shm_group",
1087 .data = &sysctl_hugetlb_shm_group,
1088 .maxlen = sizeof(gid_t),
1090 .proc_handler = proc_dointvec,
1093 .procname = "hugepages_treat_as_movable",
1094 .data = &hugepages_treat_as_movable,
1095 .maxlen = sizeof(int),
1097 .proc_handler = hugetlb_treat_movable_handler,
1100 .procname = "nr_overcommit_hugepages",
1102 .maxlen = sizeof(unsigned long),
1104 .proc_handler = hugetlb_overcommit_handler,
1105 .extra1 = (void *)&hugetlb_zero,
1106 .extra2 = (void *)&hugetlb_infinity,
1110 .procname = "lowmem_reserve_ratio",
1111 .data = &sysctl_lowmem_reserve_ratio,
1112 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1114 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1117 .procname = "drop_caches",
1118 .data = &sysctl_drop_caches,
1119 .maxlen = sizeof(int),
1121 .proc_handler = drop_caches_sysctl_handler,
1124 .procname = "min_free_kbytes",
1125 .data = &min_free_kbytes,
1126 .maxlen = sizeof(min_free_kbytes),
1128 .proc_handler = min_free_kbytes_sysctl_handler,
1132 .procname = "percpu_pagelist_fraction",
1133 .data = &percpu_pagelist_fraction,
1134 .maxlen = sizeof(percpu_pagelist_fraction),
1136 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1137 .extra1 = &min_percpu_pagelist_fract,
1141 .procname = "max_map_count",
1142 .data = &sysctl_max_map_count,
1143 .maxlen = sizeof(sysctl_max_map_count),
1145 .proc_handler = proc_dointvec_minmax,
1150 .procname = "nr_trim_pages",
1151 .data = &sysctl_nr_trim_pages,
1152 .maxlen = sizeof(sysctl_nr_trim_pages),
1154 .proc_handler = proc_dointvec_minmax,
1159 .procname = "laptop_mode",
1160 .data = &laptop_mode,
1161 .maxlen = sizeof(laptop_mode),
1163 .proc_handler = proc_dointvec_jiffies,
1166 .procname = "block_dump",
1167 .data = &block_dump,
1168 .maxlen = sizeof(block_dump),
1170 .proc_handler = proc_dointvec,
1174 .procname = "vfs_cache_pressure",
1175 .data = &sysctl_vfs_cache_pressure,
1176 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1178 .proc_handler = proc_dointvec,
1181 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1183 .procname = "legacy_va_layout",
1184 .data = &sysctl_legacy_va_layout,
1185 .maxlen = sizeof(sysctl_legacy_va_layout),
1187 .proc_handler = proc_dointvec,
1193 .procname = "zone_reclaim_mode",
1194 .data = &zone_reclaim_mode,
1195 .maxlen = sizeof(zone_reclaim_mode),
1197 .proc_handler = proc_dointvec,
1201 .procname = "min_unmapped_ratio",
1202 .data = &sysctl_min_unmapped_ratio,
1203 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1205 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1207 .extra2 = &one_hundred,
1210 .procname = "min_slab_ratio",
1211 .data = &sysctl_min_slab_ratio,
1212 .maxlen = sizeof(sysctl_min_slab_ratio),
1214 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1216 .extra2 = &one_hundred,
1221 .procname = "stat_interval",
1222 .data = &sysctl_stat_interval,
1223 .maxlen = sizeof(sysctl_stat_interval),
1225 .proc_handler = proc_dointvec_jiffies,
1230 .procname = "mmap_min_addr",
1231 .data = &dac_mmap_min_addr,
1232 .maxlen = sizeof(unsigned long),
1234 .proc_handler = mmap_min_addr_handler,
1239 .procname = "numa_zonelist_order",
1240 .data = &numa_zonelist_order,
1241 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1243 .proc_handler = numa_zonelist_order_handler,
1246 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1247 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1249 .procname = "vdso_enabled",
1250 .data = &vdso_enabled,
1251 .maxlen = sizeof(vdso_enabled),
1253 .proc_handler = proc_dointvec,
1257 #ifdef CONFIG_HIGHMEM
1259 .procname = "highmem_is_dirtyable",
1260 .data = &vm_highmem_is_dirtyable,
1261 .maxlen = sizeof(vm_highmem_is_dirtyable),
1263 .proc_handler = proc_dointvec_minmax,
1269 .procname = "scan_unevictable_pages",
1270 .data = &scan_unevictable_pages,
1271 .maxlen = sizeof(scan_unevictable_pages),
1273 .proc_handler = scan_unevictable_handler,
1275 #ifdef CONFIG_MEMORY_FAILURE
1277 .procname = "memory_failure_early_kill",
1278 .data = &sysctl_memory_failure_early_kill,
1279 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1281 .proc_handler = proc_dointvec_minmax,
1286 .procname = "memory_failure_recovery",
1287 .data = &sysctl_memory_failure_recovery,
1288 .maxlen = sizeof(sysctl_memory_failure_recovery),
1290 .proc_handler = proc_dointvec_minmax,
1297 * NOTE: do not add new entries to this table unless you have read
1298 * Documentation/sysctl/ctl_unnumbered.txt
1303 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1304 static struct ctl_table binfmt_misc_table[] = {
1309 static struct ctl_table fs_table[] = {
1311 .procname = "inode-nr",
1312 .data = &inodes_stat,
1313 .maxlen = 2*sizeof(int),
1315 .proc_handler = proc_dointvec,
1318 .procname = "inode-state",
1319 .data = &inodes_stat,
1320 .maxlen = 7*sizeof(int),
1322 .proc_handler = proc_dointvec,
1325 .procname = "file-nr",
1326 .data = &files_stat,
1327 .maxlen = 3*sizeof(int),
1329 .proc_handler = proc_nr_files,
1332 .procname = "file-max",
1333 .data = &files_stat.max_files,
1334 .maxlen = sizeof(int),
1336 .proc_handler = proc_dointvec,
1339 .procname = "nr_open",
1340 .data = &sysctl_nr_open,
1341 .maxlen = sizeof(int),
1343 .proc_handler = proc_dointvec_minmax,
1344 .extra1 = &sysctl_nr_open_min,
1345 .extra2 = &sysctl_nr_open_max,
1348 .procname = "dentry-state",
1349 .data = &dentry_stat,
1350 .maxlen = 6*sizeof(int),
1352 .proc_handler = proc_dointvec,
1355 .procname = "overflowuid",
1356 .data = &fs_overflowuid,
1357 .maxlen = sizeof(int),
1359 .proc_handler = proc_dointvec_minmax,
1360 .extra1 = &minolduid,
1361 .extra2 = &maxolduid,
1364 .procname = "overflowgid",
1365 .data = &fs_overflowgid,
1366 .maxlen = sizeof(int),
1368 .proc_handler = proc_dointvec_minmax,
1369 .extra1 = &minolduid,
1370 .extra2 = &maxolduid,
1372 #ifdef CONFIG_FILE_LOCKING
1374 .procname = "leases-enable",
1375 .data = &leases_enable,
1376 .maxlen = sizeof(int),
1378 .proc_handler = proc_dointvec,
1381 #ifdef CONFIG_DNOTIFY
1383 .procname = "dir-notify-enable",
1384 .data = &dir_notify_enable,
1385 .maxlen = sizeof(int),
1387 .proc_handler = proc_dointvec,
1391 #ifdef CONFIG_FILE_LOCKING
1393 .procname = "lease-break-time",
1394 .data = &lease_break_time,
1395 .maxlen = sizeof(int),
1397 .proc_handler = proc_dointvec,
1402 .procname = "aio-nr",
1404 .maxlen = sizeof(aio_nr),
1406 .proc_handler = proc_doulongvec_minmax,
1409 .procname = "aio-max-nr",
1410 .data = &aio_max_nr,
1411 .maxlen = sizeof(aio_max_nr),
1413 .proc_handler = proc_doulongvec_minmax,
1415 #endif /* CONFIG_AIO */
1416 #ifdef CONFIG_INOTIFY_USER
1418 .procname = "inotify",
1420 .child = inotify_table,
1425 .procname = "epoll",
1427 .child = epoll_table,
1432 .procname = "suid_dumpable",
1433 .data = &suid_dumpable,
1434 .maxlen = sizeof(int),
1436 .proc_handler = proc_dointvec_minmax,
1440 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1442 .procname = "binfmt_misc",
1444 .child = binfmt_misc_table,
1448 * NOTE: do not add new entries to this table unless you have read
1449 * Documentation/sysctl/ctl_unnumbered.txt
1454 static struct ctl_table debug_table[] = {
1455 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
1457 .procname = "exception-trace",
1458 .data = &show_unhandled_signals,
1459 .maxlen = sizeof(int),
1461 .proc_handler = proc_dointvec
1464 #if defined(CONFIG_OPTPROBES)
1466 .procname = "kprobes-optimization",
1467 .data = &sysctl_kprobes_optimization,
1468 .maxlen = sizeof(int),
1470 .proc_handler = proc_kprobes_optimization_handler,
1478 static struct ctl_table dev_table[] = {
1482 static DEFINE_SPINLOCK(sysctl_lock);
1484 /* called under sysctl_lock */
1485 static int use_table(struct ctl_table_header *p)
1487 if (unlikely(p->unregistering))
1493 /* called under sysctl_lock */
1494 static void unuse_table(struct ctl_table_header *p)
1497 if (unlikely(p->unregistering))
1498 complete(p->unregistering);
1501 /* called under sysctl_lock, will reacquire if has to wait */
1502 static void start_unregistering(struct ctl_table_header *p)
1505 * if p->used is 0, nobody will ever touch that entry again;
1506 * we'll eliminate all paths to it before dropping sysctl_lock
1508 if (unlikely(p->used)) {
1509 struct completion wait;
1510 init_completion(&wait);
1511 p->unregistering = &wait;
1512 spin_unlock(&sysctl_lock);
1513 wait_for_completion(&wait);
1514 spin_lock(&sysctl_lock);
1516 /* anything non-NULL; we'll never dereference it */
1517 p->unregistering = ERR_PTR(-EINVAL);
1520 * do not remove from the list until nobody holds it; walking the
1521 * list in do_sysctl() relies on that.
1523 list_del_init(&p->ctl_entry);
1526 void sysctl_head_get(struct ctl_table_header *head)
1528 spin_lock(&sysctl_lock);
1530 spin_unlock(&sysctl_lock);
1533 void sysctl_head_put(struct ctl_table_header *head)
1535 spin_lock(&sysctl_lock);
1538 spin_unlock(&sysctl_lock);
1541 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1545 spin_lock(&sysctl_lock);
1546 if (!use_table(head))
1547 head = ERR_PTR(-ENOENT);
1548 spin_unlock(&sysctl_lock);
1552 void sysctl_head_finish(struct ctl_table_header *head)
1556 spin_lock(&sysctl_lock);
1558 spin_unlock(&sysctl_lock);
1561 static struct ctl_table_set *
1562 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1564 struct ctl_table_set *set = &root->default_set;
1566 set = root->lookup(root, namespaces);
1570 static struct list_head *
1571 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1573 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1577 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1578 struct ctl_table_header *prev)
1580 struct ctl_table_root *root;
1581 struct list_head *header_list;
1582 struct ctl_table_header *head;
1583 struct list_head *tmp;
1585 spin_lock(&sysctl_lock);
1588 tmp = &prev->ctl_entry;
1592 tmp = &root_table_header.ctl_entry;
1594 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1596 if (!use_table(head))
1598 spin_unlock(&sysctl_lock);
1603 header_list = lookup_header_list(root, namespaces);
1604 if (tmp != header_list)
1608 root = list_entry(root->root_list.next,
1609 struct ctl_table_root, root_list);
1610 if (root == &sysctl_table_root)
1612 header_list = lookup_header_list(root, namespaces);
1613 } while (list_empty(header_list));
1614 tmp = header_list->next;
1617 spin_unlock(&sysctl_lock);
1621 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1623 return __sysctl_head_next(current->nsproxy, prev);
1626 void register_sysctl_root(struct ctl_table_root *root)
1628 spin_lock(&sysctl_lock);
1629 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1630 spin_unlock(&sysctl_lock);
1634 * sysctl_perm does NOT grant the superuser all rights automatically, because
1635 * some sysctl variables are readonly even to root.
1638 static int test_perm(int mode, int op)
1640 if (!current_euid())
1642 else if (in_egroup_p(0))
1644 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1649 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1654 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1658 if (root->permissions)
1659 mode = root->permissions(root, current->nsproxy, table);
1663 return test_perm(mode, op);
1666 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1668 for (; table->procname; table++) {
1669 table->parent = parent;
1671 sysctl_set_parent(table, table->child);
1675 static __init int sysctl_init(void)
1677 sysctl_set_parent(NULL, root_table);
1678 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1681 err = sysctl_check_table(current->nsproxy, root_table);
1687 core_initcall(sysctl_init);
1689 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1690 struct ctl_table *table)
1692 struct ctl_table *p;
1693 const char *s = branch->procname;
1695 /* branch should have named subdirectory as its first element */
1696 if (!s || !branch->child)
1699 /* ... and nothing else */
1700 if (branch[1].procname)
1703 /* table should contain subdirectory with the same name */
1704 for (p = table; p->procname; p++) {
1707 if (p->procname && strcmp(p->procname, s) == 0)
1713 /* see if attaching q to p would be an improvement */
1714 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1716 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1717 struct ctl_table *next;
1719 int not_in_parent = !p->attached_by;
1721 while ((next = is_branch_in(by, to)) != NULL) {
1722 if (by == q->attached_by)
1724 if (to == p->attached_by)
1730 if (is_better && not_in_parent) {
1731 q->attached_by = by;
1732 q->attached_to = to;
1738 * __register_sysctl_paths - register a sysctl hierarchy
1739 * @root: List of sysctl headers to register on
1740 * @namespaces: Data to compute which lists of sysctl entries are visible
1741 * @path: The path to the directory the sysctl table is in.
1742 * @table: the top-level table structure
1744 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1745 * array. A completely 0 filled entry terminates the table.
1747 * The members of the &struct ctl_table structure are used as follows:
1749 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1750 * enter a sysctl file
1752 * data - a pointer to data for use by proc_handler
1754 * maxlen - the maximum size in bytes of the data
1756 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1758 * child - a pointer to the child sysctl table if this entry is a directory, or
1761 * proc_handler - the text handler routine (described below)
1763 * de - for internal use by the sysctl routines
1765 * extra1, extra2 - extra pointers usable by the proc handler routines
1767 * Leaf nodes in the sysctl tree will be represented by a single file
1768 * under /proc; non-leaf nodes will be represented by directories.
1770 * sysctl(2) can automatically manage read and write requests through
1771 * the sysctl table. The data and maxlen fields of the ctl_table
1772 * struct enable minimal validation of the values being written to be
1773 * performed, and the mode field allows minimal authentication.
1775 * There must be a proc_handler routine for any terminal nodes
1776 * mirrored under /proc/sys (non-terminals are handled by a built-in
1777 * directory handler). Several default handlers are available to
1778 * cover common cases -
1780 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1781 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1782 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1784 * It is the handler's job to read the input buffer from user memory
1785 * and process it. The handler should return 0 on success.
1787 * This routine returns %NULL on a failure to register, and a pointer
1788 * to the table header on success.
1790 struct ctl_table_header *__register_sysctl_paths(
1791 struct ctl_table_root *root,
1792 struct nsproxy *namespaces,
1793 const struct ctl_path *path, struct ctl_table *table)
1795 struct ctl_table_header *header;
1796 struct ctl_table *new, **prevp;
1797 unsigned int n, npath;
1798 struct ctl_table_set *set;
1800 /* Count the path components */
1801 for (npath = 0; path[npath].procname; ++npath)
1805 * For each path component, allocate a 2-element ctl_table array.
1806 * The first array element will be filled with the sysctl entry
1807 * for this, the second will be the sentinel (procname == 0).
1809 * We allocate everything in one go so that we don't have to
1810 * worry about freeing additional memory in unregister_sysctl_table.
1812 header = kzalloc(sizeof(struct ctl_table_header) +
1813 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1817 new = (struct ctl_table *) (header + 1);
1819 /* Now connect the dots */
1820 prevp = &header->ctl_table;
1821 for (n = 0; n < npath; ++n, ++path) {
1822 /* Copy the procname */
1823 new->procname = path->procname;
1827 prevp = &new->child;
1832 header->ctl_table_arg = table;
1834 INIT_LIST_HEAD(&header->ctl_entry);
1836 header->unregistering = NULL;
1837 header->root = root;
1838 sysctl_set_parent(NULL, header->ctl_table);
1840 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1841 if (sysctl_check_table(namespaces, header->ctl_table)) {
1846 spin_lock(&sysctl_lock);
1847 header->set = lookup_header_set(root, namespaces);
1848 header->attached_by = header->ctl_table;
1849 header->attached_to = root_table;
1850 header->parent = &root_table_header;
1851 for (set = header->set; set; set = set->parent) {
1852 struct ctl_table_header *p;
1853 list_for_each_entry(p, &set->list, ctl_entry) {
1854 if (p->unregistering)
1856 try_attach(p, header);
1859 header->parent->count++;
1860 list_add_tail(&header->ctl_entry, &header->set->list);
1861 spin_unlock(&sysctl_lock);
1867 * register_sysctl_table_path - register a sysctl table hierarchy
1868 * @path: The path to the directory the sysctl table is in.
1869 * @table: the top-level table structure
1871 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1872 * array. A completely 0 filled entry terminates the table.
1874 * See __register_sysctl_paths for more details.
1876 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1877 struct ctl_table *table)
1879 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1884 * register_sysctl_table - register a sysctl table hierarchy
1885 * @table: the top-level table structure
1887 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1888 * array. A completely 0 filled entry terminates the table.
1890 * See register_sysctl_paths for more details.
1892 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1894 static const struct ctl_path null_path[] = { {} };
1896 return register_sysctl_paths(null_path, table);
1900 * unregister_sysctl_table - unregister a sysctl table hierarchy
1901 * @header: the header returned from register_sysctl_table
1903 * Unregisters the sysctl table and all children. proc entries may not
1904 * actually be removed until they are no longer used by anyone.
1906 void unregister_sysctl_table(struct ctl_table_header * header)
1913 spin_lock(&sysctl_lock);
1914 start_unregistering(header);
1915 if (!--header->parent->count) {
1917 kfree(header->parent);
1919 if (!--header->count)
1921 spin_unlock(&sysctl_lock);
1924 int sysctl_is_seen(struct ctl_table_header *p)
1926 struct ctl_table_set *set = p->set;
1928 spin_lock(&sysctl_lock);
1929 if (p->unregistering)
1931 else if (!set->is_seen)
1934 res = set->is_seen(set);
1935 spin_unlock(&sysctl_lock);
1939 void setup_sysctl_set(struct ctl_table_set *p,
1940 struct ctl_table_set *parent,
1941 int (*is_seen)(struct ctl_table_set *))
1943 INIT_LIST_HEAD(&p->list);
1944 p->parent = parent ? parent : &sysctl_table_root.default_set;
1945 p->is_seen = is_seen;
1948 #else /* !CONFIG_SYSCTL */
1949 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1954 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1955 struct ctl_table *table)
1960 void unregister_sysctl_table(struct ctl_table_header * table)
1964 void setup_sysctl_set(struct ctl_table_set *p,
1965 struct ctl_table_set *parent,
1966 int (*is_seen)(struct ctl_table_set *))
1970 void sysctl_head_put(struct ctl_table_header *head)
1974 #endif /* CONFIG_SYSCTL */
1980 #ifdef CONFIG_PROC_SYSCTL
1982 static int _proc_do_string(void* data, int maxlen, int write,
1983 void __user *buffer,
1984 size_t *lenp, loff_t *ppos)
1990 if (!data || !maxlen || !*lenp) {
1998 while (len < *lenp) {
1999 if (get_user(c, p++))
2001 if (c == 0 || c == '\n')
2007 if(copy_from_user(data, buffer, len))
2009 ((char *) data)[len] = 0;
2027 if(copy_to_user(buffer, data, len))
2030 if(put_user('\n', ((char __user *) buffer) + len))
2041 * proc_dostring - read a string sysctl
2042 * @table: the sysctl table
2043 * @write: %TRUE if this is a write to the sysctl file
2044 * @buffer: the user buffer
2045 * @lenp: the size of the user buffer
2046 * @ppos: file position
2048 * Reads/writes a string from/to the user buffer. If the kernel
2049 * buffer provided is not large enough to hold the string, the
2050 * string is truncated. The copied string is %NULL-terminated.
2051 * If the string is being read by the user process, it is copied
2052 * and a newline '\n' is added. It is truncated if the buffer is
2055 * Returns 0 on success.
2057 int proc_dostring(struct ctl_table *table, int write,
2058 void __user *buffer, size_t *lenp, loff_t *ppos)
2060 return _proc_do_string(table->data, table->maxlen, write,
2061 buffer, lenp, ppos);
2065 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2067 int write, void *data)
2070 *valp = *negp ? -*lvalp : *lvalp;
2075 *lvalp = (unsigned long)-val;
2078 *lvalp = (unsigned long)val;
2084 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2085 int write, void __user *buffer,
2086 size_t *lenp, loff_t *ppos,
2087 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2088 int write, void *data),
2091 #define TMPBUFLEN 21
2092 int *i, vleft, first = 1, neg;
2096 char buf[TMPBUFLEN], *p;
2097 char __user *s = buffer;
2099 if (!tbl_data || !table->maxlen || !*lenp ||
2100 (*ppos && !write)) {
2105 i = (int *) tbl_data;
2106 vleft = table->maxlen / sizeof(*i);
2110 conv = do_proc_dointvec_conv;
2112 for (; left && vleft--; i++, first=0) {
2127 if (len > sizeof(buf) - 1)
2128 len = sizeof(buf) - 1;
2129 if (copy_from_user(buf, s, len))
2133 if (*p == '-' && left > 1) {
2137 if (*p < '0' || *p > '9')
2140 lval = simple_strtoul(p, &p, 0);
2143 if ((len < left) && *p && !isspace(*p))
2148 if (conv(&neg, &lval, i, 1, data))
2155 if (conv(&neg, &lval, i, 0, data))
2158 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2162 if(copy_to_user(s, buf, len))
2169 if (!write && !first && left) {
2170 if(put_user('\n', s))
2177 if (get_user(c, s++))
2192 static int do_proc_dointvec(struct ctl_table *table, int write,
2193 void __user *buffer, size_t *lenp, loff_t *ppos,
2194 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2195 int write, void *data),
2198 return __do_proc_dointvec(table->data, table, write,
2199 buffer, lenp, ppos, conv, data);
2203 * proc_dointvec - read a vector of integers
2204 * @table: the sysctl table
2205 * @write: %TRUE if this is a write to the sysctl file
2206 * @buffer: the user buffer
2207 * @lenp: the size of the user buffer
2208 * @ppos: file position
2210 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2211 * values from/to the user buffer, treated as an ASCII string.
2213 * Returns 0 on success.
2215 int proc_dointvec(struct ctl_table *table, int write,
2216 void __user *buffer, size_t *lenp, loff_t *ppos)
2218 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2223 * Taint values can only be increased
2224 * This means we can safely use a temporary.
2226 static int proc_taint(struct ctl_table *table, int write,
2227 void __user *buffer, size_t *lenp, loff_t *ppos)
2230 unsigned long tmptaint = get_taint();
2233 if (write && !capable(CAP_SYS_ADMIN))
2238 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2244 * Poor man's atomic or. Not worth adding a primitive
2245 * to everyone's atomic.h for this
2248 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2249 if ((tmptaint >> i) & 1)
2257 struct do_proc_dointvec_minmax_conv_param {
2262 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2264 int write, void *data)
2266 struct do_proc_dointvec_minmax_conv_param *param = data;
2268 int val = *negp ? -*lvalp : *lvalp;
2269 if ((param->min && *param->min > val) ||
2270 (param->max && *param->max < val))
2277 *lvalp = (unsigned long)-val;
2280 *lvalp = (unsigned long)val;
2287 * proc_dointvec_minmax - read a vector of integers with min/max values
2288 * @table: the sysctl table
2289 * @write: %TRUE if this is a write to the sysctl file
2290 * @buffer: the user buffer
2291 * @lenp: the size of the user buffer
2292 * @ppos: file position
2294 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2295 * values from/to the user buffer, treated as an ASCII string.
2297 * This routine will ensure the values are within the range specified by
2298 * table->extra1 (min) and table->extra2 (max).
2300 * Returns 0 on success.
2302 int proc_dointvec_minmax(struct ctl_table *table, int write,
2303 void __user *buffer, size_t *lenp, loff_t *ppos)
2305 struct do_proc_dointvec_minmax_conv_param param = {
2306 .min = (int *) table->extra1,
2307 .max = (int *) table->extra2,
2309 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2310 do_proc_dointvec_minmax_conv, ¶m);
2313 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2314 void __user *buffer,
2315 size_t *lenp, loff_t *ppos,
2316 unsigned long convmul,
2317 unsigned long convdiv)
2319 #define TMPBUFLEN 21
2320 unsigned long *i, *min, *max, val;
2321 int vleft, first=1, neg;
2323 char buf[TMPBUFLEN], *p;
2324 char __user *s = buffer;
2326 if (!data || !table->maxlen || !*lenp ||
2327 (*ppos && !write)) {
2332 i = (unsigned long *) data;
2333 min = (unsigned long *) table->extra1;
2334 max = (unsigned long *) table->extra2;
2335 vleft = table->maxlen / sizeof(unsigned long);
2338 for (; left && vleft--; i++, min++, max++, first=0) {
2353 if (len > TMPBUFLEN-1)
2355 if (copy_from_user(buf, s, len))
2359 if (*p == '-' && left > 1) {
2363 if (*p < '0' || *p > '9')
2365 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2367 if ((len < left) && *p && !isspace(*p))
2376 if ((min && val < *min) || (max && val > *max))
2383 sprintf(p, "%lu", convdiv * (*i) / convmul);
2387 if(copy_to_user(s, buf, len))
2394 if (!write && !first && left) {
2395 if(put_user('\n', s))
2402 if (get_user(c, s++))
2417 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2418 void __user *buffer,
2419 size_t *lenp, loff_t *ppos,
2420 unsigned long convmul,
2421 unsigned long convdiv)
2423 return __do_proc_doulongvec_minmax(table->data, table, write,
2424 buffer, lenp, ppos, convmul, convdiv);
2428 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2429 * @table: the sysctl table
2430 * @write: %TRUE if this is a write to the sysctl file
2431 * @buffer: the user buffer
2432 * @lenp: the size of the user buffer
2433 * @ppos: file position
2435 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2436 * values from/to the user buffer, treated as an ASCII string.
2438 * This routine will ensure the values are within the range specified by
2439 * table->extra1 (min) and table->extra2 (max).
2441 * Returns 0 on success.
2443 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2444 void __user *buffer, size_t *lenp, loff_t *ppos)
2446 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2450 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2451 * @table: the sysctl table
2452 * @write: %TRUE if this is a write to the sysctl file
2453 * @buffer: the user buffer
2454 * @lenp: the size of the user buffer
2455 * @ppos: file position
2457 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2458 * values from/to the user buffer, treated as an ASCII string. The values
2459 * are treated as milliseconds, and converted to jiffies when they are stored.
2461 * This routine will ensure the values are within the range specified by
2462 * table->extra1 (min) and table->extra2 (max).
2464 * Returns 0 on success.
2466 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2467 void __user *buffer,
2468 size_t *lenp, loff_t *ppos)
2470 return do_proc_doulongvec_minmax(table, write, buffer,
2471 lenp, ppos, HZ, 1000l);
2475 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2477 int write, void *data)
2480 if (*lvalp > LONG_MAX / HZ)
2482 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2488 lval = (unsigned long)-val;
2491 lval = (unsigned long)val;
2498 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2500 int write, void *data)
2503 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2505 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2511 lval = (unsigned long)-val;
2514 lval = (unsigned long)val;
2516 *lvalp = jiffies_to_clock_t(lval);
2521 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2523 int write, void *data)
2526 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2532 lval = (unsigned long)-val;
2535 lval = (unsigned long)val;
2537 *lvalp = jiffies_to_msecs(lval);
2543 * proc_dointvec_jiffies - read a vector of integers as seconds
2544 * @table: the sysctl table
2545 * @write: %TRUE if this is a write to the sysctl file
2546 * @buffer: the user buffer
2547 * @lenp: the size of the user buffer
2548 * @ppos: file position
2550 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2551 * values from/to the user buffer, treated as an ASCII string.
2552 * The values read are assumed to be in seconds, and are converted into
2555 * Returns 0 on success.
2557 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2558 void __user *buffer, size_t *lenp, loff_t *ppos)
2560 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2561 do_proc_dointvec_jiffies_conv,NULL);
2565 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2566 * @table: the sysctl table
2567 * @write: %TRUE if this is a write to the sysctl file
2568 * @buffer: the user buffer
2569 * @lenp: the size of the user buffer
2570 * @ppos: pointer to the file position
2572 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2573 * values from/to the user buffer, treated as an ASCII string.
2574 * The values read are assumed to be in 1/USER_HZ seconds, and
2575 * are converted into jiffies.
2577 * Returns 0 on success.
2579 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2580 void __user *buffer, size_t *lenp, loff_t *ppos)
2582 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2583 do_proc_dointvec_userhz_jiffies_conv,NULL);
2587 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2588 * @table: the sysctl table
2589 * @write: %TRUE if this is a write to the sysctl file
2590 * @buffer: the user buffer
2591 * @lenp: the size of the user buffer
2592 * @ppos: file position
2593 * @ppos: the current position in the file
2595 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2596 * values from/to the user buffer, treated as an ASCII string.
2597 * The values read are assumed to be in 1/1000 seconds, and
2598 * are converted into jiffies.
2600 * Returns 0 on success.
2602 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2603 void __user *buffer, size_t *lenp, loff_t *ppos)
2605 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2606 do_proc_dointvec_ms_jiffies_conv, NULL);
2609 static int proc_do_cad_pid(struct ctl_table *table, int write,
2610 void __user *buffer, size_t *lenp, loff_t *ppos)
2612 struct pid *new_pid;
2616 tmp = pid_vnr(cad_pid);
2618 r = __do_proc_dointvec(&tmp, table, write, buffer,
2619 lenp, ppos, NULL, NULL);
2623 new_pid = find_get_pid(tmp);
2627 put_pid(xchg(&cad_pid, new_pid));
2631 #else /* CONFIG_PROC_FS */
2633 int proc_dostring(struct ctl_table *table, int write,
2634 void __user *buffer, size_t *lenp, loff_t *ppos)
2639 int proc_dointvec(struct ctl_table *table, int write,
2640 void __user *buffer, size_t *lenp, loff_t *ppos)
2645 int proc_dointvec_minmax(struct ctl_table *table, int write,
2646 void __user *buffer, size_t *lenp, loff_t *ppos)
2651 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2652 void __user *buffer, size_t *lenp, loff_t *ppos)
2657 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2658 void __user *buffer, size_t *lenp, loff_t *ppos)
2663 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2664 void __user *buffer, size_t *lenp, loff_t *ppos)
2669 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2670 void __user *buffer, size_t *lenp, loff_t *ppos)
2675 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2676 void __user *buffer,
2677 size_t *lenp, loff_t *ppos)
2683 #endif /* CONFIG_PROC_FS */
2686 * No sense putting this after each symbol definition, twice,
2687 * exception granted :-)
2689 EXPORT_SYMBOL(proc_dointvec);
2690 EXPORT_SYMBOL(proc_dointvec_jiffies);
2691 EXPORT_SYMBOL(proc_dointvec_minmax);
2692 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2693 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2694 EXPORT_SYMBOL(proc_dostring);
2695 EXPORT_SYMBOL(proc_doulongvec_minmax);
2696 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2697 EXPORT_SYMBOL(register_sysctl_table);
2698 EXPORT_SYMBOL(register_sysctl_paths);
2699 EXPORT_SYMBOL(unregister_sysctl_table);