2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/signal.h>
27 #include <linux/proc_fs.h>
28 #include <linux/security.h>
29 #include <linux/ctype.h>
30 #include <linux/kmemcheck.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/ratelimit.h>
40 #include <linux/hugetlb.h>
41 #include <linux/initrd.h>
42 #include <linux/key.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/vmstat.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/acpi.h>
50 #include <linux/reboot.h>
51 #include <linux/ftrace.h>
52 #include <linux/slow-work.h>
53 #include <linux/perf_event.h>
54 #include <linux/kprobes.h>
56 #include <asm/uaccess.h>
57 #include <asm/processor.h>
61 #include <asm/stacktrace.h>
66 #if defined(CONFIG_SYSCTL)
68 /* External variables not in a header file. */
69 extern int sysctl_overcommit_memory
;
70 extern int sysctl_overcommit_ratio
;
71 extern int sysctl_panic_on_oom
;
72 extern int sysctl_oom_kill_allocating_task
;
73 extern int sysctl_oom_dump_tasks
;
74 extern int max_threads
;
75 extern int core_uses_pid
;
76 extern int suid_dumpable
;
77 extern char core_pattern
[];
78 extern unsigned int core_pipe_limit
;
80 extern int min_free_kbytes
;
81 extern int pid_max_min
, pid_max_max
;
82 extern int sysctl_drop_caches
;
83 extern int percpu_pagelist_fraction
;
84 extern int compat_log
;
85 extern int latencytop_enabled
;
86 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
88 extern int sysctl_nr_trim_pages
;
91 extern int blk_iopoll_enabled
;
94 /* Constants used for minimum and maximum */
95 #ifdef CONFIG_DETECT_SOFTLOCKUP
96 static int sixty
= 60;
97 static int neg_one
= -1;
101 static int __maybe_unused one
= 1;
102 static int __maybe_unused two
= 2;
103 static unsigned long one_ul
= 1;
104 static int one_hundred
= 100;
106 static int ten_thousand
= 10000;
109 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
110 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
112 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
113 static int maxolduid
= 65535;
114 static int minolduid
;
115 static int min_percpu_pagelist_fract
= 8;
117 static int ngroups_max
= NGROUPS_MAX
;
119 #ifdef CONFIG_MODULES
120 extern char modprobe_path
[];
121 extern int modules_disabled
;
123 #ifdef CONFIG_CHR_DEV_SG
124 extern int sg_big_buff
;
128 #include <asm/system.h>
131 #ifdef CONFIG_SPARC64
132 extern int sysctl_tsb_ratio
;
136 extern int pwrsw_enabled
;
137 extern int unaligned_enabled
;
141 #ifdef CONFIG_MATHEMU
142 extern int sysctl_ieee_emulation_warnings
;
144 extern int sysctl_userprocess_debug
;
145 extern int spin_retry
;
148 #ifdef CONFIG_BSD_PROCESS_ACCT
149 extern int acct_parm
[];
153 extern int no_unaligned_warning
;
154 extern int unaligned_dump_stack
;
157 extern struct ratelimit_state printk_ratelimit_state
;
159 #ifdef CONFIG_RT_MUTEXES
160 extern int max_lock_depth
;
163 #ifdef CONFIG_PROC_SYSCTL
164 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
165 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
166 static int proc_taint(struct ctl_table
*table
, int write
,
167 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
170 static struct ctl_table root_table
[];
171 static struct ctl_table_root sysctl_table_root
;
172 static struct ctl_table_header root_table_header
= {
174 .ctl_table
= root_table
,
175 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
176 .root
= &sysctl_table_root
,
177 .set
= &sysctl_table_root
.default_set
,
179 static struct ctl_table_root sysctl_table_root
= {
180 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
181 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
184 static struct ctl_table kern_table
[];
185 static struct ctl_table vm_table
[];
186 static struct ctl_table fs_table
[];
187 static struct ctl_table debug_table
[];
188 static struct ctl_table dev_table
[];
189 extern struct ctl_table random_table
[];
190 #ifdef CONFIG_INOTIFY_USER
191 extern struct ctl_table inotify_table
[];
194 extern struct ctl_table epoll_table
[];
197 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
198 int sysctl_legacy_va_layout
;
201 extern int prove_locking
;
202 extern int lock_stat
;
204 /* The default sysctl tables: */
206 static struct ctl_table root_table
[] = {
208 .procname
= "kernel",
225 .child
= debug_table
,
233 * NOTE: do not add new entries to this table unless you have read
234 * Documentation/sysctl/ctl_unnumbered.txt
239 #ifdef CONFIG_SCHED_DEBUG
240 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
241 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
242 static int min_wakeup_granularity_ns
; /* 0 usecs */
243 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
244 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
245 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
246 static int min_sched_shares_ratelimit
= 100000; /* 100 usec */
247 static int max_sched_shares_ratelimit
= NSEC_PER_SEC
; /* 1 second */
250 static struct ctl_table kern_table
[] = {
252 .procname
= "sched_child_runs_first",
253 .data
= &sysctl_sched_child_runs_first
,
254 .maxlen
= sizeof(unsigned int),
256 .proc_handler
= proc_dointvec
,
258 #ifdef CONFIG_SCHED_DEBUG
260 .procname
= "sched_min_granularity_ns",
261 .data
= &sysctl_sched_min_granularity
,
262 .maxlen
= sizeof(unsigned int),
264 .proc_handler
= sched_proc_update_handler
,
265 .extra1
= &min_sched_granularity_ns
,
266 .extra2
= &max_sched_granularity_ns
,
269 .procname
= "sched_latency_ns",
270 .data
= &sysctl_sched_latency
,
271 .maxlen
= sizeof(unsigned int),
273 .proc_handler
= sched_proc_update_handler
,
274 .extra1
= &min_sched_granularity_ns
,
275 .extra2
= &max_sched_granularity_ns
,
278 .procname
= "sched_wakeup_granularity_ns",
279 .data
= &sysctl_sched_wakeup_granularity
,
280 .maxlen
= sizeof(unsigned int),
282 .proc_handler
= sched_proc_update_handler
,
283 .extra1
= &min_wakeup_granularity_ns
,
284 .extra2
= &max_wakeup_granularity_ns
,
287 .procname
= "sched_shares_ratelimit",
288 .data
= &sysctl_sched_shares_ratelimit
,
289 .maxlen
= sizeof(unsigned int),
291 .proc_handler
= sched_proc_update_handler
,
292 .extra1
= &min_sched_shares_ratelimit
,
293 .extra2
= &max_sched_shares_ratelimit
,
296 .procname
= "sched_tunable_scaling",
297 .data
= &sysctl_sched_tunable_scaling
,
298 .maxlen
= sizeof(enum sched_tunable_scaling
),
300 .proc_handler
= sched_proc_update_handler
,
301 .extra1
= &min_sched_tunable_scaling
,
302 .extra2
= &max_sched_tunable_scaling
,
305 .procname
= "sched_shares_thresh",
306 .data
= &sysctl_sched_shares_thresh
,
307 .maxlen
= sizeof(unsigned int),
309 .proc_handler
= proc_dointvec_minmax
,
313 .procname
= "sched_migration_cost",
314 .data
= &sysctl_sched_migration_cost
,
315 .maxlen
= sizeof(unsigned int),
317 .proc_handler
= proc_dointvec
,
320 .procname
= "sched_nr_migrate",
321 .data
= &sysctl_sched_nr_migrate
,
322 .maxlen
= sizeof(unsigned int),
324 .proc_handler
= proc_dointvec
,
327 .procname
= "sched_time_avg",
328 .data
= &sysctl_sched_time_avg
,
329 .maxlen
= sizeof(unsigned int),
331 .proc_handler
= proc_dointvec
,
334 .procname
= "timer_migration",
335 .data
= &sysctl_timer_migration
,
336 .maxlen
= sizeof(unsigned int),
338 .proc_handler
= proc_dointvec_minmax
,
344 .procname
= "sched_rt_period_us",
345 .data
= &sysctl_sched_rt_period
,
346 .maxlen
= sizeof(unsigned int),
348 .proc_handler
= sched_rt_handler
,
351 .procname
= "sched_rt_runtime_us",
352 .data
= &sysctl_sched_rt_runtime
,
353 .maxlen
= sizeof(int),
355 .proc_handler
= sched_rt_handler
,
358 .procname
= "sched_compat_yield",
359 .data
= &sysctl_sched_compat_yield
,
360 .maxlen
= sizeof(unsigned int),
362 .proc_handler
= proc_dointvec
,
364 #ifdef CONFIG_PROVE_LOCKING
366 .procname
= "prove_locking",
367 .data
= &prove_locking
,
368 .maxlen
= sizeof(int),
370 .proc_handler
= proc_dointvec
,
373 #ifdef CONFIG_LOCK_STAT
375 .procname
= "lock_stat",
377 .maxlen
= sizeof(int),
379 .proc_handler
= proc_dointvec
,
384 .data
= &panic_timeout
,
385 .maxlen
= sizeof(int),
387 .proc_handler
= proc_dointvec
,
390 .procname
= "core_uses_pid",
391 .data
= &core_uses_pid
,
392 .maxlen
= sizeof(int),
394 .proc_handler
= proc_dointvec
,
397 .procname
= "core_pattern",
398 .data
= core_pattern
,
399 .maxlen
= CORENAME_MAX_SIZE
,
401 .proc_handler
= proc_dostring
,
404 .procname
= "core_pipe_limit",
405 .data
= &core_pipe_limit
,
406 .maxlen
= sizeof(unsigned int),
408 .proc_handler
= proc_dointvec
,
410 #ifdef CONFIG_PROC_SYSCTL
412 .procname
= "tainted",
413 .maxlen
= sizeof(long),
415 .proc_handler
= proc_taint
,
418 #ifdef CONFIG_LATENCYTOP
420 .procname
= "latencytop",
421 .data
= &latencytop_enabled
,
422 .maxlen
= sizeof(int),
424 .proc_handler
= proc_dointvec
,
427 #ifdef CONFIG_BLK_DEV_INITRD
429 .procname
= "real-root-dev",
430 .data
= &real_root_dev
,
431 .maxlen
= sizeof(int),
433 .proc_handler
= proc_dointvec
,
437 .procname
= "print-fatal-signals",
438 .data
= &print_fatal_signals
,
439 .maxlen
= sizeof(int),
441 .proc_handler
= proc_dointvec
,
445 .procname
= "reboot-cmd",
446 .data
= reboot_command
,
449 .proc_handler
= proc_dostring
,
452 .procname
= "stop-a",
453 .data
= &stop_a_enabled
,
454 .maxlen
= sizeof (int),
456 .proc_handler
= proc_dointvec
,
459 .procname
= "scons-poweroff",
460 .data
= &scons_pwroff
,
461 .maxlen
= sizeof (int),
463 .proc_handler
= proc_dointvec
,
466 #ifdef CONFIG_SPARC64
468 .procname
= "tsb-ratio",
469 .data
= &sysctl_tsb_ratio
,
470 .maxlen
= sizeof (int),
472 .proc_handler
= proc_dointvec
,
477 .procname
= "soft-power",
478 .data
= &pwrsw_enabled
,
479 .maxlen
= sizeof (int),
481 .proc_handler
= proc_dointvec
,
484 .procname
= "unaligned-trap",
485 .data
= &unaligned_enabled
,
486 .maxlen
= sizeof (int),
488 .proc_handler
= proc_dointvec
,
492 .procname
= "ctrl-alt-del",
494 .maxlen
= sizeof(int),
496 .proc_handler
= proc_dointvec
,
498 #ifdef CONFIG_FUNCTION_TRACER
500 .procname
= "ftrace_enabled",
501 .data
= &ftrace_enabled
,
502 .maxlen
= sizeof(int),
504 .proc_handler
= ftrace_enable_sysctl
,
507 #ifdef CONFIG_STACK_TRACER
509 .procname
= "stack_tracer_enabled",
510 .data
= &stack_tracer_enabled
,
511 .maxlen
= sizeof(int),
513 .proc_handler
= stack_trace_sysctl
,
516 #ifdef CONFIG_TRACING
518 .procname
= "ftrace_dump_on_oops",
519 .data
= &ftrace_dump_on_oops
,
520 .maxlen
= sizeof(int),
522 .proc_handler
= proc_dointvec
,
525 #ifdef CONFIG_MODULES
527 .procname
= "modprobe",
528 .data
= &modprobe_path
,
529 .maxlen
= KMOD_PATH_LEN
,
531 .proc_handler
= proc_dostring
,
534 .procname
= "modules_disabled",
535 .data
= &modules_disabled
,
536 .maxlen
= sizeof(int),
538 /* only handle a transition from default "0" to "1" */
539 .proc_handler
= proc_dointvec_minmax
,
544 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
546 .procname
= "hotplug",
547 .data
= &uevent_helper
,
548 .maxlen
= UEVENT_HELPER_PATH_LEN
,
550 .proc_handler
= proc_dostring
,
553 #ifdef CONFIG_CHR_DEV_SG
555 .procname
= "sg-big-buff",
556 .data
= &sg_big_buff
,
557 .maxlen
= sizeof (int),
559 .proc_handler
= proc_dointvec
,
562 #ifdef CONFIG_BSD_PROCESS_ACCT
566 .maxlen
= 3*sizeof(int),
568 .proc_handler
= proc_dointvec
,
571 #ifdef CONFIG_MAGIC_SYSRQ
574 .data
= &__sysrq_enabled
,
575 .maxlen
= sizeof (int),
577 .proc_handler
= proc_dointvec
,
580 #ifdef CONFIG_PROC_SYSCTL
582 .procname
= "cad_pid",
584 .maxlen
= sizeof (int),
586 .proc_handler
= proc_do_cad_pid
,
590 .procname
= "threads-max",
591 .data
= &max_threads
,
592 .maxlen
= sizeof(int),
594 .proc_handler
= proc_dointvec
,
597 .procname
= "random",
599 .child
= random_table
,
602 .procname
= "overflowuid",
603 .data
= &overflowuid
,
604 .maxlen
= sizeof(int),
606 .proc_handler
= proc_dointvec_minmax
,
607 .extra1
= &minolduid
,
608 .extra2
= &maxolduid
,
611 .procname
= "overflowgid",
612 .data
= &overflowgid
,
613 .maxlen
= sizeof(int),
615 .proc_handler
= proc_dointvec_minmax
,
616 .extra1
= &minolduid
,
617 .extra2
= &maxolduid
,
620 #ifdef CONFIG_MATHEMU
622 .procname
= "ieee_emulation_warnings",
623 .data
= &sysctl_ieee_emulation_warnings
,
624 .maxlen
= sizeof(int),
626 .proc_handler
= proc_dointvec
,
630 .procname
= "userprocess_debug",
631 .data
= &sysctl_userprocess_debug
,
632 .maxlen
= sizeof(int),
634 .proc_handler
= proc_dointvec
,
638 .procname
= "pid_max",
640 .maxlen
= sizeof (int),
642 .proc_handler
= proc_dointvec_minmax
,
643 .extra1
= &pid_max_min
,
644 .extra2
= &pid_max_max
,
647 .procname
= "panic_on_oops",
648 .data
= &panic_on_oops
,
649 .maxlen
= sizeof(int),
651 .proc_handler
= proc_dointvec
,
653 #if defined CONFIG_PRINTK
655 .procname
= "printk",
656 .data
= &console_loglevel
,
657 .maxlen
= 4*sizeof(int),
659 .proc_handler
= proc_dointvec
,
662 .procname
= "printk_ratelimit",
663 .data
= &printk_ratelimit_state
.interval
,
664 .maxlen
= sizeof(int),
666 .proc_handler
= proc_dointvec_jiffies
,
669 .procname
= "printk_ratelimit_burst",
670 .data
= &printk_ratelimit_state
.burst
,
671 .maxlen
= sizeof(int),
673 .proc_handler
= proc_dointvec
,
676 .procname
= "printk_delay",
677 .data
= &printk_delay_msec
,
678 .maxlen
= sizeof(int),
680 .proc_handler
= proc_dointvec_minmax
,
682 .extra2
= &ten_thousand
,
686 .procname
= "ngroups_max",
687 .data
= &ngroups_max
,
688 .maxlen
= sizeof (int),
690 .proc_handler
= proc_dointvec
,
692 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
694 .procname
= "unknown_nmi_panic",
695 .data
= &unknown_nmi_panic
,
696 .maxlen
= sizeof (int),
698 .proc_handler
= proc_dointvec
,
701 .procname
= "nmi_watchdog",
702 .data
= &nmi_watchdog_enabled
,
703 .maxlen
= sizeof (int),
705 .proc_handler
= proc_nmi_enabled
,
708 #if defined(CONFIG_X86)
710 .procname
= "panic_on_unrecovered_nmi",
711 .data
= &panic_on_unrecovered_nmi
,
712 .maxlen
= sizeof(int),
714 .proc_handler
= proc_dointvec
,
717 .procname
= "panic_on_io_nmi",
718 .data
= &panic_on_io_nmi
,
719 .maxlen
= sizeof(int),
721 .proc_handler
= proc_dointvec
,
724 .procname
= "bootloader_type",
725 .data
= &bootloader_type
,
726 .maxlen
= sizeof (int),
728 .proc_handler
= proc_dointvec
,
731 .procname
= "bootloader_version",
732 .data
= &bootloader_version
,
733 .maxlen
= sizeof (int),
735 .proc_handler
= proc_dointvec
,
738 .procname
= "kstack_depth_to_print",
739 .data
= &kstack_depth_to_print
,
740 .maxlen
= sizeof(int),
742 .proc_handler
= proc_dointvec
,
745 .procname
= "io_delay_type",
746 .data
= &io_delay_type
,
747 .maxlen
= sizeof(int),
749 .proc_handler
= proc_dointvec
,
752 #if defined(CONFIG_MMU)
754 .procname
= "randomize_va_space",
755 .data
= &randomize_va_space
,
756 .maxlen
= sizeof(int),
758 .proc_handler
= proc_dointvec
,
761 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
763 .procname
= "spin_retry",
765 .maxlen
= sizeof (int),
767 .proc_handler
= proc_dointvec
,
770 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
772 .procname
= "acpi_video_flags",
773 .data
= &acpi_realmode_flags
,
774 .maxlen
= sizeof (unsigned long),
776 .proc_handler
= proc_doulongvec_minmax
,
781 .procname
= "ignore-unaligned-usertrap",
782 .data
= &no_unaligned_warning
,
783 .maxlen
= sizeof (int),
785 .proc_handler
= proc_dointvec
,
788 .procname
= "unaligned-dump-stack",
789 .data
= &unaligned_dump_stack
,
790 .maxlen
= sizeof (int),
792 .proc_handler
= proc_dointvec
,
795 #ifdef CONFIG_DETECT_SOFTLOCKUP
797 .procname
= "softlockup_panic",
798 .data
= &softlockup_panic
,
799 .maxlen
= sizeof(int),
801 .proc_handler
= proc_dointvec_minmax
,
806 .procname
= "softlockup_thresh",
807 .data
= &softlockup_thresh
,
808 .maxlen
= sizeof(int),
810 .proc_handler
= proc_dosoftlockup_thresh
,
815 #ifdef CONFIG_DETECT_HUNG_TASK
817 .procname
= "hung_task_panic",
818 .data
= &sysctl_hung_task_panic
,
819 .maxlen
= sizeof(int),
821 .proc_handler
= proc_dointvec_minmax
,
826 .procname
= "hung_task_check_count",
827 .data
= &sysctl_hung_task_check_count
,
828 .maxlen
= sizeof(unsigned long),
830 .proc_handler
= proc_doulongvec_minmax
,
833 .procname
= "hung_task_timeout_secs",
834 .data
= &sysctl_hung_task_timeout_secs
,
835 .maxlen
= sizeof(unsigned long),
837 .proc_handler
= proc_dohung_task_timeout_secs
,
840 .procname
= "hung_task_warnings",
841 .data
= &sysctl_hung_task_warnings
,
842 .maxlen
= sizeof(unsigned long),
844 .proc_handler
= proc_doulongvec_minmax
,
849 .procname
= "compat-log",
851 .maxlen
= sizeof (int),
853 .proc_handler
= proc_dointvec
,
856 #ifdef CONFIG_RT_MUTEXES
858 .procname
= "max_lock_depth",
859 .data
= &max_lock_depth
,
860 .maxlen
= sizeof(int),
862 .proc_handler
= proc_dointvec
,
866 .procname
= "poweroff_cmd",
867 .data
= &poweroff_cmd
,
868 .maxlen
= POWEROFF_CMD_PATH_LEN
,
870 .proc_handler
= proc_dostring
,
876 .child
= key_sysctls
,
879 #ifdef CONFIG_RCU_TORTURE_TEST
881 .procname
= "rcutorture_runnable",
882 .data
= &rcutorture_runnable
,
883 .maxlen
= sizeof(int),
885 .proc_handler
= proc_dointvec
,
888 #ifdef CONFIG_SLOW_WORK
890 .procname
= "slow-work",
892 .child
= slow_work_sysctls
,
895 #ifdef CONFIG_PERF_EVENTS
897 .procname
= "perf_event_paranoid",
898 .data
= &sysctl_perf_event_paranoid
,
899 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
901 .proc_handler
= proc_dointvec
,
904 .procname
= "perf_event_mlock_kb",
905 .data
= &sysctl_perf_event_mlock
,
906 .maxlen
= sizeof(sysctl_perf_event_mlock
),
908 .proc_handler
= proc_dointvec
,
911 .procname
= "perf_event_max_sample_rate",
912 .data
= &sysctl_perf_event_sample_rate
,
913 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
915 .proc_handler
= proc_dointvec
,
918 #ifdef CONFIG_KMEMCHECK
920 .procname
= "kmemcheck",
921 .data
= &kmemcheck_enabled
,
922 .maxlen
= sizeof(int),
924 .proc_handler
= proc_dointvec
,
929 .procname
= "blk_iopoll",
930 .data
= &blk_iopoll_enabled
,
931 .maxlen
= sizeof(int),
933 .proc_handler
= proc_dointvec
,
937 * NOTE: do not add new entries to this table unless you have read
938 * Documentation/sysctl/ctl_unnumbered.txt
943 static struct ctl_table vm_table
[] = {
945 .procname
= "overcommit_memory",
946 .data
= &sysctl_overcommit_memory
,
947 .maxlen
= sizeof(sysctl_overcommit_memory
),
949 .proc_handler
= proc_dointvec
,
952 .procname
= "panic_on_oom",
953 .data
= &sysctl_panic_on_oom
,
954 .maxlen
= sizeof(sysctl_panic_on_oom
),
956 .proc_handler
= proc_dointvec
,
959 .procname
= "oom_kill_allocating_task",
960 .data
= &sysctl_oom_kill_allocating_task
,
961 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
963 .proc_handler
= proc_dointvec
,
966 .procname
= "oom_dump_tasks",
967 .data
= &sysctl_oom_dump_tasks
,
968 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
970 .proc_handler
= proc_dointvec
,
973 .procname
= "overcommit_ratio",
974 .data
= &sysctl_overcommit_ratio
,
975 .maxlen
= sizeof(sysctl_overcommit_ratio
),
977 .proc_handler
= proc_dointvec
,
980 .procname
= "page-cluster",
981 .data
= &page_cluster
,
982 .maxlen
= sizeof(int),
984 .proc_handler
= proc_dointvec
,
987 .procname
= "dirty_background_ratio",
988 .data
= &dirty_background_ratio
,
989 .maxlen
= sizeof(dirty_background_ratio
),
991 .proc_handler
= dirty_background_ratio_handler
,
993 .extra2
= &one_hundred
,
996 .procname
= "dirty_background_bytes",
997 .data
= &dirty_background_bytes
,
998 .maxlen
= sizeof(dirty_background_bytes
),
1000 .proc_handler
= dirty_background_bytes_handler
,
1004 .procname
= "dirty_ratio",
1005 .data
= &vm_dirty_ratio
,
1006 .maxlen
= sizeof(vm_dirty_ratio
),
1008 .proc_handler
= dirty_ratio_handler
,
1010 .extra2
= &one_hundred
,
1013 .procname
= "dirty_bytes",
1014 .data
= &vm_dirty_bytes
,
1015 .maxlen
= sizeof(vm_dirty_bytes
),
1017 .proc_handler
= dirty_bytes_handler
,
1018 .extra1
= &dirty_bytes_min
,
1021 .procname
= "dirty_writeback_centisecs",
1022 .data
= &dirty_writeback_interval
,
1023 .maxlen
= sizeof(dirty_writeback_interval
),
1025 .proc_handler
= dirty_writeback_centisecs_handler
,
1028 .procname
= "dirty_expire_centisecs",
1029 .data
= &dirty_expire_interval
,
1030 .maxlen
= sizeof(dirty_expire_interval
),
1032 .proc_handler
= proc_dointvec
,
1035 .procname
= "nr_pdflush_threads",
1036 .data
= &nr_pdflush_threads
,
1037 .maxlen
= sizeof nr_pdflush_threads
,
1038 .mode
= 0444 /* read-only*/,
1039 .proc_handler
= proc_dointvec
,
1042 .procname
= "swappiness",
1043 .data
= &vm_swappiness
,
1044 .maxlen
= sizeof(vm_swappiness
),
1046 .proc_handler
= proc_dointvec_minmax
,
1048 .extra2
= &one_hundred
,
1050 #ifdef CONFIG_HUGETLB_PAGE
1052 .procname
= "nr_hugepages",
1054 .maxlen
= sizeof(unsigned long),
1056 .proc_handler
= hugetlb_sysctl_handler
,
1057 .extra1
= (void *)&hugetlb_zero
,
1058 .extra2
= (void *)&hugetlb_infinity
,
1062 .procname
= "nr_hugepages_mempolicy",
1064 .maxlen
= sizeof(unsigned long),
1066 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1067 .extra1
= (void *)&hugetlb_zero
,
1068 .extra2
= (void *)&hugetlb_infinity
,
1072 .procname
= "hugetlb_shm_group",
1073 .data
= &sysctl_hugetlb_shm_group
,
1074 .maxlen
= sizeof(gid_t
),
1076 .proc_handler
= proc_dointvec
,
1079 .procname
= "hugepages_treat_as_movable",
1080 .data
= &hugepages_treat_as_movable
,
1081 .maxlen
= sizeof(int),
1083 .proc_handler
= hugetlb_treat_movable_handler
,
1086 .procname
= "nr_overcommit_hugepages",
1088 .maxlen
= sizeof(unsigned long),
1090 .proc_handler
= hugetlb_overcommit_handler
,
1091 .extra1
= (void *)&hugetlb_zero
,
1092 .extra2
= (void *)&hugetlb_infinity
,
1096 .procname
= "lowmem_reserve_ratio",
1097 .data
= &sysctl_lowmem_reserve_ratio
,
1098 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1100 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1103 .procname
= "drop_caches",
1104 .data
= &sysctl_drop_caches
,
1105 .maxlen
= sizeof(int),
1107 .proc_handler
= drop_caches_sysctl_handler
,
1110 .procname
= "min_free_kbytes",
1111 .data
= &min_free_kbytes
,
1112 .maxlen
= sizeof(min_free_kbytes
),
1114 .proc_handler
= min_free_kbytes_sysctl_handler
,
1118 .procname
= "percpu_pagelist_fraction",
1119 .data
= &percpu_pagelist_fraction
,
1120 .maxlen
= sizeof(percpu_pagelist_fraction
),
1122 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1123 .extra1
= &min_percpu_pagelist_fract
,
1127 .procname
= "max_map_count",
1128 .data
= &sysctl_max_map_count
,
1129 .maxlen
= sizeof(sysctl_max_map_count
),
1131 .proc_handler
= proc_dointvec_minmax
,
1136 .procname
= "nr_trim_pages",
1137 .data
= &sysctl_nr_trim_pages
,
1138 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1140 .proc_handler
= proc_dointvec_minmax
,
1145 .procname
= "laptop_mode",
1146 .data
= &laptop_mode
,
1147 .maxlen
= sizeof(laptop_mode
),
1149 .proc_handler
= proc_dointvec_jiffies
,
1152 .procname
= "block_dump",
1153 .data
= &block_dump
,
1154 .maxlen
= sizeof(block_dump
),
1156 .proc_handler
= proc_dointvec
,
1160 .procname
= "vfs_cache_pressure",
1161 .data
= &sysctl_vfs_cache_pressure
,
1162 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1164 .proc_handler
= proc_dointvec
,
1167 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1169 .procname
= "legacy_va_layout",
1170 .data
= &sysctl_legacy_va_layout
,
1171 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1173 .proc_handler
= proc_dointvec
,
1179 .procname
= "zone_reclaim_mode",
1180 .data
= &zone_reclaim_mode
,
1181 .maxlen
= sizeof(zone_reclaim_mode
),
1183 .proc_handler
= proc_dointvec
,
1187 .procname
= "min_unmapped_ratio",
1188 .data
= &sysctl_min_unmapped_ratio
,
1189 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1191 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1193 .extra2
= &one_hundred
,
1196 .procname
= "min_slab_ratio",
1197 .data
= &sysctl_min_slab_ratio
,
1198 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1200 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1202 .extra2
= &one_hundred
,
1207 .procname
= "stat_interval",
1208 .data
= &sysctl_stat_interval
,
1209 .maxlen
= sizeof(sysctl_stat_interval
),
1211 .proc_handler
= proc_dointvec_jiffies
,
1216 .procname
= "mmap_min_addr",
1217 .data
= &dac_mmap_min_addr
,
1218 .maxlen
= sizeof(unsigned long),
1220 .proc_handler
= mmap_min_addr_handler
,
1225 .procname
= "numa_zonelist_order",
1226 .data
= &numa_zonelist_order
,
1227 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1229 .proc_handler
= numa_zonelist_order_handler
,
1232 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1233 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1235 .procname
= "vdso_enabled",
1236 .data
= &vdso_enabled
,
1237 .maxlen
= sizeof(vdso_enabled
),
1239 .proc_handler
= proc_dointvec
,
1243 #ifdef CONFIG_HIGHMEM
1245 .procname
= "highmem_is_dirtyable",
1246 .data
= &vm_highmem_is_dirtyable
,
1247 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1249 .proc_handler
= proc_dointvec_minmax
,
1255 .procname
= "scan_unevictable_pages",
1256 .data
= &scan_unevictable_pages
,
1257 .maxlen
= sizeof(scan_unevictable_pages
),
1259 .proc_handler
= scan_unevictable_handler
,
1261 #ifdef CONFIG_MEMORY_FAILURE
1263 .procname
= "memory_failure_early_kill",
1264 .data
= &sysctl_memory_failure_early_kill
,
1265 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1267 .proc_handler
= proc_dointvec_minmax
,
1272 .procname
= "memory_failure_recovery",
1273 .data
= &sysctl_memory_failure_recovery
,
1274 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1276 .proc_handler
= proc_dointvec_minmax
,
1283 * NOTE: do not add new entries to this table unless you have read
1284 * Documentation/sysctl/ctl_unnumbered.txt
1289 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1290 static struct ctl_table binfmt_misc_table
[] = {
1295 static struct ctl_table fs_table
[] = {
1297 .procname
= "inode-nr",
1298 .data
= &inodes_stat
,
1299 .maxlen
= 2*sizeof(int),
1301 .proc_handler
= proc_dointvec
,
1304 .procname
= "inode-state",
1305 .data
= &inodes_stat
,
1306 .maxlen
= 7*sizeof(int),
1308 .proc_handler
= proc_dointvec
,
1311 .procname
= "file-nr",
1312 .data
= &files_stat
,
1313 .maxlen
= 3*sizeof(int),
1315 .proc_handler
= proc_nr_files
,
1318 .procname
= "file-max",
1319 .data
= &files_stat
.max_files
,
1320 .maxlen
= sizeof(int),
1322 .proc_handler
= proc_dointvec
,
1325 .procname
= "nr_open",
1326 .data
= &sysctl_nr_open
,
1327 .maxlen
= sizeof(int),
1329 .proc_handler
= proc_dointvec_minmax
,
1330 .extra1
= &sysctl_nr_open_min
,
1331 .extra2
= &sysctl_nr_open_max
,
1334 .procname
= "dentry-state",
1335 .data
= &dentry_stat
,
1336 .maxlen
= 6*sizeof(int),
1338 .proc_handler
= proc_dointvec
,
1341 .procname
= "overflowuid",
1342 .data
= &fs_overflowuid
,
1343 .maxlen
= sizeof(int),
1345 .proc_handler
= proc_dointvec_minmax
,
1346 .extra1
= &minolduid
,
1347 .extra2
= &maxolduid
,
1350 .procname
= "overflowgid",
1351 .data
= &fs_overflowgid
,
1352 .maxlen
= sizeof(int),
1354 .proc_handler
= proc_dointvec_minmax
,
1355 .extra1
= &minolduid
,
1356 .extra2
= &maxolduid
,
1358 #ifdef CONFIG_FILE_LOCKING
1360 .procname
= "leases-enable",
1361 .data
= &leases_enable
,
1362 .maxlen
= sizeof(int),
1364 .proc_handler
= proc_dointvec
,
1367 #ifdef CONFIG_DNOTIFY
1369 .procname
= "dir-notify-enable",
1370 .data
= &dir_notify_enable
,
1371 .maxlen
= sizeof(int),
1373 .proc_handler
= proc_dointvec
,
1377 #ifdef CONFIG_FILE_LOCKING
1379 .procname
= "lease-break-time",
1380 .data
= &lease_break_time
,
1381 .maxlen
= sizeof(int),
1383 .proc_handler
= proc_dointvec
,
1388 .procname
= "aio-nr",
1390 .maxlen
= sizeof(aio_nr
),
1392 .proc_handler
= proc_doulongvec_minmax
,
1395 .procname
= "aio-max-nr",
1396 .data
= &aio_max_nr
,
1397 .maxlen
= sizeof(aio_max_nr
),
1399 .proc_handler
= proc_doulongvec_minmax
,
1401 #endif /* CONFIG_AIO */
1402 #ifdef CONFIG_INOTIFY_USER
1404 .procname
= "inotify",
1406 .child
= inotify_table
,
1411 .procname
= "epoll",
1413 .child
= epoll_table
,
1418 .procname
= "suid_dumpable",
1419 .data
= &suid_dumpable
,
1420 .maxlen
= sizeof(int),
1422 .proc_handler
= proc_dointvec_minmax
,
1426 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1428 .procname
= "binfmt_misc",
1430 .child
= binfmt_misc_table
,
1434 * NOTE: do not add new entries to this table unless you have read
1435 * Documentation/sysctl/ctl_unnumbered.txt
1440 static struct ctl_table debug_table
[] = {
1441 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
1443 .procname
= "exception-trace",
1444 .data
= &show_unhandled_signals
,
1445 .maxlen
= sizeof(int),
1447 .proc_handler
= proc_dointvec
1450 #if defined(CONFIG_OPTPROBES)
1452 .procname
= "kprobes-optimization",
1453 .data
= &sysctl_kprobes_optimization
,
1454 .maxlen
= sizeof(int),
1456 .proc_handler
= proc_kprobes_optimization_handler
,
1464 static struct ctl_table dev_table
[] = {
1468 static DEFINE_SPINLOCK(sysctl_lock
);
1470 /* called under sysctl_lock */
1471 static int use_table(struct ctl_table_header
*p
)
1473 if (unlikely(p
->unregistering
))
1479 /* called under sysctl_lock */
1480 static void unuse_table(struct ctl_table_header
*p
)
1483 if (unlikely(p
->unregistering
))
1484 complete(p
->unregistering
);
1487 /* called under sysctl_lock, will reacquire if has to wait */
1488 static void start_unregistering(struct ctl_table_header
*p
)
1491 * if p->used is 0, nobody will ever touch that entry again;
1492 * we'll eliminate all paths to it before dropping sysctl_lock
1494 if (unlikely(p
->used
)) {
1495 struct completion wait
;
1496 init_completion(&wait
);
1497 p
->unregistering
= &wait
;
1498 spin_unlock(&sysctl_lock
);
1499 wait_for_completion(&wait
);
1500 spin_lock(&sysctl_lock
);
1502 /* anything non-NULL; we'll never dereference it */
1503 p
->unregistering
= ERR_PTR(-EINVAL
);
1506 * do not remove from the list until nobody holds it; walking the
1507 * list in do_sysctl() relies on that.
1509 list_del_init(&p
->ctl_entry
);
1512 void sysctl_head_get(struct ctl_table_header
*head
)
1514 spin_lock(&sysctl_lock
);
1516 spin_unlock(&sysctl_lock
);
1519 void sysctl_head_put(struct ctl_table_header
*head
)
1521 spin_lock(&sysctl_lock
);
1524 spin_unlock(&sysctl_lock
);
1527 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1531 spin_lock(&sysctl_lock
);
1532 if (!use_table(head
))
1533 head
= ERR_PTR(-ENOENT
);
1534 spin_unlock(&sysctl_lock
);
1538 void sysctl_head_finish(struct ctl_table_header
*head
)
1542 spin_lock(&sysctl_lock
);
1544 spin_unlock(&sysctl_lock
);
1547 static struct ctl_table_set
*
1548 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1550 struct ctl_table_set
*set
= &root
->default_set
;
1552 set
= root
->lookup(root
, namespaces
);
1556 static struct list_head
*
1557 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1559 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1563 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1564 struct ctl_table_header
*prev
)
1566 struct ctl_table_root
*root
;
1567 struct list_head
*header_list
;
1568 struct ctl_table_header
*head
;
1569 struct list_head
*tmp
;
1571 spin_lock(&sysctl_lock
);
1574 tmp
= &prev
->ctl_entry
;
1578 tmp
= &root_table_header
.ctl_entry
;
1580 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1582 if (!use_table(head
))
1584 spin_unlock(&sysctl_lock
);
1589 header_list
= lookup_header_list(root
, namespaces
);
1590 if (tmp
!= header_list
)
1594 root
= list_entry(root
->root_list
.next
,
1595 struct ctl_table_root
, root_list
);
1596 if (root
== &sysctl_table_root
)
1598 header_list
= lookup_header_list(root
, namespaces
);
1599 } while (list_empty(header_list
));
1600 tmp
= header_list
->next
;
1603 spin_unlock(&sysctl_lock
);
1607 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1609 return __sysctl_head_next(current
->nsproxy
, prev
);
1612 void register_sysctl_root(struct ctl_table_root
*root
)
1614 spin_lock(&sysctl_lock
);
1615 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1616 spin_unlock(&sysctl_lock
);
1620 * sysctl_perm does NOT grant the superuser all rights automatically, because
1621 * some sysctl variables are readonly even to root.
1624 static int test_perm(int mode
, int op
)
1626 if (!current_euid())
1628 else if (in_egroup_p(0))
1630 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1635 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1640 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1644 if (root
->permissions
)
1645 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1649 return test_perm(mode
, op
);
1652 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1654 for (; table
->procname
; table
++) {
1655 table
->parent
= parent
;
1657 sysctl_set_parent(table
, table
->child
);
1661 static __init
int sysctl_init(void)
1663 sysctl_set_parent(NULL
, root_table
);
1664 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1667 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1673 core_initcall(sysctl_init
);
1675 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1676 struct ctl_table
*table
)
1678 struct ctl_table
*p
;
1679 const char *s
= branch
->procname
;
1681 /* branch should have named subdirectory as its first element */
1682 if (!s
|| !branch
->child
)
1685 /* ... and nothing else */
1686 if (branch
[1].procname
)
1689 /* table should contain subdirectory with the same name */
1690 for (p
= table
; p
->procname
; p
++) {
1693 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1699 /* see if attaching q to p would be an improvement */
1700 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1702 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1703 struct ctl_table
*next
;
1705 int not_in_parent
= !p
->attached_by
;
1707 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1708 if (by
== q
->attached_by
)
1710 if (to
== p
->attached_by
)
1716 if (is_better
&& not_in_parent
) {
1717 q
->attached_by
= by
;
1718 q
->attached_to
= to
;
1724 * __register_sysctl_paths - register a sysctl hierarchy
1725 * @root: List of sysctl headers to register on
1726 * @namespaces: Data to compute which lists of sysctl entries are visible
1727 * @path: The path to the directory the sysctl table is in.
1728 * @table: the top-level table structure
1730 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1731 * array. A completely 0 filled entry terminates the table.
1733 * The members of the &struct ctl_table structure are used as follows:
1735 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1736 * enter a sysctl file
1738 * data - a pointer to data for use by proc_handler
1740 * maxlen - the maximum size in bytes of the data
1742 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1744 * child - a pointer to the child sysctl table if this entry is a directory, or
1747 * proc_handler - the text handler routine (described below)
1749 * de - for internal use by the sysctl routines
1751 * extra1, extra2 - extra pointers usable by the proc handler routines
1753 * Leaf nodes in the sysctl tree will be represented by a single file
1754 * under /proc; non-leaf nodes will be represented by directories.
1756 * sysctl(2) can automatically manage read and write requests through
1757 * the sysctl table. The data and maxlen fields of the ctl_table
1758 * struct enable minimal validation of the values being written to be
1759 * performed, and the mode field allows minimal authentication.
1761 * There must be a proc_handler routine for any terminal nodes
1762 * mirrored under /proc/sys (non-terminals are handled by a built-in
1763 * directory handler). Several default handlers are available to
1764 * cover common cases -
1766 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1767 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1768 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1770 * It is the handler's job to read the input buffer from user memory
1771 * and process it. The handler should return 0 on success.
1773 * This routine returns %NULL on a failure to register, and a pointer
1774 * to the table header on success.
1776 struct ctl_table_header
*__register_sysctl_paths(
1777 struct ctl_table_root
*root
,
1778 struct nsproxy
*namespaces
,
1779 const struct ctl_path
*path
, struct ctl_table
*table
)
1781 struct ctl_table_header
*header
;
1782 struct ctl_table
*new, **prevp
;
1783 unsigned int n
, npath
;
1784 struct ctl_table_set
*set
;
1786 /* Count the path components */
1787 for (npath
= 0; path
[npath
].procname
; ++npath
)
1791 * For each path component, allocate a 2-element ctl_table array.
1792 * The first array element will be filled with the sysctl entry
1793 * for this, the second will be the sentinel (procname == 0).
1795 * We allocate everything in one go so that we don't have to
1796 * worry about freeing additional memory in unregister_sysctl_table.
1798 header
= kzalloc(sizeof(struct ctl_table_header
) +
1799 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1803 new = (struct ctl_table
*) (header
+ 1);
1805 /* Now connect the dots */
1806 prevp
= &header
->ctl_table
;
1807 for (n
= 0; n
< npath
; ++n
, ++path
) {
1808 /* Copy the procname */
1809 new->procname
= path
->procname
;
1813 prevp
= &new->child
;
1818 header
->ctl_table_arg
= table
;
1820 INIT_LIST_HEAD(&header
->ctl_entry
);
1822 header
->unregistering
= NULL
;
1823 header
->root
= root
;
1824 sysctl_set_parent(NULL
, header
->ctl_table
);
1826 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1827 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1832 spin_lock(&sysctl_lock
);
1833 header
->set
= lookup_header_set(root
, namespaces
);
1834 header
->attached_by
= header
->ctl_table
;
1835 header
->attached_to
= root_table
;
1836 header
->parent
= &root_table_header
;
1837 for (set
= header
->set
; set
; set
= set
->parent
) {
1838 struct ctl_table_header
*p
;
1839 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1840 if (p
->unregistering
)
1842 try_attach(p
, header
);
1845 header
->parent
->count
++;
1846 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1847 spin_unlock(&sysctl_lock
);
1853 * register_sysctl_table_path - register a sysctl table hierarchy
1854 * @path: The path to the directory the sysctl table is in.
1855 * @table: the top-level table structure
1857 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1858 * array. A completely 0 filled entry terminates the table.
1860 * See __register_sysctl_paths for more details.
1862 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1863 struct ctl_table
*table
)
1865 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1870 * register_sysctl_table - register a sysctl table hierarchy
1871 * @table: the top-level table structure
1873 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1874 * array. A completely 0 filled entry terminates the table.
1876 * See register_sysctl_paths for more details.
1878 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1880 static const struct ctl_path null_path
[] = { {} };
1882 return register_sysctl_paths(null_path
, table
);
1886 * unregister_sysctl_table - unregister a sysctl table hierarchy
1887 * @header: the header returned from register_sysctl_table
1889 * Unregisters the sysctl table and all children. proc entries may not
1890 * actually be removed until they are no longer used by anyone.
1892 void unregister_sysctl_table(struct ctl_table_header
* header
)
1899 spin_lock(&sysctl_lock
);
1900 start_unregistering(header
);
1901 if (!--header
->parent
->count
) {
1903 kfree(header
->parent
);
1905 if (!--header
->count
)
1907 spin_unlock(&sysctl_lock
);
1910 int sysctl_is_seen(struct ctl_table_header
*p
)
1912 struct ctl_table_set
*set
= p
->set
;
1914 spin_lock(&sysctl_lock
);
1915 if (p
->unregistering
)
1917 else if (!set
->is_seen
)
1920 res
= set
->is_seen(set
);
1921 spin_unlock(&sysctl_lock
);
1925 void setup_sysctl_set(struct ctl_table_set
*p
,
1926 struct ctl_table_set
*parent
,
1927 int (*is_seen
)(struct ctl_table_set
*))
1929 INIT_LIST_HEAD(&p
->list
);
1930 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1931 p
->is_seen
= is_seen
;
1934 #else /* !CONFIG_SYSCTL */
1935 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1940 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1941 struct ctl_table
*table
)
1946 void unregister_sysctl_table(struct ctl_table_header
* table
)
1950 void setup_sysctl_set(struct ctl_table_set
*p
,
1951 struct ctl_table_set
*parent
,
1952 int (*is_seen
)(struct ctl_table_set
*))
1956 void sysctl_head_put(struct ctl_table_header
*head
)
1960 #endif /* CONFIG_SYSCTL */
1966 #ifdef CONFIG_PROC_SYSCTL
1968 static int _proc_do_string(void* data
, int maxlen
, int write
,
1969 void __user
*buffer
,
1970 size_t *lenp
, loff_t
*ppos
)
1976 if (!data
|| !maxlen
|| !*lenp
) {
1984 while (len
< *lenp
) {
1985 if (get_user(c
, p
++))
1987 if (c
== 0 || c
== '\n')
1993 if(copy_from_user(data
, buffer
, len
))
1995 ((char *) data
)[len
] = 0;
2013 if(copy_to_user(buffer
, data
, len
))
2016 if(put_user('\n', ((char __user
*) buffer
) + len
))
2027 * proc_dostring - read a string sysctl
2028 * @table: the sysctl table
2029 * @write: %TRUE if this is a write to the sysctl file
2030 * @buffer: the user buffer
2031 * @lenp: the size of the user buffer
2032 * @ppos: file position
2034 * Reads/writes a string from/to the user buffer. If the kernel
2035 * buffer provided is not large enough to hold the string, the
2036 * string is truncated. The copied string is %NULL-terminated.
2037 * If the string is being read by the user process, it is copied
2038 * and a newline '\n' is added. It is truncated if the buffer is
2041 * Returns 0 on success.
2043 int proc_dostring(struct ctl_table
*table
, int write
,
2044 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2046 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2047 buffer
, lenp
, ppos
);
2051 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2053 int write
, void *data
)
2056 *valp
= *negp
? -*lvalp
: *lvalp
;
2061 *lvalp
= (unsigned long)-val
;
2064 *lvalp
= (unsigned long)val
;
2070 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2071 int write
, void __user
*buffer
,
2072 size_t *lenp
, loff_t
*ppos
,
2073 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2074 int write
, void *data
),
2077 #define TMPBUFLEN 21
2078 int *i
, vleft
, first
= 1, neg
;
2082 char buf
[TMPBUFLEN
], *p
;
2083 char __user
*s
= buffer
;
2085 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2086 (*ppos
&& !write
)) {
2091 i
= (int *) tbl_data
;
2092 vleft
= table
->maxlen
/ sizeof(*i
);
2096 conv
= do_proc_dointvec_conv
;
2098 for (; left
&& vleft
--; i
++, first
=0) {
2113 if (len
> sizeof(buf
) - 1)
2114 len
= sizeof(buf
) - 1;
2115 if (copy_from_user(buf
, s
, len
))
2119 if (*p
== '-' && left
> 1) {
2123 if (*p
< '0' || *p
> '9')
2126 lval
= simple_strtoul(p
, &p
, 0);
2129 if ((len
< left
) && *p
&& !isspace(*p
))
2134 if (conv(&neg
, &lval
, i
, 1, data
))
2141 if (conv(&neg
, &lval
, i
, 0, data
))
2144 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2148 if(copy_to_user(s
, buf
, len
))
2155 if (!write
&& !first
&& left
) {
2156 if(put_user('\n', s
))
2163 if (get_user(c
, s
++))
2178 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2179 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2180 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2181 int write
, void *data
),
2184 return __do_proc_dointvec(table
->data
, table
, write
,
2185 buffer
, lenp
, ppos
, conv
, data
);
2189 * proc_dointvec - read a vector of integers
2190 * @table: the sysctl table
2191 * @write: %TRUE if this is a write to the sysctl file
2192 * @buffer: the user buffer
2193 * @lenp: the size of the user buffer
2194 * @ppos: file position
2196 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2197 * values from/to the user buffer, treated as an ASCII string.
2199 * Returns 0 on success.
2201 int proc_dointvec(struct ctl_table
*table
, int write
,
2202 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2204 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2209 * Taint values can only be increased
2210 * This means we can safely use a temporary.
2212 static int proc_taint(struct ctl_table
*table
, int write
,
2213 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2216 unsigned long tmptaint
= get_taint();
2219 if (write
&& !capable(CAP_SYS_ADMIN
))
2224 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2230 * Poor man's atomic or. Not worth adding a primitive
2231 * to everyone's atomic.h for this
2234 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2235 if ((tmptaint
>> i
) & 1)
2243 struct do_proc_dointvec_minmax_conv_param
{
2248 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2250 int write
, void *data
)
2252 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2254 int val
= *negp
? -*lvalp
: *lvalp
;
2255 if ((param
->min
&& *param
->min
> val
) ||
2256 (param
->max
&& *param
->max
< val
))
2263 *lvalp
= (unsigned long)-val
;
2266 *lvalp
= (unsigned long)val
;
2273 * proc_dointvec_minmax - read a vector of integers with min/max values
2274 * @table: the sysctl table
2275 * @write: %TRUE if this is a write to the sysctl file
2276 * @buffer: the user buffer
2277 * @lenp: the size of the user buffer
2278 * @ppos: file position
2280 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2281 * values from/to the user buffer, treated as an ASCII string.
2283 * This routine will ensure the values are within the range specified by
2284 * table->extra1 (min) and table->extra2 (max).
2286 * Returns 0 on success.
2288 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2289 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2291 struct do_proc_dointvec_minmax_conv_param param
= {
2292 .min
= (int *) table
->extra1
,
2293 .max
= (int *) table
->extra2
,
2295 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2296 do_proc_dointvec_minmax_conv
, ¶m
);
2299 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2300 void __user
*buffer
,
2301 size_t *lenp
, loff_t
*ppos
,
2302 unsigned long convmul
,
2303 unsigned long convdiv
)
2305 #define TMPBUFLEN 21
2306 unsigned long *i
, *min
, *max
, val
;
2307 int vleft
, first
=1, neg
;
2309 char buf
[TMPBUFLEN
], *p
;
2310 char __user
*s
= buffer
;
2312 if (!data
|| !table
->maxlen
|| !*lenp
||
2313 (*ppos
&& !write
)) {
2318 i
= (unsigned long *) data
;
2319 min
= (unsigned long *) table
->extra1
;
2320 max
= (unsigned long *) table
->extra2
;
2321 vleft
= table
->maxlen
/ sizeof(unsigned long);
2324 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2339 if (len
> TMPBUFLEN
-1)
2341 if (copy_from_user(buf
, s
, len
))
2345 if (*p
== '-' && left
> 1) {
2349 if (*p
< '0' || *p
> '9')
2351 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2353 if ((len
< left
) && *p
&& !isspace(*p
))
2362 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2369 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2373 if(copy_to_user(s
, buf
, len
))
2380 if (!write
&& !first
&& left
) {
2381 if(put_user('\n', s
))
2388 if (get_user(c
, s
++))
2403 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2404 void __user
*buffer
,
2405 size_t *lenp
, loff_t
*ppos
,
2406 unsigned long convmul
,
2407 unsigned long convdiv
)
2409 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2410 buffer
, lenp
, ppos
, convmul
, convdiv
);
2414 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2415 * @table: the sysctl table
2416 * @write: %TRUE if this is a write to the sysctl file
2417 * @buffer: the user buffer
2418 * @lenp: the size of the user buffer
2419 * @ppos: file position
2421 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2422 * values from/to the user buffer, treated as an ASCII string.
2424 * This routine will ensure the values are within the range specified by
2425 * table->extra1 (min) and table->extra2 (max).
2427 * Returns 0 on success.
2429 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2430 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2432 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2436 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2437 * @table: the sysctl table
2438 * @write: %TRUE if this is a write to the sysctl file
2439 * @buffer: the user buffer
2440 * @lenp: the size of the user buffer
2441 * @ppos: file position
2443 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2444 * values from/to the user buffer, treated as an ASCII string. The values
2445 * are treated as milliseconds, and converted to jiffies when they are stored.
2447 * This routine will ensure the values are within the range specified by
2448 * table->extra1 (min) and table->extra2 (max).
2450 * Returns 0 on success.
2452 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2453 void __user
*buffer
,
2454 size_t *lenp
, loff_t
*ppos
)
2456 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2457 lenp
, ppos
, HZ
, 1000l);
2461 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2463 int write
, void *data
)
2466 if (*lvalp
> LONG_MAX
/ HZ
)
2468 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2474 lval
= (unsigned long)-val
;
2477 lval
= (unsigned long)val
;
2484 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2486 int write
, void *data
)
2489 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2491 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2497 lval
= (unsigned long)-val
;
2500 lval
= (unsigned long)val
;
2502 *lvalp
= jiffies_to_clock_t(lval
);
2507 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2509 int write
, void *data
)
2512 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2518 lval
= (unsigned long)-val
;
2521 lval
= (unsigned long)val
;
2523 *lvalp
= jiffies_to_msecs(lval
);
2529 * proc_dointvec_jiffies - read a vector of integers as seconds
2530 * @table: the sysctl table
2531 * @write: %TRUE if this is a write to the sysctl file
2532 * @buffer: the user buffer
2533 * @lenp: the size of the user buffer
2534 * @ppos: file position
2536 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2537 * values from/to the user buffer, treated as an ASCII string.
2538 * The values read are assumed to be in seconds, and are converted into
2541 * Returns 0 on success.
2543 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2544 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2546 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2547 do_proc_dointvec_jiffies_conv
,NULL
);
2551 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2552 * @table: the sysctl table
2553 * @write: %TRUE if this is a write to the sysctl file
2554 * @buffer: the user buffer
2555 * @lenp: the size of the user buffer
2556 * @ppos: pointer to the file position
2558 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2559 * values from/to the user buffer, treated as an ASCII string.
2560 * The values read are assumed to be in 1/USER_HZ seconds, and
2561 * are converted into jiffies.
2563 * Returns 0 on success.
2565 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2566 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2568 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2569 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2573 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2574 * @table: the sysctl table
2575 * @write: %TRUE if this is a write to the sysctl file
2576 * @buffer: the user buffer
2577 * @lenp: the size of the user buffer
2578 * @ppos: file position
2579 * @ppos: the current position in the file
2581 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2582 * values from/to the user buffer, treated as an ASCII string.
2583 * The values read are assumed to be in 1/1000 seconds, and
2584 * are converted into jiffies.
2586 * Returns 0 on success.
2588 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2589 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2591 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2592 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2595 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2596 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2598 struct pid
*new_pid
;
2602 tmp
= pid_vnr(cad_pid
);
2604 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2605 lenp
, ppos
, NULL
, NULL
);
2609 new_pid
= find_get_pid(tmp
);
2613 put_pid(xchg(&cad_pid
, new_pid
));
2617 #else /* CONFIG_PROC_FS */
2619 int proc_dostring(struct ctl_table
*table
, int write
,
2620 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2625 int proc_dointvec(struct ctl_table
*table
, int write
,
2626 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2631 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2632 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2637 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2638 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2643 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2644 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2649 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2650 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2655 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2656 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2661 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2662 void __user
*buffer
,
2663 size_t *lenp
, loff_t
*ppos
)
2669 #endif /* CONFIG_PROC_FS */
2672 * No sense putting this after each symbol definition, twice,
2673 * exception granted :-)
2675 EXPORT_SYMBOL(proc_dointvec
);
2676 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2677 EXPORT_SYMBOL(proc_dointvec_minmax
);
2678 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2679 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2680 EXPORT_SYMBOL(proc_dostring
);
2681 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2682 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2683 EXPORT_SYMBOL(register_sysctl_table
);
2684 EXPORT_SYMBOL(register_sysctl_paths
);
2685 EXPORT_SYMBOL(unregister_sysctl_table
);