2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/kmemcheck.h>
31 #include <linux/init.h>
32 #include <linux/kernel.h>
33 #include <linux/kobject.h>
34 #include <linux/net.h>
35 #include <linux/sysrq.h>
36 #include <linux/highuid.h>
37 #include <linux/writeback.h>
38 #include <linux/ratelimit.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
51 #include <linux/slow-work.h>
52 #include <linux/perf_event.h>
54 #include <asm/uaccess.h>
55 #include <asm/processor.h>
59 #include <asm/stacktrace.h>
64 #if defined(CONFIG_SYSCTL)
66 /* External variables not in a header file. */
68 extern int print_fatal_signals
;
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
;
90 #ifdef CONFIG_RCU_TORTURE_TEST
91 extern int rcutorture_runnable
;
92 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
94 extern int blk_iopoll_enabled
;
97 /* Constants used for minimum and maximum */
98 #ifdef CONFIG_DETECT_SOFTLOCKUP
99 static int sixty
= 60;
100 static int neg_one
= -1;
104 static int __maybe_unused one
= 1;
105 static int __maybe_unused two
= 2;
106 static unsigned long one_ul
= 1;
107 static int one_hundred
= 100;
109 static int ten_thousand
= 10000;
112 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
113 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
115 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
116 static int maxolduid
= 65535;
117 static int minolduid
;
118 static int min_percpu_pagelist_fract
= 8;
120 static int ngroups_max
= NGROUPS_MAX
;
122 #ifdef CONFIG_MODULES
123 extern char modprobe_path
[];
124 extern int modules_disabled
;
126 #ifdef CONFIG_CHR_DEV_SG
127 extern int sg_big_buff
;
131 #include <asm/system.h>
134 #ifdef CONFIG_SPARC64
135 extern int sysctl_tsb_ratio
;
139 extern int pwrsw_enabled
;
140 extern int unaligned_enabled
;
144 #ifdef CONFIG_MATHEMU
145 extern int sysctl_ieee_emulation_warnings
;
147 extern int sysctl_userprocess_debug
;
148 extern int spin_retry
;
151 #ifdef CONFIG_BSD_PROCESS_ACCT
152 extern int acct_parm
[];
156 extern int no_unaligned_warning
;
157 extern int unaligned_dump_stack
;
160 extern struct ratelimit_state printk_ratelimit_state
;
162 #ifdef CONFIG_RT_MUTEXES
163 extern int max_lock_depth
;
166 #ifdef CONFIG_PROC_SYSCTL
167 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
168 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
169 static int proc_taint(struct ctl_table
*table
, int write
,
170 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
173 static struct ctl_table root_table
[];
174 static struct ctl_table_root sysctl_table_root
;
175 static struct ctl_table_header root_table_header
= {
177 .ctl_table
= root_table
,
178 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
179 .root
= &sysctl_table_root
,
180 .set
= &sysctl_table_root
.default_set
,
182 static struct ctl_table_root sysctl_table_root
= {
183 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
184 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
187 static struct ctl_table kern_table
[];
188 static struct ctl_table vm_table
[];
189 static struct ctl_table fs_table
[];
190 static struct ctl_table debug_table
[];
191 static struct ctl_table dev_table
[];
192 extern struct ctl_table random_table
[];
193 #ifdef CONFIG_INOTIFY_USER
194 extern struct ctl_table inotify_table
[];
197 extern struct ctl_table epoll_table
[];
200 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
201 int sysctl_legacy_va_layout
;
204 extern int prove_locking
;
205 extern int lock_stat
;
207 /* The default sysctl tables: */
209 static struct ctl_table root_table
[] = {
211 .procname
= "kernel",
228 .child
= debug_table
,
236 * NOTE: do not add new entries to this table unless you have read
237 * Documentation/sysctl/ctl_unnumbered.txt
242 #ifdef CONFIG_SCHED_DEBUG
243 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
244 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
245 static int min_wakeup_granularity_ns
; /* 0 usecs */
246 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
247 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
248 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
249 static int min_sched_shares_ratelimit
= 100000; /* 100 usec */
250 static int max_sched_shares_ratelimit
= NSEC_PER_SEC
; /* 1 second */
253 static struct ctl_table kern_table
[] = {
255 .procname
= "sched_child_runs_first",
256 .data
= &sysctl_sched_child_runs_first
,
257 .maxlen
= sizeof(unsigned int),
259 .proc_handler
= proc_dointvec
,
261 #ifdef CONFIG_SCHED_DEBUG
263 .procname
= "sched_min_granularity_ns",
264 .data
= &sysctl_sched_min_granularity
,
265 .maxlen
= sizeof(unsigned int),
267 .proc_handler
= sched_proc_update_handler
,
268 .extra1
= &min_sched_granularity_ns
,
269 .extra2
= &max_sched_granularity_ns
,
272 .procname
= "sched_latency_ns",
273 .data
= &sysctl_sched_latency
,
274 .maxlen
= sizeof(unsigned int),
276 .proc_handler
= sched_proc_update_handler
,
277 .extra1
= &min_sched_granularity_ns
,
278 .extra2
= &max_sched_granularity_ns
,
281 .procname
= "sched_wakeup_granularity_ns",
282 .data
= &sysctl_sched_wakeup_granularity
,
283 .maxlen
= sizeof(unsigned int),
285 .proc_handler
= sched_proc_update_handler
,
286 .extra1
= &min_wakeup_granularity_ns
,
287 .extra2
= &max_wakeup_granularity_ns
,
290 .procname
= "sched_shares_ratelimit",
291 .data
= &sysctl_sched_shares_ratelimit
,
292 .maxlen
= sizeof(unsigned int),
294 .proc_handler
= sched_proc_update_handler
,
295 .extra1
= &min_sched_shares_ratelimit
,
296 .extra2
= &max_sched_shares_ratelimit
,
299 .procname
= "sched_tunable_scaling",
300 .data
= &sysctl_sched_tunable_scaling
,
301 .maxlen
= sizeof(enum sched_tunable_scaling
),
303 .proc_handler
= sched_proc_update_handler
,
304 .extra1
= &min_sched_tunable_scaling
,
305 .extra2
= &max_sched_tunable_scaling
,
308 .procname
= "sched_shares_thresh",
309 .data
= &sysctl_sched_shares_thresh
,
310 .maxlen
= sizeof(unsigned int),
312 .proc_handler
= proc_dointvec_minmax
,
316 .procname
= "sched_migration_cost",
317 .data
= &sysctl_sched_migration_cost
,
318 .maxlen
= sizeof(unsigned int),
320 .proc_handler
= proc_dointvec
,
323 .procname
= "sched_nr_migrate",
324 .data
= &sysctl_sched_nr_migrate
,
325 .maxlen
= sizeof(unsigned int),
327 .proc_handler
= proc_dointvec
,
330 .procname
= "sched_time_avg",
331 .data
= &sysctl_sched_time_avg
,
332 .maxlen
= sizeof(unsigned int),
334 .proc_handler
= proc_dointvec
,
337 .procname
= "timer_migration",
338 .data
= &sysctl_timer_migration
,
339 .maxlen
= sizeof(unsigned int),
341 .proc_handler
= proc_dointvec_minmax
,
347 .procname
= "sched_rt_period_us",
348 .data
= &sysctl_sched_rt_period
,
349 .maxlen
= sizeof(unsigned int),
351 .proc_handler
= sched_rt_handler
,
354 .procname
= "sched_rt_runtime_us",
355 .data
= &sysctl_sched_rt_runtime
,
356 .maxlen
= sizeof(int),
358 .proc_handler
= sched_rt_handler
,
361 .procname
= "sched_compat_yield",
362 .data
= &sysctl_sched_compat_yield
,
363 .maxlen
= sizeof(unsigned int),
365 .proc_handler
= proc_dointvec
,
367 #ifdef CONFIG_PROVE_LOCKING
369 .procname
= "prove_locking",
370 .data
= &prove_locking
,
371 .maxlen
= sizeof(int),
373 .proc_handler
= proc_dointvec
,
376 #ifdef CONFIG_LOCK_STAT
378 .procname
= "lock_stat",
380 .maxlen
= sizeof(int),
382 .proc_handler
= proc_dointvec
,
387 .data
= &panic_timeout
,
388 .maxlen
= sizeof(int),
390 .proc_handler
= proc_dointvec
,
393 .procname
= "core_uses_pid",
394 .data
= &core_uses_pid
,
395 .maxlen
= sizeof(int),
397 .proc_handler
= proc_dointvec
,
400 .procname
= "core_pattern",
401 .data
= core_pattern
,
402 .maxlen
= CORENAME_MAX_SIZE
,
404 .proc_handler
= proc_dostring
,
407 .procname
= "core_pipe_limit",
408 .data
= &core_pipe_limit
,
409 .maxlen
= sizeof(unsigned int),
411 .proc_handler
= proc_dointvec
,
413 #ifdef CONFIG_PROC_SYSCTL
415 .procname
= "tainted",
416 .maxlen
= sizeof(long),
418 .proc_handler
= proc_taint
,
421 #ifdef CONFIG_LATENCYTOP
423 .procname
= "latencytop",
424 .data
= &latencytop_enabled
,
425 .maxlen
= sizeof(int),
427 .proc_handler
= proc_dointvec
,
430 #ifdef CONFIG_BLK_DEV_INITRD
432 .procname
= "real-root-dev",
433 .data
= &real_root_dev
,
434 .maxlen
= sizeof(int),
436 .proc_handler
= proc_dointvec
,
440 .procname
= "print-fatal-signals",
441 .data
= &print_fatal_signals
,
442 .maxlen
= sizeof(int),
444 .proc_handler
= proc_dointvec
,
448 .procname
= "reboot-cmd",
449 .data
= reboot_command
,
452 .proc_handler
= proc_dostring
,
455 .procname
= "stop-a",
456 .data
= &stop_a_enabled
,
457 .maxlen
= sizeof (int),
459 .proc_handler
= proc_dointvec
,
462 .procname
= "scons-poweroff",
463 .data
= &scons_pwroff
,
464 .maxlen
= sizeof (int),
466 .proc_handler
= proc_dointvec
,
469 #ifdef CONFIG_SPARC64
471 .procname
= "tsb-ratio",
472 .data
= &sysctl_tsb_ratio
,
473 .maxlen
= sizeof (int),
475 .proc_handler
= proc_dointvec
,
480 .procname
= "soft-power",
481 .data
= &pwrsw_enabled
,
482 .maxlen
= sizeof (int),
484 .proc_handler
= proc_dointvec
,
487 .procname
= "unaligned-trap",
488 .data
= &unaligned_enabled
,
489 .maxlen
= sizeof (int),
491 .proc_handler
= proc_dointvec
,
495 .procname
= "ctrl-alt-del",
497 .maxlen
= sizeof(int),
499 .proc_handler
= proc_dointvec
,
501 #ifdef CONFIG_FUNCTION_TRACER
503 .procname
= "ftrace_enabled",
504 .data
= &ftrace_enabled
,
505 .maxlen
= sizeof(int),
507 .proc_handler
= ftrace_enable_sysctl
,
510 #ifdef CONFIG_STACK_TRACER
512 .procname
= "stack_tracer_enabled",
513 .data
= &stack_tracer_enabled
,
514 .maxlen
= sizeof(int),
516 .proc_handler
= stack_trace_sysctl
,
519 #ifdef CONFIG_TRACING
521 .procname
= "ftrace_dump_on_oops",
522 .data
= &ftrace_dump_on_oops
,
523 .maxlen
= sizeof(int),
525 .proc_handler
= proc_dointvec
,
528 #ifdef CONFIG_MODULES
530 .procname
= "modprobe",
531 .data
= &modprobe_path
,
532 .maxlen
= KMOD_PATH_LEN
,
534 .proc_handler
= proc_dostring
,
537 .procname
= "modules_disabled",
538 .data
= &modules_disabled
,
539 .maxlen
= sizeof(int),
541 /* only handle a transition from default "0" to "1" */
542 .proc_handler
= proc_dointvec_minmax
,
547 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
549 .procname
= "hotplug",
550 .data
= &uevent_helper
,
551 .maxlen
= UEVENT_HELPER_PATH_LEN
,
553 .proc_handler
= proc_dostring
,
556 #ifdef CONFIG_CHR_DEV_SG
558 .procname
= "sg-big-buff",
559 .data
= &sg_big_buff
,
560 .maxlen
= sizeof (int),
562 .proc_handler
= proc_dointvec
,
565 #ifdef CONFIG_BSD_PROCESS_ACCT
569 .maxlen
= 3*sizeof(int),
571 .proc_handler
= proc_dointvec
,
574 #ifdef CONFIG_MAGIC_SYSRQ
577 .data
= &__sysrq_enabled
,
578 .maxlen
= sizeof (int),
580 .proc_handler
= proc_dointvec
,
583 #ifdef CONFIG_PROC_SYSCTL
585 .procname
= "cad_pid",
587 .maxlen
= sizeof (int),
589 .proc_handler
= proc_do_cad_pid
,
593 .procname
= "threads-max",
594 .data
= &max_threads
,
595 .maxlen
= sizeof(int),
597 .proc_handler
= proc_dointvec
,
600 .procname
= "random",
602 .child
= random_table
,
605 .procname
= "overflowuid",
606 .data
= &overflowuid
,
607 .maxlen
= sizeof(int),
609 .proc_handler
= proc_dointvec_minmax
,
610 .extra1
= &minolduid
,
611 .extra2
= &maxolduid
,
614 .procname
= "overflowgid",
615 .data
= &overflowgid
,
616 .maxlen
= sizeof(int),
618 .proc_handler
= proc_dointvec_minmax
,
619 .extra1
= &minolduid
,
620 .extra2
= &maxolduid
,
623 #ifdef CONFIG_MATHEMU
625 .procname
= "ieee_emulation_warnings",
626 .data
= &sysctl_ieee_emulation_warnings
,
627 .maxlen
= sizeof(int),
629 .proc_handler
= proc_dointvec
,
633 .procname
= "userprocess_debug",
634 .data
= &sysctl_userprocess_debug
,
635 .maxlen
= sizeof(int),
637 .proc_handler
= proc_dointvec
,
641 .procname
= "pid_max",
643 .maxlen
= sizeof (int),
645 .proc_handler
= proc_dointvec_minmax
,
646 .extra1
= &pid_max_min
,
647 .extra2
= &pid_max_max
,
650 .procname
= "panic_on_oops",
651 .data
= &panic_on_oops
,
652 .maxlen
= sizeof(int),
654 .proc_handler
= proc_dointvec
,
656 #if defined CONFIG_PRINTK
658 .procname
= "printk",
659 .data
= &console_loglevel
,
660 .maxlen
= 4*sizeof(int),
662 .proc_handler
= proc_dointvec
,
665 .procname
= "printk_ratelimit",
666 .data
= &printk_ratelimit_state
.interval
,
667 .maxlen
= sizeof(int),
669 .proc_handler
= proc_dointvec_jiffies
,
672 .procname
= "printk_ratelimit_burst",
673 .data
= &printk_ratelimit_state
.burst
,
674 .maxlen
= sizeof(int),
676 .proc_handler
= proc_dointvec
,
679 .procname
= "printk_delay",
680 .data
= &printk_delay_msec
,
681 .maxlen
= sizeof(int),
683 .proc_handler
= proc_dointvec_minmax
,
685 .extra2
= &ten_thousand
,
689 .procname
= "ngroups_max",
690 .data
= &ngroups_max
,
691 .maxlen
= sizeof (int),
693 .proc_handler
= proc_dointvec
,
695 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
697 .procname
= "unknown_nmi_panic",
698 .data
= &unknown_nmi_panic
,
699 .maxlen
= sizeof (int),
701 .proc_handler
= proc_dointvec
,
704 .procname
= "nmi_watchdog",
705 .data
= &nmi_watchdog_enabled
,
706 .maxlen
= sizeof (int),
708 .proc_handler
= proc_nmi_enabled
,
711 #if defined(CONFIG_X86)
713 .procname
= "panic_on_unrecovered_nmi",
714 .data
= &panic_on_unrecovered_nmi
,
715 .maxlen
= sizeof(int),
717 .proc_handler
= proc_dointvec
,
720 .procname
= "panic_on_io_nmi",
721 .data
= &panic_on_io_nmi
,
722 .maxlen
= sizeof(int),
724 .proc_handler
= proc_dointvec
,
727 .procname
= "bootloader_type",
728 .data
= &bootloader_type
,
729 .maxlen
= sizeof (int),
731 .proc_handler
= proc_dointvec
,
734 .procname
= "bootloader_version",
735 .data
= &bootloader_version
,
736 .maxlen
= sizeof (int),
738 .proc_handler
= proc_dointvec
,
741 .procname
= "kstack_depth_to_print",
742 .data
= &kstack_depth_to_print
,
743 .maxlen
= sizeof(int),
745 .proc_handler
= proc_dointvec
,
748 .procname
= "io_delay_type",
749 .data
= &io_delay_type
,
750 .maxlen
= sizeof(int),
752 .proc_handler
= proc_dointvec
,
755 #if defined(CONFIG_MMU)
757 .procname
= "randomize_va_space",
758 .data
= &randomize_va_space
,
759 .maxlen
= sizeof(int),
761 .proc_handler
= proc_dointvec
,
764 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
766 .procname
= "spin_retry",
768 .maxlen
= sizeof (int),
770 .proc_handler
= proc_dointvec
,
773 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
775 .procname
= "acpi_video_flags",
776 .data
= &acpi_realmode_flags
,
777 .maxlen
= sizeof (unsigned long),
779 .proc_handler
= proc_doulongvec_minmax
,
784 .procname
= "ignore-unaligned-usertrap",
785 .data
= &no_unaligned_warning
,
786 .maxlen
= sizeof (int),
788 .proc_handler
= proc_dointvec
,
791 .procname
= "unaligned-dump-stack",
792 .data
= &unaligned_dump_stack
,
793 .maxlen
= sizeof (int),
795 .proc_handler
= proc_dointvec
,
798 #ifdef CONFIG_DETECT_SOFTLOCKUP
800 .procname
= "softlockup_panic",
801 .data
= &softlockup_panic
,
802 .maxlen
= sizeof(int),
804 .proc_handler
= proc_dointvec_minmax
,
809 .procname
= "softlockup_thresh",
810 .data
= &softlockup_thresh
,
811 .maxlen
= sizeof(int),
813 .proc_handler
= proc_dosoftlockup_thresh
,
818 #ifdef CONFIG_DETECT_HUNG_TASK
820 .procname
= "hung_task_panic",
821 .data
= &sysctl_hung_task_panic
,
822 .maxlen
= sizeof(int),
824 .proc_handler
= proc_dointvec_minmax
,
829 .procname
= "hung_task_check_count",
830 .data
= &sysctl_hung_task_check_count
,
831 .maxlen
= sizeof(unsigned long),
833 .proc_handler
= proc_doulongvec_minmax
,
836 .procname
= "hung_task_timeout_secs",
837 .data
= &sysctl_hung_task_timeout_secs
,
838 .maxlen
= sizeof(unsigned long),
840 .proc_handler
= proc_dohung_task_timeout_secs
,
843 .procname
= "hung_task_warnings",
844 .data
= &sysctl_hung_task_warnings
,
845 .maxlen
= sizeof(unsigned long),
847 .proc_handler
= proc_doulongvec_minmax
,
852 .procname
= "compat-log",
854 .maxlen
= sizeof (int),
856 .proc_handler
= proc_dointvec
,
859 #ifdef CONFIG_RT_MUTEXES
861 .procname
= "max_lock_depth",
862 .data
= &max_lock_depth
,
863 .maxlen
= sizeof(int),
865 .proc_handler
= proc_dointvec
,
869 .procname
= "poweroff_cmd",
870 .data
= &poweroff_cmd
,
871 .maxlen
= POWEROFF_CMD_PATH_LEN
,
873 .proc_handler
= proc_dostring
,
879 .child
= key_sysctls
,
882 #ifdef CONFIG_RCU_TORTURE_TEST
884 .procname
= "rcutorture_runnable",
885 .data
= &rcutorture_runnable
,
886 .maxlen
= sizeof(int),
888 .proc_handler
= proc_dointvec
,
891 #ifdef CONFIG_SLOW_WORK
893 .procname
= "slow-work",
895 .child
= slow_work_sysctls
,
898 #ifdef CONFIG_PERF_EVENTS
900 .procname
= "perf_event_paranoid",
901 .data
= &sysctl_perf_event_paranoid
,
902 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
904 .proc_handler
= proc_dointvec
,
907 .procname
= "perf_event_mlock_kb",
908 .data
= &sysctl_perf_event_mlock
,
909 .maxlen
= sizeof(sysctl_perf_event_mlock
),
911 .proc_handler
= proc_dointvec
,
914 .procname
= "perf_event_max_sample_rate",
915 .data
= &sysctl_perf_event_sample_rate
,
916 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
918 .proc_handler
= proc_dointvec
,
921 #ifdef CONFIG_KMEMCHECK
923 .procname
= "kmemcheck",
924 .data
= &kmemcheck_enabled
,
925 .maxlen
= sizeof(int),
927 .proc_handler
= proc_dointvec
,
932 .procname
= "blk_iopoll",
933 .data
= &blk_iopoll_enabled
,
934 .maxlen
= sizeof(int),
936 .proc_handler
= proc_dointvec
,
940 * NOTE: do not add new entries to this table unless you have read
941 * Documentation/sysctl/ctl_unnumbered.txt
946 static struct ctl_table vm_table
[] = {
948 .procname
= "overcommit_memory",
949 .data
= &sysctl_overcommit_memory
,
950 .maxlen
= sizeof(sysctl_overcommit_memory
),
952 .proc_handler
= proc_dointvec
,
955 .procname
= "panic_on_oom",
956 .data
= &sysctl_panic_on_oom
,
957 .maxlen
= sizeof(sysctl_panic_on_oom
),
959 .proc_handler
= proc_dointvec
,
962 .procname
= "oom_kill_allocating_task",
963 .data
= &sysctl_oom_kill_allocating_task
,
964 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
966 .proc_handler
= proc_dointvec
,
969 .procname
= "oom_dump_tasks",
970 .data
= &sysctl_oom_dump_tasks
,
971 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
973 .proc_handler
= proc_dointvec
,
976 .procname
= "overcommit_ratio",
977 .data
= &sysctl_overcommit_ratio
,
978 .maxlen
= sizeof(sysctl_overcommit_ratio
),
980 .proc_handler
= proc_dointvec
,
983 .procname
= "page-cluster",
984 .data
= &page_cluster
,
985 .maxlen
= sizeof(int),
987 .proc_handler
= proc_dointvec
,
990 .procname
= "dirty_background_ratio",
991 .data
= &dirty_background_ratio
,
992 .maxlen
= sizeof(dirty_background_ratio
),
994 .proc_handler
= dirty_background_ratio_handler
,
996 .extra2
= &one_hundred
,
999 .procname
= "dirty_background_bytes",
1000 .data
= &dirty_background_bytes
,
1001 .maxlen
= sizeof(dirty_background_bytes
),
1003 .proc_handler
= dirty_background_bytes_handler
,
1007 .procname
= "dirty_ratio",
1008 .data
= &vm_dirty_ratio
,
1009 .maxlen
= sizeof(vm_dirty_ratio
),
1011 .proc_handler
= dirty_ratio_handler
,
1013 .extra2
= &one_hundred
,
1016 .procname
= "dirty_bytes",
1017 .data
= &vm_dirty_bytes
,
1018 .maxlen
= sizeof(vm_dirty_bytes
),
1020 .proc_handler
= dirty_bytes_handler
,
1021 .extra1
= &dirty_bytes_min
,
1024 .procname
= "dirty_writeback_centisecs",
1025 .data
= &dirty_writeback_interval
,
1026 .maxlen
= sizeof(dirty_writeback_interval
),
1028 .proc_handler
= dirty_writeback_centisecs_handler
,
1031 .procname
= "dirty_expire_centisecs",
1032 .data
= &dirty_expire_interval
,
1033 .maxlen
= sizeof(dirty_expire_interval
),
1035 .proc_handler
= proc_dointvec
,
1038 .procname
= "nr_pdflush_threads",
1039 .data
= &nr_pdflush_threads
,
1040 .maxlen
= sizeof nr_pdflush_threads
,
1041 .mode
= 0444 /* read-only*/,
1042 .proc_handler
= proc_dointvec
,
1045 .procname
= "swappiness",
1046 .data
= &vm_swappiness
,
1047 .maxlen
= sizeof(vm_swappiness
),
1049 .proc_handler
= proc_dointvec_minmax
,
1051 .extra2
= &one_hundred
,
1053 #ifdef CONFIG_HUGETLB_PAGE
1055 .procname
= "nr_hugepages",
1057 .maxlen
= sizeof(unsigned long),
1059 .proc_handler
= hugetlb_sysctl_handler
,
1060 .extra1
= (void *)&hugetlb_zero
,
1061 .extra2
= (void *)&hugetlb_infinity
,
1065 .procname
= "nr_hugepages_mempolicy",
1067 .maxlen
= sizeof(unsigned long),
1069 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1070 .extra1
= (void *)&hugetlb_zero
,
1071 .extra2
= (void *)&hugetlb_infinity
,
1075 .procname
= "hugetlb_shm_group",
1076 .data
= &sysctl_hugetlb_shm_group
,
1077 .maxlen
= sizeof(gid_t
),
1079 .proc_handler
= proc_dointvec
,
1082 .procname
= "hugepages_treat_as_movable",
1083 .data
= &hugepages_treat_as_movable
,
1084 .maxlen
= sizeof(int),
1086 .proc_handler
= hugetlb_treat_movable_handler
,
1089 .procname
= "nr_overcommit_hugepages",
1091 .maxlen
= sizeof(unsigned long),
1093 .proc_handler
= hugetlb_overcommit_handler
,
1094 .extra1
= (void *)&hugetlb_zero
,
1095 .extra2
= (void *)&hugetlb_infinity
,
1099 .procname
= "lowmem_reserve_ratio",
1100 .data
= &sysctl_lowmem_reserve_ratio
,
1101 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1103 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1106 .procname
= "drop_caches",
1107 .data
= &sysctl_drop_caches
,
1108 .maxlen
= sizeof(int),
1110 .proc_handler
= drop_caches_sysctl_handler
,
1113 .procname
= "min_free_kbytes",
1114 .data
= &min_free_kbytes
,
1115 .maxlen
= sizeof(min_free_kbytes
),
1117 .proc_handler
= min_free_kbytes_sysctl_handler
,
1121 .procname
= "percpu_pagelist_fraction",
1122 .data
= &percpu_pagelist_fraction
,
1123 .maxlen
= sizeof(percpu_pagelist_fraction
),
1125 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1126 .extra1
= &min_percpu_pagelist_fract
,
1130 .procname
= "max_map_count",
1131 .data
= &sysctl_max_map_count
,
1132 .maxlen
= sizeof(sysctl_max_map_count
),
1134 .proc_handler
= proc_dointvec_minmax
,
1139 .procname
= "nr_trim_pages",
1140 .data
= &sysctl_nr_trim_pages
,
1141 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1143 .proc_handler
= proc_dointvec_minmax
,
1148 .procname
= "laptop_mode",
1149 .data
= &laptop_mode
,
1150 .maxlen
= sizeof(laptop_mode
),
1152 .proc_handler
= proc_dointvec_jiffies
,
1155 .procname
= "block_dump",
1156 .data
= &block_dump
,
1157 .maxlen
= sizeof(block_dump
),
1159 .proc_handler
= proc_dointvec
,
1163 .procname
= "vfs_cache_pressure",
1164 .data
= &sysctl_vfs_cache_pressure
,
1165 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1167 .proc_handler
= proc_dointvec
,
1170 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1172 .procname
= "legacy_va_layout",
1173 .data
= &sysctl_legacy_va_layout
,
1174 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1176 .proc_handler
= proc_dointvec
,
1182 .procname
= "zone_reclaim_mode",
1183 .data
= &zone_reclaim_mode
,
1184 .maxlen
= sizeof(zone_reclaim_mode
),
1186 .proc_handler
= proc_dointvec
,
1190 .procname
= "min_unmapped_ratio",
1191 .data
= &sysctl_min_unmapped_ratio
,
1192 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1194 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1196 .extra2
= &one_hundred
,
1199 .procname
= "min_slab_ratio",
1200 .data
= &sysctl_min_slab_ratio
,
1201 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1203 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1205 .extra2
= &one_hundred
,
1210 .procname
= "stat_interval",
1211 .data
= &sysctl_stat_interval
,
1212 .maxlen
= sizeof(sysctl_stat_interval
),
1214 .proc_handler
= proc_dointvec_jiffies
,
1219 .procname
= "mmap_min_addr",
1220 .data
= &dac_mmap_min_addr
,
1221 .maxlen
= sizeof(unsigned long),
1223 .proc_handler
= mmap_min_addr_handler
,
1228 .procname
= "numa_zonelist_order",
1229 .data
= &numa_zonelist_order
,
1230 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1232 .proc_handler
= numa_zonelist_order_handler
,
1235 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1236 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1238 .procname
= "vdso_enabled",
1239 .data
= &vdso_enabled
,
1240 .maxlen
= sizeof(vdso_enabled
),
1242 .proc_handler
= proc_dointvec
,
1246 #ifdef CONFIG_HIGHMEM
1248 .procname
= "highmem_is_dirtyable",
1249 .data
= &vm_highmem_is_dirtyable
,
1250 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1252 .proc_handler
= proc_dointvec_minmax
,
1258 .procname
= "scan_unevictable_pages",
1259 .data
= &scan_unevictable_pages
,
1260 .maxlen
= sizeof(scan_unevictable_pages
),
1262 .proc_handler
= scan_unevictable_handler
,
1264 #ifdef CONFIG_MEMORY_FAILURE
1266 .procname
= "memory_failure_early_kill",
1267 .data
= &sysctl_memory_failure_early_kill
,
1268 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1270 .proc_handler
= proc_dointvec_minmax
,
1275 .procname
= "memory_failure_recovery",
1276 .data
= &sysctl_memory_failure_recovery
,
1277 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1279 .proc_handler
= proc_dointvec_minmax
,
1286 * NOTE: do not add new entries to this table unless you have read
1287 * Documentation/sysctl/ctl_unnumbered.txt
1292 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1293 static struct ctl_table binfmt_misc_table
[] = {
1298 static struct ctl_table fs_table
[] = {
1300 .procname
= "inode-nr",
1301 .data
= &inodes_stat
,
1302 .maxlen
= 2*sizeof(int),
1304 .proc_handler
= proc_dointvec
,
1307 .procname
= "inode-state",
1308 .data
= &inodes_stat
,
1309 .maxlen
= 7*sizeof(int),
1311 .proc_handler
= proc_dointvec
,
1314 .procname
= "file-nr",
1315 .data
= &files_stat
,
1316 .maxlen
= 3*sizeof(int),
1318 .proc_handler
= proc_nr_files
,
1321 .procname
= "file-max",
1322 .data
= &files_stat
.max_files
,
1323 .maxlen
= sizeof(int),
1325 .proc_handler
= proc_dointvec
,
1328 .procname
= "nr_open",
1329 .data
= &sysctl_nr_open
,
1330 .maxlen
= sizeof(int),
1332 .proc_handler
= proc_dointvec_minmax
,
1333 .extra1
= &sysctl_nr_open_min
,
1334 .extra2
= &sysctl_nr_open_max
,
1337 .procname
= "dentry-state",
1338 .data
= &dentry_stat
,
1339 .maxlen
= 6*sizeof(int),
1341 .proc_handler
= proc_dointvec
,
1344 .procname
= "overflowuid",
1345 .data
= &fs_overflowuid
,
1346 .maxlen
= sizeof(int),
1348 .proc_handler
= proc_dointvec_minmax
,
1349 .extra1
= &minolduid
,
1350 .extra2
= &maxolduid
,
1353 .procname
= "overflowgid",
1354 .data
= &fs_overflowgid
,
1355 .maxlen
= sizeof(int),
1357 .proc_handler
= proc_dointvec_minmax
,
1358 .extra1
= &minolduid
,
1359 .extra2
= &maxolduid
,
1361 #ifdef CONFIG_FILE_LOCKING
1363 .procname
= "leases-enable",
1364 .data
= &leases_enable
,
1365 .maxlen
= sizeof(int),
1367 .proc_handler
= proc_dointvec
,
1370 #ifdef CONFIG_DNOTIFY
1372 .procname
= "dir-notify-enable",
1373 .data
= &dir_notify_enable
,
1374 .maxlen
= sizeof(int),
1376 .proc_handler
= proc_dointvec
,
1380 #ifdef CONFIG_FILE_LOCKING
1382 .procname
= "lease-break-time",
1383 .data
= &lease_break_time
,
1384 .maxlen
= sizeof(int),
1386 .proc_handler
= proc_dointvec
,
1391 .procname
= "aio-nr",
1393 .maxlen
= sizeof(aio_nr
),
1395 .proc_handler
= proc_doulongvec_minmax
,
1398 .procname
= "aio-max-nr",
1399 .data
= &aio_max_nr
,
1400 .maxlen
= sizeof(aio_max_nr
),
1402 .proc_handler
= proc_doulongvec_minmax
,
1404 #endif /* CONFIG_AIO */
1405 #ifdef CONFIG_INOTIFY_USER
1407 .procname
= "inotify",
1409 .child
= inotify_table
,
1414 .procname
= "epoll",
1416 .child
= epoll_table
,
1421 .procname
= "suid_dumpable",
1422 .data
= &suid_dumpable
,
1423 .maxlen
= sizeof(int),
1425 .proc_handler
= proc_dointvec_minmax
,
1429 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1431 .procname
= "binfmt_misc",
1433 .child
= binfmt_misc_table
,
1437 * NOTE: do not add new entries to this table unless you have read
1438 * Documentation/sysctl/ctl_unnumbered.txt
1443 static struct ctl_table debug_table
[] = {
1444 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1446 .procname
= "exception-trace",
1447 .data
= &show_unhandled_signals
,
1448 .maxlen
= sizeof(int),
1450 .proc_handler
= proc_dointvec
1456 static struct ctl_table dev_table
[] = {
1460 static DEFINE_SPINLOCK(sysctl_lock
);
1462 /* called under sysctl_lock */
1463 static int use_table(struct ctl_table_header
*p
)
1465 if (unlikely(p
->unregistering
))
1471 /* called under sysctl_lock */
1472 static void unuse_table(struct ctl_table_header
*p
)
1475 if (unlikely(p
->unregistering
))
1476 complete(p
->unregistering
);
1479 /* called under sysctl_lock, will reacquire if has to wait */
1480 static void start_unregistering(struct ctl_table_header
*p
)
1483 * if p->used is 0, nobody will ever touch that entry again;
1484 * we'll eliminate all paths to it before dropping sysctl_lock
1486 if (unlikely(p
->used
)) {
1487 struct completion wait
;
1488 init_completion(&wait
);
1489 p
->unregistering
= &wait
;
1490 spin_unlock(&sysctl_lock
);
1491 wait_for_completion(&wait
);
1492 spin_lock(&sysctl_lock
);
1494 /* anything non-NULL; we'll never dereference it */
1495 p
->unregistering
= ERR_PTR(-EINVAL
);
1498 * do not remove from the list until nobody holds it; walking the
1499 * list in do_sysctl() relies on that.
1501 list_del_init(&p
->ctl_entry
);
1504 void sysctl_head_get(struct ctl_table_header
*head
)
1506 spin_lock(&sysctl_lock
);
1508 spin_unlock(&sysctl_lock
);
1511 void sysctl_head_put(struct ctl_table_header
*head
)
1513 spin_lock(&sysctl_lock
);
1516 spin_unlock(&sysctl_lock
);
1519 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1523 spin_lock(&sysctl_lock
);
1524 if (!use_table(head
))
1525 head
= ERR_PTR(-ENOENT
);
1526 spin_unlock(&sysctl_lock
);
1530 void sysctl_head_finish(struct ctl_table_header
*head
)
1534 spin_lock(&sysctl_lock
);
1536 spin_unlock(&sysctl_lock
);
1539 static struct ctl_table_set
*
1540 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1542 struct ctl_table_set
*set
= &root
->default_set
;
1544 set
= root
->lookup(root
, namespaces
);
1548 static struct list_head
*
1549 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1551 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1555 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1556 struct ctl_table_header
*prev
)
1558 struct ctl_table_root
*root
;
1559 struct list_head
*header_list
;
1560 struct ctl_table_header
*head
;
1561 struct list_head
*tmp
;
1563 spin_lock(&sysctl_lock
);
1566 tmp
= &prev
->ctl_entry
;
1570 tmp
= &root_table_header
.ctl_entry
;
1572 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1574 if (!use_table(head
))
1576 spin_unlock(&sysctl_lock
);
1581 header_list
= lookup_header_list(root
, namespaces
);
1582 if (tmp
!= header_list
)
1586 root
= list_entry(root
->root_list
.next
,
1587 struct ctl_table_root
, root_list
);
1588 if (root
== &sysctl_table_root
)
1590 header_list
= lookup_header_list(root
, namespaces
);
1591 } while (list_empty(header_list
));
1592 tmp
= header_list
->next
;
1595 spin_unlock(&sysctl_lock
);
1599 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1601 return __sysctl_head_next(current
->nsproxy
, prev
);
1604 void register_sysctl_root(struct ctl_table_root
*root
)
1606 spin_lock(&sysctl_lock
);
1607 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1608 spin_unlock(&sysctl_lock
);
1612 * sysctl_perm does NOT grant the superuser all rights automatically, because
1613 * some sysctl variables are readonly even to root.
1616 static int test_perm(int mode
, int op
)
1618 if (!current_euid())
1620 else if (in_egroup_p(0))
1622 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1627 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1632 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1636 if (root
->permissions
)
1637 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1641 return test_perm(mode
, op
);
1644 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1646 for (; table
->procname
; table
++) {
1647 table
->parent
= parent
;
1649 sysctl_set_parent(table
, table
->child
);
1653 static __init
int sysctl_init(void)
1655 sysctl_set_parent(NULL
, root_table
);
1656 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1659 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1665 core_initcall(sysctl_init
);
1667 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1668 struct ctl_table
*table
)
1670 struct ctl_table
*p
;
1671 const char *s
= branch
->procname
;
1673 /* branch should have named subdirectory as its first element */
1674 if (!s
|| !branch
->child
)
1677 /* ... and nothing else */
1678 if (branch
[1].procname
)
1681 /* table should contain subdirectory with the same name */
1682 for (p
= table
; p
->procname
; p
++) {
1685 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1691 /* see if attaching q to p would be an improvement */
1692 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1694 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1695 struct ctl_table
*next
;
1697 int not_in_parent
= !p
->attached_by
;
1699 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1700 if (by
== q
->attached_by
)
1702 if (to
== p
->attached_by
)
1708 if (is_better
&& not_in_parent
) {
1709 q
->attached_by
= by
;
1710 q
->attached_to
= to
;
1716 * __register_sysctl_paths - register a sysctl hierarchy
1717 * @root: List of sysctl headers to register on
1718 * @namespaces: Data to compute which lists of sysctl entries are visible
1719 * @path: The path to the directory the sysctl table is in.
1720 * @table: the top-level table structure
1722 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1723 * array. A completely 0 filled entry terminates the table.
1725 * The members of the &struct ctl_table structure are used as follows:
1727 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1728 * enter a sysctl file
1730 * data - a pointer to data for use by proc_handler
1732 * maxlen - the maximum size in bytes of the data
1734 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1736 * child - a pointer to the child sysctl table if this entry is a directory, or
1739 * proc_handler - the text handler routine (described below)
1741 * de - for internal use by the sysctl routines
1743 * extra1, extra2 - extra pointers usable by the proc handler routines
1745 * Leaf nodes in the sysctl tree will be represented by a single file
1746 * under /proc; non-leaf nodes will be represented by directories.
1748 * sysctl(2) can automatically manage read and write requests through
1749 * the sysctl table. The data and maxlen fields of the ctl_table
1750 * struct enable minimal validation of the values being written to be
1751 * performed, and the mode field allows minimal authentication.
1753 * There must be a proc_handler routine for any terminal nodes
1754 * mirrored under /proc/sys (non-terminals are handled by a built-in
1755 * directory handler). Several default handlers are available to
1756 * cover common cases -
1758 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1759 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1760 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1762 * It is the handler's job to read the input buffer from user memory
1763 * and process it. The handler should return 0 on success.
1765 * This routine returns %NULL on a failure to register, and a pointer
1766 * to the table header on success.
1768 struct ctl_table_header
*__register_sysctl_paths(
1769 struct ctl_table_root
*root
,
1770 struct nsproxy
*namespaces
,
1771 const struct ctl_path
*path
, struct ctl_table
*table
)
1773 struct ctl_table_header
*header
;
1774 struct ctl_table
*new, **prevp
;
1775 unsigned int n
, npath
;
1776 struct ctl_table_set
*set
;
1778 /* Count the path components */
1779 for (npath
= 0; path
[npath
].procname
; ++npath
)
1783 * For each path component, allocate a 2-element ctl_table array.
1784 * The first array element will be filled with the sysctl entry
1785 * for this, the second will be the sentinel (procname == 0).
1787 * We allocate everything in one go so that we don't have to
1788 * worry about freeing additional memory in unregister_sysctl_table.
1790 header
= kzalloc(sizeof(struct ctl_table_header
) +
1791 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1795 new = (struct ctl_table
*) (header
+ 1);
1797 /* Now connect the dots */
1798 prevp
= &header
->ctl_table
;
1799 for (n
= 0; n
< npath
; ++n
, ++path
) {
1800 /* Copy the procname */
1801 new->procname
= path
->procname
;
1805 prevp
= &new->child
;
1810 header
->ctl_table_arg
= table
;
1812 INIT_LIST_HEAD(&header
->ctl_entry
);
1814 header
->unregistering
= NULL
;
1815 header
->root
= root
;
1816 sysctl_set_parent(NULL
, header
->ctl_table
);
1818 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1819 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1824 spin_lock(&sysctl_lock
);
1825 header
->set
= lookup_header_set(root
, namespaces
);
1826 header
->attached_by
= header
->ctl_table
;
1827 header
->attached_to
= root_table
;
1828 header
->parent
= &root_table_header
;
1829 for (set
= header
->set
; set
; set
= set
->parent
) {
1830 struct ctl_table_header
*p
;
1831 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1832 if (p
->unregistering
)
1834 try_attach(p
, header
);
1837 header
->parent
->count
++;
1838 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1839 spin_unlock(&sysctl_lock
);
1845 * register_sysctl_table_path - register a sysctl table hierarchy
1846 * @path: The path to the directory the sysctl table is in.
1847 * @table: the top-level table structure
1849 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1850 * array. A completely 0 filled entry terminates the table.
1852 * See __register_sysctl_paths for more details.
1854 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1855 struct ctl_table
*table
)
1857 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1862 * register_sysctl_table - register a sysctl table hierarchy
1863 * @table: the top-level table structure
1865 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1866 * array. A completely 0 filled entry terminates the table.
1868 * See register_sysctl_paths for more details.
1870 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1872 static const struct ctl_path null_path
[] = { {} };
1874 return register_sysctl_paths(null_path
, table
);
1878 * unregister_sysctl_table - unregister a sysctl table hierarchy
1879 * @header: the header returned from register_sysctl_table
1881 * Unregisters the sysctl table and all children. proc entries may not
1882 * actually be removed until they are no longer used by anyone.
1884 void unregister_sysctl_table(struct ctl_table_header
* header
)
1891 spin_lock(&sysctl_lock
);
1892 start_unregistering(header
);
1893 if (!--header
->parent
->count
) {
1895 kfree(header
->parent
);
1897 if (!--header
->count
)
1899 spin_unlock(&sysctl_lock
);
1902 int sysctl_is_seen(struct ctl_table_header
*p
)
1904 struct ctl_table_set
*set
= p
->set
;
1906 spin_lock(&sysctl_lock
);
1907 if (p
->unregistering
)
1909 else if (!set
->is_seen
)
1912 res
= set
->is_seen(set
);
1913 spin_unlock(&sysctl_lock
);
1917 void setup_sysctl_set(struct ctl_table_set
*p
,
1918 struct ctl_table_set
*parent
,
1919 int (*is_seen
)(struct ctl_table_set
*))
1921 INIT_LIST_HEAD(&p
->list
);
1922 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1923 p
->is_seen
= is_seen
;
1926 #else /* !CONFIG_SYSCTL */
1927 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1932 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1933 struct ctl_table
*table
)
1938 void unregister_sysctl_table(struct ctl_table_header
* table
)
1942 void setup_sysctl_set(struct ctl_table_set
*p
,
1943 struct ctl_table_set
*parent
,
1944 int (*is_seen
)(struct ctl_table_set
*))
1948 void sysctl_head_put(struct ctl_table_header
*head
)
1952 #endif /* CONFIG_SYSCTL */
1958 #ifdef CONFIG_PROC_SYSCTL
1960 static int _proc_do_string(void* data
, int maxlen
, int write
,
1961 void __user
*buffer
,
1962 size_t *lenp
, loff_t
*ppos
)
1968 if (!data
|| !maxlen
|| !*lenp
) {
1976 while (len
< *lenp
) {
1977 if (get_user(c
, p
++))
1979 if (c
== 0 || c
== '\n')
1985 if(copy_from_user(data
, buffer
, len
))
1987 ((char *) data
)[len
] = 0;
2005 if(copy_to_user(buffer
, data
, len
))
2008 if(put_user('\n', ((char __user
*) buffer
) + len
))
2019 * proc_dostring - read a string sysctl
2020 * @table: the sysctl table
2021 * @write: %TRUE if this is a write to the sysctl file
2022 * @buffer: the user buffer
2023 * @lenp: the size of the user buffer
2024 * @ppos: file position
2026 * Reads/writes a string from/to the user buffer. If the kernel
2027 * buffer provided is not large enough to hold the string, the
2028 * string is truncated. The copied string is %NULL-terminated.
2029 * If the string is being read by the user process, it is copied
2030 * and a newline '\n' is added. It is truncated if the buffer is
2033 * Returns 0 on success.
2035 int proc_dostring(struct ctl_table
*table
, int write
,
2036 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2038 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2039 buffer
, lenp
, ppos
);
2043 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2045 int write
, void *data
)
2048 *valp
= *negp
? -*lvalp
: *lvalp
;
2053 *lvalp
= (unsigned long)-val
;
2056 *lvalp
= (unsigned long)val
;
2062 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2063 int write
, void __user
*buffer
,
2064 size_t *lenp
, loff_t
*ppos
,
2065 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2066 int write
, void *data
),
2069 #define TMPBUFLEN 21
2070 int *i
, vleft
, first
= 1, neg
;
2074 char buf
[TMPBUFLEN
], *p
;
2075 char __user
*s
= buffer
;
2077 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2078 (*ppos
&& !write
)) {
2083 i
= (int *) tbl_data
;
2084 vleft
= table
->maxlen
/ sizeof(*i
);
2088 conv
= do_proc_dointvec_conv
;
2090 for (; left
&& vleft
--; i
++, first
=0) {
2105 if (len
> sizeof(buf
) - 1)
2106 len
= sizeof(buf
) - 1;
2107 if (copy_from_user(buf
, s
, len
))
2111 if (*p
== '-' && left
> 1) {
2115 if (*p
< '0' || *p
> '9')
2118 lval
= simple_strtoul(p
, &p
, 0);
2121 if ((len
< left
) && *p
&& !isspace(*p
))
2126 if (conv(&neg
, &lval
, i
, 1, data
))
2133 if (conv(&neg
, &lval
, i
, 0, data
))
2136 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2140 if(copy_to_user(s
, buf
, len
))
2147 if (!write
&& !first
&& left
) {
2148 if(put_user('\n', s
))
2155 if (get_user(c
, s
++))
2170 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2171 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2172 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2173 int write
, void *data
),
2176 return __do_proc_dointvec(table
->data
, table
, write
,
2177 buffer
, lenp
, ppos
, conv
, data
);
2181 * proc_dointvec - read a vector of integers
2182 * @table: the sysctl table
2183 * @write: %TRUE if this is a write to the sysctl file
2184 * @buffer: the user buffer
2185 * @lenp: the size of the user buffer
2186 * @ppos: file position
2188 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2189 * values from/to the user buffer, treated as an ASCII string.
2191 * Returns 0 on success.
2193 int proc_dointvec(struct ctl_table
*table
, int write
,
2194 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2196 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2201 * Taint values can only be increased
2202 * This means we can safely use a temporary.
2204 static int proc_taint(struct ctl_table
*table
, int write
,
2205 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2208 unsigned long tmptaint
= get_taint();
2211 if (write
&& !capable(CAP_SYS_ADMIN
))
2216 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2222 * Poor man's atomic or. Not worth adding a primitive
2223 * to everyone's atomic.h for this
2226 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2227 if ((tmptaint
>> i
) & 1)
2235 struct do_proc_dointvec_minmax_conv_param
{
2240 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2242 int write
, void *data
)
2244 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2246 int val
= *negp
? -*lvalp
: *lvalp
;
2247 if ((param
->min
&& *param
->min
> val
) ||
2248 (param
->max
&& *param
->max
< val
))
2255 *lvalp
= (unsigned long)-val
;
2258 *lvalp
= (unsigned long)val
;
2265 * proc_dointvec_minmax - read a vector of integers with min/max values
2266 * @table: the sysctl table
2267 * @write: %TRUE if this is a write to the sysctl file
2268 * @buffer: the user buffer
2269 * @lenp: the size of the user buffer
2270 * @ppos: file position
2272 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2273 * values from/to the user buffer, treated as an ASCII string.
2275 * This routine will ensure the values are within the range specified by
2276 * table->extra1 (min) and table->extra2 (max).
2278 * Returns 0 on success.
2280 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2281 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2283 struct do_proc_dointvec_minmax_conv_param param
= {
2284 .min
= (int *) table
->extra1
,
2285 .max
= (int *) table
->extra2
,
2287 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2288 do_proc_dointvec_minmax_conv
, ¶m
);
2291 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2292 void __user
*buffer
,
2293 size_t *lenp
, loff_t
*ppos
,
2294 unsigned long convmul
,
2295 unsigned long convdiv
)
2297 #define TMPBUFLEN 21
2298 unsigned long *i
, *min
, *max
, val
;
2299 int vleft
, first
=1, neg
;
2301 char buf
[TMPBUFLEN
], *p
;
2302 char __user
*s
= buffer
;
2304 if (!data
|| !table
->maxlen
|| !*lenp
||
2305 (*ppos
&& !write
)) {
2310 i
= (unsigned long *) data
;
2311 min
= (unsigned long *) table
->extra1
;
2312 max
= (unsigned long *) table
->extra2
;
2313 vleft
= table
->maxlen
/ sizeof(unsigned long);
2316 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2331 if (len
> TMPBUFLEN
-1)
2333 if (copy_from_user(buf
, s
, len
))
2337 if (*p
== '-' && left
> 1) {
2341 if (*p
< '0' || *p
> '9')
2343 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2345 if ((len
< left
) && *p
&& !isspace(*p
))
2354 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2361 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2365 if(copy_to_user(s
, buf
, len
))
2372 if (!write
&& !first
&& left
) {
2373 if(put_user('\n', s
))
2380 if (get_user(c
, s
++))
2395 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2396 void __user
*buffer
,
2397 size_t *lenp
, loff_t
*ppos
,
2398 unsigned long convmul
,
2399 unsigned long convdiv
)
2401 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2402 buffer
, lenp
, ppos
, convmul
, convdiv
);
2406 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2407 * @table: the sysctl table
2408 * @write: %TRUE if this is a write to the sysctl file
2409 * @buffer: the user buffer
2410 * @lenp: the size of the user buffer
2411 * @ppos: file position
2413 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2414 * values from/to the user buffer, treated as an ASCII string.
2416 * This routine will ensure the values are within the range specified by
2417 * table->extra1 (min) and table->extra2 (max).
2419 * Returns 0 on success.
2421 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2422 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2424 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2428 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2429 * @table: the sysctl table
2430 * @write: %TRUE if this is a write to the sysctl file
2431 * @buffer: the user buffer
2432 * @lenp: the size of the user buffer
2433 * @ppos: file position
2435 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2436 * values from/to the user buffer, treated as an ASCII string. The values
2437 * are treated as milliseconds, and converted to jiffies when they are stored.
2439 * This routine will ensure the values are within the range specified by
2440 * table->extra1 (min) and table->extra2 (max).
2442 * Returns 0 on success.
2444 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2445 void __user
*buffer
,
2446 size_t *lenp
, loff_t
*ppos
)
2448 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2449 lenp
, ppos
, HZ
, 1000l);
2453 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2455 int write
, void *data
)
2458 if (*lvalp
> LONG_MAX
/ HZ
)
2460 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2466 lval
= (unsigned long)-val
;
2469 lval
= (unsigned long)val
;
2476 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2478 int write
, void *data
)
2481 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2483 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2489 lval
= (unsigned long)-val
;
2492 lval
= (unsigned long)val
;
2494 *lvalp
= jiffies_to_clock_t(lval
);
2499 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2501 int write
, void *data
)
2504 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2510 lval
= (unsigned long)-val
;
2513 lval
= (unsigned long)val
;
2515 *lvalp
= jiffies_to_msecs(lval
);
2521 * proc_dointvec_jiffies - read a vector of integers as seconds
2522 * @table: the sysctl table
2523 * @write: %TRUE if this is a write to the sysctl file
2524 * @buffer: the user buffer
2525 * @lenp: the size of the user buffer
2526 * @ppos: file position
2528 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2529 * values from/to the user buffer, treated as an ASCII string.
2530 * The values read are assumed to be in seconds, and are converted into
2533 * Returns 0 on success.
2535 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2536 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2538 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2539 do_proc_dointvec_jiffies_conv
,NULL
);
2543 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2544 * @table: the sysctl table
2545 * @write: %TRUE if this is a write to the sysctl file
2546 * @buffer: the user buffer
2547 * @lenp: the size of the user buffer
2548 * @ppos: pointer to the file position
2550 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2551 * values from/to the user buffer, treated as an ASCII string.
2552 * The values read are assumed to be in 1/USER_HZ seconds, and
2553 * are converted into jiffies.
2555 * Returns 0 on success.
2557 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2558 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2560 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2561 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2565 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2566 * @table: the sysctl table
2567 * @write: %TRUE if this is a write to the sysctl file
2568 * @buffer: the user buffer
2569 * @lenp: the size of the user buffer
2570 * @ppos: file position
2571 * @ppos: the current position in the file
2573 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2574 * values from/to the user buffer, treated as an ASCII string.
2575 * The values read are assumed to be in 1/1000 seconds, and
2576 * are converted into jiffies.
2578 * Returns 0 on success.
2580 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2581 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2583 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2584 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2587 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2588 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2590 struct pid
*new_pid
;
2594 tmp
= pid_vnr(cad_pid
);
2596 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2597 lenp
, ppos
, NULL
, NULL
);
2601 new_pid
= find_get_pid(tmp
);
2605 put_pid(xchg(&cad_pid
, new_pid
));
2609 #else /* CONFIG_PROC_FS */
2611 int proc_dostring(struct ctl_table
*table
, int write
,
2612 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2617 int proc_dointvec(struct ctl_table
*table
, int write
,
2618 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2623 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2624 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2629 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2630 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2635 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2636 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2641 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2642 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2647 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2648 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2653 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2654 void __user
*buffer
,
2655 size_t *lenp
, loff_t
*ppos
)
2661 #endif /* CONFIG_PROC_FS */
2664 * No sense putting this after each symbol definition, twice,
2665 * exception granted :-)
2667 EXPORT_SYMBOL(proc_dointvec
);
2668 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2669 EXPORT_SYMBOL(proc_dointvec_minmax
);
2670 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2671 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2672 EXPORT_SYMBOL(proc_dostring
);
2673 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2674 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2675 EXPORT_SYMBOL(register_sysctl_table
);
2676 EXPORT_SYMBOL(register_sysctl_paths
);
2677 EXPORT_SYMBOL(unregister_sysctl_table
);