2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/signal.h>
27 #include <linux/proc_fs.h>
28 #include <linux/security.h>
29 #include <linux/ctype.h>
30 #include <linux/kmemcheck.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/ratelimit.h>
40 #include <linux/hugetlb.h>
41 #include <linux/initrd.h>
42 #include <linux/key.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/vmstat.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/acpi.h>
50 #include <linux/reboot.h>
51 #include <linux/ftrace.h>
52 #include <linux/slow-work.h>
53 #include <linux/perf_event.h>
54 #include <linux/kprobes.h>
55 #include <linux/pipe_fs_i.h>
57 #include <asm/uaccess.h>
58 #include <asm/processor.h>
62 #include <asm/stacktrace.h>
65 #ifdef CONFIG_BSD_PROCESS_ACCT
66 #include <linux/acct.h>
68 #ifdef CONFIG_RT_MUTEXES
69 #include <linux/rtmutex.h>
71 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
72 #include <linux/lockdep.h>
74 #ifdef CONFIG_CHR_DEV_SG
79 #if defined(CONFIG_SYSCTL)
81 /* External variables not in a header file. */
82 extern int sysctl_overcommit_memory;
83 extern int sysctl_overcommit_ratio;
84 extern int sysctl_panic_on_oom;
85 extern int sysctl_oom_kill_allocating_task;
86 extern int sysctl_oom_dump_tasks;
87 extern int max_threads;
88 extern int core_uses_pid;
89 extern int suid_dumpable;
90 extern char core_pattern[];
91 extern unsigned int core_pipe_limit;
93 extern int min_free_kbytes;
94 extern int pid_max_min, pid_max_max;
95 extern int sysctl_drop_caches;
96 extern int percpu_pagelist_fraction;
97 extern int compat_log;
98 extern int latencytop_enabled;
99 extern int sysctl_nr_open_min, sysctl_nr_open_max;
101 extern int sysctl_nr_trim_pages;
104 extern int blk_iopoll_enabled;
107 /* Constants used for minimum and maximum */
108 #ifdef CONFIG_DETECT_SOFTLOCKUP
109 static int sixty = 60;
110 static int neg_one = -1;
114 static int __maybe_unused one = 1;
115 static int __maybe_unused two = 2;
116 static unsigned long one_ul = 1;
117 static int one_hundred = 100;
119 static int ten_thousand = 10000;
122 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
123 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
125 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
126 static int maxolduid = 65535;
127 static int minolduid;
128 static int min_percpu_pagelist_fract = 8;
130 static int ngroups_max = NGROUPS_MAX;
133 #include <asm/system.h>
136 #ifdef CONFIG_SPARC64
137 extern int sysctl_tsb_ratio;
141 extern int pwrsw_enabled;
142 extern int unaligned_enabled;
146 #ifdef CONFIG_MATHEMU
147 extern int sysctl_ieee_emulation_warnings;
149 extern int sysctl_userprocess_debug;
150 extern int spin_retry;
154 extern int no_unaligned_warning;
155 extern int unaligned_dump_stack;
158 extern struct ratelimit_state printk_ratelimit_state;
160 #ifdef CONFIG_PROC_SYSCTL
161 static int proc_do_cad_pid(struct ctl_table *table, int write,
162 void __user *buffer, size_t *lenp, loff_t *ppos);
163 static int proc_taint(struct ctl_table *table, int write,
164 void __user *buffer, size_t *lenp, loff_t *ppos);
167 static struct ctl_table root_table[];
168 static struct ctl_table_root sysctl_table_root;
169 static struct ctl_table_header root_table_header = {
171 .ctl_table = root_table,
172 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
173 .root = &sysctl_table_root,
174 .set = &sysctl_table_root.default_set,
176 static struct ctl_table_root sysctl_table_root = {
177 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
178 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
181 static struct ctl_table kern_table[];
182 static struct ctl_table vm_table[];
183 static struct ctl_table fs_table[];
184 static struct ctl_table debug_table[];
185 static struct ctl_table dev_table[];
186 extern struct ctl_table random_table[];
187 #ifdef CONFIG_INOTIFY_USER
188 extern struct ctl_table inotify_table[];
191 extern struct ctl_table epoll_table[];
194 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
195 int sysctl_legacy_va_layout;
198 /* The default sysctl tables: */
200 static struct ctl_table root_table[] = {
202 .procname = "kernel",
219 .child = debug_table,
227 * NOTE: do not add new entries to this table unless you have read
228 * Documentation/sysctl/ctl_unnumbered.txt
233 #ifdef CONFIG_SCHED_DEBUG
234 static int min_sched_granularity_ns = 100000; /* 100 usecs */
235 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
236 static int min_wakeup_granularity_ns; /* 0 usecs */
237 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
238 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
239 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
240 static int min_sched_shares_ratelimit = 100000; /* 100 usec */
241 static int max_sched_shares_ratelimit = NSEC_PER_SEC; /* 1 second */
244 static struct ctl_table kern_table[] = {
246 .procname = "sched_child_runs_first",
247 .data = &sysctl_sched_child_runs_first,
248 .maxlen = sizeof(unsigned int),
250 .proc_handler = proc_dointvec,
252 #ifdef CONFIG_SCHED_DEBUG
254 .procname = "sched_min_granularity_ns",
255 .data = &sysctl_sched_min_granularity,
256 .maxlen = sizeof(unsigned int),
258 .proc_handler = sched_proc_update_handler,
259 .extra1 = &min_sched_granularity_ns,
260 .extra2 = &max_sched_granularity_ns,
263 .procname = "sched_latency_ns",
264 .data = &sysctl_sched_latency,
265 .maxlen = sizeof(unsigned int),
267 .proc_handler = sched_proc_update_handler,
268 .extra1 = &min_sched_granularity_ns,
269 .extra2 = &max_sched_granularity_ns,
272 .procname = "sched_wakeup_granularity_ns",
273 .data = &sysctl_sched_wakeup_granularity,
274 .maxlen = sizeof(unsigned int),
276 .proc_handler = sched_proc_update_handler,
277 .extra1 = &min_wakeup_granularity_ns,
278 .extra2 = &max_wakeup_granularity_ns,
281 .procname = "sched_shares_ratelimit",
282 .data = &sysctl_sched_shares_ratelimit,
283 .maxlen = sizeof(unsigned int),
285 .proc_handler = sched_proc_update_handler,
286 .extra1 = &min_sched_shares_ratelimit,
287 .extra2 = &max_sched_shares_ratelimit,
290 .procname = "sched_tunable_scaling",
291 .data = &sysctl_sched_tunable_scaling,
292 .maxlen = sizeof(enum sched_tunable_scaling),
294 .proc_handler = sched_proc_update_handler,
295 .extra1 = &min_sched_tunable_scaling,
296 .extra2 = &max_sched_tunable_scaling,
299 .procname = "sched_shares_thresh",
300 .data = &sysctl_sched_shares_thresh,
301 .maxlen = sizeof(unsigned int),
303 .proc_handler = proc_dointvec_minmax,
307 .procname = "sched_migration_cost",
308 .data = &sysctl_sched_migration_cost,
309 .maxlen = sizeof(unsigned int),
311 .proc_handler = proc_dointvec,
314 .procname = "sched_nr_migrate",
315 .data = &sysctl_sched_nr_migrate,
316 .maxlen = sizeof(unsigned int),
318 .proc_handler = proc_dointvec,
321 .procname = "sched_time_avg",
322 .data = &sysctl_sched_time_avg,
323 .maxlen = sizeof(unsigned int),
325 .proc_handler = proc_dointvec,
328 .procname = "timer_migration",
329 .data = &sysctl_timer_migration,
330 .maxlen = sizeof(unsigned int),
332 .proc_handler = proc_dointvec_minmax,
338 .procname = "sched_rt_period_us",
339 .data = &sysctl_sched_rt_period,
340 .maxlen = sizeof(unsigned int),
342 .proc_handler = sched_rt_handler,
345 .procname = "sched_rt_runtime_us",
346 .data = &sysctl_sched_rt_runtime,
347 .maxlen = sizeof(int),
349 .proc_handler = sched_rt_handler,
352 .procname = "sched_compat_yield",
353 .data = &sysctl_sched_compat_yield,
354 .maxlen = sizeof(unsigned int),
356 .proc_handler = proc_dointvec,
358 #ifdef CONFIG_PROVE_LOCKING
360 .procname = "prove_locking",
361 .data = &prove_locking,
362 .maxlen = sizeof(int),
364 .proc_handler = proc_dointvec,
367 #ifdef CONFIG_LOCK_STAT
369 .procname = "lock_stat",
371 .maxlen = sizeof(int),
373 .proc_handler = proc_dointvec,
378 .data = &panic_timeout,
379 .maxlen = sizeof(int),
381 .proc_handler = proc_dointvec,
384 .procname = "core_uses_pid",
385 .data = &core_uses_pid,
386 .maxlen = sizeof(int),
388 .proc_handler = proc_dointvec,
391 .procname = "core_pattern",
392 .data = core_pattern,
393 .maxlen = CORENAME_MAX_SIZE,
395 .proc_handler = proc_dostring,
398 .procname = "core_pipe_limit",
399 .data = &core_pipe_limit,
400 .maxlen = sizeof(unsigned int),
402 .proc_handler = proc_dointvec,
404 #ifdef CONFIG_PROC_SYSCTL
406 .procname = "tainted",
407 .maxlen = sizeof(long),
409 .proc_handler = proc_taint,
412 #ifdef CONFIG_LATENCYTOP
414 .procname = "latencytop",
415 .data = &latencytop_enabled,
416 .maxlen = sizeof(int),
418 .proc_handler = proc_dointvec,
421 #ifdef CONFIG_BLK_DEV_INITRD
423 .procname = "real-root-dev",
424 .data = &real_root_dev,
425 .maxlen = sizeof(int),
427 .proc_handler = proc_dointvec,
431 .procname = "print-fatal-signals",
432 .data = &print_fatal_signals,
433 .maxlen = sizeof(int),
435 .proc_handler = proc_dointvec,
439 .procname = "reboot-cmd",
440 .data = reboot_command,
443 .proc_handler = proc_dostring,
446 .procname = "stop-a",
447 .data = &stop_a_enabled,
448 .maxlen = sizeof (int),
450 .proc_handler = proc_dointvec,
453 .procname = "scons-poweroff",
454 .data = &scons_pwroff,
455 .maxlen = sizeof (int),
457 .proc_handler = proc_dointvec,
460 #ifdef CONFIG_SPARC64
462 .procname = "tsb-ratio",
463 .data = &sysctl_tsb_ratio,
464 .maxlen = sizeof (int),
466 .proc_handler = proc_dointvec,
471 .procname = "soft-power",
472 .data = &pwrsw_enabled,
473 .maxlen = sizeof (int),
475 .proc_handler = proc_dointvec,
478 .procname = "unaligned-trap",
479 .data = &unaligned_enabled,
480 .maxlen = sizeof (int),
482 .proc_handler = proc_dointvec,
486 .procname = "ctrl-alt-del",
488 .maxlen = sizeof(int),
490 .proc_handler = proc_dointvec,
492 #ifdef CONFIG_FUNCTION_TRACER
494 .procname = "ftrace_enabled",
495 .data = &ftrace_enabled,
496 .maxlen = sizeof(int),
498 .proc_handler = ftrace_enable_sysctl,
501 #ifdef CONFIG_STACK_TRACER
503 .procname = "stack_tracer_enabled",
504 .data = &stack_tracer_enabled,
505 .maxlen = sizeof(int),
507 .proc_handler = stack_trace_sysctl,
510 #ifdef CONFIG_TRACING
512 .procname = "ftrace_dump_on_oops",
513 .data = &ftrace_dump_on_oops,
514 .maxlen = sizeof(int),
516 .proc_handler = proc_dointvec,
519 #ifdef CONFIG_MODULES
521 .procname = "modprobe",
522 .data = &modprobe_path,
523 .maxlen = KMOD_PATH_LEN,
525 .proc_handler = proc_dostring,
528 .procname = "modules_disabled",
529 .data = &modules_disabled,
530 .maxlen = sizeof(int),
532 /* only handle a transition from default "0" to "1" */
533 .proc_handler = proc_dointvec_minmax,
538 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
540 .procname = "hotplug",
541 .data = &uevent_helper,
542 .maxlen = UEVENT_HELPER_PATH_LEN,
544 .proc_handler = proc_dostring,
547 #ifdef CONFIG_CHR_DEV_SG
549 .procname = "sg-big-buff",
550 .data = &sg_big_buff,
551 .maxlen = sizeof (int),
553 .proc_handler = proc_dointvec,
556 #ifdef CONFIG_BSD_PROCESS_ACCT
560 .maxlen = 3*sizeof(int),
562 .proc_handler = proc_dointvec,
565 #ifdef CONFIG_MAGIC_SYSRQ
568 .data = &__sysrq_enabled,
569 .maxlen = sizeof (int),
571 .proc_handler = proc_dointvec,
574 #ifdef CONFIG_PROC_SYSCTL
576 .procname = "cad_pid",
578 .maxlen = sizeof (int),
580 .proc_handler = proc_do_cad_pid,
584 .procname = "threads-max",
585 .data = &max_threads,
586 .maxlen = sizeof(int),
588 .proc_handler = proc_dointvec,
591 .procname = "random",
593 .child = random_table,
596 .procname = "overflowuid",
597 .data = &overflowuid,
598 .maxlen = sizeof(int),
600 .proc_handler = proc_dointvec_minmax,
601 .extra1 = &minolduid,
602 .extra2 = &maxolduid,
605 .procname = "overflowgid",
606 .data = &overflowgid,
607 .maxlen = sizeof(int),
609 .proc_handler = proc_dointvec_minmax,
610 .extra1 = &minolduid,
611 .extra2 = &maxolduid,
614 #ifdef CONFIG_MATHEMU
616 .procname = "ieee_emulation_warnings",
617 .data = &sysctl_ieee_emulation_warnings,
618 .maxlen = sizeof(int),
620 .proc_handler = proc_dointvec,
624 .procname = "userprocess_debug",
625 .data = &sysctl_userprocess_debug,
626 .maxlen = sizeof(int),
628 .proc_handler = proc_dointvec,
632 .procname = "pid_max",
634 .maxlen = sizeof (int),
636 .proc_handler = proc_dointvec_minmax,
637 .extra1 = &pid_max_min,
638 .extra2 = &pid_max_max,
641 .procname = "panic_on_oops",
642 .data = &panic_on_oops,
643 .maxlen = sizeof(int),
645 .proc_handler = proc_dointvec,
647 #if defined CONFIG_PRINTK
649 .procname = "printk",
650 .data = &console_loglevel,
651 .maxlen = 4*sizeof(int),
653 .proc_handler = proc_dointvec,
656 .procname = "printk_ratelimit",
657 .data = &printk_ratelimit_state.interval,
658 .maxlen = sizeof(int),
660 .proc_handler = proc_dointvec_jiffies,
663 .procname = "printk_ratelimit_burst",
664 .data = &printk_ratelimit_state.burst,
665 .maxlen = sizeof(int),
667 .proc_handler = proc_dointvec,
670 .procname = "printk_delay",
671 .data = &printk_delay_msec,
672 .maxlen = sizeof(int),
674 .proc_handler = proc_dointvec_minmax,
676 .extra2 = &ten_thousand,
680 .procname = "ngroups_max",
681 .data = &ngroups_max,
682 .maxlen = sizeof (int),
684 .proc_handler = proc_dointvec,
686 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
688 .procname = "unknown_nmi_panic",
689 .data = &unknown_nmi_panic,
690 .maxlen = sizeof (int),
692 .proc_handler = proc_dointvec,
695 .procname = "nmi_watchdog",
696 .data = &nmi_watchdog_enabled,
697 .maxlen = sizeof (int),
699 .proc_handler = proc_nmi_enabled,
702 #if defined(CONFIG_X86)
704 .procname = "panic_on_unrecovered_nmi",
705 .data = &panic_on_unrecovered_nmi,
706 .maxlen = sizeof(int),
708 .proc_handler = proc_dointvec,
711 .procname = "panic_on_io_nmi",
712 .data = &panic_on_io_nmi,
713 .maxlen = sizeof(int),
715 .proc_handler = proc_dointvec,
718 .procname = "bootloader_type",
719 .data = &bootloader_type,
720 .maxlen = sizeof (int),
722 .proc_handler = proc_dointvec,
725 .procname = "bootloader_version",
726 .data = &bootloader_version,
727 .maxlen = sizeof (int),
729 .proc_handler = proc_dointvec,
732 .procname = "kstack_depth_to_print",
733 .data = &kstack_depth_to_print,
734 .maxlen = sizeof(int),
736 .proc_handler = proc_dointvec,
739 .procname = "io_delay_type",
740 .data = &io_delay_type,
741 .maxlen = sizeof(int),
743 .proc_handler = proc_dointvec,
746 #if defined(CONFIG_MMU)
748 .procname = "randomize_va_space",
749 .data = &randomize_va_space,
750 .maxlen = sizeof(int),
752 .proc_handler = proc_dointvec,
755 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
757 .procname = "spin_retry",
759 .maxlen = sizeof (int),
761 .proc_handler = proc_dointvec,
764 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
766 .procname = "acpi_video_flags",
767 .data = &acpi_realmode_flags,
768 .maxlen = sizeof (unsigned long),
770 .proc_handler = proc_doulongvec_minmax,
775 .procname = "ignore-unaligned-usertrap",
776 .data = &no_unaligned_warning,
777 .maxlen = sizeof (int),
779 .proc_handler = proc_dointvec,
782 .procname = "unaligned-dump-stack",
783 .data = &unaligned_dump_stack,
784 .maxlen = sizeof (int),
786 .proc_handler = proc_dointvec,
789 #ifdef CONFIG_DETECT_SOFTLOCKUP
791 .procname = "softlockup_panic",
792 .data = &softlockup_panic,
793 .maxlen = sizeof(int),
795 .proc_handler = proc_dointvec_minmax,
800 .procname = "softlockup_thresh",
801 .data = &softlockup_thresh,
802 .maxlen = sizeof(int),
804 .proc_handler = proc_dosoftlockup_thresh,
809 #ifdef CONFIG_DETECT_HUNG_TASK
811 .procname = "hung_task_panic",
812 .data = &sysctl_hung_task_panic,
813 .maxlen = sizeof(int),
815 .proc_handler = proc_dointvec_minmax,
820 .procname = "hung_task_check_count",
821 .data = &sysctl_hung_task_check_count,
822 .maxlen = sizeof(unsigned long),
824 .proc_handler = proc_doulongvec_minmax,
827 .procname = "hung_task_timeout_secs",
828 .data = &sysctl_hung_task_timeout_secs,
829 .maxlen = sizeof(unsigned long),
831 .proc_handler = proc_dohung_task_timeout_secs,
834 .procname = "hung_task_warnings",
835 .data = &sysctl_hung_task_warnings,
836 .maxlen = sizeof(unsigned long),
838 .proc_handler = proc_doulongvec_minmax,
843 .procname = "compat-log",
845 .maxlen = sizeof (int),
847 .proc_handler = proc_dointvec,
850 #ifdef CONFIG_RT_MUTEXES
852 .procname = "max_lock_depth",
853 .data = &max_lock_depth,
854 .maxlen = sizeof(int),
856 .proc_handler = proc_dointvec,
860 .procname = "poweroff_cmd",
861 .data = &poweroff_cmd,
862 .maxlen = POWEROFF_CMD_PATH_LEN,
864 .proc_handler = proc_dostring,
870 .child = key_sysctls,
873 #ifdef CONFIG_RCU_TORTURE_TEST
875 .procname = "rcutorture_runnable",
876 .data = &rcutorture_runnable,
877 .maxlen = sizeof(int),
879 .proc_handler = proc_dointvec,
882 #ifdef CONFIG_SLOW_WORK
884 .procname = "slow-work",
886 .child = slow_work_sysctls,
889 #ifdef CONFIG_PERF_EVENTS
891 .procname = "perf_event_paranoid",
892 .data = &sysctl_perf_event_paranoid,
893 .maxlen = sizeof(sysctl_perf_event_paranoid),
895 .proc_handler = proc_dointvec,
898 .procname = "perf_event_mlock_kb",
899 .data = &sysctl_perf_event_mlock,
900 .maxlen = sizeof(sysctl_perf_event_mlock),
902 .proc_handler = proc_dointvec,
905 .procname = "perf_event_max_sample_rate",
906 .data = &sysctl_perf_event_sample_rate,
907 .maxlen = sizeof(sysctl_perf_event_sample_rate),
909 .proc_handler = proc_dointvec,
912 #ifdef CONFIG_KMEMCHECK
914 .procname = "kmemcheck",
915 .data = &kmemcheck_enabled,
916 .maxlen = sizeof(int),
918 .proc_handler = proc_dointvec,
923 .procname = "blk_iopoll",
924 .data = &blk_iopoll_enabled,
925 .maxlen = sizeof(int),
927 .proc_handler = proc_dointvec,
931 * NOTE: do not add new entries to this table unless you have read
932 * Documentation/sysctl/ctl_unnumbered.txt
937 static struct ctl_table vm_table[] = {
939 .procname = "overcommit_memory",
940 .data = &sysctl_overcommit_memory,
941 .maxlen = sizeof(sysctl_overcommit_memory),
943 .proc_handler = proc_dointvec,
946 .procname = "panic_on_oom",
947 .data = &sysctl_panic_on_oom,
948 .maxlen = sizeof(sysctl_panic_on_oom),
950 .proc_handler = proc_dointvec,
953 .procname = "oom_kill_allocating_task",
954 .data = &sysctl_oom_kill_allocating_task,
955 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
957 .proc_handler = proc_dointvec,
960 .procname = "oom_dump_tasks",
961 .data = &sysctl_oom_dump_tasks,
962 .maxlen = sizeof(sysctl_oom_dump_tasks),
964 .proc_handler = proc_dointvec,
967 .procname = "overcommit_ratio",
968 .data = &sysctl_overcommit_ratio,
969 .maxlen = sizeof(sysctl_overcommit_ratio),
971 .proc_handler = proc_dointvec,
974 .procname = "page-cluster",
975 .data = &page_cluster,
976 .maxlen = sizeof(int),
978 .proc_handler = proc_dointvec,
981 .procname = "dirty_background_ratio",
982 .data = &dirty_background_ratio,
983 .maxlen = sizeof(dirty_background_ratio),
985 .proc_handler = dirty_background_ratio_handler,
987 .extra2 = &one_hundred,
990 .procname = "dirty_background_bytes",
991 .data = &dirty_background_bytes,
992 .maxlen = sizeof(dirty_background_bytes),
994 .proc_handler = dirty_background_bytes_handler,
998 .procname = "dirty_ratio",
999 .data = &vm_dirty_ratio,
1000 .maxlen = sizeof(vm_dirty_ratio),
1002 .proc_handler = dirty_ratio_handler,
1004 .extra2 = &one_hundred,
1007 .procname = "dirty_bytes",
1008 .data = &vm_dirty_bytes,
1009 .maxlen = sizeof(vm_dirty_bytes),
1011 .proc_handler = dirty_bytes_handler,
1012 .extra1 = &dirty_bytes_min,
1015 .procname = "dirty_writeback_centisecs",
1016 .data = &dirty_writeback_interval,
1017 .maxlen = sizeof(dirty_writeback_interval),
1019 .proc_handler = dirty_writeback_centisecs_handler,
1022 .procname = "dirty_expire_centisecs",
1023 .data = &dirty_expire_interval,
1024 .maxlen = sizeof(dirty_expire_interval),
1026 .proc_handler = proc_dointvec,
1029 .procname = "nr_pdflush_threads",
1030 .data = &nr_pdflush_threads,
1031 .maxlen = sizeof nr_pdflush_threads,
1032 .mode = 0444 /* read-only*/,
1033 .proc_handler = proc_dointvec,
1036 .procname = "swappiness",
1037 .data = &vm_swappiness,
1038 .maxlen = sizeof(vm_swappiness),
1040 .proc_handler = proc_dointvec_minmax,
1042 .extra2 = &one_hundred,
1044 #ifdef CONFIG_HUGETLB_PAGE
1046 .procname = "nr_hugepages",
1048 .maxlen = sizeof(unsigned long),
1050 .proc_handler = hugetlb_sysctl_handler,
1051 .extra1 = (void *)&hugetlb_zero,
1052 .extra2 = (void *)&hugetlb_infinity,
1056 .procname = "nr_hugepages_mempolicy",
1058 .maxlen = sizeof(unsigned long),
1060 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1061 .extra1 = (void *)&hugetlb_zero,
1062 .extra2 = (void *)&hugetlb_infinity,
1066 .procname = "hugetlb_shm_group",
1067 .data = &sysctl_hugetlb_shm_group,
1068 .maxlen = sizeof(gid_t),
1070 .proc_handler = proc_dointvec,
1073 .procname = "hugepages_treat_as_movable",
1074 .data = &hugepages_treat_as_movable,
1075 .maxlen = sizeof(int),
1077 .proc_handler = hugetlb_treat_movable_handler,
1080 .procname = "nr_overcommit_hugepages",
1082 .maxlen = sizeof(unsigned long),
1084 .proc_handler = hugetlb_overcommit_handler,
1085 .extra1 = (void *)&hugetlb_zero,
1086 .extra2 = (void *)&hugetlb_infinity,
1090 .procname = "lowmem_reserve_ratio",
1091 .data = &sysctl_lowmem_reserve_ratio,
1092 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1094 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1097 .procname = "drop_caches",
1098 .data = &sysctl_drop_caches,
1099 .maxlen = sizeof(int),
1101 .proc_handler = drop_caches_sysctl_handler,
1104 .procname = "min_free_kbytes",
1105 .data = &min_free_kbytes,
1106 .maxlen = sizeof(min_free_kbytes),
1108 .proc_handler = min_free_kbytes_sysctl_handler,
1112 .procname = "percpu_pagelist_fraction",
1113 .data = &percpu_pagelist_fraction,
1114 .maxlen = sizeof(percpu_pagelist_fraction),
1116 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1117 .extra1 = &min_percpu_pagelist_fract,
1121 .procname = "max_map_count",
1122 .data = &sysctl_max_map_count,
1123 .maxlen = sizeof(sysctl_max_map_count),
1125 .proc_handler = proc_dointvec_minmax,
1130 .procname = "nr_trim_pages",
1131 .data = &sysctl_nr_trim_pages,
1132 .maxlen = sizeof(sysctl_nr_trim_pages),
1134 .proc_handler = proc_dointvec_minmax,
1139 .procname = "laptop_mode",
1140 .data = &laptop_mode,
1141 .maxlen = sizeof(laptop_mode),
1143 .proc_handler = proc_dointvec_jiffies,
1146 .procname = "block_dump",
1147 .data = &block_dump,
1148 .maxlen = sizeof(block_dump),
1150 .proc_handler = proc_dointvec,
1154 .procname = "vfs_cache_pressure",
1155 .data = &sysctl_vfs_cache_pressure,
1156 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1158 .proc_handler = proc_dointvec,
1161 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1163 .procname = "legacy_va_layout",
1164 .data = &sysctl_legacy_va_layout,
1165 .maxlen = sizeof(sysctl_legacy_va_layout),
1167 .proc_handler = proc_dointvec,
1173 .procname = "zone_reclaim_mode",
1174 .data = &zone_reclaim_mode,
1175 .maxlen = sizeof(zone_reclaim_mode),
1177 .proc_handler = proc_dointvec,
1181 .procname = "min_unmapped_ratio",
1182 .data = &sysctl_min_unmapped_ratio,
1183 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1185 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1187 .extra2 = &one_hundred,
1190 .procname = "min_slab_ratio",
1191 .data = &sysctl_min_slab_ratio,
1192 .maxlen = sizeof(sysctl_min_slab_ratio),
1194 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1196 .extra2 = &one_hundred,
1201 .procname = "stat_interval",
1202 .data = &sysctl_stat_interval,
1203 .maxlen = sizeof(sysctl_stat_interval),
1205 .proc_handler = proc_dointvec_jiffies,
1210 .procname = "mmap_min_addr",
1211 .data = &dac_mmap_min_addr,
1212 .maxlen = sizeof(unsigned long),
1214 .proc_handler = mmap_min_addr_handler,
1219 .procname = "numa_zonelist_order",
1220 .data = &numa_zonelist_order,
1221 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1223 .proc_handler = numa_zonelist_order_handler,
1226 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1227 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1229 .procname = "vdso_enabled",
1230 .data = &vdso_enabled,
1231 .maxlen = sizeof(vdso_enabled),
1233 .proc_handler = proc_dointvec,
1237 #ifdef CONFIG_HIGHMEM
1239 .procname = "highmem_is_dirtyable",
1240 .data = &vm_highmem_is_dirtyable,
1241 .maxlen = sizeof(vm_highmem_is_dirtyable),
1243 .proc_handler = proc_dointvec_minmax,
1249 .procname = "scan_unevictable_pages",
1250 .data = &scan_unevictable_pages,
1251 .maxlen = sizeof(scan_unevictable_pages),
1253 .proc_handler = scan_unevictable_handler,
1255 #ifdef CONFIG_MEMORY_FAILURE
1257 .procname = "memory_failure_early_kill",
1258 .data = &sysctl_memory_failure_early_kill,
1259 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1261 .proc_handler = proc_dointvec_minmax,
1266 .procname = "memory_failure_recovery",
1267 .data = &sysctl_memory_failure_recovery,
1268 .maxlen = sizeof(sysctl_memory_failure_recovery),
1270 .proc_handler = proc_dointvec_minmax,
1277 * NOTE: do not add new entries to this table unless you have read
1278 * Documentation/sysctl/ctl_unnumbered.txt
1283 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1284 static struct ctl_table binfmt_misc_table[] = {
1289 static struct ctl_table fs_table[] = {
1291 .procname = "inode-nr",
1292 .data = &inodes_stat,
1293 .maxlen = 2*sizeof(int),
1295 .proc_handler = proc_dointvec,
1298 .procname = "inode-state",
1299 .data = &inodes_stat,
1300 .maxlen = 7*sizeof(int),
1302 .proc_handler = proc_dointvec,
1305 .procname = "file-nr",
1306 .data = &files_stat,
1307 .maxlen = 3*sizeof(int),
1309 .proc_handler = proc_nr_files,
1312 .procname = "file-max",
1313 .data = &files_stat.max_files,
1314 .maxlen = sizeof(int),
1316 .proc_handler = proc_dointvec,
1319 .procname = "nr_open",
1320 .data = &sysctl_nr_open,
1321 .maxlen = sizeof(int),
1323 .proc_handler = proc_dointvec_minmax,
1324 .extra1 = &sysctl_nr_open_min,
1325 .extra2 = &sysctl_nr_open_max,
1328 .procname = "dentry-state",
1329 .data = &dentry_stat,
1330 .maxlen = 6*sizeof(int),
1332 .proc_handler = proc_dointvec,
1335 .procname = "overflowuid",
1336 .data = &fs_overflowuid,
1337 .maxlen = sizeof(int),
1339 .proc_handler = proc_dointvec_minmax,
1340 .extra1 = &minolduid,
1341 .extra2 = &maxolduid,
1344 .procname = "overflowgid",
1345 .data = &fs_overflowgid,
1346 .maxlen = sizeof(int),
1348 .proc_handler = proc_dointvec_minmax,
1349 .extra1 = &minolduid,
1350 .extra2 = &maxolduid,
1352 #ifdef CONFIG_FILE_LOCKING
1354 .procname = "leases-enable",
1355 .data = &leases_enable,
1356 .maxlen = sizeof(int),
1358 .proc_handler = proc_dointvec,
1361 #ifdef CONFIG_DNOTIFY
1363 .procname = "dir-notify-enable",
1364 .data = &dir_notify_enable,
1365 .maxlen = sizeof(int),
1367 .proc_handler = proc_dointvec,
1371 #ifdef CONFIG_FILE_LOCKING
1373 .procname = "lease-break-time",
1374 .data = &lease_break_time,
1375 .maxlen = sizeof(int),
1377 .proc_handler = proc_dointvec,
1382 .procname = "aio-nr",
1384 .maxlen = sizeof(aio_nr),
1386 .proc_handler = proc_doulongvec_minmax,
1389 .procname = "aio-max-nr",
1390 .data = &aio_max_nr,
1391 .maxlen = sizeof(aio_max_nr),
1393 .proc_handler = proc_doulongvec_minmax,
1395 #endif /* CONFIG_AIO */
1396 #ifdef CONFIG_INOTIFY_USER
1398 .procname = "inotify",
1400 .child = inotify_table,
1405 .procname = "epoll",
1407 .child = epoll_table,
1412 .procname = "suid_dumpable",
1413 .data = &suid_dumpable,
1414 .maxlen = sizeof(int),
1416 .proc_handler = proc_dointvec_minmax,
1420 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1422 .procname = "binfmt_misc",
1424 .child = binfmt_misc_table,
1428 .procname = "pipe-max-pages",
1429 .data = &pipe_max_pages,
1430 .maxlen = sizeof(int),
1432 .proc_handler = &proc_dointvec_minmax,
1436 * NOTE: do not add new entries to this table unless you have read
1437 * Documentation/sysctl/ctl_unnumbered.txt
1442 static struct ctl_table debug_table[] = {
1443 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
1445 .procname = "exception-trace",
1446 .data = &show_unhandled_signals,
1447 .maxlen = sizeof(int),
1449 .proc_handler = proc_dointvec
1452 #if defined(CONFIG_OPTPROBES)
1454 .procname = "kprobes-optimization",
1455 .data = &sysctl_kprobes_optimization,
1456 .maxlen = sizeof(int),
1458 .proc_handler = proc_kprobes_optimization_handler,
1466 static struct ctl_table dev_table[] = {
1470 static DEFINE_SPINLOCK(sysctl_lock);
1472 /* called under sysctl_lock */
1473 static int use_table(struct ctl_table_header *p)
1475 if (unlikely(p->unregistering))
1481 /* called under sysctl_lock */
1482 static void unuse_table(struct ctl_table_header *p)
1485 if (unlikely(p->unregistering))
1486 complete(p->unregistering);
1489 /* called under sysctl_lock, will reacquire if has to wait */
1490 static void start_unregistering(struct ctl_table_header *p)
1493 * if p->used is 0, nobody will ever touch that entry again;
1494 * we'll eliminate all paths to it before dropping sysctl_lock
1496 if (unlikely(p->used)) {
1497 struct completion wait;
1498 init_completion(&wait);
1499 p->unregistering = &wait;
1500 spin_unlock(&sysctl_lock);
1501 wait_for_completion(&wait);
1502 spin_lock(&sysctl_lock);
1504 /* anything non-NULL; we'll never dereference it */
1505 p->unregistering = ERR_PTR(-EINVAL);
1508 * do not remove from the list until nobody holds it; walking the
1509 * list in do_sysctl() relies on that.
1511 list_del_init(&p->ctl_entry);
1514 void sysctl_head_get(struct ctl_table_header *head)
1516 spin_lock(&sysctl_lock);
1518 spin_unlock(&sysctl_lock);
1521 void sysctl_head_put(struct ctl_table_header *head)
1523 spin_lock(&sysctl_lock);
1526 spin_unlock(&sysctl_lock);
1529 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1533 spin_lock(&sysctl_lock);
1534 if (!use_table(head))
1535 head = ERR_PTR(-ENOENT);
1536 spin_unlock(&sysctl_lock);
1540 void sysctl_head_finish(struct ctl_table_header *head)
1544 spin_lock(&sysctl_lock);
1546 spin_unlock(&sysctl_lock);
1549 static struct ctl_table_set *
1550 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1552 struct ctl_table_set *set = &root->default_set;
1554 set = root->lookup(root, namespaces);
1558 static struct list_head *
1559 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1561 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1565 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1566 struct ctl_table_header *prev)
1568 struct ctl_table_root *root;
1569 struct list_head *header_list;
1570 struct ctl_table_header *head;
1571 struct list_head *tmp;
1573 spin_lock(&sysctl_lock);
1576 tmp = &prev->ctl_entry;
1580 tmp = &root_table_header.ctl_entry;
1582 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1584 if (!use_table(head))
1586 spin_unlock(&sysctl_lock);
1591 header_list = lookup_header_list(root, namespaces);
1592 if (tmp != header_list)
1596 root = list_entry(root->root_list.next,
1597 struct ctl_table_root, root_list);
1598 if (root == &sysctl_table_root)
1600 header_list = lookup_header_list(root, namespaces);
1601 } while (list_empty(header_list));
1602 tmp = header_list->next;
1605 spin_unlock(&sysctl_lock);
1609 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1611 return __sysctl_head_next(current->nsproxy, prev);
1614 void register_sysctl_root(struct ctl_table_root *root)
1616 spin_lock(&sysctl_lock);
1617 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1618 spin_unlock(&sysctl_lock);
1622 * sysctl_perm does NOT grant the superuser all rights automatically, because
1623 * some sysctl variables are readonly even to root.
1626 static int test_perm(int mode, int op)
1628 if (!current_euid())
1630 else if (in_egroup_p(0))
1632 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1637 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1642 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1646 if (root->permissions)
1647 mode = root->permissions(root, current->nsproxy, table);
1651 return test_perm(mode, op);
1654 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1656 for (; table->procname; table++) {
1657 table->parent = parent;
1659 sysctl_set_parent(table, table->child);
1663 static __init int sysctl_init(void)
1665 sysctl_set_parent(NULL, root_table);
1666 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1669 err = sysctl_check_table(current->nsproxy, root_table);
1675 core_initcall(sysctl_init);
1677 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1678 struct ctl_table *table)
1680 struct ctl_table *p;
1681 const char *s = branch->procname;
1683 /* branch should have named subdirectory as its first element */
1684 if (!s || !branch->child)
1687 /* ... and nothing else */
1688 if (branch[1].procname)
1691 /* table should contain subdirectory with the same name */
1692 for (p = table; p->procname; p++) {
1695 if (p->procname && strcmp(p->procname, s) == 0)
1701 /* see if attaching q to p would be an improvement */
1702 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1704 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1705 struct ctl_table *next;
1707 int not_in_parent = !p->attached_by;
1709 while ((next = is_branch_in(by, to)) != NULL) {
1710 if (by == q->attached_by)
1712 if (to == p->attached_by)
1718 if (is_better && not_in_parent) {
1719 q->attached_by = by;
1720 q->attached_to = to;
1726 * __register_sysctl_paths - register a sysctl hierarchy
1727 * @root: List of sysctl headers to register on
1728 * @namespaces: Data to compute which lists of sysctl entries are visible
1729 * @path: The path to the directory the sysctl table is in.
1730 * @table: the top-level table structure
1732 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1733 * array. A completely 0 filled entry terminates the table.
1735 * The members of the &struct ctl_table structure are used as follows:
1737 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1738 * enter a sysctl file
1740 * data - a pointer to data for use by proc_handler
1742 * maxlen - the maximum size in bytes of the data
1744 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1746 * child - a pointer to the child sysctl table if this entry is a directory, or
1749 * proc_handler - the text handler routine (described below)
1751 * de - for internal use by the sysctl routines
1753 * extra1, extra2 - extra pointers usable by the proc handler routines
1755 * Leaf nodes in the sysctl tree will be represented by a single file
1756 * under /proc; non-leaf nodes will be represented by directories.
1758 * sysctl(2) can automatically manage read and write requests through
1759 * the sysctl table. The data and maxlen fields of the ctl_table
1760 * struct enable minimal validation of the values being written to be
1761 * performed, and the mode field allows minimal authentication.
1763 * There must be a proc_handler routine for any terminal nodes
1764 * mirrored under /proc/sys (non-terminals are handled by a built-in
1765 * directory handler). Several default handlers are available to
1766 * cover common cases -
1768 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1769 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1770 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1772 * It is the handler's job to read the input buffer from user memory
1773 * and process it. The handler should return 0 on success.
1775 * This routine returns %NULL on a failure to register, and a pointer
1776 * to the table header on success.
1778 struct ctl_table_header *__register_sysctl_paths(
1779 struct ctl_table_root *root,
1780 struct nsproxy *namespaces,
1781 const struct ctl_path *path, struct ctl_table *table)
1783 struct ctl_table_header *header;
1784 struct ctl_table *new, **prevp;
1785 unsigned int n, npath;
1786 struct ctl_table_set *set;
1788 /* Count the path components */
1789 for (npath = 0; path[npath].procname; ++npath)
1793 * For each path component, allocate a 2-element ctl_table array.
1794 * The first array element will be filled with the sysctl entry
1795 * for this, the second will be the sentinel (procname == 0).
1797 * We allocate everything in one go so that we don't have to
1798 * worry about freeing additional memory in unregister_sysctl_table.
1800 header = kzalloc(sizeof(struct ctl_table_header) +
1801 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1805 new = (struct ctl_table *) (header + 1);
1807 /* Now connect the dots */
1808 prevp = &header->ctl_table;
1809 for (n = 0; n < npath; ++n, ++path) {
1810 /* Copy the procname */
1811 new->procname = path->procname;
1815 prevp = &new->child;
1820 header->ctl_table_arg = table;
1822 INIT_LIST_HEAD(&header->ctl_entry);
1824 header->unregistering = NULL;
1825 header->root = root;
1826 sysctl_set_parent(NULL, header->ctl_table);
1828 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1829 if (sysctl_check_table(namespaces, header->ctl_table)) {
1834 spin_lock(&sysctl_lock);
1835 header->set = lookup_header_set(root, namespaces);
1836 header->attached_by = header->ctl_table;
1837 header->attached_to = root_table;
1838 header->parent = &root_table_header;
1839 for (set = header->set; set; set = set->parent) {
1840 struct ctl_table_header *p;
1841 list_for_each_entry(p, &set->list, ctl_entry) {
1842 if (p->unregistering)
1844 try_attach(p, header);
1847 header->parent->count++;
1848 list_add_tail(&header->ctl_entry, &header->set->list);
1849 spin_unlock(&sysctl_lock);
1855 * register_sysctl_table_path - register a sysctl table hierarchy
1856 * @path: The path to the directory the sysctl table is in.
1857 * @table: the top-level table structure
1859 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1860 * array. A completely 0 filled entry terminates the table.
1862 * See __register_sysctl_paths for more details.
1864 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1865 struct ctl_table *table)
1867 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1872 * register_sysctl_table - register a sysctl table hierarchy
1873 * @table: the top-level table structure
1875 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1876 * array. A completely 0 filled entry terminates the table.
1878 * See register_sysctl_paths for more details.
1880 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1882 static const struct ctl_path null_path[] = { {} };
1884 return register_sysctl_paths(null_path, table);
1888 * unregister_sysctl_table - unregister a sysctl table hierarchy
1889 * @header: the header returned from register_sysctl_table
1891 * Unregisters the sysctl table and all children. proc entries may not
1892 * actually be removed until they are no longer used by anyone.
1894 void unregister_sysctl_table(struct ctl_table_header * header)
1901 spin_lock(&sysctl_lock);
1902 start_unregistering(header);
1903 if (!--header->parent->count) {
1905 kfree(header->parent);
1907 if (!--header->count)
1909 spin_unlock(&sysctl_lock);
1912 int sysctl_is_seen(struct ctl_table_header *p)
1914 struct ctl_table_set *set = p->set;
1916 spin_lock(&sysctl_lock);
1917 if (p->unregistering)
1919 else if (!set->is_seen)
1922 res = set->is_seen(set);
1923 spin_unlock(&sysctl_lock);
1927 void setup_sysctl_set(struct ctl_table_set *p,
1928 struct ctl_table_set *parent,
1929 int (*is_seen)(struct ctl_table_set *))
1931 INIT_LIST_HEAD(&p->list);
1932 p->parent = parent ? parent : &sysctl_table_root.default_set;
1933 p->is_seen = is_seen;
1936 #else /* !CONFIG_SYSCTL */
1937 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1942 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1943 struct ctl_table *table)
1948 void unregister_sysctl_table(struct ctl_table_header * table)
1952 void setup_sysctl_set(struct ctl_table_set *p,
1953 struct ctl_table_set *parent,
1954 int (*is_seen)(struct ctl_table_set *))
1958 void sysctl_head_put(struct ctl_table_header *head)
1962 #endif /* CONFIG_SYSCTL */
1968 #ifdef CONFIG_PROC_SYSCTL
1970 static int _proc_do_string(void* data, int maxlen, int write,
1971 void __user *buffer,
1972 size_t *lenp, loff_t *ppos)
1978 if (!data || !maxlen || !*lenp) {
1986 while (len < *lenp) {
1987 if (get_user(c, p++))
1989 if (c == 0 || c == '\n')
1995 if(copy_from_user(data, buffer, len))
1997 ((char *) data)[len] = 0;
2015 if(copy_to_user(buffer, data, len))
2018 if(put_user('\n', ((char __user *) buffer) + len))
2029 * proc_dostring - read a string sysctl
2030 * @table: the sysctl table
2031 * @write: %TRUE if this is a write to the sysctl file
2032 * @buffer: the user buffer
2033 * @lenp: the size of the user buffer
2034 * @ppos: file position
2036 * Reads/writes a string from/to the user buffer. If the kernel
2037 * buffer provided is not large enough to hold the string, the
2038 * string is truncated. The copied string is %NULL-terminated.
2039 * If the string is being read by the user process, it is copied
2040 * and a newline '\n' is added. It is truncated if the buffer is
2043 * Returns 0 on success.
2045 int proc_dostring(struct ctl_table *table, int write,
2046 void __user *buffer, size_t *lenp, loff_t *ppos)
2048 return _proc_do_string(table->data, table->maxlen, write,
2049 buffer, lenp, ppos);
2053 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2055 int write, void *data)
2058 *valp = *negp ? -*lvalp : *lvalp;
2063 *lvalp = (unsigned long)-val;
2066 *lvalp = (unsigned long)val;
2072 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2073 int write, void __user *buffer,
2074 size_t *lenp, loff_t *ppos,
2075 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2076 int write, void *data),
2079 #define TMPBUFLEN 21
2080 int *i, vleft, first = 1, neg;
2084 char buf[TMPBUFLEN], *p;
2085 char __user *s = buffer;
2087 if (!tbl_data || !table->maxlen || !*lenp ||
2088 (*ppos && !write)) {
2093 i = (int *) tbl_data;
2094 vleft = table->maxlen / sizeof(*i);
2098 conv = do_proc_dointvec_conv;
2100 for (; left && vleft--; i++, first=0) {
2115 if (len > sizeof(buf) - 1)
2116 len = sizeof(buf) - 1;
2117 if (copy_from_user(buf, s, len))
2121 if (*p == '-' && left > 1) {
2125 if (*p < '0' || *p > '9')
2128 lval = simple_strtoul(p, &p, 0);
2131 if ((len < left) && *p && !isspace(*p))
2136 if (conv(&neg, &lval, i, 1, data))
2143 if (conv(&neg, &lval, i, 0, data))
2146 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2150 if(copy_to_user(s, buf, len))
2157 if (!write && !first && left) {
2158 if(put_user('\n', s))
2165 if (get_user(c, s++))
2180 static int do_proc_dointvec(struct ctl_table *table, int write,
2181 void __user *buffer, size_t *lenp, loff_t *ppos,
2182 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2183 int write, void *data),
2186 return __do_proc_dointvec(table->data, table, write,
2187 buffer, lenp, ppos, conv, data);
2191 * proc_dointvec - read a vector of integers
2192 * @table: the sysctl table
2193 * @write: %TRUE if this is a write to the sysctl file
2194 * @buffer: the user buffer
2195 * @lenp: the size of the user buffer
2196 * @ppos: file position
2198 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2199 * values from/to the user buffer, treated as an ASCII string.
2201 * Returns 0 on success.
2203 int proc_dointvec(struct ctl_table *table, int write,
2204 void __user *buffer, size_t *lenp, loff_t *ppos)
2206 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2211 * Taint values can only be increased
2212 * This means we can safely use a temporary.
2214 static int proc_taint(struct ctl_table *table, int write,
2215 void __user *buffer, size_t *lenp, loff_t *ppos)
2218 unsigned long tmptaint = get_taint();
2221 if (write && !capable(CAP_SYS_ADMIN))
2226 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2232 * Poor man's atomic or. Not worth adding a primitive
2233 * to everyone's atomic.h for this
2236 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2237 if ((tmptaint >> i) & 1)
2245 struct do_proc_dointvec_minmax_conv_param {
2250 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2252 int write, void *data)
2254 struct do_proc_dointvec_minmax_conv_param *param = data;
2256 int val = *negp ? -*lvalp : *lvalp;
2257 if ((param->min && *param->min > val) ||
2258 (param->max && *param->max < val))
2265 *lvalp = (unsigned long)-val;
2268 *lvalp = (unsigned long)val;
2275 * proc_dointvec_minmax - read a vector of integers with min/max values
2276 * @table: the sysctl table
2277 * @write: %TRUE if this is a write to the sysctl file
2278 * @buffer: the user buffer
2279 * @lenp: the size of the user buffer
2280 * @ppos: file position
2282 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2283 * values from/to the user buffer, treated as an ASCII string.
2285 * This routine will ensure the values are within the range specified by
2286 * table->extra1 (min) and table->extra2 (max).
2288 * Returns 0 on success.
2290 int proc_dointvec_minmax(struct ctl_table *table, int write,
2291 void __user *buffer, size_t *lenp, loff_t *ppos)
2293 struct do_proc_dointvec_minmax_conv_param param = {
2294 .min = (int *) table->extra1,
2295 .max = (int *) table->extra2,
2297 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2298 do_proc_dointvec_minmax_conv, ¶m);
2301 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2302 void __user *buffer,
2303 size_t *lenp, loff_t *ppos,
2304 unsigned long convmul,
2305 unsigned long convdiv)
2307 #define TMPBUFLEN 21
2308 unsigned long *i, *min, *max, val;
2309 int vleft, first=1, neg;
2311 char buf[TMPBUFLEN], *p;
2312 char __user *s = buffer;
2314 if (!data || !table->maxlen || !*lenp ||
2315 (*ppos && !write)) {
2320 i = (unsigned long *) data;
2321 min = (unsigned long *) table->extra1;
2322 max = (unsigned long *) table->extra2;
2323 vleft = table->maxlen / sizeof(unsigned long);
2326 for (; left && vleft--; i++, min++, max++, first=0) {
2341 if (len > TMPBUFLEN-1)
2343 if (copy_from_user(buf, s, len))
2347 if (*p == '-' && left > 1) {
2351 if (*p < '0' || *p > '9')
2353 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2355 if ((len < left) && *p && !isspace(*p))
2364 if ((min && val < *min) || (max && val > *max))
2371 sprintf(p, "%lu", convdiv * (*i) / convmul);
2375 if(copy_to_user(s, buf, len))
2382 if (!write && !first && left) {
2383 if(put_user('\n', s))
2390 if (get_user(c, s++))
2405 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2406 void __user *buffer,
2407 size_t *lenp, loff_t *ppos,
2408 unsigned long convmul,
2409 unsigned long convdiv)
2411 return __do_proc_doulongvec_minmax(table->data, table, write,
2412 buffer, lenp, ppos, convmul, convdiv);
2416 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2417 * @table: the sysctl table
2418 * @write: %TRUE if this is a write to the sysctl file
2419 * @buffer: the user buffer
2420 * @lenp: the size of the user buffer
2421 * @ppos: file position
2423 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2424 * values from/to the user buffer, treated as an ASCII string.
2426 * This routine will ensure the values are within the range specified by
2427 * table->extra1 (min) and table->extra2 (max).
2429 * Returns 0 on success.
2431 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2432 void __user *buffer, size_t *lenp, loff_t *ppos)
2434 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2438 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2439 * @table: the sysctl table
2440 * @write: %TRUE if this is a write to the sysctl file
2441 * @buffer: the user buffer
2442 * @lenp: the size of the user buffer
2443 * @ppos: file position
2445 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2446 * values from/to the user buffer, treated as an ASCII string. The values
2447 * are treated as milliseconds, and converted to jiffies when they are stored.
2449 * This routine will ensure the values are within the range specified by
2450 * table->extra1 (min) and table->extra2 (max).
2452 * Returns 0 on success.
2454 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2455 void __user *buffer,
2456 size_t *lenp, loff_t *ppos)
2458 return do_proc_doulongvec_minmax(table, write, buffer,
2459 lenp, ppos, HZ, 1000l);
2463 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2465 int write, void *data)
2468 if (*lvalp > LONG_MAX / HZ)
2470 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2476 lval = (unsigned long)-val;
2479 lval = (unsigned long)val;
2486 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2488 int write, void *data)
2491 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2493 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2499 lval = (unsigned long)-val;
2502 lval = (unsigned long)val;
2504 *lvalp = jiffies_to_clock_t(lval);
2509 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2511 int write, void *data)
2514 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2520 lval = (unsigned long)-val;
2523 lval = (unsigned long)val;
2525 *lvalp = jiffies_to_msecs(lval);
2531 * proc_dointvec_jiffies - read a vector of integers as seconds
2532 * @table: the sysctl table
2533 * @write: %TRUE if this is a write to the sysctl file
2534 * @buffer: the user buffer
2535 * @lenp: the size of the user buffer
2536 * @ppos: file position
2538 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2539 * values from/to the user buffer, treated as an ASCII string.
2540 * The values read are assumed to be in seconds, and are converted into
2543 * Returns 0 on success.
2545 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2546 void __user *buffer, size_t *lenp, loff_t *ppos)
2548 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2549 do_proc_dointvec_jiffies_conv,NULL);
2553 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2554 * @table: the sysctl table
2555 * @write: %TRUE if this is a write to the sysctl file
2556 * @buffer: the user buffer
2557 * @lenp: the size of the user buffer
2558 * @ppos: pointer to the file position
2560 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2561 * values from/to the user buffer, treated as an ASCII string.
2562 * The values read are assumed to be in 1/USER_HZ seconds, and
2563 * are converted into jiffies.
2565 * Returns 0 on success.
2567 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2568 void __user *buffer, size_t *lenp, loff_t *ppos)
2570 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2571 do_proc_dointvec_userhz_jiffies_conv,NULL);
2575 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2576 * @table: the sysctl table
2577 * @write: %TRUE if this is a write to the sysctl file
2578 * @buffer: the user buffer
2579 * @lenp: the size of the user buffer
2580 * @ppos: file position
2581 * @ppos: the current position in the file
2583 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2584 * values from/to the user buffer, treated as an ASCII string.
2585 * The values read are assumed to be in 1/1000 seconds, and
2586 * are converted into jiffies.
2588 * Returns 0 on success.
2590 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2591 void __user *buffer, size_t *lenp, loff_t *ppos)
2593 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2594 do_proc_dointvec_ms_jiffies_conv, NULL);
2597 static int proc_do_cad_pid(struct ctl_table *table, int write,
2598 void __user *buffer, size_t *lenp, loff_t *ppos)
2600 struct pid *new_pid;
2604 tmp = pid_vnr(cad_pid);
2606 r = __do_proc_dointvec(&tmp, table, write, buffer,
2607 lenp, ppos, NULL, NULL);
2611 new_pid = find_get_pid(tmp);
2615 put_pid(xchg(&cad_pid, new_pid));
2619 #else /* CONFIG_PROC_FS */
2621 int proc_dostring(struct ctl_table *table, int write,
2622 void __user *buffer, size_t *lenp, loff_t *ppos)
2627 int proc_dointvec(struct ctl_table *table, int write,
2628 void __user *buffer, size_t *lenp, loff_t *ppos)
2633 int proc_dointvec_minmax(struct ctl_table *table, int write,
2634 void __user *buffer, size_t *lenp, loff_t *ppos)
2639 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2640 void __user *buffer, size_t *lenp, loff_t *ppos)
2645 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2646 void __user *buffer, size_t *lenp, loff_t *ppos)
2651 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2652 void __user *buffer, size_t *lenp, loff_t *ppos)
2657 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2658 void __user *buffer, size_t *lenp, loff_t *ppos)
2663 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2664 void __user *buffer,
2665 size_t *lenp, loff_t *ppos)
2671 #endif /* CONFIG_PROC_FS */
2674 * No sense putting this after each symbol definition, twice,
2675 * exception granted :-)
2677 EXPORT_SYMBOL(proc_dointvec);
2678 EXPORT_SYMBOL(proc_dointvec_jiffies);
2679 EXPORT_SYMBOL(proc_dointvec_minmax);
2680 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2681 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2682 EXPORT_SYMBOL(proc_dostring);
2683 EXPORT_SYMBOL(proc_doulongvec_minmax);
2684 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2685 EXPORT_SYMBOL(register_sysctl_table);
2686 EXPORT_SYMBOL(register_sysctl_paths);
2687 EXPORT_SYMBOL(unregister_sysctl_table);