2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
52 #include <asm/uaccess.h>
53 #include <asm/processor.h>
57 #include <asm/stacktrace.h>
61 static int deprecated_sysctl_warning(struct __sysctl_args *args);
63 #if defined(CONFIG_SYSCTL)
65 /* External variables not in a header file. */
67 extern int print_fatal_signals;
68 extern int sysctl_overcommit_memory;
69 extern int sysctl_overcommit_ratio;
70 extern int sysctl_panic_on_oom;
71 extern int sysctl_oom_kill_allocating_task;
72 extern int sysctl_oom_dump_tasks;
73 extern int max_threads;
74 extern int core_uses_pid;
75 extern int suid_dumpable;
76 extern char core_pattern[];
78 extern int min_free_kbytes;
79 extern int pid_max_min, pid_max_max;
80 extern int sysctl_drop_caches;
81 extern int percpu_pagelist_fraction;
82 extern int compat_log;
83 extern int latencytop_enabled;
84 extern int sysctl_nr_open_min, sysctl_nr_open_max;
85 #ifdef CONFIG_RCU_TORTURE_TEST
86 extern int rcutorture_runnable;
87 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
89 /* Constants used for minimum and maximum */
90 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
94 #ifdef CONFIG_DETECT_SOFTLOCKUP
95 static int sixty = 60;
96 static int neg_one = -1;
104 static int one_hundred = 100;
106 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
107 static int maxolduid = 65535;
108 static int minolduid;
109 static int min_percpu_pagelist_fract = 8;
111 static int ngroups_max = NGROUPS_MAX;
113 #ifdef CONFIG_MODULES
114 extern char modprobe_path[];
116 #ifdef CONFIG_CHR_DEV_SG
117 extern int sg_big_buff;
121 extern char reboot_command [];
122 extern int stop_a_enabled;
123 extern int scons_pwroff;
127 extern int pwrsw_enabled;
128 extern int unaligned_enabled;
132 #ifdef CONFIG_MATHEMU
133 extern int sysctl_ieee_emulation_warnings;
135 extern int sysctl_userprocess_debug;
136 extern int spin_retry;
139 #ifdef CONFIG_BSD_PROCESS_ACCT
140 extern int acct_parm[];
144 extern int no_unaligned_warning;
147 #ifdef CONFIG_RT_MUTEXES
148 extern int max_lock_depth;
151 #ifdef CONFIG_PROC_SYSCTL
152 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
153 void __user *buffer, size_t *lenp, loff_t *ppos);
154 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
155 void __user *buffer, size_t *lenp, loff_t *ppos);
158 static struct ctl_table root_table[];
159 static struct ctl_table_root sysctl_table_root;
160 static struct ctl_table_header root_table_header = {
162 .ctl_table = root_table,
163 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
164 .root = &sysctl_table_root,
165 .set = &sysctl_table_root.default_set,
167 static struct ctl_table_root sysctl_table_root = {
168 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
169 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
172 static struct ctl_table kern_table[];
173 static struct ctl_table vm_table[];
174 static struct ctl_table fs_table[];
175 static struct ctl_table debug_table[];
176 static struct ctl_table dev_table[];
177 extern struct ctl_table random_table[];
178 #ifdef CONFIG_INOTIFY_USER
179 extern struct ctl_table inotify_table[];
182 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
183 int sysctl_legacy_va_layout;
186 extern int prove_locking;
187 extern int lock_stat;
189 /* The default sysctl tables: */
191 static struct ctl_table root_table[] = {
193 .ctl_name = CTL_KERN,
194 .procname = "kernel",
211 .ctl_name = CTL_DEBUG,
214 .child = debug_table,
223 * NOTE: do not add new entries to this table unless you have read
224 * Documentation/sysctl/ctl_unnumbered.txt
229 #ifdef CONFIG_SCHED_DEBUG
230 static int min_sched_granularity_ns = 100000; /* 100 usecs */
231 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
232 static int min_wakeup_granularity_ns; /* 0 usecs */
233 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
236 static struct ctl_table kern_table[] = {
237 #ifdef CONFIG_SCHED_DEBUG
239 .ctl_name = CTL_UNNUMBERED,
240 .procname = "sched_min_granularity_ns",
241 .data = &sysctl_sched_min_granularity,
242 .maxlen = sizeof(unsigned int),
244 .proc_handler = &sched_nr_latency_handler,
245 .strategy = &sysctl_intvec,
246 .extra1 = &min_sched_granularity_ns,
247 .extra2 = &max_sched_granularity_ns,
250 .ctl_name = CTL_UNNUMBERED,
251 .procname = "sched_latency_ns",
252 .data = &sysctl_sched_latency,
253 .maxlen = sizeof(unsigned int),
255 .proc_handler = &sched_nr_latency_handler,
256 .strategy = &sysctl_intvec,
257 .extra1 = &min_sched_granularity_ns,
258 .extra2 = &max_sched_granularity_ns,
261 .ctl_name = CTL_UNNUMBERED,
262 .procname = "sched_wakeup_granularity_ns",
263 .data = &sysctl_sched_wakeup_granularity,
264 .maxlen = sizeof(unsigned int),
266 .proc_handler = &proc_dointvec_minmax,
267 .strategy = &sysctl_intvec,
268 .extra1 = &min_wakeup_granularity_ns,
269 .extra2 = &max_wakeup_granularity_ns,
272 .ctl_name = CTL_UNNUMBERED,
273 .procname = "sched_shares_ratelimit",
274 .data = &sysctl_sched_shares_ratelimit,
275 .maxlen = sizeof(unsigned int),
277 .proc_handler = &proc_dointvec,
280 .ctl_name = CTL_UNNUMBERED,
281 .procname = "sched_child_runs_first",
282 .data = &sysctl_sched_child_runs_first,
283 .maxlen = sizeof(unsigned int),
285 .proc_handler = &proc_dointvec,
288 .ctl_name = CTL_UNNUMBERED,
289 .procname = "sched_features",
290 .data = &sysctl_sched_features,
291 .maxlen = sizeof(unsigned int),
293 .proc_handler = &proc_dointvec,
296 .ctl_name = CTL_UNNUMBERED,
297 .procname = "sched_migration_cost",
298 .data = &sysctl_sched_migration_cost,
299 .maxlen = sizeof(unsigned int),
301 .proc_handler = &proc_dointvec,
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "sched_nr_migrate",
306 .data = &sysctl_sched_nr_migrate,
307 .maxlen = sizeof(unsigned int),
309 .proc_handler = &proc_dointvec,
313 .ctl_name = CTL_UNNUMBERED,
314 .procname = "sched_rt_period_us",
315 .data = &sysctl_sched_rt_period,
316 .maxlen = sizeof(unsigned int),
318 .proc_handler = &sched_rt_handler,
321 .ctl_name = CTL_UNNUMBERED,
322 .procname = "sched_rt_runtime_us",
323 .data = &sysctl_sched_rt_runtime,
324 .maxlen = sizeof(int),
326 .proc_handler = &sched_rt_handler,
329 .ctl_name = CTL_UNNUMBERED,
330 .procname = "sched_compat_yield",
331 .data = &sysctl_sched_compat_yield,
332 .maxlen = sizeof(unsigned int),
334 .proc_handler = &proc_dointvec,
336 #ifdef CONFIG_PROVE_LOCKING
338 .ctl_name = CTL_UNNUMBERED,
339 .procname = "prove_locking",
340 .data = &prove_locking,
341 .maxlen = sizeof(int),
343 .proc_handler = &proc_dointvec,
346 #ifdef CONFIG_LOCK_STAT
348 .ctl_name = CTL_UNNUMBERED,
349 .procname = "lock_stat",
351 .maxlen = sizeof(int),
353 .proc_handler = &proc_dointvec,
357 .ctl_name = KERN_PANIC,
359 .data = &panic_timeout,
360 .maxlen = sizeof(int),
362 .proc_handler = &proc_dointvec,
365 .ctl_name = KERN_CORE_USES_PID,
366 .procname = "core_uses_pid",
367 .data = &core_uses_pid,
368 .maxlen = sizeof(int),
370 .proc_handler = &proc_dointvec,
373 .ctl_name = KERN_CORE_PATTERN,
374 .procname = "core_pattern",
375 .data = core_pattern,
376 .maxlen = CORENAME_MAX_SIZE,
378 .proc_handler = &proc_dostring,
379 .strategy = &sysctl_string,
381 #ifdef CONFIG_PROC_SYSCTL
383 .procname = "tainted",
385 .maxlen = sizeof(int),
387 .proc_handler = &proc_dointvec_taint,
390 #ifdef CONFIG_LATENCYTOP
392 .procname = "latencytop",
393 .data = &latencytop_enabled,
394 .maxlen = sizeof(int),
396 .proc_handler = &proc_dointvec,
399 #ifdef CONFIG_BLK_DEV_INITRD
401 .ctl_name = KERN_REALROOTDEV,
402 .procname = "real-root-dev",
403 .data = &real_root_dev,
404 .maxlen = sizeof(int),
406 .proc_handler = &proc_dointvec,
410 .ctl_name = CTL_UNNUMBERED,
411 .procname = "print-fatal-signals",
412 .data = &print_fatal_signals,
413 .maxlen = sizeof(int),
415 .proc_handler = &proc_dointvec,
419 .ctl_name = KERN_SPARC_REBOOT,
420 .procname = "reboot-cmd",
421 .data = reboot_command,
424 .proc_handler = &proc_dostring,
425 .strategy = &sysctl_string,
428 .ctl_name = KERN_SPARC_STOP_A,
429 .procname = "stop-a",
430 .data = &stop_a_enabled,
431 .maxlen = sizeof (int),
433 .proc_handler = &proc_dointvec,
436 .ctl_name = KERN_SPARC_SCONS_PWROFF,
437 .procname = "scons-poweroff",
438 .data = &scons_pwroff,
439 .maxlen = sizeof (int),
441 .proc_handler = &proc_dointvec,
446 .ctl_name = KERN_HPPA_PWRSW,
447 .procname = "soft-power",
448 .data = &pwrsw_enabled,
449 .maxlen = sizeof (int),
451 .proc_handler = &proc_dointvec,
454 .ctl_name = KERN_HPPA_UNALIGNED,
455 .procname = "unaligned-trap",
456 .data = &unaligned_enabled,
457 .maxlen = sizeof (int),
459 .proc_handler = &proc_dointvec,
463 .ctl_name = KERN_CTLALTDEL,
464 .procname = "ctrl-alt-del",
466 .maxlen = sizeof(int),
468 .proc_handler = &proc_dointvec,
472 .ctl_name = CTL_UNNUMBERED,
473 .procname = "ftrace_enabled",
474 .data = &ftrace_enabled,
475 .maxlen = sizeof(int),
477 .proc_handler = &ftrace_enable_sysctl,
480 #ifdef CONFIG_MODULES
482 .ctl_name = KERN_MODPROBE,
483 .procname = "modprobe",
484 .data = &modprobe_path,
485 .maxlen = KMOD_PATH_LEN,
487 .proc_handler = &proc_dostring,
488 .strategy = &sysctl_string,
491 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
493 .ctl_name = KERN_HOTPLUG,
494 .procname = "hotplug",
495 .data = &uevent_helper,
496 .maxlen = UEVENT_HELPER_PATH_LEN,
498 .proc_handler = &proc_dostring,
499 .strategy = &sysctl_string,
502 #ifdef CONFIG_CHR_DEV_SG
504 .ctl_name = KERN_SG_BIG_BUFF,
505 .procname = "sg-big-buff",
506 .data = &sg_big_buff,
507 .maxlen = sizeof (int),
509 .proc_handler = &proc_dointvec,
512 #ifdef CONFIG_BSD_PROCESS_ACCT
514 .ctl_name = KERN_ACCT,
517 .maxlen = 3*sizeof(int),
519 .proc_handler = &proc_dointvec,
522 #ifdef CONFIG_MAGIC_SYSRQ
524 .ctl_name = KERN_SYSRQ,
526 .data = &__sysrq_enabled,
527 .maxlen = sizeof (int),
529 .proc_handler = &proc_dointvec,
532 #ifdef CONFIG_PROC_SYSCTL
534 .procname = "cad_pid",
536 .maxlen = sizeof (int),
538 .proc_handler = &proc_do_cad_pid,
542 .ctl_name = KERN_MAX_THREADS,
543 .procname = "threads-max",
544 .data = &max_threads,
545 .maxlen = sizeof(int),
547 .proc_handler = &proc_dointvec,
550 .ctl_name = KERN_RANDOM,
551 .procname = "random",
553 .child = random_table,
556 .ctl_name = KERN_OVERFLOWUID,
557 .procname = "overflowuid",
558 .data = &overflowuid,
559 .maxlen = sizeof(int),
561 .proc_handler = &proc_dointvec_minmax,
562 .strategy = &sysctl_intvec,
563 .extra1 = &minolduid,
564 .extra2 = &maxolduid,
567 .ctl_name = KERN_OVERFLOWGID,
568 .procname = "overflowgid",
569 .data = &overflowgid,
570 .maxlen = sizeof(int),
572 .proc_handler = &proc_dointvec_minmax,
573 .strategy = &sysctl_intvec,
574 .extra1 = &minolduid,
575 .extra2 = &maxolduid,
578 #ifdef CONFIG_MATHEMU
580 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
581 .procname = "ieee_emulation_warnings",
582 .data = &sysctl_ieee_emulation_warnings,
583 .maxlen = sizeof(int),
585 .proc_handler = &proc_dointvec,
589 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
590 .procname = "userprocess_debug",
591 .data = &sysctl_userprocess_debug,
592 .maxlen = sizeof(int),
594 .proc_handler = &proc_dointvec,
598 .ctl_name = KERN_PIDMAX,
599 .procname = "pid_max",
601 .maxlen = sizeof (int),
603 .proc_handler = &proc_dointvec_minmax,
604 .strategy = sysctl_intvec,
605 .extra1 = &pid_max_min,
606 .extra2 = &pid_max_max,
609 .ctl_name = KERN_PANIC_ON_OOPS,
610 .procname = "panic_on_oops",
611 .data = &panic_on_oops,
612 .maxlen = sizeof(int),
614 .proc_handler = &proc_dointvec,
616 #if defined CONFIG_PRINTK
618 .ctl_name = KERN_PRINTK,
619 .procname = "printk",
620 .data = &console_loglevel,
621 .maxlen = 4*sizeof(int),
623 .proc_handler = &proc_dointvec,
626 .ctl_name = KERN_PRINTK_RATELIMIT,
627 .procname = "printk_ratelimit",
628 .data = &printk_ratelimit_state.interval,
629 .maxlen = sizeof(int),
631 .proc_handler = &proc_dointvec_jiffies,
632 .strategy = &sysctl_jiffies,
635 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
636 .procname = "printk_ratelimit_burst",
637 .data = &printk_ratelimit_state.burst,
638 .maxlen = sizeof(int),
640 .proc_handler = &proc_dointvec,
644 .ctl_name = KERN_NGROUPS_MAX,
645 .procname = "ngroups_max",
646 .data = &ngroups_max,
647 .maxlen = sizeof (int),
649 .proc_handler = &proc_dointvec,
651 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
653 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
654 .procname = "unknown_nmi_panic",
655 .data = &unknown_nmi_panic,
656 .maxlen = sizeof (int),
658 .proc_handler = &proc_dointvec,
661 .procname = "nmi_watchdog",
662 .data = &nmi_watchdog_enabled,
663 .maxlen = sizeof (int),
665 .proc_handler = &proc_nmi_enabled,
668 #if defined(CONFIG_X86)
670 .ctl_name = KERN_PANIC_ON_NMI,
671 .procname = "panic_on_unrecovered_nmi",
672 .data = &panic_on_unrecovered_nmi,
673 .maxlen = sizeof(int),
675 .proc_handler = &proc_dointvec,
678 .ctl_name = KERN_BOOTLOADER_TYPE,
679 .procname = "bootloader_type",
680 .data = &bootloader_type,
681 .maxlen = sizeof (int),
683 .proc_handler = &proc_dointvec,
686 .ctl_name = CTL_UNNUMBERED,
687 .procname = "kstack_depth_to_print",
688 .data = &kstack_depth_to_print,
689 .maxlen = sizeof(int),
691 .proc_handler = &proc_dointvec,
694 .ctl_name = CTL_UNNUMBERED,
695 .procname = "io_delay_type",
696 .data = &io_delay_type,
697 .maxlen = sizeof(int),
699 .proc_handler = &proc_dointvec,
702 #if defined(CONFIG_MMU)
704 .ctl_name = KERN_RANDOMIZE,
705 .procname = "randomize_va_space",
706 .data = &randomize_va_space,
707 .maxlen = sizeof(int),
709 .proc_handler = &proc_dointvec,
712 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
714 .ctl_name = KERN_SPIN_RETRY,
715 .procname = "spin_retry",
717 .maxlen = sizeof (int),
719 .proc_handler = &proc_dointvec,
722 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
724 .procname = "acpi_video_flags",
725 .data = &acpi_realmode_flags,
726 .maxlen = sizeof (unsigned long),
728 .proc_handler = &proc_doulongvec_minmax,
733 .ctl_name = KERN_IA64_UNALIGNED,
734 .procname = "ignore-unaligned-usertrap",
735 .data = &no_unaligned_warning,
736 .maxlen = sizeof (int),
738 .proc_handler = &proc_dointvec,
741 #ifdef CONFIG_DETECT_SOFTLOCKUP
743 .ctl_name = CTL_UNNUMBERED,
744 .procname = "softlockup_panic",
745 .data = &softlockup_panic,
746 .maxlen = sizeof(int),
748 .proc_handler = &proc_dointvec_minmax,
749 .strategy = &sysctl_intvec,
754 .ctl_name = CTL_UNNUMBERED,
755 .procname = "softlockup_thresh",
756 .data = &softlockup_thresh,
757 .maxlen = sizeof(int),
759 .proc_handler = &proc_dointvec_minmax,
760 .strategy = &sysctl_intvec,
765 .ctl_name = CTL_UNNUMBERED,
766 .procname = "hung_task_check_count",
767 .data = &sysctl_hung_task_check_count,
768 .maxlen = sizeof(unsigned long),
770 .proc_handler = &proc_doulongvec_minmax,
771 .strategy = &sysctl_intvec,
774 .ctl_name = CTL_UNNUMBERED,
775 .procname = "hung_task_timeout_secs",
776 .data = &sysctl_hung_task_timeout_secs,
777 .maxlen = sizeof(unsigned long),
779 .proc_handler = &proc_doulongvec_minmax,
780 .strategy = &sysctl_intvec,
783 .ctl_name = CTL_UNNUMBERED,
784 .procname = "hung_task_warnings",
785 .data = &sysctl_hung_task_warnings,
786 .maxlen = sizeof(unsigned long),
788 .proc_handler = &proc_doulongvec_minmax,
789 .strategy = &sysctl_intvec,
794 .ctl_name = KERN_COMPAT_LOG,
795 .procname = "compat-log",
797 .maxlen = sizeof (int),
799 .proc_handler = &proc_dointvec,
802 #ifdef CONFIG_RT_MUTEXES
804 .ctl_name = KERN_MAX_LOCK_DEPTH,
805 .procname = "max_lock_depth",
806 .data = &max_lock_depth,
807 .maxlen = sizeof(int),
809 .proc_handler = &proc_dointvec,
813 .ctl_name = CTL_UNNUMBERED,
814 .procname = "poweroff_cmd",
815 .data = &poweroff_cmd,
816 .maxlen = POWEROFF_CMD_PATH_LEN,
818 .proc_handler = &proc_dostring,
819 .strategy = &sysctl_string,
823 .ctl_name = CTL_UNNUMBERED,
826 .child = key_sysctls,
829 #ifdef CONFIG_RCU_TORTURE_TEST
831 .ctl_name = CTL_UNNUMBERED,
832 .procname = "rcutorture_runnable",
833 .data = &rcutorture_runnable,
834 .maxlen = sizeof(int),
836 .proc_handler = &proc_dointvec,
840 * NOTE: do not add new entries to this table unless you have read
841 * Documentation/sysctl/ctl_unnumbered.txt
846 static struct ctl_table vm_table[] = {
848 .ctl_name = VM_OVERCOMMIT_MEMORY,
849 .procname = "overcommit_memory",
850 .data = &sysctl_overcommit_memory,
851 .maxlen = sizeof(sysctl_overcommit_memory),
853 .proc_handler = &proc_dointvec,
856 .ctl_name = VM_PANIC_ON_OOM,
857 .procname = "panic_on_oom",
858 .data = &sysctl_panic_on_oom,
859 .maxlen = sizeof(sysctl_panic_on_oom),
861 .proc_handler = &proc_dointvec,
864 .ctl_name = CTL_UNNUMBERED,
865 .procname = "oom_kill_allocating_task",
866 .data = &sysctl_oom_kill_allocating_task,
867 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
869 .proc_handler = &proc_dointvec,
872 .ctl_name = CTL_UNNUMBERED,
873 .procname = "oom_dump_tasks",
874 .data = &sysctl_oom_dump_tasks,
875 .maxlen = sizeof(sysctl_oom_dump_tasks),
877 .proc_handler = &proc_dointvec,
880 .ctl_name = VM_OVERCOMMIT_RATIO,
881 .procname = "overcommit_ratio",
882 .data = &sysctl_overcommit_ratio,
883 .maxlen = sizeof(sysctl_overcommit_ratio),
885 .proc_handler = &proc_dointvec,
888 .ctl_name = VM_PAGE_CLUSTER,
889 .procname = "page-cluster",
890 .data = &page_cluster,
891 .maxlen = sizeof(int),
893 .proc_handler = &proc_dointvec,
896 .ctl_name = VM_DIRTY_BACKGROUND,
897 .procname = "dirty_background_ratio",
898 .data = &dirty_background_ratio,
899 .maxlen = sizeof(dirty_background_ratio),
901 .proc_handler = &proc_dointvec_minmax,
902 .strategy = &sysctl_intvec,
904 .extra2 = &one_hundred,
907 .ctl_name = VM_DIRTY_RATIO,
908 .procname = "dirty_ratio",
909 .data = &vm_dirty_ratio,
910 .maxlen = sizeof(vm_dirty_ratio),
912 .proc_handler = &dirty_ratio_handler,
913 .strategy = &sysctl_intvec,
915 .extra2 = &one_hundred,
918 .procname = "dirty_writeback_centisecs",
919 .data = &dirty_writeback_interval,
920 .maxlen = sizeof(dirty_writeback_interval),
922 .proc_handler = &dirty_writeback_centisecs_handler,
925 .procname = "dirty_expire_centisecs",
926 .data = &dirty_expire_interval,
927 .maxlen = sizeof(dirty_expire_interval),
929 .proc_handler = &proc_dointvec_userhz_jiffies,
932 .ctl_name = VM_NR_PDFLUSH_THREADS,
933 .procname = "nr_pdflush_threads",
934 .data = &nr_pdflush_threads,
935 .maxlen = sizeof nr_pdflush_threads,
936 .mode = 0444 /* read-only*/,
937 .proc_handler = &proc_dointvec,
940 .ctl_name = VM_SWAPPINESS,
941 .procname = "swappiness",
942 .data = &vm_swappiness,
943 .maxlen = sizeof(vm_swappiness),
945 .proc_handler = &proc_dointvec_minmax,
946 .strategy = &sysctl_intvec,
948 .extra2 = &one_hundred,
950 #ifdef CONFIG_HUGETLB_PAGE
952 .procname = "nr_hugepages",
954 .maxlen = sizeof(unsigned long),
956 .proc_handler = &hugetlb_sysctl_handler,
957 .extra1 = (void *)&hugetlb_zero,
958 .extra2 = (void *)&hugetlb_infinity,
961 .ctl_name = VM_HUGETLB_GROUP,
962 .procname = "hugetlb_shm_group",
963 .data = &sysctl_hugetlb_shm_group,
964 .maxlen = sizeof(gid_t),
966 .proc_handler = &proc_dointvec,
969 .ctl_name = CTL_UNNUMBERED,
970 .procname = "hugepages_treat_as_movable",
971 .data = &hugepages_treat_as_movable,
972 .maxlen = sizeof(int),
974 .proc_handler = &hugetlb_treat_movable_handler,
977 .ctl_name = CTL_UNNUMBERED,
978 .procname = "nr_overcommit_hugepages",
980 .maxlen = sizeof(unsigned long),
982 .proc_handler = &hugetlb_overcommit_handler,
983 .extra1 = (void *)&hugetlb_zero,
984 .extra2 = (void *)&hugetlb_infinity,
988 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
989 .procname = "lowmem_reserve_ratio",
990 .data = &sysctl_lowmem_reserve_ratio,
991 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
993 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
994 .strategy = &sysctl_intvec,
997 .ctl_name = VM_DROP_PAGECACHE,
998 .procname = "drop_caches",
999 .data = &sysctl_drop_caches,
1000 .maxlen = sizeof(int),
1002 .proc_handler = drop_caches_sysctl_handler,
1003 .strategy = &sysctl_intvec,
1006 .ctl_name = VM_MIN_FREE_KBYTES,
1007 .procname = "min_free_kbytes",
1008 .data = &min_free_kbytes,
1009 .maxlen = sizeof(min_free_kbytes),
1011 .proc_handler = &min_free_kbytes_sysctl_handler,
1012 .strategy = &sysctl_intvec,
1016 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1017 .procname = "percpu_pagelist_fraction",
1018 .data = &percpu_pagelist_fraction,
1019 .maxlen = sizeof(percpu_pagelist_fraction),
1021 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1022 .strategy = &sysctl_intvec,
1023 .extra1 = &min_percpu_pagelist_fract,
1027 .ctl_name = VM_MAX_MAP_COUNT,
1028 .procname = "max_map_count",
1029 .data = &sysctl_max_map_count,
1030 .maxlen = sizeof(sysctl_max_map_count),
1032 .proc_handler = &proc_dointvec
1036 .ctl_name = VM_LAPTOP_MODE,
1037 .procname = "laptop_mode",
1038 .data = &laptop_mode,
1039 .maxlen = sizeof(laptop_mode),
1041 .proc_handler = &proc_dointvec_jiffies,
1042 .strategy = &sysctl_jiffies,
1045 .ctl_name = VM_BLOCK_DUMP,
1046 .procname = "block_dump",
1047 .data = &block_dump,
1048 .maxlen = sizeof(block_dump),
1050 .proc_handler = &proc_dointvec,
1051 .strategy = &sysctl_intvec,
1055 .ctl_name = VM_VFS_CACHE_PRESSURE,
1056 .procname = "vfs_cache_pressure",
1057 .data = &sysctl_vfs_cache_pressure,
1058 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1060 .proc_handler = &proc_dointvec,
1061 .strategy = &sysctl_intvec,
1064 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1066 .ctl_name = VM_LEGACY_VA_LAYOUT,
1067 .procname = "legacy_va_layout",
1068 .data = &sysctl_legacy_va_layout,
1069 .maxlen = sizeof(sysctl_legacy_va_layout),
1071 .proc_handler = &proc_dointvec,
1072 .strategy = &sysctl_intvec,
1078 .ctl_name = VM_ZONE_RECLAIM_MODE,
1079 .procname = "zone_reclaim_mode",
1080 .data = &zone_reclaim_mode,
1081 .maxlen = sizeof(zone_reclaim_mode),
1083 .proc_handler = &proc_dointvec,
1084 .strategy = &sysctl_intvec,
1088 .ctl_name = VM_MIN_UNMAPPED,
1089 .procname = "min_unmapped_ratio",
1090 .data = &sysctl_min_unmapped_ratio,
1091 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1093 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1094 .strategy = &sysctl_intvec,
1096 .extra2 = &one_hundred,
1099 .ctl_name = VM_MIN_SLAB,
1100 .procname = "min_slab_ratio",
1101 .data = &sysctl_min_slab_ratio,
1102 .maxlen = sizeof(sysctl_min_slab_ratio),
1104 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1105 .strategy = &sysctl_intvec,
1107 .extra2 = &one_hundred,
1112 .ctl_name = CTL_UNNUMBERED,
1113 .procname = "stat_interval",
1114 .data = &sysctl_stat_interval,
1115 .maxlen = sizeof(sysctl_stat_interval),
1117 .proc_handler = &proc_dointvec_jiffies,
1118 .strategy = &sysctl_jiffies,
1121 #ifdef CONFIG_SECURITY
1123 .ctl_name = CTL_UNNUMBERED,
1124 .procname = "mmap_min_addr",
1125 .data = &mmap_min_addr,
1126 .maxlen = sizeof(unsigned long),
1128 .proc_handler = &proc_doulongvec_minmax,
1133 .ctl_name = CTL_UNNUMBERED,
1134 .procname = "numa_zonelist_order",
1135 .data = &numa_zonelist_order,
1136 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1138 .proc_handler = &numa_zonelist_order_handler,
1139 .strategy = &sysctl_string,
1142 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1143 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1145 .ctl_name = VM_VDSO_ENABLED,
1146 .procname = "vdso_enabled",
1147 .data = &vdso_enabled,
1148 .maxlen = sizeof(vdso_enabled),
1150 .proc_handler = &proc_dointvec,
1151 .strategy = &sysctl_intvec,
1155 #ifdef CONFIG_HIGHMEM
1157 .ctl_name = CTL_UNNUMBERED,
1158 .procname = "highmem_is_dirtyable",
1159 .data = &vm_highmem_is_dirtyable,
1160 .maxlen = sizeof(vm_highmem_is_dirtyable),
1162 .proc_handler = &proc_dointvec_minmax,
1163 .strategy = &sysctl_intvec,
1169 * NOTE: do not add new entries to this table unless you have read
1170 * Documentation/sysctl/ctl_unnumbered.txt
1175 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1176 static struct ctl_table binfmt_misc_table[] = {
1181 static struct ctl_table fs_table[] = {
1183 .ctl_name = FS_NRINODE,
1184 .procname = "inode-nr",
1185 .data = &inodes_stat,
1186 .maxlen = 2*sizeof(int),
1188 .proc_handler = &proc_dointvec,
1191 .ctl_name = FS_STATINODE,
1192 .procname = "inode-state",
1193 .data = &inodes_stat,
1194 .maxlen = 7*sizeof(int),
1196 .proc_handler = &proc_dointvec,
1199 .procname = "file-nr",
1200 .data = &files_stat,
1201 .maxlen = 3*sizeof(int),
1203 .proc_handler = &proc_nr_files,
1206 .ctl_name = FS_MAXFILE,
1207 .procname = "file-max",
1208 .data = &files_stat.max_files,
1209 .maxlen = sizeof(int),
1211 .proc_handler = &proc_dointvec,
1214 .ctl_name = CTL_UNNUMBERED,
1215 .procname = "nr_open",
1216 .data = &sysctl_nr_open,
1217 .maxlen = sizeof(int),
1219 .proc_handler = &proc_dointvec_minmax,
1220 .extra1 = &sysctl_nr_open_min,
1221 .extra2 = &sysctl_nr_open_max,
1224 .ctl_name = FS_DENTRY,
1225 .procname = "dentry-state",
1226 .data = &dentry_stat,
1227 .maxlen = 6*sizeof(int),
1229 .proc_handler = &proc_dointvec,
1232 .ctl_name = FS_OVERFLOWUID,
1233 .procname = "overflowuid",
1234 .data = &fs_overflowuid,
1235 .maxlen = sizeof(int),
1237 .proc_handler = &proc_dointvec_minmax,
1238 .strategy = &sysctl_intvec,
1239 .extra1 = &minolduid,
1240 .extra2 = &maxolduid,
1243 .ctl_name = FS_OVERFLOWGID,
1244 .procname = "overflowgid",
1245 .data = &fs_overflowgid,
1246 .maxlen = sizeof(int),
1248 .proc_handler = &proc_dointvec_minmax,
1249 .strategy = &sysctl_intvec,
1250 .extra1 = &minolduid,
1251 .extra2 = &maxolduid,
1254 .ctl_name = FS_LEASES,
1255 .procname = "leases-enable",
1256 .data = &leases_enable,
1257 .maxlen = sizeof(int),
1259 .proc_handler = &proc_dointvec,
1261 #ifdef CONFIG_DNOTIFY
1263 .ctl_name = FS_DIR_NOTIFY,
1264 .procname = "dir-notify-enable",
1265 .data = &dir_notify_enable,
1266 .maxlen = sizeof(int),
1268 .proc_handler = &proc_dointvec,
1273 .ctl_name = FS_LEASE_TIME,
1274 .procname = "lease-break-time",
1275 .data = &lease_break_time,
1276 .maxlen = sizeof(int),
1278 .proc_handler = &proc_dointvec_minmax,
1279 .strategy = &sysctl_intvec,
1284 .procname = "aio-nr",
1286 .maxlen = sizeof(aio_nr),
1288 .proc_handler = &proc_doulongvec_minmax,
1291 .procname = "aio-max-nr",
1292 .data = &aio_max_nr,
1293 .maxlen = sizeof(aio_max_nr),
1295 .proc_handler = &proc_doulongvec_minmax,
1297 #ifdef CONFIG_INOTIFY_USER
1299 .ctl_name = FS_INOTIFY,
1300 .procname = "inotify",
1302 .child = inotify_table,
1307 .ctl_name = KERN_SETUID_DUMPABLE,
1308 .procname = "suid_dumpable",
1309 .data = &suid_dumpable,
1310 .maxlen = sizeof(int),
1312 .proc_handler = &proc_dointvec,
1314 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1316 .ctl_name = CTL_UNNUMBERED,
1317 .procname = "binfmt_misc",
1319 .child = binfmt_misc_table,
1323 * NOTE: do not add new entries to this table unless you have read
1324 * Documentation/sysctl/ctl_unnumbered.txt
1329 static struct ctl_table debug_table[] = {
1330 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1332 .ctl_name = CTL_UNNUMBERED,
1333 .procname = "exception-trace",
1334 .data = &show_unhandled_signals,
1335 .maxlen = sizeof(int),
1337 .proc_handler = proc_dointvec
1343 static struct ctl_table dev_table[] = {
1347 static DEFINE_SPINLOCK(sysctl_lock);
1349 /* called under sysctl_lock */
1350 static int use_table(struct ctl_table_header *p)
1352 if (unlikely(p->unregistering))
1358 /* called under sysctl_lock */
1359 static void unuse_table(struct ctl_table_header *p)
1362 if (unlikely(p->unregistering))
1363 complete(p->unregistering);
1366 /* called under sysctl_lock, will reacquire if has to wait */
1367 static void start_unregistering(struct ctl_table_header *p)
1370 * if p->used is 0, nobody will ever touch that entry again;
1371 * we'll eliminate all paths to it before dropping sysctl_lock
1373 if (unlikely(p->used)) {
1374 struct completion wait;
1375 init_completion(&wait);
1376 p->unregistering = &wait;
1377 spin_unlock(&sysctl_lock);
1378 wait_for_completion(&wait);
1379 spin_lock(&sysctl_lock);
1381 /* anything non-NULL; we'll never dereference it */
1382 p->unregistering = ERR_PTR(-EINVAL);
1385 * do not remove from the list until nobody holds it; walking the
1386 * list in do_sysctl() relies on that.
1388 list_del_init(&p->ctl_entry);
1391 void sysctl_head_get(struct ctl_table_header *head)
1393 spin_lock(&sysctl_lock);
1395 spin_unlock(&sysctl_lock);
1398 void sysctl_head_put(struct ctl_table_header *head)
1400 spin_lock(&sysctl_lock);
1403 spin_unlock(&sysctl_lock);
1406 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1410 spin_lock(&sysctl_lock);
1411 if (!use_table(head))
1412 head = ERR_PTR(-ENOENT);
1413 spin_unlock(&sysctl_lock);
1417 void sysctl_head_finish(struct ctl_table_header *head)
1421 spin_lock(&sysctl_lock);
1423 spin_unlock(&sysctl_lock);
1426 static struct ctl_table_set *
1427 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1429 struct ctl_table_set *set = &root->default_set;
1431 set = root->lookup(root, namespaces);
1435 static struct list_head *
1436 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1438 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1442 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1443 struct ctl_table_header *prev)
1445 struct ctl_table_root *root;
1446 struct list_head *header_list;
1447 struct ctl_table_header *head;
1448 struct list_head *tmp;
1450 spin_lock(&sysctl_lock);
1453 tmp = &prev->ctl_entry;
1457 tmp = &root_table_header.ctl_entry;
1459 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1461 if (!use_table(head))
1463 spin_unlock(&sysctl_lock);
1468 header_list = lookup_header_list(root, namespaces);
1469 if (tmp != header_list)
1473 root = list_entry(root->root_list.next,
1474 struct ctl_table_root, root_list);
1475 if (root == &sysctl_table_root)
1477 header_list = lookup_header_list(root, namespaces);
1478 } while (list_empty(header_list));
1479 tmp = header_list->next;
1482 spin_unlock(&sysctl_lock);
1486 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1488 return __sysctl_head_next(current->nsproxy, prev);
1491 void register_sysctl_root(struct ctl_table_root *root)
1493 spin_lock(&sysctl_lock);
1494 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1495 spin_unlock(&sysctl_lock);
1498 #ifdef CONFIG_SYSCTL_SYSCALL
1499 /* Perform the actual read/write of a sysctl table entry. */
1500 static int do_sysctl_strategy(struct ctl_table_root *root,
1501 struct ctl_table *table,
1502 int __user *name, int nlen,
1503 void __user *oldval, size_t __user *oldlenp,
1504 void __user *newval, size_t newlen)
1512 if (sysctl_perm(root, table, op))
1515 if (table->strategy) {
1516 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1524 /* If there is no strategy routine, or if the strategy returns
1525 * zero, proceed with automatic r/w */
1526 if (table->data && table->maxlen) {
1527 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1535 static int parse_table(int __user *name, int nlen,
1536 void __user *oldval, size_t __user *oldlenp,
1537 void __user *newval, size_t newlen,
1538 struct ctl_table_root *root,
1539 struct ctl_table *table)
1545 if (get_user(n, name))
1547 for ( ; table->ctl_name || table->procname; table++) {
1548 if (!table->ctl_name)
1550 if (n == table->ctl_name) {
1553 if (sysctl_perm(root, table, MAY_EXEC))
1557 table = table->child;
1560 error = do_sysctl_strategy(root, table, name, nlen,
1569 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1570 void __user *newval, size_t newlen)
1572 struct ctl_table_header *head;
1573 int error = -ENOTDIR;
1575 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1579 if (!oldlenp || get_user(old_len, oldlenp))
1583 for (head = sysctl_head_next(NULL); head;
1584 head = sysctl_head_next(head)) {
1585 error = parse_table(name, nlen, oldval, oldlenp,
1587 head->root, head->ctl_table);
1588 if (error != -ENOTDIR) {
1589 sysctl_head_finish(head);
1596 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1598 struct __sysctl_args tmp;
1601 if (copy_from_user(&tmp, args, sizeof(tmp)))
1604 error = deprecated_sysctl_warning(&tmp);
1609 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1610 tmp.newval, tmp.newlen);
1615 #endif /* CONFIG_SYSCTL_SYSCALL */
1618 * sysctl_perm does NOT grant the superuser all rights automatically, because
1619 * some sysctl variables are readonly even to root.
1622 static int test_perm(int mode, int op)
1626 else if (in_egroup_p(0))
1628 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1633 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1638 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1642 if (root->permissions)
1643 mode = root->permissions(root, current->nsproxy, table);
1647 return test_perm(mode, op);
1650 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1652 for (; table->ctl_name || table->procname; table++) {
1653 table->parent = parent;
1655 sysctl_set_parent(table, table->child);
1659 static __init int sysctl_init(void)
1661 sysctl_set_parent(NULL, root_table);
1662 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1665 err = sysctl_check_table(current->nsproxy, root_table);
1671 core_initcall(sysctl_init);
1673 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1674 struct ctl_table *table)
1676 struct ctl_table *p;
1677 const char *s = branch->procname;
1679 /* branch should have named subdirectory as its first element */
1680 if (!s || !branch->child)
1683 /* ... and nothing else */
1684 if (branch[1].procname || branch[1].ctl_name)
1687 /* table should contain subdirectory with the same name */
1688 for (p = table; p->procname || p->ctl_name; p++) {
1691 if (p->procname && strcmp(p->procname, s) == 0)
1697 /* see if attaching q to p would be an improvement */
1698 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1700 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1701 struct ctl_table *next;
1703 int not_in_parent = !p->attached_by;
1705 while ((next = is_branch_in(by, to)) != NULL) {
1706 if (by == q->attached_by)
1708 if (to == p->attached_by)
1714 if (is_better && not_in_parent) {
1715 q->attached_by = by;
1716 q->attached_to = to;
1722 * __register_sysctl_paths - register a sysctl hierarchy
1723 * @root: List of sysctl headers to register on
1724 * @namespaces: Data to compute which lists of sysctl entries are visible
1725 * @path: The path to the directory the sysctl table is in.
1726 * @table: the top-level table structure
1728 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1729 * array. A completely 0 filled entry terminates the table.
1731 * The members of the &struct ctl_table structure are used as follows:
1733 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1734 * must be unique within that level of sysctl
1736 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1737 * enter a sysctl file
1739 * data - a pointer to data for use by proc_handler
1741 * maxlen - the maximum size in bytes of the data
1743 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1745 * child - a pointer to the child sysctl table if this entry is a directory, or
1748 * proc_handler - the text handler routine (described below)
1750 * strategy - the strategy routine (described below)
1752 * de - for internal use by the sysctl routines
1754 * extra1, extra2 - extra pointers usable by the proc handler routines
1756 * Leaf nodes in the sysctl tree will be represented by a single file
1757 * under /proc; non-leaf nodes will be represented by directories.
1759 * sysctl(2) can automatically manage read and write requests through
1760 * the sysctl table. The data and maxlen fields of the ctl_table
1761 * struct enable minimal validation of the values being written to be
1762 * performed, and the mode field allows minimal authentication.
1764 * More sophisticated management can be enabled by the provision of a
1765 * strategy routine with the table entry. This will be called before
1766 * any automatic read or write of the data is performed.
1768 * The strategy routine may return
1770 * < 0 - Error occurred (error is passed to user process)
1772 * 0 - OK - proceed with automatic read or write.
1774 * > 0 - OK - read or write has been done by the strategy routine, so
1775 * return immediately.
1777 * There must be a proc_handler routine for any terminal nodes
1778 * mirrored under /proc/sys (non-terminals are handled by a built-in
1779 * directory handler). Several default handlers are available to
1780 * cover common cases -
1782 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1783 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1784 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1786 * It is the handler's job to read the input buffer from user memory
1787 * and process it. The handler should return 0 on success.
1789 * This routine returns %NULL on a failure to register, and a pointer
1790 * to the table header on success.
1792 struct ctl_table_header *__register_sysctl_paths(
1793 struct ctl_table_root *root,
1794 struct nsproxy *namespaces,
1795 const struct ctl_path *path, struct ctl_table *table)
1797 struct ctl_table_header *header;
1798 struct ctl_table *new, **prevp;
1799 unsigned int n, npath;
1800 struct ctl_table_set *set;
1802 /* Count the path components */
1803 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1807 * For each path component, allocate a 2-element ctl_table array.
1808 * The first array element will be filled with the sysctl entry
1809 * for this, the second will be the sentinel (ctl_name == 0).
1811 * We allocate everything in one go so that we don't have to
1812 * worry about freeing additional memory in unregister_sysctl_table.
1814 header = kzalloc(sizeof(struct ctl_table_header) +
1815 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1819 new = (struct ctl_table *) (header + 1);
1821 /* Now connect the dots */
1822 prevp = &header->ctl_table;
1823 for (n = 0; n < npath; ++n, ++path) {
1824 /* Copy the procname */
1825 new->procname = path->procname;
1826 new->ctl_name = path->ctl_name;
1830 prevp = &new->child;
1835 header->ctl_table_arg = table;
1837 INIT_LIST_HEAD(&header->ctl_entry);
1839 header->unregistering = NULL;
1840 header->root = root;
1841 sysctl_set_parent(NULL, header->ctl_table);
1843 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1844 if (sysctl_check_table(namespaces, header->ctl_table)) {
1849 spin_lock(&sysctl_lock);
1850 header->set = lookup_header_set(root, namespaces);
1851 header->attached_by = header->ctl_table;
1852 header->attached_to = root_table;
1853 header->parent = &root_table_header;
1854 for (set = header->set; set; set = set->parent) {
1855 struct ctl_table_header *p;
1856 list_for_each_entry(p, &set->list, ctl_entry) {
1857 if (p->unregistering)
1859 try_attach(p, header);
1862 header->parent->count++;
1863 list_add_tail(&header->ctl_entry, &header->set->list);
1864 spin_unlock(&sysctl_lock);
1870 * register_sysctl_table_path - register a sysctl table hierarchy
1871 * @path: The path to the directory the sysctl table is in.
1872 * @table: the top-level table structure
1874 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1875 * array. A completely 0 filled entry terminates the table.
1877 * See __register_sysctl_paths for more details.
1879 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1880 struct ctl_table *table)
1882 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1887 * register_sysctl_table - register a sysctl table hierarchy
1888 * @table: the top-level table structure
1890 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1891 * array. A completely 0 filled entry terminates the table.
1893 * See register_sysctl_paths for more details.
1895 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1897 static const struct ctl_path null_path[] = { {} };
1899 return register_sysctl_paths(null_path, table);
1903 * unregister_sysctl_table - unregister a sysctl table hierarchy
1904 * @header: the header returned from register_sysctl_table
1906 * Unregisters the sysctl table and all children. proc entries may not
1907 * actually be removed until they are no longer used by anyone.
1909 void unregister_sysctl_table(struct ctl_table_header * header)
1916 spin_lock(&sysctl_lock);
1917 start_unregistering(header);
1918 if (!--header->parent->count) {
1920 kfree(header->parent);
1922 if (!--header->count)
1924 spin_unlock(&sysctl_lock);
1927 int sysctl_is_seen(struct ctl_table_header *p)
1929 struct ctl_table_set *set = p->set;
1931 spin_lock(&sysctl_lock);
1932 if (p->unregistering)
1934 else if (!set->is_seen)
1937 res = set->is_seen(set);
1938 spin_unlock(&sysctl_lock);
1942 void setup_sysctl_set(struct ctl_table_set *p,
1943 struct ctl_table_set *parent,
1944 int (*is_seen)(struct ctl_table_set *))
1946 INIT_LIST_HEAD(&p->list);
1947 p->parent = parent ? parent : &sysctl_table_root.default_set;
1948 p->is_seen = is_seen;
1951 #else /* !CONFIG_SYSCTL */
1952 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1957 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1958 struct ctl_table *table)
1963 void unregister_sysctl_table(struct ctl_table_header * table)
1967 void setup_sysctl_set(struct ctl_table_set *p,
1968 struct ctl_table_set *parent,
1969 int (*is_seen)(struct ctl_table_set *))
1973 void sysctl_head_put(struct ctl_table_header *head)
1977 #endif /* CONFIG_SYSCTL */
1983 #ifdef CONFIG_PROC_SYSCTL
1985 static int _proc_do_string(void* data, int maxlen, int write,
1986 struct file *filp, void __user *buffer,
1987 size_t *lenp, loff_t *ppos)
1993 if (!data || !maxlen || !*lenp) {
2001 while (len < *lenp) {
2002 if (get_user(c, p++))
2004 if (c == 0 || c == '\n')
2010 if(copy_from_user(data, buffer, len))
2012 ((char *) data)[len] = 0;
2030 if(copy_to_user(buffer, data, len))
2033 if(put_user('\n', ((char __user *) buffer) + len))
2044 * proc_dostring - read a string sysctl
2045 * @table: the sysctl table
2046 * @write: %TRUE if this is a write to the sysctl file
2047 * @filp: the file structure
2048 * @buffer: the user buffer
2049 * @lenp: the size of the user buffer
2050 * @ppos: file position
2052 * Reads/writes a string from/to the user buffer. If the kernel
2053 * buffer provided is not large enough to hold the string, the
2054 * string is truncated. The copied string is %NULL-terminated.
2055 * If the string is being read by the user process, it is copied
2056 * and a newline '\n' is added. It is truncated if the buffer is
2059 * Returns 0 on success.
2061 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2062 void __user *buffer, size_t *lenp, loff_t *ppos)
2064 return _proc_do_string(table->data, table->maxlen, write, filp,
2065 buffer, lenp, ppos);
2069 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2071 int write, void *data)
2074 *valp = *negp ? -*lvalp : *lvalp;
2079 *lvalp = (unsigned long)-val;
2082 *lvalp = (unsigned long)val;
2088 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2089 int write, struct file *filp, void __user *buffer,
2090 size_t *lenp, loff_t *ppos,
2091 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2092 int write, void *data),
2095 #define TMPBUFLEN 21
2096 int *i, vleft, first=1, neg, val;
2100 char buf[TMPBUFLEN], *p;
2101 char __user *s = buffer;
2103 if (!tbl_data || !table->maxlen || !*lenp ||
2104 (*ppos && !write)) {
2109 i = (int *) tbl_data;
2110 vleft = table->maxlen / sizeof(*i);
2114 conv = do_proc_dointvec_conv;
2116 for (; left && vleft--; i++, first=0) {
2131 if (len > sizeof(buf) - 1)
2132 len = sizeof(buf) - 1;
2133 if (copy_from_user(buf, s, len))
2137 if (*p == '-' && left > 1) {
2141 if (*p < '0' || *p > '9')
2144 lval = simple_strtoul(p, &p, 0);
2147 if ((len < left) && *p && !isspace(*p))
2154 if (conv(&neg, &lval, i, 1, data))
2161 if (conv(&neg, &lval, i, 0, data))
2164 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2168 if(copy_to_user(s, buf, len))
2175 if (!write && !first && left) {
2176 if(put_user('\n', s))
2183 if (get_user(c, s++))
2198 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2199 void __user *buffer, size_t *lenp, loff_t *ppos,
2200 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2201 int write, void *data),
2204 return __do_proc_dointvec(table->data, table, write, filp,
2205 buffer, lenp, ppos, conv, data);
2209 * proc_dointvec - read a vector of integers
2210 * @table: the sysctl table
2211 * @write: %TRUE if this is a write to the sysctl file
2212 * @filp: the file structure
2213 * @buffer: the user buffer
2214 * @lenp: the size of the user buffer
2215 * @ppos: file position
2217 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2218 * values from/to the user buffer, treated as an ASCII string.
2220 * Returns 0 on success.
2222 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2223 void __user *buffer, size_t *lenp, loff_t *ppos)
2225 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2233 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2235 int write, void *data)
2237 int op = *(int *)data;
2239 int val = *negp ? -*lvalp : *lvalp;
2241 case OP_SET: *valp = val; break;
2242 case OP_AND: *valp &= val; break;
2243 case OP_OR: *valp |= val; break;
2249 *lvalp = (unsigned long)-val;
2252 *lvalp = (unsigned long)val;
2259 * Taint values can only be increased
2261 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
2262 void __user *buffer, size_t *lenp, loff_t *ppos)
2266 if (write && !capable(CAP_SYS_ADMIN))
2270 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2271 do_proc_dointvec_bset_conv,&op);
2274 struct do_proc_dointvec_minmax_conv_param {
2279 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2281 int write, void *data)
2283 struct do_proc_dointvec_minmax_conv_param *param = data;
2285 int val = *negp ? -*lvalp : *lvalp;
2286 if ((param->min && *param->min > val) ||
2287 (param->max && *param->max < val))
2294 *lvalp = (unsigned long)-val;
2297 *lvalp = (unsigned long)val;
2304 * proc_dointvec_minmax - read a vector of integers with min/max values
2305 * @table: the sysctl table
2306 * @write: %TRUE if this is a write to the sysctl file
2307 * @filp: the file structure
2308 * @buffer: the user buffer
2309 * @lenp: the size of the user buffer
2310 * @ppos: file position
2312 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2313 * values from/to the user buffer, treated as an ASCII string.
2315 * This routine will ensure the values are within the range specified by
2316 * table->extra1 (min) and table->extra2 (max).
2318 * Returns 0 on success.
2320 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2321 void __user *buffer, size_t *lenp, loff_t *ppos)
2323 struct do_proc_dointvec_minmax_conv_param param = {
2324 .min = (int *) table->extra1,
2325 .max = (int *) table->extra2,
2327 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2328 do_proc_dointvec_minmax_conv, ¶m);
2331 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2333 void __user *buffer,
2334 size_t *lenp, loff_t *ppos,
2335 unsigned long convmul,
2336 unsigned long convdiv)
2338 #define TMPBUFLEN 21
2339 unsigned long *i, *min, *max, val;
2340 int vleft, first=1, neg;
2342 char buf[TMPBUFLEN], *p;
2343 char __user *s = buffer;
2345 if (!data || !table->maxlen || !*lenp ||
2346 (*ppos && !write)) {
2351 i = (unsigned long *) data;
2352 min = (unsigned long *) table->extra1;
2353 max = (unsigned long *) table->extra2;
2354 vleft = table->maxlen / sizeof(unsigned long);
2357 for (; left && vleft--; i++, min++, max++, first=0) {
2372 if (len > TMPBUFLEN-1)
2374 if (copy_from_user(buf, s, len))
2378 if (*p == '-' && left > 1) {
2382 if (*p < '0' || *p > '9')
2384 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2386 if ((len < left) && *p && !isspace(*p))
2395 if ((min && val < *min) || (max && val > *max))
2402 sprintf(p, "%lu", convdiv * (*i) / convmul);
2406 if(copy_to_user(s, buf, len))
2413 if (!write && !first && left) {
2414 if(put_user('\n', s))
2421 if (get_user(c, s++))
2436 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2438 void __user *buffer,
2439 size_t *lenp, loff_t *ppos,
2440 unsigned long convmul,
2441 unsigned long convdiv)
2443 return __do_proc_doulongvec_minmax(table->data, table, write,
2444 filp, buffer, lenp, ppos, convmul, convdiv);
2448 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2449 * @table: the sysctl table
2450 * @write: %TRUE if this is a write to the sysctl file
2451 * @filp: the file structure
2452 * @buffer: the user buffer
2453 * @lenp: the size of the user buffer
2454 * @ppos: file position
2456 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2457 * values from/to the user buffer, treated as an ASCII string.
2459 * This routine will ensure the values are within the range specified by
2460 * table->extra1 (min) and table->extra2 (max).
2462 * Returns 0 on success.
2464 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2465 void __user *buffer, size_t *lenp, loff_t *ppos)
2467 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2471 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2472 * @table: the sysctl table
2473 * @write: %TRUE if this is a write to the sysctl file
2474 * @filp: the file structure
2475 * @buffer: the user buffer
2476 * @lenp: the size of the user buffer
2477 * @ppos: file position
2479 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2480 * values from/to the user buffer, treated as an ASCII string. The values
2481 * are treated as milliseconds, and converted to jiffies when they are stored.
2483 * This routine will ensure the values are within the range specified by
2484 * table->extra1 (min) and table->extra2 (max).
2486 * Returns 0 on success.
2488 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2490 void __user *buffer,
2491 size_t *lenp, loff_t *ppos)
2493 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2494 lenp, ppos, HZ, 1000l);
2498 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2500 int write, void *data)
2503 if (*lvalp > LONG_MAX / HZ)
2505 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2511 lval = (unsigned long)-val;
2514 lval = (unsigned long)val;
2521 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2523 int write, void *data)
2526 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2528 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2534 lval = (unsigned long)-val;
2537 lval = (unsigned long)val;
2539 *lvalp = jiffies_to_clock_t(lval);
2544 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2546 int write, void *data)
2549 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2555 lval = (unsigned long)-val;
2558 lval = (unsigned long)val;
2560 *lvalp = jiffies_to_msecs(lval);
2566 * proc_dointvec_jiffies - read a vector of integers as seconds
2567 * @table: the sysctl table
2568 * @write: %TRUE if this is a write to the sysctl file
2569 * @filp: the file structure
2570 * @buffer: the user buffer
2571 * @lenp: the size of the user buffer
2572 * @ppos: file position
2574 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2575 * values from/to the user buffer, treated as an ASCII string.
2576 * The values read are assumed to be in seconds, and are converted into
2579 * Returns 0 on success.
2581 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2582 void __user *buffer, size_t *lenp, loff_t *ppos)
2584 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2585 do_proc_dointvec_jiffies_conv,NULL);
2589 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2590 * @table: the sysctl table
2591 * @write: %TRUE if this is a write to the sysctl file
2592 * @filp: the file structure
2593 * @buffer: the user buffer
2594 * @lenp: the size of the user buffer
2595 * @ppos: pointer to the file position
2597 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2598 * values from/to the user buffer, treated as an ASCII string.
2599 * The values read are assumed to be in 1/USER_HZ seconds, and
2600 * are converted into jiffies.
2602 * Returns 0 on success.
2604 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2605 void __user *buffer, size_t *lenp, loff_t *ppos)
2607 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2608 do_proc_dointvec_userhz_jiffies_conv,NULL);
2612 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2613 * @table: the sysctl table
2614 * @write: %TRUE if this is a write to the sysctl file
2615 * @filp: the file structure
2616 * @buffer: the user buffer
2617 * @lenp: the size of the user buffer
2618 * @ppos: file position
2619 * @ppos: the current position in the file
2621 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2622 * values from/to the user buffer, treated as an ASCII string.
2623 * The values read are assumed to be in 1/1000 seconds, and
2624 * are converted into jiffies.
2626 * Returns 0 on success.
2628 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2629 void __user *buffer, size_t *lenp, loff_t *ppos)
2631 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2632 do_proc_dointvec_ms_jiffies_conv, NULL);
2635 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2636 void __user *buffer, size_t *lenp, loff_t *ppos)
2638 struct pid *new_pid;
2642 tmp = pid_vnr(cad_pid);
2644 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2645 lenp, ppos, NULL, NULL);
2649 new_pid = find_get_pid(tmp);
2653 put_pid(xchg(&cad_pid, new_pid));
2657 #else /* CONFIG_PROC_FS */
2659 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2660 void __user *buffer, size_t *lenp, loff_t *ppos)
2665 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2666 void __user *buffer, size_t *lenp, loff_t *ppos)
2671 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2672 void __user *buffer, size_t *lenp, loff_t *ppos)
2677 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2678 void __user *buffer, size_t *lenp, loff_t *ppos)
2683 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2684 void __user *buffer, size_t *lenp, loff_t *ppos)
2689 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2690 void __user *buffer, size_t *lenp, loff_t *ppos)
2695 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2696 void __user *buffer, size_t *lenp, loff_t *ppos)
2701 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2703 void __user *buffer,
2704 size_t *lenp, loff_t *ppos)
2710 #endif /* CONFIG_PROC_FS */
2713 #ifdef CONFIG_SYSCTL_SYSCALL
2715 * General sysctl support routines
2718 /* The generic sysctl data routine (used if no strategy routine supplied) */
2719 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2720 void __user *oldval, size_t __user *oldlenp,
2721 void __user *newval, size_t newlen)
2725 /* Get out of I don't have a variable */
2726 if (!table->data || !table->maxlen)
2729 if (oldval && oldlenp) {
2730 if (get_user(len, oldlenp))
2733 if (len > table->maxlen)
2734 len = table->maxlen;
2735 if (copy_to_user(oldval, table->data, len))
2737 if (put_user(len, oldlenp))
2742 if (newval && newlen) {
2743 if (newlen > table->maxlen)
2744 newlen = table->maxlen;
2746 if (copy_from_user(table->data, newval, newlen))
2752 /* The generic string strategy routine: */
2753 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2754 void __user *oldval, size_t __user *oldlenp,
2755 void __user *newval, size_t newlen)
2757 if (!table->data || !table->maxlen)
2760 if (oldval && oldlenp) {
2762 if (get_user(bufsize, oldlenp))
2765 size_t len = strlen(table->data), copied;
2767 /* This shouldn't trigger for a well-formed sysctl */
2768 if (len > table->maxlen)
2769 len = table->maxlen;
2771 /* Copy up to a max of bufsize-1 bytes of the string */
2772 copied = (len >= bufsize) ? bufsize - 1 : len;
2774 if (copy_to_user(oldval, table->data, copied) ||
2775 put_user(0, (char __user *)(oldval + copied)))
2777 if (put_user(len, oldlenp))
2781 if (newval && newlen) {
2782 size_t len = newlen;
2783 if (len > table->maxlen)
2784 len = table->maxlen;
2785 if(copy_from_user(table->data, newval, len))
2787 if (len == table->maxlen)
2789 ((char *) table->data)[len] = 0;
2795 * This function makes sure that all of the integers in the vector
2796 * are between the minimum and maximum values given in the arrays
2797 * table->extra1 and table->extra2, respectively.
2799 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2800 void __user *oldval, size_t __user *oldlenp,
2801 void __user *newval, size_t newlen)
2804 if (newval && newlen) {
2805 int __user *vec = (int __user *) newval;
2806 int *min = (int *) table->extra1;
2807 int *max = (int *) table->extra2;
2811 if (newlen % sizeof(int) != 0)
2814 if (!table->extra1 && !table->extra2)
2817 if (newlen > table->maxlen)
2818 newlen = table->maxlen;
2819 length = newlen / sizeof(int);
2821 for (i = 0; i < length; i++) {
2823 if (get_user(value, vec + i))
2825 if (min && value < min[i])
2827 if (max && value > max[i])
2834 /* Strategy function to convert jiffies to seconds */
2835 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2836 void __user *oldval, size_t __user *oldlenp,
2837 void __user *newval, size_t newlen)
2839 if (oldval && oldlenp) {
2842 if (get_user(olen, oldlenp))
2847 if (olen < sizeof(int))
2850 val = *(int *)(table->data) / HZ;
2851 if (put_user(val, (int __user *)oldval))
2853 if (put_user(sizeof(int), oldlenp))
2857 if (newval && newlen) {
2859 if (newlen != sizeof(int))
2861 if (get_user(new, (int __user *)newval))
2863 *(int *)(table->data) = new*HZ;
2868 /* Strategy function to convert jiffies to seconds */
2869 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2870 void __user *oldval, size_t __user *oldlenp,
2871 void __user *newval, size_t newlen)
2873 if (oldval && oldlenp) {
2876 if (get_user(olen, oldlenp))
2881 if (olen < sizeof(int))
2884 val = jiffies_to_msecs(*(int *)(table->data));
2885 if (put_user(val, (int __user *)oldval))
2887 if (put_user(sizeof(int), oldlenp))
2891 if (newval && newlen) {
2893 if (newlen != sizeof(int))
2895 if (get_user(new, (int __user *)newval))
2897 *(int *)(table->data) = msecs_to_jiffies(new);
2904 #else /* CONFIG_SYSCTL_SYSCALL */
2907 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2909 struct __sysctl_args tmp;
2912 if (copy_from_user(&tmp, args, sizeof(tmp)))
2915 error = deprecated_sysctl_warning(&tmp);
2917 /* If no error reading the parameters then just -ENOSYS ... */
2924 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2925 void __user *oldval, size_t __user *oldlenp,
2926 void __user *newval, size_t newlen)
2931 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2932 void __user *oldval, size_t __user *oldlenp,
2933 void __user *newval, size_t newlen)
2938 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2939 void __user *oldval, size_t __user *oldlenp,
2940 void __user *newval, size_t newlen)
2945 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2946 void __user *oldval, size_t __user *oldlenp,
2947 void __user *newval, size_t newlen)
2952 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2953 void __user *oldval, size_t __user *oldlenp,
2954 void __user *newval, size_t newlen)
2959 #endif /* CONFIG_SYSCTL_SYSCALL */
2961 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2963 static int msg_count;
2964 int name[CTL_MAXNAME];
2967 /* Check args->nlen. */
2968 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2971 /* Read in the sysctl name for better debug message logging */
2972 for (i = 0; i < args->nlen; i++)
2973 if (get_user(name[i], args->name + i))
2976 /* Ignore accesses to kernel.version */
2977 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2980 if (msg_count < 5) {
2983 "warning: process `%s' used the deprecated sysctl "
2984 "system call with ", current->comm);
2985 for (i = 0; i < args->nlen; i++)
2986 printk("%d.", name[i]);
2993 * No sense putting this after each symbol definition, twice,
2994 * exception granted :-)
2996 EXPORT_SYMBOL(proc_dointvec);
2997 EXPORT_SYMBOL(proc_dointvec_jiffies);
2998 EXPORT_SYMBOL(proc_dointvec_minmax);
2999 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3000 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3001 EXPORT_SYMBOL(proc_dostring);
3002 EXPORT_SYMBOL(proc_doulongvec_minmax);
3003 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3004 EXPORT_SYMBOL(register_sysctl_table);
3005 EXPORT_SYMBOL(register_sysctl_paths);
3006 EXPORT_SYMBOL(sysctl_intvec);
3007 EXPORT_SYMBOL(sysctl_jiffies);
3008 EXPORT_SYMBOL(sysctl_ms_jiffies);
3009 EXPORT_SYMBOL(sysctl_string);
3010 EXPORT_SYMBOL(sysctl_data);
3011 EXPORT_SYMBOL(unregister_sysctl_table);