2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/signal.h>
27 #include <linux/proc_fs.h>
28 #include <linux/security.h>
29 #include <linux/ctype.h>
30 #include <linux/kmemcheck.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/ratelimit.h>
40 #include <linux/compaction.h>
41 #include <linux/hugetlb.h>
42 #include <linux/initrd.h>
43 #include <linux/key.h>
44 #include <linux/times.h>
45 #include <linux/limits.h>
46 #include <linux/dcache.h>
47 #include <linux/dnotify.h>
48 #include <linux/syscalls.h>
49 #include <linux/vmstat.h>
50 #include <linux/nfs_fs.h>
51 #include <linux/acpi.h>
52 #include <linux/reboot.h>
53 #include <linux/ftrace.h>
54 #include <linux/perf_event.h>
55 #include <linux/kprobes.h>
56 #include <linux/pipe_fs_i.h>
57 #include <linux/oom.h>
59 #include <asm/uaccess.h>
60 #include <asm/processor.h>
64 #include <asm/stacktrace.h>
67 #ifdef CONFIG_BSD_PROCESS_ACCT
68 #include <linux/acct.h>
70 #ifdef CONFIG_RT_MUTEXES
71 #include <linux/rtmutex.h>
73 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
74 #include <linux/lockdep.h>
76 #ifdef CONFIG_CHR_DEV_SG
80 #ifdef CONFIG_LOCKUP_DETECTOR
81 #include <linux/nmi.h>
85 #if defined(CONFIG_SYSCTL)
87 /* External variables not in a header file. */
88 extern int sysctl_overcommit_memory
;
89 extern int sysctl_overcommit_ratio
;
90 extern int max_threads
;
91 extern int core_uses_pid
;
92 extern int suid_dumpable
;
93 extern char core_pattern
[];
94 extern unsigned int core_pipe_limit
;
96 extern int min_free_kbytes
;
97 extern int pid_max_min
, pid_max_max
;
98 extern int sysctl_drop_caches
;
99 extern int percpu_pagelist_fraction
;
100 extern int compat_log
;
101 extern int latencytop_enabled
;
102 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
104 extern int sysctl_nr_trim_pages
;
107 extern int blk_iopoll_enabled
;
110 /* Constants used for minimum and maximum */
111 #ifdef CONFIG_LOCKUP_DETECTOR
112 static int sixty
= 60;
113 static int neg_one
= -1;
117 static int __maybe_unused one
= 1;
118 static int __maybe_unused two
= 2;
119 static unsigned long one_ul
= 1;
120 static int one_hundred
= 100;
122 static int ten_thousand
= 10000;
125 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
126 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
128 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
129 static int maxolduid
= 65535;
130 static int minolduid
;
131 static int min_percpu_pagelist_fract
= 8;
133 static int ngroups_max
= NGROUPS_MAX
;
135 #ifdef CONFIG_INOTIFY_USER
136 #include <linux/inotify.h>
139 #include <asm/system.h>
142 #ifdef CONFIG_SPARC64
143 extern int sysctl_tsb_ratio
;
147 extern int pwrsw_enabled
;
148 extern int unaligned_enabled
;
152 #ifdef CONFIG_MATHEMU
153 extern int sysctl_ieee_emulation_warnings
;
155 extern int sysctl_userprocess_debug
;
156 extern int spin_retry
;
160 extern int no_unaligned_warning
;
161 extern int unaligned_dump_stack
;
164 #ifdef CONFIG_PROC_SYSCTL
165 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
166 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
167 static int proc_taint(struct ctl_table
*table
, int write
,
168 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
171 #ifdef CONFIG_MAGIC_SYSRQ
172 /* Note: sysrq code uses it's own private copy */
173 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
175 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
176 void __user
*buffer
, size_t *lenp
,
181 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
186 sysrq_toggle_support(__sysrq_enabled
);
193 static struct ctl_table root_table
[];
194 static struct ctl_table_root sysctl_table_root
;
195 static struct ctl_table_header root_table_header
= {
197 .ctl_table
= root_table
,
198 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
199 .root
= &sysctl_table_root
,
200 .set
= &sysctl_table_root
.default_set
,
202 static struct ctl_table_root sysctl_table_root
= {
203 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
204 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
207 static struct ctl_table kern_table
[];
208 static struct ctl_table vm_table
[];
209 static struct ctl_table fs_table
[];
210 static struct ctl_table debug_table
[];
211 static struct ctl_table dev_table
[];
212 extern struct ctl_table random_table
[];
214 extern struct ctl_table epoll_table
[];
217 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
218 int sysctl_legacy_va_layout
;
221 /* The default sysctl tables: */
223 static struct ctl_table root_table
[] = {
225 .procname
= "kernel",
242 .child
= debug_table
,
250 * NOTE: do not add new entries to this table unless you have read
251 * Documentation/sysctl/ctl_unnumbered.txt
256 #ifdef CONFIG_SCHED_DEBUG
257 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
258 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
259 static int min_wakeup_granularity_ns
; /* 0 usecs */
260 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
261 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
262 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
263 static int min_sched_shares_ratelimit
= 100000; /* 100 usec */
264 static int max_sched_shares_ratelimit
= NSEC_PER_SEC
; /* 1 second */
267 #ifdef CONFIG_COMPACTION
268 static int min_extfrag_threshold
;
269 static int max_extfrag_threshold
= 1000;
272 static struct ctl_table kern_table
[] = {
274 .procname
= "sched_child_runs_first",
275 .data
= &sysctl_sched_child_runs_first
,
276 .maxlen
= sizeof(unsigned int),
278 .proc_handler
= proc_dointvec
,
280 #ifdef CONFIG_SCHED_DEBUG
282 .procname
= "sched_min_granularity_ns",
283 .data
= &sysctl_sched_min_granularity
,
284 .maxlen
= sizeof(unsigned int),
286 .proc_handler
= sched_proc_update_handler
,
287 .extra1
= &min_sched_granularity_ns
,
288 .extra2
= &max_sched_granularity_ns
,
291 .procname
= "sched_latency_ns",
292 .data
= &sysctl_sched_latency
,
293 .maxlen
= sizeof(unsigned int),
295 .proc_handler
= sched_proc_update_handler
,
296 .extra1
= &min_sched_granularity_ns
,
297 .extra2
= &max_sched_granularity_ns
,
300 .procname
= "sched_wakeup_granularity_ns",
301 .data
= &sysctl_sched_wakeup_granularity
,
302 .maxlen
= sizeof(unsigned int),
304 .proc_handler
= sched_proc_update_handler
,
305 .extra1
= &min_wakeup_granularity_ns
,
306 .extra2
= &max_wakeup_granularity_ns
,
309 .procname
= "sched_shares_ratelimit",
310 .data
= &sysctl_sched_shares_ratelimit
,
311 .maxlen
= sizeof(unsigned int),
313 .proc_handler
= sched_proc_update_handler
,
314 .extra1
= &min_sched_shares_ratelimit
,
315 .extra2
= &max_sched_shares_ratelimit
,
318 .procname
= "sched_tunable_scaling",
319 .data
= &sysctl_sched_tunable_scaling
,
320 .maxlen
= sizeof(enum sched_tunable_scaling
),
322 .proc_handler
= sched_proc_update_handler
,
323 .extra1
= &min_sched_tunable_scaling
,
324 .extra2
= &max_sched_tunable_scaling
,
327 .procname
= "sched_shares_thresh",
328 .data
= &sysctl_sched_shares_thresh
,
329 .maxlen
= sizeof(unsigned int),
331 .proc_handler
= proc_dointvec_minmax
,
335 .procname
= "sched_migration_cost",
336 .data
= &sysctl_sched_migration_cost
,
337 .maxlen
= sizeof(unsigned int),
339 .proc_handler
= proc_dointvec
,
342 .procname
= "sched_nr_migrate",
343 .data
= &sysctl_sched_nr_migrate
,
344 .maxlen
= sizeof(unsigned int),
346 .proc_handler
= proc_dointvec
,
349 .procname
= "sched_time_avg",
350 .data
= &sysctl_sched_time_avg
,
351 .maxlen
= sizeof(unsigned int),
353 .proc_handler
= proc_dointvec
,
356 .procname
= "timer_migration",
357 .data
= &sysctl_timer_migration
,
358 .maxlen
= sizeof(unsigned int),
360 .proc_handler
= proc_dointvec_minmax
,
366 .procname
= "sched_rt_period_us",
367 .data
= &sysctl_sched_rt_period
,
368 .maxlen
= sizeof(unsigned int),
370 .proc_handler
= sched_rt_handler
,
373 .procname
= "sched_rt_runtime_us",
374 .data
= &sysctl_sched_rt_runtime
,
375 .maxlen
= sizeof(int),
377 .proc_handler
= sched_rt_handler
,
380 .procname
= "sched_compat_yield",
381 .data
= &sysctl_sched_compat_yield
,
382 .maxlen
= sizeof(unsigned int),
384 .proc_handler
= proc_dointvec
,
386 #ifdef CONFIG_PROVE_LOCKING
388 .procname
= "prove_locking",
389 .data
= &prove_locking
,
390 .maxlen
= sizeof(int),
392 .proc_handler
= proc_dointvec
,
395 #ifdef CONFIG_LOCK_STAT
397 .procname
= "lock_stat",
399 .maxlen
= sizeof(int),
401 .proc_handler
= proc_dointvec
,
406 .data
= &panic_timeout
,
407 .maxlen
= sizeof(int),
409 .proc_handler
= proc_dointvec
,
412 .procname
= "core_uses_pid",
413 .data
= &core_uses_pid
,
414 .maxlen
= sizeof(int),
416 .proc_handler
= proc_dointvec
,
419 .procname
= "core_pattern",
420 .data
= core_pattern
,
421 .maxlen
= CORENAME_MAX_SIZE
,
423 .proc_handler
= proc_dostring
,
426 .procname
= "core_pipe_limit",
427 .data
= &core_pipe_limit
,
428 .maxlen
= sizeof(unsigned int),
430 .proc_handler
= proc_dointvec
,
432 #ifdef CONFIG_PROC_SYSCTL
434 .procname
= "tainted",
435 .maxlen
= sizeof(long),
437 .proc_handler
= proc_taint
,
440 #ifdef CONFIG_LATENCYTOP
442 .procname
= "latencytop",
443 .data
= &latencytop_enabled
,
444 .maxlen
= sizeof(int),
446 .proc_handler
= proc_dointvec
,
449 #ifdef CONFIG_BLK_DEV_INITRD
451 .procname
= "real-root-dev",
452 .data
= &real_root_dev
,
453 .maxlen
= sizeof(int),
455 .proc_handler
= proc_dointvec
,
459 .procname
= "print-fatal-signals",
460 .data
= &print_fatal_signals
,
461 .maxlen
= sizeof(int),
463 .proc_handler
= proc_dointvec
,
467 .procname
= "reboot-cmd",
468 .data
= reboot_command
,
471 .proc_handler
= proc_dostring
,
474 .procname
= "stop-a",
475 .data
= &stop_a_enabled
,
476 .maxlen
= sizeof (int),
478 .proc_handler
= proc_dointvec
,
481 .procname
= "scons-poweroff",
482 .data
= &scons_pwroff
,
483 .maxlen
= sizeof (int),
485 .proc_handler
= proc_dointvec
,
488 #ifdef CONFIG_SPARC64
490 .procname
= "tsb-ratio",
491 .data
= &sysctl_tsb_ratio
,
492 .maxlen
= sizeof (int),
494 .proc_handler
= proc_dointvec
,
499 .procname
= "soft-power",
500 .data
= &pwrsw_enabled
,
501 .maxlen
= sizeof (int),
503 .proc_handler
= proc_dointvec
,
506 .procname
= "unaligned-trap",
507 .data
= &unaligned_enabled
,
508 .maxlen
= sizeof (int),
510 .proc_handler
= proc_dointvec
,
514 .procname
= "ctrl-alt-del",
516 .maxlen
= sizeof(int),
518 .proc_handler
= proc_dointvec
,
520 #ifdef CONFIG_FUNCTION_TRACER
522 .procname
= "ftrace_enabled",
523 .data
= &ftrace_enabled
,
524 .maxlen
= sizeof(int),
526 .proc_handler
= ftrace_enable_sysctl
,
529 #ifdef CONFIG_STACK_TRACER
531 .procname
= "stack_tracer_enabled",
532 .data
= &stack_tracer_enabled
,
533 .maxlen
= sizeof(int),
535 .proc_handler
= stack_trace_sysctl
,
538 #ifdef CONFIG_TRACING
540 .procname
= "ftrace_dump_on_oops",
541 .data
= &ftrace_dump_on_oops
,
542 .maxlen
= sizeof(int),
544 .proc_handler
= proc_dointvec
,
547 #ifdef CONFIG_MODULES
549 .procname
= "modprobe",
550 .data
= &modprobe_path
,
551 .maxlen
= KMOD_PATH_LEN
,
553 .proc_handler
= proc_dostring
,
556 .procname
= "modules_disabled",
557 .data
= &modules_disabled
,
558 .maxlen
= sizeof(int),
560 /* only handle a transition from default "0" to "1" */
561 .proc_handler
= proc_dointvec_minmax
,
566 #ifdef CONFIG_HOTPLUG
568 .procname
= "hotplug",
569 .data
= &uevent_helper
,
570 .maxlen
= UEVENT_HELPER_PATH_LEN
,
572 .proc_handler
= proc_dostring
,
575 #ifdef CONFIG_CHR_DEV_SG
577 .procname
= "sg-big-buff",
578 .data
= &sg_big_buff
,
579 .maxlen
= sizeof (int),
581 .proc_handler
= proc_dointvec
,
584 #ifdef CONFIG_BSD_PROCESS_ACCT
588 .maxlen
= 3*sizeof(int),
590 .proc_handler
= proc_dointvec
,
593 #ifdef CONFIG_MAGIC_SYSRQ
596 .data
= &__sysrq_enabled
,
597 .maxlen
= sizeof (int),
599 .proc_handler
= sysrq_sysctl_handler
,
602 #ifdef CONFIG_PROC_SYSCTL
604 .procname
= "cad_pid",
606 .maxlen
= sizeof (int),
608 .proc_handler
= proc_do_cad_pid
,
612 .procname
= "threads-max",
613 .data
= &max_threads
,
614 .maxlen
= sizeof(int),
616 .proc_handler
= proc_dointvec
,
619 .procname
= "random",
621 .child
= random_table
,
624 .procname
= "overflowuid",
625 .data
= &overflowuid
,
626 .maxlen
= sizeof(int),
628 .proc_handler
= proc_dointvec_minmax
,
629 .extra1
= &minolduid
,
630 .extra2
= &maxolduid
,
633 .procname
= "overflowgid",
634 .data
= &overflowgid
,
635 .maxlen
= sizeof(int),
637 .proc_handler
= proc_dointvec_minmax
,
638 .extra1
= &minolduid
,
639 .extra2
= &maxolduid
,
642 #ifdef CONFIG_MATHEMU
644 .procname
= "ieee_emulation_warnings",
645 .data
= &sysctl_ieee_emulation_warnings
,
646 .maxlen
= sizeof(int),
648 .proc_handler
= proc_dointvec
,
652 .procname
= "userprocess_debug",
653 .data
= &show_unhandled_signals
,
654 .maxlen
= sizeof(int),
656 .proc_handler
= proc_dointvec
,
660 .procname
= "pid_max",
662 .maxlen
= sizeof (int),
664 .proc_handler
= proc_dointvec_minmax
,
665 .extra1
= &pid_max_min
,
666 .extra2
= &pid_max_max
,
669 .procname
= "panic_on_oops",
670 .data
= &panic_on_oops
,
671 .maxlen
= sizeof(int),
673 .proc_handler
= proc_dointvec
,
675 #if defined CONFIG_PRINTK
677 .procname
= "printk",
678 .data
= &console_loglevel
,
679 .maxlen
= 4*sizeof(int),
681 .proc_handler
= proc_dointvec
,
684 .procname
= "printk_ratelimit",
685 .data
= &printk_ratelimit_state
.interval
,
686 .maxlen
= sizeof(int),
688 .proc_handler
= proc_dointvec_jiffies
,
691 .procname
= "printk_ratelimit_burst",
692 .data
= &printk_ratelimit_state
.burst
,
693 .maxlen
= sizeof(int),
695 .proc_handler
= proc_dointvec
,
698 .procname
= "printk_delay",
699 .data
= &printk_delay_msec
,
700 .maxlen
= sizeof(int),
702 .proc_handler
= proc_dointvec_minmax
,
704 .extra2
= &ten_thousand
,
707 .procname
= "dmesg_restrict",
708 .data
= &dmesg_restrict
,
709 .maxlen
= sizeof(int),
711 .proc_handler
= proc_dointvec_minmax
,
717 .procname
= "ngroups_max",
718 .data
= &ngroups_max
,
719 .maxlen
= sizeof (int),
721 .proc_handler
= proc_dointvec
,
723 #if defined(CONFIG_LOCKUP_DETECTOR)
725 .procname
= "watchdog",
726 .data
= &watchdog_enabled
,
727 .maxlen
= sizeof (int),
729 .proc_handler
= proc_dowatchdog_enabled
,
732 .procname
= "watchdog_thresh",
733 .data
= &softlockup_thresh
,
734 .maxlen
= sizeof(int),
736 .proc_handler
= proc_dowatchdog_thresh
,
741 .procname
= "softlockup_panic",
742 .data
= &softlockup_panic
,
743 .maxlen
= sizeof(int),
745 .proc_handler
= proc_dointvec_minmax
,
750 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) && !defined(CONFIG_LOCKUP_DETECTOR)
752 .procname
= "unknown_nmi_panic",
753 .data
= &unknown_nmi_panic
,
754 .maxlen
= sizeof (int),
756 .proc_handler
= proc_dointvec
,
759 .procname
= "nmi_watchdog",
760 .data
= &nmi_watchdog_enabled
,
761 .maxlen
= sizeof (int),
763 .proc_handler
= proc_nmi_enabled
,
766 #if defined(CONFIG_X86)
768 .procname
= "panic_on_unrecovered_nmi",
769 .data
= &panic_on_unrecovered_nmi
,
770 .maxlen
= sizeof(int),
772 .proc_handler
= proc_dointvec
,
775 .procname
= "panic_on_io_nmi",
776 .data
= &panic_on_io_nmi
,
777 .maxlen
= sizeof(int),
779 .proc_handler
= proc_dointvec
,
782 .procname
= "bootloader_type",
783 .data
= &bootloader_type
,
784 .maxlen
= sizeof (int),
786 .proc_handler
= proc_dointvec
,
789 .procname
= "bootloader_version",
790 .data
= &bootloader_version
,
791 .maxlen
= sizeof (int),
793 .proc_handler
= proc_dointvec
,
796 .procname
= "kstack_depth_to_print",
797 .data
= &kstack_depth_to_print
,
798 .maxlen
= sizeof(int),
800 .proc_handler
= proc_dointvec
,
803 .procname
= "io_delay_type",
804 .data
= &io_delay_type
,
805 .maxlen
= sizeof(int),
807 .proc_handler
= proc_dointvec
,
810 #if defined(CONFIG_MMU)
812 .procname
= "randomize_va_space",
813 .data
= &randomize_va_space
,
814 .maxlen
= sizeof(int),
816 .proc_handler
= proc_dointvec
,
819 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
821 .procname
= "spin_retry",
823 .maxlen
= sizeof (int),
825 .proc_handler
= proc_dointvec
,
828 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
830 .procname
= "acpi_video_flags",
831 .data
= &acpi_realmode_flags
,
832 .maxlen
= sizeof (unsigned long),
834 .proc_handler
= proc_doulongvec_minmax
,
839 .procname
= "ignore-unaligned-usertrap",
840 .data
= &no_unaligned_warning
,
841 .maxlen
= sizeof (int),
843 .proc_handler
= proc_dointvec
,
846 .procname
= "unaligned-dump-stack",
847 .data
= &unaligned_dump_stack
,
848 .maxlen
= sizeof (int),
850 .proc_handler
= proc_dointvec
,
853 #ifdef CONFIG_DETECT_HUNG_TASK
855 .procname
= "hung_task_panic",
856 .data
= &sysctl_hung_task_panic
,
857 .maxlen
= sizeof(int),
859 .proc_handler
= proc_dointvec_minmax
,
864 .procname
= "hung_task_check_count",
865 .data
= &sysctl_hung_task_check_count
,
866 .maxlen
= sizeof(unsigned long),
868 .proc_handler
= proc_doulongvec_minmax
,
871 .procname
= "hung_task_timeout_secs",
872 .data
= &sysctl_hung_task_timeout_secs
,
873 .maxlen
= sizeof(unsigned long),
875 .proc_handler
= proc_dohung_task_timeout_secs
,
878 .procname
= "hung_task_warnings",
879 .data
= &sysctl_hung_task_warnings
,
880 .maxlen
= sizeof(unsigned long),
882 .proc_handler
= proc_doulongvec_minmax
,
887 .procname
= "compat-log",
889 .maxlen
= sizeof (int),
891 .proc_handler
= proc_dointvec
,
894 #ifdef CONFIG_RT_MUTEXES
896 .procname
= "max_lock_depth",
897 .data
= &max_lock_depth
,
898 .maxlen
= sizeof(int),
900 .proc_handler
= proc_dointvec
,
904 .procname
= "poweroff_cmd",
905 .data
= &poweroff_cmd
,
906 .maxlen
= POWEROFF_CMD_PATH_LEN
,
908 .proc_handler
= proc_dostring
,
914 .child
= key_sysctls
,
917 #ifdef CONFIG_RCU_TORTURE_TEST
919 .procname
= "rcutorture_runnable",
920 .data
= &rcutorture_runnable
,
921 .maxlen
= sizeof(int),
923 .proc_handler
= proc_dointvec
,
926 #ifdef CONFIG_PERF_EVENTS
928 .procname
= "perf_event_paranoid",
929 .data
= &sysctl_perf_event_paranoid
,
930 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
932 .proc_handler
= proc_dointvec
,
935 .procname
= "perf_event_mlock_kb",
936 .data
= &sysctl_perf_event_mlock
,
937 .maxlen
= sizeof(sysctl_perf_event_mlock
),
939 .proc_handler
= proc_dointvec
,
942 .procname
= "perf_event_max_sample_rate",
943 .data
= &sysctl_perf_event_sample_rate
,
944 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
946 .proc_handler
= proc_dointvec
,
949 #ifdef CONFIG_KMEMCHECK
951 .procname
= "kmemcheck",
952 .data
= &kmemcheck_enabled
,
953 .maxlen
= sizeof(int),
955 .proc_handler
= proc_dointvec
,
960 .procname
= "blk_iopoll",
961 .data
= &blk_iopoll_enabled
,
962 .maxlen
= sizeof(int),
964 .proc_handler
= proc_dointvec
,
968 * NOTE: do not add new entries to this table unless you have read
969 * Documentation/sysctl/ctl_unnumbered.txt
974 static struct ctl_table vm_table
[] = {
976 .procname
= "overcommit_memory",
977 .data
= &sysctl_overcommit_memory
,
978 .maxlen
= sizeof(sysctl_overcommit_memory
),
980 .proc_handler
= proc_dointvec
,
983 .procname
= "panic_on_oom",
984 .data
= &sysctl_panic_on_oom
,
985 .maxlen
= sizeof(sysctl_panic_on_oom
),
987 .proc_handler
= proc_dointvec
,
990 .procname
= "oom_kill_allocating_task",
991 .data
= &sysctl_oom_kill_allocating_task
,
992 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
994 .proc_handler
= proc_dointvec
,
997 .procname
= "oom_dump_tasks",
998 .data
= &sysctl_oom_dump_tasks
,
999 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1001 .proc_handler
= proc_dointvec
,
1004 .procname
= "overcommit_ratio",
1005 .data
= &sysctl_overcommit_ratio
,
1006 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1008 .proc_handler
= proc_dointvec
,
1011 .procname
= "page-cluster",
1012 .data
= &page_cluster
,
1013 .maxlen
= sizeof(int),
1015 .proc_handler
= proc_dointvec
,
1018 .procname
= "dirty_background_ratio",
1019 .data
= &dirty_background_ratio
,
1020 .maxlen
= sizeof(dirty_background_ratio
),
1022 .proc_handler
= dirty_background_ratio_handler
,
1024 .extra2
= &one_hundred
,
1027 .procname
= "dirty_background_bytes",
1028 .data
= &dirty_background_bytes
,
1029 .maxlen
= sizeof(dirty_background_bytes
),
1031 .proc_handler
= dirty_background_bytes_handler
,
1035 .procname
= "dirty_ratio",
1036 .data
= &vm_dirty_ratio
,
1037 .maxlen
= sizeof(vm_dirty_ratio
),
1039 .proc_handler
= dirty_ratio_handler
,
1041 .extra2
= &one_hundred
,
1044 .procname
= "dirty_bytes",
1045 .data
= &vm_dirty_bytes
,
1046 .maxlen
= sizeof(vm_dirty_bytes
),
1048 .proc_handler
= dirty_bytes_handler
,
1049 .extra1
= &dirty_bytes_min
,
1052 .procname
= "dirty_writeback_centisecs",
1053 .data
= &dirty_writeback_interval
,
1054 .maxlen
= sizeof(dirty_writeback_interval
),
1056 .proc_handler
= dirty_writeback_centisecs_handler
,
1059 .procname
= "dirty_expire_centisecs",
1060 .data
= &dirty_expire_interval
,
1061 .maxlen
= sizeof(dirty_expire_interval
),
1063 .proc_handler
= proc_dointvec
,
1066 .procname
= "nr_pdflush_threads",
1067 .data
= &nr_pdflush_threads
,
1068 .maxlen
= sizeof nr_pdflush_threads
,
1069 .mode
= 0444 /* read-only*/,
1070 .proc_handler
= proc_dointvec
,
1073 .procname
= "swappiness",
1074 .data
= &vm_swappiness
,
1075 .maxlen
= sizeof(vm_swappiness
),
1077 .proc_handler
= proc_dointvec_minmax
,
1079 .extra2
= &one_hundred
,
1081 #ifdef CONFIG_HUGETLB_PAGE
1083 .procname
= "nr_hugepages",
1085 .maxlen
= sizeof(unsigned long),
1087 .proc_handler
= hugetlb_sysctl_handler
,
1088 .extra1
= (void *)&hugetlb_zero
,
1089 .extra2
= (void *)&hugetlb_infinity
,
1093 .procname
= "nr_hugepages_mempolicy",
1095 .maxlen
= sizeof(unsigned long),
1097 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1098 .extra1
= (void *)&hugetlb_zero
,
1099 .extra2
= (void *)&hugetlb_infinity
,
1103 .procname
= "hugetlb_shm_group",
1104 .data
= &sysctl_hugetlb_shm_group
,
1105 .maxlen
= sizeof(gid_t
),
1107 .proc_handler
= proc_dointvec
,
1110 .procname
= "hugepages_treat_as_movable",
1111 .data
= &hugepages_treat_as_movable
,
1112 .maxlen
= sizeof(int),
1114 .proc_handler
= hugetlb_treat_movable_handler
,
1117 .procname
= "nr_overcommit_hugepages",
1119 .maxlen
= sizeof(unsigned long),
1121 .proc_handler
= hugetlb_overcommit_handler
,
1122 .extra1
= (void *)&hugetlb_zero
,
1123 .extra2
= (void *)&hugetlb_infinity
,
1127 .procname
= "lowmem_reserve_ratio",
1128 .data
= &sysctl_lowmem_reserve_ratio
,
1129 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1131 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1134 .procname
= "drop_caches",
1135 .data
= &sysctl_drop_caches
,
1136 .maxlen
= sizeof(int),
1138 .proc_handler
= drop_caches_sysctl_handler
,
1140 #ifdef CONFIG_COMPACTION
1142 .procname
= "compact_memory",
1143 .data
= &sysctl_compact_memory
,
1144 .maxlen
= sizeof(int),
1146 .proc_handler
= sysctl_compaction_handler
,
1149 .procname
= "extfrag_threshold",
1150 .data
= &sysctl_extfrag_threshold
,
1151 .maxlen
= sizeof(int),
1153 .proc_handler
= sysctl_extfrag_handler
,
1154 .extra1
= &min_extfrag_threshold
,
1155 .extra2
= &max_extfrag_threshold
,
1158 #endif /* CONFIG_COMPACTION */
1160 .procname
= "min_free_kbytes",
1161 .data
= &min_free_kbytes
,
1162 .maxlen
= sizeof(min_free_kbytes
),
1164 .proc_handler
= min_free_kbytes_sysctl_handler
,
1168 .procname
= "percpu_pagelist_fraction",
1169 .data
= &percpu_pagelist_fraction
,
1170 .maxlen
= sizeof(percpu_pagelist_fraction
),
1172 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1173 .extra1
= &min_percpu_pagelist_fract
,
1177 .procname
= "max_map_count",
1178 .data
= &sysctl_max_map_count
,
1179 .maxlen
= sizeof(sysctl_max_map_count
),
1181 .proc_handler
= proc_dointvec_minmax
,
1186 .procname
= "nr_trim_pages",
1187 .data
= &sysctl_nr_trim_pages
,
1188 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1190 .proc_handler
= proc_dointvec_minmax
,
1195 .procname
= "laptop_mode",
1196 .data
= &laptop_mode
,
1197 .maxlen
= sizeof(laptop_mode
),
1199 .proc_handler
= proc_dointvec_jiffies
,
1202 .procname
= "block_dump",
1203 .data
= &block_dump
,
1204 .maxlen
= sizeof(block_dump
),
1206 .proc_handler
= proc_dointvec
,
1210 .procname
= "vfs_cache_pressure",
1211 .data
= &sysctl_vfs_cache_pressure
,
1212 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1214 .proc_handler
= proc_dointvec
,
1217 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1219 .procname
= "legacy_va_layout",
1220 .data
= &sysctl_legacy_va_layout
,
1221 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1223 .proc_handler
= proc_dointvec
,
1229 .procname
= "zone_reclaim_mode",
1230 .data
= &zone_reclaim_mode
,
1231 .maxlen
= sizeof(zone_reclaim_mode
),
1233 .proc_handler
= proc_dointvec
,
1237 .procname
= "min_unmapped_ratio",
1238 .data
= &sysctl_min_unmapped_ratio
,
1239 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1241 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1243 .extra2
= &one_hundred
,
1246 .procname
= "min_slab_ratio",
1247 .data
= &sysctl_min_slab_ratio
,
1248 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1250 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1252 .extra2
= &one_hundred
,
1257 .procname
= "stat_interval",
1258 .data
= &sysctl_stat_interval
,
1259 .maxlen
= sizeof(sysctl_stat_interval
),
1261 .proc_handler
= proc_dointvec_jiffies
,
1266 .procname
= "mmap_min_addr",
1267 .data
= &dac_mmap_min_addr
,
1268 .maxlen
= sizeof(unsigned long),
1270 .proc_handler
= mmap_min_addr_handler
,
1275 .procname
= "numa_zonelist_order",
1276 .data
= &numa_zonelist_order
,
1277 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1279 .proc_handler
= numa_zonelist_order_handler
,
1282 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1283 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1285 .procname
= "vdso_enabled",
1286 .data
= &vdso_enabled
,
1287 .maxlen
= sizeof(vdso_enabled
),
1289 .proc_handler
= proc_dointvec
,
1293 #ifdef CONFIG_HIGHMEM
1295 .procname
= "highmem_is_dirtyable",
1296 .data
= &vm_highmem_is_dirtyable
,
1297 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1299 .proc_handler
= proc_dointvec_minmax
,
1305 .procname
= "scan_unevictable_pages",
1306 .data
= &scan_unevictable_pages
,
1307 .maxlen
= sizeof(scan_unevictable_pages
),
1309 .proc_handler
= scan_unevictable_handler
,
1311 #ifdef CONFIG_MEMORY_FAILURE
1313 .procname
= "memory_failure_early_kill",
1314 .data
= &sysctl_memory_failure_early_kill
,
1315 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1317 .proc_handler
= proc_dointvec_minmax
,
1322 .procname
= "memory_failure_recovery",
1323 .data
= &sysctl_memory_failure_recovery
,
1324 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1326 .proc_handler
= proc_dointvec_minmax
,
1333 * NOTE: do not add new entries to this table unless you have read
1334 * Documentation/sysctl/ctl_unnumbered.txt
1339 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1340 static struct ctl_table binfmt_misc_table
[] = {
1345 static struct ctl_table fs_table
[] = {
1347 .procname
= "inode-nr",
1348 .data
= &inodes_stat
,
1349 .maxlen
= 2*sizeof(int),
1351 .proc_handler
= proc_nr_inodes
,
1354 .procname
= "inode-state",
1355 .data
= &inodes_stat
,
1356 .maxlen
= 7*sizeof(int),
1358 .proc_handler
= proc_nr_inodes
,
1361 .procname
= "file-nr",
1362 .data
= &files_stat
,
1363 .maxlen
= sizeof(files_stat
),
1365 .proc_handler
= proc_nr_files
,
1368 .procname
= "file-max",
1369 .data
= &files_stat
.max_files
,
1370 .maxlen
= sizeof(files_stat
.max_files
),
1372 .proc_handler
= proc_doulongvec_minmax
,
1375 .procname
= "nr_open",
1376 .data
= &sysctl_nr_open
,
1377 .maxlen
= sizeof(int),
1379 .proc_handler
= proc_dointvec_minmax
,
1380 .extra1
= &sysctl_nr_open_min
,
1381 .extra2
= &sysctl_nr_open_max
,
1384 .procname
= "dentry-state",
1385 .data
= &dentry_stat
,
1386 .maxlen
= 6*sizeof(int),
1388 .proc_handler
= proc_nr_dentry
,
1391 .procname
= "overflowuid",
1392 .data
= &fs_overflowuid
,
1393 .maxlen
= sizeof(int),
1395 .proc_handler
= proc_dointvec_minmax
,
1396 .extra1
= &minolduid
,
1397 .extra2
= &maxolduid
,
1400 .procname
= "overflowgid",
1401 .data
= &fs_overflowgid
,
1402 .maxlen
= sizeof(int),
1404 .proc_handler
= proc_dointvec_minmax
,
1405 .extra1
= &minolduid
,
1406 .extra2
= &maxolduid
,
1408 #ifdef CONFIG_FILE_LOCKING
1410 .procname
= "leases-enable",
1411 .data
= &leases_enable
,
1412 .maxlen
= sizeof(int),
1414 .proc_handler
= proc_dointvec
,
1417 #ifdef CONFIG_DNOTIFY
1419 .procname
= "dir-notify-enable",
1420 .data
= &dir_notify_enable
,
1421 .maxlen
= sizeof(int),
1423 .proc_handler
= proc_dointvec
,
1427 #ifdef CONFIG_FILE_LOCKING
1429 .procname
= "lease-break-time",
1430 .data
= &lease_break_time
,
1431 .maxlen
= sizeof(int),
1433 .proc_handler
= proc_dointvec
,
1438 .procname
= "aio-nr",
1440 .maxlen
= sizeof(aio_nr
),
1442 .proc_handler
= proc_doulongvec_minmax
,
1445 .procname
= "aio-max-nr",
1446 .data
= &aio_max_nr
,
1447 .maxlen
= sizeof(aio_max_nr
),
1449 .proc_handler
= proc_doulongvec_minmax
,
1451 #endif /* CONFIG_AIO */
1452 #ifdef CONFIG_INOTIFY_USER
1454 .procname
= "inotify",
1456 .child
= inotify_table
,
1461 .procname
= "epoll",
1463 .child
= epoll_table
,
1468 .procname
= "suid_dumpable",
1469 .data
= &suid_dumpable
,
1470 .maxlen
= sizeof(int),
1472 .proc_handler
= proc_dointvec_minmax
,
1476 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1478 .procname
= "binfmt_misc",
1480 .child
= binfmt_misc_table
,
1484 .procname
= "pipe-max-size",
1485 .data
= &pipe_max_size
,
1486 .maxlen
= sizeof(int),
1488 .proc_handler
= &pipe_proc_fn
,
1489 .extra1
= &pipe_min_size
,
1492 * NOTE: do not add new entries to this table unless you have read
1493 * Documentation/sysctl/ctl_unnumbered.txt
1498 static struct ctl_table debug_table
[] = {
1499 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1500 defined(CONFIG_S390)
1502 .procname
= "exception-trace",
1503 .data
= &show_unhandled_signals
,
1504 .maxlen
= sizeof(int),
1506 .proc_handler
= proc_dointvec
1509 #if defined(CONFIG_OPTPROBES)
1511 .procname
= "kprobes-optimization",
1512 .data
= &sysctl_kprobes_optimization
,
1513 .maxlen
= sizeof(int),
1515 .proc_handler
= proc_kprobes_optimization_handler
,
1523 static struct ctl_table dev_table
[] = {
1527 static DEFINE_SPINLOCK(sysctl_lock
);
1529 /* called under sysctl_lock */
1530 static int use_table(struct ctl_table_header
*p
)
1532 if (unlikely(p
->unregistering
))
1538 /* called under sysctl_lock */
1539 static void unuse_table(struct ctl_table_header
*p
)
1542 if (unlikely(p
->unregistering
))
1543 complete(p
->unregistering
);
1546 /* called under sysctl_lock, will reacquire if has to wait */
1547 static void start_unregistering(struct ctl_table_header
*p
)
1550 * if p->used is 0, nobody will ever touch that entry again;
1551 * we'll eliminate all paths to it before dropping sysctl_lock
1553 if (unlikely(p
->used
)) {
1554 struct completion wait
;
1555 init_completion(&wait
);
1556 p
->unregistering
= &wait
;
1557 spin_unlock(&sysctl_lock
);
1558 wait_for_completion(&wait
);
1559 spin_lock(&sysctl_lock
);
1561 /* anything non-NULL; we'll never dereference it */
1562 p
->unregistering
= ERR_PTR(-EINVAL
);
1565 * do not remove from the list until nobody holds it; walking the
1566 * list in do_sysctl() relies on that.
1568 list_del_init(&p
->ctl_entry
);
1571 void sysctl_head_get(struct ctl_table_header
*head
)
1573 spin_lock(&sysctl_lock
);
1575 spin_unlock(&sysctl_lock
);
1578 void sysctl_head_put(struct ctl_table_header
*head
)
1580 spin_lock(&sysctl_lock
);
1583 spin_unlock(&sysctl_lock
);
1586 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1590 spin_lock(&sysctl_lock
);
1591 if (!use_table(head
))
1592 head
= ERR_PTR(-ENOENT
);
1593 spin_unlock(&sysctl_lock
);
1597 void sysctl_head_finish(struct ctl_table_header
*head
)
1601 spin_lock(&sysctl_lock
);
1603 spin_unlock(&sysctl_lock
);
1606 static struct ctl_table_set
*
1607 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1609 struct ctl_table_set
*set
= &root
->default_set
;
1611 set
= root
->lookup(root
, namespaces
);
1615 static struct list_head
*
1616 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1618 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1622 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1623 struct ctl_table_header
*prev
)
1625 struct ctl_table_root
*root
;
1626 struct list_head
*header_list
;
1627 struct ctl_table_header
*head
;
1628 struct list_head
*tmp
;
1630 spin_lock(&sysctl_lock
);
1633 tmp
= &prev
->ctl_entry
;
1637 tmp
= &root_table_header
.ctl_entry
;
1639 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1641 if (!use_table(head
))
1643 spin_unlock(&sysctl_lock
);
1648 header_list
= lookup_header_list(root
, namespaces
);
1649 if (tmp
!= header_list
)
1653 root
= list_entry(root
->root_list
.next
,
1654 struct ctl_table_root
, root_list
);
1655 if (root
== &sysctl_table_root
)
1657 header_list
= lookup_header_list(root
, namespaces
);
1658 } while (list_empty(header_list
));
1659 tmp
= header_list
->next
;
1662 spin_unlock(&sysctl_lock
);
1666 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1668 return __sysctl_head_next(current
->nsproxy
, prev
);
1671 void register_sysctl_root(struct ctl_table_root
*root
)
1673 spin_lock(&sysctl_lock
);
1674 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1675 spin_unlock(&sysctl_lock
);
1679 * sysctl_perm does NOT grant the superuser all rights automatically, because
1680 * some sysctl variables are readonly even to root.
1683 static int test_perm(int mode
, int op
)
1685 if (!current_euid())
1687 else if (in_egroup_p(0))
1689 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1694 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1699 error
= security_sysctl(table
, op
& (MAY_READ
| MAY_WRITE
| MAY_EXEC
));
1703 if (root
->permissions
)
1704 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1708 return test_perm(mode
, op
);
1711 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1713 for (; table
->procname
; table
++) {
1714 table
->parent
= parent
;
1716 sysctl_set_parent(table
, table
->child
);
1720 static __init
int sysctl_init(void)
1722 sysctl_set_parent(NULL
, root_table
);
1723 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1724 sysctl_check_table(current
->nsproxy
, root_table
);
1729 core_initcall(sysctl_init
);
1731 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1732 struct ctl_table
*table
)
1734 struct ctl_table
*p
;
1735 const char *s
= branch
->procname
;
1737 /* branch should have named subdirectory as its first element */
1738 if (!s
|| !branch
->child
)
1741 /* ... and nothing else */
1742 if (branch
[1].procname
)
1745 /* table should contain subdirectory with the same name */
1746 for (p
= table
; p
->procname
; p
++) {
1749 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1755 /* see if attaching q to p would be an improvement */
1756 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1758 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1759 struct ctl_table
*next
;
1761 int not_in_parent
= !p
->attached_by
;
1763 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1764 if (by
== q
->attached_by
)
1766 if (to
== p
->attached_by
)
1772 if (is_better
&& not_in_parent
) {
1773 q
->attached_by
= by
;
1774 q
->attached_to
= to
;
1780 * __register_sysctl_paths - register a sysctl hierarchy
1781 * @root: List of sysctl headers to register on
1782 * @namespaces: Data to compute which lists of sysctl entries are visible
1783 * @path: The path to the directory the sysctl table is in.
1784 * @table: the top-level table structure
1786 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1787 * array. A completely 0 filled entry terminates the table.
1789 * The members of the &struct ctl_table structure are used as follows:
1791 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1792 * enter a sysctl file
1794 * data - a pointer to data for use by proc_handler
1796 * maxlen - the maximum size in bytes of the data
1798 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1800 * child - a pointer to the child sysctl table if this entry is a directory, or
1803 * proc_handler - the text handler routine (described below)
1805 * de - for internal use by the sysctl routines
1807 * extra1, extra2 - extra pointers usable by the proc handler routines
1809 * Leaf nodes in the sysctl tree will be represented by a single file
1810 * under /proc; non-leaf nodes will be represented by directories.
1812 * sysctl(2) can automatically manage read and write requests through
1813 * the sysctl table. The data and maxlen fields of the ctl_table
1814 * struct enable minimal validation of the values being written to be
1815 * performed, and the mode field allows minimal authentication.
1817 * There must be a proc_handler routine for any terminal nodes
1818 * mirrored under /proc/sys (non-terminals are handled by a built-in
1819 * directory handler). Several default handlers are available to
1820 * cover common cases -
1822 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1823 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1824 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1826 * It is the handler's job to read the input buffer from user memory
1827 * and process it. The handler should return 0 on success.
1829 * This routine returns %NULL on a failure to register, and a pointer
1830 * to the table header on success.
1832 struct ctl_table_header
*__register_sysctl_paths(
1833 struct ctl_table_root
*root
,
1834 struct nsproxy
*namespaces
,
1835 const struct ctl_path
*path
, struct ctl_table
*table
)
1837 struct ctl_table_header
*header
;
1838 struct ctl_table
*new, **prevp
;
1839 unsigned int n
, npath
;
1840 struct ctl_table_set
*set
;
1842 /* Count the path components */
1843 for (npath
= 0; path
[npath
].procname
; ++npath
)
1847 * For each path component, allocate a 2-element ctl_table array.
1848 * The first array element will be filled with the sysctl entry
1849 * for this, the second will be the sentinel (procname == 0).
1851 * We allocate everything in one go so that we don't have to
1852 * worry about freeing additional memory in unregister_sysctl_table.
1854 header
= kzalloc(sizeof(struct ctl_table_header
) +
1855 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1859 new = (struct ctl_table
*) (header
+ 1);
1861 /* Now connect the dots */
1862 prevp
= &header
->ctl_table
;
1863 for (n
= 0; n
< npath
; ++n
, ++path
) {
1864 /* Copy the procname */
1865 new->procname
= path
->procname
;
1869 prevp
= &new->child
;
1874 header
->ctl_table_arg
= table
;
1876 INIT_LIST_HEAD(&header
->ctl_entry
);
1878 header
->unregistering
= NULL
;
1879 header
->root
= root
;
1880 sysctl_set_parent(NULL
, header
->ctl_table
);
1882 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1883 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1888 spin_lock(&sysctl_lock
);
1889 header
->set
= lookup_header_set(root
, namespaces
);
1890 header
->attached_by
= header
->ctl_table
;
1891 header
->attached_to
= root_table
;
1892 header
->parent
= &root_table_header
;
1893 for (set
= header
->set
; set
; set
= set
->parent
) {
1894 struct ctl_table_header
*p
;
1895 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1896 if (p
->unregistering
)
1898 try_attach(p
, header
);
1901 header
->parent
->count
++;
1902 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1903 spin_unlock(&sysctl_lock
);
1909 * register_sysctl_table_path - register a sysctl table hierarchy
1910 * @path: The path to the directory the sysctl table is in.
1911 * @table: the top-level table structure
1913 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1914 * array. A completely 0 filled entry terminates the table.
1916 * See __register_sysctl_paths for more details.
1918 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1919 struct ctl_table
*table
)
1921 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1926 * register_sysctl_table - register a sysctl table hierarchy
1927 * @table: the top-level table structure
1929 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1930 * array. A completely 0 filled entry terminates the table.
1932 * See register_sysctl_paths for more details.
1934 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1936 static const struct ctl_path null_path
[] = { {} };
1938 return register_sysctl_paths(null_path
, table
);
1942 * unregister_sysctl_table - unregister a sysctl table hierarchy
1943 * @header: the header returned from register_sysctl_table
1945 * Unregisters the sysctl table and all children. proc entries may not
1946 * actually be removed until they are no longer used by anyone.
1948 void unregister_sysctl_table(struct ctl_table_header
* header
)
1955 spin_lock(&sysctl_lock
);
1956 start_unregistering(header
);
1957 if (!--header
->parent
->count
) {
1959 kfree(header
->parent
);
1961 if (!--header
->count
)
1963 spin_unlock(&sysctl_lock
);
1966 int sysctl_is_seen(struct ctl_table_header
*p
)
1968 struct ctl_table_set
*set
= p
->set
;
1970 spin_lock(&sysctl_lock
);
1971 if (p
->unregistering
)
1973 else if (!set
->is_seen
)
1976 res
= set
->is_seen(set
);
1977 spin_unlock(&sysctl_lock
);
1981 void setup_sysctl_set(struct ctl_table_set
*p
,
1982 struct ctl_table_set
*parent
,
1983 int (*is_seen
)(struct ctl_table_set
*))
1985 INIT_LIST_HEAD(&p
->list
);
1986 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1987 p
->is_seen
= is_seen
;
1990 #else /* !CONFIG_SYSCTL */
1991 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1996 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1997 struct ctl_table
*table
)
2002 void unregister_sysctl_table(struct ctl_table_header
* table
)
2006 void setup_sysctl_set(struct ctl_table_set
*p
,
2007 struct ctl_table_set
*parent
,
2008 int (*is_seen
)(struct ctl_table_set
*))
2012 void sysctl_head_put(struct ctl_table_header
*head
)
2016 #endif /* CONFIG_SYSCTL */
2022 #ifdef CONFIG_PROC_SYSCTL
2024 static int _proc_do_string(void* data
, int maxlen
, int write
,
2025 void __user
*buffer
,
2026 size_t *lenp
, loff_t
*ppos
)
2032 if (!data
|| !maxlen
|| !*lenp
) {
2040 while (len
< *lenp
) {
2041 if (get_user(c
, p
++))
2043 if (c
== 0 || c
== '\n')
2049 if(copy_from_user(data
, buffer
, len
))
2051 ((char *) data
)[len
] = 0;
2069 if(copy_to_user(buffer
, data
, len
))
2072 if(put_user('\n', ((char __user
*) buffer
) + len
))
2083 * proc_dostring - read a string sysctl
2084 * @table: the sysctl table
2085 * @write: %TRUE if this is a write to the sysctl file
2086 * @buffer: the user buffer
2087 * @lenp: the size of the user buffer
2088 * @ppos: file position
2090 * Reads/writes a string from/to the user buffer. If the kernel
2091 * buffer provided is not large enough to hold the string, the
2092 * string is truncated. The copied string is %NULL-terminated.
2093 * If the string is being read by the user process, it is copied
2094 * and a newline '\n' is added. It is truncated if the buffer is
2097 * Returns 0 on success.
2099 int proc_dostring(struct ctl_table
*table
, int write
,
2100 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2102 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2103 buffer
, lenp
, ppos
);
2106 static size_t proc_skip_spaces(char **buf
)
2109 char *tmp
= skip_spaces(*buf
);
2115 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2125 #define TMPBUFLEN 22
2127 * proc_get_long - reads an ASCII formatted integer from a user buffer
2129 * @buf: a kernel buffer
2130 * @size: size of the kernel buffer
2131 * @val: this is where the number will be stored
2132 * @neg: set to %TRUE if number is negative
2133 * @perm_tr: a vector which contains the allowed trailers
2134 * @perm_tr_len: size of the perm_tr vector
2135 * @tr: pointer to store the trailer character
2137 * In case of success %0 is returned and @buf and @size are updated with
2138 * the amount of bytes read. If @tr is non-NULL and a trailing
2139 * character exists (size is non-zero after returning from this
2140 * function), @tr is updated with the trailing character.
2142 static int proc_get_long(char **buf
, size_t *size
,
2143 unsigned long *val
, bool *neg
,
2144 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2147 char *p
, tmp
[TMPBUFLEN
];
2153 if (len
> TMPBUFLEN
- 1)
2154 len
= TMPBUFLEN
- 1;
2156 memcpy(tmp
, *buf
, len
);
2160 if (*p
== '-' && *size
> 1) {
2168 *val
= simple_strtoul(p
, &p
, 0);
2172 /* We don't know if the next char is whitespace thus we may accept
2173 * invalid integers (e.g. 1234...a) or two integers instead of one
2174 * (e.g. 123...1). So lets not allow such large numbers. */
2175 if (len
== TMPBUFLEN
- 1)
2178 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2181 if (tr
&& (len
< *size
))
2191 * proc_put_long - converts an integer to a decimal ASCII formatted string
2193 * @buf: the user buffer
2194 * @size: the size of the user buffer
2195 * @val: the integer to be converted
2196 * @neg: sign of the number, %TRUE for negative
2198 * In case of success %0 is returned and @buf and @size are updated with
2199 * the amount of bytes written.
2201 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2205 char tmp
[TMPBUFLEN
], *p
= tmp
;
2207 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2211 if (copy_to_user(*buf
, tmp
, len
))
2219 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2222 char __user
**buffer
= (char __user
**)buf
;
2223 if (put_user(c
, *buffer
))
2225 (*size
)--, (*buffer
)++;
2231 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2233 int write
, void *data
)
2236 *valp
= *negp
? -*lvalp
: *lvalp
;
2241 *lvalp
= (unsigned long)-val
;
2244 *lvalp
= (unsigned long)val
;
2250 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2252 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2253 int write
, void __user
*buffer
,
2254 size_t *lenp
, loff_t
*ppos
,
2255 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2256 int write
, void *data
),
2259 int *i
, vleft
, first
= 1, err
= 0;
2260 unsigned long page
= 0;
2264 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2269 i
= (int *) tbl_data
;
2270 vleft
= table
->maxlen
/ sizeof(*i
);
2274 conv
= do_proc_dointvec_conv
;
2277 if (left
> PAGE_SIZE
- 1)
2278 left
= PAGE_SIZE
- 1;
2279 page
= __get_free_page(GFP_TEMPORARY
);
2280 kbuf
= (char *) page
;
2283 if (copy_from_user(kbuf
, buffer
, left
)) {
2290 for (; left
&& vleft
--; i
++, first
=0) {
2295 left
-= proc_skip_spaces(&kbuf
);
2299 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2301 sizeof(proc_wspace_sep
), NULL
);
2304 if (conv(&neg
, &lval
, i
, 1, data
)) {
2309 if (conv(&neg
, &lval
, i
, 0, data
)) {
2314 err
= proc_put_char(&buffer
, &left
, '\t');
2317 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2323 if (!write
&& !first
&& left
&& !err
)
2324 err
= proc_put_char(&buffer
, &left
, '\n');
2325 if (write
&& !err
&& left
)
2326 left
-= proc_skip_spaces(&kbuf
);
2331 return err
? : -EINVAL
;
2338 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2339 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2340 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2341 int write
, void *data
),
2344 return __do_proc_dointvec(table
->data
, table
, write
,
2345 buffer
, lenp
, ppos
, conv
, data
);
2349 * proc_dointvec - read a vector of integers
2350 * @table: the sysctl table
2351 * @write: %TRUE if this is a write to the sysctl file
2352 * @buffer: the user buffer
2353 * @lenp: the size of the user buffer
2354 * @ppos: file position
2356 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2357 * values from/to the user buffer, treated as an ASCII string.
2359 * Returns 0 on success.
2361 int proc_dointvec(struct ctl_table
*table
, int write
,
2362 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2364 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2369 * Taint values can only be increased
2370 * This means we can safely use a temporary.
2372 static int proc_taint(struct ctl_table
*table
, int write
,
2373 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2376 unsigned long tmptaint
= get_taint();
2379 if (write
&& !capable(CAP_SYS_ADMIN
))
2384 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2390 * Poor man's atomic or. Not worth adding a primitive
2391 * to everyone's atomic.h for this
2394 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2395 if ((tmptaint
>> i
) & 1)
2403 struct do_proc_dointvec_minmax_conv_param
{
2408 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2410 int write
, void *data
)
2412 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2414 int val
= *negp
? -*lvalp
: *lvalp
;
2415 if ((param
->min
&& *param
->min
> val
) ||
2416 (param
->max
&& *param
->max
< val
))
2423 *lvalp
= (unsigned long)-val
;
2426 *lvalp
= (unsigned long)val
;
2433 * proc_dointvec_minmax - read a vector of integers with min/max values
2434 * @table: the sysctl table
2435 * @write: %TRUE if this is a write to the sysctl file
2436 * @buffer: the user buffer
2437 * @lenp: the size of the user buffer
2438 * @ppos: file position
2440 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2441 * values from/to the user buffer, treated as an ASCII string.
2443 * This routine will ensure the values are within the range specified by
2444 * table->extra1 (min) and table->extra2 (max).
2446 * Returns 0 on success.
2448 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2449 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2451 struct do_proc_dointvec_minmax_conv_param param
= {
2452 .min
= (int *) table
->extra1
,
2453 .max
= (int *) table
->extra2
,
2455 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2456 do_proc_dointvec_minmax_conv
, ¶m
);
2459 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2460 void __user
*buffer
,
2461 size_t *lenp
, loff_t
*ppos
,
2462 unsigned long convmul
,
2463 unsigned long convdiv
)
2465 unsigned long *i
, *min
, *max
;
2466 int vleft
, first
= 1, err
= 0;
2467 unsigned long page
= 0;
2471 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2476 i
= (unsigned long *) data
;
2477 min
= (unsigned long *) table
->extra1
;
2478 max
= (unsigned long *) table
->extra2
;
2479 vleft
= table
->maxlen
/ sizeof(unsigned long);
2483 if (left
> PAGE_SIZE
- 1)
2484 left
= PAGE_SIZE
- 1;
2485 page
= __get_free_page(GFP_TEMPORARY
);
2486 kbuf
= (char *) page
;
2489 if (copy_from_user(kbuf
, buffer
, left
)) {
2496 for (; left
&& vleft
--; i
++, first
= 0) {
2502 left
-= proc_skip_spaces(&kbuf
);
2504 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2506 sizeof(proc_wspace_sep
), NULL
);
2511 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2515 val
= convdiv
* (*i
) / convmul
;
2517 err
= proc_put_char(&buffer
, &left
, '\t');
2518 err
= proc_put_long(&buffer
, &left
, val
, false);
2524 if (!write
&& !first
&& left
&& !err
)
2525 err
= proc_put_char(&buffer
, &left
, '\n');
2527 left
-= proc_skip_spaces(&kbuf
);
2532 return err
? : -EINVAL
;
2539 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2540 void __user
*buffer
,
2541 size_t *lenp
, loff_t
*ppos
,
2542 unsigned long convmul
,
2543 unsigned long convdiv
)
2545 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2546 buffer
, lenp
, ppos
, convmul
, convdiv
);
2550 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2551 * @table: the sysctl table
2552 * @write: %TRUE if this is a write to the sysctl file
2553 * @buffer: the user buffer
2554 * @lenp: the size of the user buffer
2555 * @ppos: file position
2557 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2558 * values from/to the user buffer, treated as an ASCII string.
2560 * This routine will ensure the values are within the range specified by
2561 * table->extra1 (min) and table->extra2 (max).
2563 * Returns 0 on success.
2565 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2566 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2568 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2572 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2573 * @table: the sysctl table
2574 * @write: %TRUE if this is a write to the sysctl file
2575 * @buffer: the user buffer
2576 * @lenp: the size of the user buffer
2577 * @ppos: file position
2579 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2580 * values from/to the user buffer, treated as an ASCII string. The values
2581 * are treated as milliseconds, and converted to jiffies when they are stored.
2583 * This routine will ensure the values are within the range specified by
2584 * table->extra1 (min) and table->extra2 (max).
2586 * Returns 0 on success.
2588 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2589 void __user
*buffer
,
2590 size_t *lenp
, loff_t
*ppos
)
2592 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2593 lenp
, ppos
, HZ
, 1000l);
2597 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2599 int write
, void *data
)
2602 if (*lvalp
> LONG_MAX
/ HZ
)
2604 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2610 lval
= (unsigned long)-val
;
2613 lval
= (unsigned long)val
;
2620 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2622 int write
, void *data
)
2625 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2627 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2633 lval
= (unsigned long)-val
;
2636 lval
= (unsigned long)val
;
2638 *lvalp
= jiffies_to_clock_t(lval
);
2643 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2645 int write
, void *data
)
2648 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2654 lval
= (unsigned long)-val
;
2657 lval
= (unsigned long)val
;
2659 *lvalp
= jiffies_to_msecs(lval
);
2665 * proc_dointvec_jiffies - read a vector of integers as seconds
2666 * @table: the sysctl table
2667 * @write: %TRUE if this is a write to the sysctl file
2668 * @buffer: the user buffer
2669 * @lenp: the size of the user buffer
2670 * @ppos: file position
2672 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2673 * values from/to the user buffer, treated as an ASCII string.
2674 * The values read are assumed to be in seconds, and are converted into
2677 * Returns 0 on success.
2679 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2680 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2682 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2683 do_proc_dointvec_jiffies_conv
,NULL
);
2687 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2688 * @table: the sysctl table
2689 * @write: %TRUE if this is a write to the sysctl file
2690 * @buffer: the user buffer
2691 * @lenp: the size of the user buffer
2692 * @ppos: pointer to the file position
2694 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2695 * values from/to the user buffer, treated as an ASCII string.
2696 * The values read are assumed to be in 1/USER_HZ seconds, and
2697 * are converted into jiffies.
2699 * Returns 0 on success.
2701 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2702 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2704 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2705 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2709 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2710 * @table: the sysctl table
2711 * @write: %TRUE if this is a write to the sysctl file
2712 * @buffer: the user buffer
2713 * @lenp: the size of the user buffer
2714 * @ppos: file position
2715 * @ppos: the current position in the file
2717 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2718 * values from/to the user buffer, treated as an ASCII string.
2719 * The values read are assumed to be in 1/1000 seconds, and
2720 * are converted into jiffies.
2722 * Returns 0 on success.
2724 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2725 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2727 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2728 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2731 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2732 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2734 struct pid
*new_pid
;
2738 tmp
= pid_vnr(cad_pid
);
2740 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2741 lenp
, ppos
, NULL
, NULL
);
2745 new_pid
= find_get_pid(tmp
);
2749 put_pid(xchg(&cad_pid
, new_pid
));
2754 * proc_do_large_bitmap - read/write from/to a large bitmap
2755 * @table: the sysctl table
2756 * @write: %TRUE if this is a write to the sysctl file
2757 * @buffer: the user buffer
2758 * @lenp: the size of the user buffer
2759 * @ppos: file position
2761 * The bitmap is stored at table->data and the bitmap length (in bits)
2764 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2765 * large bitmaps may be represented in a compact manner. Writing into
2766 * the file will clear the bitmap then update it with the given input.
2768 * Returns 0 on success.
2770 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2771 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2775 size_t left
= *lenp
;
2776 unsigned long bitmap_len
= table
->maxlen
;
2777 unsigned long *bitmap
= (unsigned long *) table
->data
;
2778 unsigned long *tmp_bitmap
= NULL
;
2779 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2781 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2787 unsigned long page
= 0;
2790 if (left
> PAGE_SIZE
- 1)
2791 left
= PAGE_SIZE
- 1;
2793 page
= __get_free_page(GFP_TEMPORARY
);
2794 kbuf
= (char *) page
;
2797 if (copy_from_user(kbuf
, buffer
, left
)) {
2803 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2809 proc_skip_char(&kbuf
, &left
, '\n');
2810 while (!err
&& left
) {
2811 unsigned long val_a
, val_b
;
2814 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2818 if (val_a
>= bitmap_len
|| neg
) {
2830 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2831 &neg
, tr_b
, sizeof(tr_b
),
2835 if (val_b
>= bitmap_len
|| neg
||
2846 while (val_a
<= val_b
)
2847 set_bit(val_a
++, tmp_bitmap
);
2850 proc_skip_char(&kbuf
, &left
, '\n');
2854 unsigned long bit_a
, bit_b
= 0;
2857 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2858 if (bit_a
>= bitmap_len
)
2860 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2864 err
= proc_put_char(&buffer
, &left
, ',');
2868 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2871 if (bit_a
!= bit_b
) {
2872 err
= proc_put_char(&buffer
, &left
, '-');
2875 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2883 err
= proc_put_char(&buffer
, &left
, '\n');
2889 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2891 memcpy(bitmap
, tmp_bitmap
,
2892 BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long));
2904 #else /* CONFIG_PROC_FS */
2906 int proc_dostring(struct ctl_table
*table
, int write
,
2907 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2912 int proc_dointvec(struct ctl_table
*table
, int write
,
2913 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2918 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2919 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2924 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2925 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2930 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2931 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2936 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2937 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2942 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2943 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2948 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2949 void __user
*buffer
,
2950 size_t *lenp
, loff_t
*ppos
)
2956 #endif /* CONFIG_PROC_FS */
2959 * No sense putting this after each symbol definition, twice,
2960 * exception granted :-)
2962 EXPORT_SYMBOL(proc_dointvec
);
2963 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2964 EXPORT_SYMBOL(proc_dointvec_minmax
);
2965 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2966 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2967 EXPORT_SYMBOL(proc_dostring
);
2968 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2969 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2970 EXPORT_SYMBOL(register_sysctl_table
);
2971 EXPORT_SYMBOL(register_sysctl_paths
);
2972 EXPORT_SYMBOL(unregister_sysctl_table
);