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;
100 #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
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 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
184 int sysctl_legacy_va_layout;
187 extern int prove_locking;
188 extern int lock_stat;
190 /* The default sysctl tables: */
192 static struct ctl_table root_table[] = {
194 .ctl_name = CTL_KERN,
195 .procname = "kernel",
212 .ctl_name = CTL_DEBUG,
215 .child = debug_table,
224 * NOTE: do not add new entries to this table unless you have read
225 * Documentation/sysctl/ctl_unnumbered.txt
230 #ifdef CONFIG_SCHED_DEBUG
231 static int min_sched_granularity_ns = 100000; /* 100 usecs */
232 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
233 static int min_wakeup_granularity_ns; /* 0 usecs */
234 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
237 static struct ctl_table kern_table[] = {
238 #ifdef CONFIG_SCHED_DEBUG
240 .ctl_name = CTL_UNNUMBERED,
241 .procname = "sched_min_granularity_ns",
242 .data = &sysctl_sched_min_granularity,
243 .maxlen = sizeof(unsigned int),
245 .proc_handler = &sched_nr_latency_handler,
246 .strategy = &sysctl_intvec,
247 .extra1 = &min_sched_granularity_ns,
248 .extra2 = &max_sched_granularity_ns,
251 .ctl_name = CTL_UNNUMBERED,
252 .procname = "sched_latency_ns",
253 .data = &sysctl_sched_latency,
254 .maxlen = sizeof(unsigned int),
256 .proc_handler = &sched_nr_latency_handler,
257 .strategy = &sysctl_intvec,
258 .extra1 = &min_sched_granularity_ns,
259 .extra2 = &max_sched_granularity_ns,
262 .ctl_name = CTL_UNNUMBERED,
263 .procname = "sched_wakeup_granularity_ns",
264 .data = &sysctl_sched_wakeup_granularity,
265 .maxlen = sizeof(unsigned int),
267 .proc_handler = &proc_dointvec_minmax,
268 .strategy = &sysctl_intvec,
269 .extra1 = &min_wakeup_granularity_ns,
270 .extra2 = &max_wakeup_granularity_ns,
273 .ctl_name = CTL_UNNUMBERED,
274 .procname = "sched_shares_ratelimit",
275 .data = &sysctl_sched_shares_ratelimit,
276 .maxlen = sizeof(unsigned int),
278 .proc_handler = &proc_dointvec,
281 .ctl_name = CTL_UNNUMBERED,
282 .procname = "sched_child_runs_first",
283 .data = &sysctl_sched_child_runs_first,
284 .maxlen = sizeof(unsigned int),
286 .proc_handler = &proc_dointvec,
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "sched_features",
291 .data = &sysctl_sched_features,
292 .maxlen = sizeof(unsigned int),
294 .proc_handler = &proc_dointvec,
297 .ctl_name = CTL_UNNUMBERED,
298 .procname = "sched_migration_cost",
299 .data = &sysctl_sched_migration_cost,
300 .maxlen = sizeof(unsigned int),
302 .proc_handler = &proc_dointvec,
305 .ctl_name = CTL_UNNUMBERED,
306 .procname = "sched_nr_migrate",
307 .data = &sysctl_sched_nr_migrate,
308 .maxlen = sizeof(unsigned int),
310 .proc_handler = &proc_dointvec,
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_rt_period_us",
316 .data = &sysctl_sched_rt_period,
317 .maxlen = sizeof(unsigned int),
319 .proc_handler = &sched_rt_handler,
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_rt_runtime_us",
324 .data = &sysctl_sched_rt_runtime,
325 .maxlen = sizeof(int),
327 .proc_handler = &sched_rt_handler,
330 .ctl_name = CTL_UNNUMBERED,
331 .procname = "sched_compat_yield",
332 .data = &sysctl_sched_compat_yield,
333 .maxlen = sizeof(unsigned int),
335 .proc_handler = &proc_dointvec,
337 #ifdef CONFIG_PROVE_LOCKING
339 .ctl_name = CTL_UNNUMBERED,
340 .procname = "prove_locking",
341 .data = &prove_locking,
342 .maxlen = sizeof(int),
344 .proc_handler = &proc_dointvec,
347 #ifdef CONFIG_LOCK_STAT
349 .ctl_name = CTL_UNNUMBERED,
350 .procname = "lock_stat",
352 .maxlen = sizeof(int),
354 .proc_handler = &proc_dointvec,
358 .ctl_name = KERN_PANIC,
360 .data = &panic_timeout,
361 .maxlen = sizeof(int),
363 .proc_handler = &proc_dointvec,
366 .ctl_name = KERN_CORE_USES_PID,
367 .procname = "core_uses_pid",
368 .data = &core_uses_pid,
369 .maxlen = sizeof(int),
371 .proc_handler = &proc_dointvec,
374 .ctl_name = KERN_CORE_PATTERN,
375 .procname = "core_pattern",
376 .data = core_pattern,
377 .maxlen = CORENAME_MAX_SIZE,
379 .proc_handler = &proc_dostring,
380 .strategy = &sysctl_string,
382 #ifdef CONFIG_PROC_SYSCTL
384 .procname = "tainted",
386 .maxlen = sizeof(int),
388 .proc_handler = &proc_dointvec_taint,
391 #ifdef CONFIG_LATENCYTOP
393 .procname = "latencytop",
394 .data = &latencytop_enabled,
395 .maxlen = sizeof(int),
397 .proc_handler = &proc_dointvec,
400 #ifdef CONFIG_BLK_DEV_INITRD
402 .ctl_name = KERN_REALROOTDEV,
403 .procname = "real-root-dev",
404 .data = &real_root_dev,
405 .maxlen = sizeof(int),
407 .proc_handler = &proc_dointvec,
411 .ctl_name = CTL_UNNUMBERED,
412 .procname = "print-fatal-signals",
413 .data = &print_fatal_signals,
414 .maxlen = sizeof(int),
416 .proc_handler = &proc_dointvec,
420 .ctl_name = KERN_SPARC_REBOOT,
421 .procname = "reboot-cmd",
422 .data = reboot_command,
425 .proc_handler = &proc_dostring,
426 .strategy = &sysctl_string,
429 .ctl_name = KERN_SPARC_STOP_A,
430 .procname = "stop-a",
431 .data = &stop_a_enabled,
432 .maxlen = sizeof (int),
434 .proc_handler = &proc_dointvec,
437 .ctl_name = KERN_SPARC_SCONS_PWROFF,
438 .procname = "scons-poweroff",
439 .data = &scons_pwroff,
440 .maxlen = sizeof (int),
442 .proc_handler = &proc_dointvec,
447 .ctl_name = KERN_HPPA_PWRSW,
448 .procname = "soft-power",
449 .data = &pwrsw_enabled,
450 .maxlen = sizeof (int),
452 .proc_handler = &proc_dointvec,
455 .ctl_name = KERN_HPPA_UNALIGNED,
456 .procname = "unaligned-trap",
457 .data = &unaligned_enabled,
458 .maxlen = sizeof (int),
460 .proc_handler = &proc_dointvec,
464 .ctl_name = KERN_CTLALTDEL,
465 .procname = "ctrl-alt-del",
467 .maxlen = sizeof(int),
469 .proc_handler = &proc_dointvec,
473 .ctl_name = CTL_UNNUMBERED,
474 .procname = "ftrace_enabled",
475 .data = &ftrace_enabled,
476 .maxlen = sizeof(int),
478 .proc_handler = &ftrace_enable_sysctl,
481 #ifdef CONFIG_MODULES
483 .ctl_name = KERN_MODPROBE,
484 .procname = "modprobe",
485 .data = &modprobe_path,
486 .maxlen = KMOD_PATH_LEN,
488 .proc_handler = &proc_dostring,
489 .strategy = &sysctl_string,
492 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
494 .ctl_name = KERN_HOTPLUG,
495 .procname = "hotplug",
496 .data = &uevent_helper,
497 .maxlen = UEVENT_HELPER_PATH_LEN,
499 .proc_handler = &proc_dostring,
500 .strategy = &sysctl_string,
503 #ifdef CONFIG_CHR_DEV_SG
505 .ctl_name = KERN_SG_BIG_BUFF,
506 .procname = "sg-big-buff",
507 .data = &sg_big_buff,
508 .maxlen = sizeof (int),
510 .proc_handler = &proc_dointvec,
513 #ifdef CONFIG_BSD_PROCESS_ACCT
515 .ctl_name = KERN_ACCT,
518 .maxlen = 3*sizeof(int),
520 .proc_handler = &proc_dointvec,
523 #ifdef CONFIG_MAGIC_SYSRQ
525 .ctl_name = KERN_SYSRQ,
527 .data = &__sysrq_enabled,
528 .maxlen = sizeof (int),
530 .proc_handler = &proc_dointvec,
533 #ifdef CONFIG_PROC_SYSCTL
535 .procname = "cad_pid",
537 .maxlen = sizeof (int),
539 .proc_handler = &proc_do_cad_pid,
543 .ctl_name = KERN_MAX_THREADS,
544 .procname = "threads-max",
545 .data = &max_threads,
546 .maxlen = sizeof(int),
548 .proc_handler = &proc_dointvec,
551 .ctl_name = KERN_RANDOM,
552 .procname = "random",
554 .child = random_table,
557 .ctl_name = KERN_OVERFLOWUID,
558 .procname = "overflowuid",
559 .data = &overflowuid,
560 .maxlen = sizeof(int),
562 .proc_handler = &proc_dointvec_minmax,
563 .strategy = &sysctl_intvec,
564 .extra1 = &minolduid,
565 .extra2 = &maxolduid,
568 .ctl_name = KERN_OVERFLOWGID,
569 .procname = "overflowgid",
570 .data = &overflowgid,
571 .maxlen = sizeof(int),
573 .proc_handler = &proc_dointvec_minmax,
574 .strategy = &sysctl_intvec,
575 .extra1 = &minolduid,
576 .extra2 = &maxolduid,
579 #ifdef CONFIG_MATHEMU
581 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
582 .procname = "ieee_emulation_warnings",
583 .data = &sysctl_ieee_emulation_warnings,
584 .maxlen = sizeof(int),
586 .proc_handler = &proc_dointvec,
590 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
591 .procname = "userprocess_debug",
592 .data = &sysctl_userprocess_debug,
593 .maxlen = sizeof(int),
595 .proc_handler = &proc_dointvec,
599 .ctl_name = KERN_PIDMAX,
600 .procname = "pid_max",
602 .maxlen = sizeof (int),
604 .proc_handler = &proc_dointvec_minmax,
605 .strategy = sysctl_intvec,
606 .extra1 = &pid_max_min,
607 .extra2 = &pid_max_max,
610 .ctl_name = KERN_PANIC_ON_OOPS,
611 .procname = "panic_on_oops",
612 .data = &panic_on_oops,
613 .maxlen = sizeof(int),
615 .proc_handler = &proc_dointvec,
617 #if defined CONFIG_PRINTK
619 .ctl_name = KERN_PRINTK,
620 .procname = "printk",
621 .data = &console_loglevel,
622 .maxlen = 4*sizeof(int),
624 .proc_handler = &proc_dointvec,
627 .ctl_name = KERN_PRINTK_RATELIMIT,
628 .procname = "printk_ratelimit",
629 .data = &printk_ratelimit_state.interval,
630 .maxlen = sizeof(int),
632 .proc_handler = &proc_dointvec_jiffies,
633 .strategy = &sysctl_jiffies,
636 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
637 .procname = "printk_ratelimit_burst",
638 .data = &printk_ratelimit_state.burst,
639 .maxlen = sizeof(int),
641 .proc_handler = &proc_dointvec,
645 .ctl_name = KERN_NGROUPS_MAX,
646 .procname = "ngroups_max",
647 .data = &ngroups_max,
648 .maxlen = sizeof (int),
650 .proc_handler = &proc_dointvec,
652 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
654 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
655 .procname = "unknown_nmi_panic",
656 .data = &unknown_nmi_panic,
657 .maxlen = sizeof (int),
659 .proc_handler = &proc_dointvec,
662 .procname = "nmi_watchdog",
663 .data = &nmi_watchdog_enabled,
664 .maxlen = sizeof (int),
666 .proc_handler = &proc_nmi_enabled,
669 #if defined(CONFIG_X86)
671 .ctl_name = KERN_PANIC_ON_NMI,
672 .procname = "panic_on_unrecovered_nmi",
673 .data = &panic_on_unrecovered_nmi,
674 .maxlen = sizeof(int),
676 .proc_handler = &proc_dointvec,
679 .ctl_name = KERN_BOOTLOADER_TYPE,
680 .procname = "bootloader_type",
681 .data = &bootloader_type,
682 .maxlen = sizeof (int),
684 .proc_handler = &proc_dointvec,
687 .ctl_name = CTL_UNNUMBERED,
688 .procname = "kstack_depth_to_print",
689 .data = &kstack_depth_to_print,
690 .maxlen = sizeof(int),
692 .proc_handler = &proc_dointvec,
695 .ctl_name = CTL_UNNUMBERED,
696 .procname = "io_delay_type",
697 .data = &io_delay_type,
698 .maxlen = sizeof(int),
700 .proc_handler = &proc_dointvec,
703 #if defined(CONFIG_MMU)
705 .ctl_name = KERN_RANDOMIZE,
706 .procname = "randomize_va_space",
707 .data = &randomize_va_space,
708 .maxlen = sizeof(int),
710 .proc_handler = &proc_dointvec,
713 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
715 .ctl_name = KERN_SPIN_RETRY,
716 .procname = "spin_retry",
718 .maxlen = sizeof (int),
720 .proc_handler = &proc_dointvec,
723 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
725 .procname = "acpi_video_flags",
726 .data = &acpi_realmode_flags,
727 .maxlen = sizeof (unsigned long),
729 .proc_handler = &proc_doulongvec_minmax,
734 .ctl_name = KERN_IA64_UNALIGNED,
735 .procname = "ignore-unaligned-usertrap",
736 .data = &no_unaligned_warning,
737 .maxlen = sizeof (int),
739 .proc_handler = &proc_dointvec,
742 #ifdef CONFIG_DETECT_SOFTLOCKUP
744 .ctl_name = CTL_UNNUMBERED,
745 .procname = "softlockup_panic",
746 .data = &softlockup_panic,
747 .maxlen = sizeof(int),
749 .proc_handler = &proc_dointvec_minmax,
750 .strategy = &sysctl_intvec,
755 .ctl_name = CTL_UNNUMBERED,
756 .procname = "softlockup_thresh",
757 .data = &softlockup_thresh,
758 .maxlen = sizeof(int),
760 .proc_handler = &proc_dointvec_minmax,
761 .strategy = &sysctl_intvec,
766 .ctl_name = CTL_UNNUMBERED,
767 .procname = "hung_task_check_count",
768 .data = &sysctl_hung_task_check_count,
769 .maxlen = sizeof(unsigned long),
771 .proc_handler = &proc_doulongvec_minmax,
772 .strategy = &sysctl_intvec,
775 .ctl_name = CTL_UNNUMBERED,
776 .procname = "hung_task_timeout_secs",
777 .data = &sysctl_hung_task_timeout_secs,
778 .maxlen = sizeof(unsigned long),
780 .proc_handler = &proc_doulongvec_minmax,
781 .strategy = &sysctl_intvec,
784 .ctl_name = CTL_UNNUMBERED,
785 .procname = "hung_task_warnings",
786 .data = &sysctl_hung_task_warnings,
787 .maxlen = sizeof(unsigned long),
789 .proc_handler = &proc_doulongvec_minmax,
790 .strategy = &sysctl_intvec,
795 .ctl_name = KERN_COMPAT_LOG,
796 .procname = "compat-log",
798 .maxlen = sizeof (int),
800 .proc_handler = &proc_dointvec,
803 #ifdef CONFIG_RT_MUTEXES
805 .ctl_name = KERN_MAX_LOCK_DEPTH,
806 .procname = "max_lock_depth",
807 .data = &max_lock_depth,
808 .maxlen = sizeof(int),
810 .proc_handler = &proc_dointvec,
813 #ifdef CONFIG_PROC_FS
815 .ctl_name = CTL_UNNUMBERED,
816 .procname = "maps_protect",
817 .data = &maps_protect,
818 .maxlen = sizeof(int),
820 .proc_handler = &proc_dointvec,
824 .ctl_name = CTL_UNNUMBERED,
825 .procname = "poweroff_cmd",
826 .data = &poweroff_cmd,
827 .maxlen = POWEROFF_CMD_PATH_LEN,
829 .proc_handler = &proc_dostring,
830 .strategy = &sysctl_string,
834 .ctl_name = CTL_UNNUMBERED,
837 .child = key_sysctls,
840 #ifdef CONFIG_RCU_TORTURE_TEST
842 .ctl_name = CTL_UNNUMBERED,
843 .procname = "rcutorture_runnable",
844 .data = &rcutorture_runnable,
845 .maxlen = sizeof(int),
847 .proc_handler = &proc_dointvec,
851 * NOTE: do not add new entries to this table unless you have read
852 * Documentation/sysctl/ctl_unnumbered.txt
857 static struct ctl_table vm_table[] = {
859 .ctl_name = VM_OVERCOMMIT_MEMORY,
860 .procname = "overcommit_memory",
861 .data = &sysctl_overcommit_memory,
862 .maxlen = sizeof(sysctl_overcommit_memory),
864 .proc_handler = &proc_dointvec,
867 .ctl_name = VM_PANIC_ON_OOM,
868 .procname = "panic_on_oom",
869 .data = &sysctl_panic_on_oom,
870 .maxlen = sizeof(sysctl_panic_on_oom),
872 .proc_handler = &proc_dointvec,
875 .ctl_name = CTL_UNNUMBERED,
876 .procname = "oom_kill_allocating_task",
877 .data = &sysctl_oom_kill_allocating_task,
878 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
880 .proc_handler = &proc_dointvec,
883 .ctl_name = CTL_UNNUMBERED,
884 .procname = "oom_dump_tasks",
885 .data = &sysctl_oom_dump_tasks,
886 .maxlen = sizeof(sysctl_oom_dump_tasks),
888 .proc_handler = &proc_dointvec,
891 .ctl_name = VM_OVERCOMMIT_RATIO,
892 .procname = "overcommit_ratio",
893 .data = &sysctl_overcommit_ratio,
894 .maxlen = sizeof(sysctl_overcommit_ratio),
896 .proc_handler = &proc_dointvec,
899 .ctl_name = VM_PAGE_CLUSTER,
900 .procname = "page-cluster",
901 .data = &page_cluster,
902 .maxlen = sizeof(int),
904 .proc_handler = &proc_dointvec,
907 .ctl_name = VM_DIRTY_BACKGROUND,
908 .procname = "dirty_background_ratio",
909 .data = &dirty_background_ratio,
910 .maxlen = sizeof(dirty_background_ratio),
912 .proc_handler = &proc_dointvec_minmax,
913 .strategy = &sysctl_intvec,
915 .extra2 = &one_hundred,
918 .ctl_name = VM_DIRTY_RATIO,
919 .procname = "dirty_ratio",
920 .data = &vm_dirty_ratio,
921 .maxlen = sizeof(vm_dirty_ratio),
923 .proc_handler = &dirty_ratio_handler,
924 .strategy = &sysctl_intvec,
926 .extra2 = &one_hundred,
929 .procname = "dirty_writeback_centisecs",
930 .data = &dirty_writeback_interval,
931 .maxlen = sizeof(dirty_writeback_interval),
933 .proc_handler = &dirty_writeback_centisecs_handler,
936 .procname = "dirty_expire_centisecs",
937 .data = &dirty_expire_interval,
938 .maxlen = sizeof(dirty_expire_interval),
940 .proc_handler = &proc_dointvec_userhz_jiffies,
943 .ctl_name = VM_NR_PDFLUSH_THREADS,
944 .procname = "nr_pdflush_threads",
945 .data = &nr_pdflush_threads,
946 .maxlen = sizeof nr_pdflush_threads,
947 .mode = 0444 /* read-only*/,
948 .proc_handler = &proc_dointvec,
951 .ctl_name = VM_SWAPPINESS,
952 .procname = "swappiness",
953 .data = &vm_swappiness,
954 .maxlen = sizeof(vm_swappiness),
956 .proc_handler = &proc_dointvec_minmax,
957 .strategy = &sysctl_intvec,
959 .extra2 = &one_hundred,
961 #ifdef CONFIG_HUGETLB_PAGE
963 .procname = "nr_hugepages",
965 .maxlen = sizeof(unsigned long),
967 .proc_handler = &hugetlb_sysctl_handler,
968 .extra1 = (void *)&hugetlb_zero,
969 .extra2 = (void *)&hugetlb_infinity,
972 .ctl_name = VM_HUGETLB_GROUP,
973 .procname = "hugetlb_shm_group",
974 .data = &sysctl_hugetlb_shm_group,
975 .maxlen = sizeof(gid_t),
977 .proc_handler = &proc_dointvec,
980 .ctl_name = CTL_UNNUMBERED,
981 .procname = "hugepages_treat_as_movable",
982 .data = &hugepages_treat_as_movable,
983 .maxlen = sizeof(int),
985 .proc_handler = &hugetlb_treat_movable_handler,
988 .ctl_name = CTL_UNNUMBERED,
989 .procname = "nr_overcommit_hugepages",
991 .maxlen = sizeof(unsigned long),
993 .proc_handler = &hugetlb_overcommit_handler,
994 .extra1 = (void *)&hugetlb_zero,
995 .extra2 = (void *)&hugetlb_infinity,
999 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1000 .procname = "lowmem_reserve_ratio",
1001 .data = &sysctl_lowmem_reserve_ratio,
1002 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1004 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1005 .strategy = &sysctl_intvec,
1008 .ctl_name = VM_DROP_PAGECACHE,
1009 .procname = "drop_caches",
1010 .data = &sysctl_drop_caches,
1011 .maxlen = sizeof(int),
1013 .proc_handler = drop_caches_sysctl_handler,
1014 .strategy = &sysctl_intvec,
1017 .ctl_name = VM_MIN_FREE_KBYTES,
1018 .procname = "min_free_kbytes",
1019 .data = &min_free_kbytes,
1020 .maxlen = sizeof(min_free_kbytes),
1022 .proc_handler = &min_free_kbytes_sysctl_handler,
1023 .strategy = &sysctl_intvec,
1027 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1028 .procname = "percpu_pagelist_fraction",
1029 .data = &percpu_pagelist_fraction,
1030 .maxlen = sizeof(percpu_pagelist_fraction),
1032 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1033 .strategy = &sysctl_intvec,
1034 .extra1 = &min_percpu_pagelist_fract,
1038 .ctl_name = VM_MAX_MAP_COUNT,
1039 .procname = "max_map_count",
1040 .data = &sysctl_max_map_count,
1041 .maxlen = sizeof(sysctl_max_map_count),
1043 .proc_handler = &proc_dointvec
1047 .ctl_name = VM_LAPTOP_MODE,
1048 .procname = "laptop_mode",
1049 .data = &laptop_mode,
1050 .maxlen = sizeof(laptop_mode),
1052 .proc_handler = &proc_dointvec_jiffies,
1053 .strategy = &sysctl_jiffies,
1056 .ctl_name = VM_BLOCK_DUMP,
1057 .procname = "block_dump",
1058 .data = &block_dump,
1059 .maxlen = sizeof(block_dump),
1061 .proc_handler = &proc_dointvec,
1062 .strategy = &sysctl_intvec,
1066 .ctl_name = VM_VFS_CACHE_PRESSURE,
1067 .procname = "vfs_cache_pressure",
1068 .data = &sysctl_vfs_cache_pressure,
1069 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1071 .proc_handler = &proc_dointvec,
1072 .strategy = &sysctl_intvec,
1075 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1077 .ctl_name = VM_LEGACY_VA_LAYOUT,
1078 .procname = "legacy_va_layout",
1079 .data = &sysctl_legacy_va_layout,
1080 .maxlen = sizeof(sysctl_legacy_va_layout),
1082 .proc_handler = &proc_dointvec,
1083 .strategy = &sysctl_intvec,
1089 .ctl_name = VM_ZONE_RECLAIM_MODE,
1090 .procname = "zone_reclaim_mode",
1091 .data = &zone_reclaim_mode,
1092 .maxlen = sizeof(zone_reclaim_mode),
1094 .proc_handler = &proc_dointvec,
1095 .strategy = &sysctl_intvec,
1099 .ctl_name = VM_MIN_UNMAPPED,
1100 .procname = "min_unmapped_ratio",
1101 .data = &sysctl_min_unmapped_ratio,
1102 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1104 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1105 .strategy = &sysctl_intvec,
1107 .extra2 = &one_hundred,
1110 .ctl_name = VM_MIN_SLAB,
1111 .procname = "min_slab_ratio",
1112 .data = &sysctl_min_slab_ratio,
1113 .maxlen = sizeof(sysctl_min_slab_ratio),
1115 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1116 .strategy = &sysctl_intvec,
1118 .extra2 = &one_hundred,
1123 .ctl_name = CTL_UNNUMBERED,
1124 .procname = "stat_interval",
1125 .data = &sysctl_stat_interval,
1126 .maxlen = sizeof(sysctl_stat_interval),
1128 .proc_handler = &proc_dointvec_jiffies,
1129 .strategy = &sysctl_jiffies,
1132 #ifdef CONFIG_SECURITY
1134 .ctl_name = CTL_UNNUMBERED,
1135 .procname = "mmap_min_addr",
1136 .data = &mmap_min_addr,
1137 .maxlen = sizeof(unsigned long),
1139 .proc_handler = &proc_doulongvec_minmax,
1144 .ctl_name = CTL_UNNUMBERED,
1145 .procname = "numa_zonelist_order",
1146 .data = &numa_zonelist_order,
1147 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1149 .proc_handler = &numa_zonelist_order_handler,
1150 .strategy = &sysctl_string,
1153 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1154 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1156 .ctl_name = VM_VDSO_ENABLED,
1157 .procname = "vdso_enabled",
1158 .data = &vdso_enabled,
1159 .maxlen = sizeof(vdso_enabled),
1161 .proc_handler = &proc_dointvec,
1162 .strategy = &sysctl_intvec,
1166 #ifdef CONFIG_HIGHMEM
1168 .ctl_name = CTL_UNNUMBERED,
1169 .procname = "highmem_is_dirtyable",
1170 .data = &vm_highmem_is_dirtyable,
1171 .maxlen = sizeof(vm_highmem_is_dirtyable),
1173 .proc_handler = &proc_dointvec_minmax,
1174 .strategy = &sysctl_intvec,
1180 * NOTE: do not add new entries to this table unless you have read
1181 * Documentation/sysctl/ctl_unnumbered.txt
1186 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1187 static struct ctl_table binfmt_misc_table[] = {
1192 static struct ctl_table fs_table[] = {
1194 .ctl_name = FS_NRINODE,
1195 .procname = "inode-nr",
1196 .data = &inodes_stat,
1197 .maxlen = 2*sizeof(int),
1199 .proc_handler = &proc_dointvec,
1202 .ctl_name = FS_STATINODE,
1203 .procname = "inode-state",
1204 .data = &inodes_stat,
1205 .maxlen = 7*sizeof(int),
1207 .proc_handler = &proc_dointvec,
1210 .procname = "file-nr",
1211 .data = &files_stat,
1212 .maxlen = 3*sizeof(int),
1214 .proc_handler = &proc_nr_files,
1217 .ctl_name = FS_MAXFILE,
1218 .procname = "file-max",
1219 .data = &files_stat.max_files,
1220 .maxlen = sizeof(int),
1222 .proc_handler = &proc_dointvec,
1225 .ctl_name = CTL_UNNUMBERED,
1226 .procname = "nr_open",
1227 .data = &sysctl_nr_open,
1228 .maxlen = sizeof(int),
1230 .proc_handler = &proc_dointvec_minmax,
1231 .extra1 = &sysctl_nr_open_min,
1232 .extra2 = &sysctl_nr_open_max,
1235 .ctl_name = FS_DENTRY,
1236 .procname = "dentry-state",
1237 .data = &dentry_stat,
1238 .maxlen = 6*sizeof(int),
1240 .proc_handler = &proc_dointvec,
1243 .ctl_name = FS_OVERFLOWUID,
1244 .procname = "overflowuid",
1245 .data = &fs_overflowuid,
1246 .maxlen = sizeof(int),
1248 .proc_handler = &proc_dointvec_minmax,
1249 .strategy = &sysctl_intvec,
1250 .extra1 = &minolduid,
1251 .extra2 = &maxolduid,
1254 .ctl_name = FS_OVERFLOWGID,
1255 .procname = "overflowgid",
1256 .data = &fs_overflowgid,
1257 .maxlen = sizeof(int),
1259 .proc_handler = &proc_dointvec_minmax,
1260 .strategy = &sysctl_intvec,
1261 .extra1 = &minolduid,
1262 .extra2 = &maxolduid,
1264 #ifdef CONFIG_FILE_LOCKING
1266 .ctl_name = FS_LEASES,
1267 .procname = "leases-enable",
1268 .data = &leases_enable,
1269 .maxlen = sizeof(int),
1271 .proc_handler = &proc_dointvec,
1274 #ifdef CONFIG_DNOTIFY
1276 .ctl_name = FS_DIR_NOTIFY,
1277 .procname = "dir-notify-enable",
1278 .data = &dir_notify_enable,
1279 .maxlen = sizeof(int),
1281 .proc_handler = &proc_dointvec,
1285 #ifdef CONFIG_FILE_LOCKING
1287 .ctl_name = FS_LEASE_TIME,
1288 .procname = "lease-break-time",
1289 .data = &lease_break_time,
1290 .maxlen = sizeof(int),
1292 .proc_handler = &proc_dointvec_minmax,
1293 .strategy = &sysctl_intvec,
1299 .procname = "aio-nr",
1301 .maxlen = sizeof(aio_nr),
1303 .proc_handler = &proc_doulongvec_minmax,
1306 .procname = "aio-max-nr",
1307 .data = &aio_max_nr,
1308 .maxlen = sizeof(aio_max_nr),
1310 .proc_handler = &proc_doulongvec_minmax,
1312 #ifdef CONFIG_INOTIFY_USER
1314 .ctl_name = FS_INOTIFY,
1315 .procname = "inotify",
1317 .child = inotify_table,
1322 .ctl_name = KERN_SETUID_DUMPABLE,
1323 .procname = "suid_dumpable",
1324 .data = &suid_dumpable,
1325 .maxlen = sizeof(int),
1327 .proc_handler = &proc_dointvec,
1329 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1331 .ctl_name = CTL_UNNUMBERED,
1332 .procname = "binfmt_misc",
1334 .child = binfmt_misc_table,
1338 * NOTE: do not add new entries to this table unless you have read
1339 * Documentation/sysctl/ctl_unnumbered.txt
1344 static struct ctl_table debug_table[] = {
1345 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1347 .ctl_name = CTL_UNNUMBERED,
1348 .procname = "exception-trace",
1349 .data = &show_unhandled_signals,
1350 .maxlen = sizeof(int),
1352 .proc_handler = proc_dointvec
1358 static struct ctl_table dev_table[] = {
1362 static DEFINE_SPINLOCK(sysctl_lock);
1364 /* called under sysctl_lock */
1365 static int use_table(struct ctl_table_header *p)
1367 if (unlikely(p->unregistering))
1373 /* called under sysctl_lock */
1374 static void unuse_table(struct ctl_table_header *p)
1377 if (unlikely(p->unregistering))
1378 complete(p->unregistering);
1381 /* called under sysctl_lock, will reacquire if has to wait */
1382 static void start_unregistering(struct ctl_table_header *p)
1385 * if p->used is 0, nobody will ever touch that entry again;
1386 * we'll eliminate all paths to it before dropping sysctl_lock
1388 if (unlikely(p->used)) {
1389 struct completion wait;
1390 init_completion(&wait);
1391 p->unregistering = &wait;
1392 spin_unlock(&sysctl_lock);
1393 wait_for_completion(&wait);
1394 spin_lock(&sysctl_lock);
1396 /* anything non-NULL; we'll never dereference it */
1397 p->unregistering = ERR_PTR(-EINVAL);
1400 * do not remove from the list until nobody holds it; walking the
1401 * list in do_sysctl() relies on that.
1403 list_del_init(&p->ctl_entry);
1406 void sysctl_head_get(struct ctl_table_header *head)
1408 spin_lock(&sysctl_lock);
1410 spin_unlock(&sysctl_lock);
1413 void sysctl_head_put(struct ctl_table_header *head)
1415 spin_lock(&sysctl_lock);
1418 spin_unlock(&sysctl_lock);
1421 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1425 spin_lock(&sysctl_lock);
1426 if (!use_table(head))
1427 head = ERR_PTR(-ENOENT);
1428 spin_unlock(&sysctl_lock);
1432 void sysctl_head_finish(struct ctl_table_header *head)
1436 spin_lock(&sysctl_lock);
1438 spin_unlock(&sysctl_lock);
1441 static struct ctl_table_set *
1442 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1444 struct ctl_table_set *set = &root->default_set;
1446 set = root->lookup(root, namespaces);
1450 static struct list_head *
1451 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1453 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1457 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1458 struct ctl_table_header *prev)
1460 struct ctl_table_root *root;
1461 struct list_head *header_list;
1462 struct ctl_table_header *head;
1463 struct list_head *tmp;
1465 spin_lock(&sysctl_lock);
1468 tmp = &prev->ctl_entry;
1472 tmp = &root_table_header.ctl_entry;
1474 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1476 if (!use_table(head))
1478 spin_unlock(&sysctl_lock);
1483 header_list = lookup_header_list(root, namespaces);
1484 if (tmp != header_list)
1488 root = list_entry(root->root_list.next,
1489 struct ctl_table_root, root_list);
1490 if (root == &sysctl_table_root)
1492 header_list = lookup_header_list(root, namespaces);
1493 } while (list_empty(header_list));
1494 tmp = header_list->next;
1497 spin_unlock(&sysctl_lock);
1501 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1503 return __sysctl_head_next(current->nsproxy, prev);
1506 void register_sysctl_root(struct ctl_table_root *root)
1508 spin_lock(&sysctl_lock);
1509 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1510 spin_unlock(&sysctl_lock);
1513 #ifdef CONFIG_SYSCTL_SYSCALL
1514 /* Perform the actual read/write of a sysctl table entry. */
1515 static int do_sysctl_strategy(struct ctl_table_root *root,
1516 struct ctl_table *table,
1517 int __user *name, int nlen,
1518 void __user *oldval, size_t __user *oldlenp,
1519 void __user *newval, size_t newlen)
1527 if (sysctl_perm(root, table, op))
1530 if (table->strategy) {
1531 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1539 /* If there is no strategy routine, or if the strategy returns
1540 * zero, proceed with automatic r/w */
1541 if (table->data && table->maxlen) {
1542 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1550 static int parse_table(int __user *name, int nlen,
1551 void __user *oldval, size_t __user *oldlenp,
1552 void __user *newval, size_t newlen,
1553 struct ctl_table_root *root,
1554 struct ctl_table *table)
1560 if (get_user(n, name))
1562 for ( ; table->ctl_name || table->procname; table++) {
1563 if (!table->ctl_name)
1565 if (n == table->ctl_name) {
1568 if (sysctl_perm(root, table, MAY_EXEC))
1572 table = table->child;
1575 error = do_sysctl_strategy(root, table, name, nlen,
1584 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1585 void __user *newval, size_t newlen)
1587 struct ctl_table_header *head;
1588 int error = -ENOTDIR;
1590 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1594 if (!oldlenp || get_user(old_len, oldlenp))
1598 for (head = sysctl_head_next(NULL); head;
1599 head = sysctl_head_next(head)) {
1600 error = parse_table(name, nlen, oldval, oldlenp,
1602 head->root, head->ctl_table);
1603 if (error != -ENOTDIR) {
1604 sysctl_head_finish(head);
1611 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1613 struct __sysctl_args tmp;
1616 if (copy_from_user(&tmp, args, sizeof(tmp)))
1619 error = deprecated_sysctl_warning(&tmp);
1624 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1625 tmp.newval, tmp.newlen);
1630 #endif /* CONFIG_SYSCTL_SYSCALL */
1633 * sysctl_perm does NOT grant the superuser all rights automatically, because
1634 * some sysctl variables are readonly even to root.
1637 static int test_perm(int mode, int op)
1641 else if (in_egroup_p(0))
1643 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1648 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1653 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1657 if (root->permissions)
1658 mode = root->permissions(root, current->nsproxy, table);
1662 return test_perm(mode, op);
1665 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1667 for (; table->ctl_name || table->procname; table++) {
1668 table->parent = parent;
1670 sysctl_set_parent(table, table->child);
1674 static __init int sysctl_init(void)
1676 sysctl_set_parent(NULL, root_table);
1677 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1680 err = sysctl_check_table(current->nsproxy, root_table);
1686 core_initcall(sysctl_init);
1688 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1689 struct ctl_table *table)
1691 struct ctl_table *p;
1692 const char *s = branch->procname;
1694 /* branch should have named subdirectory as its first element */
1695 if (!s || !branch->child)
1698 /* ... and nothing else */
1699 if (branch[1].procname || branch[1].ctl_name)
1702 /* table should contain subdirectory with the same name */
1703 for (p = table; p->procname || p->ctl_name; p++) {
1706 if (p->procname && strcmp(p->procname, s) == 0)
1712 /* see if attaching q to p would be an improvement */
1713 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1715 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1716 struct ctl_table *next;
1718 int not_in_parent = !p->attached_by;
1720 while ((next = is_branch_in(by, to)) != NULL) {
1721 if (by == q->attached_by)
1723 if (to == p->attached_by)
1729 if (is_better && not_in_parent) {
1730 q->attached_by = by;
1731 q->attached_to = to;
1737 * __register_sysctl_paths - register a sysctl hierarchy
1738 * @root: List of sysctl headers to register on
1739 * @namespaces: Data to compute which lists of sysctl entries are visible
1740 * @path: The path to the directory the sysctl table is in.
1741 * @table: the top-level table structure
1743 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1744 * array. A completely 0 filled entry terminates the table.
1746 * The members of the &struct ctl_table structure are used as follows:
1748 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1749 * must be unique within that level of sysctl
1751 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1752 * enter a sysctl file
1754 * data - a pointer to data for use by proc_handler
1756 * maxlen - the maximum size in bytes of the data
1758 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1760 * child - a pointer to the child sysctl table if this entry is a directory, or
1763 * proc_handler - the text handler routine (described below)
1765 * strategy - the strategy routine (described below)
1767 * de - for internal use by the sysctl routines
1769 * extra1, extra2 - extra pointers usable by the proc handler routines
1771 * Leaf nodes in the sysctl tree will be represented by a single file
1772 * under /proc; non-leaf nodes will be represented by directories.
1774 * sysctl(2) can automatically manage read and write requests through
1775 * the sysctl table. The data and maxlen fields of the ctl_table
1776 * struct enable minimal validation of the values being written to be
1777 * performed, and the mode field allows minimal authentication.
1779 * More sophisticated management can be enabled by the provision of a
1780 * strategy routine with the table entry. This will be called before
1781 * any automatic read or write of the data is performed.
1783 * The strategy routine may return
1785 * < 0 - Error occurred (error is passed to user process)
1787 * 0 - OK - proceed with automatic read or write.
1789 * > 0 - OK - read or write has been done by the strategy routine, so
1790 * return immediately.
1792 * There must be a proc_handler routine for any terminal nodes
1793 * mirrored under /proc/sys (non-terminals are handled by a built-in
1794 * directory handler). Several default handlers are available to
1795 * cover common cases -
1797 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1798 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1799 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1801 * It is the handler's job to read the input buffer from user memory
1802 * and process it. The handler should return 0 on success.
1804 * This routine returns %NULL on a failure to register, and a pointer
1805 * to the table header on success.
1807 struct ctl_table_header *__register_sysctl_paths(
1808 struct ctl_table_root *root,
1809 struct nsproxy *namespaces,
1810 const struct ctl_path *path, struct ctl_table *table)
1812 struct ctl_table_header *header;
1813 struct ctl_table *new, **prevp;
1814 unsigned int n, npath;
1815 struct ctl_table_set *set;
1817 /* Count the path components */
1818 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1822 * For each path component, allocate a 2-element ctl_table array.
1823 * The first array element will be filled with the sysctl entry
1824 * for this, the second will be the sentinel (ctl_name == 0).
1826 * We allocate everything in one go so that we don't have to
1827 * worry about freeing additional memory in unregister_sysctl_table.
1829 header = kzalloc(sizeof(struct ctl_table_header) +
1830 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1834 new = (struct ctl_table *) (header + 1);
1836 /* Now connect the dots */
1837 prevp = &header->ctl_table;
1838 for (n = 0; n < npath; ++n, ++path) {
1839 /* Copy the procname */
1840 new->procname = path->procname;
1841 new->ctl_name = path->ctl_name;
1845 prevp = &new->child;
1850 header->ctl_table_arg = table;
1852 INIT_LIST_HEAD(&header->ctl_entry);
1854 header->unregistering = NULL;
1855 header->root = root;
1856 sysctl_set_parent(NULL, header->ctl_table);
1858 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1859 if (sysctl_check_table(namespaces, header->ctl_table)) {
1864 spin_lock(&sysctl_lock);
1865 header->set = lookup_header_set(root, namespaces);
1866 header->attached_by = header->ctl_table;
1867 header->attached_to = root_table;
1868 header->parent = &root_table_header;
1869 for (set = header->set; set; set = set->parent) {
1870 struct ctl_table_header *p;
1871 list_for_each_entry(p, &set->list, ctl_entry) {
1872 if (p->unregistering)
1874 try_attach(p, header);
1877 header->parent->count++;
1878 list_add_tail(&header->ctl_entry, &header->set->list);
1879 spin_unlock(&sysctl_lock);
1885 * register_sysctl_table_path - register a sysctl table hierarchy
1886 * @path: The path to the directory the sysctl table is in.
1887 * @table: the top-level table structure
1889 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1890 * array. A completely 0 filled entry terminates the table.
1892 * See __register_sysctl_paths for more details.
1894 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1895 struct ctl_table *table)
1897 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1902 * register_sysctl_table - register a sysctl table hierarchy
1903 * @table: the top-level table structure
1905 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1906 * array. A completely 0 filled entry terminates the table.
1908 * See register_sysctl_paths for more details.
1910 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1912 static const struct ctl_path null_path[] = { {} };
1914 return register_sysctl_paths(null_path, table);
1918 * unregister_sysctl_table - unregister a sysctl table hierarchy
1919 * @header: the header returned from register_sysctl_table
1921 * Unregisters the sysctl table and all children. proc entries may not
1922 * actually be removed until they are no longer used by anyone.
1924 void unregister_sysctl_table(struct ctl_table_header * header)
1931 spin_lock(&sysctl_lock);
1932 start_unregistering(header);
1933 if (!--header->parent->count) {
1935 kfree(header->parent);
1937 if (!--header->count)
1939 spin_unlock(&sysctl_lock);
1942 int sysctl_is_seen(struct ctl_table_header *p)
1944 struct ctl_table_set *set = p->set;
1946 spin_lock(&sysctl_lock);
1947 if (p->unregistering)
1949 else if (!set->is_seen)
1952 res = set->is_seen(set);
1953 spin_unlock(&sysctl_lock);
1957 void setup_sysctl_set(struct ctl_table_set *p,
1958 struct ctl_table_set *parent,
1959 int (*is_seen)(struct ctl_table_set *))
1961 INIT_LIST_HEAD(&p->list);
1962 p->parent = parent ? parent : &sysctl_table_root.default_set;
1963 p->is_seen = is_seen;
1966 #else /* !CONFIG_SYSCTL */
1967 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1972 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1973 struct ctl_table *table)
1978 void unregister_sysctl_table(struct ctl_table_header * table)
1982 void setup_sysctl_set(struct ctl_table_set *p,
1983 struct ctl_table_set *parent,
1984 int (*is_seen)(struct ctl_table_set *))
1988 void sysctl_head_put(struct ctl_table_header *head)
1992 #endif /* CONFIG_SYSCTL */
1998 #ifdef CONFIG_PROC_SYSCTL
2000 static int _proc_do_string(void* data, int maxlen, int write,
2001 struct file *filp, void __user *buffer,
2002 size_t *lenp, loff_t *ppos)
2008 if (!data || !maxlen || !*lenp) {
2016 while (len < *lenp) {
2017 if (get_user(c, p++))
2019 if (c == 0 || c == '\n')
2025 if(copy_from_user(data, buffer, len))
2027 ((char *) data)[len] = 0;
2045 if(copy_to_user(buffer, data, len))
2048 if(put_user('\n', ((char __user *) buffer) + len))
2059 * proc_dostring - read a string sysctl
2060 * @table: the sysctl table
2061 * @write: %TRUE if this is a write to the sysctl file
2062 * @filp: the file structure
2063 * @buffer: the user buffer
2064 * @lenp: the size of the user buffer
2065 * @ppos: file position
2067 * Reads/writes a string from/to the user buffer. If the kernel
2068 * buffer provided is not large enough to hold the string, the
2069 * string is truncated. The copied string is %NULL-terminated.
2070 * If the string is being read by the user process, it is copied
2071 * and a newline '\n' is added. It is truncated if the buffer is
2074 * Returns 0 on success.
2076 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2077 void __user *buffer, size_t *lenp, loff_t *ppos)
2079 return _proc_do_string(table->data, table->maxlen, write, filp,
2080 buffer, lenp, ppos);
2084 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2086 int write, void *data)
2089 *valp = *negp ? -*lvalp : *lvalp;
2094 *lvalp = (unsigned long)-val;
2097 *lvalp = (unsigned long)val;
2103 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2104 int write, struct file *filp, void __user *buffer,
2105 size_t *lenp, loff_t *ppos,
2106 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2107 int write, void *data),
2110 #define TMPBUFLEN 21
2111 int *i, vleft, first=1, neg, val;
2115 char buf[TMPBUFLEN], *p;
2116 char __user *s = buffer;
2118 if (!tbl_data || !table->maxlen || !*lenp ||
2119 (*ppos && !write)) {
2124 i = (int *) tbl_data;
2125 vleft = table->maxlen / sizeof(*i);
2129 conv = do_proc_dointvec_conv;
2131 for (; left && vleft--; i++, first=0) {
2146 if (len > sizeof(buf) - 1)
2147 len = sizeof(buf) - 1;
2148 if (copy_from_user(buf, s, len))
2152 if (*p == '-' && left > 1) {
2156 if (*p < '0' || *p > '9')
2159 lval = simple_strtoul(p, &p, 0);
2162 if ((len < left) && *p && !isspace(*p))
2169 if (conv(&neg, &lval, i, 1, data))
2176 if (conv(&neg, &lval, i, 0, data))
2179 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2183 if(copy_to_user(s, buf, len))
2190 if (!write && !first && left) {
2191 if(put_user('\n', s))
2198 if (get_user(c, s++))
2213 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2214 void __user *buffer, size_t *lenp, loff_t *ppos,
2215 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2216 int write, void *data),
2219 return __do_proc_dointvec(table->data, table, write, filp,
2220 buffer, lenp, ppos, conv, data);
2224 * proc_dointvec - read a vector of integers
2225 * @table: the sysctl table
2226 * @write: %TRUE if this is a write to the sysctl file
2227 * @filp: the file structure
2228 * @buffer: the user buffer
2229 * @lenp: the size of the user buffer
2230 * @ppos: file position
2232 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2233 * values from/to the user buffer, treated as an ASCII string.
2235 * Returns 0 on success.
2237 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2238 void __user *buffer, size_t *lenp, loff_t *ppos)
2240 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2248 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2250 int write, void *data)
2252 int op = *(int *)data;
2254 int val = *negp ? -*lvalp : *lvalp;
2256 case OP_SET: *valp = val; break;
2257 case OP_AND: *valp &= val; break;
2258 case OP_OR: *valp |= val; break;
2264 *lvalp = (unsigned long)-val;
2267 *lvalp = (unsigned long)val;
2274 * Taint values can only be increased
2276 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
2277 void __user *buffer, size_t *lenp, loff_t *ppos)
2281 if (write && !capable(CAP_SYS_ADMIN))
2285 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2286 do_proc_dointvec_bset_conv,&op);
2289 struct do_proc_dointvec_minmax_conv_param {
2294 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2296 int write, void *data)
2298 struct do_proc_dointvec_minmax_conv_param *param = data;
2300 int val = *negp ? -*lvalp : *lvalp;
2301 if ((param->min && *param->min > val) ||
2302 (param->max && *param->max < val))
2309 *lvalp = (unsigned long)-val;
2312 *lvalp = (unsigned long)val;
2319 * proc_dointvec_minmax - read a vector of integers with min/max values
2320 * @table: the sysctl table
2321 * @write: %TRUE if this is a write to the sysctl file
2322 * @filp: the file structure
2323 * @buffer: the user buffer
2324 * @lenp: the size of the user buffer
2325 * @ppos: file position
2327 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2328 * values from/to the user buffer, treated as an ASCII string.
2330 * This routine will ensure the values are within the range specified by
2331 * table->extra1 (min) and table->extra2 (max).
2333 * Returns 0 on success.
2335 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2336 void __user *buffer, size_t *lenp, loff_t *ppos)
2338 struct do_proc_dointvec_minmax_conv_param param = {
2339 .min = (int *) table->extra1,
2340 .max = (int *) table->extra2,
2342 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2343 do_proc_dointvec_minmax_conv, ¶m);
2346 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2348 void __user *buffer,
2349 size_t *lenp, loff_t *ppos,
2350 unsigned long convmul,
2351 unsigned long convdiv)
2353 #define TMPBUFLEN 21
2354 unsigned long *i, *min, *max, val;
2355 int vleft, first=1, neg;
2357 char buf[TMPBUFLEN], *p;
2358 char __user *s = buffer;
2360 if (!data || !table->maxlen || !*lenp ||
2361 (*ppos && !write)) {
2366 i = (unsigned long *) data;
2367 min = (unsigned long *) table->extra1;
2368 max = (unsigned long *) table->extra2;
2369 vleft = table->maxlen / sizeof(unsigned long);
2372 for (; left && vleft--; i++, min++, max++, first=0) {
2387 if (len > TMPBUFLEN-1)
2389 if (copy_from_user(buf, s, len))
2393 if (*p == '-' && left > 1) {
2397 if (*p < '0' || *p > '9')
2399 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2401 if ((len < left) && *p && !isspace(*p))
2410 if ((min && val < *min) || (max && val > *max))
2417 sprintf(p, "%lu", convdiv * (*i) / convmul);
2421 if(copy_to_user(s, buf, len))
2428 if (!write && !first && left) {
2429 if(put_user('\n', s))
2436 if (get_user(c, s++))
2451 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2453 void __user *buffer,
2454 size_t *lenp, loff_t *ppos,
2455 unsigned long convmul,
2456 unsigned long convdiv)
2458 return __do_proc_doulongvec_minmax(table->data, table, write,
2459 filp, buffer, lenp, ppos, convmul, convdiv);
2463 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2464 * @table: the sysctl table
2465 * @write: %TRUE if this is a write to the sysctl file
2466 * @filp: the file structure
2467 * @buffer: the user buffer
2468 * @lenp: the size of the user buffer
2469 * @ppos: file position
2471 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2472 * values from/to the user buffer, treated as an ASCII string.
2474 * This routine will ensure the values are within the range specified by
2475 * table->extra1 (min) and table->extra2 (max).
2477 * Returns 0 on success.
2479 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2480 void __user *buffer, size_t *lenp, loff_t *ppos)
2482 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2486 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2487 * @table: the sysctl table
2488 * @write: %TRUE if this is a write to the sysctl file
2489 * @filp: the file structure
2490 * @buffer: the user buffer
2491 * @lenp: the size of the user buffer
2492 * @ppos: file position
2494 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2495 * values from/to the user buffer, treated as an ASCII string. The values
2496 * are treated as milliseconds, and converted to jiffies when they are stored.
2498 * This routine will ensure the values are within the range specified by
2499 * table->extra1 (min) and table->extra2 (max).
2501 * Returns 0 on success.
2503 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2505 void __user *buffer,
2506 size_t *lenp, loff_t *ppos)
2508 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2509 lenp, ppos, HZ, 1000l);
2513 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2515 int write, void *data)
2518 if (*lvalp > LONG_MAX / HZ)
2520 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2526 lval = (unsigned long)-val;
2529 lval = (unsigned long)val;
2536 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2538 int write, void *data)
2541 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2543 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2549 lval = (unsigned long)-val;
2552 lval = (unsigned long)val;
2554 *lvalp = jiffies_to_clock_t(lval);
2559 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2561 int write, void *data)
2564 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2570 lval = (unsigned long)-val;
2573 lval = (unsigned long)val;
2575 *lvalp = jiffies_to_msecs(lval);
2581 * proc_dointvec_jiffies - read a vector of integers as seconds
2582 * @table: the sysctl table
2583 * @write: %TRUE if this is a write to the sysctl file
2584 * @filp: the file structure
2585 * @buffer: the user buffer
2586 * @lenp: the size of the user buffer
2587 * @ppos: file position
2589 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2590 * values from/to the user buffer, treated as an ASCII string.
2591 * The values read are assumed to be in seconds, and are converted into
2594 * Returns 0 on success.
2596 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2597 void __user *buffer, size_t *lenp, loff_t *ppos)
2599 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2600 do_proc_dointvec_jiffies_conv,NULL);
2604 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2605 * @table: the sysctl table
2606 * @write: %TRUE if this is a write to the sysctl file
2607 * @filp: the file structure
2608 * @buffer: the user buffer
2609 * @lenp: the size of the user buffer
2610 * @ppos: pointer to the file position
2612 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2613 * values from/to the user buffer, treated as an ASCII string.
2614 * The values read are assumed to be in 1/USER_HZ seconds, and
2615 * are converted into jiffies.
2617 * Returns 0 on success.
2619 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2620 void __user *buffer, size_t *lenp, loff_t *ppos)
2622 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2623 do_proc_dointvec_userhz_jiffies_conv,NULL);
2627 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2628 * @table: the sysctl table
2629 * @write: %TRUE if this is a write to the sysctl file
2630 * @filp: the file structure
2631 * @buffer: the user buffer
2632 * @lenp: the size of the user buffer
2633 * @ppos: file position
2634 * @ppos: the current position in the file
2636 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2637 * values from/to the user buffer, treated as an ASCII string.
2638 * The values read are assumed to be in 1/1000 seconds, and
2639 * are converted into jiffies.
2641 * Returns 0 on success.
2643 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2644 void __user *buffer, size_t *lenp, loff_t *ppos)
2646 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2647 do_proc_dointvec_ms_jiffies_conv, NULL);
2650 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2651 void __user *buffer, size_t *lenp, loff_t *ppos)
2653 struct pid *new_pid;
2657 tmp = pid_vnr(cad_pid);
2659 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2660 lenp, ppos, NULL, NULL);
2664 new_pid = find_get_pid(tmp);
2668 put_pid(xchg(&cad_pid, new_pid));
2672 #else /* CONFIG_PROC_FS */
2674 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2675 void __user *buffer, size_t *lenp, loff_t *ppos)
2680 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2681 void __user *buffer, size_t *lenp, loff_t *ppos)
2686 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2687 void __user *buffer, size_t *lenp, loff_t *ppos)
2692 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2693 void __user *buffer, size_t *lenp, loff_t *ppos)
2698 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2699 void __user *buffer, size_t *lenp, loff_t *ppos)
2704 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2705 void __user *buffer, size_t *lenp, loff_t *ppos)
2710 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2711 void __user *buffer, size_t *lenp, loff_t *ppos)
2716 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2718 void __user *buffer,
2719 size_t *lenp, loff_t *ppos)
2725 #endif /* CONFIG_PROC_FS */
2728 #ifdef CONFIG_SYSCTL_SYSCALL
2730 * General sysctl support routines
2733 /* The generic sysctl data routine (used if no strategy routine supplied) */
2734 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2735 void __user *oldval, size_t __user *oldlenp,
2736 void __user *newval, size_t newlen)
2740 /* Get out of I don't have a variable */
2741 if (!table->data || !table->maxlen)
2744 if (oldval && oldlenp) {
2745 if (get_user(len, oldlenp))
2748 if (len > table->maxlen)
2749 len = table->maxlen;
2750 if (copy_to_user(oldval, table->data, len))
2752 if (put_user(len, oldlenp))
2757 if (newval && newlen) {
2758 if (newlen > table->maxlen)
2759 newlen = table->maxlen;
2761 if (copy_from_user(table->data, newval, newlen))
2767 /* The generic string strategy routine: */
2768 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2769 void __user *oldval, size_t __user *oldlenp,
2770 void __user *newval, size_t newlen)
2772 if (!table->data || !table->maxlen)
2775 if (oldval && oldlenp) {
2777 if (get_user(bufsize, oldlenp))
2780 size_t len = strlen(table->data), copied;
2782 /* This shouldn't trigger for a well-formed sysctl */
2783 if (len > table->maxlen)
2784 len = table->maxlen;
2786 /* Copy up to a max of bufsize-1 bytes of the string */
2787 copied = (len >= bufsize) ? bufsize - 1 : len;
2789 if (copy_to_user(oldval, table->data, copied) ||
2790 put_user(0, (char __user *)(oldval + copied)))
2792 if (put_user(len, oldlenp))
2796 if (newval && newlen) {
2797 size_t len = newlen;
2798 if (len > table->maxlen)
2799 len = table->maxlen;
2800 if(copy_from_user(table->data, newval, len))
2802 if (len == table->maxlen)
2804 ((char *) table->data)[len] = 0;
2810 * This function makes sure that all of the integers in the vector
2811 * are between the minimum and maximum values given in the arrays
2812 * table->extra1 and table->extra2, respectively.
2814 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2815 void __user *oldval, size_t __user *oldlenp,
2816 void __user *newval, size_t newlen)
2819 if (newval && newlen) {
2820 int __user *vec = (int __user *) newval;
2821 int *min = (int *) table->extra1;
2822 int *max = (int *) table->extra2;
2826 if (newlen % sizeof(int) != 0)
2829 if (!table->extra1 && !table->extra2)
2832 if (newlen > table->maxlen)
2833 newlen = table->maxlen;
2834 length = newlen / sizeof(int);
2836 for (i = 0; i < length; i++) {
2838 if (get_user(value, vec + i))
2840 if (min && value < min[i])
2842 if (max && value > max[i])
2849 /* Strategy function to convert jiffies to seconds */
2850 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2851 void __user *oldval, size_t __user *oldlenp,
2852 void __user *newval, size_t newlen)
2854 if (oldval && oldlenp) {
2857 if (get_user(olen, oldlenp))
2862 if (olen < sizeof(int))
2865 val = *(int *)(table->data) / HZ;
2866 if (put_user(val, (int __user *)oldval))
2868 if (put_user(sizeof(int), oldlenp))
2872 if (newval && newlen) {
2874 if (newlen != sizeof(int))
2876 if (get_user(new, (int __user *)newval))
2878 *(int *)(table->data) = new*HZ;
2883 /* Strategy function to convert jiffies to seconds */
2884 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2885 void __user *oldval, size_t __user *oldlenp,
2886 void __user *newval, size_t newlen)
2888 if (oldval && oldlenp) {
2891 if (get_user(olen, oldlenp))
2896 if (olen < sizeof(int))
2899 val = jiffies_to_msecs(*(int *)(table->data));
2900 if (put_user(val, (int __user *)oldval))
2902 if (put_user(sizeof(int), oldlenp))
2906 if (newval && newlen) {
2908 if (newlen != sizeof(int))
2910 if (get_user(new, (int __user *)newval))
2912 *(int *)(table->data) = msecs_to_jiffies(new);
2919 #else /* CONFIG_SYSCTL_SYSCALL */
2922 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2924 struct __sysctl_args tmp;
2927 if (copy_from_user(&tmp, args, sizeof(tmp)))
2930 error = deprecated_sysctl_warning(&tmp);
2932 /* If no error reading the parameters then just -ENOSYS ... */
2939 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2940 void __user *oldval, size_t __user *oldlenp,
2941 void __user *newval, size_t newlen)
2946 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2947 void __user *oldval, size_t __user *oldlenp,
2948 void __user *newval, size_t newlen)
2953 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2954 void __user *oldval, size_t __user *oldlenp,
2955 void __user *newval, size_t newlen)
2960 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2961 void __user *oldval, size_t __user *oldlenp,
2962 void __user *newval, size_t newlen)
2967 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2968 void __user *oldval, size_t __user *oldlenp,
2969 void __user *newval, size_t newlen)
2974 #endif /* CONFIG_SYSCTL_SYSCALL */
2976 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2978 static int msg_count;
2979 int name[CTL_MAXNAME];
2982 /* Check args->nlen. */
2983 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2986 /* Read in the sysctl name for better debug message logging */
2987 for (i = 0; i < args->nlen; i++)
2988 if (get_user(name[i], args->name + i))
2991 /* Ignore accesses to kernel.version */
2992 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2995 if (msg_count < 5) {
2998 "warning: process `%s' used the deprecated sysctl "
2999 "system call with ", current->comm);
3000 for (i = 0; i < args->nlen; i++)
3001 printk("%d.", name[i]);
3008 * No sense putting this after each symbol definition, twice,
3009 * exception granted :-)
3011 EXPORT_SYMBOL(proc_dointvec);
3012 EXPORT_SYMBOL(proc_dointvec_jiffies);
3013 EXPORT_SYMBOL(proc_dointvec_minmax);
3014 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3015 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3016 EXPORT_SYMBOL(proc_dostring);
3017 EXPORT_SYMBOL(proc_doulongvec_minmax);
3018 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3019 EXPORT_SYMBOL(register_sysctl_table);
3020 EXPORT_SYMBOL(register_sysctl_paths);
3021 EXPORT_SYMBOL(sysctl_intvec);
3022 EXPORT_SYMBOL(sysctl_jiffies);
3023 EXPORT_SYMBOL(sysctl_ms_jiffies);
3024 EXPORT_SYMBOL(sysctl_string);
3025 EXPORT_SYMBOL(sysctl_data);
3026 EXPORT_SYMBOL(unregister_sysctl_table);