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 extern struct ratelimit_state printk_ratelimit_state
;
166 #ifdef CONFIG_PROC_SYSCTL
167 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
168 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
169 static int proc_taint(struct ctl_table
*table
, int write
,
170 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
173 #ifdef CONFIG_MAGIC_SYSRQ
174 static int __sysrq_enabled
; /* Note: sysrq code ises it's own private copy */
176 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
177 void __user
*buffer
, size_t *lenp
,
182 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
187 sysrq_toggle_support(__sysrq_enabled
);
194 static struct ctl_table root_table
[];
195 static struct ctl_table_root sysctl_table_root
;
196 static struct ctl_table_header root_table_header
= {
198 .ctl_table
= root_table
,
199 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
200 .root
= &sysctl_table_root
,
201 .set
= &sysctl_table_root
.default_set
,
203 static struct ctl_table_root sysctl_table_root
= {
204 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
205 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
208 static struct ctl_table kern_table
[];
209 static struct ctl_table vm_table
[];
210 static struct ctl_table fs_table
[];
211 static struct ctl_table debug_table
[];
212 static struct ctl_table dev_table
[];
213 extern struct ctl_table random_table
[];
215 extern struct ctl_table epoll_table
[];
218 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
219 int sysctl_legacy_va_layout
;
222 /* The default sysctl tables: */
224 static struct ctl_table root_table
[] = {
226 .procname
= "kernel",
243 .child
= debug_table
,
251 * NOTE: do not add new entries to this table unless you have read
252 * Documentation/sysctl/ctl_unnumbered.txt
257 #ifdef CONFIG_SCHED_DEBUG
258 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
259 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
260 static int min_wakeup_granularity_ns
; /* 0 usecs */
261 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
262 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
263 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
264 static int min_sched_shares_ratelimit
= 100000; /* 100 usec */
265 static int max_sched_shares_ratelimit
= NSEC_PER_SEC
; /* 1 second */
268 #ifdef CONFIG_COMPACTION
269 static int min_extfrag_threshold
;
270 static int max_extfrag_threshold
= 1000;
273 static struct ctl_table kern_table
[] = {
275 .procname
= "sched_child_runs_first",
276 .data
= &sysctl_sched_child_runs_first
,
277 .maxlen
= sizeof(unsigned int),
279 .proc_handler
= proc_dointvec
,
281 #ifdef CONFIG_SCHED_DEBUG
283 .procname
= "sched_min_granularity_ns",
284 .data
= &sysctl_sched_min_granularity
,
285 .maxlen
= sizeof(unsigned int),
287 .proc_handler
= sched_proc_update_handler
,
288 .extra1
= &min_sched_granularity_ns
,
289 .extra2
= &max_sched_granularity_ns
,
292 .procname
= "sched_latency_ns",
293 .data
= &sysctl_sched_latency
,
294 .maxlen
= sizeof(unsigned int),
296 .proc_handler
= sched_proc_update_handler
,
297 .extra1
= &min_sched_granularity_ns
,
298 .extra2
= &max_sched_granularity_ns
,
301 .procname
= "sched_wakeup_granularity_ns",
302 .data
= &sysctl_sched_wakeup_granularity
,
303 .maxlen
= sizeof(unsigned int),
305 .proc_handler
= sched_proc_update_handler
,
306 .extra1
= &min_wakeup_granularity_ns
,
307 .extra2
= &max_wakeup_granularity_ns
,
310 .procname
= "sched_shares_ratelimit",
311 .data
= &sysctl_sched_shares_ratelimit
,
312 .maxlen
= sizeof(unsigned int),
314 .proc_handler
= sched_proc_update_handler
,
315 .extra1
= &min_sched_shares_ratelimit
,
316 .extra2
= &max_sched_shares_ratelimit
,
319 .procname
= "sched_tunable_scaling",
320 .data
= &sysctl_sched_tunable_scaling
,
321 .maxlen
= sizeof(enum sched_tunable_scaling
),
323 .proc_handler
= sched_proc_update_handler
,
324 .extra1
= &min_sched_tunable_scaling
,
325 .extra2
= &max_sched_tunable_scaling
,
328 .procname
= "sched_shares_thresh",
329 .data
= &sysctl_sched_shares_thresh
,
330 .maxlen
= sizeof(unsigned int),
332 .proc_handler
= proc_dointvec_minmax
,
336 .procname
= "sched_migration_cost",
337 .data
= &sysctl_sched_migration_cost
,
338 .maxlen
= sizeof(unsigned int),
340 .proc_handler
= proc_dointvec
,
343 .procname
= "sched_nr_migrate",
344 .data
= &sysctl_sched_nr_migrate
,
345 .maxlen
= sizeof(unsigned int),
347 .proc_handler
= proc_dointvec
,
350 .procname
= "sched_time_avg",
351 .data
= &sysctl_sched_time_avg
,
352 .maxlen
= sizeof(unsigned int),
354 .proc_handler
= proc_dointvec
,
357 .procname
= "timer_migration",
358 .data
= &sysctl_timer_migration
,
359 .maxlen
= sizeof(unsigned int),
361 .proc_handler
= proc_dointvec_minmax
,
367 .procname
= "sched_rt_period_us",
368 .data
= &sysctl_sched_rt_period
,
369 .maxlen
= sizeof(unsigned int),
371 .proc_handler
= sched_rt_handler
,
374 .procname
= "sched_rt_runtime_us",
375 .data
= &sysctl_sched_rt_runtime
,
376 .maxlen
= sizeof(int),
378 .proc_handler
= sched_rt_handler
,
381 .procname
= "sched_compat_yield",
382 .data
= &sysctl_sched_compat_yield
,
383 .maxlen
= sizeof(unsigned int),
385 .proc_handler
= proc_dointvec
,
387 #ifdef CONFIG_PROVE_LOCKING
389 .procname
= "prove_locking",
390 .data
= &prove_locking
,
391 .maxlen
= sizeof(int),
393 .proc_handler
= proc_dointvec
,
396 #ifdef CONFIG_LOCK_STAT
398 .procname
= "lock_stat",
400 .maxlen
= sizeof(int),
402 .proc_handler
= proc_dointvec
,
407 .data
= &panic_timeout
,
408 .maxlen
= sizeof(int),
410 .proc_handler
= proc_dointvec
,
413 .procname
= "core_uses_pid",
414 .data
= &core_uses_pid
,
415 .maxlen
= sizeof(int),
417 .proc_handler
= proc_dointvec
,
420 .procname
= "core_pattern",
421 .data
= core_pattern
,
422 .maxlen
= CORENAME_MAX_SIZE
,
424 .proc_handler
= proc_dostring
,
427 .procname
= "core_pipe_limit",
428 .data
= &core_pipe_limit
,
429 .maxlen
= sizeof(unsigned int),
431 .proc_handler
= proc_dointvec
,
433 #ifdef CONFIG_PROC_SYSCTL
435 .procname
= "tainted",
436 .maxlen
= sizeof(long),
438 .proc_handler
= proc_taint
,
441 #ifdef CONFIG_LATENCYTOP
443 .procname
= "latencytop",
444 .data
= &latencytop_enabled
,
445 .maxlen
= sizeof(int),
447 .proc_handler
= proc_dointvec
,
450 #ifdef CONFIG_BLK_DEV_INITRD
452 .procname
= "real-root-dev",
453 .data
= &real_root_dev
,
454 .maxlen
= sizeof(int),
456 .proc_handler
= proc_dointvec
,
460 .procname
= "print-fatal-signals",
461 .data
= &print_fatal_signals
,
462 .maxlen
= sizeof(int),
464 .proc_handler
= proc_dointvec
,
468 .procname
= "reboot-cmd",
469 .data
= reboot_command
,
472 .proc_handler
= proc_dostring
,
475 .procname
= "stop-a",
476 .data
= &stop_a_enabled
,
477 .maxlen
= sizeof (int),
479 .proc_handler
= proc_dointvec
,
482 .procname
= "scons-poweroff",
483 .data
= &scons_pwroff
,
484 .maxlen
= sizeof (int),
486 .proc_handler
= proc_dointvec
,
489 #ifdef CONFIG_SPARC64
491 .procname
= "tsb-ratio",
492 .data
= &sysctl_tsb_ratio
,
493 .maxlen
= sizeof (int),
495 .proc_handler
= proc_dointvec
,
500 .procname
= "soft-power",
501 .data
= &pwrsw_enabled
,
502 .maxlen
= sizeof (int),
504 .proc_handler
= proc_dointvec
,
507 .procname
= "unaligned-trap",
508 .data
= &unaligned_enabled
,
509 .maxlen
= sizeof (int),
511 .proc_handler
= proc_dointvec
,
515 .procname
= "ctrl-alt-del",
517 .maxlen
= sizeof(int),
519 .proc_handler
= proc_dointvec
,
521 #ifdef CONFIG_FUNCTION_TRACER
523 .procname
= "ftrace_enabled",
524 .data
= &ftrace_enabled
,
525 .maxlen
= sizeof(int),
527 .proc_handler
= ftrace_enable_sysctl
,
530 #ifdef CONFIG_STACK_TRACER
532 .procname
= "stack_tracer_enabled",
533 .data
= &stack_tracer_enabled
,
534 .maxlen
= sizeof(int),
536 .proc_handler
= stack_trace_sysctl
,
539 #ifdef CONFIG_TRACING
541 .procname
= "ftrace_dump_on_oops",
542 .data
= &ftrace_dump_on_oops
,
543 .maxlen
= sizeof(int),
545 .proc_handler
= proc_dointvec
,
548 #ifdef CONFIG_MODULES
550 .procname
= "modprobe",
551 .data
= &modprobe_path
,
552 .maxlen
= KMOD_PATH_LEN
,
554 .proc_handler
= proc_dostring
,
557 .procname
= "modules_disabled",
558 .data
= &modules_disabled
,
559 .maxlen
= sizeof(int),
561 /* only handle a transition from default "0" to "1" */
562 .proc_handler
= proc_dointvec_minmax
,
567 #ifdef CONFIG_HOTPLUG
569 .procname
= "hotplug",
570 .data
= &uevent_helper
,
571 .maxlen
= UEVENT_HELPER_PATH_LEN
,
573 .proc_handler
= proc_dostring
,
576 #ifdef CONFIG_CHR_DEV_SG
578 .procname
= "sg-big-buff",
579 .data
= &sg_big_buff
,
580 .maxlen
= sizeof (int),
582 .proc_handler
= proc_dointvec
,
585 #ifdef CONFIG_BSD_PROCESS_ACCT
589 .maxlen
= 3*sizeof(int),
591 .proc_handler
= proc_dointvec
,
594 #ifdef CONFIG_MAGIC_SYSRQ
597 .data
= &__sysrq_enabled
,
598 .maxlen
= sizeof (int),
600 .proc_handler
= sysrq_sysctl_handler
,
603 #ifdef CONFIG_PROC_SYSCTL
605 .procname
= "cad_pid",
607 .maxlen
= sizeof (int),
609 .proc_handler
= proc_do_cad_pid
,
613 .procname
= "threads-max",
614 .data
= &max_threads
,
615 .maxlen
= sizeof(int),
617 .proc_handler
= proc_dointvec
,
620 .procname
= "random",
622 .child
= random_table
,
625 .procname
= "overflowuid",
626 .data
= &overflowuid
,
627 .maxlen
= sizeof(int),
629 .proc_handler
= proc_dointvec_minmax
,
630 .extra1
= &minolduid
,
631 .extra2
= &maxolduid
,
634 .procname
= "overflowgid",
635 .data
= &overflowgid
,
636 .maxlen
= sizeof(int),
638 .proc_handler
= proc_dointvec_minmax
,
639 .extra1
= &minolduid
,
640 .extra2
= &maxolduid
,
643 #ifdef CONFIG_MATHEMU
645 .procname
= "ieee_emulation_warnings",
646 .data
= &sysctl_ieee_emulation_warnings
,
647 .maxlen
= sizeof(int),
649 .proc_handler
= proc_dointvec
,
653 .procname
= "userprocess_debug",
654 .data
= &show_unhandled_signals
,
655 .maxlen
= sizeof(int),
657 .proc_handler
= proc_dointvec
,
661 .procname
= "pid_max",
663 .maxlen
= sizeof (int),
665 .proc_handler
= proc_dointvec_minmax
,
666 .extra1
= &pid_max_min
,
667 .extra2
= &pid_max_max
,
670 .procname
= "panic_on_oops",
671 .data
= &panic_on_oops
,
672 .maxlen
= sizeof(int),
674 .proc_handler
= proc_dointvec
,
676 #if defined CONFIG_PRINTK
678 .procname
= "printk",
679 .data
= &console_loglevel
,
680 .maxlen
= 4*sizeof(int),
682 .proc_handler
= proc_dointvec
,
685 .procname
= "printk_ratelimit",
686 .data
= &printk_ratelimit_state
.interval
,
687 .maxlen
= sizeof(int),
689 .proc_handler
= proc_dointvec_jiffies
,
692 .procname
= "printk_ratelimit_burst",
693 .data
= &printk_ratelimit_state
.burst
,
694 .maxlen
= sizeof(int),
696 .proc_handler
= proc_dointvec
,
699 .procname
= "printk_delay",
700 .data
= &printk_delay_msec
,
701 .maxlen
= sizeof(int),
703 .proc_handler
= proc_dointvec_minmax
,
705 .extra2
= &ten_thousand
,
709 .procname
= "ngroups_max",
710 .data
= &ngroups_max
,
711 .maxlen
= sizeof (int),
713 .proc_handler
= proc_dointvec
,
715 #if defined(CONFIG_LOCKUP_DETECTOR)
717 .procname
= "watchdog",
718 .data
= &watchdog_enabled
,
719 .maxlen
= sizeof (int),
721 .proc_handler
= proc_dowatchdog_enabled
,
724 .procname
= "watchdog_thresh",
725 .data
= &softlockup_thresh
,
726 .maxlen
= sizeof(int),
728 .proc_handler
= proc_dowatchdog_thresh
,
733 .procname
= "softlockup_panic",
734 .data
= &softlockup_panic
,
735 .maxlen
= sizeof(int),
737 .proc_handler
= proc_dointvec_minmax
,
742 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
744 .procname
= "unknown_nmi_panic",
745 .data
= &unknown_nmi_panic
,
746 .maxlen
= sizeof (int),
748 .proc_handler
= proc_dointvec
,
751 .procname
= "nmi_watchdog",
752 .data
= &nmi_watchdog_enabled
,
753 .maxlen
= sizeof (int),
755 .proc_handler
= proc_nmi_enabled
,
758 #if defined(CONFIG_X86)
760 .procname
= "panic_on_unrecovered_nmi",
761 .data
= &panic_on_unrecovered_nmi
,
762 .maxlen
= sizeof(int),
764 .proc_handler
= proc_dointvec
,
767 .procname
= "panic_on_io_nmi",
768 .data
= &panic_on_io_nmi
,
769 .maxlen
= sizeof(int),
771 .proc_handler
= proc_dointvec
,
774 .procname
= "bootloader_type",
775 .data
= &bootloader_type
,
776 .maxlen
= sizeof (int),
778 .proc_handler
= proc_dointvec
,
781 .procname
= "bootloader_version",
782 .data
= &bootloader_version
,
783 .maxlen
= sizeof (int),
785 .proc_handler
= proc_dointvec
,
788 .procname
= "kstack_depth_to_print",
789 .data
= &kstack_depth_to_print
,
790 .maxlen
= sizeof(int),
792 .proc_handler
= proc_dointvec
,
795 .procname
= "io_delay_type",
796 .data
= &io_delay_type
,
797 .maxlen
= sizeof(int),
799 .proc_handler
= proc_dointvec
,
802 #if defined(CONFIG_MMU)
804 .procname
= "randomize_va_space",
805 .data
= &randomize_va_space
,
806 .maxlen
= sizeof(int),
808 .proc_handler
= proc_dointvec
,
811 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
813 .procname
= "spin_retry",
815 .maxlen
= sizeof (int),
817 .proc_handler
= proc_dointvec
,
820 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
822 .procname
= "acpi_video_flags",
823 .data
= &acpi_realmode_flags
,
824 .maxlen
= sizeof (unsigned long),
826 .proc_handler
= proc_doulongvec_minmax
,
831 .procname
= "ignore-unaligned-usertrap",
832 .data
= &no_unaligned_warning
,
833 .maxlen
= sizeof (int),
835 .proc_handler
= proc_dointvec
,
838 .procname
= "unaligned-dump-stack",
839 .data
= &unaligned_dump_stack
,
840 .maxlen
= sizeof (int),
842 .proc_handler
= proc_dointvec
,
845 #ifdef CONFIG_DETECT_HUNG_TASK
847 .procname
= "hung_task_panic",
848 .data
= &sysctl_hung_task_panic
,
849 .maxlen
= sizeof(int),
851 .proc_handler
= proc_dointvec_minmax
,
856 .procname
= "hung_task_check_count",
857 .data
= &sysctl_hung_task_check_count
,
858 .maxlen
= sizeof(unsigned long),
860 .proc_handler
= proc_doulongvec_minmax
,
863 .procname
= "hung_task_timeout_secs",
864 .data
= &sysctl_hung_task_timeout_secs
,
865 .maxlen
= sizeof(unsigned long),
867 .proc_handler
= proc_dohung_task_timeout_secs
,
870 .procname
= "hung_task_warnings",
871 .data
= &sysctl_hung_task_warnings
,
872 .maxlen
= sizeof(unsigned long),
874 .proc_handler
= proc_doulongvec_minmax
,
879 .procname
= "compat-log",
881 .maxlen
= sizeof (int),
883 .proc_handler
= proc_dointvec
,
886 #ifdef CONFIG_RT_MUTEXES
888 .procname
= "max_lock_depth",
889 .data
= &max_lock_depth
,
890 .maxlen
= sizeof(int),
892 .proc_handler
= proc_dointvec
,
896 .procname
= "poweroff_cmd",
897 .data
= &poweroff_cmd
,
898 .maxlen
= POWEROFF_CMD_PATH_LEN
,
900 .proc_handler
= proc_dostring
,
906 .child
= key_sysctls
,
909 #ifdef CONFIG_RCU_TORTURE_TEST
911 .procname
= "rcutorture_runnable",
912 .data
= &rcutorture_runnable
,
913 .maxlen
= sizeof(int),
915 .proc_handler
= proc_dointvec
,
918 #ifdef CONFIG_PERF_EVENTS
920 .procname
= "perf_event_paranoid",
921 .data
= &sysctl_perf_event_paranoid
,
922 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
924 .proc_handler
= proc_dointvec
,
927 .procname
= "perf_event_mlock_kb",
928 .data
= &sysctl_perf_event_mlock
,
929 .maxlen
= sizeof(sysctl_perf_event_mlock
),
931 .proc_handler
= proc_dointvec
,
934 .procname
= "perf_event_max_sample_rate",
935 .data
= &sysctl_perf_event_sample_rate
,
936 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
938 .proc_handler
= proc_dointvec
,
941 #ifdef CONFIG_KMEMCHECK
943 .procname
= "kmemcheck",
944 .data
= &kmemcheck_enabled
,
945 .maxlen
= sizeof(int),
947 .proc_handler
= proc_dointvec
,
952 .procname
= "blk_iopoll",
953 .data
= &blk_iopoll_enabled
,
954 .maxlen
= sizeof(int),
956 .proc_handler
= proc_dointvec
,
960 * NOTE: do not add new entries to this table unless you have read
961 * Documentation/sysctl/ctl_unnumbered.txt
966 static struct ctl_table vm_table
[] = {
968 .procname
= "overcommit_memory",
969 .data
= &sysctl_overcommit_memory
,
970 .maxlen
= sizeof(sysctl_overcommit_memory
),
972 .proc_handler
= proc_dointvec
,
975 .procname
= "panic_on_oom",
976 .data
= &sysctl_panic_on_oom
,
977 .maxlen
= sizeof(sysctl_panic_on_oom
),
979 .proc_handler
= proc_dointvec
,
982 .procname
= "oom_kill_allocating_task",
983 .data
= &sysctl_oom_kill_allocating_task
,
984 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
986 .proc_handler
= proc_dointvec
,
989 .procname
= "oom_dump_tasks",
990 .data
= &sysctl_oom_dump_tasks
,
991 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
993 .proc_handler
= proc_dointvec
,
996 .procname
= "overcommit_ratio",
997 .data
= &sysctl_overcommit_ratio
,
998 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1000 .proc_handler
= proc_dointvec
,
1003 .procname
= "page-cluster",
1004 .data
= &page_cluster
,
1005 .maxlen
= sizeof(int),
1007 .proc_handler
= proc_dointvec
,
1010 .procname
= "dirty_background_ratio",
1011 .data
= &dirty_background_ratio
,
1012 .maxlen
= sizeof(dirty_background_ratio
),
1014 .proc_handler
= dirty_background_ratio_handler
,
1016 .extra2
= &one_hundred
,
1019 .procname
= "dirty_background_bytes",
1020 .data
= &dirty_background_bytes
,
1021 .maxlen
= sizeof(dirty_background_bytes
),
1023 .proc_handler
= dirty_background_bytes_handler
,
1027 .procname
= "dirty_ratio",
1028 .data
= &vm_dirty_ratio
,
1029 .maxlen
= sizeof(vm_dirty_ratio
),
1031 .proc_handler
= dirty_ratio_handler
,
1033 .extra2
= &one_hundred
,
1036 .procname
= "dirty_bytes",
1037 .data
= &vm_dirty_bytes
,
1038 .maxlen
= sizeof(vm_dirty_bytes
),
1040 .proc_handler
= dirty_bytes_handler
,
1041 .extra1
= &dirty_bytes_min
,
1044 .procname
= "dirty_writeback_centisecs",
1045 .data
= &dirty_writeback_interval
,
1046 .maxlen
= sizeof(dirty_writeback_interval
),
1048 .proc_handler
= dirty_writeback_centisecs_handler
,
1051 .procname
= "dirty_expire_centisecs",
1052 .data
= &dirty_expire_interval
,
1053 .maxlen
= sizeof(dirty_expire_interval
),
1055 .proc_handler
= proc_dointvec
,
1058 .procname
= "nr_pdflush_threads",
1059 .data
= &nr_pdflush_threads
,
1060 .maxlen
= sizeof nr_pdflush_threads
,
1061 .mode
= 0444 /* read-only*/,
1062 .proc_handler
= proc_dointvec
,
1065 .procname
= "swappiness",
1066 .data
= &vm_swappiness
,
1067 .maxlen
= sizeof(vm_swappiness
),
1069 .proc_handler
= proc_dointvec_minmax
,
1071 .extra2
= &one_hundred
,
1073 #ifdef CONFIG_HUGETLB_PAGE
1075 .procname
= "nr_hugepages",
1077 .maxlen
= sizeof(unsigned long),
1079 .proc_handler
= hugetlb_sysctl_handler
,
1080 .extra1
= (void *)&hugetlb_zero
,
1081 .extra2
= (void *)&hugetlb_infinity
,
1085 .procname
= "nr_hugepages_mempolicy",
1087 .maxlen
= sizeof(unsigned long),
1089 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1090 .extra1
= (void *)&hugetlb_zero
,
1091 .extra2
= (void *)&hugetlb_infinity
,
1095 .procname
= "hugetlb_shm_group",
1096 .data
= &sysctl_hugetlb_shm_group
,
1097 .maxlen
= sizeof(gid_t
),
1099 .proc_handler
= proc_dointvec
,
1102 .procname
= "hugepages_treat_as_movable",
1103 .data
= &hugepages_treat_as_movable
,
1104 .maxlen
= sizeof(int),
1106 .proc_handler
= hugetlb_treat_movable_handler
,
1109 .procname
= "nr_overcommit_hugepages",
1111 .maxlen
= sizeof(unsigned long),
1113 .proc_handler
= hugetlb_overcommit_handler
,
1114 .extra1
= (void *)&hugetlb_zero
,
1115 .extra2
= (void *)&hugetlb_infinity
,
1119 .procname
= "lowmem_reserve_ratio",
1120 .data
= &sysctl_lowmem_reserve_ratio
,
1121 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1123 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1126 .procname
= "drop_caches",
1127 .data
= &sysctl_drop_caches
,
1128 .maxlen
= sizeof(int),
1130 .proc_handler
= drop_caches_sysctl_handler
,
1132 #ifdef CONFIG_COMPACTION
1134 .procname
= "compact_memory",
1135 .data
= &sysctl_compact_memory
,
1136 .maxlen
= sizeof(int),
1138 .proc_handler
= sysctl_compaction_handler
,
1141 .procname
= "extfrag_threshold",
1142 .data
= &sysctl_extfrag_threshold
,
1143 .maxlen
= sizeof(int),
1145 .proc_handler
= sysctl_extfrag_handler
,
1146 .extra1
= &min_extfrag_threshold
,
1147 .extra2
= &max_extfrag_threshold
,
1150 #endif /* CONFIG_COMPACTION */
1152 .procname
= "min_free_kbytes",
1153 .data
= &min_free_kbytes
,
1154 .maxlen
= sizeof(min_free_kbytes
),
1156 .proc_handler
= min_free_kbytes_sysctl_handler
,
1160 .procname
= "percpu_pagelist_fraction",
1161 .data
= &percpu_pagelist_fraction
,
1162 .maxlen
= sizeof(percpu_pagelist_fraction
),
1164 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1165 .extra1
= &min_percpu_pagelist_fract
,
1169 .procname
= "max_map_count",
1170 .data
= &sysctl_max_map_count
,
1171 .maxlen
= sizeof(sysctl_max_map_count
),
1173 .proc_handler
= proc_dointvec_minmax
,
1178 .procname
= "nr_trim_pages",
1179 .data
= &sysctl_nr_trim_pages
,
1180 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1182 .proc_handler
= proc_dointvec_minmax
,
1187 .procname
= "laptop_mode",
1188 .data
= &laptop_mode
,
1189 .maxlen
= sizeof(laptop_mode
),
1191 .proc_handler
= proc_dointvec_jiffies
,
1194 .procname
= "block_dump",
1195 .data
= &block_dump
,
1196 .maxlen
= sizeof(block_dump
),
1198 .proc_handler
= proc_dointvec
,
1202 .procname
= "vfs_cache_pressure",
1203 .data
= &sysctl_vfs_cache_pressure
,
1204 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1206 .proc_handler
= proc_dointvec
,
1209 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1211 .procname
= "legacy_va_layout",
1212 .data
= &sysctl_legacy_va_layout
,
1213 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1215 .proc_handler
= proc_dointvec
,
1221 .procname
= "zone_reclaim_mode",
1222 .data
= &zone_reclaim_mode
,
1223 .maxlen
= sizeof(zone_reclaim_mode
),
1225 .proc_handler
= proc_dointvec
,
1229 .procname
= "min_unmapped_ratio",
1230 .data
= &sysctl_min_unmapped_ratio
,
1231 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1233 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1235 .extra2
= &one_hundred
,
1238 .procname
= "min_slab_ratio",
1239 .data
= &sysctl_min_slab_ratio
,
1240 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1242 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1244 .extra2
= &one_hundred
,
1249 .procname
= "stat_interval",
1250 .data
= &sysctl_stat_interval
,
1251 .maxlen
= sizeof(sysctl_stat_interval
),
1253 .proc_handler
= proc_dointvec_jiffies
,
1258 .procname
= "mmap_min_addr",
1259 .data
= &dac_mmap_min_addr
,
1260 .maxlen
= sizeof(unsigned long),
1262 .proc_handler
= mmap_min_addr_handler
,
1267 .procname
= "numa_zonelist_order",
1268 .data
= &numa_zonelist_order
,
1269 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1271 .proc_handler
= numa_zonelist_order_handler
,
1274 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1275 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1277 .procname
= "vdso_enabled",
1278 .data
= &vdso_enabled
,
1279 .maxlen
= sizeof(vdso_enabled
),
1281 .proc_handler
= proc_dointvec
,
1285 #ifdef CONFIG_HIGHMEM
1287 .procname
= "highmem_is_dirtyable",
1288 .data
= &vm_highmem_is_dirtyable
,
1289 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1291 .proc_handler
= proc_dointvec_minmax
,
1297 .procname
= "scan_unevictable_pages",
1298 .data
= &scan_unevictable_pages
,
1299 .maxlen
= sizeof(scan_unevictable_pages
),
1301 .proc_handler
= scan_unevictable_handler
,
1303 #ifdef CONFIG_MEMORY_FAILURE
1305 .procname
= "memory_failure_early_kill",
1306 .data
= &sysctl_memory_failure_early_kill
,
1307 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1309 .proc_handler
= proc_dointvec_minmax
,
1314 .procname
= "memory_failure_recovery",
1315 .data
= &sysctl_memory_failure_recovery
,
1316 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1318 .proc_handler
= proc_dointvec_minmax
,
1325 * NOTE: do not add new entries to this table unless you have read
1326 * Documentation/sysctl/ctl_unnumbered.txt
1331 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1332 static struct ctl_table binfmt_misc_table
[] = {
1337 static struct ctl_table fs_table
[] = {
1339 .procname
= "inode-nr",
1340 .data
= &inodes_stat
,
1341 .maxlen
= 2*sizeof(int),
1343 .proc_handler
= proc_dointvec
,
1346 .procname
= "inode-state",
1347 .data
= &inodes_stat
,
1348 .maxlen
= 7*sizeof(int),
1350 .proc_handler
= proc_dointvec
,
1353 .procname
= "file-nr",
1354 .data
= &files_stat
,
1355 .maxlen
= 3*sizeof(int),
1357 .proc_handler
= proc_nr_files
,
1360 .procname
= "file-max",
1361 .data
= &files_stat
.max_files
,
1362 .maxlen
= sizeof(int),
1364 .proc_handler
= proc_dointvec
,
1367 .procname
= "nr_open",
1368 .data
= &sysctl_nr_open
,
1369 .maxlen
= sizeof(int),
1371 .proc_handler
= proc_dointvec_minmax
,
1372 .extra1
= &sysctl_nr_open_min
,
1373 .extra2
= &sysctl_nr_open_max
,
1376 .procname
= "dentry-state",
1377 .data
= &dentry_stat
,
1378 .maxlen
= 6*sizeof(int),
1380 .proc_handler
= proc_dointvec
,
1383 .procname
= "overflowuid",
1384 .data
= &fs_overflowuid
,
1385 .maxlen
= sizeof(int),
1387 .proc_handler
= proc_dointvec_minmax
,
1388 .extra1
= &minolduid
,
1389 .extra2
= &maxolduid
,
1392 .procname
= "overflowgid",
1393 .data
= &fs_overflowgid
,
1394 .maxlen
= sizeof(int),
1396 .proc_handler
= proc_dointvec_minmax
,
1397 .extra1
= &minolduid
,
1398 .extra2
= &maxolduid
,
1400 #ifdef CONFIG_FILE_LOCKING
1402 .procname
= "leases-enable",
1403 .data
= &leases_enable
,
1404 .maxlen
= sizeof(int),
1406 .proc_handler
= proc_dointvec
,
1409 #ifdef CONFIG_DNOTIFY
1411 .procname
= "dir-notify-enable",
1412 .data
= &dir_notify_enable
,
1413 .maxlen
= sizeof(int),
1415 .proc_handler
= proc_dointvec
,
1419 #ifdef CONFIG_FILE_LOCKING
1421 .procname
= "lease-break-time",
1422 .data
= &lease_break_time
,
1423 .maxlen
= sizeof(int),
1425 .proc_handler
= proc_dointvec
,
1430 .procname
= "aio-nr",
1432 .maxlen
= sizeof(aio_nr
),
1434 .proc_handler
= proc_doulongvec_minmax
,
1437 .procname
= "aio-max-nr",
1438 .data
= &aio_max_nr
,
1439 .maxlen
= sizeof(aio_max_nr
),
1441 .proc_handler
= proc_doulongvec_minmax
,
1443 #endif /* CONFIG_AIO */
1444 #ifdef CONFIG_INOTIFY_USER
1446 .procname
= "inotify",
1448 .child
= inotify_table
,
1453 .procname
= "epoll",
1455 .child
= epoll_table
,
1460 .procname
= "suid_dumpable",
1461 .data
= &suid_dumpable
,
1462 .maxlen
= sizeof(int),
1464 .proc_handler
= proc_dointvec_minmax
,
1468 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1470 .procname
= "binfmt_misc",
1472 .child
= binfmt_misc_table
,
1476 .procname
= "pipe-max-size",
1477 .data
= &pipe_max_size
,
1478 .maxlen
= sizeof(int),
1480 .proc_handler
= &pipe_proc_fn
,
1481 .extra1
= &pipe_min_size
,
1484 * NOTE: do not add new entries to this table unless you have read
1485 * Documentation/sysctl/ctl_unnumbered.txt
1490 static struct ctl_table debug_table
[] = {
1491 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1492 defined(CONFIG_S390)
1494 .procname
= "exception-trace",
1495 .data
= &show_unhandled_signals
,
1496 .maxlen
= sizeof(int),
1498 .proc_handler
= proc_dointvec
1501 #if defined(CONFIG_OPTPROBES)
1503 .procname
= "kprobes-optimization",
1504 .data
= &sysctl_kprobes_optimization
,
1505 .maxlen
= sizeof(int),
1507 .proc_handler
= proc_kprobes_optimization_handler
,
1515 static struct ctl_table dev_table
[] = {
1519 static DEFINE_SPINLOCK(sysctl_lock
);
1521 /* called under sysctl_lock */
1522 static int use_table(struct ctl_table_header
*p
)
1524 if (unlikely(p
->unregistering
))
1530 /* called under sysctl_lock */
1531 static void unuse_table(struct ctl_table_header
*p
)
1534 if (unlikely(p
->unregistering
))
1535 complete(p
->unregistering
);
1538 /* called under sysctl_lock, will reacquire if has to wait */
1539 static void start_unregistering(struct ctl_table_header
*p
)
1542 * if p->used is 0, nobody will ever touch that entry again;
1543 * we'll eliminate all paths to it before dropping sysctl_lock
1545 if (unlikely(p
->used
)) {
1546 struct completion wait
;
1547 init_completion(&wait
);
1548 p
->unregistering
= &wait
;
1549 spin_unlock(&sysctl_lock
);
1550 wait_for_completion(&wait
);
1551 spin_lock(&sysctl_lock
);
1553 /* anything non-NULL; we'll never dereference it */
1554 p
->unregistering
= ERR_PTR(-EINVAL
);
1557 * do not remove from the list until nobody holds it; walking the
1558 * list in do_sysctl() relies on that.
1560 list_del_init(&p
->ctl_entry
);
1563 void sysctl_head_get(struct ctl_table_header
*head
)
1565 spin_lock(&sysctl_lock
);
1567 spin_unlock(&sysctl_lock
);
1570 void sysctl_head_put(struct ctl_table_header
*head
)
1572 spin_lock(&sysctl_lock
);
1575 spin_unlock(&sysctl_lock
);
1578 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1582 spin_lock(&sysctl_lock
);
1583 if (!use_table(head
))
1584 head
= ERR_PTR(-ENOENT
);
1585 spin_unlock(&sysctl_lock
);
1589 void sysctl_head_finish(struct ctl_table_header
*head
)
1593 spin_lock(&sysctl_lock
);
1595 spin_unlock(&sysctl_lock
);
1598 static struct ctl_table_set
*
1599 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1601 struct ctl_table_set
*set
= &root
->default_set
;
1603 set
= root
->lookup(root
, namespaces
);
1607 static struct list_head
*
1608 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1610 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1614 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1615 struct ctl_table_header
*prev
)
1617 struct ctl_table_root
*root
;
1618 struct list_head
*header_list
;
1619 struct ctl_table_header
*head
;
1620 struct list_head
*tmp
;
1622 spin_lock(&sysctl_lock
);
1625 tmp
= &prev
->ctl_entry
;
1629 tmp
= &root_table_header
.ctl_entry
;
1631 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1633 if (!use_table(head
))
1635 spin_unlock(&sysctl_lock
);
1640 header_list
= lookup_header_list(root
, namespaces
);
1641 if (tmp
!= header_list
)
1645 root
= list_entry(root
->root_list
.next
,
1646 struct ctl_table_root
, root_list
);
1647 if (root
== &sysctl_table_root
)
1649 header_list
= lookup_header_list(root
, namespaces
);
1650 } while (list_empty(header_list
));
1651 tmp
= header_list
->next
;
1654 spin_unlock(&sysctl_lock
);
1658 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1660 return __sysctl_head_next(current
->nsproxy
, prev
);
1663 void register_sysctl_root(struct ctl_table_root
*root
)
1665 spin_lock(&sysctl_lock
);
1666 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1667 spin_unlock(&sysctl_lock
);
1671 * sysctl_perm does NOT grant the superuser all rights automatically, because
1672 * some sysctl variables are readonly even to root.
1675 static int test_perm(int mode
, int op
)
1677 if (!current_euid())
1679 else if (in_egroup_p(0))
1681 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1686 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1691 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1695 if (root
->permissions
)
1696 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1700 return test_perm(mode
, op
);
1703 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1705 for (; table
->procname
; table
++) {
1706 table
->parent
= parent
;
1708 sysctl_set_parent(table
, table
->child
);
1712 static __init
int sysctl_init(void)
1714 sysctl_set_parent(NULL
, root_table
);
1715 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1718 err
= sysctl_check_table(current
->nsproxy
, root_table
);
1724 core_initcall(sysctl_init
);
1726 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1727 struct ctl_table
*table
)
1729 struct ctl_table
*p
;
1730 const char *s
= branch
->procname
;
1732 /* branch should have named subdirectory as its first element */
1733 if (!s
|| !branch
->child
)
1736 /* ... and nothing else */
1737 if (branch
[1].procname
)
1740 /* table should contain subdirectory with the same name */
1741 for (p
= table
; p
->procname
; p
++) {
1744 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1750 /* see if attaching q to p would be an improvement */
1751 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1753 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1754 struct ctl_table
*next
;
1756 int not_in_parent
= !p
->attached_by
;
1758 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1759 if (by
== q
->attached_by
)
1761 if (to
== p
->attached_by
)
1767 if (is_better
&& not_in_parent
) {
1768 q
->attached_by
= by
;
1769 q
->attached_to
= to
;
1775 * __register_sysctl_paths - register a sysctl hierarchy
1776 * @root: List of sysctl headers to register on
1777 * @namespaces: Data to compute which lists of sysctl entries are visible
1778 * @path: The path to the directory the sysctl table is in.
1779 * @table: the top-level table structure
1781 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1782 * array. A completely 0 filled entry terminates the table.
1784 * The members of the &struct ctl_table structure are used as follows:
1786 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1787 * enter a sysctl file
1789 * data - a pointer to data for use by proc_handler
1791 * maxlen - the maximum size in bytes of the data
1793 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1795 * child - a pointer to the child sysctl table if this entry is a directory, or
1798 * proc_handler - the text handler routine (described below)
1800 * de - for internal use by the sysctl routines
1802 * extra1, extra2 - extra pointers usable by the proc handler routines
1804 * Leaf nodes in the sysctl tree will be represented by a single file
1805 * under /proc; non-leaf nodes will be represented by directories.
1807 * sysctl(2) can automatically manage read and write requests through
1808 * the sysctl table. The data and maxlen fields of the ctl_table
1809 * struct enable minimal validation of the values being written to be
1810 * performed, and the mode field allows minimal authentication.
1812 * There must be a proc_handler routine for any terminal nodes
1813 * mirrored under /proc/sys (non-terminals are handled by a built-in
1814 * directory handler). Several default handlers are available to
1815 * cover common cases -
1817 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1818 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1819 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1821 * It is the handler's job to read the input buffer from user memory
1822 * and process it. The handler should return 0 on success.
1824 * This routine returns %NULL on a failure to register, and a pointer
1825 * to the table header on success.
1827 struct ctl_table_header
*__register_sysctl_paths(
1828 struct ctl_table_root
*root
,
1829 struct nsproxy
*namespaces
,
1830 const struct ctl_path
*path
, struct ctl_table
*table
)
1832 struct ctl_table_header
*header
;
1833 struct ctl_table
*new, **prevp
;
1834 unsigned int n
, npath
;
1835 struct ctl_table_set
*set
;
1837 /* Count the path components */
1838 for (npath
= 0; path
[npath
].procname
; ++npath
)
1842 * For each path component, allocate a 2-element ctl_table array.
1843 * The first array element will be filled with the sysctl entry
1844 * for this, the second will be the sentinel (procname == 0).
1846 * We allocate everything in one go so that we don't have to
1847 * worry about freeing additional memory in unregister_sysctl_table.
1849 header
= kzalloc(sizeof(struct ctl_table_header
) +
1850 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1854 new = (struct ctl_table
*) (header
+ 1);
1856 /* Now connect the dots */
1857 prevp
= &header
->ctl_table
;
1858 for (n
= 0; n
< npath
; ++n
, ++path
) {
1859 /* Copy the procname */
1860 new->procname
= path
->procname
;
1864 prevp
= &new->child
;
1869 header
->ctl_table_arg
= table
;
1871 INIT_LIST_HEAD(&header
->ctl_entry
);
1873 header
->unregistering
= NULL
;
1874 header
->root
= root
;
1875 sysctl_set_parent(NULL
, header
->ctl_table
);
1877 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1878 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1883 spin_lock(&sysctl_lock
);
1884 header
->set
= lookup_header_set(root
, namespaces
);
1885 header
->attached_by
= header
->ctl_table
;
1886 header
->attached_to
= root_table
;
1887 header
->parent
= &root_table_header
;
1888 for (set
= header
->set
; set
; set
= set
->parent
) {
1889 struct ctl_table_header
*p
;
1890 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1891 if (p
->unregistering
)
1893 try_attach(p
, header
);
1896 header
->parent
->count
++;
1897 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1898 spin_unlock(&sysctl_lock
);
1904 * register_sysctl_table_path - register a sysctl table hierarchy
1905 * @path: The path to the directory the sysctl table is in.
1906 * @table: the top-level table structure
1908 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1909 * array. A completely 0 filled entry terminates the table.
1911 * See __register_sysctl_paths for more details.
1913 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1914 struct ctl_table
*table
)
1916 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1921 * register_sysctl_table - register a sysctl table hierarchy
1922 * @table: the top-level table structure
1924 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1925 * array. A completely 0 filled entry terminates the table.
1927 * See register_sysctl_paths for more details.
1929 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1931 static const struct ctl_path null_path
[] = { {} };
1933 return register_sysctl_paths(null_path
, table
);
1937 * unregister_sysctl_table - unregister a sysctl table hierarchy
1938 * @header: the header returned from register_sysctl_table
1940 * Unregisters the sysctl table and all children. proc entries may not
1941 * actually be removed until they are no longer used by anyone.
1943 void unregister_sysctl_table(struct ctl_table_header
* header
)
1950 spin_lock(&sysctl_lock
);
1951 start_unregistering(header
);
1952 if (!--header
->parent
->count
) {
1954 kfree(header
->parent
);
1956 if (!--header
->count
)
1958 spin_unlock(&sysctl_lock
);
1961 int sysctl_is_seen(struct ctl_table_header
*p
)
1963 struct ctl_table_set
*set
= p
->set
;
1965 spin_lock(&sysctl_lock
);
1966 if (p
->unregistering
)
1968 else if (!set
->is_seen
)
1971 res
= set
->is_seen(set
);
1972 spin_unlock(&sysctl_lock
);
1976 void setup_sysctl_set(struct ctl_table_set
*p
,
1977 struct ctl_table_set
*parent
,
1978 int (*is_seen
)(struct ctl_table_set
*))
1980 INIT_LIST_HEAD(&p
->list
);
1981 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1982 p
->is_seen
= is_seen
;
1985 #else /* !CONFIG_SYSCTL */
1986 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1991 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1992 struct ctl_table
*table
)
1997 void unregister_sysctl_table(struct ctl_table_header
* table
)
2001 void setup_sysctl_set(struct ctl_table_set
*p
,
2002 struct ctl_table_set
*parent
,
2003 int (*is_seen
)(struct ctl_table_set
*))
2007 void sysctl_head_put(struct ctl_table_header
*head
)
2011 #endif /* CONFIG_SYSCTL */
2017 #ifdef CONFIG_PROC_SYSCTL
2019 static int _proc_do_string(void* data
, int maxlen
, int write
,
2020 void __user
*buffer
,
2021 size_t *lenp
, loff_t
*ppos
)
2027 if (!data
|| !maxlen
|| !*lenp
) {
2035 while (len
< *lenp
) {
2036 if (get_user(c
, p
++))
2038 if (c
== 0 || c
== '\n')
2044 if(copy_from_user(data
, buffer
, len
))
2046 ((char *) data
)[len
] = 0;
2064 if(copy_to_user(buffer
, data
, len
))
2067 if(put_user('\n', ((char __user
*) buffer
) + len
))
2078 * proc_dostring - read a string sysctl
2079 * @table: the sysctl table
2080 * @write: %TRUE if this is a write to the sysctl file
2081 * @buffer: the user buffer
2082 * @lenp: the size of the user buffer
2083 * @ppos: file position
2085 * Reads/writes a string from/to the user buffer. If the kernel
2086 * buffer provided is not large enough to hold the string, the
2087 * string is truncated. The copied string is %NULL-terminated.
2088 * If the string is being read by the user process, it is copied
2089 * and a newline '\n' is added. It is truncated if the buffer is
2092 * Returns 0 on success.
2094 int proc_dostring(struct ctl_table
*table
, int write
,
2095 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2097 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2098 buffer
, lenp
, ppos
);
2101 static size_t proc_skip_spaces(char **buf
)
2104 char *tmp
= skip_spaces(*buf
);
2110 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2120 #define TMPBUFLEN 22
2122 * proc_get_long - reads an ASCII formatted integer from a user buffer
2124 * @buf: a kernel buffer
2125 * @size: size of the kernel buffer
2126 * @val: this is where the number will be stored
2127 * @neg: set to %TRUE if number is negative
2128 * @perm_tr: a vector which contains the allowed trailers
2129 * @perm_tr_len: size of the perm_tr vector
2130 * @tr: pointer to store the trailer character
2132 * In case of success %0 is returned and @buf and @size are updated with
2133 * the amount of bytes read. If @tr is non-NULL and a trailing
2134 * character exists (size is non-zero after returning from this
2135 * function), @tr is updated with the trailing character.
2137 static int proc_get_long(char **buf
, size_t *size
,
2138 unsigned long *val
, bool *neg
,
2139 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2142 char *p
, tmp
[TMPBUFLEN
];
2148 if (len
> TMPBUFLEN
- 1)
2149 len
= TMPBUFLEN
- 1;
2151 memcpy(tmp
, *buf
, len
);
2155 if (*p
== '-' && *size
> 1) {
2163 *val
= simple_strtoul(p
, &p
, 0);
2167 /* We don't know if the next char is whitespace thus we may accept
2168 * invalid integers (e.g. 1234...a) or two integers instead of one
2169 * (e.g. 123...1). So lets not allow such large numbers. */
2170 if (len
== TMPBUFLEN
- 1)
2173 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2176 if (tr
&& (len
< *size
))
2186 * proc_put_long - converts an integer to a decimal ASCII formatted string
2188 * @buf: the user buffer
2189 * @size: the size of the user buffer
2190 * @val: the integer to be converted
2191 * @neg: sign of the number, %TRUE for negative
2193 * In case of success %0 is returned and @buf and @size are updated with
2194 * the amount of bytes written.
2196 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2200 char tmp
[TMPBUFLEN
], *p
= tmp
;
2202 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2206 if (copy_to_user(*buf
, tmp
, len
))
2214 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2217 char __user
**buffer
= (char __user
**)buf
;
2218 if (put_user(c
, *buffer
))
2220 (*size
)--, (*buffer
)++;
2226 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2228 int write
, void *data
)
2231 *valp
= *negp
? -*lvalp
: *lvalp
;
2236 *lvalp
= (unsigned long)-val
;
2239 *lvalp
= (unsigned long)val
;
2245 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2247 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2248 int write
, void __user
*buffer
,
2249 size_t *lenp
, loff_t
*ppos
,
2250 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2251 int write
, void *data
),
2254 int *i
, vleft
, first
= 1, err
= 0;
2255 unsigned long page
= 0;
2259 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2264 i
= (int *) tbl_data
;
2265 vleft
= table
->maxlen
/ sizeof(*i
);
2269 conv
= do_proc_dointvec_conv
;
2272 if (left
> PAGE_SIZE
- 1)
2273 left
= PAGE_SIZE
- 1;
2274 page
= __get_free_page(GFP_TEMPORARY
);
2275 kbuf
= (char *) page
;
2278 if (copy_from_user(kbuf
, buffer
, left
)) {
2285 for (; left
&& vleft
--; i
++, first
=0) {
2290 left
-= proc_skip_spaces(&kbuf
);
2294 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2296 sizeof(proc_wspace_sep
), NULL
);
2299 if (conv(&neg
, &lval
, i
, 1, data
)) {
2304 if (conv(&neg
, &lval
, i
, 0, data
)) {
2309 err
= proc_put_char(&buffer
, &left
, '\t');
2312 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2318 if (!write
&& !first
&& left
&& !err
)
2319 err
= proc_put_char(&buffer
, &left
, '\n');
2320 if (write
&& !err
&& left
)
2321 left
-= proc_skip_spaces(&kbuf
);
2326 return err
? : -EINVAL
;
2333 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2334 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2335 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2336 int write
, void *data
),
2339 return __do_proc_dointvec(table
->data
, table
, write
,
2340 buffer
, lenp
, ppos
, conv
, data
);
2344 * proc_dointvec - read a vector of integers
2345 * @table: the sysctl table
2346 * @write: %TRUE if this is a write to the sysctl file
2347 * @buffer: the user buffer
2348 * @lenp: the size of the user buffer
2349 * @ppos: file position
2351 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2352 * values from/to the user buffer, treated as an ASCII string.
2354 * Returns 0 on success.
2356 int proc_dointvec(struct ctl_table
*table
, int write
,
2357 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2359 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2364 * Taint values can only be increased
2365 * This means we can safely use a temporary.
2367 static int proc_taint(struct ctl_table
*table
, int write
,
2368 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2371 unsigned long tmptaint
= get_taint();
2374 if (write
&& !capable(CAP_SYS_ADMIN
))
2379 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2385 * Poor man's atomic or. Not worth adding a primitive
2386 * to everyone's atomic.h for this
2389 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2390 if ((tmptaint
>> i
) & 1)
2398 struct do_proc_dointvec_minmax_conv_param
{
2403 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2405 int write
, void *data
)
2407 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2409 int val
= *negp
? -*lvalp
: *lvalp
;
2410 if ((param
->min
&& *param
->min
> val
) ||
2411 (param
->max
&& *param
->max
< val
))
2418 *lvalp
= (unsigned long)-val
;
2421 *lvalp
= (unsigned long)val
;
2428 * proc_dointvec_minmax - read a vector of integers with min/max values
2429 * @table: the sysctl table
2430 * @write: %TRUE if this is a write to the sysctl file
2431 * @buffer: the user buffer
2432 * @lenp: the size of the user buffer
2433 * @ppos: file position
2435 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2436 * values from/to the user buffer, treated as an ASCII string.
2438 * This routine will ensure the values are within the range specified by
2439 * table->extra1 (min) and table->extra2 (max).
2441 * Returns 0 on success.
2443 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2444 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2446 struct do_proc_dointvec_minmax_conv_param param
= {
2447 .min
= (int *) table
->extra1
,
2448 .max
= (int *) table
->extra2
,
2450 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2451 do_proc_dointvec_minmax_conv
, ¶m
);
2454 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2455 void __user
*buffer
,
2456 size_t *lenp
, loff_t
*ppos
,
2457 unsigned long convmul
,
2458 unsigned long convdiv
)
2460 unsigned long *i
, *min
, *max
;
2461 int vleft
, first
= 1, err
= 0;
2462 unsigned long page
= 0;
2466 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2471 i
= (unsigned long *) data
;
2472 min
= (unsigned long *) table
->extra1
;
2473 max
= (unsigned long *) table
->extra2
;
2474 vleft
= table
->maxlen
/ sizeof(unsigned long);
2478 if (left
> PAGE_SIZE
- 1)
2479 left
= PAGE_SIZE
- 1;
2480 page
= __get_free_page(GFP_TEMPORARY
);
2481 kbuf
= (char *) page
;
2484 if (copy_from_user(kbuf
, buffer
, left
)) {
2491 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2497 left
-= proc_skip_spaces(&kbuf
);
2499 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2501 sizeof(proc_wspace_sep
), NULL
);
2506 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2510 val
= convdiv
* (*i
) / convmul
;
2512 err
= proc_put_char(&buffer
, &left
, '\t');
2513 err
= proc_put_long(&buffer
, &left
, val
, false);
2519 if (!write
&& !first
&& left
&& !err
)
2520 err
= proc_put_char(&buffer
, &left
, '\n');
2522 left
-= proc_skip_spaces(&kbuf
);
2527 return err
? : -EINVAL
;
2534 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2535 void __user
*buffer
,
2536 size_t *lenp
, loff_t
*ppos
,
2537 unsigned long convmul
,
2538 unsigned long convdiv
)
2540 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2541 buffer
, lenp
, ppos
, convmul
, convdiv
);
2545 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2546 * @table: the sysctl table
2547 * @write: %TRUE if this is a write to the sysctl file
2548 * @buffer: the user buffer
2549 * @lenp: the size of the user buffer
2550 * @ppos: file position
2552 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2553 * values from/to the user buffer, treated as an ASCII string.
2555 * This routine will ensure the values are within the range specified by
2556 * table->extra1 (min) and table->extra2 (max).
2558 * Returns 0 on success.
2560 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2561 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2563 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2567 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2568 * @table: the sysctl table
2569 * @write: %TRUE if this is a write to the sysctl file
2570 * @buffer: the user buffer
2571 * @lenp: the size of the user buffer
2572 * @ppos: file position
2574 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2575 * values from/to the user buffer, treated as an ASCII string. The values
2576 * are treated as milliseconds, and converted to jiffies when they are stored.
2578 * This routine will ensure the values are within the range specified by
2579 * table->extra1 (min) and table->extra2 (max).
2581 * Returns 0 on success.
2583 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2584 void __user
*buffer
,
2585 size_t *lenp
, loff_t
*ppos
)
2587 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2588 lenp
, ppos
, HZ
, 1000l);
2592 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2594 int write
, void *data
)
2597 if (*lvalp
> LONG_MAX
/ HZ
)
2599 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2605 lval
= (unsigned long)-val
;
2608 lval
= (unsigned long)val
;
2615 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2617 int write
, void *data
)
2620 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2622 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2628 lval
= (unsigned long)-val
;
2631 lval
= (unsigned long)val
;
2633 *lvalp
= jiffies_to_clock_t(lval
);
2638 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2640 int write
, void *data
)
2643 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2649 lval
= (unsigned long)-val
;
2652 lval
= (unsigned long)val
;
2654 *lvalp
= jiffies_to_msecs(lval
);
2660 * proc_dointvec_jiffies - read a vector of integers as seconds
2661 * @table: the sysctl table
2662 * @write: %TRUE if this is a write to the sysctl file
2663 * @buffer: the user buffer
2664 * @lenp: the size of the user buffer
2665 * @ppos: file position
2667 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2668 * values from/to the user buffer, treated as an ASCII string.
2669 * The values read are assumed to be in seconds, and are converted into
2672 * Returns 0 on success.
2674 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2675 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2677 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2678 do_proc_dointvec_jiffies_conv
,NULL
);
2682 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2683 * @table: the sysctl table
2684 * @write: %TRUE if this is a write to the sysctl file
2685 * @buffer: the user buffer
2686 * @lenp: the size of the user buffer
2687 * @ppos: pointer to the file position
2689 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2690 * values from/to the user buffer, treated as an ASCII string.
2691 * The values read are assumed to be in 1/USER_HZ seconds, and
2692 * are converted into jiffies.
2694 * Returns 0 on success.
2696 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2697 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2699 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2700 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2704 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2705 * @table: the sysctl table
2706 * @write: %TRUE if this is a write to the sysctl file
2707 * @buffer: the user buffer
2708 * @lenp: the size of the user buffer
2709 * @ppos: file position
2710 * @ppos: the current position in the file
2712 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2713 * values from/to the user buffer, treated as an ASCII string.
2714 * The values read are assumed to be in 1/1000 seconds, and
2715 * are converted into jiffies.
2717 * Returns 0 on success.
2719 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2720 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2722 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2723 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2726 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2727 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2729 struct pid
*new_pid
;
2733 tmp
= pid_vnr(cad_pid
);
2735 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2736 lenp
, ppos
, NULL
, NULL
);
2740 new_pid
= find_get_pid(tmp
);
2744 put_pid(xchg(&cad_pid
, new_pid
));
2749 * proc_do_large_bitmap - read/write from/to a large bitmap
2750 * @table: the sysctl table
2751 * @write: %TRUE if this is a write to the sysctl file
2752 * @buffer: the user buffer
2753 * @lenp: the size of the user buffer
2754 * @ppos: file position
2756 * The bitmap is stored at table->data and the bitmap length (in bits)
2759 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2760 * large bitmaps may be represented in a compact manner. Writing into
2761 * the file will clear the bitmap then update it with the given input.
2763 * Returns 0 on success.
2765 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2766 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2770 size_t left
= *lenp
;
2771 unsigned long bitmap_len
= table
->maxlen
;
2772 unsigned long *bitmap
= (unsigned long *) table
->data
;
2773 unsigned long *tmp_bitmap
= NULL
;
2774 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2776 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2782 unsigned long page
= 0;
2785 if (left
> PAGE_SIZE
- 1)
2786 left
= PAGE_SIZE
- 1;
2788 page
= __get_free_page(GFP_TEMPORARY
);
2789 kbuf
= (char *) page
;
2792 if (copy_from_user(kbuf
, buffer
, left
)) {
2798 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2804 proc_skip_char(&kbuf
, &left
, '\n');
2805 while (!err
&& left
) {
2806 unsigned long val_a
, val_b
;
2809 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2813 if (val_a
>= bitmap_len
|| neg
) {
2825 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2826 &neg
, tr_b
, sizeof(tr_b
),
2830 if (val_b
>= bitmap_len
|| neg
||
2841 while (val_a
<= val_b
)
2842 set_bit(val_a
++, tmp_bitmap
);
2845 proc_skip_char(&kbuf
, &left
, '\n');
2849 unsigned long bit_a
, bit_b
= 0;
2852 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2853 if (bit_a
>= bitmap_len
)
2855 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2859 err
= proc_put_char(&buffer
, &left
, ',');
2863 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2866 if (bit_a
!= bit_b
) {
2867 err
= proc_put_char(&buffer
, &left
, '-');
2870 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2878 err
= proc_put_char(&buffer
, &left
, '\n');
2884 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2886 memcpy(bitmap
, tmp_bitmap
,
2887 BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long));
2899 #else /* CONFIG_PROC_FS */
2901 int proc_dostring(struct ctl_table
*table
, int write
,
2902 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2907 int proc_dointvec(struct ctl_table
*table
, int write
,
2908 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2913 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2914 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2919 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2920 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2925 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2926 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2931 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2932 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2937 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2938 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2943 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2944 void __user
*buffer
,
2945 size_t *lenp
, loff_t
*ppos
)
2951 #endif /* CONFIG_PROC_FS */
2954 * No sense putting this after each symbol definition, twice,
2955 * exception granted :-)
2957 EXPORT_SYMBOL(proc_dointvec
);
2958 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2959 EXPORT_SYMBOL(proc_dointvec_minmax
);
2960 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2961 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2962 EXPORT_SYMBOL(proc_dostring
);
2963 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2964 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2965 EXPORT_SYMBOL(register_sysctl_table
);
2966 EXPORT_SYMBOL(register_sysctl_paths
);
2967 EXPORT_SYMBOL(unregister_sysctl_table
);