2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/signal.h>
27 #include <linux/proc_fs.h>
28 #include <linux/security.h>
29 #include <linux/ctype.h>
30 #include <linux/kmemcheck.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/ratelimit.h>
40 #include <linux/hugetlb.h>
41 #include <linux/initrd.h>
42 #include <linux/key.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/vmstat.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/acpi.h>
50 #include <linux/reboot.h>
51 #include <linux/ftrace.h>
52 #include <linux/slow-work.h>
53 #include <linux/perf_event.h>
54 #include <linux/kprobes.h>
56 #include <asm/uaccess.h>
57 #include <asm/processor.h>
61 #include <asm/stacktrace.h>
64 #ifdef CONFIG_BSD_PROCESS_ACCT
65 #include <linux/acct.h>
67 #ifdef CONFIG_RT_MUTEXES
68 #include <linux/rtmutex.h>
70 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
71 #include <linux/lockdep.h>
73 #ifdef CONFIG_CHR_DEV_SG
77 #ifdef CONFIG_LOCKUP_DETECTOR
78 #include <linux/nmi.h>
82 #if defined(CONFIG_SYSCTL)
84 /* External variables not in a header file. */
85 extern int sysctl_overcommit_memory
;
86 extern int sysctl_overcommit_ratio
;
87 extern int sysctl_panic_on_oom
;
88 extern int sysctl_oom_kill_allocating_task
;
89 extern int sysctl_oom_dump_tasks
;
90 extern int max_threads
;
91 extern int core_uses_pid
;
92 extern int suid_dumpable
;
93 extern char core_pattern
[];
94 extern unsigned int core_pipe_limit
;
96 extern int min_free_kbytes
;
97 extern int pid_max_min
, pid_max_max
;
98 extern int sysctl_drop_caches
;
99 extern int percpu_pagelist_fraction
;
100 extern int compat_log
;
101 extern int latencytop_enabled
;
102 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
104 extern int sysctl_nr_trim_pages
;
107 extern int blk_iopoll_enabled
;
110 /* Constants used for minimum and maximum */
111 #ifdef CONFIG_DETECT_SOFTLOCKUP
112 static int sixty
= 60;
113 static int neg_one
= -1;
117 static int __maybe_unused one
= 1;
118 static int __maybe_unused two
= 2;
119 static unsigned long one_ul
= 1;
120 static int one_hundred
= 100;
122 static int ten_thousand
= 10000;
125 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
126 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
128 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
129 static int maxolduid
= 65535;
130 static int minolduid
;
131 static int min_percpu_pagelist_fract
= 8;
133 static int ngroups_max
= NGROUPS_MAX
;
136 #include <asm/system.h>
139 #ifdef CONFIG_SPARC64
140 extern int sysctl_tsb_ratio
;
144 extern int pwrsw_enabled
;
145 extern int unaligned_enabled
;
149 #ifdef CONFIG_MATHEMU
150 extern int sysctl_ieee_emulation_warnings
;
152 extern int sysctl_userprocess_debug
;
153 extern int spin_retry
;
157 extern int no_unaligned_warning
;
158 extern int unaligned_dump_stack
;
161 extern struct ratelimit_state printk_ratelimit_state
;
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 /* The default sysctl tables: */
203 static struct ctl_table root_table
[] = {
205 .procname
= "kernel",
222 .child
= debug_table
,
230 * NOTE: do not add new entries to this table unless you have read
231 * Documentation/sysctl/ctl_unnumbered.txt
236 #ifdef CONFIG_SCHED_DEBUG
237 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
238 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
239 static int min_wakeup_granularity_ns
; /* 0 usecs */
240 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
241 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
242 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
243 static int min_sched_shares_ratelimit
= 100000; /* 100 usec */
244 static int max_sched_shares_ratelimit
= NSEC_PER_SEC
; /* 1 second */
247 static struct ctl_table kern_table
[] = {
249 .procname
= "sched_child_runs_first",
250 .data
= &sysctl_sched_child_runs_first
,
251 .maxlen
= sizeof(unsigned int),
253 .proc_handler
= proc_dointvec
,
255 #ifdef CONFIG_SCHED_DEBUG
257 .procname
= "sched_min_granularity_ns",
258 .data
= &sysctl_sched_min_granularity
,
259 .maxlen
= sizeof(unsigned int),
261 .proc_handler
= sched_proc_update_handler
,
262 .extra1
= &min_sched_granularity_ns
,
263 .extra2
= &max_sched_granularity_ns
,
266 .procname
= "sched_latency_ns",
267 .data
= &sysctl_sched_latency
,
268 .maxlen
= sizeof(unsigned int),
270 .proc_handler
= sched_proc_update_handler
,
271 .extra1
= &min_sched_granularity_ns
,
272 .extra2
= &max_sched_granularity_ns
,
275 .procname
= "sched_wakeup_granularity_ns",
276 .data
= &sysctl_sched_wakeup_granularity
,
277 .maxlen
= sizeof(unsigned int),
279 .proc_handler
= sched_proc_update_handler
,
280 .extra1
= &min_wakeup_granularity_ns
,
281 .extra2
= &max_wakeup_granularity_ns
,
284 .procname
= "sched_shares_ratelimit",
285 .data
= &sysctl_sched_shares_ratelimit
,
286 .maxlen
= sizeof(unsigned int),
288 .proc_handler
= sched_proc_update_handler
,
289 .extra1
= &min_sched_shares_ratelimit
,
290 .extra2
= &max_sched_shares_ratelimit
,
293 .procname
= "sched_tunable_scaling",
294 .data
= &sysctl_sched_tunable_scaling
,
295 .maxlen
= sizeof(enum sched_tunable_scaling
),
297 .proc_handler
= sched_proc_update_handler
,
298 .extra1
= &min_sched_tunable_scaling
,
299 .extra2
= &max_sched_tunable_scaling
,
302 .procname
= "sched_shares_thresh",
303 .data
= &sysctl_sched_shares_thresh
,
304 .maxlen
= sizeof(unsigned int),
306 .proc_handler
= proc_dointvec_minmax
,
310 .procname
= "sched_migration_cost",
311 .data
= &sysctl_sched_migration_cost
,
312 .maxlen
= sizeof(unsigned int),
314 .proc_handler
= proc_dointvec
,
317 .procname
= "sched_nr_migrate",
318 .data
= &sysctl_sched_nr_migrate
,
319 .maxlen
= sizeof(unsigned int),
321 .proc_handler
= proc_dointvec
,
324 .procname
= "sched_time_avg",
325 .data
= &sysctl_sched_time_avg
,
326 .maxlen
= sizeof(unsigned int),
328 .proc_handler
= proc_dointvec
,
331 .procname
= "timer_migration",
332 .data
= &sysctl_timer_migration
,
333 .maxlen
= sizeof(unsigned int),
335 .proc_handler
= proc_dointvec_minmax
,
341 .procname
= "sched_rt_period_us",
342 .data
= &sysctl_sched_rt_period
,
343 .maxlen
= sizeof(unsigned int),
345 .proc_handler
= sched_rt_handler
,
348 .procname
= "sched_rt_runtime_us",
349 .data
= &sysctl_sched_rt_runtime
,
350 .maxlen
= sizeof(int),
352 .proc_handler
= sched_rt_handler
,
355 .procname
= "sched_compat_yield",
356 .data
= &sysctl_sched_compat_yield
,
357 .maxlen
= sizeof(unsigned int),
359 .proc_handler
= proc_dointvec
,
361 #ifdef CONFIG_PROVE_LOCKING
363 .procname
= "prove_locking",
364 .data
= &prove_locking
,
365 .maxlen
= sizeof(int),
367 .proc_handler
= proc_dointvec
,
370 #ifdef CONFIG_LOCK_STAT
372 .procname
= "lock_stat",
374 .maxlen
= sizeof(int),
376 .proc_handler
= proc_dointvec
,
381 .data
= &panic_timeout
,
382 .maxlen
= sizeof(int),
384 .proc_handler
= proc_dointvec
,
387 .procname
= "core_uses_pid",
388 .data
= &core_uses_pid
,
389 .maxlen
= sizeof(int),
391 .proc_handler
= proc_dointvec
,
394 .procname
= "core_pattern",
395 .data
= core_pattern
,
396 .maxlen
= CORENAME_MAX_SIZE
,
398 .proc_handler
= proc_dostring
,
401 .procname
= "core_pipe_limit",
402 .data
= &core_pipe_limit
,
403 .maxlen
= sizeof(unsigned int),
405 .proc_handler
= proc_dointvec
,
407 #ifdef CONFIG_PROC_SYSCTL
409 .procname
= "tainted",
410 .maxlen
= sizeof(long),
412 .proc_handler
= proc_taint
,
415 #ifdef CONFIG_LATENCYTOP
417 .procname
= "latencytop",
418 .data
= &latencytop_enabled
,
419 .maxlen
= sizeof(int),
421 .proc_handler
= proc_dointvec
,
424 #ifdef CONFIG_BLK_DEV_INITRD
426 .procname
= "real-root-dev",
427 .data
= &real_root_dev
,
428 .maxlen
= sizeof(int),
430 .proc_handler
= proc_dointvec
,
434 .procname
= "print-fatal-signals",
435 .data
= &print_fatal_signals
,
436 .maxlen
= sizeof(int),
438 .proc_handler
= proc_dointvec
,
442 .procname
= "reboot-cmd",
443 .data
= reboot_command
,
446 .proc_handler
= proc_dostring
,
449 .procname
= "stop-a",
450 .data
= &stop_a_enabled
,
451 .maxlen
= sizeof (int),
453 .proc_handler
= proc_dointvec
,
456 .procname
= "scons-poweroff",
457 .data
= &scons_pwroff
,
458 .maxlen
= sizeof (int),
460 .proc_handler
= proc_dointvec
,
463 #ifdef CONFIG_SPARC64
465 .procname
= "tsb-ratio",
466 .data
= &sysctl_tsb_ratio
,
467 .maxlen
= sizeof (int),
469 .proc_handler
= proc_dointvec
,
474 .procname
= "soft-power",
475 .data
= &pwrsw_enabled
,
476 .maxlen
= sizeof (int),
478 .proc_handler
= proc_dointvec
,
481 .procname
= "unaligned-trap",
482 .data
= &unaligned_enabled
,
483 .maxlen
= sizeof (int),
485 .proc_handler
= proc_dointvec
,
489 .procname
= "ctrl-alt-del",
491 .maxlen
= sizeof(int),
493 .proc_handler
= proc_dointvec
,
495 #ifdef CONFIG_FUNCTION_TRACER
497 .procname
= "ftrace_enabled",
498 .data
= &ftrace_enabled
,
499 .maxlen
= sizeof(int),
501 .proc_handler
= ftrace_enable_sysctl
,
504 #ifdef CONFIG_STACK_TRACER
506 .procname
= "stack_tracer_enabled",
507 .data
= &stack_tracer_enabled
,
508 .maxlen
= sizeof(int),
510 .proc_handler
= stack_trace_sysctl
,
513 #ifdef CONFIG_TRACING
515 .procname
= "ftrace_dump_on_oops",
516 .data
= &ftrace_dump_on_oops
,
517 .maxlen
= sizeof(int),
519 .proc_handler
= proc_dointvec
,
522 #ifdef CONFIG_MODULES
524 .procname
= "modprobe",
525 .data
= &modprobe_path
,
526 .maxlen
= KMOD_PATH_LEN
,
528 .proc_handler
= proc_dostring
,
531 .procname
= "modules_disabled",
532 .data
= &modules_disabled
,
533 .maxlen
= sizeof(int),
535 /* only handle a transition from default "0" to "1" */
536 .proc_handler
= proc_dointvec_minmax
,
541 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
543 .procname
= "hotplug",
544 .data
= &uevent_helper
,
545 .maxlen
= UEVENT_HELPER_PATH_LEN
,
547 .proc_handler
= proc_dostring
,
550 #ifdef CONFIG_CHR_DEV_SG
552 .procname
= "sg-big-buff",
553 .data
= &sg_big_buff
,
554 .maxlen
= sizeof (int),
556 .proc_handler
= proc_dointvec
,
559 #ifdef CONFIG_BSD_PROCESS_ACCT
563 .maxlen
= 3*sizeof(int),
565 .proc_handler
= proc_dointvec
,
568 #ifdef CONFIG_MAGIC_SYSRQ
571 .data
= &__sysrq_enabled
,
572 .maxlen
= sizeof (int),
574 .proc_handler
= proc_dointvec
,
577 #ifdef CONFIG_PROC_SYSCTL
579 .procname
= "cad_pid",
581 .maxlen
= sizeof (int),
583 .proc_handler
= proc_do_cad_pid
,
587 .procname
= "threads-max",
588 .data
= &max_threads
,
589 .maxlen
= sizeof(int),
591 .proc_handler
= proc_dointvec
,
594 .procname
= "random",
596 .child
= random_table
,
599 .procname
= "overflowuid",
600 .data
= &overflowuid
,
601 .maxlen
= sizeof(int),
603 .proc_handler
= proc_dointvec_minmax
,
604 .extra1
= &minolduid
,
605 .extra2
= &maxolduid
,
608 .procname
= "overflowgid",
609 .data
= &overflowgid
,
610 .maxlen
= sizeof(int),
612 .proc_handler
= proc_dointvec_minmax
,
613 .extra1
= &minolduid
,
614 .extra2
= &maxolduid
,
617 #ifdef CONFIG_MATHEMU
619 .procname
= "ieee_emulation_warnings",
620 .data
= &sysctl_ieee_emulation_warnings
,
621 .maxlen
= sizeof(int),
623 .proc_handler
= proc_dointvec
,
627 .procname
= "userprocess_debug",
628 .data
= &sysctl_userprocess_debug
,
629 .maxlen
= sizeof(int),
631 .proc_handler
= proc_dointvec
,
635 .procname
= "pid_max",
637 .maxlen
= sizeof (int),
639 .proc_handler
= proc_dointvec_minmax
,
640 .extra1
= &pid_max_min
,
641 .extra2
= &pid_max_max
,
644 .procname
= "panic_on_oops",
645 .data
= &panic_on_oops
,
646 .maxlen
= sizeof(int),
648 .proc_handler
= proc_dointvec
,
650 #if defined CONFIG_PRINTK
652 .procname
= "printk",
653 .data
= &console_loglevel
,
654 .maxlen
= 4*sizeof(int),
656 .proc_handler
= proc_dointvec
,
659 .procname
= "printk_ratelimit",
660 .data
= &printk_ratelimit_state
.interval
,
661 .maxlen
= sizeof(int),
663 .proc_handler
= proc_dointvec_jiffies
,
666 .procname
= "printk_ratelimit_burst",
667 .data
= &printk_ratelimit_state
.burst
,
668 .maxlen
= sizeof(int),
670 .proc_handler
= proc_dointvec
,
673 .procname
= "printk_delay",
674 .data
= &printk_delay_msec
,
675 .maxlen
= sizeof(int),
677 .proc_handler
= proc_dointvec_minmax
,
679 .extra2
= &ten_thousand
,
683 .procname
= "ngroups_max",
684 .data
= &ngroups_max
,
685 .maxlen
= sizeof (int),
687 .proc_handler
= proc_dointvec
,
689 #if defined(CONFIG_LOCKUP_DETECTOR)
691 .procname
= "watchdog",
692 .data
= &watchdog_enabled
,
693 .maxlen
= sizeof (int),
695 .proc_handler
= proc_dowatchdog_enabled
,
698 .procname
= "watchdog_thresh",
699 .data
= &softlockup_thresh
,
700 .maxlen
= sizeof(int),
702 .proc_handler
= proc_dowatchdog_thresh
,
707 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
709 .procname
= "unknown_nmi_panic",
710 .data
= &unknown_nmi_panic
,
711 .maxlen
= sizeof (int),
713 .proc_handler
= proc_dointvec
,
716 .procname
= "nmi_watchdog",
717 .data
= &nmi_watchdog_enabled
,
718 .maxlen
= sizeof (int),
720 .proc_handler
= proc_nmi_enabled
,
723 #if defined(CONFIG_X86)
725 .procname
= "panic_on_unrecovered_nmi",
726 .data
= &panic_on_unrecovered_nmi
,
727 .maxlen
= sizeof(int),
729 .proc_handler
= proc_dointvec
,
732 .procname
= "panic_on_io_nmi",
733 .data
= &panic_on_io_nmi
,
734 .maxlen
= sizeof(int),
736 .proc_handler
= proc_dointvec
,
739 .procname
= "bootloader_type",
740 .data
= &bootloader_type
,
741 .maxlen
= sizeof (int),
743 .proc_handler
= proc_dointvec
,
746 .procname
= "bootloader_version",
747 .data
= &bootloader_version
,
748 .maxlen
= sizeof (int),
750 .proc_handler
= proc_dointvec
,
753 .procname
= "kstack_depth_to_print",
754 .data
= &kstack_depth_to_print
,
755 .maxlen
= sizeof(int),
757 .proc_handler
= proc_dointvec
,
760 .procname
= "io_delay_type",
761 .data
= &io_delay_type
,
762 .maxlen
= sizeof(int),
764 .proc_handler
= proc_dointvec
,
767 #if defined(CONFIG_MMU)
769 .procname
= "randomize_va_space",
770 .data
= &randomize_va_space
,
771 .maxlen
= sizeof(int),
773 .proc_handler
= proc_dointvec
,
776 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
778 .procname
= "spin_retry",
780 .maxlen
= sizeof (int),
782 .proc_handler
= proc_dointvec
,
785 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
787 .procname
= "acpi_video_flags",
788 .data
= &acpi_realmode_flags
,
789 .maxlen
= sizeof (unsigned long),
791 .proc_handler
= proc_doulongvec_minmax
,
796 .procname
= "ignore-unaligned-usertrap",
797 .data
= &no_unaligned_warning
,
798 .maxlen
= sizeof (int),
800 .proc_handler
= proc_dointvec
,
803 .procname
= "unaligned-dump-stack",
804 .data
= &unaligned_dump_stack
,
805 .maxlen
= sizeof (int),
807 .proc_handler
= proc_dointvec
,
810 #ifdef CONFIG_DETECT_SOFTLOCKUP
812 .procname
= "softlockup_panic",
813 .data
= &softlockup_panic
,
814 .maxlen
= sizeof(int),
816 .proc_handler
= proc_dointvec_minmax
,
821 .procname
= "softlockup_thresh",
822 .data
= &softlockup_thresh
,
823 .maxlen
= sizeof(int),
825 .proc_handler
= proc_dosoftlockup_thresh
,
830 #ifdef CONFIG_DETECT_HUNG_TASK
832 .procname
= "hung_task_panic",
833 .data
= &sysctl_hung_task_panic
,
834 .maxlen
= sizeof(int),
836 .proc_handler
= proc_dointvec_minmax
,
841 .procname
= "hung_task_check_count",
842 .data
= &sysctl_hung_task_check_count
,
843 .maxlen
= sizeof(unsigned long),
845 .proc_handler
= proc_doulongvec_minmax
,
848 .procname
= "hung_task_timeout_secs",
849 .data
= &sysctl_hung_task_timeout_secs
,
850 .maxlen
= sizeof(unsigned long),
852 .proc_handler
= proc_dohung_task_timeout_secs
,
855 .procname
= "hung_task_warnings",
856 .data
= &sysctl_hung_task_warnings
,
857 .maxlen
= sizeof(unsigned long),
859 .proc_handler
= proc_doulongvec_minmax
,
864 .procname
= "compat-log",
866 .maxlen
= sizeof (int),
868 .proc_handler
= proc_dointvec
,
871 #ifdef CONFIG_RT_MUTEXES
873 .procname
= "max_lock_depth",
874 .data
= &max_lock_depth
,
875 .maxlen
= sizeof(int),
877 .proc_handler
= proc_dointvec
,
881 .procname
= "poweroff_cmd",
882 .data
= &poweroff_cmd
,
883 .maxlen
= POWEROFF_CMD_PATH_LEN
,
885 .proc_handler
= proc_dostring
,
891 .child
= key_sysctls
,
894 #ifdef CONFIG_RCU_TORTURE_TEST
896 .procname
= "rcutorture_runnable",
897 .data
= &rcutorture_runnable
,
898 .maxlen
= sizeof(int),
900 .proc_handler
= proc_dointvec
,
903 #ifdef CONFIG_SLOW_WORK
905 .procname
= "slow-work",
907 .child
= slow_work_sysctls
,
910 #ifdef CONFIG_PERF_EVENTS
912 .procname
= "perf_event_paranoid",
913 .data
= &sysctl_perf_event_paranoid
,
914 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
916 .proc_handler
= proc_dointvec
,
919 .procname
= "perf_event_mlock_kb",
920 .data
= &sysctl_perf_event_mlock
,
921 .maxlen
= sizeof(sysctl_perf_event_mlock
),
923 .proc_handler
= proc_dointvec
,
926 .procname
= "perf_event_max_sample_rate",
927 .data
= &sysctl_perf_event_sample_rate
,
928 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
930 .proc_handler
= proc_dointvec
,
933 #ifdef CONFIG_KMEMCHECK
935 .procname
= "kmemcheck",
936 .data
= &kmemcheck_enabled
,
937 .maxlen
= sizeof(int),
939 .proc_handler
= proc_dointvec
,
944 .procname
= "blk_iopoll",
945 .data
= &blk_iopoll_enabled
,
946 .maxlen
= sizeof(int),
948 .proc_handler
= proc_dointvec
,
952 * NOTE: do not add new entries to this table unless you have read
953 * Documentation/sysctl/ctl_unnumbered.txt
958 static struct ctl_table vm_table
[] = {
960 .procname
= "overcommit_memory",
961 .data
= &sysctl_overcommit_memory
,
962 .maxlen
= sizeof(sysctl_overcommit_memory
),
964 .proc_handler
= proc_dointvec
,
967 .procname
= "panic_on_oom",
968 .data
= &sysctl_panic_on_oom
,
969 .maxlen
= sizeof(sysctl_panic_on_oom
),
971 .proc_handler
= proc_dointvec
,
974 .procname
= "oom_kill_allocating_task",
975 .data
= &sysctl_oom_kill_allocating_task
,
976 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
978 .proc_handler
= proc_dointvec
,
981 .procname
= "oom_dump_tasks",
982 .data
= &sysctl_oom_dump_tasks
,
983 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
985 .proc_handler
= proc_dointvec
,
988 .procname
= "overcommit_ratio",
989 .data
= &sysctl_overcommit_ratio
,
990 .maxlen
= sizeof(sysctl_overcommit_ratio
),
992 .proc_handler
= proc_dointvec
,
995 .procname
= "page-cluster",
996 .data
= &page_cluster
,
997 .maxlen
= sizeof(int),
999 .proc_handler
= proc_dointvec
,
1002 .procname
= "dirty_background_ratio",
1003 .data
= &dirty_background_ratio
,
1004 .maxlen
= sizeof(dirty_background_ratio
),
1006 .proc_handler
= dirty_background_ratio_handler
,
1008 .extra2
= &one_hundred
,
1011 .procname
= "dirty_background_bytes",
1012 .data
= &dirty_background_bytes
,
1013 .maxlen
= sizeof(dirty_background_bytes
),
1015 .proc_handler
= dirty_background_bytes_handler
,
1019 .procname
= "dirty_ratio",
1020 .data
= &vm_dirty_ratio
,
1021 .maxlen
= sizeof(vm_dirty_ratio
),
1023 .proc_handler
= dirty_ratio_handler
,
1025 .extra2
= &one_hundred
,
1028 .procname
= "dirty_bytes",
1029 .data
= &vm_dirty_bytes
,
1030 .maxlen
= sizeof(vm_dirty_bytes
),
1032 .proc_handler
= dirty_bytes_handler
,
1033 .extra1
= &dirty_bytes_min
,
1036 .procname
= "dirty_writeback_centisecs",
1037 .data
= &dirty_writeback_interval
,
1038 .maxlen
= sizeof(dirty_writeback_interval
),
1040 .proc_handler
= dirty_writeback_centisecs_handler
,
1043 .procname
= "dirty_expire_centisecs",
1044 .data
= &dirty_expire_interval
,
1045 .maxlen
= sizeof(dirty_expire_interval
),
1047 .proc_handler
= proc_dointvec
,
1050 .procname
= "nr_pdflush_threads",
1051 .data
= &nr_pdflush_threads
,
1052 .maxlen
= sizeof nr_pdflush_threads
,
1053 .mode
= 0444 /* read-only*/,
1054 .proc_handler
= proc_dointvec
,
1057 .procname
= "swappiness",
1058 .data
= &vm_swappiness
,
1059 .maxlen
= sizeof(vm_swappiness
),
1061 .proc_handler
= proc_dointvec_minmax
,
1063 .extra2
= &one_hundred
,
1065 #ifdef CONFIG_HUGETLB_PAGE
1067 .procname
= "nr_hugepages",
1069 .maxlen
= sizeof(unsigned long),
1071 .proc_handler
= hugetlb_sysctl_handler
,
1072 .extra1
= (void *)&hugetlb_zero
,
1073 .extra2
= (void *)&hugetlb_infinity
,
1077 .procname
= "nr_hugepages_mempolicy",
1079 .maxlen
= sizeof(unsigned long),
1081 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1082 .extra1
= (void *)&hugetlb_zero
,
1083 .extra2
= (void *)&hugetlb_infinity
,
1087 .procname
= "hugetlb_shm_group",
1088 .data
= &sysctl_hugetlb_shm_group
,
1089 .maxlen
= sizeof(gid_t
),
1091 .proc_handler
= proc_dointvec
,
1094 .procname
= "hugepages_treat_as_movable",
1095 .data
= &hugepages_treat_as_movable
,
1096 .maxlen
= sizeof(int),
1098 .proc_handler
= hugetlb_treat_movable_handler
,
1101 .procname
= "nr_overcommit_hugepages",
1103 .maxlen
= sizeof(unsigned long),
1105 .proc_handler
= hugetlb_overcommit_handler
,
1106 .extra1
= (void *)&hugetlb_zero
,
1107 .extra2
= (void *)&hugetlb_infinity
,
1111 .procname
= "lowmem_reserve_ratio",
1112 .data
= &sysctl_lowmem_reserve_ratio
,
1113 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1115 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1118 .procname
= "drop_caches",
1119 .data
= &sysctl_drop_caches
,
1120 .maxlen
= sizeof(int),
1122 .proc_handler
= drop_caches_sysctl_handler
,
1125 .procname
= "min_free_kbytes",
1126 .data
= &min_free_kbytes
,
1127 .maxlen
= sizeof(min_free_kbytes
),
1129 .proc_handler
= min_free_kbytes_sysctl_handler
,
1133 .procname
= "percpu_pagelist_fraction",
1134 .data
= &percpu_pagelist_fraction
,
1135 .maxlen
= sizeof(percpu_pagelist_fraction
),
1137 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1138 .extra1
= &min_percpu_pagelist_fract
,
1142 .procname
= "max_map_count",
1143 .data
= &sysctl_max_map_count
,
1144 .maxlen
= sizeof(sysctl_max_map_count
),
1146 .proc_handler
= proc_dointvec_minmax
,
1151 .procname
= "nr_trim_pages",
1152 .data
= &sysctl_nr_trim_pages
,
1153 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1155 .proc_handler
= proc_dointvec_minmax
,
1160 .procname
= "laptop_mode",
1161 .data
= &laptop_mode
,
1162 .maxlen
= sizeof(laptop_mode
),
1164 .proc_handler
= proc_dointvec_jiffies
,
1167 .procname
= "block_dump",
1168 .data
= &block_dump
,
1169 .maxlen
= sizeof(block_dump
),
1171 .proc_handler
= proc_dointvec
,
1175 .procname
= "vfs_cache_pressure",
1176 .data
= &sysctl_vfs_cache_pressure
,
1177 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1179 .proc_handler
= proc_dointvec
,
1182 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1184 .procname
= "legacy_va_layout",
1185 .data
= &sysctl_legacy_va_layout
,
1186 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1188 .proc_handler
= proc_dointvec
,
1194 .procname
= "zone_reclaim_mode",
1195 .data
= &zone_reclaim_mode
,
1196 .maxlen
= sizeof(zone_reclaim_mode
),
1198 .proc_handler
= proc_dointvec
,
1202 .procname
= "min_unmapped_ratio",
1203 .data
= &sysctl_min_unmapped_ratio
,
1204 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1206 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1208 .extra2
= &one_hundred
,
1211 .procname
= "min_slab_ratio",
1212 .data
= &sysctl_min_slab_ratio
,
1213 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1215 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1217 .extra2
= &one_hundred
,
1222 .procname
= "stat_interval",
1223 .data
= &sysctl_stat_interval
,
1224 .maxlen
= sizeof(sysctl_stat_interval
),
1226 .proc_handler
= proc_dointvec_jiffies
,
1231 .procname
= "mmap_min_addr",
1232 .data
= &dac_mmap_min_addr
,
1233 .maxlen
= sizeof(unsigned long),
1235 .proc_handler
= mmap_min_addr_handler
,
1240 .procname
= "numa_zonelist_order",
1241 .data
= &numa_zonelist_order
,
1242 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1244 .proc_handler
= numa_zonelist_order_handler
,
1247 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1248 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1250 .procname
= "vdso_enabled",
1251 .data
= &vdso_enabled
,
1252 .maxlen
= sizeof(vdso_enabled
),
1254 .proc_handler
= proc_dointvec
,
1258 #ifdef CONFIG_HIGHMEM
1260 .procname
= "highmem_is_dirtyable",
1261 .data
= &vm_highmem_is_dirtyable
,
1262 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1264 .proc_handler
= proc_dointvec_minmax
,
1270 .procname
= "scan_unevictable_pages",
1271 .data
= &scan_unevictable_pages
,
1272 .maxlen
= sizeof(scan_unevictable_pages
),
1274 .proc_handler
= scan_unevictable_handler
,
1276 #ifdef CONFIG_MEMORY_FAILURE
1278 .procname
= "memory_failure_early_kill",
1279 .data
= &sysctl_memory_failure_early_kill
,
1280 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1282 .proc_handler
= proc_dointvec_minmax
,
1287 .procname
= "memory_failure_recovery",
1288 .data
= &sysctl_memory_failure_recovery
,
1289 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1291 .proc_handler
= proc_dointvec_minmax
,
1298 * NOTE: do not add new entries to this table unless you have read
1299 * Documentation/sysctl/ctl_unnumbered.txt
1304 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1305 static struct ctl_table binfmt_misc_table
[] = {
1310 static struct ctl_table fs_table
[] = {
1312 .procname
= "inode-nr",
1313 .data
= &inodes_stat
,
1314 .maxlen
= 2*sizeof(int),
1316 .proc_handler
= proc_dointvec
,
1319 .procname
= "inode-state",
1320 .data
= &inodes_stat
,
1321 .maxlen
= 7*sizeof(int),
1323 .proc_handler
= proc_dointvec
,
1326 .procname
= "file-nr",
1327 .data
= &files_stat
,
1328 .maxlen
= 3*sizeof(int),
1330 .proc_handler
= proc_nr_files
,
1333 .procname
= "file-max",
1334 .data
= &files_stat
.max_files
,
1335 .maxlen
= sizeof(int),
1337 .proc_handler
= proc_dointvec
,
1340 .procname
= "nr_open",
1341 .data
= &sysctl_nr_open
,
1342 .maxlen
= sizeof(int),
1344 .proc_handler
= proc_dointvec_minmax
,
1345 .extra1
= &sysctl_nr_open_min
,
1346 .extra2
= &sysctl_nr_open_max
,
1349 .procname
= "dentry-state",
1350 .data
= &dentry_stat
,
1351 .maxlen
= 6*sizeof(int),
1353 .proc_handler
= proc_dointvec
,
1356 .procname
= "overflowuid",
1357 .data
= &fs_overflowuid
,
1358 .maxlen
= sizeof(int),
1360 .proc_handler
= proc_dointvec_minmax
,
1361 .extra1
= &minolduid
,
1362 .extra2
= &maxolduid
,
1365 .procname
= "overflowgid",
1366 .data
= &fs_overflowgid
,
1367 .maxlen
= sizeof(int),
1369 .proc_handler
= proc_dointvec_minmax
,
1370 .extra1
= &minolduid
,
1371 .extra2
= &maxolduid
,
1373 #ifdef CONFIG_FILE_LOCKING
1375 .procname
= "leases-enable",
1376 .data
= &leases_enable
,
1377 .maxlen
= sizeof(int),
1379 .proc_handler
= proc_dointvec
,
1382 #ifdef CONFIG_DNOTIFY
1384 .procname
= "dir-notify-enable",
1385 .data
= &dir_notify_enable
,
1386 .maxlen
= sizeof(int),
1388 .proc_handler
= proc_dointvec
,
1392 #ifdef CONFIG_FILE_LOCKING
1394 .procname
= "lease-break-time",
1395 .data
= &lease_break_time
,
1396 .maxlen
= sizeof(int),
1398 .proc_handler
= proc_dointvec
,
1403 .procname
= "aio-nr",
1405 .maxlen
= sizeof(aio_nr
),
1407 .proc_handler
= proc_doulongvec_minmax
,
1410 .procname
= "aio-max-nr",
1411 .data
= &aio_max_nr
,
1412 .maxlen
= sizeof(aio_max_nr
),
1414 .proc_handler
= proc_doulongvec_minmax
,
1416 #endif /* CONFIG_AIO */
1417 #ifdef CONFIG_INOTIFY_USER
1419 .procname
= "inotify",
1421 .child
= inotify_table
,
1426 .procname
= "epoll",
1428 .child
= epoll_table
,
1433 .procname
= "suid_dumpable",
1434 .data
= &suid_dumpable
,
1435 .maxlen
= sizeof(int),
1437 .proc_handler
= proc_dointvec_minmax
,
1441 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1443 .procname
= "binfmt_misc",
1445 .child
= binfmt_misc_table
,
1449 * NOTE: do not add new entries to this table unless you have read
1450 * Documentation/sysctl/ctl_unnumbered.txt
1455 static struct ctl_table debug_table
[] = {
1456 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
1458 .procname
= "exception-trace",
1459 .data
= &show_unhandled_signals
,
1460 .maxlen
= sizeof(int),
1462 .proc_handler
= proc_dointvec
1465 #if defined(CONFIG_OPTPROBES)
1467 .procname
= "kprobes-optimization",
1468 .data
= &sysctl_kprobes_optimization
,
1469 .maxlen
= sizeof(int),
1471 .proc_handler
= proc_kprobes_optimization_handler
,
1479 static struct ctl_table dev_table
[] = {
1483 static DEFINE_SPINLOCK(sysctl_lock
);
1485 /* called under sysctl_lock */
1486 static int use_table(struct ctl_table_header
*p
)
1488 if (unlikely(p
->unregistering
))
1494 /* called under sysctl_lock */
1495 static void unuse_table(struct ctl_table_header
*p
)
1498 if (unlikely(p
->unregistering
))
1499 complete(p
->unregistering
);
1502 /* called under sysctl_lock, will reacquire if has to wait */
1503 static void start_unregistering(struct ctl_table_header
*p
)
1506 * if p->used is 0, nobody will ever touch that entry again;
1507 * we'll eliminate all paths to it before dropping sysctl_lock
1509 if (unlikely(p
->used
)) {
1510 struct completion wait
;
1511 init_completion(&wait
);
1512 p
->unregistering
= &wait
;
1513 spin_unlock(&sysctl_lock
);
1514 wait_for_completion(&wait
);
1515 spin_lock(&sysctl_lock
);
1517 /* anything non-NULL; we'll never dereference it */
1518 p
->unregistering
= ERR_PTR(-EINVAL
);
1521 * do not remove from the list until nobody holds it; walking the
1522 * list in do_sysctl() relies on that.
1524 list_del_init(&p
->ctl_entry
);
1527 void sysctl_head_get(struct ctl_table_header
*head
)
1529 spin_lock(&sysctl_lock
);
1531 spin_unlock(&sysctl_lock
);
1534 void sysctl_head_put(struct ctl_table_header
*head
)
1536 spin_lock(&sysctl_lock
);
1539 spin_unlock(&sysctl_lock
);
1542 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1546 spin_lock(&sysctl_lock
);
1547 if (!use_table(head
))
1548 head
= ERR_PTR(-ENOENT
);
1549 spin_unlock(&sysctl_lock
);
1553 void sysctl_head_finish(struct ctl_table_header
*head
)
1557 spin_lock(&sysctl_lock
);
1559 spin_unlock(&sysctl_lock
);
1562 static struct ctl_table_set
*
1563 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1565 struct ctl_table_set
*set
= &root
->default_set
;
1567 set
= root
->lookup(root
, namespaces
);
1571 static struct list_head
*
1572 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1574 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1578 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1579 struct ctl_table_header
*prev
)
1581 struct ctl_table_root
*root
;
1582 struct list_head
*header_list
;
1583 struct ctl_table_header
*head
;
1584 struct list_head
*tmp
;
1586 spin_lock(&sysctl_lock
);
1589 tmp
= &prev
->ctl_entry
;
1593 tmp
= &root_table_header
.ctl_entry
;
1595 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1597 if (!use_table(head
))
1599 spin_unlock(&sysctl_lock
);
1604 header_list
= lookup_header_list(root
, namespaces
);
1605 if (tmp
!= header_list
)
1609 root
= list_entry(root
->root_list
.next
,
1610 struct ctl_table_root
, root_list
);
1611 if (root
== &sysctl_table_root
)
1613 header_list
= lookup_header_list(root
, namespaces
);
1614 } while (list_empty(header_list
));
1615 tmp
= header_list
->next
;
1618 spin_unlock(&sysctl_lock
);
1622 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1624 return __sysctl_head_next(current
->nsproxy
, prev
);
1627 void register_sysctl_root(struct ctl_table_root
*root
)
1629 spin_lock(&sysctl_lock
);
1630 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1631 spin_unlock(&sysctl_lock
);
1635 * sysctl_perm does NOT grant the superuser all rights automatically, because
1636 * some sysctl variables are readonly even to root.
1639 static int test_perm(int mode
, int op
)
1641 if (!current_euid())
1643 else if (in_egroup_p(0))
1645 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1650 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1655 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1659 if (root
->permissions
)
1660 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1664 return test_perm(mode
, op
);
1667 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1669 for (; table
->procname
; table
++) {
1670 table
->parent
= parent
;
1672 sysctl_set_parent(table
, table
->child
);
1676 static __init
int sysctl_init(void)
1678 sysctl_set_parent(NULL
, root_table
);
1679 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1682 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1688 core_initcall(sysctl_init
);
1690 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1691 struct ctl_table
*table
)
1693 struct ctl_table
*p
;
1694 const char *s
= branch
->procname
;
1696 /* branch should have named subdirectory as its first element */
1697 if (!s
|| !branch
->child
)
1700 /* ... and nothing else */
1701 if (branch
[1].procname
)
1704 /* table should contain subdirectory with the same name */
1705 for (p
= table
; p
->procname
; p
++) {
1708 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1714 /* see if attaching q to p would be an improvement */
1715 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1717 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1718 struct ctl_table
*next
;
1720 int not_in_parent
= !p
->attached_by
;
1722 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1723 if (by
== q
->attached_by
)
1725 if (to
== p
->attached_by
)
1731 if (is_better
&& not_in_parent
) {
1732 q
->attached_by
= by
;
1733 q
->attached_to
= to
;
1739 * __register_sysctl_paths - register a sysctl hierarchy
1740 * @root: List of sysctl headers to register on
1741 * @namespaces: Data to compute which lists of sysctl entries are visible
1742 * @path: The path to the directory the sysctl table is in.
1743 * @table: the top-level table structure
1745 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1746 * array. A completely 0 filled entry terminates the table.
1748 * The members of the &struct ctl_table structure are used as follows:
1750 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1751 * enter a sysctl file
1753 * data - a pointer to data for use by proc_handler
1755 * maxlen - the maximum size in bytes of the data
1757 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1759 * child - a pointer to the child sysctl table if this entry is a directory, or
1762 * proc_handler - the text handler routine (described below)
1764 * de - for internal use by the sysctl routines
1766 * extra1, extra2 - extra pointers usable by the proc handler routines
1768 * Leaf nodes in the sysctl tree will be represented by a single file
1769 * under /proc; non-leaf nodes will be represented by directories.
1771 * sysctl(2) can automatically manage read and write requests through
1772 * the sysctl table. The data and maxlen fields of the ctl_table
1773 * struct enable minimal validation of the values being written to be
1774 * performed, and the mode field allows minimal authentication.
1776 * There must be a proc_handler routine for any terminal nodes
1777 * mirrored under /proc/sys (non-terminals are handled by a built-in
1778 * directory handler). Several default handlers are available to
1779 * cover common cases -
1781 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1782 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1783 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1785 * It is the handler's job to read the input buffer from user memory
1786 * and process it. The handler should return 0 on success.
1788 * This routine returns %NULL on a failure to register, and a pointer
1789 * to the table header on success.
1791 struct ctl_table_header
*__register_sysctl_paths(
1792 struct ctl_table_root
*root
,
1793 struct nsproxy
*namespaces
,
1794 const struct ctl_path
*path
, struct ctl_table
*table
)
1796 struct ctl_table_header
*header
;
1797 struct ctl_table
*new, **prevp
;
1798 unsigned int n
, npath
;
1799 struct ctl_table_set
*set
;
1801 /* Count the path components */
1802 for (npath
= 0; path
[npath
].procname
; ++npath
)
1806 * For each path component, allocate a 2-element ctl_table array.
1807 * The first array element will be filled with the sysctl entry
1808 * for this, the second will be the sentinel (procname == 0).
1810 * We allocate everything in one go so that we don't have to
1811 * worry about freeing additional memory in unregister_sysctl_table.
1813 header
= kzalloc(sizeof(struct ctl_table_header
) +
1814 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1818 new = (struct ctl_table
*) (header
+ 1);
1820 /* Now connect the dots */
1821 prevp
= &header
->ctl_table
;
1822 for (n
= 0; n
< npath
; ++n
, ++path
) {
1823 /* Copy the procname */
1824 new->procname
= path
->procname
;
1828 prevp
= &new->child
;
1833 header
->ctl_table_arg
= table
;
1835 INIT_LIST_HEAD(&header
->ctl_entry
);
1837 header
->unregistering
= NULL
;
1838 header
->root
= root
;
1839 sysctl_set_parent(NULL
, header
->ctl_table
);
1841 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1842 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1847 spin_lock(&sysctl_lock
);
1848 header
->set
= lookup_header_set(root
, namespaces
);
1849 header
->attached_by
= header
->ctl_table
;
1850 header
->attached_to
= root_table
;
1851 header
->parent
= &root_table_header
;
1852 for (set
= header
->set
; set
; set
= set
->parent
) {
1853 struct ctl_table_header
*p
;
1854 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1855 if (p
->unregistering
)
1857 try_attach(p
, header
);
1860 header
->parent
->count
++;
1861 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1862 spin_unlock(&sysctl_lock
);
1868 * register_sysctl_table_path - register a sysctl table hierarchy
1869 * @path: The path to the directory the sysctl table is in.
1870 * @table: the top-level table structure
1872 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1873 * array. A completely 0 filled entry terminates the table.
1875 * See __register_sysctl_paths for more details.
1877 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1878 struct ctl_table
*table
)
1880 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1885 * register_sysctl_table - register a sysctl table hierarchy
1886 * @table: the top-level table structure
1888 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1889 * array. A completely 0 filled entry terminates the table.
1891 * See register_sysctl_paths for more details.
1893 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1895 static const struct ctl_path null_path
[] = { {} };
1897 return register_sysctl_paths(null_path
, table
);
1901 * unregister_sysctl_table - unregister a sysctl table hierarchy
1902 * @header: the header returned from register_sysctl_table
1904 * Unregisters the sysctl table and all children. proc entries may not
1905 * actually be removed until they are no longer used by anyone.
1907 void unregister_sysctl_table(struct ctl_table_header
* header
)
1914 spin_lock(&sysctl_lock
);
1915 start_unregistering(header
);
1916 if (!--header
->parent
->count
) {
1918 kfree(header
->parent
);
1920 if (!--header
->count
)
1922 spin_unlock(&sysctl_lock
);
1925 int sysctl_is_seen(struct ctl_table_header
*p
)
1927 struct ctl_table_set
*set
= p
->set
;
1929 spin_lock(&sysctl_lock
);
1930 if (p
->unregistering
)
1932 else if (!set
->is_seen
)
1935 res
= set
->is_seen(set
);
1936 spin_unlock(&sysctl_lock
);
1940 void setup_sysctl_set(struct ctl_table_set
*p
,
1941 struct ctl_table_set
*parent
,
1942 int (*is_seen
)(struct ctl_table_set
*))
1944 INIT_LIST_HEAD(&p
->list
);
1945 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1946 p
->is_seen
= is_seen
;
1949 #else /* !CONFIG_SYSCTL */
1950 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1955 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1956 struct ctl_table
*table
)
1961 void unregister_sysctl_table(struct ctl_table_header
* table
)
1965 void setup_sysctl_set(struct ctl_table_set
*p
,
1966 struct ctl_table_set
*parent
,
1967 int (*is_seen
)(struct ctl_table_set
*))
1971 void sysctl_head_put(struct ctl_table_header
*head
)
1975 #endif /* CONFIG_SYSCTL */
1981 #ifdef CONFIG_PROC_SYSCTL
1983 static int _proc_do_string(void* data
, int maxlen
, int write
,
1984 void __user
*buffer
,
1985 size_t *lenp
, loff_t
*ppos
)
1991 if (!data
|| !maxlen
|| !*lenp
) {
1999 while (len
< *lenp
) {
2000 if (get_user(c
, p
++))
2002 if (c
== 0 || c
== '\n')
2008 if(copy_from_user(data
, buffer
, len
))
2010 ((char *) data
)[len
] = 0;
2028 if(copy_to_user(buffer
, data
, len
))
2031 if(put_user('\n', ((char __user
*) buffer
) + len
))
2042 * proc_dostring - read a string sysctl
2043 * @table: the sysctl table
2044 * @write: %TRUE if this is a write to the sysctl file
2045 * @buffer: the user buffer
2046 * @lenp: the size of the user buffer
2047 * @ppos: file position
2049 * Reads/writes a string from/to the user buffer. If the kernel
2050 * buffer provided is not large enough to hold the string, the
2051 * string is truncated. The copied string is %NULL-terminated.
2052 * If the string is being read by the user process, it is copied
2053 * and a newline '\n' is added. It is truncated if the buffer is
2056 * Returns 0 on success.
2058 int proc_dostring(struct ctl_table
*table
, int write
,
2059 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2061 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2062 buffer
, lenp
, ppos
);
2066 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
2068 int write
, void *data
)
2071 *valp
= *negp
? -*lvalp
: *lvalp
;
2076 *lvalp
= (unsigned long)-val
;
2079 *lvalp
= (unsigned long)val
;
2085 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2086 int write
, void __user
*buffer
,
2087 size_t *lenp
, loff_t
*ppos
,
2088 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2089 int write
, void *data
),
2092 #define TMPBUFLEN 21
2093 int *i
, vleft
, first
= 1, neg
;
2097 char buf
[TMPBUFLEN
], *p
;
2098 char __user
*s
= buffer
;
2100 if (!tbl_data
|| !table
->maxlen
|| !*lenp
||
2101 (*ppos
&& !write
)) {
2106 i
= (int *) tbl_data
;
2107 vleft
= table
->maxlen
/ sizeof(*i
);
2111 conv
= do_proc_dointvec_conv
;
2113 for (; left
&& vleft
--; i
++, first
=0) {
2128 if (len
> sizeof(buf
) - 1)
2129 len
= sizeof(buf
) - 1;
2130 if (copy_from_user(buf
, s
, len
))
2134 if (*p
== '-' && left
> 1) {
2138 if (*p
< '0' || *p
> '9')
2141 lval
= simple_strtoul(p
, &p
, 0);
2144 if ((len
< left
) && *p
&& !isspace(*p
))
2149 if (conv(&neg
, &lval
, i
, 1, data
))
2156 if (conv(&neg
, &lval
, i
, 0, data
))
2159 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
2163 if(copy_to_user(s
, buf
, len
))
2170 if (!write
&& !first
&& left
) {
2171 if(put_user('\n', s
))
2178 if (get_user(c
, s
++))
2193 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2194 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2195 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
2196 int write
, void *data
),
2199 return __do_proc_dointvec(table
->data
, table
, write
,
2200 buffer
, lenp
, ppos
, conv
, data
);
2204 * proc_dointvec - read a vector of integers
2205 * @table: the sysctl table
2206 * @write: %TRUE if this is a write to the sysctl file
2207 * @buffer: the user buffer
2208 * @lenp: the size of the user buffer
2209 * @ppos: file position
2211 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2212 * values from/to the user buffer, treated as an ASCII string.
2214 * Returns 0 on success.
2216 int proc_dointvec(struct ctl_table
*table
, int write
,
2217 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2219 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2224 * Taint values can only be increased
2225 * This means we can safely use a temporary.
2227 static int proc_taint(struct ctl_table
*table
, int write
,
2228 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2231 unsigned long tmptaint
= get_taint();
2234 if (write
&& !capable(CAP_SYS_ADMIN
))
2239 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2245 * Poor man's atomic or. Not worth adding a primitive
2246 * to everyone's atomic.h for this
2249 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2250 if ((tmptaint
>> i
) & 1)
2258 struct do_proc_dointvec_minmax_conv_param
{
2263 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
2265 int write
, void *data
)
2267 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2269 int val
= *negp
? -*lvalp
: *lvalp
;
2270 if ((param
->min
&& *param
->min
> val
) ||
2271 (param
->max
&& *param
->max
< val
))
2278 *lvalp
= (unsigned long)-val
;
2281 *lvalp
= (unsigned long)val
;
2288 * proc_dointvec_minmax - read a vector of integers with min/max values
2289 * @table: the sysctl table
2290 * @write: %TRUE if this is a write to the sysctl file
2291 * @buffer: the user buffer
2292 * @lenp: the size of the user buffer
2293 * @ppos: file position
2295 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2296 * values from/to the user buffer, treated as an ASCII string.
2298 * This routine will ensure the values are within the range specified by
2299 * table->extra1 (min) and table->extra2 (max).
2301 * Returns 0 on success.
2303 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2304 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2306 struct do_proc_dointvec_minmax_conv_param param
= {
2307 .min
= (int *) table
->extra1
,
2308 .max
= (int *) table
->extra2
,
2310 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2311 do_proc_dointvec_minmax_conv
, ¶m
);
2314 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2315 void __user
*buffer
,
2316 size_t *lenp
, loff_t
*ppos
,
2317 unsigned long convmul
,
2318 unsigned long convdiv
)
2320 #define TMPBUFLEN 21
2321 unsigned long *i
, *min
, *max
, val
;
2322 int vleft
, first
=1, neg
;
2324 char buf
[TMPBUFLEN
], *p
;
2325 char __user
*s
= buffer
;
2327 if (!data
|| !table
->maxlen
|| !*lenp
||
2328 (*ppos
&& !write
)) {
2333 i
= (unsigned long *) data
;
2334 min
= (unsigned long *) table
->extra1
;
2335 max
= (unsigned long *) table
->extra2
;
2336 vleft
= table
->maxlen
/ sizeof(unsigned long);
2339 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2354 if (len
> TMPBUFLEN
-1)
2356 if (copy_from_user(buf
, s
, len
))
2360 if (*p
== '-' && left
> 1) {
2364 if (*p
< '0' || *p
> '9')
2366 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2368 if ((len
< left
) && *p
&& !isspace(*p
))
2377 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2384 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2388 if(copy_to_user(s
, buf
, len
))
2395 if (!write
&& !first
&& left
) {
2396 if(put_user('\n', s
))
2403 if (get_user(c
, s
++))
2418 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2419 void __user
*buffer
,
2420 size_t *lenp
, loff_t
*ppos
,
2421 unsigned long convmul
,
2422 unsigned long convdiv
)
2424 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2425 buffer
, lenp
, ppos
, convmul
, convdiv
);
2429 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2430 * @table: the sysctl table
2431 * @write: %TRUE if this is a write to the sysctl file
2432 * @buffer: the user buffer
2433 * @lenp: the size of the user buffer
2434 * @ppos: file position
2436 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2437 * values from/to the user buffer, treated as an ASCII string.
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_minmax(struct ctl_table
*table
, int write
,
2445 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2447 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2451 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2452 * @table: the sysctl table
2453 * @write: %TRUE if this is a write to the sysctl file
2454 * @buffer: the user buffer
2455 * @lenp: the size of the user buffer
2456 * @ppos: file position
2458 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2459 * values from/to the user buffer, treated as an ASCII string. The values
2460 * are treated as milliseconds, and converted to jiffies when they are stored.
2462 * This routine will ensure the values are within the range specified by
2463 * table->extra1 (min) and table->extra2 (max).
2465 * Returns 0 on success.
2467 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2468 void __user
*buffer
,
2469 size_t *lenp
, loff_t
*ppos
)
2471 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2472 lenp
, ppos
, HZ
, 1000l);
2476 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2478 int write
, void *data
)
2481 if (*lvalp
> LONG_MAX
/ HZ
)
2483 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2489 lval
= (unsigned long)-val
;
2492 lval
= (unsigned long)val
;
2499 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2501 int write
, void *data
)
2504 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2506 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2512 lval
= (unsigned long)-val
;
2515 lval
= (unsigned long)val
;
2517 *lvalp
= jiffies_to_clock_t(lval
);
2522 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2524 int write
, void *data
)
2527 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2533 lval
= (unsigned long)-val
;
2536 lval
= (unsigned long)val
;
2538 *lvalp
= jiffies_to_msecs(lval
);
2544 * proc_dointvec_jiffies - read a vector of integers as seconds
2545 * @table: the sysctl table
2546 * @write: %TRUE if this is a write to the sysctl file
2547 * @buffer: the user buffer
2548 * @lenp: the size of the user buffer
2549 * @ppos: file position
2551 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2552 * values from/to the user buffer, treated as an ASCII string.
2553 * The values read are assumed to be in seconds, and are converted into
2556 * Returns 0 on success.
2558 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2559 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2561 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2562 do_proc_dointvec_jiffies_conv
,NULL
);
2566 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2567 * @table: the sysctl table
2568 * @write: %TRUE if this is a write to the sysctl file
2569 * @buffer: the user buffer
2570 * @lenp: the size of the user buffer
2571 * @ppos: pointer to the file position
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/USER_HZ seconds, and
2576 * are converted into jiffies.
2578 * Returns 0 on success.
2580 int proc_dointvec_userhz_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_userhz_jiffies_conv
,NULL
);
2588 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2589 * @table: the sysctl table
2590 * @write: %TRUE if this is a write to the sysctl file
2591 * @buffer: the user buffer
2592 * @lenp: the size of the user buffer
2593 * @ppos: file position
2594 * @ppos: the current position in the file
2596 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2597 * values from/to the user buffer, treated as an ASCII string.
2598 * The values read are assumed to be in 1/1000 seconds, and
2599 * are converted into jiffies.
2601 * Returns 0 on success.
2603 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2604 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2606 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2607 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2610 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2611 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2613 struct pid
*new_pid
;
2617 tmp
= pid_vnr(cad_pid
);
2619 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2620 lenp
, ppos
, NULL
, NULL
);
2624 new_pid
= find_get_pid(tmp
);
2628 put_pid(xchg(&cad_pid
, new_pid
));
2632 #else /* CONFIG_PROC_FS */
2634 int proc_dostring(struct ctl_table
*table
, int write
,
2635 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2640 int proc_dointvec(struct ctl_table
*table
, int write
,
2641 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2646 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2647 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2652 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2653 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2658 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2659 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2664 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2665 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2670 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2671 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2676 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2677 void __user
*buffer
,
2678 size_t *lenp
, loff_t
*ppos
)
2684 #endif /* CONFIG_PROC_FS */
2687 * No sense putting this after each symbol definition, twice,
2688 * exception granted :-)
2690 EXPORT_SYMBOL(proc_dointvec
);
2691 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2692 EXPORT_SYMBOL(proc_dointvec_minmax
);
2693 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2694 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2695 EXPORT_SYMBOL(proc_dostring
);
2696 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2697 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2698 EXPORT_SYMBOL(register_sysctl_table
);
2699 EXPORT_SYMBOL(register_sysctl_paths
);
2700 EXPORT_SYMBOL(unregister_sysctl_table
);