2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
51 #include <linux/slow-work.h>
53 #include <asm/uaccess.h>
54 #include <asm/processor.h>
58 #include <asm/stacktrace.h>
62 static int deprecated_sysctl_warning(struct __sysctl_args *args);
64 #if defined(CONFIG_SYSCTL)
66 /* External variables not in a header file. */
68 extern int print_fatal_signals;
69 extern int sysctl_overcommit_memory;
70 extern int sysctl_overcommit_ratio;
71 extern int sysctl_panic_on_oom;
72 extern int sysctl_oom_kill_allocating_task;
73 extern int sysctl_oom_dump_tasks;
74 extern int max_threads;
75 extern int core_uses_pid;
76 extern int suid_dumpable;
77 extern char core_pattern[];
79 extern int min_free_kbytes;
80 extern int pid_max_min, pid_max_max;
81 extern int sysctl_drop_caches;
82 extern int percpu_pagelist_fraction;
83 extern int compat_log;
84 extern int latencytop_enabled;
85 extern int sysctl_nr_open_min, sysctl_nr_open_max;
87 extern int sysctl_nr_trim_pages;
89 #ifdef CONFIG_RCU_TORTURE_TEST
90 extern int rcutorture_runnable;
91 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
93 /* Constants used for minimum and maximum */
94 #ifdef CONFIG_DETECT_SOFTLOCKUP
95 static int sixty = 60;
96 static int neg_one = -1;
100 static int __maybe_unused one = 1;
101 static int __maybe_unused two = 2;
102 static unsigned long one_ul = 1;
103 static int one_hundred = 100;
105 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
106 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
108 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
109 static int maxolduid = 65535;
110 static int minolduid;
111 static int min_percpu_pagelist_fract = 8;
113 static int ngroups_max = NGROUPS_MAX;
115 #ifdef CONFIG_MODULES
116 extern char modprobe_path[];
118 #ifdef CONFIG_CHR_DEV_SG
119 extern int sg_big_buff;
123 #include <asm/system.h>
126 #ifdef CONFIG_SPARC64
127 extern int sysctl_tsb_ratio;
131 extern int pwrsw_enabled;
132 extern int unaligned_enabled;
136 #ifdef CONFIG_MATHEMU
137 extern int sysctl_ieee_emulation_warnings;
139 extern int sysctl_userprocess_debug;
140 extern int spin_retry;
143 #ifdef CONFIG_BSD_PROCESS_ACCT
144 extern int acct_parm[];
148 extern int no_unaligned_warning;
149 extern int unaligned_dump_stack;
152 #ifdef CONFIG_RT_MUTEXES
153 extern int max_lock_depth;
156 #ifdef CONFIG_PROC_SYSCTL
157 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
158 void __user *buffer, size_t *lenp, loff_t *ppos);
159 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
160 void __user *buffer, size_t *lenp, loff_t *ppos);
163 static struct ctl_table root_table[];
164 static struct ctl_table_root sysctl_table_root;
165 static struct ctl_table_header root_table_header = {
167 .ctl_table = root_table,
168 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
169 .root = &sysctl_table_root,
170 .set = &sysctl_table_root.default_set,
172 static struct ctl_table_root sysctl_table_root = {
173 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
174 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
177 static struct ctl_table kern_table[];
178 static struct ctl_table vm_table[];
179 static struct ctl_table fs_table[];
180 static struct ctl_table debug_table[];
181 static struct ctl_table dev_table[];
182 extern struct ctl_table random_table[];
183 #ifdef CONFIG_INOTIFY_USER
184 extern struct ctl_table inotify_table[];
187 extern struct ctl_table epoll_table[];
190 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
191 int sysctl_legacy_va_layout;
194 extern int prove_locking;
195 extern int lock_stat;
197 /* The default sysctl tables: */
199 static struct ctl_table root_table[] = {
201 .ctl_name = CTL_KERN,
202 .procname = "kernel",
219 .ctl_name = CTL_DEBUG,
222 .child = debug_table,
231 * NOTE: do not add new entries to this table unless you have read
232 * Documentation/sysctl/ctl_unnumbered.txt
237 #ifdef CONFIG_SCHED_DEBUG
238 static int min_sched_granularity_ns = 100000; /* 100 usecs */
239 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
240 static int min_wakeup_granularity_ns; /* 0 usecs */
241 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
244 static struct ctl_table kern_table[] = {
245 #ifdef CONFIG_SCHED_DEBUG
247 .ctl_name = CTL_UNNUMBERED,
248 .procname = "sched_min_granularity_ns",
249 .data = &sysctl_sched_min_granularity,
250 .maxlen = sizeof(unsigned int),
252 .proc_handler = &sched_nr_latency_handler,
253 .strategy = &sysctl_intvec,
254 .extra1 = &min_sched_granularity_ns,
255 .extra2 = &max_sched_granularity_ns,
258 .ctl_name = CTL_UNNUMBERED,
259 .procname = "sched_latency_ns",
260 .data = &sysctl_sched_latency,
261 .maxlen = sizeof(unsigned int),
263 .proc_handler = &sched_nr_latency_handler,
264 .strategy = &sysctl_intvec,
265 .extra1 = &min_sched_granularity_ns,
266 .extra2 = &max_sched_granularity_ns,
269 .ctl_name = CTL_UNNUMBERED,
270 .procname = "sched_wakeup_granularity_ns",
271 .data = &sysctl_sched_wakeup_granularity,
272 .maxlen = sizeof(unsigned int),
274 .proc_handler = &proc_dointvec_minmax,
275 .strategy = &sysctl_intvec,
276 .extra1 = &min_wakeup_granularity_ns,
277 .extra2 = &max_wakeup_granularity_ns,
280 .ctl_name = CTL_UNNUMBERED,
281 .procname = "sched_shares_ratelimit",
282 .data = &sysctl_sched_shares_ratelimit,
283 .maxlen = sizeof(unsigned int),
285 .proc_handler = &proc_dointvec,
288 .ctl_name = CTL_UNNUMBERED,
289 .procname = "sched_shares_thresh",
290 .data = &sysctl_sched_shares_thresh,
291 .maxlen = sizeof(unsigned int),
293 .proc_handler = &proc_dointvec_minmax,
294 .strategy = &sysctl_intvec,
298 .ctl_name = CTL_UNNUMBERED,
299 .procname = "sched_child_runs_first",
300 .data = &sysctl_sched_child_runs_first,
301 .maxlen = sizeof(unsigned int),
303 .proc_handler = &proc_dointvec,
306 .ctl_name = CTL_UNNUMBERED,
307 .procname = "sched_features",
308 .data = &sysctl_sched_features,
309 .maxlen = sizeof(unsigned int),
311 .proc_handler = &proc_dointvec,
314 .ctl_name = CTL_UNNUMBERED,
315 .procname = "sched_migration_cost",
316 .data = &sysctl_sched_migration_cost,
317 .maxlen = sizeof(unsigned int),
319 .proc_handler = &proc_dointvec,
322 .ctl_name = CTL_UNNUMBERED,
323 .procname = "sched_nr_migrate",
324 .data = &sysctl_sched_nr_migrate,
325 .maxlen = sizeof(unsigned int),
327 .proc_handler = &proc_dointvec,
331 .ctl_name = CTL_UNNUMBERED,
332 .procname = "sched_rt_period_us",
333 .data = &sysctl_sched_rt_period,
334 .maxlen = sizeof(unsigned int),
336 .proc_handler = &sched_rt_handler,
339 .ctl_name = CTL_UNNUMBERED,
340 .procname = "sched_rt_runtime_us",
341 .data = &sysctl_sched_rt_runtime,
342 .maxlen = sizeof(int),
344 .proc_handler = &sched_rt_handler,
347 .ctl_name = CTL_UNNUMBERED,
348 .procname = "sched_compat_yield",
349 .data = &sysctl_sched_compat_yield,
350 .maxlen = sizeof(unsigned int),
352 .proc_handler = &proc_dointvec,
354 #ifdef CONFIG_PROVE_LOCKING
356 .ctl_name = CTL_UNNUMBERED,
357 .procname = "prove_locking",
358 .data = &prove_locking,
359 .maxlen = sizeof(int),
361 .proc_handler = &proc_dointvec,
364 #ifdef CONFIG_LOCK_STAT
366 .ctl_name = CTL_UNNUMBERED,
367 .procname = "lock_stat",
369 .maxlen = sizeof(int),
371 .proc_handler = &proc_dointvec,
375 .ctl_name = KERN_PANIC,
377 .data = &panic_timeout,
378 .maxlen = sizeof(int),
380 .proc_handler = &proc_dointvec,
383 .ctl_name = KERN_CORE_USES_PID,
384 .procname = "core_uses_pid",
385 .data = &core_uses_pid,
386 .maxlen = sizeof(int),
388 .proc_handler = &proc_dointvec,
391 .ctl_name = KERN_CORE_PATTERN,
392 .procname = "core_pattern",
393 .data = core_pattern,
394 .maxlen = CORENAME_MAX_SIZE,
396 .proc_handler = &proc_dostring,
397 .strategy = &sysctl_string,
399 #ifdef CONFIG_PROC_SYSCTL
401 .procname = "tainted",
402 .maxlen = sizeof(long),
404 .proc_handler = &proc_taint,
407 #ifdef CONFIG_LATENCYTOP
409 .procname = "latencytop",
410 .data = &latencytop_enabled,
411 .maxlen = sizeof(int),
413 .proc_handler = &proc_dointvec,
416 #ifdef CONFIG_BLK_DEV_INITRD
418 .ctl_name = KERN_REALROOTDEV,
419 .procname = "real-root-dev",
420 .data = &real_root_dev,
421 .maxlen = sizeof(int),
423 .proc_handler = &proc_dointvec,
427 .ctl_name = CTL_UNNUMBERED,
428 .procname = "print-fatal-signals",
429 .data = &print_fatal_signals,
430 .maxlen = sizeof(int),
432 .proc_handler = &proc_dointvec,
436 .ctl_name = KERN_SPARC_REBOOT,
437 .procname = "reboot-cmd",
438 .data = reboot_command,
441 .proc_handler = &proc_dostring,
442 .strategy = &sysctl_string,
445 .ctl_name = KERN_SPARC_STOP_A,
446 .procname = "stop-a",
447 .data = &stop_a_enabled,
448 .maxlen = sizeof (int),
450 .proc_handler = &proc_dointvec,
453 .ctl_name = KERN_SPARC_SCONS_PWROFF,
454 .procname = "scons-poweroff",
455 .data = &scons_pwroff,
456 .maxlen = sizeof (int),
458 .proc_handler = &proc_dointvec,
461 #ifdef CONFIG_SPARC64
463 .ctl_name = CTL_UNNUMBERED,
464 .procname = "tsb-ratio",
465 .data = &sysctl_tsb_ratio,
466 .maxlen = sizeof (int),
468 .proc_handler = &proc_dointvec,
473 .ctl_name = KERN_HPPA_PWRSW,
474 .procname = "soft-power",
475 .data = &pwrsw_enabled,
476 .maxlen = sizeof (int),
478 .proc_handler = &proc_dointvec,
481 .ctl_name = KERN_HPPA_UNALIGNED,
482 .procname = "unaligned-trap",
483 .data = &unaligned_enabled,
484 .maxlen = sizeof (int),
486 .proc_handler = &proc_dointvec,
490 .ctl_name = KERN_CTLALTDEL,
491 .procname = "ctrl-alt-del",
493 .maxlen = sizeof(int),
495 .proc_handler = &proc_dointvec,
497 #ifdef CONFIG_FUNCTION_TRACER
499 .ctl_name = CTL_UNNUMBERED,
500 .procname = "ftrace_enabled",
501 .data = &ftrace_enabled,
502 .maxlen = sizeof(int),
504 .proc_handler = &ftrace_enable_sysctl,
507 #ifdef CONFIG_STACK_TRACER
509 .ctl_name = CTL_UNNUMBERED,
510 .procname = "stack_tracer_enabled",
511 .data = &stack_tracer_enabled,
512 .maxlen = sizeof(int),
514 .proc_handler = &stack_trace_sysctl,
517 #ifdef CONFIG_TRACING
519 .ctl_name = CTL_UNNUMBERED,
520 .procname = "ftrace_dump_on_oops",
521 .data = &ftrace_dump_on_oops,
522 .maxlen = sizeof(int),
524 .proc_handler = &proc_dointvec,
527 #ifdef CONFIG_MODULES
529 .ctl_name = KERN_MODPROBE,
530 .procname = "modprobe",
531 .data = &modprobe_path,
532 .maxlen = KMOD_PATH_LEN,
534 .proc_handler = &proc_dostring,
535 .strategy = &sysctl_string,
538 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
540 .ctl_name = KERN_HOTPLUG,
541 .procname = "hotplug",
542 .data = &uevent_helper,
543 .maxlen = UEVENT_HELPER_PATH_LEN,
545 .proc_handler = &proc_dostring,
546 .strategy = &sysctl_string,
549 #ifdef CONFIG_CHR_DEV_SG
551 .ctl_name = KERN_SG_BIG_BUFF,
552 .procname = "sg-big-buff",
553 .data = &sg_big_buff,
554 .maxlen = sizeof (int),
556 .proc_handler = &proc_dointvec,
559 #ifdef CONFIG_BSD_PROCESS_ACCT
561 .ctl_name = KERN_ACCT,
564 .maxlen = 3*sizeof(int),
566 .proc_handler = &proc_dointvec,
569 #ifdef CONFIG_MAGIC_SYSRQ
571 .ctl_name = KERN_SYSRQ,
573 .data = &__sysrq_enabled,
574 .maxlen = sizeof (int),
576 .proc_handler = &proc_dointvec,
579 #ifdef CONFIG_PROC_SYSCTL
581 .procname = "cad_pid",
583 .maxlen = sizeof (int),
585 .proc_handler = &proc_do_cad_pid,
589 .ctl_name = KERN_MAX_THREADS,
590 .procname = "threads-max",
591 .data = &max_threads,
592 .maxlen = sizeof(int),
594 .proc_handler = &proc_dointvec,
597 .ctl_name = KERN_RANDOM,
598 .procname = "random",
600 .child = random_table,
603 .ctl_name = KERN_OVERFLOWUID,
604 .procname = "overflowuid",
605 .data = &overflowuid,
606 .maxlen = sizeof(int),
608 .proc_handler = &proc_dointvec_minmax,
609 .strategy = &sysctl_intvec,
610 .extra1 = &minolduid,
611 .extra2 = &maxolduid,
614 .ctl_name = KERN_OVERFLOWGID,
615 .procname = "overflowgid",
616 .data = &overflowgid,
617 .maxlen = sizeof(int),
619 .proc_handler = &proc_dointvec_minmax,
620 .strategy = &sysctl_intvec,
621 .extra1 = &minolduid,
622 .extra2 = &maxolduid,
625 #ifdef CONFIG_MATHEMU
627 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
628 .procname = "ieee_emulation_warnings",
629 .data = &sysctl_ieee_emulation_warnings,
630 .maxlen = sizeof(int),
632 .proc_handler = &proc_dointvec,
636 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
637 .procname = "userprocess_debug",
638 .data = &sysctl_userprocess_debug,
639 .maxlen = sizeof(int),
641 .proc_handler = &proc_dointvec,
645 .ctl_name = KERN_PIDMAX,
646 .procname = "pid_max",
648 .maxlen = sizeof (int),
650 .proc_handler = &proc_dointvec_minmax,
651 .strategy = sysctl_intvec,
652 .extra1 = &pid_max_min,
653 .extra2 = &pid_max_max,
656 .ctl_name = KERN_PANIC_ON_OOPS,
657 .procname = "panic_on_oops",
658 .data = &panic_on_oops,
659 .maxlen = sizeof(int),
661 .proc_handler = &proc_dointvec,
663 #if defined CONFIG_PRINTK
665 .ctl_name = KERN_PRINTK,
666 .procname = "printk",
667 .data = &console_loglevel,
668 .maxlen = 4*sizeof(int),
670 .proc_handler = &proc_dointvec,
673 .ctl_name = KERN_PRINTK_RATELIMIT,
674 .procname = "printk_ratelimit",
675 .data = &printk_ratelimit_state.interval,
676 .maxlen = sizeof(int),
678 .proc_handler = &proc_dointvec_jiffies,
679 .strategy = &sysctl_jiffies,
682 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
683 .procname = "printk_ratelimit_burst",
684 .data = &printk_ratelimit_state.burst,
685 .maxlen = sizeof(int),
687 .proc_handler = &proc_dointvec,
691 .ctl_name = KERN_NGROUPS_MAX,
692 .procname = "ngroups_max",
693 .data = &ngroups_max,
694 .maxlen = sizeof (int),
696 .proc_handler = &proc_dointvec,
698 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
700 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
701 .procname = "unknown_nmi_panic",
702 .data = &unknown_nmi_panic,
703 .maxlen = sizeof (int),
705 .proc_handler = &proc_dointvec,
708 .procname = "nmi_watchdog",
709 .data = &nmi_watchdog_enabled,
710 .maxlen = sizeof (int),
712 .proc_handler = &proc_nmi_enabled,
715 #if defined(CONFIG_X86)
717 .ctl_name = KERN_PANIC_ON_NMI,
718 .procname = "panic_on_unrecovered_nmi",
719 .data = &panic_on_unrecovered_nmi,
720 .maxlen = sizeof(int),
722 .proc_handler = &proc_dointvec,
725 .ctl_name = KERN_BOOTLOADER_TYPE,
726 .procname = "bootloader_type",
727 .data = &bootloader_type,
728 .maxlen = sizeof (int),
730 .proc_handler = &proc_dointvec,
733 .ctl_name = CTL_UNNUMBERED,
734 .procname = "bootloader_version",
735 .data = &bootloader_version,
736 .maxlen = sizeof (int),
738 .proc_handler = &proc_dointvec,
741 .ctl_name = CTL_UNNUMBERED,
742 .procname = "kstack_depth_to_print",
743 .data = &kstack_depth_to_print,
744 .maxlen = sizeof(int),
746 .proc_handler = &proc_dointvec,
749 .ctl_name = CTL_UNNUMBERED,
750 .procname = "io_delay_type",
751 .data = &io_delay_type,
752 .maxlen = sizeof(int),
754 .proc_handler = &proc_dointvec,
757 #if defined(CONFIG_MMU)
759 .ctl_name = KERN_RANDOMIZE,
760 .procname = "randomize_va_space",
761 .data = &randomize_va_space,
762 .maxlen = sizeof(int),
764 .proc_handler = &proc_dointvec,
767 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
769 .ctl_name = KERN_SPIN_RETRY,
770 .procname = "spin_retry",
772 .maxlen = sizeof (int),
774 .proc_handler = &proc_dointvec,
777 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
779 .procname = "acpi_video_flags",
780 .data = &acpi_realmode_flags,
781 .maxlen = sizeof (unsigned long),
783 .proc_handler = &proc_doulongvec_minmax,
788 .ctl_name = KERN_IA64_UNALIGNED,
789 .procname = "ignore-unaligned-usertrap",
790 .data = &no_unaligned_warning,
791 .maxlen = sizeof (int),
793 .proc_handler = &proc_dointvec,
796 .ctl_name = CTL_UNNUMBERED,
797 .procname = "unaligned-dump-stack",
798 .data = &unaligned_dump_stack,
799 .maxlen = sizeof (int),
801 .proc_handler = &proc_dointvec,
804 #ifdef CONFIG_DETECT_SOFTLOCKUP
806 .ctl_name = CTL_UNNUMBERED,
807 .procname = "softlockup_panic",
808 .data = &softlockup_panic,
809 .maxlen = sizeof(int),
811 .proc_handler = &proc_dointvec_minmax,
812 .strategy = &sysctl_intvec,
817 .ctl_name = CTL_UNNUMBERED,
818 .procname = "softlockup_thresh",
819 .data = &softlockup_thresh,
820 .maxlen = sizeof(int),
822 .proc_handler = &proc_dosoftlockup_thresh,
823 .strategy = &sysctl_intvec,
828 #ifdef CONFIG_DETECT_HUNG_TASK
830 .ctl_name = CTL_UNNUMBERED,
831 .procname = "hung_task_panic",
832 .data = &sysctl_hung_task_panic,
833 .maxlen = sizeof(int),
835 .proc_handler = &proc_dointvec_minmax,
836 .strategy = &sysctl_intvec,
841 .ctl_name = CTL_UNNUMBERED,
842 .procname = "hung_task_check_count",
843 .data = &sysctl_hung_task_check_count,
844 .maxlen = sizeof(unsigned long),
846 .proc_handler = &proc_doulongvec_minmax,
847 .strategy = &sysctl_intvec,
850 .ctl_name = CTL_UNNUMBERED,
851 .procname = "hung_task_timeout_secs",
852 .data = &sysctl_hung_task_timeout_secs,
853 .maxlen = sizeof(unsigned long),
855 .proc_handler = &proc_dohung_task_timeout_secs,
856 .strategy = &sysctl_intvec,
859 .ctl_name = CTL_UNNUMBERED,
860 .procname = "hung_task_warnings",
861 .data = &sysctl_hung_task_warnings,
862 .maxlen = sizeof(unsigned long),
864 .proc_handler = &proc_doulongvec_minmax,
865 .strategy = &sysctl_intvec,
870 .ctl_name = KERN_COMPAT_LOG,
871 .procname = "compat-log",
873 .maxlen = sizeof (int),
875 .proc_handler = &proc_dointvec,
878 #ifdef CONFIG_RT_MUTEXES
880 .ctl_name = KERN_MAX_LOCK_DEPTH,
881 .procname = "max_lock_depth",
882 .data = &max_lock_depth,
883 .maxlen = sizeof(int),
885 .proc_handler = &proc_dointvec,
889 .ctl_name = CTL_UNNUMBERED,
890 .procname = "poweroff_cmd",
891 .data = &poweroff_cmd,
892 .maxlen = POWEROFF_CMD_PATH_LEN,
894 .proc_handler = &proc_dostring,
895 .strategy = &sysctl_string,
899 .ctl_name = CTL_UNNUMBERED,
902 .child = key_sysctls,
905 #ifdef CONFIG_RCU_TORTURE_TEST
907 .ctl_name = CTL_UNNUMBERED,
908 .procname = "rcutorture_runnable",
909 .data = &rcutorture_runnable,
910 .maxlen = sizeof(int),
912 .proc_handler = &proc_dointvec,
915 #ifdef CONFIG_SLOW_WORK
917 .ctl_name = CTL_UNNUMBERED,
918 .procname = "slow-work",
920 .child = slow_work_sysctls,
924 * NOTE: do not add new entries to this table unless you have read
925 * Documentation/sysctl/ctl_unnumbered.txt
930 static struct ctl_table vm_table[] = {
932 .ctl_name = VM_OVERCOMMIT_MEMORY,
933 .procname = "overcommit_memory",
934 .data = &sysctl_overcommit_memory,
935 .maxlen = sizeof(sysctl_overcommit_memory),
937 .proc_handler = &proc_dointvec,
940 .ctl_name = VM_PANIC_ON_OOM,
941 .procname = "panic_on_oom",
942 .data = &sysctl_panic_on_oom,
943 .maxlen = sizeof(sysctl_panic_on_oom),
945 .proc_handler = &proc_dointvec,
948 .ctl_name = CTL_UNNUMBERED,
949 .procname = "oom_kill_allocating_task",
950 .data = &sysctl_oom_kill_allocating_task,
951 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
953 .proc_handler = &proc_dointvec,
956 .ctl_name = CTL_UNNUMBERED,
957 .procname = "oom_dump_tasks",
958 .data = &sysctl_oom_dump_tasks,
959 .maxlen = sizeof(sysctl_oom_dump_tasks),
961 .proc_handler = &proc_dointvec,
964 .ctl_name = VM_OVERCOMMIT_RATIO,
965 .procname = "overcommit_ratio",
966 .data = &sysctl_overcommit_ratio,
967 .maxlen = sizeof(sysctl_overcommit_ratio),
969 .proc_handler = &proc_dointvec,
972 .ctl_name = VM_PAGE_CLUSTER,
973 .procname = "page-cluster",
974 .data = &page_cluster,
975 .maxlen = sizeof(int),
977 .proc_handler = &proc_dointvec,
980 .ctl_name = VM_DIRTY_BACKGROUND,
981 .procname = "dirty_background_ratio",
982 .data = &dirty_background_ratio,
983 .maxlen = sizeof(dirty_background_ratio),
985 .proc_handler = &dirty_background_ratio_handler,
986 .strategy = &sysctl_intvec,
988 .extra2 = &one_hundred,
991 .ctl_name = CTL_UNNUMBERED,
992 .procname = "dirty_background_bytes",
993 .data = &dirty_background_bytes,
994 .maxlen = sizeof(dirty_background_bytes),
996 .proc_handler = &dirty_background_bytes_handler,
997 .strategy = &sysctl_intvec,
1001 .ctl_name = VM_DIRTY_RATIO,
1002 .procname = "dirty_ratio",
1003 .data = &vm_dirty_ratio,
1004 .maxlen = sizeof(vm_dirty_ratio),
1006 .proc_handler = &dirty_ratio_handler,
1007 .strategy = &sysctl_intvec,
1009 .extra2 = &one_hundred,
1012 .ctl_name = CTL_UNNUMBERED,
1013 .procname = "dirty_bytes",
1014 .data = &vm_dirty_bytes,
1015 .maxlen = sizeof(vm_dirty_bytes),
1017 .proc_handler = &dirty_bytes_handler,
1018 .strategy = &sysctl_intvec,
1019 .extra1 = &dirty_bytes_min,
1022 .procname = "dirty_writeback_centisecs",
1023 .data = &dirty_writeback_interval,
1024 .maxlen = sizeof(dirty_writeback_interval),
1026 .proc_handler = &dirty_writeback_centisecs_handler,
1029 .procname = "dirty_expire_centisecs",
1030 .data = &dirty_expire_interval,
1031 .maxlen = sizeof(dirty_expire_interval),
1033 .proc_handler = &proc_dointvec,
1036 .ctl_name = VM_NR_PDFLUSH_THREADS,
1037 .procname = "nr_pdflush_threads",
1038 .data = &nr_pdflush_threads,
1039 .maxlen = sizeof nr_pdflush_threads,
1040 .mode = 0444 /* read-only*/,
1041 .proc_handler = &proc_dointvec,
1044 .ctl_name = VM_SWAPPINESS,
1045 .procname = "swappiness",
1046 .data = &vm_swappiness,
1047 .maxlen = sizeof(vm_swappiness),
1049 .proc_handler = &proc_dointvec_minmax,
1050 .strategy = &sysctl_intvec,
1052 .extra2 = &one_hundred,
1054 #ifdef CONFIG_HUGETLB_PAGE
1056 .procname = "nr_hugepages",
1058 .maxlen = sizeof(unsigned long),
1060 .proc_handler = &hugetlb_sysctl_handler,
1061 .extra1 = (void *)&hugetlb_zero,
1062 .extra2 = (void *)&hugetlb_infinity,
1065 .ctl_name = VM_HUGETLB_GROUP,
1066 .procname = "hugetlb_shm_group",
1067 .data = &sysctl_hugetlb_shm_group,
1068 .maxlen = sizeof(gid_t),
1070 .proc_handler = &proc_dointvec,
1073 .ctl_name = CTL_UNNUMBERED,
1074 .procname = "hugepages_treat_as_movable",
1075 .data = &hugepages_treat_as_movable,
1076 .maxlen = sizeof(int),
1078 .proc_handler = &hugetlb_treat_movable_handler,
1081 .ctl_name = CTL_UNNUMBERED,
1082 .procname = "nr_overcommit_hugepages",
1084 .maxlen = sizeof(unsigned long),
1086 .proc_handler = &hugetlb_overcommit_handler,
1087 .extra1 = (void *)&hugetlb_zero,
1088 .extra2 = (void *)&hugetlb_infinity,
1092 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1093 .procname = "lowmem_reserve_ratio",
1094 .data = &sysctl_lowmem_reserve_ratio,
1095 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1097 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1098 .strategy = &sysctl_intvec,
1101 .ctl_name = VM_DROP_PAGECACHE,
1102 .procname = "drop_caches",
1103 .data = &sysctl_drop_caches,
1104 .maxlen = sizeof(int),
1106 .proc_handler = drop_caches_sysctl_handler,
1107 .strategy = &sysctl_intvec,
1110 .ctl_name = VM_MIN_FREE_KBYTES,
1111 .procname = "min_free_kbytes",
1112 .data = &min_free_kbytes,
1113 .maxlen = sizeof(min_free_kbytes),
1115 .proc_handler = &min_free_kbytes_sysctl_handler,
1116 .strategy = &sysctl_intvec,
1120 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1121 .procname = "percpu_pagelist_fraction",
1122 .data = &percpu_pagelist_fraction,
1123 .maxlen = sizeof(percpu_pagelist_fraction),
1125 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1126 .strategy = &sysctl_intvec,
1127 .extra1 = &min_percpu_pagelist_fract,
1131 .ctl_name = VM_MAX_MAP_COUNT,
1132 .procname = "max_map_count",
1133 .data = &sysctl_max_map_count,
1134 .maxlen = sizeof(sysctl_max_map_count),
1136 .proc_handler = &proc_dointvec
1140 .ctl_name = CTL_UNNUMBERED,
1141 .procname = "nr_trim_pages",
1142 .data = &sysctl_nr_trim_pages,
1143 .maxlen = sizeof(sysctl_nr_trim_pages),
1145 .proc_handler = &proc_dointvec_minmax,
1146 .strategy = &sysctl_intvec,
1151 .ctl_name = VM_LAPTOP_MODE,
1152 .procname = "laptop_mode",
1153 .data = &laptop_mode,
1154 .maxlen = sizeof(laptop_mode),
1156 .proc_handler = &proc_dointvec_jiffies,
1157 .strategy = &sysctl_jiffies,
1160 .ctl_name = VM_BLOCK_DUMP,
1161 .procname = "block_dump",
1162 .data = &block_dump,
1163 .maxlen = sizeof(block_dump),
1165 .proc_handler = &proc_dointvec,
1166 .strategy = &sysctl_intvec,
1170 .ctl_name = VM_VFS_CACHE_PRESSURE,
1171 .procname = "vfs_cache_pressure",
1172 .data = &sysctl_vfs_cache_pressure,
1173 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1175 .proc_handler = &proc_dointvec,
1176 .strategy = &sysctl_intvec,
1179 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1181 .ctl_name = VM_LEGACY_VA_LAYOUT,
1182 .procname = "legacy_va_layout",
1183 .data = &sysctl_legacy_va_layout,
1184 .maxlen = sizeof(sysctl_legacy_va_layout),
1186 .proc_handler = &proc_dointvec,
1187 .strategy = &sysctl_intvec,
1193 .ctl_name = VM_ZONE_RECLAIM_MODE,
1194 .procname = "zone_reclaim_mode",
1195 .data = &zone_reclaim_mode,
1196 .maxlen = sizeof(zone_reclaim_mode),
1198 .proc_handler = &proc_dointvec,
1199 .strategy = &sysctl_intvec,
1203 .ctl_name = VM_MIN_UNMAPPED,
1204 .procname = "min_unmapped_ratio",
1205 .data = &sysctl_min_unmapped_ratio,
1206 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1208 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1209 .strategy = &sysctl_intvec,
1211 .extra2 = &one_hundred,
1214 .ctl_name = VM_MIN_SLAB,
1215 .procname = "min_slab_ratio",
1216 .data = &sysctl_min_slab_ratio,
1217 .maxlen = sizeof(sysctl_min_slab_ratio),
1219 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1220 .strategy = &sysctl_intvec,
1222 .extra2 = &one_hundred,
1227 .ctl_name = CTL_UNNUMBERED,
1228 .procname = "stat_interval",
1229 .data = &sysctl_stat_interval,
1230 .maxlen = sizeof(sysctl_stat_interval),
1232 .proc_handler = &proc_dointvec_jiffies,
1233 .strategy = &sysctl_jiffies,
1236 #ifdef CONFIG_SECURITY
1238 .ctl_name = CTL_UNNUMBERED,
1239 .procname = "mmap_min_addr",
1240 .data = &mmap_min_addr,
1241 .maxlen = sizeof(unsigned long),
1243 .proc_handler = &proc_doulongvec_minmax,
1248 .ctl_name = CTL_UNNUMBERED,
1249 .procname = "numa_zonelist_order",
1250 .data = &numa_zonelist_order,
1251 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1253 .proc_handler = &numa_zonelist_order_handler,
1254 .strategy = &sysctl_string,
1257 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1258 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1260 .ctl_name = VM_VDSO_ENABLED,
1261 .procname = "vdso_enabled",
1262 .data = &vdso_enabled,
1263 .maxlen = sizeof(vdso_enabled),
1265 .proc_handler = &proc_dointvec,
1266 .strategy = &sysctl_intvec,
1270 #ifdef CONFIG_HIGHMEM
1272 .ctl_name = CTL_UNNUMBERED,
1273 .procname = "highmem_is_dirtyable",
1274 .data = &vm_highmem_is_dirtyable,
1275 .maxlen = sizeof(vm_highmem_is_dirtyable),
1277 .proc_handler = &proc_dointvec_minmax,
1278 .strategy = &sysctl_intvec,
1283 #ifdef CONFIG_UNEVICTABLE_LRU
1285 .ctl_name = CTL_UNNUMBERED,
1286 .procname = "scan_unevictable_pages",
1287 .data = &scan_unevictable_pages,
1288 .maxlen = sizeof(scan_unevictable_pages),
1290 .proc_handler = &scan_unevictable_handler,
1294 * NOTE: do not add new entries to this table unless you have read
1295 * Documentation/sysctl/ctl_unnumbered.txt
1300 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1301 static struct ctl_table binfmt_misc_table[] = {
1306 static struct ctl_table fs_table[] = {
1308 .ctl_name = FS_NRINODE,
1309 .procname = "inode-nr",
1310 .data = &inodes_stat,
1311 .maxlen = 2*sizeof(int),
1313 .proc_handler = &proc_dointvec,
1316 .ctl_name = FS_STATINODE,
1317 .procname = "inode-state",
1318 .data = &inodes_stat,
1319 .maxlen = 7*sizeof(int),
1321 .proc_handler = &proc_dointvec,
1324 .procname = "file-nr",
1325 .data = &files_stat,
1326 .maxlen = 3*sizeof(int),
1328 .proc_handler = &proc_nr_files,
1331 .ctl_name = FS_MAXFILE,
1332 .procname = "file-max",
1333 .data = &files_stat.max_files,
1334 .maxlen = sizeof(int),
1336 .proc_handler = &proc_dointvec,
1339 .ctl_name = CTL_UNNUMBERED,
1340 .procname = "nr_open",
1341 .data = &sysctl_nr_open,
1342 .maxlen = sizeof(int),
1344 .proc_handler = &proc_dointvec_minmax,
1345 .extra1 = &sysctl_nr_open_min,
1346 .extra2 = &sysctl_nr_open_max,
1349 .ctl_name = FS_DENTRY,
1350 .procname = "dentry-state",
1351 .data = &dentry_stat,
1352 .maxlen = 6*sizeof(int),
1354 .proc_handler = &proc_dointvec,
1357 .ctl_name = FS_OVERFLOWUID,
1358 .procname = "overflowuid",
1359 .data = &fs_overflowuid,
1360 .maxlen = sizeof(int),
1362 .proc_handler = &proc_dointvec_minmax,
1363 .strategy = &sysctl_intvec,
1364 .extra1 = &minolduid,
1365 .extra2 = &maxolduid,
1368 .ctl_name = FS_OVERFLOWGID,
1369 .procname = "overflowgid",
1370 .data = &fs_overflowgid,
1371 .maxlen = sizeof(int),
1373 .proc_handler = &proc_dointvec_minmax,
1374 .strategy = &sysctl_intvec,
1375 .extra1 = &minolduid,
1376 .extra2 = &maxolduid,
1378 #ifdef CONFIG_FILE_LOCKING
1380 .ctl_name = FS_LEASES,
1381 .procname = "leases-enable",
1382 .data = &leases_enable,
1383 .maxlen = sizeof(int),
1385 .proc_handler = &proc_dointvec,
1388 #ifdef CONFIG_DNOTIFY
1390 .ctl_name = FS_DIR_NOTIFY,
1391 .procname = "dir-notify-enable",
1392 .data = &dir_notify_enable,
1393 .maxlen = sizeof(int),
1395 .proc_handler = &proc_dointvec,
1399 #ifdef CONFIG_FILE_LOCKING
1401 .ctl_name = FS_LEASE_TIME,
1402 .procname = "lease-break-time",
1403 .data = &lease_break_time,
1404 .maxlen = sizeof(int),
1406 .proc_handler = &proc_dointvec,
1411 .procname = "aio-nr",
1413 .maxlen = sizeof(aio_nr),
1415 .proc_handler = &proc_doulongvec_minmax,
1418 .procname = "aio-max-nr",
1419 .data = &aio_max_nr,
1420 .maxlen = sizeof(aio_max_nr),
1422 .proc_handler = &proc_doulongvec_minmax,
1424 #endif /* CONFIG_AIO */
1425 #ifdef CONFIG_INOTIFY_USER
1427 .ctl_name = FS_INOTIFY,
1428 .procname = "inotify",
1430 .child = inotify_table,
1435 .procname = "epoll",
1437 .child = epoll_table,
1442 .ctl_name = KERN_SETUID_DUMPABLE,
1443 .procname = "suid_dumpable",
1444 .data = &suid_dumpable,
1445 .maxlen = sizeof(int),
1447 .proc_handler = &proc_dointvec_minmax,
1448 .strategy = &sysctl_intvec,
1452 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1454 .ctl_name = CTL_UNNUMBERED,
1455 .procname = "binfmt_misc",
1457 .child = binfmt_misc_table,
1461 * NOTE: do not add new entries to this table unless you have read
1462 * Documentation/sysctl/ctl_unnumbered.txt
1467 static struct ctl_table debug_table[] = {
1468 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1470 .ctl_name = CTL_UNNUMBERED,
1471 .procname = "exception-trace",
1472 .data = &show_unhandled_signals,
1473 .maxlen = sizeof(int),
1475 .proc_handler = proc_dointvec
1481 static struct ctl_table dev_table[] = {
1485 static DEFINE_SPINLOCK(sysctl_lock);
1487 /* called under sysctl_lock */
1488 static int use_table(struct ctl_table_header *p)
1490 if (unlikely(p->unregistering))
1496 /* called under sysctl_lock */
1497 static void unuse_table(struct ctl_table_header *p)
1500 if (unlikely(p->unregistering))
1501 complete(p->unregistering);
1504 /* called under sysctl_lock, will reacquire if has to wait */
1505 static void start_unregistering(struct ctl_table_header *p)
1508 * if p->used is 0, nobody will ever touch that entry again;
1509 * we'll eliminate all paths to it before dropping sysctl_lock
1511 if (unlikely(p->used)) {
1512 struct completion wait;
1513 init_completion(&wait);
1514 p->unregistering = &wait;
1515 spin_unlock(&sysctl_lock);
1516 wait_for_completion(&wait);
1517 spin_lock(&sysctl_lock);
1519 /* anything non-NULL; we'll never dereference it */
1520 p->unregistering = ERR_PTR(-EINVAL);
1523 * do not remove from the list until nobody holds it; walking the
1524 * list in do_sysctl() relies on that.
1526 list_del_init(&p->ctl_entry);
1529 void sysctl_head_get(struct ctl_table_header *head)
1531 spin_lock(&sysctl_lock);
1533 spin_unlock(&sysctl_lock);
1536 void sysctl_head_put(struct ctl_table_header *head)
1538 spin_lock(&sysctl_lock);
1541 spin_unlock(&sysctl_lock);
1544 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1548 spin_lock(&sysctl_lock);
1549 if (!use_table(head))
1550 head = ERR_PTR(-ENOENT);
1551 spin_unlock(&sysctl_lock);
1555 void sysctl_head_finish(struct ctl_table_header *head)
1559 spin_lock(&sysctl_lock);
1561 spin_unlock(&sysctl_lock);
1564 static struct ctl_table_set *
1565 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1567 struct ctl_table_set *set = &root->default_set;
1569 set = root->lookup(root, namespaces);
1573 static struct list_head *
1574 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1576 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1580 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1581 struct ctl_table_header *prev)
1583 struct ctl_table_root *root;
1584 struct list_head *header_list;
1585 struct ctl_table_header *head;
1586 struct list_head *tmp;
1588 spin_lock(&sysctl_lock);
1591 tmp = &prev->ctl_entry;
1595 tmp = &root_table_header.ctl_entry;
1597 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1599 if (!use_table(head))
1601 spin_unlock(&sysctl_lock);
1606 header_list = lookup_header_list(root, namespaces);
1607 if (tmp != header_list)
1611 root = list_entry(root->root_list.next,
1612 struct ctl_table_root, root_list);
1613 if (root == &sysctl_table_root)
1615 header_list = lookup_header_list(root, namespaces);
1616 } while (list_empty(header_list));
1617 tmp = header_list->next;
1620 spin_unlock(&sysctl_lock);
1624 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1626 return __sysctl_head_next(current->nsproxy, prev);
1629 void register_sysctl_root(struct ctl_table_root *root)
1631 spin_lock(&sysctl_lock);
1632 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1633 spin_unlock(&sysctl_lock);
1636 #ifdef CONFIG_SYSCTL_SYSCALL
1637 /* Perform the actual read/write of a sysctl table entry. */
1638 static int do_sysctl_strategy(struct ctl_table_root *root,
1639 struct ctl_table *table,
1640 void __user *oldval, size_t __user *oldlenp,
1641 void __user *newval, size_t newlen)
1649 if (sysctl_perm(root, table, op))
1652 if (table->strategy) {
1653 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1660 /* If there is no strategy routine, or if the strategy returns
1661 * zero, proceed with automatic r/w */
1662 if (table->data && table->maxlen) {
1663 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1670 static int parse_table(int __user *name, int nlen,
1671 void __user *oldval, size_t __user *oldlenp,
1672 void __user *newval, size_t newlen,
1673 struct ctl_table_root *root,
1674 struct ctl_table *table)
1680 if (get_user(n, name))
1682 for ( ; table->ctl_name || table->procname; table++) {
1683 if (!table->ctl_name)
1685 if (n == table->ctl_name) {
1688 if (sysctl_perm(root, table, MAY_EXEC))
1692 table = table->child;
1695 error = do_sysctl_strategy(root, table,
1704 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1705 void __user *newval, size_t newlen)
1707 struct ctl_table_header *head;
1708 int error = -ENOTDIR;
1710 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1714 if (!oldlenp || get_user(old_len, oldlenp))
1718 for (head = sysctl_head_next(NULL); head;
1719 head = sysctl_head_next(head)) {
1720 error = parse_table(name, nlen, oldval, oldlenp,
1722 head->root, head->ctl_table);
1723 if (error != -ENOTDIR) {
1724 sysctl_head_finish(head);
1731 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1733 struct __sysctl_args tmp;
1736 if (copy_from_user(&tmp, args, sizeof(tmp)))
1739 error = deprecated_sysctl_warning(&tmp);
1744 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1745 tmp.newval, tmp.newlen);
1750 #endif /* CONFIG_SYSCTL_SYSCALL */
1753 * sysctl_perm does NOT grant the superuser all rights automatically, because
1754 * some sysctl variables are readonly even to root.
1757 static int test_perm(int mode, int op)
1759 if (!current_euid())
1761 else if (in_egroup_p(0))
1763 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1768 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1773 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1777 if (root->permissions)
1778 mode = root->permissions(root, current->nsproxy, table);
1782 return test_perm(mode, op);
1785 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1787 for (; table->ctl_name || table->procname; table++) {
1788 table->parent = parent;
1790 sysctl_set_parent(table, table->child);
1794 static __init int sysctl_init(void)
1796 sysctl_set_parent(NULL, root_table);
1797 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1800 err = sysctl_check_table(current->nsproxy, root_table);
1806 core_initcall(sysctl_init);
1808 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1809 struct ctl_table *table)
1811 struct ctl_table *p;
1812 const char *s = branch->procname;
1814 /* branch should have named subdirectory as its first element */
1815 if (!s || !branch->child)
1818 /* ... and nothing else */
1819 if (branch[1].procname || branch[1].ctl_name)
1822 /* table should contain subdirectory with the same name */
1823 for (p = table; p->procname || p->ctl_name; p++) {
1826 if (p->procname && strcmp(p->procname, s) == 0)
1832 /* see if attaching q to p would be an improvement */
1833 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1835 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1836 struct ctl_table *next;
1838 int not_in_parent = !p->attached_by;
1840 while ((next = is_branch_in(by, to)) != NULL) {
1841 if (by == q->attached_by)
1843 if (to == p->attached_by)
1849 if (is_better && not_in_parent) {
1850 q->attached_by = by;
1851 q->attached_to = to;
1857 * __register_sysctl_paths - register a sysctl hierarchy
1858 * @root: List of sysctl headers to register on
1859 * @namespaces: Data to compute which lists of sysctl entries are visible
1860 * @path: The path to the directory the sysctl table is in.
1861 * @table: the top-level table structure
1863 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1864 * array. A completely 0 filled entry terminates the table.
1866 * The members of the &struct ctl_table structure are used as follows:
1868 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1869 * must be unique within that level of sysctl
1871 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1872 * enter a sysctl file
1874 * data - a pointer to data for use by proc_handler
1876 * maxlen - the maximum size in bytes of the data
1878 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1880 * child - a pointer to the child sysctl table if this entry is a directory, or
1883 * proc_handler - the text handler routine (described below)
1885 * strategy - the strategy routine (described below)
1887 * de - for internal use by the sysctl routines
1889 * extra1, extra2 - extra pointers usable by the proc handler routines
1891 * Leaf nodes in the sysctl tree will be represented by a single file
1892 * under /proc; non-leaf nodes will be represented by directories.
1894 * sysctl(2) can automatically manage read and write requests through
1895 * the sysctl table. The data and maxlen fields of the ctl_table
1896 * struct enable minimal validation of the values being written to be
1897 * performed, and the mode field allows minimal authentication.
1899 * More sophisticated management can be enabled by the provision of a
1900 * strategy routine with the table entry. This will be called before
1901 * any automatic read or write of the data is performed.
1903 * The strategy routine may return
1905 * < 0 - Error occurred (error is passed to user process)
1907 * 0 - OK - proceed with automatic read or write.
1909 * > 0 - OK - read or write has been done by the strategy routine, so
1910 * return immediately.
1912 * There must be a proc_handler routine for any terminal nodes
1913 * mirrored under /proc/sys (non-terminals are handled by a built-in
1914 * directory handler). Several default handlers are available to
1915 * cover common cases -
1917 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1918 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1919 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1921 * It is the handler's job to read the input buffer from user memory
1922 * and process it. The handler should return 0 on success.
1924 * This routine returns %NULL on a failure to register, and a pointer
1925 * to the table header on success.
1927 struct ctl_table_header *__register_sysctl_paths(
1928 struct ctl_table_root *root,
1929 struct nsproxy *namespaces,
1930 const struct ctl_path *path, struct ctl_table *table)
1932 struct ctl_table_header *header;
1933 struct ctl_table *new, **prevp;
1934 unsigned int n, npath;
1935 struct ctl_table_set *set;
1937 /* Count the path components */
1938 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1942 * For each path component, allocate a 2-element ctl_table array.
1943 * The first array element will be filled with the sysctl entry
1944 * for this, the second will be the sentinel (ctl_name == 0).
1946 * We allocate everything in one go so that we don't have to
1947 * worry about freeing additional memory in unregister_sysctl_table.
1949 header = kzalloc(sizeof(struct ctl_table_header) +
1950 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1954 new = (struct ctl_table *) (header + 1);
1956 /* Now connect the dots */
1957 prevp = &header->ctl_table;
1958 for (n = 0; n < npath; ++n, ++path) {
1959 /* Copy the procname */
1960 new->procname = path->procname;
1961 new->ctl_name = path->ctl_name;
1965 prevp = &new->child;
1970 header->ctl_table_arg = table;
1972 INIT_LIST_HEAD(&header->ctl_entry);
1974 header->unregistering = NULL;
1975 header->root = root;
1976 sysctl_set_parent(NULL, header->ctl_table);
1978 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1979 if (sysctl_check_table(namespaces, header->ctl_table)) {
1984 spin_lock(&sysctl_lock);
1985 header->set = lookup_header_set(root, namespaces);
1986 header->attached_by = header->ctl_table;
1987 header->attached_to = root_table;
1988 header->parent = &root_table_header;
1989 for (set = header->set; set; set = set->parent) {
1990 struct ctl_table_header *p;
1991 list_for_each_entry(p, &set->list, ctl_entry) {
1992 if (p->unregistering)
1994 try_attach(p, header);
1997 header->parent->count++;
1998 list_add_tail(&header->ctl_entry, &header->set->list);
1999 spin_unlock(&sysctl_lock);
2005 * register_sysctl_table_path - register a sysctl table hierarchy
2006 * @path: The path to the directory the sysctl table is in.
2007 * @table: the top-level table structure
2009 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2010 * array. A completely 0 filled entry terminates the table.
2012 * See __register_sysctl_paths for more details.
2014 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2015 struct ctl_table *table)
2017 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2022 * register_sysctl_table - register a sysctl table hierarchy
2023 * @table: the top-level table structure
2025 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2026 * array. A completely 0 filled entry terminates the table.
2028 * See register_sysctl_paths for more details.
2030 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2032 static const struct ctl_path null_path[] = { {} };
2034 return register_sysctl_paths(null_path, table);
2038 * unregister_sysctl_table - unregister a sysctl table hierarchy
2039 * @header: the header returned from register_sysctl_table
2041 * Unregisters the sysctl table and all children. proc entries may not
2042 * actually be removed until they are no longer used by anyone.
2044 void unregister_sysctl_table(struct ctl_table_header * header)
2051 spin_lock(&sysctl_lock);
2052 start_unregistering(header);
2053 if (!--header->parent->count) {
2055 kfree(header->parent);
2057 if (!--header->count)
2059 spin_unlock(&sysctl_lock);
2062 int sysctl_is_seen(struct ctl_table_header *p)
2064 struct ctl_table_set *set = p->set;
2066 spin_lock(&sysctl_lock);
2067 if (p->unregistering)
2069 else if (!set->is_seen)
2072 res = set->is_seen(set);
2073 spin_unlock(&sysctl_lock);
2077 void setup_sysctl_set(struct ctl_table_set *p,
2078 struct ctl_table_set *parent,
2079 int (*is_seen)(struct ctl_table_set *))
2081 INIT_LIST_HEAD(&p->list);
2082 p->parent = parent ? parent : &sysctl_table_root.default_set;
2083 p->is_seen = is_seen;
2086 #else /* !CONFIG_SYSCTL */
2087 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2092 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2093 struct ctl_table *table)
2098 void unregister_sysctl_table(struct ctl_table_header * table)
2102 void setup_sysctl_set(struct ctl_table_set *p,
2103 struct ctl_table_set *parent,
2104 int (*is_seen)(struct ctl_table_set *))
2108 void sysctl_head_put(struct ctl_table_header *head)
2112 #endif /* CONFIG_SYSCTL */
2118 #ifdef CONFIG_PROC_SYSCTL
2120 static int _proc_do_string(void* data, int maxlen, int write,
2121 struct file *filp, void __user *buffer,
2122 size_t *lenp, loff_t *ppos)
2128 if (!data || !maxlen || !*lenp) {
2136 while (len < *lenp) {
2137 if (get_user(c, p++))
2139 if (c == 0 || c == '\n')
2145 if(copy_from_user(data, buffer, len))
2147 ((char *) data)[len] = 0;
2165 if(copy_to_user(buffer, data, len))
2168 if(put_user('\n', ((char __user *) buffer) + len))
2179 * proc_dostring - read a string sysctl
2180 * @table: the sysctl table
2181 * @write: %TRUE if this is a write to the sysctl file
2182 * @filp: the file structure
2183 * @buffer: the user buffer
2184 * @lenp: the size of the user buffer
2185 * @ppos: file position
2187 * Reads/writes a string from/to the user buffer. If the kernel
2188 * buffer provided is not large enough to hold the string, the
2189 * string is truncated. The copied string is %NULL-terminated.
2190 * If the string is being read by the user process, it is copied
2191 * and a newline '\n' is added. It is truncated if the buffer is
2194 * Returns 0 on success.
2196 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2197 void __user *buffer, size_t *lenp, loff_t *ppos)
2199 return _proc_do_string(table->data, table->maxlen, write, filp,
2200 buffer, lenp, ppos);
2204 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2206 int write, void *data)
2209 *valp = *negp ? -*lvalp : *lvalp;
2214 *lvalp = (unsigned long)-val;
2217 *lvalp = (unsigned long)val;
2223 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2224 int write, struct file *filp, void __user *buffer,
2225 size_t *lenp, loff_t *ppos,
2226 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2227 int write, void *data),
2230 #define TMPBUFLEN 21
2231 int *i, vleft, first=1, neg, val;
2235 char buf[TMPBUFLEN], *p;
2236 char __user *s = buffer;
2238 if (!tbl_data || !table->maxlen || !*lenp ||
2239 (*ppos && !write)) {
2244 i = (int *) tbl_data;
2245 vleft = table->maxlen / sizeof(*i);
2249 conv = do_proc_dointvec_conv;
2251 for (; left && vleft--; i++, first=0) {
2266 if (len > sizeof(buf) - 1)
2267 len = sizeof(buf) - 1;
2268 if (copy_from_user(buf, s, len))
2272 if (*p == '-' && left > 1) {
2276 if (*p < '0' || *p > '9')
2279 lval = simple_strtoul(p, &p, 0);
2282 if ((len < left) && *p && !isspace(*p))
2289 if (conv(&neg, &lval, i, 1, data))
2296 if (conv(&neg, &lval, i, 0, data))
2299 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2303 if(copy_to_user(s, buf, len))
2310 if (!write && !first && left) {
2311 if(put_user('\n', s))
2318 if (get_user(c, s++))
2333 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2334 void __user *buffer, size_t *lenp, loff_t *ppos,
2335 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2336 int write, void *data),
2339 return __do_proc_dointvec(table->data, table, write, filp,
2340 buffer, lenp, ppos, conv, data);
2344 * proc_dointvec - read a vector of integers
2345 * @table: the sysctl table
2346 * @write: %TRUE if this is a write to the sysctl file
2347 * @filp: the file structure
2348 * @buffer: the user buffer
2349 * @lenp: the size of the user buffer
2350 * @ppos: file position
2352 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2353 * values from/to the user buffer, treated as an ASCII string.
2355 * Returns 0 on success.
2357 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2358 void __user *buffer, size_t *lenp, loff_t *ppos)
2360 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2365 * Taint values can only be increased
2366 * This means we can safely use a temporary.
2368 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2369 void __user *buffer, size_t *lenp, loff_t *ppos)
2372 unsigned long tmptaint = get_taint();
2375 if (write && !capable(CAP_SYS_ADMIN))
2380 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2386 * Poor man's atomic or. Not worth adding a primitive
2387 * to everyone's atomic.h for this
2390 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2391 if ((tmptaint >> i) & 1)
2399 struct do_proc_dointvec_minmax_conv_param {
2404 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2406 int write, void *data)
2408 struct do_proc_dointvec_minmax_conv_param *param = data;
2410 int val = *negp ? -*lvalp : *lvalp;
2411 if ((param->min && *param->min > val) ||
2412 (param->max && *param->max < val))
2419 *lvalp = (unsigned long)-val;
2422 *lvalp = (unsigned long)val;
2429 * proc_dointvec_minmax - read a vector of integers with min/max values
2430 * @table: the sysctl table
2431 * @write: %TRUE if this is a write to the sysctl file
2432 * @filp: the file structure
2433 * @buffer: the user buffer
2434 * @lenp: the size of the user buffer
2435 * @ppos: file position
2437 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2438 * values from/to the user buffer, treated as an ASCII string.
2440 * This routine will ensure the values are within the range specified by
2441 * table->extra1 (min) and table->extra2 (max).
2443 * Returns 0 on success.
2445 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2446 void __user *buffer, size_t *lenp, loff_t *ppos)
2448 struct do_proc_dointvec_minmax_conv_param param = {
2449 .min = (int *) table->extra1,
2450 .max = (int *) table->extra2,
2452 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2453 do_proc_dointvec_minmax_conv, ¶m);
2456 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2458 void __user *buffer,
2459 size_t *lenp, loff_t *ppos,
2460 unsigned long convmul,
2461 unsigned long convdiv)
2463 #define TMPBUFLEN 21
2464 unsigned long *i, *min, *max, val;
2465 int vleft, first=1, neg;
2467 char buf[TMPBUFLEN], *p;
2468 char __user *s = buffer;
2470 if (!data || !table->maxlen || !*lenp ||
2471 (*ppos && !write)) {
2476 i = (unsigned long *) data;
2477 min = (unsigned long *) table->extra1;
2478 max = (unsigned long *) table->extra2;
2479 vleft = table->maxlen / sizeof(unsigned long);
2482 for (; left && vleft--; i++, min++, max++, first=0) {
2497 if (len > TMPBUFLEN-1)
2499 if (copy_from_user(buf, s, len))
2503 if (*p == '-' && left > 1) {
2507 if (*p < '0' || *p > '9')
2509 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2511 if ((len < left) && *p && !isspace(*p))
2520 if ((min && val < *min) || (max && val > *max))
2527 sprintf(p, "%lu", convdiv * (*i) / convmul);
2531 if(copy_to_user(s, buf, len))
2538 if (!write && !first && left) {
2539 if(put_user('\n', s))
2546 if (get_user(c, s++))
2561 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2563 void __user *buffer,
2564 size_t *lenp, loff_t *ppos,
2565 unsigned long convmul,
2566 unsigned long convdiv)
2568 return __do_proc_doulongvec_minmax(table->data, table, write,
2569 filp, buffer, lenp, ppos, convmul, convdiv);
2573 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2574 * @table: the sysctl table
2575 * @write: %TRUE if this is a write to the sysctl file
2576 * @filp: the file structure
2577 * @buffer: the user buffer
2578 * @lenp: the size of the user buffer
2579 * @ppos: file position
2581 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2582 * values from/to the user buffer, treated as an ASCII string.
2584 * This routine will ensure the values are within the range specified by
2585 * table->extra1 (min) and table->extra2 (max).
2587 * Returns 0 on success.
2589 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2590 void __user *buffer, size_t *lenp, loff_t *ppos)
2592 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2596 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2597 * @table: the sysctl table
2598 * @write: %TRUE if this is a write to the sysctl file
2599 * @filp: the file structure
2600 * @buffer: the user buffer
2601 * @lenp: the size of the user buffer
2602 * @ppos: file position
2604 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2605 * values from/to the user buffer, treated as an ASCII string. The values
2606 * are treated as milliseconds, and converted to jiffies when they are stored.
2608 * This routine will ensure the values are within the range specified by
2609 * table->extra1 (min) and table->extra2 (max).
2611 * Returns 0 on success.
2613 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2615 void __user *buffer,
2616 size_t *lenp, loff_t *ppos)
2618 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2619 lenp, ppos, HZ, 1000l);
2623 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2625 int write, void *data)
2628 if (*lvalp > LONG_MAX / HZ)
2630 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2636 lval = (unsigned long)-val;
2639 lval = (unsigned long)val;
2646 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2648 int write, void *data)
2651 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2653 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2659 lval = (unsigned long)-val;
2662 lval = (unsigned long)val;
2664 *lvalp = jiffies_to_clock_t(lval);
2669 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2671 int write, void *data)
2674 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2680 lval = (unsigned long)-val;
2683 lval = (unsigned long)val;
2685 *lvalp = jiffies_to_msecs(lval);
2691 * proc_dointvec_jiffies - read a vector of integers as seconds
2692 * @table: the sysctl table
2693 * @write: %TRUE if this is a write to the sysctl file
2694 * @filp: the file structure
2695 * @buffer: the user buffer
2696 * @lenp: the size of the user buffer
2697 * @ppos: file position
2699 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2700 * values from/to the user buffer, treated as an ASCII string.
2701 * The values read are assumed to be in seconds, and are converted into
2704 * Returns 0 on success.
2706 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2707 void __user *buffer, size_t *lenp, loff_t *ppos)
2709 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2710 do_proc_dointvec_jiffies_conv,NULL);
2714 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2715 * @table: the sysctl table
2716 * @write: %TRUE if this is a write to the sysctl file
2717 * @filp: the file structure
2718 * @buffer: the user buffer
2719 * @lenp: the size of the user buffer
2720 * @ppos: pointer to the file position
2722 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2723 * values from/to the user buffer, treated as an ASCII string.
2724 * The values read are assumed to be in 1/USER_HZ seconds, and
2725 * are converted into jiffies.
2727 * Returns 0 on success.
2729 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2730 void __user *buffer, size_t *lenp, loff_t *ppos)
2732 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2733 do_proc_dointvec_userhz_jiffies_conv,NULL);
2737 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2738 * @table: the sysctl table
2739 * @write: %TRUE if this is a write to the sysctl file
2740 * @filp: the file structure
2741 * @buffer: the user buffer
2742 * @lenp: the size of the user buffer
2743 * @ppos: file position
2744 * @ppos: the current position in the file
2746 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2747 * values from/to the user buffer, treated as an ASCII string.
2748 * The values read are assumed to be in 1/1000 seconds, and
2749 * are converted into jiffies.
2751 * Returns 0 on success.
2753 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2754 void __user *buffer, size_t *lenp, loff_t *ppos)
2756 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2757 do_proc_dointvec_ms_jiffies_conv, NULL);
2760 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2761 void __user *buffer, size_t *lenp, loff_t *ppos)
2763 struct pid *new_pid;
2767 tmp = pid_vnr(cad_pid);
2769 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2770 lenp, ppos, NULL, NULL);
2774 new_pid = find_get_pid(tmp);
2778 put_pid(xchg(&cad_pid, new_pid));
2782 #else /* CONFIG_PROC_FS */
2784 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2785 void __user *buffer, size_t *lenp, loff_t *ppos)
2790 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2791 void __user *buffer, size_t *lenp, loff_t *ppos)
2796 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2797 void __user *buffer, size_t *lenp, loff_t *ppos)
2802 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2803 void __user *buffer, size_t *lenp, loff_t *ppos)
2808 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2809 void __user *buffer, size_t *lenp, loff_t *ppos)
2814 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2815 void __user *buffer, size_t *lenp, loff_t *ppos)
2820 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2821 void __user *buffer, size_t *lenp, loff_t *ppos)
2826 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2828 void __user *buffer,
2829 size_t *lenp, loff_t *ppos)
2835 #endif /* CONFIG_PROC_FS */
2838 #ifdef CONFIG_SYSCTL_SYSCALL
2840 * General sysctl support routines
2843 /* The generic sysctl data routine (used if no strategy routine supplied) */
2844 int sysctl_data(struct ctl_table *table,
2845 void __user *oldval, size_t __user *oldlenp,
2846 void __user *newval, size_t newlen)
2850 /* Get out of I don't have a variable */
2851 if (!table->data || !table->maxlen)
2854 if (oldval && oldlenp) {
2855 if (get_user(len, oldlenp))
2858 if (len > table->maxlen)
2859 len = table->maxlen;
2860 if (copy_to_user(oldval, table->data, len))
2862 if (put_user(len, oldlenp))
2867 if (newval && newlen) {
2868 if (newlen > table->maxlen)
2869 newlen = table->maxlen;
2871 if (copy_from_user(table->data, newval, newlen))
2877 /* The generic string strategy routine: */
2878 int sysctl_string(struct ctl_table *table,
2879 void __user *oldval, size_t __user *oldlenp,
2880 void __user *newval, size_t newlen)
2882 if (!table->data || !table->maxlen)
2885 if (oldval && oldlenp) {
2887 if (get_user(bufsize, oldlenp))
2890 size_t len = strlen(table->data), copied;
2892 /* This shouldn't trigger for a well-formed sysctl */
2893 if (len > table->maxlen)
2894 len = table->maxlen;
2896 /* Copy up to a max of bufsize-1 bytes of the string */
2897 copied = (len >= bufsize) ? bufsize - 1 : len;
2899 if (copy_to_user(oldval, table->data, copied) ||
2900 put_user(0, (char __user *)(oldval + copied)))
2902 if (put_user(len, oldlenp))
2906 if (newval && newlen) {
2907 size_t len = newlen;
2908 if (len > table->maxlen)
2909 len = table->maxlen;
2910 if(copy_from_user(table->data, newval, len))
2912 if (len == table->maxlen)
2914 ((char *) table->data)[len] = 0;
2920 * This function makes sure that all of the integers in the vector
2921 * are between the minimum and maximum values given in the arrays
2922 * table->extra1 and table->extra2, respectively.
2924 int sysctl_intvec(struct ctl_table *table,
2925 void __user *oldval, size_t __user *oldlenp,
2926 void __user *newval, size_t newlen)
2929 if (newval && newlen) {
2930 int __user *vec = (int __user *) newval;
2931 int *min = (int *) table->extra1;
2932 int *max = (int *) table->extra2;
2936 if (newlen % sizeof(int) != 0)
2939 if (!table->extra1 && !table->extra2)
2942 if (newlen > table->maxlen)
2943 newlen = table->maxlen;
2944 length = newlen / sizeof(int);
2946 for (i = 0; i < length; i++) {
2948 if (get_user(value, vec + i))
2950 if (min && value < min[i])
2952 if (max && value > max[i])
2959 /* Strategy function to convert jiffies to seconds */
2960 int sysctl_jiffies(struct ctl_table *table,
2961 void __user *oldval, size_t __user *oldlenp,
2962 void __user *newval, size_t newlen)
2964 if (oldval && oldlenp) {
2967 if (get_user(olen, oldlenp))
2972 if (olen < sizeof(int))
2975 val = *(int *)(table->data) / HZ;
2976 if (put_user(val, (int __user *)oldval))
2978 if (put_user(sizeof(int), oldlenp))
2982 if (newval && newlen) {
2984 if (newlen != sizeof(int))
2986 if (get_user(new, (int __user *)newval))
2988 *(int *)(table->data) = new*HZ;
2993 /* Strategy function to convert jiffies to seconds */
2994 int sysctl_ms_jiffies(struct ctl_table *table,
2995 void __user *oldval, size_t __user *oldlenp,
2996 void __user *newval, size_t newlen)
2998 if (oldval && oldlenp) {
3001 if (get_user(olen, oldlenp))
3006 if (olen < sizeof(int))
3009 val = jiffies_to_msecs(*(int *)(table->data));
3010 if (put_user(val, (int __user *)oldval))
3012 if (put_user(sizeof(int), oldlenp))
3016 if (newval && newlen) {
3018 if (newlen != sizeof(int))
3020 if (get_user(new, (int __user *)newval))
3022 *(int *)(table->data) = msecs_to_jiffies(new);
3029 #else /* CONFIG_SYSCTL_SYSCALL */
3032 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3034 struct __sysctl_args tmp;
3037 if (copy_from_user(&tmp, args, sizeof(tmp)))
3040 error = deprecated_sysctl_warning(&tmp);
3042 /* If no error reading the parameters then just -ENOSYS ... */
3049 int sysctl_data(struct ctl_table *table,
3050 void __user *oldval, size_t __user *oldlenp,
3051 void __user *newval, size_t newlen)
3056 int sysctl_string(struct ctl_table *table,
3057 void __user *oldval, size_t __user *oldlenp,
3058 void __user *newval, size_t newlen)
3063 int sysctl_intvec(struct ctl_table *table,
3064 void __user *oldval, size_t __user *oldlenp,
3065 void __user *newval, size_t newlen)
3070 int sysctl_jiffies(struct ctl_table *table,
3071 void __user *oldval, size_t __user *oldlenp,
3072 void __user *newval, size_t newlen)
3077 int sysctl_ms_jiffies(struct ctl_table *table,
3078 void __user *oldval, size_t __user *oldlenp,
3079 void __user *newval, size_t newlen)
3084 #endif /* CONFIG_SYSCTL_SYSCALL */
3086 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3088 static int msg_count;
3089 int name[CTL_MAXNAME];
3092 /* Check args->nlen. */
3093 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3096 /* Read in the sysctl name for better debug message logging */
3097 for (i = 0; i < args->nlen; i++)
3098 if (get_user(name[i], args->name + i))
3101 /* Ignore accesses to kernel.version */
3102 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3105 if (msg_count < 5) {
3108 "warning: process `%s' used the deprecated sysctl "
3109 "system call with ", current->comm);
3110 for (i = 0; i < args->nlen; i++)
3111 printk("%d.", name[i]);
3118 * No sense putting this after each symbol definition, twice,
3119 * exception granted :-)
3121 EXPORT_SYMBOL(proc_dointvec);
3122 EXPORT_SYMBOL(proc_dointvec_jiffies);
3123 EXPORT_SYMBOL(proc_dointvec_minmax);
3124 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3125 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3126 EXPORT_SYMBOL(proc_dostring);
3127 EXPORT_SYMBOL(proc_doulongvec_minmax);
3128 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3129 EXPORT_SYMBOL(register_sysctl_table);
3130 EXPORT_SYMBOL(register_sysctl_paths);
3131 EXPORT_SYMBOL(sysctl_intvec);
3132 EXPORT_SYMBOL(sysctl_jiffies);
3133 EXPORT_SYMBOL(sysctl_ms_jiffies);
3134 EXPORT_SYMBOL(sysctl_string);
3135 EXPORT_SYMBOL(sysctl_data);
3136 EXPORT_SYMBOL(unregister_sysctl_table);