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;
85 #ifdef CONFIG_RCU_TORTURE_TEST
86 extern int rcutorture_runnable;
87 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
89 /* Constants used for minimum and maximum */
90 #ifdef CONFIG_DETECT_SOFTLOCKUP
91 static int sixty = 60;
92 static int neg_one = -1;
95 #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
101 static int one_hundred = 100;
103 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
104 static int maxolduid = 65535;
105 static int minolduid;
106 static int min_percpu_pagelist_fract = 8;
108 static int ngroups_max = NGROUPS_MAX;
110 #ifdef CONFIG_MODULES
111 extern char modprobe_path[];
113 #ifdef CONFIG_CHR_DEV_SG
114 extern int sg_big_buff;
118 #include <asm/system.h>
121 #ifdef CONFIG_SPARC64
122 extern int sysctl_tsb_ratio;
126 extern int pwrsw_enabled;
127 extern int unaligned_enabled;
131 #ifdef CONFIG_MATHEMU
132 extern int sysctl_ieee_emulation_warnings;
134 extern int sysctl_userprocess_debug;
135 extern int spin_retry;
138 #ifdef CONFIG_BSD_PROCESS_ACCT
139 extern int acct_parm[];
143 extern int no_unaligned_warning;
146 #ifdef CONFIG_RT_MUTEXES
147 extern int max_lock_depth;
150 #ifdef CONFIG_PROC_SYSCTL
151 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
152 void __user *buffer, size_t *lenp, loff_t *ppos);
153 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
154 void __user *buffer, size_t *lenp, loff_t *ppos);
157 static struct ctl_table root_table[];
158 static struct ctl_table_root sysctl_table_root;
159 static struct ctl_table_header root_table_header = {
161 .ctl_table = root_table,
162 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
163 .root = &sysctl_table_root,
164 .set = &sysctl_table_root.default_set,
166 static struct ctl_table_root sysctl_table_root = {
167 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
168 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
171 static struct ctl_table kern_table[];
172 static struct ctl_table vm_table[];
173 static struct ctl_table fs_table[];
174 static struct ctl_table debug_table[];
175 static struct ctl_table dev_table[];
176 extern struct ctl_table random_table[];
177 #ifdef CONFIG_INOTIFY_USER
178 extern struct ctl_table inotify_table[];
181 extern struct ctl_table epoll_table[];
184 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
185 int sysctl_legacy_va_layout;
188 extern int prove_locking;
189 extern int lock_stat;
191 /* The default sysctl tables: */
193 static struct ctl_table root_table[] = {
195 .ctl_name = CTL_KERN,
196 .procname = "kernel",
213 .ctl_name = CTL_DEBUG,
216 .child = debug_table,
225 * NOTE: do not add new entries to this table unless you have read
226 * Documentation/sysctl/ctl_unnumbered.txt
231 #ifdef CONFIG_SCHED_DEBUG
232 static int min_sched_granularity_ns = 100000; /* 100 usecs */
233 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
234 static int min_wakeup_granularity_ns; /* 0 usecs */
235 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
238 static struct ctl_table kern_table[] = {
239 #ifdef CONFIG_SCHED_DEBUG
241 .ctl_name = CTL_UNNUMBERED,
242 .procname = "sched_min_granularity_ns",
243 .data = &sysctl_sched_min_granularity,
244 .maxlen = sizeof(unsigned int),
246 .proc_handler = &sched_nr_latency_handler,
247 .strategy = &sysctl_intvec,
248 .extra1 = &min_sched_granularity_ns,
249 .extra2 = &max_sched_granularity_ns,
252 .ctl_name = CTL_UNNUMBERED,
253 .procname = "sched_latency_ns",
254 .data = &sysctl_sched_latency,
255 .maxlen = sizeof(unsigned int),
257 .proc_handler = &sched_nr_latency_handler,
258 .strategy = &sysctl_intvec,
259 .extra1 = &min_sched_granularity_ns,
260 .extra2 = &max_sched_granularity_ns,
263 .ctl_name = CTL_UNNUMBERED,
264 .procname = "sched_wakeup_granularity_ns",
265 .data = &sysctl_sched_wakeup_granularity,
266 .maxlen = sizeof(unsigned int),
268 .proc_handler = &proc_dointvec_minmax,
269 .strategy = &sysctl_intvec,
270 .extra1 = &min_wakeup_granularity_ns,
271 .extra2 = &max_wakeup_granularity_ns,
274 .ctl_name = CTL_UNNUMBERED,
275 .procname = "sched_shares_ratelimit",
276 .data = &sysctl_sched_shares_ratelimit,
277 .maxlen = sizeof(unsigned int),
279 .proc_handler = &proc_dointvec,
282 .ctl_name = CTL_UNNUMBERED,
283 .procname = "sched_shares_thresh",
284 .data = &sysctl_sched_shares_thresh,
285 .maxlen = sizeof(unsigned int),
287 .proc_handler = &proc_dointvec_minmax,
288 .strategy = &sysctl_intvec,
292 .ctl_name = CTL_UNNUMBERED,
293 .procname = "sched_child_runs_first",
294 .data = &sysctl_sched_child_runs_first,
295 .maxlen = sizeof(unsigned int),
297 .proc_handler = &proc_dointvec,
300 .ctl_name = CTL_UNNUMBERED,
301 .procname = "sched_features",
302 .data = &sysctl_sched_features,
303 .maxlen = sizeof(unsigned int),
305 .proc_handler = &proc_dointvec,
308 .ctl_name = CTL_UNNUMBERED,
309 .procname = "sched_migration_cost",
310 .data = &sysctl_sched_migration_cost,
311 .maxlen = sizeof(unsigned int),
313 .proc_handler = &proc_dointvec,
316 .ctl_name = CTL_UNNUMBERED,
317 .procname = "sched_nr_migrate",
318 .data = &sysctl_sched_nr_migrate,
319 .maxlen = sizeof(unsigned int),
321 .proc_handler = &proc_dointvec,
325 .ctl_name = CTL_UNNUMBERED,
326 .procname = "sched_rt_period_us",
327 .data = &sysctl_sched_rt_period,
328 .maxlen = sizeof(unsigned int),
330 .proc_handler = &sched_rt_handler,
333 .ctl_name = CTL_UNNUMBERED,
334 .procname = "sched_rt_runtime_us",
335 .data = &sysctl_sched_rt_runtime,
336 .maxlen = sizeof(int),
338 .proc_handler = &sched_rt_handler,
341 .ctl_name = CTL_UNNUMBERED,
342 .procname = "sched_compat_yield",
343 .data = &sysctl_sched_compat_yield,
344 .maxlen = sizeof(unsigned int),
346 .proc_handler = &proc_dointvec,
348 #ifdef CONFIG_PROVE_LOCKING
350 .ctl_name = CTL_UNNUMBERED,
351 .procname = "prove_locking",
352 .data = &prove_locking,
353 .maxlen = sizeof(int),
355 .proc_handler = &proc_dointvec,
358 #ifdef CONFIG_LOCK_STAT
360 .ctl_name = CTL_UNNUMBERED,
361 .procname = "lock_stat",
363 .maxlen = sizeof(int),
365 .proc_handler = &proc_dointvec,
369 .ctl_name = KERN_PANIC,
371 .data = &panic_timeout,
372 .maxlen = sizeof(int),
374 .proc_handler = &proc_dointvec,
377 .ctl_name = KERN_CORE_USES_PID,
378 .procname = "core_uses_pid",
379 .data = &core_uses_pid,
380 .maxlen = sizeof(int),
382 .proc_handler = &proc_dointvec,
385 .ctl_name = KERN_CORE_PATTERN,
386 .procname = "core_pattern",
387 .data = core_pattern,
388 .maxlen = CORENAME_MAX_SIZE,
390 .proc_handler = &proc_dostring,
391 .strategy = &sysctl_string,
393 #ifdef CONFIG_PROC_SYSCTL
395 .procname = "tainted",
396 .maxlen = sizeof(long),
398 .proc_handler = &proc_taint,
401 #ifdef CONFIG_LATENCYTOP
403 .procname = "latencytop",
404 .data = &latencytop_enabled,
405 .maxlen = sizeof(int),
407 .proc_handler = &proc_dointvec,
410 #ifdef CONFIG_BLK_DEV_INITRD
412 .ctl_name = KERN_REALROOTDEV,
413 .procname = "real-root-dev",
414 .data = &real_root_dev,
415 .maxlen = sizeof(int),
417 .proc_handler = &proc_dointvec,
421 .ctl_name = CTL_UNNUMBERED,
422 .procname = "print-fatal-signals",
423 .data = &print_fatal_signals,
424 .maxlen = sizeof(int),
426 .proc_handler = &proc_dointvec,
430 .ctl_name = KERN_SPARC_REBOOT,
431 .procname = "reboot-cmd",
432 .data = reboot_command,
435 .proc_handler = &proc_dostring,
436 .strategy = &sysctl_string,
439 .ctl_name = KERN_SPARC_STOP_A,
440 .procname = "stop-a",
441 .data = &stop_a_enabled,
442 .maxlen = sizeof (int),
444 .proc_handler = &proc_dointvec,
447 .ctl_name = KERN_SPARC_SCONS_PWROFF,
448 .procname = "scons-poweroff",
449 .data = &scons_pwroff,
450 .maxlen = sizeof (int),
452 .proc_handler = &proc_dointvec,
455 #ifdef CONFIG_SPARC64
457 .ctl_name = CTL_UNNUMBERED,
458 .procname = "tsb-ratio",
459 .data = &sysctl_tsb_ratio,
460 .maxlen = sizeof (int),
462 .proc_handler = &proc_dointvec,
467 .ctl_name = KERN_HPPA_PWRSW,
468 .procname = "soft-power",
469 .data = &pwrsw_enabled,
470 .maxlen = sizeof (int),
472 .proc_handler = &proc_dointvec,
475 .ctl_name = KERN_HPPA_UNALIGNED,
476 .procname = "unaligned-trap",
477 .data = &unaligned_enabled,
478 .maxlen = sizeof (int),
480 .proc_handler = &proc_dointvec,
484 .ctl_name = KERN_CTLALTDEL,
485 .procname = "ctrl-alt-del",
487 .maxlen = sizeof(int),
489 .proc_handler = &proc_dointvec,
491 #ifdef CONFIG_FUNCTION_TRACER
493 .ctl_name = CTL_UNNUMBERED,
494 .procname = "ftrace_enabled",
495 .data = &ftrace_enabled,
496 .maxlen = sizeof(int),
498 .proc_handler = &ftrace_enable_sysctl,
501 #ifdef CONFIG_STACK_TRACER
503 .ctl_name = CTL_UNNUMBERED,
504 .procname = "stack_tracer_enabled",
505 .data = &stack_tracer_enabled,
506 .maxlen = sizeof(int),
508 .proc_handler = &stack_trace_sysctl,
511 #ifdef CONFIG_TRACING
513 .ctl_name = CTL_UNNUMBERED,
514 .procname = "ftrace_dump_on_oops",
515 .data = &ftrace_dump_on_oops,
516 .maxlen = sizeof(int),
518 .proc_handler = &proc_dointvec,
521 #ifdef CONFIG_MODULES
523 .ctl_name = KERN_MODPROBE,
524 .procname = "modprobe",
525 .data = &modprobe_path,
526 .maxlen = KMOD_PATH_LEN,
528 .proc_handler = &proc_dostring,
529 .strategy = &sysctl_string,
532 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
534 .ctl_name = KERN_HOTPLUG,
535 .procname = "hotplug",
536 .data = &uevent_helper,
537 .maxlen = UEVENT_HELPER_PATH_LEN,
539 .proc_handler = &proc_dostring,
540 .strategy = &sysctl_string,
543 #ifdef CONFIG_CHR_DEV_SG
545 .ctl_name = KERN_SG_BIG_BUFF,
546 .procname = "sg-big-buff",
547 .data = &sg_big_buff,
548 .maxlen = sizeof (int),
550 .proc_handler = &proc_dointvec,
553 #ifdef CONFIG_BSD_PROCESS_ACCT
555 .ctl_name = KERN_ACCT,
558 .maxlen = 3*sizeof(int),
560 .proc_handler = &proc_dointvec,
563 #ifdef CONFIG_MAGIC_SYSRQ
565 .ctl_name = KERN_SYSRQ,
567 .data = &__sysrq_enabled,
568 .maxlen = sizeof (int),
570 .proc_handler = &proc_dointvec,
573 #ifdef CONFIG_PROC_SYSCTL
575 .procname = "cad_pid",
577 .maxlen = sizeof (int),
579 .proc_handler = &proc_do_cad_pid,
583 .ctl_name = KERN_MAX_THREADS,
584 .procname = "threads-max",
585 .data = &max_threads,
586 .maxlen = sizeof(int),
588 .proc_handler = &proc_dointvec,
591 .ctl_name = KERN_RANDOM,
592 .procname = "random",
594 .child = random_table,
597 .ctl_name = KERN_OVERFLOWUID,
598 .procname = "overflowuid",
599 .data = &overflowuid,
600 .maxlen = sizeof(int),
602 .proc_handler = &proc_dointvec_minmax,
603 .strategy = &sysctl_intvec,
604 .extra1 = &minolduid,
605 .extra2 = &maxolduid,
608 .ctl_name = KERN_OVERFLOWGID,
609 .procname = "overflowgid",
610 .data = &overflowgid,
611 .maxlen = sizeof(int),
613 .proc_handler = &proc_dointvec_minmax,
614 .strategy = &sysctl_intvec,
615 .extra1 = &minolduid,
616 .extra2 = &maxolduid,
619 #ifdef CONFIG_MATHEMU
621 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
622 .procname = "ieee_emulation_warnings",
623 .data = &sysctl_ieee_emulation_warnings,
624 .maxlen = sizeof(int),
626 .proc_handler = &proc_dointvec,
630 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
631 .procname = "userprocess_debug",
632 .data = &sysctl_userprocess_debug,
633 .maxlen = sizeof(int),
635 .proc_handler = &proc_dointvec,
639 .ctl_name = KERN_PIDMAX,
640 .procname = "pid_max",
642 .maxlen = sizeof (int),
644 .proc_handler = &proc_dointvec_minmax,
645 .strategy = sysctl_intvec,
646 .extra1 = &pid_max_min,
647 .extra2 = &pid_max_max,
650 .ctl_name = KERN_PANIC_ON_OOPS,
651 .procname = "panic_on_oops",
652 .data = &panic_on_oops,
653 .maxlen = sizeof(int),
655 .proc_handler = &proc_dointvec,
657 #if defined CONFIG_PRINTK
659 .ctl_name = KERN_PRINTK,
660 .procname = "printk",
661 .data = &console_loglevel,
662 .maxlen = 4*sizeof(int),
664 .proc_handler = &proc_dointvec,
667 .ctl_name = KERN_PRINTK_RATELIMIT,
668 .procname = "printk_ratelimit",
669 .data = &printk_ratelimit_state.interval,
670 .maxlen = sizeof(int),
672 .proc_handler = &proc_dointvec_jiffies,
673 .strategy = &sysctl_jiffies,
676 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
677 .procname = "printk_ratelimit_burst",
678 .data = &printk_ratelimit_state.burst,
679 .maxlen = sizeof(int),
681 .proc_handler = &proc_dointvec,
685 .ctl_name = KERN_NGROUPS_MAX,
686 .procname = "ngroups_max",
687 .data = &ngroups_max,
688 .maxlen = sizeof (int),
690 .proc_handler = &proc_dointvec,
692 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
694 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
695 .procname = "unknown_nmi_panic",
696 .data = &unknown_nmi_panic,
697 .maxlen = sizeof (int),
699 .proc_handler = &proc_dointvec,
702 .procname = "nmi_watchdog",
703 .data = &nmi_watchdog_enabled,
704 .maxlen = sizeof (int),
706 .proc_handler = &proc_nmi_enabled,
709 #if defined(CONFIG_X86)
711 .ctl_name = KERN_PANIC_ON_NMI,
712 .procname = "panic_on_unrecovered_nmi",
713 .data = &panic_on_unrecovered_nmi,
714 .maxlen = sizeof(int),
716 .proc_handler = &proc_dointvec,
719 .ctl_name = KERN_BOOTLOADER_TYPE,
720 .procname = "bootloader_type",
721 .data = &bootloader_type,
722 .maxlen = sizeof (int),
724 .proc_handler = &proc_dointvec,
727 .ctl_name = CTL_UNNUMBERED,
728 .procname = "kstack_depth_to_print",
729 .data = &kstack_depth_to_print,
730 .maxlen = sizeof(int),
732 .proc_handler = &proc_dointvec,
735 .ctl_name = CTL_UNNUMBERED,
736 .procname = "io_delay_type",
737 .data = &io_delay_type,
738 .maxlen = sizeof(int),
740 .proc_handler = &proc_dointvec,
743 #if defined(CONFIG_MMU)
745 .ctl_name = KERN_RANDOMIZE,
746 .procname = "randomize_va_space",
747 .data = &randomize_va_space,
748 .maxlen = sizeof(int),
750 .proc_handler = &proc_dointvec,
753 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
755 .ctl_name = KERN_SPIN_RETRY,
756 .procname = "spin_retry",
758 .maxlen = sizeof (int),
760 .proc_handler = &proc_dointvec,
763 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
765 .procname = "acpi_video_flags",
766 .data = &acpi_realmode_flags,
767 .maxlen = sizeof (unsigned long),
769 .proc_handler = &proc_doulongvec_minmax,
774 .ctl_name = KERN_IA64_UNALIGNED,
775 .procname = "ignore-unaligned-usertrap",
776 .data = &no_unaligned_warning,
777 .maxlen = sizeof (int),
779 .proc_handler = &proc_dointvec,
782 #ifdef CONFIG_DETECT_SOFTLOCKUP
784 .ctl_name = CTL_UNNUMBERED,
785 .procname = "softlockup_panic",
786 .data = &softlockup_panic,
787 .maxlen = sizeof(int),
789 .proc_handler = &proc_dointvec_minmax,
790 .strategy = &sysctl_intvec,
795 .ctl_name = CTL_UNNUMBERED,
796 .procname = "softlockup_thresh",
797 .data = &softlockup_thresh,
798 .maxlen = sizeof(int),
800 .proc_handler = &proc_dointvec_minmax,
801 .strategy = &sysctl_intvec,
806 .ctl_name = CTL_UNNUMBERED,
807 .procname = "hung_task_check_count",
808 .data = &sysctl_hung_task_check_count,
809 .maxlen = sizeof(unsigned long),
811 .proc_handler = &proc_doulongvec_minmax,
812 .strategy = &sysctl_intvec,
815 .ctl_name = CTL_UNNUMBERED,
816 .procname = "hung_task_timeout_secs",
817 .data = &sysctl_hung_task_timeout_secs,
818 .maxlen = sizeof(unsigned long),
820 .proc_handler = &proc_doulongvec_minmax,
821 .strategy = &sysctl_intvec,
824 .ctl_name = CTL_UNNUMBERED,
825 .procname = "hung_task_warnings",
826 .data = &sysctl_hung_task_warnings,
827 .maxlen = sizeof(unsigned long),
829 .proc_handler = &proc_doulongvec_minmax,
830 .strategy = &sysctl_intvec,
835 .ctl_name = KERN_COMPAT_LOG,
836 .procname = "compat-log",
838 .maxlen = sizeof (int),
840 .proc_handler = &proc_dointvec,
843 #ifdef CONFIG_RT_MUTEXES
845 .ctl_name = KERN_MAX_LOCK_DEPTH,
846 .procname = "max_lock_depth",
847 .data = &max_lock_depth,
848 .maxlen = sizeof(int),
850 .proc_handler = &proc_dointvec,
854 .ctl_name = CTL_UNNUMBERED,
855 .procname = "poweroff_cmd",
856 .data = &poweroff_cmd,
857 .maxlen = POWEROFF_CMD_PATH_LEN,
859 .proc_handler = &proc_dostring,
860 .strategy = &sysctl_string,
864 .ctl_name = CTL_UNNUMBERED,
867 .child = key_sysctls,
870 #ifdef CONFIG_RCU_TORTURE_TEST
872 .ctl_name = CTL_UNNUMBERED,
873 .procname = "rcutorture_runnable",
874 .data = &rcutorture_runnable,
875 .maxlen = sizeof(int),
877 .proc_handler = &proc_dointvec,
880 #ifdef CONFIG_UNEVICTABLE_LRU
882 .ctl_name = CTL_UNNUMBERED,
883 .procname = "scan_unevictable_pages",
884 .data = &scan_unevictable_pages,
885 .maxlen = sizeof(scan_unevictable_pages),
887 .proc_handler = &scan_unevictable_handler,
891 * NOTE: do not add new entries to this table unless you have read
892 * Documentation/sysctl/ctl_unnumbered.txt
897 static struct ctl_table vm_table[] = {
899 .ctl_name = VM_OVERCOMMIT_MEMORY,
900 .procname = "overcommit_memory",
901 .data = &sysctl_overcommit_memory,
902 .maxlen = sizeof(sysctl_overcommit_memory),
904 .proc_handler = &proc_dointvec,
907 .ctl_name = VM_PANIC_ON_OOM,
908 .procname = "panic_on_oom",
909 .data = &sysctl_panic_on_oom,
910 .maxlen = sizeof(sysctl_panic_on_oom),
912 .proc_handler = &proc_dointvec,
915 .ctl_name = CTL_UNNUMBERED,
916 .procname = "oom_kill_allocating_task",
917 .data = &sysctl_oom_kill_allocating_task,
918 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
920 .proc_handler = &proc_dointvec,
923 .ctl_name = CTL_UNNUMBERED,
924 .procname = "oom_dump_tasks",
925 .data = &sysctl_oom_dump_tasks,
926 .maxlen = sizeof(sysctl_oom_dump_tasks),
928 .proc_handler = &proc_dointvec,
931 .ctl_name = VM_OVERCOMMIT_RATIO,
932 .procname = "overcommit_ratio",
933 .data = &sysctl_overcommit_ratio,
934 .maxlen = sizeof(sysctl_overcommit_ratio),
936 .proc_handler = &proc_dointvec,
939 .ctl_name = VM_PAGE_CLUSTER,
940 .procname = "page-cluster",
941 .data = &page_cluster,
942 .maxlen = sizeof(int),
944 .proc_handler = &proc_dointvec,
947 .ctl_name = VM_DIRTY_BACKGROUND,
948 .procname = "dirty_background_ratio",
949 .data = &dirty_background_ratio,
950 .maxlen = sizeof(dirty_background_ratio),
952 .proc_handler = &dirty_background_ratio_handler,
953 .strategy = &sysctl_intvec,
955 .extra2 = &one_hundred,
958 .ctl_name = CTL_UNNUMBERED,
959 .procname = "dirty_background_bytes",
960 .data = &dirty_background_bytes,
961 .maxlen = sizeof(dirty_background_bytes),
963 .proc_handler = &dirty_background_bytes_handler,
964 .strategy = &sysctl_intvec,
968 .ctl_name = VM_DIRTY_RATIO,
969 .procname = "dirty_ratio",
970 .data = &vm_dirty_ratio,
971 .maxlen = sizeof(vm_dirty_ratio),
973 .proc_handler = &dirty_ratio_handler,
974 .strategy = &sysctl_intvec,
976 .extra2 = &one_hundred,
979 .ctl_name = CTL_UNNUMBERED,
980 .procname = "dirty_bytes",
981 .data = &vm_dirty_bytes,
982 .maxlen = sizeof(vm_dirty_bytes),
984 .proc_handler = &dirty_bytes_handler,
985 .strategy = &sysctl_intvec,
989 .procname = "dirty_writeback_centisecs",
990 .data = &dirty_writeback_interval,
991 .maxlen = sizeof(dirty_writeback_interval),
993 .proc_handler = &dirty_writeback_centisecs_handler,
996 .procname = "dirty_expire_centisecs",
997 .data = &dirty_expire_interval,
998 .maxlen = sizeof(dirty_expire_interval),
1000 .proc_handler = &proc_dointvec_userhz_jiffies,
1003 .ctl_name = VM_NR_PDFLUSH_THREADS,
1004 .procname = "nr_pdflush_threads",
1005 .data = &nr_pdflush_threads,
1006 .maxlen = sizeof nr_pdflush_threads,
1007 .mode = 0444 /* read-only*/,
1008 .proc_handler = &proc_dointvec,
1011 .ctl_name = VM_SWAPPINESS,
1012 .procname = "swappiness",
1013 .data = &vm_swappiness,
1014 .maxlen = sizeof(vm_swappiness),
1016 .proc_handler = &proc_dointvec_minmax,
1017 .strategy = &sysctl_intvec,
1019 .extra2 = &one_hundred,
1021 #ifdef CONFIG_HUGETLB_PAGE
1023 .procname = "nr_hugepages",
1025 .maxlen = sizeof(unsigned long),
1027 .proc_handler = &hugetlb_sysctl_handler,
1028 .extra1 = (void *)&hugetlb_zero,
1029 .extra2 = (void *)&hugetlb_infinity,
1032 .ctl_name = VM_HUGETLB_GROUP,
1033 .procname = "hugetlb_shm_group",
1034 .data = &sysctl_hugetlb_shm_group,
1035 .maxlen = sizeof(gid_t),
1037 .proc_handler = &proc_dointvec,
1040 .ctl_name = CTL_UNNUMBERED,
1041 .procname = "hugepages_treat_as_movable",
1042 .data = &hugepages_treat_as_movable,
1043 .maxlen = sizeof(int),
1045 .proc_handler = &hugetlb_treat_movable_handler,
1048 .ctl_name = CTL_UNNUMBERED,
1049 .procname = "nr_overcommit_hugepages",
1051 .maxlen = sizeof(unsigned long),
1053 .proc_handler = &hugetlb_overcommit_handler,
1054 .extra1 = (void *)&hugetlb_zero,
1055 .extra2 = (void *)&hugetlb_infinity,
1059 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1060 .procname = "lowmem_reserve_ratio",
1061 .data = &sysctl_lowmem_reserve_ratio,
1062 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1064 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1065 .strategy = &sysctl_intvec,
1068 .ctl_name = VM_DROP_PAGECACHE,
1069 .procname = "drop_caches",
1070 .data = &sysctl_drop_caches,
1071 .maxlen = sizeof(int),
1073 .proc_handler = drop_caches_sysctl_handler,
1074 .strategy = &sysctl_intvec,
1077 .ctl_name = VM_MIN_FREE_KBYTES,
1078 .procname = "min_free_kbytes",
1079 .data = &min_free_kbytes,
1080 .maxlen = sizeof(min_free_kbytes),
1082 .proc_handler = &min_free_kbytes_sysctl_handler,
1083 .strategy = &sysctl_intvec,
1087 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1088 .procname = "percpu_pagelist_fraction",
1089 .data = &percpu_pagelist_fraction,
1090 .maxlen = sizeof(percpu_pagelist_fraction),
1092 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1093 .strategy = &sysctl_intvec,
1094 .extra1 = &min_percpu_pagelist_fract,
1098 .ctl_name = VM_MAX_MAP_COUNT,
1099 .procname = "max_map_count",
1100 .data = &sysctl_max_map_count,
1101 .maxlen = sizeof(sysctl_max_map_count),
1103 .proc_handler = &proc_dointvec
1107 .ctl_name = VM_LAPTOP_MODE,
1108 .procname = "laptop_mode",
1109 .data = &laptop_mode,
1110 .maxlen = sizeof(laptop_mode),
1112 .proc_handler = &proc_dointvec_jiffies,
1113 .strategy = &sysctl_jiffies,
1116 .ctl_name = VM_BLOCK_DUMP,
1117 .procname = "block_dump",
1118 .data = &block_dump,
1119 .maxlen = sizeof(block_dump),
1121 .proc_handler = &proc_dointvec,
1122 .strategy = &sysctl_intvec,
1126 .ctl_name = VM_VFS_CACHE_PRESSURE,
1127 .procname = "vfs_cache_pressure",
1128 .data = &sysctl_vfs_cache_pressure,
1129 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1131 .proc_handler = &proc_dointvec,
1132 .strategy = &sysctl_intvec,
1135 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1137 .ctl_name = VM_LEGACY_VA_LAYOUT,
1138 .procname = "legacy_va_layout",
1139 .data = &sysctl_legacy_va_layout,
1140 .maxlen = sizeof(sysctl_legacy_va_layout),
1142 .proc_handler = &proc_dointvec,
1143 .strategy = &sysctl_intvec,
1149 .ctl_name = VM_ZONE_RECLAIM_MODE,
1150 .procname = "zone_reclaim_mode",
1151 .data = &zone_reclaim_mode,
1152 .maxlen = sizeof(zone_reclaim_mode),
1154 .proc_handler = &proc_dointvec,
1155 .strategy = &sysctl_intvec,
1159 .ctl_name = VM_MIN_UNMAPPED,
1160 .procname = "min_unmapped_ratio",
1161 .data = &sysctl_min_unmapped_ratio,
1162 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1164 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1165 .strategy = &sysctl_intvec,
1167 .extra2 = &one_hundred,
1170 .ctl_name = VM_MIN_SLAB,
1171 .procname = "min_slab_ratio",
1172 .data = &sysctl_min_slab_ratio,
1173 .maxlen = sizeof(sysctl_min_slab_ratio),
1175 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1176 .strategy = &sysctl_intvec,
1178 .extra2 = &one_hundred,
1183 .ctl_name = CTL_UNNUMBERED,
1184 .procname = "stat_interval",
1185 .data = &sysctl_stat_interval,
1186 .maxlen = sizeof(sysctl_stat_interval),
1188 .proc_handler = &proc_dointvec_jiffies,
1189 .strategy = &sysctl_jiffies,
1192 #ifdef CONFIG_SECURITY
1194 .ctl_name = CTL_UNNUMBERED,
1195 .procname = "mmap_min_addr",
1196 .data = &mmap_min_addr,
1197 .maxlen = sizeof(unsigned long),
1199 .proc_handler = &proc_doulongvec_minmax,
1204 .ctl_name = CTL_UNNUMBERED,
1205 .procname = "numa_zonelist_order",
1206 .data = &numa_zonelist_order,
1207 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1209 .proc_handler = &numa_zonelist_order_handler,
1210 .strategy = &sysctl_string,
1213 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1214 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1216 .ctl_name = VM_VDSO_ENABLED,
1217 .procname = "vdso_enabled",
1218 .data = &vdso_enabled,
1219 .maxlen = sizeof(vdso_enabled),
1221 .proc_handler = &proc_dointvec,
1222 .strategy = &sysctl_intvec,
1226 #ifdef CONFIG_HIGHMEM
1228 .ctl_name = CTL_UNNUMBERED,
1229 .procname = "highmem_is_dirtyable",
1230 .data = &vm_highmem_is_dirtyable,
1231 .maxlen = sizeof(vm_highmem_is_dirtyable),
1233 .proc_handler = &proc_dointvec_minmax,
1234 .strategy = &sysctl_intvec,
1240 * NOTE: do not add new entries to this table unless you have read
1241 * Documentation/sysctl/ctl_unnumbered.txt
1246 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1247 static struct ctl_table binfmt_misc_table[] = {
1252 static struct ctl_table fs_table[] = {
1254 .ctl_name = FS_NRINODE,
1255 .procname = "inode-nr",
1256 .data = &inodes_stat,
1257 .maxlen = 2*sizeof(int),
1259 .proc_handler = &proc_dointvec,
1262 .ctl_name = FS_STATINODE,
1263 .procname = "inode-state",
1264 .data = &inodes_stat,
1265 .maxlen = 7*sizeof(int),
1267 .proc_handler = &proc_dointvec,
1270 .procname = "file-nr",
1271 .data = &files_stat,
1272 .maxlen = 3*sizeof(int),
1274 .proc_handler = &proc_nr_files,
1277 .ctl_name = FS_MAXFILE,
1278 .procname = "file-max",
1279 .data = &files_stat.max_files,
1280 .maxlen = sizeof(int),
1282 .proc_handler = &proc_dointvec,
1285 .ctl_name = CTL_UNNUMBERED,
1286 .procname = "nr_open",
1287 .data = &sysctl_nr_open,
1288 .maxlen = sizeof(int),
1290 .proc_handler = &proc_dointvec_minmax,
1291 .extra1 = &sysctl_nr_open_min,
1292 .extra2 = &sysctl_nr_open_max,
1295 .ctl_name = FS_DENTRY,
1296 .procname = "dentry-state",
1297 .data = &dentry_stat,
1298 .maxlen = 6*sizeof(int),
1300 .proc_handler = &proc_dointvec,
1303 .ctl_name = FS_OVERFLOWUID,
1304 .procname = "overflowuid",
1305 .data = &fs_overflowuid,
1306 .maxlen = sizeof(int),
1308 .proc_handler = &proc_dointvec_minmax,
1309 .strategy = &sysctl_intvec,
1310 .extra1 = &minolduid,
1311 .extra2 = &maxolduid,
1314 .ctl_name = FS_OVERFLOWGID,
1315 .procname = "overflowgid",
1316 .data = &fs_overflowgid,
1317 .maxlen = sizeof(int),
1319 .proc_handler = &proc_dointvec_minmax,
1320 .strategy = &sysctl_intvec,
1321 .extra1 = &minolduid,
1322 .extra2 = &maxolduid,
1324 #ifdef CONFIG_FILE_LOCKING
1326 .ctl_name = FS_LEASES,
1327 .procname = "leases-enable",
1328 .data = &leases_enable,
1329 .maxlen = sizeof(int),
1331 .proc_handler = &proc_dointvec,
1334 #ifdef CONFIG_DNOTIFY
1336 .ctl_name = FS_DIR_NOTIFY,
1337 .procname = "dir-notify-enable",
1338 .data = &dir_notify_enable,
1339 .maxlen = sizeof(int),
1341 .proc_handler = &proc_dointvec,
1345 #ifdef CONFIG_FILE_LOCKING
1347 .ctl_name = FS_LEASE_TIME,
1348 .procname = "lease-break-time",
1349 .data = &lease_break_time,
1350 .maxlen = sizeof(int),
1352 .proc_handler = &proc_dointvec_minmax,
1353 .strategy = &sysctl_intvec,
1360 .procname = "aio-nr",
1362 .maxlen = sizeof(aio_nr),
1364 .proc_handler = &proc_doulongvec_minmax,
1367 .procname = "aio-max-nr",
1368 .data = &aio_max_nr,
1369 .maxlen = sizeof(aio_max_nr),
1371 .proc_handler = &proc_doulongvec_minmax,
1373 #endif /* CONFIG_AIO */
1374 #ifdef CONFIG_INOTIFY_USER
1376 .ctl_name = FS_INOTIFY,
1377 .procname = "inotify",
1379 .child = inotify_table,
1384 .procname = "epoll",
1386 .child = epoll_table,
1391 .ctl_name = KERN_SETUID_DUMPABLE,
1392 .procname = "suid_dumpable",
1393 .data = &suid_dumpable,
1394 .maxlen = sizeof(int),
1396 .proc_handler = &proc_dointvec,
1398 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1400 .ctl_name = CTL_UNNUMBERED,
1401 .procname = "binfmt_misc",
1403 .child = binfmt_misc_table,
1407 * NOTE: do not add new entries to this table unless you have read
1408 * Documentation/sysctl/ctl_unnumbered.txt
1413 static struct ctl_table debug_table[] = {
1414 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1416 .ctl_name = CTL_UNNUMBERED,
1417 .procname = "exception-trace",
1418 .data = &show_unhandled_signals,
1419 .maxlen = sizeof(int),
1421 .proc_handler = proc_dointvec
1427 static struct ctl_table dev_table[] = {
1431 static DEFINE_SPINLOCK(sysctl_lock);
1433 /* called under sysctl_lock */
1434 static int use_table(struct ctl_table_header *p)
1436 if (unlikely(p->unregistering))
1442 /* called under sysctl_lock */
1443 static void unuse_table(struct ctl_table_header *p)
1446 if (unlikely(p->unregistering))
1447 complete(p->unregistering);
1450 /* called under sysctl_lock, will reacquire if has to wait */
1451 static void start_unregistering(struct ctl_table_header *p)
1454 * if p->used is 0, nobody will ever touch that entry again;
1455 * we'll eliminate all paths to it before dropping sysctl_lock
1457 if (unlikely(p->used)) {
1458 struct completion wait;
1459 init_completion(&wait);
1460 p->unregistering = &wait;
1461 spin_unlock(&sysctl_lock);
1462 wait_for_completion(&wait);
1463 spin_lock(&sysctl_lock);
1465 /* anything non-NULL; we'll never dereference it */
1466 p->unregistering = ERR_PTR(-EINVAL);
1469 * do not remove from the list until nobody holds it; walking the
1470 * list in do_sysctl() relies on that.
1472 list_del_init(&p->ctl_entry);
1475 void sysctl_head_get(struct ctl_table_header *head)
1477 spin_lock(&sysctl_lock);
1479 spin_unlock(&sysctl_lock);
1482 void sysctl_head_put(struct ctl_table_header *head)
1484 spin_lock(&sysctl_lock);
1487 spin_unlock(&sysctl_lock);
1490 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1494 spin_lock(&sysctl_lock);
1495 if (!use_table(head))
1496 head = ERR_PTR(-ENOENT);
1497 spin_unlock(&sysctl_lock);
1501 void sysctl_head_finish(struct ctl_table_header *head)
1505 spin_lock(&sysctl_lock);
1507 spin_unlock(&sysctl_lock);
1510 static struct ctl_table_set *
1511 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1513 struct ctl_table_set *set = &root->default_set;
1515 set = root->lookup(root, namespaces);
1519 static struct list_head *
1520 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1522 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1526 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1527 struct ctl_table_header *prev)
1529 struct ctl_table_root *root;
1530 struct list_head *header_list;
1531 struct ctl_table_header *head;
1532 struct list_head *tmp;
1534 spin_lock(&sysctl_lock);
1537 tmp = &prev->ctl_entry;
1541 tmp = &root_table_header.ctl_entry;
1543 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1545 if (!use_table(head))
1547 spin_unlock(&sysctl_lock);
1552 header_list = lookup_header_list(root, namespaces);
1553 if (tmp != header_list)
1557 root = list_entry(root->root_list.next,
1558 struct ctl_table_root, root_list);
1559 if (root == &sysctl_table_root)
1561 header_list = lookup_header_list(root, namespaces);
1562 } while (list_empty(header_list));
1563 tmp = header_list->next;
1566 spin_unlock(&sysctl_lock);
1570 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1572 return __sysctl_head_next(current->nsproxy, prev);
1575 void register_sysctl_root(struct ctl_table_root *root)
1577 spin_lock(&sysctl_lock);
1578 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1579 spin_unlock(&sysctl_lock);
1582 #ifdef CONFIG_SYSCTL_SYSCALL
1583 /* Perform the actual read/write of a sysctl table entry. */
1584 static int do_sysctl_strategy(struct ctl_table_root *root,
1585 struct ctl_table *table,
1586 void __user *oldval, size_t __user *oldlenp,
1587 void __user *newval, size_t newlen)
1595 if (sysctl_perm(root, table, op))
1598 if (table->strategy) {
1599 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1606 /* If there is no strategy routine, or if the strategy returns
1607 * zero, proceed with automatic r/w */
1608 if (table->data && table->maxlen) {
1609 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1616 static int parse_table(int __user *name, int nlen,
1617 void __user *oldval, size_t __user *oldlenp,
1618 void __user *newval, size_t newlen,
1619 struct ctl_table_root *root,
1620 struct ctl_table *table)
1626 if (get_user(n, name))
1628 for ( ; table->ctl_name || table->procname; table++) {
1629 if (!table->ctl_name)
1631 if (n == table->ctl_name) {
1634 if (sysctl_perm(root, table, MAY_EXEC))
1638 table = table->child;
1641 error = do_sysctl_strategy(root, table,
1650 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1651 void __user *newval, size_t newlen)
1653 struct ctl_table_header *head;
1654 int error = -ENOTDIR;
1656 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1660 if (!oldlenp || get_user(old_len, oldlenp))
1664 for (head = sysctl_head_next(NULL); head;
1665 head = sysctl_head_next(head)) {
1666 error = parse_table(name, nlen, oldval, oldlenp,
1668 head->root, head->ctl_table);
1669 if (error != -ENOTDIR) {
1670 sysctl_head_finish(head);
1677 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1679 struct __sysctl_args tmp;
1682 if (copy_from_user(&tmp, args, sizeof(tmp)))
1685 error = deprecated_sysctl_warning(&tmp);
1690 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1691 tmp.newval, tmp.newlen);
1696 #endif /* CONFIG_SYSCTL_SYSCALL */
1699 * sysctl_perm does NOT grant the superuser all rights automatically, because
1700 * some sysctl variables are readonly even to root.
1703 static int test_perm(int mode, int op)
1705 if (!current_euid())
1707 else if (in_egroup_p(0))
1709 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1714 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1719 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1723 if (root->permissions)
1724 mode = root->permissions(root, current->nsproxy, table);
1728 return test_perm(mode, op);
1731 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1733 for (; table->ctl_name || table->procname; table++) {
1734 table->parent = parent;
1736 sysctl_set_parent(table, table->child);
1740 static __init int sysctl_init(void)
1742 sysctl_set_parent(NULL, root_table);
1743 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1746 err = sysctl_check_table(current->nsproxy, root_table);
1752 core_initcall(sysctl_init);
1754 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1755 struct ctl_table *table)
1757 struct ctl_table *p;
1758 const char *s = branch->procname;
1760 /* branch should have named subdirectory as its first element */
1761 if (!s || !branch->child)
1764 /* ... and nothing else */
1765 if (branch[1].procname || branch[1].ctl_name)
1768 /* table should contain subdirectory with the same name */
1769 for (p = table; p->procname || p->ctl_name; p++) {
1772 if (p->procname && strcmp(p->procname, s) == 0)
1778 /* see if attaching q to p would be an improvement */
1779 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1781 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1782 struct ctl_table *next;
1784 int not_in_parent = !p->attached_by;
1786 while ((next = is_branch_in(by, to)) != NULL) {
1787 if (by == q->attached_by)
1789 if (to == p->attached_by)
1795 if (is_better && not_in_parent) {
1796 q->attached_by = by;
1797 q->attached_to = to;
1803 * __register_sysctl_paths - register a sysctl hierarchy
1804 * @root: List of sysctl headers to register on
1805 * @namespaces: Data to compute which lists of sysctl entries are visible
1806 * @path: The path to the directory the sysctl table is in.
1807 * @table: the top-level table structure
1809 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1810 * array. A completely 0 filled entry terminates the table.
1812 * The members of the &struct ctl_table structure are used as follows:
1814 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1815 * must be unique within that level of sysctl
1817 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1818 * enter a sysctl file
1820 * data - a pointer to data for use by proc_handler
1822 * maxlen - the maximum size in bytes of the data
1824 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1826 * child - a pointer to the child sysctl table if this entry is a directory, or
1829 * proc_handler - the text handler routine (described below)
1831 * strategy - the strategy routine (described below)
1833 * de - for internal use by the sysctl routines
1835 * extra1, extra2 - extra pointers usable by the proc handler routines
1837 * Leaf nodes in the sysctl tree will be represented by a single file
1838 * under /proc; non-leaf nodes will be represented by directories.
1840 * sysctl(2) can automatically manage read and write requests through
1841 * the sysctl table. The data and maxlen fields of the ctl_table
1842 * struct enable minimal validation of the values being written to be
1843 * performed, and the mode field allows minimal authentication.
1845 * More sophisticated management can be enabled by the provision of a
1846 * strategy routine with the table entry. This will be called before
1847 * any automatic read or write of the data is performed.
1849 * The strategy routine may return
1851 * < 0 - Error occurred (error is passed to user process)
1853 * 0 - OK - proceed with automatic read or write.
1855 * > 0 - OK - read or write has been done by the strategy routine, so
1856 * return immediately.
1858 * There must be a proc_handler routine for any terminal nodes
1859 * mirrored under /proc/sys (non-terminals are handled by a built-in
1860 * directory handler). Several default handlers are available to
1861 * cover common cases -
1863 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1864 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1865 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1867 * It is the handler's job to read the input buffer from user memory
1868 * and process it. The handler should return 0 on success.
1870 * This routine returns %NULL on a failure to register, and a pointer
1871 * to the table header on success.
1873 struct ctl_table_header *__register_sysctl_paths(
1874 struct ctl_table_root *root,
1875 struct nsproxy *namespaces,
1876 const struct ctl_path *path, struct ctl_table *table)
1878 struct ctl_table_header *header;
1879 struct ctl_table *new, **prevp;
1880 unsigned int n, npath;
1881 struct ctl_table_set *set;
1883 /* Count the path components */
1884 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1888 * For each path component, allocate a 2-element ctl_table array.
1889 * The first array element will be filled with the sysctl entry
1890 * for this, the second will be the sentinel (ctl_name == 0).
1892 * We allocate everything in one go so that we don't have to
1893 * worry about freeing additional memory in unregister_sysctl_table.
1895 header = kzalloc(sizeof(struct ctl_table_header) +
1896 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1900 new = (struct ctl_table *) (header + 1);
1902 /* Now connect the dots */
1903 prevp = &header->ctl_table;
1904 for (n = 0; n < npath; ++n, ++path) {
1905 /* Copy the procname */
1906 new->procname = path->procname;
1907 new->ctl_name = path->ctl_name;
1911 prevp = &new->child;
1916 header->ctl_table_arg = table;
1918 INIT_LIST_HEAD(&header->ctl_entry);
1920 header->unregistering = NULL;
1921 header->root = root;
1922 sysctl_set_parent(NULL, header->ctl_table);
1924 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1925 if (sysctl_check_table(namespaces, header->ctl_table)) {
1930 spin_lock(&sysctl_lock);
1931 header->set = lookup_header_set(root, namespaces);
1932 header->attached_by = header->ctl_table;
1933 header->attached_to = root_table;
1934 header->parent = &root_table_header;
1935 for (set = header->set; set; set = set->parent) {
1936 struct ctl_table_header *p;
1937 list_for_each_entry(p, &set->list, ctl_entry) {
1938 if (p->unregistering)
1940 try_attach(p, header);
1943 header->parent->count++;
1944 list_add_tail(&header->ctl_entry, &header->set->list);
1945 spin_unlock(&sysctl_lock);
1951 * register_sysctl_table_path - register a sysctl table hierarchy
1952 * @path: The path to the directory the sysctl table is in.
1953 * @table: the top-level table structure
1955 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1956 * array. A completely 0 filled entry terminates the table.
1958 * See __register_sysctl_paths for more details.
1960 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1961 struct ctl_table *table)
1963 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1968 * register_sysctl_table - register a sysctl table hierarchy
1969 * @table: the top-level table structure
1971 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1972 * array. A completely 0 filled entry terminates the table.
1974 * See register_sysctl_paths for more details.
1976 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1978 static const struct ctl_path null_path[] = { {} };
1980 return register_sysctl_paths(null_path, table);
1984 * unregister_sysctl_table - unregister a sysctl table hierarchy
1985 * @header: the header returned from register_sysctl_table
1987 * Unregisters the sysctl table and all children. proc entries may not
1988 * actually be removed until they are no longer used by anyone.
1990 void unregister_sysctl_table(struct ctl_table_header * header)
1997 spin_lock(&sysctl_lock);
1998 start_unregistering(header);
1999 if (!--header->parent->count) {
2001 kfree(header->parent);
2003 if (!--header->count)
2005 spin_unlock(&sysctl_lock);
2008 int sysctl_is_seen(struct ctl_table_header *p)
2010 struct ctl_table_set *set = p->set;
2012 spin_lock(&sysctl_lock);
2013 if (p->unregistering)
2015 else if (!set->is_seen)
2018 res = set->is_seen(set);
2019 spin_unlock(&sysctl_lock);
2023 void setup_sysctl_set(struct ctl_table_set *p,
2024 struct ctl_table_set *parent,
2025 int (*is_seen)(struct ctl_table_set *))
2027 INIT_LIST_HEAD(&p->list);
2028 p->parent = parent ? parent : &sysctl_table_root.default_set;
2029 p->is_seen = is_seen;
2032 #else /* !CONFIG_SYSCTL */
2033 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2038 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2039 struct ctl_table *table)
2044 void unregister_sysctl_table(struct ctl_table_header * table)
2048 void setup_sysctl_set(struct ctl_table_set *p,
2049 struct ctl_table_set *parent,
2050 int (*is_seen)(struct ctl_table_set *))
2054 void sysctl_head_put(struct ctl_table_header *head)
2058 #endif /* CONFIG_SYSCTL */
2064 #ifdef CONFIG_PROC_SYSCTL
2066 static int _proc_do_string(void* data, int maxlen, int write,
2067 struct file *filp, void __user *buffer,
2068 size_t *lenp, loff_t *ppos)
2074 if (!data || !maxlen || !*lenp) {
2082 while (len < *lenp) {
2083 if (get_user(c, p++))
2085 if (c == 0 || c == '\n')
2091 if(copy_from_user(data, buffer, len))
2093 ((char *) data)[len] = 0;
2111 if(copy_to_user(buffer, data, len))
2114 if(put_user('\n', ((char __user *) buffer) + len))
2125 * proc_dostring - read a string sysctl
2126 * @table: the sysctl table
2127 * @write: %TRUE if this is a write to the sysctl file
2128 * @filp: the file structure
2129 * @buffer: the user buffer
2130 * @lenp: the size of the user buffer
2131 * @ppos: file position
2133 * Reads/writes a string from/to the user buffer. If the kernel
2134 * buffer provided is not large enough to hold the string, the
2135 * string is truncated. The copied string is %NULL-terminated.
2136 * If the string is being read by the user process, it is copied
2137 * and a newline '\n' is added. It is truncated if the buffer is
2140 * Returns 0 on success.
2142 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2143 void __user *buffer, size_t *lenp, loff_t *ppos)
2145 return _proc_do_string(table->data, table->maxlen, write, filp,
2146 buffer, lenp, ppos);
2150 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2152 int write, void *data)
2155 *valp = *negp ? -*lvalp : *lvalp;
2160 *lvalp = (unsigned long)-val;
2163 *lvalp = (unsigned long)val;
2169 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2170 int write, struct file *filp, void __user *buffer,
2171 size_t *lenp, loff_t *ppos,
2172 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2173 int write, void *data),
2176 #define TMPBUFLEN 21
2177 int *i, vleft, first=1, neg, val;
2181 char buf[TMPBUFLEN], *p;
2182 char __user *s = buffer;
2184 if (!tbl_data || !table->maxlen || !*lenp ||
2185 (*ppos && !write)) {
2190 i = (int *) tbl_data;
2191 vleft = table->maxlen / sizeof(*i);
2195 conv = do_proc_dointvec_conv;
2197 for (; left && vleft--; i++, first=0) {
2212 if (len > sizeof(buf) - 1)
2213 len = sizeof(buf) - 1;
2214 if (copy_from_user(buf, s, len))
2218 if (*p == '-' && left > 1) {
2222 if (*p < '0' || *p > '9')
2225 lval = simple_strtoul(p, &p, 0);
2228 if ((len < left) && *p && !isspace(*p))
2235 if (conv(&neg, &lval, i, 1, data))
2242 if (conv(&neg, &lval, i, 0, data))
2245 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2249 if(copy_to_user(s, buf, len))
2256 if (!write && !first && left) {
2257 if(put_user('\n', s))
2264 if (get_user(c, s++))
2279 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2280 void __user *buffer, size_t *lenp, loff_t *ppos,
2281 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2282 int write, void *data),
2285 return __do_proc_dointvec(table->data, table, write, filp,
2286 buffer, lenp, ppos, conv, data);
2290 * proc_dointvec - read a vector of integers
2291 * @table: the sysctl table
2292 * @write: %TRUE if this is a write to the sysctl file
2293 * @filp: the file structure
2294 * @buffer: the user buffer
2295 * @lenp: the size of the user buffer
2296 * @ppos: file position
2298 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2299 * values from/to the user buffer, treated as an ASCII string.
2301 * Returns 0 on success.
2303 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2304 void __user *buffer, size_t *lenp, loff_t *ppos)
2306 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2311 * Taint values can only be increased
2312 * This means we can safely use a temporary.
2314 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2315 void __user *buffer, size_t *lenp, loff_t *ppos)
2318 unsigned long tmptaint = get_taint();
2321 if (write && !capable(CAP_SYS_ADMIN))
2326 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2332 * Poor man's atomic or. Not worth adding a primitive
2333 * to everyone's atomic.h for this
2336 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2337 if ((tmptaint >> i) & 1)
2345 struct do_proc_dointvec_minmax_conv_param {
2350 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2352 int write, void *data)
2354 struct do_proc_dointvec_minmax_conv_param *param = data;
2356 int val = *negp ? -*lvalp : *lvalp;
2357 if ((param->min && *param->min > val) ||
2358 (param->max && *param->max < val))
2365 *lvalp = (unsigned long)-val;
2368 *lvalp = (unsigned long)val;
2375 * proc_dointvec_minmax - read a vector of integers with min/max values
2376 * @table: the sysctl table
2377 * @write: %TRUE if this is a write to the sysctl file
2378 * @filp: the file structure
2379 * @buffer: the user buffer
2380 * @lenp: the size of the user buffer
2381 * @ppos: file position
2383 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2384 * values from/to the user buffer, treated as an ASCII string.
2386 * This routine will ensure the values are within the range specified by
2387 * table->extra1 (min) and table->extra2 (max).
2389 * Returns 0 on success.
2391 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2392 void __user *buffer, size_t *lenp, loff_t *ppos)
2394 struct do_proc_dointvec_minmax_conv_param param = {
2395 .min = (int *) table->extra1,
2396 .max = (int *) table->extra2,
2398 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2399 do_proc_dointvec_minmax_conv, ¶m);
2402 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2404 void __user *buffer,
2405 size_t *lenp, loff_t *ppos,
2406 unsigned long convmul,
2407 unsigned long convdiv)
2409 #define TMPBUFLEN 21
2410 unsigned long *i, *min, *max, val;
2411 int vleft, first=1, neg;
2413 char buf[TMPBUFLEN], *p;
2414 char __user *s = buffer;
2416 if (!data || !table->maxlen || !*lenp ||
2417 (*ppos && !write)) {
2422 i = (unsigned long *) data;
2423 min = (unsigned long *) table->extra1;
2424 max = (unsigned long *) table->extra2;
2425 vleft = table->maxlen / sizeof(unsigned long);
2428 for (; left && vleft--; i++, min++, max++, first=0) {
2443 if (len > TMPBUFLEN-1)
2445 if (copy_from_user(buf, s, len))
2449 if (*p == '-' && left > 1) {
2453 if (*p < '0' || *p > '9')
2455 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2457 if ((len < left) && *p && !isspace(*p))
2466 if ((min && val < *min) || (max && val > *max))
2473 sprintf(p, "%lu", convdiv * (*i) / convmul);
2477 if(copy_to_user(s, buf, len))
2484 if (!write && !first && left) {
2485 if(put_user('\n', s))
2492 if (get_user(c, s++))
2507 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2509 void __user *buffer,
2510 size_t *lenp, loff_t *ppos,
2511 unsigned long convmul,
2512 unsigned long convdiv)
2514 return __do_proc_doulongvec_minmax(table->data, table, write,
2515 filp, buffer, lenp, ppos, convmul, convdiv);
2519 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2520 * @table: the sysctl table
2521 * @write: %TRUE if this is a write to the sysctl file
2522 * @filp: the file structure
2523 * @buffer: the user buffer
2524 * @lenp: the size of the user buffer
2525 * @ppos: file position
2527 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2528 * values from/to the user buffer, treated as an ASCII string.
2530 * This routine will ensure the values are within the range specified by
2531 * table->extra1 (min) and table->extra2 (max).
2533 * Returns 0 on success.
2535 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2536 void __user *buffer, size_t *lenp, loff_t *ppos)
2538 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2542 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2543 * @table: the sysctl table
2544 * @write: %TRUE if this is a write to the sysctl file
2545 * @filp: the file structure
2546 * @buffer: the user buffer
2547 * @lenp: the size of the user buffer
2548 * @ppos: file position
2550 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2551 * values from/to the user buffer, treated as an ASCII string. The values
2552 * are treated as milliseconds, and converted to jiffies when they are stored.
2554 * This routine will ensure the values are within the range specified by
2555 * table->extra1 (min) and table->extra2 (max).
2557 * Returns 0 on success.
2559 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2561 void __user *buffer,
2562 size_t *lenp, loff_t *ppos)
2564 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2565 lenp, ppos, HZ, 1000l);
2569 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2571 int write, void *data)
2574 if (*lvalp > LONG_MAX / HZ)
2576 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2582 lval = (unsigned long)-val;
2585 lval = (unsigned long)val;
2592 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2594 int write, void *data)
2597 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2599 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2605 lval = (unsigned long)-val;
2608 lval = (unsigned long)val;
2610 *lvalp = jiffies_to_clock_t(lval);
2615 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2617 int write, void *data)
2620 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2626 lval = (unsigned long)-val;
2629 lval = (unsigned long)val;
2631 *lvalp = jiffies_to_msecs(lval);
2637 * proc_dointvec_jiffies - read a vector of integers as seconds
2638 * @table: the sysctl table
2639 * @write: %TRUE if this is a write to the sysctl file
2640 * @filp: the file structure
2641 * @buffer: the user buffer
2642 * @lenp: the size of the user buffer
2643 * @ppos: file position
2645 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2646 * values from/to the user buffer, treated as an ASCII string.
2647 * The values read are assumed to be in seconds, and are converted into
2650 * Returns 0 on success.
2652 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2653 void __user *buffer, size_t *lenp, loff_t *ppos)
2655 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2656 do_proc_dointvec_jiffies_conv,NULL);
2660 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2661 * @table: the sysctl table
2662 * @write: %TRUE if this is a write to the sysctl file
2663 * @filp: the file structure
2664 * @buffer: the user buffer
2665 * @lenp: the size of the user buffer
2666 * @ppos: pointer to the file position
2668 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2669 * values from/to the user buffer, treated as an ASCII string.
2670 * The values read are assumed to be in 1/USER_HZ seconds, and
2671 * are converted into jiffies.
2673 * Returns 0 on success.
2675 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2676 void __user *buffer, size_t *lenp, loff_t *ppos)
2678 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2679 do_proc_dointvec_userhz_jiffies_conv,NULL);
2683 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2684 * @table: the sysctl table
2685 * @write: %TRUE if this is a write to the sysctl file
2686 * @filp: the file structure
2687 * @buffer: the user buffer
2688 * @lenp: the size of the user buffer
2689 * @ppos: file position
2690 * @ppos: the current position in the file
2692 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2693 * values from/to the user buffer, treated as an ASCII string.
2694 * The values read are assumed to be in 1/1000 seconds, and
2695 * are converted into jiffies.
2697 * Returns 0 on success.
2699 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2700 void __user *buffer, size_t *lenp, loff_t *ppos)
2702 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2703 do_proc_dointvec_ms_jiffies_conv, NULL);
2706 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2707 void __user *buffer, size_t *lenp, loff_t *ppos)
2709 struct pid *new_pid;
2713 tmp = pid_vnr(cad_pid);
2715 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2716 lenp, ppos, NULL, NULL);
2720 new_pid = find_get_pid(tmp);
2724 put_pid(xchg(&cad_pid, new_pid));
2728 #else /* CONFIG_PROC_FS */
2730 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2731 void __user *buffer, size_t *lenp, loff_t *ppos)
2736 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2737 void __user *buffer, size_t *lenp, loff_t *ppos)
2742 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2743 void __user *buffer, size_t *lenp, loff_t *ppos)
2748 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2749 void __user *buffer, size_t *lenp, loff_t *ppos)
2754 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2755 void __user *buffer, size_t *lenp, loff_t *ppos)
2760 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2761 void __user *buffer, size_t *lenp, loff_t *ppos)
2766 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2767 void __user *buffer, size_t *lenp, loff_t *ppos)
2772 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2774 void __user *buffer,
2775 size_t *lenp, loff_t *ppos)
2781 #endif /* CONFIG_PROC_FS */
2784 #ifdef CONFIG_SYSCTL_SYSCALL
2786 * General sysctl support routines
2789 /* The generic sysctl data routine (used if no strategy routine supplied) */
2790 int sysctl_data(struct ctl_table *table,
2791 void __user *oldval, size_t __user *oldlenp,
2792 void __user *newval, size_t newlen)
2796 /* Get out of I don't have a variable */
2797 if (!table->data || !table->maxlen)
2800 if (oldval && oldlenp) {
2801 if (get_user(len, oldlenp))
2804 if (len > table->maxlen)
2805 len = table->maxlen;
2806 if (copy_to_user(oldval, table->data, len))
2808 if (put_user(len, oldlenp))
2813 if (newval && newlen) {
2814 if (newlen > table->maxlen)
2815 newlen = table->maxlen;
2817 if (copy_from_user(table->data, newval, newlen))
2823 /* The generic string strategy routine: */
2824 int sysctl_string(struct ctl_table *table,
2825 void __user *oldval, size_t __user *oldlenp,
2826 void __user *newval, size_t newlen)
2828 if (!table->data || !table->maxlen)
2831 if (oldval && oldlenp) {
2833 if (get_user(bufsize, oldlenp))
2836 size_t len = strlen(table->data), copied;
2838 /* This shouldn't trigger for a well-formed sysctl */
2839 if (len > table->maxlen)
2840 len = table->maxlen;
2842 /* Copy up to a max of bufsize-1 bytes of the string */
2843 copied = (len >= bufsize) ? bufsize - 1 : len;
2845 if (copy_to_user(oldval, table->data, copied) ||
2846 put_user(0, (char __user *)(oldval + copied)))
2848 if (put_user(len, oldlenp))
2852 if (newval && newlen) {
2853 size_t len = newlen;
2854 if (len > table->maxlen)
2855 len = table->maxlen;
2856 if(copy_from_user(table->data, newval, len))
2858 if (len == table->maxlen)
2860 ((char *) table->data)[len] = 0;
2866 * This function makes sure that all of the integers in the vector
2867 * are between the minimum and maximum values given in the arrays
2868 * table->extra1 and table->extra2, respectively.
2870 int sysctl_intvec(struct ctl_table *table,
2871 void __user *oldval, size_t __user *oldlenp,
2872 void __user *newval, size_t newlen)
2875 if (newval && newlen) {
2876 int __user *vec = (int __user *) newval;
2877 int *min = (int *) table->extra1;
2878 int *max = (int *) table->extra2;
2882 if (newlen % sizeof(int) != 0)
2885 if (!table->extra1 && !table->extra2)
2888 if (newlen > table->maxlen)
2889 newlen = table->maxlen;
2890 length = newlen / sizeof(int);
2892 for (i = 0; i < length; i++) {
2894 if (get_user(value, vec + i))
2896 if (min && value < min[i])
2898 if (max && value > max[i])
2905 /* Strategy function to convert jiffies to seconds */
2906 int sysctl_jiffies(struct ctl_table *table,
2907 void __user *oldval, size_t __user *oldlenp,
2908 void __user *newval, size_t newlen)
2910 if (oldval && oldlenp) {
2913 if (get_user(olen, oldlenp))
2918 if (olen < sizeof(int))
2921 val = *(int *)(table->data) / HZ;
2922 if (put_user(val, (int __user *)oldval))
2924 if (put_user(sizeof(int), oldlenp))
2928 if (newval && newlen) {
2930 if (newlen != sizeof(int))
2932 if (get_user(new, (int __user *)newval))
2934 *(int *)(table->data) = new*HZ;
2939 /* Strategy function to convert jiffies to seconds */
2940 int sysctl_ms_jiffies(struct ctl_table *table,
2941 void __user *oldval, size_t __user *oldlenp,
2942 void __user *newval, size_t newlen)
2944 if (oldval && oldlenp) {
2947 if (get_user(olen, oldlenp))
2952 if (olen < sizeof(int))
2955 val = jiffies_to_msecs(*(int *)(table->data));
2956 if (put_user(val, (int __user *)oldval))
2958 if (put_user(sizeof(int), oldlenp))
2962 if (newval && newlen) {
2964 if (newlen != sizeof(int))
2966 if (get_user(new, (int __user *)newval))
2968 *(int *)(table->data) = msecs_to_jiffies(new);
2975 #else /* CONFIG_SYSCTL_SYSCALL */
2978 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2980 struct __sysctl_args tmp;
2983 if (copy_from_user(&tmp, args, sizeof(tmp)))
2986 error = deprecated_sysctl_warning(&tmp);
2988 /* If no error reading the parameters then just -ENOSYS ... */
2995 int sysctl_data(struct ctl_table *table,
2996 void __user *oldval, size_t __user *oldlenp,
2997 void __user *newval, size_t newlen)
3002 int sysctl_string(struct ctl_table *table,
3003 void __user *oldval, size_t __user *oldlenp,
3004 void __user *newval, size_t newlen)
3009 int sysctl_intvec(struct ctl_table *table,
3010 void __user *oldval, size_t __user *oldlenp,
3011 void __user *newval, size_t newlen)
3016 int sysctl_jiffies(struct ctl_table *table,
3017 void __user *oldval, size_t __user *oldlenp,
3018 void __user *newval, size_t newlen)
3023 int sysctl_ms_jiffies(struct ctl_table *table,
3024 void __user *oldval, size_t __user *oldlenp,
3025 void __user *newval, size_t newlen)
3030 #endif /* CONFIG_SYSCTL_SYSCALL */
3032 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3034 static int msg_count;
3035 int name[CTL_MAXNAME];
3038 /* Check args->nlen. */
3039 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3042 /* Read in the sysctl name for better debug message logging */
3043 for (i = 0; i < args->nlen; i++)
3044 if (get_user(name[i], args->name + i))
3047 /* Ignore accesses to kernel.version */
3048 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3051 if (msg_count < 5) {
3054 "warning: process `%s' used the deprecated sysctl "
3055 "system call with ", current->comm);
3056 for (i = 0; i < args->nlen; i++)
3057 printk("%d.", name[i]);
3064 * No sense putting this after each symbol definition, twice,
3065 * exception granted :-)
3067 EXPORT_SYMBOL(proc_dointvec);
3068 EXPORT_SYMBOL(proc_dointvec_jiffies);
3069 EXPORT_SYMBOL(proc_dointvec_minmax);
3070 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3071 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3072 EXPORT_SYMBOL(proc_dostring);
3073 EXPORT_SYMBOL(proc_doulongvec_minmax);
3074 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3075 EXPORT_SYMBOL(register_sysctl_table);
3076 EXPORT_SYMBOL(register_sysctl_paths);
3077 EXPORT_SYMBOL(sysctl_intvec);
3078 EXPORT_SYMBOL(sysctl_jiffies);
3079 EXPORT_SYMBOL(sysctl_ms_jiffies);
3080 EXPORT_SYMBOL(sysctl_string);
3081 EXPORT_SYMBOL(sysctl_data);
3082 EXPORT_SYMBOL(unregister_sysctl_table);