2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/signal.h>
27 #include <linux/proc_fs.h>
28 #include <linux/security.h>
29 #include <linux/ctype.h>
30 #include <linux/kmemcheck.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/ratelimit.h>
40 #include <linux/compaction.h>
41 #include <linux/hugetlb.h>
42 #include <linux/initrd.h>
43 #include <linux/key.h>
44 #include <linux/times.h>
45 #include <linux/limits.h>
46 #include <linux/dcache.h>
47 #include <linux/syscalls.h>
48 #include <linux/vmstat.h>
49 #include <linux/nfs_fs.h>
50 #include <linux/acpi.h>
51 #include <linux/reboot.h>
52 #include <linux/ftrace.h>
53 #include <linux/slow-work.h>
54 #include <linux/perf_event.h>
55 #include <linux/kprobes.h>
56 #include <linux/pipe_fs_i.h>
58 #include <asm/uaccess.h>
59 #include <asm/processor.h>
63 #include <asm/stacktrace.h>
66 #ifdef CONFIG_BSD_PROCESS_ACCT
67 #include <linux/acct.h>
69 #ifdef CONFIG_RT_MUTEXES
70 #include <linux/rtmutex.h>
72 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
73 #include <linux/lockdep.h>
75 #ifdef CONFIG_CHR_DEV_SG
79 #ifdef CONFIG_LOCKUP_DETECTOR
80 #include <linux/nmi.h>
84 #if defined(CONFIG_SYSCTL)
86 /* External variables not in a header file. */
87 extern int sysctl_overcommit_memory
;
88 extern int sysctl_overcommit_ratio
;
89 extern int sysctl_panic_on_oom
;
90 extern int sysctl_oom_kill_allocating_task
;
91 extern int sysctl_oom_dump_tasks
;
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 unsigned long one_ul
= 1;
122 static int one_hundred
= 100;
124 static int ten_thousand
= 10000;
127 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
128 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
130 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
131 static int maxolduid
= 65535;
132 static int minolduid
;
133 static int min_percpu_pagelist_fract
= 8;
135 static int ngroups_max
= NGROUPS_MAX
;
138 #include <asm/system.h>
141 #ifdef CONFIG_SPARC64
142 extern int sysctl_tsb_ratio
;
146 extern int pwrsw_enabled
;
147 extern int unaligned_enabled
;
151 #ifdef CONFIG_MATHEMU
152 extern int sysctl_ieee_emulation_warnings
;
154 extern int sysctl_userprocess_debug
;
155 extern int spin_retry
;
159 extern int no_unaligned_warning
;
160 extern int unaligned_dump_stack
;
163 extern struct ratelimit_state printk_ratelimit_state
;
165 #ifdef CONFIG_PROC_SYSCTL
166 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
167 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
168 static int proc_taint(struct ctl_table
*table
, int write
,
169 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
172 #ifdef CONFIG_MAGIC_SYSRQ
173 static int __sysrq_enabled
; /* Note: sysrq code ises it's own private copy */
175 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
176 void __user
*buffer
, size_t *lenp
,
181 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
186 sysrq_toggle_support(__sysrq_enabled
);
193 static struct ctl_table root_table
[];
194 static struct ctl_table_root sysctl_table_root
;
195 static struct ctl_table_header root_table_header
= {
197 .ctl_table
= root_table
,
198 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
199 .root
= &sysctl_table_root
,
200 .set
= &sysctl_table_root
.default_set
,
202 static struct ctl_table_root sysctl_table_root
= {
203 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
204 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
207 static struct ctl_table kern_table
[];
208 static struct ctl_table vm_table
[];
209 static struct ctl_table fs_table
[];
210 static struct ctl_table debug_table
[];
211 static struct ctl_table dev_table
[];
212 extern struct ctl_table random_table
[];
213 #ifdef CONFIG_INOTIFY_USER
214 extern struct ctl_table inotify_table
[];
217 extern struct ctl_table epoll_table
[];
220 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
221 int sysctl_legacy_va_layout
;
224 /* The default sysctl tables: */
226 static struct ctl_table root_table
[] = {
228 .procname
= "kernel",
245 .child
= debug_table
,
253 * NOTE: do not add new entries to this table unless you have read
254 * Documentation/sysctl/ctl_unnumbered.txt
259 #ifdef CONFIG_SCHED_DEBUG
260 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
261 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
262 static int min_wakeup_granularity_ns
; /* 0 usecs */
263 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
264 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
265 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
266 static int min_sched_shares_ratelimit
= 100000; /* 100 usec */
267 static int max_sched_shares_ratelimit
= NSEC_PER_SEC
; /* 1 second */
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_shares_ratelimit",
313 .data
= &sysctl_sched_shares_ratelimit
,
314 .maxlen
= sizeof(unsigned int),
316 .proc_handler
= sched_proc_update_handler
,
317 .extra1
= &min_sched_shares_ratelimit
,
318 .extra2
= &max_sched_shares_ratelimit
,
321 .procname
= "sched_tunable_scaling",
322 .data
= &sysctl_sched_tunable_scaling
,
323 .maxlen
= sizeof(enum sched_tunable_scaling
),
325 .proc_handler
= sched_proc_update_handler
,
326 .extra1
= &min_sched_tunable_scaling
,
327 .extra2
= &max_sched_tunable_scaling
,
330 .procname
= "sched_shares_thresh",
331 .data
= &sysctl_sched_shares_thresh
,
332 .maxlen
= sizeof(unsigned int),
334 .proc_handler
= proc_dointvec_minmax
,
338 .procname
= "sched_migration_cost",
339 .data
= &sysctl_sched_migration_cost
,
340 .maxlen
= sizeof(unsigned int),
342 .proc_handler
= proc_dointvec
,
345 .procname
= "sched_nr_migrate",
346 .data
= &sysctl_sched_nr_migrate
,
347 .maxlen
= sizeof(unsigned int),
349 .proc_handler
= proc_dointvec
,
352 .procname
= "sched_time_avg",
353 .data
= &sysctl_sched_time_avg
,
354 .maxlen
= sizeof(unsigned int),
356 .proc_handler
= proc_dointvec
,
359 .procname
= "timer_migration",
360 .data
= &sysctl_timer_migration
,
361 .maxlen
= sizeof(unsigned int),
363 .proc_handler
= proc_dointvec_minmax
,
369 .procname
= "sched_rt_period_us",
370 .data
= &sysctl_sched_rt_period
,
371 .maxlen
= sizeof(unsigned int),
373 .proc_handler
= sched_rt_handler
,
376 .procname
= "sched_rt_runtime_us",
377 .data
= &sysctl_sched_rt_runtime
,
378 .maxlen
= sizeof(int),
380 .proc_handler
= sched_rt_handler
,
383 .procname
= "sched_compat_yield",
384 .data
= &sysctl_sched_compat_yield
,
385 .maxlen
= sizeof(unsigned int),
387 .proc_handler
= proc_dointvec
,
389 #ifdef CONFIG_PROVE_LOCKING
391 .procname
= "prove_locking",
392 .data
= &prove_locking
,
393 .maxlen
= sizeof(int),
395 .proc_handler
= proc_dointvec
,
398 #ifdef CONFIG_LOCK_STAT
400 .procname
= "lock_stat",
402 .maxlen
= sizeof(int),
404 .proc_handler
= proc_dointvec
,
409 .data
= &panic_timeout
,
410 .maxlen
= sizeof(int),
412 .proc_handler
= proc_dointvec
,
415 .procname
= "core_uses_pid",
416 .data
= &core_uses_pid
,
417 .maxlen
= sizeof(int),
419 .proc_handler
= proc_dointvec
,
422 .procname
= "core_pattern",
423 .data
= core_pattern
,
424 .maxlen
= CORENAME_MAX_SIZE
,
426 .proc_handler
= proc_dostring
,
429 .procname
= "core_pipe_limit",
430 .data
= &core_pipe_limit
,
431 .maxlen
= sizeof(unsigned int),
433 .proc_handler
= proc_dointvec
,
435 #ifdef CONFIG_PROC_SYSCTL
437 .procname
= "tainted",
438 .maxlen
= sizeof(long),
440 .proc_handler
= proc_taint
,
443 #ifdef CONFIG_LATENCYTOP
445 .procname
= "latencytop",
446 .data
= &latencytop_enabled
,
447 .maxlen
= sizeof(int),
449 .proc_handler
= proc_dointvec
,
452 #ifdef CONFIG_BLK_DEV_INITRD
454 .procname
= "real-root-dev",
455 .data
= &real_root_dev
,
456 .maxlen
= sizeof(int),
458 .proc_handler
= proc_dointvec
,
462 .procname
= "print-fatal-signals",
463 .data
= &print_fatal_signals
,
464 .maxlen
= sizeof(int),
466 .proc_handler
= proc_dointvec
,
470 .procname
= "reboot-cmd",
471 .data
= reboot_command
,
474 .proc_handler
= proc_dostring
,
477 .procname
= "stop-a",
478 .data
= &stop_a_enabled
,
479 .maxlen
= sizeof (int),
481 .proc_handler
= proc_dointvec
,
484 .procname
= "scons-poweroff",
485 .data
= &scons_pwroff
,
486 .maxlen
= sizeof (int),
488 .proc_handler
= proc_dointvec
,
491 #ifdef CONFIG_SPARC64
493 .procname
= "tsb-ratio",
494 .data
= &sysctl_tsb_ratio
,
495 .maxlen
= sizeof (int),
497 .proc_handler
= proc_dointvec
,
502 .procname
= "soft-power",
503 .data
= &pwrsw_enabled
,
504 .maxlen
= sizeof (int),
506 .proc_handler
= proc_dointvec
,
509 .procname
= "unaligned-trap",
510 .data
= &unaligned_enabled
,
511 .maxlen
= sizeof (int),
513 .proc_handler
= proc_dointvec
,
517 .procname
= "ctrl-alt-del",
519 .maxlen
= sizeof(int),
521 .proc_handler
= proc_dointvec
,
523 #ifdef CONFIG_FUNCTION_TRACER
525 .procname
= "ftrace_enabled",
526 .data
= &ftrace_enabled
,
527 .maxlen
= sizeof(int),
529 .proc_handler
= ftrace_enable_sysctl
,
532 #ifdef CONFIG_STACK_TRACER
534 .procname
= "stack_tracer_enabled",
535 .data
= &stack_tracer_enabled
,
536 .maxlen
= sizeof(int),
538 .proc_handler
= stack_trace_sysctl
,
541 #ifdef CONFIG_TRACING
543 .procname
= "ftrace_dump_on_oops",
544 .data
= &ftrace_dump_on_oops
,
545 .maxlen
= sizeof(int),
547 .proc_handler
= proc_dointvec
,
550 #ifdef CONFIG_MODULES
552 .procname
= "modprobe",
553 .data
= &modprobe_path
,
554 .maxlen
= KMOD_PATH_LEN
,
556 .proc_handler
= proc_dostring
,
559 .procname
= "modules_disabled",
560 .data
= &modules_disabled
,
561 .maxlen
= sizeof(int),
563 /* only handle a transition from default "0" to "1" */
564 .proc_handler
= proc_dointvec_minmax
,
569 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
571 .procname
= "hotplug",
572 .data
= &uevent_helper
,
573 .maxlen
= UEVENT_HELPER_PATH_LEN
,
575 .proc_handler
= proc_dostring
,
578 #ifdef CONFIG_CHR_DEV_SG
580 .procname
= "sg-big-buff",
581 .data
= &sg_big_buff
,
582 .maxlen
= sizeof (int),
584 .proc_handler
= proc_dointvec
,
587 #ifdef CONFIG_BSD_PROCESS_ACCT
591 .maxlen
= 3*sizeof(int),
593 .proc_handler
= proc_dointvec
,
596 #ifdef CONFIG_MAGIC_SYSRQ
599 .data
= &__sysrq_enabled
,
600 .maxlen
= sizeof (int),
602 .proc_handler
= sysrq_sysctl_handler
,
605 #ifdef CONFIG_PROC_SYSCTL
607 .procname
= "cad_pid",
609 .maxlen
= sizeof (int),
611 .proc_handler
= proc_do_cad_pid
,
615 .procname
= "threads-max",
616 .data
= &max_threads
,
617 .maxlen
= sizeof(int),
619 .proc_handler
= proc_dointvec
,
622 .procname
= "random",
624 .child
= random_table
,
627 .procname
= "overflowuid",
628 .data
= &overflowuid
,
629 .maxlen
= sizeof(int),
631 .proc_handler
= proc_dointvec_minmax
,
632 .extra1
= &minolduid
,
633 .extra2
= &maxolduid
,
636 .procname
= "overflowgid",
637 .data
= &overflowgid
,
638 .maxlen
= sizeof(int),
640 .proc_handler
= proc_dointvec_minmax
,
641 .extra1
= &minolduid
,
642 .extra2
= &maxolduid
,
645 #ifdef CONFIG_MATHEMU
647 .procname
= "ieee_emulation_warnings",
648 .data
= &sysctl_ieee_emulation_warnings
,
649 .maxlen
= sizeof(int),
651 .proc_handler
= proc_dointvec
,
655 .procname
= "userprocess_debug",
656 .data
= &show_unhandled_signals
,
657 .maxlen
= sizeof(int),
659 .proc_handler
= proc_dointvec
,
663 .procname
= "pid_max",
665 .maxlen
= sizeof (int),
667 .proc_handler
= proc_dointvec_minmax
,
668 .extra1
= &pid_max_min
,
669 .extra2
= &pid_max_max
,
672 .procname
= "panic_on_oops",
673 .data
= &panic_on_oops
,
674 .maxlen
= sizeof(int),
676 .proc_handler
= proc_dointvec
,
678 #if defined CONFIG_PRINTK
680 .procname
= "printk",
681 .data
= &console_loglevel
,
682 .maxlen
= 4*sizeof(int),
684 .proc_handler
= proc_dointvec
,
687 .procname
= "printk_ratelimit",
688 .data
= &printk_ratelimit_state
.interval
,
689 .maxlen
= sizeof(int),
691 .proc_handler
= proc_dointvec_jiffies
,
694 .procname
= "printk_ratelimit_burst",
695 .data
= &printk_ratelimit_state
.burst
,
696 .maxlen
= sizeof(int),
698 .proc_handler
= proc_dointvec
,
701 .procname
= "printk_delay",
702 .data
= &printk_delay_msec
,
703 .maxlen
= sizeof(int),
705 .proc_handler
= proc_dointvec_minmax
,
707 .extra2
= &ten_thousand
,
711 .procname
= "ngroups_max",
712 .data
= &ngroups_max
,
713 .maxlen
= sizeof (int),
715 .proc_handler
= proc_dointvec
,
717 #if defined(CONFIG_LOCKUP_DETECTOR)
719 .procname
= "watchdog",
720 .data
= &watchdog_enabled
,
721 .maxlen
= sizeof (int),
723 .proc_handler
= proc_dowatchdog_enabled
,
726 .procname
= "watchdog_thresh",
727 .data
= &softlockup_thresh
,
728 .maxlen
= sizeof(int),
730 .proc_handler
= proc_dowatchdog_thresh
,
735 .procname
= "softlockup_panic",
736 .data
= &softlockup_panic
,
737 .maxlen
= sizeof(int),
739 .proc_handler
= proc_dointvec_minmax
,
744 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
746 .procname
= "unknown_nmi_panic",
747 .data
= &unknown_nmi_panic
,
748 .maxlen
= sizeof (int),
750 .proc_handler
= proc_dointvec
,
753 .procname
= "nmi_watchdog",
754 .data
= &nmi_watchdog_enabled
,
755 .maxlen
= sizeof (int),
757 .proc_handler
= proc_nmi_enabled
,
760 #if defined(CONFIG_X86)
762 .procname
= "panic_on_unrecovered_nmi",
763 .data
= &panic_on_unrecovered_nmi
,
764 .maxlen
= sizeof(int),
766 .proc_handler
= proc_dointvec
,
769 .procname
= "panic_on_io_nmi",
770 .data
= &panic_on_io_nmi
,
771 .maxlen
= sizeof(int),
773 .proc_handler
= proc_dointvec
,
776 .procname
= "bootloader_type",
777 .data
= &bootloader_type
,
778 .maxlen
= sizeof (int),
780 .proc_handler
= proc_dointvec
,
783 .procname
= "bootloader_version",
784 .data
= &bootloader_version
,
785 .maxlen
= sizeof (int),
787 .proc_handler
= proc_dointvec
,
790 .procname
= "kstack_depth_to_print",
791 .data
= &kstack_depth_to_print
,
792 .maxlen
= sizeof(int),
794 .proc_handler
= proc_dointvec
,
797 .procname
= "io_delay_type",
798 .data
= &io_delay_type
,
799 .maxlen
= sizeof(int),
801 .proc_handler
= proc_dointvec
,
804 #if defined(CONFIG_MMU)
806 .procname
= "randomize_va_space",
807 .data
= &randomize_va_space
,
808 .maxlen
= sizeof(int),
810 .proc_handler
= proc_dointvec
,
813 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
815 .procname
= "spin_retry",
817 .maxlen
= sizeof (int),
819 .proc_handler
= proc_dointvec
,
822 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
824 .procname
= "acpi_video_flags",
825 .data
= &acpi_realmode_flags
,
826 .maxlen
= sizeof (unsigned long),
828 .proc_handler
= proc_doulongvec_minmax
,
833 .procname
= "ignore-unaligned-usertrap",
834 .data
= &no_unaligned_warning
,
835 .maxlen
= sizeof (int),
837 .proc_handler
= proc_dointvec
,
840 .procname
= "unaligned-dump-stack",
841 .data
= &unaligned_dump_stack
,
842 .maxlen
= sizeof (int),
844 .proc_handler
= proc_dointvec
,
847 #ifdef CONFIG_DETECT_HUNG_TASK
849 .procname
= "hung_task_panic",
850 .data
= &sysctl_hung_task_panic
,
851 .maxlen
= sizeof(int),
853 .proc_handler
= proc_dointvec_minmax
,
858 .procname
= "hung_task_check_count",
859 .data
= &sysctl_hung_task_check_count
,
860 .maxlen
= sizeof(unsigned long),
862 .proc_handler
= proc_doulongvec_minmax
,
865 .procname
= "hung_task_timeout_secs",
866 .data
= &sysctl_hung_task_timeout_secs
,
867 .maxlen
= sizeof(unsigned long),
869 .proc_handler
= proc_dohung_task_timeout_secs
,
872 .procname
= "hung_task_warnings",
873 .data
= &sysctl_hung_task_warnings
,
874 .maxlen
= sizeof(unsigned long),
876 .proc_handler
= proc_doulongvec_minmax
,
881 .procname
= "compat-log",
883 .maxlen
= sizeof (int),
885 .proc_handler
= proc_dointvec
,
888 #ifdef CONFIG_RT_MUTEXES
890 .procname
= "max_lock_depth",
891 .data
= &max_lock_depth
,
892 .maxlen
= sizeof(int),
894 .proc_handler
= proc_dointvec
,
898 .procname
= "poweroff_cmd",
899 .data
= &poweroff_cmd
,
900 .maxlen
= POWEROFF_CMD_PATH_LEN
,
902 .proc_handler
= proc_dostring
,
908 .child
= key_sysctls
,
911 #ifdef CONFIG_RCU_TORTURE_TEST
913 .procname
= "rcutorture_runnable",
914 .data
= &rcutorture_runnable
,
915 .maxlen
= sizeof(int),
917 .proc_handler
= proc_dointvec
,
920 #ifdef CONFIG_SLOW_WORK
922 .procname
= "slow-work",
924 .child
= slow_work_sysctls
,
927 #ifdef CONFIG_PERF_EVENTS
929 .procname
= "perf_event_paranoid",
930 .data
= &sysctl_perf_event_paranoid
,
931 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
933 .proc_handler
= proc_dointvec
,
936 .procname
= "perf_event_mlock_kb",
937 .data
= &sysctl_perf_event_mlock
,
938 .maxlen
= sizeof(sysctl_perf_event_mlock
),
940 .proc_handler
= proc_dointvec
,
943 .procname
= "perf_event_max_sample_rate",
944 .data
= &sysctl_perf_event_sample_rate
,
945 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
947 .proc_handler
= proc_dointvec
,
950 #ifdef CONFIG_KMEMCHECK
952 .procname
= "kmemcheck",
953 .data
= &kmemcheck_enabled
,
954 .maxlen
= sizeof(int),
956 .proc_handler
= proc_dointvec
,
961 .procname
= "blk_iopoll",
962 .data
= &blk_iopoll_enabled
,
963 .maxlen
= sizeof(int),
965 .proc_handler
= proc_dointvec
,
969 * NOTE: do not add new entries to this table unless you have read
970 * Documentation/sysctl/ctl_unnumbered.txt
975 static struct ctl_table vm_table
[] = {
977 .procname
= "overcommit_memory",
978 .data
= &sysctl_overcommit_memory
,
979 .maxlen
= sizeof(sysctl_overcommit_memory
),
981 .proc_handler
= proc_dointvec
,
984 .procname
= "panic_on_oom",
985 .data
= &sysctl_panic_on_oom
,
986 .maxlen
= sizeof(sysctl_panic_on_oom
),
988 .proc_handler
= proc_dointvec
,
991 .procname
= "oom_kill_allocating_task",
992 .data
= &sysctl_oom_kill_allocating_task
,
993 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
995 .proc_handler
= proc_dointvec
,
998 .procname
= "oom_dump_tasks",
999 .data
= &sysctl_oom_dump_tasks
,
1000 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1002 .proc_handler
= proc_dointvec
,
1005 .procname
= "overcommit_ratio",
1006 .data
= &sysctl_overcommit_ratio
,
1007 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1009 .proc_handler
= proc_dointvec
,
1012 .procname
= "page-cluster",
1013 .data
= &page_cluster
,
1014 .maxlen
= sizeof(int),
1016 .proc_handler
= proc_dointvec
,
1019 .procname
= "dirty_background_ratio",
1020 .data
= &dirty_background_ratio
,
1021 .maxlen
= sizeof(dirty_background_ratio
),
1023 .proc_handler
= dirty_background_ratio_handler
,
1025 .extra2
= &one_hundred
,
1028 .procname
= "dirty_background_bytes",
1029 .data
= &dirty_background_bytes
,
1030 .maxlen
= sizeof(dirty_background_bytes
),
1032 .proc_handler
= dirty_background_bytes_handler
,
1036 .procname
= "dirty_ratio",
1037 .data
= &vm_dirty_ratio
,
1038 .maxlen
= sizeof(vm_dirty_ratio
),
1040 .proc_handler
= dirty_ratio_handler
,
1042 .extra2
= &one_hundred
,
1045 .procname
= "dirty_bytes",
1046 .data
= &vm_dirty_bytes
,
1047 .maxlen
= sizeof(vm_dirty_bytes
),
1049 .proc_handler
= dirty_bytes_handler
,
1050 .extra1
= &dirty_bytes_min
,
1053 .procname
= "dirty_writeback_centisecs",
1054 .data
= &dirty_writeback_interval
,
1055 .maxlen
= sizeof(dirty_writeback_interval
),
1057 .proc_handler
= dirty_writeback_centisecs_handler
,
1060 .procname
= "dirty_expire_centisecs",
1061 .data
= &dirty_expire_interval
,
1062 .maxlen
= sizeof(dirty_expire_interval
),
1064 .proc_handler
= proc_dointvec
,
1067 .procname
= "nr_pdflush_threads",
1068 .data
= &nr_pdflush_threads
,
1069 .maxlen
= sizeof nr_pdflush_threads
,
1070 .mode
= 0444 /* read-only*/,
1071 .proc_handler
= proc_dointvec
,
1074 .procname
= "swappiness",
1075 .data
= &vm_swappiness
,
1076 .maxlen
= sizeof(vm_swappiness
),
1078 .proc_handler
= proc_dointvec_minmax
,
1080 .extra2
= &one_hundred
,
1082 #ifdef CONFIG_HUGETLB_PAGE
1084 .procname
= "nr_hugepages",
1086 .maxlen
= sizeof(unsigned long),
1088 .proc_handler
= hugetlb_sysctl_handler
,
1089 .extra1
= (void *)&hugetlb_zero
,
1090 .extra2
= (void *)&hugetlb_infinity
,
1094 .procname
= "nr_hugepages_mempolicy",
1096 .maxlen
= sizeof(unsigned long),
1098 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1099 .extra1
= (void *)&hugetlb_zero
,
1100 .extra2
= (void *)&hugetlb_infinity
,
1104 .procname
= "hugetlb_shm_group",
1105 .data
= &sysctl_hugetlb_shm_group
,
1106 .maxlen
= sizeof(gid_t
),
1108 .proc_handler
= proc_dointvec
,
1111 .procname
= "hugepages_treat_as_movable",
1112 .data
= &hugepages_treat_as_movable
,
1113 .maxlen
= sizeof(int),
1115 .proc_handler
= hugetlb_treat_movable_handler
,
1118 .procname
= "nr_overcommit_hugepages",
1120 .maxlen
= sizeof(unsigned long),
1122 .proc_handler
= hugetlb_overcommit_handler
,
1123 .extra1
= (void *)&hugetlb_zero
,
1124 .extra2
= (void *)&hugetlb_infinity
,
1128 .procname
= "lowmem_reserve_ratio",
1129 .data
= &sysctl_lowmem_reserve_ratio
,
1130 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1132 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1135 .procname
= "drop_caches",
1136 .data
= &sysctl_drop_caches
,
1137 .maxlen
= sizeof(int),
1139 .proc_handler
= drop_caches_sysctl_handler
,
1141 #ifdef CONFIG_COMPACTION
1143 .procname
= "compact_memory",
1144 .data
= &sysctl_compact_memory
,
1145 .maxlen
= sizeof(int),
1147 .proc_handler
= sysctl_compaction_handler
,
1150 .procname
= "extfrag_threshold",
1151 .data
= &sysctl_extfrag_threshold
,
1152 .maxlen
= sizeof(int),
1154 .proc_handler
= sysctl_extfrag_handler
,
1155 .extra1
= &min_extfrag_threshold
,
1156 .extra2
= &max_extfrag_threshold
,
1159 #endif /* CONFIG_COMPACTION */
1161 .procname
= "min_free_kbytes",
1162 .data
= &min_free_kbytes
,
1163 .maxlen
= sizeof(min_free_kbytes
),
1165 .proc_handler
= min_free_kbytes_sysctl_handler
,
1169 .procname
= "percpu_pagelist_fraction",
1170 .data
= &percpu_pagelist_fraction
,
1171 .maxlen
= sizeof(percpu_pagelist_fraction
),
1173 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1174 .extra1
= &min_percpu_pagelist_fract
,
1178 .procname
= "max_map_count",
1179 .data
= &sysctl_max_map_count
,
1180 .maxlen
= sizeof(sysctl_max_map_count
),
1182 .proc_handler
= proc_dointvec_minmax
,
1187 .procname
= "nr_trim_pages",
1188 .data
= &sysctl_nr_trim_pages
,
1189 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1191 .proc_handler
= proc_dointvec_minmax
,
1196 .procname
= "laptop_mode",
1197 .data
= &laptop_mode
,
1198 .maxlen
= sizeof(laptop_mode
),
1200 .proc_handler
= proc_dointvec_jiffies
,
1203 .procname
= "block_dump",
1204 .data
= &block_dump
,
1205 .maxlen
= sizeof(block_dump
),
1207 .proc_handler
= proc_dointvec
,
1211 .procname
= "vfs_cache_pressure",
1212 .data
= &sysctl_vfs_cache_pressure
,
1213 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1215 .proc_handler
= proc_dointvec
,
1218 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1220 .procname
= "legacy_va_layout",
1221 .data
= &sysctl_legacy_va_layout
,
1222 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1224 .proc_handler
= proc_dointvec
,
1230 .procname
= "zone_reclaim_mode",
1231 .data
= &zone_reclaim_mode
,
1232 .maxlen
= sizeof(zone_reclaim_mode
),
1234 .proc_handler
= proc_dointvec
,
1238 .procname
= "min_unmapped_ratio",
1239 .data
= &sysctl_min_unmapped_ratio
,
1240 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1242 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1244 .extra2
= &one_hundred
,
1247 .procname
= "min_slab_ratio",
1248 .data
= &sysctl_min_slab_ratio
,
1249 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1251 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1253 .extra2
= &one_hundred
,
1258 .procname
= "stat_interval",
1259 .data
= &sysctl_stat_interval
,
1260 .maxlen
= sizeof(sysctl_stat_interval
),
1262 .proc_handler
= proc_dointvec_jiffies
,
1267 .procname
= "mmap_min_addr",
1268 .data
= &dac_mmap_min_addr
,
1269 .maxlen
= sizeof(unsigned long),
1271 .proc_handler
= mmap_min_addr_handler
,
1276 .procname
= "numa_zonelist_order",
1277 .data
= &numa_zonelist_order
,
1278 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1280 .proc_handler
= numa_zonelist_order_handler
,
1283 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1284 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1286 .procname
= "vdso_enabled",
1287 .data
= &vdso_enabled
,
1288 .maxlen
= sizeof(vdso_enabled
),
1290 .proc_handler
= proc_dointvec
,
1294 #ifdef CONFIG_HIGHMEM
1296 .procname
= "highmem_is_dirtyable",
1297 .data
= &vm_highmem_is_dirtyable
,
1298 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1300 .proc_handler
= proc_dointvec_minmax
,
1306 .procname
= "scan_unevictable_pages",
1307 .data
= &scan_unevictable_pages
,
1308 .maxlen
= sizeof(scan_unevictable_pages
),
1310 .proc_handler
= scan_unevictable_handler
,
1312 #ifdef CONFIG_MEMORY_FAILURE
1314 .procname
= "memory_failure_early_kill",
1315 .data
= &sysctl_memory_failure_early_kill
,
1316 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1318 .proc_handler
= proc_dointvec_minmax
,
1323 .procname
= "memory_failure_recovery",
1324 .data
= &sysctl_memory_failure_recovery
,
1325 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1327 .proc_handler
= proc_dointvec_minmax
,
1334 * NOTE: do not add new entries to this table unless you have read
1335 * Documentation/sysctl/ctl_unnumbered.txt
1340 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1341 static struct ctl_table binfmt_misc_table
[] = {
1346 static struct ctl_table fs_table
[] = {
1348 .procname
= "inode-nr",
1349 .data
= &inodes_stat
,
1350 .maxlen
= 2*sizeof(int),
1352 .proc_handler
= proc_dointvec
,
1355 .procname
= "inode-state",
1356 .data
= &inodes_stat
,
1357 .maxlen
= 7*sizeof(int),
1359 .proc_handler
= proc_dointvec
,
1362 .procname
= "file-nr",
1363 .data
= &files_stat
,
1364 .maxlen
= 3*sizeof(int),
1366 .proc_handler
= proc_nr_files
,
1369 .procname
= "file-max",
1370 .data
= &files_stat
.max_files
,
1371 .maxlen
= sizeof(int),
1373 .proc_handler
= proc_dointvec
,
1376 .procname
= "nr_open",
1377 .data
= &sysctl_nr_open
,
1378 .maxlen
= sizeof(int),
1380 .proc_handler
= proc_dointvec_minmax
,
1381 .extra1
= &sysctl_nr_open_min
,
1382 .extra2
= &sysctl_nr_open_max
,
1385 .procname
= "dentry-state",
1386 .data
= &dentry_stat
,
1387 .maxlen
= 6*sizeof(int),
1389 .proc_handler
= proc_dointvec
,
1392 .procname
= "overflowuid",
1393 .data
= &fs_overflowuid
,
1394 .maxlen
= sizeof(int),
1396 .proc_handler
= proc_dointvec_minmax
,
1397 .extra1
= &minolduid
,
1398 .extra2
= &maxolduid
,
1401 .procname
= "overflowgid",
1402 .data
= &fs_overflowgid
,
1403 .maxlen
= sizeof(int),
1405 .proc_handler
= proc_dointvec_minmax
,
1406 .extra1
= &minolduid
,
1407 .extra2
= &maxolduid
,
1409 #ifdef CONFIG_FILE_LOCKING
1411 .procname
= "leases-enable",
1412 .data
= &leases_enable
,
1413 .maxlen
= sizeof(int),
1415 .proc_handler
= proc_dointvec
,
1418 #ifdef CONFIG_DNOTIFY
1420 .procname
= "dir-notify-enable",
1421 .data
= &dir_notify_enable
,
1422 .maxlen
= sizeof(int),
1424 .proc_handler
= proc_dointvec
,
1428 #ifdef CONFIG_FILE_LOCKING
1430 .procname
= "lease-break-time",
1431 .data
= &lease_break_time
,
1432 .maxlen
= sizeof(int),
1434 .proc_handler
= proc_dointvec
,
1439 .procname
= "aio-nr",
1441 .maxlen
= sizeof(aio_nr
),
1443 .proc_handler
= proc_doulongvec_minmax
,
1446 .procname
= "aio-max-nr",
1447 .data
= &aio_max_nr
,
1448 .maxlen
= sizeof(aio_max_nr
),
1450 .proc_handler
= proc_doulongvec_minmax
,
1452 #endif /* CONFIG_AIO */
1453 #ifdef CONFIG_INOTIFY_USER
1455 .procname
= "inotify",
1457 .child
= inotify_table
,
1462 .procname
= "epoll",
1464 .child
= epoll_table
,
1469 .procname
= "suid_dumpable",
1470 .data
= &suid_dumpable
,
1471 .maxlen
= sizeof(int),
1473 .proc_handler
= proc_dointvec_minmax
,
1477 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1479 .procname
= "binfmt_misc",
1481 .child
= binfmt_misc_table
,
1485 .procname
= "pipe-max-size",
1486 .data
= &pipe_max_size
,
1487 .maxlen
= sizeof(int),
1489 .proc_handler
= &pipe_proc_fn
,
1490 .extra1
= &pipe_min_size
,
1493 * NOTE: do not add new entries to this table unless you have read
1494 * Documentation/sysctl/ctl_unnumbered.txt
1499 static struct ctl_table debug_table
[] = {
1500 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1501 defined(CONFIG_S390)
1503 .procname
= "exception-trace",
1504 .data
= &show_unhandled_signals
,
1505 .maxlen
= sizeof(int),
1507 .proc_handler
= proc_dointvec
1510 #if defined(CONFIG_OPTPROBES)
1512 .procname
= "kprobes-optimization",
1513 .data
= &sysctl_kprobes_optimization
,
1514 .maxlen
= sizeof(int),
1516 .proc_handler
= proc_kprobes_optimization_handler
,
1524 static struct ctl_table dev_table
[] = {
1528 static DEFINE_SPINLOCK(sysctl_lock
);
1530 /* called under sysctl_lock */
1531 static int use_table(struct ctl_table_header
*p
)
1533 if (unlikely(p
->unregistering
))
1539 /* called under sysctl_lock */
1540 static void unuse_table(struct ctl_table_header
*p
)
1543 if (unlikely(p
->unregistering
))
1544 complete(p
->unregistering
);
1547 /* called under sysctl_lock, will reacquire if has to wait */
1548 static void start_unregistering(struct ctl_table_header
*p
)
1551 * if p->used is 0, nobody will ever touch that entry again;
1552 * we'll eliminate all paths to it before dropping sysctl_lock
1554 if (unlikely(p
->used
)) {
1555 struct completion wait
;
1556 init_completion(&wait
);
1557 p
->unregistering
= &wait
;
1558 spin_unlock(&sysctl_lock
);
1559 wait_for_completion(&wait
);
1560 spin_lock(&sysctl_lock
);
1562 /* anything non-NULL; we'll never dereference it */
1563 p
->unregistering
= ERR_PTR(-EINVAL
);
1566 * do not remove from the list until nobody holds it; walking the
1567 * list in do_sysctl() relies on that.
1569 list_del_init(&p
->ctl_entry
);
1572 void sysctl_head_get(struct ctl_table_header
*head
)
1574 spin_lock(&sysctl_lock
);
1576 spin_unlock(&sysctl_lock
);
1579 void sysctl_head_put(struct ctl_table_header
*head
)
1581 spin_lock(&sysctl_lock
);
1584 spin_unlock(&sysctl_lock
);
1587 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1591 spin_lock(&sysctl_lock
);
1592 if (!use_table(head
))
1593 head
= ERR_PTR(-ENOENT
);
1594 spin_unlock(&sysctl_lock
);
1598 void sysctl_head_finish(struct ctl_table_header
*head
)
1602 spin_lock(&sysctl_lock
);
1604 spin_unlock(&sysctl_lock
);
1607 static struct ctl_table_set
*
1608 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1610 struct ctl_table_set
*set
= &root
->default_set
;
1612 set
= root
->lookup(root
, namespaces
);
1616 static struct list_head
*
1617 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1619 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1623 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1624 struct ctl_table_header
*prev
)
1626 struct ctl_table_root
*root
;
1627 struct list_head
*header_list
;
1628 struct ctl_table_header
*head
;
1629 struct list_head
*tmp
;
1631 spin_lock(&sysctl_lock
);
1634 tmp
= &prev
->ctl_entry
;
1638 tmp
= &root_table_header
.ctl_entry
;
1640 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1642 if (!use_table(head
))
1644 spin_unlock(&sysctl_lock
);
1649 header_list
= lookup_header_list(root
, namespaces
);
1650 if (tmp
!= header_list
)
1654 root
= list_entry(root
->root_list
.next
,
1655 struct ctl_table_root
, root_list
);
1656 if (root
== &sysctl_table_root
)
1658 header_list
= lookup_header_list(root
, namespaces
);
1659 } while (list_empty(header_list
));
1660 tmp
= header_list
->next
;
1663 spin_unlock(&sysctl_lock
);
1667 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1669 return __sysctl_head_next(current
->nsproxy
, prev
);
1672 void register_sysctl_root(struct ctl_table_root
*root
)
1674 spin_lock(&sysctl_lock
);
1675 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1676 spin_unlock(&sysctl_lock
);
1680 * sysctl_perm does NOT grant the superuser all rights automatically, because
1681 * some sysctl variables are readonly even to root.
1684 static int test_perm(int mode
, int op
)
1686 if (!current_euid())
1688 else if (in_egroup_p(0))
1690 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1695 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1700 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1704 if (root
->permissions
)
1705 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1709 return test_perm(mode
, op
);
1712 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1714 for (; table
->procname
; table
++) {
1715 table
->parent
= parent
;
1717 sysctl_set_parent(table
, table
->child
);
1721 static __init
int sysctl_init(void)
1723 sysctl_set_parent(NULL
, root_table
);
1724 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1727 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1733 core_initcall(sysctl_init
);
1735 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1736 struct ctl_table
*table
)
1738 struct ctl_table
*p
;
1739 const char *s
= branch
->procname
;
1741 /* branch should have named subdirectory as its first element */
1742 if (!s
|| !branch
->child
)
1745 /* ... and nothing else */
1746 if (branch
[1].procname
)
1749 /* table should contain subdirectory with the same name */
1750 for (p
= table
; p
->procname
; p
++) {
1753 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1759 /* see if attaching q to p would be an improvement */
1760 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1762 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1763 struct ctl_table
*next
;
1765 int not_in_parent
= !p
->attached_by
;
1767 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1768 if (by
== q
->attached_by
)
1770 if (to
== p
->attached_by
)
1776 if (is_better
&& not_in_parent
) {
1777 q
->attached_by
= by
;
1778 q
->attached_to
= to
;
1784 * __register_sysctl_paths - register a sysctl hierarchy
1785 * @root: List of sysctl headers to register on
1786 * @namespaces: Data to compute which lists of sysctl entries are visible
1787 * @path: The path to the directory the sysctl table is in.
1788 * @table: the top-level table structure
1790 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1791 * array. A completely 0 filled entry terminates the table.
1793 * The members of the &struct ctl_table structure are used as follows:
1795 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1796 * enter a sysctl file
1798 * data - a pointer to data for use by proc_handler
1800 * maxlen - the maximum size in bytes of the data
1802 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1804 * child - a pointer to the child sysctl table if this entry is a directory, or
1807 * proc_handler - the text handler routine (described below)
1809 * de - for internal use by the sysctl routines
1811 * extra1, extra2 - extra pointers usable by the proc handler routines
1813 * Leaf nodes in the sysctl tree will be represented by a single file
1814 * under /proc; non-leaf nodes will be represented by directories.
1816 * sysctl(2) can automatically manage read and write requests through
1817 * the sysctl table. The data and maxlen fields of the ctl_table
1818 * struct enable minimal validation of the values being written to be
1819 * performed, and the mode field allows minimal authentication.
1821 * There must be a proc_handler routine for any terminal nodes
1822 * mirrored under /proc/sys (non-terminals are handled by a built-in
1823 * directory handler). Several default handlers are available to
1824 * cover common cases -
1826 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1827 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1828 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1830 * It is the handler's job to read the input buffer from user memory
1831 * and process it. The handler should return 0 on success.
1833 * This routine returns %NULL on a failure to register, and a pointer
1834 * to the table header on success.
1836 struct ctl_table_header
*__register_sysctl_paths(
1837 struct ctl_table_root
*root
,
1838 struct nsproxy
*namespaces
,
1839 const struct ctl_path
*path
, struct ctl_table
*table
)
1841 struct ctl_table_header
*header
;
1842 struct ctl_table
*new, **prevp
;
1843 unsigned int n
, npath
;
1844 struct ctl_table_set
*set
;
1846 /* Count the path components */
1847 for (npath
= 0; path
[npath
].procname
; ++npath
)
1851 * For each path component, allocate a 2-element ctl_table array.
1852 * The first array element will be filled with the sysctl entry
1853 * for this, the second will be the sentinel (procname == 0).
1855 * We allocate everything in one go so that we don't have to
1856 * worry about freeing additional memory in unregister_sysctl_table.
1858 header
= kzalloc(sizeof(struct ctl_table_header
) +
1859 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1863 new = (struct ctl_table
*) (header
+ 1);
1865 /* Now connect the dots */
1866 prevp
= &header
->ctl_table
;
1867 for (n
= 0; n
< npath
; ++n
, ++path
) {
1868 /* Copy the procname */
1869 new->procname
= path
->procname
;
1873 prevp
= &new->child
;
1878 header
->ctl_table_arg
= table
;
1880 INIT_LIST_HEAD(&header
->ctl_entry
);
1882 header
->unregistering
= NULL
;
1883 header
->root
= root
;
1884 sysctl_set_parent(NULL
, header
->ctl_table
);
1886 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1887 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1892 spin_lock(&sysctl_lock
);
1893 header
->set
= lookup_header_set(root
, namespaces
);
1894 header
->attached_by
= header
->ctl_table
;
1895 header
->attached_to
= root_table
;
1896 header
->parent
= &root_table_header
;
1897 for (set
= header
->set
; set
; set
= set
->parent
) {
1898 struct ctl_table_header
*p
;
1899 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1900 if (p
->unregistering
)
1902 try_attach(p
, header
);
1905 header
->parent
->count
++;
1906 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1907 spin_unlock(&sysctl_lock
);
1913 * register_sysctl_table_path - register a sysctl table hierarchy
1914 * @path: The path to the directory the sysctl table is in.
1915 * @table: the top-level table structure
1917 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1918 * array. A completely 0 filled entry terminates the table.
1920 * See __register_sysctl_paths for more details.
1922 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1923 struct ctl_table
*table
)
1925 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1930 * register_sysctl_table - register a sysctl table hierarchy
1931 * @table: the top-level table structure
1933 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1934 * array. A completely 0 filled entry terminates the table.
1936 * See register_sysctl_paths for more details.
1938 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1940 static const struct ctl_path null_path
[] = { {} };
1942 return register_sysctl_paths(null_path
, table
);
1946 * unregister_sysctl_table - unregister a sysctl table hierarchy
1947 * @header: the header returned from register_sysctl_table
1949 * Unregisters the sysctl table and all children. proc entries may not
1950 * actually be removed until they are no longer used by anyone.
1952 void unregister_sysctl_table(struct ctl_table_header
* header
)
1959 spin_lock(&sysctl_lock
);
1960 start_unregistering(header
);
1961 if (!--header
->parent
->count
) {
1963 kfree(header
->parent
);
1965 if (!--header
->count
)
1967 spin_unlock(&sysctl_lock
);
1970 int sysctl_is_seen(struct ctl_table_header
*p
)
1972 struct ctl_table_set
*set
= p
->set
;
1974 spin_lock(&sysctl_lock
);
1975 if (p
->unregistering
)
1977 else if (!set
->is_seen
)
1980 res
= set
->is_seen(set
);
1981 spin_unlock(&sysctl_lock
);
1985 void setup_sysctl_set(struct ctl_table_set
*p
,
1986 struct ctl_table_set
*parent
,
1987 int (*is_seen
)(struct ctl_table_set
*))
1989 INIT_LIST_HEAD(&p
->list
);
1990 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1991 p
->is_seen
= is_seen
;
1994 #else /* !CONFIG_SYSCTL */
1995 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2000 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2001 struct ctl_table
*table
)
2006 void unregister_sysctl_table(struct ctl_table_header
* table
)
2010 void setup_sysctl_set(struct ctl_table_set
*p
,
2011 struct ctl_table_set
*parent
,
2012 int (*is_seen
)(struct ctl_table_set
*))
2016 void sysctl_head_put(struct ctl_table_header
*head
)
2020 #endif /* CONFIG_SYSCTL */
2026 #ifdef CONFIG_PROC_SYSCTL
2028 static int _proc_do_string(void* data
, int maxlen
, int write
,
2029 void __user
*buffer
,
2030 size_t *lenp
, loff_t
*ppos
)
2036 if (!data
|| !maxlen
|| !*lenp
) {
2044 while (len
< *lenp
) {
2045 if (get_user(c
, p
++))
2047 if (c
== 0 || c
== '\n')
2053 if(copy_from_user(data
, buffer
, len
))
2055 ((char *) data
)[len
] = 0;
2073 if(copy_to_user(buffer
, data
, len
))
2076 if(put_user('\n', ((char __user
*) buffer
) + len
))
2087 * proc_dostring - read a string sysctl
2088 * @table: the sysctl table
2089 * @write: %TRUE if this is a write to the sysctl file
2090 * @buffer: the user buffer
2091 * @lenp: the size of the user buffer
2092 * @ppos: file position
2094 * Reads/writes a string from/to the user buffer. If the kernel
2095 * buffer provided is not large enough to hold the string, the
2096 * string is truncated. The copied string is %NULL-terminated.
2097 * If the string is being read by the user process, it is copied
2098 * and a newline '\n' is added. It is truncated if the buffer is
2101 * Returns 0 on success.
2103 int proc_dostring(struct ctl_table
*table
, int write
,
2104 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2106 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2107 buffer
, lenp
, ppos
);
2110 static size_t proc_skip_spaces(char **buf
)
2113 char *tmp
= skip_spaces(*buf
);
2119 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2129 #define TMPBUFLEN 22
2131 * proc_get_long - reads an ASCII formatted integer from a user buffer
2133 * @buf: a kernel buffer
2134 * @size: size of the kernel buffer
2135 * @val: this is where the number will be stored
2136 * @neg: set to %TRUE if number is negative
2137 * @perm_tr: a vector which contains the allowed trailers
2138 * @perm_tr_len: size of the perm_tr vector
2139 * @tr: pointer to store the trailer character
2141 * In case of success %0 is returned and @buf and @size are updated with
2142 * the amount of bytes read. If @tr is non-NULL and a trailing
2143 * character exists (size is non-zero after returning from this
2144 * function), @tr is updated with the trailing character.
2146 static int proc_get_long(char **buf
, size_t *size
,
2147 unsigned long *val
, bool *neg
,
2148 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2151 char *p
, tmp
[TMPBUFLEN
];
2157 if (len
> TMPBUFLEN
- 1)
2158 len
= TMPBUFLEN
- 1;
2160 memcpy(tmp
, *buf
, len
);
2164 if (*p
== '-' && *size
> 1) {
2172 *val
= simple_strtoul(p
, &p
, 0);
2176 /* We don't know if the next char is whitespace thus we may accept
2177 * invalid integers (e.g. 1234...a) or two integers instead of one
2178 * (e.g. 123...1). So lets not allow such large numbers. */
2179 if (len
== TMPBUFLEN
- 1)
2182 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2185 if (tr
&& (len
< *size
))
2195 * proc_put_long - converts an integer to a decimal ASCII formatted string
2197 * @buf: the user buffer
2198 * @size: the size of the user buffer
2199 * @val: the integer to be converted
2200 * @neg: sign of the number, %TRUE for negative
2202 * In case of success %0 is returned and @buf and @size are updated with
2203 * the amount of bytes written.
2205 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2209 char tmp
[TMPBUFLEN
], *p
= tmp
;
2211 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2215 if (copy_to_user(*buf
, tmp
, len
))
2223 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2226 char __user
**buffer
= (char __user
**)buf
;
2227 if (put_user(c
, *buffer
))
2229 (*size
)--, (*buffer
)++;
2235 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2237 int write
, void *data
)
2240 *valp
= *negp
? -*lvalp
: *lvalp
;
2245 *lvalp
= (unsigned long)-val
;
2248 *lvalp
= (unsigned long)val
;
2254 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2256 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2257 int write
, void __user
*buffer
,
2258 size_t *lenp
, loff_t
*ppos
,
2259 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2260 int write
, void *data
),
2263 int *i
, vleft
, first
= 1, err
= 0;
2264 unsigned long page
= 0;
2268 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2273 i
= (int *) tbl_data
;
2274 vleft
= table
->maxlen
/ sizeof(*i
);
2278 conv
= do_proc_dointvec_conv
;
2281 if (left
> PAGE_SIZE
- 1)
2282 left
= PAGE_SIZE
- 1;
2283 page
= __get_free_page(GFP_TEMPORARY
);
2284 kbuf
= (char *) page
;
2287 if (copy_from_user(kbuf
, buffer
, left
)) {
2294 for (; left
&& vleft
--; i
++, first
=0) {
2299 left
-= proc_skip_spaces(&kbuf
);
2303 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2305 sizeof(proc_wspace_sep
), NULL
);
2308 if (conv(&neg
, &lval
, i
, 1, data
)) {
2313 if (conv(&neg
, &lval
, i
, 0, data
)) {
2318 err
= proc_put_char(&buffer
, &left
, '\t');
2321 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2327 if (!write
&& !first
&& left
&& !err
)
2328 err
= proc_put_char(&buffer
, &left
, '\n');
2329 if (write
&& !err
&& left
)
2330 left
-= proc_skip_spaces(&kbuf
);
2335 return err
? : -EINVAL
;
2342 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2343 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2344 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2345 int write
, void *data
),
2348 return __do_proc_dointvec(table
->data
, table
, write
,
2349 buffer
, lenp
, ppos
, conv
, data
);
2353 * proc_dointvec - read a vector of integers
2354 * @table: the sysctl table
2355 * @write: %TRUE if this is a write to the sysctl file
2356 * @buffer: the user buffer
2357 * @lenp: the size of the user buffer
2358 * @ppos: file position
2360 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2361 * values from/to the user buffer, treated as an ASCII string.
2363 * Returns 0 on success.
2365 int proc_dointvec(struct ctl_table
*table
, int write
,
2366 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2368 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2373 * Taint values can only be increased
2374 * This means we can safely use a temporary.
2376 static int proc_taint(struct ctl_table
*table
, int write
,
2377 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2380 unsigned long tmptaint
= get_taint();
2383 if (write
&& !capable(CAP_SYS_ADMIN
))
2388 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2394 * Poor man's atomic or. Not worth adding a primitive
2395 * to everyone's atomic.h for this
2398 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2399 if ((tmptaint
>> i
) & 1)
2407 struct do_proc_dointvec_minmax_conv_param
{
2412 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2414 int write
, void *data
)
2416 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2418 int val
= *negp
? -*lvalp
: *lvalp
;
2419 if ((param
->min
&& *param
->min
> val
) ||
2420 (param
->max
&& *param
->max
< val
))
2427 *lvalp
= (unsigned long)-val
;
2430 *lvalp
= (unsigned long)val
;
2437 * proc_dointvec_minmax - read a vector of integers with min/max values
2438 * @table: the sysctl table
2439 * @write: %TRUE if this is a write to the sysctl file
2440 * @buffer: the user buffer
2441 * @lenp: the size of the user buffer
2442 * @ppos: file position
2444 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2445 * values from/to the user buffer, treated as an ASCII string.
2447 * This routine will ensure the values are within the range specified by
2448 * table->extra1 (min) and table->extra2 (max).
2450 * Returns 0 on success.
2452 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2453 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2455 struct do_proc_dointvec_minmax_conv_param param
= {
2456 .min
= (int *) table
->extra1
,
2457 .max
= (int *) table
->extra2
,
2459 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2460 do_proc_dointvec_minmax_conv
, ¶m
);
2463 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2464 void __user
*buffer
,
2465 size_t *lenp
, loff_t
*ppos
,
2466 unsigned long convmul
,
2467 unsigned long convdiv
)
2469 unsigned long *i
, *min
, *max
;
2470 int vleft
, first
= 1, err
= 0;
2471 unsigned long page
= 0;
2475 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2480 i
= (unsigned long *) data
;
2481 min
= (unsigned long *) table
->extra1
;
2482 max
= (unsigned long *) table
->extra2
;
2483 vleft
= table
->maxlen
/ sizeof(unsigned long);
2487 if (left
> PAGE_SIZE
- 1)
2488 left
= PAGE_SIZE
- 1;
2489 page
= __get_free_page(GFP_TEMPORARY
);
2490 kbuf
= (char *) page
;
2493 if (copy_from_user(kbuf
, buffer
, left
)) {
2500 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2506 left
-= proc_skip_spaces(&kbuf
);
2508 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2510 sizeof(proc_wspace_sep
), NULL
);
2515 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2519 val
= convdiv
* (*i
) / convmul
;
2521 err
= proc_put_char(&buffer
, &left
, '\t');
2522 err
= proc_put_long(&buffer
, &left
, val
, false);
2528 if (!write
&& !first
&& left
&& !err
)
2529 err
= proc_put_char(&buffer
, &left
, '\n');
2531 left
-= proc_skip_spaces(&kbuf
);
2536 return err
? : -EINVAL
;
2543 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2544 void __user
*buffer
,
2545 size_t *lenp
, loff_t
*ppos
,
2546 unsigned long convmul
,
2547 unsigned long convdiv
)
2549 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2550 buffer
, lenp
, ppos
, convmul
, convdiv
);
2554 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2555 * @table: the sysctl table
2556 * @write: %TRUE if this is a write to the sysctl file
2557 * @buffer: the user buffer
2558 * @lenp: the size of the user buffer
2559 * @ppos: file position
2561 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2562 * values from/to the user buffer, treated as an ASCII string.
2564 * This routine will ensure the values are within the range specified by
2565 * table->extra1 (min) and table->extra2 (max).
2567 * Returns 0 on success.
2569 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2570 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2572 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2576 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2577 * @table: the sysctl table
2578 * @write: %TRUE if this is a write to the sysctl file
2579 * @buffer: the user buffer
2580 * @lenp: the size of the user buffer
2581 * @ppos: file position
2583 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2584 * values from/to the user buffer, treated as an ASCII string. The values
2585 * are treated as milliseconds, and converted to jiffies when they are stored.
2587 * This routine will ensure the values are within the range specified by
2588 * table->extra1 (min) and table->extra2 (max).
2590 * Returns 0 on success.
2592 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2593 void __user
*buffer
,
2594 size_t *lenp
, loff_t
*ppos
)
2596 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2597 lenp
, ppos
, HZ
, 1000l);
2601 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2603 int write
, void *data
)
2606 if (*lvalp
> LONG_MAX
/ HZ
)
2608 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2614 lval
= (unsigned long)-val
;
2617 lval
= (unsigned long)val
;
2624 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2626 int write
, void *data
)
2629 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2631 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2637 lval
= (unsigned long)-val
;
2640 lval
= (unsigned long)val
;
2642 *lvalp
= jiffies_to_clock_t(lval
);
2647 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2649 int write
, void *data
)
2652 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2658 lval
= (unsigned long)-val
;
2661 lval
= (unsigned long)val
;
2663 *lvalp
= jiffies_to_msecs(lval
);
2669 * proc_dointvec_jiffies - read a vector of integers as seconds
2670 * @table: the sysctl table
2671 * @write: %TRUE if this is a write to the sysctl file
2672 * @buffer: the user buffer
2673 * @lenp: the size of the user buffer
2674 * @ppos: file position
2676 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2677 * values from/to the user buffer, treated as an ASCII string.
2678 * The values read are assumed to be in seconds, and are converted into
2681 * Returns 0 on success.
2683 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2684 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2686 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2687 do_proc_dointvec_jiffies_conv
,NULL
);
2691 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2692 * @table: the sysctl table
2693 * @write: %TRUE if this is a write to the sysctl file
2694 * @buffer: the user buffer
2695 * @lenp: the size of the user buffer
2696 * @ppos: pointer to the file position
2698 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2699 * values from/to the user buffer, treated as an ASCII string.
2700 * The values read are assumed to be in 1/USER_HZ seconds, and
2701 * are converted into jiffies.
2703 * Returns 0 on success.
2705 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2706 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2708 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2709 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2713 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2714 * @table: the sysctl table
2715 * @write: %TRUE if this is a write to the sysctl file
2716 * @buffer: the user buffer
2717 * @lenp: the size of the user buffer
2718 * @ppos: file position
2719 * @ppos: the current position in the file
2721 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2722 * values from/to the user buffer, treated as an ASCII string.
2723 * The values read are assumed to be in 1/1000 seconds, and
2724 * are converted into jiffies.
2726 * Returns 0 on success.
2728 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2729 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2731 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2732 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2735 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2736 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2738 struct pid
*new_pid
;
2742 tmp
= pid_vnr(cad_pid
);
2744 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2745 lenp
, ppos
, NULL
, NULL
);
2749 new_pid
= find_get_pid(tmp
);
2753 put_pid(xchg(&cad_pid
, new_pid
));
2758 * proc_do_large_bitmap - read/write from/to a large bitmap
2759 * @table: the sysctl table
2760 * @write: %TRUE if this is a write to the sysctl file
2761 * @buffer: the user buffer
2762 * @lenp: the size of the user buffer
2763 * @ppos: file position
2765 * The bitmap is stored at table->data and the bitmap length (in bits)
2768 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2769 * large bitmaps may be represented in a compact manner. Writing into
2770 * the file will clear the bitmap then update it with the given input.
2772 * Returns 0 on success.
2774 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2775 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2779 size_t left
= *lenp
;
2780 unsigned long bitmap_len
= table
->maxlen
;
2781 unsigned long *bitmap
= (unsigned long *) table
->data
;
2782 unsigned long *tmp_bitmap
= NULL
;
2783 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2785 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2791 unsigned long page
= 0;
2794 if (left
> PAGE_SIZE
- 1)
2795 left
= PAGE_SIZE
- 1;
2797 page
= __get_free_page(GFP_TEMPORARY
);
2798 kbuf
= (char *) page
;
2801 if (copy_from_user(kbuf
, buffer
, left
)) {
2807 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2813 proc_skip_char(&kbuf
, &left
, '\n');
2814 while (!err
&& left
) {
2815 unsigned long val_a
, val_b
;
2818 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2822 if (val_a
>= bitmap_len
|| neg
) {
2834 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2835 &neg
, tr_b
, sizeof(tr_b
),
2839 if (val_b
>= bitmap_len
|| neg
||
2850 while (val_a
<= val_b
)
2851 set_bit(val_a
++, tmp_bitmap
);
2854 proc_skip_char(&kbuf
, &left
, '\n');
2858 unsigned long bit_a
, bit_b
= 0;
2861 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2862 if (bit_a
>= bitmap_len
)
2864 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2868 err
= proc_put_char(&buffer
, &left
, ',');
2872 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2875 if (bit_a
!= bit_b
) {
2876 err
= proc_put_char(&buffer
, &left
, '-');
2879 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2887 err
= proc_put_char(&buffer
, &left
, '\n');
2893 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2895 memcpy(bitmap
, tmp_bitmap
,
2896 BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long));
2908 #else /* CONFIG_PROC_FS */
2910 int proc_dostring(struct ctl_table
*table
, int write
,
2911 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2916 int proc_dointvec(struct ctl_table
*table
, int write
,
2917 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2922 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2923 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2928 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2929 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2934 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2935 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2940 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2941 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2946 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2947 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2952 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2953 void __user
*buffer
,
2954 size_t *lenp
, loff_t
*ppos
)
2960 #endif /* CONFIG_PROC_FS */
2963 * No sense putting this after each symbol definition, twice,
2964 * exception granted :-)
2966 EXPORT_SYMBOL(proc_dointvec
);
2967 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2968 EXPORT_SYMBOL(proc_dointvec_minmax
);
2969 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2970 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2971 EXPORT_SYMBOL(proc_dostring
);
2972 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2973 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2974 EXPORT_SYMBOL(register_sysctl_table
);
2975 EXPORT_SYMBOL(register_sysctl_paths
);
2976 EXPORT_SYMBOL(unregister_sysctl_table
);