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/kmemcheck.h>
31 #include <linux/smp_lock.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/hugetlb.h>
41 #include <linux/initrd.h>
42 #include <linux/key.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/vmstat.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/acpi.h>
50 #include <linux/reboot.h>
51 #include <linux/ftrace.h>
52 #include <linux/slow-work.h>
53 #include <linux/perf_counter.h>
55 #include <asm/uaccess.h>
56 #include <asm/processor.h>
60 #include <asm/stacktrace.h>
64 static int deprecated_sysctl_warning(struct __sysctl_args *args);
66 #if defined(CONFIG_SYSCTL)
68 /* External variables not in a header file. */
70 extern int print_fatal_signals;
71 extern int sysctl_overcommit_memory;
72 extern int sysctl_overcommit_ratio;
73 extern int sysctl_panic_on_oom;
74 extern int sysctl_oom_kill_allocating_task;
75 extern int sysctl_oom_dump_tasks;
76 extern int max_threads;
77 extern int core_uses_pid;
78 extern int suid_dumpable;
79 extern char core_pattern[];
81 extern int min_free_kbytes;
82 extern int pid_max_min, pid_max_max;
83 extern int sysctl_drop_caches;
84 extern int percpu_pagelist_fraction;
85 extern int compat_log;
86 extern int latencytop_enabled;
87 extern int sysctl_nr_open_min, sysctl_nr_open_max;
89 extern int sysctl_nr_trim_pages;
91 #ifdef CONFIG_RCU_TORTURE_TEST
92 extern int rcutorture_runnable;
93 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
95 /* Constants used for minimum and maximum */
96 #ifdef CONFIG_DETECT_SOFTLOCKUP
97 static int sixty = 60;
98 static int neg_one = -1;
102 static int __maybe_unused one = 1;
103 static int __maybe_unused two = 2;
104 static unsigned long one_ul = 1;
105 static int one_hundred = 100;
107 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
108 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
110 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
111 static int maxolduid = 65535;
112 static int minolduid;
113 static int min_percpu_pagelist_fract = 8;
115 static int ngroups_max = NGROUPS_MAX;
117 #ifdef CONFIG_MODULES
118 extern char modprobe_path[];
119 extern int modules_disabled;
121 #ifdef CONFIG_CHR_DEV_SG
122 extern int sg_big_buff;
126 #include <asm/system.h>
129 #ifdef CONFIG_SPARC64
130 extern int sysctl_tsb_ratio;
134 extern int pwrsw_enabled;
135 extern int unaligned_enabled;
139 #ifdef CONFIG_MATHEMU
140 extern int sysctl_ieee_emulation_warnings;
142 extern int sysctl_userprocess_debug;
143 extern int spin_retry;
146 #ifdef CONFIG_BSD_PROCESS_ACCT
147 extern int acct_parm[];
151 extern int no_unaligned_warning;
152 extern int unaligned_dump_stack;
155 #ifdef CONFIG_RT_MUTEXES
156 extern int max_lock_depth;
159 #ifdef CONFIG_PROC_SYSCTL
160 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
161 void __user *buffer, size_t *lenp, loff_t *ppos);
162 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
163 void __user *buffer, size_t *lenp, loff_t *ppos);
166 static struct ctl_table root_table[];
167 static struct ctl_table_root sysctl_table_root;
168 static struct ctl_table_header root_table_header = {
170 .ctl_table = root_table,
171 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
172 .root = &sysctl_table_root,
173 .set = &sysctl_table_root.default_set,
175 static struct ctl_table_root sysctl_table_root = {
176 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
177 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
180 static struct ctl_table kern_table[];
181 static struct ctl_table vm_table[];
182 static struct ctl_table fs_table[];
183 static struct ctl_table debug_table[];
184 static struct ctl_table dev_table[];
185 extern struct ctl_table random_table[];
186 #ifdef CONFIG_INOTIFY_USER
187 extern struct ctl_table inotify_table[];
190 extern struct ctl_table epoll_table[];
193 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
194 int sysctl_legacy_va_layout;
197 extern int prove_locking;
198 extern int lock_stat;
200 /* The default sysctl tables: */
202 static struct ctl_table root_table[] = {
204 .ctl_name = CTL_KERN,
205 .procname = "kernel",
222 .ctl_name = CTL_DEBUG,
225 .child = debug_table,
234 * NOTE: do not add new entries to this table unless you have read
235 * Documentation/sysctl/ctl_unnumbered.txt
240 #ifdef CONFIG_SCHED_DEBUG
241 static int min_sched_granularity_ns = 100000; /* 100 usecs */
242 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
243 static int min_wakeup_granularity_ns; /* 0 usecs */
244 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
247 static struct ctl_table kern_table[] = {
248 #ifdef CONFIG_SCHED_DEBUG
250 .ctl_name = CTL_UNNUMBERED,
251 .procname = "sched_min_granularity_ns",
252 .data = &sysctl_sched_min_granularity,
253 .maxlen = sizeof(unsigned int),
255 .proc_handler = &sched_nr_latency_handler,
256 .strategy = &sysctl_intvec,
257 .extra1 = &min_sched_granularity_ns,
258 .extra2 = &max_sched_granularity_ns,
261 .ctl_name = CTL_UNNUMBERED,
262 .procname = "sched_latency_ns",
263 .data = &sysctl_sched_latency,
264 .maxlen = sizeof(unsigned int),
266 .proc_handler = &sched_nr_latency_handler,
267 .strategy = &sysctl_intvec,
268 .extra1 = &min_sched_granularity_ns,
269 .extra2 = &max_sched_granularity_ns,
272 .ctl_name = CTL_UNNUMBERED,
273 .procname = "sched_wakeup_granularity_ns",
274 .data = &sysctl_sched_wakeup_granularity,
275 .maxlen = sizeof(unsigned int),
277 .proc_handler = &proc_dointvec_minmax,
278 .strategy = &sysctl_intvec,
279 .extra1 = &min_wakeup_granularity_ns,
280 .extra2 = &max_wakeup_granularity_ns,
283 .ctl_name = CTL_UNNUMBERED,
284 .procname = "sched_shares_ratelimit",
285 .data = &sysctl_sched_shares_ratelimit,
286 .maxlen = sizeof(unsigned int),
288 .proc_handler = &proc_dointvec,
291 .ctl_name = CTL_UNNUMBERED,
292 .procname = "sched_shares_thresh",
293 .data = &sysctl_sched_shares_thresh,
294 .maxlen = sizeof(unsigned int),
296 .proc_handler = &proc_dointvec_minmax,
297 .strategy = &sysctl_intvec,
301 .ctl_name = CTL_UNNUMBERED,
302 .procname = "sched_child_runs_first",
303 .data = &sysctl_sched_child_runs_first,
304 .maxlen = sizeof(unsigned int),
306 .proc_handler = &proc_dointvec,
309 .ctl_name = CTL_UNNUMBERED,
310 .procname = "sched_features",
311 .data = &sysctl_sched_features,
312 .maxlen = sizeof(unsigned int),
314 .proc_handler = &proc_dointvec,
317 .ctl_name = CTL_UNNUMBERED,
318 .procname = "sched_migration_cost",
319 .data = &sysctl_sched_migration_cost,
320 .maxlen = sizeof(unsigned int),
322 .proc_handler = &proc_dointvec,
325 .ctl_name = CTL_UNNUMBERED,
326 .procname = "sched_nr_migrate",
327 .data = &sysctl_sched_nr_migrate,
328 .maxlen = sizeof(unsigned int),
330 .proc_handler = &proc_dointvec,
333 .ctl_name = CTL_UNNUMBERED,
334 .procname = "timer_migration",
335 .data = &sysctl_timer_migration,
336 .maxlen = sizeof(unsigned int),
338 .proc_handler = &proc_dointvec,
342 .ctl_name = CTL_UNNUMBERED,
343 .procname = "sched_rt_period_us",
344 .data = &sysctl_sched_rt_period,
345 .maxlen = sizeof(unsigned int),
347 .proc_handler = &sched_rt_handler,
350 .ctl_name = CTL_UNNUMBERED,
351 .procname = "sched_rt_runtime_us",
352 .data = &sysctl_sched_rt_runtime,
353 .maxlen = sizeof(int),
355 .proc_handler = &sched_rt_handler,
358 .ctl_name = CTL_UNNUMBERED,
359 .procname = "sched_compat_yield",
360 .data = &sysctl_sched_compat_yield,
361 .maxlen = sizeof(unsigned int),
363 .proc_handler = &proc_dointvec,
365 #ifdef CONFIG_PROVE_LOCKING
367 .ctl_name = CTL_UNNUMBERED,
368 .procname = "prove_locking",
369 .data = &prove_locking,
370 .maxlen = sizeof(int),
372 .proc_handler = &proc_dointvec,
375 #ifdef CONFIG_LOCK_STAT
377 .ctl_name = CTL_UNNUMBERED,
378 .procname = "lock_stat",
380 .maxlen = sizeof(int),
382 .proc_handler = &proc_dointvec,
386 .ctl_name = KERN_PANIC,
388 .data = &panic_timeout,
389 .maxlen = sizeof(int),
391 .proc_handler = &proc_dointvec,
394 .ctl_name = KERN_CORE_USES_PID,
395 .procname = "core_uses_pid",
396 .data = &core_uses_pid,
397 .maxlen = sizeof(int),
399 .proc_handler = &proc_dointvec,
402 .ctl_name = KERN_CORE_PATTERN,
403 .procname = "core_pattern",
404 .data = core_pattern,
405 .maxlen = CORENAME_MAX_SIZE,
407 .proc_handler = &proc_dostring,
408 .strategy = &sysctl_string,
410 #ifdef CONFIG_PROC_SYSCTL
412 .procname = "tainted",
413 .maxlen = sizeof(long),
415 .proc_handler = &proc_taint,
418 #ifdef CONFIG_LATENCYTOP
420 .procname = "latencytop",
421 .data = &latencytop_enabled,
422 .maxlen = sizeof(int),
424 .proc_handler = &proc_dointvec,
427 #ifdef CONFIG_BLK_DEV_INITRD
429 .ctl_name = KERN_REALROOTDEV,
430 .procname = "real-root-dev",
431 .data = &real_root_dev,
432 .maxlen = sizeof(int),
434 .proc_handler = &proc_dointvec,
438 .ctl_name = CTL_UNNUMBERED,
439 .procname = "print-fatal-signals",
440 .data = &print_fatal_signals,
441 .maxlen = sizeof(int),
443 .proc_handler = &proc_dointvec,
447 .ctl_name = KERN_SPARC_REBOOT,
448 .procname = "reboot-cmd",
449 .data = reboot_command,
452 .proc_handler = &proc_dostring,
453 .strategy = &sysctl_string,
456 .ctl_name = KERN_SPARC_STOP_A,
457 .procname = "stop-a",
458 .data = &stop_a_enabled,
459 .maxlen = sizeof (int),
461 .proc_handler = &proc_dointvec,
464 .ctl_name = KERN_SPARC_SCONS_PWROFF,
465 .procname = "scons-poweroff",
466 .data = &scons_pwroff,
467 .maxlen = sizeof (int),
469 .proc_handler = &proc_dointvec,
472 #ifdef CONFIG_SPARC64
474 .ctl_name = CTL_UNNUMBERED,
475 .procname = "tsb-ratio",
476 .data = &sysctl_tsb_ratio,
477 .maxlen = sizeof (int),
479 .proc_handler = &proc_dointvec,
484 .ctl_name = KERN_HPPA_PWRSW,
485 .procname = "soft-power",
486 .data = &pwrsw_enabled,
487 .maxlen = sizeof (int),
489 .proc_handler = &proc_dointvec,
492 .ctl_name = KERN_HPPA_UNALIGNED,
493 .procname = "unaligned-trap",
494 .data = &unaligned_enabled,
495 .maxlen = sizeof (int),
497 .proc_handler = &proc_dointvec,
501 .ctl_name = KERN_CTLALTDEL,
502 .procname = "ctrl-alt-del",
504 .maxlen = sizeof(int),
506 .proc_handler = &proc_dointvec,
508 #ifdef CONFIG_FUNCTION_TRACER
510 .ctl_name = CTL_UNNUMBERED,
511 .procname = "ftrace_enabled",
512 .data = &ftrace_enabled,
513 .maxlen = sizeof(int),
515 .proc_handler = &ftrace_enable_sysctl,
518 #ifdef CONFIG_STACK_TRACER
520 .ctl_name = CTL_UNNUMBERED,
521 .procname = "stack_tracer_enabled",
522 .data = &stack_tracer_enabled,
523 .maxlen = sizeof(int),
525 .proc_handler = &stack_trace_sysctl,
528 #ifdef CONFIG_TRACING
530 .ctl_name = CTL_UNNUMBERED,
531 .procname = "ftrace_dump_on_oops",
532 .data = &ftrace_dump_on_oops,
533 .maxlen = sizeof(int),
535 .proc_handler = &proc_dointvec,
538 #ifdef CONFIG_MODULES
540 .ctl_name = KERN_MODPROBE,
541 .procname = "modprobe",
542 .data = &modprobe_path,
543 .maxlen = KMOD_PATH_LEN,
545 .proc_handler = &proc_dostring,
546 .strategy = &sysctl_string,
549 .ctl_name = CTL_UNNUMBERED,
550 .procname = "modules_disabled",
551 .data = &modules_disabled,
552 .maxlen = sizeof(int),
554 /* only handle a transition from default "0" to "1" */
555 .proc_handler = &proc_dointvec_minmax,
560 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
562 .ctl_name = KERN_HOTPLUG,
563 .procname = "hotplug",
564 .data = &uevent_helper,
565 .maxlen = UEVENT_HELPER_PATH_LEN,
567 .proc_handler = &proc_dostring,
568 .strategy = &sysctl_string,
571 #ifdef CONFIG_CHR_DEV_SG
573 .ctl_name = KERN_SG_BIG_BUFF,
574 .procname = "sg-big-buff",
575 .data = &sg_big_buff,
576 .maxlen = sizeof (int),
578 .proc_handler = &proc_dointvec,
581 #ifdef CONFIG_BSD_PROCESS_ACCT
583 .ctl_name = KERN_ACCT,
586 .maxlen = 3*sizeof(int),
588 .proc_handler = &proc_dointvec,
591 #ifdef CONFIG_MAGIC_SYSRQ
593 .ctl_name = KERN_SYSRQ,
595 .data = &__sysrq_enabled,
596 .maxlen = sizeof (int),
598 .proc_handler = &proc_dointvec,
601 #ifdef CONFIG_PROC_SYSCTL
603 .procname = "cad_pid",
605 .maxlen = sizeof (int),
607 .proc_handler = &proc_do_cad_pid,
611 .ctl_name = KERN_MAX_THREADS,
612 .procname = "threads-max",
613 .data = &max_threads,
614 .maxlen = sizeof(int),
616 .proc_handler = &proc_dointvec,
619 .ctl_name = KERN_RANDOM,
620 .procname = "random",
622 .child = random_table,
625 .ctl_name = KERN_OVERFLOWUID,
626 .procname = "overflowuid",
627 .data = &overflowuid,
628 .maxlen = sizeof(int),
630 .proc_handler = &proc_dointvec_minmax,
631 .strategy = &sysctl_intvec,
632 .extra1 = &minolduid,
633 .extra2 = &maxolduid,
636 .ctl_name = KERN_OVERFLOWGID,
637 .procname = "overflowgid",
638 .data = &overflowgid,
639 .maxlen = sizeof(int),
641 .proc_handler = &proc_dointvec_minmax,
642 .strategy = &sysctl_intvec,
643 .extra1 = &minolduid,
644 .extra2 = &maxolduid,
647 #ifdef CONFIG_MATHEMU
649 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
650 .procname = "ieee_emulation_warnings",
651 .data = &sysctl_ieee_emulation_warnings,
652 .maxlen = sizeof(int),
654 .proc_handler = &proc_dointvec,
658 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
659 .procname = "userprocess_debug",
660 .data = &sysctl_userprocess_debug,
661 .maxlen = sizeof(int),
663 .proc_handler = &proc_dointvec,
667 .ctl_name = KERN_PIDMAX,
668 .procname = "pid_max",
670 .maxlen = sizeof (int),
672 .proc_handler = &proc_dointvec_minmax,
673 .strategy = sysctl_intvec,
674 .extra1 = &pid_max_min,
675 .extra2 = &pid_max_max,
678 .ctl_name = KERN_PANIC_ON_OOPS,
679 .procname = "panic_on_oops",
680 .data = &panic_on_oops,
681 .maxlen = sizeof(int),
683 .proc_handler = &proc_dointvec,
685 #if defined CONFIG_PRINTK
687 .ctl_name = KERN_PRINTK,
688 .procname = "printk",
689 .data = &console_loglevel,
690 .maxlen = 4*sizeof(int),
692 .proc_handler = &proc_dointvec,
695 .ctl_name = KERN_PRINTK_RATELIMIT,
696 .procname = "printk_ratelimit",
697 .data = &printk_ratelimit_state.interval,
698 .maxlen = sizeof(int),
700 .proc_handler = &proc_dointvec_jiffies,
701 .strategy = &sysctl_jiffies,
704 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
705 .procname = "printk_ratelimit_burst",
706 .data = &printk_ratelimit_state.burst,
707 .maxlen = sizeof(int),
709 .proc_handler = &proc_dointvec,
713 .ctl_name = KERN_NGROUPS_MAX,
714 .procname = "ngroups_max",
715 .data = &ngroups_max,
716 .maxlen = sizeof (int),
718 .proc_handler = &proc_dointvec,
720 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
722 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
723 .procname = "unknown_nmi_panic",
724 .data = &unknown_nmi_panic,
725 .maxlen = sizeof (int),
727 .proc_handler = &proc_dointvec,
730 .procname = "nmi_watchdog",
731 .data = &nmi_watchdog_enabled,
732 .maxlen = sizeof (int),
734 .proc_handler = &proc_nmi_enabled,
737 #if defined(CONFIG_X86)
739 .ctl_name = KERN_PANIC_ON_NMI,
740 .procname = "panic_on_unrecovered_nmi",
741 .data = &panic_on_unrecovered_nmi,
742 .maxlen = sizeof(int),
744 .proc_handler = &proc_dointvec,
747 .ctl_name = CTL_UNNUMBERED,
748 .procname = "panic_on_io_nmi",
749 .data = &panic_on_io_nmi,
750 .maxlen = sizeof(int),
752 .proc_handler = &proc_dointvec,
755 .ctl_name = KERN_BOOTLOADER_TYPE,
756 .procname = "bootloader_type",
757 .data = &bootloader_type,
758 .maxlen = sizeof (int),
760 .proc_handler = &proc_dointvec,
763 .ctl_name = CTL_UNNUMBERED,
764 .procname = "bootloader_version",
765 .data = &bootloader_version,
766 .maxlen = sizeof (int),
768 .proc_handler = &proc_dointvec,
771 .ctl_name = CTL_UNNUMBERED,
772 .procname = "kstack_depth_to_print",
773 .data = &kstack_depth_to_print,
774 .maxlen = sizeof(int),
776 .proc_handler = &proc_dointvec,
779 .ctl_name = CTL_UNNUMBERED,
780 .procname = "io_delay_type",
781 .data = &io_delay_type,
782 .maxlen = sizeof(int),
784 .proc_handler = &proc_dointvec,
787 #if defined(CONFIG_MMU)
789 .ctl_name = KERN_RANDOMIZE,
790 .procname = "randomize_va_space",
791 .data = &randomize_va_space,
792 .maxlen = sizeof(int),
794 .proc_handler = &proc_dointvec,
797 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
799 .ctl_name = KERN_SPIN_RETRY,
800 .procname = "spin_retry",
802 .maxlen = sizeof (int),
804 .proc_handler = &proc_dointvec,
807 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
809 .procname = "acpi_video_flags",
810 .data = &acpi_realmode_flags,
811 .maxlen = sizeof (unsigned long),
813 .proc_handler = &proc_doulongvec_minmax,
818 .ctl_name = KERN_IA64_UNALIGNED,
819 .procname = "ignore-unaligned-usertrap",
820 .data = &no_unaligned_warning,
821 .maxlen = sizeof (int),
823 .proc_handler = &proc_dointvec,
826 .ctl_name = CTL_UNNUMBERED,
827 .procname = "unaligned-dump-stack",
828 .data = &unaligned_dump_stack,
829 .maxlen = sizeof (int),
831 .proc_handler = &proc_dointvec,
834 #ifdef CONFIG_DETECT_SOFTLOCKUP
836 .ctl_name = CTL_UNNUMBERED,
837 .procname = "softlockup_panic",
838 .data = &softlockup_panic,
839 .maxlen = sizeof(int),
841 .proc_handler = &proc_dointvec_minmax,
842 .strategy = &sysctl_intvec,
847 .ctl_name = CTL_UNNUMBERED,
848 .procname = "softlockup_thresh",
849 .data = &softlockup_thresh,
850 .maxlen = sizeof(int),
852 .proc_handler = &proc_dosoftlockup_thresh,
853 .strategy = &sysctl_intvec,
858 #ifdef CONFIG_DETECT_HUNG_TASK
860 .ctl_name = CTL_UNNUMBERED,
861 .procname = "hung_task_panic",
862 .data = &sysctl_hung_task_panic,
863 .maxlen = sizeof(int),
865 .proc_handler = &proc_dointvec_minmax,
866 .strategy = &sysctl_intvec,
871 .ctl_name = CTL_UNNUMBERED,
872 .procname = "hung_task_check_count",
873 .data = &sysctl_hung_task_check_count,
874 .maxlen = sizeof(unsigned long),
876 .proc_handler = &proc_doulongvec_minmax,
877 .strategy = &sysctl_intvec,
880 .ctl_name = CTL_UNNUMBERED,
881 .procname = "hung_task_timeout_secs",
882 .data = &sysctl_hung_task_timeout_secs,
883 .maxlen = sizeof(unsigned long),
885 .proc_handler = &proc_dohung_task_timeout_secs,
886 .strategy = &sysctl_intvec,
889 .ctl_name = CTL_UNNUMBERED,
890 .procname = "hung_task_warnings",
891 .data = &sysctl_hung_task_warnings,
892 .maxlen = sizeof(unsigned long),
894 .proc_handler = &proc_doulongvec_minmax,
895 .strategy = &sysctl_intvec,
900 .ctl_name = KERN_COMPAT_LOG,
901 .procname = "compat-log",
903 .maxlen = sizeof (int),
905 .proc_handler = &proc_dointvec,
908 #ifdef CONFIG_RT_MUTEXES
910 .ctl_name = KERN_MAX_LOCK_DEPTH,
911 .procname = "max_lock_depth",
912 .data = &max_lock_depth,
913 .maxlen = sizeof(int),
915 .proc_handler = &proc_dointvec,
919 .ctl_name = CTL_UNNUMBERED,
920 .procname = "poweroff_cmd",
921 .data = &poweroff_cmd,
922 .maxlen = POWEROFF_CMD_PATH_LEN,
924 .proc_handler = &proc_dostring,
925 .strategy = &sysctl_string,
929 .ctl_name = CTL_UNNUMBERED,
932 .child = key_sysctls,
935 #ifdef CONFIG_RCU_TORTURE_TEST
937 .ctl_name = CTL_UNNUMBERED,
938 .procname = "rcutorture_runnable",
939 .data = &rcutorture_runnable,
940 .maxlen = sizeof(int),
942 .proc_handler = &proc_dointvec,
945 #ifdef CONFIG_SLOW_WORK
947 .ctl_name = CTL_UNNUMBERED,
948 .procname = "slow-work",
950 .child = slow_work_sysctls,
953 #ifdef CONFIG_PERF_COUNTERS
955 .ctl_name = CTL_UNNUMBERED,
956 .procname = "perf_counter_paranoid",
957 .data = &sysctl_perf_counter_paranoid,
958 .maxlen = sizeof(sysctl_perf_counter_paranoid),
960 .proc_handler = &proc_dointvec,
963 .ctl_name = CTL_UNNUMBERED,
964 .procname = "perf_counter_mlock_kb",
965 .data = &sysctl_perf_counter_mlock,
966 .maxlen = sizeof(sysctl_perf_counter_mlock),
968 .proc_handler = &proc_dointvec,
971 .ctl_name = CTL_UNNUMBERED,
972 .procname = "perf_counter_max_sample_rate",
973 .data = &sysctl_perf_counter_sample_rate,
974 .maxlen = sizeof(sysctl_perf_counter_sample_rate),
976 .proc_handler = &proc_dointvec,
979 #ifdef CONFIG_KMEMCHECK
981 .ctl_name = CTL_UNNUMBERED,
982 .procname = "kmemcheck",
983 .data = &kmemcheck_enabled,
984 .maxlen = sizeof(int),
986 .proc_handler = &proc_dointvec,
991 * NOTE: do not add new entries to this table unless you have read
992 * Documentation/sysctl/ctl_unnumbered.txt
997 static struct ctl_table vm_table[] = {
999 .ctl_name = VM_OVERCOMMIT_MEMORY,
1000 .procname = "overcommit_memory",
1001 .data = &sysctl_overcommit_memory,
1002 .maxlen = sizeof(sysctl_overcommit_memory),
1004 .proc_handler = &proc_dointvec,
1007 .ctl_name = VM_PANIC_ON_OOM,
1008 .procname = "panic_on_oom",
1009 .data = &sysctl_panic_on_oom,
1010 .maxlen = sizeof(sysctl_panic_on_oom),
1012 .proc_handler = &proc_dointvec,
1015 .ctl_name = CTL_UNNUMBERED,
1016 .procname = "oom_kill_allocating_task",
1017 .data = &sysctl_oom_kill_allocating_task,
1018 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1020 .proc_handler = &proc_dointvec,
1023 .ctl_name = CTL_UNNUMBERED,
1024 .procname = "oom_dump_tasks",
1025 .data = &sysctl_oom_dump_tasks,
1026 .maxlen = sizeof(sysctl_oom_dump_tasks),
1028 .proc_handler = &proc_dointvec,
1031 .ctl_name = VM_OVERCOMMIT_RATIO,
1032 .procname = "overcommit_ratio",
1033 .data = &sysctl_overcommit_ratio,
1034 .maxlen = sizeof(sysctl_overcommit_ratio),
1036 .proc_handler = &proc_dointvec,
1039 .ctl_name = VM_PAGE_CLUSTER,
1040 .procname = "page-cluster",
1041 .data = &page_cluster,
1042 .maxlen = sizeof(int),
1044 .proc_handler = &proc_dointvec,
1047 .ctl_name = VM_DIRTY_BACKGROUND,
1048 .procname = "dirty_background_ratio",
1049 .data = &dirty_background_ratio,
1050 .maxlen = sizeof(dirty_background_ratio),
1052 .proc_handler = &dirty_background_ratio_handler,
1053 .strategy = &sysctl_intvec,
1055 .extra2 = &one_hundred,
1058 .ctl_name = CTL_UNNUMBERED,
1059 .procname = "dirty_background_bytes",
1060 .data = &dirty_background_bytes,
1061 .maxlen = sizeof(dirty_background_bytes),
1063 .proc_handler = &dirty_background_bytes_handler,
1064 .strategy = &sysctl_intvec,
1068 .ctl_name = VM_DIRTY_RATIO,
1069 .procname = "dirty_ratio",
1070 .data = &vm_dirty_ratio,
1071 .maxlen = sizeof(vm_dirty_ratio),
1073 .proc_handler = &dirty_ratio_handler,
1074 .strategy = &sysctl_intvec,
1076 .extra2 = &one_hundred,
1079 .ctl_name = CTL_UNNUMBERED,
1080 .procname = "dirty_bytes",
1081 .data = &vm_dirty_bytes,
1082 .maxlen = sizeof(vm_dirty_bytes),
1084 .proc_handler = &dirty_bytes_handler,
1085 .strategy = &sysctl_intvec,
1086 .extra1 = &dirty_bytes_min,
1089 .procname = "dirty_writeback_centisecs",
1090 .data = &dirty_writeback_interval,
1091 .maxlen = sizeof(dirty_writeback_interval),
1093 .proc_handler = &dirty_writeback_centisecs_handler,
1096 .procname = "dirty_expire_centisecs",
1097 .data = &dirty_expire_interval,
1098 .maxlen = sizeof(dirty_expire_interval),
1100 .proc_handler = &proc_dointvec,
1103 .ctl_name = VM_NR_PDFLUSH_THREADS,
1104 .procname = "nr_pdflush_threads",
1105 .data = &nr_pdflush_threads,
1106 .maxlen = sizeof nr_pdflush_threads,
1107 .mode = 0444 /* read-only*/,
1108 .proc_handler = &proc_dointvec,
1111 .ctl_name = VM_SWAPPINESS,
1112 .procname = "swappiness",
1113 .data = &vm_swappiness,
1114 .maxlen = sizeof(vm_swappiness),
1116 .proc_handler = &proc_dointvec_minmax,
1117 .strategy = &sysctl_intvec,
1119 .extra2 = &one_hundred,
1121 #ifdef CONFIG_HUGETLB_PAGE
1123 .procname = "nr_hugepages",
1125 .maxlen = sizeof(unsigned long),
1127 .proc_handler = &hugetlb_sysctl_handler,
1128 .extra1 = (void *)&hugetlb_zero,
1129 .extra2 = (void *)&hugetlb_infinity,
1132 .ctl_name = VM_HUGETLB_GROUP,
1133 .procname = "hugetlb_shm_group",
1134 .data = &sysctl_hugetlb_shm_group,
1135 .maxlen = sizeof(gid_t),
1137 .proc_handler = &proc_dointvec,
1140 .ctl_name = CTL_UNNUMBERED,
1141 .procname = "hugepages_treat_as_movable",
1142 .data = &hugepages_treat_as_movable,
1143 .maxlen = sizeof(int),
1145 .proc_handler = &hugetlb_treat_movable_handler,
1148 .ctl_name = CTL_UNNUMBERED,
1149 .procname = "nr_overcommit_hugepages",
1151 .maxlen = sizeof(unsigned long),
1153 .proc_handler = &hugetlb_overcommit_handler,
1154 .extra1 = (void *)&hugetlb_zero,
1155 .extra2 = (void *)&hugetlb_infinity,
1159 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1160 .procname = "lowmem_reserve_ratio",
1161 .data = &sysctl_lowmem_reserve_ratio,
1162 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1164 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1165 .strategy = &sysctl_intvec,
1168 .ctl_name = VM_DROP_PAGECACHE,
1169 .procname = "drop_caches",
1170 .data = &sysctl_drop_caches,
1171 .maxlen = sizeof(int),
1173 .proc_handler = drop_caches_sysctl_handler,
1174 .strategy = &sysctl_intvec,
1177 .ctl_name = VM_MIN_FREE_KBYTES,
1178 .procname = "min_free_kbytes",
1179 .data = &min_free_kbytes,
1180 .maxlen = sizeof(min_free_kbytes),
1182 .proc_handler = &min_free_kbytes_sysctl_handler,
1183 .strategy = &sysctl_intvec,
1187 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1188 .procname = "percpu_pagelist_fraction",
1189 .data = &percpu_pagelist_fraction,
1190 .maxlen = sizeof(percpu_pagelist_fraction),
1192 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1193 .strategy = &sysctl_intvec,
1194 .extra1 = &min_percpu_pagelist_fract,
1198 .ctl_name = VM_MAX_MAP_COUNT,
1199 .procname = "max_map_count",
1200 .data = &sysctl_max_map_count,
1201 .maxlen = sizeof(sysctl_max_map_count),
1203 .proc_handler = &proc_dointvec
1207 .ctl_name = CTL_UNNUMBERED,
1208 .procname = "nr_trim_pages",
1209 .data = &sysctl_nr_trim_pages,
1210 .maxlen = sizeof(sysctl_nr_trim_pages),
1212 .proc_handler = &proc_dointvec_minmax,
1213 .strategy = &sysctl_intvec,
1218 .ctl_name = VM_LAPTOP_MODE,
1219 .procname = "laptop_mode",
1220 .data = &laptop_mode,
1221 .maxlen = sizeof(laptop_mode),
1223 .proc_handler = &proc_dointvec_jiffies,
1224 .strategy = &sysctl_jiffies,
1227 .ctl_name = VM_BLOCK_DUMP,
1228 .procname = "block_dump",
1229 .data = &block_dump,
1230 .maxlen = sizeof(block_dump),
1232 .proc_handler = &proc_dointvec,
1233 .strategy = &sysctl_intvec,
1237 .ctl_name = VM_VFS_CACHE_PRESSURE,
1238 .procname = "vfs_cache_pressure",
1239 .data = &sysctl_vfs_cache_pressure,
1240 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1242 .proc_handler = &proc_dointvec,
1243 .strategy = &sysctl_intvec,
1246 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1248 .ctl_name = VM_LEGACY_VA_LAYOUT,
1249 .procname = "legacy_va_layout",
1250 .data = &sysctl_legacy_va_layout,
1251 .maxlen = sizeof(sysctl_legacy_va_layout),
1253 .proc_handler = &proc_dointvec,
1254 .strategy = &sysctl_intvec,
1260 .ctl_name = VM_ZONE_RECLAIM_MODE,
1261 .procname = "zone_reclaim_mode",
1262 .data = &zone_reclaim_mode,
1263 .maxlen = sizeof(zone_reclaim_mode),
1265 .proc_handler = &proc_dointvec,
1266 .strategy = &sysctl_intvec,
1270 .ctl_name = VM_MIN_UNMAPPED,
1271 .procname = "min_unmapped_ratio",
1272 .data = &sysctl_min_unmapped_ratio,
1273 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1275 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1276 .strategy = &sysctl_intvec,
1278 .extra2 = &one_hundred,
1281 .ctl_name = VM_MIN_SLAB,
1282 .procname = "min_slab_ratio",
1283 .data = &sysctl_min_slab_ratio,
1284 .maxlen = sizeof(sysctl_min_slab_ratio),
1286 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1287 .strategy = &sysctl_intvec,
1289 .extra2 = &one_hundred,
1294 .ctl_name = CTL_UNNUMBERED,
1295 .procname = "stat_interval",
1296 .data = &sysctl_stat_interval,
1297 .maxlen = sizeof(sysctl_stat_interval),
1299 .proc_handler = &proc_dointvec_jiffies,
1300 .strategy = &sysctl_jiffies,
1304 .ctl_name = CTL_UNNUMBERED,
1305 .procname = "mmap_min_addr",
1306 .data = &mmap_min_addr,
1307 .maxlen = sizeof(unsigned long),
1309 .proc_handler = &proc_doulongvec_minmax,
1313 .ctl_name = CTL_UNNUMBERED,
1314 .procname = "numa_zonelist_order",
1315 .data = &numa_zonelist_order,
1316 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1318 .proc_handler = &numa_zonelist_order_handler,
1319 .strategy = &sysctl_string,
1322 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1323 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1325 .ctl_name = VM_VDSO_ENABLED,
1326 .procname = "vdso_enabled",
1327 .data = &vdso_enabled,
1328 .maxlen = sizeof(vdso_enabled),
1330 .proc_handler = &proc_dointvec,
1331 .strategy = &sysctl_intvec,
1335 #ifdef CONFIG_HIGHMEM
1337 .ctl_name = CTL_UNNUMBERED,
1338 .procname = "highmem_is_dirtyable",
1339 .data = &vm_highmem_is_dirtyable,
1340 .maxlen = sizeof(vm_highmem_is_dirtyable),
1342 .proc_handler = &proc_dointvec_minmax,
1343 .strategy = &sysctl_intvec,
1349 .ctl_name = CTL_UNNUMBERED,
1350 .procname = "scan_unevictable_pages",
1351 .data = &scan_unevictable_pages,
1352 .maxlen = sizeof(scan_unevictable_pages),
1354 .proc_handler = &scan_unevictable_handler,
1357 * NOTE: do not add new entries to this table unless you have read
1358 * Documentation/sysctl/ctl_unnumbered.txt
1363 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1364 static struct ctl_table binfmt_misc_table[] = {
1369 static struct ctl_table fs_table[] = {
1371 .ctl_name = FS_NRINODE,
1372 .procname = "inode-nr",
1373 .data = &inodes_stat,
1374 .maxlen = 2*sizeof(int),
1376 .proc_handler = &proc_dointvec,
1379 .ctl_name = FS_STATINODE,
1380 .procname = "inode-state",
1381 .data = &inodes_stat,
1382 .maxlen = 7*sizeof(int),
1384 .proc_handler = &proc_dointvec,
1387 .procname = "file-nr",
1388 .data = &files_stat,
1389 .maxlen = 3*sizeof(int),
1391 .proc_handler = &proc_nr_files,
1394 .ctl_name = FS_MAXFILE,
1395 .procname = "file-max",
1396 .data = &files_stat.max_files,
1397 .maxlen = sizeof(int),
1399 .proc_handler = &proc_dointvec,
1402 .ctl_name = CTL_UNNUMBERED,
1403 .procname = "nr_open",
1404 .data = &sysctl_nr_open,
1405 .maxlen = sizeof(int),
1407 .proc_handler = &proc_dointvec_minmax,
1408 .extra1 = &sysctl_nr_open_min,
1409 .extra2 = &sysctl_nr_open_max,
1412 .ctl_name = FS_DENTRY,
1413 .procname = "dentry-state",
1414 .data = &dentry_stat,
1415 .maxlen = 6*sizeof(int),
1417 .proc_handler = &proc_dointvec,
1420 .ctl_name = FS_OVERFLOWUID,
1421 .procname = "overflowuid",
1422 .data = &fs_overflowuid,
1423 .maxlen = sizeof(int),
1425 .proc_handler = &proc_dointvec_minmax,
1426 .strategy = &sysctl_intvec,
1427 .extra1 = &minolduid,
1428 .extra2 = &maxolduid,
1431 .ctl_name = FS_OVERFLOWGID,
1432 .procname = "overflowgid",
1433 .data = &fs_overflowgid,
1434 .maxlen = sizeof(int),
1436 .proc_handler = &proc_dointvec_minmax,
1437 .strategy = &sysctl_intvec,
1438 .extra1 = &minolduid,
1439 .extra2 = &maxolduid,
1441 #ifdef CONFIG_FILE_LOCKING
1443 .ctl_name = FS_LEASES,
1444 .procname = "leases-enable",
1445 .data = &leases_enable,
1446 .maxlen = sizeof(int),
1448 .proc_handler = &proc_dointvec,
1451 #ifdef CONFIG_DNOTIFY
1453 .ctl_name = FS_DIR_NOTIFY,
1454 .procname = "dir-notify-enable",
1455 .data = &dir_notify_enable,
1456 .maxlen = sizeof(int),
1458 .proc_handler = &proc_dointvec,
1462 #ifdef CONFIG_FILE_LOCKING
1464 .ctl_name = FS_LEASE_TIME,
1465 .procname = "lease-break-time",
1466 .data = &lease_break_time,
1467 .maxlen = sizeof(int),
1469 .proc_handler = &proc_dointvec,
1474 .procname = "aio-nr",
1476 .maxlen = sizeof(aio_nr),
1478 .proc_handler = &proc_doulongvec_minmax,
1481 .procname = "aio-max-nr",
1482 .data = &aio_max_nr,
1483 .maxlen = sizeof(aio_max_nr),
1485 .proc_handler = &proc_doulongvec_minmax,
1487 #endif /* CONFIG_AIO */
1488 #ifdef CONFIG_INOTIFY_USER
1490 .ctl_name = FS_INOTIFY,
1491 .procname = "inotify",
1493 .child = inotify_table,
1498 .procname = "epoll",
1500 .child = epoll_table,
1505 .ctl_name = KERN_SETUID_DUMPABLE,
1506 .procname = "suid_dumpable",
1507 .data = &suid_dumpable,
1508 .maxlen = sizeof(int),
1510 .proc_handler = &proc_dointvec_minmax,
1511 .strategy = &sysctl_intvec,
1515 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1517 .ctl_name = CTL_UNNUMBERED,
1518 .procname = "binfmt_misc",
1520 .child = binfmt_misc_table,
1524 * NOTE: do not add new entries to this table unless you have read
1525 * Documentation/sysctl/ctl_unnumbered.txt
1530 static struct ctl_table debug_table[] = {
1531 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1533 .ctl_name = CTL_UNNUMBERED,
1534 .procname = "exception-trace",
1535 .data = &show_unhandled_signals,
1536 .maxlen = sizeof(int),
1538 .proc_handler = proc_dointvec
1544 static struct ctl_table dev_table[] = {
1548 static DEFINE_SPINLOCK(sysctl_lock);
1550 /* called under sysctl_lock */
1551 static int use_table(struct ctl_table_header *p)
1553 if (unlikely(p->unregistering))
1559 /* called under sysctl_lock */
1560 static void unuse_table(struct ctl_table_header *p)
1563 if (unlikely(p->unregistering))
1564 complete(p->unregistering);
1567 /* called under sysctl_lock, will reacquire if has to wait */
1568 static void start_unregistering(struct ctl_table_header *p)
1571 * if p->used is 0, nobody will ever touch that entry again;
1572 * we'll eliminate all paths to it before dropping sysctl_lock
1574 if (unlikely(p->used)) {
1575 struct completion wait;
1576 init_completion(&wait);
1577 p->unregistering = &wait;
1578 spin_unlock(&sysctl_lock);
1579 wait_for_completion(&wait);
1580 spin_lock(&sysctl_lock);
1582 /* anything non-NULL; we'll never dereference it */
1583 p->unregistering = ERR_PTR(-EINVAL);
1586 * do not remove from the list until nobody holds it; walking the
1587 * list in do_sysctl() relies on that.
1589 list_del_init(&p->ctl_entry);
1592 void sysctl_head_get(struct ctl_table_header *head)
1594 spin_lock(&sysctl_lock);
1596 spin_unlock(&sysctl_lock);
1599 void sysctl_head_put(struct ctl_table_header *head)
1601 spin_lock(&sysctl_lock);
1604 spin_unlock(&sysctl_lock);
1607 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1611 spin_lock(&sysctl_lock);
1612 if (!use_table(head))
1613 head = ERR_PTR(-ENOENT);
1614 spin_unlock(&sysctl_lock);
1618 void sysctl_head_finish(struct ctl_table_header *head)
1622 spin_lock(&sysctl_lock);
1624 spin_unlock(&sysctl_lock);
1627 static struct ctl_table_set *
1628 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1630 struct ctl_table_set *set = &root->default_set;
1632 set = root->lookup(root, namespaces);
1636 static struct list_head *
1637 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1639 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1643 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1644 struct ctl_table_header *prev)
1646 struct ctl_table_root *root;
1647 struct list_head *header_list;
1648 struct ctl_table_header *head;
1649 struct list_head *tmp;
1651 spin_lock(&sysctl_lock);
1654 tmp = &prev->ctl_entry;
1658 tmp = &root_table_header.ctl_entry;
1660 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1662 if (!use_table(head))
1664 spin_unlock(&sysctl_lock);
1669 header_list = lookup_header_list(root, namespaces);
1670 if (tmp != header_list)
1674 root = list_entry(root->root_list.next,
1675 struct ctl_table_root, root_list);
1676 if (root == &sysctl_table_root)
1678 header_list = lookup_header_list(root, namespaces);
1679 } while (list_empty(header_list));
1680 tmp = header_list->next;
1683 spin_unlock(&sysctl_lock);
1687 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1689 return __sysctl_head_next(current->nsproxy, prev);
1692 void register_sysctl_root(struct ctl_table_root *root)
1694 spin_lock(&sysctl_lock);
1695 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1696 spin_unlock(&sysctl_lock);
1699 #ifdef CONFIG_SYSCTL_SYSCALL
1700 /* Perform the actual read/write of a sysctl table entry. */
1701 static int do_sysctl_strategy(struct ctl_table_root *root,
1702 struct ctl_table *table,
1703 void __user *oldval, size_t __user *oldlenp,
1704 void __user *newval, size_t newlen)
1712 if (sysctl_perm(root, table, op))
1715 if (table->strategy) {
1716 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1723 /* If there is no strategy routine, or if the strategy returns
1724 * zero, proceed with automatic r/w */
1725 if (table->data && table->maxlen) {
1726 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1733 static int parse_table(int __user *name, int nlen,
1734 void __user *oldval, size_t __user *oldlenp,
1735 void __user *newval, size_t newlen,
1736 struct ctl_table_root *root,
1737 struct ctl_table *table)
1743 if (get_user(n, name))
1745 for ( ; table->ctl_name || table->procname; table++) {
1746 if (!table->ctl_name)
1748 if (n == table->ctl_name) {
1751 if (sysctl_perm(root, table, MAY_EXEC))
1755 table = table->child;
1758 error = do_sysctl_strategy(root, table,
1767 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1768 void __user *newval, size_t newlen)
1770 struct ctl_table_header *head;
1771 int error = -ENOTDIR;
1773 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1777 if (!oldlenp || get_user(old_len, oldlenp))
1781 for (head = sysctl_head_next(NULL); head;
1782 head = sysctl_head_next(head)) {
1783 error = parse_table(name, nlen, oldval, oldlenp,
1785 head->root, head->ctl_table);
1786 if (error != -ENOTDIR) {
1787 sysctl_head_finish(head);
1794 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1796 struct __sysctl_args tmp;
1799 if (copy_from_user(&tmp, args, sizeof(tmp)))
1802 error = deprecated_sysctl_warning(&tmp);
1807 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1808 tmp.newval, tmp.newlen);
1813 #endif /* CONFIG_SYSCTL_SYSCALL */
1816 * sysctl_perm does NOT grant the superuser all rights automatically, because
1817 * some sysctl variables are readonly even to root.
1820 static int test_perm(int mode, int op)
1822 if (!current_euid())
1824 else if (in_egroup_p(0))
1826 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1831 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1836 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1840 if (root->permissions)
1841 mode = root->permissions(root, current->nsproxy, table);
1845 return test_perm(mode, op);
1848 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1850 for (; table->ctl_name || table->procname; table++) {
1851 table->parent = parent;
1853 sysctl_set_parent(table, table->child);
1857 static __init int sysctl_init(void)
1859 sysctl_set_parent(NULL, root_table);
1860 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1863 err = sysctl_check_table(current->nsproxy, root_table);
1869 core_initcall(sysctl_init);
1871 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1872 struct ctl_table *table)
1874 struct ctl_table *p;
1875 const char *s = branch->procname;
1877 /* branch should have named subdirectory as its first element */
1878 if (!s || !branch->child)
1881 /* ... and nothing else */
1882 if (branch[1].procname || branch[1].ctl_name)
1885 /* table should contain subdirectory with the same name */
1886 for (p = table; p->procname || p->ctl_name; p++) {
1889 if (p->procname && strcmp(p->procname, s) == 0)
1895 /* see if attaching q to p would be an improvement */
1896 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1898 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1899 struct ctl_table *next;
1901 int not_in_parent = !p->attached_by;
1903 while ((next = is_branch_in(by, to)) != NULL) {
1904 if (by == q->attached_by)
1906 if (to == p->attached_by)
1912 if (is_better && not_in_parent) {
1913 q->attached_by = by;
1914 q->attached_to = to;
1920 * __register_sysctl_paths - register a sysctl hierarchy
1921 * @root: List of sysctl headers to register on
1922 * @namespaces: Data to compute which lists of sysctl entries are visible
1923 * @path: The path to the directory the sysctl table is in.
1924 * @table: the top-level table structure
1926 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1927 * array. A completely 0 filled entry terminates the table.
1929 * The members of the &struct ctl_table structure are used as follows:
1931 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1932 * must be unique within that level of sysctl
1934 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1935 * enter a sysctl file
1937 * data - a pointer to data for use by proc_handler
1939 * maxlen - the maximum size in bytes of the data
1941 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1943 * child - a pointer to the child sysctl table if this entry is a directory, or
1946 * proc_handler - the text handler routine (described below)
1948 * strategy - the strategy routine (described below)
1950 * de - for internal use by the sysctl routines
1952 * extra1, extra2 - extra pointers usable by the proc handler routines
1954 * Leaf nodes in the sysctl tree will be represented by a single file
1955 * under /proc; non-leaf nodes will be represented by directories.
1957 * sysctl(2) can automatically manage read and write requests through
1958 * the sysctl table. The data and maxlen fields of the ctl_table
1959 * struct enable minimal validation of the values being written to be
1960 * performed, and the mode field allows minimal authentication.
1962 * More sophisticated management can be enabled by the provision of a
1963 * strategy routine with the table entry. This will be called before
1964 * any automatic read or write of the data is performed.
1966 * The strategy routine may return
1968 * < 0 - Error occurred (error is passed to user process)
1970 * 0 - OK - proceed with automatic read or write.
1972 * > 0 - OK - read or write has been done by the strategy routine, so
1973 * return immediately.
1975 * There must be a proc_handler routine for any terminal nodes
1976 * mirrored under /proc/sys (non-terminals are handled by a built-in
1977 * directory handler). Several default handlers are available to
1978 * cover common cases -
1980 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1981 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1982 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1984 * It is the handler's job to read the input buffer from user memory
1985 * and process it. The handler should return 0 on success.
1987 * This routine returns %NULL on a failure to register, and a pointer
1988 * to the table header on success.
1990 struct ctl_table_header *__register_sysctl_paths(
1991 struct ctl_table_root *root,
1992 struct nsproxy *namespaces,
1993 const struct ctl_path *path, struct ctl_table *table)
1995 struct ctl_table_header *header;
1996 struct ctl_table *new, **prevp;
1997 unsigned int n, npath;
1998 struct ctl_table_set *set;
2000 /* Count the path components */
2001 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2005 * For each path component, allocate a 2-element ctl_table array.
2006 * The first array element will be filled with the sysctl entry
2007 * for this, the second will be the sentinel (ctl_name == 0).
2009 * We allocate everything in one go so that we don't have to
2010 * worry about freeing additional memory in unregister_sysctl_table.
2012 header = kzalloc(sizeof(struct ctl_table_header) +
2013 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2017 new = (struct ctl_table *) (header + 1);
2019 /* Now connect the dots */
2020 prevp = &header->ctl_table;
2021 for (n = 0; n < npath; ++n, ++path) {
2022 /* Copy the procname */
2023 new->procname = path->procname;
2024 new->ctl_name = path->ctl_name;
2028 prevp = &new->child;
2033 header->ctl_table_arg = table;
2035 INIT_LIST_HEAD(&header->ctl_entry);
2037 header->unregistering = NULL;
2038 header->root = root;
2039 sysctl_set_parent(NULL, header->ctl_table);
2041 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2042 if (sysctl_check_table(namespaces, header->ctl_table)) {
2047 spin_lock(&sysctl_lock);
2048 header->set = lookup_header_set(root, namespaces);
2049 header->attached_by = header->ctl_table;
2050 header->attached_to = root_table;
2051 header->parent = &root_table_header;
2052 for (set = header->set; set; set = set->parent) {
2053 struct ctl_table_header *p;
2054 list_for_each_entry(p, &set->list, ctl_entry) {
2055 if (p->unregistering)
2057 try_attach(p, header);
2060 header->parent->count++;
2061 list_add_tail(&header->ctl_entry, &header->set->list);
2062 spin_unlock(&sysctl_lock);
2068 * register_sysctl_table_path - register a sysctl table hierarchy
2069 * @path: The path to the directory the sysctl table is in.
2070 * @table: the top-level table structure
2072 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2073 * array. A completely 0 filled entry terminates the table.
2075 * See __register_sysctl_paths for more details.
2077 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2078 struct ctl_table *table)
2080 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2085 * register_sysctl_table - register a sysctl table hierarchy
2086 * @table: the top-level table structure
2088 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2089 * array. A completely 0 filled entry terminates the table.
2091 * See register_sysctl_paths for more details.
2093 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2095 static const struct ctl_path null_path[] = { {} };
2097 return register_sysctl_paths(null_path, table);
2101 * unregister_sysctl_table - unregister a sysctl table hierarchy
2102 * @header: the header returned from register_sysctl_table
2104 * Unregisters the sysctl table and all children. proc entries may not
2105 * actually be removed until they are no longer used by anyone.
2107 void unregister_sysctl_table(struct ctl_table_header * header)
2114 spin_lock(&sysctl_lock);
2115 start_unregistering(header);
2116 if (!--header->parent->count) {
2118 kfree(header->parent);
2120 if (!--header->count)
2122 spin_unlock(&sysctl_lock);
2125 int sysctl_is_seen(struct ctl_table_header *p)
2127 struct ctl_table_set *set = p->set;
2129 spin_lock(&sysctl_lock);
2130 if (p->unregistering)
2132 else if (!set->is_seen)
2135 res = set->is_seen(set);
2136 spin_unlock(&sysctl_lock);
2140 void setup_sysctl_set(struct ctl_table_set *p,
2141 struct ctl_table_set *parent,
2142 int (*is_seen)(struct ctl_table_set *))
2144 INIT_LIST_HEAD(&p->list);
2145 p->parent = parent ? parent : &sysctl_table_root.default_set;
2146 p->is_seen = is_seen;
2149 #else /* !CONFIG_SYSCTL */
2150 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2155 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2156 struct ctl_table *table)
2161 void unregister_sysctl_table(struct ctl_table_header * table)
2165 void setup_sysctl_set(struct ctl_table_set *p,
2166 struct ctl_table_set *parent,
2167 int (*is_seen)(struct ctl_table_set *))
2171 void sysctl_head_put(struct ctl_table_header *head)
2175 #endif /* CONFIG_SYSCTL */
2181 #ifdef CONFIG_PROC_SYSCTL
2183 static int _proc_do_string(void* data, int maxlen, int write,
2184 struct file *filp, void __user *buffer,
2185 size_t *lenp, loff_t *ppos)
2191 if (!data || !maxlen || !*lenp) {
2199 while (len < *lenp) {
2200 if (get_user(c, p++))
2202 if (c == 0 || c == '\n')
2208 if(copy_from_user(data, buffer, len))
2210 ((char *) data)[len] = 0;
2228 if(copy_to_user(buffer, data, len))
2231 if(put_user('\n', ((char __user *) buffer) + len))
2242 * proc_dostring - read a string sysctl
2243 * @table: the sysctl table
2244 * @write: %TRUE if this is a write to the sysctl file
2245 * @filp: the file structure
2246 * @buffer: the user buffer
2247 * @lenp: the size of the user buffer
2248 * @ppos: file position
2250 * Reads/writes a string from/to the user buffer. If the kernel
2251 * buffer provided is not large enough to hold the string, the
2252 * string is truncated. The copied string is %NULL-terminated.
2253 * If the string is being read by the user process, it is copied
2254 * and a newline '\n' is added. It is truncated if the buffer is
2257 * Returns 0 on success.
2259 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2260 void __user *buffer, size_t *lenp, loff_t *ppos)
2262 return _proc_do_string(table->data, table->maxlen, write, filp,
2263 buffer, lenp, ppos);
2267 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2269 int write, void *data)
2272 *valp = *negp ? -*lvalp : *lvalp;
2277 *lvalp = (unsigned long)-val;
2280 *lvalp = (unsigned long)val;
2286 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2287 int write, struct file *filp, void __user *buffer,
2288 size_t *lenp, loff_t *ppos,
2289 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2290 int write, void *data),
2293 #define TMPBUFLEN 21
2294 int *i, vleft, first = 1, neg;
2298 char buf[TMPBUFLEN], *p;
2299 char __user *s = buffer;
2301 if (!tbl_data || !table->maxlen || !*lenp ||
2302 (*ppos && !write)) {
2307 i = (int *) tbl_data;
2308 vleft = table->maxlen / sizeof(*i);
2312 conv = do_proc_dointvec_conv;
2314 for (; left && vleft--; i++, first=0) {
2329 if (len > sizeof(buf) - 1)
2330 len = sizeof(buf) - 1;
2331 if (copy_from_user(buf, s, len))
2335 if (*p == '-' && left > 1) {
2339 if (*p < '0' || *p > '9')
2342 lval = simple_strtoul(p, &p, 0);
2345 if ((len < left) && *p && !isspace(*p))
2350 if (conv(&neg, &lval, i, 1, data))
2357 if (conv(&neg, &lval, i, 0, data))
2360 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2364 if(copy_to_user(s, buf, len))
2371 if (!write && !first && left) {
2372 if(put_user('\n', s))
2379 if (get_user(c, s++))
2394 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2395 void __user *buffer, size_t *lenp, loff_t *ppos,
2396 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2397 int write, void *data),
2400 return __do_proc_dointvec(table->data, table, write, filp,
2401 buffer, lenp, ppos, conv, data);
2405 * proc_dointvec - read a vector of integers
2406 * @table: the sysctl table
2407 * @write: %TRUE if this is a write to the sysctl file
2408 * @filp: the file structure
2409 * @buffer: the user buffer
2410 * @lenp: the size of the user buffer
2411 * @ppos: file position
2413 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2414 * values from/to the user buffer, treated as an ASCII string.
2416 * Returns 0 on success.
2418 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2419 void __user *buffer, size_t *lenp, loff_t *ppos)
2421 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2426 * Taint values can only be increased
2427 * This means we can safely use a temporary.
2429 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2430 void __user *buffer, size_t *lenp, loff_t *ppos)
2433 unsigned long tmptaint = get_taint();
2436 if (write && !capable(CAP_SYS_ADMIN))
2441 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2447 * Poor man's atomic or. Not worth adding a primitive
2448 * to everyone's atomic.h for this
2451 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2452 if ((tmptaint >> i) & 1)
2460 struct do_proc_dointvec_minmax_conv_param {
2465 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2467 int write, void *data)
2469 struct do_proc_dointvec_minmax_conv_param *param = data;
2471 int val = *negp ? -*lvalp : *lvalp;
2472 if ((param->min && *param->min > val) ||
2473 (param->max && *param->max < val))
2480 *lvalp = (unsigned long)-val;
2483 *lvalp = (unsigned long)val;
2490 * proc_dointvec_minmax - read a vector of integers with min/max values
2491 * @table: the sysctl table
2492 * @write: %TRUE if this is a write to the sysctl file
2493 * @filp: the file structure
2494 * @buffer: the user buffer
2495 * @lenp: the size of the user buffer
2496 * @ppos: file position
2498 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2499 * values from/to the user buffer, treated as an ASCII string.
2501 * This routine will ensure the values are within the range specified by
2502 * table->extra1 (min) and table->extra2 (max).
2504 * Returns 0 on success.
2506 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2507 void __user *buffer, size_t *lenp, loff_t *ppos)
2509 struct do_proc_dointvec_minmax_conv_param param = {
2510 .min = (int *) table->extra1,
2511 .max = (int *) table->extra2,
2513 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2514 do_proc_dointvec_minmax_conv, ¶m);
2517 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2519 void __user *buffer,
2520 size_t *lenp, loff_t *ppos,
2521 unsigned long convmul,
2522 unsigned long convdiv)
2524 #define TMPBUFLEN 21
2525 unsigned long *i, *min, *max, val;
2526 int vleft, first=1, neg;
2528 char buf[TMPBUFLEN], *p;
2529 char __user *s = buffer;
2531 if (!data || !table->maxlen || !*lenp ||
2532 (*ppos && !write)) {
2537 i = (unsigned long *) data;
2538 min = (unsigned long *) table->extra1;
2539 max = (unsigned long *) table->extra2;
2540 vleft = table->maxlen / sizeof(unsigned long);
2543 for (; left && vleft--; i++, min++, max++, first=0) {
2558 if (len > TMPBUFLEN-1)
2560 if (copy_from_user(buf, s, len))
2564 if (*p == '-' && left > 1) {
2568 if (*p < '0' || *p > '9')
2570 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2572 if ((len < left) && *p && !isspace(*p))
2581 if ((min && val < *min) || (max && val > *max))
2588 sprintf(p, "%lu", convdiv * (*i) / convmul);
2592 if(copy_to_user(s, buf, len))
2599 if (!write && !first && left) {
2600 if(put_user('\n', s))
2607 if (get_user(c, s++))
2622 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2624 void __user *buffer,
2625 size_t *lenp, loff_t *ppos,
2626 unsigned long convmul,
2627 unsigned long convdiv)
2629 return __do_proc_doulongvec_minmax(table->data, table, write,
2630 filp, buffer, lenp, ppos, convmul, convdiv);
2634 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2635 * @table: the sysctl table
2636 * @write: %TRUE if this is a write to the sysctl file
2637 * @filp: the file structure
2638 * @buffer: the user buffer
2639 * @lenp: the size of the user buffer
2640 * @ppos: file position
2642 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2643 * values from/to the user buffer, treated as an ASCII string.
2645 * This routine will ensure the values are within the range specified by
2646 * table->extra1 (min) and table->extra2 (max).
2648 * Returns 0 on success.
2650 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2651 void __user *buffer, size_t *lenp, loff_t *ppos)
2653 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2657 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2658 * @table: the sysctl table
2659 * @write: %TRUE if this is a write to the sysctl file
2660 * @filp: the file structure
2661 * @buffer: the user buffer
2662 * @lenp: the size of the user buffer
2663 * @ppos: file position
2665 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2666 * values from/to the user buffer, treated as an ASCII string. The values
2667 * are treated as milliseconds, and converted to jiffies when they are stored.
2669 * This routine will ensure the values are within the range specified by
2670 * table->extra1 (min) and table->extra2 (max).
2672 * Returns 0 on success.
2674 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2676 void __user *buffer,
2677 size_t *lenp, loff_t *ppos)
2679 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2680 lenp, ppos, HZ, 1000l);
2684 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2686 int write, void *data)
2689 if (*lvalp > LONG_MAX / HZ)
2691 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2697 lval = (unsigned long)-val;
2700 lval = (unsigned long)val;
2707 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2709 int write, void *data)
2712 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2714 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2720 lval = (unsigned long)-val;
2723 lval = (unsigned long)val;
2725 *lvalp = jiffies_to_clock_t(lval);
2730 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2732 int write, void *data)
2735 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2741 lval = (unsigned long)-val;
2744 lval = (unsigned long)val;
2746 *lvalp = jiffies_to_msecs(lval);
2752 * proc_dointvec_jiffies - read a vector of integers as seconds
2753 * @table: the sysctl table
2754 * @write: %TRUE if this is a write to the sysctl file
2755 * @filp: the file structure
2756 * @buffer: the user buffer
2757 * @lenp: the size of the user buffer
2758 * @ppos: file position
2760 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2761 * values from/to the user buffer, treated as an ASCII string.
2762 * The values read are assumed to be in seconds, and are converted into
2765 * Returns 0 on success.
2767 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2768 void __user *buffer, size_t *lenp, loff_t *ppos)
2770 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2771 do_proc_dointvec_jiffies_conv,NULL);
2775 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2776 * @table: the sysctl table
2777 * @write: %TRUE if this is a write to the sysctl file
2778 * @filp: the file structure
2779 * @buffer: the user buffer
2780 * @lenp: the size of the user buffer
2781 * @ppos: pointer to the file position
2783 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2784 * values from/to the user buffer, treated as an ASCII string.
2785 * The values read are assumed to be in 1/USER_HZ seconds, and
2786 * are converted into jiffies.
2788 * Returns 0 on success.
2790 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2791 void __user *buffer, size_t *lenp, loff_t *ppos)
2793 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2794 do_proc_dointvec_userhz_jiffies_conv,NULL);
2798 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2799 * @table: the sysctl table
2800 * @write: %TRUE if this is a write to the sysctl file
2801 * @filp: the file structure
2802 * @buffer: the user buffer
2803 * @lenp: the size of the user buffer
2804 * @ppos: file position
2805 * @ppos: the current position in the file
2807 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2808 * values from/to the user buffer, treated as an ASCII string.
2809 * The values read are assumed to be in 1/1000 seconds, and
2810 * are converted into jiffies.
2812 * Returns 0 on success.
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)
2817 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2818 do_proc_dointvec_ms_jiffies_conv, NULL);
2821 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2822 void __user *buffer, size_t *lenp, loff_t *ppos)
2824 struct pid *new_pid;
2828 tmp = pid_vnr(cad_pid);
2830 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2831 lenp, ppos, NULL, NULL);
2835 new_pid = find_get_pid(tmp);
2839 put_pid(xchg(&cad_pid, new_pid));
2843 #else /* CONFIG_PROC_FS */
2845 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2846 void __user *buffer, size_t *lenp, loff_t *ppos)
2851 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2852 void __user *buffer, size_t *lenp, loff_t *ppos)
2857 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2858 void __user *buffer, size_t *lenp, loff_t *ppos)
2863 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2864 void __user *buffer, size_t *lenp, loff_t *ppos)
2869 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2870 void __user *buffer, size_t *lenp, loff_t *ppos)
2875 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2876 void __user *buffer, size_t *lenp, loff_t *ppos)
2881 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2882 void __user *buffer, size_t *lenp, loff_t *ppos)
2887 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2889 void __user *buffer,
2890 size_t *lenp, loff_t *ppos)
2896 #endif /* CONFIG_PROC_FS */
2899 #ifdef CONFIG_SYSCTL_SYSCALL
2901 * General sysctl support routines
2904 /* The generic sysctl data routine (used if no strategy routine supplied) */
2905 int sysctl_data(struct ctl_table *table,
2906 void __user *oldval, size_t __user *oldlenp,
2907 void __user *newval, size_t newlen)
2911 /* Get out of I don't have a variable */
2912 if (!table->data || !table->maxlen)
2915 if (oldval && oldlenp) {
2916 if (get_user(len, oldlenp))
2919 if (len > table->maxlen)
2920 len = table->maxlen;
2921 if (copy_to_user(oldval, table->data, len))
2923 if (put_user(len, oldlenp))
2928 if (newval && newlen) {
2929 if (newlen > table->maxlen)
2930 newlen = table->maxlen;
2932 if (copy_from_user(table->data, newval, newlen))
2938 /* The generic string strategy routine: */
2939 int sysctl_string(struct ctl_table *table,
2940 void __user *oldval, size_t __user *oldlenp,
2941 void __user *newval, size_t newlen)
2943 if (!table->data || !table->maxlen)
2946 if (oldval && oldlenp) {
2948 if (get_user(bufsize, oldlenp))
2951 size_t len = strlen(table->data), copied;
2953 /* This shouldn't trigger for a well-formed sysctl */
2954 if (len > table->maxlen)
2955 len = table->maxlen;
2957 /* Copy up to a max of bufsize-1 bytes of the string */
2958 copied = (len >= bufsize) ? bufsize - 1 : len;
2960 if (copy_to_user(oldval, table->data, copied) ||
2961 put_user(0, (char __user *)(oldval + copied)))
2963 if (put_user(len, oldlenp))
2967 if (newval && newlen) {
2968 size_t len = newlen;
2969 if (len > table->maxlen)
2970 len = table->maxlen;
2971 if(copy_from_user(table->data, newval, len))
2973 if (len == table->maxlen)
2975 ((char *) table->data)[len] = 0;
2981 * This function makes sure that all of the integers in the vector
2982 * are between the minimum and maximum values given in the arrays
2983 * table->extra1 and table->extra2, respectively.
2985 int sysctl_intvec(struct ctl_table *table,
2986 void __user *oldval, size_t __user *oldlenp,
2987 void __user *newval, size_t newlen)
2990 if (newval && newlen) {
2991 int __user *vec = (int __user *) newval;
2992 int *min = (int *) table->extra1;
2993 int *max = (int *) table->extra2;
2997 if (newlen % sizeof(int) != 0)
3000 if (!table->extra1 && !table->extra2)
3003 if (newlen > table->maxlen)
3004 newlen = table->maxlen;
3005 length = newlen / sizeof(int);
3007 for (i = 0; i < length; i++) {
3009 if (get_user(value, vec + i))
3011 if (min && value < min[i])
3013 if (max && value > max[i])
3020 /* Strategy function to convert jiffies to seconds */
3021 int sysctl_jiffies(struct ctl_table *table,
3022 void __user *oldval, size_t __user *oldlenp,
3023 void __user *newval, size_t newlen)
3025 if (oldval && oldlenp) {
3028 if (get_user(olen, oldlenp))
3033 if (olen < sizeof(int))
3036 val = *(int *)(table->data) / HZ;
3037 if (put_user(val, (int __user *)oldval))
3039 if (put_user(sizeof(int), oldlenp))
3043 if (newval && newlen) {
3045 if (newlen != sizeof(int))
3047 if (get_user(new, (int __user *)newval))
3049 *(int *)(table->data) = new*HZ;
3054 /* Strategy function to convert jiffies to seconds */
3055 int sysctl_ms_jiffies(struct ctl_table *table,
3056 void __user *oldval, size_t __user *oldlenp,
3057 void __user *newval, size_t newlen)
3059 if (oldval && oldlenp) {
3062 if (get_user(olen, oldlenp))
3067 if (olen < sizeof(int))
3070 val = jiffies_to_msecs(*(int *)(table->data));
3071 if (put_user(val, (int __user *)oldval))
3073 if (put_user(sizeof(int), oldlenp))
3077 if (newval && newlen) {
3079 if (newlen != sizeof(int))
3081 if (get_user(new, (int __user *)newval))
3083 *(int *)(table->data) = msecs_to_jiffies(new);
3090 #else /* CONFIG_SYSCTL_SYSCALL */
3093 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3095 struct __sysctl_args tmp;
3098 if (copy_from_user(&tmp, args, sizeof(tmp)))
3101 error = deprecated_sysctl_warning(&tmp);
3103 /* If no error reading the parameters then just -ENOSYS ... */
3110 int sysctl_data(struct ctl_table *table,
3111 void __user *oldval, size_t __user *oldlenp,
3112 void __user *newval, size_t newlen)
3117 int sysctl_string(struct ctl_table *table,
3118 void __user *oldval, size_t __user *oldlenp,
3119 void __user *newval, size_t newlen)
3124 int sysctl_intvec(struct ctl_table *table,
3125 void __user *oldval, size_t __user *oldlenp,
3126 void __user *newval, size_t newlen)
3131 int sysctl_jiffies(struct ctl_table *table,
3132 void __user *oldval, size_t __user *oldlenp,
3133 void __user *newval, size_t newlen)
3138 int sysctl_ms_jiffies(struct ctl_table *table,
3139 void __user *oldval, size_t __user *oldlenp,
3140 void __user *newval, size_t newlen)
3145 #endif /* CONFIG_SYSCTL_SYSCALL */
3147 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3149 static int msg_count;
3150 int name[CTL_MAXNAME];
3153 /* Check args->nlen. */
3154 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3157 /* Read in the sysctl name for better debug message logging */
3158 for (i = 0; i < args->nlen; i++)
3159 if (get_user(name[i], args->name + i))
3162 /* Ignore accesses to kernel.version */
3163 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3166 if (msg_count < 5) {
3169 "warning: process `%s' used the deprecated sysctl "
3170 "system call with ", current->comm);
3171 for (i = 0; i < args->nlen; i++)
3172 printk("%d.", name[i]);
3179 * No sense putting this after each symbol definition, twice,
3180 * exception granted :-)
3182 EXPORT_SYMBOL(proc_dointvec);
3183 EXPORT_SYMBOL(proc_dointvec_jiffies);
3184 EXPORT_SYMBOL(proc_dointvec_minmax);
3185 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3186 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3187 EXPORT_SYMBOL(proc_dostring);
3188 EXPORT_SYMBOL(proc_doulongvec_minmax);
3189 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3190 EXPORT_SYMBOL(register_sysctl_table);
3191 EXPORT_SYMBOL(register_sysctl_paths);
3192 EXPORT_SYMBOL(sysctl_intvec);
3193 EXPORT_SYMBOL(sysctl_jiffies);
3194 EXPORT_SYMBOL(sysctl_ms_jiffies);
3195 EXPORT_SYMBOL(sysctl_string);
3196 EXPORT_SYMBOL(sysctl_data);
3197 EXPORT_SYMBOL(unregister_sysctl_table);