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/printk.h>
28 #include <linux/proc_fs.h>
29 #include <linux/security.h>
30 #include <linux/ctype.h>
31 #include <linux/kmemcheck.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/ratelimit.h>
41 #include <linux/compaction.h>
42 #include <linux/hugetlb.h>
43 #include <linux/initrd.h>
44 #include <linux/key.h>
45 #include <linux/times.h>
46 #include <linux/limits.h>
47 #include <linux/dcache.h>
48 #include <linux/dnotify.h>
49 #include <linux/syscalls.h>
50 #include <linux/vmstat.h>
51 #include <linux/nfs_fs.h>
52 #include <linux/acpi.h>
53 #include <linux/reboot.h>
54 #include <linux/ftrace.h>
55 #include <linux/perf_event.h>
56 #include <linux/kprobes.h>
57 #include <linux/pipe_fs_i.h>
58 #include <linux/oom.h>
60 #include <asm/uaccess.h>
61 #include <asm/processor.h>
65 #include <asm/stacktrace.h>
68 #ifdef CONFIG_BSD_PROCESS_ACCT
69 #include <linux/acct.h>
71 #ifdef CONFIG_RT_MUTEXES
72 #include <linux/rtmutex.h>
74 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
75 #include <linux/lockdep.h>
77 #ifdef CONFIG_CHR_DEV_SG
81 #ifdef CONFIG_LOCKUP_DETECTOR
82 #include <linux/nmi.h>
86 #if defined(CONFIG_SYSCTL)
88 /* External variables not in a header file. */
89 extern int sysctl_overcommit_memory;
90 extern int sysctl_overcommit_ratio;
91 extern int max_threads;
92 extern int core_uses_pid;
93 extern int suid_dumpable;
94 extern char core_pattern[];
95 extern unsigned int core_pipe_limit;
97 extern int min_free_kbytes;
98 extern int pid_max_min, pid_max_max;
99 extern int sysctl_drop_caches;
100 extern int percpu_pagelist_fraction;
101 extern int compat_log;
102 extern int latencytop_enabled;
103 extern int sysctl_nr_open_min, sysctl_nr_open_max;
105 extern int sysctl_nr_trim_pages;
108 extern int blk_iopoll_enabled;
111 /* Constants used for minimum and maximum */
112 #ifdef CONFIG_LOCKUP_DETECTOR
113 static int sixty = 60;
114 static int neg_one = -1;
118 static int __maybe_unused one = 1;
119 static int __maybe_unused two = 2;
120 static int __maybe_unused three = 3;
121 static unsigned long one_ul = 1;
122 static int one_hundred = 100;
124 static int ten_thousand = 10000;
127 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
128 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
130 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
131 static int maxolduid = 65535;
132 static int minolduid;
133 static int min_percpu_pagelist_fract = 8;
135 static int ngroups_max = NGROUPS_MAX;
137 #ifdef CONFIG_INOTIFY_USER
138 #include <linux/inotify.h>
141 #include <asm/system.h>
144 #ifdef CONFIG_SPARC64
145 extern int sysctl_tsb_ratio;
149 extern int pwrsw_enabled;
150 extern int unaligned_enabled;
154 #ifdef CONFIG_MATHEMU
155 extern int sysctl_ieee_emulation_warnings;
157 extern int sysctl_userprocess_debug;
158 extern int spin_retry;
162 extern int no_unaligned_warning;
163 extern int unaligned_dump_stack;
166 #ifdef CONFIG_PROC_SYSCTL
167 static int proc_do_cad_pid(struct ctl_table *table, int write,
168 void __user *buffer, size_t *lenp, loff_t *ppos);
169 static int proc_taint(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
173 #ifdef CONFIG_MAGIC_SYSRQ
174 /* Note: sysrq code uses it's own private copy */
175 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
177 static int sysrq_sysctl_handler(ctl_table *table, int write,
178 void __user *buffer, size_t *lenp,
183 error = proc_dointvec(table, write, buffer, lenp, ppos);
188 sysrq_toggle_support(__sysrq_enabled);
195 static struct ctl_table root_table[];
196 static struct ctl_table_root sysctl_table_root;
197 static struct ctl_table_header root_table_header = {
199 .ctl_table = root_table,
200 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}},
201 .root = &sysctl_table_root,
202 .set = &sysctl_table_root.default_set,
204 static struct ctl_table_root sysctl_table_root = {
205 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
206 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
209 static struct ctl_table kern_table[];
210 static struct ctl_table vm_table[];
211 static struct ctl_table fs_table[];
212 static struct ctl_table debug_table[];
213 static struct ctl_table dev_table[];
214 extern struct ctl_table random_table[];
216 extern struct ctl_table epoll_table[];
219 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
220 int sysctl_legacy_va_layout;
223 /* The default sysctl tables: */
225 static struct ctl_table root_table[] = {
227 .procname = "kernel",
244 .child = debug_table,
254 #ifdef CONFIG_SCHED_DEBUG
255 static int min_sched_granularity_ns = 100000; /* 100 usecs */
256 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
257 static int min_wakeup_granularity_ns; /* 0 usecs */
258 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
259 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
260 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
263 #ifdef CONFIG_COMPACTION
264 static int min_extfrag_threshold;
265 static int max_extfrag_threshold = 1000;
268 static struct ctl_table kern_table[] = {
270 .procname = "sched_child_runs_first",
271 .data = &sysctl_sched_child_runs_first,
272 .maxlen = sizeof(unsigned int),
274 .proc_handler = proc_dointvec,
276 #ifdef CONFIG_SCHED_DEBUG
278 .procname = "sched_min_granularity_ns",
279 .data = &sysctl_sched_min_granularity,
280 .maxlen = sizeof(unsigned int),
282 .proc_handler = sched_proc_update_handler,
283 .extra1 = &min_sched_granularity_ns,
284 .extra2 = &max_sched_granularity_ns,
287 .procname = "sched_latency_ns",
288 .data = &sysctl_sched_latency,
289 .maxlen = sizeof(unsigned int),
291 .proc_handler = sched_proc_update_handler,
292 .extra1 = &min_sched_granularity_ns,
293 .extra2 = &max_sched_granularity_ns,
296 .procname = "sched_wakeup_granularity_ns",
297 .data = &sysctl_sched_wakeup_granularity,
298 .maxlen = sizeof(unsigned int),
300 .proc_handler = sched_proc_update_handler,
301 .extra1 = &min_wakeup_granularity_ns,
302 .extra2 = &max_wakeup_granularity_ns,
305 .procname = "sched_tunable_scaling",
306 .data = &sysctl_sched_tunable_scaling,
307 .maxlen = sizeof(enum sched_tunable_scaling),
309 .proc_handler = sched_proc_update_handler,
310 .extra1 = &min_sched_tunable_scaling,
311 .extra2 = &max_sched_tunable_scaling,
314 .procname = "sched_migration_cost",
315 .data = &sysctl_sched_migration_cost,
316 .maxlen = sizeof(unsigned int),
318 .proc_handler = proc_dointvec,
321 .procname = "sched_nr_migrate",
322 .data = &sysctl_sched_nr_migrate,
323 .maxlen = sizeof(unsigned int),
325 .proc_handler = proc_dointvec,
328 .procname = "sched_time_avg",
329 .data = &sysctl_sched_time_avg,
330 .maxlen = sizeof(unsigned int),
332 .proc_handler = proc_dointvec,
335 .procname = "sched_shares_window",
336 .data = &sysctl_sched_shares_window,
337 .maxlen = sizeof(unsigned int),
339 .proc_handler = proc_dointvec,
342 .procname = "timer_migration",
343 .data = &sysctl_timer_migration,
344 .maxlen = sizeof(unsigned int),
346 .proc_handler = proc_dointvec_minmax,
352 .procname = "sched_rt_period_us",
353 .data = &sysctl_sched_rt_period,
354 .maxlen = sizeof(unsigned int),
356 .proc_handler = sched_rt_handler,
359 .procname = "sched_rt_runtime_us",
360 .data = &sysctl_sched_rt_runtime,
361 .maxlen = sizeof(int),
363 .proc_handler = sched_rt_handler,
365 #ifdef CONFIG_SCHED_AUTOGROUP
367 .procname = "sched_autogroup_enabled",
368 .data = &sysctl_sched_autogroup_enabled,
369 .maxlen = sizeof(unsigned int),
371 .proc_handler = proc_dointvec_minmax,
376 #ifdef CONFIG_PROVE_LOCKING
378 .procname = "prove_locking",
379 .data = &prove_locking,
380 .maxlen = sizeof(int),
382 .proc_handler = proc_dointvec,
385 #ifdef CONFIG_LOCK_STAT
387 .procname = "lock_stat",
389 .maxlen = sizeof(int),
391 .proc_handler = proc_dointvec,
396 .data = &panic_timeout,
397 .maxlen = sizeof(int),
399 .proc_handler = proc_dointvec,
402 .procname = "core_uses_pid",
403 .data = &core_uses_pid,
404 .maxlen = sizeof(int),
406 .proc_handler = proc_dointvec,
409 .procname = "core_pattern",
410 .data = core_pattern,
411 .maxlen = CORENAME_MAX_SIZE,
413 .proc_handler = proc_dostring,
416 .procname = "core_pipe_limit",
417 .data = &core_pipe_limit,
418 .maxlen = sizeof(unsigned int),
420 .proc_handler = proc_dointvec,
422 #ifdef CONFIG_PROC_SYSCTL
424 .procname = "tainted",
425 .maxlen = sizeof(long),
427 .proc_handler = proc_taint,
430 #ifdef CONFIG_LATENCYTOP
432 .procname = "latencytop",
433 .data = &latencytop_enabled,
434 .maxlen = sizeof(int),
436 .proc_handler = proc_dointvec,
439 #ifdef CONFIG_BLK_DEV_INITRD
441 .procname = "real-root-dev",
442 .data = &real_root_dev,
443 .maxlen = sizeof(int),
445 .proc_handler = proc_dointvec,
449 .procname = "print-fatal-signals",
450 .data = &print_fatal_signals,
451 .maxlen = sizeof(int),
453 .proc_handler = proc_dointvec,
457 .procname = "reboot-cmd",
458 .data = reboot_command,
461 .proc_handler = proc_dostring,
464 .procname = "stop-a",
465 .data = &stop_a_enabled,
466 .maxlen = sizeof (int),
468 .proc_handler = proc_dointvec,
471 .procname = "scons-poweroff",
472 .data = &scons_pwroff,
473 .maxlen = sizeof (int),
475 .proc_handler = proc_dointvec,
478 #ifdef CONFIG_SPARC64
480 .procname = "tsb-ratio",
481 .data = &sysctl_tsb_ratio,
482 .maxlen = sizeof (int),
484 .proc_handler = proc_dointvec,
489 .procname = "soft-power",
490 .data = &pwrsw_enabled,
491 .maxlen = sizeof (int),
493 .proc_handler = proc_dointvec,
496 .procname = "unaligned-trap",
497 .data = &unaligned_enabled,
498 .maxlen = sizeof (int),
500 .proc_handler = proc_dointvec,
504 .procname = "ctrl-alt-del",
506 .maxlen = sizeof(int),
508 .proc_handler = proc_dointvec,
510 #ifdef CONFIG_FUNCTION_TRACER
512 .procname = "ftrace_enabled",
513 .data = &ftrace_enabled,
514 .maxlen = sizeof(int),
516 .proc_handler = ftrace_enable_sysctl,
519 #ifdef CONFIG_STACK_TRACER
521 .procname = "stack_tracer_enabled",
522 .data = &stack_tracer_enabled,
523 .maxlen = sizeof(int),
525 .proc_handler = stack_trace_sysctl,
528 #ifdef CONFIG_TRACING
530 .procname = "ftrace_dump_on_oops",
531 .data = &ftrace_dump_on_oops,
532 .maxlen = sizeof(int),
534 .proc_handler = proc_dointvec,
537 #ifdef CONFIG_MODULES
539 .procname = "modprobe",
540 .data = &modprobe_path,
541 .maxlen = KMOD_PATH_LEN,
543 .proc_handler = proc_dostring,
546 .procname = "modules_disabled",
547 .data = &modules_disabled,
548 .maxlen = sizeof(int),
550 /* only handle a transition from default "0" to "1" */
551 .proc_handler = proc_dointvec_minmax,
556 #ifdef CONFIG_HOTPLUG
558 .procname = "hotplug",
559 .data = &uevent_helper,
560 .maxlen = UEVENT_HELPER_PATH_LEN,
562 .proc_handler = proc_dostring,
565 #ifdef CONFIG_CHR_DEV_SG
567 .procname = "sg-big-buff",
568 .data = &sg_big_buff,
569 .maxlen = sizeof (int),
571 .proc_handler = proc_dointvec,
574 #ifdef CONFIG_BSD_PROCESS_ACCT
578 .maxlen = 3*sizeof(int),
580 .proc_handler = proc_dointvec,
583 #ifdef CONFIG_MAGIC_SYSRQ
586 .data = &__sysrq_enabled,
587 .maxlen = sizeof (int),
589 .proc_handler = sysrq_sysctl_handler,
592 #ifdef CONFIG_PROC_SYSCTL
594 .procname = "cad_pid",
596 .maxlen = sizeof (int),
598 .proc_handler = proc_do_cad_pid,
602 .procname = "threads-max",
603 .data = &max_threads,
604 .maxlen = sizeof(int),
606 .proc_handler = proc_dointvec,
609 .procname = "random",
611 .child = random_table,
614 .procname = "overflowuid",
615 .data = &overflowuid,
616 .maxlen = sizeof(int),
618 .proc_handler = proc_dointvec_minmax,
619 .extra1 = &minolduid,
620 .extra2 = &maxolduid,
623 .procname = "overflowgid",
624 .data = &overflowgid,
625 .maxlen = sizeof(int),
627 .proc_handler = proc_dointvec_minmax,
628 .extra1 = &minolduid,
629 .extra2 = &maxolduid,
632 #ifdef CONFIG_MATHEMU
634 .procname = "ieee_emulation_warnings",
635 .data = &sysctl_ieee_emulation_warnings,
636 .maxlen = sizeof(int),
638 .proc_handler = proc_dointvec,
642 .procname = "userprocess_debug",
643 .data = &show_unhandled_signals,
644 .maxlen = sizeof(int),
646 .proc_handler = proc_dointvec,
650 .procname = "pid_max",
652 .maxlen = sizeof (int),
654 .proc_handler = proc_dointvec_minmax,
655 .extra1 = &pid_max_min,
656 .extra2 = &pid_max_max,
659 .procname = "panic_on_oops",
660 .data = &panic_on_oops,
661 .maxlen = sizeof(int),
663 .proc_handler = proc_dointvec,
665 #if defined CONFIG_PRINTK
667 .procname = "printk",
668 .data = &console_loglevel,
669 .maxlen = 4*sizeof(int),
671 .proc_handler = proc_dointvec,
674 .procname = "printk_ratelimit",
675 .data = &printk_ratelimit_state.interval,
676 .maxlen = sizeof(int),
678 .proc_handler = proc_dointvec_jiffies,
681 .procname = "printk_ratelimit_burst",
682 .data = &printk_ratelimit_state.burst,
683 .maxlen = sizeof(int),
685 .proc_handler = proc_dointvec,
688 .procname = "printk_delay",
689 .data = &printk_delay_msec,
690 .maxlen = sizeof(int),
692 .proc_handler = proc_dointvec_minmax,
694 .extra2 = &ten_thousand,
697 .procname = "dmesg_restrict",
698 .data = &dmesg_restrict,
699 .maxlen = sizeof(int),
701 .proc_handler = proc_dointvec_minmax,
706 .procname = "kptr_restrict",
707 .data = &kptr_restrict,
708 .maxlen = sizeof(int),
710 .proc_handler = proc_dointvec_minmax,
716 .procname = "ngroups_max",
717 .data = &ngroups_max,
718 .maxlen = sizeof (int),
720 .proc_handler = proc_dointvec,
722 #if defined(CONFIG_LOCKUP_DETECTOR)
724 .procname = "watchdog",
725 .data = &watchdog_enabled,
726 .maxlen = sizeof (int),
728 .proc_handler = proc_dowatchdog_enabled,
731 .procname = "watchdog_thresh",
732 .data = &softlockup_thresh,
733 .maxlen = sizeof(int),
735 .proc_handler = proc_dowatchdog_thresh,
740 .procname = "softlockup_panic",
741 .data = &softlockup_panic,
742 .maxlen = sizeof(int),
744 .proc_handler = proc_dointvec_minmax,
749 .procname = "nmi_watchdog",
750 .data = &watchdog_enabled,
751 .maxlen = sizeof (int),
753 .proc_handler = proc_dowatchdog_enabled,
756 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
758 .procname = "unknown_nmi_panic",
759 .data = &unknown_nmi_panic,
760 .maxlen = sizeof (int),
762 .proc_handler = proc_dointvec,
765 #if defined(CONFIG_X86)
767 .procname = "panic_on_unrecovered_nmi",
768 .data = &panic_on_unrecovered_nmi,
769 .maxlen = sizeof(int),
771 .proc_handler = proc_dointvec,
774 .procname = "panic_on_io_nmi",
775 .data = &panic_on_io_nmi,
776 .maxlen = sizeof(int),
778 .proc_handler = proc_dointvec,
781 .procname = "bootloader_type",
782 .data = &bootloader_type,
783 .maxlen = sizeof (int),
785 .proc_handler = proc_dointvec,
788 .procname = "bootloader_version",
789 .data = &bootloader_version,
790 .maxlen = sizeof (int),
792 .proc_handler = proc_dointvec,
795 .procname = "kstack_depth_to_print",
796 .data = &kstack_depth_to_print,
797 .maxlen = sizeof(int),
799 .proc_handler = proc_dointvec,
802 .procname = "io_delay_type",
803 .data = &io_delay_type,
804 .maxlen = sizeof(int),
806 .proc_handler = proc_dointvec,
809 #if defined(CONFIG_MMU)
811 .procname = "randomize_va_space",
812 .data = &randomize_va_space,
813 .maxlen = sizeof(int),
815 .proc_handler = proc_dointvec,
818 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
820 .procname = "spin_retry",
822 .maxlen = sizeof (int),
824 .proc_handler = proc_dointvec,
827 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
829 .procname = "acpi_video_flags",
830 .data = &acpi_realmode_flags,
831 .maxlen = sizeof (unsigned long),
833 .proc_handler = proc_doulongvec_minmax,
838 .procname = "ignore-unaligned-usertrap",
839 .data = &no_unaligned_warning,
840 .maxlen = sizeof (int),
842 .proc_handler = proc_dointvec,
845 .procname = "unaligned-dump-stack",
846 .data = &unaligned_dump_stack,
847 .maxlen = sizeof (int),
849 .proc_handler = proc_dointvec,
852 #ifdef CONFIG_DETECT_HUNG_TASK
854 .procname = "hung_task_panic",
855 .data = &sysctl_hung_task_panic,
856 .maxlen = sizeof(int),
858 .proc_handler = proc_dointvec_minmax,
863 .procname = "hung_task_check_count",
864 .data = &sysctl_hung_task_check_count,
865 .maxlen = sizeof(unsigned long),
867 .proc_handler = proc_doulongvec_minmax,
870 .procname = "hung_task_timeout_secs",
871 .data = &sysctl_hung_task_timeout_secs,
872 .maxlen = sizeof(unsigned long),
874 .proc_handler = proc_dohung_task_timeout_secs,
877 .procname = "hung_task_warnings",
878 .data = &sysctl_hung_task_warnings,
879 .maxlen = sizeof(unsigned long),
881 .proc_handler = proc_doulongvec_minmax,
886 .procname = "compat-log",
888 .maxlen = sizeof (int),
890 .proc_handler = proc_dointvec,
893 #ifdef CONFIG_RT_MUTEXES
895 .procname = "max_lock_depth",
896 .data = &max_lock_depth,
897 .maxlen = sizeof(int),
899 .proc_handler = proc_dointvec,
903 .procname = "poweroff_cmd",
904 .data = &poweroff_cmd,
905 .maxlen = POWEROFF_CMD_PATH_LEN,
907 .proc_handler = proc_dostring,
913 .child = key_sysctls,
916 #ifdef CONFIG_RCU_TORTURE_TEST
918 .procname = "rcutorture_runnable",
919 .data = &rcutorture_runnable,
920 .maxlen = sizeof(int),
922 .proc_handler = proc_dointvec,
925 #ifdef CONFIG_PERF_EVENTS
927 .procname = "perf_event_paranoid",
928 .data = &sysctl_perf_event_paranoid,
929 .maxlen = sizeof(sysctl_perf_event_paranoid),
931 .proc_handler = proc_dointvec,
934 .procname = "perf_event_mlock_kb",
935 .data = &sysctl_perf_event_mlock,
936 .maxlen = sizeof(sysctl_perf_event_mlock),
938 .proc_handler = proc_dointvec,
941 .procname = "perf_event_max_sample_rate",
942 .data = &sysctl_perf_event_sample_rate,
943 .maxlen = sizeof(sysctl_perf_event_sample_rate),
945 .proc_handler = perf_proc_update_handler,
948 #ifdef CONFIG_KMEMCHECK
950 .procname = "kmemcheck",
951 .data = &kmemcheck_enabled,
952 .maxlen = sizeof(int),
954 .proc_handler = proc_dointvec,
959 .procname = "blk_iopoll",
960 .data = &blk_iopoll_enabled,
961 .maxlen = sizeof(int),
963 .proc_handler = proc_dointvec,
969 static struct ctl_table vm_table[] = {
971 .procname = "overcommit_memory",
972 .data = &sysctl_overcommit_memory,
973 .maxlen = sizeof(sysctl_overcommit_memory),
975 .proc_handler = proc_dointvec_minmax,
980 .procname = "panic_on_oom",
981 .data = &sysctl_panic_on_oom,
982 .maxlen = sizeof(sysctl_panic_on_oom),
984 .proc_handler = proc_dointvec_minmax,
989 .procname = "oom_kill_allocating_task",
990 .data = &sysctl_oom_kill_allocating_task,
991 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
993 .proc_handler = proc_dointvec,
996 .procname = "oom_dump_tasks",
997 .data = &sysctl_oom_dump_tasks,
998 .maxlen = sizeof(sysctl_oom_dump_tasks),
1000 .proc_handler = proc_dointvec,
1003 .procname = "overcommit_ratio",
1004 .data = &sysctl_overcommit_ratio,
1005 .maxlen = sizeof(sysctl_overcommit_ratio),
1007 .proc_handler = proc_dointvec,
1010 .procname = "page-cluster",
1011 .data = &page_cluster,
1012 .maxlen = sizeof(int),
1014 .proc_handler = proc_dointvec_minmax,
1018 .procname = "dirty_background_ratio",
1019 .data = &dirty_background_ratio,
1020 .maxlen = sizeof(dirty_background_ratio),
1022 .proc_handler = dirty_background_ratio_handler,
1024 .extra2 = &one_hundred,
1027 .procname = "dirty_background_bytes",
1028 .data = &dirty_background_bytes,
1029 .maxlen = sizeof(dirty_background_bytes),
1031 .proc_handler = dirty_background_bytes_handler,
1035 .procname = "dirty_ratio",
1036 .data = &vm_dirty_ratio,
1037 .maxlen = sizeof(vm_dirty_ratio),
1039 .proc_handler = dirty_ratio_handler,
1041 .extra2 = &one_hundred,
1044 .procname = "dirty_bytes",
1045 .data = &vm_dirty_bytes,
1046 .maxlen = sizeof(vm_dirty_bytes),
1048 .proc_handler = dirty_bytes_handler,
1049 .extra1 = &dirty_bytes_min,
1052 .procname = "dirty_writeback_centisecs",
1053 .data = &dirty_writeback_interval,
1054 .maxlen = sizeof(dirty_writeback_interval),
1056 .proc_handler = dirty_writeback_centisecs_handler,
1059 .procname = "dirty_expire_centisecs",
1060 .data = &dirty_expire_interval,
1061 .maxlen = sizeof(dirty_expire_interval),
1063 .proc_handler = proc_dointvec_minmax,
1067 .procname = "nr_pdflush_threads",
1068 .data = &nr_pdflush_threads,
1069 .maxlen = sizeof nr_pdflush_threads,
1070 .mode = 0444 /* read-only*/,
1071 .proc_handler = proc_dointvec,
1074 .procname = "swappiness",
1075 .data = &vm_swappiness,
1076 .maxlen = sizeof(vm_swappiness),
1078 .proc_handler = proc_dointvec_minmax,
1080 .extra2 = &one_hundred,
1082 #ifdef CONFIG_HUGETLB_PAGE
1084 .procname = "nr_hugepages",
1086 .maxlen = sizeof(unsigned long),
1088 .proc_handler = hugetlb_sysctl_handler,
1089 .extra1 = (void *)&hugetlb_zero,
1090 .extra2 = (void *)&hugetlb_infinity,
1094 .procname = "nr_hugepages_mempolicy",
1096 .maxlen = sizeof(unsigned long),
1098 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1099 .extra1 = (void *)&hugetlb_zero,
1100 .extra2 = (void *)&hugetlb_infinity,
1104 .procname = "hugetlb_shm_group",
1105 .data = &sysctl_hugetlb_shm_group,
1106 .maxlen = sizeof(gid_t),
1108 .proc_handler = proc_dointvec,
1111 .procname = "hugepages_treat_as_movable",
1112 .data = &hugepages_treat_as_movable,
1113 .maxlen = sizeof(int),
1115 .proc_handler = hugetlb_treat_movable_handler,
1118 .procname = "nr_overcommit_hugepages",
1120 .maxlen = sizeof(unsigned long),
1122 .proc_handler = hugetlb_overcommit_handler,
1123 .extra1 = (void *)&hugetlb_zero,
1124 .extra2 = (void *)&hugetlb_infinity,
1128 .procname = "lowmem_reserve_ratio",
1129 .data = &sysctl_lowmem_reserve_ratio,
1130 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1132 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1135 .procname = "drop_caches",
1136 .data = &sysctl_drop_caches,
1137 .maxlen = sizeof(int),
1139 .proc_handler = drop_caches_sysctl_handler,
1143 #ifdef CONFIG_COMPACTION
1145 .procname = "compact_memory",
1146 .data = &sysctl_compact_memory,
1147 .maxlen = sizeof(int),
1149 .proc_handler = sysctl_compaction_handler,
1152 .procname = "extfrag_threshold",
1153 .data = &sysctl_extfrag_threshold,
1154 .maxlen = sizeof(int),
1156 .proc_handler = sysctl_extfrag_handler,
1157 .extra1 = &min_extfrag_threshold,
1158 .extra2 = &max_extfrag_threshold,
1161 #endif /* CONFIG_COMPACTION */
1163 .procname = "min_free_kbytes",
1164 .data = &min_free_kbytes,
1165 .maxlen = sizeof(min_free_kbytes),
1167 .proc_handler = min_free_kbytes_sysctl_handler,
1171 .procname = "percpu_pagelist_fraction",
1172 .data = &percpu_pagelist_fraction,
1173 .maxlen = sizeof(percpu_pagelist_fraction),
1175 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1176 .extra1 = &min_percpu_pagelist_fract,
1180 .procname = "max_map_count",
1181 .data = &sysctl_max_map_count,
1182 .maxlen = sizeof(sysctl_max_map_count),
1184 .proc_handler = proc_dointvec_minmax,
1189 .procname = "nr_trim_pages",
1190 .data = &sysctl_nr_trim_pages,
1191 .maxlen = sizeof(sysctl_nr_trim_pages),
1193 .proc_handler = proc_dointvec_minmax,
1198 .procname = "laptop_mode",
1199 .data = &laptop_mode,
1200 .maxlen = sizeof(laptop_mode),
1202 .proc_handler = proc_dointvec_jiffies,
1205 .procname = "block_dump",
1206 .data = &block_dump,
1207 .maxlen = sizeof(block_dump),
1209 .proc_handler = proc_dointvec,
1213 .procname = "vfs_cache_pressure",
1214 .data = &sysctl_vfs_cache_pressure,
1215 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1217 .proc_handler = proc_dointvec,
1220 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1222 .procname = "legacy_va_layout",
1223 .data = &sysctl_legacy_va_layout,
1224 .maxlen = sizeof(sysctl_legacy_va_layout),
1226 .proc_handler = proc_dointvec,
1232 .procname = "zone_reclaim_mode",
1233 .data = &zone_reclaim_mode,
1234 .maxlen = sizeof(zone_reclaim_mode),
1236 .proc_handler = proc_dointvec,
1240 .procname = "min_unmapped_ratio",
1241 .data = &sysctl_min_unmapped_ratio,
1242 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1244 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1246 .extra2 = &one_hundred,
1249 .procname = "min_slab_ratio",
1250 .data = &sysctl_min_slab_ratio,
1251 .maxlen = sizeof(sysctl_min_slab_ratio),
1253 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1255 .extra2 = &one_hundred,
1260 .procname = "stat_interval",
1261 .data = &sysctl_stat_interval,
1262 .maxlen = sizeof(sysctl_stat_interval),
1264 .proc_handler = proc_dointvec_jiffies,
1269 .procname = "mmap_min_addr",
1270 .data = &dac_mmap_min_addr,
1271 .maxlen = sizeof(unsigned long),
1273 .proc_handler = mmap_min_addr_handler,
1278 .procname = "numa_zonelist_order",
1279 .data = &numa_zonelist_order,
1280 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1282 .proc_handler = numa_zonelist_order_handler,
1285 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1286 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1288 .procname = "vdso_enabled",
1289 .data = &vdso_enabled,
1290 .maxlen = sizeof(vdso_enabled),
1292 .proc_handler = proc_dointvec,
1296 #ifdef CONFIG_HIGHMEM
1298 .procname = "highmem_is_dirtyable",
1299 .data = &vm_highmem_is_dirtyable,
1300 .maxlen = sizeof(vm_highmem_is_dirtyable),
1302 .proc_handler = proc_dointvec_minmax,
1308 .procname = "scan_unevictable_pages",
1309 .data = &scan_unevictable_pages,
1310 .maxlen = sizeof(scan_unevictable_pages),
1312 .proc_handler = scan_unevictable_handler,
1314 #ifdef CONFIG_MEMORY_FAILURE
1316 .procname = "memory_failure_early_kill",
1317 .data = &sysctl_memory_failure_early_kill,
1318 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1320 .proc_handler = proc_dointvec_minmax,
1325 .procname = "memory_failure_recovery",
1326 .data = &sysctl_memory_failure_recovery,
1327 .maxlen = sizeof(sysctl_memory_failure_recovery),
1329 .proc_handler = proc_dointvec_minmax,
1337 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1338 static struct ctl_table binfmt_misc_table[] = {
1343 static struct ctl_table fs_table[] = {
1345 .procname = "inode-nr",
1346 .data = &inodes_stat,
1347 .maxlen = 2*sizeof(int),
1349 .proc_handler = proc_nr_inodes,
1352 .procname = "inode-state",
1353 .data = &inodes_stat,
1354 .maxlen = 7*sizeof(int),
1356 .proc_handler = proc_nr_inodes,
1359 .procname = "file-nr",
1360 .data = &files_stat,
1361 .maxlen = sizeof(files_stat),
1363 .proc_handler = proc_nr_files,
1366 .procname = "file-max",
1367 .data = &files_stat.max_files,
1368 .maxlen = sizeof(files_stat.max_files),
1370 .proc_handler = proc_doulongvec_minmax,
1373 .procname = "nr_open",
1374 .data = &sysctl_nr_open,
1375 .maxlen = sizeof(int),
1377 .proc_handler = proc_dointvec_minmax,
1378 .extra1 = &sysctl_nr_open_min,
1379 .extra2 = &sysctl_nr_open_max,
1382 .procname = "dentry-state",
1383 .data = &dentry_stat,
1384 .maxlen = 6*sizeof(int),
1386 .proc_handler = proc_nr_dentry,
1389 .procname = "overflowuid",
1390 .data = &fs_overflowuid,
1391 .maxlen = sizeof(int),
1393 .proc_handler = proc_dointvec_minmax,
1394 .extra1 = &minolduid,
1395 .extra2 = &maxolduid,
1398 .procname = "overflowgid",
1399 .data = &fs_overflowgid,
1400 .maxlen = sizeof(int),
1402 .proc_handler = proc_dointvec_minmax,
1403 .extra1 = &minolduid,
1404 .extra2 = &maxolduid,
1406 #ifdef CONFIG_FILE_LOCKING
1408 .procname = "leases-enable",
1409 .data = &leases_enable,
1410 .maxlen = sizeof(int),
1412 .proc_handler = proc_dointvec,
1415 #ifdef CONFIG_DNOTIFY
1417 .procname = "dir-notify-enable",
1418 .data = &dir_notify_enable,
1419 .maxlen = sizeof(int),
1421 .proc_handler = proc_dointvec,
1425 #ifdef CONFIG_FILE_LOCKING
1427 .procname = "lease-break-time",
1428 .data = &lease_break_time,
1429 .maxlen = sizeof(int),
1431 .proc_handler = proc_dointvec,
1436 .procname = "aio-nr",
1438 .maxlen = sizeof(aio_nr),
1440 .proc_handler = proc_doulongvec_minmax,
1443 .procname = "aio-max-nr",
1444 .data = &aio_max_nr,
1445 .maxlen = sizeof(aio_max_nr),
1447 .proc_handler = proc_doulongvec_minmax,
1449 #endif /* CONFIG_AIO */
1450 #ifdef CONFIG_INOTIFY_USER
1452 .procname = "inotify",
1454 .child = inotify_table,
1459 .procname = "epoll",
1461 .child = epoll_table,
1466 .procname = "suid_dumpable",
1467 .data = &suid_dumpable,
1468 .maxlen = sizeof(int),
1470 .proc_handler = proc_dointvec_minmax,
1474 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1476 .procname = "binfmt_misc",
1478 .child = binfmt_misc_table,
1482 .procname = "pipe-max-size",
1483 .data = &pipe_max_size,
1484 .maxlen = sizeof(int),
1486 .proc_handler = &pipe_proc_fn,
1487 .extra1 = &pipe_min_size,
1492 static struct ctl_table debug_table[] = {
1493 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1494 defined(CONFIG_S390)
1496 .procname = "exception-trace",
1497 .data = &show_unhandled_signals,
1498 .maxlen = sizeof(int),
1500 .proc_handler = proc_dointvec
1503 #if defined(CONFIG_OPTPROBES)
1505 .procname = "kprobes-optimization",
1506 .data = &sysctl_kprobes_optimization,
1507 .maxlen = sizeof(int),
1509 .proc_handler = proc_kprobes_optimization_handler,
1517 static struct ctl_table dev_table[] = {
1521 static DEFINE_SPINLOCK(sysctl_lock);
1523 /* called under sysctl_lock */
1524 static int use_table(struct ctl_table_header *p)
1526 if (unlikely(p->unregistering))
1532 /* called under sysctl_lock */
1533 static void unuse_table(struct ctl_table_header *p)
1536 if (unlikely(p->unregistering))
1537 complete(p->unregistering);
1540 /* called under sysctl_lock, will reacquire if has to wait */
1541 static void start_unregistering(struct ctl_table_header *p)
1544 * if p->used is 0, nobody will ever touch that entry again;
1545 * we'll eliminate all paths to it before dropping sysctl_lock
1547 if (unlikely(p->used)) {
1548 struct completion wait;
1549 init_completion(&wait);
1550 p->unregistering = &wait;
1551 spin_unlock(&sysctl_lock);
1552 wait_for_completion(&wait);
1553 spin_lock(&sysctl_lock);
1555 /* anything non-NULL; we'll never dereference it */
1556 p->unregistering = ERR_PTR(-EINVAL);
1559 * do not remove from the list until nobody holds it; walking the
1560 * list in do_sysctl() relies on that.
1562 list_del_init(&p->ctl_entry);
1565 void sysctl_head_get(struct ctl_table_header *head)
1567 spin_lock(&sysctl_lock);
1569 spin_unlock(&sysctl_lock);
1572 static void free_head(struct rcu_head *rcu)
1574 kfree(container_of(rcu, struct ctl_table_header, rcu));
1577 void sysctl_head_put(struct ctl_table_header *head)
1579 spin_lock(&sysctl_lock);
1581 call_rcu(&head->rcu, free_head);
1582 spin_unlock(&sysctl_lock);
1585 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1589 spin_lock(&sysctl_lock);
1590 if (!use_table(head))
1591 head = ERR_PTR(-ENOENT);
1592 spin_unlock(&sysctl_lock);
1596 void sysctl_head_finish(struct ctl_table_header *head)
1600 spin_lock(&sysctl_lock);
1602 spin_unlock(&sysctl_lock);
1605 static struct ctl_table_set *
1606 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1608 struct ctl_table_set *set = &root->default_set;
1610 set = root->lookup(root, namespaces);
1614 static struct list_head *
1615 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1617 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1621 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1622 struct ctl_table_header *prev)
1624 struct ctl_table_root *root;
1625 struct list_head *header_list;
1626 struct ctl_table_header *head;
1627 struct list_head *tmp;
1629 spin_lock(&sysctl_lock);
1632 tmp = &prev->ctl_entry;
1636 tmp = &root_table_header.ctl_entry;
1638 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1640 if (!use_table(head))
1642 spin_unlock(&sysctl_lock);
1647 header_list = lookup_header_list(root, namespaces);
1648 if (tmp != header_list)
1652 root = list_entry(root->root_list.next,
1653 struct ctl_table_root, root_list);
1654 if (root == &sysctl_table_root)
1656 header_list = lookup_header_list(root, namespaces);
1657 } while (list_empty(header_list));
1658 tmp = header_list->next;
1661 spin_unlock(&sysctl_lock);
1665 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1667 return __sysctl_head_next(current->nsproxy, prev);
1670 void register_sysctl_root(struct ctl_table_root *root)
1672 spin_lock(&sysctl_lock);
1673 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1674 spin_unlock(&sysctl_lock);
1678 * sysctl_perm does NOT grant the superuser all rights automatically, because
1679 * some sysctl variables are readonly even to root.
1682 static int test_perm(int mode, int op)
1684 if (!current_euid())
1686 else if (in_egroup_p(0))
1688 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1693 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1697 if (root->permissions)
1698 mode = root->permissions(root, current->nsproxy, table);
1702 return test_perm(mode, op);
1705 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1707 for (; table->procname; table++) {
1708 table->parent = parent;
1710 sysctl_set_parent(table, table->child);
1714 static __init int sysctl_init(void)
1716 sysctl_set_parent(NULL, root_table);
1717 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1718 sysctl_check_table(current->nsproxy, root_table);
1723 core_initcall(sysctl_init);
1725 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1726 struct ctl_table *table)
1728 struct ctl_table *p;
1729 const char *s = branch->procname;
1731 /* branch should have named subdirectory as its first element */
1732 if (!s || !branch->child)
1735 /* ... and nothing else */
1736 if (branch[1].procname)
1739 /* table should contain subdirectory with the same name */
1740 for (p = table; p->procname; p++) {
1743 if (p->procname && strcmp(p->procname, s) == 0)
1749 /* see if attaching q to p would be an improvement */
1750 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1752 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1753 struct ctl_table *next;
1755 int not_in_parent = !p->attached_by;
1757 while ((next = is_branch_in(by, to)) != NULL) {
1758 if (by == q->attached_by)
1760 if (to == p->attached_by)
1766 if (is_better && not_in_parent) {
1767 q->attached_by = by;
1768 q->attached_to = to;
1774 * __register_sysctl_paths - register a sysctl hierarchy
1775 * @root: List of sysctl headers to register on
1776 * @namespaces: Data to compute which lists of sysctl entries are visible
1777 * @path: The path to the directory the sysctl table is in.
1778 * @table: the top-level table structure
1780 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1781 * array. A completely 0 filled entry terminates the table.
1783 * The members of the &struct ctl_table structure are used as follows:
1785 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1786 * enter a sysctl file
1788 * data - a pointer to data for use by proc_handler
1790 * maxlen - the maximum size in bytes of the data
1792 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1794 * child - a pointer to the child sysctl table if this entry is a directory, or
1797 * proc_handler - the text handler routine (described below)
1799 * de - for internal use by the sysctl routines
1801 * extra1, extra2 - extra pointers usable by the proc handler routines
1803 * Leaf nodes in the sysctl tree will be represented by a single file
1804 * under /proc; non-leaf nodes will be represented by directories.
1806 * sysctl(2) can automatically manage read and write requests through
1807 * the sysctl table. The data and maxlen fields of the ctl_table
1808 * struct enable minimal validation of the values being written to be
1809 * performed, and the mode field allows minimal authentication.
1811 * There must be a proc_handler routine for any terminal nodes
1812 * mirrored under /proc/sys (non-terminals are handled by a built-in
1813 * directory handler). Several default handlers are available to
1814 * cover common cases -
1816 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1817 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1818 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1820 * It is the handler's job to read the input buffer from user memory
1821 * and process it. The handler should return 0 on success.
1823 * This routine returns %NULL on a failure to register, and a pointer
1824 * to the table header on success.
1826 struct ctl_table_header *__register_sysctl_paths(
1827 struct ctl_table_root *root,
1828 struct nsproxy *namespaces,
1829 const struct ctl_path *path, struct ctl_table *table)
1831 struct ctl_table_header *header;
1832 struct ctl_table *new, **prevp;
1833 unsigned int n, npath;
1834 struct ctl_table_set *set;
1836 /* Count the path components */
1837 for (npath = 0; path[npath].procname; ++npath)
1841 * For each path component, allocate a 2-element ctl_table array.
1842 * The first array element will be filled with the sysctl entry
1843 * for this, the second will be the sentinel (procname == 0).
1845 * We allocate everything in one go so that we don't have to
1846 * worry about freeing additional memory in unregister_sysctl_table.
1848 header = kzalloc(sizeof(struct ctl_table_header) +
1849 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1853 new = (struct ctl_table *) (header + 1);
1855 /* Now connect the dots */
1856 prevp = &header->ctl_table;
1857 for (n = 0; n < npath; ++n, ++path) {
1858 /* Copy the procname */
1859 new->procname = path->procname;
1863 prevp = &new->child;
1868 header->ctl_table_arg = table;
1870 INIT_LIST_HEAD(&header->ctl_entry);
1872 header->unregistering = NULL;
1873 header->root = root;
1874 sysctl_set_parent(NULL, header->ctl_table);
1876 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1877 if (sysctl_check_table(namespaces, header->ctl_table)) {
1882 spin_lock(&sysctl_lock);
1883 header->set = lookup_header_set(root, namespaces);
1884 header->attached_by = header->ctl_table;
1885 header->attached_to = root_table;
1886 header->parent = &root_table_header;
1887 for (set = header->set; set; set = set->parent) {
1888 struct ctl_table_header *p;
1889 list_for_each_entry(p, &set->list, ctl_entry) {
1890 if (p->unregistering)
1892 try_attach(p, header);
1895 header->parent->count++;
1896 list_add_tail(&header->ctl_entry, &header->set->list);
1897 spin_unlock(&sysctl_lock);
1903 * register_sysctl_table_path - register a sysctl table hierarchy
1904 * @path: The path to the directory the sysctl table is in.
1905 * @table: the top-level table structure
1907 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1908 * array. A completely 0 filled entry terminates the table.
1910 * See __register_sysctl_paths for more details.
1912 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1913 struct ctl_table *table)
1915 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1920 * register_sysctl_table - register a sysctl table hierarchy
1921 * @table: the top-level table structure
1923 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1924 * array. A completely 0 filled entry terminates the table.
1926 * See register_sysctl_paths for more details.
1928 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1930 static const struct ctl_path null_path[] = { {} };
1932 return register_sysctl_paths(null_path, table);
1936 * unregister_sysctl_table - unregister a sysctl table hierarchy
1937 * @header: the header returned from register_sysctl_table
1939 * Unregisters the sysctl table and all children. proc entries may not
1940 * actually be removed until they are no longer used by anyone.
1942 void unregister_sysctl_table(struct ctl_table_header * header)
1949 spin_lock(&sysctl_lock);
1950 start_unregistering(header);
1951 if (!--header->parent->count) {
1953 call_rcu(&header->parent->rcu, free_head);
1955 if (!--header->count)
1956 call_rcu(&header->rcu, free_head);
1957 spin_unlock(&sysctl_lock);
1960 int sysctl_is_seen(struct ctl_table_header *p)
1962 struct ctl_table_set *set = p->set;
1964 spin_lock(&sysctl_lock);
1965 if (p->unregistering)
1967 else if (!set->is_seen)
1970 res = set->is_seen(set);
1971 spin_unlock(&sysctl_lock);
1975 void setup_sysctl_set(struct ctl_table_set *p,
1976 struct ctl_table_set *parent,
1977 int (*is_seen)(struct ctl_table_set *))
1979 INIT_LIST_HEAD(&p->list);
1980 p->parent = parent ? parent : &sysctl_table_root.default_set;
1981 p->is_seen = is_seen;
1984 #else /* !CONFIG_SYSCTL */
1985 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1990 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1991 struct ctl_table *table)
1996 void unregister_sysctl_table(struct ctl_table_header * table)
2000 void setup_sysctl_set(struct ctl_table_set *p,
2001 struct ctl_table_set *parent,
2002 int (*is_seen)(struct ctl_table_set *))
2006 void sysctl_head_put(struct ctl_table_header *head)
2010 #endif /* CONFIG_SYSCTL */
2016 #ifdef CONFIG_PROC_SYSCTL
2018 static int _proc_do_string(void* data, int maxlen, int write,
2019 void __user *buffer,
2020 size_t *lenp, loff_t *ppos)
2026 if (!data || !maxlen || !*lenp) {
2034 while (len < *lenp) {
2035 if (get_user(c, p++))
2037 if (c == 0 || c == '\n')
2043 if(copy_from_user(data, buffer, len))
2045 ((char *) data)[len] = 0;
2063 if(copy_to_user(buffer, data, len))
2066 if(put_user('\n', ((char __user *) buffer) + len))
2077 * proc_dostring - read a string sysctl
2078 * @table: the sysctl table
2079 * @write: %TRUE if this is a write to the sysctl file
2080 * @buffer: the user buffer
2081 * @lenp: the size of the user buffer
2082 * @ppos: file position
2084 * Reads/writes a string from/to the user buffer. If the kernel
2085 * buffer provided is not large enough to hold the string, the
2086 * string is truncated. The copied string is %NULL-terminated.
2087 * If the string is being read by the user process, it is copied
2088 * and a newline '\n' is added. It is truncated if the buffer is
2091 * Returns 0 on success.
2093 int proc_dostring(struct ctl_table *table, int write,
2094 void __user *buffer, size_t *lenp, loff_t *ppos)
2096 return _proc_do_string(table->data, table->maxlen, write,
2097 buffer, lenp, ppos);
2100 static size_t proc_skip_spaces(char **buf)
2103 char *tmp = skip_spaces(*buf);
2109 static void proc_skip_char(char **buf, size_t *size, const char v)
2119 #define TMPBUFLEN 22
2121 * proc_get_long - reads an ASCII formatted integer from a user buffer
2123 * @buf: a kernel buffer
2124 * @size: size of the kernel buffer
2125 * @val: this is where the number will be stored
2126 * @neg: set to %TRUE if number is negative
2127 * @perm_tr: a vector which contains the allowed trailers
2128 * @perm_tr_len: size of the perm_tr vector
2129 * @tr: pointer to store the trailer character
2131 * In case of success %0 is returned and @buf and @size are updated with
2132 * the amount of bytes read. If @tr is non-NULL and a trailing
2133 * character exists (size is non-zero after returning from this
2134 * function), @tr is updated with the trailing character.
2136 static int proc_get_long(char **buf, size_t *size,
2137 unsigned long *val, bool *neg,
2138 const char *perm_tr, unsigned perm_tr_len, char *tr)
2141 char *p, tmp[TMPBUFLEN];
2147 if (len > TMPBUFLEN - 1)
2148 len = TMPBUFLEN - 1;
2150 memcpy(tmp, *buf, len);
2154 if (*p == '-' && *size > 1) {
2162 *val = simple_strtoul(p, &p, 0);
2166 /* We don't know if the next char is whitespace thus we may accept
2167 * invalid integers (e.g. 1234...a) or two integers instead of one
2168 * (e.g. 123...1). So lets not allow such large numbers. */
2169 if (len == TMPBUFLEN - 1)
2172 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2175 if (tr && (len < *size))
2185 * proc_put_long - converts an integer to a decimal ASCII formatted string
2187 * @buf: the user buffer
2188 * @size: the size of the user buffer
2189 * @val: the integer to be converted
2190 * @neg: sign of the number, %TRUE for negative
2192 * In case of success %0 is returned and @buf and @size are updated with
2193 * the amount of bytes written.
2195 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2199 char tmp[TMPBUFLEN], *p = tmp;
2201 sprintf(p, "%s%lu", neg ? "-" : "", val);
2205 if (copy_to_user(*buf, tmp, len))
2213 static int proc_put_char(void __user **buf, size_t *size, char c)
2216 char __user **buffer = (char __user **)buf;
2217 if (put_user(c, *buffer))
2219 (*size)--, (*buffer)++;
2225 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2227 int write, void *data)
2230 *valp = *negp ? -*lvalp : *lvalp;
2235 *lvalp = (unsigned long)-val;
2238 *lvalp = (unsigned long)val;
2244 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2246 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2247 int write, void __user *buffer,
2248 size_t *lenp, loff_t *ppos,
2249 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2250 int write, void *data),
2253 int *i, vleft, first = 1, err = 0;
2254 unsigned long page = 0;
2258 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2263 i = (int *) tbl_data;
2264 vleft = table->maxlen / sizeof(*i);
2268 conv = do_proc_dointvec_conv;
2271 if (left > PAGE_SIZE - 1)
2272 left = PAGE_SIZE - 1;
2273 page = __get_free_page(GFP_TEMPORARY);
2274 kbuf = (char *) page;
2277 if (copy_from_user(kbuf, buffer, left)) {
2284 for (; left && vleft--; i++, first=0) {
2289 left -= proc_skip_spaces(&kbuf);
2293 err = proc_get_long(&kbuf, &left, &lval, &neg,
2295 sizeof(proc_wspace_sep), NULL);
2298 if (conv(&neg, &lval, i, 1, data)) {
2303 if (conv(&neg, &lval, i, 0, data)) {
2308 err = proc_put_char(&buffer, &left, '\t');
2311 err = proc_put_long(&buffer, &left, lval, neg);
2317 if (!write && !first && left && !err)
2318 err = proc_put_char(&buffer, &left, '\n');
2319 if (write && !err && left)
2320 left -= proc_skip_spaces(&kbuf);
2325 return err ? : -EINVAL;
2332 static int do_proc_dointvec(struct ctl_table *table, int write,
2333 void __user *buffer, size_t *lenp, loff_t *ppos,
2334 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2335 int write, void *data),
2338 return __do_proc_dointvec(table->data, table, write,
2339 buffer, lenp, ppos, conv, data);
2343 * proc_dointvec - read a vector of integers
2344 * @table: the sysctl table
2345 * @write: %TRUE if this is a write to the sysctl file
2346 * @buffer: the user buffer
2347 * @lenp: the size of the user buffer
2348 * @ppos: file position
2350 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2351 * values from/to the user buffer, treated as an ASCII string.
2353 * Returns 0 on success.
2355 int proc_dointvec(struct ctl_table *table, int write,
2356 void __user *buffer, size_t *lenp, loff_t *ppos)
2358 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2363 * Taint values can only be increased
2364 * This means we can safely use a temporary.
2366 static int proc_taint(struct ctl_table *table, int write,
2367 void __user *buffer, size_t *lenp, loff_t *ppos)
2370 unsigned long tmptaint = get_taint();
2373 if (write && !capable(CAP_SYS_ADMIN))
2378 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2384 * Poor man's atomic or. Not worth adding a primitive
2385 * to everyone's atomic.h for this
2388 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2389 if ((tmptaint >> i) & 1)
2397 struct do_proc_dointvec_minmax_conv_param {
2402 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2404 int write, void *data)
2406 struct do_proc_dointvec_minmax_conv_param *param = data;
2408 int val = *negp ? -*lvalp : *lvalp;
2409 if ((param->min && *param->min > val) ||
2410 (param->max && *param->max < val))
2417 *lvalp = (unsigned long)-val;
2420 *lvalp = (unsigned long)val;
2427 * proc_dointvec_minmax - read a vector of integers with min/max values
2428 * @table: the sysctl table
2429 * @write: %TRUE if this is a write to the sysctl file
2430 * @buffer: the user buffer
2431 * @lenp: the size of the user buffer
2432 * @ppos: file position
2434 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2435 * values from/to the user buffer, treated as an ASCII string.
2437 * This routine will ensure the values are within the range specified by
2438 * table->extra1 (min) and table->extra2 (max).
2440 * Returns 0 on success.
2442 int proc_dointvec_minmax(struct ctl_table *table, int write,
2443 void __user *buffer, size_t *lenp, loff_t *ppos)
2445 struct do_proc_dointvec_minmax_conv_param param = {
2446 .min = (int *) table->extra1,
2447 .max = (int *) table->extra2,
2449 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2450 do_proc_dointvec_minmax_conv, ¶m);
2453 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2454 void __user *buffer,
2455 size_t *lenp, loff_t *ppos,
2456 unsigned long convmul,
2457 unsigned long convdiv)
2459 unsigned long *i, *min, *max;
2460 int vleft, first = 1, err = 0;
2461 unsigned long page = 0;
2465 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2470 i = (unsigned long *) data;
2471 min = (unsigned long *) table->extra1;
2472 max = (unsigned long *) table->extra2;
2473 vleft = table->maxlen / sizeof(unsigned long);
2477 if (left > PAGE_SIZE - 1)
2478 left = PAGE_SIZE - 1;
2479 page = __get_free_page(GFP_TEMPORARY);
2480 kbuf = (char *) page;
2483 if (copy_from_user(kbuf, buffer, left)) {
2490 for (; left && vleft--; i++, first = 0) {
2496 left -= proc_skip_spaces(&kbuf);
2498 err = proc_get_long(&kbuf, &left, &val, &neg,
2500 sizeof(proc_wspace_sep), NULL);
2505 if ((min && val < *min) || (max && val > *max))
2509 val = convdiv * (*i) / convmul;
2511 err = proc_put_char(&buffer, &left, '\t');
2512 err = proc_put_long(&buffer, &left, val, false);
2518 if (!write && !first && left && !err)
2519 err = proc_put_char(&buffer, &left, '\n');
2521 left -= proc_skip_spaces(&kbuf);
2526 return err ? : -EINVAL;
2533 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2534 void __user *buffer,
2535 size_t *lenp, loff_t *ppos,
2536 unsigned long convmul,
2537 unsigned long convdiv)
2539 return __do_proc_doulongvec_minmax(table->data, table, write,
2540 buffer, lenp, ppos, convmul, convdiv);
2544 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2545 * @table: the sysctl table
2546 * @write: %TRUE if this is a write to the sysctl file
2547 * @buffer: the user buffer
2548 * @lenp: the size of the user buffer
2549 * @ppos: file position
2551 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2552 * values from/to the user buffer, treated as an ASCII string.
2554 * This routine will ensure the values are within the range specified by
2555 * table->extra1 (min) and table->extra2 (max).
2557 * Returns 0 on success.
2559 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2560 void __user *buffer, size_t *lenp, loff_t *ppos)
2562 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2566 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2567 * @table: the sysctl table
2568 * @write: %TRUE if this is a write to the sysctl file
2569 * @buffer: the user buffer
2570 * @lenp: the size of the user buffer
2571 * @ppos: file position
2573 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2574 * values from/to the user buffer, treated as an ASCII string. The values
2575 * are treated as milliseconds, and converted to jiffies when they are stored.
2577 * This routine will ensure the values are within the range specified by
2578 * table->extra1 (min) and table->extra2 (max).
2580 * Returns 0 on success.
2582 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2583 void __user *buffer,
2584 size_t *lenp, loff_t *ppos)
2586 return do_proc_doulongvec_minmax(table, write, buffer,
2587 lenp, ppos, HZ, 1000l);
2591 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2593 int write, void *data)
2596 if (*lvalp > LONG_MAX / HZ)
2598 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2604 lval = (unsigned long)-val;
2607 lval = (unsigned long)val;
2614 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2616 int write, void *data)
2619 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2621 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2627 lval = (unsigned long)-val;
2630 lval = (unsigned long)val;
2632 *lvalp = jiffies_to_clock_t(lval);
2637 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2639 int write, void *data)
2642 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2648 lval = (unsigned long)-val;
2651 lval = (unsigned long)val;
2653 *lvalp = jiffies_to_msecs(lval);
2659 * proc_dointvec_jiffies - read a vector of integers as seconds
2660 * @table: the sysctl table
2661 * @write: %TRUE if this is a write to the sysctl file
2662 * @buffer: the user buffer
2663 * @lenp: the size of the user buffer
2664 * @ppos: file position
2666 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2667 * values from/to the user buffer, treated as an ASCII string.
2668 * The values read are assumed to be in seconds, and are converted into
2671 * Returns 0 on success.
2673 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2674 void __user *buffer, size_t *lenp, loff_t *ppos)
2676 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2677 do_proc_dointvec_jiffies_conv,NULL);
2681 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2682 * @table: the sysctl table
2683 * @write: %TRUE if this is a write to the sysctl file
2684 * @buffer: the user buffer
2685 * @lenp: the size of the user buffer
2686 * @ppos: pointer to the file position
2688 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2689 * values from/to the user buffer, treated as an ASCII string.
2690 * The values read are assumed to be in 1/USER_HZ seconds, and
2691 * are converted into jiffies.
2693 * Returns 0 on success.
2695 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2696 void __user *buffer, size_t *lenp, loff_t *ppos)
2698 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2699 do_proc_dointvec_userhz_jiffies_conv,NULL);
2703 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2704 * @table: the sysctl table
2705 * @write: %TRUE if this is a write to the sysctl file
2706 * @buffer: the user buffer
2707 * @lenp: the size of the user buffer
2708 * @ppos: file position
2709 * @ppos: the current position in the file
2711 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2712 * values from/to the user buffer, treated as an ASCII string.
2713 * The values read are assumed to be in 1/1000 seconds, and
2714 * are converted into jiffies.
2716 * Returns 0 on success.
2718 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2719 void __user *buffer, size_t *lenp, loff_t *ppos)
2721 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2722 do_proc_dointvec_ms_jiffies_conv, NULL);
2725 static int proc_do_cad_pid(struct ctl_table *table, int write,
2726 void __user *buffer, size_t *lenp, loff_t *ppos)
2728 struct pid *new_pid;
2732 tmp = pid_vnr(cad_pid);
2734 r = __do_proc_dointvec(&tmp, table, write, buffer,
2735 lenp, ppos, NULL, NULL);
2739 new_pid = find_get_pid(tmp);
2743 put_pid(xchg(&cad_pid, new_pid));
2748 * proc_do_large_bitmap - read/write from/to a large bitmap
2749 * @table: the sysctl table
2750 * @write: %TRUE if this is a write to the sysctl file
2751 * @buffer: the user buffer
2752 * @lenp: the size of the user buffer
2753 * @ppos: file position
2755 * The bitmap is stored at table->data and the bitmap length (in bits)
2758 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2759 * large bitmaps may be represented in a compact manner. Writing into
2760 * the file will clear the bitmap then update it with the given input.
2762 * Returns 0 on success.
2764 int proc_do_large_bitmap(struct ctl_table *table, int write,
2765 void __user *buffer, size_t *lenp, loff_t *ppos)
2769 size_t left = *lenp;
2770 unsigned long bitmap_len = table->maxlen;
2771 unsigned long *bitmap = (unsigned long *) table->data;
2772 unsigned long *tmp_bitmap = NULL;
2773 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2775 if (!bitmap_len || !left || (*ppos && !write)) {
2781 unsigned long page = 0;
2784 if (left > PAGE_SIZE - 1)
2785 left = PAGE_SIZE - 1;
2787 page = __get_free_page(GFP_TEMPORARY);
2788 kbuf = (char *) page;
2791 if (copy_from_user(kbuf, buffer, left)) {
2797 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2803 proc_skip_char(&kbuf, &left, '\n');
2804 while (!err && left) {
2805 unsigned long val_a, val_b;
2808 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2812 if (val_a >= bitmap_len || neg) {
2824 err = proc_get_long(&kbuf, &left, &val_b,
2825 &neg, tr_b, sizeof(tr_b),
2829 if (val_b >= bitmap_len || neg ||
2840 while (val_a <= val_b)
2841 set_bit(val_a++, tmp_bitmap);
2844 proc_skip_char(&kbuf, &left, '\n');
2848 unsigned long bit_a, bit_b = 0;
2851 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2852 if (bit_a >= bitmap_len)
2854 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2858 err = proc_put_char(&buffer, &left, ',');
2862 err = proc_put_long(&buffer, &left, bit_a, false);
2865 if (bit_a != bit_b) {
2866 err = proc_put_char(&buffer, &left, '-');
2869 err = proc_put_long(&buffer, &left, bit_b, false);
2877 err = proc_put_char(&buffer, &left, '\n');
2883 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2885 memcpy(bitmap, tmp_bitmap,
2886 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2898 #else /* CONFIG_PROC_SYSCTL */
2900 int proc_dostring(struct ctl_table *table, int write,
2901 void __user *buffer, size_t *lenp, loff_t *ppos)
2906 int proc_dointvec(struct ctl_table *table, int write,
2907 void __user *buffer, size_t *lenp, loff_t *ppos)
2912 int proc_dointvec_minmax(struct ctl_table *table, int write,
2913 void __user *buffer, size_t *lenp, loff_t *ppos)
2918 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2919 void __user *buffer, size_t *lenp, loff_t *ppos)
2924 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2925 void __user *buffer, size_t *lenp, loff_t *ppos)
2930 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2931 void __user *buffer, size_t *lenp, loff_t *ppos)
2936 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2937 void __user *buffer, size_t *lenp, loff_t *ppos)
2942 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2943 void __user *buffer,
2944 size_t *lenp, loff_t *ppos)
2950 #endif /* CONFIG_PROC_SYSCTL */
2953 * No sense putting this after each symbol definition, twice,
2954 * exception granted :-)
2956 EXPORT_SYMBOL(proc_dointvec);
2957 EXPORT_SYMBOL(proc_dointvec_jiffies);
2958 EXPORT_SYMBOL(proc_dointvec_minmax);
2959 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2960 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2961 EXPORT_SYMBOL(proc_dostring);
2962 EXPORT_SYMBOL(proc_doulongvec_minmax);
2963 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2964 EXPORT_SYMBOL(register_sysctl_table);
2965 EXPORT_SYMBOL(register_sysctl_paths);
2966 EXPORT_SYMBOL(unregister_sysctl_table);