2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
52 #include <asm/uaccess.h>
53 #include <asm/processor.h>
57 #include <asm/stacktrace.h>
61 static int deprecated_sysctl_warning(struct __sysctl_args *args);
63 #if defined(CONFIG_SYSCTL)
65 /* External variables not in a header file. */
67 extern int print_fatal_signals;
68 extern int sysctl_overcommit_memory;
69 extern int sysctl_overcommit_ratio;
70 extern int sysctl_panic_on_oom;
71 extern int sysctl_oom_kill_allocating_task;
72 extern int sysctl_oom_dump_tasks;
73 extern int max_threads;
74 extern int core_uses_pid;
75 extern int suid_dumpable;
76 extern char core_pattern[];
78 extern int min_free_kbytes;
79 extern int pid_max_min, pid_max_max;
80 extern int sysctl_drop_caches;
81 extern int percpu_pagelist_fraction;
82 extern int compat_log;
83 extern int maps_protect;
84 extern int latencytop_enabled;
85 extern int sysctl_nr_open_min, sysctl_nr_open_max;
86 #ifdef CONFIG_RCU_TORTURE_TEST
87 extern int rcutorture_runnable;
88 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
90 /* Constants used for minimum and maximum */
91 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
95 #ifdef CONFIG_DETECT_SOFTLOCKUP
96 static int sixty = 60;
97 static int neg_one = -1;
105 static int one_hundred = 100;
107 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
108 static int maxolduid = 65535;
109 static int minolduid;
110 static int min_percpu_pagelist_fract = 8;
112 static int ngroups_max = NGROUPS_MAX;
114 #ifdef CONFIG_MODULES
115 extern char modprobe_path[];
117 #ifdef CONFIG_CHR_DEV_SG
118 extern int sg_big_buff;
122 #include <asm/system.h>
126 extern int pwrsw_enabled;
127 extern int unaligned_enabled;
131 #ifdef CONFIG_MATHEMU
132 extern int sysctl_ieee_emulation_warnings;
134 extern int sysctl_userprocess_debug;
135 extern int spin_retry;
138 #ifdef CONFIG_BSD_PROCESS_ACCT
139 extern int acct_parm[];
143 extern int no_unaligned_warning;
146 #ifdef CONFIG_RT_MUTEXES
147 extern int max_lock_depth;
150 #ifdef CONFIG_PROC_SYSCTL
151 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
152 void __user *buffer, size_t *lenp, loff_t *ppos);
153 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
154 void __user *buffer, size_t *lenp, loff_t *ppos);
157 static struct ctl_table root_table[];
158 static struct ctl_table_root sysctl_table_root;
159 static struct ctl_table_header root_table_header = {
160 .ctl_table = root_table,
161 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
162 .root = &sysctl_table_root,
163 .set = &sysctl_table_root.default_set,
165 static struct ctl_table_root sysctl_table_root = {
166 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
167 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
170 static struct ctl_table kern_table[];
171 static struct ctl_table vm_table[];
172 static struct ctl_table fs_table[];
173 static struct ctl_table debug_table[];
174 static struct ctl_table dev_table[];
175 extern struct ctl_table random_table[];
176 #ifdef CONFIG_INOTIFY_USER
177 extern struct ctl_table inotify_table[];
180 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
181 int sysctl_legacy_va_layout;
184 extern int prove_locking;
185 extern int lock_stat;
187 /* The default sysctl tables: */
189 static struct ctl_table root_table[] = {
191 .ctl_name = CTL_KERN,
192 .procname = "kernel",
209 .ctl_name = CTL_DEBUG,
212 .child = debug_table,
221 * NOTE: do not add new entries to this table unless you have read
222 * Documentation/sysctl/ctl_unnumbered.txt
227 #ifdef CONFIG_SCHED_DEBUG
228 static int min_sched_granularity_ns = 100000; /* 100 usecs */
229 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
230 static int min_wakeup_granularity_ns; /* 0 usecs */
231 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
234 static struct ctl_table kern_table[] = {
235 #ifdef CONFIG_SCHED_DEBUG
237 .ctl_name = CTL_UNNUMBERED,
238 .procname = "sched_min_granularity_ns",
239 .data = &sysctl_sched_min_granularity,
240 .maxlen = sizeof(unsigned int),
242 .proc_handler = &sched_nr_latency_handler,
243 .strategy = &sysctl_intvec,
244 .extra1 = &min_sched_granularity_ns,
245 .extra2 = &max_sched_granularity_ns,
248 .ctl_name = CTL_UNNUMBERED,
249 .procname = "sched_latency_ns",
250 .data = &sysctl_sched_latency,
251 .maxlen = sizeof(unsigned int),
253 .proc_handler = &sched_nr_latency_handler,
254 .strategy = &sysctl_intvec,
255 .extra1 = &min_sched_granularity_ns,
256 .extra2 = &max_sched_granularity_ns,
259 .ctl_name = CTL_UNNUMBERED,
260 .procname = "sched_wakeup_granularity_ns",
261 .data = &sysctl_sched_wakeup_granularity,
262 .maxlen = sizeof(unsigned int),
264 .proc_handler = &proc_dointvec_minmax,
265 .strategy = &sysctl_intvec,
266 .extra1 = &min_wakeup_granularity_ns,
267 .extra2 = &max_wakeup_granularity_ns,
270 .ctl_name = CTL_UNNUMBERED,
271 .procname = "sched_shares_ratelimit",
272 .data = &sysctl_sched_shares_ratelimit,
273 .maxlen = sizeof(unsigned int),
275 .proc_handler = &proc_dointvec,
278 .ctl_name = CTL_UNNUMBERED,
279 .procname = "sched_child_runs_first",
280 .data = &sysctl_sched_child_runs_first,
281 .maxlen = sizeof(unsigned int),
283 .proc_handler = &proc_dointvec,
286 .ctl_name = CTL_UNNUMBERED,
287 .procname = "sched_features",
288 .data = &sysctl_sched_features,
289 .maxlen = sizeof(unsigned int),
291 .proc_handler = &proc_dointvec,
294 .ctl_name = CTL_UNNUMBERED,
295 .procname = "sched_migration_cost",
296 .data = &sysctl_sched_migration_cost,
297 .maxlen = sizeof(unsigned int),
299 .proc_handler = &proc_dointvec,
302 .ctl_name = CTL_UNNUMBERED,
303 .procname = "sched_nr_migrate",
304 .data = &sysctl_sched_nr_migrate,
305 .maxlen = sizeof(unsigned int),
307 .proc_handler = &proc_dointvec,
311 .ctl_name = CTL_UNNUMBERED,
312 .procname = "sched_rt_period_us",
313 .data = &sysctl_sched_rt_period,
314 .maxlen = sizeof(unsigned int),
316 .proc_handler = &sched_rt_handler,
319 .ctl_name = CTL_UNNUMBERED,
320 .procname = "sched_rt_runtime_us",
321 .data = &sysctl_sched_rt_runtime,
322 .maxlen = sizeof(int),
324 .proc_handler = &sched_rt_handler,
327 .ctl_name = CTL_UNNUMBERED,
328 .procname = "sched_compat_yield",
329 .data = &sysctl_sched_compat_yield,
330 .maxlen = sizeof(unsigned int),
332 .proc_handler = &proc_dointvec,
334 #ifdef CONFIG_PROVE_LOCKING
336 .ctl_name = CTL_UNNUMBERED,
337 .procname = "prove_locking",
338 .data = &prove_locking,
339 .maxlen = sizeof(int),
341 .proc_handler = &proc_dointvec,
344 #ifdef CONFIG_LOCK_STAT
346 .ctl_name = CTL_UNNUMBERED,
347 .procname = "lock_stat",
349 .maxlen = sizeof(int),
351 .proc_handler = &proc_dointvec,
355 .ctl_name = KERN_PANIC,
357 .data = &panic_timeout,
358 .maxlen = sizeof(int),
360 .proc_handler = &proc_dointvec,
363 .ctl_name = KERN_CORE_USES_PID,
364 .procname = "core_uses_pid",
365 .data = &core_uses_pid,
366 .maxlen = sizeof(int),
368 .proc_handler = &proc_dointvec,
371 .ctl_name = KERN_CORE_PATTERN,
372 .procname = "core_pattern",
373 .data = core_pattern,
374 .maxlen = CORENAME_MAX_SIZE,
376 .proc_handler = &proc_dostring,
377 .strategy = &sysctl_string,
379 #ifdef CONFIG_PROC_SYSCTL
381 .procname = "tainted",
383 .maxlen = sizeof(int),
385 .proc_handler = &proc_dointvec_taint,
388 #ifdef CONFIG_LATENCYTOP
390 .procname = "latencytop",
391 .data = &latencytop_enabled,
392 .maxlen = sizeof(int),
394 .proc_handler = &proc_dointvec,
397 #ifdef CONFIG_BLK_DEV_INITRD
399 .ctl_name = KERN_REALROOTDEV,
400 .procname = "real-root-dev",
401 .data = &real_root_dev,
402 .maxlen = sizeof(int),
404 .proc_handler = &proc_dointvec,
408 .ctl_name = CTL_UNNUMBERED,
409 .procname = "print-fatal-signals",
410 .data = &print_fatal_signals,
411 .maxlen = sizeof(int),
413 .proc_handler = &proc_dointvec,
417 .ctl_name = KERN_SPARC_REBOOT,
418 .procname = "reboot-cmd",
419 .data = reboot_command,
422 .proc_handler = &proc_dostring,
423 .strategy = &sysctl_string,
426 .ctl_name = KERN_SPARC_STOP_A,
427 .procname = "stop-a",
428 .data = &stop_a_enabled,
429 .maxlen = sizeof (int),
431 .proc_handler = &proc_dointvec,
434 .ctl_name = KERN_SPARC_SCONS_PWROFF,
435 .procname = "scons-poweroff",
436 .data = &scons_pwroff,
437 .maxlen = sizeof (int),
439 .proc_handler = &proc_dointvec,
444 .ctl_name = KERN_HPPA_PWRSW,
445 .procname = "soft-power",
446 .data = &pwrsw_enabled,
447 .maxlen = sizeof (int),
449 .proc_handler = &proc_dointvec,
452 .ctl_name = KERN_HPPA_UNALIGNED,
453 .procname = "unaligned-trap",
454 .data = &unaligned_enabled,
455 .maxlen = sizeof (int),
457 .proc_handler = &proc_dointvec,
461 .ctl_name = KERN_CTLALTDEL,
462 .procname = "ctrl-alt-del",
464 .maxlen = sizeof(int),
466 .proc_handler = &proc_dointvec,
470 .ctl_name = CTL_UNNUMBERED,
471 .procname = "ftrace_enabled",
472 .data = &ftrace_enabled,
473 .maxlen = sizeof(int),
475 .proc_handler = &ftrace_enable_sysctl,
478 #ifdef CONFIG_MODULES
480 .ctl_name = KERN_MODPROBE,
481 .procname = "modprobe",
482 .data = &modprobe_path,
483 .maxlen = KMOD_PATH_LEN,
485 .proc_handler = &proc_dostring,
486 .strategy = &sysctl_string,
489 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
491 .ctl_name = KERN_HOTPLUG,
492 .procname = "hotplug",
493 .data = &uevent_helper,
494 .maxlen = UEVENT_HELPER_PATH_LEN,
496 .proc_handler = &proc_dostring,
497 .strategy = &sysctl_string,
500 #ifdef CONFIG_CHR_DEV_SG
502 .ctl_name = KERN_SG_BIG_BUFF,
503 .procname = "sg-big-buff",
504 .data = &sg_big_buff,
505 .maxlen = sizeof (int),
507 .proc_handler = &proc_dointvec,
510 #ifdef CONFIG_BSD_PROCESS_ACCT
512 .ctl_name = KERN_ACCT,
515 .maxlen = 3*sizeof(int),
517 .proc_handler = &proc_dointvec,
520 #ifdef CONFIG_MAGIC_SYSRQ
522 .ctl_name = KERN_SYSRQ,
524 .data = &__sysrq_enabled,
525 .maxlen = sizeof (int),
527 .proc_handler = &proc_dointvec,
530 #ifdef CONFIG_PROC_SYSCTL
532 .procname = "cad_pid",
534 .maxlen = sizeof (int),
536 .proc_handler = &proc_do_cad_pid,
540 .ctl_name = KERN_MAX_THREADS,
541 .procname = "threads-max",
542 .data = &max_threads,
543 .maxlen = sizeof(int),
545 .proc_handler = &proc_dointvec,
548 .ctl_name = KERN_RANDOM,
549 .procname = "random",
551 .child = random_table,
554 .ctl_name = KERN_OVERFLOWUID,
555 .procname = "overflowuid",
556 .data = &overflowuid,
557 .maxlen = sizeof(int),
559 .proc_handler = &proc_dointvec_minmax,
560 .strategy = &sysctl_intvec,
561 .extra1 = &minolduid,
562 .extra2 = &maxolduid,
565 .ctl_name = KERN_OVERFLOWGID,
566 .procname = "overflowgid",
567 .data = &overflowgid,
568 .maxlen = sizeof(int),
570 .proc_handler = &proc_dointvec_minmax,
571 .strategy = &sysctl_intvec,
572 .extra1 = &minolduid,
573 .extra2 = &maxolduid,
576 #ifdef CONFIG_MATHEMU
578 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
579 .procname = "ieee_emulation_warnings",
580 .data = &sysctl_ieee_emulation_warnings,
581 .maxlen = sizeof(int),
583 .proc_handler = &proc_dointvec,
587 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
588 .procname = "userprocess_debug",
589 .data = &sysctl_userprocess_debug,
590 .maxlen = sizeof(int),
592 .proc_handler = &proc_dointvec,
596 .ctl_name = KERN_PIDMAX,
597 .procname = "pid_max",
599 .maxlen = sizeof (int),
601 .proc_handler = &proc_dointvec_minmax,
602 .strategy = sysctl_intvec,
603 .extra1 = &pid_max_min,
604 .extra2 = &pid_max_max,
607 .ctl_name = KERN_PANIC_ON_OOPS,
608 .procname = "panic_on_oops",
609 .data = &panic_on_oops,
610 .maxlen = sizeof(int),
612 .proc_handler = &proc_dointvec,
614 #if defined CONFIG_PRINTK
616 .ctl_name = KERN_PRINTK,
617 .procname = "printk",
618 .data = &console_loglevel,
619 .maxlen = 4*sizeof(int),
621 .proc_handler = &proc_dointvec,
624 .ctl_name = KERN_PRINTK_RATELIMIT,
625 .procname = "printk_ratelimit",
626 .data = &printk_ratelimit_state.interval,
627 .maxlen = sizeof(int),
629 .proc_handler = &proc_dointvec_jiffies,
630 .strategy = &sysctl_jiffies,
633 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
634 .procname = "printk_ratelimit_burst",
635 .data = &printk_ratelimit_state.burst,
636 .maxlen = sizeof(int),
638 .proc_handler = &proc_dointvec,
642 .ctl_name = KERN_NGROUPS_MAX,
643 .procname = "ngroups_max",
644 .data = &ngroups_max,
645 .maxlen = sizeof (int),
647 .proc_handler = &proc_dointvec,
649 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
651 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
652 .procname = "unknown_nmi_panic",
653 .data = &unknown_nmi_panic,
654 .maxlen = sizeof (int),
656 .proc_handler = &proc_dointvec,
659 .procname = "nmi_watchdog",
660 .data = &nmi_watchdog_enabled,
661 .maxlen = sizeof (int),
663 .proc_handler = &proc_nmi_enabled,
666 #if defined(CONFIG_X86)
668 .ctl_name = KERN_PANIC_ON_NMI,
669 .procname = "panic_on_unrecovered_nmi",
670 .data = &panic_on_unrecovered_nmi,
671 .maxlen = sizeof(int),
673 .proc_handler = &proc_dointvec,
676 .ctl_name = KERN_BOOTLOADER_TYPE,
677 .procname = "bootloader_type",
678 .data = &bootloader_type,
679 .maxlen = sizeof (int),
681 .proc_handler = &proc_dointvec,
684 .ctl_name = CTL_UNNUMBERED,
685 .procname = "kstack_depth_to_print",
686 .data = &kstack_depth_to_print,
687 .maxlen = sizeof(int),
689 .proc_handler = &proc_dointvec,
692 .ctl_name = CTL_UNNUMBERED,
693 .procname = "io_delay_type",
694 .data = &io_delay_type,
695 .maxlen = sizeof(int),
697 .proc_handler = &proc_dointvec,
700 #if defined(CONFIG_MMU)
702 .ctl_name = KERN_RANDOMIZE,
703 .procname = "randomize_va_space",
704 .data = &randomize_va_space,
705 .maxlen = sizeof(int),
707 .proc_handler = &proc_dointvec,
710 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
712 .ctl_name = KERN_SPIN_RETRY,
713 .procname = "spin_retry",
715 .maxlen = sizeof (int),
717 .proc_handler = &proc_dointvec,
720 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
722 .procname = "acpi_video_flags",
723 .data = &acpi_realmode_flags,
724 .maxlen = sizeof (unsigned long),
726 .proc_handler = &proc_doulongvec_minmax,
731 .ctl_name = KERN_IA64_UNALIGNED,
732 .procname = "ignore-unaligned-usertrap",
733 .data = &no_unaligned_warning,
734 .maxlen = sizeof (int),
736 .proc_handler = &proc_dointvec,
739 #ifdef CONFIG_DETECT_SOFTLOCKUP
741 .ctl_name = CTL_UNNUMBERED,
742 .procname = "softlockup_panic",
743 .data = &softlockup_panic,
744 .maxlen = sizeof(int),
746 .proc_handler = &proc_dointvec_minmax,
747 .strategy = &sysctl_intvec,
752 .ctl_name = CTL_UNNUMBERED,
753 .procname = "softlockup_thresh",
754 .data = &softlockup_thresh,
755 .maxlen = sizeof(int),
757 .proc_handler = &proc_dointvec_minmax,
758 .strategy = &sysctl_intvec,
763 .ctl_name = CTL_UNNUMBERED,
764 .procname = "hung_task_check_count",
765 .data = &sysctl_hung_task_check_count,
766 .maxlen = sizeof(unsigned long),
768 .proc_handler = &proc_doulongvec_minmax,
769 .strategy = &sysctl_intvec,
772 .ctl_name = CTL_UNNUMBERED,
773 .procname = "hung_task_timeout_secs",
774 .data = &sysctl_hung_task_timeout_secs,
775 .maxlen = sizeof(unsigned long),
777 .proc_handler = &proc_doulongvec_minmax,
778 .strategy = &sysctl_intvec,
781 .ctl_name = CTL_UNNUMBERED,
782 .procname = "hung_task_warnings",
783 .data = &sysctl_hung_task_warnings,
784 .maxlen = sizeof(unsigned long),
786 .proc_handler = &proc_doulongvec_minmax,
787 .strategy = &sysctl_intvec,
792 .ctl_name = KERN_COMPAT_LOG,
793 .procname = "compat-log",
795 .maxlen = sizeof (int),
797 .proc_handler = &proc_dointvec,
800 #ifdef CONFIG_RT_MUTEXES
802 .ctl_name = KERN_MAX_LOCK_DEPTH,
803 .procname = "max_lock_depth",
804 .data = &max_lock_depth,
805 .maxlen = sizeof(int),
807 .proc_handler = &proc_dointvec,
810 #ifdef CONFIG_PROC_FS
812 .ctl_name = CTL_UNNUMBERED,
813 .procname = "maps_protect",
814 .data = &maps_protect,
815 .maxlen = sizeof(int),
817 .proc_handler = &proc_dointvec,
821 .ctl_name = CTL_UNNUMBERED,
822 .procname = "poweroff_cmd",
823 .data = &poweroff_cmd,
824 .maxlen = POWEROFF_CMD_PATH_LEN,
826 .proc_handler = &proc_dostring,
827 .strategy = &sysctl_string,
831 .ctl_name = CTL_UNNUMBERED,
834 .child = key_sysctls,
837 #ifdef CONFIG_RCU_TORTURE_TEST
839 .ctl_name = CTL_UNNUMBERED,
840 .procname = "rcutorture_runnable",
841 .data = &rcutorture_runnable,
842 .maxlen = sizeof(int),
844 .proc_handler = &proc_dointvec,
848 * NOTE: do not add new entries to this table unless you have read
849 * Documentation/sysctl/ctl_unnumbered.txt
854 static struct ctl_table vm_table[] = {
856 .ctl_name = VM_OVERCOMMIT_MEMORY,
857 .procname = "overcommit_memory",
858 .data = &sysctl_overcommit_memory,
859 .maxlen = sizeof(sysctl_overcommit_memory),
861 .proc_handler = &proc_dointvec,
864 .ctl_name = VM_PANIC_ON_OOM,
865 .procname = "panic_on_oom",
866 .data = &sysctl_panic_on_oom,
867 .maxlen = sizeof(sysctl_panic_on_oom),
869 .proc_handler = &proc_dointvec,
872 .ctl_name = CTL_UNNUMBERED,
873 .procname = "oom_kill_allocating_task",
874 .data = &sysctl_oom_kill_allocating_task,
875 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
877 .proc_handler = &proc_dointvec,
880 .ctl_name = CTL_UNNUMBERED,
881 .procname = "oom_dump_tasks",
882 .data = &sysctl_oom_dump_tasks,
883 .maxlen = sizeof(sysctl_oom_dump_tasks),
885 .proc_handler = &proc_dointvec,
888 .ctl_name = VM_OVERCOMMIT_RATIO,
889 .procname = "overcommit_ratio",
890 .data = &sysctl_overcommit_ratio,
891 .maxlen = sizeof(sysctl_overcommit_ratio),
893 .proc_handler = &proc_dointvec,
896 .ctl_name = VM_PAGE_CLUSTER,
897 .procname = "page-cluster",
898 .data = &page_cluster,
899 .maxlen = sizeof(int),
901 .proc_handler = &proc_dointvec,
904 .ctl_name = VM_DIRTY_BACKGROUND,
905 .procname = "dirty_background_ratio",
906 .data = &dirty_background_ratio,
907 .maxlen = sizeof(dirty_background_ratio),
909 .proc_handler = &proc_dointvec_minmax,
910 .strategy = &sysctl_intvec,
912 .extra2 = &one_hundred,
915 .ctl_name = VM_DIRTY_RATIO,
916 .procname = "dirty_ratio",
917 .data = &vm_dirty_ratio,
918 .maxlen = sizeof(vm_dirty_ratio),
920 .proc_handler = &dirty_ratio_handler,
921 .strategy = &sysctl_intvec,
923 .extra2 = &one_hundred,
926 .procname = "dirty_writeback_centisecs",
927 .data = &dirty_writeback_interval,
928 .maxlen = sizeof(dirty_writeback_interval),
930 .proc_handler = &dirty_writeback_centisecs_handler,
933 .procname = "dirty_expire_centisecs",
934 .data = &dirty_expire_interval,
935 .maxlen = sizeof(dirty_expire_interval),
937 .proc_handler = &proc_dointvec_userhz_jiffies,
940 .ctl_name = VM_NR_PDFLUSH_THREADS,
941 .procname = "nr_pdflush_threads",
942 .data = &nr_pdflush_threads,
943 .maxlen = sizeof nr_pdflush_threads,
944 .mode = 0444 /* read-only*/,
945 .proc_handler = &proc_dointvec,
948 .ctl_name = VM_SWAPPINESS,
949 .procname = "swappiness",
950 .data = &vm_swappiness,
951 .maxlen = sizeof(vm_swappiness),
953 .proc_handler = &proc_dointvec_minmax,
954 .strategy = &sysctl_intvec,
956 .extra2 = &one_hundred,
958 #ifdef CONFIG_HUGETLB_PAGE
960 .procname = "nr_hugepages",
962 .maxlen = sizeof(unsigned long),
964 .proc_handler = &hugetlb_sysctl_handler,
965 .extra1 = (void *)&hugetlb_zero,
966 .extra2 = (void *)&hugetlb_infinity,
969 .ctl_name = VM_HUGETLB_GROUP,
970 .procname = "hugetlb_shm_group",
971 .data = &sysctl_hugetlb_shm_group,
972 .maxlen = sizeof(gid_t),
974 .proc_handler = &proc_dointvec,
977 .ctl_name = CTL_UNNUMBERED,
978 .procname = "hugepages_treat_as_movable",
979 .data = &hugepages_treat_as_movable,
980 .maxlen = sizeof(int),
982 .proc_handler = &hugetlb_treat_movable_handler,
985 .ctl_name = CTL_UNNUMBERED,
986 .procname = "nr_overcommit_hugepages",
988 .maxlen = sizeof(unsigned long),
990 .proc_handler = &hugetlb_overcommit_handler,
991 .extra1 = (void *)&hugetlb_zero,
992 .extra2 = (void *)&hugetlb_infinity,
996 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
997 .procname = "lowmem_reserve_ratio",
998 .data = &sysctl_lowmem_reserve_ratio,
999 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1001 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1002 .strategy = &sysctl_intvec,
1005 .ctl_name = VM_DROP_PAGECACHE,
1006 .procname = "drop_caches",
1007 .data = &sysctl_drop_caches,
1008 .maxlen = sizeof(int),
1010 .proc_handler = drop_caches_sysctl_handler,
1011 .strategy = &sysctl_intvec,
1014 .ctl_name = VM_MIN_FREE_KBYTES,
1015 .procname = "min_free_kbytes",
1016 .data = &min_free_kbytes,
1017 .maxlen = sizeof(min_free_kbytes),
1019 .proc_handler = &min_free_kbytes_sysctl_handler,
1020 .strategy = &sysctl_intvec,
1024 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1025 .procname = "percpu_pagelist_fraction",
1026 .data = &percpu_pagelist_fraction,
1027 .maxlen = sizeof(percpu_pagelist_fraction),
1029 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1030 .strategy = &sysctl_intvec,
1031 .extra1 = &min_percpu_pagelist_fract,
1035 .ctl_name = VM_MAX_MAP_COUNT,
1036 .procname = "max_map_count",
1037 .data = &sysctl_max_map_count,
1038 .maxlen = sizeof(sysctl_max_map_count),
1040 .proc_handler = &proc_dointvec
1044 .ctl_name = VM_LAPTOP_MODE,
1045 .procname = "laptop_mode",
1046 .data = &laptop_mode,
1047 .maxlen = sizeof(laptop_mode),
1049 .proc_handler = &proc_dointvec_jiffies,
1050 .strategy = &sysctl_jiffies,
1053 .ctl_name = VM_BLOCK_DUMP,
1054 .procname = "block_dump",
1055 .data = &block_dump,
1056 .maxlen = sizeof(block_dump),
1058 .proc_handler = &proc_dointvec,
1059 .strategy = &sysctl_intvec,
1063 .ctl_name = VM_VFS_CACHE_PRESSURE,
1064 .procname = "vfs_cache_pressure",
1065 .data = &sysctl_vfs_cache_pressure,
1066 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1068 .proc_handler = &proc_dointvec,
1069 .strategy = &sysctl_intvec,
1072 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1074 .ctl_name = VM_LEGACY_VA_LAYOUT,
1075 .procname = "legacy_va_layout",
1076 .data = &sysctl_legacy_va_layout,
1077 .maxlen = sizeof(sysctl_legacy_va_layout),
1079 .proc_handler = &proc_dointvec,
1080 .strategy = &sysctl_intvec,
1086 .ctl_name = VM_ZONE_RECLAIM_MODE,
1087 .procname = "zone_reclaim_mode",
1088 .data = &zone_reclaim_mode,
1089 .maxlen = sizeof(zone_reclaim_mode),
1091 .proc_handler = &proc_dointvec,
1092 .strategy = &sysctl_intvec,
1096 .ctl_name = VM_MIN_UNMAPPED,
1097 .procname = "min_unmapped_ratio",
1098 .data = &sysctl_min_unmapped_ratio,
1099 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1101 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1102 .strategy = &sysctl_intvec,
1104 .extra2 = &one_hundred,
1107 .ctl_name = VM_MIN_SLAB,
1108 .procname = "min_slab_ratio",
1109 .data = &sysctl_min_slab_ratio,
1110 .maxlen = sizeof(sysctl_min_slab_ratio),
1112 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1113 .strategy = &sysctl_intvec,
1115 .extra2 = &one_hundred,
1120 .ctl_name = CTL_UNNUMBERED,
1121 .procname = "stat_interval",
1122 .data = &sysctl_stat_interval,
1123 .maxlen = sizeof(sysctl_stat_interval),
1125 .proc_handler = &proc_dointvec_jiffies,
1126 .strategy = &sysctl_jiffies,
1129 #ifdef CONFIG_SECURITY
1131 .ctl_name = CTL_UNNUMBERED,
1132 .procname = "mmap_min_addr",
1133 .data = &mmap_min_addr,
1134 .maxlen = sizeof(unsigned long),
1136 .proc_handler = &proc_doulongvec_minmax,
1141 .ctl_name = CTL_UNNUMBERED,
1142 .procname = "numa_zonelist_order",
1143 .data = &numa_zonelist_order,
1144 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1146 .proc_handler = &numa_zonelist_order_handler,
1147 .strategy = &sysctl_string,
1150 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1151 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1153 .ctl_name = VM_VDSO_ENABLED,
1154 .procname = "vdso_enabled",
1155 .data = &vdso_enabled,
1156 .maxlen = sizeof(vdso_enabled),
1158 .proc_handler = &proc_dointvec,
1159 .strategy = &sysctl_intvec,
1163 #ifdef CONFIG_HIGHMEM
1165 .ctl_name = CTL_UNNUMBERED,
1166 .procname = "highmem_is_dirtyable",
1167 .data = &vm_highmem_is_dirtyable,
1168 .maxlen = sizeof(vm_highmem_is_dirtyable),
1170 .proc_handler = &proc_dointvec_minmax,
1171 .strategy = &sysctl_intvec,
1177 * NOTE: do not add new entries to this table unless you have read
1178 * Documentation/sysctl/ctl_unnumbered.txt
1183 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1184 static struct ctl_table binfmt_misc_table[] = {
1189 static struct ctl_table fs_table[] = {
1191 .ctl_name = FS_NRINODE,
1192 .procname = "inode-nr",
1193 .data = &inodes_stat,
1194 .maxlen = 2*sizeof(int),
1196 .proc_handler = &proc_dointvec,
1199 .ctl_name = FS_STATINODE,
1200 .procname = "inode-state",
1201 .data = &inodes_stat,
1202 .maxlen = 7*sizeof(int),
1204 .proc_handler = &proc_dointvec,
1207 .procname = "file-nr",
1208 .data = &files_stat,
1209 .maxlen = 3*sizeof(int),
1211 .proc_handler = &proc_nr_files,
1214 .ctl_name = FS_MAXFILE,
1215 .procname = "file-max",
1216 .data = &files_stat.max_files,
1217 .maxlen = sizeof(int),
1219 .proc_handler = &proc_dointvec,
1222 .ctl_name = CTL_UNNUMBERED,
1223 .procname = "nr_open",
1224 .data = &sysctl_nr_open,
1225 .maxlen = sizeof(int),
1227 .proc_handler = &proc_dointvec_minmax,
1228 .extra1 = &sysctl_nr_open_min,
1229 .extra2 = &sysctl_nr_open_max,
1232 .ctl_name = FS_DENTRY,
1233 .procname = "dentry-state",
1234 .data = &dentry_stat,
1235 .maxlen = 6*sizeof(int),
1237 .proc_handler = &proc_dointvec,
1240 .ctl_name = FS_OVERFLOWUID,
1241 .procname = "overflowuid",
1242 .data = &fs_overflowuid,
1243 .maxlen = sizeof(int),
1245 .proc_handler = &proc_dointvec_minmax,
1246 .strategy = &sysctl_intvec,
1247 .extra1 = &minolduid,
1248 .extra2 = &maxolduid,
1251 .ctl_name = FS_OVERFLOWGID,
1252 .procname = "overflowgid",
1253 .data = &fs_overflowgid,
1254 .maxlen = sizeof(int),
1256 .proc_handler = &proc_dointvec_minmax,
1257 .strategy = &sysctl_intvec,
1258 .extra1 = &minolduid,
1259 .extra2 = &maxolduid,
1262 .ctl_name = FS_LEASES,
1263 .procname = "leases-enable",
1264 .data = &leases_enable,
1265 .maxlen = sizeof(int),
1267 .proc_handler = &proc_dointvec,
1269 #ifdef CONFIG_DNOTIFY
1271 .ctl_name = FS_DIR_NOTIFY,
1272 .procname = "dir-notify-enable",
1273 .data = &dir_notify_enable,
1274 .maxlen = sizeof(int),
1276 .proc_handler = &proc_dointvec,
1281 .ctl_name = FS_LEASE_TIME,
1282 .procname = "lease-break-time",
1283 .data = &lease_break_time,
1284 .maxlen = sizeof(int),
1286 .proc_handler = &proc_dointvec_minmax,
1287 .strategy = &sysctl_intvec,
1292 .procname = "aio-nr",
1294 .maxlen = sizeof(aio_nr),
1296 .proc_handler = &proc_doulongvec_minmax,
1299 .procname = "aio-max-nr",
1300 .data = &aio_max_nr,
1301 .maxlen = sizeof(aio_max_nr),
1303 .proc_handler = &proc_doulongvec_minmax,
1305 #ifdef CONFIG_INOTIFY_USER
1307 .ctl_name = FS_INOTIFY,
1308 .procname = "inotify",
1310 .child = inotify_table,
1315 .ctl_name = KERN_SETUID_DUMPABLE,
1316 .procname = "suid_dumpable",
1317 .data = &suid_dumpable,
1318 .maxlen = sizeof(int),
1320 .proc_handler = &proc_dointvec,
1322 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1324 .ctl_name = CTL_UNNUMBERED,
1325 .procname = "binfmt_misc",
1327 .child = binfmt_misc_table,
1331 * NOTE: do not add new entries to this table unless you have read
1332 * Documentation/sysctl/ctl_unnumbered.txt
1337 static struct ctl_table debug_table[] = {
1338 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1340 .ctl_name = CTL_UNNUMBERED,
1341 .procname = "exception-trace",
1342 .data = &show_unhandled_signals,
1343 .maxlen = sizeof(int),
1345 .proc_handler = proc_dointvec
1351 static struct ctl_table dev_table[] = {
1355 static DEFINE_SPINLOCK(sysctl_lock);
1357 /* called under sysctl_lock */
1358 static int use_table(struct ctl_table_header *p)
1360 if (unlikely(p->unregistering))
1366 /* called under sysctl_lock */
1367 static void unuse_table(struct ctl_table_header *p)
1370 if (unlikely(p->unregistering))
1371 complete(p->unregistering);
1374 /* called under sysctl_lock, will reacquire if has to wait */
1375 static void start_unregistering(struct ctl_table_header *p)
1378 * if p->used is 0, nobody will ever touch that entry again;
1379 * we'll eliminate all paths to it before dropping sysctl_lock
1381 if (unlikely(p->used)) {
1382 struct completion wait;
1383 init_completion(&wait);
1384 p->unregistering = &wait;
1385 spin_unlock(&sysctl_lock);
1386 wait_for_completion(&wait);
1387 spin_lock(&sysctl_lock);
1389 /* anything non-NULL; we'll never dereference it */
1390 p->unregistering = ERR_PTR(-EINVAL);
1393 * do not remove from the list until nobody holds it; walking the
1394 * list in do_sysctl() relies on that.
1396 list_del_init(&p->ctl_entry);
1399 void sysctl_head_get(struct ctl_table_header *head)
1401 spin_lock(&sysctl_lock);
1403 spin_unlock(&sysctl_lock);
1406 void sysctl_head_put(struct ctl_table_header *head)
1408 spin_lock(&sysctl_lock);
1411 spin_unlock(&sysctl_lock);
1414 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1418 spin_lock(&sysctl_lock);
1419 if (!use_table(head))
1420 head = ERR_PTR(-ENOENT);
1421 spin_unlock(&sysctl_lock);
1425 void sysctl_head_finish(struct ctl_table_header *head)
1429 spin_lock(&sysctl_lock);
1431 spin_unlock(&sysctl_lock);
1434 static struct ctl_table_set *
1435 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1437 struct ctl_table_set *set = &root->default_set;
1439 set = root->lookup(root, namespaces);
1443 static struct list_head *
1444 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1446 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1450 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1451 struct ctl_table_header *prev)
1453 struct ctl_table_root *root;
1454 struct list_head *header_list;
1455 struct ctl_table_header *head;
1456 struct list_head *tmp;
1458 spin_lock(&sysctl_lock);
1461 tmp = &prev->ctl_entry;
1465 tmp = &root_table_header.ctl_entry;
1467 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1469 if (!use_table(head))
1471 spin_unlock(&sysctl_lock);
1476 header_list = lookup_header_list(root, namespaces);
1477 if (tmp != header_list)
1481 root = list_entry(root->root_list.next,
1482 struct ctl_table_root, root_list);
1483 if (root == &sysctl_table_root)
1485 header_list = lookup_header_list(root, namespaces);
1486 } while (list_empty(header_list));
1487 tmp = header_list->next;
1490 spin_unlock(&sysctl_lock);
1494 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1496 return __sysctl_head_next(current->nsproxy, prev);
1499 void register_sysctl_root(struct ctl_table_root *root)
1501 spin_lock(&sysctl_lock);
1502 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1503 spin_unlock(&sysctl_lock);
1506 #ifdef CONFIG_SYSCTL_SYSCALL
1507 /* Perform the actual read/write of a sysctl table entry. */
1508 static int do_sysctl_strategy(struct ctl_table_root *root,
1509 struct ctl_table *table,
1510 int __user *name, int nlen,
1511 void __user *oldval, size_t __user *oldlenp,
1512 void __user *newval, size_t newlen)
1520 if (sysctl_perm(root, table, op))
1523 if (table->strategy) {
1524 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1532 /* If there is no strategy routine, or if the strategy returns
1533 * zero, proceed with automatic r/w */
1534 if (table->data && table->maxlen) {
1535 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1543 static int parse_table(int __user *name, int nlen,
1544 void __user *oldval, size_t __user *oldlenp,
1545 void __user *newval, size_t newlen,
1546 struct ctl_table_root *root,
1547 struct ctl_table *table)
1553 if (get_user(n, name))
1555 for ( ; table->ctl_name || table->procname; table++) {
1556 if (!table->ctl_name)
1558 if (n == table->ctl_name) {
1561 if (sysctl_perm(root, table, MAY_EXEC))
1565 table = table->child;
1568 error = do_sysctl_strategy(root, table, name, nlen,
1577 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1578 void __user *newval, size_t newlen)
1580 struct ctl_table_header *head;
1581 int error = -ENOTDIR;
1583 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1587 if (!oldlenp || get_user(old_len, oldlenp))
1591 for (head = sysctl_head_next(NULL); head;
1592 head = sysctl_head_next(head)) {
1593 error = parse_table(name, nlen, oldval, oldlenp,
1595 head->root, head->ctl_table);
1596 if (error != -ENOTDIR) {
1597 sysctl_head_finish(head);
1604 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1606 struct __sysctl_args tmp;
1609 if (copy_from_user(&tmp, args, sizeof(tmp)))
1612 error = deprecated_sysctl_warning(&tmp);
1617 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1618 tmp.newval, tmp.newlen);
1623 #endif /* CONFIG_SYSCTL_SYSCALL */
1626 * sysctl_perm does NOT grant the superuser all rights automatically, because
1627 * some sysctl variables are readonly even to root.
1630 static int test_perm(int mode, int op)
1634 else if (in_egroup_p(0))
1636 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1641 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1646 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1650 if (root->permissions)
1651 mode = root->permissions(root, current->nsproxy, table);
1655 return test_perm(mode, op);
1658 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1660 for (; table->ctl_name || table->procname; table++) {
1661 table->parent = parent;
1663 sysctl_set_parent(table, table->child);
1667 static __init int sysctl_init(void)
1669 sysctl_set_parent(NULL, root_table);
1670 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1673 err = sysctl_check_table(current->nsproxy, root_table);
1679 core_initcall(sysctl_init);
1681 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1682 struct ctl_table *table)
1684 struct ctl_table *p;
1685 const char *s = branch->procname;
1687 /* branch should have named subdirectory as its first element */
1688 if (!s || !branch->child)
1691 /* ... and nothing else */
1692 if (branch[1].procname || branch[1].ctl_name)
1695 /* table should contain subdirectory with the same name */
1696 for (p = table; p->procname || p->ctl_name; p++) {
1699 if (p->procname && strcmp(p->procname, s) == 0)
1705 /* see if attaching q to p would be an improvement */
1706 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1708 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1709 struct ctl_table *next;
1711 int not_in_parent = !p->attached_by;
1713 while ((next = is_branch_in(by, to)) != NULL) {
1714 if (by == q->attached_by)
1716 if (to == p->attached_by)
1722 if (is_better && not_in_parent) {
1723 q->attached_by = by;
1724 q->attached_to = to;
1730 * __register_sysctl_paths - register a sysctl hierarchy
1731 * @root: List of sysctl headers to register on
1732 * @namespaces: Data to compute which lists of sysctl entries are visible
1733 * @path: The path to the directory the sysctl table is in.
1734 * @table: the top-level table structure
1736 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1737 * array. A completely 0 filled entry terminates the table.
1739 * The members of the &struct ctl_table structure are used as follows:
1741 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1742 * must be unique within that level of sysctl
1744 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1745 * enter a sysctl file
1747 * data - a pointer to data for use by proc_handler
1749 * maxlen - the maximum size in bytes of the data
1751 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1753 * child - a pointer to the child sysctl table if this entry is a directory, or
1756 * proc_handler - the text handler routine (described below)
1758 * strategy - the strategy routine (described below)
1760 * de - for internal use by the sysctl routines
1762 * extra1, extra2 - extra pointers usable by the proc handler routines
1764 * Leaf nodes in the sysctl tree will be represented by a single file
1765 * under /proc; non-leaf nodes will be represented by directories.
1767 * sysctl(2) can automatically manage read and write requests through
1768 * the sysctl table. The data and maxlen fields of the ctl_table
1769 * struct enable minimal validation of the values being written to be
1770 * performed, and the mode field allows minimal authentication.
1772 * More sophisticated management can be enabled by the provision of a
1773 * strategy routine with the table entry. This will be called before
1774 * any automatic read or write of the data is performed.
1776 * The strategy routine may return
1778 * < 0 - Error occurred (error is passed to user process)
1780 * 0 - OK - proceed with automatic read or write.
1782 * > 0 - OK - read or write has been done by the strategy routine, so
1783 * return immediately.
1785 * There must be a proc_handler routine for any terminal nodes
1786 * mirrored under /proc/sys (non-terminals are handled by a built-in
1787 * directory handler). Several default handlers are available to
1788 * cover common cases -
1790 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1791 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1792 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1794 * It is the handler's job to read the input buffer from user memory
1795 * and process it. The handler should return 0 on success.
1797 * This routine returns %NULL on a failure to register, and a pointer
1798 * to the table header on success.
1800 struct ctl_table_header *__register_sysctl_paths(
1801 struct ctl_table_root *root,
1802 struct nsproxy *namespaces,
1803 const struct ctl_path *path, struct ctl_table *table)
1805 struct ctl_table_header *header;
1806 struct ctl_table *new, **prevp;
1807 unsigned int n, npath;
1808 struct ctl_table_set *set;
1810 /* Count the path components */
1811 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1815 * For each path component, allocate a 2-element ctl_table array.
1816 * The first array element will be filled with the sysctl entry
1817 * for this, the second will be the sentinel (ctl_name == 0).
1819 * We allocate everything in one go so that we don't have to
1820 * worry about freeing additional memory in unregister_sysctl_table.
1822 header = kzalloc(sizeof(struct ctl_table_header) +
1823 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1827 new = (struct ctl_table *) (header + 1);
1829 /* Now connect the dots */
1830 prevp = &header->ctl_table;
1831 for (n = 0; n < npath; ++n, ++path) {
1832 /* Copy the procname */
1833 new->procname = path->procname;
1834 new->ctl_name = path->ctl_name;
1838 prevp = &new->child;
1843 header->ctl_table_arg = table;
1845 INIT_LIST_HEAD(&header->ctl_entry);
1847 header->unregistering = NULL;
1848 header->root = root;
1849 sysctl_set_parent(NULL, header->ctl_table);
1851 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1852 if (sysctl_check_table(namespaces, header->ctl_table)) {
1857 spin_lock(&sysctl_lock);
1858 header->set = lookup_header_set(root, namespaces);
1859 header->attached_by = header->ctl_table;
1860 header->attached_to = root_table;
1861 header->parent = &root_table_header;
1862 for (set = header->set; set; set = set->parent) {
1863 struct ctl_table_header *p;
1864 list_for_each_entry(p, &set->list, ctl_entry) {
1865 if (p->unregistering)
1867 try_attach(p, header);
1870 header->parent->count++;
1871 list_add_tail(&header->ctl_entry, &header->set->list);
1872 spin_unlock(&sysctl_lock);
1878 * register_sysctl_table_path - register a sysctl table hierarchy
1879 * @path: The path to the directory the sysctl table is in.
1880 * @table: the top-level table structure
1882 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1883 * array. A completely 0 filled entry terminates the table.
1885 * See __register_sysctl_paths for more details.
1887 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1888 struct ctl_table *table)
1890 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1895 * register_sysctl_table - register a sysctl table hierarchy
1896 * @table: the top-level table structure
1898 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1899 * array. A completely 0 filled entry terminates the table.
1901 * See register_sysctl_paths for more details.
1903 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1905 static const struct ctl_path null_path[] = { {} };
1907 return register_sysctl_paths(null_path, table);
1911 * unregister_sysctl_table - unregister a sysctl table hierarchy
1912 * @header: the header returned from register_sysctl_table
1914 * Unregisters the sysctl table and all children. proc entries may not
1915 * actually be removed until they are no longer used by anyone.
1917 void unregister_sysctl_table(struct ctl_table_header * header)
1924 spin_lock(&sysctl_lock);
1925 start_unregistering(header);
1926 if (!--header->parent->count) {
1928 kfree(header->parent);
1930 if (!--header->count)
1932 spin_unlock(&sysctl_lock);
1935 int sysctl_is_seen(struct ctl_table_header *p)
1937 struct ctl_table_set *set = p->set;
1939 spin_lock(&sysctl_lock);
1940 if (p->unregistering)
1942 else if (!set->is_seen)
1945 res = set->is_seen(set);
1946 spin_unlock(&sysctl_lock);
1950 void setup_sysctl_set(struct ctl_table_set *p,
1951 struct ctl_table_set *parent,
1952 int (*is_seen)(struct ctl_table_set *))
1954 INIT_LIST_HEAD(&p->list);
1955 p->parent = parent ? parent : &sysctl_table_root.default_set;
1956 p->is_seen = is_seen;
1959 #else /* !CONFIG_SYSCTL */
1960 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1965 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1966 struct ctl_table *table)
1971 void unregister_sysctl_table(struct ctl_table_header * table)
1975 void setup_sysctl_set(struct ctl_table_set *p,
1976 struct ctl_table_set *parent,
1977 int (*is_seen)(struct ctl_table_set *))
1981 void sysctl_head_put(struct ctl_table_header *head)
1985 #endif /* CONFIG_SYSCTL */
1991 #ifdef CONFIG_PROC_SYSCTL
1993 static int _proc_do_string(void* data, int maxlen, int write,
1994 struct file *filp, void __user *buffer,
1995 size_t *lenp, loff_t *ppos)
2001 if (!data || !maxlen || !*lenp) {
2009 while (len < *lenp) {
2010 if (get_user(c, p++))
2012 if (c == 0 || c == '\n')
2018 if(copy_from_user(data, buffer, len))
2020 ((char *) data)[len] = 0;
2038 if(copy_to_user(buffer, data, len))
2041 if(put_user('\n', ((char __user *) buffer) + len))
2052 * proc_dostring - read a string sysctl
2053 * @table: the sysctl table
2054 * @write: %TRUE if this is a write to the sysctl file
2055 * @filp: the file structure
2056 * @buffer: the user buffer
2057 * @lenp: the size of the user buffer
2058 * @ppos: file position
2060 * Reads/writes a string from/to the user buffer. If the kernel
2061 * buffer provided is not large enough to hold the string, the
2062 * string is truncated. The copied string is %NULL-terminated.
2063 * If the string is being read by the user process, it is copied
2064 * and a newline '\n' is added. It is truncated if the buffer is
2067 * Returns 0 on success.
2069 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2070 void __user *buffer, size_t *lenp, loff_t *ppos)
2072 return _proc_do_string(table->data, table->maxlen, write, filp,
2073 buffer, lenp, ppos);
2077 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2079 int write, void *data)
2082 *valp = *negp ? -*lvalp : *lvalp;
2087 *lvalp = (unsigned long)-val;
2090 *lvalp = (unsigned long)val;
2096 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2097 int write, struct file *filp, void __user *buffer,
2098 size_t *lenp, loff_t *ppos,
2099 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2100 int write, void *data),
2103 #define TMPBUFLEN 21
2104 int *i, vleft, first=1, neg, val;
2108 char buf[TMPBUFLEN], *p;
2109 char __user *s = buffer;
2111 if (!tbl_data || !table->maxlen || !*lenp ||
2112 (*ppos && !write)) {
2117 i = (int *) tbl_data;
2118 vleft = table->maxlen / sizeof(*i);
2122 conv = do_proc_dointvec_conv;
2124 for (; left && vleft--; i++, first=0) {
2139 if (len > sizeof(buf) - 1)
2140 len = sizeof(buf) - 1;
2141 if (copy_from_user(buf, s, len))
2145 if (*p == '-' && left > 1) {
2149 if (*p < '0' || *p > '9')
2152 lval = simple_strtoul(p, &p, 0);
2155 if ((len < left) && *p && !isspace(*p))
2162 if (conv(&neg, &lval, i, 1, data))
2169 if (conv(&neg, &lval, i, 0, data))
2172 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2176 if(copy_to_user(s, buf, len))
2183 if (!write && !first && left) {
2184 if(put_user('\n', s))
2191 if (get_user(c, s++))
2206 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2207 void __user *buffer, size_t *lenp, loff_t *ppos,
2208 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2209 int write, void *data),
2212 return __do_proc_dointvec(table->data, table, write, filp,
2213 buffer, lenp, ppos, conv, data);
2217 * proc_dointvec - read a vector of integers
2218 * @table: the sysctl table
2219 * @write: %TRUE if this is a write to the sysctl file
2220 * @filp: the file structure
2221 * @buffer: the user buffer
2222 * @lenp: the size of the user buffer
2223 * @ppos: file position
2225 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2226 * values from/to the user buffer, treated as an ASCII string.
2228 * Returns 0 on success.
2230 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2231 void __user *buffer, size_t *lenp, loff_t *ppos)
2233 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2241 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2243 int write, void *data)
2245 int op = *(int *)data;
2247 int val = *negp ? -*lvalp : *lvalp;
2249 case OP_SET: *valp = val; break;
2250 case OP_AND: *valp &= val; break;
2251 case OP_OR: *valp |= val; break;
2257 *lvalp = (unsigned long)-val;
2260 *lvalp = (unsigned long)val;
2267 * Taint values can only be increased
2269 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
2270 void __user *buffer, size_t *lenp, loff_t *ppos)
2274 if (write && !capable(CAP_SYS_ADMIN))
2278 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2279 do_proc_dointvec_bset_conv,&op);
2282 struct do_proc_dointvec_minmax_conv_param {
2287 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2289 int write, void *data)
2291 struct do_proc_dointvec_minmax_conv_param *param = data;
2293 int val = *negp ? -*lvalp : *lvalp;
2294 if ((param->min && *param->min > val) ||
2295 (param->max && *param->max < val))
2302 *lvalp = (unsigned long)-val;
2305 *lvalp = (unsigned long)val;
2312 * proc_dointvec_minmax - read a vector of integers with min/max values
2313 * @table: the sysctl table
2314 * @write: %TRUE if this is a write to the sysctl file
2315 * @filp: the file structure
2316 * @buffer: the user buffer
2317 * @lenp: the size of the user buffer
2318 * @ppos: file position
2320 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2321 * values from/to the user buffer, treated as an ASCII string.
2323 * This routine will ensure the values are within the range specified by
2324 * table->extra1 (min) and table->extra2 (max).
2326 * Returns 0 on success.
2328 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2329 void __user *buffer, size_t *lenp, loff_t *ppos)
2331 struct do_proc_dointvec_minmax_conv_param param = {
2332 .min = (int *) table->extra1,
2333 .max = (int *) table->extra2,
2335 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2336 do_proc_dointvec_minmax_conv, ¶m);
2339 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2341 void __user *buffer,
2342 size_t *lenp, loff_t *ppos,
2343 unsigned long convmul,
2344 unsigned long convdiv)
2346 #define TMPBUFLEN 21
2347 unsigned long *i, *min, *max, val;
2348 int vleft, first=1, neg;
2350 char buf[TMPBUFLEN], *p;
2351 char __user *s = buffer;
2353 if (!data || !table->maxlen || !*lenp ||
2354 (*ppos && !write)) {
2359 i = (unsigned long *) data;
2360 min = (unsigned long *) table->extra1;
2361 max = (unsigned long *) table->extra2;
2362 vleft = table->maxlen / sizeof(unsigned long);
2365 for (; left && vleft--; i++, min++, max++, first=0) {
2380 if (len > TMPBUFLEN-1)
2382 if (copy_from_user(buf, s, len))
2386 if (*p == '-' && left > 1) {
2390 if (*p < '0' || *p > '9')
2392 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2394 if ((len < left) && *p && !isspace(*p))
2403 if ((min && val < *min) || (max && val > *max))
2410 sprintf(p, "%lu", convdiv * (*i) / convmul);
2414 if(copy_to_user(s, buf, len))
2421 if (!write && !first && left) {
2422 if(put_user('\n', s))
2429 if (get_user(c, s++))
2444 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2446 void __user *buffer,
2447 size_t *lenp, loff_t *ppos,
2448 unsigned long convmul,
2449 unsigned long convdiv)
2451 return __do_proc_doulongvec_minmax(table->data, table, write,
2452 filp, buffer, lenp, ppos, convmul, convdiv);
2456 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2457 * @table: the sysctl table
2458 * @write: %TRUE if this is a write to the sysctl file
2459 * @filp: the file structure
2460 * @buffer: the user buffer
2461 * @lenp: the size of the user buffer
2462 * @ppos: file position
2464 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2465 * values from/to the user buffer, treated as an ASCII string.
2467 * This routine will ensure the values are within the range specified by
2468 * table->extra1 (min) and table->extra2 (max).
2470 * Returns 0 on success.
2472 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2473 void __user *buffer, size_t *lenp, loff_t *ppos)
2475 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2479 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2480 * @table: the sysctl table
2481 * @write: %TRUE if this is a write to the sysctl file
2482 * @filp: the file structure
2483 * @buffer: the user buffer
2484 * @lenp: the size of the user buffer
2485 * @ppos: file position
2487 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2488 * values from/to the user buffer, treated as an ASCII string. The values
2489 * are treated as milliseconds, and converted to jiffies when they are stored.
2491 * This routine will ensure the values are within the range specified by
2492 * table->extra1 (min) and table->extra2 (max).
2494 * Returns 0 on success.
2496 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2498 void __user *buffer,
2499 size_t *lenp, loff_t *ppos)
2501 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2502 lenp, ppos, HZ, 1000l);
2506 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2508 int write, void *data)
2511 if (*lvalp > LONG_MAX / HZ)
2513 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2519 lval = (unsigned long)-val;
2522 lval = (unsigned long)val;
2529 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2531 int write, void *data)
2534 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2536 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2542 lval = (unsigned long)-val;
2545 lval = (unsigned long)val;
2547 *lvalp = jiffies_to_clock_t(lval);
2552 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2554 int write, void *data)
2557 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2563 lval = (unsigned long)-val;
2566 lval = (unsigned long)val;
2568 *lvalp = jiffies_to_msecs(lval);
2574 * proc_dointvec_jiffies - read a vector of integers as seconds
2575 * @table: the sysctl table
2576 * @write: %TRUE if this is a write to the sysctl file
2577 * @filp: the file structure
2578 * @buffer: the user buffer
2579 * @lenp: the size of the user buffer
2580 * @ppos: file position
2582 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2583 * values from/to the user buffer, treated as an ASCII string.
2584 * The values read are assumed to be in seconds, and are converted into
2587 * Returns 0 on success.
2589 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2590 void __user *buffer, size_t *lenp, loff_t *ppos)
2592 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2593 do_proc_dointvec_jiffies_conv,NULL);
2597 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2598 * @table: the sysctl table
2599 * @write: %TRUE if this is a write to the sysctl file
2600 * @filp: the file structure
2601 * @buffer: the user buffer
2602 * @lenp: the size of the user buffer
2603 * @ppos: pointer to the file position
2605 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2606 * values from/to the user buffer, treated as an ASCII string.
2607 * The values read are assumed to be in 1/USER_HZ seconds, and
2608 * are converted into jiffies.
2610 * Returns 0 on success.
2612 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2613 void __user *buffer, size_t *lenp, loff_t *ppos)
2615 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2616 do_proc_dointvec_userhz_jiffies_conv,NULL);
2620 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2621 * @table: the sysctl table
2622 * @write: %TRUE if this is a write to the sysctl file
2623 * @filp: the file structure
2624 * @buffer: the user buffer
2625 * @lenp: the size of the user buffer
2626 * @ppos: file position
2627 * @ppos: the current position in the file
2629 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2630 * values from/to the user buffer, treated as an ASCII string.
2631 * The values read are assumed to be in 1/1000 seconds, and
2632 * are converted into jiffies.
2634 * Returns 0 on success.
2636 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2637 void __user *buffer, size_t *lenp, loff_t *ppos)
2639 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2640 do_proc_dointvec_ms_jiffies_conv, NULL);
2643 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2644 void __user *buffer, size_t *lenp, loff_t *ppos)
2646 struct pid *new_pid;
2650 tmp = pid_vnr(cad_pid);
2652 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2653 lenp, ppos, NULL, NULL);
2657 new_pid = find_get_pid(tmp);
2661 put_pid(xchg(&cad_pid, new_pid));
2665 #else /* CONFIG_PROC_FS */
2667 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2668 void __user *buffer, size_t *lenp, loff_t *ppos)
2673 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2674 void __user *buffer, size_t *lenp, loff_t *ppos)
2679 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2680 void __user *buffer, size_t *lenp, loff_t *ppos)
2685 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2686 void __user *buffer, size_t *lenp, loff_t *ppos)
2691 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2692 void __user *buffer, size_t *lenp, loff_t *ppos)
2697 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2698 void __user *buffer, size_t *lenp, loff_t *ppos)
2703 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2704 void __user *buffer, size_t *lenp, loff_t *ppos)
2709 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2711 void __user *buffer,
2712 size_t *lenp, loff_t *ppos)
2718 #endif /* CONFIG_PROC_FS */
2721 #ifdef CONFIG_SYSCTL_SYSCALL
2723 * General sysctl support routines
2726 /* The generic sysctl data routine (used if no strategy routine supplied) */
2727 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2728 void __user *oldval, size_t __user *oldlenp,
2729 void __user *newval, size_t newlen)
2733 /* Get out of I don't have a variable */
2734 if (!table->data || !table->maxlen)
2737 if (oldval && oldlenp) {
2738 if (get_user(len, oldlenp))
2741 if (len > table->maxlen)
2742 len = table->maxlen;
2743 if (copy_to_user(oldval, table->data, len))
2745 if (put_user(len, oldlenp))
2750 if (newval && newlen) {
2751 if (newlen > table->maxlen)
2752 newlen = table->maxlen;
2754 if (copy_from_user(table->data, newval, newlen))
2760 /* The generic string strategy routine: */
2761 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2762 void __user *oldval, size_t __user *oldlenp,
2763 void __user *newval, size_t newlen)
2765 if (!table->data || !table->maxlen)
2768 if (oldval && oldlenp) {
2770 if (get_user(bufsize, oldlenp))
2773 size_t len = strlen(table->data), copied;
2775 /* This shouldn't trigger for a well-formed sysctl */
2776 if (len > table->maxlen)
2777 len = table->maxlen;
2779 /* Copy up to a max of bufsize-1 bytes of the string */
2780 copied = (len >= bufsize) ? bufsize - 1 : len;
2782 if (copy_to_user(oldval, table->data, copied) ||
2783 put_user(0, (char __user *)(oldval + copied)))
2785 if (put_user(len, oldlenp))
2789 if (newval && newlen) {
2790 size_t len = newlen;
2791 if (len > table->maxlen)
2792 len = table->maxlen;
2793 if(copy_from_user(table->data, newval, len))
2795 if (len == table->maxlen)
2797 ((char *) table->data)[len] = 0;
2803 * This function makes sure that all of the integers in the vector
2804 * are between the minimum and maximum values given in the arrays
2805 * table->extra1 and table->extra2, respectively.
2807 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2808 void __user *oldval, size_t __user *oldlenp,
2809 void __user *newval, size_t newlen)
2812 if (newval && newlen) {
2813 int __user *vec = (int __user *) newval;
2814 int *min = (int *) table->extra1;
2815 int *max = (int *) table->extra2;
2819 if (newlen % sizeof(int) != 0)
2822 if (!table->extra1 && !table->extra2)
2825 if (newlen > table->maxlen)
2826 newlen = table->maxlen;
2827 length = newlen / sizeof(int);
2829 for (i = 0; i < length; i++) {
2831 if (get_user(value, vec + i))
2833 if (min && value < min[i])
2835 if (max && value > max[i])
2842 /* Strategy function to convert jiffies to seconds */
2843 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2844 void __user *oldval, size_t __user *oldlenp,
2845 void __user *newval, size_t newlen)
2847 if (oldval && oldlenp) {
2850 if (get_user(olen, oldlenp))
2855 if (olen < sizeof(int))
2858 val = *(int *)(table->data) / HZ;
2859 if (put_user(val, (int __user *)oldval))
2861 if (put_user(sizeof(int), oldlenp))
2865 if (newval && newlen) {
2867 if (newlen != sizeof(int))
2869 if (get_user(new, (int __user *)newval))
2871 *(int *)(table->data) = new*HZ;
2876 /* Strategy function to convert jiffies to seconds */
2877 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2878 void __user *oldval, size_t __user *oldlenp,
2879 void __user *newval, size_t newlen)
2881 if (oldval && oldlenp) {
2884 if (get_user(olen, oldlenp))
2889 if (olen < sizeof(int))
2892 val = jiffies_to_msecs(*(int *)(table->data));
2893 if (put_user(val, (int __user *)oldval))
2895 if (put_user(sizeof(int), oldlenp))
2899 if (newval && newlen) {
2901 if (newlen != sizeof(int))
2903 if (get_user(new, (int __user *)newval))
2905 *(int *)(table->data) = msecs_to_jiffies(new);
2912 #else /* CONFIG_SYSCTL_SYSCALL */
2915 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2917 struct __sysctl_args tmp;
2920 if (copy_from_user(&tmp, args, sizeof(tmp)))
2923 error = deprecated_sysctl_warning(&tmp);
2925 /* If no error reading the parameters then just -ENOSYS ... */
2932 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2933 void __user *oldval, size_t __user *oldlenp,
2934 void __user *newval, size_t newlen)
2939 int sysctl_string(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_intvec(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_jiffies(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_ms_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 #endif /* CONFIG_SYSCTL_SYSCALL */
2969 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2971 static int msg_count;
2972 int name[CTL_MAXNAME];
2975 /* Check args->nlen. */
2976 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2979 /* Read in the sysctl name for better debug message logging */
2980 for (i = 0; i < args->nlen; i++)
2981 if (get_user(name[i], args->name + i))
2984 /* Ignore accesses to kernel.version */
2985 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2988 if (msg_count < 5) {
2991 "warning: process `%s' used the deprecated sysctl "
2992 "system call with ", current->comm);
2993 for (i = 0; i < args->nlen; i++)
2994 printk("%d.", name[i]);
3001 * No sense putting this after each symbol definition, twice,
3002 * exception granted :-)
3004 EXPORT_SYMBOL(proc_dointvec);
3005 EXPORT_SYMBOL(proc_dointvec_jiffies);
3006 EXPORT_SYMBOL(proc_dointvec_minmax);
3007 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3008 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3009 EXPORT_SYMBOL(proc_dostring);
3010 EXPORT_SYMBOL(proc_doulongvec_minmax);
3011 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3012 EXPORT_SYMBOL(register_sysctl_table);
3013 EXPORT_SYMBOL(register_sysctl_paths);
3014 EXPORT_SYMBOL(sysctl_intvec);
3015 EXPORT_SYMBOL(sysctl_jiffies);
3016 EXPORT_SYMBOL(sysctl_ms_jiffies);
3017 EXPORT_SYMBOL(sysctl_string);
3018 EXPORT_SYMBOL(sysctl_data);
3019 EXPORT_SYMBOL(unregister_sysctl_table);