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
77 #ifdef CONFIG_NMI_WATCHDOG
78 #include <linux/nmi.h>
82 #if defined(CONFIG_SYSCTL)
84 /* External variables not in a header file. */
85 extern int sysctl_overcommit_memory;
86 extern int sysctl_overcommit_ratio;
87 extern int sysctl_panic_on_oom;
88 extern int sysctl_oom_kill_allocating_task;
89 extern int sysctl_oom_dump_tasks;
90 extern int max_threads;
91 extern int core_uses_pid;
92 extern int suid_dumpable;
93 extern char core_pattern[];
94 extern unsigned int core_pipe_limit;
96 extern int min_free_kbytes;
97 extern int pid_max_min, pid_max_max;
98 extern int sysctl_drop_caches;
99 extern int percpu_pagelist_fraction;
100 extern int compat_log;
101 extern int latencytop_enabled;
102 extern int sysctl_nr_open_min, sysctl_nr_open_max;
104 extern int sysctl_nr_trim_pages;
107 extern int blk_iopoll_enabled;
110 /* Constants used for minimum and maximum */
111 #ifdef CONFIG_DETECT_SOFTLOCKUP
112 static int sixty = 60;
113 static int neg_one = -1;
117 static int __maybe_unused one = 1;
118 static int __maybe_unused two = 2;
119 static unsigned long one_ul = 1;
120 static int one_hundred = 100;
122 static int ten_thousand = 10000;
125 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
126 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
128 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
129 static int maxolduid = 65535;
130 static int minolduid;
131 static int min_percpu_pagelist_fract = 8;
133 static int ngroups_max = NGROUPS_MAX;
136 #include <asm/system.h>
139 #ifdef CONFIG_SPARC64
140 extern int sysctl_tsb_ratio;
144 extern int pwrsw_enabled;
145 extern int unaligned_enabled;
149 #ifdef CONFIG_MATHEMU
150 extern int sysctl_ieee_emulation_warnings;
152 extern int sysctl_userprocess_debug;
153 extern int spin_retry;
157 extern int no_unaligned_warning;
158 extern int unaligned_dump_stack;
161 extern struct ratelimit_state printk_ratelimit_state;
163 #ifdef CONFIG_PROC_SYSCTL
164 static int proc_do_cad_pid(struct ctl_table *table, int write,
165 void __user *buffer, size_t *lenp, loff_t *ppos);
166 static int proc_taint(struct ctl_table *table, int write,
167 void __user *buffer, size_t *lenp, loff_t *ppos);
170 static struct ctl_table root_table[];
171 static struct ctl_table_root sysctl_table_root;
172 static struct ctl_table_header root_table_header = {
174 .ctl_table = root_table,
175 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
176 .root = &sysctl_table_root,
177 .set = &sysctl_table_root.default_set,
179 static struct ctl_table_root sysctl_table_root = {
180 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
181 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
184 static struct ctl_table kern_table[];
185 static struct ctl_table vm_table[];
186 static struct ctl_table fs_table[];
187 static struct ctl_table debug_table[];
188 static struct ctl_table dev_table[];
189 extern struct ctl_table random_table[];
190 #ifdef CONFIG_INOTIFY_USER
191 extern struct ctl_table inotify_table[];
194 extern struct ctl_table epoll_table[];
197 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
198 int sysctl_legacy_va_layout;
201 /* The default sysctl tables: */
203 static struct ctl_table root_table[] = {
205 .procname = "kernel",
222 .child = debug_table,
230 * NOTE: do not add new entries to this table unless you have read
231 * Documentation/sysctl/ctl_unnumbered.txt
236 #ifdef CONFIG_SCHED_DEBUG
237 static int min_sched_granularity_ns = 100000; /* 100 usecs */
238 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
239 static int min_wakeup_granularity_ns; /* 0 usecs */
240 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
241 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
242 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
243 static int min_sched_shares_ratelimit = 100000; /* 100 usec */
244 static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
247 static struct ctl_table kern_table[] = {
249 .procname = "sched_child_runs_first",
250 .data = &sysctl_sched_child_runs_first,
251 .maxlen = sizeof(unsigned int),
253 .proc_handler = proc_dointvec,
255 #ifdef CONFIG_SCHED_DEBUG
257 .procname = "sched_min_granularity_ns",
258 .data = &sysctl_sched_min_granularity,
259 .maxlen = sizeof(unsigned int),
261 .proc_handler = sched_proc_update_handler,
262 .extra1 = &min_sched_granularity_ns,
263 .extra2 = &max_sched_granularity_ns,
266 .procname = "sched_latency_ns",
267 .data = &sysctl_sched_latency,
268 .maxlen = sizeof(unsigned int),
270 .proc_handler = sched_proc_update_handler,
271 .extra1 = &min_sched_granularity_ns,
272 .extra2 = &max_sched_granularity_ns,
275 .procname = "sched_wakeup_granularity_ns",
276 .data = &sysctl_sched_wakeup_granularity,
277 .maxlen = sizeof(unsigned int),
279 .proc_handler = sched_proc_update_handler,
280 .extra1 = &min_wakeup_granularity_ns,
281 .extra2 = &max_wakeup_granularity_ns,
284 .procname = "sched_shares_ratelimit",
285 .data = &sysctl_sched_shares_ratelimit,
286 .maxlen = sizeof(unsigned int),
288 .proc_handler = sched_proc_update_handler,
289 .extra1 = &min_sched_shares_ratelimit,
290 .extra2 = &max_sched_shares_ratelimit,
293 .procname = "sched_tunable_scaling",
294 .data = &sysctl_sched_tunable_scaling,
295 .maxlen = sizeof(enum sched_tunable_scaling),
297 .proc_handler = sched_proc_update_handler,
298 .extra1 = &min_sched_tunable_scaling,
299 .extra2 = &max_sched_tunable_scaling,
302 .procname = "sched_shares_thresh",
303 .data = &sysctl_sched_shares_thresh,
304 .maxlen = sizeof(unsigned int),
306 .proc_handler = proc_dointvec_minmax,
310 .procname = "sched_migration_cost",
311 .data = &sysctl_sched_migration_cost,
312 .maxlen = sizeof(unsigned int),
314 .proc_handler = proc_dointvec,
317 .procname = "sched_nr_migrate",
318 .data = &sysctl_sched_nr_migrate,
319 .maxlen = sizeof(unsigned int),
321 .proc_handler = proc_dointvec,
324 .procname = "sched_time_avg",
325 .data = &sysctl_sched_time_avg,
326 .maxlen = sizeof(unsigned int),
328 .proc_handler = proc_dointvec,
331 .procname = "timer_migration",
332 .data = &sysctl_timer_migration,
333 .maxlen = sizeof(unsigned int),
335 .proc_handler = proc_dointvec_minmax,
341 .procname = "sched_rt_period_us",
342 .data = &sysctl_sched_rt_period,
343 .maxlen = sizeof(unsigned int),
345 .proc_handler = sched_rt_handler,
348 .procname = "sched_rt_runtime_us",
349 .data = &sysctl_sched_rt_runtime,
350 .maxlen = sizeof(int),
352 .proc_handler = sched_rt_handler,
355 .procname = "sched_compat_yield",
356 .data = &sysctl_sched_compat_yield,
357 .maxlen = sizeof(unsigned int),
359 .proc_handler = proc_dointvec,
361 #ifdef CONFIG_PROVE_LOCKING
363 .procname = "prove_locking",
364 .data = &prove_locking,
365 .maxlen = sizeof(int),
367 .proc_handler = proc_dointvec,
370 #ifdef CONFIG_LOCK_STAT
372 .procname = "lock_stat",
374 .maxlen = sizeof(int),
376 .proc_handler = proc_dointvec,
381 .data = &panic_timeout,
382 .maxlen = sizeof(int),
384 .proc_handler = proc_dointvec,
387 .procname = "core_uses_pid",
388 .data = &core_uses_pid,
389 .maxlen = sizeof(int),
391 .proc_handler = proc_dointvec,
394 .procname = "core_pattern",
395 .data = core_pattern,
396 .maxlen = CORENAME_MAX_SIZE,
398 .proc_handler = proc_dostring,
401 .procname = "core_pipe_limit",
402 .data = &core_pipe_limit,
403 .maxlen = sizeof(unsigned int),
405 .proc_handler = proc_dointvec,
407 #ifdef CONFIG_PROC_SYSCTL
409 .procname = "tainted",
410 .maxlen = sizeof(long),
412 .proc_handler = proc_taint,
415 #ifdef CONFIG_LATENCYTOP
417 .procname = "latencytop",
418 .data = &latencytop_enabled,
419 .maxlen = sizeof(int),
421 .proc_handler = proc_dointvec,
424 #ifdef CONFIG_BLK_DEV_INITRD
426 .procname = "real-root-dev",
427 .data = &real_root_dev,
428 .maxlen = sizeof(int),
430 .proc_handler = proc_dointvec,
434 .procname = "print-fatal-signals",
435 .data = &print_fatal_signals,
436 .maxlen = sizeof(int),
438 .proc_handler = proc_dointvec,
442 .procname = "reboot-cmd",
443 .data = reboot_command,
446 .proc_handler = proc_dostring,
449 .procname = "stop-a",
450 .data = &stop_a_enabled,
451 .maxlen = sizeof (int),
453 .proc_handler = proc_dointvec,
456 .procname = "scons-poweroff",
457 .data = &scons_pwroff,
458 .maxlen = sizeof (int),
460 .proc_handler = proc_dointvec,
463 #ifdef CONFIG_SPARC64
465 .procname = "tsb-ratio",
466 .data = &sysctl_tsb_ratio,
467 .maxlen = sizeof (int),
469 .proc_handler = proc_dointvec,
474 .procname = "soft-power",
475 .data = &pwrsw_enabled,
476 .maxlen = sizeof (int),
478 .proc_handler = proc_dointvec,
481 .procname = "unaligned-trap",
482 .data = &unaligned_enabled,
483 .maxlen = sizeof (int),
485 .proc_handler = proc_dointvec,
489 .procname = "ctrl-alt-del",
491 .maxlen = sizeof(int),
493 .proc_handler = proc_dointvec,
495 #ifdef CONFIG_FUNCTION_TRACER
497 .procname = "ftrace_enabled",
498 .data = &ftrace_enabled,
499 .maxlen = sizeof(int),
501 .proc_handler = ftrace_enable_sysctl,
504 #ifdef CONFIG_STACK_TRACER
506 .procname = "stack_tracer_enabled",
507 .data = &stack_tracer_enabled,
508 .maxlen = sizeof(int),
510 .proc_handler = stack_trace_sysctl,
513 #ifdef CONFIG_TRACING
515 .procname = "ftrace_dump_on_oops",
516 .data = &ftrace_dump_on_oops,
517 .maxlen = sizeof(int),
519 .proc_handler = proc_dointvec,
522 #ifdef CONFIG_MODULES
524 .procname = "modprobe",
525 .data = &modprobe_path,
526 .maxlen = KMOD_PATH_LEN,
528 .proc_handler = proc_dostring,
531 .procname = "modules_disabled",
532 .data = &modules_disabled,
533 .maxlen = sizeof(int),
535 /* only handle a transition from default "0" to "1" */
536 .proc_handler = proc_dointvec_minmax,
541 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
543 .procname = "hotplug",
544 .data = &uevent_helper,
545 .maxlen = UEVENT_HELPER_PATH_LEN,
547 .proc_handler = proc_dostring,
550 #ifdef CONFIG_CHR_DEV_SG
552 .procname = "sg-big-buff",
553 .data = &sg_big_buff,
554 .maxlen = sizeof (int),
556 .proc_handler = proc_dointvec,
559 #ifdef CONFIG_BSD_PROCESS_ACCT
563 .maxlen = 3*sizeof(int),
565 .proc_handler = proc_dointvec,
568 #ifdef CONFIG_MAGIC_SYSRQ
571 .data = &__sysrq_enabled,
572 .maxlen = sizeof (int),
574 .proc_handler = proc_dointvec,
577 #ifdef CONFIG_PROC_SYSCTL
579 .procname = "cad_pid",
581 .maxlen = sizeof (int),
583 .proc_handler = proc_do_cad_pid,
587 .procname = "threads-max",
588 .data = &max_threads,
589 .maxlen = sizeof(int),
591 .proc_handler = proc_dointvec,
594 .procname = "random",
596 .child = random_table,
599 .procname = "overflowuid",
600 .data = &overflowuid,
601 .maxlen = sizeof(int),
603 .proc_handler = proc_dointvec_minmax,
604 .extra1 = &minolduid,
605 .extra2 = &maxolduid,
608 .procname = "overflowgid",
609 .data = &overflowgid,
610 .maxlen = sizeof(int),
612 .proc_handler = proc_dointvec_minmax,
613 .extra1 = &minolduid,
614 .extra2 = &maxolduid,
617 #ifdef CONFIG_MATHEMU
619 .procname = "ieee_emulation_warnings",
620 .data = &sysctl_ieee_emulation_warnings,
621 .maxlen = sizeof(int),
623 .proc_handler = proc_dointvec,
627 .procname = "userprocess_debug",
628 .data = &sysctl_userprocess_debug,
629 .maxlen = sizeof(int),
631 .proc_handler = proc_dointvec,
635 .procname = "pid_max",
637 .maxlen = sizeof (int),
639 .proc_handler = proc_dointvec_minmax,
640 .extra1 = &pid_max_min,
641 .extra2 = &pid_max_max,
644 .procname = "panic_on_oops",
645 .data = &panic_on_oops,
646 .maxlen = sizeof(int),
648 .proc_handler = proc_dointvec,
650 #if defined CONFIG_PRINTK
652 .procname = "printk",
653 .data = &console_loglevel,
654 .maxlen = 4*sizeof(int),
656 .proc_handler = proc_dointvec,
659 .procname = "printk_ratelimit",
660 .data = &printk_ratelimit_state.interval,
661 .maxlen = sizeof(int),
663 .proc_handler = proc_dointvec_jiffies,
666 .procname = "printk_ratelimit_burst",
667 .data = &printk_ratelimit_state.burst,
668 .maxlen = sizeof(int),
670 .proc_handler = proc_dointvec,
673 .procname = "printk_delay",
674 .data = &printk_delay_msec,
675 .maxlen = sizeof(int),
677 .proc_handler = proc_dointvec_minmax,
679 .extra2 = &ten_thousand,
683 .procname = "ngroups_max",
684 .data = &ngroups_max,
685 .maxlen = sizeof (int),
687 .proc_handler = proc_dointvec,
689 #if defined(CONFIG_NMI_WATCHDOG)
691 .procname = "nmi_watchdog",
692 .data = &nmi_watchdog_enabled,
693 .maxlen = sizeof (int),
695 .proc_handler = proc_nmi_enabled,
698 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_NMI_WATCHDOG)
700 .procname = "unknown_nmi_panic",
701 .data = &unknown_nmi_panic,
702 .maxlen = sizeof (int),
704 .proc_handler = proc_dointvec,
707 .procname = "nmi_watchdog",
708 .data = &nmi_watchdog_enabled,
709 .maxlen = sizeof (int),
711 .proc_handler = proc_nmi_enabled,
714 #if defined(CONFIG_X86)
716 .procname = "panic_on_unrecovered_nmi",
717 .data = &panic_on_unrecovered_nmi,
718 .maxlen = sizeof(int),
720 .proc_handler = proc_dointvec,
723 .procname = "panic_on_io_nmi",
724 .data = &panic_on_io_nmi,
725 .maxlen = sizeof(int),
727 .proc_handler = proc_dointvec,
730 .procname = "bootloader_type",
731 .data = &bootloader_type,
732 .maxlen = sizeof (int),
734 .proc_handler = proc_dointvec,
737 .procname = "bootloader_version",
738 .data = &bootloader_version,
739 .maxlen = sizeof (int),
741 .proc_handler = proc_dointvec,
744 .procname = "kstack_depth_to_print",
745 .data = &kstack_depth_to_print,
746 .maxlen = sizeof(int),
748 .proc_handler = proc_dointvec,
751 .procname = "io_delay_type",
752 .data = &io_delay_type,
753 .maxlen = sizeof(int),
755 .proc_handler = proc_dointvec,
758 #if defined(CONFIG_MMU)
760 .procname = "randomize_va_space",
761 .data = &randomize_va_space,
762 .maxlen = sizeof(int),
764 .proc_handler = proc_dointvec,
767 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
769 .procname = "spin_retry",
771 .maxlen = sizeof (int),
773 .proc_handler = proc_dointvec,
776 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
778 .procname = "acpi_video_flags",
779 .data = &acpi_realmode_flags,
780 .maxlen = sizeof (unsigned long),
782 .proc_handler = proc_doulongvec_minmax,
787 .procname = "ignore-unaligned-usertrap",
788 .data = &no_unaligned_warning,
789 .maxlen = sizeof (int),
791 .proc_handler = proc_dointvec,
794 .procname = "unaligned-dump-stack",
795 .data = &unaligned_dump_stack,
796 .maxlen = sizeof (int),
798 .proc_handler = proc_dointvec,
801 #ifdef CONFIG_DETECT_SOFTLOCKUP
803 .procname = "softlockup_panic",
804 .data = &softlockup_panic,
805 .maxlen = sizeof(int),
807 .proc_handler = proc_dointvec_minmax,
812 .procname = "softlockup_thresh",
813 .data = &softlockup_thresh,
814 .maxlen = sizeof(int),
816 .proc_handler = proc_dosoftlockup_thresh,
821 #ifdef CONFIG_DETECT_HUNG_TASK
823 .procname = "hung_task_panic",
824 .data = &sysctl_hung_task_panic,
825 .maxlen = sizeof(int),
827 .proc_handler = proc_dointvec_minmax,
832 .procname = "hung_task_check_count",
833 .data = &sysctl_hung_task_check_count,
834 .maxlen = sizeof(unsigned long),
836 .proc_handler = proc_doulongvec_minmax,
839 .procname = "hung_task_timeout_secs",
840 .data = &sysctl_hung_task_timeout_secs,
841 .maxlen = sizeof(unsigned long),
843 .proc_handler = proc_dohung_task_timeout_secs,
846 .procname = "hung_task_warnings",
847 .data = &sysctl_hung_task_warnings,
848 .maxlen = sizeof(unsigned long),
850 .proc_handler = proc_doulongvec_minmax,
855 .procname = "compat-log",
857 .maxlen = sizeof (int),
859 .proc_handler = proc_dointvec,
862 #ifdef CONFIG_RT_MUTEXES
864 .procname = "max_lock_depth",
865 .data = &max_lock_depth,
866 .maxlen = sizeof(int),
868 .proc_handler = proc_dointvec,
872 .procname = "poweroff_cmd",
873 .data = &poweroff_cmd,
874 .maxlen = POWEROFF_CMD_PATH_LEN,
876 .proc_handler = proc_dostring,
882 .child = key_sysctls,
885 #ifdef CONFIG_RCU_TORTURE_TEST
887 .procname = "rcutorture_runnable",
888 .data = &rcutorture_runnable,
889 .maxlen = sizeof(int),
891 .proc_handler = proc_dointvec,
894 #ifdef CONFIG_SLOW_WORK
896 .procname = "slow-work",
898 .child = slow_work_sysctls,
901 #ifdef CONFIG_PERF_EVENTS
903 .procname = "perf_event_paranoid",
904 .data = &sysctl_perf_event_paranoid,
905 .maxlen = sizeof(sysctl_perf_event_paranoid),
907 .proc_handler = proc_dointvec,
910 .procname = "perf_event_mlock_kb",
911 .data = &sysctl_perf_event_mlock,
912 .maxlen = sizeof(sysctl_perf_event_mlock),
914 .proc_handler = proc_dointvec,
917 .procname = "perf_event_max_sample_rate",
918 .data = &sysctl_perf_event_sample_rate,
919 .maxlen = sizeof(sysctl_perf_event_sample_rate),
921 .proc_handler = proc_dointvec,
924 #ifdef CONFIG_KMEMCHECK
926 .procname = "kmemcheck",
927 .data = &kmemcheck_enabled,
928 .maxlen = sizeof(int),
930 .proc_handler = proc_dointvec,
935 .procname = "blk_iopoll",
936 .data = &blk_iopoll_enabled,
937 .maxlen = sizeof(int),
939 .proc_handler = proc_dointvec,
943 * NOTE: do not add new entries to this table unless you have read
944 * Documentation/sysctl/ctl_unnumbered.txt
949 static struct ctl_table vm_table[] = {
951 .procname = "overcommit_memory",
952 .data = &sysctl_overcommit_memory,
953 .maxlen = sizeof(sysctl_overcommit_memory),
955 .proc_handler = proc_dointvec,
958 .procname = "panic_on_oom",
959 .data = &sysctl_panic_on_oom,
960 .maxlen = sizeof(sysctl_panic_on_oom),
962 .proc_handler = proc_dointvec,
965 .procname = "oom_kill_allocating_task",
966 .data = &sysctl_oom_kill_allocating_task,
967 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
969 .proc_handler = proc_dointvec,
972 .procname = "oom_dump_tasks",
973 .data = &sysctl_oom_dump_tasks,
974 .maxlen = sizeof(sysctl_oom_dump_tasks),
976 .proc_handler = proc_dointvec,
979 .procname = "overcommit_ratio",
980 .data = &sysctl_overcommit_ratio,
981 .maxlen = sizeof(sysctl_overcommit_ratio),
983 .proc_handler = proc_dointvec,
986 .procname = "page-cluster",
987 .data = &page_cluster,
988 .maxlen = sizeof(int),
990 .proc_handler = proc_dointvec,
993 .procname = "dirty_background_ratio",
994 .data = &dirty_background_ratio,
995 .maxlen = sizeof(dirty_background_ratio),
997 .proc_handler = dirty_background_ratio_handler,
999 .extra2 = &one_hundred,
1002 .procname = "dirty_background_bytes",
1003 .data = &dirty_background_bytes,
1004 .maxlen = sizeof(dirty_background_bytes),
1006 .proc_handler = dirty_background_bytes_handler,
1010 .procname = "dirty_ratio",
1011 .data = &vm_dirty_ratio,
1012 .maxlen = sizeof(vm_dirty_ratio),
1014 .proc_handler = dirty_ratio_handler,
1016 .extra2 = &one_hundred,
1019 .procname = "dirty_bytes",
1020 .data = &vm_dirty_bytes,
1021 .maxlen = sizeof(vm_dirty_bytes),
1023 .proc_handler = dirty_bytes_handler,
1024 .extra1 = &dirty_bytes_min,
1027 .procname = "dirty_writeback_centisecs",
1028 .data = &dirty_writeback_interval,
1029 .maxlen = sizeof(dirty_writeback_interval),
1031 .proc_handler = dirty_writeback_centisecs_handler,
1034 .procname = "dirty_expire_centisecs",
1035 .data = &dirty_expire_interval,
1036 .maxlen = sizeof(dirty_expire_interval),
1038 .proc_handler = proc_dointvec,
1041 .procname = "nr_pdflush_threads",
1042 .data = &nr_pdflush_threads,
1043 .maxlen = sizeof nr_pdflush_threads,
1044 .mode = 0444 /* read-only*/,
1045 .proc_handler = proc_dointvec,
1048 .procname = "swappiness",
1049 .data = &vm_swappiness,
1050 .maxlen = sizeof(vm_swappiness),
1052 .proc_handler = proc_dointvec_minmax,
1054 .extra2 = &one_hundred,
1056 #ifdef CONFIG_HUGETLB_PAGE
1058 .procname = "nr_hugepages",
1060 .maxlen = sizeof(unsigned long),
1062 .proc_handler = hugetlb_sysctl_handler,
1063 .extra1 = (void *)&hugetlb_zero,
1064 .extra2 = (void *)&hugetlb_infinity,
1068 .procname = "nr_hugepages_mempolicy",
1070 .maxlen = sizeof(unsigned long),
1072 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1073 .extra1 = (void *)&hugetlb_zero,
1074 .extra2 = (void *)&hugetlb_infinity,
1078 .procname = "hugetlb_shm_group",
1079 .data = &sysctl_hugetlb_shm_group,
1080 .maxlen = sizeof(gid_t),
1082 .proc_handler = proc_dointvec,
1085 .procname = "hugepages_treat_as_movable",
1086 .data = &hugepages_treat_as_movable,
1087 .maxlen = sizeof(int),
1089 .proc_handler = hugetlb_treat_movable_handler,
1092 .procname = "nr_overcommit_hugepages",
1094 .maxlen = sizeof(unsigned long),
1096 .proc_handler = hugetlb_overcommit_handler,
1097 .extra1 = (void *)&hugetlb_zero,
1098 .extra2 = (void *)&hugetlb_infinity,
1102 .procname = "lowmem_reserve_ratio",
1103 .data = &sysctl_lowmem_reserve_ratio,
1104 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1106 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1109 .procname = "drop_caches",
1110 .data = &sysctl_drop_caches,
1111 .maxlen = sizeof(int),
1113 .proc_handler = drop_caches_sysctl_handler,
1116 .procname = "min_free_kbytes",
1117 .data = &min_free_kbytes,
1118 .maxlen = sizeof(min_free_kbytes),
1120 .proc_handler = min_free_kbytes_sysctl_handler,
1124 .procname = "percpu_pagelist_fraction",
1125 .data = &percpu_pagelist_fraction,
1126 .maxlen = sizeof(percpu_pagelist_fraction),
1128 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1129 .extra1 = &min_percpu_pagelist_fract,
1133 .procname = "max_map_count",
1134 .data = &sysctl_max_map_count,
1135 .maxlen = sizeof(sysctl_max_map_count),
1137 .proc_handler = proc_dointvec_minmax,
1142 .procname = "nr_trim_pages",
1143 .data = &sysctl_nr_trim_pages,
1144 .maxlen = sizeof(sysctl_nr_trim_pages),
1146 .proc_handler = proc_dointvec_minmax,
1151 .procname = "laptop_mode",
1152 .data = &laptop_mode,
1153 .maxlen = sizeof(laptop_mode),
1155 .proc_handler = proc_dointvec_jiffies,
1158 .procname = "block_dump",
1159 .data = &block_dump,
1160 .maxlen = sizeof(block_dump),
1162 .proc_handler = proc_dointvec,
1166 .procname = "vfs_cache_pressure",
1167 .data = &sysctl_vfs_cache_pressure,
1168 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1170 .proc_handler = proc_dointvec,
1173 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1175 .procname = "legacy_va_layout",
1176 .data = &sysctl_legacy_va_layout,
1177 .maxlen = sizeof(sysctl_legacy_va_layout),
1179 .proc_handler = proc_dointvec,
1185 .procname = "zone_reclaim_mode",
1186 .data = &zone_reclaim_mode,
1187 .maxlen = sizeof(zone_reclaim_mode),
1189 .proc_handler = proc_dointvec,
1193 .procname = "min_unmapped_ratio",
1194 .data = &sysctl_min_unmapped_ratio,
1195 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1197 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1199 .extra2 = &one_hundred,
1202 .procname = "min_slab_ratio",
1203 .data = &sysctl_min_slab_ratio,
1204 .maxlen = sizeof(sysctl_min_slab_ratio),
1206 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1208 .extra2 = &one_hundred,
1213 .procname = "stat_interval",
1214 .data = &sysctl_stat_interval,
1215 .maxlen = sizeof(sysctl_stat_interval),
1217 .proc_handler = proc_dointvec_jiffies,
1222 .procname = "mmap_min_addr",
1223 .data = &dac_mmap_min_addr,
1224 .maxlen = sizeof(unsigned long),
1226 .proc_handler = mmap_min_addr_handler,
1231 .procname = "numa_zonelist_order",
1232 .data = &numa_zonelist_order,
1233 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1235 .proc_handler = numa_zonelist_order_handler,
1238 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1239 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1241 .procname = "vdso_enabled",
1242 .data = &vdso_enabled,
1243 .maxlen = sizeof(vdso_enabled),
1245 .proc_handler = proc_dointvec,
1249 #ifdef CONFIG_HIGHMEM
1251 .procname = "highmem_is_dirtyable",
1252 .data = &vm_highmem_is_dirtyable,
1253 .maxlen = sizeof(vm_highmem_is_dirtyable),
1255 .proc_handler = proc_dointvec_minmax,
1261 .procname = "scan_unevictable_pages",
1262 .data = &scan_unevictable_pages,
1263 .maxlen = sizeof(scan_unevictable_pages),
1265 .proc_handler = scan_unevictable_handler,
1267 #ifdef CONFIG_MEMORY_FAILURE
1269 .procname = "memory_failure_early_kill",
1270 .data = &sysctl_memory_failure_early_kill,
1271 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1273 .proc_handler = proc_dointvec_minmax,
1278 .procname = "memory_failure_recovery",
1279 .data = &sysctl_memory_failure_recovery,
1280 .maxlen = sizeof(sysctl_memory_failure_recovery),
1282 .proc_handler = proc_dointvec_minmax,
1289 * NOTE: do not add new entries to this table unless you have read
1290 * Documentation/sysctl/ctl_unnumbered.txt
1295 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1296 static struct ctl_table binfmt_misc_table[] = {
1301 static struct ctl_table fs_table[] = {
1303 .procname = "inode-nr",
1304 .data = &inodes_stat,
1305 .maxlen = 2*sizeof(int),
1307 .proc_handler = proc_dointvec,
1310 .procname = "inode-state",
1311 .data = &inodes_stat,
1312 .maxlen = 7*sizeof(int),
1314 .proc_handler = proc_dointvec,
1317 .procname = "file-nr",
1318 .data = &files_stat,
1319 .maxlen = 3*sizeof(int),
1321 .proc_handler = proc_nr_files,
1324 .procname = "file-max",
1325 .data = &files_stat.max_files,
1326 .maxlen = sizeof(int),
1328 .proc_handler = proc_dointvec,
1331 .procname = "nr_open",
1332 .data = &sysctl_nr_open,
1333 .maxlen = sizeof(int),
1335 .proc_handler = proc_dointvec_minmax,
1336 .extra1 = &sysctl_nr_open_min,
1337 .extra2 = &sysctl_nr_open_max,
1340 .procname = "dentry-state",
1341 .data = &dentry_stat,
1342 .maxlen = 6*sizeof(int),
1344 .proc_handler = proc_dointvec,
1347 .procname = "overflowuid",
1348 .data = &fs_overflowuid,
1349 .maxlen = sizeof(int),
1351 .proc_handler = proc_dointvec_minmax,
1352 .extra1 = &minolduid,
1353 .extra2 = &maxolduid,
1356 .procname = "overflowgid",
1357 .data = &fs_overflowgid,
1358 .maxlen = sizeof(int),
1360 .proc_handler = proc_dointvec_minmax,
1361 .extra1 = &minolduid,
1362 .extra2 = &maxolduid,
1364 #ifdef CONFIG_FILE_LOCKING
1366 .procname = "leases-enable",
1367 .data = &leases_enable,
1368 .maxlen = sizeof(int),
1370 .proc_handler = proc_dointvec,
1373 #ifdef CONFIG_DNOTIFY
1375 .procname = "dir-notify-enable",
1376 .data = &dir_notify_enable,
1377 .maxlen = sizeof(int),
1379 .proc_handler = proc_dointvec,
1383 #ifdef CONFIG_FILE_LOCKING
1385 .procname = "lease-break-time",
1386 .data = &lease_break_time,
1387 .maxlen = sizeof(int),
1389 .proc_handler = proc_dointvec,
1394 .procname = "aio-nr",
1396 .maxlen = sizeof(aio_nr),
1398 .proc_handler = proc_doulongvec_minmax,
1401 .procname = "aio-max-nr",
1402 .data = &aio_max_nr,
1403 .maxlen = sizeof(aio_max_nr),
1405 .proc_handler = proc_doulongvec_minmax,
1407 #endif /* CONFIG_AIO */
1408 #ifdef CONFIG_INOTIFY_USER
1410 .procname = "inotify",
1412 .child = inotify_table,
1417 .procname = "epoll",
1419 .child = epoll_table,
1424 .procname = "suid_dumpable",
1425 .data = &suid_dumpable,
1426 .maxlen = sizeof(int),
1428 .proc_handler = proc_dointvec_minmax,
1432 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1434 .procname = "binfmt_misc",
1436 .child = binfmt_misc_table,
1440 * NOTE: do not add new entries to this table unless you have read
1441 * Documentation/sysctl/ctl_unnumbered.txt
1446 static struct ctl_table debug_table[] = {
1447 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
1449 .procname = "exception-trace",
1450 .data = &show_unhandled_signals,
1451 .maxlen = sizeof(int),
1453 .proc_handler = proc_dointvec
1456 #if defined(CONFIG_OPTPROBES)
1458 .procname = "kprobes-optimization",
1459 .data = &sysctl_kprobes_optimization,
1460 .maxlen = sizeof(int),
1462 .proc_handler = proc_kprobes_optimization_handler,
1470 static struct ctl_table dev_table[] = {
1474 static DEFINE_SPINLOCK(sysctl_lock);
1476 /* called under sysctl_lock */
1477 static int use_table(struct ctl_table_header *p)
1479 if (unlikely(p->unregistering))
1485 /* called under sysctl_lock */
1486 static void unuse_table(struct ctl_table_header *p)
1489 if (unlikely(p->unregistering))
1490 complete(p->unregistering);
1493 /* called under sysctl_lock, will reacquire if has to wait */
1494 static void start_unregistering(struct ctl_table_header *p)
1497 * if p->used is 0, nobody will ever touch that entry again;
1498 * we'll eliminate all paths to it before dropping sysctl_lock
1500 if (unlikely(p->used)) {
1501 struct completion wait;
1502 init_completion(&wait);
1503 p->unregistering = &wait;
1504 spin_unlock(&sysctl_lock);
1505 wait_for_completion(&wait);
1506 spin_lock(&sysctl_lock);
1508 /* anything non-NULL; we'll never dereference it */
1509 p->unregistering = ERR_PTR(-EINVAL);
1512 * do not remove from the list until nobody holds it; walking the
1513 * list in do_sysctl() relies on that.
1515 list_del_init(&p->ctl_entry);
1518 void sysctl_head_get(struct ctl_table_header *head)
1520 spin_lock(&sysctl_lock);
1522 spin_unlock(&sysctl_lock);
1525 void sysctl_head_put(struct ctl_table_header *head)
1527 spin_lock(&sysctl_lock);
1530 spin_unlock(&sysctl_lock);
1533 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1537 spin_lock(&sysctl_lock);
1538 if (!use_table(head))
1539 head = ERR_PTR(-ENOENT);
1540 spin_unlock(&sysctl_lock);
1544 void sysctl_head_finish(struct ctl_table_header *head)
1548 spin_lock(&sysctl_lock);
1550 spin_unlock(&sysctl_lock);
1553 static struct ctl_table_set *
1554 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1556 struct ctl_table_set *set = &root->default_set;
1558 set = root->lookup(root, namespaces);
1562 static struct list_head *
1563 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1565 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1569 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1570 struct ctl_table_header *prev)
1572 struct ctl_table_root *root;
1573 struct list_head *header_list;
1574 struct ctl_table_header *head;
1575 struct list_head *tmp;
1577 spin_lock(&sysctl_lock);
1580 tmp = &prev->ctl_entry;
1584 tmp = &root_table_header.ctl_entry;
1586 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1588 if (!use_table(head))
1590 spin_unlock(&sysctl_lock);
1595 header_list = lookup_header_list(root, namespaces);
1596 if (tmp != header_list)
1600 root = list_entry(root->root_list.next,
1601 struct ctl_table_root, root_list);
1602 if (root == &sysctl_table_root)
1604 header_list = lookup_header_list(root, namespaces);
1605 } while (list_empty(header_list));
1606 tmp = header_list->next;
1609 spin_unlock(&sysctl_lock);
1613 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1615 return __sysctl_head_next(current->nsproxy, prev);
1618 void register_sysctl_root(struct ctl_table_root *root)
1620 spin_lock(&sysctl_lock);
1621 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1622 spin_unlock(&sysctl_lock);
1626 * sysctl_perm does NOT grant the superuser all rights automatically, because
1627 * some sysctl variables are readonly even to root.
1630 static int test_perm(int mode, int op)
1632 if (!current_euid())
1634 else if (in_egroup_p(0))
1636 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1641 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1646 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1650 if (root->permissions)
1651 mode = root->permissions(root, current->nsproxy, table);
1655 return test_perm(mode, op);
1658 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1660 for (; table->procname; table++) {
1661 table->parent = parent;
1663 sysctl_set_parent(table, table->child);
1667 static __init int sysctl_init(void)
1669 sysctl_set_parent(NULL, root_table);
1670 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1673 err = sysctl_check_table(current->nsproxy, root_table);
1679 core_initcall(sysctl_init);
1681 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1682 struct ctl_table *table)
1684 struct ctl_table *p;
1685 const char *s = branch->procname;
1687 /* branch should have named subdirectory as its first element */
1688 if (!s || !branch->child)
1691 /* ... and nothing else */
1692 if (branch[1].procname)
1695 /* table should contain subdirectory with the same name */
1696 for (p = table; p->procname; p++) {
1699 if (p->procname && strcmp(p->procname, s) == 0)
1705 /* see if attaching q to p would be an improvement */
1706 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1708 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1709 struct ctl_table *next;
1711 int not_in_parent = !p->attached_by;
1713 while ((next = is_branch_in(by, to)) != NULL) {
1714 if (by == q->attached_by)
1716 if (to == p->attached_by)
1722 if (is_better && not_in_parent) {
1723 q->attached_by = by;
1724 q->attached_to = to;
1730 * __register_sysctl_paths - register a sysctl hierarchy
1731 * @root: List of sysctl headers to register on
1732 * @namespaces: Data to compute which lists of sysctl entries are visible
1733 * @path: The path to the directory the sysctl table is in.
1734 * @table: the top-level table structure
1736 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1737 * array. A completely 0 filled entry terminates the table.
1739 * The members of the &struct ctl_table structure are used as follows:
1741 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1742 * enter a sysctl file
1744 * data - a pointer to data for use by proc_handler
1746 * maxlen - the maximum size in bytes of the data
1748 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1750 * child - a pointer to the child sysctl table if this entry is a directory, or
1753 * proc_handler - the text handler routine (described below)
1755 * de - for internal use by the sysctl routines
1757 * extra1, extra2 - extra pointers usable by the proc handler routines
1759 * Leaf nodes in the sysctl tree will be represented by a single file
1760 * under /proc; non-leaf nodes will be represented by directories.
1762 * sysctl(2) can automatically manage read and write requests through
1763 * the sysctl table. The data and maxlen fields of the ctl_table
1764 * struct enable minimal validation of the values being written to be
1765 * performed, and the mode field allows minimal authentication.
1767 * There must be a proc_handler routine for any terminal nodes
1768 * mirrored under /proc/sys (non-terminals are handled by a built-in
1769 * directory handler). Several default handlers are available to
1770 * cover common cases -
1772 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1773 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1774 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1776 * It is the handler's job to read the input buffer from user memory
1777 * and process it. The handler should return 0 on success.
1779 * This routine returns %NULL on a failure to register, and a pointer
1780 * to the table header on success.
1782 struct ctl_table_header *__register_sysctl_paths(
1783 struct ctl_table_root *root,
1784 struct nsproxy *namespaces,
1785 const struct ctl_path *path, struct ctl_table *table)
1787 struct ctl_table_header *header;
1788 struct ctl_table *new, **prevp;
1789 unsigned int n, npath;
1790 struct ctl_table_set *set;
1792 /* Count the path components */
1793 for (npath = 0; path[npath].procname; ++npath)
1797 * For each path component, allocate a 2-element ctl_table array.
1798 * The first array element will be filled with the sysctl entry
1799 * for this, the second will be the sentinel (procname == 0).
1801 * We allocate everything in one go so that we don't have to
1802 * worry about freeing additional memory in unregister_sysctl_table.
1804 header = kzalloc(sizeof(struct ctl_table_header) +
1805 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1809 new = (struct ctl_table *) (header + 1);
1811 /* Now connect the dots */
1812 prevp = &header->ctl_table;
1813 for (n = 0; n < npath; ++n, ++path) {
1814 /* Copy the procname */
1815 new->procname = path->procname;
1819 prevp = &new->child;
1824 header->ctl_table_arg = table;
1826 INIT_LIST_HEAD(&header->ctl_entry);
1828 header->unregistering = NULL;
1829 header->root = root;
1830 sysctl_set_parent(NULL, header->ctl_table);
1832 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1833 if (sysctl_check_table(namespaces, header->ctl_table)) {
1838 spin_lock(&sysctl_lock);
1839 header->set = lookup_header_set(root, namespaces);
1840 header->attached_by = header->ctl_table;
1841 header->attached_to = root_table;
1842 header->parent = &root_table_header;
1843 for (set = header->set; set; set = set->parent) {
1844 struct ctl_table_header *p;
1845 list_for_each_entry(p, &set->list, ctl_entry) {
1846 if (p->unregistering)
1848 try_attach(p, header);
1851 header->parent->count++;
1852 list_add_tail(&header->ctl_entry, &header->set->list);
1853 spin_unlock(&sysctl_lock);
1859 * register_sysctl_table_path - register a sysctl table hierarchy
1860 * @path: The path to the directory the sysctl table is in.
1861 * @table: the top-level table structure
1863 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1864 * array. A completely 0 filled entry terminates the table.
1866 * See __register_sysctl_paths for more details.
1868 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1869 struct ctl_table *table)
1871 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1876 * register_sysctl_table - register a sysctl table hierarchy
1877 * @table: the top-level table structure
1879 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1880 * array. A completely 0 filled entry terminates the table.
1882 * See register_sysctl_paths for more details.
1884 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1886 static const struct ctl_path null_path[] = { {} };
1888 return register_sysctl_paths(null_path, table);
1892 * unregister_sysctl_table - unregister a sysctl table hierarchy
1893 * @header: the header returned from register_sysctl_table
1895 * Unregisters the sysctl table and all children. proc entries may not
1896 * actually be removed until they are no longer used by anyone.
1898 void unregister_sysctl_table(struct ctl_table_header * header)
1905 spin_lock(&sysctl_lock);
1906 start_unregistering(header);
1907 if (!--header->parent->count) {
1909 kfree(header->parent);
1911 if (!--header->count)
1913 spin_unlock(&sysctl_lock);
1916 int sysctl_is_seen(struct ctl_table_header *p)
1918 struct ctl_table_set *set = p->set;
1920 spin_lock(&sysctl_lock);
1921 if (p->unregistering)
1923 else if (!set->is_seen)
1926 res = set->is_seen(set);
1927 spin_unlock(&sysctl_lock);
1931 void setup_sysctl_set(struct ctl_table_set *p,
1932 struct ctl_table_set *parent,
1933 int (*is_seen)(struct ctl_table_set *))
1935 INIT_LIST_HEAD(&p->list);
1936 p->parent = parent ? parent : &sysctl_table_root.default_set;
1937 p->is_seen = is_seen;
1940 #else /* !CONFIG_SYSCTL */
1941 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1946 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1947 struct ctl_table *table)
1952 void unregister_sysctl_table(struct ctl_table_header * table)
1956 void setup_sysctl_set(struct ctl_table_set *p,
1957 struct ctl_table_set *parent,
1958 int (*is_seen)(struct ctl_table_set *))
1962 void sysctl_head_put(struct ctl_table_header *head)
1966 #endif /* CONFIG_SYSCTL */
1972 #ifdef CONFIG_PROC_SYSCTL
1974 static int _proc_do_string(void* data, int maxlen, int write,
1975 void __user *buffer,
1976 size_t *lenp, loff_t *ppos)
1982 if (!data || !maxlen || !*lenp) {
1990 while (len < *lenp) {
1991 if (get_user(c, p++))
1993 if (c == 0 || c == '\n')
1999 if(copy_from_user(data, buffer, len))
2001 ((char *) data)[len] = 0;
2019 if(copy_to_user(buffer, data, len))
2022 if(put_user('\n', ((char __user *) buffer) + len))
2033 * proc_dostring - read a string sysctl
2034 * @table: the sysctl table
2035 * @write: %TRUE if this is a write to the sysctl file
2036 * @buffer: the user buffer
2037 * @lenp: the size of the user buffer
2038 * @ppos: file position
2040 * Reads/writes a string from/to the user buffer. If the kernel
2041 * buffer provided is not large enough to hold the string, the
2042 * string is truncated. The copied string is %NULL-terminated.
2043 * If the string is being read by the user process, it is copied
2044 * and a newline '\n' is added. It is truncated if the buffer is
2047 * Returns 0 on success.
2049 int proc_dostring(struct ctl_table *table, int write,
2050 void __user *buffer, size_t *lenp, loff_t *ppos)
2052 return _proc_do_string(table->data, table->maxlen, write,
2053 buffer, lenp, ppos);
2057 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2059 int write, void *data)
2062 *valp = *negp ? -*lvalp : *lvalp;
2067 *lvalp = (unsigned long)-val;
2070 *lvalp = (unsigned long)val;
2076 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2077 int write, void __user *buffer,
2078 size_t *lenp, loff_t *ppos,
2079 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2080 int write, void *data),
2083 #define TMPBUFLEN 21
2084 int *i, vleft, first = 1, neg;
2088 char buf[TMPBUFLEN], *p;
2089 char __user *s = buffer;
2091 if (!tbl_data || !table->maxlen || !*lenp ||
2092 (*ppos && !write)) {
2097 i = (int *) tbl_data;
2098 vleft = table->maxlen / sizeof(*i);
2102 conv = do_proc_dointvec_conv;
2104 for (; left && vleft--; i++, first=0) {
2119 if (len > sizeof(buf) - 1)
2120 len = sizeof(buf) - 1;
2121 if (copy_from_user(buf, s, len))
2125 if (*p == '-' && left > 1) {
2129 if (*p < '0' || *p > '9')
2132 lval = simple_strtoul(p, &p, 0);
2135 if ((len < left) && *p && !isspace(*p))
2140 if (conv(&neg, &lval, i, 1, data))
2147 if (conv(&neg, &lval, i, 0, data))
2150 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2154 if(copy_to_user(s, buf, len))
2161 if (!write && !first && left) {
2162 if(put_user('\n', s))
2169 if (get_user(c, s++))
2184 static int do_proc_dointvec(struct ctl_table *table, int write,
2185 void __user *buffer, size_t *lenp, loff_t *ppos,
2186 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2187 int write, void *data),
2190 return __do_proc_dointvec(table->data, table, write,
2191 buffer, lenp, ppos, conv, data);
2195 * proc_dointvec - read a vector of integers
2196 * @table: the sysctl table
2197 * @write: %TRUE if this is a write to the sysctl file
2198 * @buffer: the user buffer
2199 * @lenp: the size of the user buffer
2200 * @ppos: file position
2202 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2203 * values from/to the user buffer, treated as an ASCII string.
2205 * Returns 0 on success.
2207 int proc_dointvec(struct ctl_table *table, int write,
2208 void __user *buffer, size_t *lenp, loff_t *ppos)
2210 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2215 * Taint values can only be increased
2216 * This means we can safely use a temporary.
2218 static int proc_taint(struct ctl_table *table, int write,
2219 void __user *buffer, size_t *lenp, loff_t *ppos)
2222 unsigned long tmptaint = get_taint();
2225 if (write && !capable(CAP_SYS_ADMIN))
2230 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2236 * Poor man's atomic or. Not worth adding a primitive
2237 * to everyone's atomic.h for this
2240 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2241 if ((tmptaint >> i) & 1)
2249 struct do_proc_dointvec_minmax_conv_param {
2254 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2256 int write, void *data)
2258 struct do_proc_dointvec_minmax_conv_param *param = data;
2260 int val = *negp ? -*lvalp : *lvalp;
2261 if ((param->min && *param->min > val) ||
2262 (param->max && *param->max < val))
2269 *lvalp = (unsigned long)-val;
2272 *lvalp = (unsigned long)val;
2279 * proc_dointvec_minmax - read a vector of integers with min/max values
2280 * @table: the sysctl table
2281 * @write: %TRUE if this is a write to the sysctl file
2282 * @buffer: the user buffer
2283 * @lenp: the size of the user buffer
2284 * @ppos: file position
2286 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2287 * values from/to the user buffer, treated as an ASCII string.
2289 * This routine will ensure the values are within the range specified by
2290 * table->extra1 (min) and table->extra2 (max).
2292 * Returns 0 on success.
2294 int proc_dointvec_minmax(struct ctl_table *table, int write,
2295 void __user *buffer, size_t *lenp, loff_t *ppos)
2297 struct do_proc_dointvec_minmax_conv_param param = {
2298 .min = (int *) table->extra1,
2299 .max = (int *) table->extra2,
2301 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2302 do_proc_dointvec_minmax_conv, ¶m);
2305 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2306 void __user *buffer,
2307 size_t *lenp, loff_t *ppos,
2308 unsigned long convmul,
2309 unsigned long convdiv)
2311 #define TMPBUFLEN 21
2312 unsigned long *i, *min, *max, val;
2313 int vleft, first=1, neg;
2315 char buf[TMPBUFLEN], *p;
2316 char __user *s = buffer;
2318 if (!data || !table->maxlen || !*lenp ||
2319 (*ppos && !write)) {
2324 i = (unsigned long *) data;
2325 min = (unsigned long *) table->extra1;
2326 max = (unsigned long *) table->extra2;
2327 vleft = table->maxlen / sizeof(unsigned long);
2330 for (; left && vleft--; i++, min++, max++, first=0) {
2345 if (len > TMPBUFLEN-1)
2347 if (copy_from_user(buf, s, len))
2351 if (*p == '-' && left > 1) {
2355 if (*p < '0' || *p > '9')
2357 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2359 if ((len < left) && *p && !isspace(*p))
2368 if ((min && val < *min) || (max && val > *max))
2375 sprintf(p, "%lu", convdiv * (*i) / convmul);
2379 if(copy_to_user(s, buf, len))
2386 if (!write && !first && left) {
2387 if(put_user('\n', s))
2394 if (get_user(c, s++))
2409 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2410 void __user *buffer,
2411 size_t *lenp, loff_t *ppos,
2412 unsigned long convmul,
2413 unsigned long convdiv)
2415 return __do_proc_doulongvec_minmax(table->data, table, write,
2416 buffer, lenp, ppos, convmul, convdiv);
2420 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2421 * @table: the sysctl table
2422 * @write: %TRUE if this is a write to the sysctl file
2423 * @buffer: the user buffer
2424 * @lenp: the size of the user buffer
2425 * @ppos: file position
2427 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2428 * values from/to the user buffer, treated as an ASCII string.
2430 * This routine will ensure the values are within the range specified by
2431 * table->extra1 (min) and table->extra2 (max).
2433 * Returns 0 on success.
2435 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2436 void __user *buffer, size_t *lenp, loff_t *ppos)
2438 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2442 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2443 * @table: the sysctl table
2444 * @write: %TRUE if this is a write to the sysctl file
2445 * @buffer: the user buffer
2446 * @lenp: the size of the user buffer
2447 * @ppos: file position
2449 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2450 * values from/to the user buffer, treated as an ASCII string. The values
2451 * are treated as milliseconds, and converted to jiffies when they are stored.
2453 * This routine will ensure the values are within the range specified by
2454 * table->extra1 (min) and table->extra2 (max).
2456 * Returns 0 on success.
2458 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2459 void __user *buffer,
2460 size_t *lenp, loff_t *ppos)
2462 return do_proc_doulongvec_minmax(table, write, buffer,
2463 lenp, ppos, HZ, 1000l);
2467 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2469 int write, void *data)
2472 if (*lvalp > LONG_MAX / HZ)
2474 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2480 lval = (unsigned long)-val;
2483 lval = (unsigned long)val;
2490 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2492 int write, void *data)
2495 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2497 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2503 lval = (unsigned long)-val;
2506 lval = (unsigned long)val;
2508 *lvalp = jiffies_to_clock_t(lval);
2513 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2515 int write, void *data)
2518 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2524 lval = (unsigned long)-val;
2527 lval = (unsigned long)val;
2529 *lvalp = jiffies_to_msecs(lval);
2535 * proc_dointvec_jiffies - read a vector of integers as seconds
2536 * @table: the sysctl table
2537 * @write: %TRUE if this is a write to the sysctl file
2538 * @buffer: the user buffer
2539 * @lenp: the size of the user buffer
2540 * @ppos: file position
2542 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2543 * values from/to the user buffer, treated as an ASCII string.
2544 * The values read are assumed to be in seconds, and are converted into
2547 * Returns 0 on success.
2549 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2550 void __user *buffer, size_t *lenp, loff_t *ppos)
2552 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2553 do_proc_dointvec_jiffies_conv,NULL);
2557 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2558 * @table: the sysctl table
2559 * @write: %TRUE if this is a write to the sysctl file
2560 * @buffer: the user buffer
2561 * @lenp: the size of the user buffer
2562 * @ppos: pointer to the file position
2564 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2565 * values from/to the user buffer, treated as an ASCII string.
2566 * The values read are assumed to be in 1/USER_HZ seconds, and
2567 * are converted into jiffies.
2569 * Returns 0 on success.
2571 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2572 void __user *buffer, size_t *lenp, loff_t *ppos)
2574 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2575 do_proc_dointvec_userhz_jiffies_conv,NULL);
2579 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2580 * @table: the sysctl table
2581 * @write: %TRUE if this is a write to the sysctl file
2582 * @buffer: the user buffer
2583 * @lenp: the size of the user buffer
2584 * @ppos: file position
2585 * @ppos: the current position in the file
2587 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2588 * values from/to the user buffer, treated as an ASCII string.
2589 * The values read are assumed to be in 1/1000 seconds, and
2590 * are converted into jiffies.
2592 * Returns 0 on success.
2594 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2595 void __user *buffer, size_t *lenp, loff_t *ppos)
2597 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2598 do_proc_dointvec_ms_jiffies_conv, NULL);
2601 static int proc_do_cad_pid(struct ctl_table *table, int write,
2602 void __user *buffer, size_t *lenp, loff_t *ppos)
2604 struct pid *new_pid;
2608 tmp = pid_vnr(cad_pid);
2610 r = __do_proc_dointvec(&tmp, table, write, buffer,
2611 lenp, ppos, NULL, NULL);
2615 new_pid = find_get_pid(tmp);
2619 put_pid(xchg(&cad_pid, new_pid));
2623 #else /* CONFIG_PROC_FS */
2625 int proc_dostring(struct ctl_table *table, int write,
2626 void __user *buffer, size_t *lenp, loff_t *ppos)
2631 int proc_dointvec(struct ctl_table *table, int write,
2632 void __user *buffer, size_t *lenp, loff_t *ppos)
2637 int proc_dointvec_minmax(struct ctl_table *table, int write,
2638 void __user *buffer, size_t *lenp, loff_t *ppos)
2643 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2644 void __user *buffer, size_t *lenp, loff_t *ppos)
2649 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2650 void __user *buffer, size_t *lenp, loff_t *ppos)
2655 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2656 void __user *buffer, size_t *lenp, loff_t *ppos)
2661 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2662 void __user *buffer, size_t *lenp, loff_t *ppos)
2667 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2668 void __user *buffer,
2669 size_t *lenp, loff_t *ppos)
2675 #endif /* CONFIG_PROC_FS */
2678 * No sense putting this after each symbol definition, twice,
2679 * exception granted :-)
2681 EXPORT_SYMBOL(proc_dointvec);
2682 EXPORT_SYMBOL(proc_dointvec_jiffies);
2683 EXPORT_SYMBOL(proc_dointvec_minmax);
2684 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2685 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2686 EXPORT_SYMBOL(proc_dostring);
2687 EXPORT_SYMBOL(proc_doulongvec_minmax);
2688 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2689 EXPORT_SYMBOL(register_sysctl_table);
2690 EXPORT_SYMBOL(register_sysctl_paths);
2691 EXPORT_SYMBOL(unregister_sysctl_table);