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/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/kmemcheck.h>
30 #include <linux/smp_lock.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>
55 #include <asm/uaccess.h>
56 #include <asm/processor.h>
60 #include <asm/stacktrace.h>
64 static int deprecated_sysctl_warning(struct __sysctl_args *args);
66 #if defined(CONFIG_SYSCTL)
68 /* External variables not in a header file. */
70 extern int print_fatal_signals;
71 extern int sysctl_overcommit_memory;
72 extern int sysctl_overcommit_ratio;
73 extern int sysctl_panic_on_oom;
74 extern int sysctl_oom_kill_allocating_task;
75 extern int sysctl_oom_dump_tasks;
76 extern int max_threads;
77 extern int core_uses_pid;
78 extern int suid_dumpable;
79 extern char core_pattern[];
80 extern unsigned int core_pipe_limit;
82 extern int min_free_kbytes;
83 extern int pid_max_min, pid_max_max;
84 extern int sysctl_drop_caches;
85 extern int percpu_pagelist_fraction;
86 extern int compat_log;
87 extern int latencytop_enabled;
88 extern int sysctl_nr_open_min, sysctl_nr_open_max;
90 extern int sysctl_nr_trim_pages;
92 #ifdef CONFIG_RCU_TORTURE_TEST
93 extern int rcutorture_runnable;
94 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
96 extern int blk_iopoll_enabled;
99 /* Constants used for minimum and maximum */
100 #ifdef CONFIG_DETECT_SOFTLOCKUP
101 static int sixty = 60;
102 static int neg_one = -1;
106 static int __maybe_unused one = 1;
107 static int __maybe_unused two = 2;
108 static unsigned long one_ul = 1;
109 static int one_hundred = 100;
111 static int ten_thousand = 10000;
114 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
115 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
117 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
118 static int maxolduid = 65535;
119 static int minolduid;
120 static int min_percpu_pagelist_fract = 8;
122 static int ngroups_max = NGROUPS_MAX;
124 #ifdef CONFIG_MODULES
125 extern char modprobe_path[];
126 extern int modules_disabled;
128 #ifdef CONFIG_CHR_DEV_SG
129 extern int sg_big_buff;
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;
153 #ifdef CONFIG_BSD_PROCESS_ACCT
154 extern int acct_parm[];
158 extern int no_unaligned_warning;
159 extern int unaligned_dump_stack;
162 extern struct ratelimit_state printk_ratelimit_state;
164 #ifdef CONFIG_RT_MUTEXES
165 extern int max_lock_depth;
168 #ifdef CONFIG_PROC_SYSCTL
169 static int proc_do_cad_pid(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
171 static int proc_taint(struct ctl_table *table, int write,
172 void __user *buffer, size_t *lenp, loff_t *ppos);
175 static struct ctl_table root_table[];
176 static struct ctl_table_root sysctl_table_root;
177 static struct ctl_table_header root_table_header = {
179 .ctl_table = root_table,
180 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
181 .root = &sysctl_table_root,
182 .set = &sysctl_table_root.default_set,
184 static struct ctl_table_root sysctl_table_root = {
185 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
186 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
189 static struct ctl_table kern_table[];
190 static struct ctl_table vm_table[];
191 static struct ctl_table fs_table[];
192 static struct ctl_table debug_table[];
193 static struct ctl_table dev_table[];
194 extern struct ctl_table random_table[];
195 #ifdef CONFIG_INOTIFY_USER
196 extern struct ctl_table inotify_table[];
199 extern struct ctl_table epoll_table[];
202 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
203 int sysctl_legacy_va_layout;
206 extern int prove_locking;
207 extern int lock_stat;
209 /* The default sysctl tables: */
211 static struct ctl_table root_table[] = {
213 .ctl_name = CTL_KERN,
214 .procname = "kernel",
231 .ctl_name = CTL_DEBUG,
234 .child = debug_table,
243 * NOTE: do not add new entries to this table unless you have read
244 * Documentation/sysctl/ctl_unnumbered.txt
249 #ifdef CONFIG_SCHED_DEBUG
250 static int min_sched_granularity_ns = 100000; /* 100 usecs */
251 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
252 static int min_wakeup_granularity_ns; /* 0 usecs */
253 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
254 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
255 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
258 static struct ctl_table kern_table[] = {
260 .ctl_name = CTL_UNNUMBERED,
261 .procname = "sched_child_runs_first",
262 .data = &sysctl_sched_child_runs_first,
263 .maxlen = sizeof(unsigned int),
265 .proc_handler = &proc_dointvec,
267 #ifdef CONFIG_SCHED_DEBUG
269 .ctl_name = CTL_UNNUMBERED,
270 .procname = "sched_min_granularity_ns",
271 .data = &sysctl_sched_min_granularity,
272 .maxlen = sizeof(unsigned int),
274 .proc_handler = &sched_nr_latency_handler,
275 .strategy = &sysctl_intvec,
276 .extra1 = &min_sched_granularity_ns,
277 .extra2 = &max_sched_granularity_ns,
280 .ctl_name = CTL_UNNUMBERED,
281 .procname = "sched_latency_ns",
282 .data = &sysctl_sched_latency,
283 .maxlen = sizeof(unsigned int),
285 .proc_handler = &sched_nr_latency_handler,
286 .strategy = &sysctl_intvec,
287 .extra1 = &min_sched_granularity_ns,
288 .extra2 = &max_sched_granularity_ns,
291 .ctl_name = CTL_UNNUMBERED,
292 .procname = "sched_wakeup_granularity_ns",
293 .data = &sysctl_sched_wakeup_granularity,
294 .maxlen = sizeof(unsigned int),
296 .proc_handler = &proc_dointvec_minmax,
297 .strategy = &sysctl_intvec,
298 .extra1 = &min_wakeup_granularity_ns,
299 .extra2 = &max_wakeup_granularity_ns,
302 .ctl_name = CTL_UNNUMBERED,
303 .procname = "sched_shares_ratelimit",
304 .data = &sysctl_sched_shares_ratelimit,
305 .maxlen = sizeof(unsigned int),
307 .proc_handler = &proc_dointvec,
310 .ctl_name = CTL_UNNUMBERED,
311 .procname = "sched_tunable_scaling",
312 .data = &sysctl_sched_tunable_scaling,
313 .maxlen = sizeof(enum sched_tunable_scaling),
315 .proc_handler = &proc_dointvec_minmax,
316 .strategy = &sysctl_intvec,
317 .extra1 = &min_sched_tunable_scaling,
318 .extra2 = &max_sched_tunable_scaling,
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_shares_thresh",
324 .data = &sysctl_sched_shares_thresh,
325 .maxlen = sizeof(unsigned int),
327 .proc_handler = &proc_dointvec_minmax,
328 .strategy = &sysctl_intvec,
332 .ctl_name = CTL_UNNUMBERED,
333 .procname = "sched_migration_cost",
334 .data = &sysctl_sched_migration_cost,
335 .maxlen = sizeof(unsigned int),
337 .proc_handler = &proc_dointvec,
340 .ctl_name = CTL_UNNUMBERED,
341 .procname = "sched_nr_migrate",
342 .data = &sysctl_sched_nr_migrate,
343 .maxlen = sizeof(unsigned int),
345 .proc_handler = &proc_dointvec,
348 .ctl_name = CTL_UNNUMBERED,
349 .procname = "sched_time_avg",
350 .data = &sysctl_sched_time_avg,
351 .maxlen = sizeof(unsigned int),
353 .proc_handler = &proc_dointvec,
356 .ctl_name = CTL_UNNUMBERED,
357 .procname = "timer_migration",
358 .data = &sysctl_timer_migration,
359 .maxlen = sizeof(unsigned int),
361 .proc_handler = &proc_dointvec_minmax,
362 .strategy = &sysctl_intvec,
368 .ctl_name = CTL_UNNUMBERED,
369 .procname = "sched_rt_period_us",
370 .data = &sysctl_sched_rt_period,
371 .maxlen = sizeof(unsigned int),
373 .proc_handler = &sched_rt_handler,
376 .ctl_name = CTL_UNNUMBERED,
377 .procname = "sched_rt_runtime_us",
378 .data = &sysctl_sched_rt_runtime,
379 .maxlen = sizeof(int),
381 .proc_handler = &sched_rt_handler,
384 .ctl_name = CTL_UNNUMBERED,
385 .procname = "sched_compat_yield",
386 .data = &sysctl_sched_compat_yield,
387 .maxlen = sizeof(unsigned int),
389 .proc_handler = &proc_dointvec,
391 #ifdef CONFIG_PROVE_LOCKING
393 .ctl_name = CTL_UNNUMBERED,
394 .procname = "prove_locking",
395 .data = &prove_locking,
396 .maxlen = sizeof(int),
398 .proc_handler = &proc_dointvec,
401 #ifdef CONFIG_LOCK_STAT
403 .ctl_name = CTL_UNNUMBERED,
404 .procname = "lock_stat",
406 .maxlen = sizeof(int),
408 .proc_handler = &proc_dointvec,
412 .ctl_name = KERN_PANIC,
414 .data = &panic_timeout,
415 .maxlen = sizeof(int),
417 .proc_handler = &proc_dointvec,
420 .ctl_name = KERN_CORE_USES_PID,
421 .procname = "core_uses_pid",
422 .data = &core_uses_pid,
423 .maxlen = sizeof(int),
425 .proc_handler = &proc_dointvec,
428 .ctl_name = KERN_CORE_PATTERN,
429 .procname = "core_pattern",
430 .data = core_pattern,
431 .maxlen = CORENAME_MAX_SIZE,
433 .proc_handler = &proc_dostring,
434 .strategy = &sysctl_string,
437 .ctl_name = CTL_UNNUMBERED,
438 .procname = "core_pipe_limit",
439 .data = &core_pipe_limit,
440 .maxlen = sizeof(unsigned int),
442 .proc_handler = &proc_dointvec,
444 #ifdef CONFIG_PROC_SYSCTL
446 .procname = "tainted",
447 .maxlen = sizeof(long),
449 .proc_handler = &proc_taint,
452 #ifdef CONFIG_LATENCYTOP
454 .procname = "latencytop",
455 .data = &latencytop_enabled,
456 .maxlen = sizeof(int),
458 .proc_handler = &proc_dointvec,
461 #ifdef CONFIG_BLK_DEV_INITRD
463 .ctl_name = KERN_REALROOTDEV,
464 .procname = "real-root-dev",
465 .data = &real_root_dev,
466 .maxlen = sizeof(int),
468 .proc_handler = &proc_dointvec,
472 .ctl_name = CTL_UNNUMBERED,
473 .procname = "print-fatal-signals",
474 .data = &print_fatal_signals,
475 .maxlen = sizeof(int),
477 .proc_handler = &proc_dointvec,
481 .ctl_name = KERN_SPARC_REBOOT,
482 .procname = "reboot-cmd",
483 .data = reboot_command,
486 .proc_handler = &proc_dostring,
487 .strategy = &sysctl_string,
490 .ctl_name = KERN_SPARC_STOP_A,
491 .procname = "stop-a",
492 .data = &stop_a_enabled,
493 .maxlen = sizeof (int),
495 .proc_handler = &proc_dointvec,
498 .ctl_name = KERN_SPARC_SCONS_PWROFF,
499 .procname = "scons-poweroff",
500 .data = &scons_pwroff,
501 .maxlen = sizeof (int),
503 .proc_handler = &proc_dointvec,
506 #ifdef CONFIG_SPARC64
508 .ctl_name = CTL_UNNUMBERED,
509 .procname = "tsb-ratio",
510 .data = &sysctl_tsb_ratio,
511 .maxlen = sizeof (int),
513 .proc_handler = &proc_dointvec,
518 .ctl_name = KERN_HPPA_PWRSW,
519 .procname = "soft-power",
520 .data = &pwrsw_enabled,
521 .maxlen = sizeof (int),
523 .proc_handler = &proc_dointvec,
526 .ctl_name = KERN_HPPA_UNALIGNED,
527 .procname = "unaligned-trap",
528 .data = &unaligned_enabled,
529 .maxlen = sizeof (int),
531 .proc_handler = &proc_dointvec,
535 .ctl_name = KERN_CTLALTDEL,
536 .procname = "ctrl-alt-del",
538 .maxlen = sizeof(int),
540 .proc_handler = &proc_dointvec,
542 #ifdef CONFIG_FUNCTION_TRACER
544 .ctl_name = CTL_UNNUMBERED,
545 .procname = "ftrace_enabled",
546 .data = &ftrace_enabled,
547 .maxlen = sizeof(int),
549 .proc_handler = &ftrace_enable_sysctl,
552 #ifdef CONFIG_STACK_TRACER
554 .ctl_name = CTL_UNNUMBERED,
555 .procname = "stack_tracer_enabled",
556 .data = &stack_tracer_enabled,
557 .maxlen = sizeof(int),
559 .proc_handler = &stack_trace_sysctl,
562 #ifdef CONFIG_TRACING
564 .ctl_name = CTL_UNNUMBERED,
565 .procname = "ftrace_dump_on_oops",
566 .data = &ftrace_dump_on_oops,
567 .maxlen = sizeof(int),
569 .proc_handler = &proc_dointvec,
572 #ifdef CONFIG_MODULES
574 .ctl_name = KERN_MODPROBE,
575 .procname = "modprobe",
576 .data = &modprobe_path,
577 .maxlen = KMOD_PATH_LEN,
579 .proc_handler = &proc_dostring,
580 .strategy = &sysctl_string,
583 .ctl_name = CTL_UNNUMBERED,
584 .procname = "modules_disabled",
585 .data = &modules_disabled,
586 .maxlen = sizeof(int),
588 /* only handle a transition from default "0" to "1" */
589 .proc_handler = &proc_dointvec_minmax,
594 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
596 .ctl_name = KERN_HOTPLUG,
597 .procname = "hotplug",
598 .data = &uevent_helper,
599 .maxlen = UEVENT_HELPER_PATH_LEN,
601 .proc_handler = &proc_dostring,
602 .strategy = &sysctl_string,
605 #ifdef CONFIG_CHR_DEV_SG
607 .ctl_name = KERN_SG_BIG_BUFF,
608 .procname = "sg-big-buff",
609 .data = &sg_big_buff,
610 .maxlen = sizeof (int),
612 .proc_handler = &proc_dointvec,
615 #ifdef CONFIG_BSD_PROCESS_ACCT
617 .ctl_name = KERN_ACCT,
620 .maxlen = 3*sizeof(int),
622 .proc_handler = &proc_dointvec,
625 #ifdef CONFIG_MAGIC_SYSRQ
627 .ctl_name = KERN_SYSRQ,
629 .data = &__sysrq_enabled,
630 .maxlen = sizeof (int),
632 .proc_handler = &proc_dointvec,
635 #ifdef CONFIG_PROC_SYSCTL
637 .procname = "cad_pid",
639 .maxlen = sizeof (int),
641 .proc_handler = &proc_do_cad_pid,
645 .ctl_name = KERN_MAX_THREADS,
646 .procname = "threads-max",
647 .data = &max_threads,
648 .maxlen = sizeof(int),
650 .proc_handler = &proc_dointvec,
653 .ctl_name = KERN_RANDOM,
654 .procname = "random",
656 .child = random_table,
659 .ctl_name = KERN_OVERFLOWUID,
660 .procname = "overflowuid",
661 .data = &overflowuid,
662 .maxlen = sizeof(int),
664 .proc_handler = &proc_dointvec_minmax,
665 .strategy = &sysctl_intvec,
666 .extra1 = &minolduid,
667 .extra2 = &maxolduid,
670 .ctl_name = KERN_OVERFLOWGID,
671 .procname = "overflowgid",
672 .data = &overflowgid,
673 .maxlen = sizeof(int),
675 .proc_handler = &proc_dointvec_minmax,
676 .strategy = &sysctl_intvec,
677 .extra1 = &minolduid,
678 .extra2 = &maxolduid,
681 #ifdef CONFIG_MATHEMU
683 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
684 .procname = "ieee_emulation_warnings",
685 .data = &sysctl_ieee_emulation_warnings,
686 .maxlen = sizeof(int),
688 .proc_handler = &proc_dointvec,
692 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
693 .procname = "userprocess_debug",
694 .data = &sysctl_userprocess_debug,
695 .maxlen = sizeof(int),
697 .proc_handler = &proc_dointvec,
701 .ctl_name = KERN_PIDMAX,
702 .procname = "pid_max",
704 .maxlen = sizeof (int),
706 .proc_handler = &proc_dointvec_minmax,
707 .strategy = sysctl_intvec,
708 .extra1 = &pid_max_min,
709 .extra2 = &pid_max_max,
712 .ctl_name = KERN_PANIC_ON_OOPS,
713 .procname = "panic_on_oops",
714 .data = &panic_on_oops,
715 .maxlen = sizeof(int),
717 .proc_handler = &proc_dointvec,
719 #if defined CONFIG_PRINTK
721 .ctl_name = KERN_PRINTK,
722 .procname = "printk",
723 .data = &console_loglevel,
724 .maxlen = 4*sizeof(int),
726 .proc_handler = &proc_dointvec,
729 .ctl_name = KERN_PRINTK_RATELIMIT,
730 .procname = "printk_ratelimit",
731 .data = &printk_ratelimit_state.interval,
732 .maxlen = sizeof(int),
734 .proc_handler = &proc_dointvec_jiffies,
735 .strategy = &sysctl_jiffies,
738 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
739 .procname = "printk_ratelimit_burst",
740 .data = &printk_ratelimit_state.burst,
741 .maxlen = sizeof(int),
743 .proc_handler = &proc_dointvec,
746 .ctl_name = CTL_UNNUMBERED,
747 .procname = "printk_delay",
748 .data = &printk_delay_msec,
749 .maxlen = sizeof(int),
751 .proc_handler = &proc_dointvec_minmax,
752 .strategy = &sysctl_intvec,
754 .extra2 = &ten_thousand,
758 .ctl_name = KERN_NGROUPS_MAX,
759 .procname = "ngroups_max",
760 .data = &ngroups_max,
761 .maxlen = sizeof (int),
763 .proc_handler = &proc_dointvec,
765 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
767 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
768 .procname = "unknown_nmi_panic",
769 .data = &unknown_nmi_panic,
770 .maxlen = sizeof (int),
772 .proc_handler = &proc_dointvec,
775 .procname = "nmi_watchdog",
776 .data = &nmi_watchdog_enabled,
777 .maxlen = sizeof (int),
779 .proc_handler = &proc_nmi_enabled,
782 #if defined(CONFIG_X86)
784 .ctl_name = KERN_PANIC_ON_NMI,
785 .procname = "panic_on_unrecovered_nmi",
786 .data = &panic_on_unrecovered_nmi,
787 .maxlen = sizeof(int),
789 .proc_handler = &proc_dointvec,
792 .ctl_name = CTL_UNNUMBERED,
793 .procname = "panic_on_io_nmi",
794 .data = &panic_on_io_nmi,
795 .maxlen = sizeof(int),
797 .proc_handler = &proc_dointvec,
800 .ctl_name = KERN_BOOTLOADER_TYPE,
801 .procname = "bootloader_type",
802 .data = &bootloader_type,
803 .maxlen = sizeof (int),
805 .proc_handler = &proc_dointvec,
808 .ctl_name = CTL_UNNUMBERED,
809 .procname = "bootloader_version",
810 .data = &bootloader_version,
811 .maxlen = sizeof (int),
813 .proc_handler = &proc_dointvec,
816 .ctl_name = CTL_UNNUMBERED,
817 .procname = "kstack_depth_to_print",
818 .data = &kstack_depth_to_print,
819 .maxlen = sizeof(int),
821 .proc_handler = &proc_dointvec,
824 .ctl_name = CTL_UNNUMBERED,
825 .procname = "io_delay_type",
826 .data = &io_delay_type,
827 .maxlen = sizeof(int),
829 .proc_handler = &proc_dointvec,
832 #if defined(CONFIG_MMU)
834 .ctl_name = KERN_RANDOMIZE,
835 .procname = "randomize_va_space",
836 .data = &randomize_va_space,
837 .maxlen = sizeof(int),
839 .proc_handler = &proc_dointvec,
842 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
844 .ctl_name = KERN_SPIN_RETRY,
845 .procname = "spin_retry",
847 .maxlen = sizeof (int),
849 .proc_handler = &proc_dointvec,
852 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
854 .procname = "acpi_video_flags",
855 .data = &acpi_realmode_flags,
856 .maxlen = sizeof (unsigned long),
858 .proc_handler = &proc_doulongvec_minmax,
863 .ctl_name = KERN_IA64_UNALIGNED,
864 .procname = "ignore-unaligned-usertrap",
865 .data = &no_unaligned_warning,
866 .maxlen = sizeof (int),
868 .proc_handler = &proc_dointvec,
871 .ctl_name = CTL_UNNUMBERED,
872 .procname = "unaligned-dump-stack",
873 .data = &unaligned_dump_stack,
874 .maxlen = sizeof (int),
876 .proc_handler = &proc_dointvec,
879 #ifdef CONFIG_DETECT_SOFTLOCKUP
881 .ctl_name = CTL_UNNUMBERED,
882 .procname = "softlockup_panic",
883 .data = &softlockup_panic,
884 .maxlen = sizeof(int),
886 .proc_handler = &proc_dointvec_minmax,
887 .strategy = &sysctl_intvec,
892 .ctl_name = CTL_UNNUMBERED,
893 .procname = "softlockup_thresh",
894 .data = &softlockup_thresh,
895 .maxlen = sizeof(int),
897 .proc_handler = &proc_dosoftlockup_thresh,
898 .strategy = &sysctl_intvec,
903 #ifdef CONFIG_DETECT_HUNG_TASK
905 .ctl_name = CTL_UNNUMBERED,
906 .procname = "hung_task_panic",
907 .data = &sysctl_hung_task_panic,
908 .maxlen = sizeof(int),
910 .proc_handler = &proc_dointvec_minmax,
911 .strategy = &sysctl_intvec,
916 .ctl_name = CTL_UNNUMBERED,
917 .procname = "hung_task_check_count",
918 .data = &sysctl_hung_task_check_count,
919 .maxlen = sizeof(unsigned long),
921 .proc_handler = &proc_doulongvec_minmax,
922 .strategy = &sysctl_intvec,
925 .ctl_name = CTL_UNNUMBERED,
926 .procname = "hung_task_timeout_secs",
927 .data = &sysctl_hung_task_timeout_secs,
928 .maxlen = sizeof(unsigned long),
930 .proc_handler = &proc_dohung_task_timeout_secs,
931 .strategy = &sysctl_intvec,
934 .ctl_name = CTL_UNNUMBERED,
935 .procname = "hung_task_warnings",
936 .data = &sysctl_hung_task_warnings,
937 .maxlen = sizeof(unsigned long),
939 .proc_handler = &proc_doulongvec_minmax,
940 .strategy = &sysctl_intvec,
945 .ctl_name = KERN_COMPAT_LOG,
946 .procname = "compat-log",
948 .maxlen = sizeof (int),
950 .proc_handler = &proc_dointvec,
953 #ifdef CONFIG_RT_MUTEXES
955 .ctl_name = KERN_MAX_LOCK_DEPTH,
956 .procname = "max_lock_depth",
957 .data = &max_lock_depth,
958 .maxlen = sizeof(int),
960 .proc_handler = &proc_dointvec,
964 .ctl_name = CTL_UNNUMBERED,
965 .procname = "poweroff_cmd",
966 .data = &poweroff_cmd,
967 .maxlen = POWEROFF_CMD_PATH_LEN,
969 .proc_handler = &proc_dostring,
970 .strategy = &sysctl_string,
974 .ctl_name = CTL_UNNUMBERED,
977 .child = key_sysctls,
980 #ifdef CONFIG_RCU_TORTURE_TEST
982 .ctl_name = CTL_UNNUMBERED,
983 .procname = "rcutorture_runnable",
984 .data = &rcutorture_runnable,
985 .maxlen = sizeof(int),
987 .proc_handler = &proc_dointvec,
990 #ifdef CONFIG_SLOW_WORK
992 .ctl_name = CTL_UNNUMBERED,
993 .procname = "slow-work",
995 .child = slow_work_sysctls,
998 #ifdef CONFIG_PERF_EVENTS
1000 .ctl_name = CTL_UNNUMBERED,
1001 .procname = "perf_event_paranoid",
1002 .data = &sysctl_perf_event_paranoid,
1003 .maxlen = sizeof(sysctl_perf_event_paranoid),
1005 .proc_handler = &proc_dointvec,
1008 .ctl_name = CTL_UNNUMBERED,
1009 .procname = "perf_event_mlock_kb",
1010 .data = &sysctl_perf_event_mlock,
1011 .maxlen = sizeof(sysctl_perf_event_mlock),
1013 .proc_handler = &proc_dointvec,
1016 .ctl_name = CTL_UNNUMBERED,
1017 .procname = "perf_event_max_sample_rate",
1018 .data = &sysctl_perf_event_sample_rate,
1019 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1021 .proc_handler = &proc_dointvec,
1024 #ifdef CONFIG_KMEMCHECK
1026 .ctl_name = CTL_UNNUMBERED,
1027 .procname = "kmemcheck",
1028 .data = &kmemcheck_enabled,
1029 .maxlen = sizeof(int),
1031 .proc_handler = &proc_dointvec,
1036 .ctl_name = CTL_UNNUMBERED,
1037 .procname = "blk_iopoll",
1038 .data = &blk_iopoll_enabled,
1039 .maxlen = sizeof(int),
1041 .proc_handler = &proc_dointvec,
1045 * NOTE: do not add new entries to this table unless you have read
1046 * Documentation/sysctl/ctl_unnumbered.txt
1051 static struct ctl_table vm_table[] = {
1053 .ctl_name = VM_OVERCOMMIT_MEMORY,
1054 .procname = "overcommit_memory",
1055 .data = &sysctl_overcommit_memory,
1056 .maxlen = sizeof(sysctl_overcommit_memory),
1058 .proc_handler = &proc_dointvec,
1061 .ctl_name = VM_PANIC_ON_OOM,
1062 .procname = "panic_on_oom",
1063 .data = &sysctl_panic_on_oom,
1064 .maxlen = sizeof(sysctl_panic_on_oom),
1066 .proc_handler = &proc_dointvec,
1069 .ctl_name = CTL_UNNUMBERED,
1070 .procname = "oom_kill_allocating_task",
1071 .data = &sysctl_oom_kill_allocating_task,
1072 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1074 .proc_handler = &proc_dointvec,
1077 .ctl_name = CTL_UNNUMBERED,
1078 .procname = "oom_dump_tasks",
1079 .data = &sysctl_oom_dump_tasks,
1080 .maxlen = sizeof(sysctl_oom_dump_tasks),
1082 .proc_handler = &proc_dointvec,
1085 .ctl_name = VM_OVERCOMMIT_RATIO,
1086 .procname = "overcommit_ratio",
1087 .data = &sysctl_overcommit_ratio,
1088 .maxlen = sizeof(sysctl_overcommit_ratio),
1090 .proc_handler = &proc_dointvec,
1093 .ctl_name = VM_PAGE_CLUSTER,
1094 .procname = "page-cluster",
1095 .data = &page_cluster,
1096 .maxlen = sizeof(int),
1098 .proc_handler = &proc_dointvec,
1101 .ctl_name = VM_DIRTY_BACKGROUND,
1102 .procname = "dirty_background_ratio",
1103 .data = &dirty_background_ratio,
1104 .maxlen = sizeof(dirty_background_ratio),
1106 .proc_handler = &dirty_background_ratio_handler,
1107 .strategy = &sysctl_intvec,
1109 .extra2 = &one_hundred,
1112 .ctl_name = CTL_UNNUMBERED,
1113 .procname = "dirty_background_bytes",
1114 .data = &dirty_background_bytes,
1115 .maxlen = sizeof(dirty_background_bytes),
1117 .proc_handler = &dirty_background_bytes_handler,
1118 .strategy = &sysctl_intvec,
1122 .ctl_name = VM_DIRTY_RATIO,
1123 .procname = "dirty_ratio",
1124 .data = &vm_dirty_ratio,
1125 .maxlen = sizeof(vm_dirty_ratio),
1127 .proc_handler = &dirty_ratio_handler,
1128 .strategy = &sysctl_intvec,
1130 .extra2 = &one_hundred,
1133 .ctl_name = CTL_UNNUMBERED,
1134 .procname = "dirty_bytes",
1135 .data = &vm_dirty_bytes,
1136 .maxlen = sizeof(vm_dirty_bytes),
1138 .proc_handler = &dirty_bytes_handler,
1139 .strategy = &sysctl_intvec,
1140 .extra1 = &dirty_bytes_min,
1143 .procname = "dirty_writeback_centisecs",
1144 .data = &dirty_writeback_interval,
1145 .maxlen = sizeof(dirty_writeback_interval),
1147 .proc_handler = &dirty_writeback_centisecs_handler,
1150 .procname = "dirty_expire_centisecs",
1151 .data = &dirty_expire_interval,
1152 .maxlen = sizeof(dirty_expire_interval),
1154 .proc_handler = &proc_dointvec,
1157 .ctl_name = VM_NR_PDFLUSH_THREADS,
1158 .procname = "nr_pdflush_threads",
1159 .data = &nr_pdflush_threads,
1160 .maxlen = sizeof nr_pdflush_threads,
1161 .mode = 0444 /* read-only*/,
1162 .proc_handler = &proc_dointvec,
1165 .ctl_name = VM_SWAPPINESS,
1166 .procname = "swappiness",
1167 .data = &vm_swappiness,
1168 .maxlen = sizeof(vm_swappiness),
1170 .proc_handler = &proc_dointvec_minmax,
1171 .strategy = &sysctl_intvec,
1173 .extra2 = &one_hundred,
1175 #ifdef CONFIG_HUGETLB_PAGE
1177 .procname = "nr_hugepages",
1179 .maxlen = sizeof(unsigned long),
1181 .proc_handler = &hugetlb_sysctl_handler,
1182 .extra1 = (void *)&hugetlb_zero,
1183 .extra2 = (void *)&hugetlb_infinity,
1186 .ctl_name = VM_HUGETLB_GROUP,
1187 .procname = "hugetlb_shm_group",
1188 .data = &sysctl_hugetlb_shm_group,
1189 .maxlen = sizeof(gid_t),
1191 .proc_handler = &proc_dointvec,
1194 .ctl_name = CTL_UNNUMBERED,
1195 .procname = "hugepages_treat_as_movable",
1196 .data = &hugepages_treat_as_movable,
1197 .maxlen = sizeof(int),
1199 .proc_handler = &hugetlb_treat_movable_handler,
1202 .ctl_name = CTL_UNNUMBERED,
1203 .procname = "nr_overcommit_hugepages",
1205 .maxlen = sizeof(unsigned long),
1207 .proc_handler = &hugetlb_overcommit_handler,
1208 .extra1 = (void *)&hugetlb_zero,
1209 .extra2 = (void *)&hugetlb_infinity,
1213 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1214 .procname = "lowmem_reserve_ratio",
1215 .data = &sysctl_lowmem_reserve_ratio,
1216 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1218 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1219 .strategy = &sysctl_intvec,
1222 .ctl_name = VM_DROP_PAGECACHE,
1223 .procname = "drop_caches",
1224 .data = &sysctl_drop_caches,
1225 .maxlen = sizeof(int),
1227 .proc_handler = drop_caches_sysctl_handler,
1228 .strategy = &sysctl_intvec,
1231 .ctl_name = VM_MIN_FREE_KBYTES,
1232 .procname = "min_free_kbytes",
1233 .data = &min_free_kbytes,
1234 .maxlen = sizeof(min_free_kbytes),
1236 .proc_handler = &min_free_kbytes_sysctl_handler,
1237 .strategy = &sysctl_intvec,
1241 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1242 .procname = "percpu_pagelist_fraction",
1243 .data = &percpu_pagelist_fraction,
1244 .maxlen = sizeof(percpu_pagelist_fraction),
1246 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1247 .strategy = &sysctl_intvec,
1248 .extra1 = &min_percpu_pagelist_fract,
1252 .ctl_name = VM_MAX_MAP_COUNT,
1253 .procname = "max_map_count",
1254 .data = &sysctl_max_map_count,
1255 .maxlen = sizeof(sysctl_max_map_count),
1257 .proc_handler = &proc_dointvec
1261 .ctl_name = CTL_UNNUMBERED,
1262 .procname = "nr_trim_pages",
1263 .data = &sysctl_nr_trim_pages,
1264 .maxlen = sizeof(sysctl_nr_trim_pages),
1266 .proc_handler = &proc_dointvec_minmax,
1267 .strategy = &sysctl_intvec,
1272 .ctl_name = VM_LAPTOP_MODE,
1273 .procname = "laptop_mode",
1274 .data = &laptop_mode,
1275 .maxlen = sizeof(laptop_mode),
1277 .proc_handler = &proc_dointvec_jiffies,
1278 .strategy = &sysctl_jiffies,
1281 .ctl_name = VM_BLOCK_DUMP,
1282 .procname = "block_dump",
1283 .data = &block_dump,
1284 .maxlen = sizeof(block_dump),
1286 .proc_handler = &proc_dointvec,
1287 .strategy = &sysctl_intvec,
1291 .ctl_name = VM_VFS_CACHE_PRESSURE,
1292 .procname = "vfs_cache_pressure",
1293 .data = &sysctl_vfs_cache_pressure,
1294 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1296 .proc_handler = &proc_dointvec,
1297 .strategy = &sysctl_intvec,
1300 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1302 .ctl_name = VM_LEGACY_VA_LAYOUT,
1303 .procname = "legacy_va_layout",
1304 .data = &sysctl_legacy_va_layout,
1305 .maxlen = sizeof(sysctl_legacy_va_layout),
1307 .proc_handler = &proc_dointvec,
1308 .strategy = &sysctl_intvec,
1314 .ctl_name = VM_ZONE_RECLAIM_MODE,
1315 .procname = "zone_reclaim_mode",
1316 .data = &zone_reclaim_mode,
1317 .maxlen = sizeof(zone_reclaim_mode),
1319 .proc_handler = &proc_dointvec,
1320 .strategy = &sysctl_intvec,
1324 .ctl_name = VM_MIN_UNMAPPED,
1325 .procname = "min_unmapped_ratio",
1326 .data = &sysctl_min_unmapped_ratio,
1327 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1329 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1330 .strategy = &sysctl_intvec,
1332 .extra2 = &one_hundred,
1335 .ctl_name = VM_MIN_SLAB,
1336 .procname = "min_slab_ratio",
1337 .data = &sysctl_min_slab_ratio,
1338 .maxlen = sizeof(sysctl_min_slab_ratio),
1340 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1341 .strategy = &sysctl_intvec,
1343 .extra2 = &one_hundred,
1348 .ctl_name = CTL_UNNUMBERED,
1349 .procname = "stat_interval",
1350 .data = &sysctl_stat_interval,
1351 .maxlen = sizeof(sysctl_stat_interval),
1353 .proc_handler = &proc_dointvec_jiffies,
1354 .strategy = &sysctl_jiffies,
1358 .ctl_name = CTL_UNNUMBERED,
1359 .procname = "mmap_min_addr",
1360 .data = &dac_mmap_min_addr,
1361 .maxlen = sizeof(unsigned long),
1363 .proc_handler = &mmap_min_addr_handler,
1367 .ctl_name = CTL_UNNUMBERED,
1368 .procname = "numa_zonelist_order",
1369 .data = &numa_zonelist_order,
1370 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1372 .proc_handler = &numa_zonelist_order_handler,
1373 .strategy = &sysctl_string,
1376 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1377 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1379 .ctl_name = VM_VDSO_ENABLED,
1380 .procname = "vdso_enabled",
1381 .data = &vdso_enabled,
1382 .maxlen = sizeof(vdso_enabled),
1384 .proc_handler = &proc_dointvec,
1385 .strategy = &sysctl_intvec,
1389 #ifdef CONFIG_HIGHMEM
1391 .ctl_name = CTL_UNNUMBERED,
1392 .procname = "highmem_is_dirtyable",
1393 .data = &vm_highmem_is_dirtyable,
1394 .maxlen = sizeof(vm_highmem_is_dirtyable),
1396 .proc_handler = &proc_dointvec_minmax,
1397 .strategy = &sysctl_intvec,
1403 .ctl_name = CTL_UNNUMBERED,
1404 .procname = "scan_unevictable_pages",
1405 .data = &scan_unevictable_pages,
1406 .maxlen = sizeof(scan_unevictable_pages),
1408 .proc_handler = &scan_unevictable_handler,
1410 #ifdef CONFIG_MEMORY_FAILURE
1412 .ctl_name = CTL_UNNUMBERED,
1413 .procname = "memory_failure_early_kill",
1414 .data = &sysctl_memory_failure_early_kill,
1415 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1417 .proc_handler = &proc_dointvec_minmax,
1418 .strategy = &sysctl_intvec,
1423 .ctl_name = CTL_UNNUMBERED,
1424 .procname = "memory_failure_recovery",
1425 .data = &sysctl_memory_failure_recovery,
1426 .maxlen = sizeof(sysctl_memory_failure_recovery),
1428 .proc_handler = &proc_dointvec_minmax,
1429 .strategy = &sysctl_intvec,
1436 * NOTE: do not add new entries to this table unless you have read
1437 * Documentation/sysctl/ctl_unnumbered.txt
1442 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1443 static struct ctl_table binfmt_misc_table[] = {
1448 static struct ctl_table fs_table[] = {
1450 .ctl_name = FS_NRINODE,
1451 .procname = "inode-nr",
1452 .data = &inodes_stat,
1453 .maxlen = 2*sizeof(int),
1455 .proc_handler = &proc_dointvec,
1458 .ctl_name = FS_STATINODE,
1459 .procname = "inode-state",
1460 .data = &inodes_stat,
1461 .maxlen = 7*sizeof(int),
1463 .proc_handler = &proc_dointvec,
1466 .procname = "file-nr",
1467 .data = &files_stat,
1468 .maxlen = 3*sizeof(int),
1470 .proc_handler = &proc_nr_files,
1473 .ctl_name = FS_MAXFILE,
1474 .procname = "file-max",
1475 .data = &files_stat.max_files,
1476 .maxlen = sizeof(int),
1478 .proc_handler = &proc_dointvec,
1481 .ctl_name = CTL_UNNUMBERED,
1482 .procname = "nr_open",
1483 .data = &sysctl_nr_open,
1484 .maxlen = sizeof(int),
1486 .proc_handler = &proc_dointvec_minmax,
1487 .extra1 = &sysctl_nr_open_min,
1488 .extra2 = &sysctl_nr_open_max,
1491 .ctl_name = FS_DENTRY,
1492 .procname = "dentry-state",
1493 .data = &dentry_stat,
1494 .maxlen = 6*sizeof(int),
1496 .proc_handler = &proc_dointvec,
1499 .ctl_name = FS_OVERFLOWUID,
1500 .procname = "overflowuid",
1501 .data = &fs_overflowuid,
1502 .maxlen = sizeof(int),
1504 .proc_handler = &proc_dointvec_minmax,
1505 .strategy = &sysctl_intvec,
1506 .extra1 = &minolduid,
1507 .extra2 = &maxolduid,
1510 .ctl_name = FS_OVERFLOWGID,
1511 .procname = "overflowgid",
1512 .data = &fs_overflowgid,
1513 .maxlen = sizeof(int),
1515 .proc_handler = &proc_dointvec_minmax,
1516 .strategy = &sysctl_intvec,
1517 .extra1 = &minolduid,
1518 .extra2 = &maxolduid,
1520 #ifdef CONFIG_FILE_LOCKING
1522 .ctl_name = FS_LEASES,
1523 .procname = "leases-enable",
1524 .data = &leases_enable,
1525 .maxlen = sizeof(int),
1527 .proc_handler = &proc_dointvec,
1530 #ifdef CONFIG_DNOTIFY
1532 .ctl_name = FS_DIR_NOTIFY,
1533 .procname = "dir-notify-enable",
1534 .data = &dir_notify_enable,
1535 .maxlen = sizeof(int),
1537 .proc_handler = &proc_dointvec,
1541 #ifdef CONFIG_FILE_LOCKING
1543 .ctl_name = FS_LEASE_TIME,
1544 .procname = "lease-break-time",
1545 .data = &lease_break_time,
1546 .maxlen = sizeof(int),
1548 .proc_handler = &proc_dointvec,
1553 .procname = "aio-nr",
1555 .maxlen = sizeof(aio_nr),
1557 .proc_handler = &proc_doulongvec_minmax,
1560 .procname = "aio-max-nr",
1561 .data = &aio_max_nr,
1562 .maxlen = sizeof(aio_max_nr),
1564 .proc_handler = &proc_doulongvec_minmax,
1566 #endif /* CONFIG_AIO */
1567 #ifdef CONFIG_INOTIFY_USER
1569 .ctl_name = FS_INOTIFY,
1570 .procname = "inotify",
1572 .child = inotify_table,
1577 .procname = "epoll",
1579 .child = epoll_table,
1584 .ctl_name = KERN_SETUID_DUMPABLE,
1585 .procname = "suid_dumpable",
1586 .data = &suid_dumpable,
1587 .maxlen = sizeof(int),
1589 .proc_handler = &proc_dointvec_minmax,
1590 .strategy = &sysctl_intvec,
1594 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1596 .ctl_name = CTL_UNNUMBERED,
1597 .procname = "binfmt_misc",
1599 .child = binfmt_misc_table,
1603 * NOTE: do not add new entries to this table unless you have read
1604 * Documentation/sysctl/ctl_unnumbered.txt
1609 static struct ctl_table debug_table[] = {
1610 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1612 .ctl_name = CTL_UNNUMBERED,
1613 .procname = "exception-trace",
1614 .data = &show_unhandled_signals,
1615 .maxlen = sizeof(int),
1617 .proc_handler = proc_dointvec
1623 static struct ctl_table dev_table[] = {
1627 static DEFINE_SPINLOCK(sysctl_lock);
1629 /* called under sysctl_lock */
1630 static int use_table(struct ctl_table_header *p)
1632 if (unlikely(p->unregistering))
1638 /* called under sysctl_lock */
1639 static void unuse_table(struct ctl_table_header *p)
1642 if (unlikely(p->unregistering))
1643 complete(p->unregistering);
1646 /* called under sysctl_lock, will reacquire if has to wait */
1647 static void start_unregistering(struct ctl_table_header *p)
1650 * if p->used is 0, nobody will ever touch that entry again;
1651 * we'll eliminate all paths to it before dropping sysctl_lock
1653 if (unlikely(p->used)) {
1654 struct completion wait;
1655 init_completion(&wait);
1656 p->unregistering = &wait;
1657 spin_unlock(&sysctl_lock);
1658 wait_for_completion(&wait);
1659 spin_lock(&sysctl_lock);
1661 /* anything non-NULL; we'll never dereference it */
1662 p->unregistering = ERR_PTR(-EINVAL);
1665 * do not remove from the list until nobody holds it; walking the
1666 * list in do_sysctl() relies on that.
1668 list_del_init(&p->ctl_entry);
1671 void sysctl_head_get(struct ctl_table_header *head)
1673 spin_lock(&sysctl_lock);
1675 spin_unlock(&sysctl_lock);
1678 void sysctl_head_put(struct ctl_table_header *head)
1680 spin_lock(&sysctl_lock);
1683 spin_unlock(&sysctl_lock);
1686 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1690 spin_lock(&sysctl_lock);
1691 if (!use_table(head))
1692 head = ERR_PTR(-ENOENT);
1693 spin_unlock(&sysctl_lock);
1697 void sysctl_head_finish(struct ctl_table_header *head)
1701 spin_lock(&sysctl_lock);
1703 spin_unlock(&sysctl_lock);
1706 static struct ctl_table_set *
1707 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1709 struct ctl_table_set *set = &root->default_set;
1711 set = root->lookup(root, namespaces);
1715 static struct list_head *
1716 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1718 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1722 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1723 struct ctl_table_header *prev)
1725 struct ctl_table_root *root;
1726 struct list_head *header_list;
1727 struct ctl_table_header *head;
1728 struct list_head *tmp;
1730 spin_lock(&sysctl_lock);
1733 tmp = &prev->ctl_entry;
1737 tmp = &root_table_header.ctl_entry;
1739 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1741 if (!use_table(head))
1743 spin_unlock(&sysctl_lock);
1748 header_list = lookup_header_list(root, namespaces);
1749 if (tmp != header_list)
1753 root = list_entry(root->root_list.next,
1754 struct ctl_table_root, root_list);
1755 if (root == &sysctl_table_root)
1757 header_list = lookup_header_list(root, namespaces);
1758 } while (list_empty(header_list));
1759 tmp = header_list->next;
1762 spin_unlock(&sysctl_lock);
1766 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1768 return __sysctl_head_next(current->nsproxy, prev);
1771 void register_sysctl_root(struct ctl_table_root *root)
1773 spin_lock(&sysctl_lock);
1774 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1775 spin_unlock(&sysctl_lock);
1778 #ifdef CONFIG_SYSCTL_SYSCALL
1779 /* Perform the actual read/write of a sysctl table entry. */
1780 static int do_sysctl_strategy(struct ctl_table_root *root,
1781 struct ctl_table *table,
1782 void __user *oldval, size_t __user *oldlenp,
1783 void __user *newval, size_t newlen)
1791 if (sysctl_perm(root, table, op))
1794 if (table->strategy) {
1795 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1802 /* If there is no strategy routine, or if the strategy returns
1803 * zero, proceed with automatic r/w */
1804 if (table->data && table->maxlen) {
1805 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1812 static int parse_table(int __user *name, int nlen,
1813 void __user *oldval, size_t __user *oldlenp,
1814 void __user *newval, size_t newlen,
1815 struct ctl_table_root *root,
1816 struct ctl_table *table)
1822 if (get_user(n, name))
1824 for ( ; table->ctl_name || table->procname; table++) {
1825 if (!table->ctl_name)
1827 if (n == table->ctl_name) {
1830 if (sysctl_perm(root, table, MAY_EXEC))
1834 table = table->child;
1837 error = do_sysctl_strategy(root, table,
1846 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1847 void __user *newval, size_t newlen)
1849 struct ctl_table_header *head;
1850 int error = -ENOTDIR;
1852 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1856 if (!oldlenp || get_user(old_len, oldlenp))
1860 for (head = sysctl_head_next(NULL); head;
1861 head = sysctl_head_next(head)) {
1862 error = parse_table(name, nlen, oldval, oldlenp,
1864 head->root, head->ctl_table);
1865 if (error != -ENOTDIR) {
1866 sysctl_head_finish(head);
1873 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1875 struct __sysctl_args tmp;
1878 if (copy_from_user(&tmp, args, sizeof(tmp)))
1881 error = deprecated_sysctl_warning(&tmp);
1886 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1887 tmp.newval, tmp.newlen);
1892 #endif /* CONFIG_SYSCTL_SYSCALL */
1895 * sysctl_perm does NOT grant the superuser all rights automatically, because
1896 * some sysctl variables are readonly even to root.
1899 static int test_perm(int mode, int op)
1901 if (!current_euid())
1903 else if (in_egroup_p(0))
1905 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1910 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1915 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1919 if (root->permissions)
1920 mode = root->permissions(root, current->nsproxy, table);
1924 return test_perm(mode, op);
1927 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1929 for (; table->ctl_name || table->procname; table++) {
1930 table->parent = parent;
1932 sysctl_set_parent(table, table->child);
1936 static __init int sysctl_init(void)
1938 sysctl_set_parent(NULL, root_table);
1939 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1942 err = sysctl_check_table(current->nsproxy, root_table);
1948 core_initcall(sysctl_init);
1950 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1951 struct ctl_table *table)
1953 struct ctl_table *p;
1954 const char *s = branch->procname;
1956 /* branch should have named subdirectory as its first element */
1957 if (!s || !branch->child)
1960 /* ... and nothing else */
1961 if (branch[1].procname || branch[1].ctl_name)
1964 /* table should contain subdirectory with the same name */
1965 for (p = table; p->procname || p->ctl_name; p++) {
1968 if (p->procname && strcmp(p->procname, s) == 0)
1974 /* see if attaching q to p would be an improvement */
1975 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1977 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1978 struct ctl_table *next;
1980 int not_in_parent = !p->attached_by;
1982 while ((next = is_branch_in(by, to)) != NULL) {
1983 if (by == q->attached_by)
1985 if (to == p->attached_by)
1991 if (is_better && not_in_parent) {
1992 q->attached_by = by;
1993 q->attached_to = to;
1999 * __register_sysctl_paths - register a sysctl hierarchy
2000 * @root: List of sysctl headers to register on
2001 * @namespaces: Data to compute which lists of sysctl entries are visible
2002 * @path: The path to the directory the sysctl table is in.
2003 * @table: the top-level table structure
2005 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2006 * array. A completely 0 filled entry terminates the table.
2008 * The members of the &struct ctl_table structure are used as follows:
2010 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
2011 * must be unique within that level of sysctl
2013 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
2014 * enter a sysctl file
2016 * data - a pointer to data for use by proc_handler
2018 * maxlen - the maximum size in bytes of the data
2020 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
2022 * child - a pointer to the child sysctl table if this entry is a directory, or
2025 * proc_handler - the text handler routine (described below)
2027 * strategy - the strategy routine (described below)
2029 * de - for internal use by the sysctl routines
2031 * extra1, extra2 - extra pointers usable by the proc handler routines
2033 * Leaf nodes in the sysctl tree will be represented by a single file
2034 * under /proc; non-leaf nodes will be represented by directories.
2036 * sysctl(2) can automatically manage read and write requests through
2037 * the sysctl table. The data and maxlen fields of the ctl_table
2038 * struct enable minimal validation of the values being written to be
2039 * performed, and the mode field allows minimal authentication.
2041 * More sophisticated management can be enabled by the provision of a
2042 * strategy routine with the table entry. This will be called before
2043 * any automatic read or write of the data is performed.
2045 * The strategy routine may return
2047 * < 0 - Error occurred (error is passed to user process)
2049 * 0 - OK - proceed with automatic read or write.
2051 * > 0 - OK - read or write has been done by the strategy routine, so
2052 * return immediately.
2054 * There must be a proc_handler routine for any terminal nodes
2055 * mirrored under /proc/sys (non-terminals are handled by a built-in
2056 * directory handler). Several default handlers are available to
2057 * cover common cases -
2059 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2060 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2061 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2063 * It is the handler's job to read the input buffer from user memory
2064 * and process it. The handler should return 0 on success.
2066 * This routine returns %NULL on a failure to register, and a pointer
2067 * to the table header on success.
2069 struct ctl_table_header *__register_sysctl_paths(
2070 struct ctl_table_root *root,
2071 struct nsproxy *namespaces,
2072 const struct ctl_path *path, struct ctl_table *table)
2074 struct ctl_table_header *header;
2075 struct ctl_table *new, **prevp;
2076 unsigned int n, npath;
2077 struct ctl_table_set *set;
2079 /* Count the path components */
2080 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2084 * For each path component, allocate a 2-element ctl_table array.
2085 * The first array element will be filled with the sysctl entry
2086 * for this, the second will be the sentinel (ctl_name == 0).
2088 * We allocate everything in one go so that we don't have to
2089 * worry about freeing additional memory in unregister_sysctl_table.
2091 header = kzalloc(sizeof(struct ctl_table_header) +
2092 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2096 new = (struct ctl_table *) (header + 1);
2098 /* Now connect the dots */
2099 prevp = &header->ctl_table;
2100 for (n = 0; n < npath; ++n, ++path) {
2101 /* Copy the procname */
2102 new->procname = path->procname;
2103 new->ctl_name = path->ctl_name;
2107 prevp = &new->child;
2112 header->ctl_table_arg = table;
2114 INIT_LIST_HEAD(&header->ctl_entry);
2116 header->unregistering = NULL;
2117 header->root = root;
2118 sysctl_set_parent(NULL, header->ctl_table);
2120 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2121 if (sysctl_check_table(namespaces, header->ctl_table)) {
2126 spin_lock(&sysctl_lock);
2127 header->set = lookup_header_set(root, namespaces);
2128 header->attached_by = header->ctl_table;
2129 header->attached_to = root_table;
2130 header->parent = &root_table_header;
2131 for (set = header->set; set; set = set->parent) {
2132 struct ctl_table_header *p;
2133 list_for_each_entry(p, &set->list, ctl_entry) {
2134 if (p->unregistering)
2136 try_attach(p, header);
2139 header->parent->count++;
2140 list_add_tail(&header->ctl_entry, &header->set->list);
2141 spin_unlock(&sysctl_lock);
2147 * register_sysctl_table_path - register a sysctl table hierarchy
2148 * @path: The path to the directory the sysctl table is in.
2149 * @table: the top-level table structure
2151 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2152 * array. A completely 0 filled entry terminates the table.
2154 * See __register_sysctl_paths for more details.
2156 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2157 struct ctl_table *table)
2159 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2164 * register_sysctl_table - register a sysctl table hierarchy
2165 * @table: the top-level table structure
2167 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2168 * array. A completely 0 filled entry terminates the table.
2170 * See register_sysctl_paths for more details.
2172 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2174 static const struct ctl_path null_path[] = { {} };
2176 return register_sysctl_paths(null_path, table);
2180 * unregister_sysctl_table - unregister a sysctl table hierarchy
2181 * @header: the header returned from register_sysctl_table
2183 * Unregisters the sysctl table and all children. proc entries may not
2184 * actually be removed until they are no longer used by anyone.
2186 void unregister_sysctl_table(struct ctl_table_header * header)
2193 spin_lock(&sysctl_lock);
2194 start_unregistering(header);
2195 if (!--header->parent->count) {
2197 kfree(header->parent);
2199 if (!--header->count)
2201 spin_unlock(&sysctl_lock);
2204 int sysctl_is_seen(struct ctl_table_header *p)
2206 struct ctl_table_set *set = p->set;
2208 spin_lock(&sysctl_lock);
2209 if (p->unregistering)
2211 else if (!set->is_seen)
2214 res = set->is_seen(set);
2215 spin_unlock(&sysctl_lock);
2219 void setup_sysctl_set(struct ctl_table_set *p,
2220 struct ctl_table_set *parent,
2221 int (*is_seen)(struct ctl_table_set *))
2223 INIT_LIST_HEAD(&p->list);
2224 p->parent = parent ? parent : &sysctl_table_root.default_set;
2225 p->is_seen = is_seen;
2228 #else /* !CONFIG_SYSCTL */
2229 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2234 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2235 struct ctl_table *table)
2240 void unregister_sysctl_table(struct ctl_table_header * table)
2244 void setup_sysctl_set(struct ctl_table_set *p,
2245 struct ctl_table_set *parent,
2246 int (*is_seen)(struct ctl_table_set *))
2250 void sysctl_head_put(struct ctl_table_header *head)
2254 #endif /* CONFIG_SYSCTL */
2260 #ifdef CONFIG_PROC_SYSCTL
2262 static int _proc_do_string(void* data, int maxlen, int write,
2263 void __user *buffer,
2264 size_t *lenp, loff_t *ppos)
2270 if (!data || !maxlen || !*lenp) {
2278 while (len < *lenp) {
2279 if (get_user(c, p++))
2281 if (c == 0 || c == '\n')
2287 if(copy_from_user(data, buffer, len))
2289 ((char *) data)[len] = 0;
2307 if(copy_to_user(buffer, data, len))
2310 if(put_user('\n', ((char __user *) buffer) + len))
2321 * proc_dostring - read a string sysctl
2322 * @table: the sysctl table
2323 * @write: %TRUE if this is a write to the sysctl file
2324 * @buffer: the user buffer
2325 * @lenp: the size of the user buffer
2326 * @ppos: file position
2328 * Reads/writes a string from/to the user buffer. If the kernel
2329 * buffer provided is not large enough to hold the string, the
2330 * string is truncated. The copied string is %NULL-terminated.
2331 * If the string is being read by the user process, it is copied
2332 * and a newline '\n' is added. It is truncated if the buffer is
2335 * Returns 0 on success.
2337 int proc_dostring(struct ctl_table *table, int write,
2338 void __user *buffer, size_t *lenp, loff_t *ppos)
2340 return _proc_do_string(table->data, table->maxlen, write,
2341 buffer, lenp, ppos);
2345 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2347 int write, void *data)
2350 *valp = *negp ? -*lvalp : *lvalp;
2355 *lvalp = (unsigned long)-val;
2358 *lvalp = (unsigned long)val;
2364 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2365 int write, void __user *buffer,
2366 size_t *lenp, loff_t *ppos,
2367 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2368 int write, void *data),
2371 #define TMPBUFLEN 21
2372 int *i, vleft, first = 1, neg;
2376 char buf[TMPBUFLEN], *p;
2377 char __user *s = buffer;
2379 if (!tbl_data || !table->maxlen || !*lenp ||
2380 (*ppos && !write)) {
2385 i = (int *) tbl_data;
2386 vleft = table->maxlen / sizeof(*i);
2390 conv = do_proc_dointvec_conv;
2392 for (; left && vleft--; i++, first=0) {
2407 if (len > sizeof(buf) - 1)
2408 len = sizeof(buf) - 1;
2409 if (copy_from_user(buf, s, len))
2413 if (*p == '-' && left > 1) {
2417 if (*p < '0' || *p > '9')
2420 lval = simple_strtoul(p, &p, 0);
2423 if ((len < left) && *p && !isspace(*p))
2428 if (conv(&neg, &lval, i, 1, data))
2435 if (conv(&neg, &lval, i, 0, data))
2438 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2442 if(copy_to_user(s, buf, len))
2449 if (!write && !first && left) {
2450 if(put_user('\n', s))
2457 if (get_user(c, s++))
2472 static int do_proc_dointvec(struct ctl_table *table, int write,
2473 void __user *buffer, size_t *lenp, loff_t *ppos,
2474 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2475 int write, void *data),
2478 return __do_proc_dointvec(table->data, table, write,
2479 buffer, lenp, ppos, conv, data);
2483 * proc_dointvec - read a vector of integers
2484 * @table: the sysctl table
2485 * @write: %TRUE if this is a write to the sysctl file
2486 * @buffer: the user buffer
2487 * @lenp: the size of the user buffer
2488 * @ppos: file position
2490 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2491 * values from/to the user buffer, treated as an ASCII string.
2493 * Returns 0 on success.
2495 int proc_dointvec(struct ctl_table *table, int write,
2496 void __user *buffer, size_t *lenp, loff_t *ppos)
2498 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2503 * Taint values can only be increased
2504 * This means we can safely use a temporary.
2506 static int proc_taint(struct ctl_table *table, int write,
2507 void __user *buffer, size_t *lenp, loff_t *ppos)
2510 unsigned long tmptaint = get_taint();
2513 if (write && !capable(CAP_SYS_ADMIN))
2518 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2524 * Poor man's atomic or. Not worth adding a primitive
2525 * to everyone's atomic.h for this
2528 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2529 if ((tmptaint >> i) & 1)
2537 struct do_proc_dointvec_minmax_conv_param {
2542 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2544 int write, void *data)
2546 struct do_proc_dointvec_minmax_conv_param *param = data;
2548 int val = *negp ? -*lvalp : *lvalp;
2549 if ((param->min && *param->min > val) ||
2550 (param->max && *param->max < val))
2557 *lvalp = (unsigned long)-val;
2560 *lvalp = (unsigned long)val;
2567 * proc_dointvec_minmax - read a vector of integers with min/max values
2568 * @table: the sysctl table
2569 * @write: %TRUE if this is a write to the sysctl file
2570 * @buffer: the user buffer
2571 * @lenp: the size of the user buffer
2572 * @ppos: file position
2574 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2575 * values from/to the user buffer, treated as an ASCII string.
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_dointvec_minmax(struct ctl_table *table, int write,
2583 void __user *buffer, size_t *lenp, loff_t *ppos)
2585 struct do_proc_dointvec_minmax_conv_param param = {
2586 .min = (int *) table->extra1,
2587 .max = (int *) table->extra2,
2589 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2590 do_proc_dointvec_minmax_conv, ¶m);
2593 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2594 void __user *buffer,
2595 size_t *lenp, loff_t *ppos,
2596 unsigned long convmul,
2597 unsigned long convdiv)
2599 #define TMPBUFLEN 21
2600 unsigned long *i, *min, *max, val;
2601 int vleft, first=1, neg;
2603 char buf[TMPBUFLEN], *p;
2604 char __user *s = buffer;
2606 if (!data || !table->maxlen || !*lenp ||
2607 (*ppos && !write)) {
2612 i = (unsigned long *) data;
2613 min = (unsigned long *) table->extra1;
2614 max = (unsigned long *) table->extra2;
2615 vleft = table->maxlen / sizeof(unsigned long);
2618 for (; left && vleft--; i++, min++, max++, first=0) {
2633 if (len > TMPBUFLEN-1)
2635 if (copy_from_user(buf, s, len))
2639 if (*p == '-' && left > 1) {
2643 if (*p < '0' || *p > '9')
2645 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2647 if ((len < left) && *p && !isspace(*p))
2656 if ((min && val < *min) || (max && val > *max))
2663 sprintf(p, "%lu", convdiv * (*i) / convmul);
2667 if(copy_to_user(s, buf, len))
2674 if (!write && !first && left) {
2675 if(put_user('\n', s))
2682 if (get_user(c, s++))
2697 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2698 void __user *buffer,
2699 size_t *lenp, loff_t *ppos,
2700 unsigned long convmul,
2701 unsigned long convdiv)
2703 return __do_proc_doulongvec_minmax(table->data, table, write,
2704 buffer, lenp, ppos, convmul, convdiv);
2708 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2709 * @table: the sysctl table
2710 * @write: %TRUE if this is a write to the sysctl file
2711 * @buffer: the user buffer
2712 * @lenp: the size of the user buffer
2713 * @ppos: file position
2715 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2716 * values from/to the user buffer, treated as an ASCII string.
2718 * This routine will ensure the values are within the range specified by
2719 * table->extra1 (min) and table->extra2 (max).
2721 * Returns 0 on success.
2723 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2724 void __user *buffer, size_t *lenp, loff_t *ppos)
2726 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2730 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2731 * @table: the sysctl table
2732 * @write: %TRUE if this is a write to the sysctl file
2733 * @buffer: the user buffer
2734 * @lenp: the size of the user buffer
2735 * @ppos: file position
2737 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2738 * values from/to the user buffer, treated as an ASCII string. The values
2739 * are treated as milliseconds, and converted to jiffies when they are stored.
2741 * This routine will ensure the values are within the range specified by
2742 * table->extra1 (min) and table->extra2 (max).
2744 * Returns 0 on success.
2746 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2747 void __user *buffer,
2748 size_t *lenp, loff_t *ppos)
2750 return do_proc_doulongvec_minmax(table, write, buffer,
2751 lenp, ppos, HZ, 1000l);
2755 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2757 int write, void *data)
2760 if (*lvalp > LONG_MAX / HZ)
2762 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2768 lval = (unsigned long)-val;
2771 lval = (unsigned long)val;
2778 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2780 int write, void *data)
2783 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2785 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2791 lval = (unsigned long)-val;
2794 lval = (unsigned long)val;
2796 *lvalp = jiffies_to_clock_t(lval);
2801 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2803 int write, void *data)
2806 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2812 lval = (unsigned long)-val;
2815 lval = (unsigned long)val;
2817 *lvalp = jiffies_to_msecs(lval);
2823 * proc_dointvec_jiffies - read a vector of integers as seconds
2824 * @table: the sysctl table
2825 * @write: %TRUE if this is a write to the sysctl file
2826 * @buffer: the user buffer
2827 * @lenp: the size of the user buffer
2828 * @ppos: file position
2830 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2831 * values from/to the user buffer, treated as an ASCII string.
2832 * The values read are assumed to be in seconds, and are converted into
2835 * Returns 0 on success.
2837 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2838 void __user *buffer, size_t *lenp, loff_t *ppos)
2840 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2841 do_proc_dointvec_jiffies_conv,NULL);
2845 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2846 * @table: the sysctl table
2847 * @write: %TRUE if this is a write to the sysctl file
2848 * @buffer: the user buffer
2849 * @lenp: the size of the user buffer
2850 * @ppos: pointer to the file position
2852 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2853 * values from/to the user buffer, treated as an ASCII string.
2854 * The values read are assumed to be in 1/USER_HZ seconds, and
2855 * are converted into jiffies.
2857 * Returns 0 on success.
2859 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2860 void __user *buffer, size_t *lenp, loff_t *ppos)
2862 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2863 do_proc_dointvec_userhz_jiffies_conv,NULL);
2867 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2868 * @table: the sysctl table
2869 * @write: %TRUE if this is a write to the sysctl file
2870 * @buffer: the user buffer
2871 * @lenp: the size of the user buffer
2872 * @ppos: file position
2873 * @ppos: the current position in the file
2875 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2876 * values from/to the user buffer, treated as an ASCII string.
2877 * The values read are assumed to be in 1/1000 seconds, and
2878 * are converted into jiffies.
2880 * Returns 0 on success.
2882 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2883 void __user *buffer, size_t *lenp, loff_t *ppos)
2885 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2886 do_proc_dointvec_ms_jiffies_conv, NULL);
2889 static int proc_do_cad_pid(struct ctl_table *table, int write,
2890 void __user *buffer, size_t *lenp, loff_t *ppos)
2892 struct pid *new_pid;
2896 tmp = pid_vnr(cad_pid);
2898 r = __do_proc_dointvec(&tmp, table, write, buffer,
2899 lenp, ppos, NULL, NULL);
2903 new_pid = find_get_pid(tmp);
2907 put_pid(xchg(&cad_pid, new_pid));
2911 #else /* CONFIG_PROC_FS */
2913 int proc_dostring(struct ctl_table *table, int write,
2914 void __user *buffer, size_t *lenp, loff_t *ppos)
2919 int proc_dointvec(struct ctl_table *table, int write,
2920 void __user *buffer, size_t *lenp, loff_t *ppos)
2925 int proc_dointvec_minmax(struct ctl_table *table, int write,
2926 void __user *buffer, size_t *lenp, loff_t *ppos)
2931 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2932 void __user *buffer, size_t *lenp, loff_t *ppos)
2937 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2938 void __user *buffer, size_t *lenp, loff_t *ppos)
2943 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2944 void __user *buffer, size_t *lenp, loff_t *ppos)
2949 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2950 void __user *buffer, size_t *lenp, loff_t *ppos)
2955 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2956 void __user *buffer,
2957 size_t *lenp, loff_t *ppos)
2963 #endif /* CONFIG_PROC_FS */
2966 #ifdef CONFIG_SYSCTL_SYSCALL
2968 * General sysctl support routines
2971 /* The generic sysctl data routine (used if no strategy routine supplied) */
2972 int sysctl_data(struct ctl_table *table,
2973 void __user *oldval, size_t __user *oldlenp,
2974 void __user *newval, size_t newlen)
2978 /* Get out of I don't have a variable */
2979 if (!table->data || !table->maxlen)
2982 if (oldval && oldlenp) {
2983 if (get_user(len, oldlenp))
2986 if (len > table->maxlen)
2987 len = table->maxlen;
2988 if (copy_to_user(oldval, table->data, len))
2990 if (put_user(len, oldlenp))
2995 if (newval && newlen) {
2996 if (newlen > table->maxlen)
2997 newlen = table->maxlen;
2999 if (copy_from_user(table->data, newval, newlen))
3005 /* The generic string strategy routine: */
3006 int sysctl_string(struct ctl_table *table,
3007 void __user *oldval, size_t __user *oldlenp,
3008 void __user *newval, size_t newlen)
3010 if (!table->data || !table->maxlen)
3013 if (oldval && oldlenp) {
3015 if (get_user(bufsize, oldlenp))
3018 size_t len = strlen(table->data), copied;
3020 /* This shouldn't trigger for a well-formed sysctl */
3021 if (len > table->maxlen)
3022 len = table->maxlen;
3024 /* Copy up to a max of bufsize-1 bytes of the string */
3025 copied = (len >= bufsize) ? bufsize - 1 : len;
3027 if (copy_to_user(oldval, table->data, copied) ||
3028 put_user(0, (char __user *)(oldval + copied)))
3030 if (put_user(len, oldlenp))
3034 if (newval && newlen) {
3035 size_t len = newlen;
3036 if (len > table->maxlen)
3037 len = table->maxlen;
3038 if(copy_from_user(table->data, newval, len))
3040 if (len == table->maxlen)
3042 ((char *) table->data)[len] = 0;
3048 * This function makes sure that all of the integers in the vector
3049 * are between the minimum and maximum values given in the arrays
3050 * table->extra1 and table->extra2, respectively.
3052 int sysctl_intvec(struct ctl_table *table,
3053 void __user *oldval, size_t __user *oldlenp,
3054 void __user *newval, size_t newlen)
3057 if (newval && newlen) {
3058 int __user *vec = (int __user *) newval;
3059 int *min = (int *) table->extra1;
3060 int *max = (int *) table->extra2;
3064 if (newlen % sizeof(int) != 0)
3067 if (!table->extra1 && !table->extra2)
3070 if (newlen > table->maxlen)
3071 newlen = table->maxlen;
3072 length = newlen / sizeof(int);
3074 for (i = 0; i < length; i++) {
3076 if (get_user(value, vec + i))
3078 if (min && value < min[i])
3080 if (max && value > max[i])
3087 /* Strategy function to convert jiffies to seconds */
3088 int sysctl_jiffies(struct ctl_table *table,
3089 void __user *oldval, size_t __user *oldlenp,
3090 void __user *newval, size_t newlen)
3092 if (oldval && oldlenp) {
3095 if (get_user(olen, oldlenp))
3100 if (olen < sizeof(int))
3103 val = *(int *)(table->data) / HZ;
3104 if (put_user(val, (int __user *)oldval))
3106 if (put_user(sizeof(int), oldlenp))
3110 if (newval && newlen) {
3112 if (newlen != sizeof(int))
3114 if (get_user(new, (int __user *)newval))
3116 *(int *)(table->data) = new*HZ;
3121 /* Strategy function to convert jiffies to seconds */
3122 int sysctl_ms_jiffies(struct ctl_table *table,
3123 void __user *oldval, size_t __user *oldlenp,
3124 void __user *newval, size_t newlen)
3126 if (oldval && oldlenp) {
3129 if (get_user(olen, oldlenp))
3134 if (olen < sizeof(int))
3137 val = jiffies_to_msecs(*(int *)(table->data));
3138 if (put_user(val, (int __user *)oldval))
3140 if (put_user(sizeof(int), oldlenp))
3144 if (newval && newlen) {
3146 if (newlen != sizeof(int))
3148 if (get_user(new, (int __user *)newval))
3150 *(int *)(table->data) = msecs_to_jiffies(new);
3157 #else /* CONFIG_SYSCTL_SYSCALL */
3160 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3162 struct __sysctl_args tmp;
3165 if (copy_from_user(&tmp, args, sizeof(tmp)))
3168 error = deprecated_sysctl_warning(&tmp);
3170 /* If no error reading the parameters then just -ENOSYS ... */
3177 int sysctl_data(struct ctl_table *table,
3178 void __user *oldval, size_t __user *oldlenp,
3179 void __user *newval, size_t newlen)
3184 int sysctl_string(struct ctl_table *table,
3185 void __user *oldval, size_t __user *oldlenp,
3186 void __user *newval, size_t newlen)
3191 int sysctl_intvec(struct ctl_table *table,
3192 void __user *oldval, size_t __user *oldlenp,
3193 void __user *newval, size_t newlen)
3198 int sysctl_jiffies(struct ctl_table *table,
3199 void __user *oldval, size_t __user *oldlenp,
3200 void __user *newval, size_t newlen)
3205 int sysctl_ms_jiffies(struct ctl_table *table,
3206 void __user *oldval, size_t __user *oldlenp,
3207 void __user *newval, size_t newlen)
3212 #endif /* CONFIG_SYSCTL_SYSCALL */
3214 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3216 static int msg_count;
3217 int name[CTL_MAXNAME];
3220 /* Check args->nlen. */
3221 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3224 /* Read in the sysctl name for better debug message logging */
3225 for (i = 0; i < args->nlen; i++)
3226 if (get_user(name[i], args->name + i))
3229 /* Ignore accesses to kernel.version */
3230 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3233 if (msg_count < 5) {
3236 "warning: process `%s' used the deprecated sysctl "
3237 "system call with ", current->comm);
3238 for (i = 0; i < args->nlen; i++)
3239 printk("%d.", name[i]);
3246 * No sense putting this after each symbol definition, twice,
3247 * exception granted :-)
3249 EXPORT_SYMBOL(proc_dointvec);
3250 EXPORT_SYMBOL(proc_dointvec_jiffies);
3251 EXPORT_SYMBOL(proc_dointvec_minmax);
3252 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3253 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3254 EXPORT_SYMBOL(proc_dostring);
3255 EXPORT_SYMBOL(proc_doulongvec_minmax);
3256 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3257 EXPORT_SYMBOL(register_sysctl_table);
3258 EXPORT_SYMBOL(register_sysctl_paths);
3259 EXPORT_SYMBOL(sysctl_intvec);
3260 EXPORT_SYMBOL(sysctl_jiffies);
3261 EXPORT_SYMBOL(sysctl_ms_jiffies);
3262 EXPORT_SYMBOL(sysctl_string);
3263 EXPORT_SYMBOL(sysctl_data);
3264 EXPORT_SYMBOL(unregister_sysctl_table);