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/printk.h>
28 #include <linux/proc_fs.h>
29 #include <linux/security.h>
30 #include <linux/ctype.h>
31 #include <linux/kmemcheck.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/ratelimit.h>
41 #include <linux/compaction.h>
42 #include <linux/hugetlb.h>
43 #include <linux/initrd.h>
44 #include <linux/key.h>
45 #include <linux/times.h>
46 #include <linux/limits.h>
47 #include <linux/dcache.h>
48 #include <linux/dnotify.h>
49 #include <linux/syscalls.h>
50 #include <linux/vmstat.h>
51 #include <linux/nfs_fs.h>
52 #include <linux/acpi.h>
53 #include <linux/reboot.h>
54 #include <linux/ftrace.h>
55 #include <linux/perf_event.h>
56 #include <linux/kprobes.h>
57 #include <linux/pipe_fs_i.h>
58 #include <linux/oom.h>
60 #include <asm/uaccess.h>
61 #include <asm/processor.h>
65 #include <asm/stacktrace.h>
68 #ifdef CONFIG_BSD_PROCESS_ACCT
69 #include <linux/acct.h>
71 #ifdef CONFIG_RT_MUTEXES
72 #include <linux/rtmutex.h>
74 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
75 #include <linux/lockdep.h>
77 #ifdef CONFIG_CHR_DEV_SG
81 #ifdef CONFIG_LOCKUP_DETECTOR
82 #include <linux/nmi.h>
86 #if defined(CONFIG_SYSCTL)
88 /* External variables not in a header file. */
89 extern int sysctl_overcommit_memory
;
90 extern int sysctl_overcommit_ratio
;
91 extern int max_threads
;
92 extern int core_uses_pid
;
93 extern int suid_dumpable
;
94 extern char core_pattern
[];
95 extern unsigned int core_pipe_limit
;
97 extern int min_free_kbytes
;
98 extern int pid_max_min
, pid_max_max
;
99 extern int sysctl_drop_caches
;
100 extern int percpu_pagelist_fraction
;
101 extern int compat_log
;
102 extern int latencytop_enabled
;
103 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
105 extern int sysctl_nr_trim_pages
;
108 extern int blk_iopoll_enabled
;
111 /* Constants used for minimum and maximum */
112 #ifdef CONFIG_LOCKUP_DETECTOR
113 static int sixty
= 60;
114 static int neg_one
= -1;
118 static int __maybe_unused one
= 1;
119 static int __maybe_unused two
= 2;
120 static unsigned long one_ul
= 1;
121 static int one_hundred
= 100;
123 static int ten_thousand
= 10000;
126 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
127 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
129 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
130 static int maxolduid
= 65535;
131 static int minolduid
;
132 static int min_percpu_pagelist_fract
= 8;
134 static int ngroups_max
= NGROUPS_MAX
;
136 #ifdef CONFIG_INOTIFY_USER
137 #include <linux/inotify.h>
140 #include <asm/system.h>
143 #ifdef CONFIG_SPARC64
144 extern int sysctl_tsb_ratio
;
148 extern int pwrsw_enabled
;
149 extern int unaligned_enabled
;
153 #ifdef CONFIG_MATHEMU
154 extern int sysctl_ieee_emulation_warnings
;
156 extern int sysctl_userprocess_debug
;
157 extern int spin_retry
;
161 extern int no_unaligned_warning
;
162 extern int unaligned_dump_stack
;
165 #ifdef CONFIG_PROC_SYSCTL
166 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
167 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
168 static int proc_taint(struct ctl_table
*table
, int write
,
169 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
173 static int proc_dmesg_restrict(struct ctl_table
*table
, int write
,
174 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
177 #ifdef CONFIG_MAGIC_SYSRQ
178 /* Note: sysrq code uses it's own private copy */
179 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
181 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
182 void __user
*buffer
, size_t *lenp
,
187 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
192 sysrq_toggle_support(__sysrq_enabled
);
199 static struct ctl_table root_table
[];
200 static struct ctl_table_root sysctl_table_root
;
201 static struct ctl_table_header root_table_header
= {
203 .ctl_table
= root_table
,
204 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),}},
205 .root
= &sysctl_table_root
,
206 .set
= &sysctl_table_root
.default_set
,
208 static struct ctl_table_root sysctl_table_root
= {
209 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
210 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
213 static struct ctl_table kern_table
[];
214 static struct ctl_table vm_table
[];
215 static struct ctl_table fs_table
[];
216 static struct ctl_table debug_table
[];
217 static struct ctl_table dev_table
[];
218 extern struct ctl_table random_table
[];
220 extern struct ctl_table epoll_table
[];
223 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
224 int sysctl_legacy_va_layout
;
227 /* The default sysctl tables: */
229 static struct ctl_table root_table
[] = {
231 .procname
= "kernel",
248 .child
= debug_table
,
258 #ifdef CONFIG_SCHED_DEBUG
259 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
260 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
261 static int min_wakeup_granularity_ns
; /* 0 usecs */
262 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
263 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
264 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
267 #ifdef CONFIG_COMPACTION
268 static int min_extfrag_threshold
;
269 static int max_extfrag_threshold
= 1000;
272 static struct ctl_table kern_table
[] = {
274 .procname
= "sched_child_runs_first",
275 .data
= &sysctl_sched_child_runs_first
,
276 .maxlen
= sizeof(unsigned int),
278 .proc_handler
= proc_dointvec
,
280 #ifdef CONFIG_SCHED_DEBUG
282 .procname
= "sched_min_granularity_ns",
283 .data
= &sysctl_sched_min_granularity
,
284 .maxlen
= sizeof(unsigned int),
286 .proc_handler
= sched_proc_update_handler
,
287 .extra1
= &min_sched_granularity_ns
,
288 .extra2
= &max_sched_granularity_ns
,
291 .procname
= "sched_latency_ns",
292 .data
= &sysctl_sched_latency
,
293 .maxlen
= sizeof(unsigned int),
295 .proc_handler
= sched_proc_update_handler
,
296 .extra1
= &min_sched_granularity_ns
,
297 .extra2
= &max_sched_granularity_ns
,
300 .procname
= "sched_wakeup_granularity_ns",
301 .data
= &sysctl_sched_wakeup_granularity
,
302 .maxlen
= sizeof(unsigned int),
304 .proc_handler
= sched_proc_update_handler
,
305 .extra1
= &min_wakeup_granularity_ns
,
306 .extra2
= &max_wakeup_granularity_ns
,
309 .procname
= "sched_tunable_scaling",
310 .data
= &sysctl_sched_tunable_scaling
,
311 .maxlen
= sizeof(enum sched_tunable_scaling
),
313 .proc_handler
= sched_proc_update_handler
,
314 .extra1
= &min_sched_tunable_scaling
,
315 .extra2
= &max_sched_tunable_scaling
,
318 .procname
= "sched_migration_cost",
319 .data
= &sysctl_sched_migration_cost
,
320 .maxlen
= sizeof(unsigned int),
322 .proc_handler
= proc_dointvec
,
325 .procname
= "sched_nr_migrate",
326 .data
= &sysctl_sched_nr_migrate
,
327 .maxlen
= sizeof(unsigned int),
329 .proc_handler
= proc_dointvec
,
332 .procname
= "sched_time_avg",
333 .data
= &sysctl_sched_time_avg
,
334 .maxlen
= sizeof(unsigned int),
336 .proc_handler
= proc_dointvec
,
339 .procname
= "sched_shares_window",
340 .data
= &sysctl_sched_shares_window
,
341 .maxlen
= sizeof(unsigned int),
343 .proc_handler
= proc_dointvec
,
346 .procname
= "timer_migration",
347 .data
= &sysctl_timer_migration
,
348 .maxlen
= sizeof(unsigned int),
350 .proc_handler
= proc_dointvec_minmax
,
356 .procname
= "sched_rt_period_us",
357 .data
= &sysctl_sched_rt_period
,
358 .maxlen
= sizeof(unsigned int),
360 .proc_handler
= sched_rt_handler
,
363 .procname
= "sched_rt_runtime_us",
364 .data
= &sysctl_sched_rt_runtime
,
365 .maxlen
= sizeof(int),
367 .proc_handler
= sched_rt_handler
,
370 .procname
= "sched_compat_yield",
371 .data
= &sysctl_sched_compat_yield
,
372 .maxlen
= sizeof(unsigned int),
374 .proc_handler
= proc_dointvec
,
376 #ifdef CONFIG_SCHED_AUTOGROUP
378 .procname
= "sched_autogroup_enabled",
379 .data
= &sysctl_sched_autogroup_enabled
,
380 .maxlen
= sizeof(unsigned int),
382 .proc_handler
= proc_dointvec
,
387 #ifdef CONFIG_PROVE_LOCKING
389 .procname
= "prove_locking",
390 .data
= &prove_locking
,
391 .maxlen
= sizeof(int),
393 .proc_handler
= proc_dointvec
,
396 #ifdef CONFIG_LOCK_STAT
398 .procname
= "lock_stat",
400 .maxlen
= sizeof(int),
402 .proc_handler
= proc_dointvec
,
407 .data
= &panic_timeout
,
408 .maxlen
= sizeof(int),
410 .proc_handler
= proc_dointvec
,
413 .procname
= "core_uses_pid",
414 .data
= &core_uses_pid
,
415 .maxlen
= sizeof(int),
417 .proc_handler
= proc_dointvec
,
420 .procname
= "core_pattern",
421 .data
= core_pattern
,
422 .maxlen
= CORENAME_MAX_SIZE
,
424 .proc_handler
= proc_dostring
,
427 .procname
= "core_pipe_limit",
428 .data
= &core_pipe_limit
,
429 .maxlen
= sizeof(unsigned int),
431 .proc_handler
= proc_dointvec
,
433 #ifdef CONFIG_PROC_SYSCTL
435 .procname
= "tainted",
436 .maxlen
= sizeof(long),
438 .proc_handler
= proc_taint
,
441 #ifdef CONFIG_LATENCYTOP
443 .procname
= "latencytop",
444 .data
= &latencytop_enabled
,
445 .maxlen
= sizeof(int),
447 .proc_handler
= proc_dointvec
,
450 #ifdef CONFIG_BLK_DEV_INITRD
452 .procname
= "real-root-dev",
453 .data
= &real_root_dev
,
454 .maxlen
= sizeof(int),
456 .proc_handler
= proc_dointvec
,
460 .procname
= "print-fatal-signals",
461 .data
= &print_fatal_signals
,
462 .maxlen
= sizeof(int),
464 .proc_handler
= proc_dointvec
,
468 .procname
= "reboot-cmd",
469 .data
= reboot_command
,
472 .proc_handler
= proc_dostring
,
475 .procname
= "stop-a",
476 .data
= &stop_a_enabled
,
477 .maxlen
= sizeof (int),
479 .proc_handler
= proc_dointvec
,
482 .procname
= "scons-poweroff",
483 .data
= &scons_pwroff
,
484 .maxlen
= sizeof (int),
486 .proc_handler
= proc_dointvec
,
489 #ifdef CONFIG_SPARC64
491 .procname
= "tsb-ratio",
492 .data
= &sysctl_tsb_ratio
,
493 .maxlen
= sizeof (int),
495 .proc_handler
= proc_dointvec
,
500 .procname
= "soft-power",
501 .data
= &pwrsw_enabled
,
502 .maxlen
= sizeof (int),
504 .proc_handler
= proc_dointvec
,
507 .procname
= "unaligned-trap",
508 .data
= &unaligned_enabled
,
509 .maxlen
= sizeof (int),
511 .proc_handler
= proc_dointvec
,
515 .procname
= "ctrl-alt-del",
517 .maxlen
= sizeof(int),
519 .proc_handler
= proc_dointvec
,
521 #ifdef CONFIG_FUNCTION_TRACER
523 .procname
= "ftrace_enabled",
524 .data
= &ftrace_enabled
,
525 .maxlen
= sizeof(int),
527 .proc_handler
= ftrace_enable_sysctl
,
530 #ifdef CONFIG_STACK_TRACER
532 .procname
= "stack_tracer_enabled",
533 .data
= &stack_tracer_enabled
,
534 .maxlen
= sizeof(int),
536 .proc_handler
= stack_trace_sysctl
,
539 #ifdef CONFIG_TRACING
541 .procname
= "ftrace_dump_on_oops",
542 .data
= &ftrace_dump_on_oops
,
543 .maxlen
= sizeof(int),
545 .proc_handler
= proc_dointvec
,
548 #ifdef CONFIG_MODULES
550 .procname
= "modprobe",
551 .data
= &modprobe_path
,
552 .maxlen
= KMOD_PATH_LEN
,
554 .proc_handler
= proc_dostring
,
557 .procname
= "modules_disabled",
558 .data
= &modules_disabled
,
559 .maxlen
= sizeof(int),
561 /* only handle a transition from default "0" to "1" */
562 .proc_handler
= proc_dointvec_minmax
,
567 #ifdef CONFIG_HOTPLUG
569 .procname
= "hotplug",
570 .data
= &uevent_helper
,
571 .maxlen
= UEVENT_HELPER_PATH_LEN
,
573 .proc_handler
= proc_dostring
,
576 #ifdef CONFIG_CHR_DEV_SG
578 .procname
= "sg-big-buff",
579 .data
= &sg_big_buff
,
580 .maxlen
= sizeof (int),
582 .proc_handler
= proc_dointvec
,
585 #ifdef CONFIG_BSD_PROCESS_ACCT
589 .maxlen
= 3*sizeof(int),
591 .proc_handler
= proc_dointvec
,
594 #ifdef CONFIG_MAGIC_SYSRQ
597 .data
= &__sysrq_enabled
,
598 .maxlen
= sizeof (int),
600 .proc_handler
= sysrq_sysctl_handler
,
603 #ifdef CONFIG_PROC_SYSCTL
605 .procname
= "cad_pid",
607 .maxlen
= sizeof (int),
609 .proc_handler
= proc_do_cad_pid
,
613 .procname
= "threads-max",
614 .data
= &max_threads
,
615 .maxlen
= sizeof(int),
617 .proc_handler
= proc_dointvec
,
620 .procname
= "random",
622 .child
= random_table
,
625 .procname
= "overflowuid",
626 .data
= &overflowuid
,
627 .maxlen
= sizeof(int),
629 .proc_handler
= proc_dointvec_minmax
,
630 .extra1
= &minolduid
,
631 .extra2
= &maxolduid
,
634 .procname
= "overflowgid",
635 .data
= &overflowgid
,
636 .maxlen
= sizeof(int),
638 .proc_handler
= proc_dointvec_minmax
,
639 .extra1
= &minolduid
,
640 .extra2
= &maxolduid
,
643 #ifdef CONFIG_MATHEMU
645 .procname
= "ieee_emulation_warnings",
646 .data
= &sysctl_ieee_emulation_warnings
,
647 .maxlen
= sizeof(int),
649 .proc_handler
= proc_dointvec
,
653 .procname
= "userprocess_debug",
654 .data
= &show_unhandled_signals
,
655 .maxlen
= sizeof(int),
657 .proc_handler
= proc_dointvec
,
661 .procname
= "pid_max",
663 .maxlen
= sizeof (int),
665 .proc_handler
= proc_dointvec_minmax
,
666 .extra1
= &pid_max_min
,
667 .extra2
= &pid_max_max
,
670 .procname
= "panic_on_oops",
671 .data
= &panic_on_oops
,
672 .maxlen
= sizeof(int),
674 .proc_handler
= proc_dointvec
,
676 #if defined CONFIG_PRINTK
678 .procname
= "printk",
679 .data
= &console_loglevel
,
680 .maxlen
= 4*sizeof(int),
682 .proc_handler
= proc_dointvec
,
685 .procname
= "printk_ratelimit",
686 .data
= &printk_ratelimit_state
.interval
,
687 .maxlen
= sizeof(int),
689 .proc_handler
= proc_dointvec_jiffies
,
692 .procname
= "printk_ratelimit_burst",
693 .data
= &printk_ratelimit_state
.burst
,
694 .maxlen
= sizeof(int),
696 .proc_handler
= proc_dointvec
,
699 .procname
= "printk_delay",
700 .data
= &printk_delay_msec
,
701 .maxlen
= sizeof(int),
703 .proc_handler
= proc_dointvec_minmax
,
705 .extra2
= &ten_thousand
,
708 .procname
= "dmesg_restrict",
709 .data
= &dmesg_restrict
,
710 .maxlen
= sizeof(int),
712 .proc_handler
= proc_dointvec_minmax
,
717 .procname
= "kptr_restrict",
718 .data
= &kptr_restrict
,
719 .maxlen
= sizeof(int),
721 .proc_handler
= proc_dmesg_restrict
,
727 .procname
= "ngroups_max",
728 .data
= &ngroups_max
,
729 .maxlen
= sizeof (int),
731 .proc_handler
= proc_dointvec
,
733 #if defined(CONFIG_LOCKUP_DETECTOR)
735 .procname
= "watchdog",
736 .data
= &watchdog_enabled
,
737 .maxlen
= sizeof (int),
739 .proc_handler
= proc_dowatchdog_enabled
,
742 .procname
= "watchdog_thresh",
743 .data
= &softlockup_thresh
,
744 .maxlen
= sizeof(int),
746 .proc_handler
= proc_dowatchdog_thresh
,
751 .procname
= "softlockup_panic",
752 .data
= &softlockup_panic
,
753 .maxlen
= sizeof(int),
755 .proc_handler
= proc_dointvec_minmax
,
760 .procname
= "nmi_watchdog",
761 .data
= &watchdog_enabled
,
762 .maxlen
= sizeof (int),
764 .proc_handler
= proc_dowatchdog_enabled
,
767 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
769 .procname
= "unknown_nmi_panic",
770 .data
= &unknown_nmi_panic
,
771 .maxlen
= sizeof (int),
773 .proc_handler
= proc_dointvec
,
776 #if defined(CONFIG_X86)
778 .procname
= "panic_on_unrecovered_nmi",
779 .data
= &panic_on_unrecovered_nmi
,
780 .maxlen
= sizeof(int),
782 .proc_handler
= proc_dointvec
,
785 .procname
= "panic_on_io_nmi",
786 .data
= &panic_on_io_nmi
,
787 .maxlen
= sizeof(int),
789 .proc_handler
= proc_dointvec
,
792 .procname
= "bootloader_type",
793 .data
= &bootloader_type
,
794 .maxlen
= sizeof (int),
796 .proc_handler
= proc_dointvec
,
799 .procname
= "bootloader_version",
800 .data
= &bootloader_version
,
801 .maxlen
= sizeof (int),
803 .proc_handler
= proc_dointvec
,
806 .procname
= "kstack_depth_to_print",
807 .data
= &kstack_depth_to_print
,
808 .maxlen
= sizeof(int),
810 .proc_handler
= proc_dointvec
,
813 .procname
= "io_delay_type",
814 .data
= &io_delay_type
,
815 .maxlen
= sizeof(int),
817 .proc_handler
= proc_dointvec
,
820 #if defined(CONFIG_MMU)
822 .procname
= "randomize_va_space",
823 .data
= &randomize_va_space
,
824 .maxlen
= sizeof(int),
826 .proc_handler
= proc_dointvec
,
829 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
831 .procname
= "spin_retry",
833 .maxlen
= sizeof (int),
835 .proc_handler
= proc_dointvec
,
838 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
840 .procname
= "acpi_video_flags",
841 .data
= &acpi_realmode_flags
,
842 .maxlen
= sizeof (unsigned long),
844 .proc_handler
= proc_doulongvec_minmax
,
849 .procname
= "ignore-unaligned-usertrap",
850 .data
= &no_unaligned_warning
,
851 .maxlen
= sizeof (int),
853 .proc_handler
= proc_dointvec
,
856 .procname
= "unaligned-dump-stack",
857 .data
= &unaligned_dump_stack
,
858 .maxlen
= sizeof (int),
860 .proc_handler
= proc_dointvec
,
863 #ifdef CONFIG_DETECT_HUNG_TASK
865 .procname
= "hung_task_panic",
866 .data
= &sysctl_hung_task_panic
,
867 .maxlen
= sizeof(int),
869 .proc_handler
= proc_dointvec_minmax
,
874 .procname
= "hung_task_check_count",
875 .data
= &sysctl_hung_task_check_count
,
876 .maxlen
= sizeof(unsigned long),
878 .proc_handler
= proc_doulongvec_minmax
,
881 .procname
= "hung_task_timeout_secs",
882 .data
= &sysctl_hung_task_timeout_secs
,
883 .maxlen
= sizeof(unsigned long),
885 .proc_handler
= proc_dohung_task_timeout_secs
,
888 .procname
= "hung_task_warnings",
889 .data
= &sysctl_hung_task_warnings
,
890 .maxlen
= sizeof(unsigned long),
892 .proc_handler
= proc_doulongvec_minmax
,
897 .procname
= "compat-log",
899 .maxlen
= sizeof (int),
901 .proc_handler
= proc_dointvec
,
904 #ifdef CONFIG_RT_MUTEXES
906 .procname
= "max_lock_depth",
907 .data
= &max_lock_depth
,
908 .maxlen
= sizeof(int),
910 .proc_handler
= proc_dointvec
,
914 .procname
= "poweroff_cmd",
915 .data
= &poweroff_cmd
,
916 .maxlen
= POWEROFF_CMD_PATH_LEN
,
918 .proc_handler
= proc_dostring
,
924 .child
= key_sysctls
,
927 #ifdef CONFIG_RCU_TORTURE_TEST
929 .procname
= "rcutorture_runnable",
930 .data
= &rcutorture_runnable
,
931 .maxlen
= sizeof(int),
933 .proc_handler
= proc_dointvec
,
936 #ifdef CONFIG_PERF_EVENTS
938 .procname
= "perf_event_paranoid",
939 .data
= &sysctl_perf_event_paranoid
,
940 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
942 .proc_handler
= proc_dointvec
,
945 .procname
= "perf_event_mlock_kb",
946 .data
= &sysctl_perf_event_mlock
,
947 .maxlen
= sizeof(sysctl_perf_event_mlock
),
949 .proc_handler
= proc_dointvec
,
952 .procname
= "perf_event_max_sample_rate",
953 .data
= &sysctl_perf_event_sample_rate
,
954 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
956 .proc_handler
= proc_dointvec
,
959 #ifdef CONFIG_KMEMCHECK
961 .procname
= "kmemcheck",
962 .data
= &kmemcheck_enabled
,
963 .maxlen
= sizeof(int),
965 .proc_handler
= proc_dointvec
,
970 .procname
= "blk_iopoll",
971 .data
= &blk_iopoll_enabled
,
972 .maxlen
= sizeof(int),
974 .proc_handler
= proc_dointvec
,
980 static struct ctl_table vm_table
[] = {
982 .procname
= "overcommit_memory",
983 .data
= &sysctl_overcommit_memory
,
984 .maxlen
= sizeof(sysctl_overcommit_memory
),
986 .proc_handler
= proc_dointvec
,
989 .procname
= "panic_on_oom",
990 .data
= &sysctl_panic_on_oom
,
991 .maxlen
= sizeof(sysctl_panic_on_oom
),
993 .proc_handler
= proc_dointvec
,
996 .procname
= "oom_kill_allocating_task",
997 .data
= &sysctl_oom_kill_allocating_task
,
998 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1000 .proc_handler
= proc_dointvec
,
1003 .procname
= "oom_dump_tasks",
1004 .data
= &sysctl_oom_dump_tasks
,
1005 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1007 .proc_handler
= proc_dointvec
,
1010 .procname
= "overcommit_ratio",
1011 .data
= &sysctl_overcommit_ratio
,
1012 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1014 .proc_handler
= proc_dointvec
,
1017 .procname
= "page-cluster",
1018 .data
= &page_cluster
,
1019 .maxlen
= sizeof(int),
1021 .proc_handler
= proc_dointvec
,
1024 .procname
= "dirty_background_ratio",
1025 .data
= &dirty_background_ratio
,
1026 .maxlen
= sizeof(dirty_background_ratio
),
1028 .proc_handler
= dirty_background_ratio_handler
,
1030 .extra2
= &one_hundred
,
1033 .procname
= "dirty_background_bytes",
1034 .data
= &dirty_background_bytes
,
1035 .maxlen
= sizeof(dirty_background_bytes
),
1037 .proc_handler
= dirty_background_bytes_handler
,
1041 .procname
= "dirty_ratio",
1042 .data
= &vm_dirty_ratio
,
1043 .maxlen
= sizeof(vm_dirty_ratio
),
1045 .proc_handler
= dirty_ratio_handler
,
1047 .extra2
= &one_hundred
,
1050 .procname
= "dirty_bytes",
1051 .data
= &vm_dirty_bytes
,
1052 .maxlen
= sizeof(vm_dirty_bytes
),
1054 .proc_handler
= dirty_bytes_handler
,
1055 .extra1
= &dirty_bytes_min
,
1058 .procname
= "dirty_writeback_centisecs",
1059 .data
= &dirty_writeback_interval
,
1060 .maxlen
= sizeof(dirty_writeback_interval
),
1062 .proc_handler
= dirty_writeback_centisecs_handler
,
1065 .procname
= "dirty_expire_centisecs",
1066 .data
= &dirty_expire_interval
,
1067 .maxlen
= sizeof(dirty_expire_interval
),
1069 .proc_handler
= proc_dointvec
,
1072 .procname
= "nr_pdflush_threads",
1073 .data
= &nr_pdflush_threads
,
1074 .maxlen
= sizeof nr_pdflush_threads
,
1075 .mode
= 0444 /* read-only*/,
1076 .proc_handler
= proc_dointvec
,
1079 .procname
= "swappiness",
1080 .data
= &vm_swappiness
,
1081 .maxlen
= sizeof(vm_swappiness
),
1083 .proc_handler
= proc_dointvec_minmax
,
1085 .extra2
= &one_hundred
,
1087 #ifdef CONFIG_HUGETLB_PAGE
1089 .procname
= "nr_hugepages",
1091 .maxlen
= sizeof(unsigned long),
1093 .proc_handler
= hugetlb_sysctl_handler
,
1094 .extra1
= (void *)&hugetlb_zero
,
1095 .extra2
= (void *)&hugetlb_infinity
,
1099 .procname
= "nr_hugepages_mempolicy",
1101 .maxlen
= sizeof(unsigned long),
1103 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1104 .extra1
= (void *)&hugetlb_zero
,
1105 .extra2
= (void *)&hugetlb_infinity
,
1109 .procname
= "hugetlb_shm_group",
1110 .data
= &sysctl_hugetlb_shm_group
,
1111 .maxlen
= sizeof(gid_t
),
1113 .proc_handler
= proc_dointvec
,
1116 .procname
= "hugepages_treat_as_movable",
1117 .data
= &hugepages_treat_as_movable
,
1118 .maxlen
= sizeof(int),
1120 .proc_handler
= hugetlb_treat_movable_handler
,
1123 .procname
= "nr_overcommit_hugepages",
1125 .maxlen
= sizeof(unsigned long),
1127 .proc_handler
= hugetlb_overcommit_handler
,
1128 .extra1
= (void *)&hugetlb_zero
,
1129 .extra2
= (void *)&hugetlb_infinity
,
1133 .procname
= "lowmem_reserve_ratio",
1134 .data
= &sysctl_lowmem_reserve_ratio
,
1135 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1137 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1140 .procname
= "drop_caches",
1141 .data
= &sysctl_drop_caches
,
1142 .maxlen
= sizeof(int),
1144 .proc_handler
= drop_caches_sysctl_handler
,
1146 #ifdef CONFIG_COMPACTION
1148 .procname
= "compact_memory",
1149 .data
= &sysctl_compact_memory
,
1150 .maxlen
= sizeof(int),
1152 .proc_handler
= sysctl_compaction_handler
,
1155 .procname
= "extfrag_threshold",
1156 .data
= &sysctl_extfrag_threshold
,
1157 .maxlen
= sizeof(int),
1159 .proc_handler
= sysctl_extfrag_handler
,
1160 .extra1
= &min_extfrag_threshold
,
1161 .extra2
= &max_extfrag_threshold
,
1164 #endif /* CONFIG_COMPACTION */
1166 .procname
= "min_free_kbytes",
1167 .data
= &min_free_kbytes
,
1168 .maxlen
= sizeof(min_free_kbytes
),
1170 .proc_handler
= min_free_kbytes_sysctl_handler
,
1174 .procname
= "percpu_pagelist_fraction",
1175 .data
= &percpu_pagelist_fraction
,
1176 .maxlen
= sizeof(percpu_pagelist_fraction
),
1178 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1179 .extra1
= &min_percpu_pagelist_fract
,
1183 .procname
= "max_map_count",
1184 .data
= &sysctl_max_map_count
,
1185 .maxlen
= sizeof(sysctl_max_map_count
),
1187 .proc_handler
= proc_dointvec_minmax
,
1192 .procname
= "nr_trim_pages",
1193 .data
= &sysctl_nr_trim_pages
,
1194 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1196 .proc_handler
= proc_dointvec_minmax
,
1201 .procname
= "laptop_mode",
1202 .data
= &laptop_mode
,
1203 .maxlen
= sizeof(laptop_mode
),
1205 .proc_handler
= proc_dointvec_jiffies
,
1208 .procname
= "block_dump",
1209 .data
= &block_dump
,
1210 .maxlen
= sizeof(block_dump
),
1212 .proc_handler
= proc_dointvec
,
1216 .procname
= "vfs_cache_pressure",
1217 .data
= &sysctl_vfs_cache_pressure
,
1218 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1220 .proc_handler
= proc_dointvec
,
1223 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1225 .procname
= "legacy_va_layout",
1226 .data
= &sysctl_legacy_va_layout
,
1227 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1229 .proc_handler
= proc_dointvec
,
1235 .procname
= "zone_reclaim_mode",
1236 .data
= &zone_reclaim_mode
,
1237 .maxlen
= sizeof(zone_reclaim_mode
),
1239 .proc_handler
= proc_dointvec
,
1243 .procname
= "min_unmapped_ratio",
1244 .data
= &sysctl_min_unmapped_ratio
,
1245 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1247 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1249 .extra2
= &one_hundred
,
1252 .procname
= "min_slab_ratio",
1253 .data
= &sysctl_min_slab_ratio
,
1254 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1256 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1258 .extra2
= &one_hundred
,
1263 .procname
= "stat_interval",
1264 .data
= &sysctl_stat_interval
,
1265 .maxlen
= sizeof(sysctl_stat_interval
),
1267 .proc_handler
= proc_dointvec_jiffies
,
1272 .procname
= "mmap_min_addr",
1273 .data
= &dac_mmap_min_addr
,
1274 .maxlen
= sizeof(unsigned long),
1276 .proc_handler
= mmap_min_addr_handler
,
1281 .procname
= "numa_zonelist_order",
1282 .data
= &numa_zonelist_order
,
1283 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1285 .proc_handler
= numa_zonelist_order_handler
,
1288 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1289 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1291 .procname
= "vdso_enabled",
1292 .data
= &vdso_enabled
,
1293 .maxlen
= sizeof(vdso_enabled
),
1295 .proc_handler
= proc_dointvec
,
1299 #ifdef CONFIG_HIGHMEM
1301 .procname
= "highmem_is_dirtyable",
1302 .data
= &vm_highmem_is_dirtyable
,
1303 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1305 .proc_handler
= proc_dointvec_minmax
,
1311 .procname
= "scan_unevictable_pages",
1312 .data
= &scan_unevictable_pages
,
1313 .maxlen
= sizeof(scan_unevictable_pages
),
1315 .proc_handler
= scan_unevictable_handler
,
1317 #ifdef CONFIG_MEMORY_FAILURE
1319 .procname
= "memory_failure_early_kill",
1320 .data
= &sysctl_memory_failure_early_kill
,
1321 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1323 .proc_handler
= proc_dointvec_minmax
,
1328 .procname
= "memory_failure_recovery",
1329 .data
= &sysctl_memory_failure_recovery
,
1330 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1332 .proc_handler
= proc_dointvec_minmax
,
1340 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1341 static struct ctl_table binfmt_misc_table
[] = {
1346 static struct ctl_table fs_table
[] = {
1348 .procname
= "inode-nr",
1349 .data
= &inodes_stat
,
1350 .maxlen
= 2*sizeof(int),
1352 .proc_handler
= proc_nr_inodes
,
1355 .procname
= "inode-state",
1356 .data
= &inodes_stat
,
1357 .maxlen
= 7*sizeof(int),
1359 .proc_handler
= proc_nr_inodes
,
1362 .procname
= "file-nr",
1363 .data
= &files_stat
,
1364 .maxlen
= sizeof(files_stat
),
1366 .proc_handler
= proc_nr_files
,
1369 .procname
= "file-max",
1370 .data
= &files_stat
.max_files
,
1371 .maxlen
= sizeof(files_stat
.max_files
),
1373 .proc_handler
= proc_doulongvec_minmax
,
1376 .procname
= "nr_open",
1377 .data
= &sysctl_nr_open
,
1378 .maxlen
= sizeof(int),
1380 .proc_handler
= proc_dointvec_minmax
,
1381 .extra1
= &sysctl_nr_open_min
,
1382 .extra2
= &sysctl_nr_open_max
,
1385 .procname
= "dentry-state",
1386 .data
= &dentry_stat
,
1387 .maxlen
= 6*sizeof(int),
1389 .proc_handler
= proc_nr_dentry
,
1392 .procname
= "overflowuid",
1393 .data
= &fs_overflowuid
,
1394 .maxlen
= sizeof(int),
1396 .proc_handler
= proc_dointvec_minmax
,
1397 .extra1
= &minolduid
,
1398 .extra2
= &maxolduid
,
1401 .procname
= "overflowgid",
1402 .data
= &fs_overflowgid
,
1403 .maxlen
= sizeof(int),
1405 .proc_handler
= proc_dointvec_minmax
,
1406 .extra1
= &minolduid
,
1407 .extra2
= &maxolduid
,
1409 #ifdef CONFIG_FILE_LOCKING
1411 .procname
= "leases-enable",
1412 .data
= &leases_enable
,
1413 .maxlen
= sizeof(int),
1415 .proc_handler
= proc_dointvec
,
1418 #ifdef CONFIG_DNOTIFY
1420 .procname
= "dir-notify-enable",
1421 .data
= &dir_notify_enable
,
1422 .maxlen
= sizeof(int),
1424 .proc_handler
= proc_dointvec
,
1428 #ifdef CONFIG_FILE_LOCKING
1430 .procname
= "lease-break-time",
1431 .data
= &lease_break_time
,
1432 .maxlen
= sizeof(int),
1434 .proc_handler
= proc_dointvec
,
1439 .procname
= "aio-nr",
1441 .maxlen
= sizeof(aio_nr
),
1443 .proc_handler
= proc_doulongvec_minmax
,
1446 .procname
= "aio-max-nr",
1447 .data
= &aio_max_nr
,
1448 .maxlen
= sizeof(aio_max_nr
),
1450 .proc_handler
= proc_doulongvec_minmax
,
1452 #endif /* CONFIG_AIO */
1453 #ifdef CONFIG_INOTIFY_USER
1455 .procname
= "inotify",
1457 .child
= inotify_table
,
1462 .procname
= "epoll",
1464 .child
= epoll_table
,
1469 .procname
= "suid_dumpable",
1470 .data
= &suid_dumpable
,
1471 .maxlen
= sizeof(int),
1473 .proc_handler
= proc_dointvec_minmax
,
1477 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1479 .procname
= "binfmt_misc",
1481 .child
= binfmt_misc_table
,
1485 .procname
= "pipe-max-size",
1486 .data
= &pipe_max_size
,
1487 .maxlen
= sizeof(int),
1489 .proc_handler
= &pipe_proc_fn
,
1490 .extra1
= &pipe_min_size
,
1495 static struct ctl_table debug_table
[] = {
1496 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1497 defined(CONFIG_S390)
1499 .procname
= "exception-trace",
1500 .data
= &show_unhandled_signals
,
1501 .maxlen
= sizeof(int),
1503 .proc_handler
= proc_dointvec
1506 #if defined(CONFIG_OPTPROBES)
1508 .procname
= "kprobes-optimization",
1509 .data
= &sysctl_kprobes_optimization
,
1510 .maxlen
= sizeof(int),
1512 .proc_handler
= proc_kprobes_optimization_handler
,
1520 static struct ctl_table dev_table
[] = {
1524 static DEFINE_SPINLOCK(sysctl_lock
);
1526 /* called under sysctl_lock */
1527 static int use_table(struct ctl_table_header
*p
)
1529 if (unlikely(p
->unregistering
))
1535 /* called under sysctl_lock */
1536 static void unuse_table(struct ctl_table_header
*p
)
1539 if (unlikely(p
->unregistering
))
1540 complete(p
->unregistering
);
1543 /* called under sysctl_lock, will reacquire if has to wait */
1544 static void start_unregistering(struct ctl_table_header
*p
)
1547 * if p->used is 0, nobody will ever touch that entry again;
1548 * we'll eliminate all paths to it before dropping sysctl_lock
1550 if (unlikely(p
->used
)) {
1551 struct completion wait
;
1552 init_completion(&wait
);
1553 p
->unregistering
= &wait
;
1554 spin_unlock(&sysctl_lock
);
1555 wait_for_completion(&wait
);
1556 spin_lock(&sysctl_lock
);
1558 /* anything non-NULL; we'll never dereference it */
1559 p
->unregistering
= ERR_PTR(-EINVAL
);
1562 * do not remove from the list until nobody holds it; walking the
1563 * list in do_sysctl() relies on that.
1565 list_del_init(&p
->ctl_entry
);
1568 void sysctl_head_get(struct ctl_table_header
*head
)
1570 spin_lock(&sysctl_lock
);
1572 spin_unlock(&sysctl_lock
);
1575 static void free_head(struct rcu_head
*rcu
)
1577 kfree(container_of(rcu
, struct ctl_table_header
, rcu
));
1580 void sysctl_head_put(struct ctl_table_header
*head
)
1582 spin_lock(&sysctl_lock
);
1584 call_rcu(&head
->rcu
, free_head
);
1585 spin_unlock(&sysctl_lock
);
1588 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1592 spin_lock(&sysctl_lock
);
1593 if (!use_table(head
))
1594 head
= ERR_PTR(-ENOENT
);
1595 spin_unlock(&sysctl_lock
);
1599 void sysctl_head_finish(struct ctl_table_header
*head
)
1603 spin_lock(&sysctl_lock
);
1605 spin_unlock(&sysctl_lock
);
1608 static struct ctl_table_set
*
1609 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1611 struct ctl_table_set
*set
= &root
->default_set
;
1613 set
= root
->lookup(root
, namespaces
);
1617 static struct list_head
*
1618 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1620 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1624 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1625 struct ctl_table_header
*prev
)
1627 struct ctl_table_root
*root
;
1628 struct list_head
*header_list
;
1629 struct ctl_table_header
*head
;
1630 struct list_head
*tmp
;
1632 spin_lock(&sysctl_lock
);
1635 tmp
= &prev
->ctl_entry
;
1639 tmp
= &root_table_header
.ctl_entry
;
1641 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1643 if (!use_table(head
))
1645 spin_unlock(&sysctl_lock
);
1650 header_list
= lookup_header_list(root
, namespaces
);
1651 if (tmp
!= header_list
)
1655 root
= list_entry(root
->root_list
.next
,
1656 struct ctl_table_root
, root_list
);
1657 if (root
== &sysctl_table_root
)
1659 header_list
= lookup_header_list(root
, namespaces
);
1660 } while (list_empty(header_list
));
1661 tmp
= header_list
->next
;
1664 spin_unlock(&sysctl_lock
);
1668 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1670 return __sysctl_head_next(current
->nsproxy
, prev
);
1673 void register_sysctl_root(struct ctl_table_root
*root
)
1675 spin_lock(&sysctl_lock
);
1676 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1677 spin_unlock(&sysctl_lock
);
1681 * sysctl_perm does NOT grant the superuser all rights automatically, because
1682 * some sysctl variables are readonly even to root.
1685 static int test_perm(int mode
, int op
)
1687 if (!current_euid())
1689 else if (in_egroup_p(0))
1691 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1696 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1701 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1705 if (root
->permissions
)
1706 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1710 return test_perm(mode
, op
);
1713 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1715 for (; table
->procname
; table
++) {
1716 table
->parent
= parent
;
1718 sysctl_set_parent(table
, table
->child
);
1722 static __init
int sysctl_init(void)
1724 sysctl_set_parent(NULL
, root_table
);
1725 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1726 sysctl_check_table(current
->nsproxy
, root_table
);
1731 core_initcall(sysctl_init
);
1733 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1734 struct ctl_table
*table
)
1736 struct ctl_table
*p
;
1737 const char *s
= branch
->procname
;
1739 /* branch should have named subdirectory as its first element */
1740 if (!s
|| !branch
->child
)
1743 /* ... and nothing else */
1744 if (branch
[1].procname
)
1747 /* table should contain subdirectory with the same name */
1748 for (p
= table
; p
->procname
; p
++) {
1751 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1757 /* see if attaching q to p would be an improvement */
1758 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1760 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1761 struct ctl_table
*next
;
1763 int not_in_parent
= !p
->attached_by
;
1765 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1766 if (by
== q
->attached_by
)
1768 if (to
== p
->attached_by
)
1774 if (is_better
&& not_in_parent
) {
1775 q
->attached_by
= by
;
1776 q
->attached_to
= to
;
1782 * __register_sysctl_paths - register a sysctl hierarchy
1783 * @root: List of sysctl headers to register on
1784 * @namespaces: Data to compute which lists of sysctl entries are visible
1785 * @path: The path to the directory the sysctl table is in.
1786 * @table: the top-level table structure
1788 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1789 * array. A completely 0 filled entry terminates the table.
1791 * The members of the &struct ctl_table structure are used as follows:
1793 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1794 * enter a sysctl file
1796 * data - a pointer to data for use by proc_handler
1798 * maxlen - the maximum size in bytes of the data
1800 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1802 * child - a pointer to the child sysctl table if this entry is a directory, or
1805 * proc_handler - the text handler routine (described below)
1807 * de - for internal use by the sysctl routines
1809 * extra1, extra2 - extra pointers usable by the proc handler routines
1811 * Leaf nodes in the sysctl tree will be represented by a single file
1812 * under /proc; non-leaf nodes will be represented by directories.
1814 * sysctl(2) can automatically manage read and write requests through
1815 * the sysctl table. The data and maxlen fields of the ctl_table
1816 * struct enable minimal validation of the values being written to be
1817 * performed, and the mode field allows minimal authentication.
1819 * There must be a proc_handler routine for any terminal nodes
1820 * mirrored under /proc/sys (non-terminals are handled by a built-in
1821 * directory handler). Several default handlers are available to
1822 * cover common cases -
1824 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1825 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1826 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1828 * It is the handler's job to read the input buffer from user memory
1829 * and process it. The handler should return 0 on success.
1831 * This routine returns %NULL on a failure to register, and a pointer
1832 * to the table header on success.
1834 struct ctl_table_header
*__register_sysctl_paths(
1835 struct ctl_table_root
*root
,
1836 struct nsproxy
*namespaces
,
1837 const struct ctl_path
*path
, struct ctl_table
*table
)
1839 struct ctl_table_header
*header
;
1840 struct ctl_table
*new, **prevp
;
1841 unsigned int n
, npath
;
1842 struct ctl_table_set
*set
;
1844 /* Count the path components */
1845 for (npath
= 0; path
[npath
].procname
; ++npath
)
1849 * For each path component, allocate a 2-element ctl_table array.
1850 * The first array element will be filled with the sysctl entry
1851 * for this, the second will be the sentinel (procname == 0).
1853 * We allocate everything in one go so that we don't have to
1854 * worry about freeing additional memory in unregister_sysctl_table.
1856 header
= kzalloc(sizeof(struct ctl_table_header
) +
1857 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1861 new = (struct ctl_table
*) (header
+ 1);
1863 /* Now connect the dots */
1864 prevp
= &header
->ctl_table
;
1865 for (n
= 0; n
< npath
; ++n
, ++path
) {
1866 /* Copy the procname */
1867 new->procname
= path
->procname
;
1871 prevp
= &new->child
;
1876 header
->ctl_table_arg
= table
;
1878 INIT_LIST_HEAD(&header
->ctl_entry
);
1880 header
->unregistering
= NULL
;
1881 header
->root
= root
;
1882 sysctl_set_parent(NULL
, header
->ctl_table
);
1884 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1885 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1890 spin_lock(&sysctl_lock
);
1891 header
->set
= lookup_header_set(root
, namespaces
);
1892 header
->attached_by
= header
->ctl_table
;
1893 header
->attached_to
= root_table
;
1894 header
->parent
= &root_table_header
;
1895 for (set
= header
->set
; set
; set
= set
->parent
) {
1896 struct ctl_table_header
*p
;
1897 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1898 if (p
->unregistering
)
1900 try_attach(p
, header
);
1903 header
->parent
->count
++;
1904 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1905 spin_unlock(&sysctl_lock
);
1911 * register_sysctl_table_path - register a sysctl table hierarchy
1912 * @path: The path to the directory the sysctl table is in.
1913 * @table: the top-level table structure
1915 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1916 * array. A completely 0 filled entry terminates the table.
1918 * See __register_sysctl_paths for more details.
1920 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1921 struct ctl_table
*table
)
1923 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1928 * register_sysctl_table - register a sysctl table hierarchy
1929 * @table: the top-level table structure
1931 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1932 * array. A completely 0 filled entry terminates the table.
1934 * See register_sysctl_paths for more details.
1936 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1938 static const struct ctl_path null_path
[] = { {} };
1940 return register_sysctl_paths(null_path
, table
);
1944 * unregister_sysctl_table - unregister a sysctl table hierarchy
1945 * @header: the header returned from register_sysctl_table
1947 * Unregisters the sysctl table and all children. proc entries may not
1948 * actually be removed until they are no longer used by anyone.
1950 void unregister_sysctl_table(struct ctl_table_header
* header
)
1957 spin_lock(&sysctl_lock
);
1958 start_unregistering(header
);
1959 if (!--header
->parent
->count
) {
1961 call_rcu(&header
->parent
->rcu
, free_head
);
1963 if (!--header
->count
)
1964 call_rcu(&header
->rcu
, free_head
);
1965 spin_unlock(&sysctl_lock
);
1968 int sysctl_is_seen(struct ctl_table_header
*p
)
1970 struct ctl_table_set
*set
= p
->set
;
1972 spin_lock(&sysctl_lock
);
1973 if (p
->unregistering
)
1975 else if (!set
->is_seen
)
1978 res
= set
->is_seen(set
);
1979 spin_unlock(&sysctl_lock
);
1983 void setup_sysctl_set(struct ctl_table_set
*p
,
1984 struct ctl_table_set
*parent
,
1985 int (*is_seen
)(struct ctl_table_set
*))
1987 INIT_LIST_HEAD(&p
->list
);
1988 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1989 p
->is_seen
= is_seen
;
1992 #else /* !CONFIG_SYSCTL */
1993 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1998 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1999 struct ctl_table
*table
)
2004 void unregister_sysctl_table(struct ctl_table_header
* table
)
2008 void setup_sysctl_set(struct ctl_table_set
*p
,
2009 struct ctl_table_set
*parent
,
2010 int (*is_seen
)(struct ctl_table_set
*))
2014 void sysctl_head_put(struct ctl_table_header
*head
)
2018 #endif /* CONFIG_SYSCTL */
2024 #ifdef CONFIG_PROC_SYSCTL
2026 static int _proc_do_string(void* data
, int maxlen
, int write
,
2027 void __user
*buffer
,
2028 size_t *lenp
, loff_t
*ppos
)
2034 if (!data
|| !maxlen
|| !*lenp
) {
2042 while (len
< *lenp
) {
2043 if (get_user(c
, p
++))
2045 if (c
== 0 || c
== '\n')
2051 if(copy_from_user(data
, buffer
, len
))
2053 ((char *) data
)[len
] = 0;
2071 if(copy_to_user(buffer
, data
, len
))
2074 if(put_user('\n', ((char __user
*) buffer
) + len
))
2085 * proc_dostring - read a string sysctl
2086 * @table: the sysctl table
2087 * @write: %TRUE if this is a write to the sysctl file
2088 * @buffer: the user buffer
2089 * @lenp: the size of the user buffer
2090 * @ppos: file position
2092 * Reads/writes a string from/to the user buffer. If the kernel
2093 * buffer provided is not large enough to hold the string, the
2094 * string is truncated. The copied string is %NULL-terminated.
2095 * If the string is being read by the user process, it is copied
2096 * and a newline '\n' is added. It is truncated if the buffer is
2099 * Returns 0 on success.
2101 int proc_dostring(struct ctl_table
*table
, int write
,
2102 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2104 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2105 buffer
, lenp
, ppos
);
2108 static size_t proc_skip_spaces(char **buf
)
2111 char *tmp
= skip_spaces(*buf
);
2117 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2127 #define TMPBUFLEN 22
2129 * proc_get_long - reads an ASCII formatted integer from a user buffer
2131 * @buf: a kernel buffer
2132 * @size: size of the kernel buffer
2133 * @val: this is where the number will be stored
2134 * @neg: set to %TRUE if number is negative
2135 * @perm_tr: a vector which contains the allowed trailers
2136 * @perm_tr_len: size of the perm_tr vector
2137 * @tr: pointer to store the trailer character
2139 * In case of success %0 is returned and @buf and @size are updated with
2140 * the amount of bytes read. If @tr is non-NULL and a trailing
2141 * character exists (size is non-zero after returning from this
2142 * function), @tr is updated with the trailing character.
2144 static int proc_get_long(char **buf
, size_t *size
,
2145 unsigned long *val
, bool *neg
,
2146 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2149 char *p
, tmp
[TMPBUFLEN
];
2155 if (len
> TMPBUFLEN
- 1)
2156 len
= TMPBUFLEN
- 1;
2158 memcpy(tmp
, *buf
, len
);
2162 if (*p
== '-' && *size
> 1) {
2170 *val
= simple_strtoul(p
, &p
, 0);
2174 /* We don't know if the next char is whitespace thus we may accept
2175 * invalid integers (e.g. 1234...a) or two integers instead of one
2176 * (e.g. 123...1). So lets not allow such large numbers. */
2177 if (len
== TMPBUFLEN
- 1)
2180 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2183 if (tr
&& (len
< *size
))
2193 * proc_put_long - converts an integer to a decimal ASCII formatted string
2195 * @buf: the user buffer
2196 * @size: the size of the user buffer
2197 * @val: the integer to be converted
2198 * @neg: sign of the number, %TRUE for negative
2200 * In case of success %0 is returned and @buf and @size are updated with
2201 * the amount of bytes written.
2203 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2207 char tmp
[TMPBUFLEN
], *p
= tmp
;
2209 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2213 if (copy_to_user(*buf
, tmp
, len
))
2221 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2224 char __user
**buffer
= (char __user
**)buf
;
2225 if (put_user(c
, *buffer
))
2227 (*size
)--, (*buffer
)++;
2233 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2235 int write
, void *data
)
2238 *valp
= *negp
? -*lvalp
: *lvalp
;
2243 *lvalp
= (unsigned long)-val
;
2246 *lvalp
= (unsigned long)val
;
2252 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2254 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2255 int write
, void __user
*buffer
,
2256 size_t *lenp
, loff_t
*ppos
,
2257 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2258 int write
, void *data
),
2261 int *i
, vleft
, first
= 1, err
= 0;
2262 unsigned long page
= 0;
2266 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2271 i
= (int *) tbl_data
;
2272 vleft
= table
->maxlen
/ sizeof(*i
);
2276 conv
= do_proc_dointvec_conv
;
2279 if (left
> PAGE_SIZE
- 1)
2280 left
= PAGE_SIZE
- 1;
2281 page
= __get_free_page(GFP_TEMPORARY
);
2282 kbuf
= (char *) page
;
2285 if (copy_from_user(kbuf
, buffer
, left
)) {
2292 for (; left
&& vleft
--; i
++, first
=0) {
2297 left
-= proc_skip_spaces(&kbuf
);
2301 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2303 sizeof(proc_wspace_sep
), NULL
);
2306 if (conv(&neg
, &lval
, i
, 1, data
)) {
2311 if (conv(&neg
, &lval
, i
, 0, data
)) {
2316 err
= proc_put_char(&buffer
, &left
, '\t');
2319 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2325 if (!write
&& !first
&& left
&& !err
)
2326 err
= proc_put_char(&buffer
, &left
, '\n');
2327 if (write
&& !err
&& left
)
2328 left
-= proc_skip_spaces(&kbuf
);
2333 return err
? : -EINVAL
;
2340 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2341 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2342 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2343 int write
, void *data
),
2346 return __do_proc_dointvec(table
->data
, table
, write
,
2347 buffer
, lenp
, ppos
, conv
, data
);
2351 * proc_dointvec - read a vector of integers
2352 * @table: the sysctl table
2353 * @write: %TRUE if this is a write to the sysctl file
2354 * @buffer: the user buffer
2355 * @lenp: the size of the user buffer
2356 * @ppos: file position
2358 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2359 * values from/to the user buffer, treated as an ASCII string.
2361 * Returns 0 on success.
2363 int proc_dointvec(struct ctl_table
*table
, int write
,
2364 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2366 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2371 * Taint values can only be increased
2372 * This means we can safely use a temporary.
2374 static int proc_taint(struct ctl_table
*table
, int write
,
2375 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2378 unsigned long tmptaint
= get_taint();
2381 if (write
&& !capable(CAP_SYS_ADMIN
))
2386 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2392 * Poor man's atomic or. Not worth adding a primitive
2393 * to everyone's atomic.h for this
2396 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2397 if ((tmptaint
>> i
) & 1)
2405 #ifdef CONFIG_PRINTK
2406 static int proc_dmesg_restrict(struct ctl_table
*table
, int write
,
2407 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2409 if (write
&& !capable(CAP_SYS_ADMIN
))
2412 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2416 struct do_proc_dointvec_minmax_conv_param
{
2421 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2423 int write
, void *data
)
2425 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2427 int val
= *negp
? -*lvalp
: *lvalp
;
2428 if ((param
->min
&& *param
->min
> val
) ||
2429 (param
->max
&& *param
->max
< val
))
2436 *lvalp
= (unsigned long)-val
;
2439 *lvalp
= (unsigned long)val
;
2446 * proc_dointvec_minmax - read a vector of integers with min/max values
2447 * @table: the sysctl table
2448 * @write: %TRUE if this is a write to the sysctl file
2449 * @buffer: the user buffer
2450 * @lenp: the size of the user buffer
2451 * @ppos: file position
2453 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2454 * values from/to the user buffer, treated as an ASCII string.
2456 * This routine will ensure the values are within the range specified by
2457 * table->extra1 (min) and table->extra2 (max).
2459 * Returns 0 on success.
2461 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2462 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2464 struct do_proc_dointvec_minmax_conv_param param
= {
2465 .min
= (int *) table
->extra1
,
2466 .max
= (int *) table
->extra2
,
2468 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2469 do_proc_dointvec_minmax_conv
, ¶m
);
2472 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2473 void __user
*buffer
,
2474 size_t *lenp
, loff_t
*ppos
,
2475 unsigned long convmul
,
2476 unsigned long convdiv
)
2478 unsigned long *i
, *min
, *max
;
2479 int vleft
, first
= 1, err
= 0;
2480 unsigned long page
= 0;
2484 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2489 i
= (unsigned long *) data
;
2490 min
= (unsigned long *) table
->extra1
;
2491 max
= (unsigned long *) table
->extra2
;
2492 vleft
= table
->maxlen
/ sizeof(unsigned long);
2496 if (left
> PAGE_SIZE
- 1)
2497 left
= PAGE_SIZE
- 1;
2498 page
= __get_free_page(GFP_TEMPORARY
);
2499 kbuf
= (char *) page
;
2502 if (copy_from_user(kbuf
, buffer
, left
)) {
2509 for (; left
&& vleft
--; i
++, first
= 0) {
2515 left
-= proc_skip_spaces(&kbuf
);
2517 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2519 sizeof(proc_wspace_sep
), NULL
);
2524 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2528 val
= convdiv
* (*i
) / convmul
;
2530 err
= proc_put_char(&buffer
, &left
, '\t');
2531 err
= proc_put_long(&buffer
, &left
, val
, false);
2537 if (!write
&& !first
&& left
&& !err
)
2538 err
= proc_put_char(&buffer
, &left
, '\n');
2540 left
-= proc_skip_spaces(&kbuf
);
2545 return err
? : -EINVAL
;
2552 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2553 void __user
*buffer
,
2554 size_t *lenp
, loff_t
*ppos
,
2555 unsigned long convmul
,
2556 unsigned long convdiv
)
2558 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2559 buffer
, lenp
, ppos
, convmul
, convdiv
);
2563 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2564 * @table: the sysctl table
2565 * @write: %TRUE if this is a write to the sysctl file
2566 * @buffer: the user buffer
2567 * @lenp: the size of the user buffer
2568 * @ppos: file position
2570 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2571 * values from/to the user buffer, treated as an ASCII string.
2573 * This routine will ensure the values are within the range specified by
2574 * table->extra1 (min) and table->extra2 (max).
2576 * Returns 0 on success.
2578 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2579 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2581 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2585 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2586 * @table: the sysctl table
2587 * @write: %TRUE if this is a write to the sysctl file
2588 * @buffer: the user buffer
2589 * @lenp: the size of the user buffer
2590 * @ppos: file position
2592 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2593 * values from/to the user buffer, treated as an ASCII string. The values
2594 * are treated as milliseconds, and converted to jiffies when they are stored.
2596 * This routine will ensure the values are within the range specified by
2597 * table->extra1 (min) and table->extra2 (max).
2599 * Returns 0 on success.
2601 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2602 void __user
*buffer
,
2603 size_t *lenp
, loff_t
*ppos
)
2605 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2606 lenp
, ppos
, HZ
, 1000l);
2610 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2612 int write
, void *data
)
2615 if (*lvalp
> LONG_MAX
/ HZ
)
2617 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2623 lval
= (unsigned long)-val
;
2626 lval
= (unsigned long)val
;
2633 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2635 int write
, void *data
)
2638 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2640 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2646 lval
= (unsigned long)-val
;
2649 lval
= (unsigned long)val
;
2651 *lvalp
= jiffies_to_clock_t(lval
);
2656 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2658 int write
, void *data
)
2661 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2667 lval
= (unsigned long)-val
;
2670 lval
= (unsigned long)val
;
2672 *lvalp
= jiffies_to_msecs(lval
);
2678 * proc_dointvec_jiffies - read a vector of integers as seconds
2679 * @table: the sysctl table
2680 * @write: %TRUE if this is a write to the sysctl file
2681 * @buffer: the user buffer
2682 * @lenp: the size of the user buffer
2683 * @ppos: file position
2685 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2686 * values from/to the user buffer, treated as an ASCII string.
2687 * The values read are assumed to be in seconds, and are converted into
2690 * Returns 0 on success.
2692 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2693 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2695 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2696 do_proc_dointvec_jiffies_conv
,NULL
);
2700 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2701 * @table: the sysctl table
2702 * @write: %TRUE if this is a write to the sysctl file
2703 * @buffer: the user buffer
2704 * @lenp: the size of the user buffer
2705 * @ppos: pointer to the file position
2707 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2708 * values from/to the user buffer, treated as an ASCII string.
2709 * The values read are assumed to be in 1/USER_HZ seconds, and
2710 * are converted into jiffies.
2712 * Returns 0 on success.
2714 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2715 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2717 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2718 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2722 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2723 * @table: the sysctl table
2724 * @write: %TRUE if this is a write to the sysctl file
2725 * @buffer: the user buffer
2726 * @lenp: the size of the user buffer
2727 * @ppos: file position
2728 * @ppos: the current position in the file
2730 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2731 * values from/to the user buffer, treated as an ASCII string.
2732 * The values read are assumed to be in 1/1000 seconds, and
2733 * are converted into jiffies.
2735 * Returns 0 on success.
2737 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2738 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2740 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2741 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2744 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2745 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2747 struct pid
*new_pid
;
2751 tmp
= pid_vnr(cad_pid
);
2753 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2754 lenp
, ppos
, NULL
, NULL
);
2758 new_pid
= find_get_pid(tmp
);
2762 put_pid(xchg(&cad_pid
, new_pid
));
2767 * proc_do_large_bitmap - read/write from/to a large bitmap
2768 * @table: the sysctl table
2769 * @write: %TRUE if this is a write to the sysctl file
2770 * @buffer: the user buffer
2771 * @lenp: the size of the user buffer
2772 * @ppos: file position
2774 * The bitmap is stored at table->data and the bitmap length (in bits)
2777 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2778 * large bitmaps may be represented in a compact manner. Writing into
2779 * the file will clear the bitmap then update it with the given input.
2781 * Returns 0 on success.
2783 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2784 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2788 size_t left
= *lenp
;
2789 unsigned long bitmap_len
= table
->maxlen
;
2790 unsigned long *bitmap
= (unsigned long *) table
->data
;
2791 unsigned long *tmp_bitmap
= NULL
;
2792 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2794 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2800 unsigned long page
= 0;
2803 if (left
> PAGE_SIZE
- 1)
2804 left
= PAGE_SIZE
- 1;
2806 page
= __get_free_page(GFP_TEMPORARY
);
2807 kbuf
= (char *) page
;
2810 if (copy_from_user(kbuf
, buffer
, left
)) {
2816 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2822 proc_skip_char(&kbuf
, &left
, '\n');
2823 while (!err
&& left
) {
2824 unsigned long val_a
, val_b
;
2827 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2831 if (val_a
>= bitmap_len
|| neg
) {
2843 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2844 &neg
, tr_b
, sizeof(tr_b
),
2848 if (val_b
>= bitmap_len
|| neg
||
2859 while (val_a
<= val_b
)
2860 set_bit(val_a
++, tmp_bitmap
);
2863 proc_skip_char(&kbuf
, &left
, '\n');
2867 unsigned long bit_a
, bit_b
= 0;
2870 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2871 if (bit_a
>= bitmap_len
)
2873 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2877 err
= proc_put_char(&buffer
, &left
, ',');
2881 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2884 if (bit_a
!= bit_b
) {
2885 err
= proc_put_char(&buffer
, &left
, '-');
2888 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2896 err
= proc_put_char(&buffer
, &left
, '\n');
2902 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2904 memcpy(bitmap
, tmp_bitmap
,
2905 BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long));
2917 #else /* CONFIG_PROC_SYSCTL */
2919 int proc_dostring(struct ctl_table
*table
, int write
,
2920 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2925 int proc_dointvec(struct ctl_table
*table
, int write
,
2926 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2931 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2932 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2937 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2938 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2943 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2944 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2949 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2950 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2955 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2956 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2961 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2962 void __user
*buffer
,
2963 size_t *lenp
, loff_t
*ppos
)
2969 #endif /* CONFIG_PROC_SYSCTL */
2972 * No sense putting this after each symbol definition, twice,
2973 * exception granted :-)
2975 EXPORT_SYMBOL(proc_dointvec
);
2976 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2977 EXPORT_SYMBOL(proc_dointvec_minmax
);
2978 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2979 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2980 EXPORT_SYMBOL(proc_dostring
);
2981 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2982 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2983 EXPORT_SYMBOL(register_sysctl_table
);
2984 EXPORT_SYMBOL(register_sysctl_paths
);
2985 EXPORT_SYMBOL(unregister_sysctl_table
);