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 maps_protect;
84 extern int latencytop_enabled;
85 extern int sysctl_nr_open_min, sysctl_nr_open_max;
86 #ifdef CONFIG_RCU_TORTURE_TEST
87 extern int rcutorture_runnable;
88 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
90 /* Constants used for minimum and maximum */
91 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
95 #ifdef CONFIG_DETECT_SOFTLOCKUP
96 static int sixty = 60;
97 static int neg_one = -1;
105 static int one_hundred = 100;
107 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
108 static int maxolduid = 65535;
109 static int minolduid;
110 static int min_percpu_pagelist_fract = 8;
112 static int ngroups_max = NGROUPS_MAX;
114 #ifdef CONFIG_MODULES
115 extern char modprobe_path[];
117 #ifdef CONFIG_CHR_DEV_SG
118 extern int sg_big_buff;
122 extern char reboot_command [];
123 extern int stop_a_enabled;
124 extern int scons_pwroff;
128 extern int pwrsw_enabled;
129 extern int unaligned_enabled;
133 #ifdef CONFIG_MATHEMU
134 extern int sysctl_ieee_emulation_warnings;
136 extern int sysctl_userprocess_debug;
137 extern int spin_retry;
140 #ifdef CONFIG_BSD_PROCESS_ACCT
141 extern int acct_parm[];
145 extern int no_unaligned_warning;
148 #ifdef CONFIG_RT_MUTEXES
149 extern int max_lock_depth;
152 #ifdef CONFIG_PROC_SYSCTL
153 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
154 void __user *buffer, size_t *lenp, loff_t *ppos);
155 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
156 void __user *buffer, size_t *lenp, loff_t *ppos);
159 static struct ctl_table root_table[];
160 static struct ctl_table_root sysctl_table_root;
161 static struct ctl_table_header root_table_header = {
163 .ctl_table = root_table,
164 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
165 .root = &sysctl_table_root,
166 .set = &sysctl_table_root.default_set,
168 static struct ctl_table_root sysctl_table_root = {
169 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
170 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
173 static struct ctl_table kern_table[];
174 static struct ctl_table vm_table[];
175 static struct ctl_table fs_table[];
176 static struct ctl_table debug_table[];
177 static struct ctl_table dev_table[];
178 extern struct ctl_table random_table[];
179 #ifdef CONFIG_INOTIFY_USER
180 extern struct ctl_table inotify_table[];
183 extern struct ctl_table epoll_table[];
186 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
187 int sysctl_legacy_va_layout;
190 extern int prove_locking;
191 extern int lock_stat;
193 /* The default sysctl tables: */
195 static struct ctl_table root_table[] = {
197 .ctl_name = CTL_KERN,
198 .procname = "kernel",
215 .ctl_name = CTL_DEBUG,
218 .child = debug_table,
227 * NOTE: do not add new entries to this table unless you have read
228 * Documentation/sysctl/ctl_unnumbered.txt
233 #ifdef CONFIG_SCHED_DEBUG
234 static int min_sched_granularity_ns = 100000; /* 100 usecs */
235 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
236 static int min_wakeup_granularity_ns; /* 0 usecs */
237 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
240 static struct ctl_table kern_table[] = {
241 #ifdef CONFIG_SCHED_DEBUG
243 .ctl_name = CTL_UNNUMBERED,
244 .procname = "sched_min_granularity_ns",
245 .data = &sysctl_sched_min_granularity,
246 .maxlen = sizeof(unsigned int),
248 .proc_handler = &sched_nr_latency_handler,
249 .strategy = &sysctl_intvec,
250 .extra1 = &min_sched_granularity_ns,
251 .extra2 = &max_sched_granularity_ns,
254 .ctl_name = CTL_UNNUMBERED,
255 .procname = "sched_latency_ns",
256 .data = &sysctl_sched_latency,
257 .maxlen = sizeof(unsigned int),
259 .proc_handler = &sched_nr_latency_handler,
260 .strategy = &sysctl_intvec,
261 .extra1 = &min_sched_granularity_ns,
262 .extra2 = &max_sched_granularity_ns,
265 .ctl_name = CTL_UNNUMBERED,
266 .procname = "sched_wakeup_granularity_ns",
267 .data = &sysctl_sched_wakeup_granularity,
268 .maxlen = sizeof(unsigned int),
270 .proc_handler = &proc_dointvec_minmax,
271 .strategy = &sysctl_intvec,
272 .extra1 = &min_wakeup_granularity_ns,
273 .extra2 = &max_wakeup_granularity_ns,
276 .ctl_name = CTL_UNNUMBERED,
277 .procname = "sched_shares_ratelimit",
278 .data = &sysctl_sched_shares_ratelimit,
279 .maxlen = sizeof(unsigned int),
281 .proc_handler = &proc_dointvec,
284 .ctl_name = CTL_UNNUMBERED,
285 .procname = "sched_child_runs_first",
286 .data = &sysctl_sched_child_runs_first,
287 .maxlen = sizeof(unsigned int),
289 .proc_handler = &proc_dointvec,
292 .ctl_name = CTL_UNNUMBERED,
293 .procname = "sched_features",
294 .data = &sysctl_sched_features,
295 .maxlen = sizeof(unsigned int),
297 .proc_handler = &proc_dointvec,
300 .ctl_name = CTL_UNNUMBERED,
301 .procname = "sched_migration_cost",
302 .data = &sysctl_sched_migration_cost,
303 .maxlen = sizeof(unsigned int),
305 .proc_handler = &proc_dointvec,
308 .ctl_name = CTL_UNNUMBERED,
309 .procname = "sched_nr_migrate",
310 .data = &sysctl_sched_nr_migrate,
311 .maxlen = sizeof(unsigned int),
313 .proc_handler = &proc_dointvec,
317 .ctl_name = CTL_UNNUMBERED,
318 .procname = "sched_rt_period_us",
319 .data = &sysctl_sched_rt_period,
320 .maxlen = sizeof(unsigned int),
322 .proc_handler = &sched_rt_handler,
325 .ctl_name = CTL_UNNUMBERED,
326 .procname = "sched_rt_runtime_us",
327 .data = &sysctl_sched_rt_runtime,
328 .maxlen = sizeof(int),
330 .proc_handler = &sched_rt_handler,
333 .ctl_name = CTL_UNNUMBERED,
334 .procname = "sched_compat_yield",
335 .data = &sysctl_sched_compat_yield,
336 .maxlen = sizeof(unsigned int),
338 .proc_handler = &proc_dointvec,
340 #ifdef CONFIG_PROVE_LOCKING
342 .ctl_name = CTL_UNNUMBERED,
343 .procname = "prove_locking",
344 .data = &prove_locking,
345 .maxlen = sizeof(int),
347 .proc_handler = &proc_dointvec,
350 #ifdef CONFIG_LOCK_STAT
352 .ctl_name = CTL_UNNUMBERED,
353 .procname = "lock_stat",
355 .maxlen = sizeof(int),
357 .proc_handler = &proc_dointvec,
361 .ctl_name = KERN_PANIC,
363 .data = &panic_timeout,
364 .maxlen = sizeof(int),
366 .proc_handler = &proc_dointvec,
369 .ctl_name = KERN_CORE_USES_PID,
370 .procname = "core_uses_pid",
371 .data = &core_uses_pid,
372 .maxlen = sizeof(int),
374 .proc_handler = &proc_dointvec,
377 .ctl_name = KERN_CORE_PATTERN,
378 .procname = "core_pattern",
379 .data = core_pattern,
380 .maxlen = CORENAME_MAX_SIZE,
382 .proc_handler = &proc_dostring,
383 .strategy = &sysctl_string,
385 #ifdef CONFIG_PROC_SYSCTL
387 .procname = "tainted",
389 .maxlen = sizeof(int),
391 .proc_handler = &proc_dointvec_taint,
394 #ifdef CONFIG_LATENCYTOP
396 .procname = "latencytop",
397 .data = &latencytop_enabled,
398 .maxlen = sizeof(int),
400 .proc_handler = &proc_dointvec,
403 #ifdef CONFIG_BLK_DEV_INITRD
405 .ctl_name = KERN_REALROOTDEV,
406 .procname = "real-root-dev",
407 .data = &real_root_dev,
408 .maxlen = sizeof(int),
410 .proc_handler = &proc_dointvec,
414 .ctl_name = CTL_UNNUMBERED,
415 .procname = "print-fatal-signals",
416 .data = &print_fatal_signals,
417 .maxlen = sizeof(int),
419 .proc_handler = &proc_dointvec,
423 .ctl_name = KERN_SPARC_REBOOT,
424 .procname = "reboot-cmd",
425 .data = reboot_command,
428 .proc_handler = &proc_dostring,
429 .strategy = &sysctl_string,
432 .ctl_name = KERN_SPARC_STOP_A,
433 .procname = "stop-a",
434 .data = &stop_a_enabled,
435 .maxlen = sizeof (int),
437 .proc_handler = &proc_dointvec,
440 .ctl_name = KERN_SPARC_SCONS_PWROFF,
441 .procname = "scons-poweroff",
442 .data = &scons_pwroff,
443 .maxlen = sizeof (int),
445 .proc_handler = &proc_dointvec,
450 .ctl_name = KERN_HPPA_PWRSW,
451 .procname = "soft-power",
452 .data = &pwrsw_enabled,
453 .maxlen = sizeof (int),
455 .proc_handler = &proc_dointvec,
458 .ctl_name = KERN_HPPA_UNALIGNED,
459 .procname = "unaligned-trap",
460 .data = &unaligned_enabled,
461 .maxlen = sizeof (int),
463 .proc_handler = &proc_dointvec,
467 .ctl_name = KERN_CTLALTDEL,
468 .procname = "ctrl-alt-del",
470 .maxlen = sizeof(int),
472 .proc_handler = &proc_dointvec,
476 .ctl_name = CTL_UNNUMBERED,
477 .procname = "ftrace_enabled",
478 .data = &ftrace_enabled,
479 .maxlen = sizeof(int),
481 .proc_handler = &ftrace_enable_sysctl,
484 #ifdef CONFIG_MODULES
486 .ctl_name = KERN_MODPROBE,
487 .procname = "modprobe",
488 .data = &modprobe_path,
489 .maxlen = KMOD_PATH_LEN,
491 .proc_handler = &proc_dostring,
492 .strategy = &sysctl_string,
495 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
497 .ctl_name = KERN_HOTPLUG,
498 .procname = "hotplug",
499 .data = &uevent_helper,
500 .maxlen = UEVENT_HELPER_PATH_LEN,
502 .proc_handler = &proc_dostring,
503 .strategy = &sysctl_string,
506 #ifdef CONFIG_CHR_DEV_SG
508 .ctl_name = KERN_SG_BIG_BUFF,
509 .procname = "sg-big-buff",
510 .data = &sg_big_buff,
511 .maxlen = sizeof (int),
513 .proc_handler = &proc_dointvec,
516 #ifdef CONFIG_BSD_PROCESS_ACCT
518 .ctl_name = KERN_ACCT,
521 .maxlen = 3*sizeof(int),
523 .proc_handler = &proc_dointvec,
526 #ifdef CONFIG_MAGIC_SYSRQ
528 .ctl_name = KERN_SYSRQ,
530 .data = &__sysrq_enabled,
531 .maxlen = sizeof (int),
533 .proc_handler = &proc_dointvec,
536 #ifdef CONFIG_PROC_SYSCTL
538 .procname = "cad_pid",
540 .maxlen = sizeof (int),
542 .proc_handler = &proc_do_cad_pid,
546 .ctl_name = KERN_MAX_THREADS,
547 .procname = "threads-max",
548 .data = &max_threads,
549 .maxlen = sizeof(int),
551 .proc_handler = &proc_dointvec,
554 .ctl_name = KERN_RANDOM,
555 .procname = "random",
557 .child = random_table,
560 .ctl_name = KERN_OVERFLOWUID,
561 .procname = "overflowuid",
562 .data = &overflowuid,
563 .maxlen = sizeof(int),
565 .proc_handler = &proc_dointvec_minmax,
566 .strategy = &sysctl_intvec,
567 .extra1 = &minolduid,
568 .extra2 = &maxolduid,
571 .ctl_name = KERN_OVERFLOWGID,
572 .procname = "overflowgid",
573 .data = &overflowgid,
574 .maxlen = sizeof(int),
576 .proc_handler = &proc_dointvec_minmax,
577 .strategy = &sysctl_intvec,
578 .extra1 = &minolduid,
579 .extra2 = &maxolduid,
582 #ifdef CONFIG_MATHEMU
584 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
585 .procname = "ieee_emulation_warnings",
586 .data = &sysctl_ieee_emulation_warnings,
587 .maxlen = sizeof(int),
589 .proc_handler = &proc_dointvec,
593 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
594 .procname = "userprocess_debug",
595 .data = &sysctl_userprocess_debug,
596 .maxlen = sizeof(int),
598 .proc_handler = &proc_dointvec,
602 .ctl_name = KERN_PIDMAX,
603 .procname = "pid_max",
605 .maxlen = sizeof (int),
607 .proc_handler = &proc_dointvec_minmax,
608 .strategy = sysctl_intvec,
609 .extra1 = &pid_max_min,
610 .extra2 = &pid_max_max,
613 .ctl_name = KERN_PANIC_ON_OOPS,
614 .procname = "panic_on_oops",
615 .data = &panic_on_oops,
616 .maxlen = sizeof(int),
618 .proc_handler = &proc_dointvec,
620 #if defined CONFIG_PRINTK
622 .ctl_name = KERN_PRINTK,
623 .procname = "printk",
624 .data = &console_loglevel,
625 .maxlen = 4*sizeof(int),
627 .proc_handler = &proc_dointvec,
630 .ctl_name = KERN_PRINTK_RATELIMIT,
631 .procname = "printk_ratelimit",
632 .data = &printk_ratelimit_state.interval,
633 .maxlen = sizeof(int),
635 .proc_handler = &proc_dointvec_jiffies,
636 .strategy = &sysctl_jiffies,
639 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
640 .procname = "printk_ratelimit_burst",
641 .data = &printk_ratelimit_state.burst,
642 .maxlen = sizeof(int),
644 .proc_handler = &proc_dointvec,
648 .ctl_name = KERN_NGROUPS_MAX,
649 .procname = "ngroups_max",
650 .data = &ngroups_max,
651 .maxlen = sizeof (int),
653 .proc_handler = &proc_dointvec,
655 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
657 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
658 .procname = "unknown_nmi_panic",
659 .data = &unknown_nmi_panic,
660 .maxlen = sizeof (int),
662 .proc_handler = &proc_dointvec,
665 .procname = "nmi_watchdog",
666 .data = &nmi_watchdog_enabled,
667 .maxlen = sizeof (int),
669 .proc_handler = &proc_nmi_enabled,
672 #if defined(CONFIG_X86)
674 .ctl_name = KERN_PANIC_ON_NMI,
675 .procname = "panic_on_unrecovered_nmi",
676 .data = &panic_on_unrecovered_nmi,
677 .maxlen = sizeof(int),
679 .proc_handler = &proc_dointvec,
682 .ctl_name = KERN_BOOTLOADER_TYPE,
683 .procname = "bootloader_type",
684 .data = &bootloader_type,
685 .maxlen = sizeof (int),
687 .proc_handler = &proc_dointvec,
690 .ctl_name = CTL_UNNUMBERED,
691 .procname = "kstack_depth_to_print",
692 .data = &kstack_depth_to_print,
693 .maxlen = sizeof(int),
695 .proc_handler = &proc_dointvec,
698 .ctl_name = CTL_UNNUMBERED,
699 .procname = "io_delay_type",
700 .data = &io_delay_type,
701 .maxlen = sizeof(int),
703 .proc_handler = &proc_dointvec,
706 #if defined(CONFIG_MMU)
708 .ctl_name = KERN_RANDOMIZE,
709 .procname = "randomize_va_space",
710 .data = &randomize_va_space,
711 .maxlen = sizeof(int),
713 .proc_handler = &proc_dointvec,
716 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
718 .ctl_name = KERN_SPIN_RETRY,
719 .procname = "spin_retry",
721 .maxlen = sizeof (int),
723 .proc_handler = &proc_dointvec,
726 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
728 .procname = "acpi_video_flags",
729 .data = &acpi_realmode_flags,
730 .maxlen = sizeof (unsigned long),
732 .proc_handler = &proc_doulongvec_minmax,
737 .ctl_name = KERN_IA64_UNALIGNED,
738 .procname = "ignore-unaligned-usertrap",
739 .data = &no_unaligned_warning,
740 .maxlen = sizeof (int),
742 .proc_handler = &proc_dointvec,
745 #ifdef CONFIG_DETECT_SOFTLOCKUP
747 .ctl_name = CTL_UNNUMBERED,
748 .procname = "softlockup_panic",
749 .data = &softlockup_panic,
750 .maxlen = sizeof(int),
752 .proc_handler = &proc_dointvec_minmax,
753 .strategy = &sysctl_intvec,
758 .ctl_name = CTL_UNNUMBERED,
759 .procname = "softlockup_thresh",
760 .data = &softlockup_thresh,
761 .maxlen = sizeof(int),
763 .proc_handler = &proc_dointvec_minmax,
764 .strategy = &sysctl_intvec,
769 .ctl_name = CTL_UNNUMBERED,
770 .procname = "hung_task_check_count",
771 .data = &sysctl_hung_task_check_count,
772 .maxlen = sizeof(unsigned long),
774 .proc_handler = &proc_doulongvec_minmax,
775 .strategy = &sysctl_intvec,
778 .ctl_name = CTL_UNNUMBERED,
779 .procname = "hung_task_timeout_secs",
780 .data = &sysctl_hung_task_timeout_secs,
781 .maxlen = sizeof(unsigned long),
783 .proc_handler = &proc_doulongvec_minmax,
784 .strategy = &sysctl_intvec,
787 .ctl_name = CTL_UNNUMBERED,
788 .procname = "hung_task_warnings",
789 .data = &sysctl_hung_task_warnings,
790 .maxlen = sizeof(unsigned long),
792 .proc_handler = &proc_doulongvec_minmax,
793 .strategy = &sysctl_intvec,
798 .ctl_name = KERN_COMPAT_LOG,
799 .procname = "compat-log",
801 .maxlen = sizeof (int),
803 .proc_handler = &proc_dointvec,
806 #ifdef CONFIG_RT_MUTEXES
808 .ctl_name = KERN_MAX_LOCK_DEPTH,
809 .procname = "max_lock_depth",
810 .data = &max_lock_depth,
811 .maxlen = sizeof(int),
813 .proc_handler = &proc_dointvec,
816 #ifdef CONFIG_PROC_FS
818 .ctl_name = CTL_UNNUMBERED,
819 .procname = "maps_protect",
820 .data = &maps_protect,
821 .maxlen = sizeof(int),
823 .proc_handler = &proc_dointvec,
827 .ctl_name = CTL_UNNUMBERED,
828 .procname = "poweroff_cmd",
829 .data = &poweroff_cmd,
830 .maxlen = POWEROFF_CMD_PATH_LEN,
832 .proc_handler = &proc_dostring,
833 .strategy = &sysctl_string,
837 .ctl_name = CTL_UNNUMBERED,
840 .child = key_sysctls,
843 #ifdef CONFIG_RCU_TORTURE_TEST
845 .ctl_name = CTL_UNNUMBERED,
846 .procname = "rcutorture_runnable",
847 .data = &rcutorture_runnable,
848 .maxlen = sizeof(int),
850 .proc_handler = &proc_dointvec,
854 * NOTE: do not add new entries to this table unless you have read
855 * Documentation/sysctl/ctl_unnumbered.txt
860 static struct ctl_table vm_table[] = {
862 .ctl_name = VM_OVERCOMMIT_MEMORY,
863 .procname = "overcommit_memory",
864 .data = &sysctl_overcommit_memory,
865 .maxlen = sizeof(sysctl_overcommit_memory),
867 .proc_handler = &proc_dointvec,
870 .ctl_name = VM_PANIC_ON_OOM,
871 .procname = "panic_on_oom",
872 .data = &sysctl_panic_on_oom,
873 .maxlen = sizeof(sysctl_panic_on_oom),
875 .proc_handler = &proc_dointvec,
878 .ctl_name = CTL_UNNUMBERED,
879 .procname = "oom_kill_allocating_task",
880 .data = &sysctl_oom_kill_allocating_task,
881 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
883 .proc_handler = &proc_dointvec,
886 .ctl_name = CTL_UNNUMBERED,
887 .procname = "oom_dump_tasks",
888 .data = &sysctl_oom_dump_tasks,
889 .maxlen = sizeof(sysctl_oom_dump_tasks),
891 .proc_handler = &proc_dointvec,
894 .ctl_name = VM_OVERCOMMIT_RATIO,
895 .procname = "overcommit_ratio",
896 .data = &sysctl_overcommit_ratio,
897 .maxlen = sizeof(sysctl_overcommit_ratio),
899 .proc_handler = &proc_dointvec,
902 .ctl_name = VM_PAGE_CLUSTER,
903 .procname = "page-cluster",
904 .data = &page_cluster,
905 .maxlen = sizeof(int),
907 .proc_handler = &proc_dointvec,
910 .ctl_name = VM_DIRTY_BACKGROUND,
911 .procname = "dirty_background_ratio",
912 .data = &dirty_background_ratio,
913 .maxlen = sizeof(dirty_background_ratio),
915 .proc_handler = &proc_dointvec_minmax,
916 .strategy = &sysctl_intvec,
918 .extra2 = &one_hundred,
921 .ctl_name = VM_DIRTY_RATIO,
922 .procname = "dirty_ratio",
923 .data = &vm_dirty_ratio,
924 .maxlen = sizeof(vm_dirty_ratio),
926 .proc_handler = &dirty_ratio_handler,
927 .strategy = &sysctl_intvec,
929 .extra2 = &one_hundred,
932 .procname = "dirty_writeback_centisecs",
933 .data = &dirty_writeback_interval,
934 .maxlen = sizeof(dirty_writeback_interval),
936 .proc_handler = &dirty_writeback_centisecs_handler,
939 .procname = "dirty_expire_centisecs",
940 .data = &dirty_expire_interval,
941 .maxlen = sizeof(dirty_expire_interval),
943 .proc_handler = &proc_dointvec_userhz_jiffies,
946 .ctl_name = VM_NR_PDFLUSH_THREADS,
947 .procname = "nr_pdflush_threads",
948 .data = &nr_pdflush_threads,
949 .maxlen = sizeof nr_pdflush_threads,
950 .mode = 0444 /* read-only*/,
951 .proc_handler = &proc_dointvec,
954 .ctl_name = VM_SWAPPINESS,
955 .procname = "swappiness",
956 .data = &vm_swappiness,
957 .maxlen = sizeof(vm_swappiness),
959 .proc_handler = &proc_dointvec_minmax,
960 .strategy = &sysctl_intvec,
962 .extra2 = &one_hundred,
964 #ifdef CONFIG_HUGETLB_PAGE
966 .procname = "nr_hugepages",
968 .maxlen = sizeof(unsigned long),
970 .proc_handler = &hugetlb_sysctl_handler,
971 .extra1 = (void *)&hugetlb_zero,
972 .extra2 = (void *)&hugetlb_infinity,
975 .ctl_name = VM_HUGETLB_GROUP,
976 .procname = "hugetlb_shm_group",
977 .data = &sysctl_hugetlb_shm_group,
978 .maxlen = sizeof(gid_t),
980 .proc_handler = &proc_dointvec,
983 .ctl_name = CTL_UNNUMBERED,
984 .procname = "hugepages_treat_as_movable",
985 .data = &hugepages_treat_as_movable,
986 .maxlen = sizeof(int),
988 .proc_handler = &hugetlb_treat_movable_handler,
991 .ctl_name = CTL_UNNUMBERED,
992 .procname = "nr_overcommit_hugepages",
994 .maxlen = sizeof(unsigned long),
996 .proc_handler = &hugetlb_overcommit_handler,
997 .extra1 = (void *)&hugetlb_zero,
998 .extra2 = (void *)&hugetlb_infinity,
1002 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1003 .procname = "lowmem_reserve_ratio",
1004 .data = &sysctl_lowmem_reserve_ratio,
1005 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1007 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1008 .strategy = &sysctl_intvec,
1011 .ctl_name = VM_DROP_PAGECACHE,
1012 .procname = "drop_caches",
1013 .data = &sysctl_drop_caches,
1014 .maxlen = sizeof(int),
1016 .proc_handler = drop_caches_sysctl_handler,
1017 .strategy = &sysctl_intvec,
1020 .ctl_name = VM_MIN_FREE_KBYTES,
1021 .procname = "min_free_kbytes",
1022 .data = &min_free_kbytes,
1023 .maxlen = sizeof(min_free_kbytes),
1025 .proc_handler = &min_free_kbytes_sysctl_handler,
1026 .strategy = &sysctl_intvec,
1030 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1031 .procname = "percpu_pagelist_fraction",
1032 .data = &percpu_pagelist_fraction,
1033 .maxlen = sizeof(percpu_pagelist_fraction),
1035 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1036 .strategy = &sysctl_intvec,
1037 .extra1 = &min_percpu_pagelist_fract,
1041 .ctl_name = VM_MAX_MAP_COUNT,
1042 .procname = "max_map_count",
1043 .data = &sysctl_max_map_count,
1044 .maxlen = sizeof(sysctl_max_map_count),
1046 .proc_handler = &proc_dointvec
1050 .ctl_name = VM_LAPTOP_MODE,
1051 .procname = "laptop_mode",
1052 .data = &laptop_mode,
1053 .maxlen = sizeof(laptop_mode),
1055 .proc_handler = &proc_dointvec_jiffies,
1056 .strategy = &sysctl_jiffies,
1059 .ctl_name = VM_BLOCK_DUMP,
1060 .procname = "block_dump",
1061 .data = &block_dump,
1062 .maxlen = sizeof(block_dump),
1064 .proc_handler = &proc_dointvec,
1065 .strategy = &sysctl_intvec,
1069 .ctl_name = VM_VFS_CACHE_PRESSURE,
1070 .procname = "vfs_cache_pressure",
1071 .data = &sysctl_vfs_cache_pressure,
1072 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1074 .proc_handler = &proc_dointvec,
1075 .strategy = &sysctl_intvec,
1078 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1080 .ctl_name = VM_LEGACY_VA_LAYOUT,
1081 .procname = "legacy_va_layout",
1082 .data = &sysctl_legacy_va_layout,
1083 .maxlen = sizeof(sysctl_legacy_va_layout),
1085 .proc_handler = &proc_dointvec,
1086 .strategy = &sysctl_intvec,
1092 .ctl_name = VM_ZONE_RECLAIM_MODE,
1093 .procname = "zone_reclaim_mode",
1094 .data = &zone_reclaim_mode,
1095 .maxlen = sizeof(zone_reclaim_mode),
1097 .proc_handler = &proc_dointvec,
1098 .strategy = &sysctl_intvec,
1102 .ctl_name = VM_MIN_UNMAPPED,
1103 .procname = "min_unmapped_ratio",
1104 .data = &sysctl_min_unmapped_ratio,
1105 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1107 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1108 .strategy = &sysctl_intvec,
1110 .extra2 = &one_hundred,
1113 .ctl_name = VM_MIN_SLAB,
1114 .procname = "min_slab_ratio",
1115 .data = &sysctl_min_slab_ratio,
1116 .maxlen = sizeof(sysctl_min_slab_ratio),
1118 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1119 .strategy = &sysctl_intvec,
1121 .extra2 = &one_hundred,
1126 .ctl_name = CTL_UNNUMBERED,
1127 .procname = "stat_interval",
1128 .data = &sysctl_stat_interval,
1129 .maxlen = sizeof(sysctl_stat_interval),
1131 .proc_handler = &proc_dointvec_jiffies,
1132 .strategy = &sysctl_jiffies,
1136 .ctl_name = CTL_UNNUMBERED,
1137 .procname = "mmap_min_addr",
1138 .data = &mmap_min_addr,
1139 .maxlen = sizeof(unsigned long),
1141 .proc_handler = &proc_doulongvec_minmax,
1145 .ctl_name = CTL_UNNUMBERED,
1146 .procname = "numa_zonelist_order",
1147 .data = &numa_zonelist_order,
1148 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1150 .proc_handler = &numa_zonelist_order_handler,
1151 .strategy = &sysctl_string,
1154 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1155 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1157 .ctl_name = VM_VDSO_ENABLED,
1158 .procname = "vdso_enabled",
1159 .data = &vdso_enabled,
1160 .maxlen = sizeof(vdso_enabled),
1162 .proc_handler = &proc_dointvec,
1163 .strategy = &sysctl_intvec,
1167 #ifdef CONFIG_HIGHMEM
1169 .ctl_name = CTL_UNNUMBERED,
1170 .procname = "highmem_is_dirtyable",
1171 .data = &vm_highmem_is_dirtyable,
1172 .maxlen = sizeof(vm_highmem_is_dirtyable),
1174 .proc_handler = &proc_dointvec_minmax,
1175 .strategy = &sysctl_intvec,
1181 * NOTE: do not add new entries to this table unless you have read
1182 * Documentation/sysctl/ctl_unnumbered.txt
1187 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1188 static struct ctl_table binfmt_misc_table[] = {
1193 static struct ctl_table fs_table[] = {
1195 .ctl_name = FS_NRINODE,
1196 .procname = "inode-nr",
1197 .data = &inodes_stat,
1198 .maxlen = 2*sizeof(int),
1200 .proc_handler = &proc_dointvec,
1203 .ctl_name = FS_STATINODE,
1204 .procname = "inode-state",
1205 .data = &inodes_stat,
1206 .maxlen = 7*sizeof(int),
1208 .proc_handler = &proc_dointvec,
1211 .procname = "file-nr",
1212 .data = &files_stat,
1213 .maxlen = 3*sizeof(int),
1215 .proc_handler = &proc_nr_files,
1218 .ctl_name = FS_MAXFILE,
1219 .procname = "file-max",
1220 .data = &files_stat.max_files,
1221 .maxlen = sizeof(int),
1223 .proc_handler = &proc_dointvec,
1226 .ctl_name = CTL_UNNUMBERED,
1227 .procname = "nr_open",
1228 .data = &sysctl_nr_open,
1229 .maxlen = sizeof(int),
1231 .proc_handler = &proc_dointvec_minmax,
1232 .extra1 = &sysctl_nr_open_min,
1233 .extra2 = &sysctl_nr_open_max,
1236 .ctl_name = FS_DENTRY,
1237 .procname = "dentry-state",
1238 .data = &dentry_stat,
1239 .maxlen = 6*sizeof(int),
1241 .proc_handler = &proc_dointvec,
1244 .ctl_name = FS_OVERFLOWUID,
1245 .procname = "overflowuid",
1246 .data = &fs_overflowuid,
1247 .maxlen = sizeof(int),
1249 .proc_handler = &proc_dointvec_minmax,
1250 .strategy = &sysctl_intvec,
1251 .extra1 = &minolduid,
1252 .extra2 = &maxolduid,
1255 .ctl_name = FS_OVERFLOWGID,
1256 .procname = "overflowgid",
1257 .data = &fs_overflowgid,
1258 .maxlen = sizeof(int),
1260 .proc_handler = &proc_dointvec_minmax,
1261 .strategy = &sysctl_intvec,
1262 .extra1 = &minolduid,
1263 .extra2 = &maxolduid,
1266 .ctl_name = FS_LEASES,
1267 .procname = "leases-enable",
1268 .data = &leases_enable,
1269 .maxlen = sizeof(int),
1271 .proc_handler = &proc_dointvec,
1273 #ifdef CONFIG_DNOTIFY
1275 .ctl_name = FS_DIR_NOTIFY,
1276 .procname = "dir-notify-enable",
1277 .data = &dir_notify_enable,
1278 .maxlen = sizeof(int),
1280 .proc_handler = &proc_dointvec,
1285 .ctl_name = FS_LEASE_TIME,
1286 .procname = "lease-break-time",
1287 .data = &lease_break_time,
1288 .maxlen = sizeof(int),
1290 .proc_handler = &proc_dointvec_minmax,
1291 .strategy = &sysctl_intvec,
1296 .procname = "aio-nr",
1298 .maxlen = sizeof(aio_nr),
1300 .proc_handler = &proc_doulongvec_minmax,
1303 .procname = "aio-max-nr",
1304 .data = &aio_max_nr,
1305 .maxlen = sizeof(aio_max_nr),
1307 .proc_handler = &proc_doulongvec_minmax,
1309 #ifdef CONFIG_INOTIFY_USER
1311 .ctl_name = FS_INOTIFY,
1312 .procname = "inotify",
1314 .child = inotify_table,
1319 .procname = "epoll",
1321 .child = epoll_table,
1326 .ctl_name = KERN_SETUID_DUMPABLE,
1327 .procname = "suid_dumpable",
1328 .data = &suid_dumpable,
1329 .maxlen = sizeof(int),
1331 .proc_handler = &proc_dointvec,
1333 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1335 .ctl_name = CTL_UNNUMBERED,
1336 .procname = "binfmt_misc",
1338 .child = binfmt_misc_table,
1342 * NOTE: do not add new entries to this table unless you have read
1343 * Documentation/sysctl/ctl_unnumbered.txt
1348 static struct ctl_table debug_table[] = {
1349 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1351 .ctl_name = CTL_UNNUMBERED,
1352 .procname = "exception-trace",
1353 .data = &show_unhandled_signals,
1354 .maxlen = sizeof(int),
1356 .proc_handler = proc_dointvec
1362 static struct ctl_table dev_table[] = {
1366 static DEFINE_SPINLOCK(sysctl_lock);
1368 /* called under sysctl_lock */
1369 static int use_table(struct ctl_table_header *p)
1371 if (unlikely(p->unregistering))
1377 /* called under sysctl_lock */
1378 static void unuse_table(struct ctl_table_header *p)
1381 if (unlikely(p->unregistering))
1382 complete(p->unregistering);
1385 /* called under sysctl_lock, will reacquire if has to wait */
1386 static void start_unregistering(struct ctl_table_header *p)
1389 * if p->used is 0, nobody will ever touch that entry again;
1390 * we'll eliminate all paths to it before dropping sysctl_lock
1392 if (unlikely(p->used)) {
1393 struct completion wait;
1394 init_completion(&wait);
1395 p->unregistering = &wait;
1396 spin_unlock(&sysctl_lock);
1397 wait_for_completion(&wait);
1398 spin_lock(&sysctl_lock);
1400 /* anything non-NULL; we'll never dereference it */
1401 p->unregistering = ERR_PTR(-EINVAL);
1404 * do not remove from the list until nobody holds it; walking the
1405 * list in do_sysctl() relies on that.
1407 list_del_init(&p->ctl_entry);
1410 void sysctl_head_get(struct ctl_table_header *head)
1412 spin_lock(&sysctl_lock);
1414 spin_unlock(&sysctl_lock);
1417 void sysctl_head_put(struct ctl_table_header *head)
1419 spin_lock(&sysctl_lock);
1422 spin_unlock(&sysctl_lock);
1425 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1429 spin_lock(&sysctl_lock);
1430 if (!use_table(head))
1431 head = ERR_PTR(-ENOENT);
1432 spin_unlock(&sysctl_lock);
1436 void sysctl_head_finish(struct ctl_table_header *head)
1440 spin_lock(&sysctl_lock);
1442 spin_unlock(&sysctl_lock);
1445 static struct ctl_table_set *
1446 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1448 struct ctl_table_set *set = &root->default_set;
1450 set = root->lookup(root, namespaces);
1454 static struct list_head *
1455 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1457 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1461 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1462 struct ctl_table_header *prev)
1464 struct ctl_table_root *root;
1465 struct list_head *header_list;
1466 struct ctl_table_header *head;
1467 struct list_head *tmp;
1469 spin_lock(&sysctl_lock);
1472 tmp = &prev->ctl_entry;
1476 tmp = &root_table_header.ctl_entry;
1478 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1480 if (!use_table(head))
1482 spin_unlock(&sysctl_lock);
1487 header_list = lookup_header_list(root, namespaces);
1488 if (tmp != header_list)
1492 root = list_entry(root->root_list.next,
1493 struct ctl_table_root, root_list);
1494 if (root == &sysctl_table_root)
1496 header_list = lookup_header_list(root, namespaces);
1497 } while (list_empty(header_list));
1498 tmp = header_list->next;
1501 spin_unlock(&sysctl_lock);
1505 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1507 return __sysctl_head_next(current->nsproxy, prev);
1510 void register_sysctl_root(struct ctl_table_root *root)
1512 spin_lock(&sysctl_lock);
1513 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1514 spin_unlock(&sysctl_lock);
1517 #ifdef CONFIG_SYSCTL_SYSCALL
1518 /* Perform the actual read/write of a sysctl table entry. */
1519 static int do_sysctl_strategy(struct ctl_table_root *root,
1520 struct ctl_table *table,
1521 int __user *name, int nlen,
1522 void __user *oldval, size_t __user *oldlenp,
1523 void __user *newval, size_t newlen)
1531 if (sysctl_perm(root, table, op))
1534 if (table->strategy) {
1535 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1543 /* If there is no strategy routine, or if the strategy returns
1544 * zero, proceed with automatic r/w */
1545 if (table->data && table->maxlen) {
1546 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1554 static int parse_table(int __user *name, int nlen,
1555 void __user *oldval, size_t __user *oldlenp,
1556 void __user *newval, size_t newlen,
1557 struct ctl_table_root *root,
1558 struct ctl_table *table)
1564 if (get_user(n, name))
1566 for ( ; table->ctl_name || table->procname; table++) {
1567 if (!table->ctl_name)
1569 if (n == table->ctl_name) {
1572 if (sysctl_perm(root, table, MAY_EXEC))
1576 table = table->child;
1579 error = do_sysctl_strategy(root, table, name, nlen,
1588 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1589 void __user *newval, size_t newlen)
1591 struct ctl_table_header *head;
1592 int error = -ENOTDIR;
1594 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1598 if (!oldlenp || get_user(old_len, oldlenp))
1602 for (head = sysctl_head_next(NULL); head;
1603 head = sysctl_head_next(head)) {
1604 error = parse_table(name, nlen, oldval, oldlenp,
1606 head->root, head->ctl_table);
1607 if (error != -ENOTDIR) {
1608 sysctl_head_finish(head);
1615 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1617 struct __sysctl_args tmp;
1620 if (copy_from_user(&tmp, args, sizeof(tmp)))
1623 error = deprecated_sysctl_warning(&tmp);
1628 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1629 tmp.newval, tmp.newlen);
1634 #endif /* CONFIG_SYSCTL_SYSCALL */
1637 * sysctl_perm does NOT grant the superuser all rights automatically, because
1638 * some sysctl variables are readonly even to root.
1641 static int test_perm(int mode, int op)
1645 else if (in_egroup_p(0))
1647 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1652 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1657 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1661 if (root->permissions)
1662 mode = root->permissions(root, current->nsproxy, table);
1666 return test_perm(mode, op);
1669 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1671 for (; table->ctl_name || table->procname; table++) {
1672 table->parent = parent;
1674 sysctl_set_parent(table, table->child);
1678 static __init int sysctl_init(void)
1680 sysctl_set_parent(NULL, root_table);
1681 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1684 err = sysctl_check_table(current->nsproxy, root_table);
1690 core_initcall(sysctl_init);
1692 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1693 struct ctl_table *table)
1695 struct ctl_table *p;
1696 const char *s = branch->procname;
1698 /* branch should have named subdirectory as its first element */
1699 if (!s || !branch->child)
1702 /* ... and nothing else */
1703 if (branch[1].procname || branch[1].ctl_name)
1706 /* table should contain subdirectory with the same name */
1707 for (p = table; p->procname || p->ctl_name; p++) {
1710 if (p->procname && strcmp(p->procname, s) == 0)
1716 /* see if attaching q to p would be an improvement */
1717 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1719 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1720 struct ctl_table *next;
1722 int not_in_parent = !p->attached_by;
1724 while ((next = is_branch_in(by, to)) != NULL) {
1725 if (by == q->attached_by)
1727 if (to == p->attached_by)
1733 if (is_better && not_in_parent) {
1734 q->attached_by = by;
1735 q->attached_to = to;
1741 * __register_sysctl_paths - register a sysctl hierarchy
1742 * @root: List of sysctl headers to register on
1743 * @namespaces: Data to compute which lists of sysctl entries are visible
1744 * @path: The path to the directory the sysctl table is in.
1745 * @table: the top-level table structure
1747 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1748 * array. A completely 0 filled entry terminates the table.
1750 * The members of the &struct ctl_table structure are used as follows:
1752 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1753 * must be unique within that level of sysctl
1755 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1756 * enter a sysctl file
1758 * data - a pointer to data for use by proc_handler
1760 * maxlen - the maximum size in bytes of the data
1762 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1764 * child - a pointer to the child sysctl table if this entry is a directory, or
1767 * proc_handler - the text handler routine (described below)
1769 * strategy - the strategy routine (described below)
1771 * de - for internal use by the sysctl routines
1773 * extra1, extra2 - extra pointers usable by the proc handler routines
1775 * Leaf nodes in the sysctl tree will be represented by a single file
1776 * under /proc; non-leaf nodes will be represented by directories.
1778 * sysctl(2) can automatically manage read and write requests through
1779 * the sysctl table. The data and maxlen fields of the ctl_table
1780 * struct enable minimal validation of the values being written to be
1781 * performed, and the mode field allows minimal authentication.
1783 * More sophisticated management can be enabled by the provision of a
1784 * strategy routine with the table entry. This will be called before
1785 * any automatic read or write of the data is performed.
1787 * The strategy routine may return
1789 * < 0 - Error occurred (error is passed to user process)
1791 * 0 - OK - proceed with automatic read or write.
1793 * > 0 - OK - read or write has been done by the strategy routine, so
1794 * return immediately.
1796 * There must be a proc_handler routine for any terminal nodes
1797 * mirrored under /proc/sys (non-terminals are handled by a built-in
1798 * directory handler). Several default handlers are available to
1799 * cover common cases -
1801 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1802 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1803 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1805 * It is the handler's job to read the input buffer from user memory
1806 * and process it. The handler should return 0 on success.
1808 * This routine returns %NULL on a failure to register, and a pointer
1809 * to the table header on success.
1811 struct ctl_table_header *__register_sysctl_paths(
1812 struct ctl_table_root *root,
1813 struct nsproxy *namespaces,
1814 const struct ctl_path *path, struct ctl_table *table)
1816 struct ctl_table_header *header;
1817 struct ctl_table *new, **prevp;
1818 unsigned int n, npath;
1819 struct ctl_table_set *set;
1821 /* Count the path components */
1822 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1826 * For each path component, allocate a 2-element ctl_table array.
1827 * The first array element will be filled with the sysctl entry
1828 * for this, the second will be the sentinel (ctl_name == 0).
1830 * We allocate everything in one go so that we don't have to
1831 * worry about freeing additional memory in unregister_sysctl_table.
1833 header = kzalloc(sizeof(struct ctl_table_header) +
1834 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1838 new = (struct ctl_table *) (header + 1);
1840 /* Now connect the dots */
1841 prevp = &header->ctl_table;
1842 for (n = 0; n < npath; ++n, ++path) {
1843 /* Copy the procname */
1844 new->procname = path->procname;
1845 new->ctl_name = path->ctl_name;
1849 prevp = &new->child;
1854 header->ctl_table_arg = table;
1856 INIT_LIST_HEAD(&header->ctl_entry);
1858 header->unregistering = NULL;
1859 header->root = root;
1860 sysctl_set_parent(NULL, header->ctl_table);
1862 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1863 if (sysctl_check_table(namespaces, header->ctl_table)) {
1868 spin_lock(&sysctl_lock);
1869 header->set = lookup_header_set(root, namespaces);
1870 header->attached_by = header->ctl_table;
1871 header->attached_to = root_table;
1872 header->parent = &root_table_header;
1873 for (set = header->set; set; set = set->parent) {
1874 struct ctl_table_header *p;
1875 list_for_each_entry(p, &set->list, ctl_entry) {
1876 if (p->unregistering)
1878 try_attach(p, header);
1881 header->parent->count++;
1882 list_add_tail(&header->ctl_entry, &header->set->list);
1883 spin_unlock(&sysctl_lock);
1889 * register_sysctl_table_path - register a sysctl table hierarchy
1890 * @path: The path to the directory the sysctl table is in.
1891 * @table: the top-level table structure
1893 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1894 * array. A completely 0 filled entry terminates the table.
1896 * See __register_sysctl_paths for more details.
1898 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1899 struct ctl_table *table)
1901 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1906 * register_sysctl_table - register a sysctl table hierarchy
1907 * @table: the top-level table structure
1909 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1910 * array. A completely 0 filled entry terminates the table.
1912 * See register_sysctl_paths for more details.
1914 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1916 static const struct ctl_path null_path[] = { {} };
1918 return register_sysctl_paths(null_path, table);
1922 * unregister_sysctl_table - unregister a sysctl table hierarchy
1923 * @header: the header returned from register_sysctl_table
1925 * Unregisters the sysctl table and all children. proc entries may not
1926 * actually be removed until they are no longer used by anyone.
1928 void unregister_sysctl_table(struct ctl_table_header * header)
1935 spin_lock(&sysctl_lock);
1936 start_unregistering(header);
1937 if (!--header->parent->count) {
1939 kfree(header->parent);
1941 if (!--header->count)
1943 spin_unlock(&sysctl_lock);
1946 int sysctl_is_seen(struct ctl_table_header *p)
1948 struct ctl_table_set *set = p->set;
1950 spin_lock(&sysctl_lock);
1951 if (p->unregistering)
1953 else if (!set->is_seen)
1956 res = set->is_seen(set);
1957 spin_unlock(&sysctl_lock);
1961 void setup_sysctl_set(struct ctl_table_set *p,
1962 struct ctl_table_set *parent,
1963 int (*is_seen)(struct ctl_table_set *))
1965 INIT_LIST_HEAD(&p->list);
1966 p->parent = parent ? parent : &sysctl_table_root.default_set;
1967 p->is_seen = is_seen;
1970 #else /* !CONFIG_SYSCTL */
1971 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1976 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1977 struct ctl_table *table)
1982 void unregister_sysctl_table(struct ctl_table_header * table)
1986 void setup_sysctl_set(struct ctl_table_set *p,
1987 struct ctl_table_set *parent,
1988 int (*is_seen)(struct ctl_table_set *))
1992 void sysctl_head_put(struct ctl_table_header *head)
1996 #endif /* CONFIG_SYSCTL */
2002 #ifdef CONFIG_PROC_SYSCTL
2004 static int _proc_do_string(void* data, int maxlen, int write,
2005 struct file *filp, void __user *buffer,
2006 size_t *lenp, loff_t *ppos)
2012 if (!data || !maxlen || !*lenp) {
2020 while (len < *lenp) {
2021 if (get_user(c, p++))
2023 if (c == 0 || c == '\n')
2029 if(copy_from_user(data, buffer, len))
2031 ((char *) data)[len] = 0;
2049 if(copy_to_user(buffer, data, len))
2052 if(put_user('\n', ((char __user *) buffer) + len))
2063 * proc_dostring - read a string sysctl
2064 * @table: the sysctl table
2065 * @write: %TRUE if this is a write to the sysctl file
2066 * @filp: the file structure
2067 * @buffer: the user buffer
2068 * @lenp: the size of the user buffer
2069 * @ppos: file position
2071 * Reads/writes a string from/to the user buffer. If the kernel
2072 * buffer provided is not large enough to hold the string, the
2073 * string is truncated. The copied string is %NULL-terminated.
2074 * If the string is being read by the user process, it is copied
2075 * and a newline '\n' is added. It is truncated if the buffer is
2078 * Returns 0 on success.
2080 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2081 void __user *buffer, size_t *lenp, loff_t *ppos)
2083 return _proc_do_string(table->data, table->maxlen, write, filp,
2084 buffer, lenp, ppos);
2088 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2090 int write, void *data)
2093 *valp = *negp ? -*lvalp : *lvalp;
2098 *lvalp = (unsigned long)-val;
2101 *lvalp = (unsigned long)val;
2107 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2108 int write, struct file *filp, void __user *buffer,
2109 size_t *lenp, loff_t *ppos,
2110 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2111 int write, void *data),
2114 #define TMPBUFLEN 21
2115 int *i, vleft, first=1, neg, val;
2119 char buf[TMPBUFLEN], *p;
2120 char __user *s = buffer;
2122 if (!tbl_data || !table->maxlen || !*lenp ||
2123 (*ppos && !write)) {
2128 i = (int *) tbl_data;
2129 vleft = table->maxlen / sizeof(*i);
2133 conv = do_proc_dointvec_conv;
2135 for (; left && vleft--; i++, first=0) {
2150 if (len > sizeof(buf) - 1)
2151 len = sizeof(buf) - 1;
2152 if (copy_from_user(buf, s, len))
2156 if (*p == '-' && left > 1) {
2160 if (*p < '0' || *p > '9')
2163 lval = simple_strtoul(p, &p, 0);
2166 if ((len < left) && *p && !isspace(*p))
2173 if (conv(&neg, &lval, i, 1, data))
2180 if (conv(&neg, &lval, i, 0, data))
2183 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2187 if(copy_to_user(s, buf, len))
2194 if (!write && !first && left) {
2195 if(put_user('\n', s))
2202 if (get_user(c, s++))
2217 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2218 void __user *buffer, size_t *lenp, loff_t *ppos,
2219 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2220 int write, void *data),
2223 return __do_proc_dointvec(table->data, table, write, filp,
2224 buffer, lenp, ppos, conv, data);
2228 * proc_dointvec - read a vector of integers
2229 * @table: the sysctl table
2230 * @write: %TRUE if this is a write to the sysctl file
2231 * @filp: the file structure
2232 * @buffer: the user buffer
2233 * @lenp: the size of the user buffer
2234 * @ppos: file position
2236 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2237 * values from/to the user buffer, treated as an ASCII string.
2239 * Returns 0 on success.
2241 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2242 void __user *buffer, size_t *lenp, loff_t *ppos)
2244 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2252 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2254 int write, void *data)
2256 int op = *(int *)data;
2258 int val = *negp ? -*lvalp : *lvalp;
2260 case OP_SET: *valp = val; break;
2261 case OP_AND: *valp &= val; break;
2262 case OP_OR: *valp |= val; break;
2268 *lvalp = (unsigned long)-val;
2271 *lvalp = (unsigned long)val;
2278 * Taint values can only be increased
2280 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
2281 void __user *buffer, size_t *lenp, loff_t *ppos)
2285 if (write && !capable(CAP_SYS_ADMIN))
2289 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2290 do_proc_dointvec_bset_conv,&op);
2293 struct do_proc_dointvec_minmax_conv_param {
2298 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2300 int write, void *data)
2302 struct do_proc_dointvec_minmax_conv_param *param = data;
2304 int val = *negp ? -*lvalp : *lvalp;
2305 if ((param->min && *param->min > val) ||
2306 (param->max && *param->max < val))
2313 *lvalp = (unsigned long)-val;
2316 *lvalp = (unsigned long)val;
2323 * proc_dointvec_minmax - read a vector of integers with min/max values
2324 * @table: the sysctl table
2325 * @write: %TRUE if this is a write to the sysctl file
2326 * @filp: the file structure
2327 * @buffer: the user buffer
2328 * @lenp: the size of the user buffer
2329 * @ppos: file position
2331 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2332 * values from/to the user buffer, treated as an ASCII string.
2334 * This routine will ensure the values are within the range specified by
2335 * table->extra1 (min) and table->extra2 (max).
2337 * Returns 0 on success.
2339 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2340 void __user *buffer, size_t *lenp, loff_t *ppos)
2342 struct do_proc_dointvec_minmax_conv_param param = {
2343 .min = (int *) table->extra1,
2344 .max = (int *) table->extra2,
2346 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2347 do_proc_dointvec_minmax_conv, ¶m);
2350 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2352 void __user *buffer,
2353 size_t *lenp, loff_t *ppos,
2354 unsigned long convmul,
2355 unsigned long convdiv)
2357 #define TMPBUFLEN 21
2358 unsigned long *i, *min, *max, val;
2359 int vleft, first=1, neg;
2361 char buf[TMPBUFLEN], *p;
2362 char __user *s = buffer;
2364 if (!data || !table->maxlen || !*lenp ||
2365 (*ppos && !write)) {
2370 i = (unsigned long *) data;
2371 min = (unsigned long *) table->extra1;
2372 max = (unsigned long *) table->extra2;
2373 vleft = table->maxlen / sizeof(unsigned long);
2376 for (; left && vleft--; i++, min++, max++, first=0) {
2391 if (len > TMPBUFLEN-1)
2393 if (copy_from_user(buf, s, len))
2397 if (*p == '-' && left > 1) {
2401 if (*p < '0' || *p > '9')
2403 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2405 if ((len < left) && *p && !isspace(*p))
2414 if ((min && val < *min) || (max && val > *max))
2421 sprintf(p, "%lu", convdiv * (*i) / convmul);
2425 if(copy_to_user(s, buf, len))
2432 if (!write && !first && left) {
2433 if(put_user('\n', s))
2440 if (get_user(c, s++))
2455 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2457 void __user *buffer,
2458 size_t *lenp, loff_t *ppos,
2459 unsigned long convmul,
2460 unsigned long convdiv)
2462 return __do_proc_doulongvec_minmax(table->data, table, write,
2463 filp, buffer, lenp, ppos, convmul, convdiv);
2467 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2468 * @table: the sysctl table
2469 * @write: %TRUE if this is a write to the sysctl file
2470 * @filp: the file structure
2471 * @buffer: the user buffer
2472 * @lenp: the size of the user buffer
2473 * @ppos: file position
2475 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2476 * values from/to the user buffer, treated as an ASCII string.
2478 * This routine will ensure the values are within the range specified by
2479 * table->extra1 (min) and table->extra2 (max).
2481 * Returns 0 on success.
2483 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2484 void __user *buffer, size_t *lenp, loff_t *ppos)
2486 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2490 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2491 * @table: the sysctl table
2492 * @write: %TRUE if this is a write to the sysctl file
2493 * @filp: the file structure
2494 * @buffer: the user buffer
2495 * @lenp: the size of the user buffer
2496 * @ppos: file position
2498 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2499 * values from/to the user buffer, treated as an ASCII string. The values
2500 * are treated as milliseconds, and converted to jiffies when they are stored.
2502 * This routine will ensure the values are within the range specified by
2503 * table->extra1 (min) and table->extra2 (max).
2505 * Returns 0 on success.
2507 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2509 void __user *buffer,
2510 size_t *lenp, loff_t *ppos)
2512 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2513 lenp, ppos, HZ, 1000l);
2517 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2519 int write, void *data)
2522 if (*lvalp > LONG_MAX / HZ)
2524 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2530 lval = (unsigned long)-val;
2533 lval = (unsigned long)val;
2540 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2542 int write, void *data)
2545 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2547 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2553 lval = (unsigned long)-val;
2556 lval = (unsigned long)val;
2558 *lvalp = jiffies_to_clock_t(lval);
2563 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2565 int write, void *data)
2568 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2574 lval = (unsigned long)-val;
2577 lval = (unsigned long)val;
2579 *lvalp = jiffies_to_msecs(lval);
2585 * proc_dointvec_jiffies - read a vector of integers as seconds
2586 * @table: the sysctl table
2587 * @write: %TRUE if this is a write to the sysctl file
2588 * @filp: the file structure
2589 * @buffer: the user buffer
2590 * @lenp: the size of the user buffer
2591 * @ppos: file position
2593 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2594 * values from/to the user buffer, treated as an ASCII string.
2595 * The values read are assumed to be in seconds, and are converted into
2598 * Returns 0 on success.
2600 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2601 void __user *buffer, size_t *lenp, loff_t *ppos)
2603 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2604 do_proc_dointvec_jiffies_conv,NULL);
2608 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2609 * @table: the sysctl table
2610 * @write: %TRUE if this is a write to the sysctl file
2611 * @filp: the file structure
2612 * @buffer: the user buffer
2613 * @lenp: the size of the user buffer
2614 * @ppos: pointer to the file position
2616 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2617 * values from/to the user buffer, treated as an ASCII string.
2618 * The values read are assumed to be in 1/USER_HZ seconds, and
2619 * are converted into jiffies.
2621 * Returns 0 on success.
2623 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2624 void __user *buffer, size_t *lenp, loff_t *ppos)
2626 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2627 do_proc_dointvec_userhz_jiffies_conv,NULL);
2631 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2632 * @table: the sysctl table
2633 * @write: %TRUE if this is a write to the sysctl file
2634 * @filp: the file structure
2635 * @buffer: the user buffer
2636 * @lenp: the size of the user buffer
2637 * @ppos: file position
2638 * @ppos: the current position in the file
2640 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2641 * values from/to the user buffer, treated as an ASCII string.
2642 * The values read are assumed to be in 1/1000 seconds, and
2643 * are converted into jiffies.
2645 * Returns 0 on success.
2647 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2648 void __user *buffer, size_t *lenp, loff_t *ppos)
2650 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2651 do_proc_dointvec_ms_jiffies_conv, NULL);
2654 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2655 void __user *buffer, size_t *lenp, loff_t *ppos)
2657 struct pid *new_pid;
2661 tmp = pid_vnr(cad_pid);
2663 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2664 lenp, ppos, NULL, NULL);
2668 new_pid = find_get_pid(tmp);
2672 put_pid(xchg(&cad_pid, new_pid));
2676 #else /* CONFIG_PROC_FS */
2678 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2679 void __user *buffer, size_t *lenp, loff_t *ppos)
2684 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2685 void __user *buffer, size_t *lenp, loff_t *ppos)
2690 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2691 void __user *buffer, size_t *lenp, loff_t *ppos)
2696 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2697 void __user *buffer, size_t *lenp, loff_t *ppos)
2702 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2703 void __user *buffer, size_t *lenp, loff_t *ppos)
2708 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2709 void __user *buffer, size_t *lenp, loff_t *ppos)
2714 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2715 void __user *buffer, size_t *lenp, loff_t *ppos)
2720 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2722 void __user *buffer,
2723 size_t *lenp, loff_t *ppos)
2729 #endif /* CONFIG_PROC_FS */
2732 #ifdef CONFIG_SYSCTL_SYSCALL
2734 * General sysctl support routines
2737 /* The generic sysctl data routine (used if no strategy routine supplied) */
2738 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2739 void __user *oldval, size_t __user *oldlenp,
2740 void __user *newval, size_t newlen)
2744 /* Get out of I don't have a variable */
2745 if (!table->data || !table->maxlen)
2748 if (oldval && oldlenp) {
2749 if (get_user(len, oldlenp))
2752 if (len > table->maxlen)
2753 len = table->maxlen;
2754 if (copy_to_user(oldval, table->data, len))
2756 if (put_user(len, oldlenp))
2761 if (newval && newlen) {
2762 if (newlen > table->maxlen)
2763 newlen = table->maxlen;
2765 if (copy_from_user(table->data, newval, newlen))
2771 /* The generic string strategy routine: */
2772 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2773 void __user *oldval, size_t __user *oldlenp,
2774 void __user *newval, size_t newlen)
2776 if (!table->data || !table->maxlen)
2779 if (oldval && oldlenp) {
2781 if (get_user(bufsize, oldlenp))
2784 size_t len = strlen(table->data), copied;
2786 /* This shouldn't trigger for a well-formed sysctl */
2787 if (len > table->maxlen)
2788 len = table->maxlen;
2790 /* Copy up to a max of bufsize-1 bytes of the string */
2791 copied = (len >= bufsize) ? bufsize - 1 : len;
2793 if (copy_to_user(oldval, table->data, copied) ||
2794 put_user(0, (char __user *)(oldval + copied)))
2796 if (put_user(len, oldlenp))
2800 if (newval && newlen) {
2801 size_t len = newlen;
2802 if (len > table->maxlen)
2803 len = table->maxlen;
2804 if(copy_from_user(table->data, newval, len))
2806 if (len == table->maxlen)
2808 ((char *) table->data)[len] = 0;
2814 * This function makes sure that all of the integers in the vector
2815 * are between the minimum and maximum values given in the arrays
2816 * table->extra1 and table->extra2, respectively.
2818 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2819 void __user *oldval, size_t __user *oldlenp,
2820 void __user *newval, size_t newlen)
2823 if (newval && newlen) {
2824 int __user *vec = (int __user *) newval;
2825 int *min = (int *) table->extra1;
2826 int *max = (int *) table->extra2;
2830 if (newlen % sizeof(int) != 0)
2833 if (!table->extra1 && !table->extra2)
2836 if (newlen > table->maxlen)
2837 newlen = table->maxlen;
2838 length = newlen / sizeof(int);
2840 for (i = 0; i < length; i++) {
2842 if (get_user(value, vec + i))
2844 if (min && value < min[i])
2846 if (max && value > max[i])
2853 /* Strategy function to convert jiffies to seconds */
2854 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2855 void __user *oldval, size_t __user *oldlenp,
2856 void __user *newval, size_t newlen)
2858 if (oldval && oldlenp) {
2861 if (get_user(olen, oldlenp))
2866 if (olen < sizeof(int))
2869 val = *(int *)(table->data) / HZ;
2870 if (put_user(val, (int __user *)oldval))
2872 if (put_user(sizeof(int), oldlenp))
2876 if (newval && newlen) {
2878 if (newlen != sizeof(int))
2880 if (get_user(new, (int __user *)newval))
2882 *(int *)(table->data) = new*HZ;
2887 /* Strategy function to convert jiffies to seconds */
2888 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2889 void __user *oldval, size_t __user *oldlenp,
2890 void __user *newval, size_t newlen)
2892 if (oldval && oldlenp) {
2895 if (get_user(olen, oldlenp))
2900 if (olen < sizeof(int))
2903 val = jiffies_to_msecs(*(int *)(table->data));
2904 if (put_user(val, (int __user *)oldval))
2906 if (put_user(sizeof(int), oldlenp))
2910 if (newval && newlen) {
2912 if (newlen != sizeof(int))
2914 if (get_user(new, (int __user *)newval))
2916 *(int *)(table->data) = msecs_to_jiffies(new);
2923 #else /* CONFIG_SYSCTL_SYSCALL */
2926 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
2928 struct __sysctl_args tmp;
2931 if (copy_from_user(&tmp, args, sizeof(tmp)))
2934 error = deprecated_sysctl_warning(&tmp);
2936 /* If no error reading the parameters then just -ENOSYS ... */
2943 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2944 void __user *oldval, size_t __user *oldlenp,
2945 void __user *newval, size_t newlen)
2950 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2951 void __user *oldval, size_t __user *oldlenp,
2952 void __user *newval, size_t newlen)
2957 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2958 void __user *oldval, size_t __user *oldlenp,
2959 void __user *newval, size_t newlen)
2964 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2965 void __user *oldval, size_t __user *oldlenp,
2966 void __user *newval, size_t newlen)
2971 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2972 void __user *oldval, size_t __user *oldlenp,
2973 void __user *newval, size_t newlen)
2978 #endif /* CONFIG_SYSCTL_SYSCALL */
2980 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2982 static int msg_count;
2983 int name[CTL_MAXNAME];
2986 /* Check args->nlen. */
2987 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2990 /* Read in the sysctl name for better debug message logging */
2991 for (i = 0; i < args->nlen; i++)
2992 if (get_user(name[i], args->name + i))
2995 /* Ignore accesses to kernel.version */
2996 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2999 if (msg_count < 5) {
3002 "warning: process `%s' used the deprecated sysctl "
3003 "system call with ", current->comm);
3004 for (i = 0; i < args->nlen; i++)
3005 printk("%d.", name[i]);
3012 * No sense putting this after each symbol definition, twice,
3013 * exception granted :-)
3015 EXPORT_SYMBOL(proc_dointvec);
3016 EXPORT_SYMBOL(proc_dointvec_jiffies);
3017 EXPORT_SYMBOL(proc_dointvec_minmax);
3018 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3019 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3020 EXPORT_SYMBOL(proc_dostring);
3021 EXPORT_SYMBOL(proc_doulongvec_minmax);
3022 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3023 EXPORT_SYMBOL(register_sysctl_table);
3024 EXPORT_SYMBOL(register_sysctl_paths);
3025 EXPORT_SYMBOL(sysctl_intvec);
3026 EXPORT_SYMBOL(sysctl_jiffies);
3027 EXPORT_SYMBOL(sysctl_ms_jiffies);
3028 EXPORT_SYMBOL(sysctl_string);
3029 EXPORT_SYMBOL(sysctl_data);
3030 EXPORT_SYMBOL(unregister_sysctl_table);