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>
31 #include <linux/init.h>
32 #include <linux/kernel.h>
33 #include <linux/kobject.h>
34 #include <linux/net.h>
35 #include <linux/sysrq.h>
36 #include <linux/highuid.h>
37 #include <linux/writeback.h>
38 #include <linux/hugetlb.h>
39 #include <linux/initrd.h>
40 #include <linux/key.h>
41 #include <linux/times.h>
42 #include <linux/limits.h>
43 #include <linux/dcache.h>
44 #include <linux/syscalls.h>
45 #include <linux/vmstat.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
48 #include <linux/reboot.h>
49 #include <linux/ftrace.h>
50 #include <linux/slow-work.h>
51 #include <linux/perf_event.h>
53 #include <asm/uaccess.h>
54 #include <asm/processor.h>
58 #include <asm/stacktrace.h>
63 #if defined(CONFIG_SYSCTL)
65 /* External variables not in a header file. */
67 extern int print_fatal_signals;
68 extern int sysctl_overcommit_memory;
69 extern int sysctl_overcommit_ratio;
70 extern int sysctl_panic_on_oom;
71 extern int sysctl_oom_kill_allocating_task;
72 extern int sysctl_oom_dump_tasks;
73 extern int max_threads;
74 extern int core_uses_pid;
75 extern int suid_dumpable;
76 extern char core_pattern[];
77 extern unsigned int core_pipe_limit;
79 extern int min_free_kbytes;
80 extern int pid_max_min, pid_max_max;
81 extern int sysctl_drop_caches;
82 extern int percpu_pagelist_fraction;
83 extern int compat_log;
84 extern int latencytop_enabled;
85 extern int sysctl_nr_open_min, sysctl_nr_open_max;
87 extern int sysctl_nr_trim_pages;
89 #ifdef CONFIG_RCU_TORTURE_TEST
90 extern int rcutorture_runnable;
91 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
93 extern int blk_iopoll_enabled;
96 /* Constants used for minimum and maximum */
97 #ifdef CONFIG_DETECT_SOFTLOCKUP
98 static int sixty = 60;
99 static int neg_one = -1;
103 static int __maybe_unused one = 1;
104 static int __maybe_unused two = 2;
105 static unsigned long one_ul = 1;
106 static int one_hundred = 100;
108 static int ten_thousand = 10000;
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 #ifdef CONFIG_RT_MUTEXES
160 extern int max_lock_depth;
163 #ifdef CONFIG_PROC_SYSCTL
164 static int proc_do_cad_pid(struct ctl_table *table, int write,
165 void __user *buffer, size_t *lenp, loff_t *ppos);
166 static int proc_taint(struct ctl_table *table, int write,
167 void __user *buffer, size_t *lenp, loff_t *ppos);
170 static struct ctl_table root_table[];
171 static struct ctl_table_root sysctl_table_root;
172 static struct ctl_table_header root_table_header = {
174 .ctl_table = root_table,
175 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
176 .root = &sysctl_table_root,
177 .set = &sysctl_table_root.default_set,
179 static struct ctl_table_root sysctl_table_root = {
180 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
181 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
184 static struct ctl_table kern_table[];
185 static struct ctl_table vm_table[];
186 static struct ctl_table fs_table[];
187 static struct ctl_table debug_table[];
188 static struct ctl_table dev_table[];
189 extern struct ctl_table random_table[];
190 #ifdef CONFIG_INOTIFY_USER
191 extern struct ctl_table inotify_table[];
194 extern struct ctl_table epoll_table[];
197 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
198 int sysctl_legacy_va_layout;
201 extern int prove_locking;
202 extern int lock_stat;
204 /* The default sysctl tables: */
206 static struct ctl_table root_table[] = {
208 .ctl_name = CTL_KERN,
209 .procname = "kernel",
226 .ctl_name = CTL_DEBUG,
229 .child = debug_table,
238 * NOTE: do not add new entries to this table unless you have read
239 * Documentation/sysctl/ctl_unnumbered.txt
244 #ifdef CONFIG_SCHED_DEBUG
245 static int min_sched_granularity_ns = 100000; /* 100 usecs */
246 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
247 static int min_wakeup_granularity_ns; /* 0 usecs */
248 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
251 static struct ctl_table kern_table[] = {
253 .ctl_name = CTL_UNNUMBERED,
254 .procname = "sched_child_runs_first",
255 .data = &sysctl_sched_child_runs_first,
256 .maxlen = sizeof(unsigned int),
258 .proc_handler = &proc_dointvec,
260 #ifdef CONFIG_SCHED_DEBUG
262 .ctl_name = CTL_UNNUMBERED,
263 .procname = "sched_min_granularity_ns",
264 .data = &sysctl_sched_min_granularity,
265 .maxlen = sizeof(unsigned int),
267 .proc_handler = &sched_nr_latency_handler,
268 .strategy = &sysctl_intvec,
269 .extra1 = &min_sched_granularity_ns,
270 .extra2 = &max_sched_granularity_ns,
273 .ctl_name = CTL_UNNUMBERED,
274 .procname = "sched_latency_ns",
275 .data = &sysctl_sched_latency,
276 .maxlen = sizeof(unsigned int),
278 .proc_handler = &sched_nr_latency_handler,
279 .strategy = &sysctl_intvec,
280 .extra1 = &min_sched_granularity_ns,
281 .extra2 = &max_sched_granularity_ns,
284 .ctl_name = CTL_UNNUMBERED,
285 .procname = "sched_wakeup_granularity_ns",
286 .data = &sysctl_sched_wakeup_granularity,
287 .maxlen = sizeof(unsigned int),
289 .proc_handler = &proc_dointvec_minmax,
290 .strategy = &sysctl_intvec,
291 .extra1 = &min_wakeup_granularity_ns,
292 .extra2 = &max_wakeup_granularity_ns,
295 .ctl_name = CTL_UNNUMBERED,
296 .procname = "sched_shares_ratelimit",
297 .data = &sysctl_sched_shares_ratelimit,
298 .maxlen = sizeof(unsigned int),
300 .proc_handler = &proc_dointvec,
303 .ctl_name = CTL_UNNUMBERED,
304 .procname = "sched_shares_thresh",
305 .data = &sysctl_sched_shares_thresh,
306 .maxlen = sizeof(unsigned int),
308 .proc_handler = &proc_dointvec_minmax,
309 .strategy = &sysctl_intvec,
313 .ctl_name = CTL_UNNUMBERED,
314 .procname = "sched_features",
315 .data = &sysctl_sched_features,
316 .maxlen = sizeof(unsigned int),
318 .proc_handler = &proc_dointvec,
321 .ctl_name = CTL_UNNUMBERED,
322 .procname = "sched_migration_cost",
323 .data = &sysctl_sched_migration_cost,
324 .maxlen = sizeof(unsigned int),
326 .proc_handler = &proc_dointvec,
329 .ctl_name = CTL_UNNUMBERED,
330 .procname = "sched_nr_migrate",
331 .data = &sysctl_sched_nr_migrate,
332 .maxlen = sizeof(unsigned int),
334 .proc_handler = &proc_dointvec,
337 .ctl_name = CTL_UNNUMBERED,
338 .procname = "sched_time_avg",
339 .data = &sysctl_sched_time_avg,
340 .maxlen = sizeof(unsigned int),
342 .proc_handler = &proc_dointvec,
345 .ctl_name = CTL_UNNUMBERED,
346 .procname = "timer_migration",
347 .data = &sysctl_timer_migration,
348 .maxlen = sizeof(unsigned int),
350 .proc_handler = &proc_dointvec_minmax,
351 .strategy = &sysctl_intvec,
357 .ctl_name = CTL_UNNUMBERED,
358 .procname = "sched_rt_period_us",
359 .data = &sysctl_sched_rt_period,
360 .maxlen = sizeof(unsigned int),
362 .proc_handler = &sched_rt_handler,
365 .ctl_name = CTL_UNNUMBERED,
366 .procname = "sched_rt_runtime_us",
367 .data = &sysctl_sched_rt_runtime,
368 .maxlen = sizeof(int),
370 .proc_handler = &sched_rt_handler,
373 .ctl_name = CTL_UNNUMBERED,
374 .procname = "sched_compat_yield",
375 .data = &sysctl_sched_compat_yield,
376 .maxlen = sizeof(unsigned int),
378 .proc_handler = &proc_dointvec,
380 #ifdef CONFIG_PROVE_LOCKING
382 .ctl_name = CTL_UNNUMBERED,
383 .procname = "prove_locking",
384 .data = &prove_locking,
385 .maxlen = sizeof(int),
387 .proc_handler = &proc_dointvec,
390 #ifdef CONFIG_LOCK_STAT
392 .ctl_name = CTL_UNNUMBERED,
393 .procname = "lock_stat",
395 .maxlen = sizeof(int),
397 .proc_handler = &proc_dointvec,
401 .ctl_name = KERN_PANIC,
403 .data = &panic_timeout,
404 .maxlen = sizeof(int),
406 .proc_handler = &proc_dointvec,
409 .ctl_name = KERN_CORE_USES_PID,
410 .procname = "core_uses_pid",
411 .data = &core_uses_pid,
412 .maxlen = sizeof(int),
414 .proc_handler = &proc_dointvec,
417 .ctl_name = KERN_CORE_PATTERN,
418 .procname = "core_pattern",
419 .data = core_pattern,
420 .maxlen = CORENAME_MAX_SIZE,
422 .proc_handler = &proc_dostring,
423 .strategy = &sysctl_string,
426 .ctl_name = CTL_UNNUMBERED,
427 .procname = "core_pipe_limit",
428 .data = &core_pipe_limit,
429 .maxlen = sizeof(unsigned int),
431 .proc_handler = &proc_dointvec,
433 #ifdef CONFIG_PROC_SYSCTL
435 .procname = "tainted",
436 .maxlen = sizeof(long),
438 .proc_handler = &proc_taint,
441 #ifdef CONFIG_LATENCYTOP
443 .procname = "latencytop",
444 .data = &latencytop_enabled,
445 .maxlen = sizeof(int),
447 .proc_handler = &proc_dointvec,
450 #ifdef CONFIG_BLK_DEV_INITRD
452 .ctl_name = KERN_REALROOTDEV,
453 .procname = "real-root-dev",
454 .data = &real_root_dev,
455 .maxlen = sizeof(int),
457 .proc_handler = &proc_dointvec,
461 .ctl_name = CTL_UNNUMBERED,
462 .procname = "print-fatal-signals",
463 .data = &print_fatal_signals,
464 .maxlen = sizeof(int),
466 .proc_handler = &proc_dointvec,
470 .ctl_name = KERN_SPARC_REBOOT,
471 .procname = "reboot-cmd",
472 .data = reboot_command,
475 .proc_handler = &proc_dostring,
476 .strategy = &sysctl_string,
479 .ctl_name = KERN_SPARC_STOP_A,
480 .procname = "stop-a",
481 .data = &stop_a_enabled,
482 .maxlen = sizeof (int),
484 .proc_handler = &proc_dointvec,
487 .ctl_name = KERN_SPARC_SCONS_PWROFF,
488 .procname = "scons-poweroff",
489 .data = &scons_pwroff,
490 .maxlen = sizeof (int),
492 .proc_handler = &proc_dointvec,
495 #ifdef CONFIG_SPARC64
497 .ctl_name = CTL_UNNUMBERED,
498 .procname = "tsb-ratio",
499 .data = &sysctl_tsb_ratio,
500 .maxlen = sizeof (int),
502 .proc_handler = &proc_dointvec,
507 .ctl_name = KERN_HPPA_PWRSW,
508 .procname = "soft-power",
509 .data = &pwrsw_enabled,
510 .maxlen = sizeof (int),
512 .proc_handler = &proc_dointvec,
515 .ctl_name = KERN_HPPA_UNALIGNED,
516 .procname = "unaligned-trap",
517 .data = &unaligned_enabled,
518 .maxlen = sizeof (int),
520 .proc_handler = &proc_dointvec,
524 .ctl_name = KERN_CTLALTDEL,
525 .procname = "ctrl-alt-del",
527 .maxlen = sizeof(int),
529 .proc_handler = &proc_dointvec,
531 #ifdef CONFIG_FUNCTION_TRACER
533 .ctl_name = CTL_UNNUMBERED,
534 .procname = "ftrace_enabled",
535 .data = &ftrace_enabled,
536 .maxlen = sizeof(int),
538 .proc_handler = &ftrace_enable_sysctl,
541 #ifdef CONFIG_STACK_TRACER
543 .ctl_name = CTL_UNNUMBERED,
544 .procname = "stack_tracer_enabled",
545 .data = &stack_tracer_enabled,
546 .maxlen = sizeof(int),
548 .proc_handler = &stack_trace_sysctl,
551 #ifdef CONFIG_TRACING
553 .ctl_name = CTL_UNNUMBERED,
554 .procname = "ftrace_dump_on_oops",
555 .data = &ftrace_dump_on_oops,
556 .maxlen = sizeof(int),
558 .proc_handler = &proc_dointvec,
561 #ifdef CONFIG_MODULES
563 .ctl_name = KERN_MODPROBE,
564 .procname = "modprobe",
565 .data = &modprobe_path,
566 .maxlen = KMOD_PATH_LEN,
568 .proc_handler = &proc_dostring,
569 .strategy = &sysctl_string,
572 .ctl_name = CTL_UNNUMBERED,
573 .procname = "modules_disabled",
574 .data = &modules_disabled,
575 .maxlen = sizeof(int),
577 /* only handle a transition from default "0" to "1" */
578 .proc_handler = &proc_dointvec_minmax,
583 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
585 .ctl_name = KERN_HOTPLUG,
586 .procname = "hotplug",
587 .data = &uevent_helper,
588 .maxlen = UEVENT_HELPER_PATH_LEN,
590 .proc_handler = &proc_dostring,
591 .strategy = &sysctl_string,
594 #ifdef CONFIG_CHR_DEV_SG
596 .ctl_name = KERN_SG_BIG_BUFF,
597 .procname = "sg-big-buff",
598 .data = &sg_big_buff,
599 .maxlen = sizeof (int),
601 .proc_handler = &proc_dointvec,
604 #ifdef CONFIG_BSD_PROCESS_ACCT
606 .ctl_name = KERN_ACCT,
609 .maxlen = 3*sizeof(int),
611 .proc_handler = &proc_dointvec,
614 #ifdef CONFIG_MAGIC_SYSRQ
616 .ctl_name = KERN_SYSRQ,
618 .data = &__sysrq_enabled,
619 .maxlen = sizeof (int),
621 .proc_handler = &proc_dointvec,
624 #ifdef CONFIG_PROC_SYSCTL
626 .procname = "cad_pid",
628 .maxlen = sizeof (int),
630 .proc_handler = &proc_do_cad_pid,
634 .ctl_name = KERN_MAX_THREADS,
635 .procname = "threads-max",
636 .data = &max_threads,
637 .maxlen = sizeof(int),
639 .proc_handler = &proc_dointvec,
642 .ctl_name = KERN_RANDOM,
643 .procname = "random",
645 .child = random_table,
648 .ctl_name = KERN_OVERFLOWUID,
649 .procname = "overflowuid",
650 .data = &overflowuid,
651 .maxlen = sizeof(int),
653 .proc_handler = &proc_dointvec_minmax,
654 .strategy = &sysctl_intvec,
655 .extra1 = &minolduid,
656 .extra2 = &maxolduid,
659 .ctl_name = KERN_OVERFLOWGID,
660 .procname = "overflowgid",
661 .data = &overflowgid,
662 .maxlen = sizeof(int),
664 .proc_handler = &proc_dointvec_minmax,
665 .strategy = &sysctl_intvec,
666 .extra1 = &minolduid,
667 .extra2 = &maxolduid,
670 #ifdef CONFIG_MATHEMU
672 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
673 .procname = "ieee_emulation_warnings",
674 .data = &sysctl_ieee_emulation_warnings,
675 .maxlen = sizeof(int),
677 .proc_handler = &proc_dointvec,
681 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
682 .procname = "userprocess_debug",
683 .data = &sysctl_userprocess_debug,
684 .maxlen = sizeof(int),
686 .proc_handler = &proc_dointvec,
690 .ctl_name = KERN_PIDMAX,
691 .procname = "pid_max",
693 .maxlen = sizeof (int),
695 .proc_handler = &proc_dointvec_minmax,
696 .strategy = sysctl_intvec,
697 .extra1 = &pid_max_min,
698 .extra2 = &pid_max_max,
701 .ctl_name = KERN_PANIC_ON_OOPS,
702 .procname = "panic_on_oops",
703 .data = &panic_on_oops,
704 .maxlen = sizeof(int),
706 .proc_handler = &proc_dointvec,
708 #if defined CONFIG_PRINTK
710 .ctl_name = KERN_PRINTK,
711 .procname = "printk",
712 .data = &console_loglevel,
713 .maxlen = 4*sizeof(int),
715 .proc_handler = &proc_dointvec,
718 .ctl_name = KERN_PRINTK_RATELIMIT,
719 .procname = "printk_ratelimit",
720 .data = &printk_ratelimit_state.interval,
721 .maxlen = sizeof(int),
723 .proc_handler = &proc_dointvec_jiffies,
724 .strategy = &sysctl_jiffies,
727 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
728 .procname = "printk_ratelimit_burst",
729 .data = &printk_ratelimit_state.burst,
730 .maxlen = sizeof(int),
732 .proc_handler = &proc_dointvec,
735 .ctl_name = CTL_UNNUMBERED,
736 .procname = "printk_delay",
737 .data = &printk_delay_msec,
738 .maxlen = sizeof(int),
740 .proc_handler = &proc_dointvec_minmax,
741 .strategy = &sysctl_intvec,
743 .extra2 = &ten_thousand,
747 .ctl_name = KERN_NGROUPS_MAX,
748 .procname = "ngroups_max",
749 .data = &ngroups_max,
750 .maxlen = sizeof (int),
752 .proc_handler = &proc_dointvec,
754 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
756 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
757 .procname = "unknown_nmi_panic",
758 .data = &unknown_nmi_panic,
759 .maxlen = sizeof (int),
761 .proc_handler = &proc_dointvec,
764 .procname = "nmi_watchdog",
765 .data = &nmi_watchdog_enabled,
766 .maxlen = sizeof (int),
768 .proc_handler = &proc_nmi_enabled,
771 #if defined(CONFIG_X86)
773 .ctl_name = KERN_PANIC_ON_NMI,
774 .procname = "panic_on_unrecovered_nmi",
775 .data = &panic_on_unrecovered_nmi,
776 .maxlen = sizeof(int),
778 .proc_handler = &proc_dointvec,
781 .ctl_name = CTL_UNNUMBERED,
782 .procname = "panic_on_io_nmi",
783 .data = &panic_on_io_nmi,
784 .maxlen = sizeof(int),
786 .proc_handler = &proc_dointvec,
789 .ctl_name = KERN_BOOTLOADER_TYPE,
790 .procname = "bootloader_type",
791 .data = &bootloader_type,
792 .maxlen = sizeof (int),
794 .proc_handler = &proc_dointvec,
797 .ctl_name = CTL_UNNUMBERED,
798 .procname = "bootloader_version",
799 .data = &bootloader_version,
800 .maxlen = sizeof (int),
802 .proc_handler = &proc_dointvec,
805 .ctl_name = CTL_UNNUMBERED,
806 .procname = "kstack_depth_to_print",
807 .data = &kstack_depth_to_print,
808 .maxlen = sizeof(int),
810 .proc_handler = &proc_dointvec,
813 .ctl_name = CTL_UNNUMBERED,
814 .procname = "io_delay_type",
815 .data = &io_delay_type,
816 .maxlen = sizeof(int),
818 .proc_handler = &proc_dointvec,
821 #if defined(CONFIG_MMU)
823 .ctl_name = KERN_RANDOMIZE,
824 .procname = "randomize_va_space",
825 .data = &randomize_va_space,
826 .maxlen = sizeof(int),
828 .proc_handler = &proc_dointvec,
831 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
833 .ctl_name = KERN_SPIN_RETRY,
834 .procname = "spin_retry",
836 .maxlen = sizeof (int),
838 .proc_handler = &proc_dointvec,
841 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
843 .procname = "acpi_video_flags",
844 .data = &acpi_realmode_flags,
845 .maxlen = sizeof (unsigned long),
847 .proc_handler = &proc_doulongvec_minmax,
852 .ctl_name = KERN_IA64_UNALIGNED,
853 .procname = "ignore-unaligned-usertrap",
854 .data = &no_unaligned_warning,
855 .maxlen = sizeof (int),
857 .proc_handler = &proc_dointvec,
860 .ctl_name = CTL_UNNUMBERED,
861 .procname = "unaligned-dump-stack",
862 .data = &unaligned_dump_stack,
863 .maxlen = sizeof (int),
865 .proc_handler = &proc_dointvec,
868 #ifdef CONFIG_DETECT_SOFTLOCKUP
870 .ctl_name = CTL_UNNUMBERED,
871 .procname = "softlockup_panic",
872 .data = &softlockup_panic,
873 .maxlen = sizeof(int),
875 .proc_handler = &proc_dointvec_minmax,
876 .strategy = &sysctl_intvec,
881 .ctl_name = CTL_UNNUMBERED,
882 .procname = "softlockup_thresh",
883 .data = &softlockup_thresh,
884 .maxlen = sizeof(int),
886 .proc_handler = &proc_dosoftlockup_thresh,
887 .strategy = &sysctl_intvec,
892 #ifdef CONFIG_DETECT_HUNG_TASK
894 .ctl_name = CTL_UNNUMBERED,
895 .procname = "hung_task_panic",
896 .data = &sysctl_hung_task_panic,
897 .maxlen = sizeof(int),
899 .proc_handler = &proc_dointvec_minmax,
900 .strategy = &sysctl_intvec,
905 .ctl_name = CTL_UNNUMBERED,
906 .procname = "hung_task_check_count",
907 .data = &sysctl_hung_task_check_count,
908 .maxlen = sizeof(unsigned long),
910 .proc_handler = &proc_doulongvec_minmax,
911 .strategy = &sysctl_intvec,
914 .ctl_name = CTL_UNNUMBERED,
915 .procname = "hung_task_timeout_secs",
916 .data = &sysctl_hung_task_timeout_secs,
917 .maxlen = sizeof(unsigned long),
919 .proc_handler = &proc_dohung_task_timeout_secs,
920 .strategy = &sysctl_intvec,
923 .ctl_name = CTL_UNNUMBERED,
924 .procname = "hung_task_warnings",
925 .data = &sysctl_hung_task_warnings,
926 .maxlen = sizeof(unsigned long),
928 .proc_handler = &proc_doulongvec_minmax,
929 .strategy = &sysctl_intvec,
934 .ctl_name = KERN_COMPAT_LOG,
935 .procname = "compat-log",
937 .maxlen = sizeof (int),
939 .proc_handler = &proc_dointvec,
942 #ifdef CONFIG_RT_MUTEXES
944 .ctl_name = KERN_MAX_LOCK_DEPTH,
945 .procname = "max_lock_depth",
946 .data = &max_lock_depth,
947 .maxlen = sizeof(int),
949 .proc_handler = &proc_dointvec,
953 .ctl_name = CTL_UNNUMBERED,
954 .procname = "poweroff_cmd",
955 .data = &poweroff_cmd,
956 .maxlen = POWEROFF_CMD_PATH_LEN,
958 .proc_handler = &proc_dostring,
959 .strategy = &sysctl_string,
963 .ctl_name = CTL_UNNUMBERED,
966 .child = key_sysctls,
969 #ifdef CONFIG_RCU_TORTURE_TEST
971 .ctl_name = CTL_UNNUMBERED,
972 .procname = "rcutorture_runnable",
973 .data = &rcutorture_runnable,
974 .maxlen = sizeof(int),
976 .proc_handler = &proc_dointvec,
979 #ifdef CONFIG_SLOW_WORK
981 .ctl_name = CTL_UNNUMBERED,
982 .procname = "slow-work",
984 .child = slow_work_sysctls,
987 #ifdef CONFIG_PERF_EVENTS
989 .ctl_name = CTL_UNNUMBERED,
990 .procname = "perf_event_paranoid",
991 .data = &sysctl_perf_event_paranoid,
992 .maxlen = sizeof(sysctl_perf_event_paranoid),
994 .proc_handler = &proc_dointvec,
997 .ctl_name = CTL_UNNUMBERED,
998 .procname = "perf_event_mlock_kb",
999 .data = &sysctl_perf_event_mlock,
1000 .maxlen = sizeof(sysctl_perf_event_mlock),
1002 .proc_handler = &proc_dointvec,
1005 .ctl_name = CTL_UNNUMBERED,
1006 .procname = "perf_event_max_sample_rate",
1007 .data = &sysctl_perf_event_sample_rate,
1008 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1010 .proc_handler = &proc_dointvec,
1013 #ifdef CONFIG_KMEMCHECK
1015 .ctl_name = CTL_UNNUMBERED,
1016 .procname = "kmemcheck",
1017 .data = &kmemcheck_enabled,
1018 .maxlen = sizeof(int),
1020 .proc_handler = &proc_dointvec,
1025 .ctl_name = CTL_UNNUMBERED,
1026 .procname = "blk_iopoll",
1027 .data = &blk_iopoll_enabled,
1028 .maxlen = sizeof(int),
1030 .proc_handler = &proc_dointvec,
1034 * NOTE: do not add new entries to this table unless you have read
1035 * Documentation/sysctl/ctl_unnumbered.txt
1040 static struct ctl_table vm_table[] = {
1042 .ctl_name = VM_OVERCOMMIT_MEMORY,
1043 .procname = "overcommit_memory",
1044 .data = &sysctl_overcommit_memory,
1045 .maxlen = sizeof(sysctl_overcommit_memory),
1047 .proc_handler = &proc_dointvec,
1050 .ctl_name = VM_PANIC_ON_OOM,
1051 .procname = "panic_on_oom",
1052 .data = &sysctl_panic_on_oom,
1053 .maxlen = sizeof(sysctl_panic_on_oom),
1055 .proc_handler = &proc_dointvec,
1058 .ctl_name = CTL_UNNUMBERED,
1059 .procname = "oom_kill_allocating_task",
1060 .data = &sysctl_oom_kill_allocating_task,
1061 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1063 .proc_handler = &proc_dointvec,
1066 .ctl_name = CTL_UNNUMBERED,
1067 .procname = "oom_dump_tasks",
1068 .data = &sysctl_oom_dump_tasks,
1069 .maxlen = sizeof(sysctl_oom_dump_tasks),
1071 .proc_handler = &proc_dointvec,
1074 .ctl_name = VM_OVERCOMMIT_RATIO,
1075 .procname = "overcommit_ratio",
1076 .data = &sysctl_overcommit_ratio,
1077 .maxlen = sizeof(sysctl_overcommit_ratio),
1079 .proc_handler = &proc_dointvec,
1082 .ctl_name = VM_PAGE_CLUSTER,
1083 .procname = "page-cluster",
1084 .data = &page_cluster,
1085 .maxlen = sizeof(int),
1087 .proc_handler = &proc_dointvec,
1090 .ctl_name = VM_DIRTY_BACKGROUND,
1091 .procname = "dirty_background_ratio",
1092 .data = &dirty_background_ratio,
1093 .maxlen = sizeof(dirty_background_ratio),
1095 .proc_handler = &dirty_background_ratio_handler,
1096 .strategy = &sysctl_intvec,
1098 .extra2 = &one_hundred,
1101 .ctl_name = CTL_UNNUMBERED,
1102 .procname = "dirty_background_bytes",
1103 .data = &dirty_background_bytes,
1104 .maxlen = sizeof(dirty_background_bytes),
1106 .proc_handler = &dirty_background_bytes_handler,
1107 .strategy = &sysctl_intvec,
1111 .ctl_name = VM_DIRTY_RATIO,
1112 .procname = "dirty_ratio",
1113 .data = &vm_dirty_ratio,
1114 .maxlen = sizeof(vm_dirty_ratio),
1116 .proc_handler = &dirty_ratio_handler,
1117 .strategy = &sysctl_intvec,
1119 .extra2 = &one_hundred,
1122 .ctl_name = CTL_UNNUMBERED,
1123 .procname = "dirty_bytes",
1124 .data = &vm_dirty_bytes,
1125 .maxlen = sizeof(vm_dirty_bytes),
1127 .proc_handler = &dirty_bytes_handler,
1128 .strategy = &sysctl_intvec,
1129 .extra1 = &dirty_bytes_min,
1132 .procname = "dirty_writeback_centisecs",
1133 .data = &dirty_writeback_interval,
1134 .maxlen = sizeof(dirty_writeback_interval),
1136 .proc_handler = &dirty_writeback_centisecs_handler,
1139 .procname = "dirty_expire_centisecs",
1140 .data = &dirty_expire_interval,
1141 .maxlen = sizeof(dirty_expire_interval),
1143 .proc_handler = &proc_dointvec,
1146 .ctl_name = VM_NR_PDFLUSH_THREADS,
1147 .procname = "nr_pdflush_threads",
1148 .data = &nr_pdflush_threads,
1149 .maxlen = sizeof nr_pdflush_threads,
1150 .mode = 0444 /* read-only*/,
1151 .proc_handler = &proc_dointvec,
1154 .ctl_name = VM_SWAPPINESS,
1155 .procname = "swappiness",
1156 .data = &vm_swappiness,
1157 .maxlen = sizeof(vm_swappiness),
1159 .proc_handler = &proc_dointvec_minmax,
1160 .strategy = &sysctl_intvec,
1162 .extra2 = &one_hundred,
1164 #ifdef CONFIG_HUGETLB_PAGE
1166 .procname = "nr_hugepages",
1168 .maxlen = sizeof(unsigned long),
1170 .proc_handler = &hugetlb_sysctl_handler,
1171 .extra1 = (void *)&hugetlb_zero,
1172 .extra2 = (void *)&hugetlb_infinity,
1175 .ctl_name = VM_HUGETLB_GROUP,
1176 .procname = "hugetlb_shm_group",
1177 .data = &sysctl_hugetlb_shm_group,
1178 .maxlen = sizeof(gid_t),
1180 .proc_handler = &proc_dointvec,
1183 .ctl_name = CTL_UNNUMBERED,
1184 .procname = "hugepages_treat_as_movable",
1185 .data = &hugepages_treat_as_movable,
1186 .maxlen = sizeof(int),
1188 .proc_handler = &hugetlb_treat_movable_handler,
1191 .ctl_name = CTL_UNNUMBERED,
1192 .procname = "nr_overcommit_hugepages",
1194 .maxlen = sizeof(unsigned long),
1196 .proc_handler = &hugetlb_overcommit_handler,
1197 .extra1 = (void *)&hugetlb_zero,
1198 .extra2 = (void *)&hugetlb_infinity,
1202 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1203 .procname = "lowmem_reserve_ratio",
1204 .data = &sysctl_lowmem_reserve_ratio,
1205 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1207 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1208 .strategy = &sysctl_intvec,
1211 .ctl_name = VM_DROP_PAGECACHE,
1212 .procname = "drop_caches",
1213 .data = &sysctl_drop_caches,
1214 .maxlen = sizeof(int),
1216 .proc_handler = drop_caches_sysctl_handler,
1217 .strategy = &sysctl_intvec,
1220 .ctl_name = VM_MIN_FREE_KBYTES,
1221 .procname = "min_free_kbytes",
1222 .data = &min_free_kbytes,
1223 .maxlen = sizeof(min_free_kbytes),
1225 .proc_handler = &min_free_kbytes_sysctl_handler,
1226 .strategy = &sysctl_intvec,
1230 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1231 .procname = "percpu_pagelist_fraction",
1232 .data = &percpu_pagelist_fraction,
1233 .maxlen = sizeof(percpu_pagelist_fraction),
1235 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1236 .strategy = &sysctl_intvec,
1237 .extra1 = &min_percpu_pagelist_fract,
1241 .ctl_name = VM_MAX_MAP_COUNT,
1242 .procname = "max_map_count",
1243 .data = &sysctl_max_map_count,
1244 .maxlen = sizeof(sysctl_max_map_count),
1246 .proc_handler = &proc_dointvec
1250 .ctl_name = CTL_UNNUMBERED,
1251 .procname = "nr_trim_pages",
1252 .data = &sysctl_nr_trim_pages,
1253 .maxlen = sizeof(sysctl_nr_trim_pages),
1255 .proc_handler = &proc_dointvec_minmax,
1256 .strategy = &sysctl_intvec,
1261 .ctl_name = VM_LAPTOP_MODE,
1262 .procname = "laptop_mode",
1263 .data = &laptop_mode,
1264 .maxlen = sizeof(laptop_mode),
1266 .proc_handler = &proc_dointvec_jiffies,
1267 .strategy = &sysctl_jiffies,
1270 .ctl_name = VM_BLOCK_DUMP,
1271 .procname = "block_dump",
1272 .data = &block_dump,
1273 .maxlen = sizeof(block_dump),
1275 .proc_handler = &proc_dointvec,
1276 .strategy = &sysctl_intvec,
1280 .ctl_name = VM_VFS_CACHE_PRESSURE,
1281 .procname = "vfs_cache_pressure",
1282 .data = &sysctl_vfs_cache_pressure,
1283 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1285 .proc_handler = &proc_dointvec,
1286 .strategy = &sysctl_intvec,
1289 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1291 .ctl_name = VM_LEGACY_VA_LAYOUT,
1292 .procname = "legacy_va_layout",
1293 .data = &sysctl_legacy_va_layout,
1294 .maxlen = sizeof(sysctl_legacy_va_layout),
1296 .proc_handler = &proc_dointvec,
1297 .strategy = &sysctl_intvec,
1303 .ctl_name = VM_ZONE_RECLAIM_MODE,
1304 .procname = "zone_reclaim_mode",
1305 .data = &zone_reclaim_mode,
1306 .maxlen = sizeof(zone_reclaim_mode),
1308 .proc_handler = &proc_dointvec,
1309 .strategy = &sysctl_intvec,
1313 .ctl_name = VM_MIN_UNMAPPED,
1314 .procname = "min_unmapped_ratio",
1315 .data = &sysctl_min_unmapped_ratio,
1316 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1318 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1319 .strategy = &sysctl_intvec,
1321 .extra2 = &one_hundred,
1324 .ctl_name = VM_MIN_SLAB,
1325 .procname = "min_slab_ratio",
1326 .data = &sysctl_min_slab_ratio,
1327 .maxlen = sizeof(sysctl_min_slab_ratio),
1329 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1330 .strategy = &sysctl_intvec,
1332 .extra2 = &one_hundred,
1337 .ctl_name = CTL_UNNUMBERED,
1338 .procname = "stat_interval",
1339 .data = &sysctl_stat_interval,
1340 .maxlen = sizeof(sysctl_stat_interval),
1342 .proc_handler = &proc_dointvec_jiffies,
1343 .strategy = &sysctl_jiffies,
1347 .ctl_name = CTL_UNNUMBERED,
1348 .procname = "mmap_min_addr",
1349 .data = &dac_mmap_min_addr,
1350 .maxlen = sizeof(unsigned long),
1352 .proc_handler = &mmap_min_addr_handler,
1356 .ctl_name = CTL_UNNUMBERED,
1357 .procname = "numa_zonelist_order",
1358 .data = &numa_zonelist_order,
1359 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1361 .proc_handler = &numa_zonelist_order_handler,
1362 .strategy = &sysctl_string,
1365 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1366 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1368 .ctl_name = VM_VDSO_ENABLED,
1369 .procname = "vdso_enabled",
1370 .data = &vdso_enabled,
1371 .maxlen = sizeof(vdso_enabled),
1373 .proc_handler = &proc_dointvec,
1374 .strategy = &sysctl_intvec,
1378 #ifdef CONFIG_HIGHMEM
1380 .ctl_name = CTL_UNNUMBERED,
1381 .procname = "highmem_is_dirtyable",
1382 .data = &vm_highmem_is_dirtyable,
1383 .maxlen = sizeof(vm_highmem_is_dirtyable),
1385 .proc_handler = &proc_dointvec_minmax,
1386 .strategy = &sysctl_intvec,
1392 .ctl_name = CTL_UNNUMBERED,
1393 .procname = "scan_unevictable_pages",
1394 .data = &scan_unevictable_pages,
1395 .maxlen = sizeof(scan_unevictable_pages),
1397 .proc_handler = &scan_unevictable_handler,
1399 #ifdef CONFIG_MEMORY_FAILURE
1401 .ctl_name = CTL_UNNUMBERED,
1402 .procname = "memory_failure_early_kill",
1403 .data = &sysctl_memory_failure_early_kill,
1404 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1406 .proc_handler = &proc_dointvec_minmax,
1407 .strategy = &sysctl_intvec,
1412 .ctl_name = CTL_UNNUMBERED,
1413 .procname = "memory_failure_recovery",
1414 .data = &sysctl_memory_failure_recovery,
1415 .maxlen = sizeof(sysctl_memory_failure_recovery),
1417 .proc_handler = &proc_dointvec_minmax,
1418 .strategy = &sysctl_intvec,
1425 * NOTE: do not add new entries to this table unless you have read
1426 * Documentation/sysctl/ctl_unnumbered.txt
1431 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1432 static struct ctl_table binfmt_misc_table[] = {
1437 static struct ctl_table fs_table[] = {
1439 .ctl_name = FS_NRINODE,
1440 .procname = "inode-nr",
1441 .data = &inodes_stat,
1442 .maxlen = 2*sizeof(int),
1444 .proc_handler = &proc_dointvec,
1447 .ctl_name = FS_STATINODE,
1448 .procname = "inode-state",
1449 .data = &inodes_stat,
1450 .maxlen = 7*sizeof(int),
1452 .proc_handler = &proc_dointvec,
1455 .procname = "file-nr",
1456 .data = &files_stat,
1457 .maxlen = 3*sizeof(int),
1459 .proc_handler = &proc_nr_files,
1462 .ctl_name = FS_MAXFILE,
1463 .procname = "file-max",
1464 .data = &files_stat.max_files,
1465 .maxlen = sizeof(int),
1467 .proc_handler = &proc_dointvec,
1470 .ctl_name = CTL_UNNUMBERED,
1471 .procname = "nr_open",
1472 .data = &sysctl_nr_open,
1473 .maxlen = sizeof(int),
1475 .proc_handler = &proc_dointvec_minmax,
1476 .extra1 = &sysctl_nr_open_min,
1477 .extra2 = &sysctl_nr_open_max,
1480 .ctl_name = FS_DENTRY,
1481 .procname = "dentry-state",
1482 .data = &dentry_stat,
1483 .maxlen = 6*sizeof(int),
1485 .proc_handler = &proc_dointvec,
1488 .ctl_name = FS_OVERFLOWUID,
1489 .procname = "overflowuid",
1490 .data = &fs_overflowuid,
1491 .maxlen = sizeof(int),
1493 .proc_handler = &proc_dointvec_minmax,
1494 .strategy = &sysctl_intvec,
1495 .extra1 = &minolduid,
1496 .extra2 = &maxolduid,
1499 .ctl_name = FS_OVERFLOWGID,
1500 .procname = "overflowgid",
1501 .data = &fs_overflowgid,
1502 .maxlen = sizeof(int),
1504 .proc_handler = &proc_dointvec_minmax,
1505 .strategy = &sysctl_intvec,
1506 .extra1 = &minolduid,
1507 .extra2 = &maxolduid,
1509 #ifdef CONFIG_FILE_LOCKING
1511 .ctl_name = FS_LEASES,
1512 .procname = "leases-enable",
1513 .data = &leases_enable,
1514 .maxlen = sizeof(int),
1516 .proc_handler = &proc_dointvec,
1519 #ifdef CONFIG_DNOTIFY
1521 .ctl_name = FS_DIR_NOTIFY,
1522 .procname = "dir-notify-enable",
1523 .data = &dir_notify_enable,
1524 .maxlen = sizeof(int),
1526 .proc_handler = &proc_dointvec,
1530 #ifdef CONFIG_FILE_LOCKING
1532 .ctl_name = FS_LEASE_TIME,
1533 .procname = "lease-break-time",
1534 .data = &lease_break_time,
1535 .maxlen = sizeof(int),
1537 .proc_handler = &proc_dointvec,
1542 .procname = "aio-nr",
1544 .maxlen = sizeof(aio_nr),
1546 .proc_handler = &proc_doulongvec_minmax,
1549 .procname = "aio-max-nr",
1550 .data = &aio_max_nr,
1551 .maxlen = sizeof(aio_max_nr),
1553 .proc_handler = &proc_doulongvec_minmax,
1555 #endif /* CONFIG_AIO */
1556 #ifdef CONFIG_INOTIFY_USER
1558 .ctl_name = FS_INOTIFY,
1559 .procname = "inotify",
1561 .child = inotify_table,
1566 .procname = "epoll",
1568 .child = epoll_table,
1573 .ctl_name = KERN_SETUID_DUMPABLE,
1574 .procname = "suid_dumpable",
1575 .data = &suid_dumpable,
1576 .maxlen = sizeof(int),
1578 .proc_handler = &proc_dointvec_minmax,
1579 .strategy = &sysctl_intvec,
1583 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1585 .ctl_name = CTL_UNNUMBERED,
1586 .procname = "binfmt_misc",
1588 .child = binfmt_misc_table,
1592 * NOTE: do not add new entries to this table unless you have read
1593 * Documentation/sysctl/ctl_unnumbered.txt
1598 static struct ctl_table debug_table[] = {
1599 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1601 .ctl_name = CTL_UNNUMBERED,
1602 .procname = "exception-trace",
1603 .data = &show_unhandled_signals,
1604 .maxlen = sizeof(int),
1606 .proc_handler = proc_dointvec
1612 static struct ctl_table dev_table[] = {
1616 static DEFINE_SPINLOCK(sysctl_lock);
1618 /* called under sysctl_lock */
1619 static int use_table(struct ctl_table_header *p)
1621 if (unlikely(p->unregistering))
1627 /* called under sysctl_lock */
1628 static void unuse_table(struct ctl_table_header *p)
1631 if (unlikely(p->unregistering))
1632 complete(p->unregistering);
1635 /* called under sysctl_lock, will reacquire if has to wait */
1636 static void start_unregistering(struct ctl_table_header *p)
1639 * if p->used is 0, nobody will ever touch that entry again;
1640 * we'll eliminate all paths to it before dropping sysctl_lock
1642 if (unlikely(p->used)) {
1643 struct completion wait;
1644 init_completion(&wait);
1645 p->unregistering = &wait;
1646 spin_unlock(&sysctl_lock);
1647 wait_for_completion(&wait);
1648 spin_lock(&sysctl_lock);
1650 /* anything non-NULL; we'll never dereference it */
1651 p->unregistering = ERR_PTR(-EINVAL);
1654 * do not remove from the list until nobody holds it; walking the
1655 * list in do_sysctl() relies on that.
1657 list_del_init(&p->ctl_entry);
1660 void sysctl_head_get(struct ctl_table_header *head)
1662 spin_lock(&sysctl_lock);
1664 spin_unlock(&sysctl_lock);
1667 void sysctl_head_put(struct ctl_table_header *head)
1669 spin_lock(&sysctl_lock);
1672 spin_unlock(&sysctl_lock);
1675 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1679 spin_lock(&sysctl_lock);
1680 if (!use_table(head))
1681 head = ERR_PTR(-ENOENT);
1682 spin_unlock(&sysctl_lock);
1686 void sysctl_head_finish(struct ctl_table_header *head)
1690 spin_lock(&sysctl_lock);
1692 spin_unlock(&sysctl_lock);
1695 static struct ctl_table_set *
1696 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1698 struct ctl_table_set *set = &root->default_set;
1700 set = root->lookup(root, namespaces);
1704 static struct list_head *
1705 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1707 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1711 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1712 struct ctl_table_header *prev)
1714 struct ctl_table_root *root;
1715 struct list_head *header_list;
1716 struct ctl_table_header *head;
1717 struct list_head *tmp;
1719 spin_lock(&sysctl_lock);
1722 tmp = &prev->ctl_entry;
1726 tmp = &root_table_header.ctl_entry;
1728 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1730 if (!use_table(head))
1732 spin_unlock(&sysctl_lock);
1737 header_list = lookup_header_list(root, namespaces);
1738 if (tmp != header_list)
1742 root = list_entry(root->root_list.next,
1743 struct ctl_table_root, root_list);
1744 if (root == &sysctl_table_root)
1746 header_list = lookup_header_list(root, namespaces);
1747 } while (list_empty(header_list));
1748 tmp = header_list->next;
1751 spin_unlock(&sysctl_lock);
1755 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1757 return __sysctl_head_next(current->nsproxy, prev);
1760 void register_sysctl_root(struct ctl_table_root *root)
1762 spin_lock(&sysctl_lock);
1763 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1764 spin_unlock(&sysctl_lock);
1768 * sysctl_perm does NOT grant the superuser all rights automatically, because
1769 * some sysctl variables are readonly even to root.
1772 static int test_perm(int mode, int op)
1774 if (!current_euid())
1776 else if (in_egroup_p(0))
1778 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1783 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1788 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1792 if (root->permissions)
1793 mode = root->permissions(root, current->nsproxy, table);
1797 return test_perm(mode, op);
1800 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1802 for (; table->ctl_name || table->procname; table++) {
1803 table->parent = parent;
1805 sysctl_set_parent(table, table->child);
1809 static __init int sysctl_init(void)
1811 sysctl_set_parent(NULL, root_table);
1812 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1815 err = sysctl_check_table(current->nsproxy, root_table);
1821 core_initcall(sysctl_init);
1823 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1824 struct ctl_table *table)
1826 struct ctl_table *p;
1827 const char *s = branch->procname;
1829 /* branch should have named subdirectory as its first element */
1830 if (!s || !branch->child)
1833 /* ... and nothing else */
1834 if (branch[1].procname || branch[1].ctl_name)
1837 /* table should contain subdirectory with the same name */
1838 for (p = table; p->procname || p->ctl_name; p++) {
1841 if (p->procname && strcmp(p->procname, s) == 0)
1847 /* see if attaching q to p would be an improvement */
1848 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1850 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1851 struct ctl_table *next;
1853 int not_in_parent = !p->attached_by;
1855 while ((next = is_branch_in(by, to)) != NULL) {
1856 if (by == q->attached_by)
1858 if (to == p->attached_by)
1864 if (is_better && not_in_parent) {
1865 q->attached_by = by;
1866 q->attached_to = to;
1872 * __register_sysctl_paths - register a sysctl hierarchy
1873 * @root: List of sysctl headers to register on
1874 * @namespaces: Data to compute which lists of sysctl entries are visible
1875 * @path: The path to the directory the sysctl table is in.
1876 * @table: the top-level table structure
1878 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1879 * array. A completely 0 filled entry terminates the table.
1881 * The members of the &struct ctl_table structure are used as follows:
1883 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1884 * must be unique within that level of sysctl
1886 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1887 * enter a sysctl file
1889 * data - a pointer to data for use by proc_handler
1891 * maxlen - the maximum size in bytes of the data
1893 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1895 * child - a pointer to the child sysctl table if this entry is a directory, or
1898 * proc_handler - the text handler routine (described below)
1900 * strategy - the strategy routine (described below)
1902 * de - for internal use by the sysctl routines
1904 * extra1, extra2 - extra pointers usable by the proc handler routines
1906 * Leaf nodes in the sysctl tree will be represented by a single file
1907 * under /proc; non-leaf nodes will be represented by directories.
1909 * sysctl(2) can automatically manage read and write requests through
1910 * the sysctl table. The data and maxlen fields of the ctl_table
1911 * struct enable minimal validation of the values being written to be
1912 * performed, and the mode field allows minimal authentication.
1914 * More sophisticated management can be enabled by the provision of a
1915 * strategy routine with the table entry. This will be called before
1916 * any automatic read or write of the data is performed.
1918 * The strategy routine may return
1920 * < 0 - Error occurred (error is passed to user process)
1922 * 0 - OK - proceed with automatic read or write.
1924 * > 0 - OK - read or write has been done by the strategy routine, so
1925 * return immediately.
1927 * There must be a proc_handler routine for any terminal nodes
1928 * mirrored under /proc/sys (non-terminals are handled by a built-in
1929 * directory handler). Several default handlers are available to
1930 * cover common cases -
1932 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1933 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1934 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1936 * It is the handler's job to read the input buffer from user memory
1937 * and process it. The handler should return 0 on success.
1939 * This routine returns %NULL on a failure to register, and a pointer
1940 * to the table header on success.
1942 struct ctl_table_header *__register_sysctl_paths(
1943 struct ctl_table_root *root,
1944 struct nsproxy *namespaces,
1945 const struct ctl_path *path, struct ctl_table *table)
1947 struct ctl_table_header *header;
1948 struct ctl_table *new, **prevp;
1949 unsigned int n, npath;
1950 struct ctl_table_set *set;
1952 /* Count the path components */
1953 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1957 * For each path component, allocate a 2-element ctl_table array.
1958 * The first array element will be filled with the sysctl entry
1959 * for this, the second will be the sentinel (ctl_name == 0).
1961 * We allocate everything in one go so that we don't have to
1962 * worry about freeing additional memory in unregister_sysctl_table.
1964 header = kzalloc(sizeof(struct ctl_table_header) +
1965 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1969 new = (struct ctl_table *) (header + 1);
1971 /* Now connect the dots */
1972 prevp = &header->ctl_table;
1973 for (n = 0; n < npath; ++n, ++path) {
1974 /* Copy the procname */
1975 new->procname = path->procname;
1976 new->ctl_name = path->ctl_name;
1980 prevp = &new->child;
1985 header->ctl_table_arg = table;
1987 INIT_LIST_HEAD(&header->ctl_entry);
1989 header->unregistering = NULL;
1990 header->root = root;
1991 sysctl_set_parent(NULL, header->ctl_table);
1993 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1994 if (sysctl_check_table(namespaces, header->ctl_table)) {
1999 spin_lock(&sysctl_lock);
2000 header->set = lookup_header_set(root, namespaces);
2001 header->attached_by = header->ctl_table;
2002 header->attached_to = root_table;
2003 header->parent = &root_table_header;
2004 for (set = header->set; set; set = set->parent) {
2005 struct ctl_table_header *p;
2006 list_for_each_entry(p, &set->list, ctl_entry) {
2007 if (p->unregistering)
2009 try_attach(p, header);
2012 header->parent->count++;
2013 list_add_tail(&header->ctl_entry, &header->set->list);
2014 spin_unlock(&sysctl_lock);
2020 * register_sysctl_table_path - register a sysctl table hierarchy
2021 * @path: The path to the directory the sysctl table is in.
2022 * @table: the top-level table structure
2024 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2025 * array. A completely 0 filled entry terminates the table.
2027 * See __register_sysctl_paths for more details.
2029 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2030 struct ctl_table *table)
2032 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2037 * register_sysctl_table - register a sysctl table hierarchy
2038 * @table: the top-level table structure
2040 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2041 * array. A completely 0 filled entry terminates the table.
2043 * See register_sysctl_paths for more details.
2045 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2047 static const struct ctl_path null_path[] = { {} };
2049 return register_sysctl_paths(null_path, table);
2053 * unregister_sysctl_table - unregister a sysctl table hierarchy
2054 * @header: the header returned from register_sysctl_table
2056 * Unregisters the sysctl table and all children. proc entries may not
2057 * actually be removed until they are no longer used by anyone.
2059 void unregister_sysctl_table(struct ctl_table_header * header)
2066 spin_lock(&sysctl_lock);
2067 start_unregistering(header);
2068 if (!--header->parent->count) {
2070 kfree(header->parent);
2072 if (!--header->count)
2074 spin_unlock(&sysctl_lock);
2077 int sysctl_is_seen(struct ctl_table_header *p)
2079 struct ctl_table_set *set = p->set;
2081 spin_lock(&sysctl_lock);
2082 if (p->unregistering)
2084 else if (!set->is_seen)
2087 res = set->is_seen(set);
2088 spin_unlock(&sysctl_lock);
2092 void setup_sysctl_set(struct ctl_table_set *p,
2093 struct ctl_table_set *parent,
2094 int (*is_seen)(struct ctl_table_set *))
2096 INIT_LIST_HEAD(&p->list);
2097 p->parent = parent ? parent : &sysctl_table_root.default_set;
2098 p->is_seen = is_seen;
2101 #else /* !CONFIG_SYSCTL */
2102 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2107 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2108 struct ctl_table *table)
2113 void unregister_sysctl_table(struct ctl_table_header * table)
2117 void setup_sysctl_set(struct ctl_table_set *p,
2118 struct ctl_table_set *parent,
2119 int (*is_seen)(struct ctl_table_set *))
2123 void sysctl_head_put(struct ctl_table_header *head)
2127 #endif /* CONFIG_SYSCTL */
2133 #ifdef CONFIG_PROC_SYSCTL
2135 static int _proc_do_string(void* data, int maxlen, int write,
2136 void __user *buffer,
2137 size_t *lenp, loff_t *ppos)
2143 if (!data || !maxlen || !*lenp) {
2151 while (len < *lenp) {
2152 if (get_user(c, p++))
2154 if (c == 0 || c == '\n')
2160 if(copy_from_user(data, buffer, len))
2162 ((char *) data)[len] = 0;
2180 if(copy_to_user(buffer, data, len))
2183 if(put_user('\n', ((char __user *) buffer) + len))
2194 * proc_dostring - read a string sysctl
2195 * @table: the sysctl table
2196 * @write: %TRUE if this is a write to the sysctl file
2197 * @buffer: the user buffer
2198 * @lenp: the size of the user buffer
2199 * @ppos: file position
2201 * Reads/writes a string from/to the user buffer. If the kernel
2202 * buffer provided is not large enough to hold the string, the
2203 * string is truncated. The copied string is %NULL-terminated.
2204 * If the string is being read by the user process, it is copied
2205 * and a newline '\n' is added. It is truncated if the buffer is
2208 * Returns 0 on success.
2210 int proc_dostring(struct ctl_table *table, int write,
2211 void __user *buffer, size_t *lenp, loff_t *ppos)
2213 return _proc_do_string(table->data, table->maxlen, write,
2214 buffer, lenp, ppos);
2218 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2220 int write, void *data)
2223 *valp = *negp ? -*lvalp : *lvalp;
2228 *lvalp = (unsigned long)-val;
2231 *lvalp = (unsigned long)val;
2237 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2238 int write, void __user *buffer,
2239 size_t *lenp, loff_t *ppos,
2240 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2241 int write, void *data),
2244 #define TMPBUFLEN 21
2245 int *i, vleft, first = 1, neg;
2249 char buf[TMPBUFLEN], *p;
2250 char __user *s = buffer;
2252 if (!tbl_data || !table->maxlen || !*lenp ||
2253 (*ppos && !write)) {
2258 i = (int *) tbl_data;
2259 vleft = table->maxlen / sizeof(*i);
2263 conv = do_proc_dointvec_conv;
2265 for (; left && vleft--; i++, first=0) {
2280 if (len > sizeof(buf) - 1)
2281 len = sizeof(buf) - 1;
2282 if (copy_from_user(buf, s, len))
2286 if (*p == '-' && left > 1) {
2290 if (*p < '0' || *p > '9')
2293 lval = simple_strtoul(p, &p, 0);
2296 if ((len < left) && *p && !isspace(*p))
2301 if (conv(&neg, &lval, i, 1, data))
2308 if (conv(&neg, &lval, i, 0, data))
2311 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2315 if(copy_to_user(s, buf, len))
2322 if (!write && !first && left) {
2323 if(put_user('\n', s))
2330 if (get_user(c, s++))
2345 static int do_proc_dointvec(struct ctl_table *table, int write,
2346 void __user *buffer, size_t *lenp, loff_t *ppos,
2347 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2348 int write, void *data),
2351 return __do_proc_dointvec(table->data, table, write,
2352 buffer, lenp, ppos, conv, data);
2356 * proc_dointvec - read a vector of integers
2357 * @table: the sysctl table
2358 * @write: %TRUE if this is a write to the sysctl file
2359 * @buffer: the user buffer
2360 * @lenp: the size of the user buffer
2361 * @ppos: file position
2363 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2364 * values from/to the user buffer, treated as an ASCII string.
2366 * Returns 0 on success.
2368 int proc_dointvec(struct ctl_table *table, int write,
2369 void __user *buffer, size_t *lenp, loff_t *ppos)
2371 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2376 * Taint values can only be increased
2377 * This means we can safely use a temporary.
2379 static int proc_taint(struct ctl_table *table, int write,
2380 void __user *buffer, size_t *lenp, loff_t *ppos)
2383 unsigned long tmptaint = get_taint();
2386 if (write && !capable(CAP_SYS_ADMIN))
2391 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2397 * Poor man's atomic or. Not worth adding a primitive
2398 * to everyone's atomic.h for this
2401 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2402 if ((tmptaint >> i) & 1)
2410 struct do_proc_dointvec_minmax_conv_param {
2415 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2417 int write, void *data)
2419 struct do_proc_dointvec_minmax_conv_param *param = data;
2421 int val = *negp ? -*lvalp : *lvalp;
2422 if ((param->min && *param->min > val) ||
2423 (param->max && *param->max < val))
2430 *lvalp = (unsigned long)-val;
2433 *lvalp = (unsigned long)val;
2440 * proc_dointvec_minmax - read a vector of integers with min/max values
2441 * @table: the sysctl table
2442 * @write: %TRUE if this is a write to the sysctl file
2443 * @buffer: the user buffer
2444 * @lenp: the size of the user buffer
2445 * @ppos: file position
2447 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2448 * values from/to the user buffer, treated as an ASCII string.
2450 * This routine will ensure the values are within the range specified by
2451 * table->extra1 (min) and table->extra2 (max).
2453 * Returns 0 on success.
2455 int proc_dointvec_minmax(struct ctl_table *table, int write,
2456 void __user *buffer, size_t *lenp, loff_t *ppos)
2458 struct do_proc_dointvec_minmax_conv_param param = {
2459 .min = (int *) table->extra1,
2460 .max = (int *) table->extra2,
2462 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2463 do_proc_dointvec_minmax_conv, ¶m);
2466 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2467 void __user *buffer,
2468 size_t *lenp, loff_t *ppos,
2469 unsigned long convmul,
2470 unsigned long convdiv)
2472 #define TMPBUFLEN 21
2473 unsigned long *i, *min, *max, val;
2474 int vleft, first=1, neg;
2476 char buf[TMPBUFLEN], *p;
2477 char __user *s = buffer;
2479 if (!data || !table->maxlen || !*lenp ||
2480 (*ppos && !write)) {
2485 i = (unsigned long *) data;
2486 min = (unsigned long *) table->extra1;
2487 max = (unsigned long *) table->extra2;
2488 vleft = table->maxlen / sizeof(unsigned long);
2491 for (; left && vleft--; i++, min++, max++, first=0) {
2506 if (len > TMPBUFLEN-1)
2508 if (copy_from_user(buf, s, len))
2512 if (*p == '-' && left > 1) {
2516 if (*p < '0' || *p > '9')
2518 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2520 if ((len < left) && *p && !isspace(*p))
2529 if ((min && val < *min) || (max && val > *max))
2536 sprintf(p, "%lu", convdiv * (*i) / convmul);
2540 if(copy_to_user(s, buf, len))
2547 if (!write && !first && left) {
2548 if(put_user('\n', s))
2555 if (get_user(c, s++))
2570 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2571 void __user *buffer,
2572 size_t *lenp, loff_t *ppos,
2573 unsigned long convmul,
2574 unsigned long convdiv)
2576 return __do_proc_doulongvec_minmax(table->data, table, write,
2577 buffer, lenp, ppos, convmul, convdiv);
2581 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2582 * @table: the sysctl table
2583 * @write: %TRUE if this is a write to the sysctl file
2584 * @buffer: the user buffer
2585 * @lenp: the size of the user buffer
2586 * @ppos: file position
2588 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2589 * values from/to the user buffer, treated as an ASCII string.
2591 * This routine will ensure the values are within the range specified by
2592 * table->extra1 (min) and table->extra2 (max).
2594 * Returns 0 on success.
2596 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2597 void __user *buffer, size_t *lenp, loff_t *ppos)
2599 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2603 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2604 * @table: the sysctl table
2605 * @write: %TRUE if this is a write to the sysctl file
2606 * @buffer: the user buffer
2607 * @lenp: the size of the user buffer
2608 * @ppos: file position
2610 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2611 * values from/to the user buffer, treated as an ASCII string. The values
2612 * are treated as milliseconds, and converted to jiffies when they are stored.
2614 * This routine will ensure the values are within the range specified by
2615 * table->extra1 (min) and table->extra2 (max).
2617 * Returns 0 on success.
2619 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2620 void __user *buffer,
2621 size_t *lenp, loff_t *ppos)
2623 return do_proc_doulongvec_minmax(table, write, buffer,
2624 lenp, ppos, HZ, 1000l);
2628 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2630 int write, void *data)
2633 if (*lvalp > LONG_MAX / HZ)
2635 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2641 lval = (unsigned long)-val;
2644 lval = (unsigned long)val;
2651 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2653 int write, void *data)
2656 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2658 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2664 lval = (unsigned long)-val;
2667 lval = (unsigned long)val;
2669 *lvalp = jiffies_to_clock_t(lval);
2674 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2676 int write, void *data)
2679 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2685 lval = (unsigned long)-val;
2688 lval = (unsigned long)val;
2690 *lvalp = jiffies_to_msecs(lval);
2696 * proc_dointvec_jiffies - read a vector of integers as seconds
2697 * @table: the sysctl table
2698 * @write: %TRUE if this is a write to the sysctl file
2699 * @buffer: the user buffer
2700 * @lenp: the size of the user buffer
2701 * @ppos: file position
2703 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2704 * values from/to the user buffer, treated as an ASCII string.
2705 * The values read are assumed to be in seconds, and are converted into
2708 * Returns 0 on success.
2710 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2711 void __user *buffer, size_t *lenp, loff_t *ppos)
2713 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2714 do_proc_dointvec_jiffies_conv,NULL);
2718 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2719 * @table: the sysctl table
2720 * @write: %TRUE if this is a write to the sysctl file
2721 * @buffer: the user buffer
2722 * @lenp: the size of the user buffer
2723 * @ppos: pointer to the file position
2725 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2726 * values from/to the user buffer, treated as an ASCII string.
2727 * The values read are assumed to be in 1/USER_HZ seconds, and
2728 * are converted into jiffies.
2730 * Returns 0 on success.
2732 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2733 void __user *buffer, size_t *lenp, loff_t *ppos)
2735 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2736 do_proc_dointvec_userhz_jiffies_conv,NULL);
2740 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2741 * @table: the sysctl table
2742 * @write: %TRUE if this is a write to the sysctl file
2743 * @buffer: the user buffer
2744 * @lenp: the size of the user buffer
2745 * @ppos: file position
2746 * @ppos: the current position in the file
2748 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2749 * values from/to the user buffer, treated as an ASCII string.
2750 * The values read are assumed to be in 1/1000 seconds, and
2751 * are converted into jiffies.
2753 * Returns 0 on success.
2755 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2756 void __user *buffer, size_t *lenp, loff_t *ppos)
2758 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2759 do_proc_dointvec_ms_jiffies_conv, NULL);
2762 static int proc_do_cad_pid(struct ctl_table *table, int write,
2763 void __user *buffer, size_t *lenp, loff_t *ppos)
2765 struct pid *new_pid;
2769 tmp = pid_vnr(cad_pid);
2771 r = __do_proc_dointvec(&tmp, table, write, buffer,
2772 lenp, ppos, NULL, NULL);
2776 new_pid = find_get_pid(tmp);
2780 put_pid(xchg(&cad_pid, new_pid));
2784 #else /* CONFIG_PROC_FS */
2786 int proc_dostring(struct ctl_table *table, int write,
2787 void __user *buffer, size_t *lenp, loff_t *ppos)
2792 int proc_dointvec(struct ctl_table *table, int write,
2793 void __user *buffer, size_t *lenp, loff_t *ppos)
2798 int proc_dointvec_minmax(struct ctl_table *table, int write,
2799 void __user *buffer, size_t *lenp, loff_t *ppos)
2804 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2805 void __user *buffer, size_t *lenp, loff_t *ppos)
2810 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2811 void __user *buffer, size_t *lenp, loff_t *ppos)
2816 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2817 void __user *buffer, size_t *lenp, loff_t *ppos)
2822 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2823 void __user *buffer, size_t *lenp, loff_t *ppos)
2828 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2829 void __user *buffer,
2830 size_t *lenp, loff_t *ppos)
2836 #endif /* CONFIG_PROC_FS */
2839 #ifdef CONFIG_SYSCTL_SYSCALL
2841 * General sysctl support routines
2844 /* The generic sysctl data routine (used if no strategy routine supplied) */
2845 int sysctl_data(struct ctl_table *table,
2846 void __user *oldval, size_t __user *oldlenp,
2847 void __user *newval, size_t newlen)
2851 /* Get out of I don't have a variable */
2852 if (!table->data || !table->maxlen)
2855 if (oldval && oldlenp) {
2856 if (get_user(len, oldlenp))
2859 if (len > table->maxlen)
2860 len = table->maxlen;
2861 if (copy_to_user(oldval, table->data, len))
2863 if (put_user(len, oldlenp))
2868 if (newval && newlen) {
2869 if (newlen > table->maxlen)
2870 newlen = table->maxlen;
2872 if (copy_from_user(table->data, newval, newlen))
2878 /* The generic string strategy routine: */
2879 int sysctl_string(struct ctl_table *table,
2880 void __user *oldval, size_t __user *oldlenp,
2881 void __user *newval, size_t newlen)
2883 if (!table->data || !table->maxlen)
2886 if (oldval && oldlenp) {
2888 if (get_user(bufsize, oldlenp))
2891 size_t len = strlen(table->data), copied;
2893 /* This shouldn't trigger for a well-formed sysctl */
2894 if (len > table->maxlen)
2895 len = table->maxlen;
2897 /* Copy up to a max of bufsize-1 bytes of the string */
2898 copied = (len >= bufsize) ? bufsize - 1 : len;
2900 if (copy_to_user(oldval, table->data, copied) ||
2901 put_user(0, (char __user *)(oldval + copied)))
2903 if (put_user(len, oldlenp))
2907 if (newval && newlen) {
2908 size_t len = newlen;
2909 if (len > table->maxlen)
2910 len = table->maxlen;
2911 if(copy_from_user(table->data, newval, len))
2913 if (len == table->maxlen)
2915 ((char *) table->data)[len] = 0;
2921 * This function makes sure that all of the integers in the vector
2922 * are between the minimum and maximum values given in the arrays
2923 * table->extra1 and table->extra2, respectively.
2925 int sysctl_intvec(struct ctl_table *table,
2926 void __user *oldval, size_t __user *oldlenp,
2927 void __user *newval, size_t newlen)
2930 if (newval && newlen) {
2931 int __user *vec = (int __user *) newval;
2932 int *min = (int *) table->extra1;
2933 int *max = (int *) table->extra2;
2937 if (newlen % sizeof(int) != 0)
2940 if (!table->extra1 && !table->extra2)
2943 if (newlen > table->maxlen)
2944 newlen = table->maxlen;
2945 length = newlen / sizeof(int);
2947 for (i = 0; i < length; i++) {
2949 if (get_user(value, vec + i))
2951 if (min && value < min[i])
2953 if (max && value > max[i])
2960 /* Strategy function to convert jiffies to seconds */
2961 int sysctl_jiffies(struct ctl_table *table,
2962 void __user *oldval, size_t __user *oldlenp,
2963 void __user *newval, size_t newlen)
2965 if (oldval && oldlenp) {
2968 if (get_user(olen, oldlenp))
2973 if (olen < sizeof(int))
2976 val = *(int *)(table->data) / HZ;
2977 if (put_user(val, (int __user *)oldval))
2979 if (put_user(sizeof(int), oldlenp))
2983 if (newval && newlen) {
2985 if (newlen != sizeof(int))
2987 if (get_user(new, (int __user *)newval))
2989 *(int *)(table->data) = new*HZ;
2994 /* Strategy function to convert jiffies to seconds */
2995 int sysctl_ms_jiffies(struct ctl_table *table,
2996 void __user *oldval, size_t __user *oldlenp,
2997 void __user *newval, size_t newlen)
2999 if (oldval && oldlenp) {
3002 if (get_user(olen, oldlenp))
3007 if (olen < sizeof(int))
3010 val = jiffies_to_msecs(*(int *)(table->data));
3011 if (put_user(val, (int __user *)oldval))
3013 if (put_user(sizeof(int), oldlenp))
3017 if (newval && newlen) {
3019 if (newlen != sizeof(int))
3021 if (get_user(new, (int __user *)newval))
3023 *(int *)(table->data) = msecs_to_jiffies(new);
3030 #else /* CONFIG_SYSCTL_SYSCALL */
3033 int sysctl_data(struct ctl_table *table,
3034 void __user *oldval, size_t __user *oldlenp,
3035 void __user *newval, size_t newlen)
3040 int sysctl_string(struct ctl_table *table,
3041 void __user *oldval, size_t __user *oldlenp,
3042 void __user *newval, size_t newlen)
3047 int sysctl_intvec(struct ctl_table *table,
3048 void __user *oldval, size_t __user *oldlenp,
3049 void __user *newval, size_t newlen)
3054 int sysctl_jiffies(struct ctl_table *table,
3055 void __user *oldval, size_t __user *oldlenp,
3056 void __user *newval, size_t newlen)
3061 int sysctl_ms_jiffies(struct ctl_table *table,
3062 void __user *oldval, size_t __user *oldlenp,
3063 void __user *newval, size_t newlen)
3068 #endif /* CONFIG_SYSCTL_SYSCALL */
3072 * No sense putting this after each symbol definition, twice,
3073 * exception granted :-)
3075 EXPORT_SYMBOL(proc_dointvec);
3076 EXPORT_SYMBOL(proc_dointvec_jiffies);
3077 EXPORT_SYMBOL(proc_dointvec_minmax);
3078 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3079 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3080 EXPORT_SYMBOL(proc_dostring);
3081 EXPORT_SYMBOL(proc_doulongvec_minmax);
3082 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3083 EXPORT_SYMBOL(register_sysctl_table);
3084 EXPORT_SYMBOL(register_sysctl_paths);
3085 EXPORT_SYMBOL(sysctl_intvec);
3086 EXPORT_SYMBOL(sysctl_jiffies);
3087 EXPORT_SYMBOL(sysctl_ms_jiffies);
3088 EXPORT_SYMBOL(sysctl_string);
3089 EXPORT_SYMBOL(sysctl_data);
3090 EXPORT_SYMBOL(unregister_sysctl_table);