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/export.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 pid_max_min
, pid_max_max
;
100 extern int sysctl_drop_caches
;
101 extern int percpu_pagelist_fraction
;
102 extern int compat_log
;
103 extern int latencytop_enabled
;
104 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
106 extern int sysctl_nr_trim_pages
;
109 extern int blk_iopoll_enabled
;
112 /* Constants used for minimum and maximum */
113 #ifdef CONFIG_LOCKUP_DETECTOR
114 static int sixty
= 60;
115 static int neg_one
= -1;
119 static int __maybe_unused one
= 1;
120 static int __maybe_unused two
= 2;
121 static int __maybe_unused three
= 3;
122 static unsigned long one_ul
= 1;
123 static int one_hundred
= 100;
125 static int ten_thousand
= 10000;
128 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
129 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
131 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
132 static int maxolduid
= 65535;
133 static int minolduid
;
134 static int min_percpu_pagelist_fract
= 8;
136 static int ngroups_max
= NGROUPS_MAX
;
138 #ifdef CONFIG_INOTIFY_USER
139 #include <linux/inotify.h>
142 #include <asm/system.h>
145 #ifdef CONFIG_SPARC64
146 extern int sysctl_tsb_ratio
;
150 extern int pwrsw_enabled
;
151 extern int unaligned_enabled
;
155 #ifdef CONFIG_MATHEMU
156 extern int sysctl_ieee_emulation_warnings
;
158 extern int sysctl_userprocess_debug
;
159 extern int spin_retry
;
163 extern int no_unaligned_warning
;
164 extern int unaligned_dump_stack
;
167 #ifdef CONFIG_PROC_SYSCTL
168 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
169 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
170 static int proc_taint(struct ctl_table
*table
, int write
,
171 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
175 static int proc_dmesg_restrict(struct ctl_table
*table
, int write
,
176 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
179 #ifdef CONFIG_MAGIC_SYSRQ
180 /* Note: sysrq code uses it's own private copy */
181 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
183 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
184 void __user
*buffer
, size_t *lenp
,
189 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
194 sysrq_toggle_support(__sysrq_enabled
);
201 static struct ctl_table root_table
[];
202 static struct ctl_table_root sysctl_table_root
;
203 static struct ctl_table_header root_table_header
= {
205 .ctl_table
= root_table
,
206 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),}},
207 .root
= &sysctl_table_root
,
208 .set
= &sysctl_table_root
.default_set
,
210 static struct ctl_table_root sysctl_table_root
= {
211 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
212 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
215 static struct ctl_table kern_table
[];
216 static struct ctl_table vm_table
[];
217 static struct ctl_table fs_table
[];
218 static struct ctl_table debug_table
[];
219 static struct ctl_table dev_table
[];
220 extern struct ctl_table random_table
[];
222 extern struct ctl_table epoll_table
[];
225 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
226 int sysctl_legacy_va_layout
;
229 /* The default sysctl tables: */
231 static struct ctl_table root_table
[] = {
233 .procname
= "kernel",
250 .child
= debug_table
,
260 #ifdef CONFIG_SCHED_DEBUG
261 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
262 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
263 static int min_wakeup_granularity_ns
; /* 0 usecs */
264 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
265 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
266 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
269 #ifdef CONFIG_COMPACTION
270 static int min_extfrag_threshold
;
271 static int max_extfrag_threshold
= 1000;
274 static struct ctl_table kern_table
[] = {
276 .procname
= "sched_child_runs_first",
277 .data
= &sysctl_sched_child_runs_first
,
278 .maxlen
= sizeof(unsigned int),
280 .proc_handler
= proc_dointvec
,
282 #ifdef CONFIG_SCHED_DEBUG
284 .procname
= "sched_min_granularity_ns",
285 .data
= &sysctl_sched_min_granularity
,
286 .maxlen
= sizeof(unsigned int),
288 .proc_handler
= sched_proc_update_handler
,
289 .extra1
= &min_sched_granularity_ns
,
290 .extra2
= &max_sched_granularity_ns
,
293 .procname
= "sched_latency_ns",
294 .data
= &sysctl_sched_latency
,
295 .maxlen
= sizeof(unsigned int),
297 .proc_handler
= sched_proc_update_handler
,
298 .extra1
= &min_sched_granularity_ns
,
299 .extra2
= &max_sched_granularity_ns
,
302 .procname
= "sched_wakeup_granularity_ns",
303 .data
= &sysctl_sched_wakeup_granularity
,
304 .maxlen
= sizeof(unsigned int),
306 .proc_handler
= sched_proc_update_handler
,
307 .extra1
= &min_wakeup_granularity_ns
,
308 .extra2
= &max_wakeup_granularity_ns
,
311 .procname
= "sched_tunable_scaling",
312 .data
= &sysctl_sched_tunable_scaling
,
313 .maxlen
= sizeof(enum sched_tunable_scaling
),
315 .proc_handler
= sched_proc_update_handler
,
316 .extra1
= &min_sched_tunable_scaling
,
317 .extra2
= &max_sched_tunable_scaling
,
320 .procname
= "sched_migration_cost",
321 .data
= &sysctl_sched_migration_cost
,
322 .maxlen
= sizeof(unsigned int),
324 .proc_handler
= proc_dointvec
,
327 .procname
= "sched_nr_migrate",
328 .data
= &sysctl_sched_nr_migrate
,
329 .maxlen
= sizeof(unsigned int),
331 .proc_handler
= proc_dointvec
,
334 .procname
= "sched_time_avg",
335 .data
= &sysctl_sched_time_avg
,
336 .maxlen
= sizeof(unsigned int),
338 .proc_handler
= proc_dointvec
,
341 .procname
= "sched_shares_window",
342 .data
= &sysctl_sched_shares_window
,
343 .maxlen
= sizeof(unsigned int),
345 .proc_handler
= proc_dointvec
,
348 .procname
= "timer_migration",
349 .data
= &sysctl_timer_migration
,
350 .maxlen
= sizeof(unsigned int),
352 .proc_handler
= proc_dointvec_bool
,
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
,
369 #ifdef CONFIG_SCHED_AUTOGROUP
371 .procname
= "sched_autogroup_enabled",
372 .data
= &sysctl_sched_autogroup_enabled
,
373 .maxlen
= sizeof(unsigned int),
375 .proc_handler
= proc_dointvec_minmax
,
380 #ifdef CONFIG_PROVE_LOCKING
382 .procname
= "prove_locking",
383 .data
= &prove_locking
,
384 .maxlen
= sizeof(int),
386 .proc_handler
= proc_dointvec
,
389 #ifdef CONFIG_LOCK_STAT
391 .procname
= "lock_stat",
393 .maxlen
= sizeof(int),
395 .proc_handler
= proc_dointvec
,
400 .data
= &panic_timeout
,
401 .maxlen
= sizeof(int),
403 .proc_handler
= proc_dointvec
,
406 .procname
= "core_uses_pid",
407 .data
= &core_uses_pid
,
408 .maxlen
= sizeof(int),
410 .proc_handler
= proc_dointvec
,
413 .procname
= "core_pattern",
414 .data
= core_pattern
,
415 .maxlen
= CORENAME_MAX_SIZE
,
417 .proc_handler
= proc_dostring
,
420 .procname
= "core_pipe_limit",
421 .data
= &core_pipe_limit
,
422 .maxlen
= sizeof(unsigned int),
424 .proc_handler
= proc_dointvec
,
426 #ifdef CONFIG_PROC_SYSCTL
428 .procname
= "tainted",
429 .maxlen
= sizeof(long),
431 .proc_handler
= proc_taint
,
434 #ifdef CONFIG_LATENCYTOP
436 .procname
= "latencytop",
437 .data
= &latencytop_enabled
,
438 .maxlen
= sizeof(int),
440 .proc_handler
= proc_dointvec
,
443 #ifdef CONFIG_BLK_DEV_INITRD
445 .procname
= "real-root-dev",
446 .data
= &real_root_dev
,
447 .maxlen
= sizeof(int),
449 .proc_handler
= proc_dointvec
,
453 .procname
= "print-fatal-signals",
454 .data
= &print_fatal_signals
,
455 .maxlen
= sizeof(int),
457 .proc_handler
= proc_dointvec
,
461 .procname
= "reboot-cmd",
462 .data
= reboot_command
,
465 .proc_handler
= proc_dostring
,
468 .procname
= "stop-a",
469 .data
= &stop_a_enabled
,
470 .maxlen
= sizeof (int),
472 .proc_handler
= proc_dointvec
,
475 .procname
= "scons-poweroff",
476 .data
= &scons_pwroff
,
477 .maxlen
= sizeof (int),
479 .proc_handler
= proc_dointvec
,
482 #ifdef CONFIG_SPARC64
484 .procname
= "tsb-ratio",
485 .data
= &sysctl_tsb_ratio
,
486 .maxlen
= sizeof (int),
488 .proc_handler
= proc_dointvec
,
493 .procname
= "soft-power",
494 .data
= &pwrsw_enabled
,
495 .maxlen
= sizeof (int),
497 .proc_handler
= proc_dointvec
,
500 .procname
= "unaligned-trap",
501 .data
= &unaligned_enabled
,
502 .maxlen
= sizeof (int),
504 .proc_handler
= proc_dointvec
,
508 .procname
= "ctrl-alt-del",
510 .maxlen
= sizeof(int),
512 .proc_handler
= proc_dointvec
,
514 #ifdef CONFIG_FUNCTION_TRACER
516 .procname
= "ftrace_enabled",
517 .data
= &ftrace_enabled
,
518 .maxlen
= sizeof(int),
520 .proc_handler
= ftrace_enable_sysctl
,
523 #ifdef CONFIG_STACK_TRACER
525 .procname
= "stack_tracer_enabled",
526 .data
= &stack_tracer_enabled
,
527 .maxlen
= sizeof(int),
529 .proc_handler
= stack_trace_sysctl
,
532 #ifdef CONFIG_TRACING
534 .procname
= "ftrace_dump_on_oops",
535 .data
= &ftrace_dump_on_oops
,
536 .maxlen
= sizeof(int),
538 .proc_handler
= proc_dointvec
,
541 #ifdef CONFIG_MODULES
543 .procname
= "modprobe",
544 .data
= &modprobe_path
,
545 .maxlen
= KMOD_PATH_LEN
,
547 .proc_handler
= proc_dostring
,
550 .procname
= "modules_disabled",
551 .data
= &modules_disabled
,
552 .maxlen
= sizeof(int),
554 /* only handle a transition from default "0" to "1" */
555 .proc_handler
= proc_dointvec_minmax
,
560 #ifdef CONFIG_HOTPLUG
562 .procname
= "hotplug",
563 .data
= &uevent_helper
,
564 .maxlen
= UEVENT_HELPER_PATH_LEN
,
566 .proc_handler
= proc_dostring
,
569 #ifdef CONFIG_CHR_DEV_SG
571 .procname
= "sg-big-buff",
572 .data
= &sg_big_buff
,
573 .maxlen
= sizeof (int),
575 .proc_handler
= proc_dointvec
,
578 #ifdef CONFIG_BSD_PROCESS_ACCT
582 .maxlen
= 3*sizeof(int),
584 .proc_handler
= proc_dointvec
,
587 #ifdef CONFIG_MAGIC_SYSRQ
590 .data
= &__sysrq_enabled
,
591 .maxlen
= sizeof (int),
593 .proc_handler
= sysrq_sysctl_handler
,
596 #ifdef CONFIG_PROC_SYSCTL
598 .procname
= "cad_pid",
600 .maxlen
= sizeof (int),
602 .proc_handler
= proc_do_cad_pid
,
606 .procname
= "threads-max",
607 .data
= &max_threads
,
608 .maxlen
= sizeof(int),
610 .proc_handler
= proc_dointvec
,
613 .procname
= "random",
615 .child
= random_table
,
618 .procname
= "usermodehelper",
620 .child
= usermodehelper_table
,
623 .procname
= "overflowuid",
624 .data
= &overflowuid
,
625 .maxlen
= sizeof(int),
627 .proc_handler
= proc_dointvec_minmax
,
628 .extra1
= &minolduid
,
629 .extra2
= &maxolduid
,
632 .procname
= "overflowgid",
633 .data
= &overflowgid
,
634 .maxlen
= sizeof(int),
636 .proc_handler
= proc_dointvec_minmax
,
637 .extra1
= &minolduid
,
638 .extra2
= &maxolduid
,
641 #ifdef CONFIG_MATHEMU
643 .procname
= "ieee_emulation_warnings",
644 .data
= &sysctl_ieee_emulation_warnings
,
645 .maxlen
= sizeof(int),
647 .proc_handler
= proc_dointvec
,
651 .procname
= "userprocess_debug",
652 .data
= &show_unhandled_signals
,
653 .maxlen
= sizeof(int),
655 .proc_handler
= proc_dointvec
,
659 .procname
= "pid_max",
661 .maxlen
= sizeof (int),
663 .proc_handler
= proc_dointvec_minmax
,
664 .extra1
= &pid_max_min
,
665 .extra2
= &pid_max_max
,
668 .procname
= "panic_on_oops",
669 .data
= &panic_on_oops
,
670 .maxlen
= sizeof(int),
672 .proc_handler
= proc_dointvec
,
674 #if defined CONFIG_PRINTK
676 .procname
= "printk",
677 .data
= &console_loglevel
,
678 .maxlen
= 4*sizeof(int),
680 .proc_handler
= proc_dointvec
,
683 .procname
= "printk_ratelimit",
684 .data
= &printk_ratelimit_state
.interval
,
685 .maxlen
= sizeof(int),
687 .proc_handler
= proc_dointvec_jiffies
,
690 .procname
= "printk_ratelimit_burst",
691 .data
= &printk_ratelimit_state
.burst
,
692 .maxlen
= sizeof(int),
694 .proc_handler
= proc_dointvec
,
697 .procname
= "printk_delay",
698 .data
= &printk_delay_msec
,
699 .maxlen
= sizeof(int),
701 .proc_handler
= proc_dointvec_minmax
,
703 .extra2
= &ten_thousand
,
706 .procname
= "dmesg_restrict",
707 .data
= &dmesg_restrict
,
708 .maxlen
= sizeof(int),
710 .proc_handler
= proc_dointvec_bool
,
713 .procname
= "kptr_restrict",
714 .data
= &kptr_restrict
,
715 .maxlen
= sizeof(int),
717 .proc_handler
= proc_dmesg_restrict
,
723 .procname
= "ngroups_max",
724 .data
= &ngroups_max
,
725 .maxlen
= sizeof (int),
727 .proc_handler
= proc_dointvec
,
729 #if defined(CONFIG_LOCKUP_DETECTOR)
731 .procname
= "watchdog",
732 .data
= &watchdog_enabled
,
733 .maxlen
= sizeof (int),
735 .proc_handler
= proc_dowatchdog
,
740 .procname
= "watchdog_thresh",
741 .data
= &watchdog_thresh
,
742 .maxlen
= sizeof(int),
744 .proc_handler
= proc_dowatchdog
,
749 .procname
= "softlockup_panic",
750 .data
= &softlockup_panic
,
751 .maxlen
= sizeof(int),
753 .proc_handler
= proc_dointvec_bool
,
756 .procname
= "nmi_watchdog",
757 .data
= &watchdog_enabled
,
758 .maxlen
= sizeof (int),
760 .proc_handler
= proc_dowatchdog
,
765 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
767 .procname
= "unknown_nmi_panic",
768 .data
= &unknown_nmi_panic
,
769 .maxlen
= sizeof (int),
771 .proc_handler
= proc_dointvec
,
774 #if defined(CONFIG_X86)
776 .procname
= "panic_on_unrecovered_nmi",
777 .data
= &panic_on_unrecovered_nmi
,
778 .maxlen
= sizeof(int),
780 .proc_handler
= proc_dointvec
,
783 .procname
= "panic_on_io_nmi",
784 .data
= &panic_on_io_nmi
,
785 .maxlen
= sizeof(int),
787 .proc_handler
= proc_dointvec
,
790 .procname
= "bootloader_type",
791 .data
= &bootloader_type
,
792 .maxlen
= sizeof (int),
794 .proc_handler
= proc_dointvec
,
797 .procname
= "bootloader_version",
798 .data
= &bootloader_version
,
799 .maxlen
= sizeof (int),
801 .proc_handler
= proc_dointvec
,
804 .procname
= "kstack_depth_to_print",
805 .data
= &kstack_depth_to_print
,
806 .maxlen
= sizeof(int),
808 .proc_handler
= proc_dointvec
,
811 .procname
= "io_delay_type",
812 .data
= &io_delay_type
,
813 .maxlen
= sizeof(int),
815 .proc_handler
= proc_dointvec
,
818 #if defined(CONFIG_MMU)
820 .procname
= "randomize_va_space",
821 .data
= &randomize_va_space
,
822 .maxlen
= sizeof(int),
824 .proc_handler
= proc_dointvec
,
827 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
829 .procname
= "spin_retry",
831 .maxlen
= sizeof (int),
833 .proc_handler
= proc_dointvec
,
836 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
838 .procname
= "acpi_video_flags",
839 .data
= &acpi_realmode_flags
,
840 .maxlen
= sizeof (unsigned long),
842 .proc_handler
= proc_doulongvec_minmax
,
847 .procname
= "ignore-unaligned-usertrap",
848 .data
= &no_unaligned_warning
,
849 .maxlen
= sizeof (int),
851 .proc_handler
= proc_dointvec
,
854 .procname
= "unaligned-dump-stack",
855 .data
= &unaligned_dump_stack
,
856 .maxlen
= sizeof (int),
858 .proc_handler
= proc_dointvec
,
861 #ifdef CONFIG_DETECT_HUNG_TASK
863 .procname
= "hung_task_panic",
864 .data
= &sysctl_hung_task_panic
,
865 .maxlen
= sizeof(int),
867 .proc_handler
= proc_dointvec_bool
,
870 .procname
= "hung_task_check_count",
871 .data
= &sysctl_hung_task_check_count
,
872 .maxlen
= sizeof(unsigned long),
874 .proc_handler
= proc_doulongvec_minmax
,
877 .procname
= "hung_task_timeout_secs",
878 .data
= &sysctl_hung_task_timeout_secs
,
879 .maxlen
= sizeof(unsigned long),
881 .proc_handler
= proc_dohung_task_timeout_secs
,
884 .procname
= "hung_task_warnings",
885 .data
= &sysctl_hung_task_warnings
,
886 .maxlen
= sizeof(unsigned long),
888 .proc_handler
= proc_doulongvec_minmax
,
893 .procname
= "compat-log",
895 .maxlen
= sizeof (int),
897 .proc_handler
= proc_dointvec
,
900 #ifdef CONFIG_RT_MUTEXES
902 .procname
= "max_lock_depth",
903 .data
= &max_lock_depth
,
904 .maxlen
= sizeof(int),
906 .proc_handler
= proc_dointvec
,
910 .procname
= "poweroff_cmd",
911 .data
= &poweroff_cmd
,
912 .maxlen
= POWEROFF_CMD_PATH_LEN
,
914 .proc_handler
= proc_dostring
,
920 .child
= key_sysctls
,
923 #ifdef CONFIG_RCU_TORTURE_TEST
925 .procname
= "rcutorture_runnable",
926 .data
= &rcutorture_runnable
,
927 .maxlen
= sizeof(int),
929 .proc_handler
= proc_dointvec
,
932 #ifdef CONFIG_PERF_EVENTS
934 * User-space scripts rely on the existence of this file
935 * as a feature check for perf_events being enabled.
937 * So it's an ABI, do not remove!
940 .procname
= "perf_event_paranoid",
941 .data
= &sysctl_perf_event_paranoid
,
942 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
944 .proc_handler
= proc_dointvec
,
947 .procname
= "perf_event_mlock_kb",
948 .data
= &sysctl_perf_event_mlock
,
949 .maxlen
= sizeof(sysctl_perf_event_mlock
),
951 .proc_handler
= proc_dointvec
,
954 .procname
= "perf_event_max_sample_rate",
955 .data
= &sysctl_perf_event_sample_rate
,
956 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
958 .proc_handler
= perf_proc_update_handler
,
961 #ifdef CONFIG_KMEMCHECK
963 .procname
= "kmemcheck",
964 .data
= &kmemcheck_enabled
,
965 .maxlen
= sizeof(int),
967 .proc_handler
= proc_dointvec
,
972 .procname
= "blk_iopoll",
973 .data
= &blk_iopoll_enabled
,
974 .maxlen
= sizeof(int),
976 .proc_handler
= proc_dointvec
,
982 static struct ctl_table vm_table
[] = {
984 .procname
= "overcommit_memory",
985 .data
= &sysctl_overcommit_memory
,
986 .maxlen
= sizeof(sysctl_overcommit_memory
),
988 .proc_handler
= proc_dointvec_minmax
,
993 .procname
= "panic_on_oom",
994 .data
= &sysctl_panic_on_oom
,
995 .maxlen
= sizeof(sysctl_panic_on_oom
),
997 .proc_handler
= proc_dointvec_minmax
,
1002 .procname
= "oom_kill_allocating_task",
1003 .data
= &sysctl_oom_kill_allocating_task
,
1004 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1006 .proc_handler
= proc_dointvec
,
1009 .procname
= "oom_dump_tasks",
1010 .data
= &sysctl_oom_dump_tasks
,
1011 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1013 .proc_handler
= proc_dointvec
,
1016 .procname
= "overcommit_ratio",
1017 .data
= &sysctl_overcommit_ratio
,
1018 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1020 .proc_handler
= proc_dointvec
,
1023 .procname
= "page-cluster",
1024 .data
= &page_cluster
,
1025 .maxlen
= sizeof(int),
1027 .proc_handler
= proc_dointvec_minmax
,
1031 .procname
= "dirty_background_ratio",
1032 .data
= &dirty_background_ratio
,
1033 .maxlen
= sizeof(dirty_background_ratio
),
1035 .proc_handler
= dirty_background_ratio_handler
,
1037 .extra2
= &one_hundred
,
1040 .procname
= "dirty_background_bytes",
1041 .data
= &dirty_background_bytes
,
1042 .maxlen
= sizeof(dirty_background_bytes
),
1044 .proc_handler
= dirty_background_bytes_handler
,
1048 .procname
= "dirty_ratio",
1049 .data
= &vm_dirty_ratio
,
1050 .maxlen
= sizeof(vm_dirty_ratio
),
1052 .proc_handler
= dirty_ratio_handler
,
1054 .extra2
= &one_hundred
,
1057 .procname
= "dirty_bytes",
1058 .data
= &vm_dirty_bytes
,
1059 .maxlen
= sizeof(vm_dirty_bytes
),
1061 .proc_handler
= dirty_bytes_handler
,
1062 .extra1
= &dirty_bytes_min
,
1065 .procname
= "dirty_writeback_centisecs",
1066 .data
= &dirty_writeback_interval
,
1067 .maxlen
= sizeof(dirty_writeback_interval
),
1069 .proc_handler
= dirty_writeback_centisecs_handler
,
1072 .procname
= "dirty_expire_centisecs",
1073 .data
= &dirty_expire_interval
,
1074 .maxlen
= sizeof(dirty_expire_interval
),
1076 .proc_handler
= proc_dointvec_minmax
,
1080 .procname
= "nr_pdflush_threads",
1081 .data
= &nr_pdflush_threads
,
1082 .maxlen
= sizeof nr_pdflush_threads
,
1083 .mode
= 0444 /* read-only*/,
1084 .proc_handler
= proc_dointvec
,
1087 .procname
= "swappiness",
1088 .data
= &vm_swappiness
,
1089 .maxlen
= sizeof(vm_swappiness
),
1091 .proc_handler
= proc_dointvec_minmax
,
1093 .extra2
= &one_hundred
,
1095 #ifdef CONFIG_HUGETLB_PAGE
1097 .procname
= "nr_hugepages",
1099 .maxlen
= sizeof(unsigned long),
1101 .proc_handler
= hugetlb_sysctl_handler
,
1102 .extra1
= (void *)&hugetlb_zero
,
1103 .extra2
= (void *)&hugetlb_infinity
,
1107 .procname
= "nr_hugepages_mempolicy",
1109 .maxlen
= sizeof(unsigned long),
1111 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1112 .extra1
= (void *)&hugetlb_zero
,
1113 .extra2
= (void *)&hugetlb_infinity
,
1117 .procname
= "hugetlb_shm_group",
1118 .data
= &sysctl_hugetlb_shm_group
,
1119 .maxlen
= sizeof(gid_t
),
1121 .proc_handler
= proc_dointvec
,
1124 .procname
= "hugepages_treat_as_movable",
1125 .data
= &hugepages_treat_as_movable
,
1126 .maxlen
= sizeof(int),
1128 .proc_handler
= hugetlb_treat_movable_handler
,
1131 .procname
= "nr_overcommit_hugepages",
1133 .maxlen
= sizeof(unsigned long),
1135 .proc_handler
= hugetlb_overcommit_handler
,
1136 .extra1
= (void *)&hugetlb_zero
,
1137 .extra2
= (void *)&hugetlb_infinity
,
1141 .procname
= "lowmem_reserve_ratio",
1142 .data
= &sysctl_lowmem_reserve_ratio
,
1143 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1145 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1148 .procname
= "drop_caches",
1149 .data
= &sysctl_drop_caches
,
1150 .maxlen
= sizeof(int),
1152 .proc_handler
= drop_caches_sysctl_handler
,
1156 #ifdef CONFIG_COMPACTION
1158 .procname
= "compact_memory",
1159 .data
= &sysctl_compact_memory
,
1160 .maxlen
= sizeof(int),
1162 .proc_handler
= sysctl_compaction_handler
,
1165 .procname
= "extfrag_threshold",
1166 .data
= &sysctl_extfrag_threshold
,
1167 .maxlen
= sizeof(int),
1169 .proc_handler
= sysctl_extfrag_handler
,
1170 .extra1
= &min_extfrag_threshold
,
1171 .extra2
= &max_extfrag_threshold
,
1174 #endif /* CONFIG_COMPACTION */
1176 .procname
= "min_free_kbytes",
1177 .data
= &min_free_kbytes
,
1178 .maxlen
= sizeof(min_free_kbytes
),
1180 .proc_handler
= min_free_kbytes_sysctl_handler
,
1184 .procname
= "percpu_pagelist_fraction",
1185 .data
= &percpu_pagelist_fraction
,
1186 .maxlen
= sizeof(percpu_pagelist_fraction
),
1188 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1189 .extra1
= &min_percpu_pagelist_fract
,
1193 .procname
= "max_map_count",
1194 .data
= &sysctl_max_map_count
,
1195 .maxlen
= sizeof(sysctl_max_map_count
),
1197 .proc_handler
= proc_dointvec_unsigned
,
1201 .procname
= "nr_trim_pages",
1202 .data
= &sysctl_nr_trim_pages
,
1203 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1205 .proc_handler
= proc_dointvec_unsigned
,
1209 .procname
= "laptop_mode",
1210 .data
= &laptop_mode
,
1211 .maxlen
= sizeof(laptop_mode
),
1213 .proc_handler
= proc_dointvec_jiffies
,
1216 .procname
= "block_dump",
1217 .data
= &block_dump
,
1218 .maxlen
= sizeof(block_dump
),
1220 .proc_handler
= proc_dointvec_unsigned
,
1223 .procname
= "vfs_cache_pressure",
1224 .data
= &sysctl_vfs_cache_pressure
,
1225 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1227 .proc_handler
= proc_dointvec_unsigned
,
1229 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1231 .procname
= "legacy_va_layout",
1232 .data
= &sysctl_legacy_va_layout
,
1233 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1235 .proc_handler
= proc_dointvec_unsigned
,
1240 .procname
= "zone_reclaim_mode",
1241 .data
= &zone_reclaim_mode
,
1242 .maxlen
= sizeof(zone_reclaim_mode
),
1244 .proc_handler
= proc_dointvec_unsigned
,
1247 .procname
= "min_unmapped_ratio",
1248 .data
= &sysctl_min_unmapped_ratio
,
1249 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1251 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1253 .extra2
= &one_hundred
,
1256 .procname
= "min_slab_ratio",
1257 .data
= &sysctl_min_slab_ratio
,
1258 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1260 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1262 .extra2
= &one_hundred
,
1267 .procname
= "stat_interval",
1268 .data
= &sysctl_stat_interval
,
1269 .maxlen
= sizeof(sysctl_stat_interval
),
1271 .proc_handler
= proc_dointvec_jiffies
,
1276 .procname
= "mmap_min_addr",
1277 .data
= &dac_mmap_min_addr
,
1278 .maxlen
= sizeof(unsigned long),
1280 .proc_handler
= mmap_min_addr_handler
,
1285 .procname
= "numa_zonelist_order",
1286 .data
= &numa_zonelist_order
,
1287 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1289 .proc_handler
= numa_zonelist_order_handler
,
1292 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1293 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1295 .procname
= "vdso_enabled",
1296 .data
= &vdso_enabled
,
1297 .maxlen
= sizeof(vdso_enabled
),
1299 .proc_handler
= proc_dointvec_unsigned
,
1302 #ifdef CONFIG_HIGHMEM
1304 .procname
= "highmem_is_dirtyable",
1305 .data
= &vm_highmem_is_dirtyable
,
1306 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1308 .proc_handler
= proc_dointvec_bool
,
1312 .procname
= "scan_unevictable_pages",
1313 .data
= &scan_unevictable_pages
,
1314 .maxlen
= sizeof(scan_unevictable_pages
),
1316 .proc_handler
= scan_unevictable_handler
,
1318 #ifdef CONFIG_MEMORY_FAILURE
1320 .procname
= "memory_failure_early_kill",
1321 .data
= &sysctl_memory_failure_early_kill
,
1322 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1324 .proc_handler
= proc_dointvec_bool
,
1327 .procname
= "memory_failure_recovery",
1328 .data
= &sysctl_memory_failure_recovery
,
1329 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1331 .proc_handler
= proc_dointvec_bool
,
1337 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1338 static struct ctl_table binfmt_misc_table
[] = {
1343 static struct ctl_table fs_table
[] = {
1345 .procname
= "inode-nr",
1346 .data
= &inodes_stat
,
1347 .maxlen
= 2*sizeof(int),
1349 .proc_handler
= proc_nr_inodes
,
1352 .procname
= "inode-state",
1353 .data
= &inodes_stat
,
1354 .maxlen
= 7*sizeof(int),
1356 .proc_handler
= proc_nr_inodes
,
1359 .procname
= "file-nr",
1360 .data
= &files_stat
,
1361 .maxlen
= sizeof(files_stat
),
1363 .proc_handler
= proc_nr_files
,
1366 .procname
= "file-max",
1367 .data
= &files_stat
.max_files
,
1368 .maxlen
= sizeof(files_stat
.max_files
),
1370 .proc_handler
= proc_doulongvec_minmax
,
1373 .procname
= "nr_open",
1374 .data
= &sysctl_nr_open
,
1375 .maxlen
= sizeof(int),
1377 .proc_handler
= proc_dointvec_minmax
,
1378 .extra1
= &sysctl_nr_open_min
,
1379 .extra2
= &sysctl_nr_open_max
,
1382 .procname
= "dentry-state",
1383 .data
= &dentry_stat
,
1384 .maxlen
= 6*sizeof(int),
1386 .proc_handler
= proc_nr_dentry
,
1389 .procname
= "overflowuid",
1390 .data
= &fs_overflowuid
,
1391 .maxlen
= sizeof(int),
1393 .proc_handler
= proc_dointvec_minmax
,
1394 .extra1
= &minolduid
,
1395 .extra2
= &maxolduid
,
1398 .procname
= "overflowgid",
1399 .data
= &fs_overflowgid
,
1400 .maxlen
= sizeof(int),
1402 .proc_handler
= proc_dointvec_minmax
,
1403 .extra1
= &minolduid
,
1404 .extra2
= &maxolduid
,
1406 #ifdef CONFIG_FILE_LOCKING
1408 .procname
= "leases-enable",
1409 .data
= &leases_enable
,
1410 .maxlen
= sizeof(int),
1412 .proc_handler
= proc_dointvec
,
1415 #ifdef CONFIG_DNOTIFY
1417 .procname
= "dir-notify-enable",
1418 .data
= &dir_notify_enable
,
1419 .maxlen
= sizeof(int),
1421 .proc_handler
= proc_dointvec
,
1425 #ifdef CONFIG_FILE_LOCKING
1427 .procname
= "lease-break-time",
1428 .data
= &lease_break_time
,
1429 .maxlen
= sizeof(int),
1431 .proc_handler
= proc_dointvec
,
1436 .procname
= "aio-nr",
1438 .maxlen
= sizeof(aio_nr
),
1440 .proc_handler
= proc_doulongvec_minmax
,
1443 .procname
= "aio-max-nr",
1444 .data
= &aio_max_nr
,
1445 .maxlen
= sizeof(aio_max_nr
),
1447 .proc_handler
= proc_doulongvec_minmax
,
1449 #endif /* CONFIG_AIO */
1450 #ifdef CONFIG_INOTIFY_USER
1452 .procname
= "inotify",
1454 .child
= inotify_table
,
1459 .procname
= "epoll",
1461 .child
= epoll_table
,
1466 .procname
= "suid_dumpable",
1467 .data
= &suid_dumpable
,
1468 .maxlen
= sizeof(int),
1470 .proc_handler
= proc_dointvec_minmax
,
1474 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1476 .procname
= "binfmt_misc",
1478 .child
= binfmt_misc_table
,
1482 .procname
= "pipe-max-size",
1483 .data
= &pipe_max_size
,
1484 .maxlen
= sizeof(int),
1486 .proc_handler
= &pipe_proc_fn
,
1487 .extra1
= &pipe_min_size
,
1492 static struct ctl_table debug_table
[] = {
1493 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1494 defined(CONFIG_S390) || defined(CONFIG_TILE)
1496 .procname
= "exception-trace",
1497 .data
= &show_unhandled_signals
,
1498 .maxlen
= sizeof(int),
1500 .proc_handler
= proc_dointvec
1503 #if defined(CONFIG_OPTPROBES)
1505 .procname
= "kprobes-optimization",
1506 .data
= &sysctl_kprobes_optimization
,
1507 .maxlen
= sizeof(int),
1509 .proc_handler
= proc_kprobes_optimization_handler
,
1517 static struct ctl_table dev_table
[] = {
1521 static DEFINE_SPINLOCK(sysctl_lock
);
1523 /* called under sysctl_lock */
1524 static int use_table(struct ctl_table_header
*p
)
1526 if (unlikely(p
->unregistering
))
1532 /* called under sysctl_lock */
1533 static void unuse_table(struct ctl_table_header
*p
)
1536 if (unlikely(p
->unregistering
))
1537 complete(p
->unregistering
);
1540 /* called under sysctl_lock, will reacquire if has to wait */
1541 static void start_unregistering(struct ctl_table_header
*p
)
1544 * if p->used is 0, nobody will ever touch that entry again;
1545 * we'll eliminate all paths to it before dropping sysctl_lock
1547 if (unlikely(p
->used
)) {
1548 struct completion wait
;
1549 init_completion(&wait
);
1550 p
->unregistering
= &wait
;
1551 spin_unlock(&sysctl_lock
);
1552 wait_for_completion(&wait
);
1553 spin_lock(&sysctl_lock
);
1555 /* anything non-NULL; we'll never dereference it */
1556 p
->unregistering
= ERR_PTR(-EINVAL
);
1559 * do not remove from the list until nobody holds it; walking the
1560 * list in do_sysctl() relies on that.
1562 list_del_init(&p
->ctl_entry
);
1565 void sysctl_head_get(struct ctl_table_header
*head
)
1567 spin_lock(&sysctl_lock
);
1569 spin_unlock(&sysctl_lock
);
1572 void sysctl_head_put(struct ctl_table_header
*head
)
1574 spin_lock(&sysctl_lock
);
1576 kfree_rcu(head
, rcu
);
1577 spin_unlock(&sysctl_lock
);
1580 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1584 spin_lock(&sysctl_lock
);
1585 if (!use_table(head
))
1586 head
= ERR_PTR(-ENOENT
);
1587 spin_unlock(&sysctl_lock
);
1591 void sysctl_head_finish(struct ctl_table_header
*head
)
1595 spin_lock(&sysctl_lock
);
1597 spin_unlock(&sysctl_lock
);
1600 static struct ctl_table_set
*
1601 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1603 struct ctl_table_set
*set
= &root
->default_set
;
1605 set
= root
->lookup(root
, namespaces
);
1609 static struct list_head
*
1610 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1612 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1616 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1617 struct ctl_table_header
*prev
)
1619 struct ctl_table_root
*root
;
1620 struct list_head
*header_list
;
1621 struct ctl_table_header
*head
;
1622 struct list_head
*tmp
;
1624 spin_lock(&sysctl_lock
);
1627 tmp
= &prev
->ctl_entry
;
1631 tmp
= &root_table_header
.ctl_entry
;
1633 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1635 if (!use_table(head
))
1637 spin_unlock(&sysctl_lock
);
1642 header_list
= lookup_header_list(root
, namespaces
);
1643 if (tmp
!= header_list
)
1647 root
= list_entry(root
->root_list
.next
,
1648 struct ctl_table_root
, root_list
);
1649 if (root
== &sysctl_table_root
)
1651 header_list
= lookup_header_list(root
, namespaces
);
1652 } while (list_empty(header_list
));
1653 tmp
= header_list
->next
;
1656 spin_unlock(&sysctl_lock
);
1660 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1662 return __sysctl_head_next(current
->nsproxy
, prev
);
1665 void register_sysctl_root(struct ctl_table_root
*root
)
1667 spin_lock(&sysctl_lock
);
1668 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1669 spin_unlock(&sysctl_lock
);
1673 * sysctl_perm does NOT grant the superuser all rights automatically, because
1674 * some sysctl variables are readonly even to root.
1677 static int test_perm(int mode
, int op
)
1679 if (!current_euid())
1681 else if (in_egroup_p(0))
1683 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1688 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1692 if (root
->permissions
)
1693 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1697 return test_perm(mode
, op
);
1700 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1702 for (; table
->procname
; table
++) {
1703 table
->parent
= parent
;
1705 sysctl_set_parent(table
, table
->child
);
1709 static __init
int sysctl_init(void)
1711 sysctl_set_parent(NULL
, root_table
);
1712 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1713 sysctl_check_table(current
->nsproxy
, root_table
);
1718 core_initcall(sysctl_init
);
1720 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1721 struct ctl_table
*table
)
1723 struct ctl_table
*p
;
1724 const char *s
= branch
->procname
;
1726 /* branch should have named subdirectory as its first element */
1727 if (!s
|| !branch
->child
)
1730 /* ... and nothing else */
1731 if (branch
[1].procname
)
1734 /* table should contain subdirectory with the same name */
1735 for (p
= table
; p
->procname
; p
++) {
1738 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1744 /* see if attaching q to p would be an improvement */
1745 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1747 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1748 struct ctl_table
*next
;
1750 int not_in_parent
= !p
->attached_by
;
1752 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1753 if (by
== q
->attached_by
)
1755 if (to
== p
->attached_by
)
1761 if (is_better
&& not_in_parent
) {
1762 q
->attached_by
= by
;
1763 q
->attached_to
= to
;
1769 * __register_sysctl_paths - register a sysctl hierarchy
1770 * @root: List of sysctl headers to register on
1771 * @namespaces: Data to compute which lists of sysctl entries are visible
1772 * @path: The path to the directory the sysctl table is in.
1773 * @table: the top-level table structure
1775 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1776 * array. A completely 0 filled entry terminates the table.
1778 * The members of the &struct ctl_table structure are used as follows:
1780 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1781 * enter a sysctl file
1783 * data - a pointer to data for use by proc_handler
1785 * maxlen - the maximum size in bytes of the data
1787 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1789 * child - a pointer to the child sysctl table if this entry is a directory, or
1792 * proc_handler - the text handler routine (described below)
1794 * de - for internal use by the sysctl routines
1796 * extra1, extra2 - extra pointers usable by the proc handler routines
1798 * Leaf nodes in the sysctl tree will be represented by a single file
1799 * under /proc; non-leaf nodes will be represented by directories.
1801 * sysctl(2) can automatically manage read and write requests through
1802 * the sysctl table. The data and maxlen fields of the ctl_table
1803 * struct enable minimal validation of the values being written to be
1804 * performed, and the mode field allows minimal authentication.
1806 * There must be a proc_handler routine for any terminal nodes
1807 * mirrored under /proc/sys (non-terminals are handled by a built-in
1808 * directory handler). Several default handlers are available to
1809 * cover common cases -
1811 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1812 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1813 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1815 * It is the handler's job to read the input buffer from user memory
1816 * and process it. The handler should return 0 on success.
1818 * This routine returns %NULL on a failure to register, and a pointer
1819 * to the table header on success.
1821 struct ctl_table_header
*__register_sysctl_paths(
1822 struct ctl_table_root
*root
,
1823 struct nsproxy
*namespaces
,
1824 const struct ctl_path
*path
, struct ctl_table
*table
)
1826 struct ctl_table_header
*header
;
1827 struct ctl_table
*new, **prevp
;
1828 unsigned int n
, npath
;
1829 struct ctl_table_set
*set
;
1831 /* Count the path components */
1832 for (npath
= 0; path
[npath
].procname
; ++npath
)
1836 * For each path component, allocate a 2-element ctl_table array.
1837 * The first array element will be filled with the sysctl entry
1838 * for this, the second will be the sentinel (procname == 0).
1840 * We allocate everything in one go so that we don't have to
1841 * worry about freeing additional memory in unregister_sysctl_table.
1843 header
= kzalloc(sizeof(struct ctl_table_header
) +
1844 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1848 new = (struct ctl_table
*) (header
+ 1);
1850 /* Now connect the dots */
1851 prevp
= &header
->ctl_table
;
1852 for (n
= 0; n
< npath
; ++n
, ++path
) {
1853 /* Copy the procname */
1854 new->procname
= path
->procname
;
1858 prevp
= &new->child
;
1863 header
->ctl_table_arg
= table
;
1865 INIT_LIST_HEAD(&header
->ctl_entry
);
1867 header
->unregistering
= NULL
;
1868 header
->root
= root
;
1869 sysctl_set_parent(NULL
, header
->ctl_table
);
1871 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1872 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1877 spin_lock(&sysctl_lock
);
1878 header
->set
= lookup_header_set(root
, namespaces
);
1879 header
->attached_by
= header
->ctl_table
;
1880 header
->attached_to
= root_table
;
1881 header
->parent
= &root_table_header
;
1882 for (set
= header
->set
; set
; set
= set
->parent
) {
1883 struct ctl_table_header
*p
;
1884 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1885 if (p
->unregistering
)
1887 try_attach(p
, header
);
1890 header
->parent
->count
++;
1891 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1892 spin_unlock(&sysctl_lock
);
1898 * register_sysctl_table_path - register a sysctl table hierarchy
1899 * @path: The path to the directory the sysctl table is in.
1900 * @table: the top-level table structure
1902 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1903 * array. A completely 0 filled entry terminates the table.
1905 * See __register_sysctl_paths for more details.
1907 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1908 struct ctl_table
*table
)
1910 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1915 * register_sysctl_table - register a sysctl table hierarchy
1916 * @table: the top-level table structure
1918 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1919 * array. A completely 0 filled entry terminates the table.
1921 * See register_sysctl_paths for more details.
1923 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1925 static const struct ctl_path null_path
[] = { {} };
1927 return register_sysctl_paths(null_path
, table
);
1931 * unregister_sysctl_table - unregister a sysctl table hierarchy
1932 * @header: the header returned from register_sysctl_table
1934 * Unregisters the sysctl table and all children. proc entries may not
1935 * actually be removed until they are no longer used by anyone.
1937 void unregister_sysctl_table(struct ctl_table_header
* header
)
1944 spin_lock(&sysctl_lock
);
1945 start_unregistering(header
);
1946 if (!--header
->parent
->count
) {
1948 kfree_rcu(header
->parent
, rcu
);
1950 if (!--header
->count
)
1951 kfree_rcu(header
, rcu
);
1952 spin_unlock(&sysctl_lock
);
1955 int sysctl_is_seen(struct ctl_table_header
*p
)
1957 struct ctl_table_set
*set
= p
->set
;
1959 spin_lock(&sysctl_lock
);
1960 if (p
->unregistering
)
1962 else if (!set
->is_seen
)
1965 res
= set
->is_seen(set
);
1966 spin_unlock(&sysctl_lock
);
1970 void setup_sysctl_set(struct ctl_table_set
*p
,
1971 struct ctl_table_set
*parent
,
1972 int (*is_seen
)(struct ctl_table_set
*))
1974 INIT_LIST_HEAD(&p
->list
);
1975 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1976 p
->is_seen
= is_seen
;
1979 #else /* !CONFIG_SYSCTL */
1980 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1985 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1986 struct ctl_table
*table
)
1991 void unregister_sysctl_table(struct ctl_table_header
* table
)
1995 void setup_sysctl_set(struct ctl_table_set
*p
,
1996 struct ctl_table_set
*parent
,
1997 int (*is_seen
)(struct ctl_table_set
*))
2001 void sysctl_head_put(struct ctl_table_header
*head
)
2005 #endif /* CONFIG_SYSCTL */
2011 #ifdef CONFIG_PROC_SYSCTL
2013 static int _proc_do_string(void* data
, int maxlen
, int write
,
2014 void __user
*buffer
,
2015 size_t *lenp
, loff_t
*ppos
)
2021 if (!data
|| !maxlen
|| !*lenp
) {
2029 while (len
< *lenp
) {
2030 if (get_user(c
, p
++))
2032 if (c
== 0 || c
== '\n')
2038 if(copy_from_user(data
, buffer
, len
))
2040 ((char *) data
)[len
] = 0;
2058 if(copy_to_user(buffer
, data
, len
))
2061 if(put_user('\n', ((char __user
*) buffer
) + len
))
2072 * proc_dostring - read a string sysctl
2073 * @table: the sysctl table
2074 * @write: %TRUE if this is a write to the sysctl file
2075 * @buffer: the user buffer
2076 * @lenp: the size of the user buffer
2077 * @ppos: file position
2079 * Reads/writes a string from/to the user buffer. If the kernel
2080 * buffer provided is not large enough to hold the string, the
2081 * string is truncated. The copied string is %NULL-terminated.
2082 * If the string is being read by the user process, it is copied
2083 * and a newline '\n' is added. It is truncated if the buffer is
2086 * Returns 0 on success.
2088 int proc_dostring(struct ctl_table
*table
, int write
,
2089 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2091 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2092 buffer
, lenp
, ppos
);
2095 static size_t proc_skip_spaces(char **buf
)
2098 char *tmp
= skip_spaces(*buf
);
2104 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2114 #define TMPBUFLEN 22
2116 * proc_get_long - reads an ASCII formatted integer from a user buffer
2118 * @buf: a kernel buffer
2119 * @size: size of the kernel buffer
2120 * @val: this is where the number will be stored
2121 * @neg: set to %TRUE if number is negative
2122 * @perm_tr: a vector which contains the allowed trailers
2123 * @perm_tr_len: size of the perm_tr vector
2124 * @tr: pointer to store the trailer character
2126 * In case of success %0 is returned and @buf and @size are updated with
2127 * the amount of bytes read. If @tr is non-NULL and a trailing
2128 * character exists (size is non-zero after returning from this
2129 * function), @tr is updated with the trailing character.
2131 static int proc_get_long(char **buf
, size_t *size
,
2132 unsigned long *val
, bool *neg
,
2133 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2136 char *p
, tmp
[TMPBUFLEN
];
2142 if (len
> TMPBUFLEN
- 1)
2143 len
= TMPBUFLEN
- 1;
2145 memcpy(tmp
, *buf
, len
);
2149 if (*p
== '-' && *size
> 1) {
2157 *val
= simple_strtoul(p
, &p
, 0);
2161 /* We don't know if the next char is whitespace thus we may accept
2162 * invalid integers (e.g. 1234...a) or two integers instead of one
2163 * (e.g. 123...1). So lets not allow such large numbers. */
2164 if (len
== TMPBUFLEN
- 1)
2167 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2170 if (tr
&& (len
< *size
))
2180 * proc_put_long - converts an integer to a decimal ASCII formatted string
2182 * @buf: the user buffer
2183 * @size: the size of the user buffer
2184 * @val: the integer to be converted
2185 * @neg: sign of the number, %TRUE for negative
2187 * In case of success %0 is returned and @buf and @size are updated with
2188 * the amount of bytes written.
2190 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2194 char tmp
[TMPBUFLEN
], *p
= tmp
;
2196 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2200 if (copy_to_user(*buf
, tmp
, len
))
2208 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2211 char __user
**buffer
= (char __user
**)buf
;
2212 if (put_user(c
, *buffer
))
2214 (*size
)--, (*buffer
)++;
2220 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2222 int write
, void *data
)
2225 *valp
= *negp
? -*lvalp
: *lvalp
;
2230 *lvalp
= (unsigned long)-val
;
2233 *lvalp
= (unsigned long)val
;
2239 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2241 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2242 int write
, void __user
*buffer
,
2243 size_t *lenp
, loff_t
*ppos
,
2244 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2245 int write
, void *data
),
2248 int *i
, vleft
, first
= 1, err
= 0;
2249 unsigned long page
= 0;
2253 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2258 i
= (int *) tbl_data
;
2259 vleft
= table
->maxlen
/ sizeof(*i
);
2263 conv
= do_proc_dointvec_conv
;
2266 if (left
> PAGE_SIZE
- 1)
2267 left
= PAGE_SIZE
- 1;
2268 page
= __get_free_page(GFP_TEMPORARY
);
2269 kbuf
= (char *) page
;
2272 if (copy_from_user(kbuf
, buffer
, left
)) {
2279 for (; left
&& vleft
--; i
++, first
=0) {
2284 left
-= proc_skip_spaces(&kbuf
);
2288 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2290 sizeof(proc_wspace_sep
), NULL
);
2293 if (conv(&neg
, &lval
, i
, 1, data
)) {
2298 if (conv(&neg
, &lval
, i
, 0, data
)) {
2303 err
= proc_put_char(&buffer
, &left
, '\t');
2306 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2312 if (!write
&& !first
&& left
&& !err
)
2313 err
= proc_put_char(&buffer
, &left
, '\n');
2314 if (write
&& !err
&& left
)
2315 left
-= proc_skip_spaces(&kbuf
);
2320 return err
? : -EINVAL
;
2327 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2328 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2329 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2330 int write
, void *data
),
2333 return __do_proc_dointvec(table
->data
, table
, write
,
2334 buffer
, lenp
, ppos
, conv
, data
);
2338 * proc_dointvec - read a vector of integers
2339 * @table: the sysctl table
2340 * @write: %TRUE if this is a write to the sysctl file
2341 * @buffer: the user buffer
2342 * @lenp: the size of the user buffer
2343 * @ppos: file position
2345 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2346 * values from/to the user buffer, treated as an ASCII string.
2348 * Returns 0 on success.
2350 int proc_dointvec(struct ctl_table
*table
, int write
,
2351 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2353 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2358 * Taint values can only be increased
2359 * This means we can safely use a temporary.
2361 static int proc_taint(struct ctl_table
*table
, int write
,
2362 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2365 unsigned long tmptaint
= get_taint();
2368 if (write
&& !capable(CAP_SYS_ADMIN
))
2373 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2379 * Poor man's atomic or. Not worth adding a primitive
2380 * to everyone's atomic.h for this
2383 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2384 if ((tmptaint
>> i
) & 1)
2392 #ifdef CONFIG_PRINTK
2393 static int proc_dmesg_restrict(struct ctl_table
*table
, int write
,
2394 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2396 if (write
&& !capable(CAP_SYS_ADMIN
))
2399 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2403 struct do_proc_dointvec_minmax_conv_param
{
2408 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2410 int write
, void *data
)
2412 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2414 int val
= *negp
? -*lvalp
: *lvalp
;
2415 if ((param
->min
&& *param
->min
> val
) ||
2416 (param
->max
&& *param
->max
< val
))
2423 *lvalp
= (unsigned long)-val
;
2426 *lvalp
= (unsigned long)val
;
2433 * proc_dointvec_minmax - read a vector of integers with min/max values
2434 * @table: the sysctl table
2435 * @write: %TRUE if this is a write to the sysctl file
2436 * @buffer: the user buffer
2437 * @lenp: the size of the user buffer
2438 * @ppos: file position
2440 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2441 * values from/to the user buffer, treated as an ASCII string.
2443 * This routine will ensure the values are within the range specified by
2444 * table->extra1 (min) and table->extra2 (max).
2446 * Returns 0 on success.
2448 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2449 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2451 struct do_proc_dointvec_minmax_conv_param param
= {
2452 .min
= (int *) table
->extra1
,
2453 .max
= (int *) table
->extra2
,
2455 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2456 do_proc_dointvec_minmax_conv
, ¶m
);
2460 * proc_dointvec_bool - read a vector of integers with 0/1 values
2461 * @table: the sysctl table
2462 * @write: %TRUE if this is a write to the sysctl file
2463 * @buffer: the user buffer
2464 * @lenp: the size of the user buffer
2465 * @ppos: file position
2467 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2468 * values from/to the user buffer, treated as an ASCII string.
2470 * This routine will ensure the values are either 0 or 1.
2472 * Returns 0 on success.
2474 int proc_dointvec_bool(struct ctl_table
*table
, int write
,
2475 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2477 struct do_proc_dointvec_minmax_conv_param param
= {
2481 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2482 do_proc_dointvec_minmax_conv
, ¶m
);
2484 EXPORT_SYMBOL(proc_dointvec_bool
);
2487 * proc_dointvec_unsigned - read a vector of integers with positive values
2488 * @table: the sysctl table
2489 * @write: %TRUE if this is a write to the sysctl file
2490 * @buffer: the user buffer
2491 * @lenp: the size of the user buffer
2492 * @ppos: file position
2494 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2495 * values from/to the user buffer, treated as an ASCII string.
2497 * This routine will ensure the values are positive.
2499 * Returns 0 on success.
2501 int proc_dointvec_unsigned(struct ctl_table
*table
, int write
,
2502 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2504 struct do_proc_dointvec_minmax_conv_param param
= {
2506 .max
= (int *) table
->extra2
,
2508 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2509 do_proc_dointvec_minmax_conv
, ¶m
);
2511 EXPORT_SYMBOL(proc_dointvec_unsigned
);
2513 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2514 void __user
*buffer
,
2515 size_t *lenp
, loff_t
*ppos
,
2516 unsigned long convmul
,
2517 unsigned long convdiv
)
2519 unsigned long *i
, *min
, *max
;
2520 int vleft
, first
= 1, err
= 0;
2521 unsigned long page
= 0;
2525 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2530 i
= (unsigned long *) data
;
2531 min
= (unsigned long *) table
->extra1
;
2532 max
= (unsigned long *) table
->extra2
;
2533 vleft
= table
->maxlen
/ sizeof(unsigned long);
2537 if (left
> PAGE_SIZE
- 1)
2538 left
= PAGE_SIZE
- 1;
2539 page
= __get_free_page(GFP_TEMPORARY
);
2540 kbuf
= (char *) page
;
2543 if (copy_from_user(kbuf
, buffer
, left
)) {
2550 for (; left
&& vleft
--; i
++, first
= 0) {
2556 left
-= proc_skip_spaces(&kbuf
);
2558 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2560 sizeof(proc_wspace_sep
), NULL
);
2565 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2569 val
= convdiv
* (*i
) / convmul
;
2571 err
= proc_put_char(&buffer
, &left
, '\t');
2572 err
= proc_put_long(&buffer
, &left
, val
, false);
2578 if (!write
&& !first
&& left
&& !err
)
2579 err
= proc_put_char(&buffer
, &left
, '\n');
2581 left
-= proc_skip_spaces(&kbuf
);
2586 return err
? : -EINVAL
;
2593 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2594 void __user
*buffer
,
2595 size_t *lenp
, loff_t
*ppos
,
2596 unsigned long convmul
,
2597 unsigned long convdiv
)
2599 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2600 buffer
, lenp
, ppos
, convmul
, convdiv
);
2604 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2605 * @table: the sysctl table
2606 * @write: %TRUE if this is a write to the sysctl file
2607 * @buffer: the user buffer
2608 * @lenp: the size of the user buffer
2609 * @ppos: file position
2611 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2612 * values from/to the user buffer, treated as an ASCII string.
2614 * This routine will ensure the values are within the range specified by
2615 * table->extra1 (min) and table->extra2 (max).
2617 * Returns 0 on success.
2619 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2620 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2622 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2626 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2627 * @table: the sysctl table
2628 * @write: %TRUE if this is a write to the sysctl file
2629 * @buffer: the user buffer
2630 * @lenp: the size of the user buffer
2631 * @ppos: file position
2633 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2634 * values from/to the user buffer, treated as an ASCII string. The values
2635 * are treated as milliseconds, and converted to jiffies when they are stored.
2637 * This routine will ensure the values are within the range specified by
2638 * table->extra1 (min) and table->extra2 (max).
2640 * Returns 0 on success.
2642 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2643 void __user
*buffer
,
2644 size_t *lenp
, loff_t
*ppos
)
2646 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2647 lenp
, ppos
, HZ
, 1000l);
2651 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2653 int write
, void *data
)
2656 if (*lvalp
> LONG_MAX
/ HZ
)
2658 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2664 lval
= (unsigned long)-val
;
2667 lval
= (unsigned long)val
;
2674 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2676 int write
, void *data
)
2679 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2681 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2687 lval
= (unsigned long)-val
;
2690 lval
= (unsigned long)val
;
2692 *lvalp
= jiffies_to_clock_t(lval
);
2697 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2699 int write
, void *data
)
2702 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2708 lval
= (unsigned long)-val
;
2711 lval
= (unsigned long)val
;
2713 *lvalp
= jiffies_to_msecs(lval
);
2719 * proc_dointvec_jiffies - read a vector of integers as seconds
2720 * @table: the sysctl table
2721 * @write: %TRUE if this is a write to the sysctl file
2722 * @buffer: the user buffer
2723 * @lenp: the size of the user buffer
2724 * @ppos: file position
2726 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2727 * values from/to the user buffer, treated as an ASCII string.
2728 * The values read are assumed to be in seconds, and are converted into
2731 * Returns 0 on success.
2733 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2734 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2736 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2737 do_proc_dointvec_jiffies_conv
,NULL
);
2741 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2742 * @table: the sysctl table
2743 * @write: %TRUE if this is a write to the sysctl file
2744 * @buffer: the user buffer
2745 * @lenp: the size of the user buffer
2746 * @ppos: pointer to the file position
2748 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2749 * values from/to the user buffer, treated as an ASCII string.
2750 * The values read are assumed to be in 1/USER_HZ seconds, and
2751 * are converted into jiffies.
2753 * Returns 0 on success.
2755 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2756 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2758 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2759 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2763 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2764 * @table: the sysctl table
2765 * @write: %TRUE if this is a write to the sysctl file
2766 * @buffer: the user buffer
2767 * @lenp: the size of the user buffer
2768 * @ppos: file position
2769 * @ppos: the current position in the file
2771 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2772 * values from/to the user buffer, treated as an ASCII string.
2773 * The values read are assumed to be in 1/1000 seconds, and
2774 * are converted into jiffies.
2776 * Returns 0 on success.
2778 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2779 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2781 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2782 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2785 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2786 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2788 struct pid
*new_pid
;
2792 tmp
= pid_vnr(cad_pid
);
2794 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2795 lenp
, ppos
, NULL
, NULL
);
2799 new_pid
= find_get_pid(tmp
);
2803 put_pid(xchg(&cad_pid
, new_pid
));
2808 * proc_do_large_bitmap - read/write from/to a large bitmap
2809 * @table: the sysctl table
2810 * @write: %TRUE if this is a write to the sysctl file
2811 * @buffer: the user buffer
2812 * @lenp: the size of the user buffer
2813 * @ppos: file position
2815 * The bitmap is stored at table->data and the bitmap length (in bits)
2818 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2819 * large bitmaps may be represented in a compact manner. Writing into
2820 * the file will clear the bitmap then update it with the given input.
2822 * Returns 0 on success.
2824 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2825 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2829 size_t left
= *lenp
;
2830 unsigned long bitmap_len
= table
->maxlen
;
2831 unsigned long *bitmap
= (unsigned long *) table
->data
;
2832 unsigned long *tmp_bitmap
= NULL
;
2833 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2835 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2841 unsigned long page
= 0;
2844 if (left
> PAGE_SIZE
- 1)
2845 left
= PAGE_SIZE
- 1;
2847 page
= __get_free_page(GFP_TEMPORARY
);
2848 kbuf
= (char *) page
;
2851 if (copy_from_user(kbuf
, buffer
, left
)) {
2857 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2863 proc_skip_char(&kbuf
, &left
, '\n');
2864 while (!err
&& left
) {
2865 unsigned long val_a
, val_b
;
2868 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2872 if (val_a
>= bitmap_len
|| neg
) {
2884 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2885 &neg
, tr_b
, sizeof(tr_b
),
2889 if (val_b
>= bitmap_len
|| neg
||
2900 while (val_a
<= val_b
)
2901 set_bit(val_a
++, tmp_bitmap
);
2904 proc_skip_char(&kbuf
, &left
, '\n');
2908 unsigned long bit_a
, bit_b
= 0;
2911 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2912 if (bit_a
>= bitmap_len
)
2914 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2918 err
= proc_put_char(&buffer
, &left
, ',');
2922 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2925 if (bit_a
!= bit_b
) {
2926 err
= proc_put_char(&buffer
, &left
, '-');
2929 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2937 err
= proc_put_char(&buffer
, &left
, '\n');
2943 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2945 memcpy(bitmap
, tmp_bitmap
,
2946 BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long));
2958 #else /* CONFIG_PROC_SYSCTL */
2960 int proc_dostring(struct ctl_table
*table
, int write
,
2961 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2966 int proc_dointvec(struct ctl_table
*table
, int write
,
2967 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2972 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2973 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2978 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2979 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2984 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2985 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2990 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2991 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2996 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2997 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3002 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3003 void __user
*buffer
,
3004 size_t *lenp
, loff_t
*ppos
)
3010 #endif /* CONFIG_PROC_SYSCTL */
3013 * No sense putting this after each symbol definition, twice,
3014 * exception granted :-)
3016 EXPORT_SYMBOL(proc_dointvec
);
3017 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3018 EXPORT_SYMBOL(proc_dointvec_minmax
);
3019 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3020 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3021 EXPORT_SYMBOL(proc_dostring
);
3022 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3023 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3024 EXPORT_SYMBOL(register_sysctl_table
);
3025 EXPORT_SYMBOL(register_sysctl_paths
);
3026 EXPORT_SYMBOL(unregister_sysctl_table
);