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/ratelimit.h>
41 #include <linux/hugetlb.h>
42 #include <linux/initrd.h>
43 #include <linux/key.h>
44 #include <linux/times.h>
45 #include <linux/limits.h>
46 #include <linux/dcache.h>
47 #include <linux/syscalls.h>
48 #include <linux/vmstat.h>
49 #include <linux/nfs_fs.h>
50 #include <linux/acpi.h>
51 #include <linux/reboot.h>
52 #include <linux/ftrace.h>
53 #include <linux/slow-work.h>
54 #include <linux/perf_counter.h>
56 #include <asm/uaccess.h>
57 #include <asm/processor.h>
61 #include <asm/stacktrace.h>
65 static int deprecated_sysctl_warning(struct __sysctl_args *args);
67 #if defined(CONFIG_SYSCTL)
69 /* External variables not in a header file. */
71 extern int print_fatal_signals;
72 extern int sysctl_overcommit_memory;
73 extern int sysctl_overcommit_ratio;
74 extern int sysctl_panic_on_oom;
75 extern int sysctl_oom_kill_allocating_task;
76 extern int sysctl_oom_dump_tasks;
77 extern int max_threads;
78 extern int core_uses_pid;
79 extern int suid_dumpable;
80 extern char core_pattern[];
82 extern int min_free_kbytes;
83 extern int pid_max_min, pid_max_max;
84 extern int sysctl_drop_caches;
85 extern int percpu_pagelist_fraction;
86 extern int compat_log;
87 extern int latencytop_enabled;
88 extern int sysctl_nr_open_min, sysctl_nr_open_max;
90 extern int sysctl_nr_trim_pages;
92 #ifdef CONFIG_RCU_TORTURE_TEST
93 extern int rcutorture_runnable;
94 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
96 extern int blk_iopoll_enabled;
99 /* Constants used for minimum and maximum */
100 #ifdef CONFIG_DETECT_SOFTLOCKUP
101 static int sixty = 60;
102 static int neg_one = -1;
106 static int __maybe_unused one = 1;
107 static int __maybe_unused two = 2;
108 static unsigned long one_ul = 1;
109 static int one_hundred = 100;
111 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
112 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
114 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
115 static int maxolduid = 65535;
116 static int minolduid;
117 static int min_percpu_pagelist_fract = 8;
119 static int ngroups_max = NGROUPS_MAX;
121 #ifdef CONFIG_MODULES
122 extern char modprobe_path[];
123 extern int modules_disabled;
125 #ifdef CONFIG_CHR_DEV_SG
126 extern int sg_big_buff;
130 #include <asm/system.h>
133 #ifdef CONFIG_SPARC64
134 extern int sysctl_tsb_ratio;
138 extern int pwrsw_enabled;
139 extern int unaligned_enabled;
143 #ifdef CONFIG_MATHEMU
144 extern int sysctl_ieee_emulation_warnings;
146 extern int sysctl_userprocess_debug;
147 extern int spin_retry;
150 #ifdef CONFIG_BSD_PROCESS_ACCT
151 extern int acct_parm[];
155 extern int no_unaligned_warning;
156 extern int unaligned_dump_stack;
159 extern struct ratelimit_state printk_ratelimit_state;
161 #ifdef CONFIG_RT_MUTEXES
162 extern int max_lock_depth;
165 #ifdef CONFIG_PROC_SYSCTL
166 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
167 void __user *buffer, size_t *lenp, loff_t *ppos);
168 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
169 void __user *buffer, size_t *lenp, loff_t *ppos);
172 static struct ctl_table root_table[];
173 static struct ctl_table_root sysctl_table_root;
174 static struct ctl_table_header root_table_header = {
176 .ctl_table = root_table,
177 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
178 .root = &sysctl_table_root,
179 .set = &sysctl_table_root.default_set,
181 static struct ctl_table_root sysctl_table_root = {
182 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
183 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
186 static struct ctl_table kern_table[];
187 static struct ctl_table vm_table[];
188 static struct ctl_table fs_table[];
189 static struct ctl_table debug_table[];
190 static struct ctl_table dev_table[];
191 extern struct ctl_table random_table[];
192 #ifdef CONFIG_INOTIFY_USER
193 extern struct ctl_table inotify_table[];
196 extern struct ctl_table epoll_table[];
199 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
200 int sysctl_legacy_va_layout;
203 extern int prove_locking;
204 extern int lock_stat;
206 /* The default sysctl tables: */
208 static struct ctl_table root_table[] = {
210 .ctl_name = CTL_KERN,
211 .procname = "kernel",
228 .ctl_name = CTL_DEBUG,
231 .child = debug_table,
240 * NOTE: do not add new entries to this table unless you have read
241 * Documentation/sysctl/ctl_unnumbered.txt
246 #ifdef CONFIG_SCHED_DEBUG
247 static int min_sched_granularity_ns = 100000; /* 100 usecs */
248 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
249 static int min_wakeup_granularity_ns; /* 0 usecs */
250 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
253 static struct ctl_table kern_table[] = {
255 .ctl_name = CTL_UNNUMBERED,
256 .procname = "sched_child_runs_first",
257 .data = &sysctl_sched_child_runs_first,
258 .maxlen = sizeof(unsigned int),
260 .proc_handler = &proc_dointvec,
262 #ifdef CONFIG_SCHED_DEBUG
264 .ctl_name = CTL_UNNUMBERED,
265 .procname = "sched_min_granularity_ns",
266 .data = &sysctl_sched_min_granularity,
267 .maxlen = sizeof(unsigned int),
269 .proc_handler = &sched_nr_latency_handler,
270 .strategy = &sysctl_intvec,
271 .extra1 = &min_sched_granularity_ns,
272 .extra2 = &max_sched_granularity_ns,
275 .ctl_name = CTL_UNNUMBERED,
276 .procname = "sched_latency_ns",
277 .data = &sysctl_sched_latency,
278 .maxlen = sizeof(unsigned int),
280 .proc_handler = &sched_nr_latency_handler,
281 .strategy = &sysctl_intvec,
282 .extra1 = &min_sched_granularity_ns,
283 .extra2 = &max_sched_granularity_ns,
286 .ctl_name = CTL_UNNUMBERED,
287 .procname = "sched_wakeup_granularity_ns",
288 .data = &sysctl_sched_wakeup_granularity,
289 .maxlen = sizeof(unsigned int),
291 .proc_handler = &proc_dointvec_minmax,
292 .strategy = &sysctl_intvec,
293 .extra1 = &min_wakeup_granularity_ns,
294 .extra2 = &max_wakeup_granularity_ns,
297 .ctl_name = CTL_UNNUMBERED,
298 .procname = "sched_shares_ratelimit",
299 .data = &sysctl_sched_shares_ratelimit,
300 .maxlen = sizeof(unsigned int),
302 .proc_handler = &proc_dointvec,
305 .ctl_name = CTL_UNNUMBERED,
306 .procname = "sched_shares_thresh",
307 .data = &sysctl_sched_shares_thresh,
308 .maxlen = sizeof(unsigned int),
310 .proc_handler = &proc_dointvec_minmax,
311 .strategy = &sysctl_intvec,
315 .ctl_name = CTL_UNNUMBERED,
316 .procname = "sched_features",
317 .data = &sysctl_sched_features,
318 .maxlen = sizeof(unsigned int),
320 .proc_handler = &proc_dointvec,
323 .ctl_name = CTL_UNNUMBERED,
324 .procname = "sched_migration_cost",
325 .data = &sysctl_sched_migration_cost,
326 .maxlen = sizeof(unsigned int),
328 .proc_handler = &proc_dointvec,
331 .ctl_name = CTL_UNNUMBERED,
332 .procname = "sched_nr_migrate",
333 .data = &sysctl_sched_nr_migrate,
334 .maxlen = sizeof(unsigned int),
336 .proc_handler = &proc_dointvec,
339 .ctl_name = CTL_UNNUMBERED,
340 .procname = "sched_time_avg",
341 .data = &sysctl_sched_time_avg,
342 .maxlen = sizeof(unsigned int),
344 .proc_handler = &proc_dointvec,
347 .ctl_name = CTL_UNNUMBERED,
348 .procname = "timer_migration",
349 .data = &sysctl_timer_migration,
350 .maxlen = sizeof(unsigned int),
352 .proc_handler = &proc_dointvec_minmax,
353 .strategy = &sysctl_intvec,
359 .ctl_name = CTL_UNNUMBERED,
360 .procname = "sched_rt_period_us",
361 .data = &sysctl_sched_rt_period,
362 .maxlen = sizeof(unsigned int),
364 .proc_handler = &sched_rt_handler,
367 .ctl_name = CTL_UNNUMBERED,
368 .procname = "sched_rt_runtime_us",
369 .data = &sysctl_sched_rt_runtime,
370 .maxlen = sizeof(int),
372 .proc_handler = &sched_rt_handler,
375 .ctl_name = CTL_UNNUMBERED,
376 .procname = "sched_compat_yield",
377 .data = &sysctl_sched_compat_yield,
378 .maxlen = sizeof(unsigned int),
380 .proc_handler = &proc_dointvec,
382 #ifdef CONFIG_PROVE_LOCKING
384 .ctl_name = CTL_UNNUMBERED,
385 .procname = "prove_locking",
386 .data = &prove_locking,
387 .maxlen = sizeof(int),
389 .proc_handler = &proc_dointvec,
392 #ifdef CONFIG_LOCK_STAT
394 .ctl_name = CTL_UNNUMBERED,
395 .procname = "lock_stat",
397 .maxlen = sizeof(int),
399 .proc_handler = &proc_dointvec,
403 .ctl_name = KERN_PANIC,
405 .data = &panic_timeout,
406 .maxlen = sizeof(int),
408 .proc_handler = &proc_dointvec,
411 .ctl_name = KERN_CORE_USES_PID,
412 .procname = "core_uses_pid",
413 .data = &core_uses_pid,
414 .maxlen = sizeof(int),
416 .proc_handler = &proc_dointvec,
419 .ctl_name = KERN_CORE_PATTERN,
420 .procname = "core_pattern",
421 .data = core_pattern,
422 .maxlen = CORENAME_MAX_SIZE,
424 .proc_handler = &proc_dostring,
425 .strategy = &sysctl_string,
427 #ifdef CONFIG_PROC_SYSCTL
429 .procname = "tainted",
430 .maxlen = sizeof(long),
432 .proc_handler = &proc_taint,
435 #ifdef CONFIG_LATENCYTOP
437 .procname = "latencytop",
438 .data = &latencytop_enabled,
439 .maxlen = sizeof(int),
441 .proc_handler = &proc_dointvec,
444 #ifdef CONFIG_BLK_DEV_INITRD
446 .ctl_name = KERN_REALROOTDEV,
447 .procname = "real-root-dev",
448 .data = &real_root_dev,
449 .maxlen = sizeof(int),
451 .proc_handler = &proc_dointvec,
455 .ctl_name = CTL_UNNUMBERED,
456 .procname = "print-fatal-signals",
457 .data = &print_fatal_signals,
458 .maxlen = sizeof(int),
460 .proc_handler = &proc_dointvec,
464 .ctl_name = KERN_SPARC_REBOOT,
465 .procname = "reboot-cmd",
466 .data = reboot_command,
469 .proc_handler = &proc_dostring,
470 .strategy = &sysctl_string,
473 .ctl_name = KERN_SPARC_STOP_A,
474 .procname = "stop-a",
475 .data = &stop_a_enabled,
476 .maxlen = sizeof (int),
478 .proc_handler = &proc_dointvec,
481 .ctl_name = KERN_SPARC_SCONS_PWROFF,
482 .procname = "scons-poweroff",
483 .data = &scons_pwroff,
484 .maxlen = sizeof (int),
486 .proc_handler = &proc_dointvec,
489 #ifdef CONFIG_SPARC64
491 .ctl_name = CTL_UNNUMBERED,
492 .procname = "tsb-ratio",
493 .data = &sysctl_tsb_ratio,
494 .maxlen = sizeof (int),
496 .proc_handler = &proc_dointvec,
501 .ctl_name = KERN_HPPA_PWRSW,
502 .procname = "soft-power",
503 .data = &pwrsw_enabled,
504 .maxlen = sizeof (int),
506 .proc_handler = &proc_dointvec,
509 .ctl_name = KERN_HPPA_UNALIGNED,
510 .procname = "unaligned-trap",
511 .data = &unaligned_enabled,
512 .maxlen = sizeof (int),
514 .proc_handler = &proc_dointvec,
518 .ctl_name = KERN_CTLALTDEL,
519 .procname = "ctrl-alt-del",
521 .maxlen = sizeof(int),
523 .proc_handler = &proc_dointvec,
525 #ifdef CONFIG_FUNCTION_TRACER
527 .ctl_name = CTL_UNNUMBERED,
528 .procname = "ftrace_enabled",
529 .data = &ftrace_enabled,
530 .maxlen = sizeof(int),
532 .proc_handler = &ftrace_enable_sysctl,
535 #ifdef CONFIG_STACK_TRACER
537 .ctl_name = CTL_UNNUMBERED,
538 .procname = "stack_tracer_enabled",
539 .data = &stack_tracer_enabled,
540 .maxlen = sizeof(int),
542 .proc_handler = &stack_trace_sysctl,
545 #ifdef CONFIG_TRACING
547 .ctl_name = CTL_UNNUMBERED,
548 .procname = "ftrace_dump_on_oops",
549 .data = &ftrace_dump_on_oops,
550 .maxlen = sizeof(int),
552 .proc_handler = &proc_dointvec,
555 #ifdef CONFIG_MODULES
557 .ctl_name = KERN_MODPROBE,
558 .procname = "modprobe",
559 .data = &modprobe_path,
560 .maxlen = KMOD_PATH_LEN,
562 .proc_handler = &proc_dostring,
563 .strategy = &sysctl_string,
566 .ctl_name = CTL_UNNUMBERED,
567 .procname = "modules_disabled",
568 .data = &modules_disabled,
569 .maxlen = sizeof(int),
571 /* only handle a transition from default "0" to "1" */
572 .proc_handler = &proc_dointvec_minmax,
577 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
579 .ctl_name = KERN_HOTPLUG,
580 .procname = "hotplug",
581 .data = &uevent_helper,
582 .maxlen = UEVENT_HELPER_PATH_LEN,
584 .proc_handler = &proc_dostring,
585 .strategy = &sysctl_string,
588 #ifdef CONFIG_CHR_DEV_SG
590 .ctl_name = KERN_SG_BIG_BUFF,
591 .procname = "sg-big-buff",
592 .data = &sg_big_buff,
593 .maxlen = sizeof (int),
595 .proc_handler = &proc_dointvec,
598 #ifdef CONFIG_BSD_PROCESS_ACCT
600 .ctl_name = KERN_ACCT,
603 .maxlen = 3*sizeof(int),
605 .proc_handler = &proc_dointvec,
608 #ifdef CONFIG_MAGIC_SYSRQ
610 .ctl_name = KERN_SYSRQ,
612 .data = &__sysrq_enabled,
613 .maxlen = sizeof (int),
615 .proc_handler = &proc_dointvec,
618 #ifdef CONFIG_PROC_SYSCTL
620 .procname = "cad_pid",
622 .maxlen = sizeof (int),
624 .proc_handler = &proc_do_cad_pid,
628 .ctl_name = KERN_MAX_THREADS,
629 .procname = "threads-max",
630 .data = &max_threads,
631 .maxlen = sizeof(int),
633 .proc_handler = &proc_dointvec,
636 .ctl_name = KERN_RANDOM,
637 .procname = "random",
639 .child = random_table,
642 .ctl_name = KERN_OVERFLOWUID,
643 .procname = "overflowuid",
644 .data = &overflowuid,
645 .maxlen = sizeof(int),
647 .proc_handler = &proc_dointvec_minmax,
648 .strategy = &sysctl_intvec,
649 .extra1 = &minolduid,
650 .extra2 = &maxolduid,
653 .ctl_name = KERN_OVERFLOWGID,
654 .procname = "overflowgid",
655 .data = &overflowgid,
656 .maxlen = sizeof(int),
658 .proc_handler = &proc_dointvec_minmax,
659 .strategy = &sysctl_intvec,
660 .extra1 = &minolduid,
661 .extra2 = &maxolduid,
664 #ifdef CONFIG_MATHEMU
666 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
667 .procname = "ieee_emulation_warnings",
668 .data = &sysctl_ieee_emulation_warnings,
669 .maxlen = sizeof(int),
671 .proc_handler = &proc_dointvec,
675 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
676 .procname = "userprocess_debug",
677 .data = &sysctl_userprocess_debug,
678 .maxlen = sizeof(int),
680 .proc_handler = &proc_dointvec,
684 .ctl_name = KERN_PIDMAX,
685 .procname = "pid_max",
687 .maxlen = sizeof (int),
689 .proc_handler = &proc_dointvec_minmax,
690 .strategy = sysctl_intvec,
691 .extra1 = &pid_max_min,
692 .extra2 = &pid_max_max,
695 .ctl_name = KERN_PANIC_ON_OOPS,
696 .procname = "panic_on_oops",
697 .data = &panic_on_oops,
698 .maxlen = sizeof(int),
700 .proc_handler = &proc_dointvec,
702 #if defined CONFIG_PRINTK
704 .ctl_name = KERN_PRINTK,
705 .procname = "printk",
706 .data = &console_loglevel,
707 .maxlen = 4*sizeof(int),
709 .proc_handler = &proc_dointvec,
712 .ctl_name = KERN_PRINTK_RATELIMIT,
713 .procname = "printk_ratelimit",
714 .data = &printk_ratelimit_state.interval,
715 .maxlen = sizeof(int),
717 .proc_handler = &proc_dointvec_jiffies,
718 .strategy = &sysctl_jiffies,
721 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
722 .procname = "printk_ratelimit_burst",
723 .data = &printk_ratelimit_state.burst,
724 .maxlen = sizeof(int),
726 .proc_handler = &proc_dointvec,
730 .ctl_name = KERN_NGROUPS_MAX,
731 .procname = "ngroups_max",
732 .data = &ngroups_max,
733 .maxlen = sizeof (int),
735 .proc_handler = &proc_dointvec,
737 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
739 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
740 .procname = "unknown_nmi_panic",
741 .data = &unknown_nmi_panic,
742 .maxlen = sizeof (int),
744 .proc_handler = &proc_dointvec,
747 .procname = "nmi_watchdog",
748 .data = &nmi_watchdog_enabled,
749 .maxlen = sizeof (int),
751 .proc_handler = &proc_nmi_enabled,
754 #if defined(CONFIG_X86)
756 .ctl_name = KERN_PANIC_ON_NMI,
757 .procname = "panic_on_unrecovered_nmi",
758 .data = &panic_on_unrecovered_nmi,
759 .maxlen = sizeof(int),
761 .proc_handler = &proc_dointvec,
764 .ctl_name = CTL_UNNUMBERED,
765 .procname = "panic_on_io_nmi",
766 .data = &panic_on_io_nmi,
767 .maxlen = sizeof(int),
769 .proc_handler = &proc_dointvec,
772 .ctl_name = KERN_BOOTLOADER_TYPE,
773 .procname = "bootloader_type",
774 .data = &bootloader_type,
775 .maxlen = sizeof (int),
777 .proc_handler = &proc_dointvec,
780 .ctl_name = CTL_UNNUMBERED,
781 .procname = "bootloader_version",
782 .data = &bootloader_version,
783 .maxlen = sizeof (int),
785 .proc_handler = &proc_dointvec,
788 .ctl_name = CTL_UNNUMBERED,
789 .procname = "kstack_depth_to_print",
790 .data = &kstack_depth_to_print,
791 .maxlen = sizeof(int),
793 .proc_handler = &proc_dointvec,
796 .ctl_name = CTL_UNNUMBERED,
797 .procname = "io_delay_type",
798 .data = &io_delay_type,
799 .maxlen = sizeof(int),
801 .proc_handler = &proc_dointvec,
804 #if defined(CONFIG_MMU)
806 .ctl_name = KERN_RANDOMIZE,
807 .procname = "randomize_va_space",
808 .data = &randomize_va_space,
809 .maxlen = sizeof(int),
811 .proc_handler = &proc_dointvec,
814 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
816 .ctl_name = KERN_SPIN_RETRY,
817 .procname = "spin_retry",
819 .maxlen = sizeof (int),
821 .proc_handler = &proc_dointvec,
824 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
826 .procname = "acpi_video_flags",
827 .data = &acpi_realmode_flags,
828 .maxlen = sizeof (unsigned long),
830 .proc_handler = &proc_doulongvec_minmax,
835 .ctl_name = KERN_IA64_UNALIGNED,
836 .procname = "ignore-unaligned-usertrap",
837 .data = &no_unaligned_warning,
838 .maxlen = sizeof (int),
840 .proc_handler = &proc_dointvec,
843 .ctl_name = CTL_UNNUMBERED,
844 .procname = "unaligned-dump-stack",
845 .data = &unaligned_dump_stack,
846 .maxlen = sizeof (int),
848 .proc_handler = &proc_dointvec,
851 #ifdef CONFIG_DETECT_SOFTLOCKUP
853 .ctl_name = CTL_UNNUMBERED,
854 .procname = "softlockup_panic",
855 .data = &softlockup_panic,
856 .maxlen = sizeof(int),
858 .proc_handler = &proc_dointvec_minmax,
859 .strategy = &sysctl_intvec,
864 .ctl_name = CTL_UNNUMBERED,
865 .procname = "softlockup_thresh",
866 .data = &softlockup_thresh,
867 .maxlen = sizeof(int),
869 .proc_handler = &proc_dosoftlockup_thresh,
870 .strategy = &sysctl_intvec,
875 #ifdef CONFIG_DETECT_HUNG_TASK
877 .ctl_name = CTL_UNNUMBERED,
878 .procname = "hung_task_panic",
879 .data = &sysctl_hung_task_panic,
880 .maxlen = sizeof(int),
882 .proc_handler = &proc_dointvec_minmax,
883 .strategy = &sysctl_intvec,
888 .ctl_name = CTL_UNNUMBERED,
889 .procname = "hung_task_check_count",
890 .data = &sysctl_hung_task_check_count,
891 .maxlen = sizeof(unsigned long),
893 .proc_handler = &proc_doulongvec_minmax,
894 .strategy = &sysctl_intvec,
897 .ctl_name = CTL_UNNUMBERED,
898 .procname = "hung_task_timeout_secs",
899 .data = &sysctl_hung_task_timeout_secs,
900 .maxlen = sizeof(unsigned long),
902 .proc_handler = &proc_dohung_task_timeout_secs,
903 .strategy = &sysctl_intvec,
906 .ctl_name = CTL_UNNUMBERED,
907 .procname = "hung_task_warnings",
908 .data = &sysctl_hung_task_warnings,
909 .maxlen = sizeof(unsigned long),
911 .proc_handler = &proc_doulongvec_minmax,
912 .strategy = &sysctl_intvec,
917 .ctl_name = KERN_COMPAT_LOG,
918 .procname = "compat-log",
920 .maxlen = sizeof (int),
922 .proc_handler = &proc_dointvec,
925 #ifdef CONFIG_RT_MUTEXES
927 .ctl_name = KERN_MAX_LOCK_DEPTH,
928 .procname = "max_lock_depth",
929 .data = &max_lock_depth,
930 .maxlen = sizeof(int),
932 .proc_handler = &proc_dointvec,
936 .ctl_name = CTL_UNNUMBERED,
937 .procname = "poweroff_cmd",
938 .data = &poweroff_cmd,
939 .maxlen = POWEROFF_CMD_PATH_LEN,
941 .proc_handler = &proc_dostring,
942 .strategy = &sysctl_string,
946 .ctl_name = CTL_UNNUMBERED,
949 .child = key_sysctls,
952 #ifdef CONFIG_RCU_TORTURE_TEST
954 .ctl_name = CTL_UNNUMBERED,
955 .procname = "rcutorture_runnable",
956 .data = &rcutorture_runnable,
957 .maxlen = sizeof(int),
959 .proc_handler = &proc_dointvec,
962 #ifdef CONFIG_SLOW_WORK
964 .ctl_name = CTL_UNNUMBERED,
965 .procname = "slow-work",
967 .child = slow_work_sysctls,
970 #ifdef CONFIG_PERF_COUNTERS
972 .ctl_name = CTL_UNNUMBERED,
973 .procname = "perf_counter_paranoid",
974 .data = &sysctl_perf_counter_paranoid,
975 .maxlen = sizeof(sysctl_perf_counter_paranoid),
977 .proc_handler = &proc_dointvec,
980 .ctl_name = CTL_UNNUMBERED,
981 .procname = "perf_counter_mlock_kb",
982 .data = &sysctl_perf_counter_mlock,
983 .maxlen = sizeof(sysctl_perf_counter_mlock),
985 .proc_handler = &proc_dointvec,
988 .ctl_name = CTL_UNNUMBERED,
989 .procname = "perf_counter_max_sample_rate",
990 .data = &sysctl_perf_counter_sample_rate,
991 .maxlen = sizeof(sysctl_perf_counter_sample_rate),
993 .proc_handler = &proc_dointvec,
996 #ifdef CONFIG_KMEMCHECK
998 .ctl_name = CTL_UNNUMBERED,
999 .procname = "kmemcheck",
1000 .data = &kmemcheck_enabled,
1001 .maxlen = sizeof(int),
1003 .proc_handler = &proc_dointvec,
1008 .ctl_name = CTL_UNNUMBERED,
1009 .procname = "blk_iopoll",
1010 .data = &blk_iopoll_enabled,
1011 .maxlen = sizeof(int),
1013 .proc_handler = &proc_dointvec,
1017 * NOTE: do not add new entries to this table unless you have read
1018 * Documentation/sysctl/ctl_unnumbered.txt
1023 static struct ctl_table vm_table[] = {
1025 .ctl_name = VM_OVERCOMMIT_MEMORY,
1026 .procname = "overcommit_memory",
1027 .data = &sysctl_overcommit_memory,
1028 .maxlen = sizeof(sysctl_overcommit_memory),
1030 .proc_handler = &proc_dointvec,
1033 .ctl_name = VM_PANIC_ON_OOM,
1034 .procname = "panic_on_oom",
1035 .data = &sysctl_panic_on_oom,
1036 .maxlen = sizeof(sysctl_panic_on_oom),
1038 .proc_handler = &proc_dointvec,
1041 .ctl_name = CTL_UNNUMBERED,
1042 .procname = "oom_kill_allocating_task",
1043 .data = &sysctl_oom_kill_allocating_task,
1044 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1046 .proc_handler = &proc_dointvec,
1049 .ctl_name = CTL_UNNUMBERED,
1050 .procname = "oom_dump_tasks",
1051 .data = &sysctl_oom_dump_tasks,
1052 .maxlen = sizeof(sysctl_oom_dump_tasks),
1054 .proc_handler = &proc_dointvec,
1057 .ctl_name = VM_OVERCOMMIT_RATIO,
1058 .procname = "overcommit_ratio",
1059 .data = &sysctl_overcommit_ratio,
1060 .maxlen = sizeof(sysctl_overcommit_ratio),
1062 .proc_handler = &proc_dointvec,
1065 .ctl_name = VM_PAGE_CLUSTER,
1066 .procname = "page-cluster",
1067 .data = &page_cluster,
1068 .maxlen = sizeof(int),
1070 .proc_handler = &proc_dointvec,
1073 .ctl_name = VM_DIRTY_BACKGROUND,
1074 .procname = "dirty_background_ratio",
1075 .data = &dirty_background_ratio,
1076 .maxlen = sizeof(dirty_background_ratio),
1078 .proc_handler = &dirty_background_ratio_handler,
1079 .strategy = &sysctl_intvec,
1081 .extra2 = &one_hundred,
1084 .ctl_name = CTL_UNNUMBERED,
1085 .procname = "dirty_background_bytes",
1086 .data = &dirty_background_bytes,
1087 .maxlen = sizeof(dirty_background_bytes),
1089 .proc_handler = &dirty_background_bytes_handler,
1090 .strategy = &sysctl_intvec,
1094 .ctl_name = VM_DIRTY_RATIO,
1095 .procname = "dirty_ratio",
1096 .data = &vm_dirty_ratio,
1097 .maxlen = sizeof(vm_dirty_ratio),
1099 .proc_handler = &dirty_ratio_handler,
1100 .strategy = &sysctl_intvec,
1102 .extra2 = &one_hundred,
1105 .ctl_name = CTL_UNNUMBERED,
1106 .procname = "dirty_bytes",
1107 .data = &vm_dirty_bytes,
1108 .maxlen = sizeof(vm_dirty_bytes),
1110 .proc_handler = &dirty_bytes_handler,
1111 .strategy = &sysctl_intvec,
1112 .extra1 = &dirty_bytes_min,
1115 .procname = "dirty_writeback_centisecs",
1116 .data = &dirty_writeback_interval,
1117 .maxlen = sizeof(dirty_writeback_interval),
1119 .proc_handler = &dirty_writeback_centisecs_handler,
1122 .procname = "dirty_expire_centisecs",
1123 .data = &dirty_expire_interval,
1124 .maxlen = sizeof(dirty_expire_interval),
1126 .proc_handler = &proc_dointvec,
1129 .ctl_name = VM_NR_PDFLUSH_THREADS,
1130 .procname = "nr_pdflush_threads",
1131 .data = &nr_pdflush_threads,
1132 .maxlen = sizeof nr_pdflush_threads,
1133 .mode = 0444 /* read-only*/,
1134 .proc_handler = &proc_dointvec,
1137 .ctl_name = VM_SWAPPINESS,
1138 .procname = "swappiness",
1139 .data = &vm_swappiness,
1140 .maxlen = sizeof(vm_swappiness),
1142 .proc_handler = &proc_dointvec_minmax,
1143 .strategy = &sysctl_intvec,
1145 .extra2 = &one_hundred,
1147 #ifdef CONFIG_HUGETLB_PAGE
1149 .procname = "nr_hugepages",
1151 .maxlen = sizeof(unsigned long),
1153 .proc_handler = &hugetlb_sysctl_handler,
1154 .extra1 = (void *)&hugetlb_zero,
1155 .extra2 = (void *)&hugetlb_infinity,
1158 .ctl_name = VM_HUGETLB_GROUP,
1159 .procname = "hugetlb_shm_group",
1160 .data = &sysctl_hugetlb_shm_group,
1161 .maxlen = sizeof(gid_t),
1163 .proc_handler = &proc_dointvec,
1166 .ctl_name = CTL_UNNUMBERED,
1167 .procname = "hugepages_treat_as_movable",
1168 .data = &hugepages_treat_as_movable,
1169 .maxlen = sizeof(int),
1171 .proc_handler = &hugetlb_treat_movable_handler,
1174 .ctl_name = CTL_UNNUMBERED,
1175 .procname = "nr_overcommit_hugepages",
1177 .maxlen = sizeof(unsigned long),
1179 .proc_handler = &hugetlb_overcommit_handler,
1180 .extra1 = (void *)&hugetlb_zero,
1181 .extra2 = (void *)&hugetlb_infinity,
1185 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1186 .procname = "lowmem_reserve_ratio",
1187 .data = &sysctl_lowmem_reserve_ratio,
1188 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1190 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1191 .strategy = &sysctl_intvec,
1194 .ctl_name = VM_DROP_PAGECACHE,
1195 .procname = "drop_caches",
1196 .data = &sysctl_drop_caches,
1197 .maxlen = sizeof(int),
1199 .proc_handler = drop_caches_sysctl_handler,
1200 .strategy = &sysctl_intvec,
1203 .ctl_name = VM_MIN_FREE_KBYTES,
1204 .procname = "min_free_kbytes",
1205 .data = &min_free_kbytes,
1206 .maxlen = sizeof(min_free_kbytes),
1208 .proc_handler = &min_free_kbytes_sysctl_handler,
1209 .strategy = &sysctl_intvec,
1213 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1214 .procname = "percpu_pagelist_fraction",
1215 .data = &percpu_pagelist_fraction,
1216 .maxlen = sizeof(percpu_pagelist_fraction),
1218 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1219 .strategy = &sysctl_intvec,
1220 .extra1 = &min_percpu_pagelist_fract,
1224 .ctl_name = VM_MAX_MAP_COUNT,
1225 .procname = "max_map_count",
1226 .data = &sysctl_max_map_count,
1227 .maxlen = sizeof(sysctl_max_map_count),
1229 .proc_handler = &proc_dointvec
1233 .ctl_name = CTL_UNNUMBERED,
1234 .procname = "nr_trim_pages",
1235 .data = &sysctl_nr_trim_pages,
1236 .maxlen = sizeof(sysctl_nr_trim_pages),
1238 .proc_handler = &proc_dointvec_minmax,
1239 .strategy = &sysctl_intvec,
1244 .ctl_name = VM_LAPTOP_MODE,
1245 .procname = "laptop_mode",
1246 .data = &laptop_mode,
1247 .maxlen = sizeof(laptop_mode),
1249 .proc_handler = &proc_dointvec_jiffies,
1250 .strategy = &sysctl_jiffies,
1253 .ctl_name = VM_BLOCK_DUMP,
1254 .procname = "block_dump",
1255 .data = &block_dump,
1256 .maxlen = sizeof(block_dump),
1258 .proc_handler = &proc_dointvec,
1259 .strategy = &sysctl_intvec,
1263 .ctl_name = VM_VFS_CACHE_PRESSURE,
1264 .procname = "vfs_cache_pressure",
1265 .data = &sysctl_vfs_cache_pressure,
1266 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1268 .proc_handler = &proc_dointvec,
1269 .strategy = &sysctl_intvec,
1272 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1274 .ctl_name = VM_LEGACY_VA_LAYOUT,
1275 .procname = "legacy_va_layout",
1276 .data = &sysctl_legacy_va_layout,
1277 .maxlen = sizeof(sysctl_legacy_va_layout),
1279 .proc_handler = &proc_dointvec,
1280 .strategy = &sysctl_intvec,
1286 .ctl_name = VM_ZONE_RECLAIM_MODE,
1287 .procname = "zone_reclaim_mode",
1288 .data = &zone_reclaim_mode,
1289 .maxlen = sizeof(zone_reclaim_mode),
1291 .proc_handler = &proc_dointvec,
1292 .strategy = &sysctl_intvec,
1296 .ctl_name = VM_MIN_UNMAPPED,
1297 .procname = "min_unmapped_ratio",
1298 .data = &sysctl_min_unmapped_ratio,
1299 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1301 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1302 .strategy = &sysctl_intvec,
1304 .extra2 = &one_hundred,
1307 .ctl_name = VM_MIN_SLAB,
1308 .procname = "min_slab_ratio",
1309 .data = &sysctl_min_slab_ratio,
1310 .maxlen = sizeof(sysctl_min_slab_ratio),
1312 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1313 .strategy = &sysctl_intvec,
1315 .extra2 = &one_hundred,
1320 .ctl_name = CTL_UNNUMBERED,
1321 .procname = "stat_interval",
1322 .data = &sysctl_stat_interval,
1323 .maxlen = sizeof(sysctl_stat_interval),
1325 .proc_handler = &proc_dointvec_jiffies,
1326 .strategy = &sysctl_jiffies,
1330 .ctl_name = CTL_UNNUMBERED,
1331 .procname = "mmap_min_addr",
1332 .data = &dac_mmap_min_addr,
1333 .maxlen = sizeof(unsigned long),
1335 .proc_handler = &mmap_min_addr_handler,
1339 .ctl_name = CTL_UNNUMBERED,
1340 .procname = "numa_zonelist_order",
1341 .data = &numa_zonelist_order,
1342 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1344 .proc_handler = &numa_zonelist_order_handler,
1345 .strategy = &sysctl_string,
1348 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1349 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1351 .ctl_name = VM_VDSO_ENABLED,
1352 .procname = "vdso_enabled",
1353 .data = &vdso_enabled,
1354 .maxlen = sizeof(vdso_enabled),
1356 .proc_handler = &proc_dointvec,
1357 .strategy = &sysctl_intvec,
1361 #ifdef CONFIG_HIGHMEM
1363 .ctl_name = CTL_UNNUMBERED,
1364 .procname = "highmem_is_dirtyable",
1365 .data = &vm_highmem_is_dirtyable,
1366 .maxlen = sizeof(vm_highmem_is_dirtyable),
1368 .proc_handler = &proc_dointvec_minmax,
1369 .strategy = &sysctl_intvec,
1375 .ctl_name = CTL_UNNUMBERED,
1376 .procname = "scan_unevictable_pages",
1377 .data = &scan_unevictable_pages,
1378 .maxlen = sizeof(scan_unevictable_pages),
1380 .proc_handler = &scan_unevictable_handler,
1383 * NOTE: do not add new entries to this table unless you have read
1384 * Documentation/sysctl/ctl_unnumbered.txt
1389 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1390 static struct ctl_table binfmt_misc_table[] = {
1395 static struct ctl_table fs_table[] = {
1397 .ctl_name = FS_NRINODE,
1398 .procname = "inode-nr",
1399 .data = &inodes_stat,
1400 .maxlen = 2*sizeof(int),
1402 .proc_handler = &proc_dointvec,
1405 .ctl_name = FS_STATINODE,
1406 .procname = "inode-state",
1407 .data = &inodes_stat,
1408 .maxlen = 7*sizeof(int),
1410 .proc_handler = &proc_dointvec,
1413 .procname = "file-nr",
1414 .data = &files_stat,
1415 .maxlen = 3*sizeof(int),
1417 .proc_handler = &proc_nr_files,
1420 .ctl_name = FS_MAXFILE,
1421 .procname = "file-max",
1422 .data = &files_stat.max_files,
1423 .maxlen = sizeof(int),
1425 .proc_handler = &proc_dointvec,
1428 .ctl_name = CTL_UNNUMBERED,
1429 .procname = "nr_open",
1430 .data = &sysctl_nr_open,
1431 .maxlen = sizeof(int),
1433 .proc_handler = &proc_dointvec_minmax,
1434 .extra1 = &sysctl_nr_open_min,
1435 .extra2 = &sysctl_nr_open_max,
1438 .ctl_name = FS_DENTRY,
1439 .procname = "dentry-state",
1440 .data = &dentry_stat,
1441 .maxlen = 6*sizeof(int),
1443 .proc_handler = &proc_dointvec,
1446 .ctl_name = FS_OVERFLOWUID,
1447 .procname = "overflowuid",
1448 .data = &fs_overflowuid,
1449 .maxlen = sizeof(int),
1451 .proc_handler = &proc_dointvec_minmax,
1452 .strategy = &sysctl_intvec,
1453 .extra1 = &minolduid,
1454 .extra2 = &maxolduid,
1457 .ctl_name = FS_OVERFLOWGID,
1458 .procname = "overflowgid",
1459 .data = &fs_overflowgid,
1460 .maxlen = sizeof(int),
1462 .proc_handler = &proc_dointvec_minmax,
1463 .strategy = &sysctl_intvec,
1464 .extra1 = &minolduid,
1465 .extra2 = &maxolduid,
1467 #ifdef CONFIG_FILE_LOCKING
1469 .ctl_name = FS_LEASES,
1470 .procname = "leases-enable",
1471 .data = &leases_enable,
1472 .maxlen = sizeof(int),
1474 .proc_handler = &proc_dointvec,
1477 #ifdef CONFIG_DNOTIFY
1479 .ctl_name = FS_DIR_NOTIFY,
1480 .procname = "dir-notify-enable",
1481 .data = &dir_notify_enable,
1482 .maxlen = sizeof(int),
1484 .proc_handler = &proc_dointvec,
1488 #ifdef CONFIG_FILE_LOCKING
1490 .ctl_name = FS_LEASE_TIME,
1491 .procname = "lease-break-time",
1492 .data = &lease_break_time,
1493 .maxlen = sizeof(int),
1495 .proc_handler = &proc_dointvec,
1500 .procname = "aio-nr",
1502 .maxlen = sizeof(aio_nr),
1504 .proc_handler = &proc_doulongvec_minmax,
1507 .procname = "aio-max-nr",
1508 .data = &aio_max_nr,
1509 .maxlen = sizeof(aio_max_nr),
1511 .proc_handler = &proc_doulongvec_minmax,
1513 #endif /* CONFIG_AIO */
1514 #ifdef CONFIG_INOTIFY_USER
1516 .ctl_name = FS_INOTIFY,
1517 .procname = "inotify",
1519 .child = inotify_table,
1524 .procname = "epoll",
1526 .child = epoll_table,
1531 .ctl_name = KERN_SETUID_DUMPABLE,
1532 .procname = "suid_dumpable",
1533 .data = &suid_dumpable,
1534 .maxlen = sizeof(int),
1536 .proc_handler = &proc_dointvec_minmax,
1537 .strategy = &sysctl_intvec,
1541 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1543 .ctl_name = CTL_UNNUMBERED,
1544 .procname = "binfmt_misc",
1546 .child = binfmt_misc_table,
1550 * NOTE: do not add new entries to this table unless you have read
1551 * Documentation/sysctl/ctl_unnumbered.txt
1556 static struct ctl_table debug_table[] = {
1557 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1559 .ctl_name = CTL_UNNUMBERED,
1560 .procname = "exception-trace",
1561 .data = &show_unhandled_signals,
1562 .maxlen = sizeof(int),
1564 .proc_handler = proc_dointvec
1570 static struct ctl_table dev_table[] = {
1574 static DEFINE_SPINLOCK(sysctl_lock);
1576 /* called under sysctl_lock */
1577 static int use_table(struct ctl_table_header *p)
1579 if (unlikely(p->unregistering))
1585 /* called under sysctl_lock */
1586 static void unuse_table(struct ctl_table_header *p)
1589 if (unlikely(p->unregistering))
1590 complete(p->unregistering);
1593 /* called under sysctl_lock, will reacquire if has to wait */
1594 static void start_unregistering(struct ctl_table_header *p)
1597 * if p->used is 0, nobody will ever touch that entry again;
1598 * we'll eliminate all paths to it before dropping sysctl_lock
1600 if (unlikely(p->used)) {
1601 struct completion wait;
1602 init_completion(&wait);
1603 p->unregistering = &wait;
1604 spin_unlock(&sysctl_lock);
1605 wait_for_completion(&wait);
1606 spin_lock(&sysctl_lock);
1608 /* anything non-NULL; we'll never dereference it */
1609 p->unregistering = ERR_PTR(-EINVAL);
1612 * do not remove from the list until nobody holds it; walking the
1613 * list in do_sysctl() relies on that.
1615 list_del_init(&p->ctl_entry);
1618 void sysctl_head_get(struct ctl_table_header *head)
1620 spin_lock(&sysctl_lock);
1622 spin_unlock(&sysctl_lock);
1625 void sysctl_head_put(struct ctl_table_header *head)
1627 spin_lock(&sysctl_lock);
1630 spin_unlock(&sysctl_lock);
1633 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1637 spin_lock(&sysctl_lock);
1638 if (!use_table(head))
1639 head = ERR_PTR(-ENOENT);
1640 spin_unlock(&sysctl_lock);
1644 void sysctl_head_finish(struct ctl_table_header *head)
1648 spin_lock(&sysctl_lock);
1650 spin_unlock(&sysctl_lock);
1653 static struct ctl_table_set *
1654 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1656 struct ctl_table_set *set = &root->default_set;
1658 set = root->lookup(root, namespaces);
1662 static struct list_head *
1663 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1665 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1669 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1670 struct ctl_table_header *prev)
1672 struct ctl_table_root *root;
1673 struct list_head *header_list;
1674 struct ctl_table_header *head;
1675 struct list_head *tmp;
1677 spin_lock(&sysctl_lock);
1680 tmp = &prev->ctl_entry;
1684 tmp = &root_table_header.ctl_entry;
1686 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1688 if (!use_table(head))
1690 spin_unlock(&sysctl_lock);
1695 header_list = lookup_header_list(root, namespaces);
1696 if (tmp != header_list)
1700 root = list_entry(root->root_list.next,
1701 struct ctl_table_root, root_list);
1702 if (root == &sysctl_table_root)
1704 header_list = lookup_header_list(root, namespaces);
1705 } while (list_empty(header_list));
1706 tmp = header_list->next;
1709 spin_unlock(&sysctl_lock);
1713 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1715 return __sysctl_head_next(current->nsproxy, prev);
1718 void register_sysctl_root(struct ctl_table_root *root)
1720 spin_lock(&sysctl_lock);
1721 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1722 spin_unlock(&sysctl_lock);
1725 #ifdef CONFIG_SYSCTL_SYSCALL
1726 /* Perform the actual read/write of a sysctl table entry. */
1727 static int do_sysctl_strategy(struct ctl_table_root *root,
1728 struct ctl_table *table,
1729 void __user *oldval, size_t __user *oldlenp,
1730 void __user *newval, size_t newlen)
1738 if (sysctl_perm(root, table, op))
1741 if (table->strategy) {
1742 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1749 /* If there is no strategy routine, or if the strategy returns
1750 * zero, proceed with automatic r/w */
1751 if (table->data && table->maxlen) {
1752 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1759 static int parse_table(int __user *name, int nlen,
1760 void __user *oldval, size_t __user *oldlenp,
1761 void __user *newval, size_t newlen,
1762 struct ctl_table_root *root,
1763 struct ctl_table *table)
1769 if (get_user(n, name))
1771 for ( ; table->ctl_name || table->procname; table++) {
1772 if (!table->ctl_name)
1774 if (n == table->ctl_name) {
1777 if (sysctl_perm(root, table, MAY_EXEC))
1781 table = table->child;
1784 error = do_sysctl_strategy(root, table,
1793 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1794 void __user *newval, size_t newlen)
1796 struct ctl_table_header *head;
1797 int error = -ENOTDIR;
1799 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1803 if (!oldlenp || get_user(old_len, oldlenp))
1807 for (head = sysctl_head_next(NULL); head;
1808 head = sysctl_head_next(head)) {
1809 error = parse_table(name, nlen, oldval, oldlenp,
1811 head->root, head->ctl_table);
1812 if (error != -ENOTDIR) {
1813 sysctl_head_finish(head);
1820 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1822 struct __sysctl_args tmp;
1825 if (copy_from_user(&tmp, args, sizeof(tmp)))
1828 error = deprecated_sysctl_warning(&tmp);
1833 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1834 tmp.newval, tmp.newlen);
1839 #endif /* CONFIG_SYSCTL_SYSCALL */
1842 * sysctl_perm does NOT grant the superuser all rights automatically, because
1843 * some sysctl variables are readonly even to root.
1846 static int test_perm(int mode, int op)
1848 if (!current_euid())
1850 else if (in_egroup_p(0))
1852 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1857 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1862 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1866 if (root->permissions)
1867 mode = root->permissions(root, current->nsproxy, table);
1871 return test_perm(mode, op);
1874 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1876 for (; table->ctl_name || table->procname; table++) {
1877 table->parent = parent;
1879 sysctl_set_parent(table, table->child);
1883 static __init int sysctl_init(void)
1885 sysctl_set_parent(NULL, root_table);
1886 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1889 err = sysctl_check_table(current->nsproxy, root_table);
1895 core_initcall(sysctl_init);
1897 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1898 struct ctl_table *table)
1900 struct ctl_table *p;
1901 const char *s = branch->procname;
1903 /* branch should have named subdirectory as its first element */
1904 if (!s || !branch->child)
1907 /* ... and nothing else */
1908 if (branch[1].procname || branch[1].ctl_name)
1911 /* table should contain subdirectory with the same name */
1912 for (p = table; p->procname || p->ctl_name; p++) {
1915 if (p->procname && strcmp(p->procname, s) == 0)
1921 /* see if attaching q to p would be an improvement */
1922 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1924 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1925 struct ctl_table *next;
1927 int not_in_parent = !p->attached_by;
1929 while ((next = is_branch_in(by, to)) != NULL) {
1930 if (by == q->attached_by)
1932 if (to == p->attached_by)
1938 if (is_better && not_in_parent) {
1939 q->attached_by = by;
1940 q->attached_to = to;
1946 * __register_sysctl_paths - register a sysctl hierarchy
1947 * @root: List of sysctl headers to register on
1948 * @namespaces: Data to compute which lists of sysctl entries are visible
1949 * @path: The path to the directory the sysctl table is in.
1950 * @table: the top-level table structure
1952 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1953 * array. A completely 0 filled entry terminates the table.
1955 * The members of the &struct ctl_table structure are used as follows:
1957 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1958 * must be unique within that level of sysctl
1960 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1961 * enter a sysctl file
1963 * data - a pointer to data for use by proc_handler
1965 * maxlen - the maximum size in bytes of the data
1967 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1969 * child - a pointer to the child sysctl table if this entry is a directory, or
1972 * proc_handler - the text handler routine (described below)
1974 * strategy - the strategy routine (described below)
1976 * de - for internal use by the sysctl routines
1978 * extra1, extra2 - extra pointers usable by the proc handler routines
1980 * Leaf nodes in the sysctl tree will be represented by a single file
1981 * under /proc; non-leaf nodes will be represented by directories.
1983 * sysctl(2) can automatically manage read and write requests through
1984 * the sysctl table. The data and maxlen fields of the ctl_table
1985 * struct enable minimal validation of the values being written to be
1986 * performed, and the mode field allows minimal authentication.
1988 * More sophisticated management can be enabled by the provision of a
1989 * strategy routine with the table entry. This will be called before
1990 * any automatic read or write of the data is performed.
1992 * The strategy routine may return
1994 * < 0 - Error occurred (error is passed to user process)
1996 * 0 - OK - proceed with automatic read or write.
1998 * > 0 - OK - read or write has been done by the strategy routine, so
1999 * return immediately.
2001 * There must be a proc_handler routine for any terminal nodes
2002 * mirrored under /proc/sys (non-terminals are handled by a built-in
2003 * directory handler). Several default handlers are available to
2004 * cover common cases -
2006 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2007 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2008 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2010 * It is the handler's job to read the input buffer from user memory
2011 * and process it. The handler should return 0 on success.
2013 * This routine returns %NULL on a failure to register, and a pointer
2014 * to the table header on success.
2016 struct ctl_table_header *__register_sysctl_paths(
2017 struct ctl_table_root *root,
2018 struct nsproxy *namespaces,
2019 const struct ctl_path *path, struct ctl_table *table)
2021 struct ctl_table_header *header;
2022 struct ctl_table *new, **prevp;
2023 unsigned int n, npath;
2024 struct ctl_table_set *set;
2026 /* Count the path components */
2027 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2031 * For each path component, allocate a 2-element ctl_table array.
2032 * The first array element will be filled with the sysctl entry
2033 * for this, the second will be the sentinel (ctl_name == 0).
2035 * We allocate everything in one go so that we don't have to
2036 * worry about freeing additional memory in unregister_sysctl_table.
2038 header = kzalloc(sizeof(struct ctl_table_header) +
2039 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2043 new = (struct ctl_table *) (header + 1);
2045 /* Now connect the dots */
2046 prevp = &header->ctl_table;
2047 for (n = 0; n < npath; ++n, ++path) {
2048 /* Copy the procname */
2049 new->procname = path->procname;
2050 new->ctl_name = path->ctl_name;
2054 prevp = &new->child;
2059 header->ctl_table_arg = table;
2061 INIT_LIST_HEAD(&header->ctl_entry);
2063 header->unregistering = NULL;
2064 header->root = root;
2065 sysctl_set_parent(NULL, header->ctl_table);
2067 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2068 if (sysctl_check_table(namespaces, header->ctl_table)) {
2073 spin_lock(&sysctl_lock);
2074 header->set = lookup_header_set(root, namespaces);
2075 header->attached_by = header->ctl_table;
2076 header->attached_to = root_table;
2077 header->parent = &root_table_header;
2078 for (set = header->set; set; set = set->parent) {
2079 struct ctl_table_header *p;
2080 list_for_each_entry(p, &set->list, ctl_entry) {
2081 if (p->unregistering)
2083 try_attach(p, header);
2086 header->parent->count++;
2087 list_add_tail(&header->ctl_entry, &header->set->list);
2088 spin_unlock(&sysctl_lock);
2094 * register_sysctl_table_path - register a sysctl table hierarchy
2095 * @path: The path to the directory the sysctl table is in.
2096 * @table: the top-level table structure
2098 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2099 * array. A completely 0 filled entry terminates the table.
2101 * See __register_sysctl_paths for more details.
2103 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2104 struct ctl_table *table)
2106 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2111 * register_sysctl_table - register a sysctl table hierarchy
2112 * @table: the top-level table structure
2114 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2115 * array. A completely 0 filled entry terminates the table.
2117 * See register_sysctl_paths for more details.
2119 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2121 static const struct ctl_path null_path[] = { {} };
2123 return register_sysctl_paths(null_path, table);
2127 * unregister_sysctl_table - unregister a sysctl table hierarchy
2128 * @header: the header returned from register_sysctl_table
2130 * Unregisters the sysctl table and all children. proc entries may not
2131 * actually be removed until they are no longer used by anyone.
2133 void unregister_sysctl_table(struct ctl_table_header * header)
2140 spin_lock(&sysctl_lock);
2141 start_unregistering(header);
2142 if (!--header->parent->count) {
2144 kfree(header->parent);
2146 if (!--header->count)
2148 spin_unlock(&sysctl_lock);
2151 int sysctl_is_seen(struct ctl_table_header *p)
2153 struct ctl_table_set *set = p->set;
2155 spin_lock(&sysctl_lock);
2156 if (p->unregistering)
2158 else if (!set->is_seen)
2161 res = set->is_seen(set);
2162 spin_unlock(&sysctl_lock);
2166 void setup_sysctl_set(struct ctl_table_set *p,
2167 struct ctl_table_set *parent,
2168 int (*is_seen)(struct ctl_table_set *))
2170 INIT_LIST_HEAD(&p->list);
2171 p->parent = parent ? parent : &sysctl_table_root.default_set;
2172 p->is_seen = is_seen;
2175 #else /* !CONFIG_SYSCTL */
2176 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2181 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2182 struct ctl_table *table)
2187 void unregister_sysctl_table(struct ctl_table_header * table)
2191 void setup_sysctl_set(struct ctl_table_set *p,
2192 struct ctl_table_set *parent,
2193 int (*is_seen)(struct ctl_table_set *))
2197 void sysctl_head_put(struct ctl_table_header *head)
2201 #endif /* CONFIG_SYSCTL */
2207 #ifdef CONFIG_PROC_SYSCTL
2209 static int _proc_do_string(void* data, int maxlen, int write,
2210 struct file *filp, void __user *buffer,
2211 size_t *lenp, loff_t *ppos)
2217 if (!data || !maxlen || !*lenp) {
2225 while (len < *lenp) {
2226 if (get_user(c, p++))
2228 if (c == 0 || c == '\n')
2234 if(copy_from_user(data, buffer, len))
2236 ((char *) data)[len] = 0;
2254 if(copy_to_user(buffer, data, len))
2257 if(put_user('\n', ((char __user *) buffer) + len))
2268 * proc_dostring - read a string sysctl
2269 * @table: the sysctl table
2270 * @write: %TRUE if this is a write to the sysctl file
2271 * @filp: the file structure
2272 * @buffer: the user buffer
2273 * @lenp: the size of the user buffer
2274 * @ppos: file position
2276 * Reads/writes a string from/to the user buffer. If the kernel
2277 * buffer provided is not large enough to hold the string, the
2278 * string is truncated. The copied string is %NULL-terminated.
2279 * If the string is being read by the user process, it is copied
2280 * and a newline '\n' is added. It is truncated if the buffer is
2283 * Returns 0 on success.
2285 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2286 void __user *buffer, size_t *lenp, loff_t *ppos)
2288 return _proc_do_string(table->data, table->maxlen, write, filp,
2289 buffer, lenp, ppos);
2293 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2295 int write, void *data)
2298 *valp = *negp ? -*lvalp : *lvalp;
2303 *lvalp = (unsigned long)-val;
2306 *lvalp = (unsigned long)val;
2312 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2313 int write, struct file *filp, void __user *buffer,
2314 size_t *lenp, loff_t *ppos,
2315 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2316 int write, void *data),
2319 #define TMPBUFLEN 21
2320 int *i, vleft, first = 1, neg;
2324 char buf[TMPBUFLEN], *p;
2325 char __user *s = buffer;
2327 if (!tbl_data || !table->maxlen || !*lenp ||
2328 (*ppos && !write)) {
2333 i = (int *) tbl_data;
2334 vleft = table->maxlen / sizeof(*i);
2338 conv = do_proc_dointvec_conv;
2340 for (; left && vleft--; i++, first=0) {
2355 if (len > sizeof(buf) - 1)
2356 len = sizeof(buf) - 1;
2357 if (copy_from_user(buf, s, len))
2361 if (*p == '-' && left > 1) {
2365 if (*p < '0' || *p > '9')
2368 lval = simple_strtoul(p, &p, 0);
2371 if ((len < left) && *p && !isspace(*p))
2376 if (conv(&neg, &lval, i, 1, data))
2383 if (conv(&neg, &lval, i, 0, data))
2386 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2390 if(copy_to_user(s, buf, len))
2397 if (!write && !first && left) {
2398 if(put_user('\n', s))
2405 if (get_user(c, s++))
2420 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2421 void __user *buffer, size_t *lenp, loff_t *ppos,
2422 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2423 int write, void *data),
2426 return __do_proc_dointvec(table->data, table, write, filp,
2427 buffer, lenp, ppos, conv, data);
2431 * proc_dointvec - read a vector of integers
2432 * @table: the sysctl table
2433 * @write: %TRUE if this is a write to the sysctl file
2434 * @filp: the file structure
2435 * @buffer: the user buffer
2436 * @lenp: the size of the user buffer
2437 * @ppos: file position
2439 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2440 * values from/to the user buffer, treated as an ASCII string.
2442 * Returns 0 on success.
2444 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2445 void __user *buffer, size_t *lenp, loff_t *ppos)
2447 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2452 * Taint values can only be increased
2453 * This means we can safely use a temporary.
2455 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2456 void __user *buffer, size_t *lenp, loff_t *ppos)
2459 unsigned long tmptaint = get_taint();
2462 if (write && !capable(CAP_SYS_ADMIN))
2467 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2473 * Poor man's atomic or. Not worth adding a primitive
2474 * to everyone's atomic.h for this
2477 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2478 if ((tmptaint >> i) & 1)
2486 struct do_proc_dointvec_minmax_conv_param {
2491 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2493 int write, void *data)
2495 struct do_proc_dointvec_minmax_conv_param *param = data;
2497 int val = *negp ? -*lvalp : *lvalp;
2498 if ((param->min && *param->min > val) ||
2499 (param->max && *param->max < val))
2506 *lvalp = (unsigned long)-val;
2509 *lvalp = (unsigned long)val;
2516 * proc_dointvec_minmax - read a vector of integers with min/max values
2517 * @table: the sysctl table
2518 * @write: %TRUE if this is a write to the sysctl file
2519 * @filp: the file structure
2520 * @buffer: the user buffer
2521 * @lenp: the size of the user buffer
2522 * @ppos: file position
2524 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2525 * values from/to the user buffer, treated as an ASCII string.
2527 * This routine will ensure the values are within the range specified by
2528 * table->extra1 (min) and table->extra2 (max).
2530 * Returns 0 on success.
2532 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2533 void __user *buffer, size_t *lenp, loff_t *ppos)
2535 struct do_proc_dointvec_minmax_conv_param param = {
2536 .min = (int *) table->extra1,
2537 .max = (int *) table->extra2,
2539 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2540 do_proc_dointvec_minmax_conv, ¶m);
2543 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2545 void __user *buffer,
2546 size_t *lenp, loff_t *ppos,
2547 unsigned long convmul,
2548 unsigned long convdiv)
2550 #define TMPBUFLEN 21
2551 unsigned long *i, *min, *max, val;
2552 int vleft, first=1, neg;
2554 char buf[TMPBUFLEN], *p;
2555 char __user *s = buffer;
2557 if (!data || !table->maxlen || !*lenp ||
2558 (*ppos && !write)) {
2563 i = (unsigned long *) data;
2564 min = (unsigned long *) table->extra1;
2565 max = (unsigned long *) table->extra2;
2566 vleft = table->maxlen / sizeof(unsigned long);
2569 for (; left && vleft--; i++, min++, max++, first=0) {
2584 if (len > TMPBUFLEN-1)
2586 if (copy_from_user(buf, s, len))
2590 if (*p == '-' && left > 1) {
2594 if (*p < '0' || *p > '9')
2596 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2598 if ((len < left) && *p && !isspace(*p))
2607 if ((min && val < *min) || (max && val > *max))
2614 sprintf(p, "%lu", convdiv * (*i) / convmul);
2618 if(copy_to_user(s, buf, len))
2625 if (!write && !first && left) {
2626 if(put_user('\n', s))
2633 if (get_user(c, s++))
2648 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2650 void __user *buffer,
2651 size_t *lenp, loff_t *ppos,
2652 unsigned long convmul,
2653 unsigned long convdiv)
2655 return __do_proc_doulongvec_minmax(table->data, table, write,
2656 filp, buffer, lenp, ppos, convmul, convdiv);
2660 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2661 * @table: the sysctl table
2662 * @write: %TRUE if this is a write to the sysctl file
2663 * @filp: the file structure
2664 * @buffer: the user buffer
2665 * @lenp: the size of the user buffer
2666 * @ppos: file position
2668 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2669 * values from/to the user buffer, treated as an ASCII string.
2671 * This routine will ensure the values are within the range specified by
2672 * table->extra1 (min) and table->extra2 (max).
2674 * Returns 0 on success.
2676 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2677 void __user *buffer, size_t *lenp, loff_t *ppos)
2679 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2683 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2684 * @table: the sysctl table
2685 * @write: %TRUE if this is a write to the sysctl file
2686 * @filp: the file structure
2687 * @buffer: the user buffer
2688 * @lenp: the size of the user buffer
2689 * @ppos: file position
2691 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2692 * values from/to the user buffer, treated as an ASCII string. The values
2693 * are treated as milliseconds, and converted to jiffies when they are stored.
2695 * This routine will ensure the values are within the range specified by
2696 * table->extra1 (min) and table->extra2 (max).
2698 * Returns 0 on success.
2700 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2702 void __user *buffer,
2703 size_t *lenp, loff_t *ppos)
2705 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2706 lenp, ppos, HZ, 1000l);
2710 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2712 int write, void *data)
2715 if (*lvalp > LONG_MAX / HZ)
2717 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2723 lval = (unsigned long)-val;
2726 lval = (unsigned long)val;
2733 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2735 int write, void *data)
2738 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2740 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2746 lval = (unsigned long)-val;
2749 lval = (unsigned long)val;
2751 *lvalp = jiffies_to_clock_t(lval);
2756 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2758 int write, void *data)
2761 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2767 lval = (unsigned long)-val;
2770 lval = (unsigned long)val;
2772 *lvalp = jiffies_to_msecs(lval);
2778 * proc_dointvec_jiffies - read a vector of integers as seconds
2779 * @table: the sysctl table
2780 * @write: %TRUE if this is a write to the sysctl file
2781 * @filp: the file structure
2782 * @buffer: the user buffer
2783 * @lenp: the size of the user buffer
2784 * @ppos: file position
2786 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2787 * values from/to the user buffer, treated as an ASCII string.
2788 * The values read are assumed to be in seconds, and are converted into
2791 * Returns 0 on success.
2793 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2794 void __user *buffer, size_t *lenp, loff_t *ppos)
2796 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2797 do_proc_dointvec_jiffies_conv,NULL);
2801 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2802 * @table: the sysctl table
2803 * @write: %TRUE if this is a write to the sysctl file
2804 * @filp: the file structure
2805 * @buffer: the user buffer
2806 * @lenp: the size of the user buffer
2807 * @ppos: pointer to the file position
2809 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2810 * values from/to the user buffer, treated as an ASCII string.
2811 * The values read are assumed to be in 1/USER_HZ seconds, and
2812 * are converted into jiffies.
2814 * Returns 0 on success.
2816 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2817 void __user *buffer, size_t *lenp, loff_t *ppos)
2819 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2820 do_proc_dointvec_userhz_jiffies_conv,NULL);
2824 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2825 * @table: the sysctl table
2826 * @write: %TRUE if this is a write to the sysctl file
2827 * @filp: the file structure
2828 * @buffer: the user buffer
2829 * @lenp: the size of the user buffer
2830 * @ppos: file position
2831 * @ppos: the current position in the file
2833 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2834 * values from/to the user buffer, treated as an ASCII string.
2835 * The values read are assumed to be in 1/1000 seconds, and
2836 * are converted into jiffies.
2838 * Returns 0 on success.
2840 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2841 void __user *buffer, size_t *lenp, loff_t *ppos)
2843 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2844 do_proc_dointvec_ms_jiffies_conv, NULL);
2847 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2848 void __user *buffer, size_t *lenp, loff_t *ppos)
2850 struct pid *new_pid;
2854 tmp = pid_vnr(cad_pid);
2856 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2857 lenp, ppos, NULL, NULL);
2861 new_pid = find_get_pid(tmp);
2865 put_pid(xchg(&cad_pid, new_pid));
2869 #else /* CONFIG_PROC_FS */
2871 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2872 void __user *buffer, size_t *lenp, loff_t *ppos)
2877 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2878 void __user *buffer, size_t *lenp, loff_t *ppos)
2883 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2884 void __user *buffer, size_t *lenp, loff_t *ppos)
2889 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2890 void __user *buffer, size_t *lenp, loff_t *ppos)
2895 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2896 void __user *buffer, size_t *lenp, loff_t *ppos)
2901 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2902 void __user *buffer, size_t *lenp, loff_t *ppos)
2907 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2908 void __user *buffer, size_t *lenp, loff_t *ppos)
2913 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2915 void __user *buffer,
2916 size_t *lenp, loff_t *ppos)
2922 #endif /* CONFIG_PROC_FS */
2925 #ifdef CONFIG_SYSCTL_SYSCALL
2927 * General sysctl support routines
2930 /* The generic sysctl data routine (used if no strategy routine supplied) */
2931 int sysctl_data(struct ctl_table *table,
2932 void __user *oldval, size_t __user *oldlenp,
2933 void __user *newval, size_t newlen)
2937 /* Get out of I don't have a variable */
2938 if (!table->data || !table->maxlen)
2941 if (oldval && oldlenp) {
2942 if (get_user(len, oldlenp))
2945 if (len > table->maxlen)
2946 len = table->maxlen;
2947 if (copy_to_user(oldval, table->data, len))
2949 if (put_user(len, oldlenp))
2954 if (newval && newlen) {
2955 if (newlen > table->maxlen)
2956 newlen = table->maxlen;
2958 if (copy_from_user(table->data, newval, newlen))
2964 /* The generic string strategy routine: */
2965 int sysctl_string(struct ctl_table *table,
2966 void __user *oldval, size_t __user *oldlenp,
2967 void __user *newval, size_t newlen)
2969 if (!table->data || !table->maxlen)
2972 if (oldval && oldlenp) {
2974 if (get_user(bufsize, oldlenp))
2977 size_t len = strlen(table->data), copied;
2979 /* This shouldn't trigger for a well-formed sysctl */
2980 if (len > table->maxlen)
2981 len = table->maxlen;
2983 /* Copy up to a max of bufsize-1 bytes of the string */
2984 copied = (len >= bufsize) ? bufsize - 1 : len;
2986 if (copy_to_user(oldval, table->data, copied) ||
2987 put_user(0, (char __user *)(oldval + copied)))
2989 if (put_user(len, oldlenp))
2993 if (newval && newlen) {
2994 size_t len = newlen;
2995 if (len > table->maxlen)
2996 len = table->maxlen;
2997 if(copy_from_user(table->data, newval, len))
2999 if (len == table->maxlen)
3001 ((char *) table->data)[len] = 0;
3007 * This function makes sure that all of the integers in the vector
3008 * are between the minimum and maximum values given in the arrays
3009 * table->extra1 and table->extra2, respectively.
3011 int sysctl_intvec(struct ctl_table *table,
3012 void __user *oldval, size_t __user *oldlenp,
3013 void __user *newval, size_t newlen)
3016 if (newval && newlen) {
3017 int __user *vec = (int __user *) newval;
3018 int *min = (int *) table->extra1;
3019 int *max = (int *) table->extra2;
3023 if (newlen % sizeof(int) != 0)
3026 if (!table->extra1 && !table->extra2)
3029 if (newlen > table->maxlen)
3030 newlen = table->maxlen;
3031 length = newlen / sizeof(int);
3033 for (i = 0; i < length; i++) {
3035 if (get_user(value, vec + i))
3037 if (min && value < min[i])
3039 if (max && value > max[i])
3046 /* Strategy function to convert jiffies to seconds */
3047 int sysctl_jiffies(struct ctl_table *table,
3048 void __user *oldval, size_t __user *oldlenp,
3049 void __user *newval, size_t newlen)
3051 if (oldval && oldlenp) {
3054 if (get_user(olen, oldlenp))
3059 if (olen < sizeof(int))
3062 val = *(int *)(table->data) / HZ;
3063 if (put_user(val, (int __user *)oldval))
3065 if (put_user(sizeof(int), oldlenp))
3069 if (newval && newlen) {
3071 if (newlen != sizeof(int))
3073 if (get_user(new, (int __user *)newval))
3075 *(int *)(table->data) = new*HZ;
3080 /* Strategy function to convert jiffies to seconds */
3081 int sysctl_ms_jiffies(struct ctl_table *table,
3082 void __user *oldval, size_t __user *oldlenp,
3083 void __user *newval, size_t newlen)
3085 if (oldval && oldlenp) {
3088 if (get_user(olen, oldlenp))
3093 if (olen < sizeof(int))
3096 val = jiffies_to_msecs(*(int *)(table->data));
3097 if (put_user(val, (int __user *)oldval))
3099 if (put_user(sizeof(int), oldlenp))
3103 if (newval && newlen) {
3105 if (newlen != sizeof(int))
3107 if (get_user(new, (int __user *)newval))
3109 *(int *)(table->data) = msecs_to_jiffies(new);
3116 #else /* CONFIG_SYSCTL_SYSCALL */
3119 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3121 struct __sysctl_args tmp;
3124 if (copy_from_user(&tmp, args, sizeof(tmp)))
3127 error = deprecated_sysctl_warning(&tmp);
3129 /* If no error reading the parameters then just -ENOSYS ... */
3136 int sysctl_data(struct ctl_table *table,
3137 void __user *oldval, size_t __user *oldlenp,
3138 void __user *newval, size_t newlen)
3143 int sysctl_string(struct ctl_table *table,
3144 void __user *oldval, size_t __user *oldlenp,
3145 void __user *newval, size_t newlen)
3150 int sysctl_intvec(struct ctl_table *table,
3151 void __user *oldval, size_t __user *oldlenp,
3152 void __user *newval, size_t newlen)
3157 int sysctl_jiffies(struct ctl_table *table,
3158 void __user *oldval, size_t __user *oldlenp,
3159 void __user *newval, size_t newlen)
3164 int sysctl_ms_jiffies(struct ctl_table *table,
3165 void __user *oldval, size_t __user *oldlenp,
3166 void __user *newval, size_t newlen)
3171 #endif /* CONFIG_SYSCTL_SYSCALL */
3173 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3175 static int msg_count;
3176 int name[CTL_MAXNAME];
3179 /* Check args->nlen. */
3180 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3183 /* Read in the sysctl name for better debug message logging */
3184 for (i = 0; i < args->nlen; i++)
3185 if (get_user(name[i], args->name + i))
3188 /* Ignore accesses to kernel.version */
3189 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3192 if (msg_count < 5) {
3195 "warning: process `%s' used the deprecated sysctl "
3196 "system call with ", current->comm);
3197 for (i = 0; i < args->nlen; i++)
3198 printk("%d.", name[i]);
3205 * No sense putting this after each symbol definition, twice,
3206 * exception granted :-)
3208 EXPORT_SYMBOL(proc_dointvec);
3209 EXPORT_SYMBOL(proc_dointvec_jiffies);
3210 EXPORT_SYMBOL(proc_dointvec_minmax);
3211 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3212 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3213 EXPORT_SYMBOL(proc_dostring);
3214 EXPORT_SYMBOL(proc_doulongvec_minmax);
3215 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3216 EXPORT_SYMBOL(register_sysctl_table);
3217 EXPORT_SYMBOL(register_sysctl_paths);
3218 EXPORT_SYMBOL(sysctl_intvec);
3219 EXPORT_SYMBOL(sysctl_jiffies);
3220 EXPORT_SYMBOL(sysctl_ms_jiffies);
3221 EXPORT_SYMBOL(sysctl_string);
3222 EXPORT_SYMBOL(sysctl_data);
3223 EXPORT_SYMBOL(unregister_sysctl_table);