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>
59 #include <linux/kmod.h>
61 #include <asm/uaccess.h>
62 #include <asm/processor.h>
66 #include <asm/stacktrace.h>
69 #ifdef CONFIG_BSD_PROCESS_ACCT
70 #include <linux/acct.h>
72 #ifdef CONFIG_RT_MUTEXES
73 #include <linux/rtmutex.h>
75 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
76 #include <linux/lockdep.h>
78 #ifdef CONFIG_CHR_DEV_SG
82 #ifdef CONFIG_LOCKUP_DETECTOR
83 #include <linux/nmi.h>
87 #if defined(CONFIG_SYSCTL)
89 /* External variables not in a header file. */
90 extern int sysctl_overcommit_memory
;
91 extern int sysctl_overcommit_ratio
;
92 extern int max_threads
;
93 extern int core_uses_pid
;
94 extern int suid_dumpable
;
95 extern char core_pattern
[];
96 extern unsigned int core_pipe_limit
;
98 extern int min_free_kbytes
;
99 extern int min_free_order_shift
;
100 extern int pid_max_min
, pid_max_max
;
101 extern int sysctl_drop_caches
;
102 extern int percpu_pagelist_fraction
;
103 extern int compat_log
;
104 extern int latencytop_enabled
;
105 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
107 extern int sysctl_nr_trim_pages
;
110 extern int blk_iopoll_enabled
;
113 /* Constants used for minimum and maximum */
114 #ifdef CONFIG_LOCKUP_DETECTOR
115 static int sixty
= 60;
116 static int neg_one
= -1;
120 static int __maybe_unused one
= 1;
121 static int __maybe_unused two
= 2;
122 static int __maybe_unused three
= 3;
123 static unsigned long one_ul
= 1;
124 static int one_hundred
= 100;
126 static int ten_thousand
= 10000;
129 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
130 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
132 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
133 static int maxolduid
= 65535;
134 static int minolduid
;
135 static int min_percpu_pagelist_fract
= 8;
137 static int ngroups_max
= NGROUPS_MAX
;
139 #ifdef CONFIG_INOTIFY_USER
140 #include <linux/inotify.h>
143 #include <asm/system.h>
146 #ifdef CONFIG_SPARC64
147 extern int sysctl_tsb_ratio
;
151 extern int pwrsw_enabled
;
152 extern int unaligned_enabled
;
156 #ifdef CONFIG_MATHEMU
157 extern int sysctl_ieee_emulation_warnings
;
159 extern int sysctl_userprocess_debug
;
160 extern int spin_retry
;
164 extern int no_unaligned_warning
;
165 extern int unaligned_dump_stack
;
168 #ifdef CONFIG_PROC_SYSCTL
169 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
170 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
171 static int proc_taint(struct ctl_table
*table
, int write
,
172 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
176 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
177 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
180 #ifdef CONFIG_MAGIC_SYSRQ
181 /* Note: sysrq code uses it's own private copy */
182 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
184 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
185 void __user
*buffer
, size_t *lenp
,
190 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
195 sysrq_toggle_support(__sysrq_enabled
);
202 static struct ctl_table root_table
[];
203 static struct ctl_table_root sysctl_table_root
;
204 static struct ctl_table_header root_table_header
= {
206 .ctl_table
= root_table
,
207 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),}},
208 .root
= &sysctl_table_root
,
209 .set
= &sysctl_table_root
.default_set
,
211 static struct ctl_table_root sysctl_table_root
= {
212 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
213 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
216 static struct ctl_table kern_table
[];
217 static struct ctl_table vm_table
[];
218 static struct ctl_table fs_table
[];
219 static struct ctl_table debug_table
[];
220 static struct ctl_table dev_table
[];
221 extern struct ctl_table random_table
[];
223 extern struct ctl_table epoll_table
[];
226 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
227 int sysctl_legacy_va_layout
;
230 /* The default sysctl tables: */
232 static struct ctl_table root_table
[] = {
234 .procname
= "kernel",
251 .child
= debug_table
,
261 #ifdef CONFIG_SCHED_DEBUG
262 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
263 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
264 static int min_wakeup_granularity_ns
; /* 0 usecs */
265 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
266 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
267 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
270 #ifdef CONFIG_COMPACTION
271 static int min_extfrag_threshold
;
272 static int max_extfrag_threshold
= 1000;
275 static struct ctl_table kern_table
[] = {
277 .procname
= "sched_child_runs_first",
278 .data
= &sysctl_sched_child_runs_first
,
279 .maxlen
= sizeof(unsigned int),
281 .proc_handler
= proc_dointvec
,
283 #ifdef CONFIG_SCHED_DEBUG
285 .procname
= "sched_min_granularity_ns",
286 .data
= &sysctl_sched_min_granularity
,
287 .maxlen
= sizeof(unsigned int),
289 .proc_handler
= sched_proc_update_handler
,
290 .extra1
= &min_sched_granularity_ns
,
291 .extra2
= &max_sched_granularity_ns
,
294 .procname
= "sched_latency_ns",
295 .data
= &sysctl_sched_latency
,
296 .maxlen
= sizeof(unsigned int),
298 .proc_handler
= sched_proc_update_handler
,
299 .extra1
= &min_sched_granularity_ns
,
300 .extra2
= &max_sched_granularity_ns
,
303 .procname
= "sched_wakeup_granularity_ns",
304 .data
= &sysctl_sched_wakeup_granularity
,
305 .maxlen
= sizeof(unsigned int),
307 .proc_handler
= sched_proc_update_handler
,
308 .extra1
= &min_wakeup_granularity_ns
,
309 .extra2
= &max_wakeup_granularity_ns
,
312 .procname
= "sched_tunable_scaling",
313 .data
= &sysctl_sched_tunable_scaling
,
314 .maxlen
= sizeof(enum sched_tunable_scaling
),
316 .proc_handler
= sched_proc_update_handler
,
317 .extra1
= &min_sched_tunable_scaling
,
318 .extra2
= &max_sched_tunable_scaling
,
321 .procname
= "sched_migration_cost",
322 .data
= &sysctl_sched_migration_cost
,
323 .maxlen
= sizeof(unsigned int),
325 .proc_handler
= proc_dointvec
,
328 .procname
= "sched_nr_migrate",
329 .data
= &sysctl_sched_nr_migrate
,
330 .maxlen
= sizeof(unsigned int),
332 .proc_handler
= proc_dointvec
,
335 .procname
= "sched_time_avg",
336 .data
= &sysctl_sched_time_avg
,
337 .maxlen
= sizeof(unsigned int),
339 .proc_handler
= proc_dointvec
,
342 .procname
= "sched_shares_window",
343 .data
= &sysctl_sched_shares_window
,
344 .maxlen
= sizeof(unsigned int),
346 .proc_handler
= proc_dointvec
,
349 .procname
= "timer_migration",
350 .data
= &sysctl_timer_migration
,
351 .maxlen
= sizeof(unsigned int),
353 .proc_handler
= proc_dointvec_minmax
,
359 .procname
= "sched_rt_period_us",
360 .data
= &sysctl_sched_rt_period
,
361 .maxlen
= sizeof(unsigned int),
363 .proc_handler
= sched_rt_handler
,
366 .procname
= "sched_rt_runtime_us",
367 .data
= &sysctl_sched_rt_runtime
,
368 .maxlen
= sizeof(int),
370 .proc_handler
= sched_rt_handler
,
372 #ifdef CONFIG_SCHED_AUTOGROUP
374 .procname
= "sched_autogroup_enabled",
375 .data
= &sysctl_sched_autogroup_enabled
,
376 .maxlen
= sizeof(unsigned int),
378 .proc_handler
= proc_dointvec_minmax
,
383 #ifdef CONFIG_PROVE_LOCKING
385 .procname
= "prove_locking",
386 .data
= &prove_locking
,
387 .maxlen
= sizeof(int),
389 .proc_handler
= proc_dointvec
,
392 #ifdef CONFIG_LOCK_STAT
394 .procname
= "lock_stat",
396 .maxlen
= sizeof(int),
398 .proc_handler
= proc_dointvec
,
403 .data
= &panic_timeout
,
404 .maxlen
= sizeof(int),
406 .proc_handler
= proc_dointvec
,
409 .procname
= "core_uses_pid",
410 .data
= &core_uses_pid
,
411 .maxlen
= sizeof(int),
413 .proc_handler
= proc_dointvec
,
416 .procname
= "core_pattern",
417 .data
= core_pattern
,
418 .maxlen
= CORENAME_MAX_SIZE
,
420 .proc_handler
= proc_dostring
,
423 .procname
= "core_pipe_limit",
424 .data
= &core_pipe_limit
,
425 .maxlen
= sizeof(unsigned int),
427 .proc_handler
= proc_dointvec
,
429 #ifdef CONFIG_PROC_SYSCTL
431 .procname
= "tainted",
432 .maxlen
= sizeof(long),
434 .proc_handler
= proc_taint
,
437 #ifdef CONFIG_LATENCYTOP
439 .procname
= "latencytop",
440 .data
= &latencytop_enabled
,
441 .maxlen
= sizeof(int),
443 .proc_handler
= proc_dointvec
,
446 #ifdef CONFIG_BLK_DEV_INITRD
448 .procname
= "real-root-dev",
449 .data
= &real_root_dev
,
450 .maxlen
= sizeof(int),
452 .proc_handler
= proc_dointvec
,
456 .procname
= "print-fatal-signals",
457 .data
= &print_fatal_signals
,
458 .maxlen
= sizeof(int),
460 .proc_handler
= proc_dointvec
,
464 .procname
= "reboot-cmd",
465 .data
= reboot_command
,
468 .proc_handler
= proc_dostring
,
471 .procname
= "stop-a",
472 .data
= &stop_a_enabled
,
473 .maxlen
= sizeof (int),
475 .proc_handler
= proc_dointvec
,
478 .procname
= "scons-poweroff",
479 .data
= &scons_pwroff
,
480 .maxlen
= sizeof (int),
482 .proc_handler
= proc_dointvec
,
485 #ifdef CONFIG_SPARC64
487 .procname
= "tsb-ratio",
488 .data
= &sysctl_tsb_ratio
,
489 .maxlen
= sizeof (int),
491 .proc_handler
= proc_dointvec
,
496 .procname
= "soft-power",
497 .data
= &pwrsw_enabled
,
498 .maxlen
= sizeof (int),
500 .proc_handler
= proc_dointvec
,
503 .procname
= "unaligned-trap",
504 .data
= &unaligned_enabled
,
505 .maxlen
= sizeof (int),
507 .proc_handler
= proc_dointvec
,
511 .procname
= "ctrl-alt-del",
513 .maxlen
= sizeof(int),
515 .proc_handler
= proc_dointvec
,
517 #ifdef CONFIG_FUNCTION_TRACER
519 .procname
= "ftrace_enabled",
520 .data
= &ftrace_enabled
,
521 .maxlen
= sizeof(int),
523 .proc_handler
= ftrace_enable_sysctl
,
526 #ifdef CONFIG_STACK_TRACER
528 .procname
= "stack_tracer_enabled",
529 .data
= &stack_tracer_enabled
,
530 .maxlen
= sizeof(int),
532 .proc_handler
= stack_trace_sysctl
,
535 #ifdef CONFIG_TRACING
537 .procname
= "ftrace_dump_on_oops",
538 .data
= &ftrace_dump_on_oops
,
539 .maxlen
= sizeof(int),
541 .proc_handler
= proc_dointvec
,
544 #ifdef CONFIG_MODULES
546 .procname
= "modprobe",
547 .data
= &modprobe_path
,
548 .maxlen
= KMOD_PATH_LEN
,
550 .proc_handler
= proc_dostring
,
553 .procname
= "modules_disabled",
554 .data
= &modules_disabled
,
555 .maxlen
= sizeof(int),
557 /* only handle a transition from default "0" to "1" */
558 .proc_handler
= proc_dointvec_minmax
,
563 #ifdef CONFIG_HOTPLUG
565 .procname
= "hotplug",
566 .data
= &uevent_helper
,
567 .maxlen
= UEVENT_HELPER_PATH_LEN
,
569 .proc_handler
= proc_dostring
,
572 #ifdef CONFIG_CHR_DEV_SG
574 .procname
= "sg-big-buff",
575 .data
= &sg_big_buff
,
576 .maxlen
= sizeof (int),
578 .proc_handler
= proc_dointvec
,
581 #ifdef CONFIG_BSD_PROCESS_ACCT
585 .maxlen
= 3*sizeof(int),
587 .proc_handler
= proc_dointvec
,
590 #ifdef CONFIG_MAGIC_SYSRQ
593 .data
= &__sysrq_enabled
,
594 .maxlen
= sizeof (int),
596 .proc_handler
= sysrq_sysctl_handler
,
599 #ifdef CONFIG_PROC_SYSCTL
601 .procname
= "cad_pid",
603 .maxlen
= sizeof (int),
605 .proc_handler
= proc_do_cad_pid
,
609 .procname
= "threads-max",
610 .data
= &max_threads
,
611 .maxlen
= sizeof(int),
613 .proc_handler
= proc_dointvec
,
616 .procname
= "random",
618 .child
= random_table
,
621 .procname
= "usermodehelper",
623 .child
= usermodehelper_table
,
626 .procname
= "overflowuid",
627 .data
= &overflowuid
,
628 .maxlen
= sizeof(int),
630 .proc_handler
= proc_dointvec_minmax
,
631 .extra1
= &minolduid
,
632 .extra2
= &maxolduid
,
635 .procname
= "overflowgid",
636 .data
= &overflowgid
,
637 .maxlen
= sizeof(int),
639 .proc_handler
= proc_dointvec_minmax
,
640 .extra1
= &minolduid
,
641 .extra2
= &maxolduid
,
644 #ifdef CONFIG_MATHEMU
646 .procname
= "ieee_emulation_warnings",
647 .data
= &sysctl_ieee_emulation_warnings
,
648 .maxlen
= sizeof(int),
650 .proc_handler
= proc_dointvec
,
654 .procname
= "userprocess_debug",
655 .data
= &show_unhandled_signals
,
656 .maxlen
= sizeof(int),
658 .proc_handler
= proc_dointvec
,
662 .procname
= "pid_max",
664 .maxlen
= sizeof (int),
666 .proc_handler
= proc_dointvec_minmax
,
667 .extra1
= &pid_max_min
,
668 .extra2
= &pid_max_max
,
671 .procname
= "panic_on_oops",
672 .data
= &panic_on_oops
,
673 .maxlen
= sizeof(int),
675 .proc_handler
= proc_dointvec
,
677 #if defined CONFIG_PRINTK
679 .procname
= "printk",
680 .data
= &console_loglevel
,
681 .maxlen
= 4*sizeof(int),
683 .proc_handler
= proc_dointvec
,
686 .procname
= "printk_ratelimit",
687 .data
= &printk_ratelimit_state
.interval
,
688 .maxlen
= sizeof(int),
690 .proc_handler
= proc_dointvec_jiffies
,
693 .procname
= "printk_ratelimit_burst",
694 .data
= &printk_ratelimit_state
.burst
,
695 .maxlen
= sizeof(int),
697 .proc_handler
= proc_dointvec
,
700 .procname
= "printk_delay",
701 .data
= &printk_delay_msec
,
702 .maxlen
= sizeof(int),
704 .proc_handler
= proc_dointvec_minmax
,
706 .extra2
= &ten_thousand
,
709 .procname
= "dmesg_restrict",
710 .data
= &dmesg_restrict
,
711 .maxlen
= sizeof(int),
713 .proc_handler
= proc_dointvec_minmax_sysadmin
,
718 .procname
= "kptr_restrict",
719 .data
= &kptr_restrict
,
720 .maxlen
= sizeof(int),
722 .proc_handler
= proc_dointvec_minmax_sysadmin
,
728 .procname
= "ngroups_max",
729 .data
= &ngroups_max
,
730 .maxlen
= sizeof (int),
732 .proc_handler
= proc_dointvec
,
734 #if defined(CONFIG_LOCKUP_DETECTOR)
736 .procname
= "watchdog",
737 .data
= &watchdog_enabled
,
738 .maxlen
= sizeof (int),
740 .proc_handler
= proc_dowatchdog
,
745 .procname
= "watchdog_thresh",
746 .data
= &watchdog_thresh
,
747 .maxlen
= sizeof(int),
749 .proc_handler
= proc_dowatchdog
,
754 .procname
= "softlockup_panic",
755 .data
= &softlockup_panic
,
756 .maxlen
= sizeof(int),
758 .proc_handler
= proc_dointvec_minmax
,
763 .procname
= "nmi_watchdog",
764 .data
= &watchdog_enabled
,
765 .maxlen
= sizeof (int),
767 .proc_handler
= proc_dowatchdog
,
772 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
774 .procname
= "unknown_nmi_panic",
775 .data
= &unknown_nmi_panic
,
776 .maxlen
= sizeof (int),
778 .proc_handler
= proc_dointvec
,
781 #if defined(CONFIG_X86)
783 .procname
= "panic_on_unrecovered_nmi",
784 .data
= &panic_on_unrecovered_nmi
,
785 .maxlen
= sizeof(int),
787 .proc_handler
= proc_dointvec
,
790 .procname
= "panic_on_io_nmi",
791 .data
= &panic_on_io_nmi
,
792 .maxlen
= sizeof(int),
794 .proc_handler
= proc_dointvec
,
797 .procname
= "bootloader_type",
798 .data
= &bootloader_type
,
799 .maxlen
= sizeof (int),
801 .proc_handler
= proc_dointvec
,
804 .procname
= "bootloader_version",
805 .data
= &bootloader_version
,
806 .maxlen
= sizeof (int),
808 .proc_handler
= proc_dointvec
,
811 .procname
= "kstack_depth_to_print",
812 .data
= &kstack_depth_to_print
,
813 .maxlen
= sizeof(int),
815 .proc_handler
= proc_dointvec
,
818 .procname
= "io_delay_type",
819 .data
= &io_delay_type
,
820 .maxlen
= sizeof(int),
822 .proc_handler
= proc_dointvec
,
825 #if defined(CONFIG_MMU)
827 .procname
= "randomize_va_space",
828 .data
= &randomize_va_space
,
829 .maxlen
= sizeof(int),
831 .proc_handler
= proc_dointvec
,
834 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
836 .procname
= "spin_retry",
838 .maxlen
= sizeof (int),
840 .proc_handler
= proc_dointvec
,
843 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
845 .procname
= "acpi_video_flags",
846 .data
= &acpi_realmode_flags
,
847 .maxlen
= sizeof (unsigned long),
849 .proc_handler
= proc_doulongvec_minmax
,
854 .procname
= "ignore-unaligned-usertrap",
855 .data
= &no_unaligned_warning
,
856 .maxlen
= sizeof (int),
858 .proc_handler
= proc_dointvec
,
861 .procname
= "unaligned-dump-stack",
862 .data
= &unaligned_dump_stack
,
863 .maxlen
= sizeof (int),
865 .proc_handler
= proc_dointvec
,
868 #ifdef CONFIG_DETECT_HUNG_TASK
870 .procname
= "hung_task_panic",
871 .data
= &sysctl_hung_task_panic
,
872 .maxlen
= sizeof(int),
874 .proc_handler
= proc_dointvec_minmax
,
879 .procname
= "hung_task_check_count",
880 .data
= &sysctl_hung_task_check_count
,
881 .maxlen
= sizeof(unsigned long),
883 .proc_handler
= proc_doulongvec_minmax
,
886 .procname
= "hung_task_timeout_secs",
887 .data
= &sysctl_hung_task_timeout_secs
,
888 .maxlen
= sizeof(unsigned long),
890 .proc_handler
= proc_dohung_task_timeout_secs
,
893 .procname
= "hung_task_warnings",
894 .data
= &sysctl_hung_task_warnings
,
895 .maxlen
= sizeof(unsigned long),
897 .proc_handler
= proc_doulongvec_minmax
,
902 .procname
= "compat-log",
904 .maxlen
= sizeof (int),
906 .proc_handler
= proc_dointvec
,
909 #ifdef CONFIG_RT_MUTEXES
911 .procname
= "max_lock_depth",
912 .data
= &max_lock_depth
,
913 .maxlen
= sizeof(int),
915 .proc_handler
= proc_dointvec
,
919 .procname
= "poweroff_cmd",
920 .data
= &poweroff_cmd
,
921 .maxlen
= POWEROFF_CMD_PATH_LEN
,
923 .proc_handler
= proc_dostring
,
929 .child
= key_sysctls
,
932 #ifdef CONFIG_RCU_TORTURE_TEST
934 .procname
= "rcutorture_runnable",
935 .data
= &rcutorture_runnable
,
936 .maxlen
= sizeof(int),
938 .proc_handler
= proc_dointvec
,
941 #ifdef CONFIG_PERF_EVENTS
943 * User-space scripts rely on the existence of this file
944 * as a feature check for perf_events being enabled.
946 * So it's an ABI, do not remove!
949 .procname
= "perf_event_paranoid",
950 .data
= &sysctl_perf_event_paranoid
,
951 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
953 .proc_handler
= proc_dointvec
,
956 .procname
= "perf_event_mlock_kb",
957 .data
= &sysctl_perf_event_mlock
,
958 .maxlen
= sizeof(sysctl_perf_event_mlock
),
960 .proc_handler
= proc_dointvec
,
963 .procname
= "perf_event_max_sample_rate",
964 .data
= &sysctl_perf_event_sample_rate
,
965 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
967 .proc_handler
= perf_proc_update_handler
,
970 #ifdef CONFIG_KMEMCHECK
972 .procname
= "kmemcheck",
973 .data
= &kmemcheck_enabled
,
974 .maxlen
= sizeof(int),
976 .proc_handler
= proc_dointvec
,
981 .procname
= "blk_iopoll",
982 .data
= &blk_iopoll_enabled
,
983 .maxlen
= sizeof(int),
985 .proc_handler
= proc_dointvec
,
991 static struct ctl_table vm_table
[] = {
993 .procname
= "overcommit_memory",
994 .data
= &sysctl_overcommit_memory
,
995 .maxlen
= sizeof(sysctl_overcommit_memory
),
997 .proc_handler
= proc_dointvec_minmax
,
1002 .procname
= "panic_on_oom",
1003 .data
= &sysctl_panic_on_oom
,
1004 .maxlen
= sizeof(sysctl_panic_on_oom
),
1006 .proc_handler
= proc_dointvec_minmax
,
1011 .procname
= "oom_kill_allocating_task",
1012 .data
= &sysctl_oom_kill_allocating_task
,
1013 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1015 .proc_handler
= proc_dointvec
,
1018 .procname
= "oom_dump_tasks",
1019 .data
= &sysctl_oom_dump_tasks
,
1020 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1022 .proc_handler
= proc_dointvec
,
1025 .procname
= "overcommit_ratio",
1026 .data
= &sysctl_overcommit_ratio
,
1027 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1029 .proc_handler
= proc_dointvec
,
1032 .procname
= "page-cluster",
1033 .data
= &page_cluster
,
1034 .maxlen
= sizeof(int),
1036 .proc_handler
= proc_dointvec_minmax
,
1040 .procname
= "dirty_background_ratio",
1041 .data
= &dirty_background_ratio
,
1042 .maxlen
= sizeof(dirty_background_ratio
),
1044 .proc_handler
= dirty_background_ratio_handler
,
1046 .extra2
= &one_hundred
,
1049 .procname
= "dirty_background_bytes",
1050 .data
= &dirty_background_bytes
,
1051 .maxlen
= sizeof(dirty_background_bytes
),
1053 .proc_handler
= dirty_background_bytes_handler
,
1057 .procname
= "dirty_ratio",
1058 .data
= &vm_dirty_ratio
,
1059 .maxlen
= sizeof(vm_dirty_ratio
),
1061 .proc_handler
= dirty_ratio_handler
,
1063 .extra2
= &one_hundred
,
1066 .procname
= "dirty_bytes",
1067 .data
= &vm_dirty_bytes
,
1068 .maxlen
= sizeof(vm_dirty_bytes
),
1070 .proc_handler
= dirty_bytes_handler
,
1071 .extra1
= &dirty_bytes_min
,
1074 .procname
= "dirty_writeback_centisecs",
1075 .data
= &dirty_writeback_interval
,
1076 .maxlen
= sizeof(dirty_writeback_interval
),
1078 .proc_handler
= dirty_writeback_centisecs_handler
,
1081 .procname
= "dirty_expire_centisecs",
1082 .data
= &dirty_expire_interval
,
1083 .maxlen
= sizeof(dirty_expire_interval
),
1085 .proc_handler
= proc_dointvec_minmax
,
1089 .procname
= "nr_pdflush_threads",
1090 .data
= &nr_pdflush_threads
,
1091 .maxlen
= sizeof nr_pdflush_threads
,
1092 .mode
= 0444 /* read-only*/,
1093 .proc_handler
= proc_dointvec
,
1096 .procname
= "swappiness",
1097 .data
= &vm_swappiness
,
1098 .maxlen
= sizeof(vm_swappiness
),
1100 .proc_handler
= proc_dointvec_minmax
,
1102 .extra2
= &one_hundred
,
1104 #ifdef CONFIG_HUGETLB_PAGE
1106 .procname
= "nr_hugepages",
1108 .maxlen
= sizeof(unsigned long),
1110 .proc_handler
= hugetlb_sysctl_handler
,
1111 .extra1
= (void *)&hugetlb_zero
,
1112 .extra2
= (void *)&hugetlb_infinity
,
1116 .procname
= "nr_hugepages_mempolicy",
1118 .maxlen
= sizeof(unsigned long),
1120 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1121 .extra1
= (void *)&hugetlb_zero
,
1122 .extra2
= (void *)&hugetlb_infinity
,
1126 .procname
= "hugetlb_shm_group",
1127 .data
= &sysctl_hugetlb_shm_group
,
1128 .maxlen
= sizeof(gid_t
),
1130 .proc_handler
= proc_dointvec
,
1133 .procname
= "hugepages_treat_as_movable",
1134 .data
= &hugepages_treat_as_movable
,
1135 .maxlen
= sizeof(int),
1137 .proc_handler
= hugetlb_treat_movable_handler
,
1140 .procname
= "nr_overcommit_hugepages",
1142 .maxlen
= sizeof(unsigned long),
1144 .proc_handler
= hugetlb_overcommit_handler
,
1145 .extra1
= (void *)&hugetlb_zero
,
1146 .extra2
= (void *)&hugetlb_infinity
,
1150 .procname
= "lowmem_reserve_ratio",
1151 .data
= &sysctl_lowmem_reserve_ratio
,
1152 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1154 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1157 .procname
= "drop_caches",
1158 .data
= &sysctl_drop_caches
,
1159 .maxlen
= sizeof(int),
1161 .proc_handler
= drop_caches_sysctl_handler
,
1165 #ifdef CONFIG_COMPACTION
1167 .procname
= "compact_memory",
1168 .data
= &sysctl_compact_memory
,
1169 .maxlen
= sizeof(int),
1171 .proc_handler
= sysctl_compaction_handler
,
1174 .procname
= "extfrag_threshold",
1175 .data
= &sysctl_extfrag_threshold
,
1176 .maxlen
= sizeof(int),
1178 .proc_handler
= sysctl_extfrag_handler
,
1179 .extra1
= &min_extfrag_threshold
,
1180 .extra2
= &max_extfrag_threshold
,
1183 #endif /* CONFIG_COMPACTION */
1185 .procname
= "min_free_kbytes",
1186 .data
= &min_free_kbytes
,
1187 .maxlen
= sizeof(min_free_kbytes
),
1189 .proc_handler
= min_free_kbytes_sysctl_handler
,
1193 .procname
= "min_free_order_shift",
1194 .data
= &min_free_order_shift
,
1195 .maxlen
= sizeof(min_free_order_shift
),
1197 .proc_handler
= &proc_dointvec
1200 .procname
= "percpu_pagelist_fraction",
1201 .data
= &percpu_pagelist_fraction
,
1202 .maxlen
= sizeof(percpu_pagelist_fraction
),
1204 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1205 .extra1
= &min_percpu_pagelist_fract
,
1209 .procname
= "max_map_count",
1210 .data
= &sysctl_max_map_count
,
1211 .maxlen
= sizeof(sysctl_max_map_count
),
1213 .proc_handler
= proc_dointvec_minmax
,
1218 .procname
= "nr_trim_pages",
1219 .data
= &sysctl_nr_trim_pages
,
1220 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1222 .proc_handler
= proc_dointvec_minmax
,
1227 .procname
= "laptop_mode",
1228 .data
= &laptop_mode
,
1229 .maxlen
= sizeof(laptop_mode
),
1231 .proc_handler
= proc_dointvec_jiffies
,
1234 .procname
= "block_dump",
1235 .data
= &block_dump
,
1236 .maxlen
= sizeof(block_dump
),
1238 .proc_handler
= proc_dointvec
,
1242 .procname
= "vfs_cache_pressure",
1243 .data
= &sysctl_vfs_cache_pressure
,
1244 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1246 .proc_handler
= proc_dointvec
,
1249 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1251 .procname
= "legacy_va_layout",
1252 .data
= &sysctl_legacy_va_layout
,
1253 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1255 .proc_handler
= proc_dointvec
,
1261 .procname
= "zone_reclaim_mode",
1262 .data
= &zone_reclaim_mode
,
1263 .maxlen
= sizeof(zone_reclaim_mode
),
1265 .proc_handler
= proc_dointvec
,
1269 .procname
= "min_unmapped_ratio",
1270 .data
= &sysctl_min_unmapped_ratio
,
1271 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1273 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1275 .extra2
= &one_hundred
,
1278 .procname
= "min_slab_ratio",
1279 .data
= &sysctl_min_slab_ratio
,
1280 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1282 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1284 .extra2
= &one_hundred
,
1289 .procname
= "stat_interval",
1290 .data
= &sysctl_stat_interval
,
1291 .maxlen
= sizeof(sysctl_stat_interval
),
1293 .proc_handler
= proc_dointvec_jiffies
,
1298 .procname
= "mmap_min_addr",
1299 .data
= &dac_mmap_min_addr
,
1300 .maxlen
= sizeof(unsigned long),
1302 .proc_handler
= mmap_min_addr_handler
,
1307 .procname
= "numa_zonelist_order",
1308 .data
= &numa_zonelist_order
,
1309 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1311 .proc_handler
= numa_zonelist_order_handler
,
1314 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1315 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1317 .procname
= "vdso_enabled",
1318 .data
= &vdso_enabled
,
1319 .maxlen
= sizeof(vdso_enabled
),
1321 .proc_handler
= proc_dointvec
,
1325 #ifdef CONFIG_HIGHMEM
1327 .procname
= "highmem_is_dirtyable",
1328 .data
= &vm_highmem_is_dirtyable
,
1329 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1331 .proc_handler
= proc_dointvec_minmax
,
1337 .procname
= "scan_unevictable_pages",
1338 .data
= &scan_unevictable_pages
,
1339 .maxlen
= sizeof(scan_unevictable_pages
),
1341 .proc_handler
= scan_unevictable_handler
,
1343 #ifdef CONFIG_MEMORY_FAILURE
1345 .procname
= "memory_failure_early_kill",
1346 .data
= &sysctl_memory_failure_early_kill
,
1347 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1349 .proc_handler
= proc_dointvec_minmax
,
1354 .procname
= "memory_failure_recovery",
1355 .data
= &sysctl_memory_failure_recovery
,
1356 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1358 .proc_handler
= proc_dointvec_minmax
,
1366 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1367 static struct ctl_table binfmt_misc_table
[] = {
1372 static struct ctl_table fs_table
[] = {
1374 .procname
= "inode-nr",
1375 .data
= &inodes_stat
,
1376 .maxlen
= 2*sizeof(int),
1378 .proc_handler
= proc_nr_inodes
,
1381 .procname
= "inode-state",
1382 .data
= &inodes_stat
,
1383 .maxlen
= 7*sizeof(int),
1385 .proc_handler
= proc_nr_inodes
,
1388 .procname
= "file-nr",
1389 .data
= &files_stat
,
1390 .maxlen
= sizeof(files_stat
),
1392 .proc_handler
= proc_nr_files
,
1395 .procname
= "file-max",
1396 .data
= &files_stat
.max_files
,
1397 .maxlen
= sizeof(files_stat
.max_files
),
1399 .proc_handler
= proc_doulongvec_minmax
,
1402 .procname
= "nr_open",
1403 .data
= &sysctl_nr_open
,
1404 .maxlen
= sizeof(int),
1406 .proc_handler
= proc_dointvec_minmax
,
1407 .extra1
= &sysctl_nr_open_min
,
1408 .extra2
= &sysctl_nr_open_max
,
1411 .procname
= "dentry-state",
1412 .data
= &dentry_stat
,
1413 .maxlen
= 6*sizeof(int),
1415 .proc_handler
= proc_nr_dentry
,
1418 .procname
= "overflowuid",
1419 .data
= &fs_overflowuid
,
1420 .maxlen
= sizeof(int),
1422 .proc_handler
= proc_dointvec_minmax
,
1423 .extra1
= &minolduid
,
1424 .extra2
= &maxolduid
,
1427 .procname
= "overflowgid",
1428 .data
= &fs_overflowgid
,
1429 .maxlen
= sizeof(int),
1431 .proc_handler
= proc_dointvec_minmax
,
1432 .extra1
= &minolduid
,
1433 .extra2
= &maxolduid
,
1435 #ifdef CONFIG_FILE_LOCKING
1437 .procname
= "leases-enable",
1438 .data
= &leases_enable
,
1439 .maxlen
= sizeof(int),
1441 .proc_handler
= proc_dointvec
,
1444 #ifdef CONFIG_DNOTIFY
1446 .procname
= "dir-notify-enable",
1447 .data
= &dir_notify_enable
,
1448 .maxlen
= sizeof(int),
1450 .proc_handler
= proc_dointvec
,
1454 #ifdef CONFIG_FILE_LOCKING
1456 .procname
= "lease-break-time",
1457 .data
= &lease_break_time
,
1458 .maxlen
= sizeof(int),
1460 .proc_handler
= proc_dointvec
,
1465 .procname
= "aio-nr",
1467 .maxlen
= sizeof(aio_nr
),
1469 .proc_handler
= proc_doulongvec_minmax
,
1472 .procname
= "aio-max-nr",
1473 .data
= &aio_max_nr
,
1474 .maxlen
= sizeof(aio_max_nr
),
1476 .proc_handler
= proc_doulongvec_minmax
,
1478 #endif /* CONFIG_AIO */
1479 #ifdef CONFIG_INOTIFY_USER
1481 .procname
= "inotify",
1483 .child
= inotify_table
,
1488 .procname
= "epoll",
1490 .child
= epoll_table
,
1495 .procname
= "suid_dumpable",
1496 .data
= &suid_dumpable
,
1497 .maxlen
= sizeof(int),
1499 .proc_handler
= proc_dointvec_minmax
,
1503 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1505 .procname
= "binfmt_misc",
1507 .child
= binfmt_misc_table
,
1511 .procname
= "pipe-max-size",
1512 .data
= &pipe_max_size
,
1513 .maxlen
= sizeof(int),
1515 .proc_handler
= &pipe_proc_fn
,
1516 .extra1
= &pipe_min_size
,
1521 static struct ctl_table debug_table
[] = {
1522 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1523 defined(CONFIG_S390) || defined(CONFIG_TILE)
1525 .procname
= "exception-trace",
1526 .data
= &show_unhandled_signals
,
1527 .maxlen
= sizeof(int),
1529 .proc_handler
= proc_dointvec
1532 #if defined(CONFIG_OPTPROBES)
1534 .procname
= "kprobes-optimization",
1535 .data
= &sysctl_kprobes_optimization
,
1536 .maxlen
= sizeof(int),
1538 .proc_handler
= proc_kprobes_optimization_handler
,
1546 static struct ctl_table dev_table
[] = {
1550 static DEFINE_SPINLOCK(sysctl_lock
);
1552 /* called under sysctl_lock */
1553 static int use_table(struct ctl_table_header
*p
)
1555 if (unlikely(p
->unregistering
))
1561 /* called under sysctl_lock */
1562 static void unuse_table(struct ctl_table_header
*p
)
1565 if (unlikely(p
->unregistering
))
1566 complete(p
->unregistering
);
1569 /* called under sysctl_lock, will reacquire if has to wait */
1570 static void start_unregistering(struct ctl_table_header
*p
)
1573 * if p->used is 0, nobody will ever touch that entry again;
1574 * we'll eliminate all paths to it before dropping sysctl_lock
1576 if (unlikely(p
->used
)) {
1577 struct completion wait
;
1578 init_completion(&wait
);
1579 p
->unregistering
= &wait
;
1580 spin_unlock(&sysctl_lock
);
1581 wait_for_completion(&wait
);
1582 spin_lock(&sysctl_lock
);
1584 /* anything non-NULL; we'll never dereference it */
1585 p
->unregistering
= ERR_PTR(-EINVAL
);
1588 * do not remove from the list until nobody holds it; walking the
1589 * list in do_sysctl() relies on that.
1591 list_del_init(&p
->ctl_entry
);
1594 void sysctl_head_get(struct ctl_table_header
*head
)
1596 spin_lock(&sysctl_lock
);
1598 spin_unlock(&sysctl_lock
);
1601 static void free_head(struct rcu_head
*rcu
)
1603 kfree(container_of(rcu
, struct ctl_table_header
, rcu
));
1606 void sysctl_head_put(struct ctl_table_header
*head
)
1608 spin_lock(&sysctl_lock
);
1610 call_rcu(&head
->rcu
, free_head
);
1611 spin_unlock(&sysctl_lock
);
1614 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1618 spin_lock(&sysctl_lock
);
1619 if (!use_table(head
))
1620 head
= ERR_PTR(-ENOENT
);
1621 spin_unlock(&sysctl_lock
);
1625 void sysctl_head_finish(struct ctl_table_header
*head
)
1629 spin_lock(&sysctl_lock
);
1631 spin_unlock(&sysctl_lock
);
1634 static struct ctl_table_set
*
1635 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1637 struct ctl_table_set
*set
= &root
->default_set
;
1639 set
= root
->lookup(root
, namespaces
);
1643 static struct list_head
*
1644 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1646 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1650 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1651 struct ctl_table_header
*prev
)
1653 struct ctl_table_root
*root
;
1654 struct list_head
*header_list
;
1655 struct ctl_table_header
*head
;
1656 struct list_head
*tmp
;
1658 spin_lock(&sysctl_lock
);
1661 tmp
= &prev
->ctl_entry
;
1665 tmp
= &root_table_header
.ctl_entry
;
1667 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1669 if (!use_table(head
))
1671 spin_unlock(&sysctl_lock
);
1676 header_list
= lookup_header_list(root
, namespaces
);
1677 if (tmp
!= header_list
)
1681 root
= list_entry(root
->root_list
.next
,
1682 struct ctl_table_root
, root_list
);
1683 if (root
== &sysctl_table_root
)
1685 header_list
= lookup_header_list(root
, namespaces
);
1686 } while (list_empty(header_list
));
1687 tmp
= header_list
->next
;
1690 spin_unlock(&sysctl_lock
);
1694 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1696 return __sysctl_head_next(current
->nsproxy
, prev
);
1699 void register_sysctl_root(struct ctl_table_root
*root
)
1701 spin_lock(&sysctl_lock
);
1702 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1703 spin_unlock(&sysctl_lock
);
1707 * sysctl_perm does NOT grant the superuser all rights automatically, because
1708 * some sysctl variables are readonly even to root.
1711 static int test_perm(int mode
, int op
)
1713 if (!current_euid())
1715 else if (in_egroup_p(0))
1717 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1722 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1726 if (root
->permissions
)
1727 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1731 return test_perm(mode
, op
);
1734 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1736 for (; table
->procname
; table
++) {
1737 table
->parent
= parent
;
1739 sysctl_set_parent(table
, table
->child
);
1743 static __init
int sysctl_init(void)
1745 sysctl_set_parent(NULL
, root_table
);
1746 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1747 sysctl_check_table(current
->nsproxy
, root_table
);
1752 core_initcall(sysctl_init
);
1754 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1755 struct ctl_table
*table
)
1757 struct ctl_table
*p
;
1758 const char *s
= branch
->procname
;
1760 /* branch should have named subdirectory as its first element */
1761 if (!s
|| !branch
->child
)
1764 /* ... and nothing else */
1765 if (branch
[1].procname
)
1768 /* table should contain subdirectory with the same name */
1769 for (p
= table
; p
->procname
; p
++) {
1772 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1778 /* see if attaching q to p would be an improvement */
1779 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1781 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1782 struct ctl_table
*next
;
1784 int not_in_parent
= !p
->attached_by
;
1786 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1787 if (by
== q
->attached_by
)
1789 if (to
== p
->attached_by
)
1795 if (is_better
&& not_in_parent
) {
1796 q
->attached_by
= by
;
1797 q
->attached_to
= to
;
1803 * __register_sysctl_paths - register a sysctl hierarchy
1804 * @root: List of sysctl headers to register on
1805 * @namespaces: Data to compute which lists of sysctl entries are visible
1806 * @path: The path to the directory the sysctl table is in.
1807 * @table: the top-level table structure
1809 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1810 * array. A completely 0 filled entry terminates the table.
1812 * The members of the &struct ctl_table structure are used as follows:
1814 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1815 * enter a sysctl file
1817 * data - a pointer to data for use by proc_handler
1819 * maxlen - the maximum size in bytes of the data
1821 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1823 * child - a pointer to the child sysctl table if this entry is a directory, or
1826 * proc_handler - the text handler routine (described below)
1828 * de - for internal use by the sysctl routines
1830 * extra1, extra2 - extra pointers usable by the proc handler routines
1832 * Leaf nodes in the sysctl tree will be represented by a single file
1833 * under /proc; non-leaf nodes will be represented by directories.
1835 * sysctl(2) can automatically manage read and write requests through
1836 * the sysctl table. The data and maxlen fields of the ctl_table
1837 * struct enable minimal validation of the values being written to be
1838 * performed, and the mode field allows minimal authentication.
1840 * There must be a proc_handler routine for any terminal nodes
1841 * mirrored under /proc/sys (non-terminals are handled by a built-in
1842 * directory handler). Several default handlers are available to
1843 * cover common cases -
1845 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1846 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1847 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1849 * It is the handler's job to read the input buffer from user memory
1850 * and process it. The handler should return 0 on success.
1852 * This routine returns %NULL on a failure to register, and a pointer
1853 * to the table header on success.
1855 struct ctl_table_header
*__register_sysctl_paths(
1856 struct ctl_table_root
*root
,
1857 struct nsproxy
*namespaces
,
1858 const struct ctl_path
*path
, struct ctl_table
*table
)
1860 struct ctl_table_header
*header
;
1861 struct ctl_table
*new, **prevp
;
1862 unsigned int n
, npath
;
1863 struct ctl_table_set
*set
;
1865 /* Count the path components */
1866 for (npath
= 0; path
[npath
].procname
; ++npath
)
1870 * For each path component, allocate a 2-element ctl_table array.
1871 * The first array element will be filled with the sysctl entry
1872 * for this, the second will be the sentinel (procname == 0).
1874 * We allocate everything in one go so that we don't have to
1875 * worry about freeing additional memory in unregister_sysctl_table.
1877 header
= kzalloc(sizeof(struct ctl_table_header
) +
1878 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1882 new = (struct ctl_table
*) (header
+ 1);
1884 /* Now connect the dots */
1885 prevp
= &header
->ctl_table
;
1886 for (n
= 0; n
< npath
; ++n
, ++path
) {
1887 /* Copy the procname */
1888 new->procname
= path
->procname
;
1892 prevp
= &new->child
;
1897 header
->ctl_table_arg
= table
;
1899 INIT_LIST_HEAD(&header
->ctl_entry
);
1901 header
->unregistering
= NULL
;
1902 header
->root
= root
;
1903 sysctl_set_parent(NULL
, header
->ctl_table
);
1905 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1906 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1911 spin_lock(&sysctl_lock
);
1912 header
->set
= lookup_header_set(root
, namespaces
);
1913 header
->attached_by
= header
->ctl_table
;
1914 header
->attached_to
= root_table
;
1915 header
->parent
= &root_table_header
;
1916 for (set
= header
->set
; set
; set
= set
->parent
) {
1917 struct ctl_table_header
*p
;
1918 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1919 if (p
->unregistering
)
1921 try_attach(p
, header
);
1924 header
->parent
->count
++;
1925 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1926 spin_unlock(&sysctl_lock
);
1932 * register_sysctl_table_path - register a sysctl table hierarchy
1933 * @path: The path to the directory the sysctl table is in.
1934 * @table: the top-level table structure
1936 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1937 * array. A completely 0 filled entry terminates the table.
1939 * See __register_sysctl_paths for more details.
1941 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1942 struct ctl_table
*table
)
1944 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1949 * register_sysctl_table - register a sysctl table hierarchy
1950 * @table: the top-level table structure
1952 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1953 * array. A completely 0 filled entry terminates the table.
1955 * See register_sysctl_paths for more details.
1957 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1959 static const struct ctl_path null_path
[] = { {} };
1961 return register_sysctl_paths(null_path
, table
);
1965 * unregister_sysctl_table - unregister a sysctl table hierarchy
1966 * @header: the header returned from register_sysctl_table
1968 * Unregisters the sysctl table and all children. proc entries may not
1969 * actually be removed until they are no longer used by anyone.
1971 void unregister_sysctl_table(struct ctl_table_header
* header
)
1978 spin_lock(&sysctl_lock
);
1979 start_unregistering(header
);
1980 if (!--header
->parent
->count
) {
1982 call_rcu(&header
->parent
->rcu
, free_head
);
1984 if (!--header
->count
)
1985 call_rcu(&header
->rcu
, free_head
);
1986 spin_unlock(&sysctl_lock
);
1989 int sysctl_is_seen(struct ctl_table_header
*p
)
1991 struct ctl_table_set
*set
= p
->set
;
1993 spin_lock(&sysctl_lock
);
1994 if (p
->unregistering
)
1996 else if (!set
->is_seen
)
1999 res
= set
->is_seen(set
);
2000 spin_unlock(&sysctl_lock
);
2004 void setup_sysctl_set(struct ctl_table_set
*p
,
2005 struct ctl_table_set
*parent
,
2006 int (*is_seen
)(struct ctl_table_set
*))
2008 INIT_LIST_HEAD(&p
->list
);
2009 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2010 p
->is_seen
= is_seen
;
2013 #else /* !CONFIG_SYSCTL */
2014 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2019 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2020 struct ctl_table
*table
)
2025 void unregister_sysctl_table(struct ctl_table_header
* table
)
2029 void setup_sysctl_set(struct ctl_table_set
*p
,
2030 struct ctl_table_set
*parent
,
2031 int (*is_seen
)(struct ctl_table_set
*))
2035 void sysctl_head_put(struct ctl_table_header
*head
)
2039 #endif /* CONFIG_SYSCTL */
2045 #ifdef CONFIG_PROC_SYSCTL
2047 static int _proc_do_string(void* data
, int maxlen
, int write
,
2048 void __user
*buffer
,
2049 size_t *lenp
, loff_t
*ppos
)
2055 if (!data
|| !maxlen
|| !*lenp
) {
2063 while (len
< *lenp
) {
2064 if (get_user(c
, p
++))
2066 if (c
== 0 || c
== '\n')
2072 if(copy_from_user(data
, buffer
, len
))
2074 ((char *) data
)[len
] = 0;
2092 if(copy_to_user(buffer
, data
, len
))
2095 if(put_user('\n', ((char __user
*) buffer
) + len
))
2106 * proc_dostring - read a string sysctl
2107 * @table: the sysctl table
2108 * @write: %TRUE if this is a write to the sysctl file
2109 * @buffer: the user buffer
2110 * @lenp: the size of the user buffer
2111 * @ppos: file position
2113 * Reads/writes a string from/to the user buffer. If the kernel
2114 * buffer provided is not large enough to hold the string, the
2115 * string is truncated. The copied string is %NULL-terminated.
2116 * If the string is being read by the user process, it is copied
2117 * and a newline '\n' is added. It is truncated if the buffer is
2120 * Returns 0 on success.
2122 int proc_dostring(struct ctl_table
*table
, int write
,
2123 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2125 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2126 buffer
, lenp
, ppos
);
2129 static size_t proc_skip_spaces(char **buf
)
2132 char *tmp
= skip_spaces(*buf
);
2138 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2148 #define TMPBUFLEN 22
2150 * proc_get_long - reads an ASCII formatted integer from a user buffer
2152 * @buf: a kernel buffer
2153 * @size: size of the kernel buffer
2154 * @val: this is where the number will be stored
2155 * @neg: set to %TRUE if number is negative
2156 * @perm_tr: a vector which contains the allowed trailers
2157 * @perm_tr_len: size of the perm_tr vector
2158 * @tr: pointer to store the trailer character
2160 * In case of success %0 is returned and @buf and @size are updated with
2161 * the amount of bytes read. If @tr is non-NULL and a trailing
2162 * character exists (size is non-zero after returning from this
2163 * function), @tr is updated with the trailing character.
2165 static int proc_get_long(char **buf
, size_t *size
,
2166 unsigned long *val
, bool *neg
,
2167 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2170 char *p
, tmp
[TMPBUFLEN
];
2176 if (len
> TMPBUFLEN
- 1)
2177 len
= TMPBUFLEN
- 1;
2179 memcpy(tmp
, *buf
, len
);
2183 if (*p
== '-' && *size
> 1) {
2191 *val
= simple_strtoul(p
, &p
, 0);
2195 /* We don't know if the next char is whitespace thus we may accept
2196 * invalid integers (e.g. 1234...a) or two integers instead of one
2197 * (e.g. 123...1). So lets not allow such large numbers. */
2198 if (len
== TMPBUFLEN
- 1)
2201 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2204 if (tr
&& (len
< *size
))
2214 * proc_put_long - converts an integer to a decimal ASCII formatted string
2216 * @buf: the user buffer
2217 * @size: the size of the user buffer
2218 * @val: the integer to be converted
2219 * @neg: sign of the number, %TRUE for negative
2221 * In case of success %0 is returned and @buf and @size are updated with
2222 * the amount of bytes written.
2224 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2228 char tmp
[TMPBUFLEN
], *p
= tmp
;
2230 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2234 if (copy_to_user(*buf
, tmp
, len
))
2242 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2245 char __user
**buffer
= (char __user
**)buf
;
2246 if (put_user(c
, *buffer
))
2248 (*size
)--, (*buffer
)++;
2254 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2256 int write
, void *data
)
2259 *valp
= *negp
? -*lvalp
: *lvalp
;
2264 *lvalp
= (unsigned long)-val
;
2267 *lvalp
= (unsigned long)val
;
2273 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2275 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2276 int write
, void __user
*buffer
,
2277 size_t *lenp
, loff_t
*ppos
,
2278 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2279 int write
, void *data
),
2282 int *i
, vleft
, first
= 1, err
= 0;
2283 unsigned long page
= 0;
2287 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2292 i
= (int *) tbl_data
;
2293 vleft
= table
->maxlen
/ sizeof(*i
);
2297 conv
= do_proc_dointvec_conv
;
2300 if (left
> PAGE_SIZE
- 1)
2301 left
= PAGE_SIZE
- 1;
2302 page
= __get_free_page(GFP_TEMPORARY
);
2303 kbuf
= (char *) page
;
2306 if (copy_from_user(kbuf
, buffer
, left
)) {
2313 for (; left
&& vleft
--; i
++, first
=0) {
2318 left
-= proc_skip_spaces(&kbuf
);
2322 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2324 sizeof(proc_wspace_sep
), NULL
);
2327 if (conv(&neg
, &lval
, i
, 1, data
)) {
2332 if (conv(&neg
, &lval
, i
, 0, data
)) {
2337 err
= proc_put_char(&buffer
, &left
, '\t');
2340 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2346 if (!write
&& !first
&& left
&& !err
)
2347 err
= proc_put_char(&buffer
, &left
, '\n');
2348 if (write
&& !err
&& left
)
2349 left
-= proc_skip_spaces(&kbuf
);
2354 return err
? : -EINVAL
;
2361 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2362 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2363 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2364 int write
, void *data
),
2367 return __do_proc_dointvec(table
->data
, table
, write
,
2368 buffer
, lenp
, ppos
, conv
, data
);
2372 * proc_dointvec - read a vector of integers
2373 * @table: the sysctl table
2374 * @write: %TRUE if this is a write to the sysctl file
2375 * @buffer: the user buffer
2376 * @lenp: the size of the user buffer
2377 * @ppos: file position
2379 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2380 * values from/to the user buffer, treated as an ASCII string.
2382 * Returns 0 on success.
2384 int proc_dointvec(struct ctl_table
*table
, int write
,
2385 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2387 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2392 * Taint values can only be increased
2393 * This means we can safely use a temporary.
2395 static int proc_taint(struct ctl_table
*table
, int write
,
2396 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2399 unsigned long tmptaint
= get_taint();
2402 if (write
&& !capable(CAP_SYS_ADMIN
))
2407 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2413 * Poor man's atomic or. Not worth adding a primitive
2414 * to everyone's atomic.h for this
2417 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2418 if ((tmptaint
>> i
) & 1)
2426 #ifdef CONFIG_PRINTK
2427 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2428 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2430 if (write
&& !capable(CAP_SYS_ADMIN
))
2433 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2437 struct do_proc_dointvec_minmax_conv_param
{
2442 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2444 int write
, void *data
)
2446 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2448 int val
= *negp
? -*lvalp
: *lvalp
;
2449 if ((param
->min
&& *param
->min
> val
) ||
2450 (param
->max
&& *param
->max
< val
))
2457 *lvalp
= (unsigned long)-val
;
2460 *lvalp
= (unsigned long)val
;
2467 * proc_dointvec_minmax - read a vector of integers with min/max values
2468 * @table: the sysctl table
2469 * @write: %TRUE if this is a write to the sysctl file
2470 * @buffer: the user buffer
2471 * @lenp: the size of the user buffer
2472 * @ppos: file position
2474 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2475 * values from/to the user buffer, treated as an ASCII string.
2477 * This routine will ensure the values are within the range specified by
2478 * table->extra1 (min) and table->extra2 (max).
2480 * Returns 0 on success.
2482 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2483 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2485 struct do_proc_dointvec_minmax_conv_param param
= {
2486 .min
= (int *) table
->extra1
,
2487 .max
= (int *) table
->extra2
,
2489 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2490 do_proc_dointvec_minmax_conv
, ¶m
);
2493 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2494 void __user
*buffer
,
2495 size_t *lenp
, loff_t
*ppos
,
2496 unsigned long convmul
,
2497 unsigned long convdiv
)
2499 unsigned long *i
, *min
, *max
;
2500 int vleft
, first
= 1, err
= 0;
2501 unsigned long page
= 0;
2505 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2510 i
= (unsigned long *) data
;
2511 min
= (unsigned long *) table
->extra1
;
2512 max
= (unsigned long *) table
->extra2
;
2513 vleft
= table
->maxlen
/ sizeof(unsigned long);
2517 if (left
> PAGE_SIZE
- 1)
2518 left
= PAGE_SIZE
- 1;
2519 page
= __get_free_page(GFP_TEMPORARY
);
2520 kbuf
= (char *) page
;
2523 if (copy_from_user(kbuf
, buffer
, left
)) {
2530 for (; left
&& vleft
--; i
++, first
= 0) {
2536 left
-= proc_skip_spaces(&kbuf
);
2538 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2540 sizeof(proc_wspace_sep
), NULL
);
2545 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2549 val
= convdiv
* (*i
) / convmul
;
2551 err
= proc_put_char(&buffer
, &left
, '\t');
2552 err
= proc_put_long(&buffer
, &left
, val
, false);
2558 if (!write
&& !first
&& left
&& !err
)
2559 err
= proc_put_char(&buffer
, &left
, '\n');
2561 left
-= proc_skip_spaces(&kbuf
);
2566 return err
? : -EINVAL
;
2573 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2574 void __user
*buffer
,
2575 size_t *lenp
, loff_t
*ppos
,
2576 unsigned long convmul
,
2577 unsigned long convdiv
)
2579 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2580 buffer
, lenp
, ppos
, convmul
, convdiv
);
2584 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2585 * @table: the sysctl table
2586 * @write: %TRUE if this is a write to the sysctl file
2587 * @buffer: the user buffer
2588 * @lenp: the size of the user buffer
2589 * @ppos: file position
2591 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2592 * values from/to the user buffer, treated as an ASCII string.
2594 * This routine will ensure the values are within the range specified by
2595 * table->extra1 (min) and table->extra2 (max).
2597 * Returns 0 on success.
2599 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2600 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2602 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2606 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2607 * @table: the sysctl table
2608 * @write: %TRUE if this is a write to the sysctl file
2609 * @buffer: the user buffer
2610 * @lenp: the size of the user buffer
2611 * @ppos: file position
2613 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2614 * values from/to the user buffer, treated as an ASCII string. The values
2615 * are treated as milliseconds, and converted to jiffies when they are stored.
2617 * This routine will ensure the values are within the range specified by
2618 * table->extra1 (min) and table->extra2 (max).
2620 * Returns 0 on success.
2622 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2623 void __user
*buffer
,
2624 size_t *lenp
, loff_t
*ppos
)
2626 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2627 lenp
, ppos
, HZ
, 1000l);
2631 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2633 int write
, void *data
)
2636 if (*lvalp
> LONG_MAX
/ HZ
)
2638 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2644 lval
= (unsigned long)-val
;
2647 lval
= (unsigned long)val
;
2654 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2656 int write
, void *data
)
2659 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2661 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2667 lval
= (unsigned long)-val
;
2670 lval
= (unsigned long)val
;
2672 *lvalp
= jiffies_to_clock_t(lval
);
2677 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2679 int write
, void *data
)
2682 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2688 lval
= (unsigned long)-val
;
2691 lval
= (unsigned long)val
;
2693 *lvalp
= jiffies_to_msecs(lval
);
2699 * proc_dointvec_jiffies - read a vector of integers as seconds
2700 * @table: the sysctl table
2701 * @write: %TRUE if this is a write to the sysctl file
2702 * @buffer: the user buffer
2703 * @lenp: the size of the user buffer
2704 * @ppos: file position
2706 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2707 * values from/to the user buffer, treated as an ASCII string.
2708 * The values read are assumed to be in seconds, and are converted into
2711 * Returns 0 on success.
2713 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2714 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2716 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2717 do_proc_dointvec_jiffies_conv
,NULL
);
2721 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2722 * @table: the sysctl table
2723 * @write: %TRUE if this is a write to the sysctl file
2724 * @buffer: the user buffer
2725 * @lenp: the size of the user buffer
2726 * @ppos: pointer to the file position
2728 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2729 * values from/to the user buffer, treated as an ASCII string.
2730 * The values read are assumed to be in 1/USER_HZ seconds, and
2731 * are converted into jiffies.
2733 * Returns 0 on success.
2735 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2736 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2738 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2739 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2743 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2744 * @table: the sysctl table
2745 * @write: %TRUE if this is a write to the sysctl file
2746 * @buffer: the user buffer
2747 * @lenp: the size of the user buffer
2748 * @ppos: file position
2749 * @ppos: the current position in the file
2751 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2752 * values from/to the user buffer, treated as an ASCII string.
2753 * The values read are assumed to be in 1/1000 seconds, and
2754 * are converted into jiffies.
2756 * Returns 0 on success.
2758 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2759 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2761 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2762 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2765 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2766 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2768 struct pid
*new_pid
;
2772 tmp
= pid_vnr(cad_pid
);
2774 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2775 lenp
, ppos
, NULL
, NULL
);
2779 new_pid
= find_get_pid(tmp
);
2783 put_pid(xchg(&cad_pid
, new_pid
));
2788 * proc_do_large_bitmap - read/write from/to a large bitmap
2789 * @table: the sysctl table
2790 * @write: %TRUE if this is a write to the sysctl file
2791 * @buffer: the user buffer
2792 * @lenp: the size of the user buffer
2793 * @ppos: file position
2795 * The bitmap is stored at table->data and the bitmap length (in bits)
2798 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2799 * large bitmaps may be represented in a compact manner. Writing into
2800 * the file will clear the bitmap then update it with the given input.
2802 * Returns 0 on success.
2804 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2805 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2809 size_t left
= *lenp
;
2810 unsigned long bitmap_len
= table
->maxlen
;
2811 unsigned long *bitmap
= (unsigned long *) table
->data
;
2812 unsigned long *tmp_bitmap
= NULL
;
2813 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2815 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2821 unsigned long page
= 0;
2824 if (left
> PAGE_SIZE
- 1)
2825 left
= PAGE_SIZE
- 1;
2827 page
= __get_free_page(GFP_TEMPORARY
);
2828 kbuf
= (char *) page
;
2831 if (copy_from_user(kbuf
, buffer
, left
)) {
2837 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2843 proc_skip_char(&kbuf
, &left
, '\n');
2844 while (!err
&& left
) {
2845 unsigned long val_a
, val_b
;
2848 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2852 if (val_a
>= bitmap_len
|| neg
) {
2864 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2865 &neg
, tr_b
, sizeof(tr_b
),
2869 if (val_b
>= bitmap_len
|| neg
||
2880 while (val_a
<= val_b
)
2881 set_bit(val_a
++, tmp_bitmap
);
2884 proc_skip_char(&kbuf
, &left
, '\n');
2888 unsigned long bit_a
, bit_b
= 0;
2891 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2892 if (bit_a
>= bitmap_len
)
2894 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2898 err
= proc_put_char(&buffer
, &left
, ',');
2902 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2905 if (bit_a
!= bit_b
) {
2906 err
= proc_put_char(&buffer
, &left
, '-');
2909 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2917 err
= proc_put_char(&buffer
, &left
, '\n');
2923 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2925 memcpy(bitmap
, tmp_bitmap
,
2926 BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long));
2938 #else /* CONFIG_PROC_SYSCTL */
2940 int proc_dostring(struct ctl_table
*table
, int write
,
2941 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2946 int proc_dointvec(struct ctl_table
*table
, int write
,
2947 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2952 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2953 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2958 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2959 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2964 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2965 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2970 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2971 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2976 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2977 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2982 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2983 void __user
*buffer
,
2984 size_t *lenp
, loff_t
*ppos
)
2990 #endif /* CONFIG_PROC_SYSCTL */
2993 * No sense putting this after each symbol definition, twice,
2994 * exception granted :-)
2996 EXPORT_SYMBOL(proc_dointvec
);
2997 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2998 EXPORT_SYMBOL(proc_dointvec_minmax
);
2999 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3000 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3001 EXPORT_SYMBOL(proc_dostring
);
3002 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3003 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3004 EXPORT_SYMBOL(register_sysctl_table
);
3005 EXPORT_SYMBOL(register_sysctl_paths
);
3006 EXPORT_SYMBOL(unregister_sysctl_table
);