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>
59 #include <linux/kmod.h>
60 #include <linux/capability.h>
62 #include <asm/uaccess.h>
63 #include <asm/processor.h>
67 #include <asm/stacktrace.h>
70 #ifdef CONFIG_BSD_PROCESS_ACCT
71 #include <linux/acct.h>
73 #ifdef CONFIG_RT_MUTEXES
74 #include <linux/rtmutex.h>
76 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
77 #include <linux/lockdep.h>
79 #ifdef CONFIG_CHR_DEV_SG
83 #ifdef CONFIG_LOCKUP_DETECTOR
84 #include <linux/nmi.h>
88 #if defined(CONFIG_SYSCTL)
90 /* External variables not in a header file. */
91 extern int sysctl_overcommit_memory
;
92 extern int sysctl_overcommit_ratio
;
93 extern int max_threads
;
94 extern int core_uses_pid
;
95 extern int suid_dumpable
;
96 extern char core_pattern
[];
97 extern unsigned int core_pipe_limit
;
99 extern int min_free_kbytes
;
100 extern int pid_max_min
, pid_max_max
;
101 extern int sysctl_drop_caches
;
102 extern int percpu_pagelist_fraction
;
103 extern int compat_log
;
104 extern int latencytop_enabled
;
105 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
107 extern int sysctl_nr_trim_pages
;
110 extern int blk_iopoll_enabled
;
113 /* Constants used for minimum and maximum */
114 #ifdef CONFIG_LOCKUP_DETECTOR
115 static int sixty
= 60;
116 static int neg_one
= -1;
120 static int __maybe_unused one
= 1;
121 static int __maybe_unused two
= 2;
122 static int __maybe_unused three
= 3;
123 static unsigned long one_ul
= 1;
124 static int one_hundred
= 100;
126 static int ten_thousand
= 10000;
129 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
130 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
132 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
133 static int maxolduid
= 65535;
134 static int minolduid
;
135 static int min_percpu_pagelist_fract
= 8;
137 static int ngroups_max
= NGROUPS_MAX
;
138 static const int cap_last_cap
= CAP_LAST_CAP
;
140 #ifdef CONFIG_INOTIFY_USER
141 #include <linux/inotify.h>
144 #include <asm/system.h>
147 #ifdef CONFIG_SPARC64
148 extern int sysctl_tsb_ratio
;
152 extern int pwrsw_enabled
;
153 extern int unaligned_enabled
;
157 extern int no_unaligned_warning
;
158 extern int unaligned_dump_stack
;
161 #ifdef CONFIG_PROC_SYSCTL
162 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
163 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
164 static int proc_taint(struct ctl_table
*table
, int write
,
165 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
169 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
170 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
173 #ifdef CONFIG_MAGIC_SYSRQ
174 /* Note: sysrq code uses it's own private copy */
175 static int __sysrq_enabled
= SYSRQ_DEFAULT_ENABLE
;
177 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
178 void __user
*buffer
, size_t *lenp
,
183 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
188 sysrq_toggle_support(__sysrq_enabled
);
195 static struct ctl_table root_table
[];
196 static struct ctl_table_root sysctl_table_root
;
197 static struct ctl_table_header root_table_header
= {
199 .ctl_table
= root_table
,
200 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),}},
201 .root
= &sysctl_table_root
,
202 .set
= &sysctl_table_root
.default_set
,
204 static struct ctl_table_root sysctl_table_root
= {
205 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
206 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
209 static struct ctl_table kern_table
[];
210 static struct ctl_table vm_table
[];
211 static struct ctl_table fs_table
[];
212 static struct ctl_table debug_table
[];
213 static struct ctl_table dev_table
[];
214 extern struct ctl_table random_table
[];
216 extern struct ctl_table epoll_table
[];
219 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
220 int sysctl_legacy_va_layout
;
223 /* The default sysctl tables: */
225 static struct ctl_table root_table
[] = {
227 .procname
= "kernel",
244 .child
= debug_table
,
254 #ifdef CONFIG_SCHED_DEBUG
255 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
256 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
257 static int min_wakeup_granularity_ns
; /* 0 usecs */
258 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
259 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
260 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
263 #ifdef CONFIG_COMPACTION
264 static int min_extfrag_threshold
;
265 static int max_extfrag_threshold
= 1000;
268 static struct ctl_table kern_table
[] = {
270 .procname
= "sched_child_runs_first",
271 .data
= &sysctl_sched_child_runs_first
,
272 .maxlen
= sizeof(unsigned int),
274 .proc_handler
= proc_dointvec
,
276 #ifdef CONFIG_SCHED_DEBUG
278 .procname
= "sched_min_granularity_ns",
279 .data
= &sysctl_sched_min_granularity
,
280 .maxlen
= sizeof(unsigned int),
282 .proc_handler
= sched_proc_update_handler
,
283 .extra1
= &min_sched_granularity_ns
,
284 .extra2
= &max_sched_granularity_ns
,
287 .procname
= "sched_latency_ns",
288 .data
= &sysctl_sched_latency
,
289 .maxlen
= sizeof(unsigned int),
291 .proc_handler
= sched_proc_update_handler
,
292 .extra1
= &min_sched_granularity_ns
,
293 .extra2
= &max_sched_granularity_ns
,
296 .procname
= "sched_wakeup_granularity_ns",
297 .data
= &sysctl_sched_wakeup_granularity
,
298 .maxlen
= sizeof(unsigned int),
300 .proc_handler
= sched_proc_update_handler
,
301 .extra1
= &min_wakeup_granularity_ns
,
302 .extra2
= &max_wakeup_granularity_ns
,
305 .procname
= "sched_tunable_scaling",
306 .data
= &sysctl_sched_tunable_scaling
,
307 .maxlen
= sizeof(enum sched_tunable_scaling
),
309 .proc_handler
= sched_proc_update_handler
,
310 .extra1
= &min_sched_tunable_scaling
,
311 .extra2
= &max_sched_tunable_scaling
,
314 .procname
= "sched_migration_cost",
315 .data
= &sysctl_sched_migration_cost
,
316 .maxlen
= sizeof(unsigned int),
318 .proc_handler
= proc_dointvec
,
321 .procname
= "sched_nr_migrate",
322 .data
= &sysctl_sched_nr_migrate
,
323 .maxlen
= sizeof(unsigned int),
325 .proc_handler
= proc_dointvec
,
328 .procname
= "sched_time_avg",
329 .data
= &sysctl_sched_time_avg
,
330 .maxlen
= sizeof(unsigned int),
332 .proc_handler
= proc_dointvec
,
335 .procname
= "sched_shares_window",
336 .data
= &sysctl_sched_shares_window
,
337 .maxlen
= sizeof(unsigned int),
339 .proc_handler
= proc_dointvec
,
342 .procname
= "timer_migration",
343 .data
= &sysctl_timer_migration
,
344 .maxlen
= sizeof(unsigned int),
346 .proc_handler
= proc_dointvec_minmax
,
352 .procname
= "sched_rt_period_us",
353 .data
= &sysctl_sched_rt_period
,
354 .maxlen
= sizeof(unsigned int),
356 .proc_handler
= sched_rt_handler
,
359 .procname
= "sched_rt_runtime_us",
360 .data
= &sysctl_sched_rt_runtime
,
361 .maxlen
= sizeof(int),
363 .proc_handler
= sched_rt_handler
,
365 #ifdef CONFIG_SCHED_AUTOGROUP
367 .procname
= "sched_autogroup_enabled",
368 .data
= &sysctl_sched_autogroup_enabled
,
369 .maxlen
= sizeof(unsigned int),
371 .proc_handler
= proc_dointvec_minmax
,
376 #ifdef CONFIG_CFS_BANDWIDTH
378 .procname
= "sched_cfs_bandwidth_slice_us",
379 .data
= &sysctl_sched_cfs_bandwidth_slice
,
380 .maxlen
= sizeof(unsigned int),
382 .proc_handler
= proc_dointvec_minmax
,
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
= "usermodehelper",
626 .child
= usermodehelper_table
,
629 .procname
= "overflowuid",
630 .data
= &overflowuid
,
631 .maxlen
= sizeof(int),
633 .proc_handler
= proc_dointvec_minmax
,
634 .extra1
= &minolduid
,
635 .extra2
= &maxolduid
,
638 .procname
= "overflowgid",
639 .data
= &overflowgid
,
640 .maxlen
= sizeof(int),
642 .proc_handler
= proc_dointvec_minmax
,
643 .extra1
= &minolduid
,
644 .extra2
= &maxolduid
,
647 #ifdef CONFIG_MATHEMU
649 .procname
= "ieee_emulation_warnings",
650 .data
= &sysctl_ieee_emulation_warnings
,
651 .maxlen
= sizeof(int),
653 .proc_handler
= proc_dointvec
,
657 .procname
= "userprocess_debug",
658 .data
= &show_unhandled_signals
,
659 .maxlen
= sizeof(int),
661 .proc_handler
= proc_dointvec
,
665 .procname
= "pid_max",
667 .maxlen
= sizeof (int),
669 .proc_handler
= proc_dointvec_minmax
,
670 .extra1
= &pid_max_min
,
671 .extra2
= &pid_max_max
,
674 .procname
= "panic_on_oops",
675 .data
= &panic_on_oops
,
676 .maxlen
= sizeof(int),
678 .proc_handler
= proc_dointvec
,
680 #if defined CONFIG_PRINTK
682 .procname
= "printk",
683 .data
= &console_loglevel
,
684 .maxlen
= 4*sizeof(int),
686 .proc_handler
= proc_dointvec
,
689 .procname
= "printk_ratelimit",
690 .data
= &printk_ratelimit_state
.interval
,
691 .maxlen
= sizeof(int),
693 .proc_handler
= proc_dointvec_jiffies
,
696 .procname
= "printk_ratelimit_burst",
697 .data
= &printk_ratelimit_state
.burst
,
698 .maxlen
= sizeof(int),
700 .proc_handler
= proc_dointvec
,
703 .procname
= "printk_delay",
704 .data
= &printk_delay_msec
,
705 .maxlen
= sizeof(int),
707 .proc_handler
= proc_dointvec_minmax
,
709 .extra2
= &ten_thousand
,
712 .procname
= "dmesg_restrict",
713 .data
= &dmesg_restrict
,
714 .maxlen
= sizeof(int),
716 .proc_handler
= proc_dointvec_minmax_sysadmin
,
721 .procname
= "kptr_restrict",
722 .data
= &kptr_restrict
,
723 .maxlen
= sizeof(int),
725 .proc_handler
= proc_dointvec_minmax_sysadmin
,
731 .procname
= "ngroups_max",
732 .data
= &ngroups_max
,
733 .maxlen
= sizeof (int),
735 .proc_handler
= proc_dointvec
,
738 .procname
= "cap_last_cap",
739 .data
= (void *)&cap_last_cap
,
740 .maxlen
= sizeof(int),
742 .proc_handler
= proc_dointvec
,
744 #if defined(CONFIG_LOCKUP_DETECTOR)
746 .procname
= "watchdog",
747 .data
= &watchdog_enabled
,
748 .maxlen
= sizeof (int),
750 .proc_handler
= proc_dowatchdog
,
755 .procname
= "watchdog_thresh",
756 .data
= &watchdog_thresh
,
757 .maxlen
= sizeof(int),
759 .proc_handler
= proc_dowatchdog
,
764 .procname
= "softlockup_panic",
765 .data
= &softlockup_panic
,
766 .maxlen
= sizeof(int),
768 .proc_handler
= proc_dointvec_minmax
,
773 .procname
= "nmi_watchdog",
774 .data
= &watchdog_enabled
,
775 .maxlen
= sizeof (int),
777 .proc_handler
= proc_dowatchdog
,
782 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
784 .procname
= "unknown_nmi_panic",
785 .data
= &unknown_nmi_panic
,
786 .maxlen
= sizeof (int),
788 .proc_handler
= proc_dointvec
,
791 #if defined(CONFIG_X86)
793 .procname
= "panic_on_unrecovered_nmi",
794 .data
= &panic_on_unrecovered_nmi
,
795 .maxlen
= sizeof(int),
797 .proc_handler
= proc_dointvec
,
800 .procname
= "panic_on_io_nmi",
801 .data
= &panic_on_io_nmi
,
802 .maxlen
= sizeof(int),
804 .proc_handler
= proc_dointvec
,
807 .procname
= "bootloader_type",
808 .data
= &bootloader_type
,
809 .maxlen
= sizeof (int),
811 .proc_handler
= proc_dointvec
,
814 .procname
= "bootloader_version",
815 .data
= &bootloader_version
,
816 .maxlen
= sizeof (int),
818 .proc_handler
= proc_dointvec
,
821 .procname
= "kstack_depth_to_print",
822 .data
= &kstack_depth_to_print
,
823 .maxlen
= sizeof(int),
825 .proc_handler
= proc_dointvec
,
828 .procname
= "io_delay_type",
829 .data
= &io_delay_type
,
830 .maxlen
= sizeof(int),
832 .proc_handler
= proc_dointvec
,
835 #if defined(CONFIG_MMU)
837 .procname
= "randomize_va_space",
838 .data
= &randomize_va_space
,
839 .maxlen
= sizeof(int),
841 .proc_handler
= proc_dointvec
,
844 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
846 .procname
= "spin_retry",
848 .maxlen
= sizeof (int),
850 .proc_handler
= proc_dointvec
,
853 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
855 .procname
= "acpi_video_flags",
856 .data
= &acpi_realmode_flags
,
857 .maxlen
= sizeof (unsigned long),
859 .proc_handler
= proc_doulongvec_minmax
,
864 .procname
= "ignore-unaligned-usertrap",
865 .data
= &no_unaligned_warning
,
866 .maxlen
= sizeof (int),
868 .proc_handler
= proc_dointvec
,
871 .procname
= "unaligned-dump-stack",
872 .data
= &unaligned_dump_stack
,
873 .maxlen
= sizeof (int),
875 .proc_handler
= proc_dointvec
,
878 #ifdef CONFIG_DETECT_HUNG_TASK
880 .procname
= "hung_task_panic",
881 .data
= &sysctl_hung_task_panic
,
882 .maxlen
= sizeof(int),
884 .proc_handler
= proc_dointvec_minmax
,
889 .procname
= "hung_task_check_count",
890 .data
= &sysctl_hung_task_check_count
,
891 .maxlen
= sizeof(unsigned long),
893 .proc_handler
= proc_doulongvec_minmax
,
896 .procname
= "hung_task_timeout_secs",
897 .data
= &sysctl_hung_task_timeout_secs
,
898 .maxlen
= sizeof(unsigned long),
900 .proc_handler
= proc_dohung_task_timeout_secs
,
903 .procname
= "hung_task_warnings",
904 .data
= &sysctl_hung_task_warnings
,
905 .maxlen
= sizeof(unsigned long),
907 .proc_handler
= proc_doulongvec_minmax
,
912 .procname
= "compat-log",
914 .maxlen
= sizeof (int),
916 .proc_handler
= proc_dointvec
,
919 #ifdef CONFIG_RT_MUTEXES
921 .procname
= "max_lock_depth",
922 .data
= &max_lock_depth
,
923 .maxlen
= sizeof(int),
925 .proc_handler
= proc_dointvec
,
929 .procname
= "poweroff_cmd",
930 .data
= &poweroff_cmd
,
931 .maxlen
= POWEROFF_CMD_PATH_LEN
,
933 .proc_handler
= proc_dostring
,
939 .child
= key_sysctls
,
942 #ifdef CONFIG_RCU_TORTURE_TEST
944 .procname
= "rcutorture_runnable",
945 .data
= &rcutorture_runnable
,
946 .maxlen
= sizeof(int),
948 .proc_handler
= proc_dointvec
,
951 #ifdef CONFIG_PERF_EVENTS
953 * User-space scripts rely on the existence of this file
954 * as a feature check for perf_events being enabled.
956 * So it's an ABI, do not remove!
959 .procname
= "perf_event_paranoid",
960 .data
= &sysctl_perf_event_paranoid
,
961 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
963 .proc_handler
= proc_dointvec
,
966 .procname
= "perf_event_mlock_kb",
967 .data
= &sysctl_perf_event_mlock
,
968 .maxlen
= sizeof(sysctl_perf_event_mlock
),
970 .proc_handler
= proc_dointvec
,
973 .procname
= "perf_event_max_sample_rate",
974 .data
= &sysctl_perf_event_sample_rate
,
975 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
977 .proc_handler
= perf_proc_update_handler
,
980 #ifdef CONFIG_KMEMCHECK
982 .procname
= "kmemcheck",
983 .data
= &kmemcheck_enabled
,
984 .maxlen
= sizeof(int),
986 .proc_handler
= proc_dointvec
,
991 .procname
= "blk_iopoll",
992 .data
= &blk_iopoll_enabled
,
993 .maxlen
= sizeof(int),
995 .proc_handler
= proc_dointvec
,
1001 static struct ctl_table vm_table
[] = {
1003 .procname
= "overcommit_memory",
1004 .data
= &sysctl_overcommit_memory
,
1005 .maxlen
= sizeof(sysctl_overcommit_memory
),
1007 .proc_handler
= proc_dointvec_minmax
,
1012 .procname
= "panic_on_oom",
1013 .data
= &sysctl_panic_on_oom
,
1014 .maxlen
= sizeof(sysctl_panic_on_oom
),
1016 .proc_handler
= proc_dointvec_minmax
,
1021 .procname
= "oom_kill_allocating_task",
1022 .data
= &sysctl_oom_kill_allocating_task
,
1023 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1025 .proc_handler
= proc_dointvec
,
1028 .procname
= "oom_dump_tasks",
1029 .data
= &sysctl_oom_dump_tasks
,
1030 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1032 .proc_handler
= proc_dointvec
,
1035 .procname
= "overcommit_ratio",
1036 .data
= &sysctl_overcommit_ratio
,
1037 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1039 .proc_handler
= proc_dointvec
,
1042 .procname
= "page-cluster",
1043 .data
= &page_cluster
,
1044 .maxlen
= sizeof(int),
1046 .proc_handler
= proc_dointvec_minmax
,
1050 .procname
= "dirty_background_ratio",
1051 .data
= &dirty_background_ratio
,
1052 .maxlen
= sizeof(dirty_background_ratio
),
1054 .proc_handler
= dirty_background_ratio_handler
,
1056 .extra2
= &one_hundred
,
1059 .procname
= "dirty_background_bytes",
1060 .data
= &dirty_background_bytes
,
1061 .maxlen
= sizeof(dirty_background_bytes
),
1063 .proc_handler
= dirty_background_bytes_handler
,
1067 .procname
= "dirty_ratio",
1068 .data
= &vm_dirty_ratio
,
1069 .maxlen
= sizeof(vm_dirty_ratio
),
1071 .proc_handler
= dirty_ratio_handler
,
1073 .extra2
= &one_hundred
,
1076 .procname
= "dirty_bytes",
1077 .data
= &vm_dirty_bytes
,
1078 .maxlen
= sizeof(vm_dirty_bytes
),
1080 .proc_handler
= dirty_bytes_handler
,
1081 .extra1
= &dirty_bytes_min
,
1084 .procname
= "dirty_writeback_centisecs",
1085 .data
= &dirty_writeback_interval
,
1086 .maxlen
= sizeof(dirty_writeback_interval
),
1088 .proc_handler
= dirty_writeback_centisecs_handler
,
1091 .procname
= "dirty_expire_centisecs",
1092 .data
= &dirty_expire_interval
,
1093 .maxlen
= sizeof(dirty_expire_interval
),
1095 .proc_handler
= proc_dointvec_minmax
,
1099 .procname
= "nr_pdflush_threads",
1100 .data
= &nr_pdflush_threads
,
1101 .maxlen
= sizeof nr_pdflush_threads
,
1102 .mode
= 0444 /* read-only*/,
1103 .proc_handler
= proc_dointvec
,
1106 .procname
= "swappiness",
1107 .data
= &vm_swappiness
,
1108 .maxlen
= sizeof(vm_swappiness
),
1110 .proc_handler
= proc_dointvec_minmax
,
1112 .extra2
= &one_hundred
,
1114 #ifdef CONFIG_HUGETLB_PAGE
1116 .procname
= "nr_hugepages",
1118 .maxlen
= sizeof(unsigned long),
1120 .proc_handler
= hugetlb_sysctl_handler
,
1121 .extra1
= (void *)&hugetlb_zero
,
1122 .extra2
= (void *)&hugetlb_infinity
,
1126 .procname
= "nr_hugepages_mempolicy",
1128 .maxlen
= sizeof(unsigned long),
1130 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1131 .extra1
= (void *)&hugetlb_zero
,
1132 .extra2
= (void *)&hugetlb_infinity
,
1136 .procname
= "hugetlb_shm_group",
1137 .data
= &sysctl_hugetlb_shm_group
,
1138 .maxlen
= sizeof(gid_t
),
1140 .proc_handler
= proc_dointvec
,
1143 .procname
= "hugepages_treat_as_movable",
1144 .data
= &hugepages_treat_as_movable
,
1145 .maxlen
= sizeof(int),
1147 .proc_handler
= hugetlb_treat_movable_handler
,
1150 .procname
= "nr_overcommit_hugepages",
1152 .maxlen
= sizeof(unsigned long),
1154 .proc_handler
= hugetlb_overcommit_handler
,
1155 .extra1
= (void *)&hugetlb_zero
,
1156 .extra2
= (void *)&hugetlb_infinity
,
1160 .procname
= "lowmem_reserve_ratio",
1161 .data
= &sysctl_lowmem_reserve_ratio
,
1162 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1164 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1167 .procname
= "drop_caches",
1168 .data
= &sysctl_drop_caches
,
1169 .maxlen
= sizeof(int),
1171 .proc_handler
= drop_caches_sysctl_handler
,
1175 #ifdef CONFIG_COMPACTION
1177 .procname
= "compact_memory",
1178 .data
= &sysctl_compact_memory
,
1179 .maxlen
= sizeof(int),
1181 .proc_handler
= sysctl_compaction_handler
,
1184 .procname
= "extfrag_threshold",
1185 .data
= &sysctl_extfrag_threshold
,
1186 .maxlen
= sizeof(int),
1188 .proc_handler
= sysctl_extfrag_handler
,
1189 .extra1
= &min_extfrag_threshold
,
1190 .extra2
= &max_extfrag_threshold
,
1193 #endif /* CONFIG_COMPACTION */
1195 .procname
= "min_free_kbytes",
1196 .data
= &min_free_kbytes
,
1197 .maxlen
= sizeof(min_free_kbytes
),
1199 .proc_handler
= min_free_kbytes_sysctl_handler
,
1203 .procname
= "percpu_pagelist_fraction",
1204 .data
= &percpu_pagelist_fraction
,
1205 .maxlen
= sizeof(percpu_pagelist_fraction
),
1207 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1208 .extra1
= &min_percpu_pagelist_fract
,
1212 .procname
= "max_map_count",
1213 .data
= &sysctl_max_map_count
,
1214 .maxlen
= sizeof(sysctl_max_map_count
),
1216 .proc_handler
= proc_dointvec_minmax
,
1221 .procname
= "nr_trim_pages",
1222 .data
= &sysctl_nr_trim_pages
,
1223 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1225 .proc_handler
= proc_dointvec_minmax
,
1230 .procname
= "laptop_mode",
1231 .data
= &laptop_mode
,
1232 .maxlen
= sizeof(laptop_mode
),
1234 .proc_handler
= proc_dointvec_jiffies
,
1237 .procname
= "block_dump",
1238 .data
= &block_dump
,
1239 .maxlen
= sizeof(block_dump
),
1241 .proc_handler
= proc_dointvec
,
1245 .procname
= "vfs_cache_pressure",
1246 .data
= &sysctl_vfs_cache_pressure
,
1247 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1249 .proc_handler
= proc_dointvec
,
1252 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1254 .procname
= "legacy_va_layout",
1255 .data
= &sysctl_legacy_va_layout
,
1256 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1258 .proc_handler
= proc_dointvec
,
1264 .procname
= "zone_reclaim_mode",
1265 .data
= &zone_reclaim_mode
,
1266 .maxlen
= sizeof(zone_reclaim_mode
),
1268 .proc_handler
= proc_dointvec
,
1272 .procname
= "min_unmapped_ratio",
1273 .data
= &sysctl_min_unmapped_ratio
,
1274 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1276 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1278 .extra2
= &one_hundred
,
1281 .procname
= "min_slab_ratio",
1282 .data
= &sysctl_min_slab_ratio
,
1283 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1285 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1287 .extra2
= &one_hundred
,
1292 .procname
= "stat_interval",
1293 .data
= &sysctl_stat_interval
,
1294 .maxlen
= sizeof(sysctl_stat_interval
),
1296 .proc_handler
= proc_dointvec_jiffies
,
1301 .procname
= "mmap_min_addr",
1302 .data
= &dac_mmap_min_addr
,
1303 .maxlen
= sizeof(unsigned long),
1305 .proc_handler
= mmap_min_addr_handler
,
1310 .procname
= "numa_zonelist_order",
1311 .data
= &numa_zonelist_order
,
1312 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1314 .proc_handler
= numa_zonelist_order_handler
,
1317 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1318 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1320 .procname
= "vdso_enabled",
1321 .data
= &vdso_enabled
,
1322 .maxlen
= sizeof(vdso_enabled
),
1324 .proc_handler
= proc_dointvec
,
1328 #ifdef CONFIG_HIGHMEM
1330 .procname
= "highmem_is_dirtyable",
1331 .data
= &vm_highmem_is_dirtyable
,
1332 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1334 .proc_handler
= proc_dointvec_minmax
,
1340 .procname
= "scan_unevictable_pages",
1341 .data
= &scan_unevictable_pages
,
1342 .maxlen
= sizeof(scan_unevictable_pages
),
1344 .proc_handler
= scan_unevictable_handler
,
1346 #ifdef CONFIG_MEMORY_FAILURE
1348 .procname
= "memory_failure_early_kill",
1349 .data
= &sysctl_memory_failure_early_kill
,
1350 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1352 .proc_handler
= proc_dointvec_minmax
,
1357 .procname
= "memory_failure_recovery",
1358 .data
= &sysctl_memory_failure_recovery
,
1359 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1361 .proc_handler
= proc_dointvec_minmax
,
1369 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1370 static struct ctl_table binfmt_misc_table
[] = {
1375 static struct ctl_table fs_table
[] = {
1377 .procname
= "inode-nr",
1378 .data
= &inodes_stat
,
1379 .maxlen
= 2*sizeof(int),
1381 .proc_handler
= proc_nr_inodes
,
1384 .procname
= "inode-state",
1385 .data
= &inodes_stat
,
1386 .maxlen
= 7*sizeof(int),
1388 .proc_handler
= proc_nr_inodes
,
1391 .procname
= "file-nr",
1392 .data
= &files_stat
,
1393 .maxlen
= sizeof(files_stat
),
1395 .proc_handler
= proc_nr_files
,
1398 .procname
= "file-max",
1399 .data
= &files_stat
.max_files
,
1400 .maxlen
= sizeof(files_stat
.max_files
),
1402 .proc_handler
= proc_doulongvec_minmax
,
1405 .procname
= "nr_open",
1406 .data
= &sysctl_nr_open
,
1407 .maxlen
= sizeof(int),
1409 .proc_handler
= proc_dointvec_minmax
,
1410 .extra1
= &sysctl_nr_open_min
,
1411 .extra2
= &sysctl_nr_open_max
,
1414 .procname
= "dentry-state",
1415 .data
= &dentry_stat
,
1416 .maxlen
= 6*sizeof(int),
1418 .proc_handler
= proc_nr_dentry
,
1421 .procname
= "overflowuid",
1422 .data
= &fs_overflowuid
,
1423 .maxlen
= sizeof(int),
1425 .proc_handler
= proc_dointvec_minmax
,
1426 .extra1
= &minolduid
,
1427 .extra2
= &maxolduid
,
1430 .procname
= "overflowgid",
1431 .data
= &fs_overflowgid
,
1432 .maxlen
= sizeof(int),
1434 .proc_handler
= proc_dointvec_minmax
,
1435 .extra1
= &minolduid
,
1436 .extra2
= &maxolduid
,
1438 #ifdef CONFIG_FILE_LOCKING
1440 .procname
= "leases-enable",
1441 .data
= &leases_enable
,
1442 .maxlen
= sizeof(int),
1444 .proc_handler
= proc_dointvec
,
1447 #ifdef CONFIG_DNOTIFY
1449 .procname
= "dir-notify-enable",
1450 .data
= &dir_notify_enable
,
1451 .maxlen
= sizeof(int),
1453 .proc_handler
= proc_dointvec
,
1457 #ifdef CONFIG_FILE_LOCKING
1459 .procname
= "lease-break-time",
1460 .data
= &lease_break_time
,
1461 .maxlen
= sizeof(int),
1463 .proc_handler
= proc_dointvec
,
1468 .procname
= "aio-nr",
1470 .maxlen
= sizeof(aio_nr
),
1472 .proc_handler
= proc_doulongvec_minmax
,
1475 .procname
= "aio-max-nr",
1476 .data
= &aio_max_nr
,
1477 .maxlen
= sizeof(aio_max_nr
),
1479 .proc_handler
= proc_doulongvec_minmax
,
1481 #endif /* CONFIG_AIO */
1482 #ifdef CONFIG_INOTIFY_USER
1484 .procname
= "inotify",
1486 .child
= inotify_table
,
1491 .procname
= "epoll",
1493 .child
= epoll_table
,
1498 .procname
= "suid_dumpable",
1499 .data
= &suid_dumpable
,
1500 .maxlen
= sizeof(int),
1502 .proc_handler
= proc_dointvec_minmax
,
1506 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1508 .procname
= "binfmt_misc",
1510 .child
= binfmt_misc_table
,
1514 .procname
= "pipe-max-size",
1515 .data
= &pipe_max_size
,
1516 .maxlen
= sizeof(int),
1518 .proc_handler
= &pipe_proc_fn
,
1519 .extra1
= &pipe_min_size
,
1524 static struct ctl_table debug_table
[] = {
1525 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1526 defined(CONFIG_S390) || defined(CONFIG_TILE)
1528 .procname
= "exception-trace",
1529 .data
= &show_unhandled_signals
,
1530 .maxlen
= sizeof(int),
1532 .proc_handler
= proc_dointvec
1535 #if defined(CONFIG_OPTPROBES)
1537 .procname
= "kprobes-optimization",
1538 .data
= &sysctl_kprobes_optimization
,
1539 .maxlen
= sizeof(int),
1541 .proc_handler
= proc_kprobes_optimization_handler
,
1549 static struct ctl_table dev_table
[] = {
1553 static DEFINE_SPINLOCK(sysctl_lock
);
1555 /* called under sysctl_lock */
1556 static int use_table(struct ctl_table_header
*p
)
1558 if (unlikely(p
->unregistering
))
1564 /* called under sysctl_lock */
1565 static void unuse_table(struct ctl_table_header
*p
)
1568 if (unlikely(p
->unregistering
))
1569 complete(p
->unregistering
);
1572 /* called under sysctl_lock, will reacquire if has to wait */
1573 static void start_unregistering(struct ctl_table_header
*p
)
1576 * if p->used is 0, nobody will ever touch that entry again;
1577 * we'll eliminate all paths to it before dropping sysctl_lock
1579 if (unlikely(p
->used
)) {
1580 struct completion wait
;
1581 init_completion(&wait
);
1582 p
->unregistering
= &wait
;
1583 spin_unlock(&sysctl_lock
);
1584 wait_for_completion(&wait
);
1585 spin_lock(&sysctl_lock
);
1587 /* anything non-NULL; we'll never dereference it */
1588 p
->unregistering
= ERR_PTR(-EINVAL
);
1591 * do not remove from the list until nobody holds it; walking the
1592 * list in do_sysctl() relies on that.
1594 list_del_init(&p
->ctl_entry
);
1597 void sysctl_head_get(struct ctl_table_header
*head
)
1599 spin_lock(&sysctl_lock
);
1601 spin_unlock(&sysctl_lock
);
1604 void sysctl_head_put(struct ctl_table_header
*head
)
1606 spin_lock(&sysctl_lock
);
1608 kfree_rcu(head
, rcu
);
1609 spin_unlock(&sysctl_lock
);
1612 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1616 spin_lock(&sysctl_lock
);
1617 if (!use_table(head
))
1618 head
= ERR_PTR(-ENOENT
);
1619 spin_unlock(&sysctl_lock
);
1623 void sysctl_head_finish(struct ctl_table_header
*head
)
1627 spin_lock(&sysctl_lock
);
1629 spin_unlock(&sysctl_lock
);
1632 static struct ctl_table_set
*
1633 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1635 struct ctl_table_set
*set
= &root
->default_set
;
1637 set
= root
->lookup(root
, namespaces
);
1641 static struct list_head
*
1642 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1644 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1648 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1649 struct ctl_table_header
*prev
)
1651 struct ctl_table_root
*root
;
1652 struct list_head
*header_list
;
1653 struct ctl_table_header
*head
;
1654 struct list_head
*tmp
;
1656 spin_lock(&sysctl_lock
);
1659 tmp
= &prev
->ctl_entry
;
1663 tmp
= &root_table_header
.ctl_entry
;
1665 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1667 if (!use_table(head
))
1669 spin_unlock(&sysctl_lock
);
1674 header_list
= lookup_header_list(root
, namespaces
);
1675 if (tmp
!= header_list
)
1679 root
= list_entry(root
->root_list
.next
,
1680 struct ctl_table_root
, root_list
);
1681 if (root
== &sysctl_table_root
)
1683 header_list
= lookup_header_list(root
, namespaces
);
1684 } while (list_empty(header_list
));
1685 tmp
= header_list
->next
;
1688 spin_unlock(&sysctl_lock
);
1692 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1694 return __sysctl_head_next(current
->nsproxy
, prev
);
1697 void register_sysctl_root(struct ctl_table_root
*root
)
1699 spin_lock(&sysctl_lock
);
1700 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1701 spin_unlock(&sysctl_lock
);
1705 * sysctl_perm does NOT grant the superuser all rights automatically, because
1706 * some sysctl variables are readonly even to root.
1709 static int test_perm(int mode
, int op
)
1711 if (!current_euid())
1713 else if (in_egroup_p(0))
1715 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1720 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1724 if (root
->permissions
)
1725 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1729 return test_perm(mode
, op
);
1732 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1734 for (; table
->procname
; table
++) {
1735 table
->parent
= parent
;
1737 sysctl_set_parent(table
, table
->child
);
1741 static __init
int sysctl_init(void)
1743 sysctl_set_parent(NULL
, root_table
);
1744 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1745 sysctl_check_table(current
->nsproxy
, root_table
);
1750 core_initcall(sysctl_init
);
1752 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1753 struct ctl_table
*table
)
1755 struct ctl_table
*p
;
1756 const char *s
= branch
->procname
;
1758 /* branch should have named subdirectory as its first element */
1759 if (!s
|| !branch
->child
)
1762 /* ... and nothing else */
1763 if (branch
[1].procname
)
1766 /* table should contain subdirectory with the same name */
1767 for (p
= table
; p
->procname
; p
++) {
1770 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1776 /* see if attaching q to p would be an improvement */
1777 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1779 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1780 struct ctl_table
*next
;
1782 int not_in_parent
= !p
->attached_by
;
1784 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1785 if (by
== q
->attached_by
)
1787 if (to
== p
->attached_by
)
1793 if (is_better
&& not_in_parent
) {
1794 q
->attached_by
= by
;
1795 q
->attached_to
= to
;
1801 * __register_sysctl_paths - register a sysctl hierarchy
1802 * @root: List of sysctl headers to register on
1803 * @namespaces: Data to compute which lists of sysctl entries are visible
1804 * @path: The path to the directory the sysctl table is in.
1805 * @table: the top-level table structure
1807 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1808 * array. A completely 0 filled entry terminates the table.
1810 * The members of the &struct ctl_table structure are used as follows:
1812 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1813 * enter a sysctl file
1815 * data - a pointer to data for use by proc_handler
1817 * maxlen - the maximum size in bytes of the data
1819 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1821 * child - a pointer to the child sysctl table if this entry is a directory, or
1824 * proc_handler - the text handler routine (described below)
1826 * de - for internal use by the sysctl routines
1828 * extra1, extra2 - extra pointers usable by the proc handler routines
1830 * Leaf nodes in the sysctl tree will be represented by a single file
1831 * under /proc; non-leaf nodes will be represented by directories.
1833 * sysctl(2) can automatically manage read and write requests through
1834 * the sysctl table. The data and maxlen fields of the ctl_table
1835 * struct enable minimal validation of the values being written to be
1836 * performed, and the mode field allows minimal authentication.
1838 * There must be a proc_handler routine for any terminal nodes
1839 * mirrored under /proc/sys (non-terminals are handled by a built-in
1840 * directory handler). Several default handlers are available to
1841 * cover common cases -
1843 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1844 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1845 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1847 * It is the handler's job to read the input buffer from user memory
1848 * and process it. The handler should return 0 on success.
1850 * This routine returns %NULL on a failure to register, and a pointer
1851 * to the table header on success.
1853 struct ctl_table_header
*__register_sysctl_paths(
1854 struct ctl_table_root
*root
,
1855 struct nsproxy
*namespaces
,
1856 const struct ctl_path
*path
, struct ctl_table
*table
)
1858 struct ctl_table_header
*header
;
1859 struct ctl_table
*new, **prevp
;
1860 unsigned int n
, npath
;
1861 struct ctl_table_set
*set
;
1863 /* Count the path components */
1864 for (npath
= 0; path
[npath
].procname
; ++npath
)
1868 * For each path component, allocate a 2-element ctl_table array.
1869 * The first array element will be filled with the sysctl entry
1870 * for this, the second will be the sentinel (procname == 0).
1872 * We allocate everything in one go so that we don't have to
1873 * worry about freeing additional memory in unregister_sysctl_table.
1875 header
= kzalloc(sizeof(struct ctl_table_header
) +
1876 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1880 new = (struct ctl_table
*) (header
+ 1);
1882 /* Now connect the dots */
1883 prevp
= &header
->ctl_table
;
1884 for (n
= 0; n
< npath
; ++n
, ++path
) {
1885 /* Copy the procname */
1886 new->procname
= path
->procname
;
1890 prevp
= &new->child
;
1895 header
->ctl_table_arg
= table
;
1897 INIT_LIST_HEAD(&header
->ctl_entry
);
1899 header
->unregistering
= NULL
;
1900 header
->root
= root
;
1901 sysctl_set_parent(NULL
, header
->ctl_table
);
1903 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1904 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1909 spin_lock(&sysctl_lock
);
1910 header
->set
= lookup_header_set(root
, namespaces
);
1911 header
->attached_by
= header
->ctl_table
;
1912 header
->attached_to
= root_table
;
1913 header
->parent
= &root_table_header
;
1914 for (set
= header
->set
; set
; set
= set
->parent
) {
1915 struct ctl_table_header
*p
;
1916 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1917 if (p
->unregistering
)
1919 try_attach(p
, header
);
1922 header
->parent
->count
++;
1923 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1924 spin_unlock(&sysctl_lock
);
1930 * register_sysctl_table_path - register a sysctl table hierarchy
1931 * @path: The path to the directory the sysctl table is in.
1932 * @table: the top-level table structure
1934 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1935 * array. A completely 0 filled entry terminates the table.
1937 * See __register_sysctl_paths for more details.
1939 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1940 struct ctl_table
*table
)
1942 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1947 * register_sysctl_table - register a sysctl table hierarchy
1948 * @table: the top-level table structure
1950 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1951 * array. A completely 0 filled entry terminates the table.
1953 * See register_sysctl_paths for more details.
1955 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1957 static const struct ctl_path null_path
[] = { {} };
1959 return register_sysctl_paths(null_path
, table
);
1963 * unregister_sysctl_table - unregister a sysctl table hierarchy
1964 * @header: the header returned from register_sysctl_table
1966 * Unregisters the sysctl table and all children. proc entries may not
1967 * actually be removed until they are no longer used by anyone.
1969 void unregister_sysctl_table(struct ctl_table_header
* header
)
1976 spin_lock(&sysctl_lock
);
1977 start_unregistering(header
);
1978 if (!--header
->parent
->count
) {
1980 kfree_rcu(header
->parent
, rcu
);
1982 if (!--header
->count
)
1983 kfree_rcu(header
, rcu
);
1984 spin_unlock(&sysctl_lock
);
1987 int sysctl_is_seen(struct ctl_table_header
*p
)
1989 struct ctl_table_set
*set
= p
->set
;
1991 spin_lock(&sysctl_lock
);
1992 if (p
->unregistering
)
1994 else if (!set
->is_seen
)
1997 res
= set
->is_seen(set
);
1998 spin_unlock(&sysctl_lock
);
2002 void setup_sysctl_set(struct ctl_table_set
*p
,
2003 struct ctl_table_set
*parent
,
2004 int (*is_seen
)(struct ctl_table_set
*))
2006 INIT_LIST_HEAD(&p
->list
);
2007 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
2008 p
->is_seen
= is_seen
;
2011 #else /* !CONFIG_SYSCTL */
2012 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
2017 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
2018 struct ctl_table
*table
)
2023 void unregister_sysctl_table(struct ctl_table_header
* table
)
2027 void setup_sysctl_set(struct ctl_table_set
*p
,
2028 struct ctl_table_set
*parent
,
2029 int (*is_seen
)(struct ctl_table_set
*))
2033 void sysctl_head_put(struct ctl_table_header
*head
)
2037 #endif /* CONFIG_SYSCTL */
2043 #ifdef CONFIG_PROC_SYSCTL
2045 static int _proc_do_string(void* data
, int maxlen
, int write
,
2046 void __user
*buffer
,
2047 size_t *lenp
, loff_t
*ppos
)
2053 if (!data
|| !maxlen
|| !*lenp
) {
2061 while (len
< *lenp
) {
2062 if (get_user(c
, p
++))
2064 if (c
== 0 || c
== '\n')
2070 if(copy_from_user(data
, buffer
, len
))
2072 ((char *) data
)[len
] = 0;
2090 if(copy_to_user(buffer
, data
, len
))
2093 if(put_user('\n', ((char __user
*) buffer
) + len
))
2104 * proc_dostring - read a string sysctl
2105 * @table: the sysctl table
2106 * @write: %TRUE if this is a write to the sysctl file
2107 * @buffer: the user buffer
2108 * @lenp: the size of the user buffer
2109 * @ppos: file position
2111 * Reads/writes a string from/to the user buffer. If the kernel
2112 * buffer provided is not large enough to hold the string, the
2113 * string is truncated. The copied string is %NULL-terminated.
2114 * If the string is being read by the user process, it is copied
2115 * and a newline '\n' is added. It is truncated if the buffer is
2118 * Returns 0 on success.
2120 int proc_dostring(struct ctl_table
*table
, int write
,
2121 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2123 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2124 buffer
, lenp
, ppos
);
2127 static size_t proc_skip_spaces(char **buf
)
2130 char *tmp
= skip_spaces(*buf
);
2136 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2146 #define TMPBUFLEN 22
2148 * proc_get_long - reads an ASCII formatted integer from a user buffer
2150 * @buf: a kernel buffer
2151 * @size: size of the kernel buffer
2152 * @val: this is where the number will be stored
2153 * @neg: set to %TRUE if number is negative
2154 * @perm_tr: a vector which contains the allowed trailers
2155 * @perm_tr_len: size of the perm_tr vector
2156 * @tr: pointer to store the trailer character
2158 * In case of success %0 is returned and @buf and @size are updated with
2159 * the amount of bytes read. If @tr is non-NULL and a trailing
2160 * character exists (size is non-zero after returning from this
2161 * function), @tr is updated with the trailing character.
2163 static int proc_get_long(char **buf
, size_t *size
,
2164 unsigned long *val
, bool *neg
,
2165 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2168 char *p
, tmp
[TMPBUFLEN
];
2174 if (len
> TMPBUFLEN
- 1)
2175 len
= TMPBUFLEN
- 1;
2177 memcpy(tmp
, *buf
, len
);
2181 if (*p
== '-' && *size
> 1) {
2189 *val
= simple_strtoul(p
, &p
, 0);
2193 /* We don't know if the next char is whitespace thus we may accept
2194 * invalid integers (e.g. 1234...a) or two integers instead of one
2195 * (e.g. 123...1). So lets not allow such large numbers. */
2196 if (len
== TMPBUFLEN
- 1)
2199 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2202 if (tr
&& (len
< *size
))
2212 * proc_put_long - converts an integer to a decimal ASCII formatted string
2214 * @buf: the user buffer
2215 * @size: the size of the user buffer
2216 * @val: the integer to be converted
2217 * @neg: sign of the number, %TRUE for negative
2219 * In case of success %0 is returned and @buf and @size are updated with
2220 * the amount of bytes written.
2222 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2226 char tmp
[TMPBUFLEN
], *p
= tmp
;
2228 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2232 if (copy_to_user(*buf
, tmp
, len
))
2240 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2243 char __user
**buffer
= (char __user
**)buf
;
2244 if (put_user(c
, *buffer
))
2246 (*size
)--, (*buffer
)++;
2252 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2254 int write
, void *data
)
2257 *valp
= *negp
? -*lvalp
: *lvalp
;
2262 *lvalp
= (unsigned long)-val
;
2265 *lvalp
= (unsigned long)val
;
2271 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2273 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2274 int write
, void __user
*buffer
,
2275 size_t *lenp
, loff_t
*ppos
,
2276 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2277 int write
, void *data
),
2280 int *i
, vleft
, first
= 1, err
= 0;
2281 unsigned long page
= 0;
2285 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2290 i
= (int *) tbl_data
;
2291 vleft
= table
->maxlen
/ sizeof(*i
);
2295 conv
= do_proc_dointvec_conv
;
2298 if (left
> PAGE_SIZE
- 1)
2299 left
= PAGE_SIZE
- 1;
2300 page
= __get_free_page(GFP_TEMPORARY
);
2301 kbuf
= (char *) page
;
2304 if (copy_from_user(kbuf
, buffer
, left
)) {
2311 for (; left
&& vleft
--; i
++, first
=0) {
2316 left
-= proc_skip_spaces(&kbuf
);
2320 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2322 sizeof(proc_wspace_sep
), NULL
);
2325 if (conv(&neg
, &lval
, i
, 1, data
)) {
2330 if (conv(&neg
, &lval
, i
, 0, data
)) {
2335 err
= proc_put_char(&buffer
, &left
, '\t');
2338 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2344 if (!write
&& !first
&& left
&& !err
)
2345 err
= proc_put_char(&buffer
, &left
, '\n');
2346 if (write
&& !err
&& left
)
2347 left
-= proc_skip_spaces(&kbuf
);
2352 return err
? : -EINVAL
;
2359 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2360 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2361 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2362 int write
, void *data
),
2365 return __do_proc_dointvec(table
->data
, table
, write
,
2366 buffer
, lenp
, ppos
, conv
, data
);
2370 * proc_dointvec - read a vector of integers
2371 * @table: the sysctl table
2372 * @write: %TRUE if this is a write to the sysctl file
2373 * @buffer: the user buffer
2374 * @lenp: the size of the user buffer
2375 * @ppos: file position
2377 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2378 * values from/to the user buffer, treated as an ASCII string.
2380 * Returns 0 on success.
2382 int proc_dointvec(struct ctl_table
*table
, int write
,
2383 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2385 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2390 * Taint values can only be increased
2391 * This means we can safely use a temporary.
2393 static int proc_taint(struct ctl_table
*table
, int write
,
2394 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2397 unsigned long tmptaint
= get_taint();
2400 if (write
&& !capable(CAP_SYS_ADMIN
))
2405 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2411 * Poor man's atomic or. Not worth adding a primitive
2412 * to everyone's atomic.h for this
2415 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2416 if ((tmptaint
>> i
) & 1)
2424 #ifdef CONFIG_PRINTK
2425 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2426 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2428 if (write
&& !capable(CAP_SYS_ADMIN
))
2431 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2435 struct do_proc_dointvec_minmax_conv_param
{
2440 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2442 int write
, void *data
)
2444 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2446 int val
= *negp
? -*lvalp
: *lvalp
;
2447 if ((param
->min
&& *param
->min
> val
) ||
2448 (param
->max
&& *param
->max
< val
))
2455 *lvalp
= (unsigned long)-val
;
2458 *lvalp
= (unsigned long)val
;
2465 * proc_dointvec_minmax - read a vector of integers with min/max values
2466 * @table: the sysctl table
2467 * @write: %TRUE if this is a write to the sysctl file
2468 * @buffer: the user buffer
2469 * @lenp: the size of the user buffer
2470 * @ppos: file position
2472 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2473 * values from/to the user buffer, treated as an ASCII string.
2475 * This routine will ensure the values are within the range specified by
2476 * table->extra1 (min) and table->extra2 (max).
2478 * Returns 0 on success.
2480 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2481 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2483 struct do_proc_dointvec_minmax_conv_param param
= {
2484 .min
= (int *) table
->extra1
,
2485 .max
= (int *) table
->extra2
,
2487 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2488 do_proc_dointvec_minmax_conv
, ¶m
);
2491 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2492 void __user
*buffer
,
2493 size_t *lenp
, loff_t
*ppos
,
2494 unsigned long convmul
,
2495 unsigned long convdiv
)
2497 unsigned long *i
, *min
, *max
;
2498 int vleft
, first
= 1, err
= 0;
2499 unsigned long page
= 0;
2503 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2508 i
= (unsigned long *) data
;
2509 min
= (unsigned long *) table
->extra1
;
2510 max
= (unsigned long *) table
->extra2
;
2511 vleft
= table
->maxlen
/ sizeof(unsigned long);
2515 if (left
> PAGE_SIZE
- 1)
2516 left
= PAGE_SIZE
- 1;
2517 page
= __get_free_page(GFP_TEMPORARY
);
2518 kbuf
= (char *) page
;
2521 if (copy_from_user(kbuf
, buffer
, left
)) {
2528 for (; left
&& vleft
--; i
++, first
= 0) {
2534 left
-= proc_skip_spaces(&kbuf
);
2536 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2538 sizeof(proc_wspace_sep
), NULL
);
2543 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2547 val
= convdiv
* (*i
) / convmul
;
2549 err
= proc_put_char(&buffer
, &left
, '\t');
2550 err
= proc_put_long(&buffer
, &left
, val
, false);
2556 if (!write
&& !first
&& left
&& !err
)
2557 err
= proc_put_char(&buffer
, &left
, '\n');
2559 left
-= proc_skip_spaces(&kbuf
);
2564 return err
? : -EINVAL
;
2571 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2572 void __user
*buffer
,
2573 size_t *lenp
, loff_t
*ppos
,
2574 unsigned long convmul
,
2575 unsigned long convdiv
)
2577 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2578 buffer
, lenp
, ppos
, convmul
, convdiv
);
2582 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2583 * @table: the sysctl table
2584 * @write: %TRUE if this is a write to the sysctl file
2585 * @buffer: the user buffer
2586 * @lenp: the size of the user buffer
2587 * @ppos: file position
2589 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2590 * values from/to the user buffer, treated as an ASCII string.
2592 * This routine will ensure the values are within the range specified by
2593 * table->extra1 (min) and table->extra2 (max).
2595 * Returns 0 on success.
2597 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2598 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2600 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2604 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2605 * @table: the sysctl table
2606 * @write: %TRUE if this is a write to the sysctl file
2607 * @buffer: the user buffer
2608 * @lenp: the size of the user buffer
2609 * @ppos: file position
2611 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2612 * values from/to the user buffer, treated as an ASCII string. The values
2613 * are treated as milliseconds, and converted to jiffies when they are stored.
2615 * This routine will ensure the values are within the range specified by
2616 * table->extra1 (min) and table->extra2 (max).
2618 * Returns 0 on success.
2620 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2621 void __user
*buffer
,
2622 size_t *lenp
, loff_t
*ppos
)
2624 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2625 lenp
, ppos
, HZ
, 1000l);
2629 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2631 int write
, void *data
)
2634 if (*lvalp
> LONG_MAX
/ HZ
)
2636 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2642 lval
= (unsigned long)-val
;
2645 lval
= (unsigned long)val
;
2652 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2654 int write
, void *data
)
2657 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2659 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2665 lval
= (unsigned long)-val
;
2668 lval
= (unsigned long)val
;
2670 *lvalp
= jiffies_to_clock_t(lval
);
2675 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2677 int write
, void *data
)
2680 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2686 lval
= (unsigned long)-val
;
2689 lval
= (unsigned long)val
;
2691 *lvalp
= jiffies_to_msecs(lval
);
2697 * proc_dointvec_jiffies - read a vector of integers as seconds
2698 * @table: the sysctl table
2699 * @write: %TRUE if this is a write to the sysctl file
2700 * @buffer: the user buffer
2701 * @lenp: the size of the user buffer
2702 * @ppos: file position
2704 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2705 * values from/to the user buffer, treated as an ASCII string.
2706 * The values read are assumed to be in seconds, and are converted into
2709 * Returns 0 on success.
2711 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2712 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2714 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2715 do_proc_dointvec_jiffies_conv
,NULL
);
2719 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2720 * @table: the sysctl table
2721 * @write: %TRUE if this is a write to the sysctl file
2722 * @buffer: the user buffer
2723 * @lenp: the size of the user buffer
2724 * @ppos: pointer to the file position
2726 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2727 * values from/to the user buffer, treated as an ASCII string.
2728 * The values read are assumed to be in 1/USER_HZ seconds, and
2729 * are converted into jiffies.
2731 * Returns 0 on success.
2733 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2734 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2736 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2737 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2741 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2742 * @table: the sysctl table
2743 * @write: %TRUE if this is a write to the sysctl file
2744 * @buffer: the user buffer
2745 * @lenp: the size of the user buffer
2746 * @ppos: file position
2747 * @ppos: the current position in the file
2749 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2750 * values from/to the user buffer, treated as an ASCII string.
2751 * The values read are assumed to be in 1/1000 seconds, and
2752 * are converted into jiffies.
2754 * Returns 0 on success.
2756 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2757 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2759 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2760 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2763 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2764 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2766 struct pid
*new_pid
;
2770 tmp
= pid_vnr(cad_pid
);
2772 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2773 lenp
, ppos
, NULL
, NULL
);
2777 new_pid
= find_get_pid(tmp
);
2781 put_pid(xchg(&cad_pid
, new_pid
));
2786 * proc_do_large_bitmap - read/write from/to a large bitmap
2787 * @table: the sysctl table
2788 * @write: %TRUE if this is a write to the sysctl file
2789 * @buffer: the user buffer
2790 * @lenp: the size of the user buffer
2791 * @ppos: file position
2793 * The bitmap is stored at table->data and the bitmap length (in bits)
2796 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2797 * large bitmaps may be represented in a compact manner. Writing into
2798 * the file will clear the bitmap then update it with the given input.
2800 * Returns 0 on success.
2802 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2803 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2807 size_t left
= *lenp
;
2808 unsigned long bitmap_len
= table
->maxlen
;
2809 unsigned long *bitmap
= (unsigned long *) table
->data
;
2810 unsigned long *tmp_bitmap
= NULL
;
2811 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2813 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2819 unsigned long page
= 0;
2822 if (left
> PAGE_SIZE
- 1)
2823 left
= PAGE_SIZE
- 1;
2825 page
= __get_free_page(GFP_TEMPORARY
);
2826 kbuf
= (char *) page
;
2829 if (copy_from_user(kbuf
, buffer
, left
)) {
2835 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2841 proc_skip_char(&kbuf
, &left
, '\n');
2842 while (!err
&& left
) {
2843 unsigned long val_a
, val_b
;
2846 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2850 if (val_a
>= bitmap_len
|| neg
) {
2862 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2863 &neg
, tr_b
, sizeof(tr_b
),
2867 if (val_b
>= bitmap_len
|| neg
||
2878 while (val_a
<= val_b
)
2879 set_bit(val_a
++, tmp_bitmap
);
2882 proc_skip_char(&kbuf
, &left
, '\n');
2886 unsigned long bit_a
, bit_b
= 0;
2889 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2890 if (bit_a
>= bitmap_len
)
2892 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2896 err
= proc_put_char(&buffer
, &left
, ',');
2900 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2903 if (bit_a
!= bit_b
) {
2904 err
= proc_put_char(&buffer
, &left
, '-');
2907 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2915 err
= proc_put_char(&buffer
, &left
, '\n');
2921 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2923 memcpy(bitmap
, tmp_bitmap
,
2924 BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long));
2936 #else /* CONFIG_PROC_SYSCTL */
2938 int proc_dostring(struct ctl_table
*table
, int write
,
2939 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2944 int proc_dointvec(struct ctl_table
*table
, int write
,
2945 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2950 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2951 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2956 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2957 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2962 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2963 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2968 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2969 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2974 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2975 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2980 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2981 void __user
*buffer
,
2982 size_t *lenp
, loff_t
*ppos
)
2988 #endif /* CONFIG_PROC_SYSCTL */
2991 * No sense putting this after each symbol definition, twice,
2992 * exception granted :-)
2994 EXPORT_SYMBOL(proc_dointvec
);
2995 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2996 EXPORT_SYMBOL(proc_dointvec_minmax
);
2997 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2998 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2999 EXPORT_SYMBOL(proc_dostring
);
3000 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3001 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3002 EXPORT_SYMBOL(register_sysctl_table
);
3003 EXPORT_SYMBOL(register_sysctl_paths
);
3004 EXPORT_SYMBOL(unregister_sysctl_table
);