1 // SPDX-License-Identifier: GPL-2.0-only
3 * sysctl.c: General linux system control interface
5 * Begun 24 March 1995, Stephen Tweedie
6 * Added /proc support, Dec 1995
7 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
8 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
9 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
10 * Dynamic registration fixes, Stephen Tweedie.
11 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
12 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
14 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
15 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
16 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
18 * The list_for_each() macro wasn't appropriate for the sysctl loop.
19 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
22 #include <linux/module.h>
23 #include <linux/aio.h>
25 #include <linux/swap.h>
26 #include <linux/slab.h>
27 #include <linux/sysctl.h>
28 #include <linux/bitmap.h>
29 #include <linux/signal.h>
30 #include <linux/printk.h>
31 #include <linux/proc_fs.h>
32 #include <linux/security.h>
33 #include <linux/ctype.h>
34 #include <linux/kmemleak.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/kobject.h>
39 #include <linux/net.h>
40 #include <linux/sysrq.h>
41 #include <linux/highuid.h>
42 #include <linux/writeback.h>
43 #include <linux/ratelimit.h>
44 #include <linux/compaction.h>
45 #include <linux/hugetlb.h>
46 #include <linux/initrd.h>
47 #include <linux/key.h>
48 #include <linux/times.h>
49 #include <linux/limits.h>
50 #include <linux/dcache.h>
51 #include <linux/dnotify.h>
52 #include <linux/syscalls.h>
53 #include <linux/vmstat.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/acpi.h>
56 #include <linux/reboot.h>
57 #include <linux/ftrace.h>
58 #include <linux/perf_event.h>
59 #include <linux/kprobes.h>
60 #include <linux/pipe_fs_i.h>
61 #include <linux/oom.h>
62 #include <linux/kmod.h>
63 #include <linux/capability.h>
64 #include <linux/binfmts.h>
65 #include <linux/sched/sysctl.h>
66 #include <linux/sched/coredump.h>
67 #include <linux/kexec.h>
68 #include <linux/bpf.h>
69 #include <linux/mount.h>
70 #include <linux/userfaultfd_k.h>
72 #include "../lib/kstrtox.h"
74 #include <linux/uaccess.h>
75 #include <asm/processor.h>
79 #include <asm/stacktrace.h>
83 #include <asm/setup.h>
85 #ifdef CONFIG_BSD_PROCESS_ACCT
86 #include <linux/acct.h>
88 #ifdef CONFIG_RT_MUTEXES
89 #include <linux/rtmutex.h>
91 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
92 #include <linux/lockdep.h>
94 #ifdef CONFIG_CHR_DEV_SG
97 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
98 #include <linux/stackleak.h>
100 #ifdef CONFIG_LOCKUP_DETECTOR
101 #include <linux/nmi.h>
104 #if defined(CONFIG_SYSCTL)
106 /* External variables not in a header file. */
107 extern int suid_dumpable
;
108 #ifdef CONFIG_COREDUMP
109 extern int core_uses_pid
;
110 extern char core_pattern
[];
111 extern unsigned int core_pipe_limit
;
114 extern int pid_max_min
, pid_max_max
;
115 extern int percpu_pagelist_fraction
;
116 extern int latencytop_enabled
;
117 extern unsigned int sysctl_nr_open_min
, sysctl_nr_open_max
;
119 extern int sysctl_nr_trim_pages
;
122 /* Constants used for minimum and maximum */
123 #ifdef CONFIG_LOCKUP_DETECTOR
124 static int sixty
= 60;
127 static int __maybe_unused neg_one
= -1;
130 static int __maybe_unused one
= 1;
131 static int __maybe_unused two
= 2;
132 static int __maybe_unused four
= 4;
133 static unsigned long zero_ul
;
134 static unsigned long one_ul
= 1;
135 static unsigned long long_max
= LONG_MAX
;
136 static int one_hundred
= 100;
137 static int one_thousand
= 1000;
139 static int ten_thousand
= 10000;
141 #ifdef CONFIG_PERF_EVENTS
142 static int six_hundred_forty_kb
= 640 * 1024;
145 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
146 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
148 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
149 static int maxolduid
= 65535;
150 static int minolduid
;
152 static int ngroups_max
= NGROUPS_MAX
;
153 static const int cap_last_cap
= CAP_LAST_CAP
;
156 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
157 * and hung_task_check_interval_secs
159 #ifdef CONFIG_DETECT_HUNG_TASK
160 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
163 #ifdef CONFIG_INOTIFY_USER
164 #include <linux/inotify.h>
170 extern int pwrsw_enabled
;
173 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
174 extern int unaligned_enabled
;
178 extern int unaligned_dump_stack
;
181 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
182 extern int no_unaligned_warning
;
185 #ifdef CONFIG_PROC_SYSCTL
188 * enum sysctl_writes_mode - supported sysctl write modes
190 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
191 * to be written, and multiple writes on the same sysctl file descriptor
192 * will rewrite the sysctl value, regardless of file position. No warning
193 * is issued when the initial position is not 0.
194 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
196 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
197 * file position 0 and the value must be fully contained in the buffer
198 * sent to the write syscall. If dealing with strings respect the file
199 * position, but restrict this to the max length of the buffer, anything
200 * passed the max lenght will be ignored. Multiple writes will append
203 * These write modes control how current file position affects the behavior of
204 * updating sysctl values through the proc interface on each write.
206 enum sysctl_writes_mode
{
207 SYSCTL_WRITES_LEGACY
= -1,
208 SYSCTL_WRITES_WARN
= 0,
209 SYSCTL_WRITES_STRICT
= 1,
212 static enum sysctl_writes_mode sysctl_writes_strict
= SYSCTL_WRITES_STRICT
;
214 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
215 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
216 static int proc_taint(struct ctl_table
*table
, int write
,
217 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
221 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
222 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
225 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
226 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
227 #ifdef CONFIG_COREDUMP
228 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
229 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
231 static int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
232 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
233 #ifdef CONFIG_BPF_SYSCALL
234 static int proc_dointvec_minmax_bpf_stats(struct ctl_table
*table
, int write
,
235 void __user
*buffer
, size_t *lenp
,
239 #ifdef CONFIG_MAGIC_SYSRQ
240 /* Note: sysrq code uses its own private copy */
241 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
243 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
244 void __user
*buffer
, size_t *lenp
,
249 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
254 sysrq_toggle_support(__sysrq_enabled
);
261 static struct ctl_table kern_table
[];
262 static struct ctl_table vm_table
[];
263 static struct ctl_table fs_table
[];
264 static struct ctl_table debug_table
[];
265 static struct ctl_table dev_table
[];
266 extern struct ctl_table random_table
[];
268 extern struct ctl_table epoll_table
[];
271 #ifdef CONFIG_FW_LOADER_USER_HELPER
272 extern struct ctl_table firmware_config_table
[];
275 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
276 int sysctl_legacy_va_layout
;
279 /* The default sysctl tables: */
281 static struct ctl_table sysctl_base_table
[] = {
283 .procname
= "kernel",
300 .child
= debug_table
,
310 #ifdef CONFIG_SCHED_DEBUG
311 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
312 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
313 static int min_wakeup_granularity_ns
; /* 0 usecs */
314 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
316 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
317 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
318 #endif /* CONFIG_SMP */
319 #endif /* CONFIG_SCHED_DEBUG */
321 #ifdef CONFIG_COMPACTION
322 static int min_extfrag_threshold
;
323 static int max_extfrag_threshold
= 1000;
326 static struct ctl_table kern_table
[] = {
328 .procname
= "sched_child_runs_first",
329 .data
= &sysctl_sched_child_runs_first
,
330 .maxlen
= sizeof(unsigned int),
332 .proc_handler
= proc_dointvec
,
334 #ifdef CONFIG_SCHED_DEBUG
336 .procname
= "sched_min_granularity_ns",
337 .data
= &sysctl_sched_min_granularity
,
338 .maxlen
= sizeof(unsigned int),
340 .proc_handler
= sched_proc_update_handler
,
341 .extra1
= &min_sched_granularity_ns
,
342 .extra2
= &max_sched_granularity_ns
,
345 .procname
= "sched_latency_ns",
346 .data
= &sysctl_sched_latency
,
347 .maxlen
= sizeof(unsigned int),
349 .proc_handler
= sched_proc_update_handler
,
350 .extra1
= &min_sched_granularity_ns
,
351 .extra2
= &max_sched_granularity_ns
,
354 .procname
= "sched_wakeup_granularity_ns",
355 .data
= &sysctl_sched_wakeup_granularity
,
356 .maxlen
= sizeof(unsigned int),
358 .proc_handler
= sched_proc_update_handler
,
359 .extra1
= &min_wakeup_granularity_ns
,
360 .extra2
= &max_wakeup_granularity_ns
,
364 .procname
= "sched_tunable_scaling",
365 .data
= &sysctl_sched_tunable_scaling
,
366 .maxlen
= sizeof(enum sched_tunable_scaling
),
368 .proc_handler
= sched_proc_update_handler
,
369 .extra1
= &min_sched_tunable_scaling
,
370 .extra2
= &max_sched_tunable_scaling
,
373 .procname
= "sched_migration_cost_ns",
374 .data
= &sysctl_sched_migration_cost
,
375 .maxlen
= sizeof(unsigned int),
377 .proc_handler
= proc_dointvec
,
380 .procname
= "sched_nr_migrate",
381 .data
= &sysctl_sched_nr_migrate
,
382 .maxlen
= sizeof(unsigned int),
384 .proc_handler
= proc_dointvec
,
386 #ifdef CONFIG_SCHEDSTATS
388 .procname
= "sched_schedstats",
390 .maxlen
= sizeof(unsigned int),
392 .proc_handler
= sysctl_schedstats
,
396 #endif /* CONFIG_SCHEDSTATS */
397 #endif /* CONFIG_SMP */
398 #ifdef CONFIG_NUMA_BALANCING
400 .procname
= "numa_balancing_scan_delay_ms",
401 .data
= &sysctl_numa_balancing_scan_delay
,
402 .maxlen
= sizeof(unsigned int),
404 .proc_handler
= proc_dointvec
,
407 .procname
= "numa_balancing_scan_period_min_ms",
408 .data
= &sysctl_numa_balancing_scan_period_min
,
409 .maxlen
= sizeof(unsigned int),
411 .proc_handler
= proc_dointvec
,
414 .procname
= "numa_balancing_scan_period_max_ms",
415 .data
= &sysctl_numa_balancing_scan_period_max
,
416 .maxlen
= sizeof(unsigned int),
418 .proc_handler
= proc_dointvec
,
421 .procname
= "numa_balancing_scan_size_mb",
422 .data
= &sysctl_numa_balancing_scan_size
,
423 .maxlen
= sizeof(unsigned int),
425 .proc_handler
= proc_dointvec_minmax
,
429 .procname
= "numa_balancing",
430 .data
= NULL
, /* filled in by handler */
431 .maxlen
= sizeof(unsigned int),
433 .proc_handler
= sysctl_numa_balancing
,
437 #endif /* CONFIG_NUMA_BALANCING */
438 #endif /* CONFIG_SCHED_DEBUG */
440 .procname
= "sched_rt_period_us",
441 .data
= &sysctl_sched_rt_period
,
442 .maxlen
= sizeof(unsigned int),
444 .proc_handler
= sched_rt_handler
,
447 .procname
= "sched_rt_runtime_us",
448 .data
= &sysctl_sched_rt_runtime
,
449 .maxlen
= sizeof(int),
451 .proc_handler
= sched_rt_handler
,
454 .procname
= "sched_rr_timeslice_ms",
455 .data
= &sysctl_sched_rr_timeslice
,
456 .maxlen
= sizeof(int),
458 .proc_handler
= sched_rr_handler
,
460 #ifdef CONFIG_SCHED_AUTOGROUP
462 .procname
= "sched_autogroup_enabled",
463 .data
= &sysctl_sched_autogroup_enabled
,
464 .maxlen
= sizeof(unsigned int),
466 .proc_handler
= proc_dointvec_minmax
,
471 #ifdef CONFIG_CFS_BANDWIDTH
473 .procname
= "sched_cfs_bandwidth_slice_us",
474 .data
= &sysctl_sched_cfs_bandwidth_slice
,
475 .maxlen
= sizeof(unsigned int),
477 .proc_handler
= proc_dointvec_minmax
,
481 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
483 .procname
= "sched_energy_aware",
484 .data
= &sysctl_sched_energy_aware
,
485 .maxlen
= sizeof(unsigned int),
487 .proc_handler
= sched_energy_aware_handler
,
492 #ifdef CONFIG_PROVE_LOCKING
494 .procname
= "prove_locking",
495 .data
= &prove_locking
,
496 .maxlen
= sizeof(int),
498 .proc_handler
= proc_dointvec
,
501 #ifdef CONFIG_LOCK_STAT
503 .procname
= "lock_stat",
505 .maxlen
= sizeof(int),
507 .proc_handler
= proc_dointvec
,
512 .data
= &panic_timeout
,
513 .maxlen
= sizeof(int),
515 .proc_handler
= proc_dointvec
,
517 #ifdef CONFIG_COREDUMP
519 .procname
= "core_uses_pid",
520 .data
= &core_uses_pid
,
521 .maxlen
= sizeof(int),
523 .proc_handler
= proc_dointvec
,
526 .procname
= "core_pattern",
527 .data
= core_pattern
,
528 .maxlen
= CORENAME_MAX_SIZE
,
530 .proc_handler
= proc_dostring_coredump
,
533 .procname
= "core_pipe_limit",
534 .data
= &core_pipe_limit
,
535 .maxlen
= sizeof(unsigned int),
537 .proc_handler
= proc_dointvec
,
540 #ifdef CONFIG_PROC_SYSCTL
542 .procname
= "tainted",
543 .maxlen
= sizeof(long),
545 .proc_handler
= proc_taint
,
548 .procname
= "sysctl_writes_strict",
549 .data
= &sysctl_writes_strict
,
550 .maxlen
= sizeof(int),
552 .proc_handler
= proc_dointvec_minmax
,
557 #ifdef CONFIG_LATENCYTOP
559 .procname
= "latencytop",
560 .data
= &latencytop_enabled
,
561 .maxlen
= sizeof(int),
563 .proc_handler
= sysctl_latencytop
,
566 #ifdef CONFIG_BLK_DEV_INITRD
568 .procname
= "real-root-dev",
569 .data
= &real_root_dev
,
570 .maxlen
= sizeof(int),
572 .proc_handler
= proc_dointvec
,
576 .procname
= "print-fatal-signals",
577 .data
= &print_fatal_signals
,
578 .maxlen
= sizeof(int),
580 .proc_handler
= proc_dointvec
,
584 .procname
= "reboot-cmd",
585 .data
= reboot_command
,
588 .proc_handler
= proc_dostring
,
591 .procname
= "stop-a",
592 .data
= &stop_a_enabled
,
593 .maxlen
= sizeof (int),
595 .proc_handler
= proc_dointvec
,
598 .procname
= "scons-poweroff",
599 .data
= &scons_pwroff
,
600 .maxlen
= sizeof (int),
602 .proc_handler
= proc_dointvec
,
605 #ifdef CONFIG_SPARC64
607 .procname
= "tsb-ratio",
608 .data
= &sysctl_tsb_ratio
,
609 .maxlen
= sizeof (int),
611 .proc_handler
= proc_dointvec
,
616 .procname
= "soft-power",
617 .data
= &pwrsw_enabled
,
618 .maxlen
= sizeof (int),
620 .proc_handler
= proc_dointvec
,
623 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
625 .procname
= "unaligned-trap",
626 .data
= &unaligned_enabled
,
627 .maxlen
= sizeof (int),
629 .proc_handler
= proc_dointvec
,
633 .procname
= "ctrl-alt-del",
635 .maxlen
= sizeof(int),
637 .proc_handler
= proc_dointvec
,
639 #ifdef CONFIG_FUNCTION_TRACER
641 .procname
= "ftrace_enabled",
642 .data
= &ftrace_enabled
,
643 .maxlen
= sizeof(int),
645 .proc_handler
= ftrace_enable_sysctl
,
648 #ifdef CONFIG_STACK_TRACER
650 .procname
= "stack_tracer_enabled",
651 .data
= &stack_tracer_enabled
,
652 .maxlen
= sizeof(int),
654 .proc_handler
= stack_trace_sysctl
,
657 #ifdef CONFIG_TRACING
659 .procname
= "ftrace_dump_on_oops",
660 .data
= &ftrace_dump_on_oops
,
661 .maxlen
= sizeof(int),
663 .proc_handler
= proc_dointvec
,
666 .procname
= "traceoff_on_warning",
667 .data
= &__disable_trace_on_warning
,
668 .maxlen
= sizeof(__disable_trace_on_warning
),
670 .proc_handler
= proc_dointvec
,
673 .procname
= "tracepoint_printk",
674 .data
= &tracepoint_printk
,
675 .maxlen
= sizeof(tracepoint_printk
),
677 .proc_handler
= tracepoint_printk_sysctl
,
680 #ifdef CONFIG_KEXEC_CORE
682 .procname
= "kexec_load_disabled",
683 .data
= &kexec_load_disabled
,
684 .maxlen
= sizeof(int),
686 /* only handle a transition from default "0" to "1" */
687 .proc_handler
= proc_dointvec_minmax
,
692 #ifdef CONFIG_MODULES
694 .procname
= "modprobe",
695 .data
= &modprobe_path
,
696 .maxlen
= KMOD_PATH_LEN
,
698 .proc_handler
= proc_dostring
,
701 .procname
= "modules_disabled",
702 .data
= &modules_disabled
,
703 .maxlen
= sizeof(int),
705 /* only handle a transition from default "0" to "1" */
706 .proc_handler
= proc_dointvec_minmax
,
711 #ifdef CONFIG_UEVENT_HELPER
713 .procname
= "hotplug",
714 .data
= &uevent_helper
,
715 .maxlen
= UEVENT_HELPER_PATH_LEN
,
717 .proc_handler
= proc_dostring
,
720 #ifdef CONFIG_CHR_DEV_SG
722 .procname
= "sg-big-buff",
723 .data
= &sg_big_buff
,
724 .maxlen
= sizeof (int),
726 .proc_handler
= proc_dointvec
,
729 #ifdef CONFIG_BSD_PROCESS_ACCT
733 .maxlen
= 3*sizeof(int),
735 .proc_handler
= proc_dointvec
,
738 #ifdef CONFIG_MAGIC_SYSRQ
741 .data
= &__sysrq_enabled
,
742 .maxlen
= sizeof (int),
744 .proc_handler
= sysrq_sysctl_handler
,
747 #ifdef CONFIG_PROC_SYSCTL
749 .procname
= "cad_pid",
751 .maxlen
= sizeof (int),
753 .proc_handler
= proc_do_cad_pid
,
757 .procname
= "threads-max",
759 .maxlen
= sizeof(int),
761 .proc_handler
= sysctl_max_threads
,
764 .procname
= "random",
766 .child
= random_table
,
769 .procname
= "usermodehelper",
771 .child
= usermodehelper_table
,
773 #ifdef CONFIG_FW_LOADER_USER_HELPER
775 .procname
= "firmware_config",
777 .child
= firmware_config_table
,
781 .procname
= "overflowuid",
782 .data
= &overflowuid
,
783 .maxlen
= sizeof(int),
785 .proc_handler
= proc_dointvec_minmax
,
786 .extra1
= &minolduid
,
787 .extra2
= &maxolduid
,
790 .procname
= "overflowgid",
791 .data
= &overflowgid
,
792 .maxlen
= sizeof(int),
794 .proc_handler
= proc_dointvec_minmax
,
795 .extra1
= &minolduid
,
796 .extra2
= &maxolduid
,
799 #ifdef CONFIG_MATHEMU
801 .procname
= "ieee_emulation_warnings",
802 .data
= &sysctl_ieee_emulation_warnings
,
803 .maxlen
= sizeof(int),
805 .proc_handler
= proc_dointvec
,
809 .procname
= "userprocess_debug",
810 .data
= &show_unhandled_signals
,
811 .maxlen
= sizeof(int),
813 .proc_handler
= proc_dointvec
,
817 .procname
= "pid_max",
819 .maxlen
= sizeof (int),
821 .proc_handler
= proc_dointvec_minmax
,
822 .extra1
= &pid_max_min
,
823 .extra2
= &pid_max_max
,
826 .procname
= "panic_on_oops",
827 .data
= &panic_on_oops
,
828 .maxlen
= sizeof(int),
830 .proc_handler
= proc_dointvec
,
833 .procname
= "panic_print",
834 .data
= &panic_print
,
835 .maxlen
= sizeof(unsigned long),
837 .proc_handler
= proc_doulongvec_minmax
,
839 #if defined CONFIG_PRINTK
841 .procname
= "printk",
842 .data
= &console_loglevel
,
843 .maxlen
= 4*sizeof(int),
845 .proc_handler
= proc_dointvec
,
848 .procname
= "printk_ratelimit",
849 .data
= &printk_ratelimit_state
.interval
,
850 .maxlen
= sizeof(int),
852 .proc_handler
= proc_dointvec_jiffies
,
855 .procname
= "printk_ratelimit_burst",
856 .data
= &printk_ratelimit_state
.burst
,
857 .maxlen
= sizeof(int),
859 .proc_handler
= proc_dointvec
,
862 .procname
= "printk_delay",
863 .data
= &printk_delay_msec
,
864 .maxlen
= sizeof(int),
866 .proc_handler
= proc_dointvec_minmax
,
868 .extra2
= &ten_thousand
,
871 .procname
= "printk_devkmsg",
872 .data
= devkmsg_log_str
,
873 .maxlen
= DEVKMSG_STR_MAX_SIZE
,
875 .proc_handler
= devkmsg_sysctl_set_loglvl
,
878 .procname
= "dmesg_restrict",
879 .data
= &dmesg_restrict
,
880 .maxlen
= sizeof(int),
882 .proc_handler
= proc_dointvec_minmax_sysadmin
,
887 .procname
= "kptr_restrict",
888 .data
= &kptr_restrict
,
889 .maxlen
= sizeof(int),
891 .proc_handler
= proc_dointvec_minmax_sysadmin
,
897 .procname
= "ngroups_max",
898 .data
= &ngroups_max
,
899 .maxlen
= sizeof (int),
901 .proc_handler
= proc_dointvec
,
904 .procname
= "cap_last_cap",
905 .data
= (void *)&cap_last_cap
,
906 .maxlen
= sizeof(int),
908 .proc_handler
= proc_dointvec
,
910 #if defined(CONFIG_LOCKUP_DETECTOR)
912 .procname
= "watchdog",
913 .data
= &watchdog_user_enabled
,
914 .maxlen
= sizeof(int),
916 .proc_handler
= proc_watchdog
,
921 .procname
= "watchdog_thresh",
922 .data
= &watchdog_thresh
,
923 .maxlen
= sizeof(int),
925 .proc_handler
= proc_watchdog_thresh
,
930 .procname
= "nmi_watchdog",
931 .data
= &nmi_watchdog_user_enabled
,
932 .maxlen
= sizeof(int),
933 .mode
= NMI_WATCHDOG_SYSCTL_PERM
,
934 .proc_handler
= proc_nmi_watchdog
,
939 .procname
= "watchdog_cpumask",
940 .data
= &watchdog_cpumask_bits
,
943 .proc_handler
= proc_watchdog_cpumask
,
945 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
947 .procname
= "soft_watchdog",
948 .data
= &soft_watchdog_user_enabled
,
949 .maxlen
= sizeof(int),
951 .proc_handler
= proc_soft_watchdog
,
956 .procname
= "softlockup_panic",
957 .data
= &softlockup_panic
,
958 .maxlen
= sizeof(int),
960 .proc_handler
= proc_dointvec_minmax
,
966 .procname
= "softlockup_all_cpu_backtrace",
967 .data
= &sysctl_softlockup_all_cpu_backtrace
,
968 .maxlen
= sizeof(int),
970 .proc_handler
= proc_dointvec_minmax
,
974 #endif /* CONFIG_SMP */
976 #ifdef CONFIG_HARDLOCKUP_DETECTOR
978 .procname
= "hardlockup_panic",
979 .data
= &hardlockup_panic
,
980 .maxlen
= sizeof(int),
982 .proc_handler
= proc_dointvec_minmax
,
988 .procname
= "hardlockup_all_cpu_backtrace",
989 .data
= &sysctl_hardlockup_all_cpu_backtrace
,
990 .maxlen
= sizeof(int),
992 .proc_handler
= proc_dointvec_minmax
,
996 #endif /* CONFIG_SMP */
1000 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1002 .procname
= "unknown_nmi_panic",
1003 .data
= &unknown_nmi_panic
,
1004 .maxlen
= sizeof (int),
1006 .proc_handler
= proc_dointvec
,
1009 #if defined(CONFIG_X86)
1011 .procname
= "panic_on_unrecovered_nmi",
1012 .data
= &panic_on_unrecovered_nmi
,
1013 .maxlen
= sizeof(int),
1015 .proc_handler
= proc_dointvec
,
1018 .procname
= "panic_on_io_nmi",
1019 .data
= &panic_on_io_nmi
,
1020 .maxlen
= sizeof(int),
1022 .proc_handler
= proc_dointvec
,
1024 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1026 .procname
= "panic_on_stackoverflow",
1027 .data
= &sysctl_panic_on_stackoverflow
,
1028 .maxlen
= sizeof(int),
1030 .proc_handler
= proc_dointvec
,
1034 .procname
= "bootloader_type",
1035 .data
= &bootloader_type
,
1036 .maxlen
= sizeof (int),
1038 .proc_handler
= proc_dointvec
,
1041 .procname
= "bootloader_version",
1042 .data
= &bootloader_version
,
1043 .maxlen
= sizeof (int),
1045 .proc_handler
= proc_dointvec
,
1048 .procname
= "io_delay_type",
1049 .data
= &io_delay_type
,
1050 .maxlen
= sizeof(int),
1052 .proc_handler
= proc_dointvec
,
1055 #if defined(CONFIG_MMU)
1057 .procname
= "randomize_va_space",
1058 .data
= &randomize_va_space
,
1059 .maxlen
= sizeof(int),
1061 .proc_handler
= proc_dointvec
,
1064 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1066 .procname
= "spin_retry",
1067 .data
= &spin_retry
,
1068 .maxlen
= sizeof (int),
1070 .proc_handler
= proc_dointvec
,
1073 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1075 .procname
= "acpi_video_flags",
1076 .data
= &acpi_realmode_flags
,
1077 .maxlen
= sizeof (unsigned long),
1079 .proc_handler
= proc_doulongvec_minmax
,
1082 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1084 .procname
= "ignore-unaligned-usertrap",
1085 .data
= &no_unaligned_warning
,
1086 .maxlen
= sizeof (int),
1088 .proc_handler
= proc_dointvec
,
1093 .procname
= "unaligned-dump-stack",
1094 .data
= &unaligned_dump_stack
,
1095 .maxlen
= sizeof (int),
1097 .proc_handler
= proc_dointvec
,
1100 #ifdef CONFIG_DETECT_HUNG_TASK
1102 .procname
= "hung_task_panic",
1103 .data
= &sysctl_hung_task_panic
,
1104 .maxlen
= sizeof(int),
1106 .proc_handler
= proc_dointvec_minmax
,
1111 .procname
= "hung_task_check_count",
1112 .data
= &sysctl_hung_task_check_count
,
1113 .maxlen
= sizeof(int),
1115 .proc_handler
= proc_dointvec_minmax
,
1119 .procname
= "hung_task_timeout_secs",
1120 .data
= &sysctl_hung_task_timeout_secs
,
1121 .maxlen
= sizeof(unsigned long),
1123 .proc_handler
= proc_dohung_task_timeout_secs
,
1124 .extra2
= &hung_task_timeout_max
,
1127 .procname
= "hung_task_check_interval_secs",
1128 .data
= &sysctl_hung_task_check_interval_secs
,
1129 .maxlen
= sizeof(unsigned long),
1131 .proc_handler
= proc_dohung_task_timeout_secs
,
1132 .extra2
= &hung_task_timeout_max
,
1135 .procname
= "hung_task_warnings",
1136 .data
= &sysctl_hung_task_warnings
,
1137 .maxlen
= sizeof(int),
1139 .proc_handler
= proc_dointvec_minmax
,
1143 #ifdef CONFIG_RT_MUTEXES
1145 .procname
= "max_lock_depth",
1146 .data
= &max_lock_depth
,
1147 .maxlen
= sizeof(int),
1149 .proc_handler
= proc_dointvec
,
1153 .procname
= "poweroff_cmd",
1154 .data
= &poweroff_cmd
,
1155 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1157 .proc_handler
= proc_dostring
,
1163 .child
= key_sysctls
,
1166 #ifdef CONFIG_PERF_EVENTS
1168 * User-space scripts rely on the existence of this file
1169 * as a feature check for perf_events being enabled.
1171 * So it's an ABI, do not remove!
1174 .procname
= "perf_event_paranoid",
1175 .data
= &sysctl_perf_event_paranoid
,
1176 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1178 .proc_handler
= proc_dointvec
,
1181 .procname
= "perf_event_mlock_kb",
1182 .data
= &sysctl_perf_event_mlock
,
1183 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1185 .proc_handler
= proc_dointvec
,
1188 .procname
= "perf_event_max_sample_rate",
1189 .data
= &sysctl_perf_event_sample_rate
,
1190 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1192 .proc_handler
= perf_proc_update_handler
,
1196 .procname
= "perf_cpu_time_max_percent",
1197 .data
= &sysctl_perf_cpu_time_max_percent
,
1198 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1200 .proc_handler
= perf_cpu_time_max_percent_handler
,
1202 .extra2
= &one_hundred
,
1205 .procname
= "perf_event_max_stack",
1206 .data
= &sysctl_perf_event_max_stack
,
1207 .maxlen
= sizeof(sysctl_perf_event_max_stack
),
1209 .proc_handler
= perf_event_max_stack_handler
,
1211 .extra2
= &six_hundred_forty_kb
,
1214 .procname
= "perf_event_max_contexts_per_stack",
1215 .data
= &sysctl_perf_event_max_contexts_per_stack
,
1216 .maxlen
= sizeof(sysctl_perf_event_max_contexts_per_stack
),
1218 .proc_handler
= perf_event_max_stack_handler
,
1220 .extra2
= &one_thousand
,
1224 .procname
= "panic_on_warn",
1225 .data
= &panic_on_warn
,
1226 .maxlen
= sizeof(int),
1228 .proc_handler
= proc_dointvec_minmax
,
1232 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1234 .procname
= "timer_migration",
1235 .data
= &sysctl_timer_migration
,
1236 .maxlen
= sizeof(unsigned int),
1238 .proc_handler
= timer_migration_handler
,
1243 #ifdef CONFIG_BPF_SYSCALL
1245 .procname
= "unprivileged_bpf_disabled",
1246 .data
= &sysctl_unprivileged_bpf_disabled
,
1247 .maxlen
= sizeof(sysctl_unprivileged_bpf_disabled
),
1249 /* only handle a transition from default "0" to "1" */
1250 .proc_handler
= proc_dointvec_minmax
,
1255 .procname
= "bpf_stats_enabled",
1256 .data
= &sysctl_bpf_stats_enabled
,
1257 .maxlen
= sizeof(sysctl_bpf_stats_enabled
),
1259 .proc_handler
= proc_dointvec_minmax_bpf_stats
,
1264 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1266 .procname
= "panic_on_rcu_stall",
1267 .data
= &sysctl_panic_on_rcu_stall
,
1268 .maxlen
= sizeof(sysctl_panic_on_rcu_stall
),
1270 .proc_handler
= proc_dointvec_minmax
,
1275 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1277 .procname
= "stack_erasing",
1279 .maxlen
= sizeof(int),
1281 .proc_handler
= stack_erasing_sysctl
,
1289 static struct ctl_table vm_table
[] = {
1291 .procname
= "overcommit_memory",
1292 .data
= &sysctl_overcommit_memory
,
1293 .maxlen
= sizeof(sysctl_overcommit_memory
),
1295 .proc_handler
= proc_dointvec_minmax
,
1300 .procname
= "panic_on_oom",
1301 .data
= &sysctl_panic_on_oom
,
1302 .maxlen
= sizeof(sysctl_panic_on_oom
),
1304 .proc_handler
= proc_dointvec_minmax
,
1309 .procname
= "oom_kill_allocating_task",
1310 .data
= &sysctl_oom_kill_allocating_task
,
1311 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1313 .proc_handler
= proc_dointvec
,
1316 .procname
= "oom_dump_tasks",
1317 .data
= &sysctl_oom_dump_tasks
,
1318 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1320 .proc_handler
= proc_dointvec
,
1323 .procname
= "overcommit_ratio",
1324 .data
= &sysctl_overcommit_ratio
,
1325 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1327 .proc_handler
= overcommit_ratio_handler
,
1330 .procname
= "overcommit_kbytes",
1331 .data
= &sysctl_overcommit_kbytes
,
1332 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1334 .proc_handler
= overcommit_kbytes_handler
,
1337 .procname
= "page-cluster",
1338 .data
= &page_cluster
,
1339 .maxlen
= sizeof(int),
1341 .proc_handler
= proc_dointvec_minmax
,
1345 .procname
= "dirty_background_ratio",
1346 .data
= &dirty_background_ratio
,
1347 .maxlen
= sizeof(dirty_background_ratio
),
1349 .proc_handler
= dirty_background_ratio_handler
,
1351 .extra2
= &one_hundred
,
1354 .procname
= "dirty_background_bytes",
1355 .data
= &dirty_background_bytes
,
1356 .maxlen
= sizeof(dirty_background_bytes
),
1358 .proc_handler
= dirty_background_bytes_handler
,
1362 .procname
= "dirty_ratio",
1363 .data
= &vm_dirty_ratio
,
1364 .maxlen
= sizeof(vm_dirty_ratio
),
1366 .proc_handler
= dirty_ratio_handler
,
1368 .extra2
= &one_hundred
,
1371 .procname
= "dirty_bytes",
1372 .data
= &vm_dirty_bytes
,
1373 .maxlen
= sizeof(vm_dirty_bytes
),
1375 .proc_handler
= dirty_bytes_handler
,
1376 .extra1
= &dirty_bytes_min
,
1379 .procname
= "dirty_writeback_centisecs",
1380 .data
= &dirty_writeback_interval
,
1381 .maxlen
= sizeof(dirty_writeback_interval
),
1383 .proc_handler
= dirty_writeback_centisecs_handler
,
1386 .procname
= "dirty_expire_centisecs",
1387 .data
= &dirty_expire_interval
,
1388 .maxlen
= sizeof(dirty_expire_interval
),
1390 .proc_handler
= proc_dointvec_minmax
,
1394 .procname
= "dirtytime_expire_seconds",
1395 .data
= &dirtytime_expire_interval
,
1396 .maxlen
= sizeof(dirtytime_expire_interval
),
1398 .proc_handler
= dirtytime_interval_handler
,
1402 .procname
= "swappiness",
1403 .data
= &vm_swappiness
,
1404 .maxlen
= sizeof(vm_swappiness
),
1406 .proc_handler
= proc_dointvec_minmax
,
1408 .extra2
= &one_hundred
,
1410 #ifdef CONFIG_HUGETLB_PAGE
1412 .procname
= "nr_hugepages",
1414 .maxlen
= sizeof(unsigned long),
1416 .proc_handler
= hugetlb_sysctl_handler
,
1420 .procname
= "nr_hugepages_mempolicy",
1422 .maxlen
= sizeof(unsigned long),
1424 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1427 .procname
= "numa_stat",
1428 .data
= &sysctl_vm_numa_stat
,
1429 .maxlen
= sizeof(int),
1431 .proc_handler
= sysctl_vm_numa_stat_handler
,
1437 .procname
= "hugetlb_shm_group",
1438 .data
= &sysctl_hugetlb_shm_group
,
1439 .maxlen
= sizeof(gid_t
),
1441 .proc_handler
= proc_dointvec
,
1444 .procname
= "nr_overcommit_hugepages",
1446 .maxlen
= sizeof(unsigned long),
1448 .proc_handler
= hugetlb_overcommit_handler
,
1452 .procname
= "lowmem_reserve_ratio",
1453 .data
= &sysctl_lowmem_reserve_ratio
,
1454 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1456 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1459 .procname
= "drop_caches",
1460 .data
= &sysctl_drop_caches
,
1461 .maxlen
= sizeof(int),
1463 .proc_handler
= drop_caches_sysctl_handler
,
1467 #ifdef CONFIG_COMPACTION
1469 .procname
= "compact_memory",
1470 .data
= &sysctl_compact_memory
,
1471 .maxlen
= sizeof(int),
1473 .proc_handler
= sysctl_compaction_handler
,
1476 .procname
= "extfrag_threshold",
1477 .data
= &sysctl_extfrag_threshold
,
1478 .maxlen
= sizeof(int),
1480 .proc_handler
= proc_dointvec_minmax
,
1481 .extra1
= &min_extfrag_threshold
,
1482 .extra2
= &max_extfrag_threshold
,
1485 .procname
= "compact_unevictable_allowed",
1486 .data
= &sysctl_compact_unevictable_allowed
,
1487 .maxlen
= sizeof(int),
1489 .proc_handler
= proc_dointvec
,
1494 #endif /* CONFIG_COMPACTION */
1496 .procname
= "min_free_kbytes",
1497 .data
= &min_free_kbytes
,
1498 .maxlen
= sizeof(min_free_kbytes
),
1500 .proc_handler
= min_free_kbytes_sysctl_handler
,
1504 .procname
= "watermark_boost_factor",
1505 .data
= &watermark_boost_factor
,
1506 .maxlen
= sizeof(watermark_boost_factor
),
1508 .proc_handler
= watermark_boost_factor_sysctl_handler
,
1512 .procname
= "watermark_scale_factor",
1513 .data
= &watermark_scale_factor
,
1514 .maxlen
= sizeof(watermark_scale_factor
),
1516 .proc_handler
= watermark_scale_factor_sysctl_handler
,
1518 .extra2
= &one_thousand
,
1521 .procname
= "percpu_pagelist_fraction",
1522 .data
= &percpu_pagelist_fraction
,
1523 .maxlen
= sizeof(percpu_pagelist_fraction
),
1525 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1530 .procname
= "max_map_count",
1531 .data
= &sysctl_max_map_count
,
1532 .maxlen
= sizeof(sysctl_max_map_count
),
1534 .proc_handler
= proc_dointvec_minmax
,
1539 .procname
= "nr_trim_pages",
1540 .data
= &sysctl_nr_trim_pages
,
1541 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1543 .proc_handler
= proc_dointvec_minmax
,
1548 .procname
= "laptop_mode",
1549 .data
= &laptop_mode
,
1550 .maxlen
= sizeof(laptop_mode
),
1552 .proc_handler
= proc_dointvec_jiffies
,
1555 .procname
= "block_dump",
1556 .data
= &block_dump
,
1557 .maxlen
= sizeof(block_dump
),
1559 .proc_handler
= proc_dointvec
,
1563 .procname
= "vfs_cache_pressure",
1564 .data
= &sysctl_vfs_cache_pressure
,
1565 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1567 .proc_handler
= proc_dointvec
,
1570 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1572 .procname
= "legacy_va_layout",
1573 .data
= &sysctl_legacy_va_layout
,
1574 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1576 .proc_handler
= proc_dointvec
,
1582 .procname
= "zone_reclaim_mode",
1583 .data
= &node_reclaim_mode
,
1584 .maxlen
= sizeof(node_reclaim_mode
),
1586 .proc_handler
= proc_dointvec
,
1590 .procname
= "min_unmapped_ratio",
1591 .data
= &sysctl_min_unmapped_ratio
,
1592 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1594 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1596 .extra2
= &one_hundred
,
1599 .procname
= "min_slab_ratio",
1600 .data
= &sysctl_min_slab_ratio
,
1601 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1603 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1605 .extra2
= &one_hundred
,
1610 .procname
= "stat_interval",
1611 .data
= &sysctl_stat_interval
,
1612 .maxlen
= sizeof(sysctl_stat_interval
),
1614 .proc_handler
= proc_dointvec_jiffies
,
1617 .procname
= "stat_refresh",
1621 .proc_handler
= vmstat_refresh
,
1626 .procname
= "mmap_min_addr",
1627 .data
= &dac_mmap_min_addr
,
1628 .maxlen
= sizeof(unsigned long),
1630 .proc_handler
= mmap_min_addr_handler
,
1635 .procname
= "numa_zonelist_order",
1636 .data
= &numa_zonelist_order
,
1637 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1639 .proc_handler
= numa_zonelist_order_handler
,
1642 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1643 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1645 .procname
= "vdso_enabled",
1646 #ifdef CONFIG_X86_32
1647 .data
= &vdso32_enabled
,
1648 .maxlen
= sizeof(vdso32_enabled
),
1650 .data
= &vdso_enabled
,
1651 .maxlen
= sizeof(vdso_enabled
),
1654 .proc_handler
= proc_dointvec
,
1658 #ifdef CONFIG_HIGHMEM
1660 .procname
= "highmem_is_dirtyable",
1661 .data
= &vm_highmem_is_dirtyable
,
1662 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1664 .proc_handler
= proc_dointvec_minmax
,
1669 #ifdef CONFIG_MEMORY_FAILURE
1671 .procname
= "memory_failure_early_kill",
1672 .data
= &sysctl_memory_failure_early_kill
,
1673 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1675 .proc_handler
= proc_dointvec_minmax
,
1680 .procname
= "memory_failure_recovery",
1681 .data
= &sysctl_memory_failure_recovery
,
1682 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1684 .proc_handler
= proc_dointvec_minmax
,
1690 .procname
= "user_reserve_kbytes",
1691 .data
= &sysctl_user_reserve_kbytes
,
1692 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1694 .proc_handler
= proc_doulongvec_minmax
,
1697 .procname
= "admin_reserve_kbytes",
1698 .data
= &sysctl_admin_reserve_kbytes
,
1699 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1701 .proc_handler
= proc_doulongvec_minmax
,
1703 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1705 .procname
= "mmap_rnd_bits",
1706 .data
= &mmap_rnd_bits
,
1707 .maxlen
= sizeof(mmap_rnd_bits
),
1709 .proc_handler
= proc_dointvec_minmax
,
1710 .extra1
= (void *)&mmap_rnd_bits_min
,
1711 .extra2
= (void *)&mmap_rnd_bits_max
,
1714 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1716 .procname
= "mmap_rnd_compat_bits",
1717 .data
= &mmap_rnd_compat_bits
,
1718 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1720 .proc_handler
= proc_dointvec_minmax
,
1721 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1722 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1725 #ifdef CONFIG_USERFAULTFD
1727 .procname
= "unprivileged_userfaultfd",
1728 .data
= &sysctl_unprivileged_userfaultfd
,
1729 .maxlen
= sizeof(sysctl_unprivileged_userfaultfd
),
1731 .proc_handler
= proc_dointvec_minmax
,
1739 static struct ctl_table fs_table
[] = {
1741 .procname
= "inode-nr",
1742 .data
= &inodes_stat
,
1743 .maxlen
= 2*sizeof(long),
1745 .proc_handler
= proc_nr_inodes
,
1748 .procname
= "inode-state",
1749 .data
= &inodes_stat
,
1750 .maxlen
= 7*sizeof(long),
1752 .proc_handler
= proc_nr_inodes
,
1755 .procname
= "file-nr",
1756 .data
= &files_stat
,
1757 .maxlen
= sizeof(files_stat
),
1759 .proc_handler
= proc_nr_files
,
1762 .procname
= "file-max",
1763 .data
= &files_stat
.max_files
,
1764 .maxlen
= sizeof(files_stat
.max_files
),
1766 .proc_handler
= proc_doulongvec_minmax
,
1768 .extra2
= &long_max
,
1771 .procname
= "nr_open",
1772 .data
= &sysctl_nr_open
,
1773 .maxlen
= sizeof(unsigned int),
1775 .proc_handler
= proc_dointvec_minmax
,
1776 .extra1
= &sysctl_nr_open_min
,
1777 .extra2
= &sysctl_nr_open_max
,
1780 .procname
= "dentry-state",
1781 .data
= &dentry_stat
,
1782 .maxlen
= 6*sizeof(long),
1784 .proc_handler
= proc_nr_dentry
,
1787 .procname
= "overflowuid",
1788 .data
= &fs_overflowuid
,
1789 .maxlen
= sizeof(int),
1791 .proc_handler
= proc_dointvec_minmax
,
1792 .extra1
= &minolduid
,
1793 .extra2
= &maxolduid
,
1796 .procname
= "overflowgid",
1797 .data
= &fs_overflowgid
,
1798 .maxlen
= sizeof(int),
1800 .proc_handler
= proc_dointvec_minmax
,
1801 .extra1
= &minolduid
,
1802 .extra2
= &maxolduid
,
1804 #ifdef CONFIG_FILE_LOCKING
1806 .procname
= "leases-enable",
1807 .data
= &leases_enable
,
1808 .maxlen
= sizeof(int),
1810 .proc_handler
= proc_dointvec
,
1813 #ifdef CONFIG_DNOTIFY
1815 .procname
= "dir-notify-enable",
1816 .data
= &dir_notify_enable
,
1817 .maxlen
= sizeof(int),
1819 .proc_handler
= proc_dointvec
,
1823 #ifdef CONFIG_FILE_LOCKING
1825 .procname
= "lease-break-time",
1826 .data
= &lease_break_time
,
1827 .maxlen
= sizeof(int),
1829 .proc_handler
= proc_dointvec
,
1834 .procname
= "aio-nr",
1836 .maxlen
= sizeof(aio_nr
),
1838 .proc_handler
= proc_doulongvec_minmax
,
1841 .procname
= "aio-max-nr",
1842 .data
= &aio_max_nr
,
1843 .maxlen
= sizeof(aio_max_nr
),
1845 .proc_handler
= proc_doulongvec_minmax
,
1847 #endif /* CONFIG_AIO */
1848 #ifdef CONFIG_INOTIFY_USER
1850 .procname
= "inotify",
1852 .child
= inotify_table
,
1857 .procname
= "epoll",
1859 .child
= epoll_table
,
1864 .procname
= "protected_symlinks",
1865 .data
= &sysctl_protected_symlinks
,
1866 .maxlen
= sizeof(int),
1868 .proc_handler
= proc_dointvec_minmax
,
1873 .procname
= "protected_hardlinks",
1874 .data
= &sysctl_protected_hardlinks
,
1875 .maxlen
= sizeof(int),
1877 .proc_handler
= proc_dointvec_minmax
,
1882 .procname
= "protected_fifos",
1883 .data
= &sysctl_protected_fifos
,
1884 .maxlen
= sizeof(int),
1886 .proc_handler
= proc_dointvec_minmax
,
1891 .procname
= "protected_regular",
1892 .data
= &sysctl_protected_regular
,
1893 .maxlen
= sizeof(int),
1895 .proc_handler
= proc_dointvec_minmax
,
1900 .procname
= "suid_dumpable",
1901 .data
= &suid_dumpable
,
1902 .maxlen
= sizeof(int),
1904 .proc_handler
= proc_dointvec_minmax_coredump
,
1908 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1910 .procname
= "binfmt_misc",
1912 .child
= sysctl_mount_point
,
1916 .procname
= "pipe-max-size",
1917 .data
= &pipe_max_size
,
1918 .maxlen
= sizeof(pipe_max_size
),
1920 .proc_handler
= proc_dopipe_max_size
,
1923 .procname
= "pipe-user-pages-hard",
1924 .data
= &pipe_user_pages_hard
,
1925 .maxlen
= sizeof(pipe_user_pages_hard
),
1927 .proc_handler
= proc_doulongvec_minmax
,
1930 .procname
= "pipe-user-pages-soft",
1931 .data
= &pipe_user_pages_soft
,
1932 .maxlen
= sizeof(pipe_user_pages_soft
),
1934 .proc_handler
= proc_doulongvec_minmax
,
1937 .procname
= "mount-max",
1938 .data
= &sysctl_mount_max
,
1939 .maxlen
= sizeof(unsigned int),
1941 .proc_handler
= proc_dointvec_minmax
,
1947 static struct ctl_table debug_table
[] = {
1948 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1950 .procname
= "exception-trace",
1951 .data
= &show_unhandled_signals
,
1952 .maxlen
= sizeof(int),
1954 .proc_handler
= proc_dointvec
1957 #if defined(CONFIG_OPTPROBES)
1959 .procname
= "kprobes-optimization",
1960 .data
= &sysctl_kprobes_optimization
,
1961 .maxlen
= sizeof(int),
1963 .proc_handler
= proc_kprobes_optimization_handler
,
1971 static struct ctl_table dev_table
[] = {
1975 int __init
sysctl_init(void)
1977 struct ctl_table_header
*hdr
;
1979 hdr
= register_sysctl_table(sysctl_base_table
);
1980 kmemleak_not_leak(hdr
);
1984 #endif /* CONFIG_SYSCTL */
1990 #ifdef CONFIG_PROC_SYSCTL
1992 static int _proc_do_string(char *data
, int maxlen
, int write
,
1993 char __user
*buffer
,
1994 size_t *lenp
, loff_t
*ppos
)
2000 if (!data
|| !maxlen
|| !*lenp
) {
2006 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
2007 /* Only continue writes not past the end of buffer. */
2009 if (len
> maxlen
- 1)
2016 /* Start writing from beginning of buffer. */
2022 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
2023 if (get_user(c
, p
++))
2025 if (c
== 0 || c
== '\n')
2046 if (copy_to_user(buffer
, data
, len
))
2049 if (put_user('\n', buffer
+ len
))
2059 static void warn_sysctl_write(struct ctl_table
*table
)
2061 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2062 "This will not be supported in the future. To silence this\n"
2063 "warning, set kernel.sysctl_writes_strict = -1\n",
2064 current
->comm
, table
->procname
);
2068 * proc_first_pos_non_zero_ignore - check if first position is allowed
2069 * @ppos: file position
2070 * @table: the sysctl table
2072 * Returns true if the first position is non-zero and the sysctl_writes_strict
2073 * mode indicates this is not allowed for numeric input types. String proc
2074 * handlers can ignore the return value.
2076 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
2077 struct ctl_table
*table
)
2082 switch (sysctl_writes_strict
) {
2083 case SYSCTL_WRITES_STRICT
:
2085 case SYSCTL_WRITES_WARN
:
2086 warn_sysctl_write(table
);
2094 * proc_dostring - read a string sysctl
2095 * @table: the sysctl table
2096 * @write: %TRUE if this is a write to the sysctl file
2097 * @buffer: the user buffer
2098 * @lenp: the size of the user buffer
2099 * @ppos: file position
2101 * Reads/writes a string from/to the user buffer. If the kernel
2102 * buffer provided is not large enough to hold the string, the
2103 * string is truncated. The copied string is %NULL-terminated.
2104 * If the string is being read by the user process, it is copied
2105 * and a newline '\n' is added. It is truncated if the buffer is
2108 * Returns 0 on success.
2110 int proc_dostring(struct ctl_table
*table
, int write
,
2111 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2114 proc_first_pos_non_zero_ignore(ppos
, table
);
2116 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2117 (char __user
*)buffer
, lenp
, ppos
);
2120 static size_t proc_skip_spaces(char **buf
)
2123 char *tmp
= skip_spaces(*buf
);
2129 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2140 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2143 * @cp: kernel buffer containing the string to parse
2144 * @endp: pointer to store the trailing characters
2145 * @base: the base to use
2146 * @res: where the parsed integer will be stored
2148 * In case of success 0 is returned and @res will contain the parsed integer,
2149 * @endp will hold any trailing characters.
2150 * This function will fail the parse on overflow. If there wasn't an overflow
2151 * the function will defer the decision what characters count as invalid to the
2154 static int strtoul_lenient(const char *cp
, char **endp
, unsigned int base
,
2157 unsigned long long result
;
2160 cp
= _parse_integer_fixup_radix(cp
, &base
);
2161 rv
= _parse_integer(cp
, base
, &result
);
2162 if ((rv
& KSTRTOX_OVERFLOW
) || (result
!= (unsigned long)result
))
2170 *res
= (unsigned long)result
;
2174 #define TMPBUFLEN 22
2176 * proc_get_long - reads an ASCII formatted integer from a user buffer
2178 * @buf: a kernel buffer
2179 * @size: size of the kernel buffer
2180 * @val: this is where the number will be stored
2181 * @neg: set to %TRUE if number is negative
2182 * @perm_tr: a vector which contains the allowed trailers
2183 * @perm_tr_len: size of the perm_tr vector
2184 * @tr: pointer to store the trailer character
2186 * In case of success %0 is returned and @buf and @size are updated with
2187 * the amount of bytes read. If @tr is non-NULL and a trailing
2188 * character exists (size is non-zero after returning from this
2189 * function), @tr is updated with the trailing character.
2191 static int proc_get_long(char **buf
, size_t *size
,
2192 unsigned long *val
, bool *neg
,
2193 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2196 char *p
, tmp
[TMPBUFLEN
];
2202 if (len
> TMPBUFLEN
- 1)
2203 len
= TMPBUFLEN
- 1;
2205 memcpy(tmp
, *buf
, len
);
2209 if (*p
== '-' && *size
> 1) {
2217 if (strtoul_lenient(p
, &p
, 0, val
))
2222 /* We don't know if the next char is whitespace thus we may accept
2223 * invalid integers (e.g. 1234...a) or two integers instead of one
2224 * (e.g. 123...1). So lets not allow such large numbers. */
2225 if (len
== TMPBUFLEN
- 1)
2228 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2231 if (tr
&& (len
< *size
))
2241 * proc_put_long - converts an integer to a decimal ASCII formatted string
2243 * @buf: the user buffer
2244 * @size: the size of the user buffer
2245 * @val: the integer to be converted
2246 * @neg: sign of the number, %TRUE for negative
2248 * In case of success %0 is returned and @buf and @size are updated with
2249 * the amount of bytes written.
2251 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2255 char tmp
[TMPBUFLEN
], *p
= tmp
;
2257 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2261 if (copy_to_user(*buf
, tmp
, len
))
2269 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2272 char __user
**buffer
= (char __user
**)buf
;
2273 if (put_user(c
, *buffer
))
2275 (*size
)--, (*buffer
)++;
2281 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2283 int write
, void *data
)
2287 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2291 if (*lvalp
> (unsigned long) INT_MAX
)
2299 *lvalp
= -(unsigned long)val
;
2302 *lvalp
= (unsigned long)val
;
2308 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2310 int write
, void *data
)
2313 if (*lvalp
> UINT_MAX
)
2317 unsigned int val
= *valp
;
2318 *lvalp
= (unsigned long)val
;
2323 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2325 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2326 int write
, void __user
*buffer
,
2327 size_t *lenp
, loff_t
*ppos
,
2328 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2329 int write
, void *data
),
2332 int *i
, vleft
, first
= 1, err
= 0;
2334 char *kbuf
= NULL
, *p
;
2336 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2341 i
= (int *) tbl_data
;
2342 vleft
= table
->maxlen
/ sizeof(*i
);
2346 conv
= do_proc_dointvec_conv
;
2349 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2352 if (left
> PAGE_SIZE
- 1)
2353 left
= PAGE_SIZE
- 1;
2354 p
= kbuf
= memdup_user_nul(buffer
, left
);
2356 return PTR_ERR(kbuf
);
2359 for (; left
&& vleft
--; i
++, first
=0) {
2364 left
-= proc_skip_spaces(&p
);
2368 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2370 sizeof(proc_wspace_sep
), NULL
);
2373 if (conv(&neg
, &lval
, i
, 1, data
)) {
2378 if (conv(&neg
, &lval
, i
, 0, data
)) {
2383 err
= proc_put_char(&buffer
, &left
, '\t');
2386 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2392 if (!write
&& !first
&& left
&& !err
)
2393 err
= proc_put_char(&buffer
, &left
, '\n');
2394 if (write
&& !err
&& left
)
2395 left
-= proc_skip_spaces(&p
);
2399 return err
? : -EINVAL
;
2407 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2408 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2409 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2410 int write
, void *data
),
2413 return __do_proc_dointvec(table
->data
, table
, write
,
2414 buffer
, lenp
, ppos
, conv
, data
);
2417 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2418 struct ctl_table
*table
,
2419 void __user
*buffer
,
2420 size_t *lenp
, loff_t
*ppos
,
2421 int (*conv
)(unsigned long *lvalp
,
2423 int write
, void *data
),
2430 char *kbuf
= NULL
, *p
;
2434 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2437 if (left
> PAGE_SIZE
- 1)
2438 left
= PAGE_SIZE
- 1;
2440 p
= kbuf
= memdup_user_nul(buffer
, left
);
2444 left
-= proc_skip_spaces(&p
);
2450 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2452 sizeof(proc_wspace_sep
), NULL
);
2458 if (conv(&lval
, tbl_data
, 1, data
)) {
2464 left
-= proc_skip_spaces(&p
);
2473 /* This is in keeping with old __do_proc_dointvec() */
2479 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2480 size_t *lenp
, loff_t
*ppos
,
2481 int (*conv
)(unsigned long *lvalp
,
2483 int write
, void *data
),
2492 if (conv(&lval
, tbl_data
, 0, data
)) {
2497 err
= proc_put_long(&buffer
, &left
, lval
, false);
2501 err
= proc_put_char(&buffer
, &left
, '\n');
2510 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2511 int write
, void __user
*buffer
,
2512 size_t *lenp
, loff_t
*ppos
,
2513 int (*conv
)(unsigned long *lvalp
,
2515 int write
, void *data
),
2518 unsigned int *i
, vleft
;
2520 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2525 i
= (unsigned int *) tbl_data
;
2526 vleft
= table
->maxlen
/ sizeof(*i
);
2529 * Arrays are not supported, keep this simple. *Do not* add
2538 conv
= do_proc_douintvec_conv
;
2541 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2543 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2546 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2547 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2548 int (*conv
)(unsigned long *lvalp
,
2550 int write
, void *data
),
2553 return __do_proc_douintvec(table
->data
, table
, write
,
2554 buffer
, lenp
, ppos
, conv
, data
);
2558 * proc_dointvec - read a vector of integers
2559 * @table: the sysctl table
2560 * @write: %TRUE if this is a write to the sysctl file
2561 * @buffer: the user buffer
2562 * @lenp: the size of the user buffer
2563 * @ppos: file position
2565 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2566 * values from/to the user buffer, treated as an ASCII string.
2568 * Returns 0 on success.
2570 int proc_dointvec(struct ctl_table
*table
, int write
,
2571 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2573 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2577 * proc_douintvec - read a vector of unsigned integers
2578 * @table: the sysctl table
2579 * @write: %TRUE if this is a write to the sysctl file
2580 * @buffer: the user buffer
2581 * @lenp: the size of the user buffer
2582 * @ppos: file position
2584 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2585 * values from/to the user buffer, treated as an ASCII string.
2587 * Returns 0 on success.
2589 int proc_douintvec(struct ctl_table
*table
, int write
,
2590 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2592 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2593 do_proc_douintvec_conv
, NULL
);
2597 * Taint values can only be increased
2598 * This means we can safely use a temporary.
2600 static int proc_taint(struct ctl_table
*table
, int write
,
2601 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2604 unsigned long tmptaint
= get_taint();
2607 if (write
&& !capable(CAP_SYS_ADMIN
))
2612 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2618 * Poor man's atomic or. Not worth adding a primitive
2619 * to everyone's atomic.h for this
2622 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2623 if ((tmptaint
>> i
) & 1)
2624 add_taint(i
, LOCKDEP_STILL_OK
);
2631 #ifdef CONFIG_PRINTK
2632 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2633 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2635 if (write
&& !capable(CAP_SYS_ADMIN
))
2638 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2643 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2644 * @min: pointer to minimum allowable value
2645 * @max: pointer to maximum allowable value
2647 * The do_proc_dointvec_minmax_conv_param structure provides the
2648 * minimum and maximum values for doing range checking for those sysctl
2649 * parameters that use the proc_dointvec_minmax() handler.
2651 struct do_proc_dointvec_minmax_conv_param
{
2656 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2658 int write
, void *data
)
2661 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2663 * If writing, first do so via a temporary local int so we can
2664 * bounds-check it before touching *valp.
2666 int *ip
= write
? &tmp
: valp
;
2668 ret
= do_proc_dointvec_conv(negp
, lvalp
, ip
, write
, data
);
2673 if ((param
->min
&& *param
->min
> tmp
) ||
2674 (param
->max
&& *param
->max
< tmp
))
2683 * proc_dointvec_minmax - read a vector of integers with min/max values
2684 * @table: the sysctl table
2685 * @write: %TRUE if this is a write to the sysctl file
2686 * @buffer: the user buffer
2687 * @lenp: the size of the user buffer
2688 * @ppos: file position
2690 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2691 * values from/to the user buffer, treated as an ASCII string.
2693 * This routine will ensure the values are within the range specified by
2694 * table->extra1 (min) and table->extra2 (max).
2696 * Returns 0 on success or -EINVAL on write when the range check fails.
2698 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2699 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2701 struct do_proc_dointvec_minmax_conv_param param
= {
2702 .min
= (int *) table
->extra1
,
2703 .max
= (int *) table
->extra2
,
2705 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2706 do_proc_dointvec_minmax_conv
, ¶m
);
2710 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2711 * @min: pointer to minimum allowable value
2712 * @max: pointer to maximum allowable value
2714 * The do_proc_douintvec_minmax_conv_param structure provides the
2715 * minimum and maximum values for doing range checking for those sysctl
2716 * parameters that use the proc_douintvec_minmax() handler.
2718 struct do_proc_douintvec_minmax_conv_param
{
2723 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp
,
2725 int write
, void *data
)
2729 struct do_proc_douintvec_minmax_conv_param
*param
= data
;
2730 /* write via temporary local uint for bounds-checking */
2731 unsigned int *up
= write
? &tmp
: valp
;
2733 ret
= do_proc_douintvec_conv(lvalp
, up
, write
, data
);
2738 if ((param
->min
&& *param
->min
> tmp
) ||
2739 (param
->max
&& *param
->max
< tmp
))
2749 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2750 * @table: the sysctl table
2751 * @write: %TRUE if this is a write to the sysctl file
2752 * @buffer: the user buffer
2753 * @lenp: the size of the user buffer
2754 * @ppos: file position
2756 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2757 * values from/to the user buffer, treated as an ASCII string. Negative
2758 * strings are not allowed.
2760 * This routine will ensure the values are within the range specified by
2761 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2762 * check for UINT_MAX to avoid having to support wrap around uses from
2765 * Returns 0 on success or -ERANGE on write when the range check fails.
2767 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
2768 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2770 struct do_proc_douintvec_minmax_conv_param param
= {
2771 .min
= (unsigned int *) table
->extra1
,
2772 .max
= (unsigned int *) table
->extra2
,
2774 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2775 do_proc_douintvec_minmax_conv
, ¶m
);
2778 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp
,
2780 int write
, void *data
)
2785 val
= round_pipe_size(*lvalp
);
2791 unsigned int val
= *valp
;
2792 *lvalp
= (unsigned long) val
;
2798 static int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
2799 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2801 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2802 do_proc_dopipe_max_size_conv
, NULL
);
2805 static void validate_coredump_safety(void)
2807 #ifdef CONFIG_COREDUMP
2808 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2809 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2811 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2812 "Pipe handler or fully qualified core dump path required.\n"
2813 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2819 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2820 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2822 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2824 validate_coredump_safety();
2828 #ifdef CONFIG_COREDUMP
2829 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2830 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2832 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2834 validate_coredump_safety();
2839 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2840 void __user
*buffer
,
2841 size_t *lenp
, loff_t
*ppos
,
2842 unsigned long convmul
,
2843 unsigned long convdiv
)
2845 unsigned long *i
, *min
, *max
;
2846 int vleft
, first
= 1, err
= 0;
2848 char *kbuf
= NULL
, *p
;
2850 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2855 i
= (unsigned long *) data
;
2856 min
= (unsigned long *) table
->extra1
;
2857 max
= (unsigned long *) table
->extra2
;
2858 vleft
= table
->maxlen
/ sizeof(unsigned long);
2862 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2865 if (left
> PAGE_SIZE
- 1)
2866 left
= PAGE_SIZE
- 1;
2867 p
= kbuf
= memdup_user_nul(buffer
, left
);
2869 return PTR_ERR(kbuf
);
2872 for (; left
&& vleft
--; i
++, first
= 0) {
2878 left
-= proc_skip_spaces(&p
);
2882 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2884 sizeof(proc_wspace_sep
), NULL
);
2889 val
= convmul
* val
/ convdiv
;
2890 if ((min
&& val
< *min
) || (max
&& val
> *max
)) {
2896 val
= convdiv
* (*i
) / convmul
;
2898 err
= proc_put_char(&buffer
, &left
, '\t');
2902 err
= proc_put_long(&buffer
, &left
, val
, false);
2908 if (!write
&& !first
&& left
&& !err
)
2909 err
= proc_put_char(&buffer
, &left
, '\n');
2911 left
-= proc_skip_spaces(&p
);
2915 return err
? : -EINVAL
;
2923 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2924 void __user
*buffer
,
2925 size_t *lenp
, loff_t
*ppos
,
2926 unsigned long convmul
,
2927 unsigned long convdiv
)
2929 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2930 buffer
, lenp
, ppos
, convmul
, convdiv
);
2934 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2935 * @table: the sysctl table
2936 * @write: %TRUE if this is a write to the sysctl file
2937 * @buffer: the user buffer
2938 * @lenp: the size of the user buffer
2939 * @ppos: file position
2941 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2942 * values from/to the user buffer, treated as an ASCII string.
2944 * This routine will ensure the values are within the range specified by
2945 * table->extra1 (min) and table->extra2 (max).
2947 * Returns 0 on success.
2949 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2950 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2952 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2956 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2957 * @table: the sysctl table
2958 * @write: %TRUE if this is a write to the sysctl file
2959 * @buffer: the user buffer
2960 * @lenp: the size of the user buffer
2961 * @ppos: file position
2963 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2964 * values from/to the user buffer, treated as an ASCII string. The values
2965 * are treated as milliseconds, and converted to jiffies when they are stored.
2967 * This routine will ensure the values are within the range specified by
2968 * table->extra1 (min) and table->extra2 (max).
2970 * Returns 0 on success.
2972 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2973 void __user
*buffer
,
2974 size_t *lenp
, loff_t
*ppos
)
2976 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2977 lenp
, ppos
, HZ
, 1000l);
2981 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2983 int write
, void *data
)
2986 if (*lvalp
> INT_MAX
/ HZ
)
2988 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2994 lval
= -(unsigned long)val
;
2997 lval
= (unsigned long)val
;
3004 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
3006 int write
, void *data
)
3009 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
3011 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
3017 lval
= -(unsigned long)val
;
3020 lval
= (unsigned long)val
;
3022 *lvalp
= jiffies_to_clock_t(lval
);
3027 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
3029 int write
, void *data
)
3032 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
3042 lval
= -(unsigned long)val
;
3045 lval
= (unsigned long)val
;
3047 *lvalp
= jiffies_to_msecs(lval
);
3053 * proc_dointvec_jiffies - read a vector of integers as seconds
3054 * @table: the sysctl table
3055 * @write: %TRUE if this is a write to the sysctl file
3056 * @buffer: the user buffer
3057 * @lenp: the size of the user buffer
3058 * @ppos: file position
3060 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3061 * values from/to the user buffer, treated as an ASCII string.
3062 * The values read are assumed to be in seconds, and are converted into
3065 * Returns 0 on success.
3067 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3068 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3070 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
3071 do_proc_dointvec_jiffies_conv
,NULL
);
3075 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3076 * @table: the sysctl table
3077 * @write: %TRUE if this is a write to the sysctl file
3078 * @buffer: the user buffer
3079 * @lenp: the size of the user buffer
3080 * @ppos: pointer to the file position
3082 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3083 * values from/to the user buffer, treated as an ASCII string.
3084 * The values read are assumed to be in 1/USER_HZ seconds, and
3085 * are converted into jiffies.
3087 * Returns 0 on success.
3089 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3090 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3092 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
3093 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
3097 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3098 * @table: the sysctl table
3099 * @write: %TRUE if this is a write to the sysctl file
3100 * @buffer: the user buffer
3101 * @lenp: the size of the user buffer
3102 * @ppos: file position
3103 * @ppos: the current position in the file
3105 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3106 * values from/to the user buffer, treated as an ASCII string.
3107 * The values read are assumed to be in 1/1000 seconds, and
3108 * are converted into jiffies.
3110 * Returns 0 on success.
3112 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3113 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3115 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
3116 do_proc_dointvec_ms_jiffies_conv
, NULL
);
3119 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
3120 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3122 struct pid
*new_pid
;
3126 tmp
= pid_vnr(cad_pid
);
3128 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
3129 lenp
, ppos
, NULL
, NULL
);
3133 new_pid
= find_get_pid(tmp
);
3137 put_pid(xchg(&cad_pid
, new_pid
));
3142 * proc_do_large_bitmap - read/write from/to a large bitmap
3143 * @table: the sysctl table
3144 * @write: %TRUE if this is a write to the sysctl file
3145 * @buffer: the user buffer
3146 * @lenp: the size of the user buffer
3147 * @ppos: file position
3149 * The bitmap is stored at table->data and the bitmap length (in bits)
3152 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3153 * large bitmaps may be represented in a compact manner. Writing into
3154 * the file will clear the bitmap then update it with the given input.
3156 * Returns 0 on success.
3158 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3159 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3163 size_t left
= *lenp
;
3164 unsigned long bitmap_len
= table
->maxlen
;
3165 unsigned long *bitmap
= *(unsigned long **) table
->data
;
3166 unsigned long *tmp_bitmap
= NULL
;
3167 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
3169 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3178 if (left
> PAGE_SIZE
- 1) {
3179 left
= PAGE_SIZE
- 1;
3180 /* How much of the buffer we'll skip this pass */
3181 skipped
= *lenp
- left
;
3184 p
= kbuf
= memdup_user_nul(buffer
, left
);
3186 return PTR_ERR(kbuf
);
3188 tmp_bitmap
= bitmap_zalloc(bitmap_len
, GFP_KERNEL
);
3193 proc_skip_char(&p
, &left
, '\n');
3194 while (!err
&& left
) {
3195 unsigned long val_a
, val_b
;
3199 /* In case we stop parsing mid-number, we can reset */
3201 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3204 * If we consumed the entirety of a truncated buffer or
3205 * only one char is left (may be a "-"), then stop here,
3206 * reset, & come back for more.
3208 if ((left
<= 1) && skipped
) {
3215 if (val_a
>= bitmap_len
|| neg
) {
3227 err
= proc_get_long(&p
, &left
, &val_b
,
3228 &neg
, tr_b
, sizeof(tr_b
),
3231 * If we consumed all of a truncated buffer or
3232 * then stop here, reset, & come back for more.
3234 if (!left
&& skipped
) {
3241 if (val_b
>= bitmap_len
|| neg
||
3252 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3254 proc_skip_char(&p
, &left
, '\n');
3259 unsigned long bit_a
, bit_b
= 0;
3262 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3263 if (bit_a
>= bitmap_len
)
3265 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3269 err
= proc_put_char(&buffer
, &left
, ',');
3273 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3276 if (bit_a
!= bit_b
) {
3277 err
= proc_put_char(&buffer
, &left
, '-');
3280 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3288 err
= proc_put_char(&buffer
, &left
, '\n');
3294 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3296 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3302 bitmap_free(tmp_bitmap
);
3306 #else /* CONFIG_PROC_SYSCTL */
3308 int proc_dostring(struct ctl_table
*table
, int write
,
3309 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3314 int proc_dointvec(struct ctl_table
*table
, int write
,
3315 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3320 int proc_douintvec(struct ctl_table
*table
, int write
,
3321 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3326 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3327 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3332 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3333 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3338 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3339 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3344 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3345 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3350 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3351 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3356 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3357 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3362 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3363 void __user
*buffer
,
3364 size_t *lenp
, loff_t
*ppos
)
3369 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3370 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3375 #endif /* CONFIG_PROC_SYSCTL */
3377 #if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL)
3378 static int proc_dointvec_minmax_bpf_stats(struct ctl_table
*table
, int write
,
3379 void __user
*buffer
, size_t *lenp
,
3382 int ret
, bpf_stats
= *(int *)table
->data
;
3383 struct ctl_table tmp
= *table
;
3385 if (write
&& !capable(CAP_SYS_ADMIN
))
3388 tmp
.data
= &bpf_stats
;
3389 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
3390 if (write
&& !ret
) {
3391 *(int *)table
->data
= bpf_stats
;
3393 static_branch_enable(&bpf_stats_enabled_key
);
3395 static_branch_disable(&bpf_stats_enabled_key
);
3401 * No sense putting this after each symbol definition, twice,
3402 * exception granted :-)
3404 EXPORT_SYMBOL(proc_dointvec
);
3405 EXPORT_SYMBOL(proc_douintvec
);
3406 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3407 EXPORT_SYMBOL(proc_dointvec_minmax
);
3408 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3409 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3410 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3411 EXPORT_SYMBOL(proc_dostring
);
3412 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3413 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3414 EXPORT_SYMBOL(proc_do_large_bitmap
);