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/utsname.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/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
52 #include <asm/uaccess.h>
53 #include <asm/processor.h>
57 #include <asm/stacktrace.h>
61 static int deprecated_sysctl_warning(struct __sysctl_args *args);
63 #if defined(CONFIG_SYSCTL)
65 /* External variables not in a header file. */
67 extern int print_fatal_signals;
68 extern int sysctl_overcommit_memory;
69 extern int sysctl_overcommit_ratio;
70 extern int sysctl_panic_on_oom;
71 extern int sysctl_oom_kill_allocating_task;
72 extern int sysctl_oom_dump_tasks;
73 extern int max_threads;
74 extern int core_uses_pid;
75 extern int suid_dumpable;
76 extern char core_pattern[];
78 extern int min_free_kbytes;
79 extern int pid_max_min, pid_max_max;
80 extern int sysctl_drop_caches;
81 extern int percpu_pagelist_fraction;
82 extern int compat_log;
83 extern int latencytop_enabled;
84 extern int sysctl_nr_open_min, sysctl_nr_open_max;
86 extern int sysctl_nr_trim_pages;
88 #ifdef CONFIG_RCU_TORTURE_TEST
89 extern int rcutorture_runnable;
90 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
92 /* Constants used for minimum and maximum */
93 #ifdef CONFIG_DETECT_SOFTLOCKUP
94 static int sixty = 60;
95 static int neg_one = -1;
98 #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
104 static unsigned long one_ul = 1;
105 static int one_hundred = 100;
107 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
108 static int maxolduid = 65535;
109 static int minolduid;
110 static int min_percpu_pagelist_fract = 8;
112 static int ngroups_max = NGROUPS_MAX;
114 #ifdef CONFIG_MODULES
115 extern char modprobe_path[];
116 extern int modules_disabled;
118 #ifdef CONFIG_CHR_DEV_SG
119 extern int sg_big_buff;
123 #include <asm/system.h>
126 #ifdef CONFIG_SPARC64
127 extern int sysctl_tsb_ratio;
131 extern int pwrsw_enabled;
132 extern int unaligned_enabled;
136 #ifdef CONFIG_MATHEMU
137 extern int sysctl_ieee_emulation_warnings;
139 extern int sysctl_userprocess_debug;
140 extern int spin_retry;
143 #ifdef CONFIG_BSD_PROCESS_ACCT
144 extern int acct_parm[];
148 extern int no_unaligned_warning;
149 extern int unaligned_dump_stack;
152 #ifdef CONFIG_RT_MUTEXES
153 extern int max_lock_depth;
156 #ifdef CONFIG_PROC_SYSCTL
157 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
158 void __user *buffer, size_t *lenp, loff_t *ppos);
159 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
160 void __user *buffer, size_t *lenp, loff_t *ppos);
163 static struct ctl_table root_table[];
164 static struct ctl_table_root sysctl_table_root;
165 static struct ctl_table_header root_table_header = {
167 .ctl_table = root_table,
168 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
169 .root = &sysctl_table_root,
170 .set = &sysctl_table_root.default_set,
172 static struct ctl_table_root sysctl_table_root = {
173 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
174 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
177 static struct ctl_table kern_table[];
178 static struct ctl_table vm_table[];
179 static struct ctl_table fs_table[];
180 static struct ctl_table debug_table[];
181 static struct ctl_table dev_table[];
182 extern struct ctl_table random_table[];
183 #ifdef CONFIG_INOTIFY_USER
184 extern struct ctl_table inotify_table[];
187 extern struct ctl_table epoll_table[];
190 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
191 int sysctl_legacy_va_layout;
194 extern int prove_locking;
195 extern int lock_stat;
197 /* The default sysctl tables: */
199 static struct ctl_table root_table[] = {
201 .ctl_name = CTL_KERN,
202 .procname = "kernel",
219 .ctl_name = CTL_DEBUG,
222 .child = debug_table,
231 * NOTE: do not add new entries to this table unless you have read
232 * Documentation/sysctl/ctl_unnumbered.txt
237 #ifdef CONFIG_SCHED_DEBUG
238 static int min_sched_granularity_ns = 100000; /* 100 usecs */
239 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
240 static int min_wakeup_granularity_ns; /* 0 usecs */
241 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
244 static struct ctl_table kern_table[] = {
245 #ifdef CONFIG_SCHED_DEBUG
247 .ctl_name = CTL_UNNUMBERED,
248 .procname = "sched_min_granularity_ns",
249 .data = &sysctl_sched_min_granularity,
250 .maxlen = sizeof(unsigned int),
252 .proc_handler = &sched_nr_latency_handler,
253 .strategy = &sysctl_intvec,
254 .extra1 = &min_sched_granularity_ns,
255 .extra2 = &max_sched_granularity_ns,
258 .ctl_name = CTL_UNNUMBERED,
259 .procname = "sched_latency_ns",
260 .data = &sysctl_sched_latency,
261 .maxlen = sizeof(unsigned int),
263 .proc_handler = &sched_nr_latency_handler,
264 .strategy = &sysctl_intvec,
265 .extra1 = &min_sched_granularity_ns,
266 .extra2 = &max_sched_granularity_ns,
269 .ctl_name = CTL_UNNUMBERED,
270 .procname = "sched_wakeup_granularity_ns",
271 .data = &sysctl_sched_wakeup_granularity,
272 .maxlen = sizeof(unsigned int),
274 .proc_handler = &proc_dointvec_minmax,
275 .strategy = &sysctl_intvec,
276 .extra1 = &min_wakeup_granularity_ns,
277 .extra2 = &max_wakeup_granularity_ns,
280 .ctl_name = CTL_UNNUMBERED,
281 .procname = "sched_shares_ratelimit",
282 .data = &sysctl_sched_shares_ratelimit,
283 .maxlen = sizeof(unsigned int),
285 .proc_handler = &proc_dointvec,
288 .ctl_name = CTL_UNNUMBERED,
289 .procname = "sched_shares_thresh",
290 .data = &sysctl_sched_shares_thresh,
291 .maxlen = sizeof(unsigned int),
293 .proc_handler = &proc_dointvec_minmax,
294 .strategy = &sysctl_intvec,
298 .ctl_name = CTL_UNNUMBERED,
299 .procname = "sched_child_runs_first",
300 .data = &sysctl_sched_child_runs_first,
301 .maxlen = sizeof(unsigned int),
303 .proc_handler = &proc_dointvec,
306 .ctl_name = CTL_UNNUMBERED,
307 .procname = "sched_features",
308 .data = &sysctl_sched_features,
309 .maxlen = sizeof(unsigned int),
311 .proc_handler = &proc_dointvec,
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_migration_cost",
316 .data = &sysctl_sched_migration_cost,
317 .maxlen = sizeof(unsigned int),
319 .proc_handler = &proc_dointvec,
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_nr_migrate",
324 .data = &sysctl_sched_nr_migrate,
325 .maxlen = sizeof(unsigned int),
327 .proc_handler = &proc_dointvec,
331 .ctl_name = CTL_UNNUMBERED,
332 .procname = "sched_rt_period_us",
333 .data = &sysctl_sched_rt_period,
334 .maxlen = sizeof(unsigned int),
336 .proc_handler = &sched_rt_handler,
339 .ctl_name = CTL_UNNUMBERED,
340 .procname = "sched_rt_runtime_us",
341 .data = &sysctl_sched_rt_runtime,
342 .maxlen = sizeof(int),
344 .proc_handler = &sched_rt_handler,
347 .ctl_name = CTL_UNNUMBERED,
348 .procname = "sched_compat_yield",
349 .data = &sysctl_sched_compat_yield,
350 .maxlen = sizeof(unsigned int),
352 .proc_handler = &proc_dointvec,
354 #ifdef CONFIG_PROVE_LOCKING
356 .ctl_name = CTL_UNNUMBERED,
357 .procname = "prove_locking",
358 .data = &prove_locking,
359 .maxlen = sizeof(int),
361 .proc_handler = &proc_dointvec,
364 #ifdef CONFIG_LOCK_STAT
366 .ctl_name = CTL_UNNUMBERED,
367 .procname = "lock_stat",
369 .maxlen = sizeof(int),
371 .proc_handler = &proc_dointvec,
375 .ctl_name = KERN_PANIC,
377 .data = &panic_timeout,
378 .maxlen = sizeof(int),
380 .proc_handler = &proc_dointvec,
383 .ctl_name = KERN_CORE_USES_PID,
384 .procname = "core_uses_pid",
385 .data = &core_uses_pid,
386 .maxlen = sizeof(int),
388 .proc_handler = &proc_dointvec,
391 .ctl_name = KERN_CORE_PATTERN,
392 .procname = "core_pattern",
393 .data = core_pattern,
394 .maxlen = CORENAME_MAX_SIZE,
396 .proc_handler = &proc_dostring,
397 .strategy = &sysctl_string,
399 #ifdef CONFIG_PROC_SYSCTL
401 .procname = "tainted",
402 .maxlen = sizeof(long),
404 .proc_handler = &proc_taint,
407 #ifdef CONFIG_LATENCYTOP
409 .procname = "latencytop",
410 .data = &latencytop_enabled,
411 .maxlen = sizeof(int),
413 .proc_handler = &proc_dointvec,
416 #ifdef CONFIG_BLK_DEV_INITRD
418 .ctl_name = KERN_REALROOTDEV,
419 .procname = "real-root-dev",
420 .data = &real_root_dev,
421 .maxlen = sizeof(int),
423 .proc_handler = &proc_dointvec,
427 .ctl_name = CTL_UNNUMBERED,
428 .procname = "print-fatal-signals",
429 .data = &print_fatal_signals,
430 .maxlen = sizeof(int),
432 .proc_handler = &proc_dointvec,
436 .ctl_name = KERN_SPARC_REBOOT,
437 .procname = "reboot-cmd",
438 .data = reboot_command,
441 .proc_handler = &proc_dostring,
442 .strategy = &sysctl_string,
445 .ctl_name = KERN_SPARC_STOP_A,
446 .procname = "stop-a",
447 .data = &stop_a_enabled,
448 .maxlen = sizeof (int),
450 .proc_handler = &proc_dointvec,
453 .ctl_name = KERN_SPARC_SCONS_PWROFF,
454 .procname = "scons-poweroff",
455 .data = &scons_pwroff,
456 .maxlen = sizeof (int),
458 .proc_handler = &proc_dointvec,
461 #ifdef CONFIG_SPARC64
463 .ctl_name = CTL_UNNUMBERED,
464 .procname = "tsb-ratio",
465 .data = &sysctl_tsb_ratio,
466 .maxlen = sizeof (int),
468 .proc_handler = &proc_dointvec,
473 .ctl_name = KERN_HPPA_PWRSW,
474 .procname = "soft-power",
475 .data = &pwrsw_enabled,
476 .maxlen = sizeof (int),
478 .proc_handler = &proc_dointvec,
481 .ctl_name = KERN_HPPA_UNALIGNED,
482 .procname = "unaligned-trap",
483 .data = &unaligned_enabled,
484 .maxlen = sizeof (int),
486 .proc_handler = &proc_dointvec,
490 .ctl_name = KERN_CTLALTDEL,
491 .procname = "ctrl-alt-del",
493 .maxlen = sizeof(int),
495 .proc_handler = &proc_dointvec,
497 #ifdef CONFIG_FUNCTION_TRACER
499 .ctl_name = CTL_UNNUMBERED,
500 .procname = "ftrace_enabled",
501 .data = &ftrace_enabled,
502 .maxlen = sizeof(int),
504 .proc_handler = &ftrace_enable_sysctl,
507 #ifdef CONFIG_STACK_TRACER
509 .ctl_name = CTL_UNNUMBERED,
510 .procname = "stack_tracer_enabled",
511 .data = &stack_tracer_enabled,
512 .maxlen = sizeof(int),
514 .proc_handler = &stack_trace_sysctl,
517 #ifdef CONFIG_TRACING
519 .ctl_name = CTL_UNNUMBERED,
520 .procname = "ftrace_dump_on_oops",
521 .data = &ftrace_dump_on_oops,
522 .maxlen = sizeof(int),
524 .proc_handler = &proc_dointvec,
527 #ifdef CONFIG_MODULES
529 .ctl_name = KERN_MODPROBE,
530 .procname = "modprobe",
531 .data = &modprobe_path,
532 .maxlen = KMOD_PATH_LEN,
534 .proc_handler = &proc_dostring,
535 .strategy = &sysctl_string,
538 .ctl_name = CTL_UNNUMBERED,
539 .procname = "modules_disabled",
540 .data = &modules_disabled,
541 .maxlen = sizeof(int),
543 /* only handle a transition from default "0" to "1" */
544 .proc_handler = &proc_dointvec_minmax,
549 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
551 .ctl_name = KERN_HOTPLUG,
552 .procname = "hotplug",
553 .data = &uevent_helper,
554 .maxlen = UEVENT_HELPER_PATH_LEN,
556 .proc_handler = &proc_dostring,
557 .strategy = &sysctl_string,
560 #ifdef CONFIG_CHR_DEV_SG
562 .ctl_name = KERN_SG_BIG_BUFF,
563 .procname = "sg-big-buff",
564 .data = &sg_big_buff,
565 .maxlen = sizeof (int),
567 .proc_handler = &proc_dointvec,
570 #ifdef CONFIG_BSD_PROCESS_ACCT
572 .ctl_name = KERN_ACCT,
575 .maxlen = 3*sizeof(int),
577 .proc_handler = &proc_dointvec,
580 #ifdef CONFIG_MAGIC_SYSRQ
582 .ctl_name = KERN_SYSRQ,
584 .data = &__sysrq_enabled,
585 .maxlen = sizeof (int),
587 .proc_handler = &proc_dointvec,
590 #ifdef CONFIG_PROC_SYSCTL
592 .procname = "cad_pid",
594 .maxlen = sizeof (int),
596 .proc_handler = &proc_do_cad_pid,
600 .ctl_name = KERN_MAX_THREADS,
601 .procname = "threads-max",
602 .data = &max_threads,
603 .maxlen = sizeof(int),
605 .proc_handler = &proc_dointvec,
608 .ctl_name = KERN_RANDOM,
609 .procname = "random",
611 .child = random_table,
614 .ctl_name = KERN_OVERFLOWUID,
615 .procname = "overflowuid",
616 .data = &overflowuid,
617 .maxlen = sizeof(int),
619 .proc_handler = &proc_dointvec_minmax,
620 .strategy = &sysctl_intvec,
621 .extra1 = &minolduid,
622 .extra2 = &maxolduid,
625 .ctl_name = KERN_OVERFLOWGID,
626 .procname = "overflowgid",
627 .data = &overflowgid,
628 .maxlen = sizeof(int),
630 .proc_handler = &proc_dointvec_minmax,
631 .strategy = &sysctl_intvec,
632 .extra1 = &minolduid,
633 .extra2 = &maxolduid,
636 #ifdef CONFIG_MATHEMU
638 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
639 .procname = "ieee_emulation_warnings",
640 .data = &sysctl_ieee_emulation_warnings,
641 .maxlen = sizeof(int),
643 .proc_handler = &proc_dointvec,
647 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
648 .procname = "userprocess_debug",
649 .data = &sysctl_userprocess_debug,
650 .maxlen = sizeof(int),
652 .proc_handler = &proc_dointvec,
656 .ctl_name = KERN_PIDMAX,
657 .procname = "pid_max",
659 .maxlen = sizeof (int),
661 .proc_handler = &proc_dointvec_minmax,
662 .strategy = sysctl_intvec,
663 .extra1 = &pid_max_min,
664 .extra2 = &pid_max_max,
667 .ctl_name = KERN_PANIC_ON_OOPS,
668 .procname = "panic_on_oops",
669 .data = &panic_on_oops,
670 .maxlen = sizeof(int),
672 .proc_handler = &proc_dointvec,
674 #if defined CONFIG_PRINTK
676 .ctl_name = KERN_PRINTK,
677 .procname = "printk",
678 .data = &console_loglevel,
679 .maxlen = 4*sizeof(int),
681 .proc_handler = &proc_dointvec,
684 .ctl_name = KERN_PRINTK_RATELIMIT,
685 .procname = "printk_ratelimit",
686 .data = &printk_ratelimit_state.interval,
687 .maxlen = sizeof(int),
689 .proc_handler = &proc_dointvec_jiffies,
690 .strategy = &sysctl_jiffies,
693 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
694 .procname = "printk_ratelimit_burst",
695 .data = &printk_ratelimit_state.burst,
696 .maxlen = sizeof(int),
698 .proc_handler = &proc_dointvec,
702 .ctl_name = KERN_NGROUPS_MAX,
703 .procname = "ngroups_max",
704 .data = &ngroups_max,
705 .maxlen = sizeof (int),
707 .proc_handler = &proc_dointvec,
709 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
711 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
712 .procname = "unknown_nmi_panic",
713 .data = &unknown_nmi_panic,
714 .maxlen = sizeof (int),
716 .proc_handler = &proc_dointvec,
719 .procname = "nmi_watchdog",
720 .data = &nmi_watchdog_enabled,
721 .maxlen = sizeof (int),
723 .proc_handler = &proc_nmi_enabled,
726 #if defined(CONFIG_X86)
728 .ctl_name = KERN_PANIC_ON_NMI,
729 .procname = "panic_on_unrecovered_nmi",
730 .data = &panic_on_unrecovered_nmi,
731 .maxlen = sizeof(int),
733 .proc_handler = &proc_dointvec,
736 .ctl_name = KERN_BOOTLOADER_TYPE,
737 .procname = "bootloader_type",
738 .data = &bootloader_type,
739 .maxlen = sizeof (int),
741 .proc_handler = &proc_dointvec,
744 .ctl_name = CTL_UNNUMBERED,
745 .procname = "kstack_depth_to_print",
746 .data = &kstack_depth_to_print,
747 .maxlen = sizeof(int),
749 .proc_handler = &proc_dointvec,
752 .ctl_name = CTL_UNNUMBERED,
753 .procname = "io_delay_type",
754 .data = &io_delay_type,
755 .maxlen = sizeof(int),
757 .proc_handler = &proc_dointvec,
760 #if defined(CONFIG_MMU)
762 .ctl_name = KERN_RANDOMIZE,
763 .procname = "randomize_va_space",
764 .data = &randomize_va_space,
765 .maxlen = sizeof(int),
767 .proc_handler = &proc_dointvec,
770 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
772 .ctl_name = KERN_SPIN_RETRY,
773 .procname = "spin_retry",
775 .maxlen = sizeof (int),
777 .proc_handler = &proc_dointvec,
780 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
782 .procname = "acpi_video_flags",
783 .data = &acpi_realmode_flags,
784 .maxlen = sizeof (unsigned long),
786 .proc_handler = &proc_doulongvec_minmax,
791 .ctl_name = KERN_IA64_UNALIGNED,
792 .procname = "ignore-unaligned-usertrap",
793 .data = &no_unaligned_warning,
794 .maxlen = sizeof (int),
796 .proc_handler = &proc_dointvec,
799 .ctl_name = CTL_UNNUMBERED,
800 .procname = "unaligned-dump-stack",
801 .data = &unaligned_dump_stack,
802 .maxlen = sizeof (int),
804 .proc_handler = &proc_dointvec,
807 #ifdef CONFIG_DETECT_SOFTLOCKUP
809 .ctl_name = CTL_UNNUMBERED,
810 .procname = "softlockup_panic",
811 .data = &softlockup_panic,
812 .maxlen = sizeof(int),
814 .proc_handler = &proc_dointvec_minmax,
815 .strategy = &sysctl_intvec,
820 .ctl_name = CTL_UNNUMBERED,
821 .procname = "softlockup_thresh",
822 .data = &softlockup_thresh,
823 .maxlen = sizeof(int),
825 .proc_handler = &proc_dosoftlockup_thresh,
826 .strategy = &sysctl_intvec,
831 .ctl_name = CTL_UNNUMBERED,
832 .procname = "hung_task_check_count",
833 .data = &sysctl_hung_task_check_count,
834 .maxlen = sizeof(unsigned long),
836 .proc_handler = &proc_doulongvec_minmax,
837 .strategy = &sysctl_intvec,
840 .ctl_name = CTL_UNNUMBERED,
841 .procname = "hung_task_timeout_secs",
842 .data = &sysctl_hung_task_timeout_secs,
843 .maxlen = sizeof(unsigned long),
845 .proc_handler = &proc_doulongvec_minmax,
846 .strategy = &sysctl_intvec,
849 .ctl_name = CTL_UNNUMBERED,
850 .procname = "hung_task_warnings",
851 .data = &sysctl_hung_task_warnings,
852 .maxlen = sizeof(unsigned long),
854 .proc_handler = &proc_doulongvec_minmax,
855 .strategy = &sysctl_intvec,
860 .ctl_name = KERN_COMPAT_LOG,
861 .procname = "compat-log",
863 .maxlen = sizeof (int),
865 .proc_handler = &proc_dointvec,
868 #ifdef CONFIG_RT_MUTEXES
870 .ctl_name = KERN_MAX_LOCK_DEPTH,
871 .procname = "max_lock_depth",
872 .data = &max_lock_depth,
873 .maxlen = sizeof(int),
875 .proc_handler = &proc_dointvec,
879 .ctl_name = CTL_UNNUMBERED,
880 .procname = "poweroff_cmd",
881 .data = &poweroff_cmd,
882 .maxlen = POWEROFF_CMD_PATH_LEN,
884 .proc_handler = &proc_dostring,
885 .strategy = &sysctl_string,
889 .ctl_name = CTL_UNNUMBERED,
892 .child = key_sysctls,
895 #ifdef CONFIG_RCU_TORTURE_TEST
897 .ctl_name = CTL_UNNUMBERED,
898 .procname = "rcutorture_runnable",
899 .data = &rcutorture_runnable,
900 .maxlen = sizeof(int),
902 .proc_handler = &proc_dointvec,
905 #ifdef CONFIG_UNEVICTABLE_LRU
907 .ctl_name = CTL_UNNUMBERED,
908 .procname = "scan_unevictable_pages",
909 .data = &scan_unevictable_pages,
910 .maxlen = sizeof(scan_unevictable_pages),
912 .proc_handler = &scan_unevictable_handler,
916 * NOTE: do not add new entries to this table unless you have read
917 * Documentation/sysctl/ctl_unnumbered.txt
922 static struct ctl_table vm_table[] = {
924 .ctl_name = VM_OVERCOMMIT_MEMORY,
925 .procname = "overcommit_memory",
926 .data = &sysctl_overcommit_memory,
927 .maxlen = sizeof(sysctl_overcommit_memory),
929 .proc_handler = &proc_dointvec,
932 .ctl_name = VM_PANIC_ON_OOM,
933 .procname = "panic_on_oom",
934 .data = &sysctl_panic_on_oom,
935 .maxlen = sizeof(sysctl_panic_on_oom),
937 .proc_handler = &proc_dointvec,
940 .ctl_name = CTL_UNNUMBERED,
941 .procname = "oom_kill_allocating_task",
942 .data = &sysctl_oom_kill_allocating_task,
943 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
945 .proc_handler = &proc_dointvec,
948 .ctl_name = CTL_UNNUMBERED,
949 .procname = "oom_dump_tasks",
950 .data = &sysctl_oom_dump_tasks,
951 .maxlen = sizeof(sysctl_oom_dump_tasks),
953 .proc_handler = &proc_dointvec,
956 .ctl_name = VM_OVERCOMMIT_RATIO,
957 .procname = "overcommit_ratio",
958 .data = &sysctl_overcommit_ratio,
959 .maxlen = sizeof(sysctl_overcommit_ratio),
961 .proc_handler = &proc_dointvec,
964 .ctl_name = VM_PAGE_CLUSTER,
965 .procname = "page-cluster",
966 .data = &page_cluster,
967 .maxlen = sizeof(int),
969 .proc_handler = &proc_dointvec,
972 .ctl_name = VM_DIRTY_BACKGROUND,
973 .procname = "dirty_background_ratio",
974 .data = &dirty_background_ratio,
975 .maxlen = sizeof(dirty_background_ratio),
977 .proc_handler = &dirty_background_ratio_handler,
978 .strategy = &sysctl_intvec,
980 .extra2 = &one_hundred,
983 .ctl_name = CTL_UNNUMBERED,
984 .procname = "dirty_background_bytes",
985 .data = &dirty_background_bytes,
986 .maxlen = sizeof(dirty_background_bytes),
988 .proc_handler = &dirty_background_bytes_handler,
989 .strategy = &sysctl_intvec,
993 .ctl_name = VM_DIRTY_RATIO,
994 .procname = "dirty_ratio",
995 .data = &vm_dirty_ratio,
996 .maxlen = sizeof(vm_dirty_ratio),
998 .proc_handler = &dirty_ratio_handler,
999 .strategy = &sysctl_intvec,
1001 .extra2 = &one_hundred,
1004 .ctl_name = CTL_UNNUMBERED,
1005 .procname = "dirty_bytes",
1006 .data = &vm_dirty_bytes,
1007 .maxlen = sizeof(vm_dirty_bytes),
1009 .proc_handler = &dirty_bytes_handler,
1010 .strategy = &sysctl_intvec,
1014 .procname = "dirty_writeback_centisecs",
1015 .data = &dirty_writeback_interval,
1016 .maxlen = sizeof(dirty_writeback_interval),
1018 .proc_handler = &dirty_writeback_centisecs_handler,
1021 .procname = "dirty_expire_centisecs",
1022 .data = &dirty_expire_interval,
1023 .maxlen = sizeof(dirty_expire_interval),
1025 .proc_handler = &proc_dointvec_userhz_jiffies,
1028 .ctl_name = VM_NR_PDFLUSH_THREADS,
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 .ctl_name = VM_SWAPPINESS,
1037 .procname = "swappiness",
1038 .data = &vm_swappiness,
1039 .maxlen = sizeof(vm_swappiness),
1041 .proc_handler = &proc_dointvec_minmax,
1042 .strategy = &sysctl_intvec,
1044 .extra2 = &one_hundred,
1046 #ifdef CONFIG_HUGETLB_PAGE
1048 .procname = "nr_hugepages",
1050 .maxlen = sizeof(unsigned long),
1052 .proc_handler = &hugetlb_sysctl_handler,
1053 .extra1 = (void *)&hugetlb_zero,
1054 .extra2 = (void *)&hugetlb_infinity,
1057 .ctl_name = VM_HUGETLB_GROUP,
1058 .procname = "hugetlb_shm_group",
1059 .data = &sysctl_hugetlb_shm_group,
1060 .maxlen = sizeof(gid_t),
1062 .proc_handler = &proc_dointvec,
1065 .ctl_name = CTL_UNNUMBERED,
1066 .procname = "hugepages_treat_as_movable",
1067 .data = &hugepages_treat_as_movable,
1068 .maxlen = sizeof(int),
1070 .proc_handler = &hugetlb_treat_movable_handler,
1073 .ctl_name = CTL_UNNUMBERED,
1074 .procname = "nr_overcommit_hugepages",
1076 .maxlen = sizeof(unsigned long),
1078 .proc_handler = &hugetlb_overcommit_handler,
1079 .extra1 = (void *)&hugetlb_zero,
1080 .extra2 = (void *)&hugetlb_infinity,
1084 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1085 .procname = "lowmem_reserve_ratio",
1086 .data = &sysctl_lowmem_reserve_ratio,
1087 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1089 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1090 .strategy = &sysctl_intvec,
1093 .ctl_name = VM_DROP_PAGECACHE,
1094 .procname = "drop_caches",
1095 .data = &sysctl_drop_caches,
1096 .maxlen = sizeof(int),
1098 .proc_handler = drop_caches_sysctl_handler,
1099 .strategy = &sysctl_intvec,
1102 .ctl_name = VM_MIN_FREE_KBYTES,
1103 .procname = "min_free_kbytes",
1104 .data = &min_free_kbytes,
1105 .maxlen = sizeof(min_free_kbytes),
1107 .proc_handler = &min_free_kbytes_sysctl_handler,
1108 .strategy = &sysctl_intvec,
1112 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1113 .procname = "percpu_pagelist_fraction",
1114 .data = &percpu_pagelist_fraction,
1115 .maxlen = sizeof(percpu_pagelist_fraction),
1117 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1118 .strategy = &sysctl_intvec,
1119 .extra1 = &min_percpu_pagelist_fract,
1123 .ctl_name = VM_MAX_MAP_COUNT,
1124 .procname = "max_map_count",
1125 .data = &sysctl_max_map_count,
1126 .maxlen = sizeof(sysctl_max_map_count),
1128 .proc_handler = &proc_dointvec
1132 .ctl_name = CTL_UNNUMBERED,
1133 .procname = "nr_trim_pages",
1134 .data = &sysctl_nr_trim_pages,
1135 .maxlen = sizeof(sysctl_nr_trim_pages),
1137 .proc_handler = &proc_dointvec_minmax,
1138 .strategy = &sysctl_intvec,
1143 .ctl_name = VM_LAPTOP_MODE,
1144 .procname = "laptop_mode",
1145 .data = &laptop_mode,
1146 .maxlen = sizeof(laptop_mode),
1148 .proc_handler = &proc_dointvec_jiffies,
1149 .strategy = &sysctl_jiffies,
1152 .ctl_name = VM_BLOCK_DUMP,
1153 .procname = "block_dump",
1154 .data = &block_dump,
1155 .maxlen = sizeof(block_dump),
1157 .proc_handler = &proc_dointvec,
1158 .strategy = &sysctl_intvec,
1162 .ctl_name = VM_VFS_CACHE_PRESSURE,
1163 .procname = "vfs_cache_pressure",
1164 .data = &sysctl_vfs_cache_pressure,
1165 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1167 .proc_handler = &proc_dointvec,
1168 .strategy = &sysctl_intvec,
1171 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1173 .ctl_name = VM_LEGACY_VA_LAYOUT,
1174 .procname = "legacy_va_layout",
1175 .data = &sysctl_legacy_va_layout,
1176 .maxlen = sizeof(sysctl_legacy_va_layout),
1178 .proc_handler = &proc_dointvec,
1179 .strategy = &sysctl_intvec,
1185 .ctl_name = VM_ZONE_RECLAIM_MODE,
1186 .procname = "zone_reclaim_mode",
1187 .data = &zone_reclaim_mode,
1188 .maxlen = sizeof(zone_reclaim_mode),
1190 .proc_handler = &proc_dointvec,
1191 .strategy = &sysctl_intvec,
1195 .ctl_name = VM_MIN_UNMAPPED,
1196 .procname = "min_unmapped_ratio",
1197 .data = &sysctl_min_unmapped_ratio,
1198 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1200 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1201 .strategy = &sysctl_intvec,
1203 .extra2 = &one_hundred,
1206 .ctl_name = VM_MIN_SLAB,
1207 .procname = "min_slab_ratio",
1208 .data = &sysctl_min_slab_ratio,
1209 .maxlen = sizeof(sysctl_min_slab_ratio),
1211 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1212 .strategy = &sysctl_intvec,
1214 .extra2 = &one_hundred,
1219 .ctl_name = CTL_UNNUMBERED,
1220 .procname = "stat_interval",
1221 .data = &sysctl_stat_interval,
1222 .maxlen = sizeof(sysctl_stat_interval),
1224 .proc_handler = &proc_dointvec_jiffies,
1225 .strategy = &sysctl_jiffies,
1228 #ifdef CONFIG_SECURITY
1230 .ctl_name = CTL_UNNUMBERED,
1231 .procname = "mmap_min_addr",
1232 .data = &mmap_min_addr,
1233 .maxlen = sizeof(unsigned long),
1235 .proc_handler = &proc_doulongvec_minmax,
1240 .ctl_name = CTL_UNNUMBERED,
1241 .procname = "numa_zonelist_order",
1242 .data = &numa_zonelist_order,
1243 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1245 .proc_handler = &numa_zonelist_order_handler,
1246 .strategy = &sysctl_string,
1249 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1250 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1252 .ctl_name = VM_VDSO_ENABLED,
1253 .procname = "vdso_enabled",
1254 .data = &vdso_enabled,
1255 .maxlen = sizeof(vdso_enabled),
1257 .proc_handler = &proc_dointvec,
1258 .strategy = &sysctl_intvec,
1262 #ifdef CONFIG_HIGHMEM
1264 .ctl_name = CTL_UNNUMBERED,
1265 .procname = "highmem_is_dirtyable",
1266 .data = &vm_highmem_is_dirtyable,
1267 .maxlen = sizeof(vm_highmem_is_dirtyable),
1269 .proc_handler = &proc_dointvec_minmax,
1270 .strategy = &sysctl_intvec,
1276 * NOTE: do not add new entries to this table unless you have read
1277 * Documentation/sysctl/ctl_unnumbered.txt
1282 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1283 static struct ctl_table binfmt_misc_table[] = {
1288 static struct ctl_table fs_table[] = {
1290 .ctl_name = FS_NRINODE,
1291 .procname = "inode-nr",
1292 .data = &inodes_stat,
1293 .maxlen = 2*sizeof(int),
1295 .proc_handler = &proc_dointvec,
1298 .ctl_name = FS_STATINODE,
1299 .procname = "inode-state",
1300 .data = &inodes_stat,
1301 .maxlen = 7*sizeof(int),
1303 .proc_handler = &proc_dointvec,
1306 .procname = "file-nr",
1307 .data = &files_stat,
1308 .maxlen = 3*sizeof(int),
1310 .proc_handler = &proc_nr_files,
1313 .ctl_name = FS_MAXFILE,
1314 .procname = "file-max",
1315 .data = &files_stat.max_files,
1316 .maxlen = sizeof(int),
1318 .proc_handler = &proc_dointvec,
1321 .ctl_name = CTL_UNNUMBERED,
1322 .procname = "nr_open",
1323 .data = &sysctl_nr_open,
1324 .maxlen = sizeof(int),
1326 .proc_handler = &proc_dointvec_minmax,
1327 .extra1 = &sysctl_nr_open_min,
1328 .extra2 = &sysctl_nr_open_max,
1331 .ctl_name = FS_DENTRY,
1332 .procname = "dentry-state",
1333 .data = &dentry_stat,
1334 .maxlen = 6*sizeof(int),
1336 .proc_handler = &proc_dointvec,
1339 .ctl_name = FS_OVERFLOWUID,
1340 .procname = "overflowuid",
1341 .data = &fs_overflowuid,
1342 .maxlen = sizeof(int),
1344 .proc_handler = &proc_dointvec_minmax,
1345 .strategy = &sysctl_intvec,
1346 .extra1 = &minolduid,
1347 .extra2 = &maxolduid,
1350 .ctl_name = FS_OVERFLOWGID,
1351 .procname = "overflowgid",
1352 .data = &fs_overflowgid,
1353 .maxlen = sizeof(int),
1355 .proc_handler = &proc_dointvec_minmax,
1356 .strategy = &sysctl_intvec,
1357 .extra1 = &minolduid,
1358 .extra2 = &maxolduid,
1360 #ifdef CONFIG_FILE_LOCKING
1362 .ctl_name = FS_LEASES,
1363 .procname = "leases-enable",
1364 .data = &leases_enable,
1365 .maxlen = sizeof(int),
1367 .proc_handler = &proc_dointvec,
1370 #ifdef CONFIG_DNOTIFY
1372 .ctl_name = FS_DIR_NOTIFY,
1373 .procname = "dir-notify-enable",
1374 .data = &dir_notify_enable,
1375 .maxlen = sizeof(int),
1377 .proc_handler = &proc_dointvec,
1381 #ifdef CONFIG_FILE_LOCKING
1383 .ctl_name = FS_LEASE_TIME,
1384 .procname = "lease-break-time",
1385 .data = &lease_break_time,
1386 .maxlen = sizeof(int),
1388 .proc_handler = &proc_dointvec_minmax,
1389 .strategy = &sysctl_intvec,
1396 .procname = "aio-nr",
1398 .maxlen = sizeof(aio_nr),
1400 .proc_handler = &proc_doulongvec_minmax,
1403 .procname = "aio-max-nr",
1404 .data = &aio_max_nr,
1405 .maxlen = sizeof(aio_max_nr),
1407 .proc_handler = &proc_doulongvec_minmax,
1409 #endif /* CONFIG_AIO */
1410 #ifdef CONFIG_INOTIFY_USER
1412 .ctl_name = FS_INOTIFY,
1413 .procname = "inotify",
1415 .child = inotify_table,
1420 .procname = "epoll",
1422 .child = epoll_table,
1427 .ctl_name = KERN_SETUID_DUMPABLE,
1428 .procname = "suid_dumpable",
1429 .data = &suid_dumpable,
1430 .maxlen = sizeof(int),
1432 .proc_handler = &proc_dointvec,
1434 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1436 .ctl_name = CTL_UNNUMBERED,
1437 .procname = "binfmt_misc",
1439 .child = binfmt_misc_table,
1443 * NOTE: do not add new entries to this table unless you have read
1444 * Documentation/sysctl/ctl_unnumbered.txt
1449 static struct ctl_table debug_table[] = {
1450 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1452 .ctl_name = CTL_UNNUMBERED,
1453 .procname = "exception-trace",
1454 .data = &show_unhandled_signals,
1455 .maxlen = sizeof(int),
1457 .proc_handler = proc_dointvec
1463 static struct ctl_table dev_table[] = {
1467 static DEFINE_SPINLOCK(sysctl_lock);
1469 /* called under sysctl_lock */
1470 static int use_table(struct ctl_table_header *p)
1472 if (unlikely(p->unregistering))
1478 /* called under sysctl_lock */
1479 static void unuse_table(struct ctl_table_header *p)
1482 if (unlikely(p->unregistering))
1483 complete(p->unregistering);
1486 /* called under sysctl_lock, will reacquire if has to wait */
1487 static void start_unregistering(struct ctl_table_header *p)
1490 * if p->used is 0, nobody will ever touch that entry again;
1491 * we'll eliminate all paths to it before dropping sysctl_lock
1493 if (unlikely(p->used)) {
1494 struct completion wait;
1495 init_completion(&wait);
1496 p->unregistering = &wait;
1497 spin_unlock(&sysctl_lock);
1498 wait_for_completion(&wait);
1499 spin_lock(&sysctl_lock);
1501 /* anything non-NULL; we'll never dereference it */
1502 p->unregistering = ERR_PTR(-EINVAL);
1505 * do not remove from the list until nobody holds it; walking the
1506 * list in do_sysctl() relies on that.
1508 list_del_init(&p->ctl_entry);
1511 void sysctl_head_get(struct ctl_table_header *head)
1513 spin_lock(&sysctl_lock);
1515 spin_unlock(&sysctl_lock);
1518 void sysctl_head_put(struct ctl_table_header *head)
1520 spin_lock(&sysctl_lock);
1523 spin_unlock(&sysctl_lock);
1526 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1530 spin_lock(&sysctl_lock);
1531 if (!use_table(head))
1532 head = ERR_PTR(-ENOENT);
1533 spin_unlock(&sysctl_lock);
1537 void sysctl_head_finish(struct ctl_table_header *head)
1541 spin_lock(&sysctl_lock);
1543 spin_unlock(&sysctl_lock);
1546 static struct ctl_table_set *
1547 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1549 struct ctl_table_set *set = &root->default_set;
1551 set = root->lookup(root, namespaces);
1555 static struct list_head *
1556 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1558 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1562 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1563 struct ctl_table_header *prev)
1565 struct ctl_table_root *root;
1566 struct list_head *header_list;
1567 struct ctl_table_header *head;
1568 struct list_head *tmp;
1570 spin_lock(&sysctl_lock);
1573 tmp = &prev->ctl_entry;
1577 tmp = &root_table_header.ctl_entry;
1579 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1581 if (!use_table(head))
1583 spin_unlock(&sysctl_lock);
1588 header_list = lookup_header_list(root, namespaces);
1589 if (tmp != header_list)
1593 root = list_entry(root->root_list.next,
1594 struct ctl_table_root, root_list);
1595 if (root == &sysctl_table_root)
1597 header_list = lookup_header_list(root, namespaces);
1598 } while (list_empty(header_list));
1599 tmp = header_list->next;
1602 spin_unlock(&sysctl_lock);
1606 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1608 return __sysctl_head_next(current->nsproxy, prev);
1611 void register_sysctl_root(struct ctl_table_root *root)
1613 spin_lock(&sysctl_lock);
1614 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1615 spin_unlock(&sysctl_lock);
1618 #ifdef CONFIG_SYSCTL_SYSCALL
1619 /* Perform the actual read/write of a sysctl table entry. */
1620 static int do_sysctl_strategy(struct ctl_table_root *root,
1621 struct ctl_table *table,
1622 void __user *oldval, size_t __user *oldlenp,
1623 void __user *newval, size_t newlen)
1631 if (sysctl_perm(root, table, op))
1634 if (table->strategy) {
1635 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1642 /* If there is no strategy routine, or if the strategy returns
1643 * zero, proceed with automatic r/w */
1644 if (table->data && table->maxlen) {
1645 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1652 static int parse_table(int __user *name, int nlen,
1653 void __user *oldval, size_t __user *oldlenp,
1654 void __user *newval, size_t newlen,
1655 struct ctl_table_root *root,
1656 struct ctl_table *table)
1662 if (get_user(n, name))
1664 for ( ; table->ctl_name || table->procname; table++) {
1665 if (!table->ctl_name)
1667 if (n == table->ctl_name) {
1670 if (sysctl_perm(root, table, MAY_EXEC))
1674 table = table->child;
1677 error = do_sysctl_strategy(root, table,
1686 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1687 void __user *newval, size_t newlen)
1689 struct ctl_table_header *head;
1690 int error = -ENOTDIR;
1692 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1696 if (!oldlenp || get_user(old_len, oldlenp))
1700 for (head = sysctl_head_next(NULL); head;
1701 head = sysctl_head_next(head)) {
1702 error = parse_table(name, nlen, oldval, oldlenp,
1704 head->root, head->ctl_table);
1705 if (error != -ENOTDIR) {
1706 sysctl_head_finish(head);
1713 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1715 struct __sysctl_args tmp;
1718 if (copy_from_user(&tmp, args, sizeof(tmp)))
1721 error = deprecated_sysctl_warning(&tmp);
1726 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1727 tmp.newval, tmp.newlen);
1732 #endif /* CONFIG_SYSCTL_SYSCALL */
1735 * sysctl_perm does NOT grant the superuser all rights automatically, because
1736 * some sysctl variables are readonly even to root.
1739 static int test_perm(int mode, int op)
1741 if (!current_euid())
1743 else if (in_egroup_p(0))
1745 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1750 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1755 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1759 if (root->permissions)
1760 mode = root->permissions(root, current->nsproxy, table);
1764 return test_perm(mode, op);
1767 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1769 for (; table->ctl_name || table->procname; table++) {
1770 table->parent = parent;
1772 sysctl_set_parent(table, table->child);
1776 static __init int sysctl_init(void)
1778 sysctl_set_parent(NULL, root_table);
1779 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1782 err = sysctl_check_table(current->nsproxy, root_table);
1788 core_initcall(sysctl_init);
1790 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1791 struct ctl_table *table)
1793 struct ctl_table *p;
1794 const char *s = branch->procname;
1796 /* branch should have named subdirectory as its first element */
1797 if (!s || !branch->child)
1800 /* ... and nothing else */
1801 if (branch[1].procname || branch[1].ctl_name)
1804 /* table should contain subdirectory with the same name */
1805 for (p = table; p->procname || p->ctl_name; p++) {
1808 if (p->procname && strcmp(p->procname, s) == 0)
1814 /* see if attaching q to p would be an improvement */
1815 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1817 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1818 struct ctl_table *next;
1820 int not_in_parent = !p->attached_by;
1822 while ((next = is_branch_in(by, to)) != NULL) {
1823 if (by == q->attached_by)
1825 if (to == p->attached_by)
1831 if (is_better && not_in_parent) {
1832 q->attached_by = by;
1833 q->attached_to = to;
1839 * __register_sysctl_paths - register a sysctl hierarchy
1840 * @root: List of sysctl headers to register on
1841 * @namespaces: Data to compute which lists of sysctl entries are visible
1842 * @path: The path to the directory the sysctl table is in.
1843 * @table: the top-level table structure
1845 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1846 * array. A completely 0 filled entry terminates the table.
1848 * The members of the &struct ctl_table structure are used as follows:
1850 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1851 * must be unique within that level of sysctl
1853 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1854 * enter a sysctl file
1856 * data - a pointer to data for use by proc_handler
1858 * maxlen - the maximum size in bytes of the data
1860 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1862 * child - a pointer to the child sysctl table if this entry is a directory, or
1865 * proc_handler - the text handler routine (described below)
1867 * strategy - the strategy routine (described below)
1869 * de - for internal use by the sysctl routines
1871 * extra1, extra2 - extra pointers usable by the proc handler routines
1873 * Leaf nodes in the sysctl tree will be represented by a single file
1874 * under /proc; non-leaf nodes will be represented by directories.
1876 * sysctl(2) can automatically manage read and write requests through
1877 * the sysctl table. The data and maxlen fields of the ctl_table
1878 * struct enable minimal validation of the values being written to be
1879 * performed, and the mode field allows minimal authentication.
1881 * More sophisticated management can be enabled by the provision of a
1882 * strategy routine with the table entry. This will be called before
1883 * any automatic read or write of the data is performed.
1885 * The strategy routine may return
1887 * < 0 - Error occurred (error is passed to user process)
1889 * 0 - OK - proceed with automatic read or write.
1891 * > 0 - OK - read or write has been done by the strategy routine, so
1892 * return immediately.
1894 * There must be a proc_handler routine for any terminal nodes
1895 * mirrored under /proc/sys (non-terminals are handled by a built-in
1896 * directory handler). Several default handlers are available to
1897 * cover common cases -
1899 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1900 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1901 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1903 * It is the handler's job to read the input buffer from user memory
1904 * and process it. The handler should return 0 on success.
1906 * This routine returns %NULL on a failure to register, and a pointer
1907 * to the table header on success.
1909 struct ctl_table_header *__register_sysctl_paths(
1910 struct ctl_table_root *root,
1911 struct nsproxy *namespaces,
1912 const struct ctl_path *path, struct ctl_table *table)
1914 struct ctl_table_header *header;
1915 struct ctl_table *new, **prevp;
1916 unsigned int n, npath;
1917 struct ctl_table_set *set;
1919 /* Count the path components */
1920 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1924 * For each path component, allocate a 2-element ctl_table array.
1925 * The first array element will be filled with the sysctl entry
1926 * for this, the second will be the sentinel (ctl_name == 0).
1928 * We allocate everything in one go so that we don't have to
1929 * worry about freeing additional memory in unregister_sysctl_table.
1931 header = kzalloc(sizeof(struct ctl_table_header) +
1932 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1936 new = (struct ctl_table *) (header + 1);
1938 /* Now connect the dots */
1939 prevp = &header->ctl_table;
1940 for (n = 0; n < npath; ++n, ++path) {
1941 /* Copy the procname */
1942 new->procname = path->procname;
1943 new->ctl_name = path->ctl_name;
1947 prevp = &new->child;
1952 header->ctl_table_arg = table;
1954 INIT_LIST_HEAD(&header->ctl_entry);
1956 header->unregistering = NULL;
1957 header->root = root;
1958 sysctl_set_parent(NULL, header->ctl_table);
1960 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1961 if (sysctl_check_table(namespaces, header->ctl_table)) {
1966 spin_lock(&sysctl_lock);
1967 header->set = lookup_header_set(root, namespaces);
1968 header->attached_by = header->ctl_table;
1969 header->attached_to = root_table;
1970 header->parent = &root_table_header;
1971 for (set = header->set; set; set = set->parent) {
1972 struct ctl_table_header *p;
1973 list_for_each_entry(p, &set->list, ctl_entry) {
1974 if (p->unregistering)
1976 try_attach(p, header);
1979 header->parent->count++;
1980 list_add_tail(&header->ctl_entry, &header->set->list);
1981 spin_unlock(&sysctl_lock);
1987 * register_sysctl_table_path - register a sysctl table hierarchy
1988 * @path: The path to the directory the sysctl table is in.
1989 * @table: the top-level table structure
1991 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1992 * array. A completely 0 filled entry terminates the table.
1994 * See __register_sysctl_paths for more details.
1996 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1997 struct ctl_table *table)
1999 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2004 * register_sysctl_table - register a sysctl table hierarchy
2005 * @table: the top-level table structure
2007 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2008 * array. A completely 0 filled entry terminates the table.
2010 * See register_sysctl_paths for more details.
2012 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2014 static const struct ctl_path null_path[] = { {} };
2016 return register_sysctl_paths(null_path, table);
2020 * unregister_sysctl_table - unregister a sysctl table hierarchy
2021 * @header: the header returned from register_sysctl_table
2023 * Unregisters the sysctl table and all children. proc entries may not
2024 * actually be removed until they are no longer used by anyone.
2026 void unregister_sysctl_table(struct ctl_table_header * header)
2033 spin_lock(&sysctl_lock);
2034 start_unregistering(header);
2035 if (!--header->parent->count) {
2037 kfree(header->parent);
2039 if (!--header->count)
2041 spin_unlock(&sysctl_lock);
2044 int sysctl_is_seen(struct ctl_table_header *p)
2046 struct ctl_table_set *set = p->set;
2048 spin_lock(&sysctl_lock);
2049 if (p->unregistering)
2051 else if (!set->is_seen)
2054 res = set->is_seen(set);
2055 spin_unlock(&sysctl_lock);
2059 void setup_sysctl_set(struct ctl_table_set *p,
2060 struct ctl_table_set *parent,
2061 int (*is_seen)(struct ctl_table_set *))
2063 INIT_LIST_HEAD(&p->list);
2064 p->parent = parent ? parent : &sysctl_table_root.default_set;
2065 p->is_seen = is_seen;
2068 #else /* !CONFIG_SYSCTL */
2069 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2074 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2075 struct ctl_table *table)
2080 void unregister_sysctl_table(struct ctl_table_header * table)
2084 void setup_sysctl_set(struct ctl_table_set *p,
2085 struct ctl_table_set *parent,
2086 int (*is_seen)(struct ctl_table_set *))
2090 void sysctl_head_put(struct ctl_table_header *head)
2094 #endif /* CONFIG_SYSCTL */
2100 #ifdef CONFIG_PROC_SYSCTL
2102 static int _proc_do_string(void* data, int maxlen, int write,
2103 struct file *filp, void __user *buffer,
2104 size_t *lenp, loff_t *ppos)
2110 if (!data || !maxlen || !*lenp) {
2118 while (len < *lenp) {
2119 if (get_user(c, p++))
2121 if (c == 0 || c == '\n')
2127 if(copy_from_user(data, buffer, len))
2129 ((char *) data)[len] = 0;
2147 if(copy_to_user(buffer, data, len))
2150 if(put_user('\n', ((char __user *) buffer) + len))
2161 * proc_dostring - read a string sysctl
2162 * @table: the sysctl table
2163 * @write: %TRUE if this is a write to the sysctl file
2164 * @filp: the file structure
2165 * @buffer: the user buffer
2166 * @lenp: the size of the user buffer
2167 * @ppos: file position
2169 * Reads/writes a string from/to the user buffer. If the kernel
2170 * buffer provided is not large enough to hold the string, the
2171 * string is truncated. The copied string is %NULL-terminated.
2172 * If the string is being read by the user process, it is copied
2173 * and a newline '\n' is added. It is truncated if the buffer is
2176 * Returns 0 on success.
2178 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2179 void __user *buffer, size_t *lenp, loff_t *ppos)
2181 return _proc_do_string(table->data, table->maxlen, write, filp,
2182 buffer, lenp, ppos);
2186 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2188 int write, void *data)
2191 *valp = *negp ? -*lvalp : *lvalp;
2196 *lvalp = (unsigned long)-val;
2199 *lvalp = (unsigned long)val;
2205 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2206 int write, struct file *filp, void __user *buffer,
2207 size_t *lenp, loff_t *ppos,
2208 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2209 int write, void *data),
2212 #define TMPBUFLEN 21
2213 int *i, vleft, first=1, neg, val;
2217 char buf[TMPBUFLEN], *p;
2218 char __user *s = buffer;
2220 if (!tbl_data || !table->maxlen || !*lenp ||
2221 (*ppos && !write)) {
2226 i = (int *) tbl_data;
2227 vleft = table->maxlen / sizeof(*i);
2231 conv = do_proc_dointvec_conv;
2233 for (; left && vleft--; i++, first=0) {
2248 if (len > sizeof(buf) - 1)
2249 len = sizeof(buf) - 1;
2250 if (copy_from_user(buf, s, len))
2254 if (*p == '-' && left > 1) {
2258 if (*p < '0' || *p > '9')
2261 lval = simple_strtoul(p, &p, 0);
2264 if ((len < left) && *p && !isspace(*p))
2271 if (conv(&neg, &lval, i, 1, data))
2278 if (conv(&neg, &lval, i, 0, data))
2281 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2285 if(copy_to_user(s, buf, len))
2292 if (!write && !first && left) {
2293 if(put_user('\n', s))
2300 if (get_user(c, s++))
2315 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2316 void __user *buffer, size_t *lenp, loff_t *ppos,
2317 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2318 int write, void *data),
2321 return __do_proc_dointvec(table->data, table, write, filp,
2322 buffer, lenp, ppos, conv, data);
2326 * proc_dointvec - read a vector of integers
2327 * @table: the sysctl table
2328 * @write: %TRUE if this is a write to the sysctl file
2329 * @filp: the file structure
2330 * @buffer: the user buffer
2331 * @lenp: the size of the user buffer
2332 * @ppos: file position
2334 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2335 * values from/to the user buffer, treated as an ASCII string.
2337 * Returns 0 on success.
2339 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2340 void __user *buffer, size_t *lenp, loff_t *ppos)
2342 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2347 * Taint values can only be increased
2348 * This means we can safely use a temporary.
2350 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2351 void __user *buffer, size_t *lenp, loff_t *ppos)
2354 unsigned long tmptaint = get_taint();
2357 if (write && !capable(CAP_SYS_ADMIN))
2362 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2368 * Poor man's atomic or. Not worth adding a primitive
2369 * to everyone's atomic.h for this
2372 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2373 if ((tmptaint >> i) & 1)
2381 struct do_proc_dointvec_minmax_conv_param {
2386 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2388 int write, void *data)
2390 struct do_proc_dointvec_minmax_conv_param *param = data;
2392 int val = *negp ? -*lvalp : *lvalp;
2393 if ((param->min && *param->min > val) ||
2394 (param->max && *param->max < val))
2401 *lvalp = (unsigned long)-val;
2404 *lvalp = (unsigned long)val;
2411 * proc_dointvec_minmax - read a vector of integers with min/max values
2412 * @table: the sysctl table
2413 * @write: %TRUE if this is a write to the sysctl file
2414 * @filp: the file structure
2415 * @buffer: the user buffer
2416 * @lenp: the size of the user buffer
2417 * @ppos: file position
2419 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2420 * values from/to the user buffer, treated as an ASCII string.
2422 * This routine will ensure the values are within the range specified by
2423 * table->extra1 (min) and table->extra2 (max).
2425 * Returns 0 on success.
2427 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2428 void __user *buffer, size_t *lenp, loff_t *ppos)
2430 struct do_proc_dointvec_minmax_conv_param param = {
2431 .min = (int *) table->extra1,
2432 .max = (int *) table->extra2,
2434 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2435 do_proc_dointvec_minmax_conv, ¶m);
2438 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2440 void __user *buffer,
2441 size_t *lenp, loff_t *ppos,
2442 unsigned long convmul,
2443 unsigned long convdiv)
2445 #define TMPBUFLEN 21
2446 unsigned long *i, *min, *max, val;
2447 int vleft, first=1, neg;
2449 char buf[TMPBUFLEN], *p;
2450 char __user *s = buffer;
2452 if (!data || !table->maxlen || !*lenp ||
2453 (*ppos && !write)) {
2458 i = (unsigned long *) data;
2459 min = (unsigned long *) table->extra1;
2460 max = (unsigned long *) table->extra2;
2461 vleft = table->maxlen / sizeof(unsigned long);
2464 for (; left && vleft--; i++, min++, max++, first=0) {
2479 if (len > TMPBUFLEN-1)
2481 if (copy_from_user(buf, s, len))
2485 if (*p == '-' && left > 1) {
2489 if (*p < '0' || *p > '9')
2491 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2493 if ((len < left) && *p && !isspace(*p))
2502 if ((min && val < *min) || (max && val > *max))
2509 sprintf(p, "%lu", convdiv * (*i) / convmul);
2513 if(copy_to_user(s, buf, len))
2520 if (!write && !first && left) {
2521 if(put_user('\n', s))
2528 if (get_user(c, s++))
2543 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2545 void __user *buffer,
2546 size_t *lenp, loff_t *ppos,
2547 unsigned long convmul,
2548 unsigned long convdiv)
2550 return __do_proc_doulongvec_minmax(table->data, table, write,
2551 filp, buffer, lenp, ppos, convmul, convdiv);
2555 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2556 * @table: the sysctl table
2557 * @write: %TRUE if this is a write to the sysctl file
2558 * @filp: the file structure
2559 * @buffer: the user buffer
2560 * @lenp: the size of the user buffer
2561 * @ppos: file position
2563 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2564 * values from/to the user buffer, treated as an ASCII string.
2566 * This routine will ensure the values are within the range specified by
2567 * table->extra1 (min) and table->extra2 (max).
2569 * Returns 0 on success.
2571 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2572 void __user *buffer, size_t *lenp, loff_t *ppos)
2574 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2578 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2579 * @table: the sysctl table
2580 * @write: %TRUE if this is a write to the sysctl file
2581 * @filp: the file structure
2582 * @buffer: the user buffer
2583 * @lenp: the size of the user buffer
2584 * @ppos: file position
2586 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2587 * values from/to the user buffer, treated as an ASCII string. The values
2588 * are treated as milliseconds, and converted to jiffies when they are stored.
2590 * This routine will ensure the values are within the range specified by
2591 * table->extra1 (min) and table->extra2 (max).
2593 * Returns 0 on success.
2595 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2597 void __user *buffer,
2598 size_t *lenp, loff_t *ppos)
2600 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2601 lenp, ppos, HZ, 1000l);
2605 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2607 int write, void *data)
2610 if (*lvalp > LONG_MAX / HZ)
2612 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2618 lval = (unsigned long)-val;
2621 lval = (unsigned long)val;
2628 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2630 int write, void *data)
2633 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2635 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2641 lval = (unsigned long)-val;
2644 lval = (unsigned long)val;
2646 *lvalp = jiffies_to_clock_t(lval);
2651 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2653 int write, void *data)
2656 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2662 lval = (unsigned long)-val;
2665 lval = (unsigned long)val;
2667 *lvalp = jiffies_to_msecs(lval);
2673 * proc_dointvec_jiffies - read a vector of integers as seconds
2674 * @table: the sysctl table
2675 * @write: %TRUE if this is a write to the sysctl file
2676 * @filp: the file structure
2677 * @buffer: the user buffer
2678 * @lenp: the size of the user buffer
2679 * @ppos: file position
2681 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2682 * values from/to the user buffer, treated as an ASCII string.
2683 * The values read are assumed to be in seconds, and are converted into
2686 * Returns 0 on success.
2688 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2689 void __user *buffer, size_t *lenp, loff_t *ppos)
2691 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2692 do_proc_dointvec_jiffies_conv,NULL);
2696 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2697 * @table: the sysctl table
2698 * @write: %TRUE if this is a write to the sysctl file
2699 * @filp: the file structure
2700 * @buffer: the user buffer
2701 * @lenp: the size of the user buffer
2702 * @ppos: pointer to the file position
2704 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2705 * values from/to the user buffer, treated as an ASCII string.
2706 * The values read are assumed to be in 1/USER_HZ seconds, and
2707 * are converted into jiffies.
2709 * Returns 0 on success.
2711 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2712 void __user *buffer, size_t *lenp, loff_t *ppos)
2714 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2715 do_proc_dointvec_userhz_jiffies_conv,NULL);
2719 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2720 * @table: the sysctl table
2721 * @write: %TRUE if this is a write to the sysctl file
2722 * @filp: the file structure
2723 * @buffer: the user buffer
2724 * @lenp: the size of the user buffer
2725 * @ppos: file position
2726 * @ppos: the current position in the file
2728 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2729 * values from/to the user buffer, treated as an ASCII string.
2730 * The values read are assumed to be in 1/1000 seconds, and
2731 * are converted into jiffies.
2733 * Returns 0 on success.
2735 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2736 void __user *buffer, size_t *lenp, loff_t *ppos)
2738 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2739 do_proc_dointvec_ms_jiffies_conv, NULL);
2742 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2743 void __user *buffer, size_t *lenp, loff_t *ppos)
2745 struct pid *new_pid;
2749 tmp = pid_vnr(cad_pid);
2751 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2752 lenp, ppos, NULL, NULL);
2756 new_pid = find_get_pid(tmp);
2760 put_pid(xchg(&cad_pid, new_pid));
2764 #else /* CONFIG_PROC_FS */
2766 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2767 void __user *buffer, size_t *lenp, loff_t *ppos)
2772 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2773 void __user *buffer, size_t *lenp, loff_t *ppos)
2778 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2779 void __user *buffer, size_t *lenp, loff_t *ppos)
2784 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2785 void __user *buffer, size_t *lenp, loff_t *ppos)
2790 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2791 void __user *buffer, size_t *lenp, loff_t *ppos)
2796 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2797 void __user *buffer, size_t *lenp, loff_t *ppos)
2802 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2803 void __user *buffer, size_t *lenp, loff_t *ppos)
2808 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2810 void __user *buffer,
2811 size_t *lenp, loff_t *ppos)
2817 #endif /* CONFIG_PROC_FS */
2820 #ifdef CONFIG_SYSCTL_SYSCALL
2822 * General sysctl support routines
2825 /* The generic sysctl data routine (used if no strategy routine supplied) */
2826 int sysctl_data(struct ctl_table *table,
2827 void __user *oldval, size_t __user *oldlenp,
2828 void __user *newval, size_t newlen)
2832 /* Get out of I don't have a variable */
2833 if (!table->data || !table->maxlen)
2836 if (oldval && oldlenp) {
2837 if (get_user(len, oldlenp))
2840 if (len > table->maxlen)
2841 len = table->maxlen;
2842 if (copy_to_user(oldval, table->data, len))
2844 if (put_user(len, oldlenp))
2849 if (newval && newlen) {
2850 if (newlen > table->maxlen)
2851 newlen = table->maxlen;
2853 if (copy_from_user(table->data, newval, newlen))
2859 /* The generic string strategy routine: */
2860 int sysctl_string(struct ctl_table *table,
2861 void __user *oldval, size_t __user *oldlenp,
2862 void __user *newval, size_t newlen)
2864 if (!table->data || !table->maxlen)
2867 if (oldval && oldlenp) {
2869 if (get_user(bufsize, oldlenp))
2872 size_t len = strlen(table->data), copied;
2874 /* This shouldn't trigger for a well-formed sysctl */
2875 if (len > table->maxlen)
2876 len = table->maxlen;
2878 /* Copy up to a max of bufsize-1 bytes of the string */
2879 copied = (len >= bufsize) ? bufsize - 1 : len;
2881 if (copy_to_user(oldval, table->data, copied) ||
2882 put_user(0, (char __user *)(oldval + copied)))
2884 if (put_user(len, oldlenp))
2888 if (newval && newlen) {
2889 size_t len = newlen;
2890 if (len > table->maxlen)
2891 len = table->maxlen;
2892 if(copy_from_user(table->data, newval, len))
2894 if (len == table->maxlen)
2896 ((char *) table->data)[len] = 0;
2902 * This function makes sure that all of the integers in the vector
2903 * are between the minimum and maximum values given in the arrays
2904 * table->extra1 and table->extra2, respectively.
2906 int sysctl_intvec(struct ctl_table *table,
2907 void __user *oldval, size_t __user *oldlenp,
2908 void __user *newval, size_t newlen)
2911 if (newval && newlen) {
2912 int __user *vec = (int __user *) newval;
2913 int *min = (int *) table->extra1;
2914 int *max = (int *) table->extra2;
2918 if (newlen % sizeof(int) != 0)
2921 if (!table->extra1 && !table->extra2)
2924 if (newlen > table->maxlen)
2925 newlen = table->maxlen;
2926 length = newlen / sizeof(int);
2928 for (i = 0; i < length; i++) {
2930 if (get_user(value, vec + i))
2932 if (min && value < min[i])
2934 if (max && value > max[i])
2941 /* Strategy function to convert jiffies to seconds */
2942 int sysctl_jiffies(struct ctl_table *table,
2943 void __user *oldval, size_t __user *oldlenp,
2944 void __user *newval, size_t newlen)
2946 if (oldval && oldlenp) {
2949 if (get_user(olen, oldlenp))
2954 if (olen < sizeof(int))
2957 val = *(int *)(table->data) / HZ;
2958 if (put_user(val, (int __user *)oldval))
2960 if (put_user(sizeof(int), oldlenp))
2964 if (newval && newlen) {
2966 if (newlen != sizeof(int))
2968 if (get_user(new, (int __user *)newval))
2970 *(int *)(table->data) = new*HZ;
2975 /* Strategy function to convert jiffies to seconds */
2976 int sysctl_ms_jiffies(struct ctl_table *table,
2977 void __user *oldval, size_t __user *oldlenp,
2978 void __user *newval, size_t newlen)
2980 if (oldval && oldlenp) {
2983 if (get_user(olen, oldlenp))
2988 if (olen < sizeof(int))
2991 val = jiffies_to_msecs(*(int *)(table->data));
2992 if (put_user(val, (int __user *)oldval))
2994 if (put_user(sizeof(int), oldlenp))
2998 if (newval && newlen) {
3000 if (newlen != sizeof(int))
3002 if (get_user(new, (int __user *)newval))
3004 *(int *)(table->data) = msecs_to_jiffies(new);
3011 #else /* CONFIG_SYSCTL_SYSCALL */
3014 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3016 struct __sysctl_args tmp;
3019 if (copy_from_user(&tmp, args, sizeof(tmp)))
3022 error = deprecated_sysctl_warning(&tmp);
3024 /* If no error reading the parameters then just -ENOSYS ... */
3031 int sysctl_data(struct ctl_table *table,
3032 void __user *oldval, size_t __user *oldlenp,
3033 void __user *newval, size_t newlen)
3038 int sysctl_string(struct ctl_table *table,
3039 void __user *oldval, size_t __user *oldlenp,
3040 void __user *newval, size_t newlen)
3045 int sysctl_intvec(struct ctl_table *table,
3046 void __user *oldval, size_t __user *oldlenp,
3047 void __user *newval, size_t newlen)
3052 int sysctl_jiffies(struct ctl_table *table,
3053 void __user *oldval, size_t __user *oldlenp,
3054 void __user *newval, size_t newlen)
3059 int sysctl_ms_jiffies(struct ctl_table *table,
3060 void __user *oldval, size_t __user *oldlenp,
3061 void __user *newval, size_t newlen)
3066 #endif /* CONFIG_SYSCTL_SYSCALL */
3068 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3070 static int msg_count;
3071 int name[CTL_MAXNAME];
3074 /* Check args->nlen. */
3075 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3078 /* Read in the sysctl name for better debug message logging */
3079 for (i = 0; i < args->nlen; i++)
3080 if (get_user(name[i], args->name + i))
3083 /* Ignore accesses to kernel.version */
3084 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3087 if (msg_count < 5) {
3090 "warning: process `%s' used the deprecated sysctl "
3091 "system call with ", current->comm);
3092 for (i = 0; i < args->nlen; i++)
3093 printk("%d.", name[i]);
3100 * No sense putting this after each symbol definition, twice,
3101 * exception granted :-)
3103 EXPORT_SYMBOL(proc_dointvec);
3104 EXPORT_SYMBOL(proc_dointvec_jiffies);
3105 EXPORT_SYMBOL(proc_dointvec_minmax);
3106 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3107 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3108 EXPORT_SYMBOL(proc_dostring);
3109 EXPORT_SYMBOL(proc_doulongvec_minmax);
3110 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3111 EXPORT_SYMBOL(register_sysctl_table);
3112 EXPORT_SYMBOL(register_sysctl_paths);
3113 EXPORT_SYMBOL(sysctl_intvec);
3114 EXPORT_SYMBOL(sysctl_jiffies);
3115 EXPORT_SYMBOL(sysctl_ms_jiffies);
3116 EXPORT_SYMBOL(sysctl_string);
3117 EXPORT_SYMBOL(sysctl_data);
3118 EXPORT_SYMBOL(unregister_sysctl_table);