2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/signal.h>
27 #include <linux/proc_fs.h>
28 #include <linux/security.h>
29 #include <linux/ctype.h>
30 #include <linux/kmemcheck.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/ratelimit.h>
40 #include <linux/compaction.h>
41 #include <linux/hugetlb.h>
42 #include <linux/initrd.h>
43 #include <linux/key.h>
44 #include <linux/times.h>
45 #include <linux/limits.h>
46 #include <linux/dcache.h>
47 #include <linux/dnotify.h>
48 #include <linux/syscalls.h>
49 #include <linux/vmstat.h>
50 #include <linux/nfs_fs.h>
51 #include <linux/acpi.h>
52 #include <linux/reboot.h>
53 #include <linux/ftrace.h>
54 #include <linux/perf_event.h>
55 #include <linux/kprobes.h>
56 #include <linux/pipe_fs_i.h>
57 #include <linux/oom.h>
59 #include <asm/uaccess.h>
60 #include <asm/processor.h>
64 #include <asm/stacktrace.h>
67 #ifdef CONFIG_BSD_PROCESS_ACCT
68 #include <linux/acct.h>
70 #ifdef CONFIG_RT_MUTEXES
71 #include <linux/rtmutex.h>
73 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
74 #include <linux/lockdep.h>
76 #ifdef CONFIG_CHR_DEV_SG
80 #ifdef CONFIG_LOCKUP_DETECTOR
81 #include <linux/nmi.h>
85 #if defined(CONFIG_SYSCTL)
87 /* External variables not in a header file. */
88 extern int sysctl_overcommit_memory;
89 extern int sysctl_overcommit_ratio;
90 extern int max_threads;
91 extern int core_uses_pid;
92 extern int suid_dumpable;
93 extern char core_pattern[];
94 extern unsigned int core_pipe_limit;
96 extern int min_free_kbytes;
97 extern int pid_max_min, pid_max_max;
98 extern int sysctl_drop_caches;
99 extern int percpu_pagelist_fraction;
100 extern int compat_log;
101 extern int latencytop_enabled;
102 extern int sysctl_nr_open_min, sysctl_nr_open_max;
104 extern int sysctl_nr_trim_pages;
107 extern int blk_iopoll_enabled;
110 /* Constants used for minimum and maximum */
111 #ifdef CONFIG_LOCKUP_DETECTOR
112 static int sixty = 60;
113 static int neg_one = -1;
117 static int __maybe_unused one = 1;
118 static int __maybe_unused two = 2;
119 static unsigned long one_ul = 1;
120 static int one_hundred = 100;
122 static int ten_thousand = 10000;
125 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
126 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
128 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
129 static int maxolduid = 65535;
130 static int minolduid;
131 static int min_percpu_pagelist_fract = 8;
133 static int ngroups_max = NGROUPS_MAX;
135 #ifdef CONFIG_INOTIFY_USER
136 #include <linux/inotify.h>
139 #include <asm/system.h>
142 #ifdef CONFIG_SPARC64
143 extern int sysctl_tsb_ratio;
147 extern int pwrsw_enabled;
148 extern int unaligned_enabled;
152 #ifdef CONFIG_MATHEMU
153 extern int sysctl_ieee_emulation_warnings;
155 extern int sysctl_userprocess_debug;
156 extern int spin_retry;
160 extern int no_unaligned_warning;
161 extern int unaligned_dump_stack;
164 #ifdef CONFIG_PROC_SYSCTL
165 static int proc_do_cad_pid(struct ctl_table *table, int write,
166 void __user *buffer, size_t *lenp, loff_t *ppos);
167 static int proc_taint(struct ctl_table *table, int write,
168 void __user *buffer, size_t *lenp, loff_t *ppos);
171 #ifdef CONFIG_MAGIC_SYSRQ
172 /* Note: sysrq code uses it's own private copy */
173 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
175 static int sysrq_sysctl_handler(ctl_table *table, int write,
176 void __user *buffer, size_t *lenp,
181 error = proc_dointvec(table, write, buffer, lenp, ppos);
186 sysrq_toggle_support(__sysrq_enabled);
193 static struct ctl_table root_table[];
194 static struct ctl_table_root sysctl_table_root;
195 static struct ctl_table_header root_table_header = {
197 .ctl_table = root_table,
198 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
199 .root = &sysctl_table_root,
200 .set = &sysctl_table_root.default_set,
202 static struct ctl_table_root sysctl_table_root = {
203 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
204 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
207 static struct ctl_table kern_table[];
208 static struct ctl_table vm_table[];
209 static struct ctl_table fs_table[];
210 static struct ctl_table debug_table[];
211 static struct ctl_table dev_table[];
212 extern struct ctl_table random_table[];
214 extern struct ctl_table epoll_table[];
217 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
218 int sysctl_legacy_va_layout;
221 /* The default sysctl tables: */
223 static struct ctl_table root_table[] = {
225 .procname = "kernel",
242 .child = debug_table,
250 * NOTE: do not add new entries to this table unless you have read
251 * Documentation/sysctl/ctl_unnumbered.txt
256 #ifdef CONFIG_SCHED_DEBUG
257 static int min_sched_granularity_ns = 100000; /* 100 usecs */
258 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
259 static int min_wakeup_granularity_ns; /* 0 usecs */
260 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
261 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
262 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
263 static int min_sched_shares_ratelimit = 100000; /* 100 usec */
264 static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
267 #ifdef CONFIG_COMPACTION
268 static int min_extfrag_threshold;
269 static int max_extfrag_threshold = 1000;
272 static struct ctl_table kern_table[] = {
274 .procname = "sched_child_runs_first",
275 .data = &sysctl_sched_child_runs_first,
276 .maxlen = sizeof(unsigned int),
278 .proc_handler = proc_dointvec,
280 #ifdef CONFIG_SCHED_DEBUG
282 .procname = "sched_min_granularity_ns",
283 .data = &sysctl_sched_min_granularity,
284 .maxlen = sizeof(unsigned int),
286 .proc_handler = sched_proc_update_handler,
287 .extra1 = &min_sched_granularity_ns,
288 .extra2 = &max_sched_granularity_ns,
291 .procname = "sched_latency_ns",
292 .data = &sysctl_sched_latency,
293 .maxlen = sizeof(unsigned int),
295 .proc_handler = sched_proc_update_handler,
296 .extra1 = &min_sched_granularity_ns,
297 .extra2 = &max_sched_granularity_ns,
300 .procname = "sched_wakeup_granularity_ns",
301 .data = &sysctl_sched_wakeup_granularity,
302 .maxlen = sizeof(unsigned int),
304 .proc_handler = sched_proc_update_handler,
305 .extra1 = &min_wakeup_granularity_ns,
306 .extra2 = &max_wakeup_granularity_ns,
309 .procname = "sched_shares_ratelimit",
310 .data = &sysctl_sched_shares_ratelimit,
311 .maxlen = sizeof(unsigned int),
313 .proc_handler = sched_proc_update_handler,
314 .extra1 = &min_sched_shares_ratelimit,
315 .extra2 = &max_sched_shares_ratelimit,
318 .procname = "sched_tunable_scaling",
319 .data = &sysctl_sched_tunable_scaling,
320 .maxlen = sizeof(enum sched_tunable_scaling),
322 .proc_handler = sched_proc_update_handler,
323 .extra1 = &min_sched_tunable_scaling,
324 .extra2 = &max_sched_tunable_scaling,
327 .procname = "sched_shares_thresh",
328 .data = &sysctl_sched_shares_thresh,
329 .maxlen = sizeof(unsigned int),
331 .proc_handler = proc_dointvec_minmax,
335 .procname = "sched_migration_cost",
336 .data = &sysctl_sched_migration_cost,
337 .maxlen = sizeof(unsigned int),
339 .proc_handler = proc_dointvec,
342 .procname = "sched_nr_migrate",
343 .data = &sysctl_sched_nr_migrate,
344 .maxlen = sizeof(unsigned int),
346 .proc_handler = proc_dointvec,
349 .procname = "sched_time_avg",
350 .data = &sysctl_sched_time_avg,
351 .maxlen = sizeof(unsigned int),
353 .proc_handler = proc_dointvec,
356 .procname = "timer_migration",
357 .data = &sysctl_timer_migration,
358 .maxlen = sizeof(unsigned int),
360 .proc_handler = proc_dointvec_minmax,
366 .procname = "sched_rt_period_us",
367 .data = &sysctl_sched_rt_period,
368 .maxlen = sizeof(unsigned int),
370 .proc_handler = sched_rt_handler,
373 .procname = "sched_rt_runtime_us",
374 .data = &sysctl_sched_rt_runtime,
375 .maxlen = sizeof(int),
377 .proc_handler = sched_rt_handler,
380 .procname = "sched_compat_yield",
381 .data = &sysctl_sched_compat_yield,
382 .maxlen = sizeof(unsigned int),
384 .proc_handler = proc_dointvec,
386 #ifdef CONFIG_PROVE_LOCKING
388 .procname = "prove_locking",
389 .data = &prove_locking,
390 .maxlen = sizeof(int),
392 .proc_handler = proc_dointvec,
395 #ifdef CONFIG_LOCK_STAT
397 .procname = "lock_stat",
399 .maxlen = sizeof(int),
401 .proc_handler = proc_dointvec,
406 .data = &panic_timeout,
407 .maxlen = sizeof(int),
409 .proc_handler = proc_dointvec,
412 .procname = "core_uses_pid",
413 .data = &core_uses_pid,
414 .maxlen = sizeof(int),
416 .proc_handler = proc_dointvec,
419 .procname = "core_pattern",
420 .data = core_pattern,
421 .maxlen = CORENAME_MAX_SIZE,
423 .proc_handler = proc_dostring,
426 .procname = "core_pipe_limit",
427 .data = &core_pipe_limit,
428 .maxlen = sizeof(unsigned int),
430 .proc_handler = proc_dointvec,
432 #ifdef CONFIG_PROC_SYSCTL
434 .procname = "tainted",
435 .maxlen = sizeof(long),
437 .proc_handler = proc_taint,
440 #ifdef CONFIG_LATENCYTOP
442 .procname = "latencytop",
443 .data = &latencytop_enabled,
444 .maxlen = sizeof(int),
446 .proc_handler = proc_dointvec,
449 #ifdef CONFIG_BLK_DEV_INITRD
451 .procname = "real-root-dev",
452 .data = &real_root_dev,
453 .maxlen = sizeof(int),
455 .proc_handler = proc_dointvec,
459 .procname = "print-fatal-signals",
460 .data = &print_fatal_signals,
461 .maxlen = sizeof(int),
463 .proc_handler = proc_dointvec,
467 .procname = "reboot-cmd",
468 .data = reboot_command,
471 .proc_handler = proc_dostring,
474 .procname = "stop-a",
475 .data = &stop_a_enabled,
476 .maxlen = sizeof (int),
478 .proc_handler = proc_dointvec,
481 .procname = "scons-poweroff",
482 .data = &scons_pwroff,
483 .maxlen = sizeof (int),
485 .proc_handler = proc_dointvec,
488 #ifdef CONFIG_SPARC64
490 .procname = "tsb-ratio",
491 .data = &sysctl_tsb_ratio,
492 .maxlen = sizeof (int),
494 .proc_handler = proc_dointvec,
499 .procname = "soft-power",
500 .data = &pwrsw_enabled,
501 .maxlen = sizeof (int),
503 .proc_handler = proc_dointvec,
506 .procname = "unaligned-trap",
507 .data = &unaligned_enabled,
508 .maxlen = sizeof (int),
510 .proc_handler = proc_dointvec,
514 .procname = "ctrl-alt-del",
516 .maxlen = sizeof(int),
518 .proc_handler = proc_dointvec,
520 #ifdef CONFIG_FUNCTION_TRACER
522 .procname = "ftrace_enabled",
523 .data = &ftrace_enabled,
524 .maxlen = sizeof(int),
526 .proc_handler = ftrace_enable_sysctl,
529 #ifdef CONFIG_STACK_TRACER
531 .procname = "stack_tracer_enabled",
532 .data = &stack_tracer_enabled,
533 .maxlen = sizeof(int),
535 .proc_handler = stack_trace_sysctl,
538 #ifdef CONFIG_TRACING
540 .procname = "ftrace_dump_on_oops",
541 .data = &ftrace_dump_on_oops,
542 .maxlen = sizeof(int),
544 .proc_handler = proc_dointvec,
547 #ifdef CONFIG_MODULES
549 .procname = "modprobe",
550 .data = &modprobe_path,
551 .maxlen = KMOD_PATH_LEN,
553 .proc_handler = proc_dostring,
556 .procname = "modules_disabled",
557 .data = &modules_disabled,
558 .maxlen = sizeof(int),
560 /* only handle a transition from default "0" to "1" */
561 .proc_handler = proc_dointvec_minmax,
566 #ifdef CONFIG_HOTPLUG
568 .procname = "hotplug",
569 .data = &uevent_helper,
570 .maxlen = UEVENT_HELPER_PATH_LEN,
572 .proc_handler = proc_dostring,
575 #ifdef CONFIG_CHR_DEV_SG
577 .procname = "sg-big-buff",
578 .data = &sg_big_buff,
579 .maxlen = sizeof (int),
581 .proc_handler = proc_dointvec,
584 #ifdef CONFIG_BSD_PROCESS_ACCT
588 .maxlen = 3*sizeof(int),
590 .proc_handler = proc_dointvec,
593 #ifdef CONFIG_MAGIC_SYSRQ
596 .data = &__sysrq_enabled,
597 .maxlen = sizeof (int),
599 .proc_handler = sysrq_sysctl_handler,
602 #ifdef CONFIG_PROC_SYSCTL
604 .procname = "cad_pid",
606 .maxlen = sizeof (int),
608 .proc_handler = proc_do_cad_pid,
612 .procname = "threads-max",
613 .data = &max_threads,
614 .maxlen = sizeof(int),
616 .proc_handler = proc_dointvec,
619 .procname = "random",
621 .child = random_table,
624 .procname = "overflowuid",
625 .data = &overflowuid,
626 .maxlen = sizeof(int),
628 .proc_handler = proc_dointvec_minmax,
629 .extra1 = &minolduid,
630 .extra2 = &maxolduid,
633 .procname = "overflowgid",
634 .data = &overflowgid,
635 .maxlen = sizeof(int),
637 .proc_handler = proc_dointvec_minmax,
638 .extra1 = &minolduid,
639 .extra2 = &maxolduid,
642 #ifdef CONFIG_MATHEMU
644 .procname = "ieee_emulation_warnings",
645 .data = &sysctl_ieee_emulation_warnings,
646 .maxlen = sizeof(int),
648 .proc_handler = proc_dointvec,
652 .procname = "userprocess_debug",
653 .data = &show_unhandled_signals,
654 .maxlen = sizeof(int),
656 .proc_handler = proc_dointvec,
660 .procname = "pid_max",
662 .maxlen = sizeof (int),
664 .proc_handler = proc_dointvec_minmax,
665 .extra1 = &pid_max_min,
666 .extra2 = &pid_max_max,
669 .procname = "panic_on_oops",
670 .data = &panic_on_oops,
671 .maxlen = sizeof(int),
673 .proc_handler = proc_dointvec,
675 #if defined CONFIG_PRINTK
677 .procname = "printk",
678 .data = &console_loglevel,
679 .maxlen = 4*sizeof(int),
681 .proc_handler = proc_dointvec,
684 .procname = "printk_ratelimit",
685 .data = &printk_ratelimit_state.interval,
686 .maxlen = sizeof(int),
688 .proc_handler = proc_dointvec_jiffies,
691 .procname = "printk_ratelimit_burst",
692 .data = &printk_ratelimit_state.burst,
693 .maxlen = sizeof(int),
695 .proc_handler = proc_dointvec,
698 .procname = "printk_delay",
699 .data = &printk_delay_msec,
700 .maxlen = sizeof(int),
702 .proc_handler = proc_dointvec_minmax,
704 .extra2 = &ten_thousand,
708 .procname = "ngroups_max",
709 .data = &ngroups_max,
710 .maxlen = sizeof (int),
712 .proc_handler = proc_dointvec,
714 #if defined(CONFIG_LOCKUP_DETECTOR)
716 .procname = "watchdog",
717 .data = &watchdog_enabled,
718 .maxlen = sizeof (int),
720 .proc_handler = proc_dowatchdog_enabled,
723 .procname = "watchdog_thresh",
724 .data = &softlockup_thresh,
725 .maxlen = sizeof(int),
727 .proc_handler = proc_dowatchdog_thresh,
732 .procname = "softlockup_panic",
733 .data = &softlockup_panic,
734 .maxlen = sizeof(int),
736 .proc_handler = proc_dointvec_minmax,
741 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
743 .procname = "unknown_nmi_panic",
744 .data = &unknown_nmi_panic,
745 .maxlen = sizeof (int),
747 .proc_handler = proc_dointvec,
750 .procname = "nmi_watchdog",
751 .data = &nmi_watchdog_enabled,
752 .maxlen = sizeof (int),
754 .proc_handler = proc_nmi_enabled,
757 #if defined(CONFIG_X86)
759 .procname = "panic_on_unrecovered_nmi",
760 .data = &panic_on_unrecovered_nmi,
761 .maxlen = sizeof(int),
763 .proc_handler = proc_dointvec,
766 .procname = "panic_on_io_nmi",
767 .data = &panic_on_io_nmi,
768 .maxlen = sizeof(int),
770 .proc_handler = proc_dointvec,
773 .procname = "bootloader_type",
774 .data = &bootloader_type,
775 .maxlen = sizeof (int),
777 .proc_handler = proc_dointvec,
780 .procname = "bootloader_version",
781 .data = &bootloader_version,
782 .maxlen = sizeof (int),
784 .proc_handler = proc_dointvec,
787 .procname = "kstack_depth_to_print",
788 .data = &kstack_depth_to_print,
789 .maxlen = sizeof(int),
791 .proc_handler = proc_dointvec,
794 .procname = "io_delay_type",
795 .data = &io_delay_type,
796 .maxlen = sizeof(int),
798 .proc_handler = proc_dointvec,
801 #if defined(CONFIG_MMU)
803 .procname = "randomize_va_space",
804 .data = &randomize_va_space,
805 .maxlen = sizeof(int),
807 .proc_handler = proc_dointvec,
810 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
812 .procname = "spin_retry",
814 .maxlen = sizeof (int),
816 .proc_handler = proc_dointvec,
819 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
821 .procname = "acpi_video_flags",
822 .data = &acpi_realmode_flags,
823 .maxlen = sizeof (unsigned long),
825 .proc_handler = proc_doulongvec_minmax,
830 .procname = "ignore-unaligned-usertrap",
831 .data = &no_unaligned_warning,
832 .maxlen = sizeof (int),
834 .proc_handler = proc_dointvec,
837 .procname = "unaligned-dump-stack",
838 .data = &unaligned_dump_stack,
839 .maxlen = sizeof (int),
841 .proc_handler = proc_dointvec,
844 #ifdef CONFIG_DETECT_HUNG_TASK
846 .procname = "hung_task_panic",
847 .data = &sysctl_hung_task_panic,
848 .maxlen = sizeof(int),
850 .proc_handler = proc_dointvec_minmax,
855 .procname = "hung_task_check_count",
856 .data = &sysctl_hung_task_check_count,
857 .maxlen = sizeof(unsigned long),
859 .proc_handler = proc_doulongvec_minmax,
862 .procname = "hung_task_timeout_secs",
863 .data = &sysctl_hung_task_timeout_secs,
864 .maxlen = sizeof(unsigned long),
866 .proc_handler = proc_dohung_task_timeout_secs,
869 .procname = "hung_task_warnings",
870 .data = &sysctl_hung_task_warnings,
871 .maxlen = sizeof(unsigned long),
873 .proc_handler = proc_doulongvec_minmax,
878 .procname = "compat-log",
880 .maxlen = sizeof (int),
882 .proc_handler = proc_dointvec,
885 #ifdef CONFIG_RT_MUTEXES
887 .procname = "max_lock_depth",
888 .data = &max_lock_depth,
889 .maxlen = sizeof(int),
891 .proc_handler = proc_dointvec,
895 .procname = "poweroff_cmd",
896 .data = &poweroff_cmd,
897 .maxlen = POWEROFF_CMD_PATH_LEN,
899 .proc_handler = proc_dostring,
905 .child = key_sysctls,
908 #ifdef CONFIG_RCU_TORTURE_TEST
910 .procname = "rcutorture_runnable",
911 .data = &rcutorture_runnable,
912 .maxlen = sizeof(int),
914 .proc_handler = proc_dointvec,
917 #ifdef CONFIG_PERF_EVENTS
919 .procname = "perf_event_paranoid",
920 .data = &sysctl_perf_event_paranoid,
921 .maxlen = sizeof(sysctl_perf_event_paranoid),
923 .proc_handler = proc_dointvec,
926 .procname = "perf_event_mlock_kb",
927 .data = &sysctl_perf_event_mlock,
928 .maxlen = sizeof(sysctl_perf_event_mlock),
930 .proc_handler = proc_dointvec,
933 .procname = "perf_event_max_sample_rate",
934 .data = &sysctl_perf_event_sample_rate,
935 .maxlen = sizeof(sysctl_perf_event_sample_rate),
937 .proc_handler = proc_dointvec,
940 #ifdef CONFIG_KMEMCHECK
942 .procname = "kmemcheck",
943 .data = &kmemcheck_enabled,
944 .maxlen = sizeof(int),
946 .proc_handler = proc_dointvec,
951 .procname = "blk_iopoll",
952 .data = &blk_iopoll_enabled,
953 .maxlen = sizeof(int),
955 .proc_handler = proc_dointvec,
959 * NOTE: do not add new entries to this table unless you have read
960 * Documentation/sysctl/ctl_unnumbered.txt
965 static struct ctl_table vm_table[] = {
967 .procname = "overcommit_memory",
968 .data = &sysctl_overcommit_memory,
969 .maxlen = sizeof(sysctl_overcommit_memory),
971 .proc_handler = proc_dointvec,
974 .procname = "panic_on_oom",
975 .data = &sysctl_panic_on_oom,
976 .maxlen = sizeof(sysctl_panic_on_oom),
978 .proc_handler = proc_dointvec,
981 .procname = "oom_kill_allocating_task",
982 .data = &sysctl_oom_kill_allocating_task,
983 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
985 .proc_handler = proc_dointvec,
988 .procname = "oom_dump_tasks",
989 .data = &sysctl_oom_dump_tasks,
990 .maxlen = sizeof(sysctl_oom_dump_tasks),
992 .proc_handler = proc_dointvec,
995 .procname = "overcommit_ratio",
996 .data = &sysctl_overcommit_ratio,
997 .maxlen = sizeof(sysctl_overcommit_ratio),
999 .proc_handler = proc_dointvec,
1002 .procname = "page-cluster",
1003 .data = &page_cluster,
1004 .maxlen = sizeof(int),
1006 .proc_handler = proc_dointvec,
1009 .procname = "dirty_background_ratio",
1010 .data = &dirty_background_ratio,
1011 .maxlen = sizeof(dirty_background_ratio),
1013 .proc_handler = dirty_background_ratio_handler,
1015 .extra2 = &one_hundred,
1018 .procname = "dirty_background_bytes",
1019 .data = &dirty_background_bytes,
1020 .maxlen = sizeof(dirty_background_bytes),
1022 .proc_handler = dirty_background_bytes_handler,
1026 .procname = "dirty_ratio",
1027 .data = &vm_dirty_ratio,
1028 .maxlen = sizeof(vm_dirty_ratio),
1030 .proc_handler = dirty_ratio_handler,
1032 .extra2 = &one_hundred,
1035 .procname = "dirty_bytes",
1036 .data = &vm_dirty_bytes,
1037 .maxlen = sizeof(vm_dirty_bytes),
1039 .proc_handler = dirty_bytes_handler,
1040 .extra1 = &dirty_bytes_min,
1043 .procname = "dirty_writeback_centisecs",
1044 .data = &dirty_writeback_interval,
1045 .maxlen = sizeof(dirty_writeback_interval),
1047 .proc_handler = dirty_writeback_centisecs_handler,
1050 .procname = "dirty_expire_centisecs",
1051 .data = &dirty_expire_interval,
1052 .maxlen = sizeof(dirty_expire_interval),
1054 .proc_handler = proc_dointvec,
1057 .procname = "nr_pdflush_threads",
1058 .data = &nr_pdflush_threads,
1059 .maxlen = sizeof nr_pdflush_threads,
1060 .mode = 0444 /* read-only*/,
1061 .proc_handler = proc_dointvec,
1064 .procname = "swappiness",
1065 .data = &vm_swappiness,
1066 .maxlen = sizeof(vm_swappiness),
1068 .proc_handler = proc_dointvec_minmax,
1070 .extra2 = &one_hundred,
1072 #ifdef CONFIG_HUGETLB_PAGE
1074 .procname = "nr_hugepages",
1076 .maxlen = sizeof(unsigned long),
1078 .proc_handler = hugetlb_sysctl_handler,
1079 .extra1 = (void *)&hugetlb_zero,
1080 .extra2 = (void *)&hugetlb_infinity,
1084 .procname = "nr_hugepages_mempolicy",
1086 .maxlen = sizeof(unsigned long),
1088 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1089 .extra1 = (void *)&hugetlb_zero,
1090 .extra2 = (void *)&hugetlb_infinity,
1094 .procname = "hugetlb_shm_group",
1095 .data = &sysctl_hugetlb_shm_group,
1096 .maxlen = sizeof(gid_t),
1098 .proc_handler = proc_dointvec,
1101 .procname = "hugepages_treat_as_movable",
1102 .data = &hugepages_treat_as_movable,
1103 .maxlen = sizeof(int),
1105 .proc_handler = hugetlb_treat_movable_handler,
1108 .procname = "nr_overcommit_hugepages",
1110 .maxlen = sizeof(unsigned long),
1112 .proc_handler = hugetlb_overcommit_handler,
1113 .extra1 = (void *)&hugetlb_zero,
1114 .extra2 = (void *)&hugetlb_infinity,
1118 .procname = "lowmem_reserve_ratio",
1119 .data = &sysctl_lowmem_reserve_ratio,
1120 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1122 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1125 .procname = "drop_caches",
1126 .data = &sysctl_drop_caches,
1127 .maxlen = sizeof(int),
1129 .proc_handler = drop_caches_sysctl_handler,
1131 #ifdef CONFIG_COMPACTION
1133 .procname = "compact_memory",
1134 .data = &sysctl_compact_memory,
1135 .maxlen = sizeof(int),
1137 .proc_handler = sysctl_compaction_handler,
1140 .procname = "extfrag_threshold",
1141 .data = &sysctl_extfrag_threshold,
1142 .maxlen = sizeof(int),
1144 .proc_handler = sysctl_extfrag_handler,
1145 .extra1 = &min_extfrag_threshold,
1146 .extra2 = &max_extfrag_threshold,
1149 #endif /* CONFIG_COMPACTION */
1151 .procname = "min_free_kbytes",
1152 .data = &min_free_kbytes,
1153 .maxlen = sizeof(min_free_kbytes),
1155 .proc_handler = min_free_kbytes_sysctl_handler,
1159 .procname = "percpu_pagelist_fraction",
1160 .data = &percpu_pagelist_fraction,
1161 .maxlen = sizeof(percpu_pagelist_fraction),
1163 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1164 .extra1 = &min_percpu_pagelist_fract,
1168 .procname = "max_map_count",
1169 .data = &sysctl_max_map_count,
1170 .maxlen = sizeof(sysctl_max_map_count),
1172 .proc_handler = proc_dointvec_minmax,
1177 .procname = "nr_trim_pages",
1178 .data = &sysctl_nr_trim_pages,
1179 .maxlen = sizeof(sysctl_nr_trim_pages),
1181 .proc_handler = proc_dointvec_minmax,
1186 .procname = "laptop_mode",
1187 .data = &laptop_mode,
1188 .maxlen = sizeof(laptop_mode),
1190 .proc_handler = proc_dointvec_jiffies,
1193 .procname = "block_dump",
1194 .data = &block_dump,
1195 .maxlen = sizeof(block_dump),
1197 .proc_handler = proc_dointvec,
1201 .procname = "vfs_cache_pressure",
1202 .data = &sysctl_vfs_cache_pressure,
1203 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1205 .proc_handler = proc_dointvec,
1208 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1210 .procname = "legacy_va_layout",
1211 .data = &sysctl_legacy_va_layout,
1212 .maxlen = sizeof(sysctl_legacy_va_layout),
1214 .proc_handler = proc_dointvec,
1220 .procname = "zone_reclaim_mode",
1221 .data = &zone_reclaim_mode,
1222 .maxlen = sizeof(zone_reclaim_mode),
1224 .proc_handler = proc_dointvec,
1228 .procname = "min_unmapped_ratio",
1229 .data = &sysctl_min_unmapped_ratio,
1230 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1232 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1234 .extra2 = &one_hundred,
1237 .procname = "min_slab_ratio",
1238 .data = &sysctl_min_slab_ratio,
1239 .maxlen = sizeof(sysctl_min_slab_ratio),
1241 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1243 .extra2 = &one_hundred,
1248 .procname = "stat_interval",
1249 .data = &sysctl_stat_interval,
1250 .maxlen = sizeof(sysctl_stat_interval),
1252 .proc_handler = proc_dointvec_jiffies,
1257 .procname = "mmap_min_addr",
1258 .data = &dac_mmap_min_addr,
1259 .maxlen = sizeof(unsigned long),
1261 .proc_handler = mmap_min_addr_handler,
1266 .procname = "numa_zonelist_order",
1267 .data = &numa_zonelist_order,
1268 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1270 .proc_handler = numa_zonelist_order_handler,
1273 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1274 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1276 .procname = "vdso_enabled",
1277 .data = &vdso_enabled,
1278 .maxlen = sizeof(vdso_enabled),
1280 .proc_handler = proc_dointvec,
1284 #ifdef CONFIG_HIGHMEM
1286 .procname = "highmem_is_dirtyable",
1287 .data = &vm_highmem_is_dirtyable,
1288 .maxlen = sizeof(vm_highmem_is_dirtyable),
1290 .proc_handler = proc_dointvec_minmax,
1296 .procname = "scan_unevictable_pages",
1297 .data = &scan_unevictable_pages,
1298 .maxlen = sizeof(scan_unevictable_pages),
1300 .proc_handler = scan_unevictable_handler,
1302 #ifdef CONFIG_MEMORY_FAILURE
1304 .procname = "memory_failure_early_kill",
1305 .data = &sysctl_memory_failure_early_kill,
1306 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1308 .proc_handler = proc_dointvec_minmax,
1313 .procname = "memory_failure_recovery",
1314 .data = &sysctl_memory_failure_recovery,
1315 .maxlen = sizeof(sysctl_memory_failure_recovery),
1317 .proc_handler = proc_dointvec_minmax,
1324 * NOTE: do not add new entries to this table unless you have read
1325 * Documentation/sysctl/ctl_unnumbered.txt
1330 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1331 static struct ctl_table binfmt_misc_table[] = {
1336 static struct ctl_table fs_table[] = {
1338 .procname = "inode-nr",
1339 .data = &inodes_stat,
1340 .maxlen = 2*sizeof(int),
1342 .proc_handler = proc_nr_inodes,
1345 .procname = "inode-state",
1346 .data = &inodes_stat,
1347 .maxlen = 7*sizeof(int),
1349 .proc_handler = proc_nr_inodes,
1352 .procname = "file-nr",
1353 .data = &files_stat,
1354 .maxlen = sizeof(files_stat),
1356 .proc_handler = proc_nr_files,
1359 .procname = "file-max",
1360 .data = &files_stat.max_files,
1361 .maxlen = sizeof(files_stat.max_files),
1363 .proc_handler = proc_doulongvec_minmax,
1366 .procname = "nr_open",
1367 .data = &sysctl_nr_open,
1368 .maxlen = sizeof(int),
1370 .proc_handler = proc_dointvec_minmax,
1371 .extra1 = &sysctl_nr_open_min,
1372 .extra2 = &sysctl_nr_open_max,
1375 .procname = "dentry-state",
1376 .data = &dentry_stat,
1377 .maxlen = 6*sizeof(int),
1379 .proc_handler = proc_nr_dentry,
1382 .procname = "overflowuid",
1383 .data = &fs_overflowuid,
1384 .maxlen = sizeof(int),
1386 .proc_handler = proc_dointvec_minmax,
1387 .extra1 = &minolduid,
1388 .extra2 = &maxolduid,
1391 .procname = "overflowgid",
1392 .data = &fs_overflowgid,
1393 .maxlen = sizeof(int),
1395 .proc_handler = proc_dointvec_minmax,
1396 .extra1 = &minolduid,
1397 .extra2 = &maxolduid,
1399 #ifdef CONFIG_FILE_LOCKING
1401 .procname = "leases-enable",
1402 .data = &leases_enable,
1403 .maxlen = sizeof(int),
1405 .proc_handler = proc_dointvec,
1408 #ifdef CONFIG_DNOTIFY
1410 .procname = "dir-notify-enable",
1411 .data = &dir_notify_enable,
1412 .maxlen = sizeof(int),
1414 .proc_handler = proc_dointvec,
1418 #ifdef CONFIG_FILE_LOCKING
1420 .procname = "lease-break-time",
1421 .data = &lease_break_time,
1422 .maxlen = sizeof(int),
1424 .proc_handler = proc_dointvec,
1429 .procname = "aio-nr",
1431 .maxlen = sizeof(aio_nr),
1433 .proc_handler = proc_doulongvec_minmax,
1436 .procname = "aio-max-nr",
1437 .data = &aio_max_nr,
1438 .maxlen = sizeof(aio_max_nr),
1440 .proc_handler = proc_doulongvec_minmax,
1442 #endif /* CONFIG_AIO */
1443 #ifdef CONFIG_INOTIFY_USER
1445 .procname = "inotify",
1447 .child = inotify_table,
1452 .procname = "epoll",
1454 .child = epoll_table,
1459 .procname = "suid_dumpable",
1460 .data = &suid_dumpable,
1461 .maxlen = sizeof(int),
1463 .proc_handler = proc_dointvec_minmax,
1467 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1469 .procname = "binfmt_misc",
1471 .child = binfmt_misc_table,
1475 .procname = "pipe-max-size",
1476 .data = &pipe_max_size,
1477 .maxlen = sizeof(int),
1479 .proc_handler = &pipe_proc_fn,
1480 .extra1 = &pipe_min_size,
1483 * NOTE: do not add new entries to this table unless you have read
1484 * Documentation/sysctl/ctl_unnumbered.txt
1489 static struct ctl_table debug_table[] = {
1490 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1491 defined(CONFIG_S390)
1493 .procname = "exception-trace",
1494 .data = &show_unhandled_signals,
1495 .maxlen = sizeof(int),
1497 .proc_handler = proc_dointvec
1500 #if defined(CONFIG_OPTPROBES)
1502 .procname = "kprobes-optimization",
1503 .data = &sysctl_kprobes_optimization,
1504 .maxlen = sizeof(int),
1506 .proc_handler = proc_kprobes_optimization_handler,
1514 static struct ctl_table dev_table[] = {
1518 static DEFINE_SPINLOCK(sysctl_lock);
1520 /* called under sysctl_lock */
1521 static int use_table(struct ctl_table_header *p)
1523 if (unlikely(p->unregistering))
1529 /* called under sysctl_lock */
1530 static void unuse_table(struct ctl_table_header *p)
1533 if (unlikely(p->unregistering))
1534 complete(p->unregistering);
1537 /* called under sysctl_lock, will reacquire if has to wait */
1538 static void start_unregistering(struct ctl_table_header *p)
1541 * if p->used is 0, nobody will ever touch that entry again;
1542 * we'll eliminate all paths to it before dropping sysctl_lock
1544 if (unlikely(p->used)) {
1545 struct completion wait;
1546 init_completion(&wait);
1547 p->unregistering = &wait;
1548 spin_unlock(&sysctl_lock);
1549 wait_for_completion(&wait);
1550 spin_lock(&sysctl_lock);
1552 /* anything non-NULL; we'll never dereference it */
1553 p->unregistering = ERR_PTR(-EINVAL);
1556 * do not remove from the list until nobody holds it; walking the
1557 * list in do_sysctl() relies on that.
1559 list_del_init(&p->ctl_entry);
1562 void sysctl_head_get(struct ctl_table_header *head)
1564 spin_lock(&sysctl_lock);
1566 spin_unlock(&sysctl_lock);
1569 void sysctl_head_put(struct ctl_table_header *head)
1571 spin_lock(&sysctl_lock);
1574 spin_unlock(&sysctl_lock);
1577 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1581 spin_lock(&sysctl_lock);
1582 if (!use_table(head))
1583 head = ERR_PTR(-ENOENT);
1584 spin_unlock(&sysctl_lock);
1588 void sysctl_head_finish(struct ctl_table_header *head)
1592 spin_lock(&sysctl_lock);
1594 spin_unlock(&sysctl_lock);
1597 static struct ctl_table_set *
1598 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1600 struct ctl_table_set *set = &root->default_set;
1602 set = root->lookup(root, namespaces);
1606 static struct list_head *
1607 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1609 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1613 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1614 struct ctl_table_header *prev)
1616 struct ctl_table_root *root;
1617 struct list_head *header_list;
1618 struct ctl_table_header *head;
1619 struct list_head *tmp;
1621 spin_lock(&sysctl_lock);
1624 tmp = &prev->ctl_entry;
1628 tmp = &root_table_header.ctl_entry;
1630 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1632 if (!use_table(head))
1634 spin_unlock(&sysctl_lock);
1639 header_list = lookup_header_list(root, namespaces);
1640 if (tmp != header_list)
1644 root = list_entry(root->root_list.next,
1645 struct ctl_table_root, root_list);
1646 if (root == &sysctl_table_root)
1648 header_list = lookup_header_list(root, namespaces);
1649 } while (list_empty(header_list));
1650 tmp = header_list->next;
1653 spin_unlock(&sysctl_lock);
1657 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1659 return __sysctl_head_next(current->nsproxy, prev);
1662 void register_sysctl_root(struct ctl_table_root *root)
1664 spin_lock(&sysctl_lock);
1665 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1666 spin_unlock(&sysctl_lock);
1670 * sysctl_perm does NOT grant the superuser all rights automatically, because
1671 * some sysctl variables are readonly even to root.
1674 static int test_perm(int mode, int op)
1676 if (!current_euid())
1678 else if (in_egroup_p(0))
1680 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1685 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1690 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1694 if (root->permissions)
1695 mode = root->permissions(root, current->nsproxy, table);
1699 return test_perm(mode, op);
1702 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1704 for (; table->procname; table++) {
1705 table->parent = parent;
1707 sysctl_set_parent(table, table->child);
1711 static __init int sysctl_init(void)
1713 sysctl_set_parent(NULL, root_table);
1714 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1715 sysctl_check_table(current->nsproxy, root_table);
1720 core_initcall(sysctl_init);
1722 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1723 struct ctl_table *table)
1725 struct ctl_table *p;
1726 const char *s = branch->procname;
1728 /* branch should have named subdirectory as its first element */
1729 if (!s || !branch->child)
1732 /* ... and nothing else */
1733 if (branch[1].procname)
1736 /* table should contain subdirectory with the same name */
1737 for (p = table; p->procname; p++) {
1740 if (p->procname && strcmp(p->procname, s) == 0)
1746 /* see if attaching q to p would be an improvement */
1747 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1749 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1750 struct ctl_table *next;
1752 int not_in_parent = !p->attached_by;
1754 while ((next = is_branch_in(by, to)) != NULL) {
1755 if (by == q->attached_by)
1757 if (to == p->attached_by)
1763 if (is_better && not_in_parent) {
1764 q->attached_by = by;
1765 q->attached_to = to;
1771 * __register_sysctl_paths - register a sysctl hierarchy
1772 * @root: List of sysctl headers to register on
1773 * @namespaces: Data to compute which lists of sysctl entries are visible
1774 * @path: The path to the directory the sysctl table is in.
1775 * @table: the top-level table structure
1777 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1778 * array. A completely 0 filled entry terminates the table.
1780 * The members of the &struct ctl_table structure are used as follows:
1782 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1783 * enter a sysctl file
1785 * data - a pointer to data for use by proc_handler
1787 * maxlen - the maximum size in bytes of the data
1789 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1791 * child - a pointer to the child sysctl table if this entry is a directory, or
1794 * proc_handler - the text handler routine (described below)
1796 * de - for internal use by the sysctl routines
1798 * extra1, extra2 - extra pointers usable by the proc handler routines
1800 * Leaf nodes in the sysctl tree will be represented by a single file
1801 * under /proc; non-leaf nodes will be represented by directories.
1803 * sysctl(2) can automatically manage read and write requests through
1804 * the sysctl table. The data and maxlen fields of the ctl_table
1805 * struct enable minimal validation of the values being written to be
1806 * performed, and the mode field allows minimal authentication.
1808 * There must be a proc_handler routine for any terminal nodes
1809 * mirrored under /proc/sys (non-terminals are handled by a built-in
1810 * directory handler). Several default handlers are available to
1811 * cover common cases -
1813 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1814 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1815 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1817 * It is the handler's job to read the input buffer from user memory
1818 * and process it. The handler should return 0 on success.
1820 * This routine returns %NULL on a failure to register, and a pointer
1821 * to the table header on success.
1823 struct ctl_table_header *__register_sysctl_paths(
1824 struct ctl_table_root *root,
1825 struct nsproxy *namespaces,
1826 const struct ctl_path *path, struct ctl_table *table)
1828 struct ctl_table_header *header;
1829 struct ctl_table *new, **prevp;
1830 unsigned int n, npath;
1831 struct ctl_table_set *set;
1833 /* Count the path components */
1834 for (npath = 0; path[npath].procname; ++npath)
1838 * For each path component, allocate a 2-element ctl_table array.
1839 * The first array element will be filled with the sysctl entry
1840 * for this, the second will be the sentinel (procname == 0).
1842 * We allocate everything in one go so that we don't have to
1843 * worry about freeing additional memory in unregister_sysctl_table.
1845 header = kzalloc(sizeof(struct ctl_table_header) +
1846 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1850 new = (struct ctl_table *) (header + 1);
1852 /* Now connect the dots */
1853 prevp = &header->ctl_table;
1854 for (n = 0; n < npath; ++n, ++path) {
1855 /* Copy the procname */
1856 new->procname = path->procname;
1860 prevp = &new->child;
1865 header->ctl_table_arg = table;
1867 INIT_LIST_HEAD(&header->ctl_entry);
1869 header->unregistering = NULL;
1870 header->root = root;
1871 sysctl_set_parent(NULL, header->ctl_table);
1873 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1874 if (sysctl_check_table(namespaces, header->ctl_table)) {
1879 spin_lock(&sysctl_lock);
1880 header->set = lookup_header_set(root, namespaces);
1881 header->attached_by = header->ctl_table;
1882 header->attached_to = root_table;
1883 header->parent = &root_table_header;
1884 for (set = header->set; set; set = set->parent) {
1885 struct ctl_table_header *p;
1886 list_for_each_entry(p, &set->list, ctl_entry) {
1887 if (p->unregistering)
1889 try_attach(p, header);
1892 header->parent->count++;
1893 list_add_tail(&header->ctl_entry, &header->set->list);
1894 spin_unlock(&sysctl_lock);
1900 * register_sysctl_table_path - register a sysctl table hierarchy
1901 * @path: The path to the directory the sysctl table is in.
1902 * @table: the top-level table structure
1904 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1905 * array. A completely 0 filled entry terminates the table.
1907 * See __register_sysctl_paths for more details.
1909 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1910 struct ctl_table *table)
1912 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1917 * register_sysctl_table - register a sysctl table hierarchy
1918 * @table: the top-level table structure
1920 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1921 * array. A completely 0 filled entry terminates the table.
1923 * See register_sysctl_paths for more details.
1925 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1927 static const struct ctl_path null_path[] = { {} };
1929 return register_sysctl_paths(null_path, table);
1933 * unregister_sysctl_table - unregister a sysctl table hierarchy
1934 * @header: the header returned from register_sysctl_table
1936 * Unregisters the sysctl table and all children. proc entries may not
1937 * actually be removed until they are no longer used by anyone.
1939 void unregister_sysctl_table(struct ctl_table_header * header)
1946 spin_lock(&sysctl_lock);
1947 start_unregistering(header);
1948 if (!--header->parent->count) {
1950 kfree(header->parent);
1952 if (!--header->count)
1954 spin_unlock(&sysctl_lock);
1957 int sysctl_is_seen(struct ctl_table_header *p)
1959 struct ctl_table_set *set = p->set;
1961 spin_lock(&sysctl_lock);
1962 if (p->unregistering)
1964 else if (!set->is_seen)
1967 res = set->is_seen(set);
1968 spin_unlock(&sysctl_lock);
1972 void setup_sysctl_set(struct ctl_table_set *p,
1973 struct ctl_table_set *parent,
1974 int (*is_seen)(struct ctl_table_set *))
1976 INIT_LIST_HEAD(&p->list);
1977 p->parent = parent ? parent : &sysctl_table_root.default_set;
1978 p->is_seen = is_seen;
1981 #else /* !CONFIG_SYSCTL */
1982 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1987 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1988 struct ctl_table *table)
1993 void unregister_sysctl_table(struct ctl_table_header * table)
1997 void setup_sysctl_set(struct ctl_table_set *p,
1998 struct ctl_table_set *parent,
1999 int (*is_seen)(struct ctl_table_set *))
2003 void sysctl_head_put(struct ctl_table_header *head)
2007 #endif /* CONFIG_SYSCTL */
2013 #ifdef CONFIG_PROC_SYSCTL
2015 static int _proc_do_string(void* data, int maxlen, int write,
2016 void __user *buffer,
2017 size_t *lenp, loff_t *ppos)
2023 if (!data || !maxlen || !*lenp) {
2031 while (len < *lenp) {
2032 if (get_user(c, p++))
2034 if (c == 0 || c == '\n')
2040 if(copy_from_user(data, buffer, len))
2042 ((char *) data)[len] = 0;
2060 if(copy_to_user(buffer, data, len))
2063 if(put_user('\n', ((char __user *) buffer) + len))
2074 * proc_dostring - read a string sysctl
2075 * @table: the sysctl table
2076 * @write: %TRUE if this is a write to the sysctl file
2077 * @buffer: the user buffer
2078 * @lenp: the size of the user buffer
2079 * @ppos: file position
2081 * Reads/writes a string from/to the user buffer. If the kernel
2082 * buffer provided is not large enough to hold the string, the
2083 * string is truncated. The copied string is %NULL-terminated.
2084 * If the string is being read by the user process, it is copied
2085 * and a newline '\n' is added. It is truncated if the buffer is
2088 * Returns 0 on success.
2090 int proc_dostring(struct ctl_table *table, int write,
2091 void __user *buffer, size_t *lenp, loff_t *ppos)
2093 return _proc_do_string(table->data, table->maxlen, write,
2094 buffer, lenp, ppos);
2097 static size_t proc_skip_spaces(char **buf)
2100 char *tmp = skip_spaces(*buf);
2106 static void proc_skip_char(char **buf, size_t *size, const char v)
2116 #define TMPBUFLEN 22
2118 * proc_get_long - reads an ASCII formatted integer from a user buffer
2120 * @buf: a kernel buffer
2121 * @size: size of the kernel buffer
2122 * @val: this is where the number will be stored
2123 * @neg: set to %TRUE if number is negative
2124 * @perm_tr: a vector which contains the allowed trailers
2125 * @perm_tr_len: size of the perm_tr vector
2126 * @tr: pointer to store the trailer character
2128 * In case of success %0 is returned and @buf and @size are updated with
2129 * the amount of bytes read. If @tr is non-NULL and a trailing
2130 * character exists (size is non-zero after returning from this
2131 * function), @tr is updated with the trailing character.
2133 static int proc_get_long(char **buf, size_t *size,
2134 unsigned long *val, bool *neg,
2135 const char *perm_tr, unsigned perm_tr_len, char *tr)
2138 char *p, tmp[TMPBUFLEN];
2144 if (len > TMPBUFLEN - 1)
2145 len = TMPBUFLEN - 1;
2147 memcpy(tmp, *buf, len);
2151 if (*p == '-' && *size > 1) {
2159 *val = simple_strtoul(p, &p, 0);
2163 /* We don't know if the next char is whitespace thus we may accept
2164 * invalid integers (e.g. 1234...a) or two integers instead of one
2165 * (e.g. 123...1). So lets not allow such large numbers. */
2166 if (len == TMPBUFLEN - 1)
2169 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2172 if (tr && (len < *size))
2182 * proc_put_long - converts an integer to a decimal ASCII formatted string
2184 * @buf: the user buffer
2185 * @size: the size of the user buffer
2186 * @val: the integer to be converted
2187 * @neg: sign of the number, %TRUE for negative
2189 * In case of success %0 is returned and @buf and @size are updated with
2190 * the amount of bytes written.
2192 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2196 char tmp[TMPBUFLEN], *p = tmp;
2198 sprintf(p, "%s%lu", neg ? "-" : "", val);
2202 if (copy_to_user(*buf, tmp, len))
2210 static int proc_put_char(void __user **buf, size_t *size, char c)
2213 char __user **buffer = (char __user **)buf;
2214 if (put_user(c, *buffer))
2216 (*size)--, (*buffer)++;
2222 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2224 int write, void *data)
2227 *valp = *negp ? -*lvalp : *lvalp;
2232 *lvalp = (unsigned long)-val;
2235 *lvalp = (unsigned long)val;
2241 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2243 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2244 int write, void __user *buffer,
2245 size_t *lenp, loff_t *ppos,
2246 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2247 int write, void *data),
2250 int *i, vleft, first = 1, err = 0;
2251 unsigned long page = 0;
2255 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2260 i = (int *) tbl_data;
2261 vleft = table->maxlen / sizeof(*i);
2265 conv = do_proc_dointvec_conv;
2268 if (left > PAGE_SIZE - 1)
2269 left = PAGE_SIZE - 1;
2270 page = __get_free_page(GFP_TEMPORARY);
2271 kbuf = (char *) page;
2274 if (copy_from_user(kbuf, buffer, left)) {
2281 for (; left && vleft--; i++, first=0) {
2286 left -= proc_skip_spaces(&kbuf);
2290 err = proc_get_long(&kbuf, &left, &lval, &neg,
2292 sizeof(proc_wspace_sep), NULL);
2295 if (conv(&neg, &lval, i, 1, data)) {
2300 if (conv(&neg, &lval, i, 0, data)) {
2305 err = proc_put_char(&buffer, &left, '\t');
2308 err = proc_put_long(&buffer, &left, lval, neg);
2314 if (!write && !first && left && !err)
2315 err = proc_put_char(&buffer, &left, '\n');
2316 if (write && !err && left)
2317 left -= proc_skip_spaces(&kbuf);
2322 return err ? : -EINVAL;
2329 static int do_proc_dointvec(struct ctl_table *table, int write,
2330 void __user *buffer, size_t *lenp, loff_t *ppos,
2331 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2332 int write, void *data),
2335 return __do_proc_dointvec(table->data, table, write,
2336 buffer, lenp, ppos, conv, data);
2340 * proc_dointvec - read a vector of integers
2341 * @table: the sysctl table
2342 * @write: %TRUE if this is a write to the sysctl file
2343 * @buffer: the user buffer
2344 * @lenp: the size of the user buffer
2345 * @ppos: file position
2347 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2348 * values from/to the user buffer, treated as an ASCII string.
2350 * Returns 0 on success.
2352 int proc_dointvec(struct ctl_table *table, int write,
2353 void __user *buffer, size_t *lenp, loff_t *ppos)
2355 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2360 * Taint values can only be increased
2361 * This means we can safely use a temporary.
2363 static int proc_taint(struct ctl_table *table, int write,
2364 void __user *buffer, size_t *lenp, loff_t *ppos)
2367 unsigned long tmptaint = get_taint();
2370 if (write && !capable(CAP_SYS_ADMIN))
2375 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2381 * Poor man's atomic or. Not worth adding a primitive
2382 * to everyone's atomic.h for this
2385 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2386 if ((tmptaint >> i) & 1)
2394 struct do_proc_dointvec_minmax_conv_param {
2399 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2401 int write, void *data)
2403 struct do_proc_dointvec_minmax_conv_param *param = data;
2405 int val = *negp ? -*lvalp : *lvalp;
2406 if ((param->min && *param->min > val) ||
2407 (param->max && *param->max < val))
2414 *lvalp = (unsigned long)-val;
2417 *lvalp = (unsigned long)val;
2424 * proc_dointvec_minmax - read a vector of integers with min/max values
2425 * @table: the sysctl table
2426 * @write: %TRUE if this is a write to the sysctl file
2427 * @buffer: the user buffer
2428 * @lenp: the size of the user buffer
2429 * @ppos: file position
2431 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2432 * values from/to the user buffer, treated as an ASCII string.
2434 * This routine will ensure the values are within the range specified by
2435 * table->extra1 (min) and table->extra2 (max).
2437 * Returns 0 on success.
2439 int proc_dointvec_minmax(struct ctl_table *table, int write,
2440 void __user *buffer, size_t *lenp, loff_t *ppos)
2442 struct do_proc_dointvec_minmax_conv_param param = {
2443 .min = (int *) table->extra1,
2444 .max = (int *) table->extra2,
2446 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2447 do_proc_dointvec_minmax_conv, ¶m);
2450 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2451 void __user *buffer,
2452 size_t *lenp, loff_t *ppos,
2453 unsigned long convmul,
2454 unsigned long convdiv)
2456 unsigned long *i, *min, *max;
2457 int vleft, first = 1, err = 0;
2458 unsigned long page = 0;
2462 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2467 i = (unsigned long *) data;
2468 min = (unsigned long *) table->extra1;
2469 max = (unsigned long *) table->extra2;
2470 vleft = table->maxlen / sizeof(unsigned long);
2474 if (left > PAGE_SIZE - 1)
2475 left = PAGE_SIZE - 1;
2476 page = __get_free_page(GFP_TEMPORARY);
2477 kbuf = (char *) page;
2480 if (copy_from_user(kbuf, buffer, left)) {
2487 for (; left && vleft--; i++, first = 0) {
2493 left -= proc_skip_spaces(&kbuf);
2495 err = proc_get_long(&kbuf, &left, &val, &neg,
2497 sizeof(proc_wspace_sep), NULL);
2502 if ((min && val < *min) || (max && val > *max))
2506 val = convdiv * (*i) / convmul;
2508 err = proc_put_char(&buffer, &left, '\t');
2509 err = proc_put_long(&buffer, &left, val, false);
2515 if (!write && !first && left && !err)
2516 err = proc_put_char(&buffer, &left, '\n');
2518 left -= proc_skip_spaces(&kbuf);
2523 return err ? : -EINVAL;
2530 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2531 void __user *buffer,
2532 size_t *lenp, loff_t *ppos,
2533 unsigned long convmul,
2534 unsigned long convdiv)
2536 return __do_proc_doulongvec_minmax(table->data, table, write,
2537 buffer, lenp, ppos, convmul, convdiv);
2541 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2542 * @table: the sysctl table
2543 * @write: %TRUE if this is a write to the sysctl file
2544 * @buffer: the user buffer
2545 * @lenp: the size of the user buffer
2546 * @ppos: file position
2548 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2549 * values from/to the user buffer, treated as an ASCII string.
2551 * This routine will ensure the values are within the range specified by
2552 * table->extra1 (min) and table->extra2 (max).
2554 * Returns 0 on success.
2556 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2557 void __user *buffer, size_t *lenp, loff_t *ppos)
2559 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2563 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2564 * @table: the sysctl table
2565 * @write: %TRUE if this is a write to the sysctl file
2566 * @buffer: the user buffer
2567 * @lenp: the size of the user buffer
2568 * @ppos: file position
2570 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2571 * values from/to the user buffer, treated as an ASCII string. The values
2572 * are treated as milliseconds, and converted to jiffies when they are stored.
2574 * This routine will ensure the values are within the range specified by
2575 * table->extra1 (min) and table->extra2 (max).
2577 * Returns 0 on success.
2579 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2580 void __user *buffer,
2581 size_t *lenp, loff_t *ppos)
2583 return do_proc_doulongvec_minmax(table, write, buffer,
2584 lenp, ppos, HZ, 1000l);
2588 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2590 int write, void *data)
2593 if (*lvalp > LONG_MAX / HZ)
2595 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2601 lval = (unsigned long)-val;
2604 lval = (unsigned long)val;
2611 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2613 int write, void *data)
2616 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2618 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2624 lval = (unsigned long)-val;
2627 lval = (unsigned long)val;
2629 *lvalp = jiffies_to_clock_t(lval);
2634 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2636 int write, void *data)
2639 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2645 lval = (unsigned long)-val;
2648 lval = (unsigned long)val;
2650 *lvalp = jiffies_to_msecs(lval);
2656 * proc_dointvec_jiffies - read a vector of integers as seconds
2657 * @table: the sysctl table
2658 * @write: %TRUE if this is a write to the sysctl file
2659 * @buffer: the user buffer
2660 * @lenp: the size of the user buffer
2661 * @ppos: file position
2663 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2664 * values from/to the user buffer, treated as an ASCII string.
2665 * The values read are assumed to be in seconds, and are converted into
2668 * Returns 0 on success.
2670 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2671 void __user *buffer, size_t *lenp, loff_t *ppos)
2673 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2674 do_proc_dointvec_jiffies_conv,NULL);
2678 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2679 * @table: the sysctl table
2680 * @write: %TRUE if this is a write to the sysctl file
2681 * @buffer: the user buffer
2682 * @lenp: the size of the user buffer
2683 * @ppos: pointer to the file position
2685 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2686 * values from/to the user buffer, treated as an ASCII string.
2687 * The values read are assumed to be in 1/USER_HZ seconds, and
2688 * are converted into jiffies.
2690 * Returns 0 on success.
2692 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2693 void __user *buffer, size_t *lenp, loff_t *ppos)
2695 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2696 do_proc_dointvec_userhz_jiffies_conv,NULL);
2700 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2701 * @table: the sysctl table
2702 * @write: %TRUE if this is a write to the sysctl file
2703 * @buffer: the user buffer
2704 * @lenp: the size of the user buffer
2705 * @ppos: file position
2706 * @ppos: the current position in the file
2708 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2709 * values from/to the user buffer, treated as an ASCII string.
2710 * The values read are assumed to be in 1/1000 seconds, and
2711 * are converted into jiffies.
2713 * Returns 0 on success.
2715 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2716 void __user *buffer, size_t *lenp, loff_t *ppos)
2718 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2719 do_proc_dointvec_ms_jiffies_conv, NULL);
2722 static int proc_do_cad_pid(struct ctl_table *table, int write,
2723 void __user *buffer, size_t *lenp, loff_t *ppos)
2725 struct pid *new_pid;
2729 tmp = pid_vnr(cad_pid);
2731 r = __do_proc_dointvec(&tmp, table, write, buffer,
2732 lenp, ppos, NULL, NULL);
2736 new_pid = find_get_pid(tmp);
2740 put_pid(xchg(&cad_pid, new_pid));
2745 * proc_do_large_bitmap - read/write from/to a large bitmap
2746 * @table: the sysctl table
2747 * @write: %TRUE if this is a write to the sysctl file
2748 * @buffer: the user buffer
2749 * @lenp: the size of the user buffer
2750 * @ppos: file position
2752 * The bitmap is stored at table->data and the bitmap length (in bits)
2755 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2756 * large bitmaps may be represented in a compact manner. Writing into
2757 * the file will clear the bitmap then update it with the given input.
2759 * Returns 0 on success.
2761 int proc_do_large_bitmap(struct ctl_table *table, int write,
2762 void __user *buffer, size_t *lenp, loff_t *ppos)
2766 size_t left = *lenp;
2767 unsigned long bitmap_len = table->maxlen;
2768 unsigned long *bitmap = (unsigned long *) table->data;
2769 unsigned long *tmp_bitmap = NULL;
2770 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2772 if (!bitmap_len || !left || (*ppos && !write)) {
2778 unsigned long page = 0;
2781 if (left > PAGE_SIZE - 1)
2782 left = PAGE_SIZE - 1;
2784 page = __get_free_page(GFP_TEMPORARY);
2785 kbuf = (char *) page;
2788 if (copy_from_user(kbuf, buffer, left)) {
2794 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2800 proc_skip_char(&kbuf, &left, '\n');
2801 while (!err && left) {
2802 unsigned long val_a, val_b;
2805 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2809 if (val_a >= bitmap_len || neg) {
2821 err = proc_get_long(&kbuf, &left, &val_b,
2822 &neg, tr_b, sizeof(tr_b),
2826 if (val_b >= bitmap_len || neg ||
2837 while (val_a <= val_b)
2838 set_bit(val_a++, tmp_bitmap);
2841 proc_skip_char(&kbuf, &left, '\n');
2845 unsigned long bit_a, bit_b = 0;
2848 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2849 if (bit_a >= bitmap_len)
2851 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2855 err = proc_put_char(&buffer, &left, ',');
2859 err = proc_put_long(&buffer, &left, bit_a, false);
2862 if (bit_a != bit_b) {
2863 err = proc_put_char(&buffer, &left, '-');
2866 err = proc_put_long(&buffer, &left, bit_b, false);
2874 err = proc_put_char(&buffer, &left, '\n');
2880 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2882 memcpy(bitmap, tmp_bitmap,
2883 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2895 #else /* CONFIG_PROC_FS */
2897 int proc_dostring(struct ctl_table *table, int write,
2898 void __user *buffer, size_t *lenp, loff_t *ppos)
2903 int proc_dointvec(struct ctl_table *table, int write,
2904 void __user *buffer, size_t *lenp, loff_t *ppos)
2909 int proc_dointvec_minmax(struct ctl_table *table, int write,
2910 void __user *buffer, size_t *lenp, loff_t *ppos)
2915 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2916 void __user *buffer, size_t *lenp, loff_t *ppos)
2921 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2922 void __user *buffer, size_t *lenp, loff_t *ppos)
2927 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2928 void __user *buffer, size_t *lenp, loff_t *ppos)
2933 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2934 void __user *buffer, size_t *lenp, loff_t *ppos)
2939 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2940 void __user *buffer,
2941 size_t *lenp, loff_t *ppos)
2947 #endif /* CONFIG_PROC_FS */
2950 * No sense putting this after each symbol definition, twice,
2951 * exception granted :-)
2953 EXPORT_SYMBOL(proc_dointvec);
2954 EXPORT_SYMBOL(proc_dointvec_jiffies);
2955 EXPORT_SYMBOL(proc_dointvec_minmax);
2956 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2957 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2958 EXPORT_SYMBOL(proc_dostring);
2959 EXPORT_SYMBOL(proc_doulongvec_minmax);
2960 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2961 EXPORT_SYMBOL(register_sysctl_table);
2962 EXPORT_SYMBOL(register_sysctl_paths);
2963 EXPORT_SYMBOL(unregister_sysctl_table);