2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/signal.h>
27 #include <linux/printk.h>
28 #include <linux/proc_fs.h>
29 #include <linux/security.h>
30 #include <linux/ctype.h>
31 #include <linux/kmemcheck.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/ratelimit.h>
41 #include <linux/compaction.h>
42 #include <linux/hugetlb.h>
43 #include <linux/initrd.h>
44 #include <linux/key.h>
45 #include <linux/times.h>
46 #include <linux/limits.h>
47 #include <linux/dcache.h>
48 #include <linux/dnotify.h>
49 #include <linux/syscalls.h>
50 #include <linux/vmstat.h>
51 #include <linux/nfs_fs.h>
52 #include <linux/acpi.h>
53 #include <linux/reboot.h>
54 #include <linux/ftrace.h>
55 #include <linux/perf_event.h>
56 #include <linux/kprobes.h>
57 #include <linux/pipe_fs_i.h>
58 #include <linux/oom.h>
60 #include <asm/uaccess.h>
61 #include <asm/processor.h>
65 #include <asm/stacktrace.h>
68 #ifdef CONFIG_BSD_PROCESS_ACCT
69 #include <linux/acct.h>
71 #ifdef CONFIG_RT_MUTEXES
72 #include <linux/rtmutex.h>
74 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
75 #include <linux/lockdep.h>
77 #ifdef CONFIG_CHR_DEV_SG
81 #ifdef CONFIG_LOCKUP_DETECTOR
82 #include <linux/nmi.h>
86 #if defined(CONFIG_SYSCTL)
88 /* External variables not in a header file. */
89 extern int sysctl_overcommit_memory
;
90 extern int sysctl_overcommit_ratio
;
91 extern int max_threads
;
92 extern int core_uses_pid
;
93 extern int suid_dumpable
;
94 extern char core_pattern
[];
95 extern unsigned int core_pipe_limit
;
97 extern int min_free_kbytes
;
98 extern int pid_max_min
, pid_max_max
;
99 extern int sysctl_drop_caches
;
100 extern int percpu_pagelist_fraction
;
101 extern int compat_log
;
102 extern int latencytop_enabled
;
103 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
105 extern int sysctl_nr_trim_pages
;
108 extern int blk_iopoll_enabled
;
111 /* Constants used for minimum and maximum */
112 #ifdef CONFIG_LOCKUP_DETECTOR
113 static int sixty
= 60;
114 static int neg_one
= -1;
118 static int __maybe_unused one
= 1;
119 static int __maybe_unused two
= 2;
120 static int __maybe_unused three
= 3;
121 static unsigned long one_ul
= 1;
122 static int one_hundred
= 100;
124 static int ten_thousand
= 10000;
127 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
128 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
130 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
131 static int maxolduid
= 65535;
132 static int minolduid
;
133 static int min_percpu_pagelist_fract
= 8;
135 static int ngroups_max
= NGROUPS_MAX
;
137 #ifdef CONFIG_INOTIFY_USER
138 #include <linux/inotify.h>
141 #include <asm/system.h>
144 #ifdef CONFIG_SPARC64
145 extern int sysctl_tsb_ratio
;
149 extern int pwrsw_enabled
;
150 extern int unaligned_enabled
;
154 #ifdef CONFIG_MATHEMU
155 extern int sysctl_ieee_emulation_warnings
;
157 extern int sysctl_userprocess_debug
;
158 extern int spin_retry
;
162 extern int no_unaligned_warning
;
163 extern int unaligned_dump_stack
;
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
);
174 static int proc_dmesg_restrict(struct ctl_table
*table
, int write
,
175 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
178 #ifdef CONFIG_MAGIC_SYSRQ
179 /* Note: sysrq code uses it's own private copy */
180 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
182 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
183 void __user
*buffer
, size_t *lenp
,
188 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
193 sysrq_toggle_support(__sysrq_enabled
);
200 static struct ctl_table root_table
[];
201 static struct ctl_table_root sysctl_table_root
;
202 static struct ctl_table_header root_table_header
= {
204 .ctl_table
= root_table
,
205 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),}},
206 .root
= &sysctl_table_root
,
207 .set
= &sysctl_table_root
.default_set
,
209 static struct ctl_table_root sysctl_table_root
= {
210 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
211 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
214 static struct ctl_table kern_table
[];
215 static struct ctl_table vm_table
[];
216 static struct ctl_table fs_table
[];
217 static struct ctl_table debug_table
[];
218 static struct ctl_table dev_table
[];
219 extern struct ctl_table random_table
[];
221 extern struct ctl_table epoll_table
[];
224 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
225 int sysctl_legacy_va_layout
;
228 /* The default sysctl tables: */
230 static struct ctl_table root_table
[] = {
232 .procname
= "kernel",
249 .child
= debug_table
,
259 #ifdef CONFIG_SCHED_DEBUG
260 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
261 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
262 static int min_wakeup_granularity_ns
; /* 0 usecs */
263 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
264 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
265 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
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_tunable_scaling",
311 .data
= &sysctl_sched_tunable_scaling
,
312 .maxlen
= sizeof(enum sched_tunable_scaling
),
314 .proc_handler
= sched_proc_update_handler
,
315 .extra1
= &min_sched_tunable_scaling
,
316 .extra2
= &max_sched_tunable_scaling
,
319 .procname
= "sched_migration_cost",
320 .data
= &sysctl_sched_migration_cost
,
321 .maxlen
= sizeof(unsigned int),
323 .proc_handler
= proc_dointvec
,
326 .procname
= "sched_nr_migrate",
327 .data
= &sysctl_sched_nr_migrate
,
328 .maxlen
= sizeof(unsigned int),
330 .proc_handler
= proc_dointvec
,
333 .procname
= "sched_time_avg",
334 .data
= &sysctl_sched_time_avg
,
335 .maxlen
= sizeof(unsigned int),
337 .proc_handler
= proc_dointvec
,
340 .procname
= "sched_shares_window",
341 .data
= &sysctl_sched_shares_window
,
342 .maxlen
= sizeof(unsigned int),
344 .proc_handler
= proc_dointvec
,
347 .procname
= "timer_migration",
348 .data
= &sysctl_timer_migration
,
349 .maxlen
= sizeof(unsigned int),
351 .proc_handler
= proc_dointvec_minmax
,
357 .procname
= "sched_rt_period_us",
358 .data
= &sysctl_sched_rt_period
,
359 .maxlen
= sizeof(unsigned int),
361 .proc_handler
= sched_rt_handler
,
364 .procname
= "sched_rt_runtime_us",
365 .data
= &sysctl_sched_rt_runtime
,
366 .maxlen
= sizeof(int),
368 .proc_handler
= sched_rt_handler
,
370 #ifdef CONFIG_SCHED_AUTOGROUP
372 .procname
= "sched_autogroup_enabled",
373 .data
= &sysctl_sched_autogroup_enabled
,
374 .maxlen
= sizeof(unsigned int),
376 .proc_handler
= proc_dointvec_minmax
,
381 #ifdef CONFIG_PROVE_LOCKING
383 .procname
= "prove_locking",
384 .data
= &prove_locking
,
385 .maxlen
= sizeof(int),
387 .proc_handler
= proc_dointvec
,
390 #ifdef CONFIG_LOCK_STAT
392 .procname
= "lock_stat",
394 .maxlen
= sizeof(int),
396 .proc_handler
= proc_dointvec
,
401 .data
= &panic_timeout
,
402 .maxlen
= sizeof(int),
404 .proc_handler
= proc_dointvec
,
407 .procname
= "core_uses_pid",
408 .data
= &core_uses_pid
,
409 .maxlen
= sizeof(int),
411 .proc_handler
= proc_dointvec
,
414 .procname
= "core_pattern",
415 .data
= core_pattern
,
416 .maxlen
= CORENAME_MAX_SIZE
,
418 .proc_handler
= proc_dostring
,
421 .procname
= "core_pipe_limit",
422 .data
= &core_pipe_limit
,
423 .maxlen
= sizeof(unsigned int),
425 .proc_handler
= proc_dointvec
,
427 #ifdef CONFIG_PROC_SYSCTL
429 .procname
= "tainted",
430 .maxlen
= sizeof(long),
432 .proc_handler
= proc_taint
,
435 #ifdef CONFIG_LATENCYTOP
437 .procname
= "latencytop",
438 .data
= &latencytop_enabled
,
439 .maxlen
= sizeof(int),
441 .proc_handler
= proc_dointvec
,
444 #ifdef CONFIG_BLK_DEV_INITRD
446 .procname
= "real-root-dev",
447 .data
= &real_root_dev
,
448 .maxlen
= sizeof(int),
450 .proc_handler
= proc_dointvec
,
454 .procname
= "print-fatal-signals",
455 .data
= &print_fatal_signals
,
456 .maxlen
= sizeof(int),
458 .proc_handler
= proc_dointvec
,
462 .procname
= "reboot-cmd",
463 .data
= reboot_command
,
466 .proc_handler
= proc_dostring
,
469 .procname
= "stop-a",
470 .data
= &stop_a_enabled
,
471 .maxlen
= sizeof (int),
473 .proc_handler
= proc_dointvec
,
476 .procname
= "scons-poweroff",
477 .data
= &scons_pwroff
,
478 .maxlen
= sizeof (int),
480 .proc_handler
= proc_dointvec
,
483 #ifdef CONFIG_SPARC64
485 .procname
= "tsb-ratio",
486 .data
= &sysctl_tsb_ratio
,
487 .maxlen
= sizeof (int),
489 .proc_handler
= proc_dointvec
,
494 .procname
= "soft-power",
495 .data
= &pwrsw_enabled
,
496 .maxlen
= sizeof (int),
498 .proc_handler
= proc_dointvec
,
501 .procname
= "unaligned-trap",
502 .data
= &unaligned_enabled
,
503 .maxlen
= sizeof (int),
505 .proc_handler
= proc_dointvec
,
509 .procname
= "ctrl-alt-del",
511 .maxlen
= sizeof(int),
513 .proc_handler
= proc_dointvec
,
515 #ifdef CONFIG_FUNCTION_TRACER
517 .procname
= "ftrace_enabled",
518 .data
= &ftrace_enabled
,
519 .maxlen
= sizeof(int),
521 .proc_handler
= ftrace_enable_sysctl
,
524 #ifdef CONFIG_STACK_TRACER
526 .procname
= "stack_tracer_enabled",
527 .data
= &stack_tracer_enabled
,
528 .maxlen
= sizeof(int),
530 .proc_handler
= stack_trace_sysctl
,
533 #ifdef CONFIG_TRACING
535 .procname
= "ftrace_dump_on_oops",
536 .data
= &ftrace_dump_on_oops
,
537 .maxlen
= sizeof(int),
539 .proc_handler
= proc_dointvec
,
542 #ifdef CONFIG_MODULES
544 .procname
= "modprobe",
545 .data
= &modprobe_path
,
546 .maxlen
= KMOD_PATH_LEN
,
548 .proc_handler
= proc_dostring
,
551 .procname
= "modules_disabled",
552 .data
= &modules_disabled
,
553 .maxlen
= sizeof(int),
555 /* only handle a transition from default "0" to "1" */
556 .proc_handler
= proc_dointvec_minmax
,
561 #ifdef CONFIG_HOTPLUG
563 .procname
= "hotplug",
564 .data
= &uevent_helper
,
565 .maxlen
= UEVENT_HELPER_PATH_LEN
,
567 .proc_handler
= proc_dostring
,
570 #ifdef CONFIG_CHR_DEV_SG
572 .procname
= "sg-big-buff",
573 .data
= &sg_big_buff
,
574 .maxlen
= sizeof (int),
576 .proc_handler
= proc_dointvec
,
579 #ifdef CONFIG_BSD_PROCESS_ACCT
583 .maxlen
= 3*sizeof(int),
585 .proc_handler
= proc_dointvec
,
588 #ifdef CONFIG_MAGIC_SYSRQ
591 .data
= &__sysrq_enabled
,
592 .maxlen
= sizeof (int),
594 .proc_handler
= sysrq_sysctl_handler
,
597 #ifdef CONFIG_PROC_SYSCTL
599 .procname
= "cad_pid",
601 .maxlen
= sizeof (int),
603 .proc_handler
= proc_do_cad_pid
,
607 .procname
= "threads-max",
608 .data
= &max_threads
,
609 .maxlen
= sizeof(int),
611 .proc_handler
= proc_dointvec
,
614 .procname
= "random",
616 .child
= random_table
,
619 .procname
= "overflowuid",
620 .data
= &overflowuid
,
621 .maxlen
= sizeof(int),
623 .proc_handler
= proc_dointvec_minmax
,
624 .extra1
= &minolduid
,
625 .extra2
= &maxolduid
,
628 .procname
= "overflowgid",
629 .data
= &overflowgid
,
630 .maxlen
= sizeof(int),
632 .proc_handler
= proc_dointvec_minmax
,
633 .extra1
= &minolduid
,
634 .extra2
= &maxolduid
,
637 #ifdef CONFIG_MATHEMU
639 .procname
= "ieee_emulation_warnings",
640 .data
= &sysctl_ieee_emulation_warnings
,
641 .maxlen
= sizeof(int),
643 .proc_handler
= proc_dointvec
,
647 .procname
= "userprocess_debug",
648 .data
= &show_unhandled_signals
,
649 .maxlen
= sizeof(int),
651 .proc_handler
= proc_dointvec
,
655 .procname
= "pid_max",
657 .maxlen
= sizeof (int),
659 .proc_handler
= proc_dointvec_minmax
,
660 .extra1
= &pid_max_min
,
661 .extra2
= &pid_max_max
,
664 .procname
= "panic_on_oops",
665 .data
= &panic_on_oops
,
666 .maxlen
= sizeof(int),
668 .proc_handler
= proc_dointvec
,
670 #if defined CONFIG_PRINTK
672 .procname
= "printk",
673 .data
= &console_loglevel
,
674 .maxlen
= 4*sizeof(int),
676 .proc_handler
= proc_dointvec
,
679 .procname
= "printk_ratelimit",
680 .data
= &printk_ratelimit_state
.interval
,
681 .maxlen
= sizeof(int),
683 .proc_handler
= proc_dointvec_jiffies
,
686 .procname
= "printk_ratelimit_burst",
687 .data
= &printk_ratelimit_state
.burst
,
688 .maxlen
= sizeof(int),
690 .proc_handler
= proc_dointvec
,
693 .procname
= "printk_delay",
694 .data
= &printk_delay_msec
,
695 .maxlen
= sizeof(int),
697 .proc_handler
= proc_dointvec_minmax
,
699 .extra2
= &ten_thousand
,
702 .procname
= "dmesg_restrict",
703 .data
= &dmesg_restrict
,
704 .maxlen
= sizeof(int),
706 .proc_handler
= proc_dointvec_minmax
,
711 .procname
= "kptr_restrict",
712 .data
= &kptr_restrict
,
713 .maxlen
= sizeof(int),
715 .proc_handler
= proc_dmesg_restrict
,
721 .procname
= "ngroups_max",
722 .data
= &ngroups_max
,
723 .maxlen
= sizeof (int),
725 .proc_handler
= proc_dointvec
,
727 #if defined(CONFIG_LOCKUP_DETECTOR)
729 .procname
= "watchdog",
730 .data
= &watchdog_enabled
,
731 .maxlen
= sizeof (int),
733 .proc_handler
= proc_dowatchdog
,
738 .procname
= "watchdog_thresh",
739 .data
= &watchdog_thresh
,
740 .maxlen
= sizeof(int),
742 .proc_handler
= proc_dowatchdog
,
747 .procname
= "softlockup_panic",
748 .data
= &softlockup_panic
,
749 .maxlen
= sizeof(int),
751 .proc_handler
= proc_dointvec_minmax
,
756 .procname
= "nmi_watchdog",
757 .data
= &watchdog_enabled
,
758 .maxlen
= sizeof (int),
760 .proc_handler
= proc_dowatchdog
,
765 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
767 .procname
= "unknown_nmi_panic",
768 .data
= &unknown_nmi_panic
,
769 .maxlen
= sizeof (int),
771 .proc_handler
= proc_dointvec
,
774 #if defined(CONFIG_X86)
776 .procname
= "panic_on_unrecovered_nmi",
777 .data
= &panic_on_unrecovered_nmi
,
778 .maxlen
= sizeof(int),
780 .proc_handler
= proc_dointvec
,
783 .procname
= "panic_on_io_nmi",
784 .data
= &panic_on_io_nmi
,
785 .maxlen
= sizeof(int),
787 .proc_handler
= proc_dointvec
,
790 .procname
= "bootloader_type",
791 .data
= &bootloader_type
,
792 .maxlen
= sizeof (int),
794 .proc_handler
= proc_dointvec
,
797 .procname
= "bootloader_version",
798 .data
= &bootloader_version
,
799 .maxlen
= sizeof (int),
801 .proc_handler
= proc_dointvec
,
804 .procname
= "kstack_depth_to_print",
805 .data
= &kstack_depth_to_print
,
806 .maxlen
= sizeof(int),
808 .proc_handler
= proc_dointvec
,
811 .procname
= "io_delay_type",
812 .data
= &io_delay_type
,
813 .maxlen
= sizeof(int),
815 .proc_handler
= proc_dointvec
,
818 #if defined(CONFIG_MMU)
820 .procname
= "randomize_va_space",
821 .data
= &randomize_va_space
,
822 .maxlen
= sizeof(int),
824 .proc_handler
= proc_dointvec
,
827 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
829 .procname
= "spin_retry",
831 .maxlen
= sizeof (int),
833 .proc_handler
= proc_dointvec
,
836 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
838 .procname
= "acpi_video_flags",
839 .data
= &acpi_realmode_flags
,
840 .maxlen
= sizeof (unsigned long),
842 .proc_handler
= proc_doulongvec_minmax
,
847 .procname
= "ignore-unaligned-usertrap",
848 .data
= &no_unaligned_warning
,
849 .maxlen
= sizeof (int),
851 .proc_handler
= proc_dointvec
,
854 .procname
= "unaligned-dump-stack",
855 .data
= &unaligned_dump_stack
,
856 .maxlen
= sizeof (int),
858 .proc_handler
= proc_dointvec
,
861 #ifdef CONFIG_DETECT_HUNG_TASK
863 .procname
= "hung_task_panic",
864 .data
= &sysctl_hung_task_panic
,
865 .maxlen
= sizeof(int),
867 .proc_handler
= proc_dointvec_minmax
,
872 .procname
= "hung_task_check_count",
873 .data
= &sysctl_hung_task_check_count
,
874 .maxlen
= sizeof(unsigned long),
876 .proc_handler
= proc_doulongvec_minmax
,
879 .procname
= "hung_task_timeout_secs",
880 .data
= &sysctl_hung_task_timeout_secs
,
881 .maxlen
= sizeof(unsigned long),
883 .proc_handler
= proc_dohung_task_timeout_secs
,
886 .procname
= "hung_task_warnings",
887 .data
= &sysctl_hung_task_warnings
,
888 .maxlen
= sizeof(unsigned long),
890 .proc_handler
= proc_doulongvec_minmax
,
895 .procname
= "compat-log",
897 .maxlen
= sizeof (int),
899 .proc_handler
= proc_dointvec
,
902 #ifdef CONFIG_RT_MUTEXES
904 .procname
= "max_lock_depth",
905 .data
= &max_lock_depth
,
906 .maxlen
= sizeof(int),
908 .proc_handler
= proc_dointvec
,
912 .procname
= "poweroff_cmd",
913 .data
= &poweroff_cmd
,
914 .maxlen
= POWEROFF_CMD_PATH_LEN
,
916 .proc_handler
= proc_dostring
,
922 .child
= key_sysctls
,
925 #ifdef CONFIG_RCU_TORTURE_TEST
927 .procname
= "rcutorture_runnable",
928 .data
= &rcutorture_runnable
,
929 .maxlen
= sizeof(int),
931 .proc_handler
= proc_dointvec
,
934 #ifdef CONFIG_PERF_EVENTS
936 .procname
= "perf_event_paranoid",
937 .data
= &sysctl_perf_event_paranoid
,
938 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
940 .proc_handler
= proc_dointvec
,
943 .procname
= "perf_event_mlock_kb",
944 .data
= &sysctl_perf_event_mlock
,
945 .maxlen
= sizeof(sysctl_perf_event_mlock
),
947 .proc_handler
= proc_dointvec
,
950 .procname
= "perf_event_max_sample_rate",
951 .data
= &sysctl_perf_event_sample_rate
,
952 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
954 .proc_handler
= perf_proc_update_handler
,
957 #ifdef CONFIG_KMEMCHECK
959 .procname
= "kmemcheck",
960 .data
= &kmemcheck_enabled
,
961 .maxlen
= sizeof(int),
963 .proc_handler
= proc_dointvec
,
968 .procname
= "blk_iopoll",
969 .data
= &blk_iopoll_enabled
,
970 .maxlen
= sizeof(int),
972 .proc_handler
= proc_dointvec
,
978 static struct ctl_table vm_table
[] = {
980 .procname
= "overcommit_memory",
981 .data
= &sysctl_overcommit_memory
,
982 .maxlen
= sizeof(sysctl_overcommit_memory
),
984 .proc_handler
= proc_dointvec_minmax
,
989 .procname
= "panic_on_oom",
990 .data
= &sysctl_panic_on_oom
,
991 .maxlen
= sizeof(sysctl_panic_on_oom
),
993 .proc_handler
= proc_dointvec_minmax
,
998 .procname
= "oom_kill_allocating_task",
999 .data
= &sysctl_oom_kill_allocating_task
,
1000 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1002 .proc_handler
= proc_dointvec
,
1005 .procname
= "oom_dump_tasks",
1006 .data
= &sysctl_oom_dump_tasks
,
1007 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1009 .proc_handler
= proc_dointvec
,
1012 .procname
= "overcommit_ratio",
1013 .data
= &sysctl_overcommit_ratio
,
1014 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1016 .proc_handler
= proc_dointvec
,
1019 .procname
= "page-cluster",
1020 .data
= &page_cluster
,
1021 .maxlen
= sizeof(int),
1023 .proc_handler
= proc_dointvec_minmax
,
1027 .procname
= "dirty_background_ratio",
1028 .data
= &dirty_background_ratio
,
1029 .maxlen
= sizeof(dirty_background_ratio
),
1031 .proc_handler
= dirty_background_ratio_handler
,
1033 .extra2
= &one_hundred
,
1036 .procname
= "dirty_background_bytes",
1037 .data
= &dirty_background_bytes
,
1038 .maxlen
= sizeof(dirty_background_bytes
),
1040 .proc_handler
= dirty_background_bytes_handler
,
1044 .procname
= "dirty_ratio",
1045 .data
= &vm_dirty_ratio
,
1046 .maxlen
= sizeof(vm_dirty_ratio
),
1048 .proc_handler
= dirty_ratio_handler
,
1050 .extra2
= &one_hundred
,
1053 .procname
= "dirty_bytes",
1054 .data
= &vm_dirty_bytes
,
1055 .maxlen
= sizeof(vm_dirty_bytes
),
1057 .proc_handler
= dirty_bytes_handler
,
1058 .extra1
= &dirty_bytes_min
,
1061 .procname
= "dirty_writeback_centisecs",
1062 .data
= &dirty_writeback_interval
,
1063 .maxlen
= sizeof(dirty_writeback_interval
),
1065 .proc_handler
= dirty_writeback_centisecs_handler
,
1068 .procname
= "dirty_expire_centisecs",
1069 .data
= &dirty_expire_interval
,
1070 .maxlen
= sizeof(dirty_expire_interval
),
1072 .proc_handler
= proc_dointvec_minmax
,
1076 .procname
= "nr_pdflush_threads",
1077 .data
= &nr_pdflush_threads
,
1078 .maxlen
= sizeof nr_pdflush_threads
,
1079 .mode
= 0444 /* read-only*/,
1080 .proc_handler
= proc_dointvec
,
1083 .procname
= "swappiness",
1084 .data
= &vm_swappiness
,
1085 .maxlen
= sizeof(vm_swappiness
),
1087 .proc_handler
= proc_dointvec_minmax
,
1089 .extra2
= &one_hundred
,
1091 #ifdef CONFIG_HUGETLB_PAGE
1093 .procname
= "nr_hugepages",
1095 .maxlen
= sizeof(unsigned long),
1097 .proc_handler
= hugetlb_sysctl_handler
,
1098 .extra1
= (void *)&hugetlb_zero
,
1099 .extra2
= (void *)&hugetlb_infinity
,
1103 .procname
= "nr_hugepages_mempolicy",
1105 .maxlen
= sizeof(unsigned long),
1107 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1108 .extra1
= (void *)&hugetlb_zero
,
1109 .extra2
= (void *)&hugetlb_infinity
,
1113 .procname
= "hugetlb_shm_group",
1114 .data
= &sysctl_hugetlb_shm_group
,
1115 .maxlen
= sizeof(gid_t
),
1117 .proc_handler
= proc_dointvec
,
1120 .procname
= "hugepages_treat_as_movable",
1121 .data
= &hugepages_treat_as_movable
,
1122 .maxlen
= sizeof(int),
1124 .proc_handler
= hugetlb_treat_movable_handler
,
1127 .procname
= "nr_overcommit_hugepages",
1129 .maxlen
= sizeof(unsigned long),
1131 .proc_handler
= hugetlb_overcommit_handler
,
1132 .extra1
= (void *)&hugetlb_zero
,
1133 .extra2
= (void *)&hugetlb_infinity
,
1137 .procname
= "lowmem_reserve_ratio",
1138 .data
= &sysctl_lowmem_reserve_ratio
,
1139 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1141 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1144 .procname
= "drop_caches",
1145 .data
= &sysctl_drop_caches
,
1146 .maxlen
= sizeof(int),
1148 .proc_handler
= drop_caches_sysctl_handler
,
1152 #ifdef CONFIG_COMPACTION
1154 .procname
= "compact_memory",
1155 .data
= &sysctl_compact_memory
,
1156 .maxlen
= sizeof(int),
1158 .proc_handler
= sysctl_compaction_handler
,
1161 .procname
= "extfrag_threshold",
1162 .data
= &sysctl_extfrag_threshold
,
1163 .maxlen
= sizeof(int),
1165 .proc_handler
= sysctl_extfrag_handler
,
1166 .extra1
= &min_extfrag_threshold
,
1167 .extra2
= &max_extfrag_threshold
,
1170 #endif /* CONFIG_COMPACTION */
1172 .procname
= "min_free_kbytes",
1173 .data
= &min_free_kbytes
,
1174 .maxlen
= sizeof(min_free_kbytes
),
1176 .proc_handler
= min_free_kbytes_sysctl_handler
,
1180 .procname
= "percpu_pagelist_fraction",
1181 .data
= &percpu_pagelist_fraction
,
1182 .maxlen
= sizeof(percpu_pagelist_fraction
),
1184 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1185 .extra1
= &min_percpu_pagelist_fract
,
1189 .procname
= "max_map_count",
1190 .data
= &sysctl_max_map_count
,
1191 .maxlen
= sizeof(sysctl_max_map_count
),
1193 .proc_handler
= proc_dointvec_minmax
,
1198 .procname
= "nr_trim_pages",
1199 .data
= &sysctl_nr_trim_pages
,
1200 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1202 .proc_handler
= proc_dointvec_minmax
,
1207 .procname
= "laptop_mode",
1208 .data
= &laptop_mode
,
1209 .maxlen
= sizeof(laptop_mode
),
1211 .proc_handler
= proc_dointvec_jiffies
,
1214 .procname
= "block_dump",
1215 .data
= &block_dump
,
1216 .maxlen
= sizeof(block_dump
),
1218 .proc_handler
= proc_dointvec
,
1222 .procname
= "vfs_cache_pressure",
1223 .data
= &sysctl_vfs_cache_pressure
,
1224 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1226 .proc_handler
= proc_dointvec
,
1229 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1231 .procname
= "legacy_va_layout",
1232 .data
= &sysctl_legacy_va_layout
,
1233 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1235 .proc_handler
= proc_dointvec
,
1241 .procname
= "zone_reclaim_mode",
1242 .data
= &zone_reclaim_mode
,
1243 .maxlen
= sizeof(zone_reclaim_mode
),
1245 .proc_handler
= proc_dointvec
,
1249 .procname
= "min_unmapped_ratio",
1250 .data
= &sysctl_min_unmapped_ratio
,
1251 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1253 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1255 .extra2
= &one_hundred
,
1258 .procname
= "min_slab_ratio",
1259 .data
= &sysctl_min_slab_ratio
,
1260 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1262 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1264 .extra2
= &one_hundred
,
1269 .procname
= "stat_interval",
1270 .data
= &sysctl_stat_interval
,
1271 .maxlen
= sizeof(sysctl_stat_interval
),
1273 .proc_handler
= proc_dointvec_jiffies
,
1278 .procname
= "mmap_min_addr",
1279 .data
= &dac_mmap_min_addr
,
1280 .maxlen
= sizeof(unsigned long),
1282 .proc_handler
= mmap_min_addr_handler
,
1287 .procname
= "numa_zonelist_order",
1288 .data
= &numa_zonelist_order
,
1289 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1291 .proc_handler
= numa_zonelist_order_handler
,
1294 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1295 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1297 .procname
= "vdso_enabled",
1298 .data
= &vdso_enabled
,
1299 .maxlen
= sizeof(vdso_enabled
),
1301 .proc_handler
= proc_dointvec
,
1305 #ifdef CONFIG_HIGHMEM
1307 .procname
= "highmem_is_dirtyable",
1308 .data
= &vm_highmem_is_dirtyable
,
1309 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1311 .proc_handler
= proc_dointvec_minmax
,
1317 .procname
= "scan_unevictable_pages",
1318 .data
= &scan_unevictable_pages
,
1319 .maxlen
= sizeof(scan_unevictable_pages
),
1321 .proc_handler
= scan_unevictable_handler
,
1323 #ifdef CONFIG_MEMORY_FAILURE
1325 .procname
= "memory_failure_early_kill",
1326 .data
= &sysctl_memory_failure_early_kill
,
1327 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1329 .proc_handler
= proc_dointvec_minmax
,
1334 .procname
= "memory_failure_recovery",
1335 .data
= &sysctl_memory_failure_recovery
,
1336 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1338 .proc_handler
= proc_dointvec_minmax
,
1346 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1347 static struct ctl_table binfmt_misc_table
[] = {
1352 static struct ctl_table fs_table
[] = {
1354 .procname
= "inode-nr",
1355 .data
= &inodes_stat
,
1356 .maxlen
= 2*sizeof(int),
1358 .proc_handler
= proc_nr_inodes
,
1361 .procname
= "inode-state",
1362 .data
= &inodes_stat
,
1363 .maxlen
= 7*sizeof(int),
1365 .proc_handler
= proc_nr_inodes
,
1368 .procname
= "file-nr",
1369 .data
= &files_stat
,
1370 .maxlen
= sizeof(files_stat
),
1372 .proc_handler
= proc_nr_files
,
1375 .procname
= "file-max",
1376 .data
= &files_stat
.max_files
,
1377 .maxlen
= sizeof(files_stat
.max_files
),
1379 .proc_handler
= proc_doulongvec_minmax
,
1382 .procname
= "nr_open",
1383 .data
= &sysctl_nr_open
,
1384 .maxlen
= sizeof(int),
1386 .proc_handler
= proc_dointvec_minmax
,
1387 .extra1
= &sysctl_nr_open_min
,
1388 .extra2
= &sysctl_nr_open_max
,
1391 .procname
= "dentry-state",
1392 .data
= &dentry_stat
,
1393 .maxlen
= 6*sizeof(int),
1395 .proc_handler
= proc_nr_dentry
,
1398 .procname
= "overflowuid",
1399 .data
= &fs_overflowuid
,
1400 .maxlen
= sizeof(int),
1402 .proc_handler
= proc_dointvec_minmax
,
1403 .extra1
= &minolduid
,
1404 .extra2
= &maxolduid
,
1407 .procname
= "overflowgid",
1408 .data
= &fs_overflowgid
,
1409 .maxlen
= sizeof(int),
1411 .proc_handler
= proc_dointvec_minmax
,
1412 .extra1
= &minolduid
,
1413 .extra2
= &maxolduid
,
1415 #ifdef CONFIG_FILE_LOCKING
1417 .procname
= "leases-enable",
1418 .data
= &leases_enable
,
1419 .maxlen
= sizeof(int),
1421 .proc_handler
= proc_dointvec
,
1424 #ifdef CONFIG_DNOTIFY
1426 .procname
= "dir-notify-enable",
1427 .data
= &dir_notify_enable
,
1428 .maxlen
= sizeof(int),
1430 .proc_handler
= proc_dointvec
,
1434 #ifdef CONFIG_FILE_LOCKING
1436 .procname
= "lease-break-time",
1437 .data
= &lease_break_time
,
1438 .maxlen
= sizeof(int),
1440 .proc_handler
= proc_dointvec
,
1445 .procname
= "aio-nr",
1447 .maxlen
= sizeof(aio_nr
),
1449 .proc_handler
= proc_doulongvec_minmax
,
1452 .procname
= "aio-max-nr",
1453 .data
= &aio_max_nr
,
1454 .maxlen
= sizeof(aio_max_nr
),
1456 .proc_handler
= proc_doulongvec_minmax
,
1458 #endif /* CONFIG_AIO */
1459 #ifdef CONFIG_INOTIFY_USER
1461 .procname
= "inotify",
1463 .child
= inotify_table
,
1468 .procname
= "epoll",
1470 .child
= epoll_table
,
1475 .procname
= "suid_dumpable",
1476 .data
= &suid_dumpable
,
1477 .maxlen
= sizeof(int),
1479 .proc_handler
= proc_dointvec_minmax
,
1483 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1485 .procname
= "binfmt_misc",
1487 .child
= binfmt_misc_table
,
1491 .procname
= "pipe-max-size",
1492 .data
= &pipe_max_size
,
1493 .maxlen
= sizeof(int),
1495 .proc_handler
= &pipe_proc_fn
,
1496 .extra1
= &pipe_min_size
,
1501 static struct ctl_table debug_table
[] = {
1502 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1503 defined(CONFIG_S390)
1505 .procname
= "exception-trace",
1506 .data
= &show_unhandled_signals
,
1507 .maxlen
= sizeof(int),
1509 .proc_handler
= proc_dointvec
1512 #if defined(CONFIG_OPTPROBES)
1514 .procname
= "kprobes-optimization",
1515 .data
= &sysctl_kprobes_optimization
,
1516 .maxlen
= sizeof(int),
1518 .proc_handler
= proc_kprobes_optimization_handler
,
1526 static struct ctl_table dev_table
[] = {
1530 static DEFINE_SPINLOCK(sysctl_lock
);
1532 /* called under sysctl_lock */
1533 static int use_table(struct ctl_table_header
*p
)
1535 if (unlikely(p
->unregistering
))
1541 /* called under sysctl_lock */
1542 static void unuse_table(struct ctl_table_header
*p
)
1545 if (unlikely(p
->unregistering
))
1546 complete(p
->unregistering
);
1549 /* called under sysctl_lock, will reacquire if has to wait */
1550 static void start_unregistering(struct ctl_table_header
*p
)
1553 * if p->used is 0, nobody will ever touch that entry again;
1554 * we'll eliminate all paths to it before dropping sysctl_lock
1556 if (unlikely(p
->used
)) {
1557 struct completion wait
;
1558 init_completion(&wait
);
1559 p
->unregistering
= &wait
;
1560 spin_unlock(&sysctl_lock
);
1561 wait_for_completion(&wait
);
1562 spin_lock(&sysctl_lock
);
1564 /* anything non-NULL; we'll never dereference it */
1565 p
->unregistering
= ERR_PTR(-EINVAL
);
1568 * do not remove from the list until nobody holds it; walking the
1569 * list in do_sysctl() relies on that.
1571 list_del_init(&p
->ctl_entry
);
1574 void sysctl_head_get(struct ctl_table_header
*head
)
1576 spin_lock(&sysctl_lock
);
1578 spin_unlock(&sysctl_lock
);
1581 static void free_head(struct rcu_head
*rcu
)
1583 kfree(container_of(rcu
, struct ctl_table_header
, rcu
));
1586 void sysctl_head_put(struct ctl_table_header
*head
)
1588 spin_lock(&sysctl_lock
);
1590 call_rcu(&head
->rcu
, free_head
);
1591 spin_unlock(&sysctl_lock
);
1594 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1598 spin_lock(&sysctl_lock
);
1599 if (!use_table(head
))
1600 head
= ERR_PTR(-ENOENT
);
1601 spin_unlock(&sysctl_lock
);
1605 void sysctl_head_finish(struct ctl_table_header
*head
)
1609 spin_lock(&sysctl_lock
);
1611 spin_unlock(&sysctl_lock
);
1614 static struct ctl_table_set
*
1615 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1617 struct ctl_table_set
*set
= &root
->default_set
;
1619 set
= root
->lookup(root
, namespaces
);
1623 static struct list_head
*
1624 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1626 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1630 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1631 struct ctl_table_header
*prev
)
1633 struct ctl_table_root
*root
;
1634 struct list_head
*header_list
;
1635 struct ctl_table_header
*head
;
1636 struct list_head
*tmp
;
1638 spin_lock(&sysctl_lock
);
1641 tmp
= &prev
->ctl_entry
;
1645 tmp
= &root_table_header
.ctl_entry
;
1647 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1649 if (!use_table(head
))
1651 spin_unlock(&sysctl_lock
);
1656 header_list
= lookup_header_list(root
, namespaces
);
1657 if (tmp
!= header_list
)
1661 root
= list_entry(root
->root_list
.next
,
1662 struct ctl_table_root
, root_list
);
1663 if (root
== &sysctl_table_root
)
1665 header_list
= lookup_header_list(root
, namespaces
);
1666 } while (list_empty(header_list
));
1667 tmp
= header_list
->next
;
1670 spin_unlock(&sysctl_lock
);
1674 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1676 return __sysctl_head_next(current
->nsproxy
, prev
);
1679 void register_sysctl_root(struct ctl_table_root
*root
)
1681 spin_lock(&sysctl_lock
);
1682 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1683 spin_unlock(&sysctl_lock
);
1687 * sysctl_perm does NOT grant the superuser all rights automatically, because
1688 * some sysctl variables are readonly even to root.
1691 static int test_perm(int mode
, int op
)
1693 if (!current_euid())
1695 else if (in_egroup_p(0))
1697 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1702 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1706 if (root
->permissions
)
1707 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1711 return test_perm(mode
, op
);
1714 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1716 for (; table
->procname
; table
++) {
1717 table
->parent
= parent
;
1719 sysctl_set_parent(table
, table
->child
);
1723 static __init
int sysctl_init(void)
1725 sysctl_set_parent(NULL
, root_table
);
1726 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1727 sysctl_check_table(current
->nsproxy
, root_table
);
1732 core_initcall(sysctl_init
);
1734 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1735 struct ctl_table
*table
)
1737 struct ctl_table
*p
;
1738 const char *s
= branch
->procname
;
1740 /* branch should have named subdirectory as its first element */
1741 if (!s
|| !branch
->child
)
1744 /* ... and nothing else */
1745 if (branch
[1].procname
)
1748 /* table should contain subdirectory with the same name */
1749 for (p
= table
; p
->procname
; p
++) {
1752 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1758 /* see if attaching q to p would be an improvement */
1759 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1761 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1762 struct ctl_table
*next
;
1764 int not_in_parent
= !p
->attached_by
;
1766 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1767 if (by
== q
->attached_by
)
1769 if (to
== p
->attached_by
)
1775 if (is_better
&& not_in_parent
) {
1776 q
->attached_by
= by
;
1777 q
->attached_to
= to
;
1783 * __register_sysctl_paths - register a sysctl hierarchy
1784 * @root: List of sysctl headers to register on
1785 * @namespaces: Data to compute which lists of sysctl entries are visible
1786 * @path: The path to the directory the sysctl table is in.
1787 * @table: the top-level table structure
1789 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1790 * array. A completely 0 filled entry terminates the table.
1792 * The members of the &struct ctl_table structure are used as follows:
1794 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1795 * enter a sysctl file
1797 * data - a pointer to data for use by proc_handler
1799 * maxlen - the maximum size in bytes of the data
1801 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1803 * child - a pointer to the child sysctl table if this entry is a directory, or
1806 * proc_handler - the text handler routine (described below)
1808 * de - for internal use by the sysctl routines
1810 * extra1, extra2 - extra pointers usable by the proc handler routines
1812 * Leaf nodes in the sysctl tree will be represented by a single file
1813 * under /proc; non-leaf nodes will be represented by directories.
1815 * sysctl(2) can automatically manage read and write requests through
1816 * the sysctl table. The data and maxlen fields of the ctl_table
1817 * struct enable minimal validation of the values being written to be
1818 * performed, and the mode field allows minimal authentication.
1820 * There must be a proc_handler routine for any terminal nodes
1821 * mirrored under /proc/sys (non-terminals are handled by a built-in
1822 * directory handler). Several default handlers are available to
1823 * cover common cases -
1825 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1826 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1827 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1829 * It is the handler's job to read the input buffer from user memory
1830 * and process it. The handler should return 0 on success.
1832 * This routine returns %NULL on a failure to register, and a pointer
1833 * to the table header on success.
1835 struct ctl_table_header
*__register_sysctl_paths(
1836 struct ctl_table_root
*root
,
1837 struct nsproxy
*namespaces
,
1838 const struct ctl_path
*path
, struct ctl_table
*table
)
1840 struct ctl_table_header
*header
;
1841 struct ctl_table
*new, **prevp
;
1842 unsigned int n
, npath
;
1843 struct ctl_table_set
*set
;
1845 /* Count the path components */
1846 for (npath
= 0; path
[npath
].procname
; ++npath
)
1850 * For each path component, allocate a 2-element ctl_table array.
1851 * The first array element will be filled with the sysctl entry
1852 * for this, the second will be the sentinel (procname == 0).
1854 * We allocate everything in one go so that we don't have to
1855 * worry about freeing additional memory in unregister_sysctl_table.
1857 header
= kzalloc(sizeof(struct ctl_table_header
) +
1858 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1862 new = (struct ctl_table
*) (header
+ 1);
1864 /* Now connect the dots */
1865 prevp
= &header
->ctl_table
;
1866 for (n
= 0; n
< npath
; ++n
, ++path
) {
1867 /* Copy the procname */
1868 new->procname
= path
->procname
;
1872 prevp
= &new->child
;
1877 header
->ctl_table_arg
= table
;
1879 INIT_LIST_HEAD(&header
->ctl_entry
);
1881 header
->unregistering
= NULL
;
1882 header
->root
= root
;
1883 sysctl_set_parent(NULL
, header
->ctl_table
);
1885 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1886 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1891 spin_lock(&sysctl_lock
);
1892 header
->set
= lookup_header_set(root
, namespaces
);
1893 header
->attached_by
= header
->ctl_table
;
1894 header
->attached_to
= root_table
;
1895 header
->parent
= &root_table_header
;
1896 for (set
= header
->set
; set
; set
= set
->parent
) {
1897 struct ctl_table_header
*p
;
1898 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1899 if (p
->unregistering
)
1901 try_attach(p
, header
);
1904 header
->parent
->count
++;
1905 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1906 spin_unlock(&sysctl_lock
);
1912 * register_sysctl_table_path - register a sysctl table hierarchy
1913 * @path: The path to the directory the sysctl table is in.
1914 * @table: the top-level table structure
1916 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1917 * array. A completely 0 filled entry terminates the table.
1919 * See __register_sysctl_paths for more details.
1921 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1922 struct ctl_table
*table
)
1924 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1929 * register_sysctl_table - register a sysctl table hierarchy
1930 * @table: the top-level table structure
1932 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1933 * array. A completely 0 filled entry terminates the table.
1935 * See register_sysctl_paths for more details.
1937 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1939 static const struct ctl_path null_path
[] = { {} };
1941 return register_sysctl_paths(null_path
, table
);
1945 * unregister_sysctl_table - unregister a sysctl table hierarchy
1946 * @header: the header returned from register_sysctl_table
1948 * Unregisters the sysctl table and all children. proc entries may not
1949 * actually be removed until they are no longer used by anyone.
1951 void unregister_sysctl_table(struct ctl_table_header
* header
)
1958 spin_lock(&sysctl_lock
);
1959 start_unregistering(header
);
1960 if (!--header
->parent
->count
) {
1962 call_rcu(&header
->parent
->rcu
, free_head
);
1964 if (!--header
->count
)
1965 call_rcu(&header
->rcu
, free_head
);
1966 spin_unlock(&sysctl_lock
);
1969 int sysctl_is_seen(struct ctl_table_header
*p
)
1971 struct ctl_table_set
*set
= p
->set
;
1973 spin_lock(&sysctl_lock
);
1974 if (p
->unregistering
)
1976 else if (!set
->is_seen
)
1979 res
= set
->is_seen(set
);
1980 spin_unlock(&sysctl_lock
);
1984 void setup_sysctl_set(struct ctl_table_set
*p
,
1985 struct ctl_table_set
*parent
,
1986 int (*is_seen
)(struct ctl_table_set
*))
1988 INIT_LIST_HEAD(&p
->list
);
1989 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1990 p
->is_seen
= is_seen
;
1993 #else /* !CONFIG_SYSCTL */
1994 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1999 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2000 struct ctl_table
*table
)
2005 void unregister_sysctl_table(struct ctl_table_header
* table
)
2009 void setup_sysctl_set(struct ctl_table_set
*p
,
2010 struct ctl_table_set
*parent
,
2011 int (*is_seen
)(struct ctl_table_set
*))
2015 void sysctl_head_put(struct ctl_table_header
*head
)
2019 #endif /* CONFIG_SYSCTL */
2025 #ifdef CONFIG_PROC_SYSCTL
2027 static int _proc_do_string(void* data
, int maxlen
, int write
,
2028 void __user
*buffer
,
2029 size_t *lenp
, loff_t
*ppos
)
2035 if (!data
|| !maxlen
|| !*lenp
) {
2043 while (len
< *lenp
) {
2044 if (get_user(c
, p
++))
2046 if (c
== 0 || c
== '\n')
2052 if(copy_from_user(data
, buffer
, len
))
2054 ((char *) data
)[len
] = 0;
2072 if(copy_to_user(buffer
, data
, len
))
2075 if(put_user('\n', ((char __user
*) buffer
) + len
))
2086 * proc_dostring - read a string sysctl
2087 * @table: the sysctl table
2088 * @write: %TRUE if this is a write to the sysctl file
2089 * @buffer: the user buffer
2090 * @lenp: the size of the user buffer
2091 * @ppos: file position
2093 * Reads/writes a string from/to the user buffer. If the kernel
2094 * buffer provided is not large enough to hold the string, the
2095 * string is truncated. The copied string is %NULL-terminated.
2096 * If the string is being read by the user process, it is copied
2097 * and a newline '\n' is added. It is truncated if the buffer is
2100 * Returns 0 on success.
2102 int proc_dostring(struct ctl_table
*table
, int write
,
2103 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2105 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2106 buffer
, lenp
, ppos
);
2109 static size_t proc_skip_spaces(char **buf
)
2112 char *tmp
= skip_spaces(*buf
);
2118 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2128 #define TMPBUFLEN 22
2130 * proc_get_long - reads an ASCII formatted integer from a user buffer
2132 * @buf: a kernel buffer
2133 * @size: size of the kernel buffer
2134 * @val: this is where the number will be stored
2135 * @neg: set to %TRUE if number is negative
2136 * @perm_tr: a vector which contains the allowed trailers
2137 * @perm_tr_len: size of the perm_tr vector
2138 * @tr: pointer to store the trailer character
2140 * In case of success %0 is returned and @buf and @size are updated with
2141 * the amount of bytes read. If @tr is non-NULL and a trailing
2142 * character exists (size is non-zero after returning from this
2143 * function), @tr is updated with the trailing character.
2145 static int proc_get_long(char **buf
, size_t *size
,
2146 unsigned long *val
, bool *neg
,
2147 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2150 char *p
, tmp
[TMPBUFLEN
];
2156 if (len
> TMPBUFLEN
- 1)
2157 len
= TMPBUFLEN
- 1;
2159 memcpy(tmp
, *buf
, len
);
2163 if (*p
== '-' && *size
> 1) {
2171 *val
= simple_strtoul(p
, &p
, 0);
2175 /* We don't know if the next char is whitespace thus we may accept
2176 * invalid integers (e.g. 1234...a) or two integers instead of one
2177 * (e.g. 123...1). So lets not allow such large numbers. */
2178 if (len
== TMPBUFLEN
- 1)
2181 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2184 if (tr
&& (len
< *size
))
2194 * proc_put_long - converts an integer to a decimal ASCII formatted string
2196 * @buf: the user buffer
2197 * @size: the size of the user buffer
2198 * @val: the integer to be converted
2199 * @neg: sign of the number, %TRUE for negative
2201 * In case of success %0 is returned and @buf and @size are updated with
2202 * the amount of bytes written.
2204 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2208 char tmp
[TMPBUFLEN
], *p
= tmp
;
2210 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2214 if (copy_to_user(*buf
, tmp
, len
))
2222 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2225 char __user
**buffer
= (char __user
**)buf
;
2226 if (put_user(c
, *buffer
))
2228 (*size
)--, (*buffer
)++;
2234 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2236 int write
, void *data
)
2239 *valp
= *negp
? -*lvalp
: *lvalp
;
2244 *lvalp
= (unsigned long)-val
;
2247 *lvalp
= (unsigned long)val
;
2253 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2255 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2256 int write
, void __user
*buffer
,
2257 size_t *lenp
, loff_t
*ppos
,
2258 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2259 int write
, void *data
),
2262 int *i
, vleft
, first
= 1, err
= 0;
2263 unsigned long page
= 0;
2267 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2272 i
= (int *) tbl_data
;
2273 vleft
= table
->maxlen
/ sizeof(*i
);
2277 conv
= do_proc_dointvec_conv
;
2280 if (left
> PAGE_SIZE
- 1)
2281 left
= PAGE_SIZE
- 1;
2282 page
= __get_free_page(GFP_TEMPORARY
);
2283 kbuf
= (char *) page
;
2286 if (copy_from_user(kbuf
, buffer
, left
)) {
2293 for (; left
&& vleft
--; i
++, first
=0) {
2298 left
-= proc_skip_spaces(&kbuf
);
2302 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2304 sizeof(proc_wspace_sep
), NULL
);
2307 if (conv(&neg
, &lval
, i
, 1, data
)) {
2312 if (conv(&neg
, &lval
, i
, 0, data
)) {
2317 err
= proc_put_char(&buffer
, &left
, '\t');
2320 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2326 if (!write
&& !first
&& left
&& !err
)
2327 err
= proc_put_char(&buffer
, &left
, '\n');
2328 if (write
&& !err
&& left
)
2329 left
-= proc_skip_spaces(&kbuf
);
2334 return err
? : -EINVAL
;
2341 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2342 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2343 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2344 int write
, void *data
),
2347 return __do_proc_dointvec(table
->data
, table
, write
,
2348 buffer
, lenp
, ppos
, conv
, data
);
2352 * proc_dointvec - read a vector of integers
2353 * @table: the sysctl table
2354 * @write: %TRUE if this is a write to the sysctl file
2355 * @buffer: the user buffer
2356 * @lenp: the size of the user buffer
2357 * @ppos: file position
2359 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2360 * values from/to the user buffer, treated as an ASCII string.
2362 * Returns 0 on success.
2364 int proc_dointvec(struct ctl_table
*table
, int write
,
2365 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2367 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2372 * Taint values can only be increased
2373 * This means we can safely use a temporary.
2375 static int proc_taint(struct ctl_table
*table
, int write
,
2376 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2379 unsigned long tmptaint
= get_taint();
2382 if (write
&& !capable(CAP_SYS_ADMIN
))
2387 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2393 * Poor man's atomic or. Not worth adding a primitive
2394 * to everyone's atomic.h for this
2397 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2398 if ((tmptaint
>> i
) & 1)
2406 #ifdef CONFIG_PRINTK
2407 static int proc_dmesg_restrict(struct ctl_table
*table
, int write
,
2408 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2410 if (write
&& !capable(CAP_SYS_ADMIN
))
2413 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2417 struct do_proc_dointvec_minmax_conv_param
{
2422 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2424 int write
, void *data
)
2426 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2428 int val
= *negp
? -*lvalp
: *lvalp
;
2429 if ((param
->min
&& *param
->min
> val
) ||
2430 (param
->max
&& *param
->max
< val
))
2437 *lvalp
= (unsigned long)-val
;
2440 *lvalp
= (unsigned long)val
;
2447 * proc_dointvec_minmax - read a vector of integers with min/max values
2448 * @table: the sysctl table
2449 * @write: %TRUE if this is a write to the sysctl file
2450 * @buffer: the user buffer
2451 * @lenp: the size of the user buffer
2452 * @ppos: file position
2454 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2455 * values from/to the user buffer, treated as an ASCII string.
2457 * This routine will ensure the values are within the range specified by
2458 * table->extra1 (min) and table->extra2 (max).
2460 * Returns 0 on success.
2462 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2463 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2465 struct do_proc_dointvec_minmax_conv_param param
= {
2466 .min
= (int *) table
->extra1
,
2467 .max
= (int *) table
->extra2
,
2469 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2470 do_proc_dointvec_minmax_conv
, ¶m
);
2473 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2474 void __user
*buffer
,
2475 size_t *lenp
, loff_t
*ppos
,
2476 unsigned long convmul
,
2477 unsigned long convdiv
)
2479 unsigned long *i
, *min
, *max
;
2480 int vleft
, first
= 1, err
= 0;
2481 unsigned long page
= 0;
2485 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2490 i
= (unsigned long *) data
;
2491 min
= (unsigned long *) table
->extra1
;
2492 max
= (unsigned long *) table
->extra2
;
2493 vleft
= table
->maxlen
/ sizeof(unsigned long);
2497 if (left
> PAGE_SIZE
- 1)
2498 left
= PAGE_SIZE
- 1;
2499 page
= __get_free_page(GFP_TEMPORARY
);
2500 kbuf
= (char *) page
;
2503 if (copy_from_user(kbuf
, buffer
, left
)) {
2510 for (; left
&& vleft
--; i
++, first
= 0) {
2516 left
-= proc_skip_spaces(&kbuf
);
2518 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2520 sizeof(proc_wspace_sep
), NULL
);
2525 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2529 val
= convdiv
* (*i
) / convmul
;
2531 err
= proc_put_char(&buffer
, &left
, '\t');
2532 err
= proc_put_long(&buffer
, &left
, val
, false);
2538 if (!write
&& !first
&& left
&& !err
)
2539 err
= proc_put_char(&buffer
, &left
, '\n');
2541 left
-= proc_skip_spaces(&kbuf
);
2546 return err
? : -EINVAL
;
2553 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2554 void __user
*buffer
,
2555 size_t *lenp
, loff_t
*ppos
,
2556 unsigned long convmul
,
2557 unsigned long convdiv
)
2559 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2560 buffer
, lenp
, ppos
, convmul
, convdiv
);
2564 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2565 * @table: the sysctl table
2566 * @write: %TRUE if this is a write to the sysctl file
2567 * @buffer: the user buffer
2568 * @lenp: the size of the user buffer
2569 * @ppos: file position
2571 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2572 * values from/to the user buffer, treated as an ASCII string.
2574 * This routine will ensure the values are within the range specified by
2575 * table->extra1 (min) and table->extra2 (max).
2577 * Returns 0 on success.
2579 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2580 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2582 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2586 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2587 * @table: the sysctl table
2588 * @write: %TRUE if this is a write to the sysctl file
2589 * @buffer: the user buffer
2590 * @lenp: the size of the user buffer
2591 * @ppos: file position
2593 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2594 * values from/to the user buffer, treated as an ASCII string. The values
2595 * are treated as milliseconds, and converted to jiffies when they are stored.
2597 * This routine will ensure the values are within the range specified by
2598 * table->extra1 (min) and table->extra2 (max).
2600 * Returns 0 on success.
2602 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2603 void __user
*buffer
,
2604 size_t *lenp
, loff_t
*ppos
)
2606 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2607 lenp
, ppos
, HZ
, 1000l);
2611 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2613 int write
, void *data
)
2616 if (*lvalp
> LONG_MAX
/ HZ
)
2618 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2624 lval
= (unsigned long)-val
;
2627 lval
= (unsigned long)val
;
2634 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2636 int write
, void *data
)
2639 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2641 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2647 lval
= (unsigned long)-val
;
2650 lval
= (unsigned long)val
;
2652 *lvalp
= jiffies_to_clock_t(lval
);
2657 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2659 int write
, void *data
)
2662 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2668 lval
= (unsigned long)-val
;
2671 lval
= (unsigned long)val
;
2673 *lvalp
= jiffies_to_msecs(lval
);
2679 * proc_dointvec_jiffies - read a vector of integers as seconds
2680 * @table: the sysctl table
2681 * @write: %TRUE if this is a write to the sysctl file
2682 * @buffer: the user buffer
2683 * @lenp: the size of the user buffer
2684 * @ppos: file position
2686 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2687 * values from/to the user buffer, treated as an ASCII string.
2688 * The values read are assumed to be in seconds, and are converted into
2691 * Returns 0 on success.
2693 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2694 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2696 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2697 do_proc_dointvec_jiffies_conv
,NULL
);
2701 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2702 * @table: the sysctl table
2703 * @write: %TRUE if this is a write to the sysctl file
2704 * @buffer: the user buffer
2705 * @lenp: the size of the user buffer
2706 * @ppos: pointer to the file position
2708 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2709 * values from/to the user buffer, treated as an ASCII string.
2710 * The values read are assumed to be in 1/USER_HZ seconds, and
2711 * are converted into jiffies.
2713 * Returns 0 on success.
2715 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2716 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2718 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2719 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2723 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2724 * @table: the sysctl table
2725 * @write: %TRUE if this is a write to the sysctl file
2726 * @buffer: the user buffer
2727 * @lenp: the size of the user buffer
2728 * @ppos: file position
2729 * @ppos: the current position in the file
2731 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2732 * values from/to the user buffer, treated as an ASCII string.
2733 * The values read are assumed to be in 1/1000 seconds, and
2734 * are converted into jiffies.
2736 * Returns 0 on success.
2738 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2739 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2741 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2742 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2745 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2746 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2748 struct pid
*new_pid
;
2752 tmp
= pid_vnr(cad_pid
);
2754 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2755 lenp
, ppos
, NULL
, NULL
);
2759 new_pid
= find_get_pid(tmp
);
2763 put_pid(xchg(&cad_pid
, new_pid
));
2768 * proc_do_large_bitmap - read/write from/to a large bitmap
2769 * @table: the sysctl table
2770 * @write: %TRUE if this is a write to the sysctl file
2771 * @buffer: the user buffer
2772 * @lenp: the size of the user buffer
2773 * @ppos: file position
2775 * The bitmap is stored at table->data and the bitmap length (in bits)
2778 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2779 * large bitmaps may be represented in a compact manner. Writing into
2780 * the file will clear the bitmap then update it with the given input.
2782 * Returns 0 on success.
2784 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2785 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2789 size_t left
= *lenp
;
2790 unsigned long bitmap_len
= table
->maxlen
;
2791 unsigned long *bitmap
= (unsigned long *) table
->data
;
2792 unsigned long *tmp_bitmap
= NULL
;
2793 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2795 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2801 unsigned long page
= 0;
2804 if (left
> PAGE_SIZE
- 1)
2805 left
= PAGE_SIZE
- 1;
2807 page
= __get_free_page(GFP_TEMPORARY
);
2808 kbuf
= (char *) page
;
2811 if (copy_from_user(kbuf
, buffer
, left
)) {
2817 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2823 proc_skip_char(&kbuf
, &left
, '\n');
2824 while (!err
&& left
) {
2825 unsigned long val_a
, val_b
;
2828 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2832 if (val_a
>= bitmap_len
|| neg
) {
2844 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2845 &neg
, tr_b
, sizeof(tr_b
),
2849 if (val_b
>= bitmap_len
|| neg
||
2860 while (val_a
<= val_b
)
2861 set_bit(val_a
++, tmp_bitmap
);
2864 proc_skip_char(&kbuf
, &left
, '\n');
2868 unsigned long bit_a
, bit_b
= 0;
2871 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2872 if (bit_a
>= bitmap_len
)
2874 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2878 err
= proc_put_char(&buffer
, &left
, ',');
2882 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2885 if (bit_a
!= bit_b
) {
2886 err
= proc_put_char(&buffer
, &left
, '-');
2889 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2897 err
= proc_put_char(&buffer
, &left
, '\n');
2903 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2905 memcpy(bitmap
, tmp_bitmap
,
2906 BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long));
2918 #else /* CONFIG_PROC_SYSCTL */
2920 int proc_dostring(struct ctl_table
*table
, int write
,
2921 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2926 int proc_dointvec(struct ctl_table
*table
, int write
,
2927 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2932 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2933 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2938 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2939 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2944 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2945 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2950 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2951 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2956 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2957 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2962 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2963 void __user
*buffer
,
2964 size_t *lenp
, loff_t
*ppos
)
2970 #endif /* CONFIG_PROC_SYSCTL */
2973 * No sense putting this after each symbol definition, twice,
2974 * exception granted :-)
2976 EXPORT_SYMBOL(proc_dointvec
);
2977 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2978 EXPORT_SYMBOL(proc_dointvec_minmax
);
2979 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2980 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2981 EXPORT_SYMBOL(proc_dostring
);
2982 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2983 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2984 EXPORT_SYMBOL(register_sysctl_table
);
2985 EXPORT_SYMBOL(register_sysctl_paths
);
2986 EXPORT_SYMBOL(unregister_sysctl_table
);