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/dnotify.h>
48 #include <linux/syscalls.h>
49 #include <linux/vmstat.h>
50 #include <linux/nfs_fs.h>
51 #include <linux/acpi.h>
52 #include <linux/reboot.h>
53 #include <linux/ftrace.h>
54 #include <linux/perf_event.h>
55 #include <linux/kprobes.h>
56 #include <linux/pipe_fs_i.h>
57 #include <linux/oom.h>
59 #include <asm/uaccess.h>
60 #include <asm/processor.h>
64 #include <asm/stacktrace.h>
67 #ifdef CONFIG_BSD_PROCESS_ACCT
68 #include <linux/acct.h>
70 #ifdef CONFIG_RT_MUTEXES
71 #include <linux/rtmutex.h>
73 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
74 #include <linux/lockdep.h>
76 #ifdef CONFIG_CHR_DEV_SG
80 #ifdef CONFIG_LOCKUP_DETECTOR
81 #include <linux/nmi.h>
85 #if defined(CONFIG_SYSCTL)
87 /* External variables not in a header file. */
88 extern int sysctl_overcommit_memory
;
89 extern int sysctl_overcommit_ratio
;
90 extern int max_threads
;
91 extern int core_uses_pid
;
92 extern int suid_dumpable
;
93 extern char core_pattern
[];
94 extern unsigned int core_pipe_limit
;
96 extern int min_free_kbytes
;
97 extern int pid_max_min
, pid_max_max
;
98 extern int sysctl_drop_caches
;
99 extern int percpu_pagelist_fraction
;
100 extern int compat_log
;
101 extern int latencytop_enabled
;
102 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
104 extern int sysctl_nr_trim_pages
;
107 extern int blk_iopoll_enabled
;
110 /* Constants used for minimum and maximum */
111 #ifdef CONFIG_LOCKUP_DETECTOR
112 static int sixty
= 60;
113 static int neg_one
= -1;
117 static int __maybe_unused one
= 1;
118 static int __maybe_unused two
= 2;
119 static unsigned long one_ul
= 1;
120 static int one_hundred
= 100;
122 static int ten_thousand
= 10000;
125 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
126 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
128 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
129 static int maxolduid
= 65535;
130 static int minolduid
;
131 static int min_percpu_pagelist_fract
= 8;
133 static int ngroups_max
= NGROUPS_MAX
;
135 #ifdef CONFIG_INOTIFY_USER
136 #include <linux/inotify.h>
139 #include <asm/system.h>
142 #ifdef CONFIG_SPARC64
143 extern int sysctl_tsb_ratio
;
147 extern int pwrsw_enabled
;
148 extern int unaligned_enabled
;
152 #ifdef CONFIG_MATHEMU
153 extern int sysctl_ieee_emulation_warnings
;
155 extern int sysctl_userprocess_debug
;
156 extern int spin_retry
;
160 extern int no_unaligned_warning
;
161 extern int unaligned_dump_stack
;
164 #ifdef CONFIG_PROC_SYSCTL
165 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
166 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
167 static int proc_taint(struct ctl_table
*table
, int write
,
168 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
171 #ifdef CONFIG_MAGIC_SYSRQ
172 static int __sysrq_enabled
; /* Note: sysrq code ises it's own private copy */
174 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
175 void __user
*buffer
, size_t *lenp
,
180 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
185 sysrq_toggle_support(__sysrq_enabled
);
192 static struct ctl_table root_table
[];
193 static struct ctl_table_root sysctl_table_root
;
194 static struct ctl_table_header root_table_header
= {
196 .ctl_table
= root_table
,
197 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
198 .root
= &sysctl_table_root
,
199 .set
= &sysctl_table_root
.default_set
,
201 static struct ctl_table_root sysctl_table_root
= {
202 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
203 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
206 static struct ctl_table kern_table
[];
207 static struct ctl_table vm_table
[];
208 static struct ctl_table fs_table
[];
209 static struct ctl_table debug_table
[];
210 static struct ctl_table dev_table
[];
211 extern struct ctl_table random_table
[];
213 extern struct ctl_table epoll_table
[];
216 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
217 int sysctl_legacy_va_layout
;
220 /* The default sysctl tables: */
222 static struct ctl_table root_table
[] = {
224 .procname
= "kernel",
241 .child
= debug_table
,
249 * NOTE: do not add new entries to this table unless you have read
250 * Documentation/sysctl/ctl_unnumbered.txt
255 #ifdef CONFIG_SCHED_DEBUG
256 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
257 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
258 static int min_wakeup_granularity_ns
; /* 0 usecs */
259 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
260 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
261 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
262 static int min_sched_shares_ratelimit
= 100000; /* 100 usec */
263 static int max_sched_shares_ratelimit
= NSEC_PER_SEC
; /* 1 second */
266 #ifdef CONFIG_COMPACTION
267 static int min_extfrag_threshold
;
268 static int max_extfrag_threshold
= 1000;
271 static struct ctl_table kern_table
[] = {
273 .procname
= "sched_child_runs_first",
274 .data
= &sysctl_sched_child_runs_first
,
275 .maxlen
= sizeof(unsigned int),
277 .proc_handler
= proc_dointvec
,
279 #ifdef CONFIG_SCHED_DEBUG
281 .procname
= "sched_min_granularity_ns",
282 .data
= &sysctl_sched_min_granularity
,
283 .maxlen
= sizeof(unsigned int),
285 .proc_handler
= sched_proc_update_handler
,
286 .extra1
= &min_sched_granularity_ns
,
287 .extra2
= &max_sched_granularity_ns
,
290 .procname
= "sched_latency_ns",
291 .data
= &sysctl_sched_latency
,
292 .maxlen
= sizeof(unsigned int),
294 .proc_handler
= sched_proc_update_handler
,
295 .extra1
= &min_sched_granularity_ns
,
296 .extra2
= &max_sched_granularity_ns
,
299 .procname
= "sched_wakeup_granularity_ns",
300 .data
= &sysctl_sched_wakeup_granularity
,
301 .maxlen
= sizeof(unsigned int),
303 .proc_handler
= sched_proc_update_handler
,
304 .extra1
= &min_wakeup_granularity_ns
,
305 .extra2
= &max_wakeup_granularity_ns
,
308 .procname
= "sched_shares_ratelimit",
309 .data
= &sysctl_sched_shares_ratelimit
,
310 .maxlen
= sizeof(unsigned int),
312 .proc_handler
= sched_proc_update_handler
,
313 .extra1
= &min_sched_shares_ratelimit
,
314 .extra2
= &max_sched_shares_ratelimit
,
317 .procname
= "sched_tunable_scaling",
318 .data
= &sysctl_sched_tunable_scaling
,
319 .maxlen
= sizeof(enum sched_tunable_scaling
),
321 .proc_handler
= sched_proc_update_handler
,
322 .extra1
= &min_sched_tunable_scaling
,
323 .extra2
= &max_sched_tunable_scaling
,
326 .procname
= "sched_shares_thresh",
327 .data
= &sysctl_sched_shares_thresh
,
328 .maxlen
= sizeof(unsigned int),
330 .proc_handler
= proc_dointvec_minmax
,
334 .procname
= "sched_migration_cost",
335 .data
= &sysctl_sched_migration_cost
,
336 .maxlen
= sizeof(unsigned int),
338 .proc_handler
= proc_dointvec
,
341 .procname
= "sched_nr_migrate",
342 .data
= &sysctl_sched_nr_migrate
,
343 .maxlen
= sizeof(unsigned int),
345 .proc_handler
= proc_dointvec
,
348 .procname
= "sched_time_avg",
349 .data
= &sysctl_sched_time_avg
,
350 .maxlen
= sizeof(unsigned int),
352 .proc_handler
= proc_dointvec
,
355 .procname
= "timer_migration",
356 .data
= &sysctl_timer_migration
,
357 .maxlen
= sizeof(unsigned int),
359 .proc_handler
= proc_dointvec_minmax
,
365 .procname
= "sched_rt_period_us",
366 .data
= &sysctl_sched_rt_period
,
367 .maxlen
= sizeof(unsigned int),
369 .proc_handler
= sched_rt_handler
,
372 .procname
= "sched_rt_runtime_us",
373 .data
= &sysctl_sched_rt_runtime
,
374 .maxlen
= sizeof(int),
376 .proc_handler
= sched_rt_handler
,
379 .procname
= "sched_compat_yield",
380 .data
= &sysctl_sched_compat_yield
,
381 .maxlen
= sizeof(unsigned int),
383 .proc_handler
= proc_dointvec
,
385 #ifdef CONFIG_PROVE_LOCKING
387 .procname
= "prove_locking",
388 .data
= &prove_locking
,
389 .maxlen
= sizeof(int),
391 .proc_handler
= proc_dointvec
,
394 #ifdef CONFIG_LOCK_STAT
396 .procname
= "lock_stat",
398 .maxlen
= sizeof(int),
400 .proc_handler
= proc_dointvec
,
405 .data
= &panic_timeout
,
406 .maxlen
= sizeof(int),
408 .proc_handler
= proc_dointvec
,
411 .procname
= "core_uses_pid",
412 .data
= &core_uses_pid
,
413 .maxlen
= sizeof(int),
415 .proc_handler
= proc_dointvec
,
418 .procname
= "core_pattern",
419 .data
= core_pattern
,
420 .maxlen
= CORENAME_MAX_SIZE
,
422 .proc_handler
= proc_dostring
,
425 .procname
= "core_pipe_limit",
426 .data
= &core_pipe_limit
,
427 .maxlen
= sizeof(unsigned int),
429 .proc_handler
= proc_dointvec
,
431 #ifdef CONFIG_PROC_SYSCTL
433 .procname
= "tainted",
434 .maxlen
= sizeof(long),
436 .proc_handler
= proc_taint
,
439 #ifdef CONFIG_LATENCYTOP
441 .procname
= "latencytop",
442 .data
= &latencytop_enabled
,
443 .maxlen
= sizeof(int),
445 .proc_handler
= proc_dointvec
,
448 #ifdef CONFIG_BLK_DEV_INITRD
450 .procname
= "real-root-dev",
451 .data
= &real_root_dev
,
452 .maxlen
= sizeof(int),
454 .proc_handler
= proc_dointvec
,
458 .procname
= "print-fatal-signals",
459 .data
= &print_fatal_signals
,
460 .maxlen
= sizeof(int),
462 .proc_handler
= proc_dointvec
,
466 .procname
= "reboot-cmd",
467 .data
= reboot_command
,
470 .proc_handler
= proc_dostring
,
473 .procname
= "stop-a",
474 .data
= &stop_a_enabled
,
475 .maxlen
= sizeof (int),
477 .proc_handler
= proc_dointvec
,
480 .procname
= "scons-poweroff",
481 .data
= &scons_pwroff
,
482 .maxlen
= sizeof (int),
484 .proc_handler
= proc_dointvec
,
487 #ifdef CONFIG_SPARC64
489 .procname
= "tsb-ratio",
490 .data
= &sysctl_tsb_ratio
,
491 .maxlen
= sizeof (int),
493 .proc_handler
= proc_dointvec
,
498 .procname
= "soft-power",
499 .data
= &pwrsw_enabled
,
500 .maxlen
= sizeof (int),
502 .proc_handler
= proc_dointvec
,
505 .procname
= "unaligned-trap",
506 .data
= &unaligned_enabled
,
507 .maxlen
= sizeof (int),
509 .proc_handler
= proc_dointvec
,
513 .procname
= "ctrl-alt-del",
515 .maxlen
= sizeof(int),
517 .proc_handler
= proc_dointvec
,
519 #ifdef CONFIG_FUNCTION_TRACER
521 .procname
= "ftrace_enabled",
522 .data
= &ftrace_enabled
,
523 .maxlen
= sizeof(int),
525 .proc_handler
= ftrace_enable_sysctl
,
528 #ifdef CONFIG_STACK_TRACER
530 .procname
= "stack_tracer_enabled",
531 .data
= &stack_tracer_enabled
,
532 .maxlen
= sizeof(int),
534 .proc_handler
= stack_trace_sysctl
,
537 #ifdef CONFIG_TRACING
539 .procname
= "ftrace_dump_on_oops",
540 .data
= &ftrace_dump_on_oops
,
541 .maxlen
= sizeof(int),
543 .proc_handler
= proc_dointvec
,
546 #ifdef CONFIG_MODULES
548 .procname
= "modprobe",
549 .data
= &modprobe_path
,
550 .maxlen
= KMOD_PATH_LEN
,
552 .proc_handler
= proc_dostring
,
555 .procname
= "modules_disabled",
556 .data
= &modules_disabled
,
557 .maxlen
= sizeof(int),
559 /* only handle a transition from default "0" to "1" */
560 .proc_handler
= proc_dointvec_minmax
,
565 #ifdef CONFIG_HOTPLUG
567 .procname
= "hotplug",
568 .data
= &uevent_helper
,
569 .maxlen
= UEVENT_HELPER_PATH_LEN
,
571 .proc_handler
= proc_dostring
,
574 #ifdef CONFIG_CHR_DEV_SG
576 .procname
= "sg-big-buff",
577 .data
= &sg_big_buff
,
578 .maxlen
= sizeof (int),
580 .proc_handler
= proc_dointvec
,
583 #ifdef CONFIG_BSD_PROCESS_ACCT
587 .maxlen
= 3*sizeof(int),
589 .proc_handler
= proc_dointvec
,
592 #ifdef CONFIG_MAGIC_SYSRQ
595 .data
= &__sysrq_enabled
,
596 .maxlen
= sizeof (int),
598 .proc_handler
= sysrq_sysctl_handler
,
601 #ifdef CONFIG_PROC_SYSCTL
603 .procname
= "cad_pid",
605 .maxlen
= sizeof (int),
607 .proc_handler
= proc_do_cad_pid
,
611 .procname
= "threads-max",
612 .data
= &max_threads
,
613 .maxlen
= sizeof(int),
615 .proc_handler
= proc_dointvec
,
618 .procname
= "random",
620 .child
= random_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
,
707 .procname
= "dmesg_restrict",
708 .data
= &dmesg_restrict
,
709 .maxlen
= sizeof(int),
711 .proc_handler
= proc_dointvec_minmax
,
716 .procname
= "ngroups_max",
717 .data
= &ngroups_max
,
718 .maxlen
= sizeof (int),
720 .proc_handler
= proc_dointvec
,
722 #if defined(CONFIG_LOCKUP_DETECTOR)
724 .procname
= "watchdog",
725 .data
= &watchdog_enabled
,
726 .maxlen
= sizeof (int),
728 .proc_handler
= proc_dowatchdog_enabled
,
731 .procname
= "watchdog_thresh",
732 .data
= &softlockup_thresh
,
733 .maxlen
= sizeof(int),
735 .proc_handler
= proc_dowatchdog_thresh
,
740 .procname
= "softlockup_panic",
741 .data
= &softlockup_panic
,
742 .maxlen
= sizeof(int),
744 .proc_handler
= proc_dointvec_minmax
,
749 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
751 .procname
= "unknown_nmi_panic",
752 .data
= &unknown_nmi_panic
,
753 .maxlen
= sizeof (int),
755 .proc_handler
= proc_dointvec
,
758 .procname
= "nmi_watchdog",
759 .data
= &nmi_watchdog_enabled
,
760 .maxlen
= sizeof (int),
762 .proc_handler
= proc_nmi_enabled
,
765 #if defined(CONFIG_X86)
767 .procname
= "panic_on_unrecovered_nmi",
768 .data
= &panic_on_unrecovered_nmi
,
769 .maxlen
= sizeof(int),
771 .proc_handler
= proc_dointvec
,
774 .procname
= "panic_on_io_nmi",
775 .data
= &panic_on_io_nmi
,
776 .maxlen
= sizeof(int),
778 .proc_handler
= proc_dointvec
,
781 .procname
= "bootloader_type",
782 .data
= &bootloader_type
,
783 .maxlen
= sizeof (int),
785 .proc_handler
= proc_dointvec
,
788 .procname
= "bootloader_version",
789 .data
= &bootloader_version
,
790 .maxlen
= sizeof (int),
792 .proc_handler
= proc_dointvec
,
795 .procname
= "kstack_depth_to_print",
796 .data
= &kstack_depth_to_print
,
797 .maxlen
= sizeof(int),
799 .proc_handler
= proc_dointvec
,
802 .procname
= "io_delay_type",
803 .data
= &io_delay_type
,
804 .maxlen
= sizeof(int),
806 .proc_handler
= proc_dointvec
,
809 #if defined(CONFIG_MMU)
811 .procname
= "randomize_va_space",
812 .data
= &randomize_va_space
,
813 .maxlen
= sizeof(int),
815 .proc_handler
= proc_dointvec
,
818 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
820 .procname
= "spin_retry",
822 .maxlen
= sizeof (int),
824 .proc_handler
= proc_dointvec
,
827 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
829 .procname
= "acpi_video_flags",
830 .data
= &acpi_realmode_flags
,
831 .maxlen
= sizeof (unsigned long),
833 .proc_handler
= proc_doulongvec_minmax
,
838 .procname
= "ignore-unaligned-usertrap",
839 .data
= &no_unaligned_warning
,
840 .maxlen
= sizeof (int),
842 .proc_handler
= proc_dointvec
,
845 .procname
= "unaligned-dump-stack",
846 .data
= &unaligned_dump_stack
,
847 .maxlen
= sizeof (int),
849 .proc_handler
= proc_dointvec
,
852 #ifdef CONFIG_DETECT_HUNG_TASK
854 .procname
= "hung_task_panic",
855 .data
= &sysctl_hung_task_panic
,
856 .maxlen
= sizeof(int),
858 .proc_handler
= proc_dointvec_minmax
,
863 .procname
= "hung_task_check_count",
864 .data
= &sysctl_hung_task_check_count
,
865 .maxlen
= sizeof(unsigned long),
867 .proc_handler
= proc_doulongvec_minmax
,
870 .procname
= "hung_task_timeout_secs",
871 .data
= &sysctl_hung_task_timeout_secs
,
872 .maxlen
= sizeof(unsigned long),
874 .proc_handler
= proc_dohung_task_timeout_secs
,
877 .procname
= "hung_task_warnings",
878 .data
= &sysctl_hung_task_warnings
,
879 .maxlen
= sizeof(unsigned long),
881 .proc_handler
= proc_doulongvec_minmax
,
886 .procname
= "compat-log",
888 .maxlen
= sizeof (int),
890 .proc_handler
= proc_dointvec
,
893 #ifdef CONFIG_RT_MUTEXES
895 .procname
= "max_lock_depth",
896 .data
= &max_lock_depth
,
897 .maxlen
= sizeof(int),
899 .proc_handler
= proc_dointvec
,
903 .procname
= "poweroff_cmd",
904 .data
= &poweroff_cmd
,
905 .maxlen
= POWEROFF_CMD_PATH_LEN
,
907 .proc_handler
= proc_dostring
,
913 .child
= key_sysctls
,
916 #ifdef CONFIG_RCU_TORTURE_TEST
918 .procname
= "rcutorture_runnable",
919 .data
= &rcutorture_runnable
,
920 .maxlen
= sizeof(int),
922 .proc_handler
= proc_dointvec
,
925 #ifdef CONFIG_PERF_EVENTS
927 .procname
= "perf_event_paranoid",
928 .data
= &sysctl_perf_event_paranoid
,
929 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
931 .proc_handler
= proc_dointvec
,
934 .procname
= "perf_event_mlock_kb",
935 .data
= &sysctl_perf_event_mlock
,
936 .maxlen
= sizeof(sysctl_perf_event_mlock
),
938 .proc_handler
= proc_dointvec
,
941 .procname
= "perf_event_max_sample_rate",
942 .data
= &sysctl_perf_event_sample_rate
,
943 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
945 .proc_handler
= proc_dointvec
,
948 #ifdef CONFIG_KMEMCHECK
950 .procname
= "kmemcheck",
951 .data
= &kmemcheck_enabled
,
952 .maxlen
= sizeof(int),
954 .proc_handler
= proc_dointvec
,
959 .procname
= "blk_iopoll",
960 .data
= &blk_iopoll_enabled
,
961 .maxlen
= sizeof(int),
963 .proc_handler
= proc_dointvec
,
967 * NOTE: do not add new entries to this table unless you have read
968 * Documentation/sysctl/ctl_unnumbered.txt
973 static struct ctl_table vm_table
[] = {
975 .procname
= "overcommit_memory",
976 .data
= &sysctl_overcommit_memory
,
977 .maxlen
= sizeof(sysctl_overcommit_memory
),
979 .proc_handler
= proc_dointvec
,
982 .procname
= "panic_on_oom",
983 .data
= &sysctl_panic_on_oom
,
984 .maxlen
= sizeof(sysctl_panic_on_oom
),
986 .proc_handler
= proc_dointvec
,
989 .procname
= "oom_kill_allocating_task",
990 .data
= &sysctl_oom_kill_allocating_task
,
991 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
993 .proc_handler
= proc_dointvec
,
996 .procname
= "oom_dump_tasks",
997 .data
= &sysctl_oom_dump_tasks
,
998 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1000 .proc_handler
= proc_dointvec
,
1003 .procname
= "overcommit_ratio",
1004 .data
= &sysctl_overcommit_ratio
,
1005 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1007 .proc_handler
= proc_dointvec
,
1010 .procname
= "page-cluster",
1011 .data
= &page_cluster
,
1012 .maxlen
= sizeof(int),
1014 .proc_handler
= proc_dointvec
,
1017 .procname
= "dirty_background_ratio",
1018 .data
= &dirty_background_ratio
,
1019 .maxlen
= sizeof(dirty_background_ratio
),
1021 .proc_handler
= dirty_background_ratio_handler
,
1023 .extra2
= &one_hundred
,
1026 .procname
= "dirty_background_bytes",
1027 .data
= &dirty_background_bytes
,
1028 .maxlen
= sizeof(dirty_background_bytes
),
1030 .proc_handler
= dirty_background_bytes_handler
,
1034 .procname
= "dirty_ratio",
1035 .data
= &vm_dirty_ratio
,
1036 .maxlen
= sizeof(vm_dirty_ratio
),
1038 .proc_handler
= dirty_ratio_handler
,
1040 .extra2
= &one_hundred
,
1043 .procname
= "dirty_bytes",
1044 .data
= &vm_dirty_bytes
,
1045 .maxlen
= sizeof(vm_dirty_bytes
),
1047 .proc_handler
= dirty_bytes_handler
,
1048 .extra1
= &dirty_bytes_min
,
1051 .procname
= "dirty_writeback_centisecs",
1052 .data
= &dirty_writeback_interval
,
1053 .maxlen
= sizeof(dirty_writeback_interval
),
1055 .proc_handler
= dirty_writeback_centisecs_handler
,
1058 .procname
= "dirty_expire_centisecs",
1059 .data
= &dirty_expire_interval
,
1060 .maxlen
= sizeof(dirty_expire_interval
),
1062 .proc_handler
= proc_dointvec
,
1065 .procname
= "nr_pdflush_threads",
1066 .data
= &nr_pdflush_threads
,
1067 .maxlen
= sizeof nr_pdflush_threads
,
1068 .mode
= 0444 /* read-only*/,
1069 .proc_handler
= proc_dointvec
,
1072 .procname
= "swappiness",
1073 .data
= &vm_swappiness
,
1074 .maxlen
= sizeof(vm_swappiness
),
1076 .proc_handler
= proc_dointvec_minmax
,
1078 .extra2
= &one_hundred
,
1080 #ifdef CONFIG_HUGETLB_PAGE
1082 .procname
= "nr_hugepages",
1084 .maxlen
= sizeof(unsigned long),
1086 .proc_handler
= hugetlb_sysctl_handler
,
1087 .extra1
= (void *)&hugetlb_zero
,
1088 .extra2
= (void *)&hugetlb_infinity
,
1092 .procname
= "nr_hugepages_mempolicy",
1094 .maxlen
= sizeof(unsigned long),
1096 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1097 .extra1
= (void *)&hugetlb_zero
,
1098 .extra2
= (void *)&hugetlb_infinity
,
1102 .procname
= "hugetlb_shm_group",
1103 .data
= &sysctl_hugetlb_shm_group
,
1104 .maxlen
= sizeof(gid_t
),
1106 .proc_handler
= proc_dointvec
,
1109 .procname
= "hugepages_treat_as_movable",
1110 .data
= &hugepages_treat_as_movable
,
1111 .maxlen
= sizeof(int),
1113 .proc_handler
= hugetlb_treat_movable_handler
,
1116 .procname
= "nr_overcommit_hugepages",
1118 .maxlen
= sizeof(unsigned long),
1120 .proc_handler
= hugetlb_overcommit_handler
,
1121 .extra1
= (void *)&hugetlb_zero
,
1122 .extra2
= (void *)&hugetlb_infinity
,
1126 .procname
= "lowmem_reserve_ratio",
1127 .data
= &sysctl_lowmem_reserve_ratio
,
1128 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1130 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1133 .procname
= "drop_caches",
1134 .data
= &sysctl_drop_caches
,
1135 .maxlen
= sizeof(int),
1137 .proc_handler
= drop_caches_sysctl_handler
,
1139 #ifdef CONFIG_COMPACTION
1141 .procname
= "compact_memory",
1142 .data
= &sysctl_compact_memory
,
1143 .maxlen
= sizeof(int),
1145 .proc_handler
= sysctl_compaction_handler
,
1148 .procname
= "extfrag_threshold",
1149 .data
= &sysctl_extfrag_threshold
,
1150 .maxlen
= sizeof(int),
1152 .proc_handler
= sysctl_extfrag_handler
,
1153 .extra1
= &min_extfrag_threshold
,
1154 .extra2
= &max_extfrag_threshold
,
1157 #endif /* CONFIG_COMPACTION */
1159 .procname
= "min_free_kbytes",
1160 .data
= &min_free_kbytes
,
1161 .maxlen
= sizeof(min_free_kbytes
),
1163 .proc_handler
= min_free_kbytes_sysctl_handler
,
1167 .procname
= "percpu_pagelist_fraction",
1168 .data
= &percpu_pagelist_fraction
,
1169 .maxlen
= sizeof(percpu_pagelist_fraction
),
1171 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1172 .extra1
= &min_percpu_pagelist_fract
,
1176 .procname
= "max_map_count",
1177 .data
= &sysctl_max_map_count
,
1178 .maxlen
= sizeof(sysctl_max_map_count
),
1180 .proc_handler
= proc_dointvec_minmax
,
1185 .procname
= "nr_trim_pages",
1186 .data
= &sysctl_nr_trim_pages
,
1187 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1189 .proc_handler
= proc_dointvec_minmax
,
1194 .procname
= "laptop_mode",
1195 .data
= &laptop_mode
,
1196 .maxlen
= sizeof(laptop_mode
),
1198 .proc_handler
= proc_dointvec_jiffies
,
1201 .procname
= "block_dump",
1202 .data
= &block_dump
,
1203 .maxlen
= sizeof(block_dump
),
1205 .proc_handler
= proc_dointvec
,
1209 .procname
= "vfs_cache_pressure",
1210 .data
= &sysctl_vfs_cache_pressure
,
1211 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1213 .proc_handler
= proc_dointvec
,
1216 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1218 .procname
= "legacy_va_layout",
1219 .data
= &sysctl_legacy_va_layout
,
1220 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1222 .proc_handler
= proc_dointvec
,
1228 .procname
= "zone_reclaim_mode",
1229 .data
= &zone_reclaim_mode
,
1230 .maxlen
= sizeof(zone_reclaim_mode
),
1232 .proc_handler
= proc_dointvec
,
1236 .procname
= "min_unmapped_ratio",
1237 .data
= &sysctl_min_unmapped_ratio
,
1238 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1240 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1242 .extra2
= &one_hundred
,
1245 .procname
= "min_slab_ratio",
1246 .data
= &sysctl_min_slab_ratio
,
1247 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1249 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1251 .extra2
= &one_hundred
,
1256 .procname
= "stat_interval",
1257 .data
= &sysctl_stat_interval
,
1258 .maxlen
= sizeof(sysctl_stat_interval
),
1260 .proc_handler
= proc_dointvec_jiffies
,
1265 .procname
= "mmap_min_addr",
1266 .data
= &dac_mmap_min_addr
,
1267 .maxlen
= sizeof(unsigned long),
1269 .proc_handler
= mmap_min_addr_handler
,
1274 .procname
= "numa_zonelist_order",
1275 .data
= &numa_zonelist_order
,
1276 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1278 .proc_handler
= numa_zonelist_order_handler
,
1281 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1282 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1284 .procname
= "vdso_enabled",
1285 .data
= &vdso_enabled
,
1286 .maxlen
= sizeof(vdso_enabled
),
1288 .proc_handler
= proc_dointvec
,
1292 #ifdef CONFIG_HIGHMEM
1294 .procname
= "highmem_is_dirtyable",
1295 .data
= &vm_highmem_is_dirtyable
,
1296 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1298 .proc_handler
= proc_dointvec_minmax
,
1304 .procname
= "scan_unevictable_pages",
1305 .data
= &scan_unevictable_pages
,
1306 .maxlen
= sizeof(scan_unevictable_pages
),
1308 .proc_handler
= scan_unevictable_handler
,
1310 #ifdef CONFIG_MEMORY_FAILURE
1312 .procname
= "memory_failure_early_kill",
1313 .data
= &sysctl_memory_failure_early_kill
,
1314 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1316 .proc_handler
= proc_dointvec_minmax
,
1321 .procname
= "memory_failure_recovery",
1322 .data
= &sysctl_memory_failure_recovery
,
1323 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1325 .proc_handler
= proc_dointvec_minmax
,
1332 * NOTE: do not add new entries to this table unless you have read
1333 * Documentation/sysctl/ctl_unnumbered.txt
1338 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1339 static struct ctl_table binfmt_misc_table
[] = {
1344 static struct ctl_table fs_table
[] = {
1346 .procname
= "inode-nr",
1347 .data
= &inodes_stat
,
1348 .maxlen
= 2*sizeof(int),
1350 .proc_handler
= proc_nr_inodes
,
1353 .procname
= "inode-state",
1354 .data
= &inodes_stat
,
1355 .maxlen
= 7*sizeof(int),
1357 .proc_handler
= proc_nr_inodes
,
1360 .procname
= "file-nr",
1361 .data
= &files_stat
,
1362 .maxlen
= sizeof(files_stat
),
1364 .proc_handler
= proc_nr_files
,
1367 .procname
= "file-max",
1368 .data
= &files_stat
.max_files
,
1369 .maxlen
= sizeof(files_stat
.max_files
),
1371 .proc_handler
= proc_doulongvec_minmax
,
1374 .procname
= "nr_open",
1375 .data
= &sysctl_nr_open
,
1376 .maxlen
= sizeof(int),
1378 .proc_handler
= proc_dointvec_minmax
,
1379 .extra1
= &sysctl_nr_open_min
,
1380 .extra2
= &sysctl_nr_open_max
,
1383 .procname
= "dentry-state",
1384 .data
= &dentry_stat
,
1385 .maxlen
= 6*sizeof(int),
1387 .proc_handler
= proc_nr_dentry
,
1390 .procname
= "overflowuid",
1391 .data
= &fs_overflowuid
,
1392 .maxlen
= sizeof(int),
1394 .proc_handler
= proc_dointvec_minmax
,
1395 .extra1
= &minolduid
,
1396 .extra2
= &maxolduid
,
1399 .procname
= "overflowgid",
1400 .data
= &fs_overflowgid
,
1401 .maxlen
= sizeof(int),
1403 .proc_handler
= proc_dointvec_minmax
,
1404 .extra1
= &minolduid
,
1405 .extra2
= &maxolduid
,
1407 #ifdef CONFIG_FILE_LOCKING
1409 .procname
= "leases-enable",
1410 .data
= &leases_enable
,
1411 .maxlen
= sizeof(int),
1413 .proc_handler
= proc_dointvec
,
1416 #ifdef CONFIG_DNOTIFY
1418 .procname
= "dir-notify-enable",
1419 .data
= &dir_notify_enable
,
1420 .maxlen
= sizeof(int),
1422 .proc_handler
= proc_dointvec
,
1426 #ifdef CONFIG_FILE_LOCKING
1428 .procname
= "lease-break-time",
1429 .data
= &lease_break_time
,
1430 .maxlen
= sizeof(int),
1432 .proc_handler
= proc_dointvec
,
1437 .procname
= "aio-nr",
1439 .maxlen
= sizeof(aio_nr
),
1441 .proc_handler
= proc_doulongvec_minmax
,
1444 .procname
= "aio-max-nr",
1445 .data
= &aio_max_nr
,
1446 .maxlen
= sizeof(aio_max_nr
),
1448 .proc_handler
= proc_doulongvec_minmax
,
1450 #endif /* CONFIG_AIO */
1451 #ifdef CONFIG_INOTIFY_USER
1453 .procname
= "inotify",
1455 .child
= inotify_table
,
1460 .procname
= "epoll",
1462 .child
= epoll_table
,
1467 .procname
= "suid_dumpable",
1468 .data
= &suid_dumpable
,
1469 .maxlen
= sizeof(int),
1471 .proc_handler
= proc_dointvec_minmax
,
1475 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1477 .procname
= "binfmt_misc",
1479 .child
= binfmt_misc_table
,
1483 .procname
= "pipe-max-size",
1484 .data
= &pipe_max_size
,
1485 .maxlen
= sizeof(int),
1487 .proc_handler
= &pipe_proc_fn
,
1488 .extra1
= &pipe_min_size
,
1491 * NOTE: do not add new entries to this table unless you have read
1492 * Documentation/sysctl/ctl_unnumbered.txt
1497 static struct ctl_table debug_table
[] = {
1498 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1499 defined(CONFIG_S390)
1501 .procname
= "exception-trace",
1502 .data
= &show_unhandled_signals
,
1503 .maxlen
= sizeof(int),
1505 .proc_handler
= proc_dointvec
1508 #if defined(CONFIG_OPTPROBES)
1510 .procname
= "kprobes-optimization",
1511 .data
= &sysctl_kprobes_optimization
,
1512 .maxlen
= sizeof(int),
1514 .proc_handler
= proc_kprobes_optimization_handler
,
1522 static struct ctl_table dev_table
[] = {
1526 static DEFINE_SPINLOCK(sysctl_lock
);
1528 /* called under sysctl_lock */
1529 static int use_table(struct ctl_table_header
*p
)
1531 if (unlikely(p
->unregistering
))
1537 /* called under sysctl_lock */
1538 static void unuse_table(struct ctl_table_header
*p
)
1541 if (unlikely(p
->unregistering
))
1542 complete(p
->unregistering
);
1545 /* called under sysctl_lock, will reacquire if has to wait */
1546 static void start_unregistering(struct ctl_table_header
*p
)
1549 * if p->used is 0, nobody will ever touch that entry again;
1550 * we'll eliminate all paths to it before dropping sysctl_lock
1552 if (unlikely(p
->used
)) {
1553 struct completion wait
;
1554 init_completion(&wait
);
1555 p
->unregistering
= &wait
;
1556 spin_unlock(&sysctl_lock
);
1557 wait_for_completion(&wait
);
1558 spin_lock(&sysctl_lock
);
1560 /* anything non-NULL; we'll never dereference it */
1561 p
->unregistering
= ERR_PTR(-EINVAL
);
1564 * do not remove from the list until nobody holds it; walking the
1565 * list in do_sysctl() relies on that.
1567 list_del_init(&p
->ctl_entry
);
1570 void sysctl_head_get(struct ctl_table_header
*head
)
1572 spin_lock(&sysctl_lock
);
1574 spin_unlock(&sysctl_lock
);
1577 void sysctl_head_put(struct ctl_table_header
*head
)
1579 spin_lock(&sysctl_lock
);
1582 spin_unlock(&sysctl_lock
);
1585 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1589 spin_lock(&sysctl_lock
);
1590 if (!use_table(head
))
1591 head
= ERR_PTR(-ENOENT
);
1592 spin_unlock(&sysctl_lock
);
1596 void sysctl_head_finish(struct ctl_table_header
*head
)
1600 spin_lock(&sysctl_lock
);
1602 spin_unlock(&sysctl_lock
);
1605 static struct ctl_table_set
*
1606 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1608 struct ctl_table_set
*set
= &root
->default_set
;
1610 set
= root
->lookup(root
, namespaces
);
1614 static struct list_head
*
1615 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1617 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1621 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1622 struct ctl_table_header
*prev
)
1624 struct ctl_table_root
*root
;
1625 struct list_head
*header_list
;
1626 struct ctl_table_header
*head
;
1627 struct list_head
*tmp
;
1629 spin_lock(&sysctl_lock
);
1632 tmp
= &prev
->ctl_entry
;
1636 tmp
= &root_table_header
.ctl_entry
;
1638 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1640 if (!use_table(head
))
1642 spin_unlock(&sysctl_lock
);
1647 header_list
= lookup_header_list(root
, namespaces
);
1648 if (tmp
!= header_list
)
1652 root
= list_entry(root
->root_list
.next
,
1653 struct ctl_table_root
, root_list
);
1654 if (root
== &sysctl_table_root
)
1656 header_list
= lookup_header_list(root
, namespaces
);
1657 } while (list_empty(header_list
));
1658 tmp
= header_list
->next
;
1661 spin_unlock(&sysctl_lock
);
1665 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1667 return __sysctl_head_next(current
->nsproxy
, prev
);
1670 void register_sysctl_root(struct ctl_table_root
*root
)
1672 spin_lock(&sysctl_lock
);
1673 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1674 spin_unlock(&sysctl_lock
);
1678 * sysctl_perm does NOT grant the superuser all rights automatically, because
1679 * some sysctl variables are readonly even to root.
1682 static int test_perm(int mode
, int op
)
1684 if (!current_euid())
1686 else if (in_egroup_p(0))
1688 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1693 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1698 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1702 if (root
->permissions
)
1703 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1707 return test_perm(mode
, op
);
1710 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1712 for (; table
->procname
; table
++) {
1713 table
->parent
= parent
;
1715 sysctl_set_parent(table
, table
->child
);
1719 static __init
int sysctl_init(void)
1721 sysctl_set_parent(NULL
, root_table
);
1722 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1723 sysctl_check_table(current
->nsproxy
, root_table
);
1728 core_initcall(sysctl_init
);
1730 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1731 struct ctl_table
*table
)
1733 struct ctl_table
*p
;
1734 const char *s
= branch
->procname
;
1736 /* branch should have named subdirectory as its first element */
1737 if (!s
|| !branch
->child
)
1740 /* ... and nothing else */
1741 if (branch
[1].procname
)
1744 /* table should contain subdirectory with the same name */
1745 for (p
= table
; p
->procname
; p
++) {
1748 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1754 /* see if attaching q to p would be an improvement */
1755 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1757 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1758 struct ctl_table
*next
;
1760 int not_in_parent
= !p
->attached_by
;
1762 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1763 if (by
== q
->attached_by
)
1765 if (to
== p
->attached_by
)
1771 if (is_better
&& not_in_parent
) {
1772 q
->attached_by
= by
;
1773 q
->attached_to
= to
;
1779 * __register_sysctl_paths - register a sysctl hierarchy
1780 * @root: List of sysctl headers to register on
1781 * @namespaces: Data to compute which lists of sysctl entries are visible
1782 * @path: The path to the directory the sysctl table is in.
1783 * @table: the top-level table structure
1785 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1786 * array. A completely 0 filled entry terminates the table.
1788 * The members of the &struct ctl_table structure are used as follows:
1790 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1791 * enter a sysctl file
1793 * data - a pointer to data for use by proc_handler
1795 * maxlen - the maximum size in bytes of the data
1797 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1799 * child - a pointer to the child sysctl table if this entry is a directory, or
1802 * proc_handler - the text handler routine (described below)
1804 * de - for internal use by the sysctl routines
1806 * extra1, extra2 - extra pointers usable by the proc handler routines
1808 * Leaf nodes in the sysctl tree will be represented by a single file
1809 * under /proc; non-leaf nodes will be represented by directories.
1811 * sysctl(2) can automatically manage read and write requests through
1812 * the sysctl table. The data and maxlen fields of the ctl_table
1813 * struct enable minimal validation of the values being written to be
1814 * performed, and the mode field allows minimal authentication.
1816 * There must be a proc_handler routine for any terminal nodes
1817 * mirrored under /proc/sys (non-terminals are handled by a built-in
1818 * directory handler). Several default handlers are available to
1819 * cover common cases -
1821 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1822 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1823 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1825 * It is the handler's job to read the input buffer from user memory
1826 * and process it. The handler should return 0 on success.
1828 * This routine returns %NULL on a failure to register, and a pointer
1829 * to the table header on success.
1831 struct ctl_table_header
*__register_sysctl_paths(
1832 struct ctl_table_root
*root
,
1833 struct nsproxy
*namespaces
,
1834 const struct ctl_path
*path
, struct ctl_table
*table
)
1836 struct ctl_table_header
*header
;
1837 struct ctl_table
*new, **prevp
;
1838 unsigned int n
, npath
;
1839 struct ctl_table_set
*set
;
1841 /* Count the path components */
1842 for (npath
= 0; path
[npath
].procname
; ++npath
)
1846 * For each path component, allocate a 2-element ctl_table array.
1847 * The first array element will be filled with the sysctl entry
1848 * for this, the second will be the sentinel (procname == 0).
1850 * We allocate everything in one go so that we don't have to
1851 * worry about freeing additional memory in unregister_sysctl_table.
1853 header
= kzalloc(sizeof(struct ctl_table_header
) +
1854 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1858 new = (struct ctl_table
*) (header
+ 1);
1860 /* Now connect the dots */
1861 prevp
= &header
->ctl_table
;
1862 for (n
= 0; n
< npath
; ++n
, ++path
) {
1863 /* Copy the procname */
1864 new->procname
= path
->procname
;
1868 prevp
= &new->child
;
1873 header
->ctl_table_arg
= table
;
1875 INIT_LIST_HEAD(&header
->ctl_entry
);
1877 header
->unregistering
= NULL
;
1878 header
->root
= root
;
1879 sysctl_set_parent(NULL
, header
->ctl_table
);
1881 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1882 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1887 spin_lock(&sysctl_lock
);
1888 header
->set
= lookup_header_set(root
, namespaces
);
1889 header
->attached_by
= header
->ctl_table
;
1890 header
->attached_to
= root_table
;
1891 header
->parent
= &root_table_header
;
1892 for (set
= header
->set
; set
; set
= set
->parent
) {
1893 struct ctl_table_header
*p
;
1894 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1895 if (p
->unregistering
)
1897 try_attach(p
, header
);
1900 header
->parent
->count
++;
1901 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1902 spin_unlock(&sysctl_lock
);
1908 * register_sysctl_table_path - register a sysctl table hierarchy
1909 * @path: The path to the directory the sysctl table is in.
1910 * @table: the top-level table structure
1912 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1913 * array. A completely 0 filled entry terminates the table.
1915 * See __register_sysctl_paths for more details.
1917 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1918 struct ctl_table
*table
)
1920 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1925 * register_sysctl_table - register a sysctl table hierarchy
1926 * @table: the top-level table structure
1928 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1929 * array. A completely 0 filled entry terminates the table.
1931 * See register_sysctl_paths for more details.
1933 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1935 static const struct ctl_path null_path
[] = { {} };
1937 return register_sysctl_paths(null_path
, table
);
1941 * unregister_sysctl_table - unregister a sysctl table hierarchy
1942 * @header: the header returned from register_sysctl_table
1944 * Unregisters the sysctl table and all children. proc entries may not
1945 * actually be removed until they are no longer used by anyone.
1947 void unregister_sysctl_table(struct ctl_table_header
* header
)
1954 spin_lock(&sysctl_lock
);
1955 start_unregistering(header
);
1956 if (!--header
->parent
->count
) {
1958 kfree(header
->parent
);
1960 if (!--header
->count
)
1962 spin_unlock(&sysctl_lock
);
1965 int sysctl_is_seen(struct ctl_table_header
*p
)
1967 struct ctl_table_set
*set
= p
->set
;
1969 spin_lock(&sysctl_lock
);
1970 if (p
->unregistering
)
1972 else if (!set
->is_seen
)
1975 res
= set
->is_seen(set
);
1976 spin_unlock(&sysctl_lock
);
1980 void setup_sysctl_set(struct ctl_table_set
*p
,
1981 struct ctl_table_set
*parent
,
1982 int (*is_seen
)(struct ctl_table_set
*))
1984 INIT_LIST_HEAD(&p
->list
);
1985 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1986 p
->is_seen
= is_seen
;
1989 #else /* !CONFIG_SYSCTL */
1990 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1995 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1996 struct ctl_table
*table
)
2001 void unregister_sysctl_table(struct ctl_table_header
* table
)
2005 void setup_sysctl_set(struct ctl_table_set
*p
,
2006 struct ctl_table_set
*parent
,
2007 int (*is_seen
)(struct ctl_table_set
*))
2011 void sysctl_head_put(struct ctl_table_header
*head
)
2015 #endif /* CONFIG_SYSCTL */
2021 #ifdef CONFIG_PROC_SYSCTL
2023 static int _proc_do_string(void* data
, int maxlen
, int write
,
2024 void __user
*buffer
,
2025 size_t *lenp
, loff_t
*ppos
)
2031 if (!data
|| !maxlen
|| !*lenp
) {
2039 while (len
< *lenp
) {
2040 if (get_user(c
, p
++))
2042 if (c
== 0 || c
== '\n')
2048 if(copy_from_user(data
, buffer
, len
))
2050 ((char *) data
)[len
] = 0;
2068 if(copy_to_user(buffer
, data
, len
))
2071 if(put_user('\n', ((char __user
*) buffer
) + len
))
2082 * proc_dostring - read a string sysctl
2083 * @table: the sysctl table
2084 * @write: %TRUE if this is a write to the sysctl file
2085 * @buffer: the user buffer
2086 * @lenp: the size of the user buffer
2087 * @ppos: file position
2089 * Reads/writes a string from/to the user buffer. If the kernel
2090 * buffer provided is not large enough to hold the string, the
2091 * string is truncated. The copied string is %NULL-terminated.
2092 * If the string is being read by the user process, it is copied
2093 * and a newline '\n' is added. It is truncated if the buffer is
2096 * Returns 0 on success.
2098 int proc_dostring(struct ctl_table
*table
, int write
,
2099 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2101 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2102 buffer
, lenp
, ppos
);
2105 static size_t proc_skip_spaces(char **buf
)
2108 char *tmp
= skip_spaces(*buf
);
2114 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2124 #define TMPBUFLEN 22
2126 * proc_get_long - reads an ASCII formatted integer from a user buffer
2128 * @buf: a kernel buffer
2129 * @size: size of the kernel buffer
2130 * @val: this is where the number will be stored
2131 * @neg: set to %TRUE if number is negative
2132 * @perm_tr: a vector which contains the allowed trailers
2133 * @perm_tr_len: size of the perm_tr vector
2134 * @tr: pointer to store the trailer character
2136 * In case of success %0 is returned and @buf and @size are updated with
2137 * the amount of bytes read. If @tr is non-NULL and a trailing
2138 * character exists (size is non-zero after returning from this
2139 * function), @tr is updated with the trailing character.
2141 static int proc_get_long(char **buf
, size_t *size
,
2142 unsigned long *val
, bool *neg
,
2143 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2146 char *p
, tmp
[TMPBUFLEN
];
2152 if (len
> TMPBUFLEN
- 1)
2153 len
= TMPBUFLEN
- 1;
2155 memcpy(tmp
, *buf
, len
);
2159 if (*p
== '-' && *size
> 1) {
2167 *val
= simple_strtoul(p
, &p
, 0);
2171 /* We don't know if the next char is whitespace thus we may accept
2172 * invalid integers (e.g. 1234...a) or two integers instead of one
2173 * (e.g. 123...1). So lets not allow such large numbers. */
2174 if (len
== TMPBUFLEN
- 1)
2177 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2180 if (tr
&& (len
< *size
))
2190 * proc_put_long - converts an integer to a decimal ASCII formatted string
2192 * @buf: the user buffer
2193 * @size: the size of the user buffer
2194 * @val: the integer to be converted
2195 * @neg: sign of the number, %TRUE for negative
2197 * In case of success %0 is returned and @buf and @size are updated with
2198 * the amount of bytes written.
2200 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2204 char tmp
[TMPBUFLEN
], *p
= tmp
;
2206 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2210 if (copy_to_user(*buf
, tmp
, len
))
2218 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2221 char __user
**buffer
= (char __user
**)buf
;
2222 if (put_user(c
, *buffer
))
2224 (*size
)--, (*buffer
)++;
2230 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2232 int write
, void *data
)
2235 *valp
= *negp
? -*lvalp
: *lvalp
;
2240 *lvalp
= (unsigned long)-val
;
2243 *lvalp
= (unsigned long)val
;
2249 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2251 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2252 int write
, void __user
*buffer
,
2253 size_t *lenp
, loff_t
*ppos
,
2254 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2255 int write
, void *data
),
2258 int *i
, vleft
, first
= 1, err
= 0;
2259 unsigned long page
= 0;
2263 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2268 i
= (int *) tbl_data
;
2269 vleft
= table
->maxlen
/ sizeof(*i
);
2273 conv
= do_proc_dointvec_conv
;
2276 if (left
> PAGE_SIZE
- 1)
2277 left
= PAGE_SIZE
- 1;
2278 page
= __get_free_page(GFP_TEMPORARY
);
2279 kbuf
= (char *) page
;
2282 if (copy_from_user(kbuf
, buffer
, left
)) {
2289 for (; left
&& vleft
--; i
++, first
=0) {
2294 left
-= proc_skip_spaces(&kbuf
);
2298 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2300 sizeof(proc_wspace_sep
), NULL
);
2303 if (conv(&neg
, &lval
, i
, 1, data
)) {
2308 if (conv(&neg
, &lval
, i
, 0, data
)) {
2313 err
= proc_put_char(&buffer
, &left
, '\t');
2316 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2322 if (!write
&& !first
&& left
&& !err
)
2323 err
= proc_put_char(&buffer
, &left
, '\n');
2324 if (write
&& !err
&& left
)
2325 left
-= proc_skip_spaces(&kbuf
);
2330 return err
? : -EINVAL
;
2337 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2338 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2339 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2340 int write
, void *data
),
2343 return __do_proc_dointvec(table
->data
, table
, write
,
2344 buffer
, lenp
, ppos
, conv
, data
);
2348 * proc_dointvec - read a vector of integers
2349 * @table: the sysctl table
2350 * @write: %TRUE if this is a write to the sysctl file
2351 * @buffer: the user buffer
2352 * @lenp: the size of the user buffer
2353 * @ppos: file position
2355 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2356 * values from/to the user buffer, treated as an ASCII string.
2358 * Returns 0 on success.
2360 int proc_dointvec(struct ctl_table
*table
, int write
,
2361 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2363 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2368 * Taint values can only be increased
2369 * This means we can safely use a temporary.
2371 static int proc_taint(struct ctl_table
*table
, int write
,
2372 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2375 unsigned long tmptaint
= get_taint();
2378 if (write
&& !capable(CAP_SYS_ADMIN
))
2383 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2389 * Poor man's atomic or. Not worth adding a primitive
2390 * to everyone's atomic.h for this
2393 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2394 if ((tmptaint
>> i
) & 1)
2402 struct do_proc_dointvec_minmax_conv_param
{
2407 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2409 int write
, void *data
)
2411 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2413 int val
= *negp
? -*lvalp
: *lvalp
;
2414 if ((param
->min
&& *param
->min
> val
) ||
2415 (param
->max
&& *param
->max
< val
))
2422 *lvalp
= (unsigned long)-val
;
2425 *lvalp
= (unsigned long)val
;
2432 * proc_dointvec_minmax - read a vector of integers with min/max values
2433 * @table: the sysctl table
2434 * @write: %TRUE if this is a write to the sysctl file
2435 * @buffer: the user buffer
2436 * @lenp: the size of the user buffer
2437 * @ppos: file position
2439 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2440 * values from/to the user buffer, treated as an ASCII string.
2442 * This routine will ensure the values are within the range specified by
2443 * table->extra1 (min) and table->extra2 (max).
2445 * Returns 0 on success.
2447 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2448 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2450 struct do_proc_dointvec_minmax_conv_param param
= {
2451 .min
= (int *) table
->extra1
,
2452 .max
= (int *) table
->extra2
,
2454 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2455 do_proc_dointvec_minmax_conv
, ¶m
);
2458 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2459 void __user
*buffer
,
2460 size_t *lenp
, loff_t
*ppos
,
2461 unsigned long convmul
,
2462 unsigned long convdiv
)
2464 unsigned long *i
, *min
, *max
;
2465 int vleft
, first
= 1, err
= 0;
2466 unsigned long page
= 0;
2470 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2475 i
= (unsigned long *) data
;
2476 min
= (unsigned long *) table
->extra1
;
2477 max
= (unsigned long *) table
->extra2
;
2478 vleft
= table
->maxlen
/ sizeof(unsigned long);
2482 if (left
> PAGE_SIZE
- 1)
2483 left
= PAGE_SIZE
- 1;
2484 page
= __get_free_page(GFP_TEMPORARY
);
2485 kbuf
= (char *) page
;
2488 if (copy_from_user(kbuf
, buffer
, left
)) {
2495 for (; left
&& vleft
--; i
++, first
= 0) {
2501 left
-= proc_skip_spaces(&kbuf
);
2503 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2505 sizeof(proc_wspace_sep
), NULL
);
2510 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2514 val
= convdiv
* (*i
) / convmul
;
2516 err
= proc_put_char(&buffer
, &left
, '\t');
2517 err
= proc_put_long(&buffer
, &left
, val
, false);
2523 if (!write
&& !first
&& left
&& !err
)
2524 err
= proc_put_char(&buffer
, &left
, '\n');
2526 left
-= proc_skip_spaces(&kbuf
);
2531 return err
? : -EINVAL
;
2538 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2539 void __user
*buffer
,
2540 size_t *lenp
, loff_t
*ppos
,
2541 unsigned long convmul
,
2542 unsigned long convdiv
)
2544 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2545 buffer
, lenp
, ppos
, convmul
, convdiv
);
2549 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2550 * @table: the sysctl table
2551 * @write: %TRUE if this is a write to the sysctl file
2552 * @buffer: the user buffer
2553 * @lenp: the size of the user buffer
2554 * @ppos: file position
2556 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2557 * values from/to the user buffer, treated as an ASCII string.
2559 * This routine will ensure the values are within the range specified by
2560 * table->extra1 (min) and table->extra2 (max).
2562 * Returns 0 on success.
2564 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2565 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2567 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2571 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2572 * @table: the sysctl table
2573 * @write: %TRUE if this is a write to the sysctl file
2574 * @buffer: the user buffer
2575 * @lenp: the size of the user buffer
2576 * @ppos: file position
2578 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2579 * values from/to the user buffer, treated as an ASCII string. The values
2580 * are treated as milliseconds, and converted to jiffies when they are stored.
2582 * This routine will ensure the values are within the range specified by
2583 * table->extra1 (min) and table->extra2 (max).
2585 * Returns 0 on success.
2587 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2588 void __user
*buffer
,
2589 size_t *lenp
, loff_t
*ppos
)
2591 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2592 lenp
, ppos
, HZ
, 1000l);
2596 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2598 int write
, void *data
)
2601 if (*lvalp
> LONG_MAX
/ HZ
)
2603 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2609 lval
= (unsigned long)-val
;
2612 lval
= (unsigned long)val
;
2619 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2621 int write
, void *data
)
2624 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2626 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2632 lval
= (unsigned long)-val
;
2635 lval
= (unsigned long)val
;
2637 *lvalp
= jiffies_to_clock_t(lval
);
2642 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2644 int write
, void *data
)
2647 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2653 lval
= (unsigned long)-val
;
2656 lval
= (unsigned long)val
;
2658 *lvalp
= jiffies_to_msecs(lval
);
2664 * proc_dointvec_jiffies - read a vector of integers as seconds
2665 * @table: the sysctl table
2666 * @write: %TRUE if this is a write to the sysctl file
2667 * @buffer: the user buffer
2668 * @lenp: the size of the user buffer
2669 * @ppos: file position
2671 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2672 * values from/to the user buffer, treated as an ASCII string.
2673 * The values read are assumed to be in seconds, and are converted into
2676 * Returns 0 on success.
2678 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2679 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2681 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2682 do_proc_dointvec_jiffies_conv
,NULL
);
2686 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2687 * @table: the sysctl table
2688 * @write: %TRUE if this is a write to the sysctl file
2689 * @buffer: the user buffer
2690 * @lenp: the size of the user buffer
2691 * @ppos: pointer to the file position
2693 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2694 * values from/to the user buffer, treated as an ASCII string.
2695 * The values read are assumed to be in 1/USER_HZ seconds, and
2696 * are converted into jiffies.
2698 * Returns 0 on success.
2700 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2701 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2703 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2704 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2708 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2709 * @table: the sysctl table
2710 * @write: %TRUE if this is a write to the sysctl file
2711 * @buffer: the user buffer
2712 * @lenp: the size of the user buffer
2713 * @ppos: file position
2714 * @ppos: the current position in the file
2716 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2717 * values from/to the user buffer, treated as an ASCII string.
2718 * The values read are assumed to be in 1/1000 seconds, and
2719 * are converted into jiffies.
2721 * Returns 0 on success.
2723 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2724 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2726 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2727 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2730 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2731 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2733 struct pid
*new_pid
;
2737 tmp
= pid_vnr(cad_pid
);
2739 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2740 lenp
, ppos
, NULL
, NULL
);
2744 new_pid
= find_get_pid(tmp
);
2748 put_pid(xchg(&cad_pid
, new_pid
));
2753 * proc_do_large_bitmap - read/write from/to a large bitmap
2754 * @table: the sysctl table
2755 * @write: %TRUE if this is a write to the sysctl file
2756 * @buffer: the user buffer
2757 * @lenp: the size of the user buffer
2758 * @ppos: file position
2760 * The bitmap is stored at table->data and the bitmap length (in bits)
2763 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2764 * large bitmaps may be represented in a compact manner. Writing into
2765 * the file will clear the bitmap then update it with the given input.
2767 * Returns 0 on success.
2769 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2770 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2774 size_t left
= *lenp
;
2775 unsigned long bitmap_len
= table
->maxlen
;
2776 unsigned long *bitmap
= (unsigned long *) table
->data
;
2777 unsigned long *tmp_bitmap
= NULL
;
2778 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2780 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2786 unsigned long page
= 0;
2789 if (left
> PAGE_SIZE
- 1)
2790 left
= PAGE_SIZE
- 1;
2792 page
= __get_free_page(GFP_TEMPORARY
);
2793 kbuf
= (char *) page
;
2796 if (copy_from_user(kbuf
, buffer
, left
)) {
2802 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2808 proc_skip_char(&kbuf
, &left
, '\n');
2809 while (!err
&& left
) {
2810 unsigned long val_a
, val_b
;
2813 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2817 if (val_a
>= bitmap_len
|| neg
) {
2829 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2830 &neg
, tr_b
, sizeof(tr_b
),
2834 if (val_b
>= bitmap_len
|| neg
||
2845 while (val_a
<= val_b
)
2846 set_bit(val_a
++, tmp_bitmap
);
2849 proc_skip_char(&kbuf
, &left
, '\n');
2853 unsigned long bit_a
, bit_b
= 0;
2856 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2857 if (bit_a
>= bitmap_len
)
2859 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2863 err
= proc_put_char(&buffer
, &left
, ',');
2867 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2870 if (bit_a
!= bit_b
) {
2871 err
= proc_put_char(&buffer
, &left
, '-');
2874 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2882 err
= proc_put_char(&buffer
, &left
, '\n');
2888 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2890 memcpy(bitmap
, tmp_bitmap
,
2891 BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long));
2903 #else /* CONFIG_PROC_FS */
2905 int proc_dostring(struct ctl_table
*table
, int write
,
2906 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2911 int proc_dointvec(struct ctl_table
*table
, int write
,
2912 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2917 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2918 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2923 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2924 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2929 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2930 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2935 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2936 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2941 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2942 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2947 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2948 void __user
*buffer
,
2949 size_t *lenp
, loff_t
*ppos
)
2955 #endif /* CONFIG_PROC_FS */
2958 * No sense putting this after each symbol definition, twice,
2959 * exception granted :-)
2961 EXPORT_SYMBOL(proc_dointvec
);
2962 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2963 EXPORT_SYMBOL(proc_dointvec_minmax
);
2964 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2965 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2966 EXPORT_SYMBOL(proc_dostring
);
2967 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2968 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2969 EXPORT_SYMBOL(register_sysctl_table
);
2970 EXPORT_SYMBOL(register_sysctl_paths
);
2971 EXPORT_SYMBOL(unregister_sysctl_table
);