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>
51 #include <linux/slow-work.h>
53 #include <asm/uaccess.h>
54 #include <asm/processor.h>
58 #include <asm/stacktrace.h>
62 static int deprecated_sysctl_warning(struct __sysctl_args *args);
64 #if defined(CONFIG_SYSCTL)
66 /* External variables not in a header file. */
68 extern int print_fatal_signals;
69 extern int sysctl_overcommit_memory;
70 extern int sysctl_overcommit_ratio;
71 extern int sysctl_panic_on_oom;
72 extern int sysctl_oom_kill_allocating_task;
73 extern int sysctl_oom_dump_tasks;
74 extern int max_threads;
75 extern int core_uses_pid;
76 extern int suid_dumpable;
77 extern char core_pattern[];
79 extern int min_free_kbytes;
80 extern int pid_max_min, pid_max_max;
81 extern int sysctl_drop_caches;
82 extern int percpu_pagelist_fraction;
83 extern int compat_log;
84 extern int latencytop_enabled;
85 extern int sysctl_nr_open_min, sysctl_nr_open_max;
87 extern int sysctl_nr_trim_pages;
89 #ifdef CONFIG_RCU_TORTURE_TEST
90 extern int rcutorture_runnable;
91 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
93 /* Constants used for minimum and maximum */
94 #ifdef CONFIG_DETECT_SOFTLOCKUP
95 static int sixty = 60;
96 static int neg_one = -1;
100 static int __maybe_unused one = 1;
101 static int __maybe_unused two = 2;
102 static unsigned long one_ul = 1;
103 static int one_hundred = 100;
105 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
106 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
108 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
109 static int maxolduid = 65535;
110 static int minolduid;
111 static int min_percpu_pagelist_fract = 8;
113 static int ngroups_max = NGROUPS_MAX;
115 #ifdef CONFIG_MODULES
116 extern char modprobe_path[];
117 extern int modules_disabled;
119 #ifdef CONFIG_CHR_DEV_SG
120 extern int sg_big_buff;
124 #include <asm/system.h>
127 #ifdef CONFIG_SPARC64
128 extern int sysctl_tsb_ratio;
132 extern int pwrsw_enabled;
133 extern int unaligned_enabled;
137 #ifdef CONFIG_MATHEMU
138 extern int sysctl_ieee_emulation_warnings;
140 extern int sysctl_userprocess_debug;
141 extern int spin_retry;
144 #ifdef CONFIG_BSD_PROCESS_ACCT
145 extern int acct_parm[];
149 extern int no_unaligned_warning;
150 extern int unaligned_dump_stack;
153 #ifdef CONFIG_RT_MUTEXES
154 extern int max_lock_depth;
157 #ifdef CONFIG_PROC_SYSCTL
158 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
159 void __user *buffer, size_t *lenp, loff_t *ppos);
160 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
161 void __user *buffer, size_t *lenp, loff_t *ppos);
164 static struct ctl_table root_table[];
165 static struct ctl_table_root sysctl_table_root;
166 static struct ctl_table_header root_table_header = {
168 .ctl_table = root_table,
169 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
170 .root = &sysctl_table_root,
171 .set = &sysctl_table_root.default_set,
173 static struct ctl_table_root sysctl_table_root = {
174 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
175 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
178 static struct ctl_table kern_table[];
179 static struct ctl_table vm_table[];
180 static struct ctl_table fs_table[];
181 static struct ctl_table debug_table[];
182 static struct ctl_table dev_table[];
183 extern struct ctl_table random_table[];
184 #ifdef CONFIG_INOTIFY_USER
185 extern struct ctl_table inotify_table[];
188 extern struct ctl_table epoll_table[];
191 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
192 int sysctl_legacy_va_layout;
195 extern int prove_locking;
196 extern int lock_stat;
198 /* The default sysctl tables: */
200 static struct ctl_table root_table[] = {
202 .ctl_name = CTL_KERN,
203 .procname = "kernel",
220 .ctl_name = CTL_DEBUG,
223 .child = debug_table,
232 * NOTE: do not add new entries to this table unless you have read
233 * Documentation/sysctl/ctl_unnumbered.txt
238 #ifdef CONFIG_SCHED_DEBUG
239 static int min_sched_granularity_ns = 100000; /* 100 usecs */
240 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
241 static int min_wakeup_granularity_ns; /* 0 usecs */
242 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
245 static struct ctl_table kern_table[] = {
246 #ifdef CONFIG_SCHED_DEBUG
248 .ctl_name = CTL_UNNUMBERED,
249 .procname = "sched_min_granularity_ns",
250 .data = &sysctl_sched_min_granularity,
251 .maxlen = sizeof(unsigned int),
253 .proc_handler = &sched_nr_latency_handler,
254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
259 .ctl_name = CTL_UNNUMBERED,
260 .procname = "sched_latency_ns",
261 .data = &sysctl_sched_latency,
262 .maxlen = sizeof(unsigned int),
264 .proc_handler = &sched_nr_latency_handler,
265 .strategy = &sysctl_intvec,
266 .extra1 = &min_sched_granularity_ns,
267 .extra2 = &max_sched_granularity_ns,
270 .ctl_name = CTL_UNNUMBERED,
271 .procname = "sched_wakeup_granularity_ns",
272 .data = &sysctl_sched_wakeup_granularity,
273 .maxlen = sizeof(unsigned int),
275 .proc_handler = &proc_dointvec_minmax,
276 .strategy = &sysctl_intvec,
277 .extra1 = &min_wakeup_granularity_ns,
278 .extra2 = &max_wakeup_granularity_ns,
281 .ctl_name = CTL_UNNUMBERED,
282 .procname = "sched_shares_ratelimit",
283 .data = &sysctl_sched_shares_ratelimit,
284 .maxlen = sizeof(unsigned int),
286 .proc_handler = &proc_dointvec,
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "sched_shares_thresh",
291 .data = &sysctl_sched_shares_thresh,
292 .maxlen = sizeof(unsigned int),
294 .proc_handler = &proc_dointvec_minmax,
295 .strategy = &sysctl_intvec,
299 .ctl_name = CTL_UNNUMBERED,
300 .procname = "sched_child_runs_first",
301 .data = &sysctl_sched_child_runs_first,
302 .maxlen = sizeof(unsigned int),
304 .proc_handler = &proc_dointvec,
307 .ctl_name = CTL_UNNUMBERED,
308 .procname = "sched_features",
309 .data = &sysctl_sched_features,
310 .maxlen = sizeof(unsigned int),
312 .proc_handler = &proc_dointvec,
315 .ctl_name = CTL_UNNUMBERED,
316 .procname = "sched_migration_cost",
317 .data = &sysctl_sched_migration_cost,
318 .maxlen = sizeof(unsigned int),
320 .proc_handler = &proc_dointvec,
323 .ctl_name = CTL_UNNUMBERED,
324 .procname = "sched_nr_migrate",
325 .data = &sysctl_sched_nr_migrate,
326 .maxlen = sizeof(unsigned int),
328 .proc_handler = &proc_dointvec,
332 .ctl_name = CTL_UNNUMBERED,
333 .procname = "sched_rt_period_us",
334 .data = &sysctl_sched_rt_period,
335 .maxlen = sizeof(unsigned int),
337 .proc_handler = &sched_rt_handler,
340 .ctl_name = CTL_UNNUMBERED,
341 .procname = "sched_rt_runtime_us",
342 .data = &sysctl_sched_rt_runtime,
343 .maxlen = sizeof(int),
345 .proc_handler = &sched_rt_handler,
348 .ctl_name = CTL_UNNUMBERED,
349 .procname = "sched_compat_yield",
350 .data = &sysctl_sched_compat_yield,
351 .maxlen = sizeof(unsigned int),
353 .proc_handler = &proc_dointvec,
355 #ifdef CONFIG_PROVE_LOCKING
357 .ctl_name = CTL_UNNUMBERED,
358 .procname = "prove_locking",
359 .data = &prove_locking,
360 .maxlen = sizeof(int),
362 .proc_handler = &proc_dointvec,
365 #ifdef CONFIG_LOCK_STAT
367 .ctl_name = CTL_UNNUMBERED,
368 .procname = "lock_stat",
370 .maxlen = sizeof(int),
372 .proc_handler = &proc_dointvec,
376 .ctl_name = KERN_PANIC,
378 .data = &panic_timeout,
379 .maxlen = sizeof(int),
381 .proc_handler = &proc_dointvec,
384 .ctl_name = KERN_CORE_USES_PID,
385 .procname = "core_uses_pid",
386 .data = &core_uses_pid,
387 .maxlen = sizeof(int),
389 .proc_handler = &proc_dointvec,
392 .ctl_name = KERN_CORE_PATTERN,
393 .procname = "core_pattern",
394 .data = core_pattern,
395 .maxlen = CORENAME_MAX_SIZE,
397 .proc_handler = &proc_dostring,
398 .strategy = &sysctl_string,
400 #ifdef CONFIG_PROC_SYSCTL
402 .procname = "tainted",
403 .maxlen = sizeof(long),
405 .proc_handler = &proc_taint,
408 #ifdef CONFIG_LATENCYTOP
410 .procname = "latencytop",
411 .data = &latencytop_enabled,
412 .maxlen = sizeof(int),
414 .proc_handler = &proc_dointvec,
417 #ifdef CONFIG_BLK_DEV_INITRD
419 .ctl_name = KERN_REALROOTDEV,
420 .procname = "real-root-dev",
421 .data = &real_root_dev,
422 .maxlen = sizeof(int),
424 .proc_handler = &proc_dointvec,
428 .ctl_name = CTL_UNNUMBERED,
429 .procname = "print-fatal-signals",
430 .data = &print_fatal_signals,
431 .maxlen = sizeof(int),
433 .proc_handler = &proc_dointvec,
437 .ctl_name = KERN_SPARC_REBOOT,
438 .procname = "reboot-cmd",
439 .data = reboot_command,
442 .proc_handler = &proc_dostring,
443 .strategy = &sysctl_string,
446 .ctl_name = KERN_SPARC_STOP_A,
447 .procname = "stop-a",
448 .data = &stop_a_enabled,
449 .maxlen = sizeof (int),
451 .proc_handler = &proc_dointvec,
454 .ctl_name = KERN_SPARC_SCONS_PWROFF,
455 .procname = "scons-poweroff",
456 .data = &scons_pwroff,
457 .maxlen = sizeof (int),
459 .proc_handler = &proc_dointvec,
462 #ifdef CONFIG_SPARC64
464 .ctl_name = CTL_UNNUMBERED,
465 .procname = "tsb-ratio",
466 .data = &sysctl_tsb_ratio,
467 .maxlen = sizeof (int),
469 .proc_handler = &proc_dointvec,
474 .ctl_name = KERN_HPPA_PWRSW,
475 .procname = "soft-power",
476 .data = &pwrsw_enabled,
477 .maxlen = sizeof (int),
479 .proc_handler = &proc_dointvec,
482 .ctl_name = KERN_HPPA_UNALIGNED,
483 .procname = "unaligned-trap",
484 .data = &unaligned_enabled,
485 .maxlen = sizeof (int),
487 .proc_handler = &proc_dointvec,
491 .ctl_name = KERN_CTLALTDEL,
492 .procname = "ctrl-alt-del",
494 .maxlen = sizeof(int),
496 .proc_handler = &proc_dointvec,
498 #ifdef CONFIG_FUNCTION_TRACER
500 .ctl_name = CTL_UNNUMBERED,
501 .procname = "ftrace_enabled",
502 .data = &ftrace_enabled,
503 .maxlen = sizeof(int),
505 .proc_handler = &ftrace_enable_sysctl,
508 #ifdef CONFIG_STACK_TRACER
510 .ctl_name = CTL_UNNUMBERED,
511 .procname = "stack_tracer_enabled",
512 .data = &stack_tracer_enabled,
513 .maxlen = sizeof(int),
515 .proc_handler = &stack_trace_sysctl,
518 #ifdef CONFIG_TRACING
520 .ctl_name = CTL_UNNUMBERED,
521 .procname = "ftrace_dump_on_oops",
522 .data = &ftrace_dump_on_oops,
523 .maxlen = sizeof(int),
525 .proc_handler = &proc_dointvec,
528 #ifdef CONFIG_MODULES
530 .ctl_name = KERN_MODPROBE,
531 .procname = "modprobe",
532 .data = &modprobe_path,
533 .maxlen = KMOD_PATH_LEN,
535 .proc_handler = &proc_dostring,
536 .strategy = &sysctl_string,
539 .ctl_name = CTL_UNNUMBERED,
540 .procname = "modules_disabled",
541 .data = &modules_disabled,
542 .maxlen = sizeof(int),
544 /* only handle a transition from default "0" to "1" */
545 .proc_handler = &proc_dointvec_minmax,
550 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
552 .ctl_name = KERN_HOTPLUG,
553 .procname = "hotplug",
554 .data = &uevent_helper,
555 .maxlen = UEVENT_HELPER_PATH_LEN,
557 .proc_handler = &proc_dostring,
558 .strategy = &sysctl_string,
561 #ifdef CONFIG_CHR_DEV_SG
563 .ctl_name = KERN_SG_BIG_BUFF,
564 .procname = "sg-big-buff",
565 .data = &sg_big_buff,
566 .maxlen = sizeof (int),
568 .proc_handler = &proc_dointvec,
571 #ifdef CONFIG_BSD_PROCESS_ACCT
573 .ctl_name = KERN_ACCT,
576 .maxlen = 3*sizeof(int),
578 .proc_handler = &proc_dointvec,
581 #ifdef CONFIG_MAGIC_SYSRQ
583 .ctl_name = KERN_SYSRQ,
585 .data = &__sysrq_enabled,
586 .maxlen = sizeof (int),
588 .proc_handler = &proc_dointvec,
591 #ifdef CONFIG_PROC_SYSCTL
593 .procname = "cad_pid",
595 .maxlen = sizeof (int),
597 .proc_handler = &proc_do_cad_pid,
601 .ctl_name = KERN_MAX_THREADS,
602 .procname = "threads-max",
603 .data = &max_threads,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec,
609 .ctl_name = KERN_RANDOM,
610 .procname = "random",
612 .child = random_table,
615 .ctl_name = KERN_OVERFLOWUID,
616 .procname = "overflowuid",
617 .data = &overflowuid,
618 .maxlen = sizeof(int),
620 .proc_handler = &proc_dointvec_minmax,
621 .strategy = &sysctl_intvec,
622 .extra1 = &minolduid,
623 .extra2 = &maxolduid,
626 .ctl_name = KERN_OVERFLOWGID,
627 .procname = "overflowgid",
628 .data = &overflowgid,
629 .maxlen = sizeof(int),
631 .proc_handler = &proc_dointvec_minmax,
632 .strategy = &sysctl_intvec,
633 .extra1 = &minolduid,
634 .extra2 = &maxolduid,
637 #ifdef CONFIG_MATHEMU
639 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
640 .procname = "ieee_emulation_warnings",
641 .data = &sysctl_ieee_emulation_warnings,
642 .maxlen = sizeof(int),
644 .proc_handler = &proc_dointvec,
648 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
649 .procname = "userprocess_debug",
650 .data = &sysctl_userprocess_debug,
651 .maxlen = sizeof(int),
653 .proc_handler = &proc_dointvec,
657 .ctl_name = KERN_PIDMAX,
658 .procname = "pid_max",
660 .maxlen = sizeof (int),
662 .proc_handler = &proc_dointvec_minmax,
663 .strategy = sysctl_intvec,
664 .extra1 = &pid_max_min,
665 .extra2 = &pid_max_max,
668 .ctl_name = KERN_PANIC_ON_OOPS,
669 .procname = "panic_on_oops",
670 .data = &panic_on_oops,
671 .maxlen = sizeof(int),
673 .proc_handler = &proc_dointvec,
675 #if defined CONFIG_PRINTK
677 .ctl_name = KERN_PRINTK,
678 .procname = "printk",
679 .data = &console_loglevel,
680 .maxlen = 4*sizeof(int),
682 .proc_handler = &proc_dointvec,
685 .ctl_name = KERN_PRINTK_RATELIMIT,
686 .procname = "printk_ratelimit",
687 .data = &printk_ratelimit_state.interval,
688 .maxlen = sizeof(int),
690 .proc_handler = &proc_dointvec_jiffies,
691 .strategy = &sysctl_jiffies,
694 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
695 .procname = "printk_ratelimit_burst",
696 .data = &printk_ratelimit_state.burst,
697 .maxlen = sizeof(int),
699 .proc_handler = &proc_dointvec,
703 .ctl_name = KERN_NGROUPS_MAX,
704 .procname = "ngroups_max",
705 .data = &ngroups_max,
706 .maxlen = sizeof (int),
708 .proc_handler = &proc_dointvec,
710 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
712 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
713 .procname = "unknown_nmi_panic",
714 .data = &unknown_nmi_panic,
715 .maxlen = sizeof (int),
717 .proc_handler = &proc_dointvec,
720 .procname = "nmi_watchdog",
721 .data = &nmi_watchdog_enabled,
722 .maxlen = sizeof (int),
724 .proc_handler = &proc_nmi_enabled,
727 #if defined(CONFIG_X86)
729 .ctl_name = KERN_PANIC_ON_NMI,
730 .procname = "panic_on_unrecovered_nmi",
731 .data = &panic_on_unrecovered_nmi,
732 .maxlen = sizeof(int),
734 .proc_handler = &proc_dointvec,
737 .ctl_name = KERN_BOOTLOADER_TYPE,
738 .procname = "bootloader_type",
739 .data = &bootloader_type,
740 .maxlen = sizeof (int),
742 .proc_handler = &proc_dointvec,
745 .ctl_name = CTL_UNNUMBERED,
746 .procname = "kstack_depth_to_print",
747 .data = &kstack_depth_to_print,
748 .maxlen = sizeof(int),
750 .proc_handler = &proc_dointvec,
753 .ctl_name = CTL_UNNUMBERED,
754 .procname = "io_delay_type",
755 .data = &io_delay_type,
756 .maxlen = sizeof(int),
758 .proc_handler = &proc_dointvec,
761 #if defined(CONFIG_MMU)
763 .ctl_name = KERN_RANDOMIZE,
764 .procname = "randomize_va_space",
765 .data = &randomize_va_space,
766 .maxlen = sizeof(int),
768 .proc_handler = &proc_dointvec,
771 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
773 .ctl_name = KERN_SPIN_RETRY,
774 .procname = "spin_retry",
776 .maxlen = sizeof (int),
778 .proc_handler = &proc_dointvec,
781 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
783 .procname = "acpi_video_flags",
784 .data = &acpi_realmode_flags,
785 .maxlen = sizeof (unsigned long),
787 .proc_handler = &proc_doulongvec_minmax,
792 .ctl_name = KERN_IA64_UNALIGNED,
793 .procname = "ignore-unaligned-usertrap",
794 .data = &no_unaligned_warning,
795 .maxlen = sizeof (int),
797 .proc_handler = &proc_dointvec,
800 .ctl_name = CTL_UNNUMBERED,
801 .procname = "unaligned-dump-stack",
802 .data = &unaligned_dump_stack,
803 .maxlen = sizeof (int),
805 .proc_handler = &proc_dointvec,
808 #ifdef CONFIG_DETECT_SOFTLOCKUP
810 .ctl_name = CTL_UNNUMBERED,
811 .procname = "softlockup_panic",
812 .data = &softlockup_panic,
813 .maxlen = sizeof(int),
815 .proc_handler = &proc_dointvec_minmax,
816 .strategy = &sysctl_intvec,
821 .ctl_name = CTL_UNNUMBERED,
822 .procname = "softlockup_thresh",
823 .data = &softlockup_thresh,
824 .maxlen = sizeof(int),
826 .proc_handler = &proc_dosoftlockup_thresh,
827 .strategy = &sysctl_intvec,
832 #ifdef CONFIG_DETECT_HUNG_TASK
834 .ctl_name = CTL_UNNUMBERED,
835 .procname = "hung_task_panic",
836 .data = &sysctl_hung_task_panic,
837 .maxlen = sizeof(int),
839 .proc_handler = &proc_dointvec_minmax,
840 .strategy = &sysctl_intvec,
845 .ctl_name = CTL_UNNUMBERED,
846 .procname = "hung_task_check_count",
847 .data = &sysctl_hung_task_check_count,
848 .maxlen = sizeof(unsigned long),
850 .proc_handler = &proc_doulongvec_minmax,
851 .strategy = &sysctl_intvec,
854 .ctl_name = CTL_UNNUMBERED,
855 .procname = "hung_task_timeout_secs",
856 .data = &sysctl_hung_task_timeout_secs,
857 .maxlen = sizeof(unsigned long),
859 .proc_handler = &proc_dohung_task_timeout_secs,
860 .strategy = &sysctl_intvec,
863 .ctl_name = CTL_UNNUMBERED,
864 .procname = "hung_task_warnings",
865 .data = &sysctl_hung_task_warnings,
866 .maxlen = sizeof(unsigned long),
868 .proc_handler = &proc_doulongvec_minmax,
869 .strategy = &sysctl_intvec,
874 .ctl_name = KERN_COMPAT_LOG,
875 .procname = "compat-log",
877 .maxlen = sizeof (int),
879 .proc_handler = &proc_dointvec,
882 #ifdef CONFIG_RT_MUTEXES
884 .ctl_name = KERN_MAX_LOCK_DEPTH,
885 .procname = "max_lock_depth",
886 .data = &max_lock_depth,
887 .maxlen = sizeof(int),
889 .proc_handler = &proc_dointvec,
893 .ctl_name = CTL_UNNUMBERED,
894 .procname = "poweroff_cmd",
895 .data = &poweroff_cmd,
896 .maxlen = POWEROFF_CMD_PATH_LEN,
898 .proc_handler = &proc_dostring,
899 .strategy = &sysctl_string,
903 .ctl_name = CTL_UNNUMBERED,
906 .child = key_sysctls,
909 #ifdef CONFIG_RCU_TORTURE_TEST
911 .ctl_name = CTL_UNNUMBERED,
912 .procname = "rcutorture_runnable",
913 .data = &rcutorture_runnable,
914 .maxlen = sizeof(int),
916 .proc_handler = &proc_dointvec,
919 #ifdef CONFIG_SLOW_WORK
921 .ctl_name = CTL_UNNUMBERED,
922 .procname = "slow-work",
924 .child = slow_work_sysctls,
928 * NOTE: do not add new entries to this table unless you have read
929 * Documentation/sysctl/ctl_unnumbered.txt
934 static struct ctl_table vm_table[] = {
936 .ctl_name = VM_OVERCOMMIT_MEMORY,
937 .procname = "overcommit_memory",
938 .data = &sysctl_overcommit_memory,
939 .maxlen = sizeof(sysctl_overcommit_memory),
941 .proc_handler = &proc_dointvec,
944 .ctl_name = VM_PANIC_ON_OOM,
945 .procname = "panic_on_oom",
946 .data = &sysctl_panic_on_oom,
947 .maxlen = sizeof(sysctl_panic_on_oom),
949 .proc_handler = &proc_dointvec,
952 .ctl_name = CTL_UNNUMBERED,
953 .procname = "oom_kill_allocating_task",
954 .data = &sysctl_oom_kill_allocating_task,
955 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
957 .proc_handler = &proc_dointvec,
960 .ctl_name = CTL_UNNUMBERED,
961 .procname = "oom_dump_tasks",
962 .data = &sysctl_oom_dump_tasks,
963 .maxlen = sizeof(sysctl_oom_dump_tasks),
965 .proc_handler = &proc_dointvec,
968 .ctl_name = VM_OVERCOMMIT_RATIO,
969 .procname = "overcommit_ratio",
970 .data = &sysctl_overcommit_ratio,
971 .maxlen = sizeof(sysctl_overcommit_ratio),
973 .proc_handler = &proc_dointvec,
976 .ctl_name = VM_PAGE_CLUSTER,
977 .procname = "page-cluster",
978 .data = &page_cluster,
979 .maxlen = sizeof(int),
981 .proc_handler = &proc_dointvec,
984 .ctl_name = VM_DIRTY_BACKGROUND,
985 .procname = "dirty_background_ratio",
986 .data = &dirty_background_ratio,
987 .maxlen = sizeof(dirty_background_ratio),
989 .proc_handler = &dirty_background_ratio_handler,
990 .strategy = &sysctl_intvec,
992 .extra2 = &one_hundred,
995 .ctl_name = CTL_UNNUMBERED,
996 .procname = "dirty_background_bytes",
997 .data = &dirty_background_bytes,
998 .maxlen = sizeof(dirty_background_bytes),
1000 .proc_handler = &dirty_background_bytes_handler,
1001 .strategy = &sysctl_intvec,
1005 .ctl_name = VM_DIRTY_RATIO,
1006 .procname = "dirty_ratio",
1007 .data = &vm_dirty_ratio,
1008 .maxlen = sizeof(vm_dirty_ratio),
1010 .proc_handler = &dirty_ratio_handler,
1011 .strategy = &sysctl_intvec,
1013 .extra2 = &one_hundred,
1016 .ctl_name = CTL_UNNUMBERED,
1017 .procname = "dirty_bytes",
1018 .data = &vm_dirty_bytes,
1019 .maxlen = sizeof(vm_dirty_bytes),
1021 .proc_handler = &dirty_bytes_handler,
1022 .strategy = &sysctl_intvec,
1023 .extra1 = &dirty_bytes_min,
1026 .procname = "dirty_writeback_centisecs",
1027 .data = &dirty_writeback_interval,
1028 .maxlen = sizeof(dirty_writeback_interval),
1030 .proc_handler = &dirty_writeback_centisecs_handler,
1033 .procname = "dirty_expire_centisecs",
1034 .data = &dirty_expire_interval,
1035 .maxlen = sizeof(dirty_expire_interval),
1037 .proc_handler = &proc_dointvec,
1040 .ctl_name = VM_NR_PDFLUSH_THREADS,
1041 .procname = "nr_pdflush_threads",
1042 .data = &nr_pdflush_threads,
1043 .maxlen = sizeof nr_pdflush_threads,
1044 .mode = 0444 /* read-only*/,
1045 .proc_handler = &proc_dointvec,
1048 .ctl_name = VM_SWAPPINESS,
1049 .procname = "swappiness",
1050 .data = &vm_swappiness,
1051 .maxlen = sizeof(vm_swappiness),
1053 .proc_handler = &proc_dointvec_minmax,
1054 .strategy = &sysctl_intvec,
1056 .extra2 = &one_hundred,
1058 #ifdef CONFIG_HUGETLB_PAGE
1060 .procname = "nr_hugepages",
1062 .maxlen = sizeof(unsigned long),
1064 .proc_handler = &hugetlb_sysctl_handler,
1065 .extra1 = (void *)&hugetlb_zero,
1066 .extra2 = (void *)&hugetlb_infinity,
1069 .ctl_name = VM_HUGETLB_GROUP,
1070 .procname = "hugetlb_shm_group",
1071 .data = &sysctl_hugetlb_shm_group,
1072 .maxlen = sizeof(gid_t),
1074 .proc_handler = &proc_dointvec,
1077 .ctl_name = CTL_UNNUMBERED,
1078 .procname = "hugepages_treat_as_movable",
1079 .data = &hugepages_treat_as_movable,
1080 .maxlen = sizeof(int),
1082 .proc_handler = &hugetlb_treat_movable_handler,
1085 .ctl_name = CTL_UNNUMBERED,
1086 .procname = "nr_overcommit_hugepages",
1088 .maxlen = sizeof(unsigned long),
1090 .proc_handler = &hugetlb_overcommit_handler,
1091 .extra1 = (void *)&hugetlb_zero,
1092 .extra2 = (void *)&hugetlb_infinity,
1096 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1097 .procname = "lowmem_reserve_ratio",
1098 .data = &sysctl_lowmem_reserve_ratio,
1099 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1101 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1102 .strategy = &sysctl_intvec,
1105 .ctl_name = VM_DROP_PAGECACHE,
1106 .procname = "drop_caches",
1107 .data = &sysctl_drop_caches,
1108 .maxlen = sizeof(int),
1110 .proc_handler = drop_caches_sysctl_handler,
1111 .strategy = &sysctl_intvec,
1114 .ctl_name = VM_MIN_FREE_KBYTES,
1115 .procname = "min_free_kbytes",
1116 .data = &min_free_kbytes,
1117 .maxlen = sizeof(min_free_kbytes),
1119 .proc_handler = &min_free_kbytes_sysctl_handler,
1120 .strategy = &sysctl_intvec,
1124 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1125 .procname = "percpu_pagelist_fraction",
1126 .data = &percpu_pagelist_fraction,
1127 .maxlen = sizeof(percpu_pagelist_fraction),
1129 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1130 .strategy = &sysctl_intvec,
1131 .extra1 = &min_percpu_pagelist_fract,
1135 .ctl_name = VM_MAX_MAP_COUNT,
1136 .procname = "max_map_count",
1137 .data = &sysctl_max_map_count,
1138 .maxlen = sizeof(sysctl_max_map_count),
1140 .proc_handler = &proc_dointvec
1144 .ctl_name = CTL_UNNUMBERED,
1145 .procname = "nr_trim_pages",
1146 .data = &sysctl_nr_trim_pages,
1147 .maxlen = sizeof(sysctl_nr_trim_pages),
1149 .proc_handler = &proc_dointvec_minmax,
1150 .strategy = &sysctl_intvec,
1155 .ctl_name = VM_LAPTOP_MODE,
1156 .procname = "laptop_mode",
1157 .data = &laptop_mode,
1158 .maxlen = sizeof(laptop_mode),
1160 .proc_handler = &proc_dointvec_jiffies,
1161 .strategy = &sysctl_jiffies,
1164 .ctl_name = VM_BLOCK_DUMP,
1165 .procname = "block_dump",
1166 .data = &block_dump,
1167 .maxlen = sizeof(block_dump),
1169 .proc_handler = &proc_dointvec,
1170 .strategy = &sysctl_intvec,
1174 .ctl_name = VM_VFS_CACHE_PRESSURE,
1175 .procname = "vfs_cache_pressure",
1176 .data = &sysctl_vfs_cache_pressure,
1177 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1179 .proc_handler = &proc_dointvec,
1180 .strategy = &sysctl_intvec,
1183 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1185 .ctl_name = VM_LEGACY_VA_LAYOUT,
1186 .procname = "legacy_va_layout",
1187 .data = &sysctl_legacy_va_layout,
1188 .maxlen = sizeof(sysctl_legacy_va_layout),
1190 .proc_handler = &proc_dointvec,
1191 .strategy = &sysctl_intvec,
1197 .ctl_name = VM_ZONE_RECLAIM_MODE,
1198 .procname = "zone_reclaim_mode",
1199 .data = &zone_reclaim_mode,
1200 .maxlen = sizeof(zone_reclaim_mode),
1202 .proc_handler = &proc_dointvec,
1203 .strategy = &sysctl_intvec,
1207 .ctl_name = VM_MIN_UNMAPPED,
1208 .procname = "min_unmapped_ratio",
1209 .data = &sysctl_min_unmapped_ratio,
1210 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1212 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1213 .strategy = &sysctl_intvec,
1215 .extra2 = &one_hundred,
1218 .ctl_name = VM_MIN_SLAB,
1219 .procname = "min_slab_ratio",
1220 .data = &sysctl_min_slab_ratio,
1221 .maxlen = sizeof(sysctl_min_slab_ratio),
1223 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1224 .strategy = &sysctl_intvec,
1226 .extra2 = &one_hundred,
1231 .ctl_name = CTL_UNNUMBERED,
1232 .procname = "stat_interval",
1233 .data = &sysctl_stat_interval,
1234 .maxlen = sizeof(sysctl_stat_interval),
1236 .proc_handler = &proc_dointvec_jiffies,
1237 .strategy = &sysctl_jiffies,
1240 #ifdef CONFIG_SECURITY
1242 .ctl_name = CTL_UNNUMBERED,
1243 .procname = "mmap_min_addr",
1244 .data = &mmap_min_addr,
1245 .maxlen = sizeof(unsigned long),
1247 .proc_handler = &proc_doulongvec_minmax,
1252 .ctl_name = CTL_UNNUMBERED,
1253 .procname = "numa_zonelist_order",
1254 .data = &numa_zonelist_order,
1255 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1257 .proc_handler = &numa_zonelist_order_handler,
1258 .strategy = &sysctl_string,
1261 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1262 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1264 .ctl_name = VM_VDSO_ENABLED,
1265 .procname = "vdso_enabled",
1266 .data = &vdso_enabled,
1267 .maxlen = sizeof(vdso_enabled),
1269 .proc_handler = &proc_dointvec,
1270 .strategy = &sysctl_intvec,
1274 #ifdef CONFIG_HIGHMEM
1276 .ctl_name = CTL_UNNUMBERED,
1277 .procname = "highmem_is_dirtyable",
1278 .data = &vm_highmem_is_dirtyable,
1279 .maxlen = sizeof(vm_highmem_is_dirtyable),
1281 .proc_handler = &proc_dointvec_minmax,
1282 .strategy = &sysctl_intvec,
1287 #ifdef CONFIG_UNEVICTABLE_LRU
1289 .ctl_name = CTL_UNNUMBERED,
1290 .procname = "scan_unevictable_pages",
1291 .data = &scan_unevictable_pages,
1292 .maxlen = sizeof(scan_unevictable_pages),
1294 .proc_handler = &scan_unevictable_handler,
1298 * NOTE: do not add new entries to this table unless you have read
1299 * Documentation/sysctl/ctl_unnumbered.txt
1304 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1305 static struct ctl_table binfmt_misc_table[] = {
1310 static struct ctl_table fs_table[] = {
1312 .ctl_name = FS_NRINODE,
1313 .procname = "inode-nr",
1314 .data = &inodes_stat,
1315 .maxlen = 2*sizeof(int),
1317 .proc_handler = &proc_dointvec,
1320 .ctl_name = FS_STATINODE,
1321 .procname = "inode-state",
1322 .data = &inodes_stat,
1323 .maxlen = 7*sizeof(int),
1325 .proc_handler = &proc_dointvec,
1328 .procname = "file-nr",
1329 .data = &files_stat,
1330 .maxlen = 3*sizeof(int),
1332 .proc_handler = &proc_nr_files,
1335 .ctl_name = FS_MAXFILE,
1336 .procname = "file-max",
1337 .data = &files_stat.max_files,
1338 .maxlen = sizeof(int),
1340 .proc_handler = &proc_dointvec,
1343 .ctl_name = CTL_UNNUMBERED,
1344 .procname = "nr_open",
1345 .data = &sysctl_nr_open,
1346 .maxlen = sizeof(int),
1348 .proc_handler = &proc_dointvec_minmax,
1349 .extra1 = &sysctl_nr_open_min,
1350 .extra2 = &sysctl_nr_open_max,
1353 .ctl_name = FS_DENTRY,
1354 .procname = "dentry-state",
1355 .data = &dentry_stat,
1356 .maxlen = 6*sizeof(int),
1358 .proc_handler = &proc_dointvec,
1361 .ctl_name = FS_OVERFLOWUID,
1362 .procname = "overflowuid",
1363 .data = &fs_overflowuid,
1364 .maxlen = sizeof(int),
1366 .proc_handler = &proc_dointvec_minmax,
1367 .strategy = &sysctl_intvec,
1368 .extra1 = &minolduid,
1369 .extra2 = &maxolduid,
1372 .ctl_name = FS_OVERFLOWGID,
1373 .procname = "overflowgid",
1374 .data = &fs_overflowgid,
1375 .maxlen = sizeof(int),
1377 .proc_handler = &proc_dointvec_minmax,
1378 .strategy = &sysctl_intvec,
1379 .extra1 = &minolduid,
1380 .extra2 = &maxolduid,
1382 #ifdef CONFIG_FILE_LOCKING
1384 .ctl_name = FS_LEASES,
1385 .procname = "leases-enable",
1386 .data = &leases_enable,
1387 .maxlen = sizeof(int),
1389 .proc_handler = &proc_dointvec,
1392 #ifdef CONFIG_DNOTIFY
1394 .ctl_name = FS_DIR_NOTIFY,
1395 .procname = "dir-notify-enable",
1396 .data = &dir_notify_enable,
1397 .maxlen = sizeof(int),
1399 .proc_handler = &proc_dointvec,
1403 #ifdef CONFIG_FILE_LOCKING
1405 .ctl_name = FS_LEASE_TIME,
1406 .procname = "lease-break-time",
1407 .data = &lease_break_time,
1408 .maxlen = sizeof(int),
1410 .proc_handler = &proc_dointvec,
1415 .procname = "aio-nr",
1417 .maxlen = sizeof(aio_nr),
1419 .proc_handler = &proc_doulongvec_minmax,
1422 .procname = "aio-max-nr",
1423 .data = &aio_max_nr,
1424 .maxlen = sizeof(aio_max_nr),
1426 .proc_handler = &proc_doulongvec_minmax,
1428 #endif /* CONFIG_AIO */
1429 #ifdef CONFIG_INOTIFY_USER
1431 .ctl_name = FS_INOTIFY,
1432 .procname = "inotify",
1434 .child = inotify_table,
1439 .procname = "epoll",
1441 .child = epoll_table,
1446 .ctl_name = KERN_SETUID_DUMPABLE,
1447 .procname = "suid_dumpable",
1448 .data = &suid_dumpable,
1449 .maxlen = sizeof(int),
1451 .proc_handler = &proc_dointvec_minmax,
1452 .strategy = &sysctl_intvec,
1456 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1458 .ctl_name = CTL_UNNUMBERED,
1459 .procname = "binfmt_misc",
1461 .child = binfmt_misc_table,
1465 * NOTE: do not add new entries to this table unless you have read
1466 * Documentation/sysctl/ctl_unnumbered.txt
1471 static struct ctl_table debug_table[] = {
1472 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1474 .ctl_name = CTL_UNNUMBERED,
1475 .procname = "exception-trace",
1476 .data = &show_unhandled_signals,
1477 .maxlen = sizeof(int),
1479 .proc_handler = proc_dointvec
1485 static struct ctl_table dev_table[] = {
1489 static DEFINE_SPINLOCK(sysctl_lock);
1491 /* called under sysctl_lock */
1492 static int use_table(struct ctl_table_header *p)
1494 if (unlikely(p->unregistering))
1500 /* called under sysctl_lock */
1501 static void unuse_table(struct ctl_table_header *p)
1504 if (unlikely(p->unregistering))
1505 complete(p->unregistering);
1508 /* called under sysctl_lock, will reacquire if has to wait */
1509 static void start_unregistering(struct ctl_table_header *p)
1512 * if p->used is 0, nobody will ever touch that entry again;
1513 * we'll eliminate all paths to it before dropping sysctl_lock
1515 if (unlikely(p->used)) {
1516 struct completion wait;
1517 init_completion(&wait);
1518 p->unregistering = &wait;
1519 spin_unlock(&sysctl_lock);
1520 wait_for_completion(&wait);
1521 spin_lock(&sysctl_lock);
1523 /* anything non-NULL; we'll never dereference it */
1524 p->unregistering = ERR_PTR(-EINVAL);
1527 * do not remove from the list until nobody holds it; walking the
1528 * list in do_sysctl() relies on that.
1530 list_del_init(&p->ctl_entry);
1533 void sysctl_head_get(struct ctl_table_header *head)
1535 spin_lock(&sysctl_lock);
1537 spin_unlock(&sysctl_lock);
1540 void sysctl_head_put(struct ctl_table_header *head)
1542 spin_lock(&sysctl_lock);
1545 spin_unlock(&sysctl_lock);
1548 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1552 spin_lock(&sysctl_lock);
1553 if (!use_table(head))
1554 head = ERR_PTR(-ENOENT);
1555 spin_unlock(&sysctl_lock);
1559 void sysctl_head_finish(struct ctl_table_header *head)
1563 spin_lock(&sysctl_lock);
1565 spin_unlock(&sysctl_lock);
1568 static struct ctl_table_set *
1569 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1571 struct ctl_table_set *set = &root->default_set;
1573 set = root->lookup(root, namespaces);
1577 static struct list_head *
1578 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1580 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1584 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1585 struct ctl_table_header *prev)
1587 struct ctl_table_root *root;
1588 struct list_head *header_list;
1589 struct ctl_table_header *head;
1590 struct list_head *tmp;
1592 spin_lock(&sysctl_lock);
1595 tmp = &prev->ctl_entry;
1599 tmp = &root_table_header.ctl_entry;
1601 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1603 if (!use_table(head))
1605 spin_unlock(&sysctl_lock);
1610 header_list = lookup_header_list(root, namespaces);
1611 if (tmp != header_list)
1615 root = list_entry(root->root_list.next,
1616 struct ctl_table_root, root_list);
1617 if (root == &sysctl_table_root)
1619 header_list = lookup_header_list(root, namespaces);
1620 } while (list_empty(header_list));
1621 tmp = header_list->next;
1624 spin_unlock(&sysctl_lock);
1628 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1630 return __sysctl_head_next(current->nsproxy, prev);
1633 void register_sysctl_root(struct ctl_table_root *root)
1635 spin_lock(&sysctl_lock);
1636 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1637 spin_unlock(&sysctl_lock);
1640 #ifdef CONFIG_SYSCTL_SYSCALL
1641 /* Perform the actual read/write of a sysctl table entry. */
1642 static int do_sysctl_strategy(struct ctl_table_root *root,
1643 struct ctl_table *table,
1644 void __user *oldval, size_t __user *oldlenp,
1645 void __user *newval, size_t newlen)
1653 if (sysctl_perm(root, table, op))
1656 if (table->strategy) {
1657 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1664 /* If there is no strategy routine, or if the strategy returns
1665 * zero, proceed with automatic r/w */
1666 if (table->data && table->maxlen) {
1667 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1674 static int parse_table(int __user *name, int nlen,
1675 void __user *oldval, size_t __user *oldlenp,
1676 void __user *newval, size_t newlen,
1677 struct ctl_table_root *root,
1678 struct ctl_table *table)
1684 if (get_user(n, name))
1686 for ( ; table->ctl_name || table->procname; table++) {
1687 if (!table->ctl_name)
1689 if (n == table->ctl_name) {
1692 if (sysctl_perm(root, table, MAY_EXEC))
1696 table = table->child;
1699 error = do_sysctl_strategy(root, table,
1708 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1709 void __user *newval, size_t newlen)
1711 struct ctl_table_header *head;
1712 int error = -ENOTDIR;
1714 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1718 if (!oldlenp || get_user(old_len, oldlenp))
1722 for (head = sysctl_head_next(NULL); head;
1723 head = sysctl_head_next(head)) {
1724 error = parse_table(name, nlen, oldval, oldlenp,
1726 head->root, head->ctl_table);
1727 if (error != -ENOTDIR) {
1728 sysctl_head_finish(head);
1735 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1737 struct __sysctl_args tmp;
1740 if (copy_from_user(&tmp, args, sizeof(tmp)))
1743 error = deprecated_sysctl_warning(&tmp);
1748 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1749 tmp.newval, tmp.newlen);
1754 #endif /* CONFIG_SYSCTL_SYSCALL */
1757 * sysctl_perm does NOT grant the superuser all rights automatically, because
1758 * some sysctl variables are readonly even to root.
1761 static int test_perm(int mode, int op)
1763 if (!current_euid())
1765 else if (in_egroup_p(0))
1767 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1772 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1777 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1781 if (root->permissions)
1782 mode = root->permissions(root, current->nsproxy, table);
1786 return test_perm(mode, op);
1789 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1791 for (; table->ctl_name || table->procname; table++) {
1792 table->parent = parent;
1794 sysctl_set_parent(table, table->child);
1798 static __init int sysctl_init(void)
1800 sysctl_set_parent(NULL, root_table);
1801 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1804 err = sysctl_check_table(current->nsproxy, root_table);
1810 core_initcall(sysctl_init);
1812 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1813 struct ctl_table *table)
1815 struct ctl_table *p;
1816 const char *s = branch->procname;
1818 /* branch should have named subdirectory as its first element */
1819 if (!s || !branch->child)
1822 /* ... and nothing else */
1823 if (branch[1].procname || branch[1].ctl_name)
1826 /* table should contain subdirectory with the same name */
1827 for (p = table; p->procname || p->ctl_name; p++) {
1830 if (p->procname && strcmp(p->procname, s) == 0)
1836 /* see if attaching q to p would be an improvement */
1837 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1839 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1840 struct ctl_table *next;
1842 int not_in_parent = !p->attached_by;
1844 while ((next = is_branch_in(by, to)) != NULL) {
1845 if (by == q->attached_by)
1847 if (to == p->attached_by)
1853 if (is_better && not_in_parent) {
1854 q->attached_by = by;
1855 q->attached_to = to;
1861 * __register_sysctl_paths - register a sysctl hierarchy
1862 * @root: List of sysctl headers to register on
1863 * @namespaces: Data to compute which lists of sysctl entries are visible
1864 * @path: The path to the directory the sysctl table is in.
1865 * @table: the top-level table structure
1867 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1868 * array. A completely 0 filled entry terminates the table.
1870 * The members of the &struct ctl_table structure are used as follows:
1872 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1873 * must be unique within that level of sysctl
1875 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1876 * enter a sysctl file
1878 * data - a pointer to data for use by proc_handler
1880 * maxlen - the maximum size in bytes of the data
1882 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1884 * child - a pointer to the child sysctl table if this entry is a directory, or
1887 * proc_handler - the text handler routine (described below)
1889 * strategy - the strategy routine (described below)
1891 * de - for internal use by the sysctl routines
1893 * extra1, extra2 - extra pointers usable by the proc handler routines
1895 * Leaf nodes in the sysctl tree will be represented by a single file
1896 * under /proc; non-leaf nodes will be represented by directories.
1898 * sysctl(2) can automatically manage read and write requests through
1899 * the sysctl table. The data and maxlen fields of the ctl_table
1900 * struct enable minimal validation of the values being written to be
1901 * performed, and the mode field allows minimal authentication.
1903 * More sophisticated management can be enabled by the provision of a
1904 * strategy routine with the table entry. This will be called before
1905 * any automatic read or write of the data is performed.
1907 * The strategy routine may return
1909 * < 0 - Error occurred (error is passed to user process)
1911 * 0 - OK - proceed with automatic read or write.
1913 * > 0 - OK - read or write has been done by the strategy routine, so
1914 * return immediately.
1916 * There must be a proc_handler routine for any terminal nodes
1917 * mirrored under /proc/sys (non-terminals are handled by a built-in
1918 * directory handler). Several default handlers are available to
1919 * cover common cases -
1921 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1922 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1923 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1925 * It is the handler's job to read the input buffer from user memory
1926 * and process it. The handler should return 0 on success.
1928 * This routine returns %NULL on a failure to register, and a pointer
1929 * to the table header on success.
1931 struct ctl_table_header *__register_sysctl_paths(
1932 struct ctl_table_root *root,
1933 struct nsproxy *namespaces,
1934 const struct ctl_path *path, struct ctl_table *table)
1936 struct ctl_table_header *header;
1937 struct ctl_table *new, **prevp;
1938 unsigned int n, npath;
1939 struct ctl_table_set *set;
1941 /* Count the path components */
1942 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1946 * For each path component, allocate a 2-element ctl_table array.
1947 * The first array element will be filled with the sysctl entry
1948 * for this, the second will be the sentinel (ctl_name == 0).
1950 * We allocate everything in one go so that we don't have to
1951 * worry about freeing additional memory in unregister_sysctl_table.
1953 header = kzalloc(sizeof(struct ctl_table_header) +
1954 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1958 new = (struct ctl_table *) (header + 1);
1960 /* Now connect the dots */
1961 prevp = &header->ctl_table;
1962 for (n = 0; n < npath; ++n, ++path) {
1963 /* Copy the procname */
1964 new->procname = path->procname;
1965 new->ctl_name = path->ctl_name;
1969 prevp = &new->child;
1974 header->ctl_table_arg = table;
1976 INIT_LIST_HEAD(&header->ctl_entry);
1978 header->unregistering = NULL;
1979 header->root = root;
1980 sysctl_set_parent(NULL, header->ctl_table);
1982 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1983 if (sysctl_check_table(namespaces, header->ctl_table)) {
1988 spin_lock(&sysctl_lock);
1989 header->set = lookup_header_set(root, namespaces);
1990 header->attached_by = header->ctl_table;
1991 header->attached_to = root_table;
1992 header->parent = &root_table_header;
1993 for (set = header->set; set; set = set->parent) {
1994 struct ctl_table_header *p;
1995 list_for_each_entry(p, &set->list, ctl_entry) {
1996 if (p->unregistering)
1998 try_attach(p, header);
2001 header->parent->count++;
2002 list_add_tail(&header->ctl_entry, &header->set->list);
2003 spin_unlock(&sysctl_lock);
2009 * register_sysctl_table_path - register a sysctl table hierarchy
2010 * @path: The path to the directory the sysctl table is in.
2011 * @table: the top-level table structure
2013 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2014 * array. A completely 0 filled entry terminates the table.
2016 * See __register_sysctl_paths for more details.
2018 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2019 struct ctl_table *table)
2021 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2026 * register_sysctl_table - register a sysctl table hierarchy
2027 * @table: the top-level table structure
2029 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2030 * array. A completely 0 filled entry terminates the table.
2032 * See register_sysctl_paths for more details.
2034 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2036 static const struct ctl_path null_path[] = { {} };
2038 return register_sysctl_paths(null_path, table);
2042 * unregister_sysctl_table - unregister a sysctl table hierarchy
2043 * @header: the header returned from register_sysctl_table
2045 * Unregisters the sysctl table and all children. proc entries may not
2046 * actually be removed until they are no longer used by anyone.
2048 void unregister_sysctl_table(struct ctl_table_header * header)
2055 spin_lock(&sysctl_lock);
2056 start_unregistering(header);
2057 if (!--header->parent->count) {
2059 kfree(header->parent);
2061 if (!--header->count)
2063 spin_unlock(&sysctl_lock);
2066 int sysctl_is_seen(struct ctl_table_header *p)
2068 struct ctl_table_set *set = p->set;
2070 spin_lock(&sysctl_lock);
2071 if (p->unregistering)
2073 else if (!set->is_seen)
2076 res = set->is_seen(set);
2077 spin_unlock(&sysctl_lock);
2081 void setup_sysctl_set(struct ctl_table_set *p,
2082 struct ctl_table_set *parent,
2083 int (*is_seen)(struct ctl_table_set *))
2085 INIT_LIST_HEAD(&p->list);
2086 p->parent = parent ? parent : &sysctl_table_root.default_set;
2087 p->is_seen = is_seen;
2090 #else /* !CONFIG_SYSCTL */
2091 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2096 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2097 struct ctl_table *table)
2102 void unregister_sysctl_table(struct ctl_table_header * table)
2106 void setup_sysctl_set(struct ctl_table_set *p,
2107 struct ctl_table_set *parent,
2108 int (*is_seen)(struct ctl_table_set *))
2112 void sysctl_head_put(struct ctl_table_header *head)
2116 #endif /* CONFIG_SYSCTL */
2122 #ifdef CONFIG_PROC_SYSCTL
2124 static int _proc_do_string(void* data, int maxlen, int write,
2125 struct file *filp, void __user *buffer,
2126 size_t *lenp, loff_t *ppos)
2132 if (!data || !maxlen || !*lenp) {
2140 while (len < *lenp) {
2141 if (get_user(c, p++))
2143 if (c == 0 || c == '\n')
2149 if(copy_from_user(data, buffer, len))
2151 ((char *) data)[len] = 0;
2169 if(copy_to_user(buffer, data, len))
2172 if(put_user('\n', ((char __user *) buffer) + len))
2183 * proc_dostring - read a string sysctl
2184 * @table: the sysctl table
2185 * @write: %TRUE if this is a write to the sysctl file
2186 * @filp: the file structure
2187 * @buffer: the user buffer
2188 * @lenp: the size of the user buffer
2189 * @ppos: file position
2191 * Reads/writes a string from/to the user buffer. If the kernel
2192 * buffer provided is not large enough to hold the string, the
2193 * string is truncated. The copied string is %NULL-terminated.
2194 * If the string is being read by the user process, it is copied
2195 * and a newline '\n' is added. It is truncated if the buffer is
2198 * Returns 0 on success.
2200 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2201 void __user *buffer, size_t *lenp, loff_t *ppos)
2203 return _proc_do_string(table->data, table->maxlen, write, filp,
2204 buffer, lenp, ppos);
2208 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2210 int write, void *data)
2213 *valp = *negp ? -*lvalp : *lvalp;
2218 *lvalp = (unsigned long)-val;
2221 *lvalp = (unsigned long)val;
2227 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2228 int write, struct file *filp, void __user *buffer,
2229 size_t *lenp, loff_t *ppos,
2230 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2231 int write, void *data),
2234 #define TMPBUFLEN 21
2235 int *i, vleft, first=1, neg, val;
2239 char buf[TMPBUFLEN], *p;
2240 char __user *s = buffer;
2242 if (!tbl_data || !table->maxlen || !*lenp ||
2243 (*ppos && !write)) {
2248 i = (int *) tbl_data;
2249 vleft = table->maxlen / sizeof(*i);
2253 conv = do_proc_dointvec_conv;
2255 for (; left && vleft--; i++, first=0) {
2270 if (len > sizeof(buf) - 1)
2271 len = sizeof(buf) - 1;
2272 if (copy_from_user(buf, s, len))
2276 if (*p == '-' && left > 1) {
2280 if (*p < '0' || *p > '9')
2283 lval = simple_strtoul(p, &p, 0);
2286 if ((len < left) && *p && !isspace(*p))
2293 if (conv(&neg, &lval, i, 1, data))
2300 if (conv(&neg, &lval, i, 0, data))
2303 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2307 if(copy_to_user(s, buf, len))
2314 if (!write && !first && left) {
2315 if(put_user('\n', s))
2322 if (get_user(c, s++))
2337 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2338 void __user *buffer, size_t *lenp, loff_t *ppos,
2339 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2340 int write, void *data),
2343 return __do_proc_dointvec(table->data, table, write, filp,
2344 buffer, lenp, ppos, conv, data);
2348 * proc_dointvec - read a vector of integers
2349 * @table: the sysctl table
2350 * @write: %TRUE if this is a write to the sysctl file
2351 * @filp: the file structure
2352 * @buffer: the user buffer
2353 * @lenp: the size of the user buffer
2354 * @ppos: file position
2356 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2357 * values from/to the user buffer, treated as an ASCII string.
2359 * Returns 0 on success.
2361 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2362 void __user *buffer, size_t *lenp, loff_t *ppos)
2364 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2369 * Taint values can only be increased
2370 * This means we can safely use a temporary.
2372 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2373 void __user *buffer, size_t *lenp, loff_t *ppos)
2376 unsigned long tmptaint = get_taint();
2379 if (write && !capable(CAP_SYS_ADMIN))
2384 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2390 * Poor man's atomic or. Not worth adding a primitive
2391 * to everyone's atomic.h for this
2394 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2395 if ((tmptaint >> i) & 1)
2403 struct do_proc_dointvec_minmax_conv_param {
2408 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2410 int write, void *data)
2412 struct do_proc_dointvec_minmax_conv_param *param = data;
2414 int val = *negp ? -*lvalp : *lvalp;
2415 if ((param->min && *param->min > val) ||
2416 (param->max && *param->max < val))
2423 *lvalp = (unsigned long)-val;
2426 *lvalp = (unsigned long)val;
2433 * proc_dointvec_minmax - read a vector of integers with min/max values
2434 * @table: the sysctl table
2435 * @write: %TRUE if this is a write to the sysctl file
2436 * @filp: the file structure
2437 * @buffer: the user buffer
2438 * @lenp: the size of the user buffer
2439 * @ppos: file position
2441 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2442 * values from/to the user buffer, treated as an ASCII string.
2444 * This routine will ensure the values are within the range specified by
2445 * table->extra1 (min) and table->extra2 (max).
2447 * Returns 0 on success.
2449 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2450 void __user *buffer, size_t *lenp, loff_t *ppos)
2452 struct do_proc_dointvec_minmax_conv_param param = {
2453 .min = (int *) table->extra1,
2454 .max = (int *) table->extra2,
2456 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2457 do_proc_dointvec_minmax_conv, ¶m);
2460 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2462 void __user *buffer,
2463 size_t *lenp, loff_t *ppos,
2464 unsigned long convmul,
2465 unsigned long convdiv)
2467 #define TMPBUFLEN 21
2468 unsigned long *i, *min, *max, val;
2469 int vleft, first=1, neg;
2471 char buf[TMPBUFLEN], *p;
2472 char __user *s = buffer;
2474 if (!data || !table->maxlen || !*lenp ||
2475 (*ppos && !write)) {
2480 i = (unsigned long *) data;
2481 min = (unsigned long *) table->extra1;
2482 max = (unsigned long *) table->extra2;
2483 vleft = table->maxlen / sizeof(unsigned long);
2486 for (; left && vleft--; i++, min++, max++, first=0) {
2501 if (len > TMPBUFLEN-1)
2503 if (copy_from_user(buf, s, len))
2507 if (*p == '-' && left > 1) {
2511 if (*p < '0' || *p > '9')
2513 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2515 if ((len < left) && *p && !isspace(*p))
2524 if ((min && val < *min) || (max && val > *max))
2531 sprintf(p, "%lu", convdiv * (*i) / convmul);
2535 if(copy_to_user(s, buf, len))
2542 if (!write && !first && left) {
2543 if(put_user('\n', s))
2550 if (get_user(c, s++))
2565 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2567 void __user *buffer,
2568 size_t *lenp, loff_t *ppos,
2569 unsigned long convmul,
2570 unsigned long convdiv)
2572 return __do_proc_doulongvec_minmax(table->data, table, write,
2573 filp, buffer, lenp, ppos, convmul, convdiv);
2577 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2578 * @table: the sysctl table
2579 * @write: %TRUE if this is a write to the sysctl file
2580 * @filp: the file structure
2581 * @buffer: the user buffer
2582 * @lenp: the size of the user buffer
2583 * @ppos: file position
2585 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2586 * values from/to the user buffer, treated as an ASCII string.
2588 * This routine will ensure the values are within the range specified by
2589 * table->extra1 (min) and table->extra2 (max).
2591 * Returns 0 on success.
2593 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2594 void __user *buffer, size_t *lenp, loff_t *ppos)
2596 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2600 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2601 * @table: the sysctl table
2602 * @write: %TRUE if this is a write to the sysctl file
2603 * @filp: the file structure
2604 * @buffer: the user buffer
2605 * @lenp: the size of the user buffer
2606 * @ppos: file position
2608 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2609 * values from/to the user buffer, treated as an ASCII string. The values
2610 * are treated as milliseconds, and converted to jiffies when they are stored.
2612 * This routine will ensure the values are within the range specified by
2613 * table->extra1 (min) and table->extra2 (max).
2615 * Returns 0 on success.
2617 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2619 void __user *buffer,
2620 size_t *lenp, loff_t *ppos)
2622 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2623 lenp, ppos, HZ, 1000l);
2627 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2629 int write, void *data)
2632 if (*lvalp > LONG_MAX / HZ)
2634 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2640 lval = (unsigned long)-val;
2643 lval = (unsigned long)val;
2650 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2652 int write, void *data)
2655 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2657 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2663 lval = (unsigned long)-val;
2666 lval = (unsigned long)val;
2668 *lvalp = jiffies_to_clock_t(lval);
2673 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2675 int write, void *data)
2678 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2684 lval = (unsigned long)-val;
2687 lval = (unsigned long)val;
2689 *lvalp = jiffies_to_msecs(lval);
2695 * proc_dointvec_jiffies - read a vector of integers as seconds
2696 * @table: the sysctl table
2697 * @write: %TRUE if this is a write to the sysctl file
2698 * @filp: the file structure
2699 * @buffer: the user buffer
2700 * @lenp: the size of the user buffer
2701 * @ppos: file position
2703 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2704 * values from/to the user buffer, treated as an ASCII string.
2705 * The values read are assumed to be in seconds, and are converted into
2708 * Returns 0 on success.
2710 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2711 void __user *buffer, size_t *lenp, loff_t *ppos)
2713 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2714 do_proc_dointvec_jiffies_conv,NULL);
2718 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2719 * @table: the sysctl table
2720 * @write: %TRUE if this is a write to the sysctl file
2721 * @filp: the file structure
2722 * @buffer: the user buffer
2723 * @lenp: the size of the user buffer
2724 * @ppos: pointer to the file position
2726 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2727 * values from/to the user buffer, treated as an ASCII string.
2728 * The values read are assumed to be in 1/USER_HZ seconds, and
2729 * are converted into jiffies.
2731 * Returns 0 on success.
2733 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2734 void __user *buffer, size_t *lenp, loff_t *ppos)
2736 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2737 do_proc_dointvec_userhz_jiffies_conv,NULL);
2741 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2742 * @table: the sysctl table
2743 * @write: %TRUE if this is a write to the sysctl file
2744 * @filp: the file structure
2745 * @buffer: the user buffer
2746 * @lenp: the size of the user buffer
2747 * @ppos: file position
2748 * @ppos: the current position in the file
2750 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2751 * values from/to the user buffer, treated as an ASCII string.
2752 * The values read are assumed to be in 1/1000 seconds, and
2753 * are converted into jiffies.
2755 * Returns 0 on success.
2757 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2758 void __user *buffer, size_t *lenp, loff_t *ppos)
2760 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2761 do_proc_dointvec_ms_jiffies_conv, NULL);
2764 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2765 void __user *buffer, size_t *lenp, loff_t *ppos)
2767 struct pid *new_pid;
2771 tmp = pid_vnr(cad_pid);
2773 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2774 lenp, ppos, NULL, NULL);
2778 new_pid = find_get_pid(tmp);
2782 put_pid(xchg(&cad_pid, new_pid));
2786 #else /* CONFIG_PROC_FS */
2788 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2789 void __user *buffer, size_t *lenp, loff_t *ppos)
2794 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2795 void __user *buffer, size_t *lenp, loff_t *ppos)
2800 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2801 void __user *buffer, size_t *lenp, loff_t *ppos)
2806 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2807 void __user *buffer, size_t *lenp, loff_t *ppos)
2812 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2813 void __user *buffer, size_t *lenp, loff_t *ppos)
2818 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2819 void __user *buffer, size_t *lenp, loff_t *ppos)
2824 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2825 void __user *buffer, size_t *lenp, loff_t *ppos)
2830 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2832 void __user *buffer,
2833 size_t *lenp, loff_t *ppos)
2839 #endif /* CONFIG_PROC_FS */
2842 #ifdef CONFIG_SYSCTL_SYSCALL
2844 * General sysctl support routines
2847 /* The generic sysctl data routine (used if no strategy routine supplied) */
2848 int sysctl_data(struct ctl_table *table,
2849 void __user *oldval, size_t __user *oldlenp,
2850 void __user *newval, size_t newlen)
2854 /* Get out of I don't have a variable */
2855 if (!table->data || !table->maxlen)
2858 if (oldval && oldlenp) {
2859 if (get_user(len, oldlenp))
2862 if (len > table->maxlen)
2863 len = table->maxlen;
2864 if (copy_to_user(oldval, table->data, len))
2866 if (put_user(len, oldlenp))
2871 if (newval && newlen) {
2872 if (newlen > table->maxlen)
2873 newlen = table->maxlen;
2875 if (copy_from_user(table->data, newval, newlen))
2881 /* The generic string strategy routine: */
2882 int sysctl_string(struct ctl_table *table,
2883 void __user *oldval, size_t __user *oldlenp,
2884 void __user *newval, size_t newlen)
2886 if (!table->data || !table->maxlen)
2889 if (oldval && oldlenp) {
2891 if (get_user(bufsize, oldlenp))
2894 size_t len = strlen(table->data), copied;
2896 /* This shouldn't trigger for a well-formed sysctl */
2897 if (len > table->maxlen)
2898 len = table->maxlen;
2900 /* Copy up to a max of bufsize-1 bytes of the string */
2901 copied = (len >= bufsize) ? bufsize - 1 : len;
2903 if (copy_to_user(oldval, table->data, copied) ||
2904 put_user(0, (char __user *)(oldval + copied)))
2906 if (put_user(len, oldlenp))
2910 if (newval && newlen) {
2911 size_t len = newlen;
2912 if (len > table->maxlen)
2913 len = table->maxlen;
2914 if(copy_from_user(table->data, newval, len))
2916 if (len == table->maxlen)
2918 ((char *) table->data)[len] = 0;
2924 * This function makes sure that all of the integers in the vector
2925 * are between the minimum and maximum values given in the arrays
2926 * table->extra1 and table->extra2, respectively.
2928 int sysctl_intvec(struct ctl_table *table,
2929 void __user *oldval, size_t __user *oldlenp,
2930 void __user *newval, size_t newlen)
2933 if (newval && newlen) {
2934 int __user *vec = (int __user *) newval;
2935 int *min = (int *) table->extra1;
2936 int *max = (int *) table->extra2;
2940 if (newlen % sizeof(int) != 0)
2943 if (!table->extra1 && !table->extra2)
2946 if (newlen > table->maxlen)
2947 newlen = table->maxlen;
2948 length = newlen / sizeof(int);
2950 for (i = 0; i < length; i++) {
2952 if (get_user(value, vec + i))
2954 if (min && value < min[i])
2956 if (max && value > max[i])
2963 /* Strategy function to convert jiffies to seconds */
2964 int sysctl_jiffies(struct ctl_table *table,
2965 void __user *oldval, size_t __user *oldlenp,
2966 void __user *newval, size_t newlen)
2968 if (oldval && oldlenp) {
2971 if (get_user(olen, oldlenp))
2976 if (olen < sizeof(int))
2979 val = *(int *)(table->data) / HZ;
2980 if (put_user(val, (int __user *)oldval))
2982 if (put_user(sizeof(int), oldlenp))
2986 if (newval && newlen) {
2988 if (newlen != sizeof(int))
2990 if (get_user(new, (int __user *)newval))
2992 *(int *)(table->data) = new*HZ;
2997 /* Strategy function to convert jiffies to seconds */
2998 int sysctl_ms_jiffies(struct ctl_table *table,
2999 void __user *oldval, size_t __user *oldlenp,
3000 void __user *newval, size_t newlen)
3002 if (oldval && oldlenp) {
3005 if (get_user(olen, oldlenp))
3010 if (olen < sizeof(int))
3013 val = jiffies_to_msecs(*(int *)(table->data));
3014 if (put_user(val, (int __user *)oldval))
3016 if (put_user(sizeof(int), oldlenp))
3020 if (newval && newlen) {
3022 if (newlen != sizeof(int))
3024 if (get_user(new, (int __user *)newval))
3026 *(int *)(table->data) = msecs_to_jiffies(new);
3033 #else /* CONFIG_SYSCTL_SYSCALL */
3036 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3038 struct __sysctl_args tmp;
3041 if (copy_from_user(&tmp, args, sizeof(tmp)))
3044 error = deprecated_sysctl_warning(&tmp);
3046 /* If no error reading the parameters then just -ENOSYS ... */
3053 int sysctl_data(struct ctl_table *table,
3054 void __user *oldval, size_t __user *oldlenp,
3055 void __user *newval, size_t newlen)
3060 int sysctl_string(struct ctl_table *table,
3061 void __user *oldval, size_t __user *oldlenp,
3062 void __user *newval, size_t newlen)
3067 int sysctl_intvec(struct ctl_table *table,
3068 void __user *oldval, size_t __user *oldlenp,
3069 void __user *newval, size_t newlen)
3074 int sysctl_jiffies(struct ctl_table *table,
3075 void __user *oldval, size_t __user *oldlenp,
3076 void __user *newval, size_t newlen)
3081 int sysctl_ms_jiffies(struct ctl_table *table,
3082 void __user *oldval, size_t __user *oldlenp,
3083 void __user *newval, size_t newlen)
3088 #endif /* CONFIG_SYSCTL_SYSCALL */
3090 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3092 static int msg_count;
3093 int name[CTL_MAXNAME];
3096 /* Check args->nlen. */
3097 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3100 /* Read in the sysctl name for better debug message logging */
3101 for (i = 0; i < args->nlen; i++)
3102 if (get_user(name[i], args->name + i))
3105 /* Ignore accesses to kernel.version */
3106 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3109 if (msg_count < 5) {
3112 "warning: process `%s' used the deprecated sysctl "
3113 "system call with ", current->comm);
3114 for (i = 0; i < args->nlen; i++)
3115 printk("%d.", name[i]);
3122 * No sense putting this after each symbol definition, twice,
3123 * exception granted :-)
3125 EXPORT_SYMBOL(proc_dointvec);
3126 EXPORT_SYMBOL(proc_dointvec_jiffies);
3127 EXPORT_SYMBOL(proc_dointvec_minmax);
3128 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3129 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3130 EXPORT_SYMBOL(proc_dostring);
3131 EXPORT_SYMBOL(proc_doulongvec_minmax);
3132 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3133 EXPORT_SYMBOL(register_sysctl_table);
3134 EXPORT_SYMBOL(register_sysctl_paths);
3135 EXPORT_SYMBOL(sysctl_intvec);
3136 EXPORT_SYMBOL(sysctl_jiffies);
3137 EXPORT_SYMBOL(sysctl_ms_jiffies);
3138 EXPORT_SYMBOL(sysctl_string);
3139 EXPORT_SYMBOL(sysctl_data);
3140 EXPORT_SYMBOL(unregister_sysctl_table);