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/kmemcheck.h>
30 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
51 #include <linux/slow-work.h>
52 #include <linux/perf_event.h>
54 #include <asm/uaccess.h>
55 #include <asm/processor.h>
59 #include <asm/stacktrace.h>
63 static int deprecated_sysctl_warning(struct __sysctl_args *args);
65 #if defined(CONFIG_SYSCTL)
67 /* External variables not in a header file. */
69 extern int print_fatal_signals;
70 extern int sysctl_overcommit_memory;
71 extern int sysctl_overcommit_ratio;
72 extern int sysctl_panic_on_oom;
73 extern int sysctl_oom_kill_allocating_task;
74 extern int sysctl_oom_dump_tasks;
75 extern int max_threads;
76 extern int core_uses_pid;
77 extern int suid_dumpable;
78 extern char core_pattern[];
79 extern unsigned int core_pipe_limit;
81 extern int min_free_kbytes;
82 extern int min_free_order_shift;
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 static int ten_thousand = 10000;
114 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
115 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
117 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
118 static int maxolduid = 65535;
119 static int minolduid;
120 static int min_percpu_pagelist_fract = 8;
122 static int ngroups_max = NGROUPS_MAX;
124 #ifdef CONFIG_MODULES
125 extern char modprobe_path[];
126 extern int modules_disabled;
128 #ifdef CONFIG_CHR_DEV_SG
129 extern int sg_big_buff;
133 #include <asm/system.h>
136 #ifdef CONFIG_SPARC64
137 extern int sysctl_tsb_ratio;
141 extern int pwrsw_enabled;
142 extern int unaligned_enabled;
146 #ifdef CONFIG_MATHEMU
147 extern int sysctl_ieee_emulation_warnings;
149 extern int sysctl_userprocess_debug;
150 extern int spin_retry;
153 #ifdef CONFIG_BSD_PROCESS_ACCT
154 extern int acct_parm[];
158 extern int no_unaligned_warning;
159 extern int unaligned_dump_stack;
162 #ifdef CONFIG_RT_MUTEXES
163 extern int max_lock_depth;
166 #ifdef CONFIG_PROC_SYSCTL
167 static int proc_do_cad_pid(struct ctl_table *table, int write,
168 void __user *buffer, size_t *lenp, loff_t *ppos);
169 static int proc_taint(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
173 static struct ctl_table root_table[];
174 static struct ctl_table_root sysctl_table_root;
175 static struct ctl_table_header root_table_header = {
177 .ctl_table = root_table,
178 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
179 .root = &sysctl_table_root,
180 .set = &sysctl_table_root.default_set,
182 static struct ctl_table_root sysctl_table_root = {
183 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
184 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
187 static struct ctl_table kern_table[];
188 static struct ctl_table vm_table[];
189 static struct ctl_table fs_table[];
190 static struct ctl_table debug_table[];
191 static struct ctl_table dev_table[];
192 extern struct ctl_table random_table[];
193 #ifdef CONFIG_INOTIFY_USER
194 extern struct ctl_table inotify_table[];
197 extern struct ctl_table epoll_table[];
200 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
201 int sysctl_legacy_va_layout;
204 extern int prove_locking;
205 extern int lock_stat;
207 /* The default sysctl tables: */
209 static struct ctl_table root_table[] = {
211 .ctl_name = CTL_KERN,
212 .procname = "kernel",
229 .ctl_name = CTL_DEBUG,
232 .child = debug_table,
241 * NOTE: do not add new entries to this table unless you have read
242 * Documentation/sysctl/ctl_unnumbered.txt
247 #ifdef CONFIG_SCHED_DEBUG
248 static int min_sched_granularity_ns = 100000; /* 100 usecs */
249 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
250 static int min_wakeup_granularity_ns; /* 0 usecs */
251 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
254 static struct ctl_table kern_table[] = {
256 .ctl_name = CTL_UNNUMBERED,
257 .procname = "sched_child_runs_first",
258 .data = &sysctl_sched_child_runs_first,
259 .maxlen = sizeof(unsigned int),
261 .proc_handler = &proc_dointvec,
263 #ifdef CONFIG_SCHED_DEBUG
265 .ctl_name = CTL_UNNUMBERED,
266 .procname = "sched_min_granularity_ns",
267 .data = &sysctl_sched_min_granularity,
268 .maxlen = sizeof(unsigned int),
270 .proc_handler = &sched_nr_latency_handler,
271 .strategy = &sysctl_intvec,
272 .extra1 = &min_sched_granularity_ns,
273 .extra2 = &max_sched_granularity_ns,
276 .ctl_name = CTL_UNNUMBERED,
277 .procname = "sched_latency_ns",
278 .data = &sysctl_sched_latency,
279 .maxlen = sizeof(unsigned int),
281 .proc_handler = &sched_nr_latency_handler,
282 .strategy = &sysctl_intvec,
283 .extra1 = &min_sched_granularity_ns,
284 .extra2 = &max_sched_granularity_ns,
287 .ctl_name = CTL_UNNUMBERED,
288 .procname = "sched_wakeup_granularity_ns",
289 .data = &sysctl_sched_wakeup_granularity,
290 .maxlen = sizeof(unsigned int),
292 .proc_handler = &proc_dointvec_minmax,
293 .strategy = &sysctl_intvec,
294 .extra1 = &min_wakeup_granularity_ns,
295 .extra2 = &max_wakeup_granularity_ns,
298 .ctl_name = CTL_UNNUMBERED,
299 .procname = "sched_shares_ratelimit",
300 .data = &sysctl_sched_shares_ratelimit,
301 .maxlen = sizeof(unsigned int),
303 .proc_handler = &proc_dointvec,
306 .ctl_name = CTL_UNNUMBERED,
307 .procname = "sched_shares_thresh",
308 .data = &sysctl_sched_shares_thresh,
309 .maxlen = sizeof(unsigned int),
311 .proc_handler = &proc_dointvec_minmax,
312 .strategy = &sysctl_intvec,
316 .ctl_name = CTL_UNNUMBERED,
317 .procname = "sched_features",
318 .data = &sysctl_sched_features,
319 .maxlen = sizeof(unsigned int),
321 .proc_handler = &proc_dointvec,
324 .ctl_name = CTL_UNNUMBERED,
325 .procname = "sched_migration_cost",
326 .data = &sysctl_sched_migration_cost,
327 .maxlen = sizeof(unsigned int),
329 .proc_handler = &proc_dointvec,
332 .ctl_name = CTL_UNNUMBERED,
333 .procname = "sched_nr_migrate",
334 .data = &sysctl_sched_nr_migrate,
335 .maxlen = sizeof(unsigned int),
337 .proc_handler = &proc_dointvec,
340 .ctl_name = CTL_UNNUMBERED,
341 .procname = "sched_time_avg",
342 .data = &sysctl_sched_time_avg,
343 .maxlen = sizeof(unsigned int),
345 .proc_handler = &proc_dointvec,
348 .ctl_name = CTL_UNNUMBERED,
349 .procname = "timer_migration",
350 .data = &sysctl_timer_migration,
351 .maxlen = sizeof(unsigned int),
353 .proc_handler = &proc_dointvec_minmax,
354 .strategy = &sysctl_intvec,
360 .ctl_name = CTL_UNNUMBERED,
361 .procname = "sched_rt_period_us",
362 .data = &sysctl_sched_rt_period,
363 .maxlen = sizeof(unsigned int),
365 .proc_handler = &sched_rt_handler,
368 .ctl_name = CTL_UNNUMBERED,
369 .procname = "sched_rt_runtime_us",
370 .data = &sysctl_sched_rt_runtime,
371 .maxlen = sizeof(int),
373 .proc_handler = &sched_rt_handler,
376 .ctl_name = CTL_UNNUMBERED,
377 .procname = "sched_compat_yield",
378 .data = &sysctl_sched_compat_yield,
379 .maxlen = sizeof(unsigned int),
381 .proc_handler = &proc_dointvec,
383 #ifdef CONFIG_PROVE_LOCKING
385 .ctl_name = CTL_UNNUMBERED,
386 .procname = "prove_locking",
387 .data = &prove_locking,
388 .maxlen = sizeof(int),
390 .proc_handler = &proc_dointvec,
393 #ifdef CONFIG_LOCK_STAT
395 .ctl_name = CTL_UNNUMBERED,
396 .procname = "lock_stat",
398 .maxlen = sizeof(int),
400 .proc_handler = &proc_dointvec,
404 .ctl_name = KERN_PANIC,
406 .data = &panic_timeout,
407 .maxlen = sizeof(int),
409 .proc_handler = &proc_dointvec,
412 .ctl_name = KERN_CORE_USES_PID,
413 .procname = "core_uses_pid",
414 .data = &core_uses_pid,
415 .maxlen = sizeof(int),
417 .proc_handler = &proc_dointvec,
420 .ctl_name = KERN_CORE_PATTERN,
421 .procname = "core_pattern",
422 .data = core_pattern,
423 .maxlen = CORENAME_MAX_SIZE,
425 .proc_handler = &proc_dostring,
426 .strategy = &sysctl_string,
429 .ctl_name = CTL_UNNUMBERED,
430 .procname = "core_pipe_limit",
431 .data = &core_pipe_limit,
432 .maxlen = sizeof(unsigned int),
434 .proc_handler = &proc_dointvec,
436 #ifdef CONFIG_PROC_SYSCTL
438 .procname = "tainted",
439 .maxlen = sizeof(long),
441 .proc_handler = &proc_taint,
444 #ifdef CONFIG_LATENCYTOP
446 .procname = "latencytop",
447 .data = &latencytop_enabled,
448 .maxlen = sizeof(int),
450 .proc_handler = &proc_dointvec,
453 #ifdef CONFIG_BLK_DEV_INITRD
455 .ctl_name = KERN_REALROOTDEV,
456 .procname = "real-root-dev",
457 .data = &real_root_dev,
458 .maxlen = sizeof(int),
460 .proc_handler = &proc_dointvec,
464 .ctl_name = CTL_UNNUMBERED,
465 .procname = "print-fatal-signals",
466 .data = &print_fatal_signals,
467 .maxlen = sizeof(int),
469 .proc_handler = &proc_dointvec,
473 .ctl_name = KERN_SPARC_REBOOT,
474 .procname = "reboot-cmd",
475 .data = reboot_command,
478 .proc_handler = &proc_dostring,
479 .strategy = &sysctl_string,
482 .ctl_name = KERN_SPARC_STOP_A,
483 .procname = "stop-a",
484 .data = &stop_a_enabled,
485 .maxlen = sizeof (int),
487 .proc_handler = &proc_dointvec,
490 .ctl_name = KERN_SPARC_SCONS_PWROFF,
491 .procname = "scons-poweroff",
492 .data = &scons_pwroff,
493 .maxlen = sizeof (int),
495 .proc_handler = &proc_dointvec,
498 #ifdef CONFIG_SPARC64
500 .ctl_name = CTL_UNNUMBERED,
501 .procname = "tsb-ratio",
502 .data = &sysctl_tsb_ratio,
503 .maxlen = sizeof (int),
505 .proc_handler = &proc_dointvec,
510 .ctl_name = KERN_HPPA_PWRSW,
511 .procname = "soft-power",
512 .data = &pwrsw_enabled,
513 .maxlen = sizeof (int),
515 .proc_handler = &proc_dointvec,
518 .ctl_name = KERN_HPPA_UNALIGNED,
519 .procname = "unaligned-trap",
520 .data = &unaligned_enabled,
521 .maxlen = sizeof (int),
523 .proc_handler = &proc_dointvec,
527 .ctl_name = KERN_CTLALTDEL,
528 .procname = "ctrl-alt-del",
530 .maxlen = sizeof(int),
532 .proc_handler = &proc_dointvec,
534 #ifdef CONFIG_FUNCTION_TRACER
536 .ctl_name = CTL_UNNUMBERED,
537 .procname = "ftrace_enabled",
538 .data = &ftrace_enabled,
539 .maxlen = sizeof(int),
541 .proc_handler = &ftrace_enable_sysctl,
544 #ifdef CONFIG_STACK_TRACER
546 .ctl_name = CTL_UNNUMBERED,
547 .procname = "stack_tracer_enabled",
548 .data = &stack_tracer_enabled,
549 .maxlen = sizeof(int),
551 .proc_handler = &stack_trace_sysctl,
554 #ifdef CONFIG_TRACING
556 .ctl_name = CTL_UNNUMBERED,
557 .procname = "ftrace_dump_on_oops",
558 .data = &ftrace_dump_on_oops,
559 .maxlen = sizeof(int),
561 .proc_handler = &proc_dointvec,
564 #ifdef CONFIG_MODULES
566 .ctl_name = KERN_MODPROBE,
567 .procname = "modprobe",
568 .data = &modprobe_path,
569 .maxlen = KMOD_PATH_LEN,
571 .proc_handler = &proc_dostring,
572 .strategy = &sysctl_string,
575 .ctl_name = CTL_UNNUMBERED,
576 .procname = "modules_disabled",
577 .data = &modules_disabled,
578 .maxlen = sizeof(int),
580 /* only handle a transition from default "0" to "1" */
581 .proc_handler = &proc_dointvec_minmax,
586 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
588 .ctl_name = KERN_HOTPLUG,
589 .procname = "hotplug",
590 .data = &uevent_helper,
591 .maxlen = UEVENT_HELPER_PATH_LEN,
593 .proc_handler = &proc_dostring,
594 .strategy = &sysctl_string,
597 #ifdef CONFIG_CHR_DEV_SG
599 .ctl_name = KERN_SG_BIG_BUFF,
600 .procname = "sg-big-buff",
601 .data = &sg_big_buff,
602 .maxlen = sizeof (int),
604 .proc_handler = &proc_dointvec,
607 #ifdef CONFIG_BSD_PROCESS_ACCT
609 .ctl_name = KERN_ACCT,
612 .maxlen = 3*sizeof(int),
614 .proc_handler = &proc_dointvec,
617 #ifdef CONFIG_MAGIC_SYSRQ
619 .ctl_name = KERN_SYSRQ,
621 .data = &__sysrq_enabled,
622 .maxlen = sizeof (int),
624 .proc_handler = &proc_dointvec,
627 #ifdef CONFIG_PROC_SYSCTL
629 .procname = "cad_pid",
631 .maxlen = sizeof (int),
633 .proc_handler = &proc_do_cad_pid,
637 .ctl_name = KERN_MAX_THREADS,
638 .procname = "threads-max",
639 .data = &max_threads,
640 .maxlen = sizeof(int),
642 .proc_handler = &proc_dointvec,
645 .ctl_name = KERN_RANDOM,
646 .procname = "random",
648 .child = random_table,
651 .ctl_name = KERN_OVERFLOWUID,
652 .procname = "overflowuid",
653 .data = &overflowuid,
654 .maxlen = sizeof(int),
656 .proc_handler = &proc_dointvec_minmax,
657 .strategy = &sysctl_intvec,
658 .extra1 = &minolduid,
659 .extra2 = &maxolduid,
662 .ctl_name = KERN_OVERFLOWGID,
663 .procname = "overflowgid",
664 .data = &overflowgid,
665 .maxlen = sizeof(int),
667 .proc_handler = &proc_dointvec_minmax,
668 .strategy = &sysctl_intvec,
669 .extra1 = &minolduid,
670 .extra2 = &maxolduid,
673 #ifdef CONFIG_MATHEMU
675 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
676 .procname = "ieee_emulation_warnings",
677 .data = &sysctl_ieee_emulation_warnings,
678 .maxlen = sizeof(int),
680 .proc_handler = &proc_dointvec,
684 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
685 .procname = "userprocess_debug",
686 .data = &sysctl_userprocess_debug,
687 .maxlen = sizeof(int),
689 .proc_handler = &proc_dointvec,
693 .ctl_name = KERN_PIDMAX,
694 .procname = "pid_max",
696 .maxlen = sizeof (int),
698 .proc_handler = &proc_dointvec_minmax,
699 .strategy = sysctl_intvec,
700 .extra1 = &pid_max_min,
701 .extra2 = &pid_max_max,
704 .ctl_name = KERN_PANIC_ON_OOPS,
705 .procname = "panic_on_oops",
706 .data = &panic_on_oops,
707 .maxlen = sizeof(int),
709 .proc_handler = &proc_dointvec,
711 #if defined CONFIG_PRINTK
713 .ctl_name = KERN_PRINTK,
714 .procname = "printk",
715 .data = &console_loglevel,
716 .maxlen = 4*sizeof(int),
718 .proc_handler = &proc_dointvec,
721 .ctl_name = KERN_PRINTK_RATELIMIT,
722 .procname = "printk_ratelimit",
723 .data = &printk_ratelimit_state.interval,
724 .maxlen = sizeof(int),
726 .proc_handler = &proc_dointvec_jiffies,
727 .strategy = &sysctl_jiffies,
730 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
731 .procname = "printk_ratelimit_burst",
732 .data = &printk_ratelimit_state.burst,
733 .maxlen = sizeof(int),
735 .proc_handler = &proc_dointvec,
738 .ctl_name = CTL_UNNUMBERED,
739 .procname = "printk_delay",
740 .data = &printk_delay_msec,
741 .maxlen = sizeof(int),
743 .proc_handler = &proc_dointvec_minmax,
744 .strategy = &sysctl_intvec,
746 .extra2 = &ten_thousand,
750 .ctl_name = KERN_NGROUPS_MAX,
751 .procname = "ngroups_max",
752 .data = &ngroups_max,
753 .maxlen = sizeof (int),
755 .proc_handler = &proc_dointvec,
757 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
759 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
760 .procname = "unknown_nmi_panic",
761 .data = &unknown_nmi_panic,
762 .maxlen = sizeof (int),
764 .proc_handler = &proc_dointvec,
767 .procname = "nmi_watchdog",
768 .data = &nmi_watchdog_enabled,
769 .maxlen = sizeof (int),
771 .proc_handler = &proc_nmi_enabled,
774 #if defined(CONFIG_X86)
776 .ctl_name = KERN_PANIC_ON_NMI,
777 .procname = "panic_on_unrecovered_nmi",
778 .data = &panic_on_unrecovered_nmi,
779 .maxlen = sizeof(int),
781 .proc_handler = &proc_dointvec,
784 .ctl_name = CTL_UNNUMBERED,
785 .procname = "panic_on_io_nmi",
786 .data = &panic_on_io_nmi,
787 .maxlen = sizeof(int),
789 .proc_handler = &proc_dointvec,
792 .ctl_name = KERN_BOOTLOADER_TYPE,
793 .procname = "bootloader_type",
794 .data = &bootloader_type,
795 .maxlen = sizeof (int),
797 .proc_handler = &proc_dointvec,
800 .ctl_name = CTL_UNNUMBERED,
801 .procname = "bootloader_version",
802 .data = &bootloader_version,
803 .maxlen = sizeof (int),
805 .proc_handler = &proc_dointvec,
808 .ctl_name = CTL_UNNUMBERED,
809 .procname = "kstack_depth_to_print",
810 .data = &kstack_depth_to_print,
811 .maxlen = sizeof(int),
813 .proc_handler = &proc_dointvec,
816 .ctl_name = CTL_UNNUMBERED,
817 .procname = "io_delay_type",
818 .data = &io_delay_type,
819 .maxlen = sizeof(int),
821 .proc_handler = &proc_dointvec,
824 #if defined(CONFIG_MMU)
826 .ctl_name = KERN_RANDOMIZE,
827 .procname = "randomize_va_space",
828 .data = &randomize_va_space,
829 .maxlen = sizeof(int),
831 .proc_handler = &proc_dointvec,
834 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
836 .ctl_name = KERN_SPIN_RETRY,
837 .procname = "spin_retry",
839 .maxlen = sizeof (int),
841 .proc_handler = &proc_dointvec,
844 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
846 .procname = "acpi_video_flags",
847 .data = &acpi_realmode_flags,
848 .maxlen = sizeof (unsigned long),
850 .proc_handler = &proc_doulongvec_minmax,
855 .ctl_name = KERN_IA64_UNALIGNED,
856 .procname = "ignore-unaligned-usertrap",
857 .data = &no_unaligned_warning,
858 .maxlen = sizeof (int),
860 .proc_handler = &proc_dointvec,
863 .ctl_name = CTL_UNNUMBERED,
864 .procname = "unaligned-dump-stack",
865 .data = &unaligned_dump_stack,
866 .maxlen = sizeof (int),
868 .proc_handler = &proc_dointvec,
871 #ifdef CONFIG_DETECT_SOFTLOCKUP
873 .ctl_name = CTL_UNNUMBERED,
874 .procname = "softlockup_panic",
875 .data = &softlockup_panic,
876 .maxlen = sizeof(int),
878 .proc_handler = &proc_dointvec_minmax,
879 .strategy = &sysctl_intvec,
884 .ctl_name = CTL_UNNUMBERED,
885 .procname = "softlockup_thresh",
886 .data = &softlockup_thresh,
887 .maxlen = sizeof(int),
889 .proc_handler = &proc_dosoftlockup_thresh,
890 .strategy = &sysctl_intvec,
895 #ifdef CONFIG_DETECT_HUNG_TASK
897 .ctl_name = CTL_UNNUMBERED,
898 .procname = "hung_task_panic",
899 .data = &sysctl_hung_task_panic,
900 .maxlen = sizeof(int),
902 .proc_handler = &proc_dointvec_minmax,
903 .strategy = &sysctl_intvec,
908 .ctl_name = CTL_UNNUMBERED,
909 .procname = "hung_task_check_count",
910 .data = &sysctl_hung_task_check_count,
911 .maxlen = sizeof(unsigned long),
913 .proc_handler = &proc_doulongvec_minmax,
914 .strategy = &sysctl_intvec,
917 .ctl_name = CTL_UNNUMBERED,
918 .procname = "hung_task_timeout_secs",
919 .data = &sysctl_hung_task_timeout_secs,
920 .maxlen = sizeof(unsigned long),
922 .proc_handler = &proc_dohung_task_timeout_secs,
923 .strategy = &sysctl_intvec,
926 .ctl_name = CTL_UNNUMBERED,
927 .procname = "hung_task_warnings",
928 .data = &sysctl_hung_task_warnings,
929 .maxlen = sizeof(unsigned long),
931 .proc_handler = &proc_doulongvec_minmax,
932 .strategy = &sysctl_intvec,
937 .ctl_name = KERN_COMPAT_LOG,
938 .procname = "compat-log",
940 .maxlen = sizeof (int),
942 .proc_handler = &proc_dointvec,
945 #ifdef CONFIG_RT_MUTEXES
947 .ctl_name = KERN_MAX_LOCK_DEPTH,
948 .procname = "max_lock_depth",
949 .data = &max_lock_depth,
950 .maxlen = sizeof(int),
952 .proc_handler = &proc_dointvec,
956 .ctl_name = CTL_UNNUMBERED,
957 .procname = "poweroff_cmd",
958 .data = &poweroff_cmd,
959 .maxlen = POWEROFF_CMD_PATH_LEN,
961 .proc_handler = &proc_dostring,
962 .strategy = &sysctl_string,
966 .ctl_name = CTL_UNNUMBERED,
969 .child = key_sysctls,
972 #ifdef CONFIG_RCU_TORTURE_TEST
974 .ctl_name = CTL_UNNUMBERED,
975 .procname = "rcutorture_runnable",
976 .data = &rcutorture_runnable,
977 .maxlen = sizeof(int),
979 .proc_handler = &proc_dointvec,
982 #ifdef CONFIG_SLOW_WORK
984 .ctl_name = CTL_UNNUMBERED,
985 .procname = "slow-work",
987 .child = slow_work_sysctls,
990 #ifdef CONFIG_PERF_EVENTS
992 .ctl_name = CTL_UNNUMBERED,
993 .procname = "perf_event_paranoid",
994 .data = &sysctl_perf_event_paranoid,
995 .maxlen = sizeof(sysctl_perf_event_paranoid),
997 .proc_handler = &proc_dointvec,
1000 .ctl_name = CTL_UNNUMBERED,
1001 .procname = "perf_event_mlock_kb",
1002 .data = &sysctl_perf_event_mlock,
1003 .maxlen = sizeof(sysctl_perf_event_mlock),
1005 .proc_handler = &proc_dointvec,
1008 .ctl_name = CTL_UNNUMBERED,
1009 .procname = "perf_event_max_sample_rate",
1010 .data = &sysctl_perf_event_sample_rate,
1011 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1013 .proc_handler = &proc_dointvec,
1016 #ifdef CONFIG_KMEMCHECK
1018 .ctl_name = CTL_UNNUMBERED,
1019 .procname = "kmemcheck",
1020 .data = &kmemcheck_enabled,
1021 .maxlen = sizeof(int),
1023 .proc_handler = &proc_dointvec,
1028 .ctl_name = CTL_UNNUMBERED,
1029 .procname = "blk_iopoll",
1030 .data = &blk_iopoll_enabled,
1031 .maxlen = sizeof(int),
1033 .proc_handler = &proc_dointvec,
1037 * NOTE: do not add new entries to this table unless you have read
1038 * Documentation/sysctl/ctl_unnumbered.txt
1043 static struct ctl_table vm_table[] = {
1045 .ctl_name = VM_OVERCOMMIT_MEMORY,
1046 .procname = "overcommit_memory",
1047 .data = &sysctl_overcommit_memory,
1048 .maxlen = sizeof(sysctl_overcommit_memory),
1050 .proc_handler = &proc_dointvec,
1053 .ctl_name = VM_PANIC_ON_OOM,
1054 .procname = "panic_on_oom",
1055 .data = &sysctl_panic_on_oom,
1056 .maxlen = sizeof(sysctl_panic_on_oom),
1058 .proc_handler = &proc_dointvec,
1061 .ctl_name = CTL_UNNUMBERED,
1062 .procname = "oom_kill_allocating_task",
1063 .data = &sysctl_oom_kill_allocating_task,
1064 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1066 .proc_handler = &proc_dointvec,
1069 .ctl_name = CTL_UNNUMBERED,
1070 .procname = "oom_dump_tasks",
1071 .data = &sysctl_oom_dump_tasks,
1072 .maxlen = sizeof(sysctl_oom_dump_tasks),
1074 .proc_handler = &proc_dointvec,
1077 .ctl_name = VM_OVERCOMMIT_RATIO,
1078 .procname = "overcommit_ratio",
1079 .data = &sysctl_overcommit_ratio,
1080 .maxlen = sizeof(sysctl_overcommit_ratio),
1082 .proc_handler = &proc_dointvec,
1085 .ctl_name = VM_PAGE_CLUSTER,
1086 .procname = "page-cluster",
1087 .data = &page_cluster,
1088 .maxlen = sizeof(int),
1090 .proc_handler = &proc_dointvec,
1093 .ctl_name = VM_DIRTY_BACKGROUND,
1094 .procname = "dirty_background_ratio",
1095 .data = &dirty_background_ratio,
1096 .maxlen = sizeof(dirty_background_ratio),
1098 .proc_handler = &dirty_background_ratio_handler,
1099 .strategy = &sysctl_intvec,
1101 .extra2 = &one_hundred,
1104 .ctl_name = CTL_UNNUMBERED,
1105 .procname = "dirty_background_bytes",
1106 .data = &dirty_background_bytes,
1107 .maxlen = sizeof(dirty_background_bytes),
1109 .proc_handler = &dirty_background_bytes_handler,
1110 .strategy = &sysctl_intvec,
1114 .ctl_name = VM_DIRTY_RATIO,
1115 .procname = "dirty_ratio",
1116 .data = &vm_dirty_ratio,
1117 .maxlen = sizeof(vm_dirty_ratio),
1119 .proc_handler = &dirty_ratio_handler,
1120 .strategy = &sysctl_intvec,
1122 .extra2 = &one_hundred,
1125 .ctl_name = CTL_UNNUMBERED,
1126 .procname = "dirty_bytes",
1127 .data = &vm_dirty_bytes,
1128 .maxlen = sizeof(vm_dirty_bytes),
1130 .proc_handler = &dirty_bytes_handler,
1131 .strategy = &sysctl_intvec,
1132 .extra1 = &dirty_bytes_min,
1135 .procname = "dirty_writeback_centisecs",
1136 .data = &dirty_writeback_interval,
1137 .maxlen = sizeof(dirty_writeback_interval),
1139 .proc_handler = &dirty_writeback_centisecs_handler,
1142 .procname = "dirty_expire_centisecs",
1143 .data = &dirty_expire_interval,
1144 .maxlen = sizeof(dirty_expire_interval),
1146 .proc_handler = &proc_dointvec,
1149 .ctl_name = VM_NR_PDFLUSH_THREADS,
1150 .procname = "nr_pdflush_threads",
1151 .data = &nr_pdflush_threads,
1152 .maxlen = sizeof nr_pdflush_threads,
1153 .mode = 0444 /* read-only*/,
1154 .proc_handler = &proc_dointvec,
1157 .ctl_name = VM_SWAPPINESS,
1158 .procname = "swappiness",
1159 .data = &vm_swappiness,
1160 .maxlen = sizeof(vm_swappiness),
1162 .proc_handler = &proc_dointvec_minmax,
1163 .strategy = &sysctl_intvec,
1165 .extra2 = &one_hundred,
1167 #ifdef CONFIG_HUGETLB_PAGE
1169 .procname = "nr_hugepages",
1171 .maxlen = sizeof(unsigned long),
1173 .proc_handler = &hugetlb_sysctl_handler,
1174 .extra1 = (void *)&hugetlb_zero,
1175 .extra2 = (void *)&hugetlb_infinity,
1178 .ctl_name = VM_HUGETLB_GROUP,
1179 .procname = "hugetlb_shm_group",
1180 .data = &sysctl_hugetlb_shm_group,
1181 .maxlen = sizeof(gid_t),
1183 .proc_handler = &proc_dointvec,
1186 .ctl_name = CTL_UNNUMBERED,
1187 .procname = "hugepages_treat_as_movable",
1188 .data = &hugepages_treat_as_movable,
1189 .maxlen = sizeof(int),
1191 .proc_handler = &hugetlb_treat_movable_handler,
1194 .ctl_name = CTL_UNNUMBERED,
1195 .procname = "nr_overcommit_hugepages",
1197 .maxlen = sizeof(unsigned long),
1199 .proc_handler = &hugetlb_overcommit_handler,
1200 .extra1 = (void *)&hugetlb_zero,
1201 .extra2 = (void *)&hugetlb_infinity,
1205 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1206 .procname = "lowmem_reserve_ratio",
1207 .data = &sysctl_lowmem_reserve_ratio,
1208 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1210 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1211 .strategy = &sysctl_intvec,
1214 .ctl_name = VM_DROP_PAGECACHE,
1215 .procname = "drop_caches",
1216 .data = &sysctl_drop_caches,
1217 .maxlen = sizeof(int),
1219 .proc_handler = drop_caches_sysctl_handler,
1220 .strategy = &sysctl_intvec,
1223 .ctl_name = VM_MIN_FREE_KBYTES,
1224 .procname = "min_free_kbytes",
1225 .data = &min_free_kbytes,
1226 .maxlen = sizeof(min_free_kbytes),
1228 .proc_handler = &min_free_kbytes_sysctl_handler,
1229 .strategy = &sysctl_intvec,
1233 .ctl_name = CTL_UNNUMBERED,
1234 .procname = "min_free_order_shift",
1235 .data = &min_free_order_shift,
1236 .maxlen = sizeof(min_free_order_shift),
1238 .proc_handler = &proc_dointvec
1241 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1242 .procname = "percpu_pagelist_fraction",
1243 .data = &percpu_pagelist_fraction,
1244 .maxlen = sizeof(percpu_pagelist_fraction),
1246 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1247 .strategy = &sysctl_intvec,
1248 .extra1 = &min_percpu_pagelist_fract,
1252 .ctl_name = VM_MAX_MAP_COUNT,
1253 .procname = "max_map_count",
1254 .data = &sysctl_max_map_count,
1255 .maxlen = sizeof(sysctl_max_map_count),
1257 .proc_handler = &proc_dointvec
1261 .ctl_name = CTL_UNNUMBERED,
1262 .procname = "nr_trim_pages",
1263 .data = &sysctl_nr_trim_pages,
1264 .maxlen = sizeof(sysctl_nr_trim_pages),
1266 .proc_handler = &proc_dointvec_minmax,
1267 .strategy = &sysctl_intvec,
1272 .ctl_name = VM_LAPTOP_MODE,
1273 .procname = "laptop_mode",
1274 .data = &laptop_mode,
1275 .maxlen = sizeof(laptop_mode),
1277 .proc_handler = &proc_dointvec_jiffies,
1278 .strategy = &sysctl_jiffies,
1281 .ctl_name = VM_BLOCK_DUMP,
1282 .procname = "block_dump",
1283 .data = &block_dump,
1284 .maxlen = sizeof(block_dump),
1286 .proc_handler = &proc_dointvec,
1287 .strategy = &sysctl_intvec,
1291 .ctl_name = VM_VFS_CACHE_PRESSURE,
1292 .procname = "vfs_cache_pressure",
1293 .data = &sysctl_vfs_cache_pressure,
1294 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1296 .proc_handler = &proc_dointvec,
1297 .strategy = &sysctl_intvec,
1300 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1302 .ctl_name = VM_LEGACY_VA_LAYOUT,
1303 .procname = "legacy_va_layout",
1304 .data = &sysctl_legacy_va_layout,
1305 .maxlen = sizeof(sysctl_legacy_va_layout),
1307 .proc_handler = &proc_dointvec,
1308 .strategy = &sysctl_intvec,
1314 .ctl_name = VM_ZONE_RECLAIM_MODE,
1315 .procname = "zone_reclaim_mode",
1316 .data = &zone_reclaim_mode,
1317 .maxlen = sizeof(zone_reclaim_mode),
1319 .proc_handler = &proc_dointvec,
1320 .strategy = &sysctl_intvec,
1324 .ctl_name = VM_MIN_UNMAPPED,
1325 .procname = "min_unmapped_ratio",
1326 .data = &sysctl_min_unmapped_ratio,
1327 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1329 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1330 .strategy = &sysctl_intvec,
1332 .extra2 = &one_hundred,
1335 .ctl_name = VM_MIN_SLAB,
1336 .procname = "min_slab_ratio",
1337 .data = &sysctl_min_slab_ratio,
1338 .maxlen = sizeof(sysctl_min_slab_ratio),
1340 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1341 .strategy = &sysctl_intvec,
1343 .extra2 = &one_hundred,
1348 .ctl_name = CTL_UNNUMBERED,
1349 .procname = "stat_interval",
1350 .data = &sysctl_stat_interval,
1351 .maxlen = sizeof(sysctl_stat_interval),
1353 .proc_handler = &proc_dointvec_jiffies,
1354 .strategy = &sysctl_jiffies,
1359 .ctl_name = CTL_UNNUMBERED,
1360 .procname = "mmap_min_addr",
1361 .data = &dac_mmap_min_addr,
1362 .maxlen = sizeof(unsigned long),
1364 .proc_handler = &mmap_min_addr_handler,
1369 .ctl_name = CTL_UNNUMBERED,
1370 .procname = "numa_zonelist_order",
1371 .data = &numa_zonelist_order,
1372 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1374 .proc_handler = &numa_zonelist_order_handler,
1375 .strategy = &sysctl_string,
1378 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1379 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1381 .ctl_name = VM_VDSO_ENABLED,
1382 .procname = "vdso_enabled",
1383 .data = &vdso_enabled,
1384 .maxlen = sizeof(vdso_enabled),
1386 .proc_handler = &proc_dointvec,
1387 .strategy = &sysctl_intvec,
1391 #ifdef CONFIG_HIGHMEM
1393 .ctl_name = CTL_UNNUMBERED,
1394 .procname = "highmem_is_dirtyable",
1395 .data = &vm_highmem_is_dirtyable,
1396 .maxlen = sizeof(vm_highmem_is_dirtyable),
1398 .proc_handler = &proc_dointvec_minmax,
1399 .strategy = &sysctl_intvec,
1405 .ctl_name = CTL_UNNUMBERED,
1406 .procname = "scan_unevictable_pages",
1407 .data = &scan_unevictable_pages,
1408 .maxlen = sizeof(scan_unevictable_pages),
1410 .proc_handler = &scan_unevictable_handler,
1412 #ifdef CONFIG_MEMORY_FAILURE
1414 .ctl_name = CTL_UNNUMBERED,
1415 .procname = "memory_failure_early_kill",
1416 .data = &sysctl_memory_failure_early_kill,
1417 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1419 .proc_handler = &proc_dointvec_minmax,
1420 .strategy = &sysctl_intvec,
1425 .ctl_name = CTL_UNNUMBERED,
1426 .procname = "memory_failure_recovery",
1427 .data = &sysctl_memory_failure_recovery,
1428 .maxlen = sizeof(sysctl_memory_failure_recovery),
1430 .proc_handler = &proc_dointvec_minmax,
1431 .strategy = &sysctl_intvec,
1438 * NOTE: do not add new entries to this table unless you have read
1439 * Documentation/sysctl/ctl_unnumbered.txt
1444 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1445 static struct ctl_table binfmt_misc_table[] = {
1450 static struct ctl_table fs_table[] = {
1452 .ctl_name = FS_NRINODE,
1453 .procname = "inode-nr",
1454 .data = &inodes_stat,
1455 .maxlen = 2*sizeof(int),
1457 .proc_handler = &proc_dointvec,
1460 .ctl_name = FS_STATINODE,
1461 .procname = "inode-state",
1462 .data = &inodes_stat,
1463 .maxlen = 7*sizeof(int),
1465 .proc_handler = &proc_dointvec,
1468 .procname = "file-nr",
1469 .data = &files_stat,
1470 .maxlen = 3*sizeof(int),
1472 .proc_handler = &proc_nr_files,
1475 .ctl_name = FS_MAXFILE,
1476 .procname = "file-max",
1477 .data = &files_stat.max_files,
1478 .maxlen = sizeof(int),
1480 .proc_handler = &proc_dointvec,
1483 .ctl_name = CTL_UNNUMBERED,
1484 .procname = "nr_open",
1485 .data = &sysctl_nr_open,
1486 .maxlen = sizeof(int),
1488 .proc_handler = &proc_dointvec_minmax,
1489 .extra1 = &sysctl_nr_open_min,
1490 .extra2 = &sysctl_nr_open_max,
1493 .ctl_name = FS_DENTRY,
1494 .procname = "dentry-state",
1495 .data = &dentry_stat,
1496 .maxlen = 6*sizeof(int),
1498 .proc_handler = &proc_dointvec,
1501 .ctl_name = FS_OVERFLOWUID,
1502 .procname = "overflowuid",
1503 .data = &fs_overflowuid,
1504 .maxlen = sizeof(int),
1506 .proc_handler = &proc_dointvec_minmax,
1507 .strategy = &sysctl_intvec,
1508 .extra1 = &minolduid,
1509 .extra2 = &maxolduid,
1512 .ctl_name = FS_OVERFLOWGID,
1513 .procname = "overflowgid",
1514 .data = &fs_overflowgid,
1515 .maxlen = sizeof(int),
1517 .proc_handler = &proc_dointvec_minmax,
1518 .strategy = &sysctl_intvec,
1519 .extra1 = &minolduid,
1520 .extra2 = &maxolduid,
1522 #ifdef CONFIG_FILE_LOCKING
1524 .ctl_name = FS_LEASES,
1525 .procname = "leases-enable",
1526 .data = &leases_enable,
1527 .maxlen = sizeof(int),
1529 .proc_handler = &proc_dointvec,
1532 #ifdef CONFIG_DNOTIFY
1534 .ctl_name = FS_DIR_NOTIFY,
1535 .procname = "dir-notify-enable",
1536 .data = &dir_notify_enable,
1537 .maxlen = sizeof(int),
1539 .proc_handler = &proc_dointvec,
1543 #ifdef CONFIG_FILE_LOCKING
1545 .ctl_name = FS_LEASE_TIME,
1546 .procname = "lease-break-time",
1547 .data = &lease_break_time,
1548 .maxlen = sizeof(int),
1550 .proc_handler = &proc_dointvec,
1555 .procname = "aio-nr",
1557 .maxlen = sizeof(aio_nr),
1559 .proc_handler = &proc_doulongvec_minmax,
1562 .procname = "aio-max-nr",
1563 .data = &aio_max_nr,
1564 .maxlen = sizeof(aio_max_nr),
1566 .proc_handler = &proc_doulongvec_minmax,
1568 #endif /* CONFIG_AIO */
1569 #ifdef CONFIG_INOTIFY_USER
1571 .ctl_name = FS_INOTIFY,
1572 .procname = "inotify",
1574 .child = inotify_table,
1579 .procname = "epoll",
1581 .child = epoll_table,
1586 .ctl_name = KERN_SETUID_DUMPABLE,
1587 .procname = "suid_dumpable",
1588 .data = &suid_dumpable,
1589 .maxlen = sizeof(int),
1591 .proc_handler = &proc_dointvec_minmax,
1592 .strategy = &sysctl_intvec,
1596 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1598 .ctl_name = CTL_UNNUMBERED,
1599 .procname = "binfmt_misc",
1601 .child = binfmt_misc_table,
1605 * NOTE: do not add new entries to this table unless you have read
1606 * Documentation/sysctl/ctl_unnumbered.txt
1611 static struct ctl_table debug_table[] = {
1612 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1614 .ctl_name = CTL_UNNUMBERED,
1615 .procname = "exception-trace",
1616 .data = &show_unhandled_signals,
1617 .maxlen = sizeof(int),
1619 .proc_handler = proc_dointvec_minmax,
1626 static struct ctl_table dev_table[] = {
1630 static DEFINE_SPINLOCK(sysctl_lock);
1632 /* called under sysctl_lock */
1633 static int use_table(struct ctl_table_header *p)
1635 if (unlikely(p->unregistering))
1641 /* called under sysctl_lock */
1642 static void unuse_table(struct ctl_table_header *p)
1645 if (unlikely(p->unregistering))
1646 complete(p->unregistering);
1649 /* called under sysctl_lock, will reacquire if has to wait */
1650 static void start_unregistering(struct ctl_table_header *p)
1653 * if p->used is 0, nobody will ever touch that entry again;
1654 * we'll eliminate all paths to it before dropping sysctl_lock
1656 if (unlikely(p->used)) {
1657 struct completion wait;
1658 init_completion(&wait);
1659 p->unregistering = &wait;
1660 spin_unlock(&sysctl_lock);
1661 wait_for_completion(&wait);
1662 spin_lock(&sysctl_lock);
1664 /* anything non-NULL; we'll never dereference it */
1665 p->unregistering = ERR_PTR(-EINVAL);
1668 * do not remove from the list until nobody holds it; walking the
1669 * list in do_sysctl() relies on that.
1671 list_del_init(&p->ctl_entry);
1674 void sysctl_head_get(struct ctl_table_header *head)
1676 spin_lock(&sysctl_lock);
1678 spin_unlock(&sysctl_lock);
1681 void sysctl_head_put(struct ctl_table_header *head)
1683 spin_lock(&sysctl_lock);
1686 spin_unlock(&sysctl_lock);
1689 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1693 spin_lock(&sysctl_lock);
1694 if (!use_table(head))
1695 head = ERR_PTR(-ENOENT);
1696 spin_unlock(&sysctl_lock);
1700 void sysctl_head_finish(struct ctl_table_header *head)
1704 spin_lock(&sysctl_lock);
1706 spin_unlock(&sysctl_lock);
1709 static struct ctl_table_set *
1710 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1712 struct ctl_table_set *set = &root->default_set;
1714 set = root->lookup(root, namespaces);
1718 static struct list_head *
1719 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1721 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1725 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1726 struct ctl_table_header *prev)
1728 struct ctl_table_root *root;
1729 struct list_head *header_list;
1730 struct ctl_table_header *head;
1731 struct list_head *tmp;
1733 spin_lock(&sysctl_lock);
1736 tmp = &prev->ctl_entry;
1740 tmp = &root_table_header.ctl_entry;
1742 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1744 if (!use_table(head))
1746 spin_unlock(&sysctl_lock);
1751 header_list = lookup_header_list(root, namespaces);
1752 if (tmp != header_list)
1756 root = list_entry(root->root_list.next,
1757 struct ctl_table_root, root_list);
1758 if (root == &sysctl_table_root)
1760 header_list = lookup_header_list(root, namespaces);
1761 } while (list_empty(header_list));
1762 tmp = header_list->next;
1765 spin_unlock(&sysctl_lock);
1769 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1771 return __sysctl_head_next(current->nsproxy, prev);
1774 void register_sysctl_root(struct ctl_table_root *root)
1776 spin_lock(&sysctl_lock);
1777 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1778 spin_unlock(&sysctl_lock);
1781 #ifdef CONFIG_SYSCTL_SYSCALL
1782 /* Perform the actual read/write of a sysctl table entry. */
1783 static int do_sysctl_strategy(struct ctl_table_root *root,
1784 struct ctl_table *table,
1785 void __user *oldval, size_t __user *oldlenp,
1786 void __user *newval, size_t newlen)
1794 if (sysctl_perm(root, table, op))
1797 if (table->strategy) {
1798 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1805 /* If there is no strategy routine, or if the strategy returns
1806 * zero, proceed with automatic r/w */
1807 if (table->data && table->maxlen) {
1808 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1815 static int parse_table(int __user *name, int nlen,
1816 void __user *oldval, size_t __user *oldlenp,
1817 void __user *newval, size_t newlen,
1818 struct ctl_table_root *root,
1819 struct ctl_table *table)
1825 if (get_user(n, name))
1827 for ( ; table->ctl_name || table->procname; table++) {
1828 if (!table->ctl_name)
1830 if (n == table->ctl_name) {
1833 if (sysctl_perm(root, table, MAY_EXEC))
1837 table = table->child;
1840 error = do_sysctl_strategy(root, table,
1849 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1850 void __user *newval, size_t newlen)
1852 struct ctl_table_header *head;
1853 int error = -ENOTDIR;
1855 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1859 if (!oldlenp || get_user(old_len, oldlenp))
1863 for (head = sysctl_head_next(NULL); head;
1864 head = sysctl_head_next(head)) {
1865 error = parse_table(name, nlen, oldval, oldlenp,
1867 head->root, head->ctl_table);
1868 if (error != -ENOTDIR) {
1869 sysctl_head_finish(head);
1876 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1878 struct __sysctl_args tmp;
1881 if (copy_from_user(&tmp, args, sizeof(tmp)))
1884 error = deprecated_sysctl_warning(&tmp);
1889 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1890 tmp.newval, tmp.newlen);
1895 #endif /* CONFIG_SYSCTL_SYSCALL */
1898 * sysctl_perm does NOT grant the superuser all rights automatically, because
1899 * some sysctl variables are readonly even to root.
1902 static int test_perm(int mode, int op)
1904 if (!current_euid())
1906 else if (in_egroup_p(0))
1908 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1913 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1918 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1922 if (root->permissions)
1923 mode = root->permissions(root, current->nsproxy, table);
1927 return test_perm(mode, op);
1930 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1932 for (; table->ctl_name || table->procname; table++) {
1933 table->parent = parent;
1935 sysctl_set_parent(table, table->child);
1939 static __init int sysctl_init(void)
1941 sysctl_set_parent(NULL, root_table);
1942 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1945 err = sysctl_check_table(current->nsproxy, root_table);
1951 core_initcall(sysctl_init);
1953 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1954 struct ctl_table *table)
1956 struct ctl_table *p;
1957 const char *s = branch->procname;
1959 /* branch should have named subdirectory as its first element */
1960 if (!s || !branch->child)
1963 /* ... and nothing else */
1964 if (branch[1].procname || branch[1].ctl_name)
1967 /* table should contain subdirectory with the same name */
1968 for (p = table; p->procname || p->ctl_name; p++) {
1971 if (p->procname && strcmp(p->procname, s) == 0)
1977 /* see if attaching q to p would be an improvement */
1978 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1980 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1981 struct ctl_table *next;
1983 int not_in_parent = !p->attached_by;
1985 while ((next = is_branch_in(by, to)) != NULL) {
1986 if (by == q->attached_by)
1988 if (to == p->attached_by)
1994 if (is_better && not_in_parent) {
1995 q->attached_by = by;
1996 q->attached_to = to;
2002 * __register_sysctl_paths - register a sysctl hierarchy
2003 * @root: List of sysctl headers to register on
2004 * @namespaces: Data to compute which lists of sysctl entries are visible
2005 * @path: The path to the directory the sysctl table is in.
2006 * @table: the top-level table structure
2008 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2009 * array. A completely 0 filled entry terminates the table.
2011 * The members of the &struct ctl_table structure are used as follows:
2013 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
2014 * must be unique within that level of sysctl
2016 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
2017 * enter a sysctl file
2019 * data - a pointer to data for use by proc_handler
2021 * maxlen - the maximum size in bytes of the data
2023 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
2025 * child - a pointer to the child sysctl table if this entry is a directory, or
2028 * proc_handler - the text handler routine (described below)
2030 * strategy - the strategy routine (described below)
2032 * de - for internal use by the sysctl routines
2034 * extra1, extra2 - extra pointers usable by the proc handler routines
2036 * Leaf nodes in the sysctl tree will be represented by a single file
2037 * under /proc; non-leaf nodes will be represented by directories.
2039 * sysctl(2) can automatically manage read and write requests through
2040 * the sysctl table. The data and maxlen fields of the ctl_table
2041 * struct enable minimal validation of the values being written to be
2042 * performed, and the mode field allows minimal authentication.
2044 * More sophisticated management can be enabled by the provision of a
2045 * strategy routine with the table entry. This will be called before
2046 * any automatic read or write of the data is performed.
2048 * The strategy routine may return
2050 * < 0 - Error occurred (error is passed to user process)
2052 * 0 - OK - proceed with automatic read or write.
2054 * > 0 - OK - read or write has been done by the strategy routine, so
2055 * return immediately.
2057 * There must be a proc_handler routine for any terminal nodes
2058 * mirrored under /proc/sys (non-terminals are handled by a built-in
2059 * directory handler). Several default handlers are available to
2060 * cover common cases -
2062 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2063 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2064 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2066 * It is the handler's job to read the input buffer from user memory
2067 * and process it. The handler should return 0 on success.
2069 * This routine returns %NULL on a failure to register, and a pointer
2070 * to the table header on success.
2072 struct ctl_table_header *__register_sysctl_paths(
2073 struct ctl_table_root *root,
2074 struct nsproxy *namespaces,
2075 const struct ctl_path *path, struct ctl_table *table)
2077 struct ctl_table_header *header;
2078 struct ctl_table *new, **prevp;
2079 unsigned int n, npath;
2080 struct ctl_table_set *set;
2082 /* Count the path components */
2083 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2087 * For each path component, allocate a 2-element ctl_table array.
2088 * The first array element will be filled with the sysctl entry
2089 * for this, the second will be the sentinel (ctl_name == 0).
2091 * We allocate everything in one go so that we don't have to
2092 * worry about freeing additional memory in unregister_sysctl_table.
2094 header = kzalloc(sizeof(struct ctl_table_header) +
2095 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2099 new = (struct ctl_table *) (header + 1);
2101 /* Now connect the dots */
2102 prevp = &header->ctl_table;
2103 for (n = 0; n < npath; ++n, ++path) {
2104 /* Copy the procname */
2105 new->procname = path->procname;
2106 new->ctl_name = path->ctl_name;
2110 prevp = &new->child;
2115 header->ctl_table_arg = table;
2117 INIT_LIST_HEAD(&header->ctl_entry);
2119 header->unregistering = NULL;
2120 header->root = root;
2121 sysctl_set_parent(NULL, header->ctl_table);
2123 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2124 if (sysctl_check_table(namespaces, header->ctl_table)) {
2129 spin_lock(&sysctl_lock);
2130 header->set = lookup_header_set(root, namespaces);
2131 header->attached_by = header->ctl_table;
2132 header->attached_to = root_table;
2133 header->parent = &root_table_header;
2134 for (set = header->set; set; set = set->parent) {
2135 struct ctl_table_header *p;
2136 list_for_each_entry(p, &set->list, ctl_entry) {
2137 if (p->unregistering)
2139 try_attach(p, header);
2142 header->parent->count++;
2143 list_add_tail(&header->ctl_entry, &header->set->list);
2144 spin_unlock(&sysctl_lock);
2150 * register_sysctl_table_path - register a sysctl table hierarchy
2151 * @path: The path to the directory the sysctl table is in.
2152 * @table: the top-level table structure
2154 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2155 * array. A completely 0 filled entry terminates the table.
2157 * See __register_sysctl_paths for more details.
2159 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2160 struct ctl_table *table)
2162 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2167 * register_sysctl_table - register a sysctl table hierarchy
2168 * @table: the top-level table structure
2170 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2171 * array. A completely 0 filled entry terminates the table.
2173 * See register_sysctl_paths for more details.
2175 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2177 static const struct ctl_path null_path[] = { {} };
2179 return register_sysctl_paths(null_path, table);
2183 * unregister_sysctl_table - unregister a sysctl table hierarchy
2184 * @header: the header returned from register_sysctl_table
2186 * Unregisters the sysctl table and all children. proc entries may not
2187 * actually be removed until they are no longer used by anyone.
2189 void unregister_sysctl_table(struct ctl_table_header * header)
2196 spin_lock(&sysctl_lock);
2197 start_unregistering(header);
2198 if (!--header->parent->count) {
2200 kfree(header->parent);
2202 if (!--header->count)
2204 spin_unlock(&sysctl_lock);
2207 int sysctl_is_seen(struct ctl_table_header *p)
2209 struct ctl_table_set *set = p->set;
2211 spin_lock(&sysctl_lock);
2212 if (p->unregistering)
2214 else if (!set->is_seen)
2217 res = set->is_seen(set);
2218 spin_unlock(&sysctl_lock);
2222 void setup_sysctl_set(struct ctl_table_set *p,
2223 struct ctl_table_set *parent,
2224 int (*is_seen)(struct ctl_table_set *))
2226 INIT_LIST_HEAD(&p->list);
2227 p->parent = parent ? parent : &sysctl_table_root.default_set;
2228 p->is_seen = is_seen;
2231 #else /* !CONFIG_SYSCTL */
2232 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2237 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2238 struct ctl_table *table)
2243 void unregister_sysctl_table(struct ctl_table_header * table)
2247 void setup_sysctl_set(struct ctl_table_set *p,
2248 struct ctl_table_set *parent,
2249 int (*is_seen)(struct ctl_table_set *))
2253 void sysctl_head_put(struct ctl_table_header *head)
2257 #endif /* CONFIG_SYSCTL */
2263 #ifdef CONFIG_PROC_SYSCTL
2265 static int _proc_do_string(void* data, int maxlen, int write,
2266 void __user *buffer,
2267 size_t *lenp, loff_t *ppos)
2273 if (!data || !maxlen || !*lenp) {
2281 while (len < *lenp) {
2282 if (get_user(c, p++))
2284 if (c == 0 || c == '\n')
2290 if(copy_from_user(data, buffer, len))
2292 ((char *) data)[len] = 0;
2310 if(copy_to_user(buffer, data, len))
2313 if(put_user('\n', ((char __user *) buffer) + len))
2324 * proc_dostring - read a string sysctl
2325 * @table: the sysctl table
2326 * @write: %TRUE if this is a write to the sysctl file
2327 * @buffer: the user buffer
2328 * @lenp: the size of the user buffer
2329 * @ppos: file position
2331 * Reads/writes a string from/to the user buffer. If the kernel
2332 * buffer provided is not large enough to hold the string, the
2333 * string is truncated. The copied string is %NULL-terminated.
2334 * If the string is being read by the user process, it is copied
2335 * and a newline '\n' is added. It is truncated if the buffer is
2338 * Returns 0 on success.
2340 int proc_dostring(struct ctl_table *table, int write,
2341 void __user *buffer, size_t *lenp, loff_t *ppos)
2343 return _proc_do_string(table->data, table->maxlen, write,
2344 buffer, lenp, ppos);
2348 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2350 int write, void *data)
2353 *valp = *negp ? -*lvalp : *lvalp;
2358 *lvalp = (unsigned long)-val;
2361 *lvalp = (unsigned long)val;
2367 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2368 int write, void __user *buffer,
2369 size_t *lenp, loff_t *ppos,
2370 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2371 int write, void *data),
2374 #define TMPBUFLEN 21
2375 int *i, vleft, first = 1, neg;
2379 char buf[TMPBUFLEN], *p;
2380 char __user *s = buffer;
2382 if (!tbl_data || !table->maxlen || !*lenp ||
2383 (*ppos && !write)) {
2388 i = (int *) tbl_data;
2389 vleft = table->maxlen / sizeof(*i);
2393 conv = do_proc_dointvec_conv;
2395 for (; left && vleft--; i++, first=0) {
2410 if (len > sizeof(buf) - 1)
2411 len = sizeof(buf) - 1;
2412 if (copy_from_user(buf, s, len))
2416 if (*p == '-' && left > 1) {
2420 if (*p < '0' || *p > '9')
2423 lval = simple_strtoul(p, &p, 0);
2426 if ((len < left) && *p && !isspace(*p))
2431 if (conv(&neg, &lval, i, 1, data))
2438 if (conv(&neg, &lval, i, 0, data))
2441 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2445 if(copy_to_user(s, buf, len))
2452 if (!write && !first && left) {
2453 if(put_user('\n', s))
2460 if (get_user(c, s++))
2475 static int do_proc_dointvec(struct ctl_table *table, int write,
2476 void __user *buffer, size_t *lenp, loff_t *ppos,
2477 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2478 int write, void *data),
2481 return __do_proc_dointvec(table->data, table, write,
2482 buffer, lenp, ppos, conv, data);
2486 * proc_dointvec - read a vector of integers
2487 * @table: the sysctl table
2488 * @write: %TRUE if this is a write to the sysctl file
2489 * @buffer: the user buffer
2490 * @lenp: the size of the user buffer
2491 * @ppos: file position
2493 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2494 * values from/to the user buffer, treated as an ASCII string.
2496 * Returns 0 on success.
2498 int proc_dointvec(struct ctl_table *table, int write,
2499 void __user *buffer, size_t *lenp, loff_t *ppos)
2501 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2506 * Taint values can only be increased
2507 * This means we can safely use a temporary.
2509 static int proc_taint(struct ctl_table *table, int write,
2510 void __user *buffer, size_t *lenp, loff_t *ppos)
2513 unsigned long tmptaint = get_taint();
2516 if (write && !capable(CAP_SYS_ADMIN))
2521 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2527 * Poor man's atomic or. Not worth adding a primitive
2528 * to everyone's atomic.h for this
2531 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2532 if ((tmptaint >> i) & 1)
2540 struct do_proc_dointvec_minmax_conv_param {
2545 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2547 int write, void *data)
2549 struct do_proc_dointvec_minmax_conv_param *param = data;
2551 int val = *negp ? -*lvalp : *lvalp;
2552 if ((param->min && *param->min > val) ||
2553 (param->max && *param->max < val))
2560 *lvalp = (unsigned long)-val;
2563 *lvalp = (unsigned long)val;
2570 * proc_dointvec_minmax - read a vector of integers with min/max values
2571 * @table: the sysctl table
2572 * @write: %TRUE if this is a write to the sysctl file
2573 * @buffer: the user buffer
2574 * @lenp: the size of the user buffer
2575 * @ppos: file position
2577 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2578 * values from/to the user buffer, treated as an ASCII string.
2580 * This routine will ensure the values are within the range specified by
2581 * table->extra1 (min) and table->extra2 (max).
2583 * Returns 0 on success.
2585 int proc_dointvec_minmax(struct ctl_table *table, int write,
2586 void __user *buffer, size_t *lenp, loff_t *ppos)
2588 struct do_proc_dointvec_minmax_conv_param param = {
2589 .min = (int *) table->extra1,
2590 .max = (int *) table->extra2,
2592 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2593 do_proc_dointvec_minmax_conv, ¶m);
2596 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2597 void __user *buffer,
2598 size_t *lenp, loff_t *ppos,
2599 unsigned long convmul,
2600 unsigned long convdiv)
2602 #define TMPBUFLEN 21
2603 unsigned long *i, *min, *max, val;
2604 int vleft, first=1, neg;
2606 char buf[TMPBUFLEN], *p;
2607 char __user *s = buffer;
2609 if (!data || !table->maxlen || !*lenp ||
2610 (*ppos && !write)) {
2615 i = (unsigned long *) data;
2616 min = (unsigned long *) table->extra1;
2617 max = (unsigned long *) table->extra2;
2618 vleft = table->maxlen / sizeof(unsigned long);
2621 for (; left && vleft--; i++, min++, max++, first=0) {
2636 if (len > TMPBUFLEN-1)
2638 if (copy_from_user(buf, s, len))
2642 if (*p == '-' && left > 1) {
2646 if (*p < '0' || *p > '9')
2648 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2650 if ((len < left) && *p && !isspace(*p))
2659 if ((min && val < *min) || (max && val > *max))
2666 sprintf(p, "%lu", convdiv * (*i) / convmul);
2670 if(copy_to_user(s, buf, len))
2677 if (!write && !first && left) {
2678 if(put_user('\n', s))
2685 if (get_user(c, s++))
2700 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2701 void __user *buffer,
2702 size_t *lenp, loff_t *ppos,
2703 unsigned long convmul,
2704 unsigned long convdiv)
2706 return __do_proc_doulongvec_minmax(table->data, table, write,
2707 buffer, lenp, ppos, convmul, convdiv);
2711 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2712 * @table: the sysctl table
2713 * @write: %TRUE if this is a write to the sysctl file
2714 * @buffer: the user buffer
2715 * @lenp: the size of the user buffer
2716 * @ppos: file position
2718 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2719 * values from/to the user buffer, treated as an ASCII string.
2721 * This routine will ensure the values are within the range specified by
2722 * table->extra1 (min) and table->extra2 (max).
2724 * Returns 0 on success.
2726 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2727 void __user *buffer, size_t *lenp, loff_t *ppos)
2729 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2733 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2734 * @table: the sysctl table
2735 * @write: %TRUE if this is a write to the sysctl file
2736 * @buffer: the user buffer
2737 * @lenp: the size of the user buffer
2738 * @ppos: file position
2740 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2741 * values from/to the user buffer, treated as an ASCII string. The values
2742 * are treated as milliseconds, and converted to jiffies when they are stored.
2744 * This routine will ensure the values are within the range specified by
2745 * table->extra1 (min) and table->extra2 (max).
2747 * Returns 0 on success.
2749 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2750 void __user *buffer,
2751 size_t *lenp, loff_t *ppos)
2753 return do_proc_doulongvec_minmax(table, write, buffer,
2754 lenp, ppos, HZ, 1000l);
2758 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2760 int write, void *data)
2763 if (*lvalp > LONG_MAX / HZ)
2765 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2771 lval = (unsigned long)-val;
2774 lval = (unsigned long)val;
2781 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2783 int write, void *data)
2786 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2788 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2794 lval = (unsigned long)-val;
2797 lval = (unsigned long)val;
2799 *lvalp = jiffies_to_clock_t(lval);
2804 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2806 int write, void *data)
2809 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2815 lval = (unsigned long)-val;
2818 lval = (unsigned long)val;
2820 *lvalp = jiffies_to_msecs(lval);
2826 * proc_dointvec_jiffies - read a vector of integers as seconds
2827 * @table: the sysctl table
2828 * @write: %TRUE if this is a write to the sysctl file
2829 * @buffer: the user buffer
2830 * @lenp: the size of the user buffer
2831 * @ppos: file position
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 seconds, and are converted into
2838 * Returns 0 on success.
2840 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2841 void __user *buffer, size_t *lenp, loff_t *ppos)
2843 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2844 do_proc_dointvec_jiffies_conv,NULL);
2848 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2849 * @table: the sysctl table
2850 * @write: %TRUE if this is a write to the sysctl file
2851 * @buffer: the user buffer
2852 * @lenp: the size of the user buffer
2853 * @ppos: pointer to the file position
2855 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2856 * values from/to the user buffer, treated as an ASCII string.
2857 * The values read are assumed to be in 1/USER_HZ seconds, and
2858 * are converted into jiffies.
2860 * Returns 0 on success.
2862 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2863 void __user *buffer, size_t *lenp, loff_t *ppos)
2865 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2866 do_proc_dointvec_userhz_jiffies_conv,NULL);
2870 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2871 * @table: the sysctl table
2872 * @write: %TRUE if this is a write to the sysctl file
2873 * @buffer: the user buffer
2874 * @lenp: the size of the user buffer
2875 * @ppos: file position
2876 * @ppos: the current position in the file
2878 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2879 * values from/to the user buffer, treated as an ASCII string.
2880 * The values read are assumed to be in 1/1000 seconds, and
2881 * are converted into jiffies.
2883 * Returns 0 on success.
2885 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2886 void __user *buffer, size_t *lenp, loff_t *ppos)
2888 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2889 do_proc_dointvec_ms_jiffies_conv, NULL);
2892 static int proc_do_cad_pid(struct ctl_table *table, int write,
2893 void __user *buffer, size_t *lenp, loff_t *ppos)
2895 struct pid *new_pid;
2899 tmp = pid_vnr(cad_pid);
2901 r = __do_proc_dointvec(&tmp, table, write, buffer,
2902 lenp, ppos, NULL, NULL);
2906 new_pid = find_get_pid(tmp);
2910 put_pid(xchg(&cad_pid, new_pid));
2914 #else /* CONFIG_PROC_FS */
2916 int proc_dostring(struct ctl_table *table, int write,
2917 void __user *buffer, size_t *lenp, loff_t *ppos)
2922 int proc_dointvec(struct ctl_table *table, int write,
2923 void __user *buffer, size_t *lenp, loff_t *ppos)
2928 int proc_dointvec_minmax(struct ctl_table *table, int write,
2929 void __user *buffer, size_t *lenp, loff_t *ppos)
2934 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2935 void __user *buffer, size_t *lenp, loff_t *ppos)
2940 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2941 void __user *buffer, size_t *lenp, loff_t *ppos)
2946 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2947 void __user *buffer, size_t *lenp, loff_t *ppos)
2952 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2953 void __user *buffer, size_t *lenp, loff_t *ppos)
2958 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2959 void __user *buffer,
2960 size_t *lenp, loff_t *ppos)
2966 #endif /* CONFIG_PROC_FS */
2969 #ifdef CONFIG_SYSCTL_SYSCALL
2971 * General sysctl support routines
2974 /* The generic sysctl data routine (used if no strategy routine supplied) */
2975 int sysctl_data(struct ctl_table *table,
2976 void __user *oldval, size_t __user *oldlenp,
2977 void __user *newval, size_t newlen)
2981 /* Get out of I don't have a variable */
2982 if (!table->data || !table->maxlen)
2985 if (oldval && oldlenp) {
2986 if (get_user(len, oldlenp))
2989 if (len > table->maxlen)
2990 len = table->maxlen;
2991 if (copy_to_user(oldval, table->data, len))
2993 if (put_user(len, oldlenp))
2998 if (newval && newlen) {
2999 if (newlen > table->maxlen)
3000 newlen = table->maxlen;
3002 if (copy_from_user(table->data, newval, newlen))
3008 /* The generic string strategy routine: */
3009 int sysctl_string(struct ctl_table *table,
3010 void __user *oldval, size_t __user *oldlenp,
3011 void __user *newval, size_t newlen)
3013 if (!table->data || !table->maxlen)
3016 if (oldval && oldlenp) {
3018 if (get_user(bufsize, oldlenp))
3021 size_t len = strlen(table->data), copied;
3023 /* This shouldn't trigger for a well-formed sysctl */
3024 if (len > table->maxlen)
3025 len = table->maxlen;
3027 /* Copy up to a max of bufsize-1 bytes of the string */
3028 copied = (len >= bufsize) ? bufsize - 1 : len;
3030 if (copy_to_user(oldval, table->data, copied) ||
3031 put_user(0, (char __user *)(oldval + copied)))
3033 if (put_user(len, oldlenp))
3037 if (newval && newlen) {
3038 size_t len = newlen;
3039 if (len > table->maxlen)
3040 len = table->maxlen;
3041 if(copy_from_user(table->data, newval, len))
3043 if (len == table->maxlen)
3045 ((char *) table->data)[len] = 0;
3051 * This function makes sure that all of the integers in the vector
3052 * are between the minimum and maximum values given in the arrays
3053 * table->extra1 and table->extra2, respectively.
3055 int sysctl_intvec(struct ctl_table *table,
3056 void __user *oldval, size_t __user *oldlenp,
3057 void __user *newval, size_t newlen)
3060 if (newval && newlen) {
3061 int __user *vec = (int __user *) newval;
3062 int *min = (int *) table->extra1;
3063 int *max = (int *) table->extra2;
3067 if (newlen % sizeof(int) != 0)
3070 if (!table->extra1 && !table->extra2)
3073 if (newlen > table->maxlen)
3074 newlen = table->maxlen;
3075 length = newlen / sizeof(int);
3077 for (i = 0; i < length; i++) {
3079 if (get_user(value, vec + i))
3081 if (min && value < min[i])
3083 if (max && value > max[i])
3090 /* Strategy function to convert jiffies to seconds */
3091 int sysctl_jiffies(struct ctl_table *table,
3092 void __user *oldval, size_t __user *oldlenp,
3093 void __user *newval, size_t newlen)
3095 if (oldval && oldlenp) {
3098 if (get_user(olen, oldlenp))
3103 if (olen < sizeof(int))
3106 val = *(int *)(table->data) / HZ;
3107 if (put_user(val, (int __user *)oldval))
3109 if (put_user(sizeof(int), oldlenp))
3113 if (newval && newlen) {
3115 if (newlen != sizeof(int))
3117 if (get_user(new, (int __user *)newval))
3119 *(int *)(table->data) = new*HZ;
3124 /* Strategy function to convert jiffies to seconds */
3125 int sysctl_ms_jiffies(struct ctl_table *table,
3126 void __user *oldval, size_t __user *oldlenp,
3127 void __user *newval, size_t newlen)
3129 if (oldval && oldlenp) {
3132 if (get_user(olen, oldlenp))
3137 if (olen < sizeof(int))
3140 val = jiffies_to_msecs(*(int *)(table->data));
3141 if (put_user(val, (int __user *)oldval))
3143 if (put_user(sizeof(int), oldlenp))
3147 if (newval && newlen) {
3149 if (newlen != sizeof(int))
3151 if (get_user(new, (int __user *)newval))
3153 *(int *)(table->data) = msecs_to_jiffies(new);
3160 #else /* CONFIG_SYSCTL_SYSCALL */
3163 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3165 struct __sysctl_args tmp;
3168 if (copy_from_user(&tmp, args, sizeof(tmp)))
3171 error = deprecated_sysctl_warning(&tmp);
3173 /* If no error reading the parameters then just -ENOSYS ... */
3180 int sysctl_data(struct ctl_table *table,
3181 void __user *oldval, size_t __user *oldlenp,
3182 void __user *newval, size_t newlen)
3187 int sysctl_string(struct ctl_table *table,
3188 void __user *oldval, size_t __user *oldlenp,
3189 void __user *newval, size_t newlen)
3194 int sysctl_intvec(struct ctl_table *table,
3195 void __user *oldval, size_t __user *oldlenp,
3196 void __user *newval, size_t newlen)
3201 int sysctl_jiffies(struct ctl_table *table,
3202 void __user *oldval, size_t __user *oldlenp,
3203 void __user *newval, size_t newlen)
3208 int sysctl_ms_jiffies(struct ctl_table *table,
3209 void __user *oldval, size_t __user *oldlenp,
3210 void __user *newval, size_t newlen)
3215 #endif /* CONFIG_SYSCTL_SYSCALL */
3217 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3219 static int msg_count;
3220 int name[CTL_MAXNAME];
3223 /* Check args->nlen. */
3224 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3227 /* Read in the sysctl name for better debug message logging */
3228 for (i = 0; i < args->nlen; i++)
3229 if (get_user(name[i], args->name + i))
3232 /* Ignore accesses to kernel.version */
3233 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3236 if (msg_count < 5) {
3239 "warning: process `%s' used the deprecated sysctl "
3240 "system call with ", current->comm);
3241 for (i = 0; i < args->nlen; i++)
3242 printk("%d.", name[i]);
3249 * No sense putting this after each symbol definition, twice,
3250 * exception granted :-)
3252 EXPORT_SYMBOL(proc_dointvec);
3253 EXPORT_SYMBOL(proc_dointvec_jiffies);
3254 EXPORT_SYMBOL(proc_dointvec_minmax);
3255 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3256 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3257 EXPORT_SYMBOL(proc_dostring);
3258 EXPORT_SYMBOL(proc_doulongvec_minmax);
3259 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3260 EXPORT_SYMBOL(register_sysctl_table);
3261 EXPORT_SYMBOL(register_sysctl_paths);
3262 EXPORT_SYMBOL(sysctl_intvec);
3263 EXPORT_SYMBOL(sysctl_jiffies);
3264 EXPORT_SYMBOL(sysctl_ms_jiffies);
3265 EXPORT_SYMBOL(sysctl_string);
3266 EXPORT_SYMBOL(sysctl_data);
3267 EXPORT_SYMBOL(unregister_sysctl_table);