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/signal.h>
27 #include <linux/proc_fs.h>
28 #include <linux/security.h>
29 #include <linux/ctype.h>
30 #include <linux/kmemcheck.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/ratelimit.h>
40 #include <linux/hugetlb.h>
41 #include <linux/initrd.h>
42 #include <linux/key.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/vmstat.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/acpi.h>
50 #include <linux/reboot.h>
51 #include <linux/ftrace.h>
52 #include <linux/slow-work.h>
53 #include <linux/perf_event.h>
54 #include <linux/kprobes.h>
56 #include <asm/uaccess.h>
57 #include <asm/processor.h>
61 #include <asm/stacktrace.h>
66 #if defined(CONFIG_SYSCTL)
68 /* External variables not in a header file. */
69 extern int sysctl_overcommit_memory
;
70 extern int sysctl_overcommit_ratio
;
71 extern int sysctl_panic_on_oom
;
72 extern int sysctl_oom_kill_allocating_task
;
73 extern int sysctl_oom_dump_tasks
;
74 extern int max_threads
;
75 extern int core_uses_pid
;
76 extern int suid_dumpable
;
77 extern char core_pattern
[];
78 extern unsigned int core_pipe_limit
;
80 extern int min_free_kbytes
;
81 extern int pid_max_min
, pid_max_max
;
82 extern int sysctl_drop_caches
;
83 extern int percpu_pagelist_fraction
;
84 extern int compat_log
;
85 extern int latencytop_enabled
;
86 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
88 extern int sysctl_nr_trim_pages
;
91 extern int blk_iopoll_enabled
;
94 /* Constants used for minimum and maximum */
95 #ifdef CONFIG_DETECT_SOFTLOCKUP
96 static int sixty
= 60;
97 static int neg_one
= -1;
101 static int __maybe_unused one
= 1;
102 static int __maybe_unused two
= 2;
103 static unsigned long one_ul
= 1;
104 static int one_hundred
= 100;
106 static int ten_thousand
= 10000;
109 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
110 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
112 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
113 static int maxolduid
= 65535;
114 static int minolduid
;
115 static int min_percpu_pagelist_fract
= 8;
117 static int ngroups_max
= NGROUPS_MAX
;
119 #ifdef CONFIG_CHR_DEV_SG
120 extern int sg_big_buff
;
124 #include <asm/system.h>
127 #ifdef CONFIG_SPARC64
128 extern int sysctl_tsb_ratio
;
132 extern int pwrsw_enabled
;
133 extern int unaligned_enabled
;
137 #ifdef CONFIG_MATHEMU
138 extern int sysctl_ieee_emulation_warnings
;
140 extern int sysctl_userprocess_debug
;
141 extern int spin_retry
;
144 #ifdef CONFIG_BSD_PROCESS_ACCT
145 extern int acct_parm
[];
149 extern int no_unaligned_warning
;
150 extern int unaligned_dump_stack
;
153 extern struct ratelimit_state printk_ratelimit_state
;
155 #ifdef CONFIG_RT_MUTEXES
156 extern int max_lock_depth
;
159 #ifdef CONFIG_PROC_SYSCTL
160 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
161 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
162 static int proc_taint(struct ctl_table
*table
, int write
,
163 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
166 static struct ctl_table root_table
[];
167 static struct ctl_table_root sysctl_table_root
;
168 static struct ctl_table_header root_table_header
= {
170 .ctl_table
= root_table
,
171 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
172 .root
= &sysctl_table_root
,
173 .set
= &sysctl_table_root
.default_set
,
175 static struct ctl_table_root sysctl_table_root
= {
176 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
177 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
180 static struct ctl_table kern_table
[];
181 static struct ctl_table vm_table
[];
182 static struct ctl_table fs_table
[];
183 static struct ctl_table debug_table
[];
184 static struct ctl_table dev_table
[];
185 extern struct ctl_table random_table
[];
186 #ifdef CONFIG_INOTIFY_USER
187 extern struct ctl_table inotify_table
[];
190 extern struct ctl_table epoll_table
[];
193 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
194 int sysctl_legacy_va_layout
;
197 extern int prove_locking
;
198 extern int lock_stat
;
200 /* The default sysctl tables: */
202 static struct ctl_table root_table
[] = {
204 .procname
= "kernel",
221 .child
= debug_table
,
229 * NOTE: do not add new entries to this table unless you have read
230 * Documentation/sysctl/ctl_unnumbered.txt
235 #ifdef CONFIG_SCHED_DEBUG
236 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
237 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
238 static int min_wakeup_granularity_ns
; /* 0 usecs */
239 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
240 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
241 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
242 static int min_sched_shares_ratelimit
= 100000; /* 100 usec */
243 static int max_sched_shares_ratelimit
= NSEC_PER_SEC
; /* 1 second */
246 static struct ctl_table kern_table
[] = {
248 .procname
= "sched_child_runs_first",
249 .data
= &sysctl_sched_child_runs_first
,
250 .maxlen
= sizeof(unsigned int),
252 .proc_handler
= proc_dointvec
,
254 #ifdef CONFIG_SCHED_DEBUG
256 .procname
= "sched_min_granularity_ns",
257 .data
= &sysctl_sched_min_granularity
,
258 .maxlen
= sizeof(unsigned int),
260 .proc_handler
= sched_proc_update_handler
,
261 .extra1
= &min_sched_granularity_ns
,
262 .extra2
= &max_sched_granularity_ns
,
265 .procname
= "sched_latency_ns",
266 .data
= &sysctl_sched_latency
,
267 .maxlen
= sizeof(unsigned int),
269 .proc_handler
= sched_proc_update_handler
,
270 .extra1
= &min_sched_granularity_ns
,
271 .extra2
= &max_sched_granularity_ns
,
274 .procname
= "sched_wakeup_granularity_ns",
275 .data
= &sysctl_sched_wakeup_granularity
,
276 .maxlen
= sizeof(unsigned int),
278 .proc_handler
= sched_proc_update_handler
,
279 .extra1
= &min_wakeup_granularity_ns
,
280 .extra2
= &max_wakeup_granularity_ns
,
283 .procname
= "sched_shares_ratelimit",
284 .data
= &sysctl_sched_shares_ratelimit
,
285 .maxlen
= sizeof(unsigned int),
287 .proc_handler
= sched_proc_update_handler
,
288 .extra1
= &min_sched_shares_ratelimit
,
289 .extra2
= &max_sched_shares_ratelimit
,
292 .procname
= "sched_tunable_scaling",
293 .data
= &sysctl_sched_tunable_scaling
,
294 .maxlen
= sizeof(enum sched_tunable_scaling
),
296 .proc_handler
= sched_proc_update_handler
,
297 .extra1
= &min_sched_tunable_scaling
,
298 .extra2
= &max_sched_tunable_scaling
,
301 .procname
= "sched_shares_thresh",
302 .data
= &sysctl_sched_shares_thresh
,
303 .maxlen
= sizeof(unsigned int),
305 .proc_handler
= proc_dointvec_minmax
,
309 .procname
= "sched_migration_cost",
310 .data
= &sysctl_sched_migration_cost
,
311 .maxlen
= sizeof(unsigned int),
313 .proc_handler
= proc_dointvec
,
316 .procname
= "sched_nr_migrate",
317 .data
= &sysctl_sched_nr_migrate
,
318 .maxlen
= sizeof(unsigned int),
320 .proc_handler
= proc_dointvec
,
323 .procname
= "sched_time_avg",
324 .data
= &sysctl_sched_time_avg
,
325 .maxlen
= sizeof(unsigned int),
327 .proc_handler
= proc_dointvec
,
330 .procname
= "timer_migration",
331 .data
= &sysctl_timer_migration
,
332 .maxlen
= sizeof(unsigned int),
334 .proc_handler
= proc_dointvec_minmax
,
340 .procname
= "sched_rt_period_us",
341 .data
= &sysctl_sched_rt_period
,
342 .maxlen
= sizeof(unsigned int),
344 .proc_handler
= sched_rt_handler
,
347 .procname
= "sched_rt_runtime_us",
348 .data
= &sysctl_sched_rt_runtime
,
349 .maxlen
= sizeof(int),
351 .proc_handler
= sched_rt_handler
,
354 .procname
= "sched_compat_yield",
355 .data
= &sysctl_sched_compat_yield
,
356 .maxlen
= sizeof(unsigned int),
358 .proc_handler
= proc_dointvec
,
360 #ifdef CONFIG_PROVE_LOCKING
362 .procname
= "prove_locking",
363 .data
= &prove_locking
,
364 .maxlen
= sizeof(int),
366 .proc_handler
= proc_dointvec
,
369 #ifdef CONFIG_LOCK_STAT
371 .procname
= "lock_stat",
373 .maxlen
= sizeof(int),
375 .proc_handler
= proc_dointvec
,
380 .data
= &panic_timeout
,
381 .maxlen
= sizeof(int),
383 .proc_handler
= proc_dointvec
,
386 .procname
= "core_uses_pid",
387 .data
= &core_uses_pid
,
388 .maxlen
= sizeof(int),
390 .proc_handler
= proc_dointvec
,
393 .procname
= "core_pattern",
394 .data
= core_pattern
,
395 .maxlen
= CORENAME_MAX_SIZE
,
397 .proc_handler
= proc_dostring
,
400 .procname
= "core_pipe_limit",
401 .data
= &core_pipe_limit
,
402 .maxlen
= sizeof(unsigned int),
404 .proc_handler
= proc_dointvec
,
406 #ifdef CONFIG_PROC_SYSCTL
408 .procname
= "tainted",
409 .maxlen
= sizeof(long),
411 .proc_handler
= proc_taint
,
414 #ifdef CONFIG_LATENCYTOP
416 .procname
= "latencytop",
417 .data
= &latencytop_enabled
,
418 .maxlen
= sizeof(int),
420 .proc_handler
= proc_dointvec
,
423 #ifdef CONFIG_BLK_DEV_INITRD
425 .procname
= "real-root-dev",
426 .data
= &real_root_dev
,
427 .maxlen
= sizeof(int),
429 .proc_handler
= proc_dointvec
,
433 .procname
= "print-fatal-signals",
434 .data
= &print_fatal_signals
,
435 .maxlen
= sizeof(int),
437 .proc_handler
= proc_dointvec
,
441 .procname
= "reboot-cmd",
442 .data
= reboot_command
,
445 .proc_handler
= proc_dostring
,
448 .procname
= "stop-a",
449 .data
= &stop_a_enabled
,
450 .maxlen
= sizeof (int),
452 .proc_handler
= proc_dointvec
,
455 .procname
= "scons-poweroff",
456 .data
= &scons_pwroff
,
457 .maxlen
= sizeof (int),
459 .proc_handler
= proc_dointvec
,
462 #ifdef CONFIG_SPARC64
464 .procname
= "tsb-ratio",
465 .data
= &sysctl_tsb_ratio
,
466 .maxlen
= sizeof (int),
468 .proc_handler
= proc_dointvec
,
473 .procname
= "soft-power",
474 .data
= &pwrsw_enabled
,
475 .maxlen
= sizeof (int),
477 .proc_handler
= proc_dointvec
,
480 .procname
= "unaligned-trap",
481 .data
= &unaligned_enabled
,
482 .maxlen
= sizeof (int),
484 .proc_handler
= proc_dointvec
,
488 .procname
= "ctrl-alt-del",
490 .maxlen
= sizeof(int),
492 .proc_handler
= proc_dointvec
,
494 #ifdef CONFIG_FUNCTION_TRACER
496 .procname
= "ftrace_enabled",
497 .data
= &ftrace_enabled
,
498 .maxlen
= sizeof(int),
500 .proc_handler
= ftrace_enable_sysctl
,
503 #ifdef CONFIG_STACK_TRACER
505 .procname
= "stack_tracer_enabled",
506 .data
= &stack_tracer_enabled
,
507 .maxlen
= sizeof(int),
509 .proc_handler
= stack_trace_sysctl
,
512 #ifdef CONFIG_TRACING
514 .procname
= "ftrace_dump_on_oops",
515 .data
= &ftrace_dump_on_oops
,
516 .maxlen
= sizeof(int),
518 .proc_handler
= proc_dointvec
,
521 #ifdef CONFIG_MODULES
523 .procname
= "modprobe",
524 .data
= &modprobe_path
,
525 .maxlen
= KMOD_PATH_LEN
,
527 .proc_handler
= proc_dostring
,
530 .procname
= "modules_disabled",
531 .data
= &modules_disabled
,
532 .maxlen
= sizeof(int),
534 /* only handle a transition from default "0" to "1" */
535 .proc_handler
= proc_dointvec_minmax
,
540 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
542 .procname
= "hotplug",
543 .data
= &uevent_helper
,
544 .maxlen
= UEVENT_HELPER_PATH_LEN
,
546 .proc_handler
= proc_dostring
,
549 #ifdef CONFIG_CHR_DEV_SG
551 .procname
= "sg-big-buff",
552 .data
= &sg_big_buff
,
553 .maxlen
= sizeof (int),
555 .proc_handler
= proc_dointvec
,
558 #ifdef CONFIG_BSD_PROCESS_ACCT
562 .maxlen
= 3*sizeof(int),
564 .proc_handler
= proc_dointvec
,
567 #ifdef CONFIG_MAGIC_SYSRQ
570 .data
= &__sysrq_enabled
,
571 .maxlen
= sizeof (int),
573 .proc_handler
= proc_dointvec
,
576 #ifdef CONFIG_PROC_SYSCTL
578 .procname
= "cad_pid",
580 .maxlen
= sizeof (int),
582 .proc_handler
= proc_do_cad_pid
,
586 .procname
= "threads-max",
587 .data
= &max_threads
,
588 .maxlen
= sizeof(int),
590 .proc_handler
= proc_dointvec
,
593 .procname
= "random",
595 .child
= random_table
,
598 .procname
= "overflowuid",
599 .data
= &overflowuid
,
600 .maxlen
= sizeof(int),
602 .proc_handler
= proc_dointvec_minmax
,
603 .extra1
= &minolduid
,
604 .extra2
= &maxolduid
,
607 .procname
= "overflowgid",
608 .data
= &overflowgid
,
609 .maxlen
= sizeof(int),
611 .proc_handler
= proc_dointvec_minmax
,
612 .extra1
= &minolduid
,
613 .extra2
= &maxolduid
,
616 #ifdef CONFIG_MATHEMU
618 .procname
= "ieee_emulation_warnings",
619 .data
= &sysctl_ieee_emulation_warnings
,
620 .maxlen
= sizeof(int),
622 .proc_handler
= proc_dointvec
,
626 .procname
= "userprocess_debug",
627 .data
= &sysctl_userprocess_debug
,
628 .maxlen
= sizeof(int),
630 .proc_handler
= proc_dointvec
,
634 .procname
= "pid_max",
636 .maxlen
= sizeof (int),
638 .proc_handler
= proc_dointvec_minmax
,
639 .extra1
= &pid_max_min
,
640 .extra2
= &pid_max_max
,
643 .procname
= "panic_on_oops",
644 .data
= &panic_on_oops
,
645 .maxlen
= sizeof(int),
647 .proc_handler
= proc_dointvec
,
649 #if defined CONFIG_PRINTK
651 .procname
= "printk",
652 .data
= &console_loglevel
,
653 .maxlen
= 4*sizeof(int),
655 .proc_handler
= proc_dointvec
,
658 .procname
= "printk_ratelimit",
659 .data
= &printk_ratelimit_state
.interval
,
660 .maxlen
= sizeof(int),
662 .proc_handler
= proc_dointvec_jiffies
,
665 .procname
= "printk_ratelimit_burst",
666 .data
= &printk_ratelimit_state
.burst
,
667 .maxlen
= sizeof(int),
669 .proc_handler
= proc_dointvec
,
672 .procname
= "printk_delay",
673 .data
= &printk_delay_msec
,
674 .maxlen
= sizeof(int),
676 .proc_handler
= proc_dointvec_minmax
,
678 .extra2
= &ten_thousand
,
682 .procname
= "ngroups_max",
683 .data
= &ngroups_max
,
684 .maxlen
= sizeof (int),
686 .proc_handler
= proc_dointvec
,
688 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
690 .procname
= "unknown_nmi_panic",
691 .data
= &unknown_nmi_panic
,
692 .maxlen
= sizeof (int),
694 .proc_handler
= proc_dointvec
,
697 .procname
= "nmi_watchdog",
698 .data
= &nmi_watchdog_enabled
,
699 .maxlen
= sizeof (int),
701 .proc_handler
= proc_nmi_enabled
,
704 #if defined(CONFIG_X86)
706 .procname
= "panic_on_unrecovered_nmi",
707 .data
= &panic_on_unrecovered_nmi
,
708 .maxlen
= sizeof(int),
710 .proc_handler
= proc_dointvec
,
713 .procname
= "panic_on_io_nmi",
714 .data
= &panic_on_io_nmi
,
715 .maxlen
= sizeof(int),
717 .proc_handler
= proc_dointvec
,
720 .procname
= "bootloader_type",
721 .data
= &bootloader_type
,
722 .maxlen
= sizeof (int),
724 .proc_handler
= proc_dointvec
,
727 .procname
= "bootloader_version",
728 .data
= &bootloader_version
,
729 .maxlen
= sizeof (int),
731 .proc_handler
= proc_dointvec
,
734 .procname
= "kstack_depth_to_print",
735 .data
= &kstack_depth_to_print
,
736 .maxlen
= sizeof(int),
738 .proc_handler
= proc_dointvec
,
741 .procname
= "io_delay_type",
742 .data
= &io_delay_type
,
743 .maxlen
= sizeof(int),
745 .proc_handler
= proc_dointvec
,
748 #if defined(CONFIG_MMU)
750 .procname
= "randomize_va_space",
751 .data
= &randomize_va_space
,
752 .maxlen
= sizeof(int),
754 .proc_handler
= proc_dointvec
,
757 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
759 .procname
= "spin_retry",
761 .maxlen
= sizeof (int),
763 .proc_handler
= proc_dointvec
,
766 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
768 .procname
= "acpi_video_flags",
769 .data
= &acpi_realmode_flags
,
770 .maxlen
= sizeof (unsigned long),
772 .proc_handler
= proc_doulongvec_minmax
,
777 .procname
= "ignore-unaligned-usertrap",
778 .data
= &no_unaligned_warning
,
779 .maxlen
= sizeof (int),
781 .proc_handler
= proc_dointvec
,
784 .procname
= "unaligned-dump-stack",
785 .data
= &unaligned_dump_stack
,
786 .maxlen
= sizeof (int),
788 .proc_handler
= proc_dointvec
,
791 #ifdef CONFIG_DETECT_SOFTLOCKUP
793 .procname
= "softlockup_panic",
794 .data
= &softlockup_panic
,
795 .maxlen
= sizeof(int),
797 .proc_handler
= proc_dointvec_minmax
,
802 .procname
= "softlockup_thresh",
803 .data
= &softlockup_thresh
,
804 .maxlen
= sizeof(int),
806 .proc_handler
= proc_dosoftlockup_thresh
,
811 #ifdef CONFIG_DETECT_HUNG_TASK
813 .procname
= "hung_task_panic",
814 .data
= &sysctl_hung_task_panic
,
815 .maxlen
= sizeof(int),
817 .proc_handler
= proc_dointvec_minmax
,
822 .procname
= "hung_task_check_count",
823 .data
= &sysctl_hung_task_check_count
,
824 .maxlen
= sizeof(unsigned long),
826 .proc_handler
= proc_doulongvec_minmax
,
829 .procname
= "hung_task_timeout_secs",
830 .data
= &sysctl_hung_task_timeout_secs
,
831 .maxlen
= sizeof(unsigned long),
833 .proc_handler
= proc_dohung_task_timeout_secs
,
836 .procname
= "hung_task_warnings",
837 .data
= &sysctl_hung_task_warnings
,
838 .maxlen
= sizeof(unsigned long),
840 .proc_handler
= proc_doulongvec_minmax
,
845 .procname
= "compat-log",
847 .maxlen
= sizeof (int),
849 .proc_handler
= proc_dointvec
,
852 #ifdef CONFIG_RT_MUTEXES
854 .procname
= "max_lock_depth",
855 .data
= &max_lock_depth
,
856 .maxlen
= sizeof(int),
858 .proc_handler
= proc_dointvec
,
862 .procname
= "poweroff_cmd",
863 .data
= &poweroff_cmd
,
864 .maxlen
= POWEROFF_CMD_PATH_LEN
,
866 .proc_handler
= proc_dostring
,
872 .child
= key_sysctls
,
875 #ifdef CONFIG_RCU_TORTURE_TEST
877 .procname
= "rcutorture_runnable",
878 .data
= &rcutorture_runnable
,
879 .maxlen
= sizeof(int),
881 .proc_handler
= proc_dointvec
,
884 #ifdef CONFIG_SLOW_WORK
886 .procname
= "slow-work",
888 .child
= slow_work_sysctls
,
891 #ifdef CONFIG_PERF_EVENTS
893 .procname
= "perf_event_paranoid",
894 .data
= &sysctl_perf_event_paranoid
,
895 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
897 .proc_handler
= proc_dointvec
,
900 .procname
= "perf_event_mlock_kb",
901 .data
= &sysctl_perf_event_mlock
,
902 .maxlen
= sizeof(sysctl_perf_event_mlock
),
904 .proc_handler
= proc_dointvec
,
907 .procname
= "perf_event_max_sample_rate",
908 .data
= &sysctl_perf_event_sample_rate
,
909 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
911 .proc_handler
= proc_dointvec
,
914 #ifdef CONFIG_KMEMCHECK
916 .procname
= "kmemcheck",
917 .data
= &kmemcheck_enabled
,
918 .maxlen
= sizeof(int),
920 .proc_handler
= proc_dointvec
,
925 .procname
= "blk_iopoll",
926 .data
= &blk_iopoll_enabled
,
927 .maxlen
= sizeof(int),
929 .proc_handler
= proc_dointvec
,
933 * NOTE: do not add new entries to this table unless you have read
934 * Documentation/sysctl/ctl_unnumbered.txt
939 static struct ctl_table vm_table
[] = {
941 .procname
= "overcommit_memory",
942 .data
= &sysctl_overcommit_memory
,
943 .maxlen
= sizeof(sysctl_overcommit_memory
),
945 .proc_handler
= proc_dointvec
,
948 .procname
= "panic_on_oom",
949 .data
= &sysctl_panic_on_oom
,
950 .maxlen
= sizeof(sysctl_panic_on_oom
),
952 .proc_handler
= proc_dointvec
,
955 .procname
= "oom_kill_allocating_task",
956 .data
= &sysctl_oom_kill_allocating_task
,
957 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
959 .proc_handler
= proc_dointvec
,
962 .procname
= "oom_dump_tasks",
963 .data
= &sysctl_oom_dump_tasks
,
964 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
966 .proc_handler
= proc_dointvec
,
969 .procname
= "overcommit_ratio",
970 .data
= &sysctl_overcommit_ratio
,
971 .maxlen
= sizeof(sysctl_overcommit_ratio
),
973 .proc_handler
= proc_dointvec
,
976 .procname
= "page-cluster",
977 .data
= &page_cluster
,
978 .maxlen
= sizeof(int),
980 .proc_handler
= proc_dointvec
,
983 .procname
= "dirty_background_ratio",
984 .data
= &dirty_background_ratio
,
985 .maxlen
= sizeof(dirty_background_ratio
),
987 .proc_handler
= dirty_background_ratio_handler
,
989 .extra2
= &one_hundred
,
992 .procname
= "dirty_background_bytes",
993 .data
= &dirty_background_bytes
,
994 .maxlen
= sizeof(dirty_background_bytes
),
996 .proc_handler
= dirty_background_bytes_handler
,
1000 .procname
= "dirty_ratio",
1001 .data
= &vm_dirty_ratio
,
1002 .maxlen
= sizeof(vm_dirty_ratio
),
1004 .proc_handler
= dirty_ratio_handler
,
1006 .extra2
= &one_hundred
,
1009 .procname
= "dirty_bytes",
1010 .data
= &vm_dirty_bytes
,
1011 .maxlen
= sizeof(vm_dirty_bytes
),
1013 .proc_handler
= dirty_bytes_handler
,
1014 .extra1
= &dirty_bytes_min
,
1017 .procname
= "dirty_writeback_centisecs",
1018 .data
= &dirty_writeback_interval
,
1019 .maxlen
= sizeof(dirty_writeback_interval
),
1021 .proc_handler
= dirty_writeback_centisecs_handler
,
1024 .procname
= "dirty_expire_centisecs",
1025 .data
= &dirty_expire_interval
,
1026 .maxlen
= sizeof(dirty_expire_interval
),
1028 .proc_handler
= proc_dointvec
,
1031 .procname
= "nr_pdflush_threads",
1032 .data
= &nr_pdflush_threads
,
1033 .maxlen
= sizeof nr_pdflush_threads
,
1034 .mode
= 0444 /* read-only*/,
1035 .proc_handler
= proc_dointvec
,
1038 .procname
= "swappiness",
1039 .data
= &vm_swappiness
,
1040 .maxlen
= sizeof(vm_swappiness
),
1042 .proc_handler
= proc_dointvec_minmax
,
1044 .extra2
= &one_hundred
,
1046 #ifdef CONFIG_HUGETLB_PAGE
1048 .procname
= "nr_hugepages",
1050 .maxlen
= sizeof(unsigned long),
1052 .proc_handler
= hugetlb_sysctl_handler
,
1053 .extra1
= (void *)&hugetlb_zero
,
1054 .extra2
= (void *)&hugetlb_infinity
,
1058 .procname
= "nr_hugepages_mempolicy",
1060 .maxlen
= sizeof(unsigned long),
1062 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1063 .extra1
= (void *)&hugetlb_zero
,
1064 .extra2
= (void *)&hugetlb_infinity
,
1068 .procname
= "hugetlb_shm_group",
1069 .data
= &sysctl_hugetlb_shm_group
,
1070 .maxlen
= sizeof(gid_t
),
1072 .proc_handler
= proc_dointvec
,
1075 .procname
= "hugepages_treat_as_movable",
1076 .data
= &hugepages_treat_as_movable
,
1077 .maxlen
= sizeof(int),
1079 .proc_handler
= hugetlb_treat_movable_handler
,
1082 .procname
= "nr_overcommit_hugepages",
1084 .maxlen
= sizeof(unsigned long),
1086 .proc_handler
= hugetlb_overcommit_handler
,
1087 .extra1
= (void *)&hugetlb_zero
,
1088 .extra2
= (void *)&hugetlb_infinity
,
1092 .procname
= "lowmem_reserve_ratio",
1093 .data
= &sysctl_lowmem_reserve_ratio
,
1094 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1096 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1099 .procname
= "drop_caches",
1100 .data
= &sysctl_drop_caches
,
1101 .maxlen
= sizeof(int),
1103 .proc_handler
= drop_caches_sysctl_handler
,
1106 .procname
= "min_free_kbytes",
1107 .data
= &min_free_kbytes
,
1108 .maxlen
= sizeof(min_free_kbytes
),
1110 .proc_handler
= min_free_kbytes_sysctl_handler
,
1114 .procname
= "percpu_pagelist_fraction",
1115 .data
= &percpu_pagelist_fraction
,
1116 .maxlen
= sizeof(percpu_pagelist_fraction
),
1118 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1119 .extra1
= &min_percpu_pagelist_fract
,
1123 .procname
= "max_map_count",
1124 .data
= &sysctl_max_map_count
,
1125 .maxlen
= sizeof(sysctl_max_map_count
),
1127 .proc_handler
= proc_dointvec_minmax
,
1132 .procname
= "nr_trim_pages",
1133 .data
= &sysctl_nr_trim_pages
,
1134 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1136 .proc_handler
= proc_dointvec_minmax
,
1141 .procname
= "laptop_mode",
1142 .data
= &laptop_mode
,
1143 .maxlen
= sizeof(laptop_mode
),
1145 .proc_handler
= proc_dointvec_jiffies
,
1148 .procname
= "block_dump",
1149 .data
= &block_dump
,
1150 .maxlen
= sizeof(block_dump
),
1152 .proc_handler
= proc_dointvec
,
1156 .procname
= "vfs_cache_pressure",
1157 .data
= &sysctl_vfs_cache_pressure
,
1158 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1160 .proc_handler
= proc_dointvec
,
1163 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1165 .procname
= "legacy_va_layout",
1166 .data
= &sysctl_legacy_va_layout
,
1167 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1169 .proc_handler
= proc_dointvec
,
1175 .procname
= "zone_reclaim_mode",
1176 .data
= &zone_reclaim_mode
,
1177 .maxlen
= sizeof(zone_reclaim_mode
),
1179 .proc_handler
= proc_dointvec
,
1183 .procname
= "min_unmapped_ratio",
1184 .data
= &sysctl_min_unmapped_ratio
,
1185 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1187 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1189 .extra2
= &one_hundred
,
1192 .procname
= "min_slab_ratio",
1193 .data
= &sysctl_min_slab_ratio
,
1194 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1196 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1198 .extra2
= &one_hundred
,
1203 .procname
= "stat_interval",
1204 .data
= &sysctl_stat_interval
,
1205 .maxlen
= sizeof(sysctl_stat_interval
),
1207 .proc_handler
= proc_dointvec_jiffies
,
1212 .procname
= "mmap_min_addr",
1213 .data
= &dac_mmap_min_addr
,
1214 .maxlen
= sizeof(unsigned long),
1216 .proc_handler
= mmap_min_addr_handler
,
1221 .procname
= "numa_zonelist_order",
1222 .data
= &numa_zonelist_order
,
1223 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1225 .proc_handler
= numa_zonelist_order_handler
,
1228 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1229 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1231 .procname
= "vdso_enabled",
1232 .data
= &vdso_enabled
,
1233 .maxlen
= sizeof(vdso_enabled
),
1235 .proc_handler
= proc_dointvec
,
1239 #ifdef CONFIG_HIGHMEM
1241 .procname
= "highmem_is_dirtyable",
1242 .data
= &vm_highmem_is_dirtyable
,
1243 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1245 .proc_handler
= proc_dointvec_minmax
,
1251 .procname
= "scan_unevictable_pages",
1252 .data
= &scan_unevictable_pages
,
1253 .maxlen
= sizeof(scan_unevictable_pages
),
1255 .proc_handler
= scan_unevictable_handler
,
1257 #ifdef CONFIG_MEMORY_FAILURE
1259 .procname
= "memory_failure_early_kill",
1260 .data
= &sysctl_memory_failure_early_kill
,
1261 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1263 .proc_handler
= proc_dointvec_minmax
,
1268 .procname
= "memory_failure_recovery",
1269 .data
= &sysctl_memory_failure_recovery
,
1270 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1272 .proc_handler
= proc_dointvec_minmax
,
1279 * NOTE: do not add new entries to this table unless you have read
1280 * Documentation/sysctl/ctl_unnumbered.txt
1285 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1286 static struct ctl_table binfmt_misc_table
[] = {
1291 static struct ctl_table fs_table
[] = {
1293 .procname
= "inode-nr",
1294 .data
= &inodes_stat
,
1295 .maxlen
= 2*sizeof(int),
1297 .proc_handler
= proc_dointvec
,
1300 .procname
= "inode-state",
1301 .data
= &inodes_stat
,
1302 .maxlen
= 7*sizeof(int),
1304 .proc_handler
= proc_dointvec
,
1307 .procname
= "file-nr",
1308 .data
= &files_stat
,
1309 .maxlen
= 3*sizeof(int),
1311 .proc_handler
= proc_nr_files
,
1314 .procname
= "file-max",
1315 .data
= &files_stat
.max_files
,
1316 .maxlen
= sizeof(int),
1318 .proc_handler
= proc_dointvec
,
1321 .procname
= "nr_open",
1322 .data
= &sysctl_nr_open
,
1323 .maxlen
= sizeof(int),
1325 .proc_handler
= proc_dointvec_minmax
,
1326 .extra1
= &sysctl_nr_open_min
,
1327 .extra2
= &sysctl_nr_open_max
,
1330 .procname
= "dentry-state",
1331 .data
= &dentry_stat
,
1332 .maxlen
= 6*sizeof(int),
1334 .proc_handler
= proc_dointvec
,
1337 .procname
= "overflowuid",
1338 .data
= &fs_overflowuid
,
1339 .maxlen
= sizeof(int),
1341 .proc_handler
= proc_dointvec_minmax
,
1342 .extra1
= &minolduid
,
1343 .extra2
= &maxolduid
,
1346 .procname
= "overflowgid",
1347 .data
= &fs_overflowgid
,
1348 .maxlen
= sizeof(int),
1350 .proc_handler
= proc_dointvec_minmax
,
1351 .extra1
= &minolduid
,
1352 .extra2
= &maxolduid
,
1354 #ifdef CONFIG_FILE_LOCKING
1356 .procname
= "leases-enable",
1357 .data
= &leases_enable
,
1358 .maxlen
= sizeof(int),
1360 .proc_handler
= proc_dointvec
,
1363 #ifdef CONFIG_DNOTIFY
1365 .procname
= "dir-notify-enable",
1366 .data
= &dir_notify_enable
,
1367 .maxlen
= sizeof(int),
1369 .proc_handler
= proc_dointvec
,
1373 #ifdef CONFIG_FILE_LOCKING
1375 .procname
= "lease-break-time",
1376 .data
= &lease_break_time
,
1377 .maxlen
= sizeof(int),
1379 .proc_handler
= proc_dointvec
,
1384 .procname
= "aio-nr",
1386 .maxlen
= sizeof(aio_nr
),
1388 .proc_handler
= proc_doulongvec_minmax
,
1391 .procname
= "aio-max-nr",
1392 .data
= &aio_max_nr
,
1393 .maxlen
= sizeof(aio_max_nr
),
1395 .proc_handler
= proc_doulongvec_minmax
,
1397 #endif /* CONFIG_AIO */
1398 #ifdef CONFIG_INOTIFY_USER
1400 .procname
= "inotify",
1402 .child
= inotify_table
,
1407 .procname
= "epoll",
1409 .child
= epoll_table
,
1414 .procname
= "suid_dumpable",
1415 .data
= &suid_dumpable
,
1416 .maxlen
= sizeof(int),
1418 .proc_handler
= proc_dointvec_minmax
,
1422 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1424 .procname
= "binfmt_misc",
1426 .child
= binfmt_misc_table
,
1430 * NOTE: do not add new entries to this table unless you have read
1431 * Documentation/sysctl/ctl_unnumbered.txt
1436 static struct ctl_table debug_table
[] = {
1437 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
1439 .procname
= "exception-trace",
1440 .data
= &show_unhandled_signals
,
1441 .maxlen
= sizeof(int),
1443 .proc_handler
= proc_dointvec
1446 #if defined(CONFIG_OPTPROBES)
1448 .procname
= "kprobes-optimization",
1449 .data
= &sysctl_kprobes_optimization
,
1450 .maxlen
= sizeof(int),
1452 .proc_handler
= proc_kprobes_optimization_handler
,
1460 static struct ctl_table dev_table
[] = {
1464 static DEFINE_SPINLOCK(sysctl_lock
);
1466 /* called under sysctl_lock */
1467 static int use_table(struct ctl_table_header
*p
)
1469 if (unlikely(p
->unregistering
))
1475 /* called under sysctl_lock */
1476 static void unuse_table(struct ctl_table_header
*p
)
1479 if (unlikely(p
->unregistering
))
1480 complete(p
->unregistering
);
1483 /* called under sysctl_lock, will reacquire if has to wait */
1484 static void start_unregistering(struct ctl_table_header
*p
)
1487 * if p->used is 0, nobody will ever touch that entry again;
1488 * we'll eliminate all paths to it before dropping sysctl_lock
1490 if (unlikely(p
->used
)) {
1491 struct completion wait
;
1492 init_completion(&wait
);
1493 p
->unregistering
= &wait
;
1494 spin_unlock(&sysctl_lock
);
1495 wait_for_completion(&wait
);
1496 spin_lock(&sysctl_lock
);
1498 /* anything non-NULL; we'll never dereference it */
1499 p
->unregistering
= ERR_PTR(-EINVAL
);
1502 * do not remove from the list until nobody holds it; walking the
1503 * list in do_sysctl() relies on that.
1505 list_del_init(&p
->ctl_entry
);
1508 void sysctl_head_get(struct ctl_table_header
*head
)
1510 spin_lock(&sysctl_lock
);
1512 spin_unlock(&sysctl_lock
);
1515 void sysctl_head_put(struct ctl_table_header
*head
)
1517 spin_lock(&sysctl_lock
);
1520 spin_unlock(&sysctl_lock
);
1523 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1527 spin_lock(&sysctl_lock
);
1528 if (!use_table(head
))
1529 head
= ERR_PTR(-ENOENT
);
1530 spin_unlock(&sysctl_lock
);
1534 void sysctl_head_finish(struct ctl_table_header
*head
)
1538 spin_lock(&sysctl_lock
);
1540 spin_unlock(&sysctl_lock
);
1543 static struct ctl_table_set
*
1544 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1546 struct ctl_table_set
*set
= &root
->default_set
;
1548 set
= root
->lookup(root
, namespaces
);
1552 static struct list_head
*
1553 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1555 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1559 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1560 struct ctl_table_header
*prev
)
1562 struct ctl_table_root
*root
;
1563 struct list_head
*header_list
;
1564 struct ctl_table_header
*head
;
1565 struct list_head
*tmp
;
1567 spin_lock(&sysctl_lock
);
1570 tmp
= &prev
->ctl_entry
;
1574 tmp
= &root_table_header
.ctl_entry
;
1576 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1578 if (!use_table(head
))
1580 spin_unlock(&sysctl_lock
);
1585 header_list
= lookup_header_list(root
, namespaces
);
1586 if (tmp
!= header_list
)
1590 root
= list_entry(root
->root_list
.next
,
1591 struct ctl_table_root
, root_list
);
1592 if (root
== &sysctl_table_root
)
1594 header_list
= lookup_header_list(root
, namespaces
);
1595 } while (list_empty(header_list
));
1596 tmp
= header_list
->next
;
1599 spin_unlock(&sysctl_lock
);
1603 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1605 return __sysctl_head_next(current
->nsproxy
, prev
);
1608 void register_sysctl_root(struct ctl_table_root
*root
)
1610 spin_lock(&sysctl_lock
);
1611 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1612 spin_unlock(&sysctl_lock
);
1616 * sysctl_perm does NOT grant the superuser all rights automatically, because
1617 * some sysctl variables are readonly even to root.
1620 static int test_perm(int mode
, int op
)
1622 if (!current_euid())
1624 else if (in_egroup_p(0))
1626 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1631 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1636 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1640 if (root
->permissions
)
1641 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1645 return test_perm(mode
, op
);
1648 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1650 for (; table
->procname
; table
++) {
1651 table
->parent
= parent
;
1653 sysctl_set_parent(table
, table
->child
);
1657 static __init
int sysctl_init(void)
1659 sysctl_set_parent(NULL
, root_table
);
1660 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1663 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1669 core_initcall(sysctl_init
);
1671 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1672 struct ctl_table
*table
)
1674 struct ctl_table
*p
;
1675 const char *s
= branch
->procname
;
1677 /* branch should have named subdirectory as its first element */
1678 if (!s
|| !branch
->child
)
1681 /* ... and nothing else */
1682 if (branch
[1].procname
)
1685 /* table should contain subdirectory with the same name */
1686 for (p
= table
; p
->procname
; p
++) {
1689 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1695 /* see if attaching q to p would be an improvement */
1696 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1698 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1699 struct ctl_table
*next
;
1701 int not_in_parent
= !p
->attached_by
;
1703 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1704 if (by
== q
->attached_by
)
1706 if (to
== p
->attached_by
)
1712 if (is_better
&& not_in_parent
) {
1713 q
->attached_by
= by
;
1714 q
->attached_to
= to
;
1720 * __register_sysctl_paths - register a sysctl hierarchy
1721 * @root: List of sysctl headers to register on
1722 * @namespaces: Data to compute which lists of sysctl entries are visible
1723 * @path: The path to the directory the sysctl table is in.
1724 * @table: the top-level table structure
1726 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1727 * array. A completely 0 filled entry terminates the table.
1729 * The members of the &struct ctl_table structure are used as follows:
1731 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1732 * enter a sysctl file
1734 * data - a pointer to data for use by proc_handler
1736 * maxlen - the maximum size in bytes of the data
1738 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1740 * child - a pointer to the child sysctl table if this entry is a directory, or
1743 * proc_handler - the text handler routine (described below)
1745 * de - for internal use by the sysctl routines
1747 * extra1, extra2 - extra pointers usable by the proc handler routines
1749 * Leaf nodes in the sysctl tree will be represented by a single file
1750 * under /proc; non-leaf nodes will be represented by directories.
1752 * sysctl(2) can automatically manage read and write requests through
1753 * the sysctl table. The data and maxlen fields of the ctl_table
1754 * struct enable minimal validation of the values being written to be
1755 * performed, and the mode field allows minimal authentication.
1757 * There must be a proc_handler routine for any terminal nodes
1758 * mirrored under /proc/sys (non-terminals are handled by a built-in
1759 * directory handler). Several default handlers are available to
1760 * cover common cases -
1762 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1763 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1764 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1766 * It is the handler's job to read the input buffer from user memory
1767 * and process it. The handler should return 0 on success.
1769 * This routine returns %NULL on a failure to register, and a pointer
1770 * to the table header on success.
1772 struct ctl_table_header
*__register_sysctl_paths(
1773 struct ctl_table_root
*root
,
1774 struct nsproxy
*namespaces
,
1775 const struct ctl_path
*path
, struct ctl_table
*table
)
1777 struct ctl_table_header
*header
;
1778 struct ctl_table
*new, **prevp
;
1779 unsigned int n
, npath
;
1780 struct ctl_table_set
*set
;
1782 /* Count the path components */
1783 for (npath
= 0; path
[npath
].procname
; ++npath
)
1787 * For each path component, allocate a 2-element ctl_table array.
1788 * The first array element will be filled with the sysctl entry
1789 * for this, the second will be the sentinel (procname == 0).
1791 * We allocate everything in one go so that we don't have to
1792 * worry about freeing additional memory in unregister_sysctl_table.
1794 header
= kzalloc(sizeof(struct ctl_table_header
) +
1795 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1799 new = (struct ctl_table
*) (header
+ 1);
1801 /* Now connect the dots */
1802 prevp
= &header
->ctl_table
;
1803 for (n
= 0; n
< npath
; ++n
, ++path
) {
1804 /* Copy the procname */
1805 new->procname
= path
->procname
;
1809 prevp
= &new->child
;
1814 header
->ctl_table_arg
= table
;
1816 INIT_LIST_HEAD(&header
->ctl_entry
);
1818 header
->unregistering
= NULL
;
1819 header
->root
= root
;
1820 sysctl_set_parent(NULL
, header
->ctl_table
);
1822 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1823 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1828 spin_lock(&sysctl_lock
);
1829 header
->set
= lookup_header_set(root
, namespaces
);
1830 header
->attached_by
= header
->ctl_table
;
1831 header
->attached_to
= root_table
;
1832 header
->parent
= &root_table_header
;
1833 for (set
= header
->set
; set
; set
= set
->parent
) {
1834 struct ctl_table_header
*p
;
1835 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1836 if (p
->unregistering
)
1838 try_attach(p
, header
);
1841 header
->parent
->count
++;
1842 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1843 spin_unlock(&sysctl_lock
);
1849 * register_sysctl_table_path - register a sysctl table hierarchy
1850 * @path: The path to the directory the sysctl table is in.
1851 * @table: the top-level table structure
1853 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1854 * array. A completely 0 filled entry terminates the table.
1856 * See __register_sysctl_paths for more details.
1858 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1859 struct ctl_table
*table
)
1861 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1866 * register_sysctl_table - register a sysctl table hierarchy
1867 * @table: the top-level table structure
1869 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1870 * array. A completely 0 filled entry terminates the table.
1872 * See register_sysctl_paths for more details.
1874 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1876 static const struct ctl_path null_path
[] = { {} };
1878 return register_sysctl_paths(null_path
, table
);
1882 * unregister_sysctl_table - unregister a sysctl table hierarchy
1883 * @header: the header returned from register_sysctl_table
1885 * Unregisters the sysctl table and all children. proc entries may not
1886 * actually be removed until they are no longer used by anyone.
1888 void unregister_sysctl_table(struct ctl_table_header
* header
)
1895 spin_lock(&sysctl_lock
);
1896 start_unregistering(header
);
1897 if (!--header
->parent
->count
) {
1899 kfree(header
->parent
);
1901 if (!--header
->count
)
1903 spin_unlock(&sysctl_lock
);
1906 int sysctl_is_seen(struct ctl_table_header
*p
)
1908 struct ctl_table_set
*set
= p
->set
;
1910 spin_lock(&sysctl_lock
);
1911 if (p
->unregistering
)
1913 else if (!set
->is_seen
)
1916 res
= set
->is_seen(set
);
1917 spin_unlock(&sysctl_lock
);
1921 void setup_sysctl_set(struct ctl_table_set
*p
,
1922 struct ctl_table_set
*parent
,
1923 int (*is_seen
)(struct ctl_table_set
*))
1925 INIT_LIST_HEAD(&p
->list
);
1926 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1927 p
->is_seen
= is_seen
;
1930 #else /* !CONFIG_SYSCTL */
1931 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1936 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1937 struct ctl_table
*table
)
1942 void unregister_sysctl_table(struct ctl_table_header
* table
)
1946 void setup_sysctl_set(struct ctl_table_set
*p
,
1947 struct ctl_table_set
*parent
,
1948 int (*is_seen
)(struct ctl_table_set
*))
1952 void sysctl_head_put(struct ctl_table_header
*head
)
1956 #endif /* CONFIG_SYSCTL */
1962 #ifdef CONFIG_PROC_SYSCTL
1964 static int _proc_do_string(void* data
, int maxlen
, int write
,
1965 void __user
*buffer
,
1966 size_t *lenp
, loff_t
*ppos
)
1972 if (!data
|| !maxlen
|| !*lenp
) {
1980 while (len
< *lenp
) {
1981 if (get_user(c
, p
++))
1983 if (c
== 0 || c
== '\n')
1989 if(copy_from_user(data
, buffer
, len
))
1991 ((char *) data
)[len
] = 0;
2009 if(copy_to_user(buffer
, data
, len
))
2012 if(put_user('\n', ((char __user
*) buffer
) + len
))
2023 * proc_dostring - read a string sysctl
2024 * @table: the sysctl table
2025 * @write: %TRUE if this is a write to the sysctl file
2026 * @buffer: the user buffer
2027 * @lenp: the size of the user buffer
2028 * @ppos: file position
2030 * Reads/writes a string from/to the user buffer. If the kernel
2031 * buffer provided is not large enough to hold the string, the
2032 * string is truncated. The copied string is %NULL-terminated.
2033 * If the string is being read by the user process, it is copied
2034 * and a newline '\n' is added. It is truncated if the buffer is
2037 * Returns 0 on success.
2039 int proc_dostring(struct ctl_table
*table
, int write
,
2040 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2042 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2043 buffer
, lenp
, ppos
);
2047 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2049 int write
, void *data
)
2052 *valp
= *negp
? -*lvalp
: *lvalp
;
2057 *lvalp
= (unsigned long)-val
;
2060 *lvalp
= (unsigned long)val
;
2066 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2067 int write
, void __user
*buffer
,
2068 size_t *lenp
, loff_t
*ppos
,
2069 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2070 int write
, void *data
),
2073 #define TMPBUFLEN 21
2074 int *i
, vleft
, first
= 1, neg
;
2078 char buf
[TMPBUFLEN
], *p
;
2079 char __user
*s
= buffer
;
2081 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2082 (*ppos
&& !write
)) {
2087 i
= (int *) tbl_data
;
2088 vleft
= table
->maxlen
/ sizeof(*i
);
2092 conv
= do_proc_dointvec_conv
;
2094 for (; left
&& vleft
--; i
++, first
=0) {
2109 if (len
> sizeof(buf
) - 1)
2110 len
= sizeof(buf
) - 1;
2111 if (copy_from_user(buf
, s
, len
))
2115 if (*p
== '-' && left
> 1) {
2119 if (*p
< '0' || *p
> '9')
2122 lval
= simple_strtoul(p
, &p
, 0);
2125 if ((len
< left
) && *p
&& !isspace(*p
))
2130 if (conv(&neg
, &lval
, i
, 1, data
))
2137 if (conv(&neg
, &lval
, i
, 0, data
))
2140 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2144 if(copy_to_user(s
, buf
, len
))
2151 if (!write
&& !first
&& left
) {
2152 if(put_user('\n', s
))
2159 if (get_user(c
, s
++))
2174 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2175 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2176 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2177 int write
, void *data
),
2180 return __do_proc_dointvec(table
->data
, table
, write
,
2181 buffer
, lenp
, ppos
, conv
, data
);
2185 * proc_dointvec - read a vector of integers
2186 * @table: the sysctl table
2187 * @write: %TRUE if this is a write to the sysctl file
2188 * @buffer: the user buffer
2189 * @lenp: the size of the user buffer
2190 * @ppos: file position
2192 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2193 * values from/to the user buffer, treated as an ASCII string.
2195 * Returns 0 on success.
2197 int proc_dointvec(struct ctl_table
*table
, int write
,
2198 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2200 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2205 * Taint values can only be increased
2206 * This means we can safely use a temporary.
2208 static int proc_taint(struct ctl_table
*table
, int write
,
2209 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2212 unsigned long tmptaint
= get_taint();
2215 if (write
&& !capable(CAP_SYS_ADMIN
))
2220 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2226 * Poor man's atomic or. Not worth adding a primitive
2227 * to everyone's atomic.h for this
2230 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2231 if ((tmptaint
>> i
) & 1)
2239 struct do_proc_dointvec_minmax_conv_param
{
2244 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2246 int write
, void *data
)
2248 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2250 int val
= *negp
? -*lvalp
: *lvalp
;
2251 if ((param
->min
&& *param
->min
> val
) ||
2252 (param
->max
&& *param
->max
< val
))
2259 *lvalp
= (unsigned long)-val
;
2262 *lvalp
= (unsigned long)val
;
2269 * proc_dointvec_minmax - read a vector of integers with min/max values
2270 * @table: the sysctl table
2271 * @write: %TRUE if this is a write to the sysctl file
2272 * @buffer: the user buffer
2273 * @lenp: the size of the user buffer
2274 * @ppos: file position
2276 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2277 * values from/to the user buffer, treated as an ASCII string.
2279 * This routine will ensure the values are within the range specified by
2280 * table->extra1 (min) and table->extra2 (max).
2282 * Returns 0 on success.
2284 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2285 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2287 struct do_proc_dointvec_minmax_conv_param param
= {
2288 .min
= (int *) table
->extra1
,
2289 .max
= (int *) table
->extra2
,
2291 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2292 do_proc_dointvec_minmax_conv
, ¶m
);
2295 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2296 void __user
*buffer
,
2297 size_t *lenp
, loff_t
*ppos
,
2298 unsigned long convmul
,
2299 unsigned long convdiv
)
2301 #define TMPBUFLEN 21
2302 unsigned long *i
, *min
, *max
, val
;
2303 int vleft
, first
=1, neg
;
2305 char buf
[TMPBUFLEN
], *p
;
2306 char __user
*s
= buffer
;
2308 if (!data
|| !table
->maxlen
|| !*lenp
||
2309 (*ppos
&& !write
)) {
2314 i
= (unsigned long *) data
;
2315 min
= (unsigned long *) table
->extra1
;
2316 max
= (unsigned long *) table
->extra2
;
2317 vleft
= table
->maxlen
/ sizeof(unsigned long);
2320 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2335 if (len
> TMPBUFLEN
-1)
2337 if (copy_from_user(buf
, s
, len
))
2341 if (*p
== '-' && left
> 1) {
2345 if (*p
< '0' || *p
> '9')
2347 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2349 if ((len
< left
) && *p
&& !isspace(*p
))
2358 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2365 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2369 if(copy_to_user(s
, buf
, len
))
2376 if (!write
&& !first
&& left
) {
2377 if(put_user('\n', s
))
2384 if (get_user(c
, s
++))
2399 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2400 void __user
*buffer
,
2401 size_t *lenp
, loff_t
*ppos
,
2402 unsigned long convmul
,
2403 unsigned long convdiv
)
2405 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2406 buffer
, lenp
, ppos
, convmul
, convdiv
);
2410 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2411 * @table: the sysctl table
2412 * @write: %TRUE if this is a write to the sysctl file
2413 * @buffer: the user buffer
2414 * @lenp: the size of the user buffer
2415 * @ppos: file position
2417 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2418 * values from/to the user buffer, treated as an ASCII string.
2420 * This routine will ensure the values are within the range specified by
2421 * table->extra1 (min) and table->extra2 (max).
2423 * Returns 0 on success.
2425 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2426 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2428 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2432 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2433 * @table: the sysctl table
2434 * @write: %TRUE if this is a write to the sysctl file
2435 * @buffer: the user buffer
2436 * @lenp: the size of the user buffer
2437 * @ppos: file position
2439 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2440 * values from/to the user buffer, treated as an ASCII string. The values
2441 * are treated as milliseconds, and converted to jiffies when they are stored.
2443 * This routine will ensure the values are within the range specified by
2444 * table->extra1 (min) and table->extra2 (max).
2446 * Returns 0 on success.
2448 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2449 void __user
*buffer
,
2450 size_t *lenp
, loff_t
*ppos
)
2452 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2453 lenp
, ppos
, HZ
, 1000l);
2457 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2459 int write
, void *data
)
2462 if (*lvalp
> LONG_MAX
/ HZ
)
2464 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2470 lval
= (unsigned long)-val
;
2473 lval
= (unsigned long)val
;
2480 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2482 int write
, void *data
)
2485 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2487 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2493 lval
= (unsigned long)-val
;
2496 lval
= (unsigned long)val
;
2498 *lvalp
= jiffies_to_clock_t(lval
);
2503 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2505 int write
, void *data
)
2508 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2514 lval
= (unsigned long)-val
;
2517 lval
= (unsigned long)val
;
2519 *lvalp
= jiffies_to_msecs(lval
);
2525 * proc_dointvec_jiffies - read a vector of integers as seconds
2526 * @table: the sysctl table
2527 * @write: %TRUE if this is a write to the sysctl file
2528 * @buffer: the user buffer
2529 * @lenp: the size of the user buffer
2530 * @ppos: file position
2532 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2533 * values from/to the user buffer, treated as an ASCII string.
2534 * The values read are assumed to be in seconds, and are converted into
2537 * Returns 0 on success.
2539 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2540 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2542 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2543 do_proc_dointvec_jiffies_conv
,NULL
);
2547 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2548 * @table: the sysctl table
2549 * @write: %TRUE if this is a write to the sysctl file
2550 * @buffer: the user buffer
2551 * @lenp: the size of the user buffer
2552 * @ppos: pointer to the file position
2554 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2555 * values from/to the user buffer, treated as an ASCII string.
2556 * The values read are assumed to be in 1/USER_HZ seconds, and
2557 * are converted into jiffies.
2559 * Returns 0 on success.
2561 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2562 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2564 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2565 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2569 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2570 * @table: the sysctl table
2571 * @write: %TRUE if this is a write to the sysctl file
2572 * @buffer: the user buffer
2573 * @lenp: the size of the user buffer
2574 * @ppos: file position
2575 * @ppos: the current position in the file
2577 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2578 * values from/to the user buffer, treated as an ASCII string.
2579 * The values read are assumed to be in 1/1000 seconds, and
2580 * are converted into jiffies.
2582 * Returns 0 on success.
2584 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2585 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2587 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2588 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2591 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2592 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2594 struct pid
*new_pid
;
2598 tmp
= pid_vnr(cad_pid
);
2600 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2601 lenp
, ppos
, NULL
, NULL
);
2605 new_pid
= find_get_pid(tmp
);
2609 put_pid(xchg(&cad_pid
, new_pid
));
2613 #else /* CONFIG_PROC_FS */
2615 int proc_dostring(struct ctl_table
*table
, int write
,
2616 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2621 int proc_dointvec(struct ctl_table
*table
, int write
,
2622 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2627 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2628 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2633 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2634 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2639 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2640 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2645 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2646 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2651 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2652 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2657 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2658 void __user
*buffer
,
2659 size_t *lenp
, loff_t
*ppos
)
2665 #endif /* CONFIG_PROC_FS */
2668 * No sense putting this after each symbol definition, twice,
2669 * exception granted :-)
2671 EXPORT_SYMBOL(proc_dointvec
);
2672 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2673 EXPORT_SYMBOL(proc_dointvec_minmax
);
2674 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2675 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2676 EXPORT_SYMBOL(proc_dostring
);
2677 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2678 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2679 EXPORT_SYMBOL(register_sysctl_table
);
2680 EXPORT_SYMBOL(register_sysctl_paths
);
2681 EXPORT_SYMBOL(unregister_sysctl_table
);