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>
64 #ifdef CONFIG_BSD_PROCESS_ACCT
65 #include <linux/acct.h>
67 #ifdef CONFIG_RT_MUTEXES
68 #include <linux/rtmutex.h>
70 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
71 #include <linux/lockdep.h>
73 #ifdef CONFIG_CHR_DEV_SG
78 #if defined(CONFIG_SYSCTL)
80 /* External variables not in a header file. */
81 extern int sysctl_overcommit_memory
;
82 extern int sysctl_overcommit_ratio
;
83 extern int sysctl_panic_on_oom
;
84 extern int sysctl_oom_kill_allocating_task
;
85 extern int sysctl_oom_dump_tasks
;
86 extern int max_threads
;
87 extern int core_uses_pid
;
88 extern int suid_dumpable
;
89 extern char core_pattern
[];
90 extern unsigned int core_pipe_limit
;
92 extern int min_free_kbytes
;
93 extern int pid_max_min
, pid_max_max
;
94 extern int sysctl_drop_caches
;
95 extern int percpu_pagelist_fraction
;
96 extern int compat_log
;
97 extern int latencytop_enabled
;
98 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
100 extern int sysctl_nr_trim_pages
;
103 extern int blk_iopoll_enabled
;
106 /* Constants used for minimum and maximum */
107 #ifdef CONFIG_DETECT_SOFTLOCKUP
108 static int sixty
= 60;
109 static int neg_one
= -1;
113 static int __maybe_unused one
= 1;
114 static int __maybe_unused two
= 2;
115 static unsigned long one_ul
= 1;
116 static int one_hundred
= 100;
118 static int ten_thousand
= 10000;
121 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
122 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
124 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
125 static int maxolduid
= 65535;
126 static int minolduid
;
127 static int min_percpu_pagelist_fract
= 8;
129 static int ngroups_max
= NGROUPS_MAX
;
132 #include <asm/system.h>
135 #ifdef CONFIG_SPARC64
136 extern int sysctl_tsb_ratio
;
140 extern int pwrsw_enabled
;
141 extern int unaligned_enabled
;
145 #ifdef CONFIG_MATHEMU
146 extern int sysctl_ieee_emulation_warnings
;
148 extern int sysctl_userprocess_debug
;
149 extern int spin_retry
;
153 extern int no_unaligned_warning
;
154 extern int unaligned_dump_stack
;
157 extern struct ratelimit_state printk_ratelimit_state
;
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 /* The default sysctl tables: */
199 static struct ctl_table root_table
[] = {
201 .procname
= "kernel",
218 .child
= debug_table
,
226 * NOTE: do not add new entries to this table unless you have read
227 * Documentation/sysctl/ctl_unnumbered.txt
232 #ifdef CONFIG_SCHED_DEBUG
233 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
234 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
235 static int min_wakeup_granularity_ns
; /* 0 usecs */
236 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
237 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
238 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
239 static int min_sched_shares_ratelimit
= 100000; /* 100 usec */
240 static int max_sched_shares_ratelimit
= NSEC_PER_SEC
; /* 1 second */
243 static struct ctl_table kern_table
[] = {
245 .procname
= "sched_child_runs_first",
246 .data
= &sysctl_sched_child_runs_first
,
247 .maxlen
= sizeof(unsigned int),
249 .proc_handler
= proc_dointvec
,
251 #ifdef CONFIG_SCHED_DEBUG
253 .procname
= "sched_min_granularity_ns",
254 .data
= &sysctl_sched_min_granularity
,
255 .maxlen
= sizeof(unsigned int),
257 .proc_handler
= sched_proc_update_handler
,
258 .extra1
= &min_sched_granularity_ns
,
259 .extra2
= &max_sched_granularity_ns
,
262 .procname
= "sched_latency_ns",
263 .data
= &sysctl_sched_latency
,
264 .maxlen
= sizeof(unsigned int),
266 .proc_handler
= sched_proc_update_handler
,
267 .extra1
= &min_sched_granularity_ns
,
268 .extra2
= &max_sched_granularity_ns
,
271 .procname
= "sched_wakeup_granularity_ns",
272 .data
= &sysctl_sched_wakeup_granularity
,
273 .maxlen
= sizeof(unsigned int),
275 .proc_handler
= sched_proc_update_handler
,
276 .extra1
= &min_wakeup_granularity_ns
,
277 .extra2
= &max_wakeup_granularity_ns
,
280 .procname
= "sched_shares_ratelimit",
281 .data
= &sysctl_sched_shares_ratelimit
,
282 .maxlen
= sizeof(unsigned int),
284 .proc_handler
= sched_proc_update_handler
,
285 .extra1
= &min_sched_shares_ratelimit
,
286 .extra2
= &max_sched_shares_ratelimit
,
289 .procname
= "sched_tunable_scaling",
290 .data
= &sysctl_sched_tunable_scaling
,
291 .maxlen
= sizeof(enum sched_tunable_scaling
),
293 .proc_handler
= sched_proc_update_handler
,
294 .extra1
= &min_sched_tunable_scaling
,
295 .extra2
= &max_sched_tunable_scaling
,
298 .procname
= "sched_shares_thresh",
299 .data
= &sysctl_sched_shares_thresh
,
300 .maxlen
= sizeof(unsigned int),
302 .proc_handler
= proc_dointvec_minmax
,
306 .procname
= "sched_migration_cost",
307 .data
= &sysctl_sched_migration_cost
,
308 .maxlen
= sizeof(unsigned int),
310 .proc_handler
= proc_dointvec
,
313 .procname
= "sched_nr_migrate",
314 .data
= &sysctl_sched_nr_migrate
,
315 .maxlen
= sizeof(unsigned int),
317 .proc_handler
= proc_dointvec
,
320 .procname
= "sched_time_avg",
321 .data
= &sysctl_sched_time_avg
,
322 .maxlen
= sizeof(unsigned int),
324 .proc_handler
= proc_dointvec
,
327 .procname
= "timer_migration",
328 .data
= &sysctl_timer_migration
,
329 .maxlen
= sizeof(unsigned int),
331 .proc_handler
= proc_dointvec_minmax
,
337 .procname
= "sched_rt_period_us",
338 .data
= &sysctl_sched_rt_period
,
339 .maxlen
= sizeof(unsigned int),
341 .proc_handler
= sched_rt_handler
,
344 .procname
= "sched_rt_runtime_us",
345 .data
= &sysctl_sched_rt_runtime
,
346 .maxlen
= sizeof(int),
348 .proc_handler
= sched_rt_handler
,
351 .procname
= "sched_compat_yield",
352 .data
= &sysctl_sched_compat_yield
,
353 .maxlen
= sizeof(unsigned int),
355 .proc_handler
= proc_dointvec
,
357 #ifdef CONFIG_PROVE_LOCKING
359 .procname
= "prove_locking",
360 .data
= &prove_locking
,
361 .maxlen
= sizeof(int),
363 .proc_handler
= proc_dointvec
,
366 #ifdef CONFIG_LOCK_STAT
368 .procname
= "lock_stat",
370 .maxlen
= sizeof(int),
372 .proc_handler
= proc_dointvec
,
377 .data
= &panic_timeout
,
378 .maxlen
= sizeof(int),
380 .proc_handler
= proc_dointvec
,
383 .procname
= "core_uses_pid",
384 .data
= &core_uses_pid
,
385 .maxlen
= sizeof(int),
387 .proc_handler
= proc_dointvec
,
390 .procname
= "core_pattern",
391 .data
= core_pattern
,
392 .maxlen
= CORENAME_MAX_SIZE
,
394 .proc_handler
= proc_dostring
,
397 .procname
= "core_pipe_limit",
398 .data
= &core_pipe_limit
,
399 .maxlen
= sizeof(unsigned int),
401 .proc_handler
= proc_dointvec
,
403 #ifdef CONFIG_PROC_SYSCTL
405 .procname
= "tainted",
406 .maxlen
= sizeof(long),
408 .proc_handler
= proc_taint
,
411 #ifdef CONFIG_LATENCYTOP
413 .procname
= "latencytop",
414 .data
= &latencytop_enabled
,
415 .maxlen
= sizeof(int),
417 .proc_handler
= proc_dointvec
,
420 #ifdef CONFIG_BLK_DEV_INITRD
422 .procname
= "real-root-dev",
423 .data
= &real_root_dev
,
424 .maxlen
= sizeof(int),
426 .proc_handler
= proc_dointvec
,
430 .procname
= "print-fatal-signals",
431 .data
= &print_fatal_signals
,
432 .maxlen
= sizeof(int),
434 .proc_handler
= proc_dointvec
,
438 .procname
= "reboot-cmd",
439 .data
= reboot_command
,
442 .proc_handler
= proc_dostring
,
445 .procname
= "stop-a",
446 .data
= &stop_a_enabled
,
447 .maxlen
= sizeof (int),
449 .proc_handler
= proc_dointvec
,
452 .procname
= "scons-poweroff",
453 .data
= &scons_pwroff
,
454 .maxlen
= sizeof (int),
456 .proc_handler
= proc_dointvec
,
459 #ifdef CONFIG_SPARC64
461 .procname
= "tsb-ratio",
462 .data
= &sysctl_tsb_ratio
,
463 .maxlen
= sizeof (int),
465 .proc_handler
= proc_dointvec
,
470 .procname
= "soft-power",
471 .data
= &pwrsw_enabled
,
472 .maxlen
= sizeof (int),
474 .proc_handler
= proc_dointvec
,
477 .procname
= "unaligned-trap",
478 .data
= &unaligned_enabled
,
479 .maxlen
= sizeof (int),
481 .proc_handler
= proc_dointvec
,
485 .procname
= "ctrl-alt-del",
487 .maxlen
= sizeof(int),
489 .proc_handler
= proc_dointvec
,
491 #ifdef CONFIG_FUNCTION_TRACER
493 .procname
= "ftrace_enabled",
494 .data
= &ftrace_enabled
,
495 .maxlen
= sizeof(int),
497 .proc_handler
= ftrace_enable_sysctl
,
500 #ifdef CONFIG_STACK_TRACER
502 .procname
= "stack_tracer_enabled",
503 .data
= &stack_tracer_enabled
,
504 .maxlen
= sizeof(int),
506 .proc_handler
= stack_trace_sysctl
,
509 #ifdef CONFIG_TRACING
511 .procname
= "ftrace_dump_on_oops",
512 .data
= &ftrace_dump_on_oops
,
513 .maxlen
= sizeof(int),
515 .proc_handler
= proc_dointvec
,
518 #ifdef CONFIG_MODULES
520 .procname
= "modprobe",
521 .data
= &modprobe_path
,
522 .maxlen
= KMOD_PATH_LEN
,
524 .proc_handler
= proc_dostring
,
527 .procname
= "modules_disabled",
528 .data
= &modules_disabled
,
529 .maxlen
= sizeof(int),
531 /* only handle a transition from default "0" to "1" */
532 .proc_handler
= proc_dointvec_minmax
,
537 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
539 .procname
= "hotplug",
540 .data
= &uevent_helper
,
541 .maxlen
= UEVENT_HELPER_PATH_LEN
,
543 .proc_handler
= proc_dostring
,
546 #ifdef CONFIG_CHR_DEV_SG
548 .procname
= "sg-big-buff",
549 .data
= &sg_big_buff
,
550 .maxlen
= sizeof (int),
552 .proc_handler
= proc_dointvec
,
555 #ifdef CONFIG_BSD_PROCESS_ACCT
559 .maxlen
= 3*sizeof(int),
561 .proc_handler
= proc_dointvec
,
564 #ifdef CONFIG_MAGIC_SYSRQ
567 .data
= &__sysrq_enabled
,
568 .maxlen
= sizeof (int),
570 .proc_handler
= proc_dointvec
,
573 #ifdef CONFIG_PROC_SYSCTL
575 .procname
= "cad_pid",
577 .maxlen
= sizeof (int),
579 .proc_handler
= proc_do_cad_pid
,
583 .procname
= "threads-max",
584 .data
= &max_threads
,
585 .maxlen
= sizeof(int),
587 .proc_handler
= proc_dointvec
,
590 .procname
= "random",
592 .child
= random_table
,
595 .procname
= "overflowuid",
596 .data
= &overflowuid
,
597 .maxlen
= sizeof(int),
599 .proc_handler
= proc_dointvec_minmax
,
600 .extra1
= &minolduid
,
601 .extra2
= &maxolduid
,
604 .procname
= "overflowgid",
605 .data
= &overflowgid
,
606 .maxlen
= sizeof(int),
608 .proc_handler
= proc_dointvec_minmax
,
609 .extra1
= &minolduid
,
610 .extra2
= &maxolduid
,
613 #ifdef CONFIG_MATHEMU
615 .procname
= "ieee_emulation_warnings",
616 .data
= &sysctl_ieee_emulation_warnings
,
617 .maxlen
= sizeof(int),
619 .proc_handler
= proc_dointvec
,
623 .procname
= "userprocess_debug",
624 .data
= &show_unhandled_signals
,
625 .maxlen
= sizeof(int),
627 .proc_handler
= proc_dointvec
,
631 .procname
= "pid_max",
633 .maxlen
= sizeof (int),
635 .proc_handler
= proc_dointvec_minmax
,
636 .extra1
= &pid_max_min
,
637 .extra2
= &pid_max_max
,
640 .procname
= "panic_on_oops",
641 .data
= &panic_on_oops
,
642 .maxlen
= sizeof(int),
644 .proc_handler
= proc_dointvec
,
646 #if defined CONFIG_PRINTK
648 .procname
= "printk",
649 .data
= &console_loglevel
,
650 .maxlen
= 4*sizeof(int),
652 .proc_handler
= proc_dointvec
,
655 .procname
= "printk_ratelimit",
656 .data
= &printk_ratelimit_state
.interval
,
657 .maxlen
= sizeof(int),
659 .proc_handler
= proc_dointvec_jiffies
,
662 .procname
= "printk_ratelimit_burst",
663 .data
= &printk_ratelimit_state
.burst
,
664 .maxlen
= sizeof(int),
666 .proc_handler
= proc_dointvec
,
669 .procname
= "printk_delay",
670 .data
= &printk_delay_msec
,
671 .maxlen
= sizeof(int),
673 .proc_handler
= proc_dointvec_minmax
,
675 .extra2
= &ten_thousand
,
679 .procname
= "ngroups_max",
680 .data
= &ngroups_max
,
681 .maxlen
= sizeof (int),
683 .proc_handler
= proc_dointvec
,
685 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
687 .procname
= "unknown_nmi_panic",
688 .data
= &unknown_nmi_panic
,
689 .maxlen
= sizeof (int),
691 .proc_handler
= proc_dointvec
,
694 .procname
= "nmi_watchdog",
695 .data
= &nmi_watchdog_enabled
,
696 .maxlen
= sizeof (int),
698 .proc_handler
= proc_nmi_enabled
,
701 #if defined(CONFIG_X86)
703 .procname
= "panic_on_unrecovered_nmi",
704 .data
= &panic_on_unrecovered_nmi
,
705 .maxlen
= sizeof(int),
707 .proc_handler
= proc_dointvec
,
710 .procname
= "panic_on_io_nmi",
711 .data
= &panic_on_io_nmi
,
712 .maxlen
= sizeof(int),
714 .proc_handler
= proc_dointvec
,
717 .procname
= "bootloader_type",
718 .data
= &bootloader_type
,
719 .maxlen
= sizeof (int),
721 .proc_handler
= proc_dointvec
,
724 .procname
= "bootloader_version",
725 .data
= &bootloader_version
,
726 .maxlen
= sizeof (int),
728 .proc_handler
= proc_dointvec
,
731 .procname
= "kstack_depth_to_print",
732 .data
= &kstack_depth_to_print
,
733 .maxlen
= sizeof(int),
735 .proc_handler
= proc_dointvec
,
738 .procname
= "io_delay_type",
739 .data
= &io_delay_type
,
740 .maxlen
= sizeof(int),
742 .proc_handler
= proc_dointvec
,
745 #if defined(CONFIG_MMU)
747 .procname
= "randomize_va_space",
748 .data
= &randomize_va_space
,
749 .maxlen
= sizeof(int),
751 .proc_handler
= proc_dointvec
,
754 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
756 .procname
= "spin_retry",
758 .maxlen
= sizeof (int),
760 .proc_handler
= proc_dointvec
,
763 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
765 .procname
= "acpi_video_flags",
766 .data
= &acpi_realmode_flags
,
767 .maxlen
= sizeof (unsigned long),
769 .proc_handler
= proc_doulongvec_minmax
,
774 .procname
= "ignore-unaligned-usertrap",
775 .data
= &no_unaligned_warning
,
776 .maxlen
= sizeof (int),
778 .proc_handler
= proc_dointvec
,
781 .procname
= "unaligned-dump-stack",
782 .data
= &unaligned_dump_stack
,
783 .maxlen
= sizeof (int),
785 .proc_handler
= proc_dointvec
,
788 #ifdef CONFIG_DETECT_SOFTLOCKUP
790 .procname
= "softlockup_panic",
791 .data
= &softlockup_panic
,
792 .maxlen
= sizeof(int),
794 .proc_handler
= proc_dointvec_minmax
,
799 .procname
= "softlockup_thresh",
800 .data
= &softlockup_thresh
,
801 .maxlen
= sizeof(int),
803 .proc_handler
= proc_dosoftlockup_thresh
,
808 #ifdef CONFIG_DETECT_HUNG_TASK
810 .procname
= "hung_task_panic",
811 .data
= &sysctl_hung_task_panic
,
812 .maxlen
= sizeof(int),
814 .proc_handler
= proc_dointvec_minmax
,
819 .procname
= "hung_task_check_count",
820 .data
= &sysctl_hung_task_check_count
,
821 .maxlen
= sizeof(unsigned long),
823 .proc_handler
= proc_doulongvec_minmax
,
826 .procname
= "hung_task_timeout_secs",
827 .data
= &sysctl_hung_task_timeout_secs
,
828 .maxlen
= sizeof(unsigned long),
830 .proc_handler
= proc_dohung_task_timeout_secs
,
833 .procname
= "hung_task_warnings",
834 .data
= &sysctl_hung_task_warnings
,
835 .maxlen
= sizeof(unsigned long),
837 .proc_handler
= proc_doulongvec_minmax
,
842 .procname
= "compat-log",
844 .maxlen
= sizeof (int),
846 .proc_handler
= proc_dointvec
,
849 #ifdef CONFIG_RT_MUTEXES
851 .procname
= "max_lock_depth",
852 .data
= &max_lock_depth
,
853 .maxlen
= sizeof(int),
855 .proc_handler
= proc_dointvec
,
859 .procname
= "poweroff_cmd",
860 .data
= &poweroff_cmd
,
861 .maxlen
= POWEROFF_CMD_PATH_LEN
,
863 .proc_handler
= proc_dostring
,
869 .child
= key_sysctls
,
872 #ifdef CONFIG_RCU_TORTURE_TEST
874 .procname
= "rcutorture_runnable",
875 .data
= &rcutorture_runnable
,
876 .maxlen
= sizeof(int),
878 .proc_handler
= proc_dointvec
,
881 #ifdef CONFIG_SLOW_WORK
883 .procname
= "slow-work",
885 .child
= slow_work_sysctls
,
888 #ifdef CONFIG_PERF_EVENTS
890 .procname
= "perf_event_paranoid",
891 .data
= &sysctl_perf_event_paranoid
,
892 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
894 .proc_handler
= proc_dointvec
,
897 .procname
= "perf_event_mlock_kb",
898 .data
= &sysctl_perf_event_mlock
,
899 .maxlen
= sizeof(sysctl_perf_event_mlock
),
901 .proc_handler
= proc_dointvec
,
904 .procname
= "perf_event_max_sample_rate",
905 .data
= &sysctl_perf_event_sample_rate
,
906 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
908 .proc_handler
= proc_dointvec
,
911 #ifdef CONFIG_KMEMCHECK
913 .procname
= "kmemcheck",
914 .data
= &kmemcheck_enabled
,
915 .maxlen
= sizeof(int),
917 .proc_handler
= proc_dointvec
,
922 .procname
= "blk_iopoll",
923 .data
= &blk_iopoll_enabled
,
924 .maxlen
= sizeof(int),
926 .proc_handler
= proc_dointvec
,
930 * NOTE: do not add new entries to this table unless you have read
931 * Documentation/sysctl/ctl_unnumbered.txt
936 static struct ctl_table vm_table
[] = {
938 .procname
= "overcommit_memory",
939 .data
= &sysctl_overcommit_memory
,
940 .maxlen
= sizeof(sysctl_overcommit_memory
),
942 .proc_handler
= proc_dointvec
,
945 .procname
= "panic_on_oom",
946 .data
= &sysctl_panic_on_oom
,
947 .maxlen
= sizeof(sysctl_panic_on_oom
),
949 .proc_handler
= proc_dointvec
,
952 .procname
= "oom_kill_allocating_task",
953 .data
= &sysctl_oom_kill_allocating_task
,
954 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
956 .proc_handler
= proc_dointvec
,
959 .procname
= "oom_dump_tasks",
960 .data
= &sysctl_oom_dump_tasks
,
961 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
963 .proc_handler
= proc_dointvec
,
966 .procname
= "overcommit_ratio",
967 .data
= &sysctl_overcommit_ratio
,
968 .maxlen
= sizeof(sysctl_overcommit_ratio
),
970 .proc_handler
= proc_dointvec
,
973 .procname
= "page-cluster",
974 .data
= &page_cluster
,
975 .maxlen
= sizeof(int),
977 .proc_handler
= proc_dointvec
,
980 .procname
= "dirty_background_ratio",
981 .data
= &dirty_background_ratio
,
982 .maxlen
= sizeof(dirty_background_ratio
),
984 .proc_handler
= dirty_background_ratio_handler
,
986 .extra2
= &one_hundred
,
989 .procname
= "dirty_background_bytes",
990 .data
= &dirty_background_bytes
,
991 .maxlen
= sizeof(dirty_background_bytes
),
993 .proc_handler
= dirty_background_bytes_handler
,
997 .procname
= "dirty_ratio",
998 .data
= &vm_dirty_ratio
,
999 .maxlen
= sizeof(vm_dirty_ratio
),
1001 .proc_handler
= dirty_ratio_handler
,
1003 .extra2
= &one_hundred
,
1006 .procname
= "dirty_bytes",
1007 .data
= &vm_dirty_bytes
,
1008 .maxlen
= sizeof(vm_dirty_bytes
),
1010 .proc_handler
= dirty_bytes_handler
,
1011 .extra1
= &dirty_bytes_min
,
1014 .procname
= "dirty_writeback_centisecs",
1015 .data
= &dirty_writeback_interval
,
1016 .maxlen
= sizeof(dirty_writeback_interval
),
1018 .proc_handler
= dirty_writeback_centisecs_handler
,
1021 .procname
= "dirty_expire_centisecs",
1022 .data
= &dirty_expire_interval
,
1023 .maxlen
= sizeof(dirty_expire_interval
),
1025 .proc_handler
= proc_dointvec
,
1028 .procname
= "nr_pdflush_threads",
1029 .data
= &nr_pdflush_threads
,
1030 .maxlen
= sizeof nr_pdflush_threads
,
1031 .mode
= 0444 /* read-only*/,
1032 .proc_handler
= proc_dointvec
,
1035 .procname
= "swappiness",
1036 .data
= &vm_swappiness
,
1037 .maxlen
= sizeof(vm_swappiness
),
1039 .proc_handler
= proc_dointvec_minmax
,
1041 .extra2
= &one_hundred
,
1043 #ifdef CONFIG_HUGETLB_PAGE
1045 .procname
= "nr_hugepages",
1047 .maxlen
= sizeof(unsigned long),
1049 .proc_handler
= hugetlb_sysctl_handler
,
1050 .extra1
= (void *)&hugetlb_zero
,
1051 .extra2
= (void *)&hugetlb_infinity
,
1055 .procname
= "nr_hugepages_mempolicy",
1057 .maxlen
= sizeof(unsigned long),
1059 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1060 .extra1
= (void *)&hugetlb_zero
,
1061 .extra2
= (void *)&hugetlb_infinity
,
1065 .procname
= "hugetlb_shm_group",
1066 .data
= &sysctl_hugetlb_shm_group
,
1067 .maxlen
= sizeof(gid_t
),
1069 .proc_handler
= proc_dointvec
,
1072 .procname
= "hugepages_treat_as_movable",
1073 .data
= &hugepages_treat_as_movable
,
1074 .maxlen
= sizeof(int),
1076 .proc_handler
= hugetlb_treat_movable_handler
,
1079 .procname
= "nr_overcommit_hugepages",
1081 .maxlen
= sizeof(unsigned long),
1083 .proc_handler
= hugetlb_overcommit_handler
,
1084 .extra1
= (void *)&hugetlb_zero
,
1085 .extra2
= (void *)&hugetlb_infinity
,
1089 .procname
= "lowmem_reserve_ratio",
1090 .data
= &sysctl_lowmem_reserve_ratio
,
1091 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1093 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1096 .procname
= "drop_caches",
1097 .data
= &sysctl_drop_caches
,
1098 .maxlen
= sizeof(int),
1100 .proc_handler
= drop_caches_sysctl_handler
,
1103 .procname
= "min_free_kbytes",
1104 .data
= &min_free_kbytes
,
1105 .maxlen
= sizeof(min_free_kbytes
),
1107 .proc_handler
= min_free_kbytes_sysctl_handler
,
1111 .procname
= "percpu_pagelist_fraction",
1112 .data
= &percpu_pagelist_fraction
,
1113 .maxlen
= sizeof(percpu_pagelist_fraction
),
1115 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1116 .extra1
= &min_percpu_pagelist_fract
,
1120 .procname
= "max_map_count",
1121 .data
= &sysctl_max_map_count
,
1122 .maxlen
= sizeof(sysctl_max_map_count
),
1124 .proc_handler
= proc_dointvec_minmax
,
1129 .procname
= "nr_trim_pages",
1130 .data
= &sysctl_nr_trim_pages
,
1131 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1133 .proc_handler
= proc_dointvec_minmax
,
1138 .procname
= "laptop_mode",
1139 .data
= &laptop_mode
,
1140 .maxlen
= sizeof(laptop_mode
),
1142 .proc_handler
= proc_dointvec_jiffies
,
1145 .procname
= "block_dump",
1146 .data
= &block_dump
,
1147 .maxlen
= sizeof(block_dump
),
1149 .proc_handler
= proc_dointvec
,
1153 .procname
= "vfs_cache_pressure",
1154 .data
= &sysctl_vfs_cache_pressure
,
1155 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1157 .proc_handler
= proc_dointvec
,
1160 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1162 .procname
= "legacy_va_layout",
1163 .data
= &sysctl_legacy_va_layout
,
1164 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1166 .proc_handler
= proc_dointvec
,
1172 .procname
= "zone_reclaim_mode",
1173 .data
= &zone_reclaim_mode
,
1174 .maxlen
= sizeof(zone_reclaim_mode
),
1176 .proc_handler
= proc_dointvec
,
1180 .procname
= "min_unmapped_ratio",
1181 .data
= &sysctl_min_unmapped_ratio
,
1182 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1184 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1186 .extra2
= &one_hundred
,
1189 .procname
= "min_slab_ratio",
1190 .data
= &sysctl_min_slab_ratio
,
1191 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1193 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1195 .extra2
= &one_hundred
,
1200 .procname
= "stat_interval",
1201 .data
= &sysctl_stat_interval
,
1202 .maxlen
= sizeof(sysctl_stat_interval
),
1204 .proc_handler
= proc_dointvec_jiffies
,
1209 .procname
= "mmap_min_addr",
1210 .data
= &dac_mmap_min_addr
,
1211 .maxlen
= sizeof(unsigned long),
1213 .proc_handler
= mmap_min_addr_handler
,
1218 .procname
= "numa_zonelist_order",
1219 .data
= &numa_zonelist_order
,
1220 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1222 .proc_handler
= numa_zonelist_order_handler
,
1225 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1226 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1228 .procname
= "vdso_enabled",
1229 .data
= &vdso_enabled
,
1230 .maxlen
= sizeof(vdso_enabled
),
1232 .proc_handler
= proc_dointvec
,
1236 #ifdef CONFIG_HIGHMEM
1238 .procname
= "highmem_is_dirtyable",
1239 .data
= &vm_highmem_is_dirtyable
,
1240 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1242 .proc_handler
= proc_dointvec_minmax
,
1248 .procname
= "scan_unevictable_pages",
1249 .data
= &scan_unevictable_pages
,
1250 .maxlen
= sizeof(scan_unevictable_pages
),
1252 .proc_handler
= scan_unevictable_handler
,
1254 #ifdef CONFIG_MEMORY_FAILURE
1256 .procname
= "memory_failure_early_kill",
1257 .data
= &sysctl_memory_failure_early_kill
,
1258 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1260 .proc_handler
= proc_dointvec_minmax
,
1265 .procname
= "memory_failure_recovery",
1266 .data
= &sysctl_memory_failure_recovery
,
1267 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1269 .proc_handler
= proc_dointvec_minmax
,
1276 * NOTE: do not add new entries to this table unless you have read
1277 * Documentation/sysctl/ctl_unnumbered.txt
1282 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1283 static struct ctl_table binfmt_misc_table
[] = {
1288 static struct ctl_table fs_table
[] = {
1290 .procname
= "inode-nr",
1291 .data
= &inodes_stat
,
1292 .maxlen
= 2*sizeof(int),
1294 .proc_handler
= proc_dointvec
,
1297 .procname
= "inode-state",
1298 .data
= &inodes_stat
,
1299 .maxlen
= 7*sizeof(int),
1301 .proc_handler
= proc_dointvec
,
1304 .procname
= "file-nr",
1305 .data
= &files_stat
,
1306 .maxlen
= 3*sizeof(int),
1308 .proc_handler
= proc_nr_files
,
1311 .procname
= "file-max",
1312 .data
= &files_stat
.max_files
,
1313 .maxlen
= sizeof(int),
1315 .proc_handler
= proc_dointvec
,
1318 .procname
= "nr_open",
1319 .data
= &sysctl_nr_open
,
1320 .maxlen
= sizeof(int),
1322 .proc_handler
= proc_dointvec_minmax
,
1323 .extra1
= &sysctl_nr_open_min
,
1324 .extra2
= &sysctl_nr_open_max
,
1327 .procname
= "dentry-state",
1328 .data
= &dentry_stat
,
1329 .maxlen
= 6*sizeof(int),
1331 .proc_handler
= proc_dointvec
,
1334 .procname
= "overflowuid",
1335 .data
= &fs_overflowuid
,
1336 .maxlen
= sizeof(int),
1338 .proc_handler
= proc_dointvec_minmax
,
1339 .extra1
= &minolduid
,
1340 .extra2
= &maxolduid
,
1343 .procname
= "overflowgid",
1344 .data
= &fs_overflowgid
,
1345 .maxlen
= sizeof(int),
1347 .proc_handler
= proc_dointvec_minmax
,
1348 .extra1
= &minolduid
,
1349 .extra2
= &maxolduid
,
1351 #ifdef CONFIG_FILE_LOCKING
1353 .procname
= "leases-enable",
1354 .data
= &leases_enable
,
1355 .maxlen
= sizeof(int),
1357 .proc_handler
= proc_dointvec
,
1360 #ifdef CONFIG_DNOTIFY
1362 .procname
= "dir-notify-enable",
1363 .data
= &dir_notify_enable
,
1364 .maxlen
= sizeof(int),
1366 .proc_handler
= proc_dointvec
,
1370 #ifdef CONFIG_FILE_LOCKING
1372 .procname
= "lease-break-time",
1373 .data
= &lease_break_time
,
1374 .maxlen
= sizeof(int),
1376 .proc_handler
= proc_dointvec
,
1381 .procname
= "aio-nr",
1383 .maxlen
= sizeof(aio_nr
),
1385 .proc_handler
= proc_doulongvec_minmax
,
1388 .procname
= "aio-max-nr",
1389 .data
= &aio_max_nr
,
1390 .maxlen
= sizeof(aio_max_nr
),
1392 .proc_handler
= proc_doulongvec_minmax
,
1394 #endif /* CONFIG_AIO */
1395 #ifdef CONFIG_INOTIFY_USER
1397 .procname
= "inotify",
1399 .child
= inotify_table
,
1404 .procname
= "epoll",
1406 .child
= epoll_table
,
1411 .procname
= "suid_dumpable",
1412 .data
= &suid_dumpable
,
1413 .maxlen
= sizeof(int),
1415 .proc_handler
= proc_dointvec_minmax
,
1419 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1421 .procname
= "binfmt_misc",
1423 .child
= binfmt_misc_table
,
1427 * NOTE: do not add new entries to this table unless you have read
1428 * Documentation/sysctl/ctl_unnumbered.txt
1433 static struct ctl_table debug_table
[] = {
1434 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1435 defined(CONFIG_S390)
1437 .procname
= "exception-trace",
1438 .data
= &show_unhandled_signals
,
1439 .maxlen
= sizeof(int),
1441 .proc_handler
= proc_dointvec
1444 #if defined(CONFIG_OPTPROBES)
1446 .procname
= "kprobes-optimization",
1447 .data
= &sysctl_kprobes_optimization
,
1448 .maxlen
= sizeof(int),
1450 .proc_handler
= proc_kprobes_optimization_handler
,
1458 static struct ctl_table dev_table
[] = {
1462 static DEFINE_SPINLOCK(sysctl_lock
);
1464 /* called under sysctl_lock */
1465 static int use_table(struct ctl_table_header
*p
)
1467 if (unlikely(p
->unregistering
))
1473 /* called under sysctl_lock */
1474 static void unuse_table(struct ctl_table_header
*p
)
1477 if (unlikely(p
->unregistering
))
1478 complete(p
->unregistering
);
1481 /* called under sysctl_lock, will reacquire if has to wait */
1482 static void start_unregistering(struct ctl_table_header
*p
)
1485 * if p->used is 0, nobody will ever touch that entry again;
1486 * we'll eliminate all paths to it before dropping sysctl_lock
1488 if (unlikely(p
->used
)) {
1489 struct completion wait
;
1490 init_completion(&wait
);
1491 p
->unregistering
= &wait
;
1492 spin_unlock(&sysctl_lock
);
1493 wait_for_completion(&wait
);
1494 spin_lock(&sysctl_lock
);
1496 /* anything non-NULL; we'll never dereference it */
1497 p
->unregistering
= ERR_PTR(-EINVAL
);
1500 * do not remove from the list until nobody holds it; walking the
1501 * list in do_sysctl() relies on that.
1503 list_del_init(&p
->ctl_entry
);
1506 void sysctl_head_get(struct ctl_table_header
*head
)
1508 spin_lock(&sysctl_lock
);
1510 spin_unlock(&sysctl_lock
);
1513 void sysctl_head_put(struct ctl_table_header
*head
)
1515 spin_lock(&sysctl_lock
);
1518 spin_unlock(&sysctl_lock
);
1521 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1525 spin_lock(&sysctl_lock
);
1526 if (!use_table(head
))
1527 head
= ERR_PTR(-ENOENT
);
1528 spin_unlock(&sysctl_lock
);
1532 void sysctl_head_finish(struct ctl_table_header
*head
)
1536 spin_lock(&sysctl_lock
);
1538 spin_unlock(&sysctl_lock
);
1541 static struct ctl_table_set
*
1542 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1544 struct ctl_table_set
*set
= &root
->default_set
;
1546 set
= root
->lookup(root
, namespaces
);
1550 static struct list_head
*
1551 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1553 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1557 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1558 struct ctl_table_header
*prev
)
1560 struct ctl_table_root
*root
;
1561 struct list_head
*header_list
;
1562 struct ctl_table_header
*head
;
1563 struct list_head
*tmp
;
1565 spin_lock(&sysctl_lock
);
1568 tmp
= &prev
->ctl_entry
;
1572 tmp
= &root_table_header
.ctl_entry
;
1574 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1576 if (!use_table(head
))
1578 spin_unlock(&sysctl_lock
);
1583 header_list
= lookup_header_list(root
, namespaces
);
1584 if (tmp
!= header_list
)
1588 root
= list_entry(root
->root_list
.next
,
1589 struct ctl_table_root
, root_list
);
1590 if (root
== &sysctl_table_root
)
1592 header_list
= lookup_header_list(root
, namespaces
);
1593 } while (list_empty(header_list
));
1594 tmp
= header_list
->next
;
1597 spin_unlock(&sysctl_lock
);
1601 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1603 return __sysctl_head_next(current
->nsproxy
, prev
);
1606 void register_sysctl_root(struct ctl_table_root
*root
)
1608 spin_lock(&sysctl_lock
);
1609 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1610 spin_unlock(&sysctl_lock
);
1614 * sysctl_perm does NOT grant the superuser all rights automatically, because
1615 * some sysctl variables are readonly even to root.
1618 static int test_perm(int mode
, int op
)
1620 if (!current_euid())
1622 else if (in_egroup_p(0))
1624 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1629 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1634 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1638 if (root
->permissions
)
1639 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1643 return test_perm(mode
, op
);
1646 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1648 for (; table
->procname
; table
++) {
1649 table
->parent
= parent
;
1651 sysctl_set_parent(table
, table
->child
);
1655 static __init
int sysctl_init(void)
1657 sysctl_set_parent(NULL
, root_table
);
1658 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1661 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1667 core_initcall(sysctl_init
);
1669 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1670 struct ctl_table
*table
)
1672 struct ctl_table
*p
;
1673 const char *s
= branch
->procname
;
1675 /* branch should have named subdirectory as its first element */
1676 if (!s
|| !branch
->child
)
1679 /* ... and nothing else */
1680 if (branch
[1].procname
)
1683 /* table should contain subdirectory with the same name */
1684 for (p
= table
; p
->procname
; p
++) {
1687 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1693 /* see if attaching q to p would be an improvement */
1694 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1696 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1697 struct ctl_table
*next
;
1699 int not_in_parent
= !p
->attached_by
;
1701 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1702 if (by
== q
->attached_by
)
1704 if (to
== p
->attached_by
)
1710 if (is_better
&& not_in_parent
) {
1711 q
->attached_by
= by
;
1712 q
->attached_to
= to
;
1718 * __register_sysctl_paths - register a sysctl hierarchy
1719 * @root: List of sysctl headers to register on
1720 * @namespaces: Data to compute which lists of sysctl entries are visible
1721 * @path: The path to the directory the sysctl table is in.
1722 * @table: the top-level table structure
1724 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1725 * array. A completely 0 filled entry terminates the table.
1727 * The members of the &struct ctl_table structure are used as follows:
1729 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1730 * enter a sysctl file
1732 * data - a pointer to data for use by proc_handler
1734 * maxlen - the maximum size in bytes of the data
1736 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1738 * child - a pointer to the child sysctl table if this entry is a directory, or
1741 * proc_handler - the text handler routine (described below)
1743 * de - for internal use by the sysctl routines
1745 * extra1, extra2 - extra pointers usable by the proc handler routines
1747 * Leaf nodes in the sysctl tree will be represented by a single file
1748 * under /proc; non-leaf nodes will be represented by directories.
1750 * sysctl(2) can automatically manage read and write requests through
1751 * the sysctl table. The data and maxlen fields of the ctl_table
1752 * struct enable minimal validation of the values being written to be
1753 * performed, and the mode field allows minimal authentication.
1755 * There must be a proc_handler routine for any terminal nodes
1756 * mirrored under /proc/sys (non-terminals are handled by a built-in
1757 * directory handler). Several default handlers are available to
1758 * cover common cases -
1760 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1761 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1762 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1764 * It is the handler's job to read the input buffer from user memory
1765 * and process it. The handler should return 0 on success.
1767 * This routine returns %NULL on a failure to register, and a pointer
1768 * to the table header on success.
1770 struct ctl_table_header
*__register_sysctl_paths(
1771 struct ctl_table_root
*root
,
1772 struct nsproxy
*namespaces
,
1773 const struct ctl_path
*path
, struct ctl_table
*table
)
1775 struct ctl_table_header
*header
;
1776 struct ctl_table
*new, **prevp
;
1777 unsigned int n
, npath
;
1778 struct ctl_table_set
*set
;
1780 /* Count the path components */
1781 for (npath
= 0; path
[npath
].procname
; ++npath
)
1785 * For each path component, allocate a 2-element ctl_table array.
1786 * The first array element will be filled with the sysctl entry
1787 * for this, the second will be the sentinel (procname == 0).
1789 * We allocate everything in one go so that we don't have to
1790 * worry about freeing additional memory in unregister_sysctl_table.
1792 header
= kzalloc(sizeof(struct ctl_table_header
) +
1793 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1797 new = (struct ctl_table
*) (header
+ 1);
1799 /* Now connect the dots */
1800 prevp
= &header
->ctl_table
;
1801 for (n
= 0; n
< npath
; ++n
, ++path
) {
1802 /* Copy the procname */
1803 new->procname
= path
->procname
;
1807 prevp
= &new->child
;
1812 header
->ctl_table_arg
= table
;
1814 INIT_LIST_HEAD(&header
->ctl_entry
);
1816 header
->unregistering
= NULL
;
1817 header
->root
= root
;
1818 sysctl_set_parent(NULL
, header
->ctl_table
);
1820 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1821 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1826 spin_lock(&sysctl_lock
);
1827 header
->set
= lookup_header_set(root
, namespaces
);
1828 header
->attached_by
= header
->ctl_table
;
1829 header
->attached_to
= root_table
;
1830 header
->parent
= &root_table_header
;
1831 for (set
= header
->set
; set
; set
= set
->parent
) {
1832 struct ctl_table_header
*p
;
1833 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1834 if (p
->unregistering
)
1836 try_attach(p
, header
);
1839 header
->parent
->count
++;
1840 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1841 spin_unlock(&sysctl_lock
);
1847 * register_sysctl_table_path - register a sysctl table hierarchy
1848 * @path: The path to the directory the sysctl table is in.
1849 * @table: the top-level table structure
1851 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1852 * array. A completely 0 filled entry terminates the table.
1854 * See __register_sysctl_paths for more details.
1856 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1857 struct ctl_table
*table
)
1859 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1864 * register_sysctl_table - register a sysctl table hierarchy
1865 * @table: the top-level table structure
1867 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1868 * array. A completely 0 filled entry terminates the table.
1870 * See register_sysctl_paths for more details.
1872 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1874 static const struct ctl_path null_path
[] = { {} };
1876 return register_sysctl_paths(null_path
, table
);
1880 * unregister_sysctl_table - unregister a sysctl table hierarchy
1881 * @header: the header returned from register_sysctl_table
1883 * Unregisters the sysctl table and all children. proc entries may not
1884 * actually be removed until they are no longer used by anyone.
1886 void unregister_sysctl_table(struct ctl_table_header
* header
)
1893 spin_lock(&sysctl_lock
);
1894 start_unregistering(header
);
1895 if (!--header
->parent
->count
) {
1897 kfree(header
->parent
);
1899 if (!--header
->count
)
1901 spin_unlock(&sysctl_lock
);
1904 int sysctl_is_seen(struct ctl_table_header
*p
)
1906 struct ctl_table_set
*set
= p
->set
;
1908 spin_lock(&sysctl_lock
);
1909 if (p
->unregistering
)
1911 else if (!set
->is_seen
)
1914 res
= set
->is_seen(set
);
1915 spin_unlock(&sysctl_lock
);
1919 void setup_sysctl_set(struct ctl_table_set
*p
,
1920 struct ctl_table_set
*parent
,
1921 int (*is_seen
)(struct ctl_table_set
*))
1923 INIT_LIST_HEAD(&p
->list
);
1924 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1925 p
->is_seen
= is_seen
;
1928 #else /* !CONFIG_SYSCTL */
1929 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1934 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1935 struct ctl_table
*table
)
1940 void unregister_sysctl_table(struct ctl_table_header
* table
)
1944 void setup_sysctl_set(struct ctl_table_set
*p
,
1945 struct ctl_table_set
*parent
,
1946 int (*is_seen
)(struct ctl_table_set
*))
1950 void sysctl_head_put(struct ctl_table_header
*head
)
1954 #endif /* CONFIG_SYSCTL */
1960 #ifdef CONFIG_PROC_SYSCTL
1962 static int _proc_do_string(void* data
, int maxlen
, int write
,
1963 void __user
*buffer
,
1964 size_t *lenp
, loff_t
*ppos
)
1970 if (!data
|| !maxlen
|| !*lenp
) {
1978 while (len
< *lenp
) {
1979 if (get_user(c
, p
++))
1981 if (c
== 0 || c
== '\n')
1987 if(copy_from_user(data
, buffer
, len
))
1989 ((char *) data
)[len
] = 0;
2007 if(copy_to_user(buffer
, data
, len
))
2010 if(put_user('\n', ((char __user
*) buffer
) + len
))
2021 * proc_dostring - read a string sysctl
2022 * @table: the sysctl table
2023 * @write: %TRUE if this is a write to the sysctl file
2024 * @buffer: the user buffer
2025 * @lenp: the size of the user buffer
2026 * @ppos: file position
2028 * Reads/writes a string from/to the user buffer. If the kernel
2029 * buffer provided is not large enough to hold the string, the
2030 * string is truncated. The copied string is %NULL-terminated.
2031 * If the string is being read by the user process, it is copied
2032 * and a newline '\n' is added. It is truncated if the buffer is
2035 * Returns 0 on success.
2037 int proc_dostring(struct ctl_table
*table
, int write
,
2038 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2040 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2041 buffer
, lenp
, ppos
);
2045 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2047 int write
, void *data
)
2050 *valp
= *negp
? -*lvalp
: *lvalp
;
2055 *lvalp
= (unsigned long)-val
;
2058 *lvalp
= (unsigned long)val
;
2064 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2065 int write
, void __user
*buffer
,
2066 size_t *lenp
, loff_t
*ppos
,
2067 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2068 int write
, void *data
),
2071 #define TMPBUFLEN 21
2072 int *i
, vleft
, first
= 1, neg
;
2076 char buf
[TMPBUFLEN
], *p
;
2077 char __user
*s
= buffer
;
2079 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2080 (*ppos
&& !write
)) {
2085 i
= (int *) tbl_data
;
2086 vleft
= table
->maxlen
/ sizeof(*i
);
2090 conv
= do_proc_dointvec_conv
;
2092 for (; left
&& vleft
--; i
++, first
=0) {
2107 if (len
> sizeof(buf
) - 1)
2108 len
= sizeof(buf
) - 1;
2109 if (copy_from_user(buf
, s
, len
))
2113 if (*p
== '-' && left
> 1) {
2117 if (*p
< '0' || *p
> '9')
2120 lval
= simple_strtoul(p
, &p
, 0);
2123 if ((len
< left
) && *p
&& !isspace(*p
))
2128 if (conv(&neg
, &lval
, i
, 1, data
))
2135 if (conv(&neg
, &lval
, i
, 0, data
))
2138 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2142 if(copy_to_user(s
, buf
, len
))
2149 if (!write
&& !first
&& left
) {
2150 if(put_user('\n', s
))
2157 if (get_user(c
, s
++))
2172 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2173 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2174 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2175 int write
, void *data
),
2178 return __do_proc_dointvec(table
->data
, table
, write
,
2179 buffer
, lenp
, ppos
, conv
, data
);
2183 * proc_dointvec - read a vector of integers
2184 * @table: the sysctl table
2185 * @write: %TRUE if this is a write to the sysctl file
2186 * @buffer: the user buffer
2187 * @lenp: the size of the user buffer
2188 * @ppos: file position
2190 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2191 * values from/to the user buffer, treated as an ASCII string.
2193 * Returns 0 on success.
2195 int proc_dointvec(struct ctl_table
*table
, int write
,
2196 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2198 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2203 * Taint values can only be increased
2204 * This means we can safely use a temporary.
2206 static int proc_taint(struct ctl_table
*table
, int write
,
2207 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2210 unsigned long tmptaint
= get_taint();
2213 if (write
&& !capable(CAP_SYS_ADMIN
))
2218 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2224 * Poor man's atomic or. Not worth adding a primitive
2225 * to everyone's atomic.h for this
2228 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2229 if ((tmptaint
>> i
) & 1)
2237 struct do_proc_dointvec_minmax_conv_param
{
2242 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2244 int write
, void *data
)
2246 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2248 int val
= *negp
? -*lvalp
: *lvalp
;
2249 if ((param
->min
&& *param
->min
> val
) ||
2250 (param
->max
&& *param
->max
< val
))
2257 *lvalp
= (unsigned long)-val
;
2260 *lvalp
= (unsigned long)val
;
2267 * proc_dointvec_minmax - read a vector of integers with min/max values
2268 * @table: the sysctl table
2269 * @write: %TRUE if this is a write to the sysctl file
2270 * @buffer: the user buffer
2271 * @lenp: the size of the user buffer
2272 * @ppos: file position
2274 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2275 * values from/to the user buffer, treated as an ASCII string.
2277 * This routine will ensure the values are within the range specified by
2278 * table->extra1 (min) and table->extra2 (max).
2280 * Returns 0 on success.
2282 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2283 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2285 struct do_proc_dointvec_minmax_conv_param param
= {
2286 .min
= (int *) table
->extra1
,
2287 .max
= (int *) table
->extra2
,
2289 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2290 do_proc_dointvec_minmax_conv
, ¶m
);
2293 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2294 void __user
*buffer
,
2295 size_t *lenp
, loff_t
*ppos
,
2296 unsigned long convmul
,
2297 unsigned long convdiv
)
2299 #define TMPBUFLEN 21
2300 unsigned long *i
, *min
, *max
, val
;
2301 int vleft
, first
=1, neg
;
2303 char buf
[TMPBUFLEN
], *p
;
2304 char __user
*s
= buffer
;
2306 if (!data
|| !table
->maxlen
|| !*lenp
||
2307 (*ppos
&& !write
)) {
2312 i
= (unsigned long *) data
;
2313 min
= (unsigned long *) table
->extra1
;
2314 max
= (unsigned long *) table
->extra2
;
2315 vleft
= table
->maxlen
/ sizeof(unsigned long);
2318 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2333 if (len
> TMPBUFLEN
-1)
2335 if (copy_from_user(buf
, s
, len
))
2339 if (*p
== '-' && left
> 1) {
2343 if (*p
< '0' || *p
> '9')
2345 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2347 if ((len
< left
) && *p
&& !isspace(*p
))
2356 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2363 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2367 if(copy_to_user(s
, buf
, len
))
2374 if (!write
&& !first
&& left
) {
2375 if(put_user('\n', s
))
2382 if (get_user(c
, s
++))
2397 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2398 void __user
*buffer
,
2399 size_t *lenp
, loff_t
*ppos
,
2400 unsigned long convmul
,
2401 unsigned long convdiv
)
2403 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2404 buffer
, lenp
, ppos
, convmul
, convdiv
);
2408 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2409 * @table: the sysctl table
2410 * @write: %TRUE if this is a write to the sysctl file
2411 * @buffer: the user buffer
2412 * @lenp: the size of the user buffer
2413 * @ppos: file position
2415 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2416 * values from/to the user buffer, treated as an ASCII string.
2418 * This routine will ensure the values are within the range specified by
2419 * table->extra1 (min) and table->extra2 (max).
2421 * Returns 0 on success.
2423 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2424 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2426 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2430 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2431 * @table: the sysctl table
2432 * @write: %TRUE if this is a write to the sysctl file
2433 * @buffer: the user buffer
2434 * @lenp: the size of the user buffer
2435 * @ppos: file position
2437 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2438 * values from/to the user buffer, treated as an ASCII string. The values
2439 * are treated as milliseconds, and converted to jiffies when they are stored.
2441 * This routine will ensure the values are within the range specified by
2442 * table->extra1 (min) and table->extra2 (max).
2444 * Returns 0 on success.
2446 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2447 void __user
*buffer
,
2448 size_t *lenp
, loff_t
*ppos
)
2450 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2451 lenp
, ppos
, HZ
, 1000l);
2455 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2457 int write
, void *data
)
2460 if (*lvalp
> LONG_MAX
/ HZ
)
2462 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2468 lval
= (unsigned long)-val
;
2471 lval
= (unsigned long)val
;
2478 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2480 int write
, void *data
)
2483 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2485 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2491 lval
= (unsigned long)-val
;
2494 lval
= (unsigned long)val
;
2496 *lvalp
= jiffies_to_clock_t(lval
);
2501 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2503 int write
, void *data
)
2506 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2512 lval
= (unsigned long)-val
;
2515 lval
= (unsigned long)val
;
2517 *lvalp
= jiffies_to_msecs(lval
);
2523 * proc_dointvec_jiffies - read a vector of integers as seconds
2524 * @table: the sysctl table
2525 * @write: %TRUE if this is a write to the sysctl file
2526 * @buffer: the user buffer
2527 * @lenp: the size of the user buffer
2528 * @ppos: file position
2530 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2531 * values from/to the user buffer, treated as an ASCII string.
2532 * The values read are assumed to be in seconds, and are converted into
2535 * Returns 0 on success.
2537 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2538 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2540 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2541 do_proc_dointvec_jiffies_conv
,NULL
);
2545 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2546 * @table: the sysctl table
2547 * @write: %TRUE if this is a write to the sysctl file
2548 * @buffer: the user buffer
2549 * @lenp: the size of the user buffer
2550 * @ppos: pointer to the file position
2552 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2553 * values from/to the user buffer, treated as an ASCII string.
2554 * The values read are assumed to be in 1/USER_HZ seconds, and
2555 * are converted into jiffies.
2557 * Returns 0 on success.
2559 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2560 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2562 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2563 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2567 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2568 * @table: the sysctl table
2569 * @write: %TRUE if this is a write to the sysctl file
2570 * @buffer: the user buffer
2571 * @lenp: the size of the user buffer
2572 * @ppos: file position
2573 * @ppos: the current position in the file
2575 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2576 * values from/to the user buffer, treated as an ASCII string.
2577 * The values read are assumed to be in 1/1000 seconds, and
2578 * are converted into jiffies.
2580 * Returns 0 on success.
2582 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2583 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2585 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2586 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2589 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2590 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2592 struct pid
*new_pid
;
2596 tmp
= pid_vnr(cad_pid
);
2598 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2599 lenp
, ppos
, NULL
, NULL
);
2603 new_pid
= find_get_pid(tmp
);
2607 put_pid(xchg(&cad_pid
, new_pid
));
2611 #else /* CONFIG_PROC_FS */
2613 int proc_dostring(struct ctl_table
*table
, int write
,
2614 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2619 int proc_dointvec(struct ctl_table
*table
, int write
,
2620 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2625 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2626 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2631 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2632 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2637 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2638 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2643 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2644 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2649 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2650 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2655 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2656 void __user
*buffer
,
2657 size_t *lenp
, loff_t
*ppos
)
2663 #endif /* CONFIG_PROC_FS */
2666 * No sense putting this after each symbol definition, twice,
2667 * exception granted :-)
2669 EXPORT_SYMBOL(proc_dointvec
);
2670 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2671 EXPORT_SYMBOL(proc_dointvec_minmax
);
2672 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2673 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2674 EXPORT_SYMBOL(proc_dostring
);
2675 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2676 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2677 EXPORT_SYMBOL(register_sysctl_table
);
2678 EXPORT_SYMBOL(register_sysctl_paths
);
2679 EXPORT_SYMBOL(unregister_sysctl_table
);