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;
128 static int __maybe_unused two = 2;
129 static int __maybe_unused four = 4;
130 static unsigned long zero_ul;
131 static unsigned long one_ul = 1;
132 static unsigned long long_max = LONG_MAX;
133 static int one_hundred = 100;
134 static int one_thousand = 1000;
136 static int ten_thousand = 10000;
138 #ifdef CONFIG_PERF_EVENTS
139 static int six_hundred_forty_kb = 640 * 1024;
142 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
143 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
145 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
146 static int maxolduid = 65535;
147 static int minolduid;
149 static int ngroups_max = NGROUPS_MAX;
150 static const int cap_last_cap = CAP_LAST_CAP;
153 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
154 * and hung_task_check_interval_secs
156 #ifdef CONFIG_DETECT_HUNG_TASK
157 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
160 #ifdef CONFIG_INOTIFY_USER
161 #include <linux/inotify.h>
167 extern int pwrsw_enabled;
170 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
171 extern int unaligned_enabled;
175 extern int unaligned_dump_stack;
178 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
179 extern int no_unaligned_warning;
182 #ifdef CONFIG_PROC_SYSCTL
185 * enum sysctl_writes_mode - supported sysctl write modes
187 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
188 * to be written, and multiple writes on the same sysctl file descriptor
189 * will rewrite the sysctl value, regardless of file position. No warning
190 * is issued when the initial position is not 0.
191 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
193 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
194 * file position 0 and the value must be fully contained in the buffer
195 * sent to the write syscall. If dealing with strings respect the file
196 * position, but restrict this to the max length of the buffer, anything
197 * passed the max length will be ignored. Multiple writes will append
200 * These write modes control how current file position affects the behavior of
201 * updating sysctl values through the proc interface on each write.
203 enum sysctl_writes_mode {
204 SYSCTL_WRITES_LEGACY = -1,
205 SYSCTL_WRITES_WARN = 0,
206 SYSCTL_WRITES_STRICT = 1,
209 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
211 static int proc_do_cad_pid(struct ctl_table *table, int write,
212 void __user *buffer, size_t *lenp, loff_t *ppos);
213 static int proc_taint(struct ctl_table *table, int write,
214 void __user *buffer, size_t *lenp, loff_t *ppos);
218 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
219 void __user *buffer, size_t *lenp, loff_t *ppos);
222 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
223 void __user *buffer, size_t *lenp, loff_t *ppos);
224 #ifdef CONFIG_COREDUMP
225 static int proc_dostring_coredump(struct ctl_table *table, int write,
226 void __user *buffer, size_t *lenp, loff_t *ppos);
228 static int proc_dopipe_max_size(struct ctl_table *table, int write,
229 void __user *buffer, size_t *lenp, loff_t *ppos);
231 #ifdef CONFIG_MAGIC_SYSRQ
232 /* Note: sysrq code uses its own private copy */
233 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
235 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
236 void __user *buffer, size_t *lenp,
241 error = proc_dointvec(table, write, buffer, lenp, ppos);
246 sysrq_toggle_support(__sysrq_enabled);
253 static struct ctl_table kern_table[];
254 static struct ctl_table vm_table[];
255 static struct ctl_table fs_table[];
256 static struct ctl_table debug_table[];
257 static struct ctl_table dev_table[];
258 extern struct ctl_table random_table[];
260 extern struct ctl_table epoll_table[];
263 #ifdef CONFIG_FW_LOADER_USER_HELPER
264 extern struct ctl_table firmware_config_table[];
267 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
268 int sysctl_legacy_va_layout;
271 /* The default sysctl tables: */
273 static struct ctl_table sysctl_base_table[] = {
275 .procname = "kernel",
292 .child = debug_table,
302 #ifdef CONFIG_SCHED_DEBUG
303 static int min_sched_granularity_ns = 100000; /* 100 usecs */
304 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
305 static int min_wakeup_granularity_ns; /* 0 usecs */
306 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
308 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
309 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
310 #endif /* CONFIG_SMP */
311 #endif /* CONFIG_SCHED_DEBUG */
313 #ifdef CONFIG_COMPACTION
314 static int min_extfrag_threshold;
315 static int max_extfrag_threshold = 1000;
318 static struct ctl_table kern_table[] = {
320 .procname = "sched_child_runs_first",
321 .data = &sysctl_sched_child_runs_first,
322 .maxlen = sizeof(unsigned int),
324 .proc_handler = proc_dointvec,
326 #ifdef CONFIG_SCHED_DEBUG
328 .procname = "sched_min_granularity_ns",
329 .data = &sysctl_sched_min_granularity,
330 .maxlen = sizeof(unsigned int),
332 .proc_handler = sched_proc_update_handler,
333 .extra1 = &min_sched_granularity_ns,
334 .extra2 = &max_sched_granularity_ns,
337 .procname = "sched_latency_ns",
338 .data = &sysctl_sched_latency,
339 .maxlen = sizeof(unsigned int),
341 .proc_handler = sched_proc_update_handler,
342 .extra1 = &min_sched_granularity_ns,
343 .extra2 = &max_sched_granularity_ns,
346 .procname = "sched_wakeup_granularity_ns",
347 .data = &sysctl_sched_wakeup_granularity,
348 .maxlen = sizeof(unsigned int),
350 .proc_handler = sched_proc_update_handler,
351 .extra1 = &min_wakeup_granularity_ns,
352 .extra2 = &max_wakeup_granularity_ns,
356 .procname = "sched_tunable_scaling",
357 .data = &sysctl_sched_tunable_scaling,
358 .maxlen = sizeof(enum sched_tunable_scaling),
360 .proc_handler = sched_proc_update_handler,
361 .extra1 = &min_sched_tunable_scaling,
362 .extra2 = &max_sched_tunable_scaling,
365 .procname = "sched_migration_cost_ns",
366 .data = &sysctl_sched_migration_cost,
367 .maxlen = sizeof(unsigned int),
369 .proc_handler = proc_dointvec,
372 .procname = "sched_nr_migrate",
373 .data = &sysctl_sched_nr_migrate,
374 .maxlen = sizeof(unsigned int),
376 .proc_handler = proc_dointvec,
378 #ifdef CONFIG_SCHEDSTATS
380 .procname = "sched_schedstats",
382 .maxlen = sizeof(unsigned int),
384 .proc_handler = sysctl_schedstats,
385 .extra1 = SYSCTL_ZERO,
386 .extra2 = SYSCTL_ONE,
388 #endif /* CONFIG_SCHEDSTATS */
389 #endif /* CONFIG_SMP */
390 #ifdef CONFIG_NUMA_BALANCING
392 .procname = "numa_balancing_scan_delay_ms",
393 .data = &sysctl_numa_balancing_scan_delay,
394 .maxlen = sizeof(unsigned int),
396 .proc_handler = proc_dointvec,
399 .procname = "numa_balancing_scan_period_min_ms",
400 .data = &sysctl_numa_balancing_scan_period_min,
401 .maxlen = sizeof(unsigned int),
403 .proc_handler = proc_dointvec,
406 .procname = "numa_balancing_scan_period_max_ms",
407 .data = &sysctl_numa_balancing_scan_period_max,
408 .maxlen = sizeof(unsigned int),
410 .proc_handler = proc_dointvec,
413 .procname = "numa_balancing_scan_size_mb",
414 .data = &sysctl_numa_balancing_scan_size,
415 .maxlen = sizeof(unsigned int),
417 .proc_handler = proc_dointvec_minmax,
418 .extra1 = SYSCTL_ONE,
421 .procname = "numa_balancing",
422 .data = NULL, /* filled in by handler */
423 .maxlen = sizeof(unsigned int),
425 .proc_handler = sysctl_numa_balancing,
426 .extra1 = SYSCTL_ZERO,
427 .extra2 = SYSCTL_ONE,
429 #endif /* CONFIG_NUMA_BALANCING */
430 #endif /* CONFIG_SCHED_DEBUG */
432 .procname = "sched_rt_period_us",
433 .data = &sysctl_sched_rt_period,
434 .maxlen = sizeof(unsigned int),
436 .proc_handler = sched_rt_handler,
439 .procname = "sched_rt_runtime_us",
440 .data = &sysctl_sched_rt_runtime,
441 .maxlen = sizeof(int),
443 .proc_handler = sched_rt_handler,
446 .procname = "sched_rr_timeslice_ms",
447 .data = &sysctl_sched_rr_timeslice,
448 .maxlen = sizeof(int),
450 .proc_handler = sched_rr_handler,
452 #ifdef CONFIG_UCLAMP_TASK
454 .procname = "sched_util_clamp_min",
455 .data = &sysctl_sched_uclamp_util_min,
456 .maxlen = sizeof(unsigned int),
458 .proc_handler = sysctl_sched_uclamp_handler,
461 .procname = "sched_util_clamp_max",
462 .data = &sysctl_sched_uclamp_util_max,
463 .maxlen = sizeof(unsigned int),
465 .proc_handler = sysctl_sched_uclamp_handler,
468 #ifdef CONFIG_SCHED_AUTOGROUP
470 .procname = "sched_autogroup_enabled",
471 .data = &sysctl_sched_autogroup_enabled,
472 .maxlen = sizeof(unsigned int),
474 .proc_handler = proc_dointvec_minmax,
475 .extra1 = SYSCTL_ZERO,
476 .extra2 = SYSCTL_ONE,
479 #ifdef CONFIG_CFS_BANDWIDTH
481 .procname = "sched_cfs_bandwidth_slice_us",
482 .data = &sysctl_sched_cfs_bandwidth_slice,
483 .maxlen = sizeof(unsigned int),
485 .proc_handler = proc_dointvec_minmax,
486 .extra1 = SYSCTL_ONE,
489 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
491 .procname = "sched_energy_aware",
492 .data = &sysctl_sched_energy_aware,
493 .maxlen = sizeof(unsigned int),
495 .proc_handler = sched_energy_aware_handler,
496 .extra1 = SYSCTL_ZERO,
497 .extra2 = SYSCTL_ONE,
500 #ifdef CONFIG_PROVE_LOCKING
502 .procname = "prove_locking",
503 .data = &prove_locking,
504 .maxlen = sizeof(int),
506 .proc_handler = proc_dointvec,
509 #ifdef CONFIG_LOCK_STAT
511 .procname = "lock_stat",
513 .maxlen = sizeof(int),
515 .proc_handler = proc_dointvec,
520 .data = &panic_timeout,
521 .maxlen = sizeof(int),
523 .proc_handler = proc_dointvec,
525 #ifdef CONFIG_COREDUMP
527 .procname = "core_uses_pid",
528 .data = &core_uses_pid,
529 .maxlen = sizeof(int),
531 .proc_handler = proc_dointvec,
534 .procname = "core_pattern",
535 .data = core_pattern,
536 .maxlen = CORENAME_MAX_SIZE,
538 .proc_handler = proc_dostring_coredump,
541 .procname = "core_pipe_limit",
542 .data = &core_pipe_limit,
543 .maxlen = sizeof(unsigned int),
545 .proc_handler = proc_dointvec,
548 #ifdef CONFIG_PROC_SYSCTL
550 .procname = "tainted",
551 .maxlen = sizeof(long),
553 .proc_handler = proc_taint,
556 .procname = "sysctl_writes_strict",
557 .data = &sysctl_writes_strict,
558 .maxlen = sizeof(int),
560 .proc_handler = proc_dointvec_minmax,
562 .extra2 = SYSCTL_ONE,
565 #ifdef CONFIG_LATENCYTOP
567 .procname = "latencytop",
568 .data = &latencytop_enabled,
569 .maxlen = sizeof(int),
571 .proc_handler = sysctl_latencytop,
574 #ifdef CONFIG_BLK_DEV_INITRD
576 .procname = "real-root-dev",
577 .data = &real_root_dev,
578 .maxlen = sizeof(int),
580 .proc_handler = proc_dointvec,
584 .procname = "print-fatal-signals",
585 .data = &print_fatal_signals,
586 .maxlen = sizeof(int),
588 .proc_handler = proc_dointvec,
592 .procname = "reboot-cmd",
593 .data = reboot_command,
596 .proc_handler = proc_dostring,
599 .procname = "stop-a",
600 .data = &stop_a_enabled,
601 .maxlen = sizeof (int),
603 .proc_handler = proc_dointvec,
606 .procname = "scons-poweroff",
607 .data = &scons_pwroff,
608 .maxlen = sizeof (int),
610 .proc_handler = proc_dointvec,
613 #ifdef CONFIG_SPARC64
615 .procname = "tsb-ratio",
616 .data = &sysctl_tsb_ratio,
617 .maxlen = sizeof (int),
619 .proc_handler = proc_dointvec,
624 .procname = "soft-power",
625 .data = &pwrsw_enabled,
626 .maxlen = sizeof (int),
628 .proc_handler = proc_dointvec,
631 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
633 .procname = "unaligned-trap",
634 .data = &unaligned_enabled,
635 .maxlen = sizeof (int),
637 .proc_handler = proc_dointvec,
641 .procname = "ctrl-alt-del",
643 .maxlen = sizeof(int),
645 .proc_handler = proc_dointvec,
647 #ifdef CONFIG_FUNCTION_TRACER
649 .procname = "ftrace_enabled",
650 .data = &ftrace_enabled,
651 .maxlen = sizeof(int),
653 .proc_handler = ftrace_enable_sysctl,
656 #ifdef CONFIG_STACK_TRACER
658 .procname = "stack_tracer_enabled",
659 .data = &stack_tracer_enabled,
660 .maxlen = sizeof(int),
662 .proc_handler = stack_trace_sysctl,
665 #ifdef CONFIG_TRACING
667 .procname = "ftrace_dump_on_oops",
668 .data = &ftrace_dump_on_oops,
669 .maxlen = sizeof(int),
671 .proc_handler = proc_dointvec,
674 .procname = "traceoff_on_warning",
675 .data = &__disable_trace_on_warning,
676 .maxlen = sizeof(__disable_trace_on_warning),
678 .proc_handler = proc_dointvec,
681 .procname = "tracepoint_printk",
682 .data = &tracepoint_printk,
683 .maxlen = sizeof(tracepoint_printk),
685 .proc_handler = tracepoint_printk_sysctl,
688 #ifdef CONFIG_KEXEC_CORE
690 .procname = "kexec_load_disabled",
691 .data = &kexec_load_disabled,
692 .maxlen = sizeof(int),
694 /* only handle a transition from default "0" to "1" */
695 .proc_handler = proc_dointvec_minmax,
696 .extra1 = SYSCTL_ONE,
697 .extra2 = SYSCTL_ONE,
700 #ifdef CONFIG_MODULES
702 .procname = "modprobe",
703 .data = &modprobe_path,
704 .maxlen = KMOD_PATH_LEN,
706 .proc_handler = proc_dostring,
709 .procname = "modules_disabled",
710 .data = &modules_disabled,
711 .maxlen = sizeof(int),
713 /* only handle a transition from default "0" to "1" */
714 .proc_handler = proc_dointvec_minmax,
715 .extra1 = SYSCTL_ONE,
716 .extra2 = SYSCTL_ONE,
719 #ifdef CONFIG_UEVENT_HELPER
721 .procname = "hotplug",
722 .data = &uevent_helper,
723 .maxlen = UEVENT_HELPER_PATH_LEN,
725 .proc_handler = proc_dostring,
728 #ifdef CONFIG_CHR_DEV_SG
730 .procname = "sg-big-buff",
731 .data = &sg_big_buff,
732 .maxlen = sizeof (int),
734 .proc_handler = proc_dointvec,
737 #ifdef CONFIG_BSD_PROCESS_ACCT
741 .maxlen = 3*sizeof(int),
743 .proc_handler = proc_dointvec,
746 #ifdef CONFIG_MAGIC_SYSRQ
749 .data = &__sysrq_enabled,
750 .maxlen = sizeof (int),
752 .proc_handler = sysrq_sysctl_handler,
755 #ifdef CONFIG_PROC_SYSCTL
757 .procname = "cad_pid",
759 .maxlen = sizeof (int),
761 .proc_handler = proc_do_cad_pid,
765 .procname = "threads-max",
767 .maxlen = sizeof(int),
769 .proc_handler = sysctl_max_threads,
772 .procname = "random",
774 .child = random_table,
777 .procname = "usermodehelper",
779 .child = usermodehelper_table,
781 #ifdef CONFIG_FW_LOADER_USER_HELPER
783 .procname = "firmware_config",
785 .child = firmware_config_table,
789 .procname = "overflowuid",
790 .data = &overflowuid,
791 .maxlen = sizeof(int),
793 .proc_handler = proc_dointvec_minmax,
794 .extra1 = &minolduid,
795 .extra2 = &maxolduid,
798 .procname = "overflowgid",
799 .data = &overflowgid,
800 .maxlen = sizeof(int),
802 .proc_handler = proc_dointvec_minmax,
803 .extra1 = &minolduid,
804 .extra2 = &maxolduid,
807 #ifdef CONFIG_MATHEMU
809 .procname = "ieee_emulation_warnings",
810 .data = &sysctl_ieee_emulation_warnings,
811 .maxlen = sizeof(int),
813 .proc_handler = proc_dointvec,
817 .procname = "userprocess_debug",
818 .data = &show_unhandled_signals,
819 .maxlen = sizeof(int),
821 .proc_handler = proc_dointvec,
825 .procname = "pid_max",
827 .maxlen = sizeof (int),
829 .proc_handler = proc_dointvec_minmax,
830 .extra1 = &pid_max_min,
831 .extra2 = &pid_max_max,
834 .procname = "panic_on_oops",
835 .data = &panic_on_oops,
836 .maxlen = sizeof(int),
838 .proc_handler = proc_dointvec,
841 .procname = "panic_print",
842 .data = &panic_print,
843 .maxlen = sizeof(unsigned long),
845 .proc_handler = proc_doulongvec_minmax,
847 #if defined CONFIG_PRINTK
849 .procname = "printk",
850 .data = &console_loglevel,
851 .maxlen = 4*sizeof(int),
853 .proc_handler = proc_dointvec,
856 .procname = "printk_ratelimit",
857 .data = &printk_ratelimit_state.interval,
858 .maxlen = sizeof(int),
860 .proc_handler = proc_dointvec_jiffies,
863 .procname = "printk_ratelimit_burst",
864 .data = &printk_ratelimit_state.burst,
865 .maxlen = sizeof(int),
867 .proc_handler = proc_dointvec,
870 .procname = "printk_delay",
871 .data = &printk_delay_msec,
872 .maxlen = sizeof(int),
874 .proc_handler = proc_dointvec_minmax,
875 .extra1 = SYSCTL_ZERO,
876 .extra2 = &ten_thousand,
879 .procname = "printk_devkmsg",
880 .data = devkmsg_log_str,
881 .maxlen = DEVKMSG_STR_MAX_SIZE,
883 .proc_handler = devkmsg_sysctl_set_loglvl,
886 .procname = "dmesg_restrict",
887 .data = &dmesg_restrict,
888 .maxlen = sizeof(int),
890 .proc_handler = proc_dointvec_minmax_sysadmin,
891 .extra1 = SYSCTL_ZERO,
892 .extra2 = SYSCTL_ONE,
895 .procname = "kptr_restrict",
896 .data = &kptr_restrict,
897 .maxlen = sizeof(int),
899 .proc_handler = proc_dointvec_minmax_sysadmin,
900 .extra1 = SYSCTL_ZERO,
905 .procname = "ngroups_max",
906 .data = &ngroups_max,
907 .maxlen = sizeof (int),
909 .proc_handler = proc_dointvec,
912 .procname = "cap_last_cap",
913 .data = (void *)&cap_last_cap,
914 .maxlen = sizeof(int),
916 .proc_handler = proc_dointvec,
918 #if defined(CONFIG_LOCKUP_DETECTOR)
920 .procname = "watchdog",
921 .data = &watchdog_user_enabled,
922 .maxlen = sizeof(int),
924 .proc_handler = proc_watchdog,
925 .extra1 = SYSCTL_ZERO,
926 .extra2 = SYSCTL_ONE,
929 .procname = "watchdog_thresh",
930 .data = &watchdog_thresh,
931 .maxlen = sizeof(int),
933 .proc_handler = proc_watchdog_thresh,
934 .extra1 = SYSCTL_ZERO,
938 .procname = "nmi_watchdog",
939 .data = &nmi_watchdog_user_enabled,
940 .maxlen = sizeof(int),
941 .mode = NMI_WATCHDOG_SYSCTL_PERM,
942 .proc_handler = proc_nmi_watchdog,
943 .extra1 = SYSCTL_ZERO,
944 .extra2 = SYSCTL_ONE,
947 .procname = "watchdog_cpumask",
948 .data = &watchdog_cpumask_bits,
951 .proc_handler = proc_watchdog_cpumask,
953 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
955 .procname = "soft_watchdog",
956 .data = &soft_watchdog_user_enabled,
957 .maxlen = sizeof(int),
959 .proc_handler = proc_soft_watchdog,
960 .extra1 = SYSCTL_ZERO,
961 .extra2 = SYSCTL_ONE,
964 .procname = "softlockup_panic",
965 .data = &softlockup_panic,
966 .maxlen = sizeof(int),
968 .proc_handler = proc_dointvec_minmax,
969 .extra1 = SYSCTL_ZERO,
970 .extra2 = SYSCTL_ONE,
974 .procname = "softlockup_all_cpu_backtrace",
975 .data = &sysctl_softlockup_all_cpu_backtrace,
976 .maxlen = sizeof(int),
978 .proc_handler = proc_dointvec_minmax,
979 .extra1 = SYSCTL_ZERO,
980 .extra2 = SYSCTL_ONE,
982 #endif /* CONFIG_SMP */
984 #ifdef CONFIG_HARDLOCKUP_DETECTOR
986 .procname = "hardlockup_panic",
987 .data = &hardlockup_panic,
988 .maxlen = sizeof(int),
990 .proc_handler = proc_dointvec_minmax,
991 .extra1 = SYSCTL_ZERO,
992 .extra2 = SYSCTL_ONE,
996 .procname = "hardlockup_all_cpu_backtrace",
997 .data = &sysctl_hardlockup_all_cpu_backtrace,
998 .maxlen = sizeof(int),
1000 .proc_handler = proc_dointvec_minmax,
1001 .extra1 = SYSCTL_ZERO,
1002 .extra2 = SYSCTL_ONE,
1004 #endif /* CONFIG_SMP */
1008 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1010 .procname = "unknown_nmi_panic",
1011 .data = &unknown_nmi_panic,
1012 .maxlen = sizeof (int),
1014 .proc_handler = proc_dointvec,
1017 #if defined(CONFIG_X86)
1019 .procname = "panic_on_unrecovered_nmi",
1020 .data = &panic_on_unrecovered_nmi,
1021 .maxlen = sizeof(int),
1023 .proc_handler = proc_dointvec,
1026 .procname = "panic_on_io_nmi",
1027 .data = &panic_on_io_nmi,
1028 .maxlen = sizeof(int),
1030 .proc_handler = proc_dointvec,
1032 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1034 .procname = "panic_on_stackoverflow",
1035 .data = &sysctl_panic_on_stackoverflow,
1036 .maxlen = sizeof(int),
1038 .proc_handler = proc_dointvec,
1042 .procname = "bootloader_type",
1043 .data = &bootloader_type,
1044 .maxlen = sizeof (int),
1046 .proc_handler = proc_dointvec,
1049 .procname = "bootloader_version",
1050 .data = &bootloader_version,
1051 .maxlen = sizeof (int),
1053 .proc_handler = proc_dointvec,
1056 .procname = "io_delay_type",
1057 .data = &io_delay_type,
1058 .maxlen = sizeof(int),
1060 .proc_handler = proc_dointvec,
1063 #if defined(CONFIG_MMU)
1065 .procname = "randomize_va_space",
1066 .data = &randomize_va_space,
1067 .maxlen = sizeof(int),
1069 .proc_handler = proc_dointvec,
1072 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1074 .procname = "spin_retry",
1075 .data = &spin_retry,
1076 .maxlen = sizeof (int),
1078 .proc_handler = proc_dointvec,
1081 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1083 .procname = "acpi_video_flags",
1084 .data = &acpi_realmode_flags,
1085 .maxlen = sizeof (unsigned long),
1087 .proc_handler = proc_doulongvec_minmax,
1090 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1092 .procname = "ignore-unaligned-usertrap",
1093 .data = &no_unaligned_warning,
1094 .maxlen = sizeof (int),
1096 .proc_handler = proc_dointvec,
1101 .procname = "unaligned-dump-stack",
1102 .data = &unaligned_dump_stack,
1103 .maxlen = sizeof (int),
1105 .proc_handler = proc_dointvec,
1108 #ifdef CONFIG_DETECT_HUNG_TASK
1110 .procname = "hung_task_panic",
1111 .data = &sysctl_hung_task_panic,
1112 .maxlen = sizeof(int),
1114 .proc_handler = proc_dointvec_minmax,
1115 .extra1 = SYSCTL_ZERO,
1116 .extra2 = SYSCTL_ONE,
1119 .procname = "hung_task_check_count",
1120 .data = &sysctl_hung_task_check_count,
1121 .maxlen = sizeof(int),
1123 .proc_handler = proc_dointvec_minmax,
1124 .extra1 = SYSCTL_ZERO,
1127 .procname = "hung_task_timeout_secs",
1128 .data = &sysctl_hung_task_timeout_secs,
1129 .maxlen = sizeof(unsigned long),
1131 .proc_handler = proc_dohung_task_timeout_secs,
1132 .extra2 = &hung_task_timeout_max,
1135 .procname = "hung_task_check_interval_secs",
1136 .data = &sysctl_hung_task_check_interval_secs,
1137 .maxlen = sizeof(unsigned long),
1139 .proc_handler = proc_dohung_task_timeout_secs,
1140 .extra2 = &hung_task_timeout_max,
1143 .procname = "hung_task_warnings",
1144 .data = &sysctl_hung_task_warnings,
1145 .maxlen = sizeof(int),
1147 .proc_handler = proc_dointvec_minmax,
1151 #ifdef CONFIG_RT_MUTEXES
1153 .procname = "max_lock_depth",
1154 .data = &max_lock_depth,
1155 .maxlen = sizeof(int),
1157 .proc_handler = proc_dointvec,
1161 .procname = "poweroff_cmd",
1162 .data = &poweroff_cmd,
1163 .maxlen = POWEROFF_CMD_PATH_LEN,
1165 .proc_handler = proc_dostring,
1171 .child = key_sysctls,
1174 #ifdef CONFIG_PERF_EVENTS
1176 * User-space scripts rely on the existence of this file
1177 * as a feature check for perf_events being enabled.
1179 * So it's an ABI, do not remove!
1182 .procname = "perf_event_paranoid",
1183 .data = &sysctl_perf_event_paranoid,
1184 .maxlen = sizeof(sysctl_perf_event_paranoid),
1186 .proc_handler = proc_dointvec,
1189 .procname = "perf_event_mlock_kb",
1190 .data = &sysctl_perf_event_mlock,
1191 .maxlen = sizeof(sysctl_perf_event_mlock),
1193 .proc_handler = proc_dointvec,
1196 .procname = "perf_event_max_sample_rate",
1197 .data = &sysctl_perf_event_sample_rate,
1198 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1200 .proc_handler = perf_proc_update_handler,
1201 .extra1 = SYSCTL_ONE,
1204 .procname = "perf_cpu_time_max_percent",
1205 .data = &sysctl_perf_cpu_time_max_percent,
1206 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1208 .proc_handler = perf_cpu_time_max_percent_handler,
1209 .extra1 = SYSCTL_ZERO,
1210 .extra2 = &one_hundred,
1213 .procname = "perf_event_max_stack",
1214 .data = &sysctl_perf_event_max_stack,
1215 .maxlen = sizeof(sysctl_perf_event_max_stack),
1217 .proc_handler = perf_event_max_stack_handler,
1218 .extra1 = SYSCTL_ZERO,
1219 .extra2 = &six_hundred_forty_kb,
1222 .procname = "perf_event_max_contexts_per_stack",
1223 .data = &sysctl_perf_event_max_contexts_per_stack,
1224 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1226 .proc_handler = perf_event_max_stack_handler,
1227 .extra1 = SYSCTL_ZERO,
1228 .extra2 = &one_thousand,
1232 .procname = "panic_on_warn",
1233 .data = &panic_on_warn,
1234 .maxlen = sizeof(int),
1236 .proc_handler = proc_dointvec_minmax,
1237 .extra1 = SYSCTL_ZERO,
1238 .extra2 = SYSCTL_ONE,
1240 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1242 .procname = "timer_migration",
1243 .data = &sysctl_timer_migration,
1244 .maxlen = sizeof(unsigned int),
1246 .proc_handler = timer_migration_handler,
1247 .extra1 = SYSCTL_ZERO,
1248 .extra2 = SYSCTL_ONE,
1251 #ifdef CONFIG_BPF_SYSCALL
1253 .procname = "unprivileged_bpf_disabled",
1254 .data = &sysctl_unprivileged_bpf_disabled,
1255 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1257 /* only handle a transition from default "0" to "1" */
1258 .proc_handler = proc_dointvec_minmax,
1259 .extra1 = SYSCTL_ONE,
1260 .extra2 = SYSCTL_ONE,
1263 .procname = "bpf_stats_enabled",
1264 .data = &bpf_stats_enabled_key.key,
1265 .maxlen = sizeof(bpf_stats_enabled_key),
1267 .proc_handler = proc_do_static_key,
1270 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1272 .procname = "panic_on_rcu_stall",
1273 .data = &sysctl_panic_on_rcu_stall,
1274 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1276 .proc_handler = proc_dointvec_minmax,
1277 .extra1 = SYSCTL_ZERO,
1278 .extra2 = SYSCTL_ONE,
1281 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1283 .procname = "stack_erasing",
1285 .maxlen = sizeof(int),
1287 .proc_handler = stack_erasing_sysctl,
1288 .extra1 = SYSCTL_ZERO,
1289 .extra2 = SYSCTL_ONE,
1295 static struct ctl_table vm_table[] = {
1297 .procname = "overcommit_memory",
1298 .data = &sysctl_overcommit_memory,
1299 .maxlen = sizeof(sysctl_overcommit_memory),
1301 .proc_handler = proc_dointvec_minmax,
1302 .extra1 = SYSCTL_ZERO,
1306 .procname = "panic_on_oom",
1307 .data = &sysctl_panic_on_oom,
1308 .maxlen = sizeof(sysctl_panic_on_oom),
1310 .proc_handler = proc_dointvec_minmax,
1311 .extra1 = SYSCTL_ZERO,
1315 .procname = "oom_kill_allocating_task",
1316 .data = &sysctl_oom_kill_allocating_task,
1317 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1319 .proc_handler = proc_dointvec,
1322 .procname = "oom_dump_tasks",
1323 .data = &sysctl_oom_dump_tasks,
1324 .maxlen = sizeof(sysctl_oom_dump_tasks),
1326 .proc_handler = proc_dointvec,
1329 .procname = "overcommit_ratio",
1330 .data = &sysctl_overcommit_ratio,
1331 .maxlen = sizeof(sysctl_overcommit_ratio),
1333 .proc_handler = overcommit_ratio_handler,
1336 .procname = "overcommit_kbytes",
1337 .data = &sysctl_overcommit_kbytes,
1338 .maxlen = sizeof(sysctl_overcommit_kbytes),
1340 .proc_handler = overcommit_kbytes_handler,
1343 .procname = "page-cluster",
1344 .data = &page_cluster,
1345 .maxlen = sizeof(int),
1347 .proc_handler = proc_dointvec_minmax,
1348 .extra1 = SYSCTL_ZERO,
1351 .procname = "dirty_background_ratio",
1352 .data = &dirty_background_ratio,
1353 .maxlen = sizeof(dirty_background_ratio),
1355 .proc_handler = dirty_background_ratio_handler,
1356 .extra1 = SYSCTL_ZERO,
1357 .extra2 = &one_hundred,
1360 .procname = "dirty_background_bytes",
1361 .data = &dirty_background_bytes,
1362 .maxlen = sizeof(dirty_background_bytes),
1364 .proc_handler = dirty_background_bytes_handler,
1368 .procname = "dirty_ratio",
1369 .data = &vm_dirty_ratio,
1370 .maxlen = sizeof(vm_dirty_ratio),
1372 .proc_handler = dirty_ratio_handler,
1373 .extra1 = SYSCTL_ZERO,
1374 .extra2 = &one_hundred,
1377 .procname = "dirty_bytes",
1378 .data = &vm_dirty_bytes,
1379 .maxlen = sizeof(vm_dirty_bytes),
1381 .proc_handler = dirty_bytes_handler,
1382 .extra1 = &dirty_bytes_min,
1385 .procname = "dirty_writeback_centisecs",
1386 .data = &dirty_writeback_interval,
1387 .maxlen = sizeof(dirty_writeback_interval),
1389 .proc_handler = dirty_writeback_centisecs_handler,
1392 .procname = "dirty_expire_centisecs",
1393 .data = &dirty_expire_interval,
1394 .maxlen = sizeof(dirty_expire_interval),
1396 .proc_handler = proc_dointvec_minmax,
1397 .extra1 = SYSCTL_ZERO,
1400 .procname = "dirtytime_expire_seconds",
1401 .data = &dirtytime_expire_interval,
1402 .maxlen = sizeof(dirtytime_expire_interval),
1404 .proc_handler = dirtytime_interval_handler,
1405 .extra1 = SYSCTL_ZERO,
1408 .procname = "swappiness",
1409 .data = &vm_swappiness,
1410 .maxlen = sizeof(vm_swappiness),
1412 .proc_handler = proc_dointvec_minmax,
1413 .extra1 = SYSCTL_ZERO,
1414 .extra2 = &one_hundred,
1416 #ifdef CONFIG_HUGETLB_PAGE
1418 .procname = "nr_hugepages",
1420 .maxlen = sizeof(unsigned long),
1422 .proc_handler = hugetlb_sysctl_handler,
1426 .procname = "nr_hugepages_mempolicy",
1428 .maxlen = sizeof(unsigned long),
1430 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1433 .procname = "numa_stat",
1434 .data = &sysctl_vm_numa_stat,
1435 .maxlen = sizeof(int),
1437 .proc_handler = sysctl_vm_numa_stat_handler,
1438 .extra1 = SYSCTL_ZERO,
1439 .extra2 = SYSCTL_ONE,
1443 .procname = "hugetlb_shm_group",
1444 .data = &sysctl_hugetlb_shm_group,
1445 .maxlen = sizeof(gid_t),
1447 .proc_handler = proc_dointvec,
1450 .procname = "nr_overcommit_hugepages",
1452 .maxlen = sizeof(unsigned long),
1454 .proc_handler = hugetlb_overcommit_handler,
1458 .procname = "lowmem_reserve_ratio",
1459 .data = &sysctl_lowmem_reserve_ratio,
1460 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1462 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1465 .procname = "drop_caches",
1466 .data = &sysctl_drop_caches,
1467 .maxlen = sizeof(int),
1469 .proc_handler = drop_caches_sysctl_handler,
1470 .extra1 = SYSCTL_ONE,
1473 #ifdef CONFIG_COMPACTION
1475 .procname = "compact_memory",
1476 .data = &sysctl_compact_memory,
1477 .maxlen = sizeof(int),
1479 .proc_handler = sysctl_compaction_handler,
1482 .procname = "extfrag_threshold",
1483 .data = &sysctl_extfrag_threshold,
1484 .maxlen = sizeof(int),
1486 .proc_handler = proc_dointvec_minmax,
1487 .extra1 = &min_extfrag_threshold,
1488 .extra2 = &max_extfrag_threshold,
1491 .procname = "compact_unevictable_allowed",
1492 .data = &sysctl_compact_unevictable_allowed,
1493 .maxlen = sizeof(int),
1495 .proc_handler = proc_dointvec,
1496 .extra1 = SYSCTL_ZERO,
1497 .extra2 = SYSCTL_ONE,
1500 #endif /* CONFIG_COMPACTION */
1502 .procname = "min_free_kbytes",
1503 .data = &min_free_kbytes,
1504 .maxlen = sizeof(min_free_kbytes),
1506 .proc_handler = min_free_kbytes_sysctl_handler,
1507 .extra1 = SYSCTL_ZERO,
1510 .procname = "watermark_boost_factor",
1511 .data = &watermark_boost_factor,
1512 .maxlen = sizeof(watermark_boost_factor),
1514 .proc_handler = watermark_boost_factor_sysctl_handler,
1515 .extra1 = SYSCTL_ZERO,
1518 .procname = "watermark_scale_factor",
1519 .data = &watermark_scale_factor,
1520 .maxlen = sizeof(watermark_scale_factor),
1522 .proc_handler = watermark_scale_factor_sysctl_handler,
1523 .extra1 = SYSCTL_ONE,
1524 .extra2 = &one_thousand,
1527 .procname = "percpu_pagelist_fraction",
1528 .data = &percpu_pagelist_fraction,
1529 .maxlen = sizeof(percpu_pagelist_fraction),
1531 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1532 .extra1 = SYSCTL_ZERO,
1536 .procname = "max_map_count",
1537 .data = &sysctl_max_map_count,
1538 .maxlen = sizeof(sysctl_max_map_count),
1540 .proc_handler = proc_dointvec_minmax,
1541 .extra1 = SYSCTL_ZERO,
1545 .procname = "nr_trim_pages",
1546 .data = &sysctl_nr_trim_pages,
1547 .maxlen = sizeof(sysctl_nr_trim_pages),
1549 .proc_handler = proc_dointvec_minmax,
1550 .extra1 = SYSCTL_ZERO,
1554 .procname = "laptop_mode",
1555 .data = &laptop_mode,
1556 .maxlen = sizeof(laptop_mode),
1558 .proc_handler = proc_dointvec_jiffies,
1561 .procname = "block_dump",
1562 .data = &block_dump,
1563 .maxlen = sizeof(block_dump),
1565 .proc_handler = proc_dointvec,
1566 .extra1 = SYSCTL_ZERO,
1569 .procname = "vfs_cache_pressure",
1570 .data = &sysctl_vfs_cache_pressure,
1571 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1573 .proc_handler = proc_dointvec,
1574 .extra1 = SYSCTL_ZERO,
1576 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1578 .procname = "legacy_va_layout",
1579 .data = &sysctl_legacy_va_layout,
1580 .maxlen = sizeof(sysctl_legacy_va_layout),
1582 .proc_handler = proc_dointvec,
1583 .extra1 = SYSCTL_ZERO,
1588 .procname = "zone_reclaim_mode",
1589 .data = &node_reclaim_mode,
1590 .maxlen = sizeof(node_reclaim_mode),
1592 .proc_handler = proc_dointvec,
1593 .extra1 = SYSCTL_ZERO,
1596 .procname = "min_unmapped_ratio",
1597 .data = &sysctl_min_unmapped_ratio,
1598 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1600 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1601 .extra1 = SYSCTL_ZERO,
1602 .extra2 = &one_hundred,
1605 .procname = "min_slab_ratio",
1606 .data = &sysctl_min_slab_ratio,
1607 .maxlen = sizeof(sysctl_min_slab_ratio),
1609 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1610 .extra1 = SYSCTL_ZERO,
1611 .extra2 = &one_hundred,
1616 .procname = "stat_interval",
1617 .data = &sysctl_stat_interval,
1618 .maxlen = sizeof(sysctl_stat_interval),
1620 .proc_handler = proc_dointvec_jiffies,
1623 .procname = "stat_refresh",
1627 .proc_handler = vmstat_refresh,
1632 .procname = "mmap_min_addr",
1633 .data = &dac_mmap_min_addr,
1634 .maxlen = sizeof(unsigned long),
1636 .proc_handler = mmap_min_addr_handler,
1641 .procname = "numa_zonelist_order",
1642 .data = &numa_zonelist_order,
1643 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1645 .proc_handler = numa_zonelist_order_handler,
1648 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1649 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1651 .procname = "vdso_enabled",
1652 #ifdef CONFIG_X86_32
1653 .data = &vdso32_enabled,
1654 .maxlen = sizeof(vdso32_enabled),
1656 .data = &vdso_enabled,
1657 .maxlen = sizeof(vdso_enabled),
1660 .proc_handler = proc_dointvec,
1661 .extra1 = SYSCTL_ZERO,
1664 #ifdef CONFIG_HIGHMEM
1666 .procname = "highmem_is_dirtyable",
1667 .data = &vm_highmem_is_dirtyable,
1668 .maxlen = sizeof(vm_highmem_is_dirtyable),
1670 .proc_handler = proc_dointvec_minmax,
1671 .extra1 = SYSCTL_ZERO,
1672 .extra2 = SYSCTL_ONE,
1675 #ifdef CONFIG_MEMORY_FAILURE
1677 .procname = "memory_failure_early_kill",
1678 .data = &sysctl_memory_failure_early_kill,
1679 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1681 .proc_handler = proc_dointvec_minmax,
1682 .extra1 = SYSCTL_ZERO,
1683 .extra2 = SYSCTL_ONE,
1686 .procname = "memory_failure_recovery",
1687 .data = &sysctl_memory_failure_recovery,
1688 .maxlen = sizeof(sysctl_memory_failure_recovery),
1690 .proc_handler = proc_dointvec_minmax,
1691 .extra1 = SYSCTL_ZERO,
1692 .extra2 = SYSCTL_ONE,
1696 .procname = "user_reserve_kbytes",
1697 .data = &sysctl_user_reserve_kbytes,
1698 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1700 .proc_handler = proc_doulongvec_minmax,
1703 .procname = "admin_reserve_kbytes",
1704 .data = &sysctl_admin_reserve_kbytes,
1705 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1707 .proc_handler = proc_doulongvec_minmax,
1709 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1711 .procname = "mmap_rnd_bits",
1712 .data = &mmap_rnd_bits,
1713 .maxlen = sizeof(mmap_rnd_bits),
1715 .proc_handler = proc_dointvec_minmax,
1716 .extra1 = (void *)&mmap_rnd_bits_min,
1717 .extra2 = (void *)&mmap_rnd_bits_max,
1720 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1722 .procname = "mmap_rnd_compat_bits",
1723 .data = &mmap_rnd_compat_bits,
1724 .maxlen = sizeof(mmap_rnd_compat_bits),
1726 .proc_handler = proc_dointvec_minmax,
1727 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1728 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1731 #ifdef CONFIG_USERFAULTFD
1733 .procname = "unprivileged_userfaultfd",
1734 .data = &sysctl_unprivileged_userfaultfd,
1735 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
1737 .proc_handler = proc_dointvec_minmax,
1738 .extra1 = SYSCTL_ZERO,
1739 .extra2 = SYSCTL_ONE,
1745 static struct ctl_table fs_table[] = {
1747 .procname = "inode-nr",
1748 .data = &inodes_stat,
1749 .maxlen = 2*sizeof(long),
1751 .proc_handler = proc_nr_inodes,
1754 .procname = "inode-state",
1755 .data = &inodes_stat,
1756 .maxlen = 7*sizeof(long),
1758 .proc_handler = proc_nr_inodes,
1761 .procname = "file-nr",
1762 .data = &files_stat,
1763 .maxlen = sizeof(files_stat),
1765 .proc_handler = proc_nr_files,
1768 .procname = "file-max",
1769 .data = &files_stat.max_files,
1770 .maxlen = sizeof(files_stat.max_files),
1772 .proc_handler = proc_doulongvec_minmax,
1774 .extra2 = &long_max,
1777 .procname = "nr_open",
1778 .data = &sysctl_nr_open,
1779 .maxlen = sizeof(unsigned int),
1781 .proc_handler = proc_dointvec_minmax,
1782 .extra1 = &sysctl_nr_open_min,
1783 .extra2 = &sysctl_nr_open_max,
1786 .procname = "dentry-state",
1787 .data = &dentry_stat,
1788 .maxlen = 6*sizeof(long),
1790 .proc_handler = proc_nr_dentry,
1793 .procname = "overflowuid",
1794 .data = &fs_overflowuid,
1795 .maxlen = sizeof(int),
1797 .proc_handler = proc_dointvec_minmax,
1798 .extra1 = &minolduid,
1799 .extra2 = &maxolduid,
1802 .procname = "overflowgid",
1803 .data = &fs_overflowgid,
1804 .maxlen = sizeof(int),
1806 .proc_handler = proc_dointvec_minmax,
1807 .extra1 = &minolduid,
1808 .extra2 = &maxolduid,
1810 #ifdef CONFIG_FILE_LOCKING
1812 .procname = "leases-enable",
1813 .data = &leases_enable,
1814 .maxlen = sizeof(int),
1816 .proc_handler = proc_dointvec,
1819 #ifdef CONFIG_DNOTIFY
1821 .procname = "dir-notify-enable",
1822 .data = &dir_notify_enable,
1823 .maxlen = sizeof(int),
1825 .proc_handler = proc_dointvec,
1829 #ifdef CONFIG_FILE_LOCKING
1831 .procname = "lease-break-time",
1832 .data = &lease_break_time,
1833 .maxlen = sizeof(int),
1835 .proc_handler = proc_dointvec,
1840 .procname = "aio-nr",
1842 .maxlen = sizeof(aio_nr),
1844 .proc_handler = proc_doulongvec_minmax,
1847 .procname = "aio-max-nr",
1848 .data = &aio_max_nr,
1849 .maxlen = sizeof(aio_max_nr),
1851 .proc_handler = proc_doulongvec_minmax,
1853 #endif /* CONFIG_AIO */
1854 #ifdef CONFIG_INOTIFY_USER
1856 .procname = "inotify",
1858 .child = inotify_table,
1863 .procname = "epoll",
1865 .child = epoll_table,
1870 .procname = "protected_symlinks",
1871 .data = &sysctl_protected_symlinks,
1872 .maxlen = sizeof(int),
1874 .proc_handler = proc_dointvec_minmax,
1875 .extra1 = SYSCTL_ZERO,
1876 .extra2 = SYSCTL_ONE,
1879 .procname = "protected_hardlinks",
1880 .data = &sysctl_protected_hardlinks,
1881 .maxlen = sizeof(int),
1883 .proc_handler = proc_dointvec_minmax,
1884 .extra1 = SYSCTL_ZERO,
1885 .extra2 = SYSCTL_ONE,
1888 .procname = "protected_fifos",
1889 .data = &sysctl_protected_fifos,
1890 .maxlen = sizeof(int),
1892 .proc_handler = proc_dointvec_minmax,
1893 .extra1 = SYSCTL_ZERO,
1897 .procname = "protected_regular",
1898 .data = &sysctl_protected_regular,
1899 .maxlen = sizeof(int),
1901 .proc_handler = proc_dointvec_minmax,
1902 .extra1 = SYSCTL_ZERO,
1906 .procname = "suid_dumpable",
1907 .data = &suid_dumpable,
1908 .maxlen = sizeof(int),
1910 .proc_handler = proc_dointvec_minmax_coredump,
1911 .extra1 = SYSCTL_ZERO,
1914 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1916 .procname = "binfmt_misc",
1918 .child = sysctl_mount_point,
1922 .procname = "pipe-max-size",
1923 .data = &pipe_max_size,
1924 .maxlen = sizeof(pipe_max_size),
1926 .proc_handler = proc_dopipe_max_size,
1929 .procname = "pipe-user-pages-hard",
1930 .data = &pipe_user_pages_hard,
1931 .maxlen = sizeof(pipe_user_pages_hard),
1933 .proc_handler = proc_doulongvec_minmax,
1936 .procname = "pipe-user-pages-soft",
1937 .data = &pipe_user_pages_soft,
1938 .maxlen = sizeof(pipe_user_pages_soft),
1940 .proc_handler = proc_doulongvec_minmax,
1943 .procname = "mount-max",
1944 .data = &sysctl_mount_max,
1945 .maxlen = sizeof(unsigned int),
1947 .proc_handler = proc_dointvec_minmax,
1948 .extra1 = SYSCTL_ONE,
1953 static struct ctl_table debug_table[] = {
1954 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1956 .procname = "exception-trace",
1957 .data = &show_unhandled_signals,
1958 .maxlen = sizeof(int),
1960 .proc_handler = proc_dointvec
1963 #if defined(CONFIG_OPTPROBES)
1965 .procname = "kprobes-optimization",
1966 .data = &sysctl_kprobes_optimization,
1967 .maxlen = sizeof(int),
1969 .proc_handler = proc_kprobes_optimization_handler,
1970 .extra1 = SYSCTL_ZERO,
1971 .extra2 = SYSCTL_ONE,
1977 static struct ctl_table dev_table[] = {
1981 int __init sysctl_init(void)
1983 struct ctl_table_header *hdr;
1985 hdr = register_sysctl_table(sysctl_base_table);
1986 kmemleak_not_leak(hdr);
1990 #endif /* CONFIG_SYSCTL */
1996 #ifdef CONFIG_PROC_SYSCTL
1998 static int _proc_do_string(char *data, int maxlen, int write,
1999 char __user *buffer,
2000 size_t *lenp, loff_t *ppos)
2006 if (!data || !maxlen || !*lenp) {
2012 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
2013 /* Only continue writes not past the end of buffer. */
2015 if (len > maxlen - 1)
2022 /* Start writing from beginning of buffer. */
2028 while ((p - buffer) < *lenp && len < maxlen - 1) {
2029 if (get_user(c, p++))
2031 if (c == 0 || c == '\n')
2052 if (copy_to_user(buffer, data, len))
2055 if (put_user('\n', buffer + len))
2065 static void warn_sysctl_write(struct ctl_table *table)
2067 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2068 "This will not be supported in the future. To silence this\n"
2069 "warning, set kernel.sysctl_writes_strict = -1\n",
2070 current->comm, table->procname);
2074 * proc_first_pos_non_zero_ignore - check if first position is allowed
2075 * @ppos: file position
2076 * @table: the sysctl table
2078 * Returns true if the first position is non-zero and the sysctl_writes_strict
2079 * mode indicates this is not allowed for numeric input types. String proc
2080 * handlers can ignore the return value.
2082 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2083 struct ctl_table *table)
2088 switch (sysctl_writes_strict) {
2089 case SYSCTL_WRITES_STRICT:
2091 case SYSCTL_WRITES_WARN:
2092 warn_sysctl_write(table);
2100 * proc_dostring - read a string sysctl
2101 * @table: the sysctl table
2102 * @write: %TRUE if this is a write to the sysctl file
2103 * @buffer: the user buffer
2104 * @lenp: the size of the user buffer
2105 * @ppos: file position
2107 * Reads/writes a string from/to the user buffer. If the kernel
2108 * buffer provided is not large enough to hold the string, the
2109 * string is truncated. The copied string is %NULL-terminated.
2110 * If the string is being read by the user process, it is copied
2111 * and a newline '\n' is added. It is truncated if the buffer is
2114 * Returns 0 on success.
2116 int proc_dostring(struct ctl_table *table, int write,
2117 void __user *buffer, size_t *lenp, loff_t *ppos)
2120 proc_first_pos_non_zero_ignore(ppos, table);
2122 return _proc_do_string((char *)(table->data), table->maxlen, write,
2123 (char __user *)buffer, lenp, ppos);
2126 static size_t proc_skip_spaces(char **buf)
2129 char *tmp = skip_spaces(*buf);
2135 static void proc_skip_char(char **buf, size_t *size, const char v)
2146 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2149 * @cp: kernel buffer containing the string to parse
2150 * @endp: pointer to store the trailing characters
2151 * @base: the base to use
2152 * @res: where the parsed integer will be stored
2154 * In case of success 0 is returned and @res will contain the parsed integer,
2155 * @endp will hold any trailing characters.
2156 * This function will fail the parse on overflow. If there wasn't an overflow
2157 * the function will defer the decision what characters count as invalid to the
2160 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2163 unsigned long long result;
2166 cp = _parse_integer_fixup_radix(cp, &base);
2167 rv = _parse_integer(cp, base, &result);
2168 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2176 *res = (unsigned long)result;
2180 #define TMPBUFLEN 22
2182 * proc_get_long - reads an ASCII formatted integer from a user buffer
2184 * @buf: a kernel buffer
2185 * @size: size of the kernel buffer
2186 * @val: this is where the number will be stored
2187 * @neg: set to %TRUE if number is negative
2188 * @perm_tr: a vector which contains the allowed trailers
2189 * @perm_tr_len: size of the perm_tr vector
2190 * @tr: pointer to store the trailer character
2192 * In case of success %0 is returned and @buf and @size are updated with
2193 * the amount of bytes read. If @tr is non-NULL and a trailing
2194 * character exists (size is non-zero after returning from this
2195 * function), @tr is updated with the trailing character.
2197 static int proc_get_long(char **buf, size_t *size,
2198 unsigned long *val, bool *neg,
2199 const char *perm_tr, unsigned perm_tr_len, char *tr)
2202 char *p, tmp[TMPBUFLEN];
2208 if (len > TMPBUFLEN - 1)
2209 len = TMPBUFLEN - 1;
2211 memcpy(tmp, *buf, len);
2215 if (*p == '-' && *size > 1) {
2223 if (strtoul_lenient(p, &p, 0, val))
2228 /* We don't know if the next char is whitespace thus we may accept
2229 * invalid integers (e.g. 1234...a) or two integers instead of one
2230 * (e.g. 123...1). So lets not allow such large numbers. */
2231 if (len == TMPBUFLEN - 1)
2234 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2237 if (tr && (len < *size))
2247 * proc_put_long - converts an integer to a decimal ASCII formatted string
2249 * @buf: the user buffer
2250 * @size: the size of the user buffer
2251 * @val: the integer to be converted
2252 * @neg: sign of the number, %TRUE for negative
2254 * In case of success %0 is returned and @buf and @size are updated with
2255 * the amount of bytes written.
2257 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2261 char tmp[TMPBUFLEN], *p = tmp;
2263 sprintf(p, "%s%lu", neg ? "-" : "", val);
2267 if (copy_to_user(*buf, tmp, len))
2275 static int proc_put_char(void __user **buf, size_t *size, char c)
2278 char __user **buffer = (char __user **)buf;
2279 if (put_user(c, *buffer))
2281 (*size)--, (*buffer)++;
2287 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2289 int write, void *data)
2293 if (*lvalp > (unsigned long) INT_MAX + 1)
2297 if (*lvalp > (unsigned long) INT_MAX)
2305 *lvalp = -(unsigned long)val;
2308 *lvalp = (unsigned long)val;
2314 static int do_proc_douintvec_conv(unsigned long *lvalp,
2316 int write, void *data)
2319 if (*lvalp > UINT_MAX)
2323 unsigned int val = *valp;
2324 *lvalp = (unsigned long)val;
2329 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2331 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2332 int write, void __user *buffer,
2333 size_t *lenp, loff_t *ppos,
2334 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2335 int write, void *data),
2338 int *i, vleft, first = 1, err = 0;
2340 char *kbuf = NULL, *p;
2342 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2347 i = (int *) tbl_data;
2348 vleft = table->maxlen / sizeof(*i);
2352 conv = do_proc_dointvec_conv;
2355 if (proc_first_pos_non_zero_ignore(ppos, table))
2358 if (left > PAGE_SIZE - 1)
2359 left = PAGE_SIZE - 1;
2360 p = kbuf = memdup_user_nul(buffer, left);
2362 return PTR_ERR(kbuf);
2365 for (; left && vleft--; i++, first=0) {
2370 left -= proc_skip_spaces(&p);
2374 err = proc_get_long(&p, &left, &lval, &neg,
2376 sizeof(proc_wspace_sep), NULL);
2379 if (conv(&neg, &lval, i, 1, data)) {
2384 if (conv(&neg, &lval, i, 0, data)) {
2389 err = proc_put_char(&buffer, &left, '\t');
2392 err = proc_put_long(&buffer, &left, lval, neg);
2398 if (!write && !first && left && !err)
2399 err = proc_put_char(&buffer, &left, '\n');
2400 if (write && !err && left)
2401 left -= proc_skip_spaces(&p);
2405 return err ? : -EINVAL;
2413 static int do_proc_dointvec(struct ctl_table *table, int write,
2414 void __user *buffer, size_t *lenp, loff_t *ppos,
2415 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2416 int write, void *data),
2419 return __do_proc_dointvec(table->data, table, write,
2420 buffer, lenp, ppos, conv, data);
2423 static int do_proc_douintvec_w(unsigned int *tbl_data,
2424 struct ctl_table *table,
2425 void __user *buffer,
2426 size_t *lenp, loff_t *ppos,
2427 int (*conv)(unsigned long *lvalp,
2429 int write, void *data),
2436 char *kbuf = NULL, *p;
2440 if (proc_first_pos_non_zero_ignore(ppos, table))
2443 if (left > PAGE_SIZE - 1)
2444 left = PAGE_SIZE - 1;
2446 p = kbuf = memdup_user_nul(buffer, left);
2450 left -= proc_skip_spaces(&p);
2456 err = proc_get_long(&p, &left, &lval, &neg,
2458 sizeof(proc_wspace_sep), NULL);
2464 if (conv(&lval, tbl_data, 1, data)) {
2470 left -= proc_skip_spaces(&p);
2479 /* This is in keeping with old __do_proc_dointvec() */
2485 static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2486 size_t *lenp, loff_t *ppos,
2487 int (*conv)(unsigned long *lvalp,
2489 int write, void *data),
2498 if (conv(&lval, tbl_data, 0, data)) {
2503 err = proc_put_long(&buffer, &left, lval, false);
2507 err = proc_put_char(&buffer, &left, '\n');
2516 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2517 int write, void __user *buffer,
2518 size_t *lenp, loff_t *ppos,
2519 int (*conv)(unsigned long *lvalp,
2521 int write, void *data),
2524 unsigned int *i, vleft;
2526 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2531 i = (unsigned int *) tbl_data;
2532 vleft = table->maxlen / sizeof(*i);
2535 * Arrays are not supported, keep this simple. *Do not* add
2544 conv = do_proc_douintvec_conv;
2547 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2549 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2552 static int do_proc_douintvec(struct ctl_table *table, int write,
2553 void __user *buffer, size_t *lenp, loff_t *ppos,
2554 int (*conv)(unsigned long *lvalp,
2556 int write, void *data),
2559 return __do_proc_douintvec(table->data, table, write,
2560 buffer, lenp, ppos, conv, data);
2564 * proc_dointvec - read a vector of 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) integer
2572 * values from/to the user buffer, treated as an ASCII string.
2574 * Returns 0 on success.
2576 int proc_dointvec(struct ctl_table *table, int write,
2577 void __user *buffer, size_t *lenp, loff_t *ppos)
2579 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2583 * proc_douintvec - read a vector of unsigned integers
2584 * @table: the sysctl table
2585 * @write: %TRUE if this is a write to the sysctl file
2586 * @buffer: the user buffer
2587 * @lenp: the size of the user buffer
2588 * @ppos: file position
2590 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2591 * values from/to the user buffer, treated as an ASCII string.
2593 * Returns 0 on success.
2595 int proc_douintvec(struct ctl_table *table, int write,
2596 void __user *buffer, size_t *lenp, loff_t *ppos)
2598 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2599 do_proc_douintvec_conv, NULL);
2603 * Taint values can only be increased
2604 * This means we can safely use a temporary.
2606 static int proc_taint(struct ctl_table *table, int write,
2607 void __user *buffer, size_t *lenp, loff_t *ppos)
2610 unsigned long tmptaint = get_taint();
2613 if (write && !capable(CAP_SYS_ADMIN))
2618 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2624 * Poor man's atomic or. Not worth adding a primitive
2625 * to everyone's atomic.h for this
2628 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2629 if ((tmptaint >> i) & 1)
2630 add_taint(i, LOCKDEP_STILL_OK);
2637 #ifdef CONFIG_PRINTK
2638 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2639 void __user *buffer, size_t *lenp, loff_t *ppos)
2641 if (write && !capable(CAP_SYS_ADMIN))
2644 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2649 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2650 * @min: pointer to minimum allowable value
2651 * @max: pointer to maximum allowable value
2653 * The do_proc_dointvec_minmax_conv_param structure provides the
2654 * minimum and maximum values for doing range checking for those sysctl
2655 * parameters that use the proc_dointvec_minmax() handler.
2657 struct do_proc_dointvec_minmax_conv_param {
2662 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2664 int write, void *data)
2667 struct do_proc_dointvec_minmax_conv_param *param = data;
2669 * If writing, first do so via a temporary local int so we can
2670 * bounds-check it before touching *valp.
2672 int *ip = write ? &tmp : valp;
2674 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
2679 if ((param->min && *param->min > tmp) ||
2680 (param->max && *param->max < tmp))
2689 * proc_dointvec_minmax - read a vector of integers with min/max values
2690 * @table: the sysctl table
2691 * @write: %TRUE if this is a write to the sysctl file
2692 * @buffer: the user buffer
2693 * @lenp: the size of the user buffer
2694 * @ppos: file position
2696 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2697 * values from/to the user buffer, treated as an ASCII string.
2699 * This routine will ensure the values are within the range specified by
2700 * table->extra1 (min) and table->extra2 (max).
2702 * Returns 0 on success or -EINVAL on write when the range check fails.
2704 int proc_dointvec_minmax(struct ctl_table *table, int write,
2705 void __user *buffer, size_t *lenp, loff_t *ppos)
2707 struct do_proc_dointvec_minmax_conv_param param = {
2708 .min = (int *) table->extra1,
2709 .max = (int *) table->extra2,
2711 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2712 do_proc_dointvec_minmax_conv, ¶m);
2716 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2717 * @min: pointer to minimum allowable value
2718 * @max: pointer to maximum allowable value
2720 * The do_proc_douintvec_minmax_conv_param structure provides the
2721 * minimum and maximum values for doing range checking for those sysctl
2722 * parameters that use the proc_douintvec_minmax() handler.
2724 struct do_proc_douintvec_minmax_conv_param {
2729 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2731 int write, void *data)
2735 struct do_proc_douintvec_minmax_conv_param *param = data;
2736 /* write via temporary local uint for bounds-checking */
2737 unsigned int *up = write ? &tmp : valp;
2739 ret = do_proc_douintvec_conv(lvalp, up, write, data);
2744 if ((param->min && *param->min > tmp) ||
2745 (param->max && *param->max < tmp))
2755 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2756 * @table: the sysctl table
2757 * @write: %TRUE if this is a write to the sysctl file
2758 * @buffer: the user buffer
2759 * @lenp: the size of the user buffer
2760 * @ppos: file position
2762 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2763 * values from/to the user buffer, treated as an ASCII string. Negative
2764 * strings are not allowed.
2766 * This routine will ensure the values are within the range specified by
2767 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2768 * check for UINT_MAX to avoid having to support wrap around uses from
2771 * Returns 0 on success or -ERANGE on write when the range check fails.
2773 int proc_douintvec_minmax(struct ctl_table *table, int write,
2774 void __user *buffer, size_t *lenp, loff_t *ppos)
2776 struct do_proc_douintvec_minmax_conv_param param = {
2777 .min = (unsigned int *) table->extra1,
2778 .max = (unsigned int *) table->extra2,
2780 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2781 do_proc_douintvec_minmax_conv, ¶m);
2784 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2786 int write, void *data)
2791 val = round_pipe_size(*lvalp);
2797 unsigned int val = *valp;
2798 *lvalp = (unsigned long) val;
2804 static int proc_dopipe_max_size(struct ctl_table *table, int write,
2805 void __user *buffer, size_t *lenp, loff_t *ppos)
2807 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2808 do_proc_dopipe_max_size_conv, NULL);
2811 static void validate_coredump_safety(void)
2813 #ifdef CONFIG_COREDUMP
2814 if (suid_dumpable == SUID_DUMP_ROOT &&
2815 core_pattern[0] != '/' && core_pattern[0] != '|') {
2817 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2818 "Pipe handler or fully qualified core dump path required.\n"
2819 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2825 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2826 void __user *buffer, size_t *lenp, loff_t *ppos)
2828 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2830 validate_coredump_safety();
2834 #ifdef CONFIG_COREDUMP
2835 static int proc_dostring_coredump(struct ctl_table *table, int write,
2836 void __user *buffer, size_t *lenp, loff_t *ppos)
2838 int error = proc_dostring(table, write, buffer, lenp, ppos);
2840 validate_coredump_safety();
2845 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2846 void __user *buffer,
2847 size_t *lenp, loff_t *ppos,
2848 unsigned long convmul,
2849 unsigned long convdiv)
2851 unsigned long *i, *min, *max;
2852 int vleft, first = 1, err = 0;
2854 char *kbuf = NULL, *p;
2856 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2861 i = (unsigned long *) data;
2862 min = (unsigned long *) table->extra1;
2863 max = (unsigned long *) table->extra2;
2864 vleft = table->maxlen / sizeof(unsigned long);
2868 if (proc_first_pos_non_zero_ignore(ppos, table))
2871 if (left > PAGE_SIZE - 1)
2872 left = PAGE_SIZE - 1;
2873 p = kbuf = memdup_user_nul(buffer, left);
2875 return PTR_ERR(kbuf);
2878 for (; left && vleft--; i++, first = 0) {
2884 left -= proc_skip_spaces(&p);
2888 err = proc_get_long(&p, &left, &val, &neg,
2890 sizeof(proc_wspace_sep), NULL);
2895 val = convmul * val / convdiv;
2896 if ((min && val < *min) || (max && val > *max)) {
2902 val = convdiv * (*i) / convmul;
2904 err = proc_put_char(&buffer, &left, '\t');
2908 err = proc_put_long(&buffer, &left, val, false);
2914 if (!write && !first && left && !err)
2915 err = proc_put_char(&buffer, &left, '\n');
2917 left -= proc_skip_spaces(&p);
2921 return err ? : -EINVAL;
2929 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2930 void __user *buffer,
2931 size_t *lenp, loff_t *ppos,
2932 unsigned long convmul,
2933 unsigned long convdiv)
2935 return __do_proc_doulongvec_minmax(table->data, table, write,
2936 buffer, lenp, ppos, convmul, convdiv);
2940 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2941 * @table: the sysctl table
2942 * @write: %TRUE if this is a write to the sysctl file
2943 * @buffer: the user buffer
2944 * @lenp: the size of the user buffer
2945 * @ppos: file position
2947 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2948 * values from/to the user buffer, treated as an ASCII string.
2950 * This routine will ensure the values are within the range specified by
2951 * table->extra1 (min) and table->extra2 (max).
2953 * Returns 0 on success.
2955 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2956 void __user *buffer, size_t *lenp, loff_t *ppos)
2958 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2962 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2963 * @table: the sysctl table
2964 * @write: %TRUE if this is a write to the sysctl file
2965 * @buffer: the user buffer
2966 * @lenp: the size of the user buffer
2967 * @ppos: file position
2969 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2970 * values from/to the user buffer, treated as an ASCII string. The values
2971 * are treated as milliseconds, and converted to jiffies when they are stored.
2973 * This routine will ensure the values are within the range specified by
2974 * table->extra1 (min) and table->extra2 (max).
2976 * Returns 0 on success.
2978 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2979 void __user *buffer,
2980 size_t *lenp, loff_t *ppos)
2982 return do_proc_doulongvec_minmax(table, write, buffer,
2983 lenp, ppos, HZ, 1000l);
2987 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2989 int write, void *data)
2992 if (*lvalp > INT_MAX / HZ)
2994 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
3000 lval = -(unsigned long)val;
3003 lval = (unsigned long)val;
3010 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
3012 int write, void *data)
3015 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
3017 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
3023 lval = -(unsigned long)val;
3026 lval = (unsigned long)val;
3028 *lvalp = jiffies_to_clock_t(lval);
3033 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
3035 int write, void *data)
3038 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3048 lval = -(unsigned long)val;
3051 lval = (unsigned long)val;
3053 *lvalp = jiffies_to_msecs(lval);
3059 * proc_dointvec_jiffies - read a vector of integers as seconds
3060 * @table: the sysctl table
3061 * @write: %TRUE if this is a write to the sysctl file
3062 * @buffer: the user buffer
3063 * @lenp: the size of the user buffer
3064 * @ppos: file position
3066 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3067 * values from/to the user buffer, treated as an ASCII string.
3068 * The values read are assumed to be in seconds, and are converted into
3071 * Returns 0 on success.
3073 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3074 void __user *buffer, size_t *lenp, loff_t *ppos)
3076 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3077 do_proc_dointvec_jiffies_conv,NULL);
3081 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3082 * @table: the sysctl table
3083 * @write: %TRUE if this is a write to the sysctl file
3084 * @buffer: the user buffer
3085 * @lenp: the size of the user buffer
3086 * @ppos: pointer to the file position
3088 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3089 * values from/to the user buffer, treated as an ASCII string.
3090 * The values read are assumed to be in 1/USER_HZ seconds, and
3091 * are converted into jiffies.
3093 * Returns 0 on success.
3095 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3096 void __user *buffer, size_t *lenp, loff_t *ppos)
3098 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3099 do_proc_dointvec_userhz_jiffies_conv,NULL);
3103 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3104 * @table: the sysctl table
3105 * @write: %TRUE if this is a write to the sysctl file
3106 * @buffer: the user buffer
3107 * @lenp: the size of the user buffer
3108 * @ppos: file position
3109 * @ppos: the current position in the file
3111 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3112 * values from/to the user buffer, treated as an ASCII string.
3113 * The values read are assumed to be in 1/1000 seconds, and
3114 * are converted into jiffies.
3116 * Returns 0 on success.
3118 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3119 void __user *buffer, size_t *lenp, loff_t *ppos)
3121 return do_proc_dointvec(table, write, buffer, lenp, ppos,
3122 do_proc_dointvec_ms_jiffies_conv, NULL);
3125 static int proc_do_cad_pid(struct ctl_table *table, int write,
3126 void __user *buffer, size_t *lenp, loff_t *ppos)
3128 struct pid *new_pid;
3132 tmp = pid_vnr(cad_pid);
3134 r = __do_proc_dointvec(&tmp, table, write, buffer,
3135 lenp, ppos, NULL, NULL);
3139 new_pid = find_get_pid(tmp);
3143 put_pid(xchg(&cad_pid, new_pid));
3148 * proc_do_large_bitmap - read/write from/to a large bitmap
3149 * @table: the sysctl table
3150 * @write: %TRUE if this is a write to the sysctl file
3151 * @buffer: the user buffer
3152 * @lenp: the size of the user buffer
3153 * @ppos: file position
3155 * The bitmap is stored at table->data and the bitmap length (in bits)
3158 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3159 * large bitmaps may be represented in a compact manner. Writing into
3160 * the file will clear the bitmap then update it with the given input.
3162 * Returns 0 on success.
3164 int proc_do_large_bitmap(struct ctl_table *table, int write,
3165 void __user *buffer, size_t *lenp, loff_t *ppos)
3169 size_t left = *lenp;
3170 unsigned long bitmap_len = table->maxlen;
3171 unsigned long *bitmap = *(unsigned long **) table->data;
3172 unsigned long *tmp_bitmap = NULL;
3173 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3175 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
3184 if (left > PAGE_SIZE - 1) {
3185 left = PAGE_SIZE - 1;
3186 /* How much of the buffer we'll skip this pass */
3187 skipped = *lenp - left;
3190 p = kbuf = memdup_user_nul(buffer, left);
3192 return PTR_ERR(kbuf);
3194 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
3199 proc_skip_char(&p, &left, '\n');
3200 while (!err && left) {
3201 unsigned long val_a, val_b;
3205 /* In case we stop parsing mid-number, we can reset */
3207 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
3210 * If we consumed the entirety of a truncated buffer or
3211 * only one char is left (may be a "-"), then stop here,
3212 * reset, & come back for more.
3214 if ((left <= 1) && skipped) {
3221 if (val_a >= bitmap_len || neg) {
3233 err = proc_get_long(&p, &left, &val_b,
3234 &neg, tr_b, sizeof(tr_b),
3237 * If we consumed all of a truncated buffer or
3238 * then stop here, reset, & come back for more.
3240 if (!left && skipped) {
3247 if (val_b >= bitmap_len || neg ||
3258 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
3260 proc_skip_char(&p, &left, '\n');
3265 unsigned long bit_a, bit_b = 0;
3268 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3269 if (bit_a >= bitmap_len)
3271 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3275 err = proc_put_char(&buffer, &left, ',');
3279 err = proc_put_long(&buffer, &left, bit_a, false);
3282 if (bit_a != bit_b) {
3283 err = proc_put_char(&buffer, &left, '-');
3286 err = proc_put_long(&buffer, &left, bit_b, false);
3294 err = proc_put_char(&buffer, &left, '\n');
3300 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3302 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
3308 bitmap_free(tmp_bitmap);
3312 #else /* CONFIG_PROC_SYSCTL */
3314 int proc_dostring(struct ctl_table *table, int write,
3315 void __user *buffer, size_t *lenp, loff_t *ppos)
3320 int proc_dointvec(struct ctl_table *table, int write,
3321 void __user *buffer, size_t *lenp, loff_t *ppos)
3326 int proc_douintvec(struct ctl_table *table, int write,
3327 void __user *buffer, size_t *lenp, loff_t *ppos)
3332 int proc_dointvec_minmax(struct ctl_table *table, int write,
3333 void __user *buffer, size_t *lenp, loff_t *ppos)
3338 int proc_douintvec_minmax(struct ctl_table *table, int write,
3339 void __user *buffer, size_t *lenp, loff_t *ppos)
3344 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3345 void __user *buffer, size_t *lenp, loff_t *ppos)
3350 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3351 void __user *buffer, size_t *lenp, loff_t *ppos)
3356 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3357 void __user *buffer, size_t *lenp, loff_t *ppos)
3362 int proc_doulongvec_minmax(struct ctl_table *table, int write,
3363 void __user *buffer, size_t *lenp, loff_t *ppos)
3368 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3369 void __user *buffer,
3370 size_t *lenp, loff_t *ppos)
3375 int proc_do_large_bitmap(struct ctl_table *table, int write,
3376 void __user *buffer, size_t *lenp, loff_t *ppos)
3381 #endif /* CONFIG_PROC_SYSCTL */
3383 #if defined(CONFIG_SYSCTL)
3384 int proc_do_static_key(struct ctl_table *table, int write,
3385 void __user *buffer, size_t *lenp,
3388 struct static_key *key = (struct static_key *)table->data;
3389 static DEFINE_MUTEX(static_key_mutex);
3391 struct ctl_table tmp = {
3393 .maxlen = sizeof(val),
3394 .mode = table->mode,
3395 .extra1 = SYSCTL_ZERO,
3396 .extra2 = SYSCTL_ONE,
3399 if (write && !capable(CAP_SYS_ADMIN))
3402 mutex_lock(&static_key_mutex);
3403 val = static_key_enabled(key);
3404 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3405 if (write && !ret) {
3407 static_key_enable(key);
3409 static_key_disable(key);
3411 mutex_unlock(&static_key_mutex);
3416 * No sense putting this after each symbol definition, twice,
3417 * exception granted :-)
3419 EXPORT_SYMBOL(proc_dointvec);
3420 EXPORT_SYMBOL(proc_douintvec);
3421 EXPORT_SYMBOL(proc_dointvec_jiffies);
3422 EXPORT_SYMBOL(proc_dointvec_minmax);
3423 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3424 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3425 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3426 EXPORT_SYMBOL(proc_dostring);
3427 EXPORT_SYMBOL(proc_doulongvec_minmax);
3428 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3429 EXPORT_SYMBOL(proc_do_large_bitmap);