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>
22 #include <linux/aio.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/bitmap.h>
28 #include <linux/signal.h>
29 #include <linux/printk.h>
30 #include <linux/proc_fs.h>
31 #include <linux/security.h>
32 #include <linux/ctype.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
65 #include <linux/sched/coredump.h>
66 #include <linux/kexec.h>
67 #include <linux/bpf.h>
68 #include <linux/mount.h>
69 #include <linux/pipe_fs_i.h>
71 #include <linux/uaccess.h>
72 #include <asm/processor.h>
76 #include <asm/stacktrace.h>
80 #include <asm/setup.h>
82 #ifdef CONFIG_BSD_PROCESS_ACCT
83 #include <linux/acct.h>
85 #ifdef CONFIG_RT_MUTEXES
86 #include <linux/rtmutex.h>
88 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
89 #include <linux/lockdep.h>
91 #ifdef CONFIG_CHR_DEV_SG
95 #ifdef CONFIG_LOCKUP_DETECTOR
96 #include <linux/nmi.h>
99 #if defined(CONFIG_SYSCTL)
101 /* External variables not in a header file. */
102 extern int suid_dumpable
;
103 #ifdef CONFIG_COREDUMP
104 extern int core_uses_pid
;
105 extern char core_pattern
[];
106 extern unsigned int core_pipe_limit
;
108 #ifdef CONFIG_USER_NS
109 extern int unprivileged_userns_clone
;
112 extern int pid_max_min
, pid_max_max
;
113 extern int percpu_pagelist_fraction
;
114 extern int latencytop_enabled
;
115 extern unsigned int sysctl_nr_open_min
, sysctl_nr_open_max
;
117 extern int sysctl_nr_trim_pages
;
120 /* Constants used for minimum and maximum */
121 #ifdef CONFIG_LOCKUP_DETECTOR
122 static int sixty
= 60;
125 static int __maybe_unused neg_one
= -1;
128 static int __maybe_unused one
= 1;
129 static int __maybe_unused two
= 2;
130 static int __maybe_unused four
= 4;
131 static unsigned long zero_ul
;
132 static unsigned long one_ul
= 1;
133 static unsigned long long_max
= LONG_MAX
;
134 static int one_hundred
= 100;
135 static int one_thousand
= 1000;
137 static int ten_thousand
= 10000;
139 #ifdef CONFIG_PERF_EVENTS
140 static int six_hundred_forty_kb
= 640 * 1024;
143 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
144 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
146 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
147 static int maxolduid
= 65535;
148 static int minolduid
;
150 static int ngroups_max
= NGROUPS_MAX
;
151 static const int cap_last_cap
= CAP_LAST_CAP
;
153 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
154 #ifdef CONFIG_DETECT_HUNG_TASK
155 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
158 #ifdef CONFIG_INOTIFY_USER
159 #include <linux/inotify.h>
165 extern int pwrsw_enabled
;
168 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
169 extern int unaligned_enabled
;
173 extern int unaligned_dump_stack
;
176 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
177 extern int no_unaligned_warning
;
180 #ifdef CONFIG_PROC_SYSCTL
183 * enum sysctl_writes_mode - supported sysctl write modes
185 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
186 * to be written, and multiple writes on the same sysctl file descriptor
187 * will rewrite the sysctl value, regardless of file position. No warning
188 * is issued when the initial position is not 0.
189 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
191 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
192 * file position 0 and the value must be fully contained in the buffer
193 * sent to the write syscall. If dealing with strings respect the file
194 * position, but restrict this to the max length of the buffer, anything
195 * passed the max lenght will be ignored. Multiple writes will append
198 * These write modes control how current file position affects the behavior of
199 * updating sysctl values through the proc interface on each write.
201 enum sysctl_writes_mode
{
202 SYSCTL_WRITES_LEGACY
= -1,
203 SYSCTL_WRITES_WARN
= 0,
204 SYSCTL_WRITES_STRICT
= 1,
207 static enum sysctl_writes_mode sysctl_writes_strict
= SYSCTL_WRITES_STRICT
;
209 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
210 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
211 static int proc_taint(struct ctl_table
*table
, int write
,
212 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
216 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
217 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
220 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
221 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
222 #ifdef CONFIG_COREDUMP
223 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
224 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
227 #ifdef CONFIG_MAGIC_SYSRQ
228 /* Note: sysrq code uses it's own private copy */
229 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
231 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
232 void __user
*buffer
, size_t *lenp
,
237 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
242 sysrq_toggle_support(__sysrq_enabled
);
249 static struct ctl_table kern_table
[];
250 static struct ctl_table vm_table
[];
251 static struct ctl_table fs_table
[];
252 static struct ctl_table debug_table
[];
253 static struct ctl_table dev_table
[];
254 extern struct ctl_table random_table
[];
256 extern struct ctl_table epoll_table
[];
259 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
260 int sysctl_legacy_va_layout
;
263 /* The default sysctl tables: */
265 static struct ctl_table sysctl_base_table
[] = {
267 .procname
= "kernel",
284 .child
= debug_table
,
294 #ifdef CONFIG_SCHED_DEBUG
295 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
296 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
297 static int min_wakeup_granularity_ns
; /* 0 usecs */
298 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
300 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
301 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
302 #endif /* CONFIG_SMP */
303 #endif /* CONFIG_SCHED_DEBUG */
305 #ifdef CONFIG_COMPACTION
306 static int min_extfrag_threshold
;
307 static int max_extfrag_threshold
= 1000;
310 static struct ctl_table kern_table
[] = {
312 .procname
= "sched_child_runs_first",
313 .data
= &sysctl_sched_child_runs_first
,
314 .maxlen
= sizeof(unsigned int),
316 .proc_handler
= proc_dointvec
,
318 #ifdef CONFIG_SCHED_DEBUG
320 .procname
= "sched_min_granularity_ns",
321 .data
= &sysctl_sched_min_granularity
,
322 .maxlen
= sizeof(unsigned int),
324 .proc_handler
= sched_proc_update_handler
,
325 .extra1
= &min_sched_granularity_ns
,
326 .extra2
= &max_sched_granularity_ns
,
329 .procname
= "sched_latency_ns",
330 .data
= &sysctl_sched_latency
,
331 .maxlen
= sizeof(unsigned int),
333 .proc_handler
= sched_proc_update_handler
,
334 .extra1
= &min_sched_granularity_ns
,
335 .extra2
= &max_sched_granularity_ns
,
338 .procname
= "sched_wakeup_granularity_ns",
339 .data
= &sysctl_sched_wakeup_granularity
,
340 .maxlen
= sizeof(unsigned int),
342 .proc_handler
= sched_proc_update_handler
,
343 .extra1
= &min_wakeup_granularity_ns
,
344 .extra2
= &max_wakeup_granularity_ns
,
348 .procname
= "sched_tunable_scaling",
349 .data
= &sysctl_sched_tunable_scaling
,
350 .maxlen
= sizeof(enum sched_tunable_scaling
),
352 .proc_handler
= sched_proc_update_handler
,
353 .extra1
= &min_sched_tunable_scaling
,
354 .extra2
= &max_sched_tunable_scaling
,
357 .procname
= "sched_migration_cost_ns",
358 .data
= &sysctl_sched_migration_cost
,
359 .maxlen
= sizeof(unsigned int),
361 .proc_handler
= proc_dointvec
,
364 .procname
= "sched_nr_migrate",
365 .data
= &sysctl_sched_nr_migrate
,
366 .maxlen
= sizeof(unsigned int),
368 .proc_handler
= proc_dointvec
,
371 .procname
= "sched_time_avg_ms",
372 .data
= &sysctl_sched_time_avg
,
373 .maxlen
= sizeof(unsigned int),
375 .proc_handler
= proc_dointvec_minmax
,
378 #ifdef CONFIG_SCHEDSTATS
380 .procname
= "sched_schedstats",
382 .maxlen
= sizeof(unsigned int),
384 .proc_handler
= sysctl_schedstats
,
388 #endif /* CONFIG_SCHEDSTATS */
389 #endif /* CONFIG_SMP */
390 #ifdef CONFIG_NUMA_BALANCING
392 .procname
= "numa_balancing_scan_delay_ms",
393 .data
= &sysctl_numa_balancing_scan_delay
,
394 .maxlen
= sizeof(unsigned int),
396 .proc_handler
= proc_dointvec
,
399 .procname
= "numa_balancing_scan_period_min_ms",
400 .data
= &sysctl_numa_balancing_scan_period_min
,
401 .maxlen
= sizeof(unsigned int),
403 .proc_handler
= proc_dointvec
,
406 .procname
= "numa_balancing_scan_period_max_ms",
407 .data
= &sysctl_numa_balancing_scan_period_max
,
408 .maxlen
= sizeof(unsigned int),
410 .proc_handler
= proc_dointvec
,
413 .procname
= "numa_balancing_scan_size_mb",
414 .data
= &sysctl_numa_balancing_scan_size
,
415 .maxlen
= sizeof(unsigned int),
417 .proc_handler
= proc_dointvec_minmax
,
421 .procname
= "numa_balancing",
422 .data
= NULL
, /* filled in by handler */
423 .maxlen
= sizeof(unsigned int),
425 .proc_handler
= sysctl_numa_balancing
,
429 #endif /* CONFIG_NUMA_BALANCING */
430 #endif /* CONFIG_SCHED_DEBUG */
432 .procname
= "sched_rt_period_us",
433 .data
= &sysctl_sched_rt_period
,
434 .maxlen
= sizeof(unsigned int),
436 .proc_handler
= sched_rt_handler
,
439 .procname
= "sched_rt_runtime_us",
440 .data
= &sysctl_sched_rt_runtime
,
441 .maxlen
= sizeof(int),
443 .proc_handler
= sched_rt_handler
,
446 .procname
= "sched_rr_timeslice_ms",
447 .data
= &sysctl_sched_rr_timeslice
,
448 .maxlen
= sizeof(int),
450 .proc_handler
= sched_rr_handler
,
452 #ifdef CONFIG_SCHED_AUTOGROUP
454 .procname
= "sched_autogroup_enabled",
455 .data
= &sysctl_sched_autogroup_enabled
,
456 .maxlen
= sizeof(unsigned int),
458 .proc_handler
= proc_dointvec_minmax
,
463 #ifdef CONFIG_CFS_BANDWIDTH
465 .procname
= "sched_cfs_bandwidth_slice_us",
466 .data
= &sysctl_sched_cfs_bandwidth_slice
,
467 .maxlen
= sizeof(unsigned int),
469 .proc_handler
= proc_dointvec_minmax
,
473 #ifdef CONFIG_PROVE_LOCKING
475 .procname
= "prove_locking",
476 .data
= &prove_locking
,
477 .maxlen
= sizeof(int),
479 .proc_handler
= proc_dointvec
,
482 #ifdef CONFIG_LOCK_STAT
484 .procname
= "lock_stat",
486 .maxlen
= sizeof(int),
488 .proc_handler
= proc_dointvec
,
493 .data
= &panic_timeout
,
494 .maxlen
= sizeof(int),
496 .proc_handler
= proc_dointvec
,
498 #ifdef CONFIG_COREDUMP
500 .procname
= "core_uses_pid",
501 .data
= &core_uses_pid
,
502 .maxlen
= sizeof(int),
504 .proc_handler
= proc_dointvec
,
507 .procname
= "core_pattern",
508 .data
= core_pattern
,
509 .maxlen
= CORENAME_MAX_SIZE
,
511 .proc_handler
= proc_dostring_coredump
,
514 .procname
= "core_pipe_limit",
515 .data
= &core_pipe_limit
,
516 .maxlen
= sizeof(unsigned int),
518 .proc_handler
= proc_dointvec
,
521 #ifdef CONFIG_USER_NS
523 .procname
= "unprivileged_userns_clone",
524 .data
= &unprivileged_userns_clone
,
525 .maxlen
= sizeof(int),
527 .proc_handler
= proc_dointvec
,
530 #ifdef CONFIG_PROC_SYSCTL
532 .procname
= "tainted",
533 .maxlen
= sizeof(long),
535 .proc_handler
= proc_taint
,
538 .procname
= "sysctl_writes_strict",
539 .data
= &sysctl_writes_strict
,
540 .maxlen
= sizeof(int),
542 .proc_handler
= proc_dointvec_minmax
,
547 #ifdef CONFIG_LATENCYTOP
549 .procname
= "latencytop",
550 .data
= &latencytop_enabled
,
551 .maxlen
= sizeof(int),
553 .proc_handler
= sysctl_latencytop
,
556 #ifdef CONFIG_BLK_DEV_INITRD
558 .procname
= "real-root-dev",
559 .data
= &real_root_dev
,
560 .maxlen
= sizeof(int),
562 .proc_handler
= proc_dointvec
,
566 .procname
= "print-fatal-signals",
567 .data
= &print_fatal_signals
,
568 .maxlen
= sizeof(int),
570 .proc_handler
= proc_dointvec
,
574 .procname
= "reboot-cmd",
575 .data
= reboot_command
,
578 .proc_handler
= proc_dostring
,
581 .procname
= "stop-a",
582 .data
= &stop_a_enabled
,
583 .maxlen
= sizeof (int),
585 .proc_handler
= proc_dointvec
,
588 .procname
= "scons-poweroff",
589 .data
= &scons_pwroff
,
590 .maxlen
= sizeof (int),
592 .proc_handler
= proc_dointvec
,
595 #ifdef CONFIG_SPARC64
597 .procname
= "tsb-ratio",
598 .data
= &sysctl_tsb_ratio
,
599 .maxlen
= sizeof (int),
601 .proc_handler
= proc_dointvec
,
606 .procname
= "soft-power",
607 .data
= &pwrsw_enabled
,
608 .maxlen
= sizeof (int),
610 .proc_handler
= proc_dointvec
,
613 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
615 .procname
= "unaligned-trap",
616 .data
= &unaligned_enabled
,
617 .maxlen
= sizeof (int),
619 .proc_handler
= proc_dointvec
,
623 .procname
= "ctrl-alt-del",
625 .maxlen
= sizeof(int),
627 .proc_handler
= proc_dointvec
,
629 #ifdef CONFIG_FUNCTION_TRACER
631 .procname
= "ftrace_enabled",
632 .data
= &ftrace_enabled
,
633 .maxlen
= sizeof(int),
635 .proc_handler
= ftrace_enable_sysctl
,
638 #ifdef CONFIG_STACK_TRACER
640 .procname
= "stack_tracer_enabled",
641 .data
= &stack_tracer_enabled
,
642 .maxlen
= sizeof(int),
644 .proc_handler
= stack_trace_sysctl
,
647 #ifdef CONFIG_TRACING
649 .procname
= "ftrace_dump_on_oops",
650 .data
= &ftrace_dump_on_oops
,
651 .maxlen
= sizeof(int),
653 .proc_handler
= proc_dointvec
,
656 .procname
= "traceoff_on_warning",
657 .data
= &__disable_trace_on_warning
,
658 .maxlen
= sizeof(__disable_trace_on_warning
),
660 .proc_handler
= proc_dointvec
,
663 .procname
= "tracepoint_printk",
664 .data
= &tracepoint_printk
,
665 .maxlen
= sizeof(tracepoint_printk
),
667 .proc_handler
= tracepoint_printk_sysctl
,
670 #ifdef CONFIG_KEXEC_CORE
672 .procname
= "kexec_load_disabled",
673 .data
= &kexec_load_disabled
,
674 .maxlen
= sizeof(int),
676 /* only handle a transition from default "0" to "1" */
677 .proc_handler
= proc_dointvec_minmax
,
682 #ifdef CONFIG_MODULES
684 .procname
= "modprobe",
685 .data
= &modprobe_path
,
686 .maxlen
= KMOD_PATH_LEN
,
688 .proc_handler
= proc_dostring
,
691 .procname
= "modules_disabled",
692 .data
= &modules_disabled
,
693 .maxlen
= sizeof(int),
695 /* only handle a transition from default "0" to "1" */
696 .proc_handler
= proc_dointvec_minmax
,
701 #ifdef CONFIG_UEVENT_HELPER
703 .procname
= "hotplug",
704 .data
= &uevent_helper
,
705 .maxlen
= UEVENT_HELPER_PATH_LEN
,
707 .proc_handler
= proc_dostring
,
710 #ifdef CONFIG_CHR_DEV_SG
712 .procname
= "sg-big-buff",
713 .data
= &sg_big_buff
,
714 .maxlen
= sizeof (int),
716 .proc_handler
= proc_dointvec
,
719 #ifdef CONFIG_BSD_PROCESS_ACCT
723 .maxlen
= 3*sizeof(int),
725 .proc_handler
= proc_dointvec
,
728 #ifdef CONFIG_MAGIC_SYSRQ
731 .data
= &__sysrq_enabled
,
732 .maxlen
= sizeof (int),
734 .proc_handler
= sysrq_sysctl_handler
,
737 #ifdef CONFIG_PROC_SYSCTL
739 .procname
= "cad_pid",
741 .maxlen
= sizeof (int),
743 .proc_handler
= proc_do_cad_pid
,
747 .procname
= "threads-max",
749 .maxlen
= sizeof(int),
751 .proc_handler
= sysctl_max_threads
,
754 .procname
= "random",
756 .child
= random_table
,
759 .procname
= "usermodehelper",
761 .child
= usermodehelper_table
,
764 .procname
= "overflowuid",
765 .data
= &overflowuid
,
766 .maxlen
= sizeof(int),
768 .proc_handler
= proc_dointvec_minmax
,
769 .extra1
= &minolduid
,
770 .extra2
= &maxolduid
,
773 .procname
= "overflowgid",
774 .data
= &overflowgid
,
775 .maxlen
= sizeof(int),
777 .proc_handler
= proc_dointvec_minmax
,
778 .extra1
= &minolduid
,
779 .extra2
= &maxolduid
,
782 #ifdef CONFIG_MATHEMU
784 .procname
= "ieee_emulation_warnings",
785 .data
= &sysctl_ieee_emulation_warnings
,
786 .maxlen
= sizeof(int),
788 .proc_handler
= proc_dointvec
,
792 .procname
= "userprocess_debug",
793 .data
= &show_unhandled_signals
,
794 .maxlen
= sizeof(int),
796 .proc_handler
= proc_dointvec
,
800 .procname
= "pid_max",
802 .maxlen
= sizeof (int),
804 .proc_handler
= proc_dointvec_minmax
,
805 .extra1
= &pid_max_min
,
806 .extra2
= &pid_max_max
,
809 .procname
= "panic_on_oops",
810 .data
= &panic_on_oops
,
811 .maxlen
= sizeof(int),
813 .proc_handler
= proc_dointvec
,
815 #if defined CONFIG_PRINTK
817 .procname
= "printk",
818 .data
= &console_loglevel
,
819 .maxlen
= 4*sizeof(int),
821 .proc_handler
= proc_dointvec
,
824 .procname
= "printk_ratelimit",
825 .data
= &printk_ratelimit_state
.interval
,
826 .maxlen
= sizeof(int),
828 .proc_handler
= proc_dointvec_jiffies
,
831 .procname
= "printk_ratelimit_burst",
832 .data
= &printk_ratelimit_state
.burst
,
833 .maxlen
= sizeof(int),
835 .proc_handler
= proc_dointvec
,
838 .procname
= "printk_delay",
839 .data
= &printk_delay_msec
,
840 .maxlen
= sizeof(int),
842 .proc_handler
= proc_dointvec_minmax
,
844 .extra2
= &ten_thousand
,
847 .procname
= "printk_devkmsg",
848 .data
= devkmsg_log_str
,
849 .maxlen
= DEVKMSG_STR_MAX_SIZE
,
851 .proc_handler
= devkmsg_sysctl_set_loglvl
,
854 .procname
= "dmesg_restrict",
855 .data
= &dmesg_restrict
,
856 .maxlen
= sizeof(int),
858 .proc_handler
= proc_dointvec_minmax_sysadmin
,
863 .procname
= "kptr_restrict",
864 .data
= &kptr_restrict
,
865 .maxlen
= sizeof(int),
867 .proc_handler
= proc_dointvec_minmax_sysadmin
,
873 .procname
= "ngroups_max",
874 .data
= &ngroups_max
,
875 .maxlen
= sizeof (int),
877 .proc_handler
= proc_dointvec
,
880 .procname
= "cap_last_cap",
881 .data
= (void *)&cap_last_cap
,
882 .maxlen
= sizeof(int),
884 .proc_handler
= proc_dointvec
,
886 #if defined(CONFIG_LOCKUP_DETECTOR)
888 .procname
= "watchdog",
889 .data
= &watchdog_user_enabled
,
890 .maxlen
= sizeof(int),
892 .proc_handler
= proc_watchdog
,
897 .procname
= "watchdog_thresh",
898 .data
= &watchdog_thresh
,
899 .maxlen
= sizeof(int),
901 .proc_handler
= proc_watchdog_thresh
,
906 .procname
= "nmi_watchdog",
907 .data
= &nmi_watchdog_user_enabled
,
908 .maxlen
= sizeof(int),
909 .mode
= NMI_WATCHDOG_SYSCTL_PERM
,
910 .proc_handler
= proc_nmi_watchdog
,
915 .procname
= "watchdog_cpumask",
916 .data
= &watchdog_cpumask_bits
,
919 .proc_handler
= proc_watchdog_cpumask
,
921 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
923 .procname
= "soft_watchdog",
924 .data
= &soft_watchdog_user_enabled
,
925 .maxlen
= sizeof(int),
927 .proc_handler
= proc_soft_watchdog
,
932 .procname
= "softlockup_panic",
933 .data
= &softlockup_panic
,
934 .maxlen
= sizeof(int),
936 .proc_handler
= proc_dointvec_minmax
,
942 .procname
= "softlockup_all_cpu_backtrace",
943 .data
= &sysctl_softlockup_all_cpu_backtrace
,
944 .maxlen
= sizeof(int),
946 .proc_handler
= proc_dointvec_minmax
,
950 #endif /* CONFIG_SMP */
952 #ifdef CONFIG_HARDLOCKUP_DETECTOR
954 .procname
= "hardlockup_panic",
955 .data
= &hardlockup_panic
,
956 .maxlen
= sizeof(int),
958 .proc_handler
= proc_dointvec_minmax
,
964 .procname
= "hardlockup_all_cpu_backtrace",
965 .data
= &sysctl_hardlockup_all_cpu_backtrace
,
966 .maxlen
= sizeof(int),
968 .proc_handler
= proc_dointvec_minmax
,
972 #endif /* CONFIG_SMP */
976 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
978 .procname
= "unknown_nmi_panic",
979 .data
= &unknown_nmi_panic
,
980 .maxlen
= sizeof (int),
982 .proc_handler
= proc_dointvec
,
985 #if defined(CONFIG_X86)
987 .procname
= "panic_on_unrecovered_nmi",
988 .data
= &panic_on_unrecovered_nmi
,
989 .maxlen
= sizeof(int),
991 .proc_handler
= proc_dointvec
,
994 .procname
= "panic_on_io_nmi",
995 .data
= &panic_on_io_nmi
,
996 .maxlen
= sizeof(int),
998 .proc_handler
= proc_dointvec
,
1000 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1002 .procname
= "panic_on_stackoverflow",
1003 .data
= &sysctl_panic_on_stackoverflow
,
1004 .maxlen
= sizeof(int),
1006 .proc_handler
= proc_dointvec
,
1010 .procname
= "bootloader_type",
1011 .data
= &bootloader_type
,
1012 .maxlen
= sizeof (int),
1014 .proc_handler
= proc_dointvec
,
1017 .procname
= "bootloader_version",
1018 .data
= &bootloader_version
,
1019 .maxlen
= sizeof (int),
1021 .proc_handler
= proc_dointvec
,
1024 .procname
= "io_delay_type",
1025 .data
= &io_delay_type
,
1026 .maxlen
= sizeof(int),
1028 .proc_handler
= proc_dointvec
,
1031 #if defined(CONFIG_MMU)
1033 .procname
= "randomize_va_space",
1034 .data
= &randomize_va_space
,
1035 .maxlen
= sizeof(int),
1037 .proc_handler
= proc_dointvec
,
1040 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1042 .procname
= "spin_retry",
1043 .data
= &spin_retry
,
1044 .maxlen
= sizeof (int),
1046 .proc_handler
= proc_dointvec
,
1049 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1051 .procname
= "acpi_video_flags",
1052 .data
= &acpi_realmode_flags
,
1053 .maxlen
= sizeof (unsigned long),
1055 .proc_handler
= proc_doulongvec_minmax
,
1058 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1060 .procname
= "ignore-unaligned-usertrap",
1061 .data
= &no_unaligned_warning
,
1062 .maxlen
= sizeof (int),
1064 .proc_handler
= proc_dointvec
,
1069 .procname
= "unaligned-dump-stack",
1070 .data
= &unaligned_dump_stack
,
1071 .maxlen
= sizeof (int),
1073 .proc_handler
= proc_dointvec
,
1076 #ifdef CONFIG_DETECT_HUNG_TASK
1078 .procname
= "hung_task_panic",
1079 .data
= &sysctl_hung_task_panic
,
1080 .maxlen
= sizeof(int),
1082 .proc_handler
= proc_dointvec_minmax
,
1087 .procname
= "hung_task_check_count",
1088 .data
= &sysctl_hung_task_check_count
,
1089 .maxlen
= sizeof(int),
1091 .proc_handler
= proc_dointvec_minmax
,
1095 .procname
= "hung_task_timeout_secs",
1096 .data
= &sysctl_hung_task_timeout_secs
,
1097 .maxlen
= sizeof(unsigned long),
1099 .proc_handler
= proc_dohung_task_timeout_secs
,
1100 .extra2
= &hung_task_timeout_max
,
1103 .procname
= "hung_task_warnings",
1104 .data
= &sysctl_hung_task_warnings
,
1105 .maxlen
= sizeof(int),
1107 .proc_handler
= proc_dointvec_minmax
,
1111 #ifdef CONFIG_RT_MUTEXES
1113 .procname
= "max_lock_depth",
1114 .data
= &max_lock_depth
,
1115 .maxlen
= sizeof(int),
1117 .proc_handler
= proc_dointvec
,
1121 .procname
= "poweroff_cmd",
1122 .data
= &poweroff_cmd
,
1123 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1125 .proc_handler
= proc_dostring
,
1131 .child
= key_sysctls
,
1134 #ifdef CONFIG_PERF_EVENTS
1136 * User-space scripts rely on the existence of this file
1137 * as a feature check for perf_events being enabled.
1139 * So it's an ABI, do not remove!
1142 .procname
= "perf_event_paranoid",
1143 .data
= &sysctl_perf_event_paranoid
,
1144 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1146 .proc_handler
= proc_dointvec
,
1149 .procname
= "perf_event_mlock_kb",
1150 .data
= &sysctl_perf_event_mlock
,
1151 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1153 .proc_handler
= proc_dointvec
,
1156 .procname
= "perf_event_max_sample_rate",
1157 .data
= &sysctl_perf_event_sample_rate
,
1158 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1160 .proc_handler
= perf_proc_update_handler
,
1164 .procname
= "perf_cpu_time_max_percent",
1165 .data
= &sysctl_perf_cpu_time_max_percent
,
1166 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1168 .proc_handler
= perf_cpu_time_max_percent_handler
,
1170 .extra2
= &one_hundred
,
1173 .procname
= "perf_event_max_stack",
1174 .data
= &sysctl_perf_event_max_stack
,
1175 .maxlen
= sizeof(sysctl_perf_event_max_stack
),
1177 .proc_handler
= perf_event_max_stack_handler
,
1179 .extra2
= &six_hundred_forty_kb
,
1182 .procname
= "perf_event_max_contexts_per_stack",
1183 .data
= &sysctl_perf_event_max_contexts_per_stack
,
1184 .maxlen
= sizeof(sysctl_perf_event_max_contexts_per_stack
),
1186 .proc_handler
= perf_event_max_stack_handler
,
1188 .extra2
= &one_thousand
,
1192 .procname
= "panic_on_warn",
1193 .data
= &panic_on_warn
,
1194 .maxlen
= sizeof(int),
1196 .proc_handler
= proc_dointvec_minmax
,
1200 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1202 .procname
= "timer_migration",
1203 .data
= &sysctl_timer_migration
,
1204 .maxlen
= sizeof(unsigned int),
1206 .proc_handler
= timer_migration_handler
,
1211 #ifdef CONFIG_BPF_SYSCALL
1213 .procname
= "unprivileged_bpf_disabled",
1214 .data
= &sysctl_unprivileged_bpf_disabled
,
1215 .maxlen
= sizeof(sysctl_unprivileged_bpf_disabled
),
1217 /* only handle a transition from default "0" to "1" */
1218 .proc_handler
= proc_dointvec_minmax
,
1223 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1225 .procname
= "panic_on_rcu_stall",
1226 .data
= &sysctl_panic_on_rcu_stall
,
1227 .maxlen
= sizeof(sysctl_panic_on_rcu_stall
),
1229 .proc_handler
= proc_dointvec_minmax
,
1237 static struct ctl_table vm_table
[] = {
1239 .procname
= "overcommit_memory",
1240 .data
= &sysctl_overcommit_memory
,
1241 .maxlen
= sizeof(sysctl_overcommit_memory
),
1243 .proc_handler
= proc_dointvec_minmax
,
1248 .procname
= "panic_on_oom",
1249 .data
= &sysctl_panic_on_oom
,
1250 .maxlen
= sizeof(sysctl_panic_on_oom
),
1252 .proc_handler
= proc_dointvec_minmax
,
1257 .procname
= "oom_kill_allocating_task",
1258 .data
= &sysctl_oom_kill_allocating_task
,
1259 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1261 .proc_handler
= proc_dointvec
,
1264 .procname
= "oom_dump_tasks",
1265 .data
= &sysctl_oom_dump_tasks
,
1266 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1268 .proc_handler
= proc_dointvec
,
1271 .procname
= "overcommit_ratio",
1272 .data
= &sysctl_overcommit_ratio
,
1273 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1275 .proc_handler
= overcommit_ratio_handler
,
1278 .procname
= "overcommit_kbytes",
1279 .data
= &sysctl_overcommit_kbytes
,
1280 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1282 .proc_handler
= overcommit_kbytes_handler
,
1285 .procname
= "page-cluster",
1286 .data
= &page_cluster
,
1287 .maxlen
= sizeof(int),
1289 .proc_handler
= proc_dointvec_minmax
,
1293 .procname
= "dirty_background_ratio",
1294 .data
= &dirty_background_ratio
,
1295 .maxlen
= sizeof(dirty_background_ratio
),
1297 .proc_handler
= dirty_background_ratio_handler
,
1299 .extra2
= &one_hundred
,
1302 .procname
= "dirty_background_bytes",
1303 .data
= &dirty_background_bytes
,
1304 .maxlen
= sizeof(dirty_background_bytes
),
1306 .proc_handler
= dirty_background_bytes_handler
,
1310 .procname
= "dirty_ratio",
1311 .data
= &vm_dirty_ratio
,
1312 .maxlen
= sizeof(vm_dirty_ratio
),
1314 .proc_handler
= dirty_ratio_handler
,
1316 .extra2
= &one_hundred
,
1319 .procname
= "dirty_bytes",
1320 .data
= &vm_dirty_bytes
,
1321 .maxlen
= sizeof(vm_dirty_bytes
),
1323 .proc_handler
= dirty_bytes_handler
,
1324 .extra1
= &dirty_bytes_min
,
1327 .procname
= "dirty_writeback_centisecs",
1328 .data
= &dirty_writeback_interval
,
1329 .maxlen
= sizeof(dirty_writeback_interval
),
1331 .proc_handler
= dirty_writeback_centisecs_handler
,
1334 .procname
= "dirty_expire_centisecs",
1335 .data
= &dirty_expire_interval
,
1336 .maxlen
= sizeof(dirty_expire_interval
),
1338 .proc_handler
= proc_dointvec_minmax
,
1342 .procname
= "dirtytime_expire_seconds",
1343 .data
= &dirtytime_expire_interval
,
1344 .maxlen
= sizeof(dirty_expire_interval
),
1346 .proc_handler
= dirtytime_interval_handler
,
1350 .procname
= "swappiness",
1351 .data
= &vm_swappiness
,
1352 .maxlen
= sizeof(vm_swappiness
),
1354 .proc_handler
= proc_dointvec_minmax
,
1356 .extra2
= &one_hundred
,
1358 #ifdef CONFIG_HUGETLB_PAGE
1360 .procname
= "nr_hugepages",
1362 .maxlen
= sizeof(unsigned long),
1364 .proc_handler
= hugetlb_sysctl_handler
,
1368 .procname
= "nr_hugepages_mempolicy",
1370 .maxlen
= sizeof(unsigned long),
1372 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1375 .procname
= "numa_stat",
1376 .data
= &sysctl_vm_numa_stat
,
1377 .maxlen
= sizeof(int),
1379 .proc_handler
= sysctl_vm_numa_stat_handler
,
1385 .procname
= "hugetlb_shm_group",
1386 .data
= &sysctl_hugetlb_shm_group
,
1387 .maxlen
= sizeof(gid_t
),
1389 .proc_handler
= proc_dointvec
,
1392 .procname
= "hugepages_treat_as_movable",
1393 .data
= &hugepages_treat_as_movable
,
1394 .maxlen
= sizeof(int),
1396 .proc_handler
= proc_dointvec
,
1399 .procname
= "nr_overcommit_hugepages",
1401 .maxlen
= sizeof(unsigned long),
1403 .proc_handler
= hugetlb_overcommit_handler
,
1407 .procname
= "lowmem_reserve_ratio",
1408 .data
= &sysctl_lowmem_reserve_ratio
,
1409 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1411 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1414 .procname
= "drop_caches",
1415 .data
= &sysctl_drop_caches
,
1416 .maxlen
= sizeof(int),
1418 .proc_handler
= drop_caches_sysctl_handler
,
1422 #ifdef CONFIG_COMPACTION
1424 .procname
= "compact_memory",
1425 .data
= &sysctl_compact_memory
,
1426 .maxlen
= sizeof(int),
1428 .proc_handler
= sysctl_compaction_handler
,
1431 .procname
= "extfrag_threshold",
1432 .data
= &sysctl_extfrag_threshold
,
1433 .maxlen
= sizeof(int),
1435 .proc_handler
= sysctl_extfrag_handler
,
1436 .extra1
= &min_extfrag_threshold
,
1437 .extra2
= &max_extfrag_threshold
,
1440 .procname
= "compact_unevictable_allowed",
1441 .data
= &sysctl_compact_unevictable_allowed
,
1442 .maxlen
= sizeof(int),
1444 .proc_handler
= proc_dointvec
,
1449 #endif /* CONFIG_COMPACTION */
1451 .procname
= "min_free_kbytes",
1452 .data
= &min_free_kbytes
,
1453 .maxlen
= sizeof(min_free_kbytes
),
1455 .proc_handler
= min_free_kbytes_sysctl_handler
,
1459 .procname
= "watermark_scale_factor",
1460 .data
= &watermark_scale_factor
,
1461 .maxlen
= sizeof(watermark_scale_factor
),
1463 .proc_handler
= watermark_scale_factor_sysctl_handler
,
1465 .extra2
= &one_thousand
,
1468 .procname
= "percpu_pagelist_fraction",
1469 .data
= &percpu_pagelist_fraction
,
1470 .maxlen
= sizeof(percpu_pagelist_fraction
),
1472 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1477 .procname
= "max_map_count",
1478 .data
= &sysctl_max_map_count
,
1479 .maxlen
= sizeof(sysctl_max_map_count
),
1481 .proc_handler
= proc_dointvec_minmax
,
1486 .procname
= "nr_trim_pages",
1487 .data
= &sysctl_nr_trim_pages
,
1488 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1490 .proc_handler
= proc_dointvec_minmax
,
1495 .procname
= "laptop_mode",
1496 .data
= &laptop_mode
,
1497 .maxlen
= sizeof(laptop_mode
),
1499 .proc_handler
= proc_dointvec_jiffies
,
1502 .procname
= "block_dump",
1503 .data
= &block_dump
,
1504 .maxlen
= sizeof(block_dump
),
1506 .proc_handler
= proc_dointvec
,
1510 .procname
= "vfs_cache_pressure",
1511 .data
= &sysctl_vfs_cache_pressure
,
1512 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1514 .proc_handler
= proc_dointvec
,
1517 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1519 .procname
= "legacy_va_layout",
1520 .data
= &sysctl_legacy_va_layout
,
1521 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1523 .proc_handler
= proc_dointvec
,
1529 .procname
= "zone_reclaim_mode",
1530 .data
= &node_reclaim_mode
,
1531 .maxlen
= sizeof(node_reclaim_mode
),
1533 .proc_handler
= proc_dointvec
,
1537 .procname
= "min_unmapped_ratio",
1538 .data
= &sysctl_min_unmapped_ratio
,
1539 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1541 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1543 .extra2
= &one_hundred
,
1546 .procname
= "min_slab_ratio",
1547 .data
= &sysctl_min_slab_ratio
,
1548 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1550 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1552 .extra2
= &one_hundred
,
1557 .procname
= "stat_interval",
1558 .data
= &sysctl_stat_interval
,
1559 .maxlen
= sizeof(sysctl_stat_interval
),
1561 .proc_handler
= proc_dointvec_jiffies
,
1564 .procname
= "stat_refresh",
1568 .proc_handler
= vmstat_refresh
,
1573 .procname
= "mmap_min_addr",
1574 .data
= &dac_mmap_min_addr
,
1575 .maxlen
= sizeof(unsigned long),
1577 .proc_handler
= mmap_min_addr_handler
,
1582 .procname
= "numa_zonelist_order",
1583 .data
= &numa_zonelist_order
,
1584 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1586 .proc_handler
= numa_zonelist_order_handler
,
1589 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1590 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1592 .procname
= "vdso_enabled",
1593 #ifdef CONFIG_X86_32
1594 .data
= &vdso32_enabled
,
1595 .maxlen
= sizeof(vdso32_enabled
),
1597 .data
= &vdso_enabled
,
1598 .maxlen
= sizeof(vdso_enabled
),
1601 .proc_handler
= proc_dointvec
,
1605 #ifdef CONFIG_HIGHMEM
1607 .procname
= "highmem_is_dirtyable",
1608 .data
= &vm_highmem_is_dirtyable
,
1609 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1611 .proc_handler
= proc_dointvec_minmax
,
1616 #ifdef CONFIG_MEMORY_FAILURE
1618 .procname
= "memory_failure_early_kill",
1619 .data
= &sysctl_memory_failure_early_kill
,
1620 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1622 .proc_handler
= proc_dointvec_minmax
,
1627 .procname
= "memory_failure_recovery",
1628 .data
= &sysctl_memory_failure_recovery
,
1629 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1631 .proc_handler
= proc_dointvec_minmax
,
1637 .procname
= "user_reserve_kbytes",
1638 .data
= &sysctl_user_reserve_kbytes
,
1639 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1641 .proc_handler
= proc_doulongvec_minmax
,
1644 .procname
= "admin_reserve_kbytes",
1645 .data
= &sysctl_admin_reserve_kbytes
,
1646 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1648 .proc_handler
= proc_doulongvec_minmax
,
1650 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1652 .procname
= "mmap_rnd_bits",
1653 .data
= &mmap_rnd_bits
,
1654 .maxlen
= sizeof(mmap_rnd_bits
),
1656 .proc_handler
= proc_dointvec_minmax
,
1657 .extra1
= (void *)&mmap_rnd_bits_min
,
1658 .extra2
= (void *)&mmap_rnd_bits_max
,
1661 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1663 .procname
= "mmap_rnd_compat_bits",
1664 .data
= &mmap_rnd_compat_bits
,
1665 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1667 .proc_handler
= proc_dointvec_minmax
,
1668 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1669 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1675 static struct ctl_table fs_table
[] = {
1677 .procname
= "inode-nr",
1678 .data
= &inodes_stat
,
1679 .maxlen
= 2*sizeof(long),
1681 .proc_handler
= proc_nr_inodes
,
1684 .procname
= "inode-state",
1685 .data
= &inodes_stat
,
1686 .maxlen
= 7*sizeof(long),
1688 .proc_handler
= proc_nr_inodes
,
1691 .procname
= "file-nr",
1692 .data
= &files_stat
,
1693 .maxlen
= sizeof(files_stat
),
1695 .proc_handler
= proc_nr_files
,
1698 .procname
= "file-max",
1699 .data
= &files_stat
.max_files
,
1700 .maxlen
= sizeof(files_stat
.max_files
),
1702 .proc_handler
= proc_doulongvec_minmax
,
1704 .extra2
= &long_max
,
1707 .procname
= "nr_open",
1708 .data
= &sysctl_nr_open
,
1709 .maxlen
= sizeof(unsigned int),
1711 .proc_handler
= proc_dointvec_minmax
,
1712 .extra1
= &sysctl_nr_open_min
,
1713 .extra2
= &sysctl_nr_open_max
,
1716 .procname
= "dentry-state",
1717 .data
= &dentry_stat
,
1718 .maxlen
= 6*sizeof(long),
1720 .proc_handler
= proc_nr_dentry
,
1723 .procname
= "overflowuid",
1724 .data
= &fs_overflowuid
,
1725 .maxlen
= sizeof(int),
1727 .proc_handler
= proc_dointvec_minmax
,
1728 .extra1
= &minolduid
,
1729 .extra2
= &maxolduid
,
1732 .procname
= "overflowgid",
1733 .data
= &fs_overflowgid
,
1734 .maxlen
= sizeof(int),
1736 .proc_handler
= proc_dointvec_minmax
,
1737 .extra1
= &minolduid
,
1738 .extra2
= &maxolduid
,
1740 #ifdef CONFIG_FILE_LOCKING
1742 .procname
= "leases-enable",
1743 .data
= &leases_enable
,
1744 .maxlen
= sizeof(int),
1746 .proc_handler
= proc_dointvec
,
1749 #ifdef CONFIG_DNOTIFY
1751 .procname
= "dir-notify-enable",
1752 .data
= &dir_notify_enable
,
1753 .maxlen
= sizeof(int),
1755 .proc_handler
= proc_dointvec
,
1759 #ifdef CONFIG_FILE_LOCKING
1761 .procname
= "lease-break-time",
1762 .data
= &lease_break_time
,
1763 .maxlen
= sizeof(int),
1765 .proc_handler
= proc_dointvec
,
1770 .procname
= "aio-nr",
1772 .maxlen
= sizeof(aio_nr
),
1774 .proc_handler
= proc_doulongvec_minmax
,
1777 .procname
= "aio-max-nr",
1778 .data
= &aio_max_nr
,
1779 .maxlen
= sizeof(aio_max_nr
),
1781 .proc_handler
= proc_doulongvec_minmax
,
1783 #endif /* CONFIG_AIO */
1784 #ifdef CONFIG_INOTIFY_USER
1786 .procname
= "inotify",
1788 .child
= inotify_table
,
1793 .procname
= "epoll",
1795 .child
= epoll_table
,
1800 .procname
= "protected_symlinks",
1801 .data
= &sysctl_protected_symlinks
,
1802 .maxlen
= sizeof(int),
1804 .proc_handler
= proc_dointvec_minmax
,
1809 .procname
= "protected_hardlinks",
1810 .data
= &sysctl_protected_hardlinks
,
1811 .maxlen
= sizeof(int),
1813 .proc_handler
= proc_dointvec_minmax
,
1818 .procname
= "suid_dumpable",
1819 .data
= &suid_dumpable
,
1820 .maxlen
= sizeof(int),
1822 .proc_handler
= proc_dointvec_minmax_coredump
,
1826 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1828 .procname
= "binfmt_misc",
1830 .child
= sysctl_mount_point
,
1834 .procname
= "pipe-max-size",
1835 .data
= &pipe_max_size
,
1836 .maxlen
= sizeof(pipe_max_size
),
1838 .proc_handler
= &pipe_proc_fn
,
1839 .extra1
= &pipe_min_size
,
1842 .procname
= "pipe-user-pages-hard",
1843 .data
= &pipe_user_pages_hard
,
1844 .maxlen
= sizeof(pipe_user_pages_hard
),
1846 .proc_handler
= proc_doulongvec_minmax
,
1849 .procname
= "pipe-user-pages-soft",
1850 .data
= &pipe_user_pages_soft
,
1851 .maxlen
= sizeof(pipe_user_pages_soft
),
1853 .proc_handler
= proc_doulongvec_minmax
,
1856 .procname
= "mount-max",
1857 .data
= &sysctl_mount_max
,
1858 .maxlen
= sizeof(unsigned int),
1860 .proc_handler
= proc_dointvec_minmax
,
1866 static struct ctl_table debug_table
[] = {
1867 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1869 .procname
= "exception-trace",
1870 .data
= &show_unhandled_signals
,
1871 .maxlen
= sizeof(int),
1873 .proc_handler
= proc_dointvec
1876 #if defined(CONFIG_OPTPROBES)
1878 .procname
= "kprobes-optimization",
1879 .data
= &sysctl_kprobes_optimization
,
1880 .maxlen
= sizeof(int),
1882 .proc_handler
= proc_kprobes_optimization_handler
,
1890 static struct ctl_table dev_table
[] = {
1894 int __init
sysctl_init(void)
1896 struct ctl_table_header
*hdr
;
1898 hdr
= register_sysctl_table(sysctl_base_table
);
1899 kmemleak_not_leak(hdr
);
1903 #endif /* CONFIG_SYSCTL */
1909 #ifdef CONFIG_PROC_SYSCTL
1911 static int _proc_do_string(char *data
, int maxlen
, int write
,
1912 char __user
*buffer
,
1913 size_t *lenp
, loff_t
*ppos
)
1919 if (!data
|| !maxlen
|| !*lenp
) {
1925 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1926 /* Only continue writes not past the end of buffer. */
1928 if (len
> maxlen
- 1)
1935 /* Start writing from beginning of buffer. */
1941 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
1942 if (get_user(c
, p
++))
1944 if (c
== 0 || c
== '\n')
1965 if (copy_to_user(buffer
, data
, len
))
1968 if (put_user('\n', buffer
+ len
))
1978 static void warn_sysctl_write(struct ctl_table
*table
)
1980 pr_warn_once("%s wrote to %s when file position was not 0!\n"
1981 "This will not be supported in the future. To silence this\n"
1982 "warning, set kernel.sysctl_writes_strict = -1\n",
1983 current
->comm
, table
->procname
);
1987 * proc_first_pos_non_zero_ignore - check if firs position is allowed
1988 * @ppos: file position
1989 * @table: the sysctl table
1991 * Returns true if the first position is non-zero and the sysctl_writes_strict
1992 * mode indicates this is not allowed for numeric input types. String proc
1993 * hadlers can ignore the return value.
1995 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
1996 struct ctl_table
*table
)
2001 switch (sysctl_writes_strict
) {
2002 case SYSCTL_WRITES_STRICT
:
2004 case SYSCTL_WRITES_WARN
:
2005 warn_sysctl_write(table
);
2013 * proc_dostring - read a string sysctl
2014 * @table: the sysctl table
2015 * @write: %TRUE if this is a write to the sysctl file
2016 * @buffer: the user buffer
2017 * @lenp: the size of the user buffer
2018 * @ppos: file position
2020 * Reads/writes a string from/to the user buffer. If the kernel
2021 * buffer provided is not large enough to hold the string, the
2022 * string is truncated. The copied string is %NULL-terminated.
2023 * If the string is being read by the user process, it is copied
2024 * and a newline '\n' is added. It is truncated if the buffer is
2027 * Returns 0 on success.
2029 int proc_dostring(struct ctl_table
*table
, int write
,
2030 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2033 proc_first_pos_non_zero_ignore(ppos
, table
);
2035 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2036 (char __user
*)buffer
, lenp
, ppos
);
2039 static size_t proc_skip_spaces(char **buf
)
2042 char *tmp
= skip_spaces(*buf
);
2048 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2058 #define TMPBUFLEN 22
2060 * proc_get_long - reads an ASCII formatted integer from a user buffer
2062 * @buf: a kernel buffer
2063 * @size: size of the kernel buffer
2064 * @val: this is where the number will be stored
2065 * @neg: set to %TRUE if number is negative
2066 * @perm_tr: a vector which contains the allowed trailers
2067 * @perm_tr_len: size of the perm_tr vector
2068 * @tr: pointer to store the trailer character
2070 * In case of success %0 is returned and @buf and @size are updated with
2071 * the amount of bytes read. If @tr is non-NULL and a trailing
2072 * character exists (size is non-zero after returning from this
2073 * function), @tr is updated with the trailing character.
2075 static int proc_get_long(char **buf
, size_t *size
,
2076 unsigned long *val
, bool *neg
,
2077 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2080 char *p
, tmp
[TMPBUFLEN
];
2086 if (len
> TMPBUFLEN
- 1)
2087 len
= TMPBUFLEN
- 1;
2089 memcpy(tmp
, *buf
, len
);
2093 if (*p
== '-' && *size
> 1) {
2101 *val
= simple_strtoul(p
, &p
, 0);
2105 /* We don't know if the next char is whitespace thus we may accept
2106 * invalid integers (e.g. 1234...a) or two integers instead of one
2107 * (e.g. 123...1). So lets not allow such large numbers. */
2108 if (len
== TMPBUFLEN
- 1)
2111 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2114 if (tr
&& (len
< *size
))
2124 * proc_put_long - converts an integer to a decimal ASCII formatted string
2126 * @buf: the user buffer
2127 * @size: the size of the user buffer
2128 * @val: the integer to be converted
2129 * @neg: sign of the number, %TRUE for negative
2131 * In case of success %0 is returned and @buf and @size are updated with
2132 * the amount of bytes written.
2134 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2138 char tmp
[TMPBUFLEN
], *p
= tmp
;
2140 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2144 if (copy_to_user(*buf
, tmp
, len
))
2152 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2155 char __user
**buffer
= (char __user
**)buf
;
2156 if (put_user(c
, *buffer
))
2158 (*size
)--, (*buffer
)++;
2164 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2166 int write
, void *data
)
2170 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2174 if (*lvalp
> (unsigned long) INT_MAX
)
2182 *lvalp
= -(unsigned long)val
;
2185 *lvalp
= (unsigned long)val
;
2191 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2193 int write
, void *data
)
2196 if (*lvalp
> UINT_MAX
)
2200 unsigned int val
= *valp
;
2201 *lvalp
= (unsigned long)val
;
2206 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2208 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2209 int write
, void __user
*buffer
,
2210 size_t *lenp
, loff_t
*ppos
,
2211 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2212 int write
, void *data
),
2215 int *i
, vleft
, first
= 1, err
= 0;
2217 char *kbuf
= NULL
, *p
;
2219 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2224 i
= (int *) tbl_data
;
2225 vleft
= table
->maxlen
/ sizeof(*i
);
2229 conv
= do_proc_dointvec_conv
;
2232 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2235 if (left
> PAGE_SIZE
- 1)
2236 left
= PAGE_SIZE
- 1;
2237 p
= kbuf
= memdup_user_nul(buffer
, left
);
2239 return PTR_ERR(kbuf
);
2242 for (; left
&& vleft
--; i
++, first
=0) {
2247 left
-= proc_skip_spaces(&p
);
2251 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2253 sizeof(proc_wspace_sep
), NULL
);
2256 if (conv(&neg
, &lval
, i
, 1, data
)) {
2261 if (conv(&neg
, &lval
, i
, 0, data
)) {
2266 err
= proc_put_char(&buffer
, &left
, '\t');
2269 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2275 if (!write
&& !first
&& left
&& !err
)
2276 err
= proc_put_char(&buffer
, &left
, '\n');
2277 if (write
&& !err
&& left
)
2278 left
-= proc_skip_spaces(&p
);
2282 return err
? : -EINVAL
;
2290 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2291 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2292 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2293 int write
, void *data
),
2296 return __do_proc_dointvec(table
->data
, table
, write
,
2297 buffer
, lenp
, ppos
, conv
, data
);
2300 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2301 struct ctl_table
*table
,
2302 void __user
*buffer
,
2303 size_t *lenp
, loff_t
*ppos
,
2304 int (*conv
)(unsigned long *lvalp
,
2306 int write
, void *data
),
2313 char *kbuf
= NULL
, *p
;
2317 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2320 if (left
> PAGE_SIZE
- 1)
2321 left
= PAGE_SIZE
- 1;
2323 p
= kbuf
= memdup_user_nul(buffer
, left
);
2327 left
-= proc_skip_spaces(&p
);
2333 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2335 sizeof(proc_wspace_sep
), NULL
);
2341 if (conv(&lval
, tbl_data
, 1, data
)) {
2347 left
-= proc_skip_spaces(&p
);
2356 /* This is in keeping with old __do_proc_dointvec() */
2362 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2363 size_t *lenp
, loff_t
*ppos
,
2364 int (*conv
)(unsigned long *lvalp
,
2366 int write
, void *data
),
2375 if (conv(&lval
, tbl_data
, 0, data
)) {
2380 err
= proc_put_long(&buffer
, &left
, lval
, false);
2384 err
= proc_put_char(&buffer
, &left
, '\n');
2393 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2394 int write
, void __user
*buffer
,
2395 size_t *lenp
, loff_t
*ppos
,
2396 int (*conv
)(unsigned long *lvalp
,
2398 int write
, void *data
),
2401 unsigned int *i
, vleft
;
2403 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2408 i
= (unsigned int *) tbl_data
;
2409 vleft
= table
->maxlen
/ sizeof(*i
);
2412 * Arrays are not supported, keep this simple. *Do not* add
2421 conv
= do_proc_douintvec_conv
;
2424 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2426 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2429 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2430 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2431 int (*conv
)(unsigned long *lvalp
,
2433 int write
, void *data
),
2436 return __do_proc_douintvec(table
->data
, table
, write
,
2437 buffer
, lenp
, ppos
, conv
, data
);
2441 * proc_dointvec - read a vector of integers
2442 * @table: the sysctl table
2443 * @write: %TRUE if this is a write to the sysctl file
2444 * @buffer: the user buffer
2445 * @lenp: the size of the user buffer
2446 * @ppos: file position
2448 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2449 * values from/to the user buffer, treated as an ASCII string.
2451 * Returns 0 on success.
2453 int proc_dointvec(struct ctl_table
*table
, int write
,
2454 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2456 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2460 * proc_douintvec - read a vector of unsigned integers
2461 * @table: the sysctl table
2462 * @write: %TRUE if this is a write to the sysctl file
2463 * @buffer: the user buffer
2464 * @lenp: the size of the user buffer
2465 * @ppos: file position
2467 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2468 * values from/to the user buffer, treated as an ASCII string.
2470 * Returns 0 on success.
2472 int proc_douintvec(struct ctl_table
*table
, int write
,
2473 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2475 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2476 do_proc_douintvec_conv
, NULL
);
2480 * Taint values can only be increased
2481 * This means we can safely use a temporary.
2483 static int proc_taint(struct ctl_table
*table
, int write
,
2484 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2487 unsigned long tmptaint
= get_taint();
2490 if (write
&& !capable(CAP_SYS_ADMIN
))
2495 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2501 * Poor man's atomic or. Not worth adding a primitive
2502 * to everyone's atomic.h for this
2505 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2506 if ((tmptaint
>> i
) & 1)
2507 add_taint(i
, LOCKDEP_STILL_OK
);
2514 #ifdef CONFIG_PRINTK
2515 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2516 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2518 if (write
&& !capable(CAP_SYS_ADMIN
))
2521 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2525 struct do_proc_dointvec_minmax_conv_param
{
2530 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2532 int write
, void *data
)
2534 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2536 int val
= *negp
? -*lvalp
: *lvalp
;
2537 if ((param
->min
&& *param
->min
> val
) ||
2538 (param
->max
&& *param
->max
< val
))
2545 *lvalp
= -(unsigned long)val
;
2548 *lvalp
= (unsigned long)val
;
2555 * proc_dointvec_minmax - read a vector of integers with min/max values
2556 * @table: the sysctl table
2557 * @write: %TRUE if this is a write to the sysctl file
2558 * @buffer: the user buffer
2559 * @lenp: the size of the user buffer
2560 * @ppos: file position
2562 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2563 * values from/to the user buffer, treated as an ASCII string.
2565 * This routine will ensure the values are within the range specified by
2566 * table->extra1 (min) and table->extra2 (max).
2568 * Returns 0 on success.
2570 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2571 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2573 struct do_proc_dointvec_minmax_conv_param param
= {
2574 .min
= (int *) table
->extra1
,
2575 .max
= (int *) table
->extra2
,
2577 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2578 do_proc_dointvec_minmax_conv
, ¶m
);
2581 struct do_proc_douintvec_minmax_conv_param
{
2586 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp
,
2588 int write
, void *data
)
2590 struct do_proc_douintvec_minmax_conv_param
*param
= data
;
2593 unsigned int val
= *lvalp
;
2595 if (*lvalp
> UINT_MAX
)
2598 if ((param
->min
&& *param
->min
> val
) ||
2599 (param
->max
&& *param
->max
< val
))
2604 unsigned int val
= *valp
;
2605 *lvalp
= (unsigned long) val
;
2612 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2613 * @table: the sysctl table
2614 * @write: %TRUE if this is a write to the sysctl file
2615 * @buffer: the user buffer
2616 * @lenp: the size of the user buffer
2617 * @ppos: file position
2619 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2620 * values from/to the user buffer, treated as an ASCII string. Negative
2621 * strings are not allowed.
2623 * This routine will ensure the values are within the range specified by
2624 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2625 * check for UINT_MAX to avoid having to support wrap around uses from
2628 * Returns 0 on success.
2630 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
2631 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2633 struct do_proc_douintvec_minmax_conv_param param
= {
2634 .min
= (unsigned int *) table
->extra1
,
2635 .max
= (unsigned int *) table
->extra2
,
2637 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2638 do_proc_douintvec_minmax_conv
, ¶m
);
2641 struct do_proc_dopipe_max_size_conv_param
{
2645 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp
,
2647 int write
, void *data
)
2649 struct do_proc_dopipe_max_size_conv_param
*param
= data
;
2654 if (*lvalp
> UINT_MAX
)
2657 val
= round_pipe_size(*lvalp
);
2661 if (param
->min
&& *param
->min
> val
)
2666 unsigned int val
= *valp
;
2667 *lvalp
= (unsigned long) val
;
2673 int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
2674 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2676 struct do_proc_dopipe_max_size_conv_param param
= {
2677 .min
= (unsigned int *) table
->extra1
,
2679 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2680 do_proc_dopipe_max_size_conv
, ¶m
);
2683 static void validate_coredump_safety(void)
2685 #ifdef CONFIG_COREDUMP
2686 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2687 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2689 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2690 "Pipe handler or fully qualified core dump path required.\n"
2691 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2697 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2698 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2700 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2702 validate_coredump_safety();
2706 #ifdef CONFIG_COREDUMP
2707 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2708 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2710 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2712 validate_coredump_safety();
2717 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2718 void __user
*buffer
,
2719 size_t *lenp
, loff_t
*ppos
,
2720 unsigned long convmul
,
2721 unsigned long convdiv
)
2723 unsigned long *i
, *min
, *max
;
2724 int vleft
, first
= 1, err
= 0;
2726 char *kbuf
= NULL
, *p
;
2728 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2733 i
= (unsigned long *) data
;
2734 min
= (unsigned long *) table
->extra1
;
2735 max
= (unsigned long *) table
->extra2
;
2736 vleft
= table
->maxlen
/ sizeof(unsigned long);
2740 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2743 if (left
> PAGE_SIZE
- 1)
2744 left
= PAGE_SIZE
- 1;
2745 p
= kbuf
= memdup_user_nul(buffer
, left
);
2747 return PTR_ERR(kbuf
);
2750 for (; left
&& vleft
--; i
++, first
= 0) {
2756 left
-= proc_skip_spaces(&p
);
2758 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2760 sizeof(proc_wspace_sep
), NULL
);
2765 val
= convmul
* val
/ convdiv
;
2766 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2770 val
= convdiv
* (*i
) / convmul
;
2772 err
= proc_put_char(&buffer
, &left
, '\t');
2776 err
= proc_put_long(&buffer
, &left
, val
, false);
2782 if (!write
&& !first
&& left
&& !err
)
2783 err
= proc_put_char(&buffer
, &left
, '\n');
2785 left
-= proc_skip_spaces(&p
);
2789 return err
? : -EINVAL
;
2797 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2798 void __user
*buffer
,
2799 size_t *lenp
, loff_t
*ppos
,
2800 unsigned long convmul
,
2801 unsigned long convdiv
)
2803 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2804 buffer
, lenp
, ppos
, convmul
, convdiv
);
2808 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2809 * @table: the sysctl table
2810 * @write: %TRUE if this is a write to the sysctl file
2811 * @buffer: the user buffer
2812 * @lenp: the size of the user buffer
2813 * @ppos: file position
2815 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2816 * values from/to the user buffer, treated as an ASCII string.
2818 * This routine will ensure the values are within the range specified by
2819 * table->extra1 (min) and table->extra2 (max).
2821 * Returns 0 on success.
2823 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2824 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2826 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2830 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2831 * @table: the sysctl table
2832 * @write: %TRUE if this is a write to the sysctl file
2833 * @buffer: the user buffer
2834 * @lenp: the size of the user buffer
2835 * @ppos: file position
2837 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2838 * values from/to the user buffer, treated as an ASCII string. The values
2839 * are treated as milliseconds, and converted to jiffies when they are stored.
2841 * This routine will ensure the values are within the range specified by
2842 * table->extra1 (min) and table->extra2 (max).
2844 * Returns 0 on success.
2846 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2847 void __user
*buffer
,
2848 size_t *lenp
, loff_t
*ppos
)
2850 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2851 lenp
, ppos
, HZ
, 1000l);
2855 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2857 int write
, void *data
)
2860 if (*lvalp
> INT_MAX
/ HZ
)
2862 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2868 lval
= -(unsigned long)val
;
2871 lval
= (unsigned long)val
;
2878 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2880 int write
, void *data
)
2883 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2885 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2891 lval
= -(unsigned long)val
;
2894 lval
= (unsigned long)val
;
2896 *lvalp
= jiffies_to_clock_t(lval
);
2901 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2903 int write
, void *data
)
2906 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2916 lval
= -(unsigned long)val
;
2919 lval
= (unsigned long)val
;
2921 *lvalp
= jiffies_to_msecs(lval
);
2927 * proc_dointvec_jiffies - read a vector of integers as seconds
2928 * @table: the sysctl table
2929 * @write: %TRUE if this is a write to the sysctl file
2930 * @buffer: the user buffer
2931 * @lenp: the size of the user buffer
2932 * @ppos: file position
2934 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2935 * values from/to the user buffer, treated as an ASCII string.
2936 * The values read are assumed to be in seconds, and are converted into
2939 * Returns 0 on success.
2941 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2942 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2944 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2945 do_proc_dointvec_jiffies_conv
,NULL
);
2949 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2950 * @table: the sysctl table
2951 * @write: %TRUE if this is a write to the sysctl file
2952 * @buffer: the user buffer
2953 * @lenp: the size of the user buffer
2954 * @ppos: pointer to the file position
2956 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2957 * values from/to the user buffer, treated as an ASCII string.
2958 * The values read are assumed to be in 1/USER_HZ seconds, and
2959 * are converted into jiffies.
2961 * Returns 0 on success.
2963 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2964 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2966 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2967 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2971 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2972 * @table: the sysctl table
2973 * @write: %TRUE if this is a write to the sysctl file
2974 * @buffer: the user buffer
2975 * @lenp: the size of the user buffer
2976 * @ppos: file position
2977 * @ppos: the current position in the file
2979 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2980 * values from/to the user buffer, treated as an ASCII string.
2981 * The values read are assumed to be in 1/1000 seconds, and
2982 * are converted into jiffies.
2984 * Returns 0 on success.
2986 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2987 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2989 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2990 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2993 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2994 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2996 struct pid
*new_pid
;
3000 tmp
= pid_vnr(cad_pid
);
3002 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
3003 lenp
, ppos
, NULL
, NULL
);
3007 new_pid
= find_get_pid(tmp
);
3011 put_pid(xchg(&cad_pid
, new_pid
));
3016 * proc_do_large_bitmap - read/write from/to a large bitmap
3017 * @table: the sysctl table
3018 * @write: %TRUE if this is a write to the sysctl file
3019 * @buffer: the user buffer
3020 * @lenp: the size of the user buffer
3021 * @ppos: file position
3023 * The bitmap is stored at table->data and the bitmap length (in bits)
3026 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3027 * large bitmaps may be represented in a compact manner. Writing into
3028 * the file will clear the bitmap then update it with the given input.
3030 * Returns 0 on success.
3032 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3033 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3037 size_t left
= *lenp
;
3038 unsigned long bitmap_len
= table
->maxlen
;
3039 unsigned long *bitmap
= *(unsigned long **) table
->data
;
3040 unsigned long *tmp_bitmap
= NULL
;
3041 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
3043 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3051 if (left
> PAGE_SIZE
- 1)
3052 left
= PAGE_SIZE
- 1;
3054 p
= kbuf
= memdup_user_nul(buffer
, left
);
3056 return PTR_ERR(kbuf
);
3058 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
3064 proc_skip_char(&p
, &left
, '\n');
3065 while (!err
&& left
) {
3066 unsigned long val_a
, val_b
;
3069 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3073 if (val_a
>= bitmap_len
|| neg
) {
3085 err
= proc_get_long(&p
, &left
, &val_b
,
3086 &neg
, tr_b
, sizeof(tr_b
),
3090 if (val_b
>= bitmap_len
|| neg
||
3101 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3103 proc_skip_char(&p
, &left
, '\n');
3107 unsigned long bit_a
, bit_b
= 0;
3110 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3111 if (bit_a
>= bitmap_len
)
3113 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3117 err
= proc_put_char(&buffer
, &left
, ',');
3121 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3124 if (bit_a
!= bit_b
) {
3125 err
= proc_put_char(&buffer
, &left
, '-');
3128 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3136 err
= proc_put_char(&buffer
, &left
, '\n');
3142 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3144 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3154 #else /* CONFIG_PROC_SYSCTL */
3156 int proc_dostring(struct ctl_table
*table
, int write
,
3157 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3162 int proc_dointvec(struct ctl_table
*table
, int write
,
3163 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3168 int proc_douintvec(struct ctl_table
*table
, int write
,
3169 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3174 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3175 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3180 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3181 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3186 int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
3187 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3192 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3193 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3198 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3199 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3204 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3205 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3210 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3211 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3216 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3217 void __user
*buffer
,
3218 size_t *lenp
, loff_t
*ppos
)
3224 #endif /* CONFIG_PROC_SYSCTL */
3227 * No sense putting this after each symbol definition, twice,
3228 * exception granted :-)
3230 EXPORT_SYMBOL(proc_dointvec
);
3231 EXPORT_SYMBOL(proc_douintvec
);
3232 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3233 EXPORT_SYMBOL(proc_dointvec_minmax
);
3234 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3235 EXPORT_SYMBOL_GPL(proc_dopipe_max_size
);
3236 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3237 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3238 EXPORT_SYMBOL(proc_dostring
);
3239 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3240 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);