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>
70 #include "../lib/kstrtox.h"
72 #include <linux/uaccess.h>
73 #include <asm/processor.h>
77 #include <asm/stacktrace.h>
81 #include <asm/setup.h>
83 #ifdef CONFIG_BSD_PROCESS_ACCT
84 #include <linux/acct.h>
86 #ifdef CONFIG_RT_MUTEXES
87 #include <linux/rtmutex.h>
89 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
90 #include <linux/lockdep.h>
92 #ifdef CONFIG_CHR_DEV_SG
95 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
96 #include <linux/stackleak.h>
98 #ifdef CONFIG_LOCKUP_DETECTOR
99 #include <linux/nmi.h>
102 #if defined(CONFIG_SYSCTL)
104 /* External variables not in a header file. */
105 extern int suid_dumpable
;
106 #ifdef CONFIG_COREDUMP
107 extern int core_uses_pid
;
108 extern char core_pattern
[];
109 extern unsigned int core_pipe_limit
;
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
;
154 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
155 * and hung_task_check_interval_secs
157 #ifdef CONFIG_DETECT_HUNG_TASK
158 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
161 #ifdef CONFIG_INOTIFY_USER
162 #include <linux/inotify.h>
168 extern int pwrsw_enabled
;
171 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
172 extern int unaligned_enabled
;
176 extern int unaligned_dump_stack
;
179 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
180 extern int no_unaligned_warning
;
183 #ifdef CONFIG_PROC_SYSCTL
186 * enum sysctl_writes_mode - supported sysctl write modes
188 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
189 * to be written, and multiple writes on the same sysctl file descriptor
190 * will rewrite the sysctl value, regardless of file position. No warning
191 * is issued when the initial position is not 0.
192 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
194 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
195 * file position 0 and the value must be fully contained in the buffer
196 * sent to the write syscall. If dealing with strings respect the file
197 * position, but restrict this to the max length of the buffer, anything
198 * passed the max lenght will be ignored. Multiple writes will append
201 * These write modes control how current file position affects the behavior of
202 * updating sysctl values through the proc interface on each write.
204 enum sysctl_writes_mode
{
205 SYSCTL_WRITES_LEGACY
= -1,
206 SYSCTL_WRITES_WARN
= 0,
207 SYSCTL_WRITES_STRICT
= 1,
210 static enum sysctl_writes_mode sysctl_writes_strict
= SYSCTL_WRITES_STRICT
;
212 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
213 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
214 static int proc_taint(struct ctl_table
*table
, int write
,
215 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
219 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
220 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
223 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
224 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
225 #ifdef CONFIG_COREDUMP
226 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
227 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
229 static int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
230 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
231 #ifdef CONFIG_BPF_SYSCALL
232 static int proc_dointvec_minmax_bpf_stats(struct ctl_table
*table
, int write
,
233 void __user
*buffer
, size_t *lenp
,
237 #ifdef CONFIG_MAGIC_SYSRQ
238 /* Note: sysrq code uses its own private copy */
239 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
241 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
242 void __user
*buffer
, size_t *lenp
,
247 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
252 sysrq_toggle_support(__sysrq_enabled
);
259 static struct ctl_table kern_table
[];
260 static struct ctl_table vm_table
[];
261 static struct ctl_table fs_table
[];
262 static struct ctl_table debug_table
[];
263 static struct ctl_table dev_table
[];
264 extern struct ctl_table random_table
[];
266 extern struct ctl_table epoll_table
[];
269 #ifdef CONFIG_FW_LOADER_USER_HELPER
270 extern struct ctl_table firmware_config_table
[];
273 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
274 int sysctl_legacy_va_layout
;
277 /* The default sysctl tables: */
279 static struct ctl_table sysctl_base_table
[] = {
281 .procname
= "kernel",
298 .child
= debug_table
,
308 #ifdef CONFIG_SCHED_DEBUG
309 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
310 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
311 static int min_wakeup_granularity_ns
; /* 0 usecs */
312 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
314 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
315 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
316 #endif /* CONFIG_SMP */
317 #endif /* CONFIG_SCHED_DEBUG */
319 #ifdef CONFIG_COMPACTION
320 static int min_extfrag_threshold
;
321 static int max_extfrag_threshold
= 1000;
324 static struct ctl_table kern_table
[] = {
326 .procname
= "sched_child_runs_first",
327 .data
= &sysctl_sched_child_runs_first
,
328 .maxlen
= sizeof(unsigned int),
330 .proc_handler
= proc_dointvec
,
332 #ifdef CONFIG_SCHED_DEBUG
334 .procname
= "sched_min_granularity_ns",
335 .data
= &sysctl_sched_min_granularity
,
336 .maxlen
= sizeof(unsigned int),
338 .proc_handler
= sched_proc_update_handler
,
339 .extra1
= &min_sched_granularity_ns
,
340 .extra2
= &max_sched_granularity_ns
,
343 .procname
= "sched_latency_ns",
344 .data
= &sysctl_sched_latency
,
345 .maxlen
= sizeof(unsigned int),
347 .proc_handler
= sched_proc_update_handler
,
348 .extra1
= &min_sched_granularity_ns
,
349 .extra2
= &max_sched_granularity_ns
,
352 .procname
= "sched_wakeup_granularity_ns",
353 .data
= &sysctl_sched_wakeup_granularity
,
354 .maxlen
= sizeof(unsigned int),
356 .proc_handler
= sched_proc_update_handler
,
357 .extra1
= &min_wakeup_granularity_ns
,
358 .extra2
= &max_wakeup_granularity_ns
,
362 .procname
= "sched_tunable_scaling",
363 .data
= &sysctl_sched_tunable_scaling
,
364 .maxlen
= sizeof(enum sched_tunable_scaling
),
366 .proc_handler
= sched_proc_update_handler
,
367 .extra1
= &min_sched_tunable_scaling
,
368 .extra2
= &max_sched_tunable_scaling
,
371 .procname
= "sched_migration_cost_ns",
372 .data
= &sysctl_sched_migration_cost
,
373 .maxlen
= sizeof(unsigned int),
375 .proc_handler
= proc_dointvec
,
378 .procname
= "sched_nr_migrate",
379 .data
= &sysctl_sched_nr_migrate
,
380 .maxlen
= sizeof(unsigned int),
382 .proc_handler
= proc_dointvec
,
384 #ifdef CONFIG_SCHEDSTATS
386 .procname
= "sched_schedstats",
388 .maxlen
= sizeof(unsigned int),
390 .proc_handler
= sysctl_schedstats
,
394 #endif /* CONFIG_SCHEDSTATS */
395 #endif /* CONFIG_SMP */
396 #ifdef CONFIG_NUMA_BALANCING
398 .procname
= "numa_balancing_scan_delay_ms",
399 .data
= &sysctl_numa_balancing_scan_delay
,
400 .maxlen
= sizeof(unsigned int),
402 .proc_handler
= proc_dointvec
,
405 .procname
= "numa_balancing_scan_period_min_ms",
406 .data
= &sysctl_numa_balancing_scan_period_min
,
407 .maxlen
= sizeof(unsigned int),
409 .proc_handler
= proc_dointvec
,
412 .procname
= "numa_balancing_scan_period_max_ms",
413 .data
= &sysctl_numa_balancing_scan_period_max
,
414 .maxlen
= sizeof(unsigned int),
416 .proc_handler
= proc_dointvec
,
419 .procname
= "numa_balancing_scan_size_mb",
420 .data
= &sysctl_numa_balancing_scan_size
,
421 .maxlen
= sizeof(unsigned int),
423 .proc_handler
= proc_dointvec_minmax
,
427 .procname
= "numa_balancing",
428 .data
= NULL
, /* filled in by handler */
429 .maxlen
= sizeof(unsigned int),
431 .proc_handler
= sysctl_numa_balancing
,
435 #endif /* CONFIG_NUMA_BALANCING */
436 #endif /* CONFIG_SCHED_DEBUG */
438 .procname
= "sched_rt_period_us",
439 .data
= &sysctl_sched_rt_period
,
440 .maxlen
= sizeof(unsigned int),
442 .proc_handler
= sched_rt_handler
,
445 .procname
= "sched_rt_runtime_us",
446 .data
= &sysctl_sched_rt_runtime
,
447 .maxlen
= sizeof(int),
449 .proc_handler
= sched_rt_handler
,
452 .procname
= "sched_rr_timeslice_ms",
453 .data
= &sysctl_sched_rr_timeslice
,
454 .maxlen
= sizeof(int),
456 .proc_handler
= sched_rr_handler
,
458 #ifdef CONFIG_SCHED_AUTOGROUP
460 .procname
= "sched_autogroup_enabled",
461 .data
= &sysctl_sched_autogroup_enabled
,
462 .maxlen
= sizeof(unsigned int),
464 .proc_handler
= proc_dointvec_minmax
,
469 #ifdef CONFIG_CFS_BANDWIDTH
471 .procname
= "sched_cfs_bandwidth_slice_us",
472 .data
= &sysctl_sched_cfs_bandwidth_slice
,
473 .maxlen
= sizeof(unsigned int),
475 .proc_handler
= proc_dointvec_minmax
,
479 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
481 .procname
= "sched_energy_aware",
482 .data
= &sysctl_sched_energy_aware
,
483 .maxlen
= sizeof(unsigned int),
485 .proc_handler
= sched_energy_aware_handler
,
490 #ifdef CONFIG_PROVE_LOCKING
492 .procname
= "prove_locking",
493 .data
= &prove_locking
,
494 .maxlen
= sizeof(int),
496 .proc_handler
= proc_dointvec
,
499 #ifdef CONFIG_LOCK_STAT
501 .procname
= "lock_stat",
503 .maxlen
= sizeof(int),
505 .proc_handler
= proc_dointvec
,
510 .data
= &panic_timeout
,
511 .maxlen
= sizeof(int),
513 .proc_handler
= proc_dointvec
,
515 #ifdef CONFIG_COREDUMP
517 .procname
= "core_uses_pid",
518 .data
= &core_uses_pid
,
519 .maxlen
= sizeof(int),
521 .proc_handler
= proc_dointvec
,
524 .procname
= "core_pattern",
525 .data
= core_pattern
,
526 .maxlen
= CORENAME_MAX_SIZE
,
528 .proc_handler
= proc_dostring_coredump
,
531 .procname
= "core_pipe_limit",
532 .data
= &core_pipe_limit
,
533 .maxlen
= sizeof(unsigned int),
535 .proc_handler
= proc_dointvec
,
538 #ifdef CONFIG_PROC_SYSCTL
540 .procname
= "tainted",
541 .maxlen
= sizeof(long),
543 .proc_handler
= proc_taint
,
546 .procname
= "sysctl_writes_strict",
547 .data
= &sysctl_writes_strict
,
548 .maxlen
= sizeof(int),
550 .proc_handler
= proc_dointvec_minmax
,
555 #ifdef CONFIG_LATENCYTOP
557 .procname
= "latencytop",
558 .data
= &latencytop_enabled
,
559 .maxlen
= sizeof(int),
561 .proc_handler
= sysctl_latencytop
,
564 #ifdef CONFIG_BLK_DEV_INITRD
566 .procname
= "real-root-dev",
567 .data
= &real_root_dev
,
568 .maxlen
= sizeof(int),
570 .proc_handler
= proc_dointvec
,
574 .procname
= "print-fatal-signals",
575 .data
= &print_fatal_signals
,
576 .maxlen
= sizeof(int),
578 .proc_handler
= proc_dointvec
,
582 .procname
= "reboot-cmd",
583 .data
= reboot_command
,
586 .proc_handler
= proc_dostring
,
589 .procname
= "stop-a",
590 .data
= &stop_a_enabled
,
591 .maxlen
= sizeof (int),
593 .proc_handler
= proc_dointvec
,
596 .procname
= "scons-poweroff",
597 .data
= &scons_pwroff
,
598 .maxlen
= sizeof (int),
600 .proc_handler
= proc_dointvec
,
603 #ifdef CONFIG_SPARC64
605 .procname
= "tsb-ratio",
606 .data
= &sysctl_tsb_ratio
,
607 .maxlen
= sizeof (int),
609 .proc_handler
= proc_dointvec
,
614 .procname
= "soft-power",
615 .data
= &pwrsw_enabled
,
616 .maxlen
= sizeof (int),
618 .proc_handler
= proc_dointvec
,
621 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
623 .procname
= "unaligned-trap",
624 .data
= &unaligned_enabled
,
625 .maxlen
= sizeof (int),
627 .proc_handler
= proc_dointvec
,
631 .procname
= "ctrl-alt-del",
633 .maxlen
= sizeof(int),
635 .proc_handler
= proc_dointvec
,
637 #ifdef CONFIG_FUNCTION_TRACER
639 .procname
= "ftrace_enabled",
640 .data
= &ftrace_enabled
,
641 .maxlen
= sizeof(int),
643 .proc_handler
= ftrace_enable_sysctl
,
646 #ifdef CONFIG_STACK_TRACER
648 .procname
= "stack_tracer_enabled",
649 .data
= &stack_tracer_enabled
,
650 .maxlen
= sizeof(int),
652 .proc_handler
= stack_trace_sysctl
,
655 #ifdef CONFIG_TRACING
657 .procname
= "ftrace_dump_on_oops",
658 .data
= &ftrace_dump_on_oops
,
659 .maxlen
= sizeof(int),
661 .proc_handler
= proc_dointvec
,
664 .procname
= "traceoff_on_warning",
665 .data
= &__disable_trace_on_warning
,
666 .maxlen
= sizeof(__disable_trace_on_warning
),
668 .proc_handler
= proc_dointvec
,
671 .procname
= "tracepoint_printk",
672 .data
= &tracepoint_printk
,
673 .maxlen
= sizeof(tracepoint_printk
),
675 .proc_handler
= tracepoint_printk_sysctl
,
678 #ifdef CONFIG_KEXEC_CORE
680 .procname
= "kexec_load_disabled",
681 .data
= &kexec_load_disabled
,
682 .maxlen
= sizeof(int),
684 /* only handle a transition from default "0" to "1" */
685 .proc_handler
= proc_dointvec_minmax
,
690 #ifdef CONFIG_MODULES
692 .procname
= "modprobe",
693 .data
= &modprobe_path
,
694 .maxlen
= KMOD_PATH_LEN
,
696 .proc_handler
= proc_dostring
,
699 .procname
= "modules_disabled",
700 .data
= &modules_disabled
,
701 .maxlen
= sizeof(int),
703 /* only handle a transition from default "0" to "1" */
704 .proc_handler
= proc_dointvec_minmax
,
709 #ifdef CONFIG_UEVENT_HELPER
711 .procname
= "hotplug",
712 .data
= &uevent_helper
,
713 .maxlen
= UEVENT_HELPER_PATH_LEN
,
715 .proc_handler
= proc_dostring
,
718 #ifdef CONFIG_CHR_DEV_SG
720 .procname
= "sg-big-buff",
721 .data
= &sg_big_buff
,
722 .maxlen
= sizeof (int),
724 .proc_handler
= proc_dointvec
,
727 #ifdef CONFIG_BSD_PROCESS_ACCT
731 .maxlen
= 3*sizeof(int),
733 .proc_handler
= proc_dointvec
,
736 #ifdef CONFIG_MAGIC_SYSRQ
739 .data
= &__sysrq_enabled
,
740 .maxlen
= sizeof (int),
742 .proc_handler
= sysrq_sysctl_handler
,
745 #ifdef CONFIG_PROC_SYSCTL
747 .procname
= "cad_pid",
749 .maxlen
= sizeof (int),
751 .proc_handler
= proc_do_cad_pid
,
755 .procname
= "threads-max",
757 .maxlen
= sizeof(int),
759 .proc_handler
= sysctl_max_threads
,
762 .procname
= "random",
764 .child
= random_table
,
767 .procname
= "usermodehelper",
769 .child
= usermodehelper_table
,
771 #ifdef CONFIG_FW_LOADER_USER_HELPER
773 .procname
= "firmware_config",
775 .child
= firmware_config_table
,
779 .procname
= "overflowuid",
780 .data
= &overflowuid
,
781 .maxlen
= sizeof(int),
783 .proc_handler
= proc_dointvec_minmax
,
784 .extra1
= &minolduid
,
785 .extra2
= &maxolduid
,
788 .procname
= "overflowgid",
789 .data
= &overflowgid
,
790 .maxlen
= sizeof(int),
792 .proc_handler
= proc_dointvec_minmax
,
793 .extra1
= &minolduid
,
794 .extra2
= &maxolduid
,
797 #ifdef CONFIG_MATHEMU
799 .procname
= "ieee_emulation_warnings",
800 .data
= &sysctl_ieee_emulation_warnings
,
801 .maxlen
= sizeof(int),
803 .proc_handler
= proc_dointvec
,
807 .procname
= "userprocess_debug",
808 .data
= &show_unhandled_signals
,
809 .maxlen
= sizeof(int),
811 .proc_handler
= proc_dointvec
,
815 .procname
= "pid_max",
817 .maxlen
= sizeof (int),
819 .proc_handler
= proc_dointvec_minmax
,
820 .extra1
= &pid_max_min
,
821 .extra2
= &pid_max_max
,
824 .procname
= "panic_on_oops",
825 .data
= &panic_on_oops
,
826 .maxlen
= sizeof(int),
828 .proc_handler
= proc_dointvec
,
831 .procname
= "panic_print",
832 .data
= &panic_print
,
833 .maxlen
= sizeof(unsigned long),
835 .proc_handler
= proc_doulongvec_minmax
,
837 #if defined CONFIG_PRINTK
839 .procname
= "printk",
840 .data
= &console_loglevel
,
841 .maxlen
= 4*sizeof(int),
843 .proc_handler
= proc_dointvec
,
846 .procname
= "printk_ratelimit",
847 .data
= &printk_ratelimit_state
.interval
,
848 .maxlen
= sizeof(int),
850 .proc_handler
= proc_dointvec_jiffies
,
853 .procname
= "printk_ratelimit_burst",
854 .data
= &printk_ratelimit_state
.burst
,
855 .maxlen
= sizeof(int),
857 .proc_handler
= proc_dointvec
,
860 .procname
= "printk_delay",
861 .data
= &printk_delay_msec
,
862 .maxlen
= sizeof(int),
864 .proc_handler
= proc_dointvec_minmax
,
866 .extra2
= &ten_thousand
,
869 .procname
= "printk_devkmsg",
870 .data
= devkmsg_log_str
,
871 .maxlen
= DEVKMSG_STR_MAX_SIZE
,
873 .proc_handler
= devkmsg_sysctl_set_loglvl
,
876 .procname
= "dmesg_restrict",
877 .data
= &dmesg_restrict
,
878 .maxlen
= sizeof(int),
880 .proc_handler
= proc_dointvec_minmax_sysadmin
,
885 .procname
= "kptr_restrict",
886 .data
= &kptr_restrict
,
887 .maxlen
= sizeof(int),
889 .proc_handler
= proc_dointvec_minmax_sysadmin
,
895 .procname
= "ngroups_max",
896 .data
= &ngroups_max
,
897 .maxlen
= sizeof (int),
899 .proc_handler
= proc_dointvec
,
902 .procname
= "cap_last_cap",
903 .data
= (void *)&cap_last_cap
,
904 .maxlen
= sizeof(int),
906 .proc_handler
= proc_dointvec
,
908 #if defined(CONFIG_LOCKUP_DETECTOR)
910 .procname
= "watchdog",
911 .data
= &watchdog_user_enabled
,
912 .maxlen
= sizeof(int),
914 .proc_handler
= proc_watchdog
,
919 .procname
= "watchdog_thresh",
920 .data
= &watchdog_thresh
,
921 .maxlen
= sizeof(int),
923 .proc_handler
= proc_watchdog_thresh
,
928 .procname
= "nmi_watchdog",
929 .data
= &nmi_watchdog_user_enabled
,
930 .maxlen
= sizeof(int),
931 .mode
= NMI_WATCHDOG_SYSCTL_PERM
,
932 .proc_handler
= proc_nmi_watchdog
,
937 .procname
= "watchdog_cpumask",
938 .data
= &watchdog_cpumask_bits
,
941 .proc_handler
= proc_watchdog_cpumask
,
943 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
945 .procname
= "soft_watchdog",
946 .data
= &soft_watchdog_user_enabled
,
947 .maxlen
= sizeof(int),
949 .proc_handler
= proc_soft_watchdog
,
954 .procname
= "softlockup_panic",
955 .data
= &softlockup_panic
,
956 .maxlen
= sizeof(int),
958 .proc_handler
= proc_dointvec_minmax
,
964 .procname
= "softlockup_all_cpu_backtrace",
965 .data
= &sysctl_softlockup_all_cpu_backtrace
,
966 .maxlen
= sizeof(int),
968 .proc_handler
= proc_dointvec_minmax
,
972 #endif /* CONFIG_SMP */
974 #ifdef CONFIG_HARDLOCKUP_DETECTOR
976 .procname
= "hardlockup_panic",
977 .data
= &hardlockup_panic
,
978 .maxlen
= sizeof(int),
980 .proc_handler
= proc_dointvec_minmax
,
986 .procname
= "hardlockup_all_cpu_backtrace",
987 .data
= &sysctl_hardlockup_all_cpu_backtrace
,
988 .maxlen
= sizeof(int),
990 .proc_handler
= proc_dointvec_minmax
,
994 #endif /* CONFIG_SMP */
998 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1000 .procname
= "unknown_nmi_panic",
1001 .data
= &unknown_nmi_panic
,
1002 .maxlen
= sizeof (int),
1004 .proc_handler
= proc_dointvec
,
1007 #if defined(CONFIG_X86)
1009 .procname
= "panic_on_unrecovered_nmi",
1010 .data
= &panic_on_unrecovered_nmi
,
1011 .maxlen
= sizeof(int),
1013 .proc_handler
= proc_dointvec
,
1016 .procname
= "panic_on_io_nmi",
1017 .data
= &panic_on_io_nmi
,
1018 .maxlen
= sizeof(int),
1020 .proc_handler
= proc_dointvec
,
1022 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1024 .procname
= "panic_on_stackoverflow",
1025 .data
= &sysctl_panic_on_stackoverflow
,
1026 .maxlen
= sizeof(int),
1028 .proc_handler
= proc_dointvec
,
1032 .procname
= "bootloader_type",
1033 .data
= &bootloader_type
,
1034 .maxlen
= sizeof (int),
1036 .proc_handler
= proc_dointvec
,
1039 .procname
= "bootloader_version",
1040 .data
= &bootloader_version
,
1041 .maxlen
= sizeof (int),
1043 .proc_handler
= proc_dointvec
,
1046 .procname
= "io_delay_type",
1047 .data
= &io_delay_type
,
1048 .maxlen
= sizeof(int),
1050 .proc_handler
= proc_dointvec
,
1053 #if defined(CONFIG_MMU)
1055 .procname
= "randomize_va_space",
1056 .data
= &randomize_va_space
,
1057 .maxlen
= sizeof(int),
1059 .proc_handler
= proc_dointvec
,
1062 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1064 .procname
= "spin_retry",
1065 .data
= &spin_retry
,
1066 .maxlen
= sizeof (int),
1068 .proc_handler
= proc_dointvec
,
1071 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1073 .procname
= "acpi_video_flags",
1074 .data
= &acpi_realmode_flags
,
1075 .maxlen
= sizeof (unsigned long),
1077 .proc_handler
= proc_doulongvec_minmax
,
1080 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1082 .procname
= "ignore-unaligned-usertrap",
1083 .data
= &no_unaligned_warning
,
1084 .maxlen
= sizeof (int),
1086 .proc_handler
= proc_dointvec
,
1091 .procname
= "unaligned-dump-stack",
1092 .data
= &unaligned_dump_stack
,
1093 .maxlen
= sizeof (int),
1095 .proc_handler
= proc_dointvec
,
1098 #ifdef CONFIG_DETECT_HUNG_TASK
1100 .procname
= "hung_task_panic",
1101 .data
= &sysctl_hung_task_panic
,
1102 .maxlen
= sizeof(int),
1104 .proc_handler
= proc_dointvec_minmax
,
1109 .procname
= "hung_task_check_count",
1110 .data
= &sysctl_hung_task_check_count
,
1111 .maxlen
= sizeof(int),
1113 .proc_handler
= proc_dointvec_minmax
,
1117 .procname
= "hung_task_timeout_secs",
1118 .data
= &sysctl_hung_task_timeout_secs
,
1119 .maxlen
= sizeof(unsigned long),
1121 .proc_handler
= proc_dohung_task_timeout_secs
,
1122 .extra2
= &hung_task_timeout_max
,
1125 .procname
= "hung_task_check_interval_secs",
1126 .data
= &sysctl_hung_task_check_interval_secs
,
1127 .maxlen
= sizeof(unsigned long),
1129 .proc_handler
= proc_dohung_task_timeout_secs
,
1130 .extra2
= &hung_task_timeout_max
,
1133 .procname
= "hung_task_warnings",
1134 .data
= &sysctl_hung_task_warnings
,
1135 .maxlen
= sizeof(int),
1137 .proc_handler
= proc_dointvec_minmax
,
1141 #ifdef CONFIG_RT_MUTEXES
1143 .procname
= "max_lock_depth",
1144 .data
= &max_lock_depth
,
1145 .maxlen
= sizeof(int),
1147 .proc_handler
= proc_dointvec
,
1151 .procname
= "poweroff_cmd",
1152 .data
= &poweroff_cmd
,
1153 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1155 .proc_handler
= proc_dostring
,
1161 .child
= key_sysctls
,
1164 #ifdef CONFIG_PERF_EVENTS
1166 * User-space scripts rely on the existence of this file
1167 * as a feature check for perf_events being enabled.
1169 * So it's an ABI, do not remove!
1172 .procname
= "perf_event_paranoid",
1173 .data
= &sysctl_perf_event_paranoid
,
1174 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1176 .proc_handler
= proc_dointvec
,
1179 .procname
= "perf_event_mlock_kb",
1180 .data
= &sysctl_perf_event_mlock
,
1181 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1183 .proc_handler
= proc_dointvec
,
1186 .procname
= "perf_event_max_sample_rate",
1187 .data
= &sysctl_perf_event_sample_rate
,
1188 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1190 .proc_handler
= perf_proc_update_handler
,
1194 .procname
= "perf_cpu_time_max_percent",
1195 .data
= &sysctl_perf_cpu_time_max_percent
,
1196 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1198 .proc_handler
= perf_cpu_time_max_percent_handler
,
1200 .extra2
= &one_hundred
,
1203 .procname
= "perf_event_max_stack",
1204 .data
= &sysctl_perf_event_max_stack
,
1205 .maxlen
= sizeof(sysctl_perf_event_max_stack
),
1207 .proc_handler
= perf_event_max_stack_handler
,
1209 .extra2
= &six_hundred_forty_kb
,
1212 .procname
= "perf_event_max_contexts_per_stack",
1213 .data
= &sysctl_perf_event_max_contexts_per_stack
,
1214 .maxlen
= sizeof(sysctl_perf_event_max_contexts_per_stack
),
1216 .proc_handler
= perf_event_max_stack_handler
,
1218 .extra2
= &one_thousand
,
1222 .procname
= "panic_on_warn",
1223 .data
= &panic_on_warn
,
1224 .maxlen
= sizeof(int),
1226 .proc_handler
= proc_dointvec_minmax
,
1230 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1232 .procname
= "timer_migration",
1233 .data
= &sysctl_timer_migration
,
1234 .maxlen
= sizeof(unsigned int),
1236 .proc_handler
= timer_migration_handler
,
1241 #ifdef CONFIG_BPF_SYSCALL
1243 .procname
= "unprivileged_bpf_disabled",
1244 .data
= &sysctl_unprivileged_bpf_disabled
,
1245 .maxlen
= sizeof(sysctl_unprivileged_bpf_disabled
),
1247 /* only handle a transition from default "0" to "1" */
1248 .proc_handler
= proc_dointvec_minmax
,
1253 .procname
= "bpf_stats_enabled",
1254 .data
= &sysctl_bpf_stats_enabled
,
1255 .maxlen
= sizeof(sysctl_bpf_stats_enabled
),
1257 .proc_handler
= proc_dointvec_minmax_bpf_stats
,
1262 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1264 .procname
= "panic_on_rcu_stall",
1265 .data
= &sysctl_panic_on_rcu_stall
,
1266 .maxlen
= sizeof(sysctl_panic_on_rcu_stall
),
1268 .proc_handler
= proc_dointvec_minmax
,
1273 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1275 .procname
= "stack_erasing",
1277 .maxlen
= sizeof(int),
1279 .proc_handler
= stack_erasing_sysctl
,
1287 static struct ctl_table vm_table
[] = {
1289 .procname
= "overcommit_memory",
1290 .data
= &sysctl_overcommit_memory
,
1291 .maxlen
= sizeof(sysctl_overcommit_memory
),
1293 .proc_handler
= proc_dointvec_minmax
,
1298 .procname
= "panic_on_oom",
1299 .data
= &sysctl_panic_on_oom
,
1300 .maxlen
= sizeof(sysctl_panic_on_oom
),
1302 .proc_handler
= proc_dointvec_minmax
,
1307 .procname
= "oom_kill_allocating_task",
1308 .data
= &sysctl_oom_kill_allocating_task
,
1309 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1311 .proc_handler
= proc_dointvec
,
1314 .procname
= "oom_dump_tasks",
1315 .data
= &sysctl_oom_dump_tasks
,
1316 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1318 .proc_handler
= proc_dointvec
,
1321 .procname
= "overcommit_ratio",
1322 .data
= &sysctl_overcommit_ratio
,
1323 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1325 .proc_handler
= overcommit_ratio_handler
,
1328 .procname
= "overcommit_kbytes",
1329 .data
= &sysctl_overcommit_kbytes
,
1330 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1332 .proc_handler
= overcommit_kbytes_handler
,
1335 .procname
= "page-cluster",
1336 .data
= &page_cluster
,
1337 .maxlen
= sizeof(int),
1339 .proc_handler
= proc_dointvec_minmax
,
1343 .procname
= "dirty_background_ratio",
1344 .data
= &dirty_background_ratio
,
1345 .maxlen
= sizeof(dirty_background_ratio
),
1347 .proc_handler
= dirty_background_ratio_handler
,
1349 .extra2
= &one_hundred
,
1352 .procname
= "dirty_background_bytes",
1353 .data
= &dirty_background_bytes
,
1354 .maxlen
= sizeof(dirty_background_bytes
),
1356 .proc_handler
= dirty_background_bytes_handler
,
1360 .procname
= "dirty_ratio",
1361 .data
= &vm_dirty_ratio
,
1362 .maxlen
= sizeof(vm_dirty_ratio
),
1364 .proc_handler
= dirty_ratio_handler
,
1366 .extra2
= &one_hundred
,
1369 .procname
= "dirty_bytes",
1370 .data
= &vm_dirty_bytes
,
1371 .maxlen
= sizeof(vm_dirty_bytes
),
1373 .proc_handler
= dirty_bytes_handler
,
1374 .extra1
= &dirty_bytes_min
,
1377 .procname
= "dirty_writeback_centisecs",
1378 .data
= &dirty_writeback_interval
,
1379 .maxlen
= sizeof(dirty_writeback_interval
),
1381 .proc_handler
= dirty_writeback_centisecs_handler
,
1384 .procname
= "dirty_expire_centisecs",
1385 .data
= &dirty_expire_interval
,
1386 .maxlen
= sizeof(dirty_expire_interval
),
1388 .proc_handler
= proc_dointvec_minmax
,
1392 .procname
= "dirtytime_expire_seconds",
1393 .data
= &dirtytime_expire_interval
,
1394 .maxlen
= sizeof(dirtytime_expire_interval
),
1396 .proc_handler
= dirtytime_interval_handler
,
1400 .procname
= "swappiness",
1401 .data
= &vm_swappiness
,
1402 .maxlen
= sizeof(vm_swappiness
),
1404 .proc_handler
= proc_dointvec_minmax
,
1406 .extra2
= &one_hundred
,
1408 #ifdef CONFIG_HUGETLB_PAGE
1410 .procname
= "nr_hugepages",
1412 .maxlen
= sizeof(unsigned long),
1414 .proc_handler
= hugetlb_sysctl_handler
,
1418 .procname
= "nr_hugepages_mempolicy",
1420 .maxlen
= sizeof(unsigned long),
1422 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1425 .procname
= "numa_stat",
1426 .data
= &sysctl_vm_numa_stat
,
1427 .maxlen
= sizeof(int),
1429 .proc_handler
= sysctl_vm_numa_stat_handler
,
1435 .procname
= "hugetlb_shm_group",
1436 .data
= &sysctl_hugetlb_shm_group
,
1437 .maxlen
= sizeof(gid_t
),
1439 .proc_handler
= proc_dointvec
,
1442 .procname
= "nr_overcommit_hugepages",
1444 .maxlen
= sizeof(unsigned long),
1446 .proc_handler
= hugetlb_overcommit_handler
,
1450 .procname
= "lowmem_reserve_ratio",
1451 .data
= &sysctl_lowmem_reserve_ratio
,
1452 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1454 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1457 .procname
= "drop_caches",
1458 .data
= &sysctl_drop_caches
,
1459 .maxlen
= sizeof(int),
1461 .proc_handler
= drop_caches_sysctl_handler
,
1465 #ifdef CONFIG_COMPACTION
1467 .procname
= "compact_memory",
1468 .data
= &sysctl_compact_memory
,
1469 .maxlen
= sizeof(int),
1471 .proc_handler
= sysctl_compaction_handler
,
1474 .procname
= "extfrag_threshold",
1475 .data
= &sysctl_extfrag_threshold
,
1476 .maxlen
= sizeof(int),
1478 .proc_handler
= proc_dointvec_minmax
,
1479 .extra1
= &min_extfrag_threshold
,
1480 .extra2
= &max_extfrag_threshold
,
1483 .procname
= "compact_unevictable_allowed",
1484 .data
= &sysctl_compact_unevictable_allowed
,
1485 .maxlen
= sizeof(int),
1487 .proc_handler
= proc_dointvec
,
1492 #endif /* CONFIG_COMPACTION */
1494 .procname
= "min_free_kbytes",
1495 .data
= &min_free_kbytes
,
1496 .maxlen
= sizeof(min_free_kbytes
),
1498 .proc_handler
= min_free_kbytes_sysctl_handler
,
1502 .procname
= "watermark_boost_factor",
1503 .data
= &watermark_boost_factor
,
1504 .maxlen
= sizeof(watermark_boost_factor
),
1506 .proc_handler
= watermark_boost_factor_sysctl_handler
,
1510 .procname
= "watermark_scale_factor",
1511 .data
= &watermark_scale_factor
,
1512 .maxlen
= sizeof(watermark_scale_factor
),
1514 .proc_handler
= watermark_scale_factor_sysctl_handler
,
1516 .extra2
= &one_thousand
,
1519 .procname
= "percpu_pagelist_fraction",
1520 .data
= &percpu_pagelist_fraction
,
1521 .maxlen
= sizeof(percpu_pagelist_fraction
),
1523 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1528 .procname
= "max_map_count",
1529 .data
= &sysctl_max_map_count
,
1530 .maxlen
= sizeof(sysctl_max_map_count
),
1532 .proc_handler
= proc_dointvec_minmax
,
1537 .procname
= "nr_trim_pages",
1538 .data
= &sysctl_nr_trim_pages
,
1539 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1541 .proc_handler
= proc_dointvec_minmax
,
1546 .procname
= "laptop_mode",
1547 .data
= &laptop_mode
,
1548 .maxlen
= sizeof(laptop_mode
),
1550 .proc_handler
= proc_dointvec_jiffies
,
1553 .procname
= "block_dump",
1554 .data
= &block_dump
,
1555 .maxlen
= sizeof(block_dump
),
1557 .proc_handler
= proc_dointvec
,
1561 .procname
= "vfs_cache_pressure",
1562 .data
= &sysctl_vfs_cache_pressure
,
1563 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1565 .proc_handler
= proc_dointvec
,
1568 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1570 .procname
= "legacy_va_layout",
1571 .data
= &sysctl_legacy_va_layout
,
1572 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1574 .proc_handler
= proc_dointvec
,
1580 .procname
= "zone_reclaim_mode",
1581 .data
= &node_reclaim_mode
,
1582 .maxlen
= sizeof(node_reclaim_mode
),
1584 .proc_handler
= proc_dointvec
,
1588 .procname
= "min_unmapped_ratio",
1589 .data
= &sysctl_min_unmapped_ratio
,
1590 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1592 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1594 .extra2
= &one_hundred
,
1597 .procname
= "min_slab_ratio",
1598 .data
= &sysctl_min_slab_ratio
,
1599 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1601 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1603 .extra2
= &one_hundred
,
1608 .procname
= "stat_interval",
1609 .data
= &sysctl_stat_interval
,
1610 .maxlen
= sizeof(sysctl_stat_interval
),
1612 .proc_handler
= proc_dointvec_jiffies
,
1615 .procname
= "stat_refresh",
1619 .proc_handler
= vmstat_refresh
,
1624 .procname
= "mmap_min_addr",
1625 .data
= &dac_mmap_min_addr
,
1626 .maxlen
= sizeof(unsigned long),
1628 .proc_handler
= mmap_min_addr_handler
,
1633 .procname
= "numa_zonelist_order",
1634 .data
= &numa_zonelist_order
,
1635 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1637 .proc_handler
= numa_zonelist_order_handler
,
1640 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1641 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1643 .procname
= "vdso_enabled",
1644 #ifdef CONFIG_X86_32
1645 .data
= &vdso32_enabled
,
1646 .maxlen
= sizeof(vdso32_enabled
),
1648 .data
= &vdso_enabled
,
1649 .maxlen
= sizeof(vdso_enabled
),
1652 .proc_handler
= proc_dointvec
,
1656 #ifdef CONFIG_HIGHMEM
1658 .procname
= "highmem_is_dirtyable",
1659 .data
= &vm_highmem_is_dirtyable
,
1660 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1662 .proc_handler
= proc_dointvec_minmax
,
1667 #ifdef CONFIG_MEMORY_FAILURE
1669 .procname
= "memory_failure_early_kill",
1670 .data
= &sysctl_memory_failure_early_kill
,
1671 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1673 .proc_handler
= proc_dointvec_minmax
,
1678 .procname
= "memory_failure_recovery",
1679 .data
= &sysctl_memory_failure_recovery
,
1680 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1682 .proc_handler
= proc_dointvec_minmax
,
1688 .procname
= "user_reserve_kbytes",
1689 .data
= &sysctl_user_reserve_kbytes
,
1690 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1692 .proc_handler
= proc_doulongvec_minmax
,
1695 .procname
= "admin_reserve_kbytes",
1696 .data
= &sysctl_admin_reserve_kbytes
,
1697 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1699 .proc_handler
= proc_doulongvec_minmax
,
1701 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1703 .procname
= "mmap_rnd_bits",
1704 .data
= &mmap_rnd_bits
,
1705 .maxlen
= sizeof(mmap_rnd_bits
),
1707 .proc_handler
= proc_dointvec_minmax
,
1708 .extra1
= (void *)&mmap_rnd_bits_min
,
1709 .extra2
= (void *)&mmap_rnd_bits_max
,
1712 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1714 .procname
= "mmap_rnd_compat_bits",
1715 .data
= &mmap_rnd_compat_bits
,
1716 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1718 .proc_handler
= proc_dointvec_minmax
,
1719 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1720 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1726 static struct ctl_table fs_table
[] = {
1728 .procname
= "inode-nr",
1729 .data
= &inodes_stat
,
1730 .maxlen
= 2*sizeof(long),
1732 .proc_handler
= proc_nr_inodes
,
1735 .procname
= "inode-state",
1736 .data
= &inodes_stat
,
1737 .maxlen
= 7*sizeof(long),
1739 .proc_handler
= proc_nr_inodes
,
1742 .procname
= "file-nr",
1743 .data
= &files_stat
,
1744 .maxlen
= sizeof(files_stat
),
1746 .proc_handler
= proc_nr_files
,
1749 .procname
= "file-max",
1750 .data
= &files_stat
.max_files
,
1751 .maxlen
= sizeof(files_stat
.max_files
),
1753 .proc_handler
= proc_doulongvec_minmax
,
1755 .extra2
= &long_max
,
1758 .procname
= "nr_open",
1759 .data
= &sysctl_nr_open
,
1760 .maxlen
= sizeof(unsigned int),
1762 .proc_handler
= proc_dointvec_minmax
,
1763 .extra1
= &sysctl_nr_open_min
,
1764 .extra2
= &sysctl_nr_open_max
,
1767 .procname
= "dentry-state",
1768 .data
= &dentry_stat
,
1769 .maxlen
= 6*sizeof(long),
1771 .proc_handler
= proc_nr_dentry
,
1774 .procname
= "overflowuid",
1775 .data
= &fs_overflowuid
,
1776 .maxlen
= sizeof(int),
1778 .proc_handler
= proc_dointvec_minmax
,
1779 .extra1
= &minolduid
,
1780 .extra2
= &maxolduid
,
1783 .procname
= "overflowgid",
1784 .data
= &fs_overflowgid
,
1785 .maxlen
= sizeof(int),
1787 .proc_handler
= proc_dointvec_minmax
,
1788 .extra1
= &minolduid
,
1789 .extra2
= &maxolduid
,
1791 #ifdef CONFIG_FILE_LOCKING
1793 .procname
= "leases-enable",
1794 .data
= &leases_enable
,
1795 .maxlen
= sizeof(int),
1797 .proc_handler
= proc_dointvec
,
1800 #ifdef CONFIG_DNOTIFY
1802 .procname
= "dir-notify-enable",
1803 .data
= &dir_notify_enable
,
1804 .maxlen
= sizeof(int),
1806 .proc_handler
= proc_dointvec
,
1810 #ifdef CONFIG_FILE_LOCKING
1812 .procname
= "lease-break-time",
1813 .data
= &lease_break_time
,
1814 .maxlen
= sizeof(int),
1816 .proc_handler
= proc_dointvec
,
1821 .procname
= "aio-nr",
1823 .maxlen
= sizeof(aio_nr
),
1825 .proc_handler
= proc_doulongvec_minmax
,
1828 .procname
= "aio-max-nr",
1829 .data
= &aio_max_nr
,
1830 .maxlen
= sizeof(aio_max_nr
),
1832 .proc_handler
= proc_doulongvec_minmax
,
1834 #endif /* CONFIG_AIO */
1835 #ifdef CONFIG_INOTIFY_USER
1837 .procname
= "inotify",
1839 .child
= inotify_table
,
1844 .procname
= "epoll",
1846 .child
= epoll_table
,
1851 .procname
= "protected_symlinks",
1852 .data
= &sysctl_protected_symlinks
,
1853 .maxlen
= sizeof(int),
1855 .proc_handler
= proc_dointvec_minmax
,
1860 .procname
= "protected_hardlinks",
1861 .data
= &sysctl_protected_hardlinks
,
1862 .maxlen
= sizeof(int),
1864 .proc_handler
= proc_dointvec_minmax
,
1869 .procname
= "protected_fifos",
1870 .data
= &sysctl_protected_fifos
,
1871 .maxlen
= sizeof(int),
1873 .proc_handler
= proc_dointvec_minmax
,
1878 .procname
= "protected_regular",
1879 .data
= &sysctl_protected_regular
,
1880 .maxlen
= sizeof(int),
1882 .proc_handler
= proc_dointvec_minmax
,
1887 .procname
= "suid_dumpable",
1888 .data
= &suid_dumpable
,
1889 .maxlen
= sizeof(int),
1891 .proc_handler
= proc_dointvec_minmax_coredump
,
1895 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1897 .procname
= "binfmt_misc",
1899 .child
= sysctl_mount_point
,
1903 .procname
= "pipe-max-size",
1904 .data
= &pipe_max_size
,
1905 .maxlen
= sizeof(pipe_max_size
),
1907 .proc_handler
= proc_dopipe_max_size
,
1910 .procname
= "pipe-user-pages-hard",
1911 .data
= &pipe_user_pages_hard
,
1912 .maxlen
= sizeof(pipe_user_pages_hard
),
1914 .proc_handler
= proc_doulongvec_minmax
,
1917 .procname
= "pipe-user-pages-soft",
1918 .data
= &pipe_user_pages_soft
,
1919 .maxlen
= sizeof(pipe_user_pages_soft
),
1921 .proc_handler
= proc_doulongvec_minmax
,
1924 .procname
= "mount-max",
1925 .data
= &sysctl_mount_max
,
1926 .maxlen
= sizeof(unsigned int),
1928 .proc_handler
= proc_dointvec_minmax
,
1934 static struct ctl_table debug_table
[] = {
1935 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1937 .procname
= "exception-trace",
1938 .data
= &show_unhandled_signals
,
1939 .maxlen
= sizeof(int),
1941 .proc_handler
= proc_dointvec
1944 #if defined(CONFIG_OPTPROBES)
1946 .procname
= "kprobes-optimization",
1947 .data
= &sysctl_kprobes_optimization
,
1948 .maxlen
= sizeof(int),
1950 .proc_handler
= proc_kprobes_optimization_handler
,
1958 static struct ctl_table dev_table
[] = {
1962 int __init
sysctl_init(void)
1964 struct ctl_table_header
*hdr
;
1966 hdr
= register_sysctl_table(sysctl_base_table
);
1967 kmemleak_not_leak(hdr
);
1971 #endif /* CONFIG_SYSCTL */
1977 #ifdef CONFIG_PROC_SYSCTL
1979 static int _proc_do_string(char *data
, int maxlen
, int write
,
1980 char __user
*buffer
,
1981 size_t *lenp
, loff_t
*ppos
)
1987 if (!data
|| !maxlen
|| !*lenp
) {
1993 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1994 /* Only continue writes not past the end of buffer. */
1996 if (len
> maxlen
- 1)
2003 /* Start writing from beginning of buffer. */
2009 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
2010 if (get_user(c
, p
++))
2012 if (c
== 0 || c
== '\n')
2033 if (copy_to_user(buffer
, data
, len
))
2036 if (put_user('\n', buffer
+ len
))
2046 static void warn_sysctl_write(struct ctl_table
*table
)
2048 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2049 "This will not be supported in the future. To silence this\n"
2050 "warning, set kernel.sysctl_writes_strict = -1\n",
2051 current
->comm
, table
->procname
);
2055 * proc_first_pos_non_zero_ignore - check if first position is allowed
2056 * @ppos: file position
2057 * @table: the sysctl table
2059 * Returns true if the first position is non-zero and the sysctl_writes_strict
2060 * mode indicates this is not allowed for numeric input types. String proc
2061 * handlers can ignore the return value.
2063 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
2064 struct ctl_table
*table
)
2069 switch (sysctl_writes_strict
) {
2070 case SYSCTL_WRITES_STRICT
:
2072 case SYSCTL_WRITES_WARN
:
2073 warn_sysctl_write(table
);
2081 * proc_dostring - read a string sysctl
2082 * @table: the sysctl table
2083 * @write: %TRUE if this is a write to the sysctl file
2084 * @buffer: the user buffer
2085 * @lenp: the size of the user buffer
2086 * @ppos: file position
2088 * Reads/writes a string from/to the user buffer. If the kernel
2089 * buffer provided is not large enough to hold the string, the
2090 * string is truncated. The copied string is %NULL-terminated.
2091 * If the string is being read by the user process, it is copied
2092 * and a newline '\n' is added. It is truncated if the buffer is
2095 * Returns 0 on success.
2097 int proc_dostring(struct ctl_table
*table
, int write
,
2098 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2101 proc_first_pos_non_zero_ignore(ppos
, table
);
2103 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2104 (char __user
*)buffer
, lenp
, ppos
);
2107 static size_t proc_skip_spaces(char **buf
)
2110 char *tmp
= skip_spaces(*buf
);
2116 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2127 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2130 * @cp: kernel buffer containing the string to parse
2131 * @endp: pointer to store the trailing characters
2132 * @base: the base to use
2133 * @res: where the parsed integer will be stored
2135 * In case of success 0 is returned and @res will contain the parsed integer,
2136 * @endp will hold any trailing characters.
2137 * This function will fail the parse on overflow. If there wasn't an overflow
2138 * the function will defer the decision what characters count as invalid to the
2141 static int strtoul_lenient(const char *cp
, char **endp
, unsigned int base
,
2144 unsigned long long result
;
2147 cp
= _parse_integer_fixup_radix(cp
, &base
);
2148 rv
= _parse_integer(cp
, base
, &result
);
2149 if ((rv
& KSTRTOX_OVERFLOW
) || (result
!= (unsigned long)result
))
2157 *res
= (unsigned long)result
;
2161 #define TMPBUFLEN 22
2163 * proc_get_long - reads an ASCII formatted integer from a user buffer
2165 * @buf: a kernel buffer
2166 * @size: size of the kernel buffer
2167 * @val: this is where the number will be stored
2168 * @neg: set to %TRUE if number is negative
2169 * @perm_tr: a vector which contains the allowed trailers
2170 * @perm_tr_len: size of the perm_tr vector
2171 * @tr: pointer to store the trailer character
2173 * In case of success %0 is returned and @buf and @size are updated with
2174 * the amount of bytes read. If @tr is non-NULL and a trailing
2175 * character exists (size is non-zero after returning from this
2176 * function), @tr is updated with the trailing character.
2178 static int proc_get_long(char **buf
, size_t *size
,
2179 unsigned long *val
, bool *neg
,
2180 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2183 char *p
, tmp
[TMPBUFLEN
];
2189 if (len
> TMPBUFLEN
- 1)
2190 len
= TMPBUFLEN
- 1;
2192 memcpy(tmp
, *buf
, len
);
2196 if (*p
== '-' && *size
> 1) {
2204 if (strtoul_lenient(p
, &p
, 0, val
))
2209 /* We don't know if the next char is whitespace thus we may accept
2210 * invalid integers (e.g. 1234...a) or two integers instead of one
2211 * (e.g. 123...1). So lets not allow such large numbers. */
2212 if (len
== TMPBUFLEN
- 1)
2215 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2218 if (tr
&& (len
< *size
))
2228 * proc_put_long - converts an integer to a decimal ASCII formatted string
2230 * @buf: the user buffer
2231 * @size: the size of the user buffer
2232 * @val: the integer to be converted
2233 * @neg: sign of the number, %TRUE for negative
2235 * In case of success %0 is returned and @buf and @size are updated with
2236 * the amount of bytes written.
2238 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2242 char tmp
[TMPBUFLEN
], *p
= tmp
;
2244 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2248 if (copy_to_user(*buf
, tmp
, len
))
2256 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2259 char __user
**buffer
= (char __user
**)buf
;
2260 if (put_user(c
, *buffer
))
2262 (*size
)--, (*buffer
)++;
2268 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2270 int write
, void *data
)
2274 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2278 if (*lvalp
> (unsigned long) INT_MAX
)
2286 *lvalp
= -(unsigned long)val
;
2289 *lvalp
= (unsigned long)val
;
2295 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2297 int write
, void *data
)
2300 if (*lvalp
> UINT_MAX
)
2304 unsigned int val
= *valp
;
2305 *lvalp
= (unsigned long)val
;
2310 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2312 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2313 int write
, void __user
*buffer
,
2314 size_t *lenp
, loff_t
*ppos
,
2315 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2316 int write
, void *data
),
2319 int *i
, vleft
, first
= 1, err
= 0;
2321 char *kbuf
= NULL
, *p
;
2323 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2328 i
= (int *) tbl_data
;
2329 vleft
= table
->maxlen
/ sizeof(*i
);
2333 conv
= do_proc_dointvec_conv
;
2336 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2339 if (left
> PAGE_SIZE
- 1)
2340 left
= PAGE_SIZE
- 1;
2341 p
= kbuf
= memdup_user_nul(buffer
, left
);
2343 return PTR_ERR(kbuf
);
2346 for (; left
&& vleft
--; i
++, first
=0) {
2351 left
-= proc_skip_spaces(&p
);
2355 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2357 sizeof(proc_wspace_sep
), NULL
);
2360 if (conv(&neg
, &lval
, i
, 1, data
)) {
2365 if (conv(&neg
, &lval
, i
, 0, data
)) {
2370 err
= proc_put_char(&buffer
, &left
, '\t');
2373 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2379 if (!write
&& !first
&& left
&& !err
)
2380 err
= proc_put_char(&buffer
, &left
, '\n');
2381 if (write
&& !err
&& left
)
2382 left
-= proc_skip_spaces(&p
);
2386 return err
? : -EINVAL
;
2394 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2395 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2396 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2397 int write
, void *data
),
2400 return __do_proc_dointvec(table
->data
, table
, write
,
2401 buffer
, lenp
, ppos
, conv
, data
);
2404 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2405 struct ctl_table
*table
,
2406 void __user
*buffer
,
2407 size_t *lenp
, loff_t
*ppos
,
2408 int (*conv
)(unsigned long *lvalp
,
2410 int write
, void *data
),
2417 char *kbuf
= NULL
, *p
;
2421 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2424 if (left
> PAGE_SIZE
- 1)
2425 left
= PAGE_SIZE
- 1;
2427 p
= kbuf
= memdup_user_nul(buffer
, left
);
2431 left
-= proc_skip_spaces(&p
);
2437 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2439 sizeof(proc_wspace_sep
), NULL
);
2445 if (conv(&lval
, tbl_data
, 1, data
)) {
2451 left
-= proc_skip_spaces(&p
);
2460 /* This is in keeping with old __do_proc_dointvec() */
2466 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2467 size_t *lenp
, loff_t
*ppos
,
2468 int (*conv
)(unsigned long *lvalp
,
2470 int write
, void *data
),
2479 if (conv(&lval
, tbl_data
, 0, data
)) {
2484 err
= proc_put_long(&buffer
, &left
, lval
, false);
2488 err
= proc_put_char(&buffer
, &left
, '\n');
2497 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2498 int write
, void __user
*buffer
,
2499 size_t *lenp
, loff_t
*ppos
,
2500 int (*conv
)(unsigned long *lvalp
,
2502 int write
, void *data
),
2505 unsigned int *i
, vleft
;
2507 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2512 i
= (unsigned int *) tbl_data
;
2513 vleft
= table
->maxlen
/ sizeof(*i
);
2516 * Arrays are not supported, keep this simple. *Do not* add
2525 conv
= do_proc_douintvec_conv
;
2528 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2530 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2533 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2534 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2535 int (*conv
)(unsigned long *lvalp
,
2537 int write
, void *data
),
2540 return __do_proc_douintvec(table
->data
, table
, write
,
2541 buffer
, lenp
, ppos
, conv
, data
);
2545 * proc_dointvec - read a vector of integers
2546 * @table: the sysctl table
2547 * @write: %TRUE if this is a write to the sysctl file
2548 * @buffer: the user buffer
2549 * @lenp: the size of the user buffer
2550 * @ppos: file position
2552 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2553 * values from/to the user buffer, treated as an ASCII string.
2555 * Returns 0 on success.
2557 int proc_dointvec(struct ctl_table
*table
, int write
,
2558 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2560 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2564 * proc_douintvec - read a vector of unsigned integers
2565 * @table: the sysctl table
2566 * @write: %TRUE if this is a write to the sysctl file
2567 * @buffer: the user buffer
2568 * @lenp: the size of the user buffer
2569 * @ppos: file position
2571 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2572 * values from/to the user buffer, treated as an ASCII string.
2574 * Returns 0 on success.
2576 int proc_douintvec(struct ctl_table
*table
, int write
,
2577 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2579 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2580 do_proc_douintvec_conv
, NULL
);
2584 * Taint values can only be increased
2585 * This means we can safely use a temporary.
2587 static int proc_taint(struct ctl_table
*table
, int write
,
2588 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2591 unsigned long tmptaint
= get_taint();
2594 if (write
&& !capable(CAP_SYS_ADMIN
))
2599 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2605 * Poor man's atomic or. Not worth adding a primitive
2606 * to everyone's atomic.h for this
2609 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2610 if ((tmptaint
>> i
) & 1)
2611 add_taint(i
, LOCKDEP_STILL_OK
);
2618 #ifdef CONFIG_PRINTK
2619 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2620 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2622 if (write
&& !capable(CAP_SYS_ADMIN
))
2625 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2630 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2631 * @min: pointer to minimum allowable value
2632 * @max: pointer to maximum allowable value
2634 * The do_proc_dointvec_minmax_conv_param structure provides the
2635 * minimum and maximum values for doing range checking for those sysctl
2636 * parameters that use the proc_dointvec_minmax() handler.
2638 struct do_proc_dointvec_minmax_conv_param
{
2643 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2645 int write
, void *data
)
2648 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2650 * If writing, first do so via a temporary local int so we can
2651 * bounds-check it before touching *valp.
2653 int *ip
= write
? &tmp
: valp
;
2655 ret
= do_proc_dointvec_conv(negp
, lvalp
, ip
, write
, data
);
2660 if ((param
->min
&& *param
->min
> tmp
) ||
2661 (param
->max
&& *param
->max
< tmp
))
2670 * proc_dointvec_minmax - read a vector of integers with min/max values
2671 * @table: the sysctl table
2672 * @write: %TRUE if this is a write to the sysctl file
2673 * @buffer: the user buffer
2674 * @lenp: the size of the user buffer
2675 * @ppos: file position
2677 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2678 * values from/to the user buffer, treated as an ASCII string.
2680 * This routine will ensure the values are within the range specified by
2681 * table->extra1 (min) and table->extra2 (max).
2683 * Returns 0 on success or -EINVAL on write when the range check fails.
2685 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2686 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2688 struct do_proc_dointvec_minmax_conv_param param
= {
2689 .min
= (int *) table
->extra1
,
2690 .max
= (int *) table
->extra2
,
2692 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2693 do_proc_dointvec_minmax_conv
, ¶m
);
2697 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2698 * @min: pointer to minimum allowable value
2699 * @max: pointer to maximum allowable value
2701 * The do_proc_douintvec_minmax_conv_param structure provides the
2702 * minimum and maximum values for doing range checking for those sysctl
2703 * parameters that use the proc_douintvec_minmax() handler.
2705 struct do_proc_douintvec_minmax_conv_param
{
2710 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp
,
2712 int write
, void *data
)
2716 struct do_proc_douintvec_minmax_conv_param
*param
= data
;
2717 /* write via temporary local uint for bounds-checking */
2718 unsigned int *up
= write
? &tmp
: valp
;
2720 ret
= do_proc_douintvec_conv(lvalp
, up
, write
, data
);
2725 if ((param
->min
&& *param
->min
> tmp
) ||
2726 (param
->max
&& *param
->max
< tmp
))
2736 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2737 * @table: the sysctl table
2738 * @write: %TRUE if this is a write to the sysctl file
2739 * @buffer: the user buffer
2740 * @lenp: the size of the user buffer
2741 * @ppos: file position
2743 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2744 * values from/to the user buffer, treated as an ASCII string. Negative
2745 * strings are not allowed.
2747 * This routine will ensure the values are within the range specified by
2748 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2749 * check for UINT_MAX to avoid having to support wrap around uses from
2752 * Returns 0 on success or -ERANGE on write when the range check fails.
2754 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
2755 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2757 struct do_proc_douintvec_minmax_conv_param param
= {
2758 .min
= (unsigned int *) table
->extra1
,
2759 .max
= (unsigned int *) table
->extra2
,
2761 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2762 do_proc_douintvec_minmax_conv
, ¶m
);
2765 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp
,
2767 int write
, void *data
)
2772 val
= round_pipe_size(*lvalp
);
2778 unsigned int val
= *valp
;
2779 *lvalp
= (unsigned long) val
;
2785 static int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
2786 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2788 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2789 do_proc_dopipe_max_size_conv
, NULL
);
2792 static void validate_coredump_safety(void)
2794 #ifdef CONFIG_COREDUMP
2795 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2796 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2798 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2799 "Pipe handler or fully qualified core dump path required.\n"
2800 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2806 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2807 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2809 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2811 validate_coredump_safety();
2815 #ifdef CONFIG_COREDUMP
2816 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2817 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2819 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2821 validate_coredump_safety();
2826 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2827 void __user
*buffer
,
2828 size_t *lenp
, loff_t
*ppos
,
2829 unsigned long convmul
,
2830 unsigned long convdiv
)
2832 unsigned long *i
, *min
, *max
;
2833 int vleft
, first
= 1, err
= 0;
2835 char *kbuf
= NULL
, *p
;
2837 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2842 i
= (unsigned long *) data
;
2843 min
= (unsigned long *) table
->extra1
;
2844 max
= (unsigned long *) table
->extra2
;
2845 vleft
= table
->maxlen
/ sizeof(unsigned long);
2849 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2852 if (left
> PAGE_SIZE
- 1)
2853 left
= PAGE_SIZE
- 1;
2854 p
= kbuf
= memdup_user_nul(buffer
, left
);
2856 return PTR_ERR(kbuf
);
2859 for (; left
&& vleft
--; i
++, first
= 0) {
2865 left
-= proc_skip_spaces(&p
);
2869 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2871 sizeof(proc_wspace_sep
), NULL
);
2876 val
= convmul
* val
/ convdiv
;
2877 if ((min
&& val
< *min
) || (max
&& val
> *max
)) {
2883 val
= convdiv
* (*i
) / convmul
;
2885 err
= proc_put_char(&buffer
, &left
, '\t');
2889 err
= proc_put_long(&buffer
, &left
, val
, false);
2895 if (!write
&& !first
&& left
&& !err
)
2896 err
= proc_put_char(&buffer
, &left
, '\n');
2898 left
-= proc_skip_spaces(&p
);
2902 return err
? : -EINVAL
;
2910 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2911 void __user
*buffer
,
2912 size_t *lenp
, loff_t
*ppos
,
2913 unsigned long convmul
,
2914 unsigned long convdiv
)
2916 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2917 buffer
, lenp
, ppos
, convmul
, convdiv
);
2921 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2922 * @table: the sysctl table
2923 * @write: %TRUE if this is a write to the sysctl file
2924 * @buffer: the user buffer
2925 * @lenp: the size of the user buffer
2926 * @ppos: file position
2928 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2929 * values from/to the user buffer, treated as an ASCII string.
2931 * This routine will ensure the values are within the range specified by
2932 * table->extra1 (min) and table->extra2 (max).
2934 * Returns 0 on success.
2936 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2937 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2939 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2943 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2944 * @table: the sysctl table
2945 * @write: %TRUE if this is a write to the sysctl file
2946 * @buffer: the user buffer
2947 * @lenp: the size of the user buffer
2948 * @ppos: file position
2950 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2951 * values from/to the user buffer, treated as an ASCII string. The values
2952 * are treated as milliseconds, and converted to jiffies when they are stored.
2954 * This routine will ensure the values are within the range specified by
2955 * table->extra1 (min) and table->extra2 (max).
2957 * Returns 0 on success.
2959 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2960 void __user
*buffer
,
2961 size_t *lenp
, loff_t
*ppos
)
2963 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2964 lenp
, ppos
, HZ
, 1000l);
2968 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2970 int write
, void *data
)
2973 if (*lvalp
> INT_MAX
/ HZ
)
2975 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2981 lval
= -(unsigned long)val
;
2984 lval
= (unsigned long)val
;
2991 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2993 int write
, void *data
)
2996 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2998 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
3004 lval
= -(unsigned long)val
;
3007 lval
= (unsigned long)val
;
3009 *lvalp
= jiffies_to_clock_t(lval
);
3014 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
3016 int write
, void *data
)
3019 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
3029 lval
= -(unsigned long)val
;
3032 lval
= (unsigned long)val
;
3034 *lvalp
= jiffies_to_msecs(lval
);
3040 * proc_dointvec_jiffies - read a vector of integers as seconds
3041 * @table: the sysctl table
3042 * @write: %TRUE if this is a write to the sysctl file
3043 * @buffer: the user buffer
3044 * @lenp: the size of the user buffer
3045 * @ppos: file position
3047 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3048 * values from/to the user buffer, treated as an ASCII string.
3049 * The values read are assumed to be in seconds, and are converted into
3052 * Returns 0 on success.
3054 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3055 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3057 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
3058 do_proc_dointvec_jiffies_conv
,NULL
);
3062 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3063 * @table: the sysctl table
3064 * @write: %TRUE if this is a write to the sysctl file
3065 * @buffer: the user buffer
3066 * @lenp: the size of the user buffer
3067 * @ppos: pointer to the file position
3069 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3070 * values from/to the user buffer, treated as an ASCII string.
3071 * The values read are assumed to be in 1/USER_HZ seconds, and
3072 * are converted into jiffies.
3074 * Returns 0 on success.
3076 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3077 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3079 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
3080 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
3084 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3085 * @table: the sysctl table
3086 * @write: %TRUE if this is a write to the sysctl file
3087 * @buffer: the user buffer
3088 * @lenp: the size of the user buffer
3089 * @ppos: file position
3090 * @ppos: the current position in the file
3092 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3093 * values from/to the user buffer, treated as an ASCII string.
3094 * The values read are assumed to be in 1/1000 seconds, and
3095 * are converted into jiffies.
3097 * Returns 0 on success.
3099 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3100 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3102 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
3103 do_proc_dointvec_ms_jiffies_conv
, NULL
);
3106 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
3107 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3109 struct pid
*new_pid
;
3113 tmp
= pid_vnr(cad_pid
);
3115 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
3116 lenp
, ppos
, NULL
, NULL
);
3120 new_pid
= find_get_pid(tmp
);
3124 put_pid(xchg(&cad_pid
, new_pid
));
3129 * proc_do_large_bitmap - read/write from/to a large bitmap
3130 * @table: the sysctl table
3131 * @write: %TRUE if this is a write to the sysctl file
3132 * @buffer: the user buffer
3133 * @lenp: the size of the user buffer
3134 * @ppos: file position
3136 * The bitmap is stored at table->data and the bitmap length (in bits)
3139 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3140 * large bitmaps may be represented in a compact manner. Writing into
3141 * the file will clear the bitmap then update it with the given input.
3143 * Returns 0 on success.
3145 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3146 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3150 size_t left
= *lenp
;
3151 unsigned long bitmap_len
= table
->maxlen
;
3152 unsigned long *bitmap
= *(unsigned long **) table
->data
;
3153 unsigned long *tmp_bitmap
= NULL
;
3154 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
3156 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3164 if (left
> PAGE_SIZE
- 1)
3165 left
= PAGE_SIZE
- 1;
3167 p
= kbuf
= memdup_user_nul(buffer
, left
);
3169 return PTR_ERR(kbuf
);
3171 tmp_bitmap
= kcalloc(BITS_TO_LONGS(bitmap_len
),
3172 sizeof(unsigned long),
3178 proc_skip_char(&p
, &left
, '\n');
3179 while (!err
&& left
) {
3180 unsigned long val_a
, val_b
;
3183 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3187 if (val_a
>= bitmap_len
|| neg
) {
3199 err
= proc_get_long(&p
, &left
, &val_b
,
3200 &neg
, tr_b
, sizeof(tr_b
),
3204 if (val_b
>= bitmap_len
|| neg
||
3215 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3217 proc_skip_char(&p
, &left
, '\n');
3221 unsigned long bit_a
, bit_b
= 0;
3224 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3225 if (bit_a
>= bitmap_len
)
3227 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3231 err
= proc_put_char(&buffer
, &left
, ',');
3235 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3238 if (bit_a
!= bit_b
) {
3239 err
= proc_put_char(&buffer
, &left
, '-');
3242 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3250 err
= proc_put_char(&buffer
, &left
, '\n');
3256 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3258 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3268 #else /* CONFIG_PROC_SYSCTL */
3270 int proc_dostring(struct ctl_table
*table
, int write
,
3271 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3276 int proc_dointvec(struct ctl_table
*table
, int write
,
3277 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3282 int proc_douintvec(struct ctl_table
*table
, int write
,
3283 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3288 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3289 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3294 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3295 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3300 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3301 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3306 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3307 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3312 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3313 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3318 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3319 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3324 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3325 void __user
*buffer
,
3326 size_t *lenp
, loff_t
*ppos
)
3332 #endif /* CONFIG_PROC_SYSCTL */
3334 #if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL)
3335 static int proc_dointvec_minmax_bpf_stats(struct ctl_table
*table
, int write
,
3336 void __user
*buffer
, size_t *lenp
,
3339 int ret
, bpf_stats
= *(int *)table
->data
;
3340 struct ctl_table tmp
= *table
;
3342 if (write
&& !capable(CAP_SYS_ADMIN
))
3345 tmp
.data
= &bpf_stats
;
3346 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
3347 if (write
&& !ret
) {
3348 *(int *)table
->data
= bpf_stats
;
3350 static_branch_enable(&bpf_stats_enabled_key
);
3352 static_branch_disable(&bpf_stats_enabled_key
);
3358 * No sense putting this after each symbol definition, twice,
3359 * exception granted :-)
3361 EXPORT_SYMBOL(proc_dointvec
);
3362 EXPORT_SYMBOL(proc_douintvec
);
3363 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3364 EXPORT_SYMBOL(proc_dointvec_minmax
);
3365 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3366 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3367 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3368 EXPORT_SYMBOL(proc_dostring
);
3369 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3370 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);