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 #ifdef CONFIG_BPF_SYSCALL
255 void __weak unpriv_ebpf_notify(int new_state)
259 static int bpf_unpriv_handler(struct ctl_table *table, int write,
260 void *buffer, size_t *lenp, loff_t *ppos)
262 int ret, unpriv_enable = *(int *)table->data;
263 bool locked_state = unpriv_enable == 1;
264 struct ctl_table tmp = *table;
266 if (write && !capable(CAP_SYS_ADMIN))
269 tmp.data = &unpriv_enable;
270 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
272 if (locked_state && unpriv_enable != 1)
274 *(int *)table->data = unpriv_enable;
277 unpriv_ebpf_notify(unpriv_enable);
283 static struct ctl_table kern_table[];
284 static struct ctl_table vm_table[];
285 static struct ctl_table fs_table[];
286 static struct ctl_table debug_table[];
287 static struct ctl_table dev_table[];
288 extern struct ctl_table random_table[];
290 extern struct ctl_table epoll_table[];
293 #ifdef CONFIG_FW_LOADER_USER_HELPER
294 extern struct ctl_table firmware_config_table[];
297 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
298 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
299 int sysctl_legacy_va_layout;
302 /* The default sysctl tables: */
304 static struct ctl_table sysctl_base_table[] = {
306 .procname = "kernel",
323 .child = debug_table,
333 #ifdef CONFIG_SCHED_DEBUG
334 static int min_sched_granularity_ns = 100000; /* 100 usecs */
335 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
336 static int min_wakeup_granularity_ns; /* 0 usecs */
337 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
339 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
340 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
341 #endif /* CONFIG_SMP */
342 #endif /* CONFIG_SCHED_DEBUG */
344 #ifdef CONFIG_COMPACTION
345 static int min_extfrag_threshold;
346 static int max_extfrag_threshold = 1000;
349 static struct ctl_table kern_table[] = {
351 .procname = "sched_child_runs_first",
352 .data = &sysctl_sched_child_runs_first,
353 .maxlen = sizeof(unsigned int),
355 .proc_handler = proc_dointvec,
357 #ifdef CONFIG_SCHED_DEBUG
359 .procname = "sched_min_granularity_ns",
360 .data = &sysctl_sched_min_granularity,
361 .maxlen = sizeof(unsigned int),
363 .proc_handler = sched_proc_update_handler,
364 .extra1 = &min_sched_granularity_ns,
365 .extra2 = &max_sched_granularity_ns,
368 .procname = "sched_latency_ns",
369 .data = &sysctl_sched_latency,
370 .maxlen = sizeof(unsigned int),
372 .proc_handler = sched_proc_update_handler,
373 .extra1 = &min_sched_granularity_ns,
374 .extra2 = &max_sched_granularity_ns,
377 .procname = "sched_wakeup_granularity_ns",
378 .data = &sysctl_sched_wakeup_granularity,
379 .maxlen = sizeof(unsigned int),
381 .proc_handler = sched_proc_update_handler,
382 .extra1 = &min_wakeup_granularity_ns,
383 .extra2 = &max_wakeup_granularity_ns,
387 .procname = "sched_tunable_scaling",
388 .data = &sysctl_sched_tunable_scaling,
389 .maxlen = sizeof(enum sched_tunable_scaling),
391 .proc_handler = sched_proc_update_handler,
392 .extra1 = &min_sched_tunable_scaling,
393 .extra2 = &max_sched_tunable_scaling,
396 .procname = "sched_migration_cost_ns",
397 .data = &sysctl_sched_migration_cost,
398 .maxlen = sizeof(unsigned int),
400 .proc_handler = proc_dointvec,
403 .procname = "sched_nr_migrate",
404 .data = &sysctl_sched_nr_migrate,
405 .maxlen = sizeof(unsigned int),
407 .proc_handler = proc_dointvec,
409 #ifdef CONFIG_SCHEDSTATS
411 .procname = "sched_schedstats",
413 .maxlen = sizeof(unsigned int),
415 .proc_handler = sysctl_schedstats,
416 .extra1 = SYSCTL_ZERO,
417 .extra2 = SYSCTL_ONE,
419 #endif /* CONFIG_SCHEDSTATS */
420 #endif /* CONFIG_SMP */
421 #ifdef CONFIG_NUMA_BALANCING
423 .procname = "numa_balancing_scan_delay_ms",
424 .data = &sysctl_numa_balancing_scan_delay,
425 .maxlen = sizeof(unsigned int),
427 .proc_handler = proc_dointvec,
430 .procname = "numa_balancing_scan_period_min_ms",
431 .data = &sysctl_numa_balancing_scan_period_min,
432 .maxlen = sizeof(unsigned int),
434 .proc_handler = proc_dointvec,
437 .procname = "numa_balancing_scan_period_max_ms",
438 .data = &sysctl_numa_balancing_scan_period_max,
439 .maxlen = sizeof(unsigned int),
441 .proc_handler = proc_dointvec,
444 .procname = "numa_balancing_scan_size_mb",
445 .data = &sysctl_numa_balancing_scan_size,
446 .maxlen = sizeof(unsigned int),
448 .proc_handler = proc_dointvec_minmax,
449 .extra1 = SYSCTL_ONE,
452 .procname = "numa_balancing",
453 .data = NULL, /* filled in by handler */
454 .maxlen = sizeof(unsigned int),
456 .proc_handler = sysctl_numa_balancing,
457 .extra1 = SYSCTL_ZERO,
458 .extra2 = SYSCTL_ONE,
460 #endif /* CONFIG_NUMA_BALANCING */
461 #endif /* CONFIG_SCHED_DEBUG */
463 .procname = "sched_rt_period_us",
464 .data = &sysctl_sched_rt_period,
465 .maxlen = sizeof(unsigned int),
467 .proc_handler = sched_rt_handler,
468 .extra1 = SYSCTL_ONE,
469 .extra2 = SYSCTL_INT_MAX,
472 .procname = "sched_rt_runtime_us",
473 .data = &sysctl_sched_rt_runtime,
474 .maxlen = sizeof(int),
476 .proc_handler = sched_rt_handler,
478 .extra2 = SYSCTL_INT_MAX,
481 .procname = "sched_rr_timeslice_ms",
482 .data = &sysctl_sched_rr_timeslice,
483 .maxlen = sizeof(int),
485 .proc_handler = sched_rr_handler,
487 #ifdef CONFIG_UCLAMP_TASK
489 .procname = "sched_util_clamp_min",
490 .data = &sysctl_sched_uclamp_util_min,
491 .maxlen = sizeof(unsigned int),
493 .proc_handler = sysctl_sched_uclamp_handler,
496 .procname = "sched_util_clamp_max",
497 .data = &sysctl_sched_uclamp_util_max,
498 .maxlen = sizeof(unsigned int),
500 .proc_handler = sysctl_sched_uclamp_handler,
503 #ifdef CONFIG_SCHED_AUTOGROUP
505 .procname = "sched_autogroup_enabled",
506 .data = &sysctl_sched_autogroup_enabled,
507 .maxlen = sizeof(unsigned int),
509 .proc_handler = proc_dointvec_minmax,
510 .extra1 = SYSCTL_ZERO,
511 .extra2 = SYSCTL_ONE,
514 #ifdef CONFIG_CFS_BANDWIDTH
516 .procname = "sched_cfs_bandwidth_slice_us",
517 .data = &sysctl_sched_cfs_bandwidth_slice,
518 .maxlen = sizeof(unsigned int),
520 .proc_handler = proc_dointvec_minmax,
521 .extra1 = SYSCTL_ONE,
524 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
526 .procname = "sched_energy_aware",
527 .data = &sysctl_sched_energy_aware,
528 .maxlen = sizeof(unsigned int),
530 .proc_handler = sched_energy_aware_handler,
531 .extra1 = SYSCTL_ZERO,
532 .extra2 = SYSCTL_ONE,
535 #ifdef CONFIG_PROVE_LOCKING
537 .procname = "prove_locking",
538 .data = &prove_locking,
539 .maxlen = sizeof(int),
541 .proc_handler = proc_dointvec,
544 #ifdef CONFIG_LOCK_STAT
546 .procname = "lock_stat",
548 .maxlen = sizeof(int),
550 .proc_handler = proc_dointvec,
555 .data = &panic_timeout,
556 .maxlen = sizeof(int),
558 .proc_handler = proc_dointvec,
560 #ifdef CONFIG_COREDUMP
562 .procname = "core_uses_pid",
563 .data = &core_uses_pid,
564 .maxlen = sizeof(int),
566 .proc_handler = proc_dointvec,
569 .procname = "core_pattern",
570 .data = core_pattern,
571 .maxlen = CORENAME_MAX_SIZE,
573 .proc_handler = proc_dostring_coredump,
576 .procname = "core_pipe_limit",
577 .data = &core_pipe_limit,
578 .maxlen = sizeof(unsigned int),
580 .proc_handler = proc_dointvec,
583 #ifdef CONFIG_PROC_SYSCTL
585 .procname = "tainted",
586 .maxlen = sizeof(long),
588 .proc_handler = proc_taint,
591 .procname = "sysctl_writes_strict",
592 .data = &sysctl_writes_strict,
593 .maxlen = sizeof(int),
595 .proc_handler = proc_dointvec_minmax,
597 .extra2 = SYSCTL_ONE,
600 #ifdef CONFIG_LATENCYTOP
602 .procname = "latencytop",
603 .data = &latencytop_enabled,
604 .maxlen = sizeof(int),
606 .proc_handler = sysctl_latencytop,
609 #ifdef CONFIG_BLK_DEV_INITRD
611 .procname = "real-root-dev",
612 .data = &real_root_dev,
613 .maxlen = sizeof(int),
615 .proc_handler = proc_dointvec,
619 .procname = "print-fatal-signals",
620 .data = &print_fatal_signals,
621 .maxlen = sizeof(int),
623 .proc_handler = proc_dointvec,
627 .procname = "reboot-cmd",
628 .data = reboot_command,
631 .proc_handler = proc_dostring,
634 .procname = "stop-a",
635 .data = &stop_a_enabled,
636 .maxlen = sizeof (int),
638 .proc_handler = proc_dointvec,
641 .procname = "scons-poweroff",
642 .data = &scons_pwroff,
643 .maxlen = sizeof (int),
645 .proc_handler = proc_dointvec,
648 #ifdef CONFIG_SPARC64
650 .procname = "tsb-ratio",
651 .data = &sysctl_tsb_ratio,
652 .maxlen = sizeof (int),
654 .proc_handler = proc_dointvec,
659 .procname = "soft-power",
660 .data = &pwrsw_enabled,
661 .maxlen = sizeof (int),
663 .proc_handler = proc_dointvec,
666 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
668 .procname = "unaligned-trap",
669 .data = &unaligned_enabled,
670 .maxlen = sizeof (int),
672 .proc_handler = proc_dointvec,
676 .procname = "ctrl-alt-del",
678 .maxlen = sizeof(int),
680 .proc_handler = proc_dointvec,
682 #ifdef CONFIG_FUNCTION_TRACER
684 .procname = "ftrace_enabled",
685 .data = &ftrace_enabled,
686 .maxlen = sizeof(int),
688 .proc_handler = ftrace_enable_sysctl,
691 #ifdef CONFIG_STACK_TRACER
693 .procname = "stack_tracer_enabled",
694 .data = &stack_tracer_enabled,
695 .maxlen = sizeof(int),
697 .proc_handler = stack_trace_sysctl,
700 #ifdef CONFIG_TRACING
702 .procname = "ftrace_dump_on_oops",
703 .data = &ftrace_dump_on_oops,
704 .maxlen = sizeof(int),
706 .proc_handler = proc_dointvec,
709 .procname = "traceoff_on_warning",
710 .data = &__disable_trace_on_warning,
711 .maxlen = sizeof(__disable_trace_on_warning),
713 .proc_handler = proc_dointvec,
716 .procname = "tracepoint_printk",
717 .data = &tracepoint_printk,
718 .maxlen = sizeof(tracepoint_printk),
720 .proc_handler = tracepoint_printk_sysctl,
723 #ifdef CONFIG_KEXEC_CORE
725 .procname = "kexec_load_disabled",
726 .data = &kexec_load_disabled,
727 .maxlen = sizeof(int),
729 /* only handle a transition from default "0" to "1" */
730 .proc_handler = proc_dointvec_minmax,
731 .extra1 = SYSCTL_ONE,
732 .extra2 = SYSCTL_ONE,
735 #ifdef CONFIG_MODULES
737 .procname = "modprobe",
738 .data = &modprobe_path,
739 .maxlen = KMOD_PATH_LEN,
741 .proc_handler = proc_dostring,
744 .procname = "modules_disabled",
745 .data = &modules_disabled,
746 .maxlen = sizeof(int),
748 /* only handle a transition from default "0" to "1" */
749 .proc_handler = proc_dointvec_minmax,
750 .extra1 = SYSCTL_ONE,
751 .extra2 = SYSCTL_ONE,
754 #ifdef CONFIG_UEVENT_HELPER
756 .procname = "hotplug",
757 .data = &uevent_helper,
758 .maxlen = UEVENT_HELPER_PATH_LEN,
760 .proc_handler = proc_dostring,
763 #ifdef CONFIG_CHR_DEV_SG
765 .procname = "sg-big-buff",
766 .data = &sg_big_buff,
767 .maxlen = sizeof (int),
769 .proc_handler = proc_dointvec,
772 #ifdef CONFIG_BSD_PROCESS_ACCT
776 .maxlen = 3*sizeof(int),
778 .proc_handler = proc_dointvec,
781 #ifdef CONFIG_MAGIC_SYSRQ
784 .data = &__sysrq_enabled,
785 .maxlen = sizeof (int),
787 .proc_handler = sysrq_sysctl_handler,
790 #ifdef CONFIG_PROC_SYSCTL
792 .procname = "cad_pid",
794 .maxlen = sizeof (int),
796 .proc_handler = proc_do_cad_pid,
800 .procname = "threads-max",
802 .maxlen = sizeof(int),
804 .proc_handler = sysctl_max_threads,
807 .procname = "random",
809 .child = random_table,
812 .procname = "usermodehelper",
814 .child = usermodehelper_table,
816 #ifdef CONFIG_FW_LOADER_USER_HELPER
818 .procname = "firmware_config",
820 .child = firmware_config_table,
824 .procname = "overflowuid",
825 .data = &overflowuid,
826 .maxlen = sizeof(int),
828 .proc_handler = proc_dointvec_minmax,
829 .extra1 = &minolduid,
830 .extra2 = &maxolduid,
833 .procname = "overflowgid",
834 .data = &overflowgid,
835 .maxlen = sizeof(int),
837 .proc_handler = proc_dointvec_minmax,
838 .extra1 = &minolduid,
839 .extra2 = &maxolduid,
842 #ifdef CONFIG_MATHEMU
844 .procname = "ieee_emulation_warnings",
845 .data = &sysctl_ieee_emulation_warnings,
846 .maxlen = sizeof(int),
848 .proc_handler = proc_dointvec,
852 .procname = "userprocess_debug",
853 .data = &show_unhandled_signals,
854 .maxlen = sizeof(int),
856 .proc_handler = proc_dointvec,
860 .procname = "pid_max",
862 .maxlen = sizeof (int),
864 .proc_handler = proc_dointvec_minmax,
865 .extra1 = &pid_max_min,
866 .extra2 = &pid_max_max,
869 .procname = "panic_on_oops",
870 .data = &panic_on_oops,
871 .maxlen = sizeof(int),
873 .proc_handler = proc_dointvec,
876 .procname = "panic_print",
877 .data = &panic_print,
878 .maxlen = sizeof(unsigned long),
880 .proc_handler = proc_doulongvec_minmax,
882 #if defined CONFIG_PRINTK
884 .procname = "printk",
885 .data = &console_loglevel,
886 .maxlen = 4*sizeof(int),
888 .proc_handler = proc_dointvec,
891 .procname = "printk_ratelimit",
892 .data = &printk_ratelimit_state.interval,
893 .maxlen = sizeof(int),
895 .proc_handler = proc_dointvec_jiffies,
898 .procname = "printk_ratelimit_burst",
899 .data = &printk_ratelimit_state.burst,
900 .maxlen = sizeof(int),
902 .proc_handler = proc_dointvec,
905 .procname = "printk_delay",
906 .data = &printk_delay_msec,
907 .maxlen = sizeof(int),
909 .proc_handler = proc_dointvec_minmax,
910 .extra1 = SYSCTL_ZERO,
911 .extra2 = &ten_thousand,
914 .procname = "printk_devkmsg",
915 .data = devkmsg_log_str,
916 .maxlen = DEVKMSG_STR_MAX_SIZE,
918 .proc_handler = devkmsg_sysctl_set_loglvl,
921 .procname = "dmesg_restrict",
922 .data = &dmesg_restrict,
923 .maxlen = sizeof(int),
925 .proc_handler = proc_dointvec_minmax_sysadmin,
926 .extra1 = SYSCTL_ZERO,
927 .extra2 = SYSCTL_ONE,
930 .procname = "kptr_restrict",
931 .data = &kptr_restrict,
932 .maxlen = sizeof(int),
934 .proc_handler = proc_dointvec_minmax_sysadmin,
935 .extra1 = SYSCTL_ZERO,
940 .procname = "ngroups_max",
941 .data = &ngroups_max,
942 .maxlen = sizeof (int),
944 .proc_handler = proc_dointvec,
947 .procname = "cap_last_cap",
948 .data = (void *)&cap_last_cap,
949 .maxlen = sizeof(int),
951 .proc_handler = proc_dointvec,
953 #if defined(CONFIG_LOCKUP_DETECTOR)
955 .procname = "watchdog",
956 .data = &watchdog_user_enabled,
957 .maxlen = sizeof(int),
959 .proc_handler = proc_watchdog,
960 .extra1 = SYSCTL_ZERO,
961 .extra2 = SYSCTL_ONE,
964 .procname = "watchdog_thresh",
965 .data = &watchdog_thresh,
966 .maxlen = sizeof(int),
968 .proc_handler = proc_watchdog_thresh,
969 .extra1 = SYSCTL_ZERO,
973 .procname = "nmi_watchdog",
974 .data = &nmi_watchdog_user_enabled,
975 .maxlen = sizeof(int),
976 .mode = NMI_WATCHDOG_SYSCTL_PERM,
977 .proc_handler = proc_nmi_watchdog,
978 .extra1 = SYSCTL_ZERO,
979 .extra2 = SYSCTL_ONE,
982 .procname = "watchdog_cpumask",
983 .data = &watchdog_cpumask_bits,
986 .proc_handler = proc_watchdog_cpumask,
988 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
990 .procname = "soft_watchdog",
991 .data = &soft_watchdog_user_enabled,
992 .maxlen = sizeof(int),
994 .proc_handler = proc_soft_watchdog,
995 .extra1 = SYSCTL_ZERO,
996 .extra2 = SYSCTL_ONE,
999 .procname = "softlockup_panic",
1000 .data = &softlockup_panic,
1001 .maxlen = sizeof(int),
1003 .proc_handler = proc_dointvec_minmax,
1004 .extra1 = SYSCTL_ZERO,
1005 .extra2 = SYSCTL_ONE,
1009 .procname = "softlockup_all_cpu_backtrace",
1010 .data = &sysctl_softlockup_all_cpu_backtrace,
1011 .maxlen = sizeof(int),
1013 .proc_handler = proc_dointvec_minmax,
1014 .extra1 = SYSCTL_ZERO,
1015 .extra2 = SYSCTL_ONE,
1017 #endif /* CONFIG_SMP */
1019 #ifdef CONFIG_HARDLOCKUP_DETECTOR
1021 .procname = "hardlockup_panic",
1022 .data = &hardlockup_panic,
1023 .maxlen = sizeof(int),
1025 .proc_handler = proc_dointvec_minmax,
1026 .extra1 = SYSCTL_ZERO,
1027 .extra2 = SYSCTL_ONE,
1031 .procname = "hardlockup_all_cpu_backtrace",
1032 .data = &sysctl_hardlockup_all_cpu_backtrace,
1033 .maxlen = sizeof(int),
1035 .proc_handler = proc_dointvec_minmax,
1036 .extra1 = SYSCTL_ZERO,
1037 .extra2 = SYSCTL_ONE,
1039 #endif /* CONFIG_SMP */
1043 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1045 .procname = "unknown_nmi_panic",
1046 .data = &unknown_nmi_panic,
1047 .maxlen = sizeof (int),
1049 .proc_handler = proc_dointvec,
1052 #if defined(CONFIG_X86)
1054 .procname = "panic_on_unrecovered_nmi",
1055 .data = &panic_on_unrecovered_nmi,
1056 .maxlen = sizeof(int),
1058 .proc_handler = proc_dointvec,
1061 .procname = "panic_on_io_nmi",
1062 .data = &panic_on_io_nmi,
1063 .maxlen = sizeof(int),
1065 .proc_handler = proc_dointvec,
1067 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1069 .procname = "panic_on_stackoverflow",
1070 .data = &sysctl_panic_on_stackoverflow,
1071 .maxlen = sizeof(int),
1073 .proc_handler = proc_dointvec,
1077 .procname = "bootloader_type",
1078 .data = &bootloader_type,
1079 .maxlen = sizeof (int),
1081 .proc_handler = proc_dointvec,
1084 .procname = "bootloader_version",
1085 .data = &bootloader_version,
1086 .maxlen = sizeof (int),
1088 .proc_handler = proc_dointvec,
1091 .procname = "io_delay_type",
1092 .data = &io_delay_type,
1093 .maxlen = sizeof(int),
1095 .proc_handler = proc_dointvec,
1098 #if defined(CONFIG_MMU)
1100 .procname = "randomize_va_space",
1101 .data = &randomize_va_space,
1102 .maxlen = sizeof(int),
1104 .proc_handler = proc_dointvec,
1107 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1109 .procname = "spin_retry",
1110 .data = &spin_retry,
1111 .maxlen = sizeof (int),
1113 .proc_handler = proc_dointvec,
1116 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1118 .procname = "acpi_video_flags",
1119 .data = &acpi_realmode_flags,
1120 .maxlen = sizeof (unsigned long),
1122 .proc_handler = proc_doulongvec_minmax,
1125 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1127 .procname = "ignore-unaligned-usertrap",
1128 .data = &no_unaligned_warning,
1129 .maxlen = sizeof (int),
1131 .proc_handler = proc_dointvec,
1136 .procname = "unaligned-dump-stack",
1137 .data = &unaligned_dump_stack,
1138 .maxlen = sizeof (int),
1140 .proc_handler = proc_dointvec,
1143 #ifdef CONFIG_DETECT_HUNG_TASK
1145 .procname = "hung_task_panic",
1146 .data = &sysctl_hung_task_panic,
1147 .maxlen = sizeof(int),
1149 .proc_handler = proc_dointvec_minmax,
1150 .extra1 = SYSCTL_ZERO,
1151 .extra2 = SYSCTL_ONE,
1154 .procname = "hung_task_check_count",
1155 .data = &sysctl_hung_task_check_count,
1156 .maxlen = sizeof(int),
1158 .proc_handler = proc_dointvec_minmax,
1159 .extra1 = SYSCTL_ZERO,
1162 .procname = "hung_task_timeout_secs",
1163 .data = &sysctl_hung_task_timeout_secs,
1164 .maxlen = sizeof(unsigned long),
1166 .proc_handler = proc_dohung_task_timeout_secs,
1167 .extra2 = &hung_task_timeout_max,
1170 .procname = "hung_task_check_interval_secs",
1171 .data = &sysctl_hung_task_check_interval_secs,
1172 .maxlen = sizeof(unsigned long),
1174 .proc_handler = proc_dohung_task_timeout_secs,
1175 .extra2 = &hung_task_timeout_max,
1178 .procname = "hung_task_warnings",
1179 .data = &sysctl_hung_task_warnings,
1180 .maxlen = sizeof(int),
1182 .proc_handler = proc_dointvec_minmax,
1186 #ifdef CONFIG_RT_MUTEXES
1188 .procname = "max_lock_depth",
1189 .data = &max_lock_depth,
1190 .maxlen = sizeof(int),
1192 .proc_handler = proc_dointvec,
1196 .procname = "poweroff_cmd",
1197 .data = &poweroff_cmd,
1198 .maxlen = POWEROFF_CMD_PATH_LEN,
1200 .proc_handler = proc_dostring,
1206 .child = key_sysctls,
1209 #ifdef CONFIG_PERF_EVENTS
1211 * User-space scripts rely on the existence of this file
1212 * as a feature check for perf_events being enabled.
1214 * So it's an ABI, do not remove!
1217 .procname = "perf_event_paranoid",
1218 .data = &sysctl_perf_event_paranoid,
1219 .maxlen = sizeof(sysctl_perf_event_paranoid),
1221 .proc_handler = proc_dointvec,
1224 .procname = "perf_event_mlock_kb",
1225 .data = &sysctl_perf_event_mlock,
1226 .maxlen = sizeof(sysctl_perf_event_mlock),
1228 .proc_handler = proc_dointvec,
1231 .procname = "perf_event_max_sample_rate",
1232 .data = &sysctl_perf_event_sample_rate,
1233 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1235 .proc_handler = perf_proc_update_handler,
1236 .extra1 = SYSCTL_ONE,
1239 .procname = "perf_cpu_time_max_percent",
1240 .data = &sysctl_perf_cpu_time_max_percent,
1241 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1243 .proc_handler = perf_cpu_time_max_percent_handler,
1244 .extra1 = SYSCTL_ZERO,
1245 .extra2 = &one_hundred,
1248 .procname = "perf_event_max_stack",
1249 .data = &sysctl_perf_event_max_stack,
1250 .maxlen = sizeof(sysctl_perf_event_max_stack),
1252 .proc_handler = perf_event_max_stack_handler,
1253 .extra1 = SYSCTL_ZERO,
1254 .extra2 = &six_hundred_forty_kb,
1257 .procname = "perf_event_max_contexts_per_stack",
1258 .data = &sysctl_perf_event_max_contexts_per_stack,
1259 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1261 .proc_handler = perf_event_max_stack_handler,
1262 .extra1 = SYSCTL_ZERO,
1263 .extra2 = &one_thousand,
1267 .procname = "panic_on_warn",
1268 .data = &panic_on_warn,
1269 .maxlen = sizeof(int),
1271 .proc_handler = proc_dointvec_minmax,
1272 .extra1 = SYSCTL_ZERO,
1273 .extra2 = SYSCTL_ONE,
1275 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1277 .procname = "timer_migration",
1278 .data = &sysctl_timer_migration,
1279 .maxlen = sizeof(unsigned int),
1281 .proc_handler = timer_migration_handler,
1282 .extra1 = SYSCTL_ZERO,
1283 .extra2 = SYSCTL_ONE,
1286 #ifdef CONFIG_BPF_SYSCALL
1288 .procname = "unprivileged_bpf_disabled",
1289 .data = &sysctl_unprivileged_bpf_disabled,
1290 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1292 .proc_handler = bpf_unpriv_handler,
1293 .extra1 = SYSCTL_ZERO,
1297 .procname = "bpf_stats_enabled",
1298 .data = &bpf_stats_enabled_key.key,
1299 .maxlen = sizeof(bpf_stats_enabled_key),
1301 .proc_handler = proc_do_static_key,
1304 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1306 .procname = "panic_on_rcu_stall",
1307 .data = &sysctl_panic_on_rcu_stall,
1308 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1310 .proc_handler = proc_dointvec_minmax,
1311 .extra1 = SYSCTL_ZERO,
1312 .extra2 = SYSCTL_ONE,
1315 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1317 .procname = "stack_erasing",
1319 .maxlen = sizeof(int),
1321 .proc_handler = stack_erasing_sysctl,
1322 .extra1 = SYSCTL_ZERO,
1323 .extra2 = SYSCTL_ONE,
1329 static struct ctl_table vm_table[] = {
1331 .procname = "overcommit_memory",
1332 .data = &sysctl_overcommit_memory,
1333 .maxlen = sizeof(sysctl_overcommit_memory),
1335 .proc_handler = proc_dointvec_minmax,
1336 .extra1 = SYSCTL_ZERO,
1340 .procname = "panic_on_oom",
1341 .data = &sysctl_panic_on_oom,
1342 .maxlen = sizeof(sysctl_panic_on_oom),
1344 .proc_handler = proc_dointvec_minmax,
1345 .extra1 = SYSCTL_ZERO,
1349 .procname = "oom_kill_allocating_task",
1350 .data = &sysctl_oom_kill_allocating_task,
1351 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1353 .proc_handler = proc_dointvec,
1356 .procname = "oom_dump_tasks",
1357 .data = &sysctl_oom_dump_tasks,
1358 .maxlen = sizeof(sysctl_oom_dump_tasks),
1360 .proc_handler = proc_dointvec,
1363 .procname = "overcommit_ratio",
1364 .data = &sysctl_overcommit_ratio,
1365 .maxlen = sizeof(sysctl_overcommit_ratio),
1367 .proc_handler = overcommit_ratio_handler,
1370 .procname = "overcommit_kbytes",
1371 .data = &sysctl_overcommit_kbytes,
1372 .maxlen = sizeof(sysctl_overcommit_kbytes),
1374 .proc_handler = overcommit_kbytes_handler,
1377 .procname = "page-cluster",
1378 .data = &page_cluster,
1379 .maxlen = sizeof(int),
1381 .proc_handler = proc_dointvec_minmax,
1382 .extra1 = SYSCTL_ZERO,
1385 .procname = "dirty_background_ratio",
1386 .data = &dirty_background_ratio,
1387 .maxlen = sizeof(dirty_background_ratio),
1389 .proc_handler = dirty_background_ratio_handler,
1390 .extra1 = SYSCTL_ZERO,
1391 .extra2 = &one_hundred,
1394 .procname = "dirty_background_bytes",
1395 .data = &dirty_background_bytes,
1396 .maxlen = sizeof(dirty_background_bytes),
1398 .proc_handler = dirty_background_bytes_handler,
1402 .procname = "dirty_ratio",
1403 .data = &vm_dirty_ratio,
1404 .maxlen = sizeof(vm_dirty_ratio),
1406 .proc_handler = dirty_ratio_handler,
1407 .extra1 = SYSCTL_ZERO,
1408 .extra2 = &one_hundred,
1411 .procname = "dirty_bytes",
1412 .data = &vm_dirty_bytes,
1413 .maxlen = sizeof(vm_dirty_bytes),
1415 .proc_handler = dirty_bytes_handler,
1416 .extra1 = &dirty_bytes_min,
1419 .procname = "dirty_writeback_centisecs",
1420 .data = &dirty_writeback_interval,
1421 .maxlen = sizeof(dirty_writeback_interval),
1423 .proc_handler = dirty_writeback_centisecs_handler,
1426 .procname = "dirty_expire_centisecs",
1427 .data = &dirty_expire_interval,
1428 .maxlen = sizeof(dirty_expire_interval),
1430 .proc_handler = proc_dointvec_minmax,
1431 .extra1 = SYSCTL_ZERO,
1434 .procname = "dirtytime_expire_seconds",
1435 .data = &dirtytime_expire_interval,
1436 .maxlen = sizeof(dirtytime_expire_interval),
1438 .proc_handler = dirtytime_interval_handler,
1439 .extra1 = SYSCTL_ZERO,
1442 .procname = "swappiness",
1443 .data = &vm_swappiness,
1444 .maxlen = sizeof(vm_swappiness),
1446 .proc_handler = proc_dointvec_minmax,
1447 .extra1 = SYSCTL_ZERO,
1448 .extra2 = &one_hundred,
1452 .procname = "numa_stat",
1453 .data = &sysctl_vm_numa_stat,
1454 .maxlen = sizeof(int),
1456 .proc_handler = sysctl_vm_numa_stat_handler,
1457 .extra1 = SYSCTL_ZERO,
1458 .extra2 = SYSCTL_ONE,
1461 #ifdef CONFIG_HUGETLB_PAGE
1463 .procname = "nr_hugepages",
1465 .maxlen = sizeof(unsigned long),
1467 .proc_handler = hugetlb_sysctl_handler,
1471 .procname = "nr_hugepages_mempolicy",
1473 .maxlen = sizeof(unsigned long),
1475 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1479 .procname = "hugetlb_shm_group",
1480 .data = &sysctl_hugetlb_shm_group,
1481 .maxlen = sizeof(gid_t),
1483 .proc_handler = proc_dointvec,
1486 .procname = "nr_overcommit_hugepages",
1488 .maxlen = sizeof(unsigned long),
1490 .proc_handler = hugetlb_overcommit_handler,
1494 .procname = "lowmem_reserve_ratio",
1495 .data = &sysctl_lowmem_reserve_ratio,
1496 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1498 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1501 .procname = "drop_caches",
1502 .data = &sysctl_drop_caches,
1503 .maxlen = sizeof(int),
1505 .proc_handler = drop_caches_sysctl_handler,
1506 .extra1 = SYSCTL_ONE,
1509 #ifdef CONFIG_COMPACTION
1511 .procname = "compact_memory",
1512 .data = &sysctl_compact_memory,
1513 .maxlen = sizeof(int),
1515 .proc_handler = sysctl_compaction_handler,
1518 .procname = "extfrag_threshold",
1519 .data = &sysctl_extfrag_threshold,
1520 .maxlen = sizeof(int),
1522 .proc_handler = proc_dointvec_minmax,
1523 .extra1 = &min_extfrag_threshold,
1524 .extra2 = &max_extfrag_threshold,
1527 .procname = "compact_unevictable_allowed",
1528 .data = &sysctl_compact_unevictable_allowed,
1529 .maxlen = sizeof(int),
1531 .proc_handler = proc_dointvec,
1532 .extra1 = SYSCTL_ZERO,
1533 .extra2 = SYSCTL_ONE,
1536 #endif /* CONFIG_COMPACTION */
1538 .procname = "min_free_kbytes",
1539 .data = &min_free_kbytes,
1540 .maxlen = sizeof(min_free_kbytes),
1542 .proc_handler = min_free_kbytes_sysctl_handler,
1543 .extra1 = SYSCTL_ZERO,
1546 .procname = "watermark_boost_factor",
1547 .data = &watermark_boost_factor,
1548 .maxlen = sizeof(watermark_boost_factor),
1550 .proc_handler = watermark_boost_factor_sysctl_handler,
1551 .extra1 = SYSCTL_ZERO,
1554 .procname = "watermark_scale_factor",
1555 .data = &watermark_scale_factor,
1556 .maxlen = sizeof(watermark_scale_factor),
1558 .proc_handler = watermark_scale_factor_sysctl_handler,
1559 .extra1 = SYSCTL_ONE,
1560 .extra2 = &one_thousand,
1563 .procname = "percpu_pagelist_fraction",
1564 .data = &percpu_pagelist_fraction,
1565 .maxlen = sizeof(percpu_pagelist_fraction),
1567 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1568 .extra1 = SYSCTL_ZERO,
1571 .procname = "page_lock_unfairness",
1572 .data = &sysctl_page_lock_unfairness,
1573 .maxlen = sizeof(sysctl_page_lock_unfairness),
1575 .proc_handler = proc_dointvec_minmax,
1576 .extra1 = SYSCTL_ZERO,
1580 .procname = "max_map_count",
1581 .data = &sysctl_max_map_count,
1582 .maxlen = sizeof(sysctl_max_map_count),
1584 .proc_handler = proc_dointvec_minmax,
1585 .extra1 = SYSCTL_ZERO,
1589 .procname = "nr_trim_pages",
1590 .data = &sysctl_nr_trim_pages,
1591 .maxlen = sizeof(sysctl_nr_trim_pages),
1593 .proc_handler = proc_dointvec_minmax,
1594 .extra1 = SYSCTL_ZERO,
1598 .procname = "laptop_mode",
1599 .data = &laptop_mode,
1600 .maxlen = sizeof(laptop_mode),
1602 .proc_handler = proc_dointvec_jiffies,
1605 .procname = "block_dump",
1606 .data = &block_dump,
1607 .maxlen = sizeof(block_dump),
1609 .proc_handler = proc_dointvec_minmax,
1610 .extra1 = SYSCTL_ZERO,
1613 .procname = "vfs_cache_pressure",
1614 .data = &sysctl_vfs_cache_pressure,
1615 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1617 .proc_handler = proc_dointvec_minmax,
1618 .extra1 = SYSCTL_ZERO,
1620 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
1621 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
1623 .procname = "legacy_va_layout",
1624 .data = &sysctl_legacy_va_layout,
1625 .maxlen = sizeof(sysctl_legacy_va_layout),
1627 .proc_handler = proc_dointvec_minmax,
1628 .extra1 = SYSCTL_ZERO,
1633 .procname = "zone_reclaim_mode",
1634 .data = &node_reclaim_mode,
1635 .maxlen = sizeof(node_reclaim_mode),
1637 .proc_handler = proc_dointvec_minmax,
1638 .extra1 = SYSCTL_ZERO,
1641 .procname = "min_unmapped_ratio",
1642 .data = &sysctl_min_unmapped_ratio,
1643 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1645 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1646 .extra1 = SYSCTL_ZERO,
1647 .extra2 = &one_hundred,
1650 .procname = "min_slab_ratio",
1651 .data = &sysctl_min_slab_ratio,
1652 .maxlen = sizeof(sysctl_min_slab_ratio),
1654 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1655 .extra1 = SYSCTL_ZERO,
1656 .extra2 = &one_hundred,
1661 .procname = "stat_interval",
1662 .data = &sysctl_stat_interval,
1663 .maxlen = sizeof(sysctl_stat_interval),
1665 .proc_handler = proc_dointvec_jiffies,
1668 .procname = "stat_refresh",
1672 .proc_handler = vmstat_refresh,
1677 .procname = "mmap_min_addr",
1678 .data = &dac_mmap_min_addr,
1679 .maxlen = sizeof(unsigned long),
1681 .proc_handler = mmap_min_addr_handler,
1686 .procname = "numa_zonelist_order",
1687 .data = &numa_zonelist_order,
1688 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1690 .proc_handler = numa_zonelist_order_handler,
1693 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1694 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1696 .procname = "vdso_enabled",
1697 #ifdef CONFIG_X86_32
1698 .data = &vdso32_enabled,
1699 .maxlen = sizeof(vdso32_enabled),
1701 .data = &vdso_enabled,
1702 .maxlen = sizeof(vdso_enabled),
1705 .proc_handler = proc_dointvec,
1706 .extra1 = SYSCTL_ZERO,
1709 #ifdef CONFIG_HIGHMEM
1711 .procname = "highmem_is_dirtyable",
1712 .data = &vm_highmem_is_dirtyable,
1713 .maxlen = sizeof(vm_highmem_is_dirtyable),
1715 .proc_handler = proc_dointvec_minmax,
1716 .extra1 = SYSCTL_ZERO,
1717 .extra2 = SYSCTL_ONE,
1720 #ifdef CONFIG_MEMORY_FAILURE
1722 .procname = "memory_failure_early_kill",
1723 .data = &sysctl_memory_failure_early_kill,
1724 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1726 .proc_handler = proc_dointvec_minmax,
1727 .extra1 = SYSCTL_ZERO,
1728 .extra2 = SYSCTL_ONE,
1731 .procname = "memory_failure_recovery",
1732 .data = &sysctl_memory_failure_recovery,
1733 .maxlen = sizeof(sysctl_memory_failure_recovery),
1735 .proc_handler = proc_dointvec_minmax,
1736 .extra1 = SYSCTL_ZERO,
1737 .extra2 = SYSCTL_ONE,
1741 .procname = "user_reserve_kbytes",
1742 .data = &sysctl_user_reserve_kbytes,
1743 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1745 .proc_handler = proc_doulongvec_minmax,
1748 .procname = "admin_reserve_kbytes",
1749 .data = &sysctl_admin_reserve_kbytes,
1750 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1752 .proc_handler = proc_doulongvec_minmax,
1754 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1756 .procname = "mmap_rnd_bits",
1757 .data = &mmap_rnd_bits,
1758 .maxlen = sizeof(mmap_rnd_bits),
1760 .proc_handler = proc_dointvec_minmax,
1761 .extra1 = (void *)&mmap_rnd_bits_min,
1762 .extra2 = (void *)&mmap_rnd_bits_max,
1765 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1767 .procname = "mmap_rnd_compat_bits",
1768 .data = &mmap_rnd_compat_bits,
1769 .maxlen = sizeof(mmap_rnd_compat_bits),
1771 .proc_handler = proc_dointvec_minmax,
1772 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1773 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1776 #ifdef CONFIG_USERFAULTFD
1778 .procname = "unprivileged_userfaultfd",
1779 .data = &sysctl_unprivileged_userfaultfd,
1780 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
1782 .proc_handler = proc_dointvec_minmax,
1783 .extra1 = SYSCTL_ZERO,
1784 .extra2 = SYSCTL_ONE,
1790 static struct ctl_table fs_table[] = {
1792 .procname = "inode-nr",
1793 .data = &inodes_stat,
1794 .maxlen = 2*sizeof(long),
1796 .proc_handler = proc_nr_inodes,
1799 .procname = "inode-state",
1800 .data = &inodes_stat,
1801 .maxlen = 7*sizeof(long),
1803 .proc_handler = proc_nr_inodes,
1806 .procname = "file-nr",
1807 .data = &files_stat,
1808 .maxlen = sizeof(files_stat),
1810 .proc_handler = proc_nr_files,
1813 .procname = "file-max",
1814 .data = &files_stat.max_files,
1815 .maxlen = sizeof(files_stat.max_files),
1817 .proc_handler = proc_doulongvec_minmax,
1819 .extra2 = &long_max,
1822 .procname = "nr_open",
1823 .data = &sysctl_nr_open,
1824 .maxlen = sizeof(unsigned int),
1826 .proc_handler = proc_dointvec_minmax,
1827 .extra1 = &sysctl_nr_open_min,
1828 .extra2 = &sysctl_nr_open_max,
1831 .procname = "dentry-state",
1832 .data = &dentry_stat,
1833 .maxlen = 6*sizeof(long),
1835 .proc_handler = proc_nr_dentry,
1838 .procname = "overflowuid",
1839 .data = &fs_overflowuid,
1840 .maxlen = sizeof(int),
1842 .proc_handler = proc_dointvec_minmax,
1843 .extra1 = &minolduid,
1844 .extra2 = &maxolduid,
1847 .procname = "overflowgid",
1848 .data = &fs_overflowgid,
1849 .maxlen = sizeof(int),
1851 .proc_handler = proc_dointvec_minmax,
1852 .extra1 = &minolduid,
1853 .extra2 = &maxolduid,
1855 #ifdef CONFIG_FILE_LOCKING
1857 .procname = "leases-enable",
1858 .data = &leases_enable,
1859 .maxlen = sizeof(int),
1861 .proc_handler = proc_dointvec,
1864 #ifdef CONFIG_DNOTIFY
1866 .procname = "dir-notify-enable",
1867 .data = &dir_notify_enable,
1868 .maxlen = sizeof(int),
1870 .proc_handler = proc_dointvec,
1874 #ifdef CONFIG_FILE_LOCKING
1876 .procname = "lease-break-time",
1877 .data = &lease_break_time,
1878 .maxlen = sizeof(int),
1880 .proc_handler = proc_dointvec,
1885 .procname = "aio-nr",
1887 .maxlen = sizeof(aio_nr),
1889 .proc_handler = proc_doulongvec_minmax,
1892 .procname = "aio-max-nr",
1893 .data = &aio_max_nr,
1894 .maxlen = sizeof(aio_max_nr),
1896 .proc_handler = proc_doulongvec_minmax,
1898 #endif /* CONFIG_AIO */
1899 #ifdef CONFIG_INOTIFY_USER
1901 .procname = "inotify",
1903 .child = inotify_table,
1908 .procname = "epoll",
1910 .child = epoll_table,
1915 .procname = "protected_symlinks",
1916 .data = &sysctl_protected_symlinks,
1917 .maxlen = sizeof(int),
1919 .proc_handler = proc_dointvec_minmax,
1920 .extra1 = SYSCTL_ZERO,
1921 .extra2 = SYSCTL_ONE,
1924 .procname = "protected_hardlinks",
1925 .data = &sysctl_protected_hardlinks,
1926 .maxlen = sizeof(int),
1928 .proc_handler = proc_dointvec_minmax,
1929 .extra1 = SYSCTL_ZERO,
1930 .extra2 = SYSCTL_ONE,
1933 .procname = "protected_fifos",
1934 .data = &sysctl_protected_fifos,
1935 .maxlen = sizeof(int),
1937 .proc_handler = proc_dointvec_minmax,
1938 .extra1 = SYSCTL_ZERO,
1942 .procname = "protected_regular",
1943 .data = &sysctl_protected_regular,
1944 .maxlen = sizeof(int),
1946 .proc_handler = proc_dointvec_minmax,
1947 .extra1 = SYSCTL_ZERO,
1951 .procname = "suid_dumpable",
1952 .data = &suid_dumpable,
1953 .maxlen = sizeof(int),
1955 .proc_handler = proc_dointvec_minmax_coredump,
1956 .extra1 = SYSCTL_ZERO,
1959 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1961 .procname = "binfmt_misc",
1963 .child = sysctl_mount_point,
1967 .procname = "pipe-max-size",
1968 .data = &pipe_max_size,
1969 .maxlen = sizeof(pipe_max_size),
1971 .proc_handler = proc_dopipe_max_size,
1974 .procname = "pipe-user-pages-hard",
1975 .data = &pipe_user_pages_hard,
1976 .maxlen = sizeof(pipe_user_pages_hard),
1978 .proc_handler = proc_doulongvec_minmax,
1981 .procname = "pipe-user-pages-soft",
1982 .data = &pipe_user_pages_soft,
1983 .maxlen = sizeof(pipe_user_pages_soft),
1985 .proc_handler = proc_doulongvec_minmax,
1988 .procname = "mount-max",
1989 .data = &sysctl_mount_max,
1990 .maxlen = sizeof(unsigned int),
1992 .proc_handler = proc_dointvec_minmax,
1993 .extra1 = SYSCTL_ONE,
1998 static struct ctl_table debug_table[] = {
1999 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
2001 .procname = "exception-trace",
2002 .data = &show_unhandled_signals,
2003 .maxlen = sizeof(int),
2005 .proc_handler = proc_dointvec
2008 #if defined(CONFIG_OPTPROBES)
2010 .procname = "kprobes-optimization",
2011 .data = &sysctl_kprobes_optimization,
2012 .maxlen = sizeof(int),
2014 .proc_handler = proc_kprobes_optimization_handler,
2015 .extra1 = SYSCTL_ZERO,
2016 .extra2 = SYSCTL_ONE,
2022 static struct ctl_table dev_table[] = {
2026 int __init sysctl_init(void)
2028 struct ctl_table_header *hdr;
2030 hdr = register_sysctl_table(sysctl_base_table);
2031 kmemleak_not_leak(hdr);
2035 #endif /* CONFIG_SYSCTL */
2041 #ifdef CONFIG_PROC_SYSCTL
2043 static int _proc_do_string(char *data, int maxlen, int write,
2044 char __user *buffer,
2045 size_t *lenp, loff_t *ppos)
2051 if (!data || !maxlen || !*lenp) {
2057 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
2058 /* Only continue writes not past the end of buffer. */
2060 if (len > maxlen - 1)
2067 /* Start writing from beginning of buffer. */
2073 while ((p - buffer) < *lenp && len < maxlen - 1) {
2074 if (get_user(c, p++))
2076 if (c == 0 || c == '\n')
2097 if (copy_to_user(buffer, data, len))
2100 if (put_user('\n', buffer + len))
2110 static void warn_sysctl_write(struct ctl_table *table)
2112 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2113 "This will not be supported in the future. To silence this\n"
2114 "warning, set kernel.sysctl_writes_strict = -1\n",
2115 current->comm, table->procname);
2119 * proc_first_pos_non_zero_ignore - check if first position is allowed
2120 * @ppos: file position
2121 * @table: the sysctl table
2123 * Returns true if the first position is non-zero and the sysctl_writes_strict
2124 * mode indicates this is not allowed for numeric input types. String proc
2125 * handlers can ignore the return value.
2127 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2128 struct ctl_table *table)
2133 switch (sysctl_writes_strict) {
2134 case SYSCTL_WRITES_STRICT:
2136 case SYSCTL_WRITES_WARN:
2137 warn_sysctl_write(table);
2145 * proc_dostring - read a string sysctl
2146 * @table: the sysctl table
2147 * @write: %TRUE if this is a write to the sysctl file
2148 * @buffer: the user buffer
2149 * @lenp: the size of the user buffer
2150 * @ppos: file position
2152 * Reads/writes a string from/to the user buffer. If the kernel
2153 * buffer provided is not large enough to hold the string, the
2154 * string is truncated. The copied string is %NULL-terminated.
2155 * If the string is being read by the user process, it is copied
2156 * and a newline '\n' is added. It is truncated if the buffer is
2159 * Returns 0 on success.
2161 int proc_dostring(struct ctl_table *table, int write,
2162 void __user *buffer, size_t *lenp, loff_t *ppos)
2165 proc_first_pos_non_zero_ignore(ppos, table);
2167 return _proc_do_string((char *)(table->data), table->maxlen, write,
2168 (char __user *)buffer, lenp, ppos);
2171 static void proc_skip_spaces(char **buf, size_t *size)
2174 if (!isspace(**buf))
2181 static void proc_skip_char(char **buf, size_t *size, const char v)
2192 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2195 * @cp: kernel buffer containing the string to parse
2196 * @endp: pointer to store the trailing characters
2197 * @base: the base to use
2198 * @res: where the parsed integer will be stored
2200 * In case of success 0 is returned and @res will contain the parsed integer,
2201 * @endp will hold any trailing characters.
2202 * This function will fail the parse on overflow. If there wasn't an overflow
2203 * the function will defer the decision what characters count as invalid to the
2206 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2209 unsigned long long result;
2212 cp = _parse_integer_fixup_radix(cp, &base);
2213 rv = _parse_integer(cp, base, &result);
2214 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2222 *res = (unsigned long)result;
2226 #define TMPBUFLEN 22
2228 * proc_get_long - reads an ASCII formatted integer from a user buffer
2230 * @buf: a kernel buffer
2231 * @size: size of the kernel buffer
2232 * @val: this is where the number will be stored
2233 * @neg: set to %TRUE if number is negative
2234 * @perm_tr: a vector which contains the allowed trailers
2235 * @perm_tr_len: size of the perm_tr vector
2236 * @tr: pointer to store the trailer character
2238 * In case of success %0 is returned and @buf and @size are updated with
2239 * the amount of bytes read. If @tr is non-NULL and a trailing
2240 * character exists (size is non-zero after returning from this
2241 * function), @tr is updated with the trailing character.
2243 static int proc_get_long(char **buf, size_t *size,
2244 unsigned long *val, bool *neg,
2245 const char *perm_tr, unsigned perm_tr_len, char *tr)
2247 char *p, tmp[TMPBUFLEN];
2248 ssize_t len = *size;
2253 if (len > TMPBUFLEN - 1)
2254 len = TMPBUFLEN - 1;
2256 memcpy(tmp, *buf, len);
2260 if (*p == '-' && *size > 1) {
2268 if (strtoul_lenient(p, &p, 0, val))
2273 /* We don't know if the next char is whitespace thus we may accept
2274 * invalid integers (e.g. 1234...a) or two integers instead of one
2275 * (e.g. 123...1). So lets not allow such large numbers. */
2276 if (len == TMPBUFLEN - 1)
2279 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2282 if (tr && (len < *size))
2292 * proc_put_long - converts an integer to a decimal ASCII formatted string
2294 * @buf: the user buffer
2295 * @size: the size of the user buffer
2296 * @val: the integer to be converted
2297 * @neg: sign of the number, %TRUE for negative
2299 * In case of success %0 is returned and @buf and @size are updated with
2300 * the amount of bytes written.
2302 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2306 char tmp[TMPBUFLEN], *p = tmp;
2308 sprintf(p, "%s%lu", neg ? "-" : "", val);
2312 if (copy_to_user(*buf, tmp, len))
2320 static int proc_put_char(void __user **buf, size_t *size, char c)
2323 char __user **buffer = (char __user **)buf;
2324 if (put_user(c, *buffer))
2326 (*size)--, (*buffer)++;
2332 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2334 int write, void *data)
2338 if (*lvalp > (unsigned long) INT_MAX + 1)
2342 if (*lvalp > (unsigned long) INT_MAX)
2350 *lvalp = -(unsigned long)val;
2353 *lvalp = (unsigned long)val;
2359 static int do_proc_douintvec_conv(unsigned long *lvalp,
2361 int write, void *data)
2364 if (*lvalp > UINT_MAX)
2368 unsigned int val = *valp;
2369 *lvalp = (unsigned long)val;
2374 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2376 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2377 int write, void __user *buffer,
2378 size_t *lenp, loff_t *ppos,
2379 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2380 int write, void *data),
2383 int *i, vleft, first = 1, err = 0;
2385 char *kbuf = NULL, *p;
2387 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2392 i = (int *) tbl_data;
2393 vleft = table->maxlen / sizeof(*i);
2397 conv = do_proc_dointvec_conv;
2400 if (proc_first_pos_non_zero_ignore(ppos, table))
2403 if (left > PAGE_SIZE - 1)
2404 left = PAGE_SIZE - 1;
2405 p = kbuf = memdup_user_nul(buffer, left);
2407 return PTR_ERR(kbuf);
2410 for (; left && vleft--; i++, first=0) {
2415 proc_skip_spaces(&p, &left);
2419 err = proc_get_long(&p, &left, &lval, &neg,
2421 sizeof(proc_wspace_sep), NULL);
2424 if (conv(&neg, &lval, i, 1, data)) {
2429 if (conv(&neg, &lval, i, 0, data)) {
2434 err = proc_put_char(&buffer, &left, '\t');
2437 err = proc_put_long(&buffer, &left, lval, neg);
2443 if (!write && !first && left && !err)
2444 err = proc_put_char(&buffer, &left, '\n');
2445 if (write && !err && left)
2446 proc_skip_spaces(&p, &left);
2450 return err ? : -EINVAL;
2458 static int do_proc_dointvec(struct ctl_table *table, int write,
2459 void __user *buffer, size_t *lenp, loff_t *ppos,
2460 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2461 int write, void *data),
2464 return __do_proc_dointvec(table->data, table, write,
2465 buffer, lenp, ppos, conv, data);
2468 static int do_proc_douintvec_w(unsigned int *tbl_data,
2469 struct ctl_table *table,
2470 void __user *buffer,
2471 size_t *lenp, loff_t *ppos,
2472 int (*conv)(unsigned long *lvalp,
2474 int write, void *data),
2481 char *kbuf = NULL, *p;
2485 if (proc_first_pos_non_zero_ignore(ppos, table))
2488 if (left > PAGE_SIZE - 1)
2489 left = PAGE_SIZE - 1;
2491 p = kbuf = memdup_user_nul(buffer, left);
2495 proc_skip_spaces(&p, &left);
2501 err = proc_get_long(&p, &left, &lval, &neg,
2503 sizeof(proc_wspace_sep), NULL);
2509 if (conv(&lval, tbl_data, 1, data)) {
2515 proc_skip_spaces(&p, &left);
2524 /* This is in keeping with old __do_proc_dointvec() */
2530 static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2531 size_t *lenp, loff_t *ppos,
2532 int (*conv)(unsigned long *lvalp,
2534 int write, void *data),
2543 if (conv(&lval, tbl_data, 0, data)) {
2548 err = proc_put_long(&buffer, &left, lval, false);
2552 err = proc_put_char(&buffer, &left, '\n');
2561 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2562 int write, void __user *buffer,
2563 size_t *lenp, loff_t *ppos,
2564 int (*conv)(unsigned long *lvalp,
2566 int write, void *data),
2569 unsigned int *i, vleft;
2571 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2576 i = (unsigned int *) tbl_data;
2577 vleft = table->maxlen / sizeof(*i);
2580 * Arrays are not supported, keep this simple. *Do not* add
2589 conv = do_proc_douintvec_conv;
2592 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2594 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2597 static int do_proc_douintvec(struct ctl_table *table, int write,
2598 void __user *buffer, size_t *lenp, loff_t *ppos,
2599 int (*conv)(unsigned long *lvalp,
2601 int write, void *data),
2604 return __do_proc_douintvec(table->data, table, write,
2605 buffer, lenp, ppos, conv, data);
2609 * proc_dointvec - read a vector of integers
2610 * @table: the sysctl table
2611 * @write: %TRUE if this is a write to the sysctl file
2612 * @buffer: the user buffer
2613 * @lenp: the size of the user buffer
2614 * @ppos: file position
2616 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2617 * values from/to the user buffer, treated as an ASCII string.
2619 * Returns 0 on success.
2621 int proc_dointvec(struct ctl_table *table, int write,
2622 void __user *buffer, size_t *lenp, loff_t *ppos)
2624 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2628 * proc_douintvec - read a vector of unsigned integers
2629 * @table: the sysctl table
2630 * @write: %TRUE if this is a write to the sysctl file
2631 * @buffer: the user buffer
2632 * @lenp: the size of the user buffer
2633 * @ppos: file position
2635 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2636 * values from/to the user buffer, treated as an ASCII string.
2638 * Returns 0 on success.
2640 int proc_douintvec(struct ctl_table *table, int write,
2641 void __user *buffer, size_t *lenp, loff_t *ppos)
2643 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2644 do_proc_douintvec_conv, NULL);
2648 * Taint values can only be increased
2649 * This means we can safely use a temporary.
2651 static int proc_taint(struct ctl_table *table, int write,
2652 void __user *buffer, size_t *lenp, loff_t *ppos)
2655 unsigned long tmptaint = get_taint();
2658 if (write && !capable(CAP_SYS_ADMIN))
2663 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2669 * Poor man's atomic or. Not worth adding a primitive
2670 * to everyone's atomic.h for this
2673 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2674 if ((tmptaint >> i) & 1)
2675 add_taint(i, LOCKDEP_STILL_OK);
2682 #ifdef CONFIG_PRINTK
2683 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2684 void __user *buffer, size_t *lenp, loff_t *ppos)
2686 if (write && !capable(CAP_SYS_ADMIN))
2689 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2694 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2695 * @min: pointer to minimum allowable value
2696 * @max: pointer to maximum allowable value
2698 * The do_proc_dointvec_minmax_conv_param structure provides the
2699 * minimum and maximum values for doing range checking for those sysctl
2700 * parameters that use the proc_dointvec_minmax() handler.
2702 struct do_proc_dointvec_minmax_conv_param {
2707 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2709 int write, void *data)
2712 struct do_proc_dointvec_minmax_conv_param *param = data;
2714 * If writing, first do so via a temporary local int so we can
2715 * bounds-check it before touching *valp.
2717 int *ip = write ? &tmp : valp;
2719 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
2724 if ((param->min && *param->min > tmp) ||
2725 (param->max && *param->max < tmp))
2734 * proc_dointvec_minmax - read a vector of integers with min/max values
2735 * @table: the sysctl table
2736 * @write: %TRUE if this is a write to the sysctl file
2737 * @buffer: the user buffer
2738 * @lenp: the size of the user buffer
2739 * @ppos: file position
2741 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2742 * values from/to the user buffer, treated as an ASCII string.
2744 * This routine will ensure the values are within the range specified by
2745 * table->extra1 (min) and table->extra2 (max).
2747 * Returns 0 on success or -EINVAL on write when the range check fails.
2749 int proc_dointvec_minmax(struct ctl_table *table, int write,
2750 void __user *buffer, size_t *lenp, loff_t *ppos)
2752 struct do_proc_dointvec_minmax_conv_param param = {
2753 .min = (int *) table->extra1,
2754 .max = (int *) table->extra2,
2756 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2757 do_proc_dointvec_minmax_conv, ¶m);
2761 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2762 * @min: pointer to minimum allowable value
2763 * @max: pointer to maximum allowable value
2765 * The do_proc_douintvec_minmax_conv_param structure provides the
2766 * minimum and maximum values for doing range checking for those sysctl
2767 * parameters that use the proc_douintvec_minmax() handler.
2769 struct do_proc_douintvec_minmax_conv_param {
2774 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2776 int write, void *data)
2780 struct do_proc_douintvec_minmax_conv_param *param = data;
2781 /* write via temporary local uint for bounds-checking */
2782 unsigned int *up = write ? &tmp : valp;
2784 ret = do_proc_douintvec_conv(lvalp, up, write, data);
2789 if ((param->min && *param->min > tmp) ||
2790 (param->max && *param->max < tmp))
2800 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2801 * @table: the sysctl table
2802 * @write: %TRUE if this is a write to the sysctl file
2803 * @buffer: the user buffer
2804 * @lenp: the size of the user buffer
2805 * @ppos: file position
2807 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2808 * values from/to the user buffer, treated as an ASCII string. Negative
2809 * strings are not allowed.
2811 * This routine will ensure the values are within the range specified by
2812 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2813 * check for UINT_MAX to avoid having to support wrap around uses from
2816 * Returns 0 on success or -ERANGE on write when the range check fails.
2818 int proc_douintvec_minmax(struct ctl_table *table, int write,
2819 void __user *buffer, size_t *lenp, loff_t *ppos)
2821 struct do_proc_douintvec_minmax_conv_param param = {
2822 .min = (unsigned int *) table->extra1,
2823 .max = (unsigned int *) table->extra2,
2825 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2826 do_proc_douintvec_minmax_conv, ¶m);
2829 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2831 int write, void *data)
2836 val = round_pipe_size(*lvalp);
2842 unsigned int val = *valp;
2843 *lvalp = (unsigned long) val;
2849 static int proc_dopipe_max_size(struct ctl_table *table, int write,
2850 void __user *buffer, size_t *lenp, loff_t *ppos)
2852 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2853 do_proc_dopipe_max_size_conv, NULL);
2856 static void validate_coredump_safety(void)
2858 #ifdef CONFIG_COREDUMP
2859 if (suid_dumpable == SUID_DUMP_ROOT &&
2860 core_pattern[0] != '/' && core_pattern[0] != '|') {
2862 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2863 "Pipe handler or fully qualified core dump path required.\n"
2864 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2870 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2871 void __user *buffer, size_t *lenp, loff_t *ppos)
2873 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2875 validate_coredump_safety();
2879 #ifdef CONFIG_COREDUMP
2880 static int proc_dostring_coredump(struct ctl_table *table, int write,
2881 void __user *buffer, size_t *lenp, loff_t *ppos)
2883 int error = proc_dostring(table, write, buffer, lenp, ppos);
2885 validate_coredump_safety();
2890 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2891 void __user *buffer,
2892 size_t *lenp, loff_t *ppos,
2893 unsigned long convmul,
2894 unsigned long convdiv)
2896 unsigned long *i, *min, *max;
2897 int vleft, first = 1, err = 0;
2899 char *kbuf = NULL, *p;
2901 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2906 i = (unsigned long *) data;
2907 min = (unsigned long *) table->extra1;
2908 max = (unsigned long *) table->extra2;
2909 vleft = table->maxlen / sizeof(unsigned long);
2913 if (proc_first_pos_non_zero_ignore(ppos, table))
2916 if (left > PAGE_SIZE - 1)
2917 left = PAGE_SIZE - 1;
2918 p = kbuf = memdup_user_nul(buffer, left);
2920 return PTR_ERR(kbuf);
2923 for (; left && vleft--; i++, first = 0) {
2929 proc_skip_spaces(&p, &left);
2933 err = proc_get_long(&p, &left, &val, &neg,
2935 sizeof(proc_wspace_sep), NULL);
2940 val = convmul * val / convdiv;
2941 if ((min && val < *min) || (max && val > *max)) {
2947 val = convdiv * (*i) / convmul;
2949 err = proc_put_char(&buffer, &left, '\t');
2953 err = proc_put_long(&buffer, &left, val, false);
2959 if (!write && !first && left && !err)
2960 err = proc_put_char(&buffer, &left, '\n');
2962 proc_skip_spaces(&p, &left);
2966 return err ? : -EINVAL;
2974 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2975 void __user *buffer,
2976 size_t *lenp, loff_t *ppos,
2977 unsigned long convmul,
2978 unsigned long convdiv)
2980 return __do_proc_doulongvec_minmax(table->data, table, write,
2981 buffer, lenp, ppos, convmul, convdiv);
2985 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2986 * @table: the sysctl table
2987 * @write: %TRUE if this is a write to the sysctl file
2988 * @buffer: the user buffer
2989 * @lenp: the size of the user buffer
2990 * @ppos: file position
2992 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2993 * values from/to the user buffer, treated as an ASCII string.
2995 * This routine will ensure the values are within the range specified by
2996 * table->extra1 (min) and table->extra2 (max).
2998 * Returns 0 on success.
3000 int proc_doulongvec_minmax(struct ctl_table *table, int write,
3001 void __user *buffer, size_t *lenp, loff_t *ppos)
3003 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
3007 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
3008 * @table: the sysctl table
3009 * @write: %TRUE if this is a write to the sysctl file
3010 * @buffer: the user buffer
3011 * @lenp: the size of the user buffer
3012 * @ppos: file position
3014 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
3015 * values from/to the user buffer, treated as an ASCII string. The values
3016 * are treated as milliseconds, and converted to jiffies when they are stored.
3018 * This routine will ensure the values are within the range specified by
3019 * table->extra1 (min) and table->extra2 (max).
3021 * Returns 0 on success.
3023 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3024 void __user *buffer,
3025 size_t *lenp, loff_t *ppos)
3027 return do_proc_doulongvec_minmax(table, write, buffer,
3028 lenp, ppos, HZ, 1000l);
3032 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
3034 int write, void *data)
3037 if (*lvalp > INT_MAX / HZ)
3039 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
3045 lval = -(unsigned long)val;
3048 lval = (unsigned long)val;
3055 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
3057 int write, void *data)
3060 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
3062 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
3068 lval = -(unsigned long)val;
3071 lval = (unsigned long)val;
3073 *lvalp = jiffies_to_clock_t(lval);
3078 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
3080 int write, void *data)
3083 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3093 lval = -(unsigned long)val;
3096 lval = (unsigned long)val;
3098 *lvalp = jiffies_to_msecs(lval);
3104 * proc_dointvec_jiffies - read a vector of integers as seconds
3105 * @table: the sysctl table
3106 * @write: %TRUE if this is a write to the sysctl file
3107 * @buffer: the user buffer
3108 * @lenp: the size of the user buffer
3109 * @ppos: file position
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 seconds, and are converted into
3116 * Returns 0 on success.
3118 int proc_dointvec_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_jiffies_conv,NULL);
3126 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3127 * @table: the sysctl table
3128 * @write: %TRUE if this is a write to the sysctl file
3129 * @buffer: the user buffer
3130 * @lenp: the size of the user buffer
3131 * @ppos: pointer to the file position
3133 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3134 * values from/to the user buffer, treated as an ASCII string.
3135 * The values read are assumed to be in 1/USER_HZ seconds, and
3136 * are converted into jiffies.
3138 * Returns 0 on success.
3140 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3141 void __user *buffer, size_t *lenp, loff_t *ppos)
3143 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3144 do_proc_dointvec_userhz_jiffies_conv,NULL);
3148 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
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
3154 * @ppos: the current position in the file
3156 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3157 * values from/to the user buffer, treated as an ASCII string.
3158 * The values read are assumed to be in 1/1000 seconds, and
3159 * are converted into jiffies.
3161 * Returns 0 on success.
3163 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3164 void __user *buffer, size_t *lenp, loff_t *ppos)
3166 return do_proc_dointvec(table, write, buffer, lenp, ppos,
3167 do_proc_dointvec_ms_jiffies_conv, NULL);
3170 static int proc_do_cad_pid(struct ctl_table *table, int write,
3171 void __user *buffer, size_t *lenp, loff_t *ppos)
3173 struct pid *new_pid;
3177 tmp = pid_vnr(cad_pid);
3179 r = __do_proc_dointvec(&tmp, table, write, buffer,
3180 lenp, ppos, NULL, NULL);
3184 new_pid = find_get_pid(tmp);
3188 put_pid(xchg(&cad_pid, new_pid));
3193 * proc_do_large_bitmap - read/write from/to a large bitmap
3194 * @table: the sysctl table
3195 * @write: %TRUE if this is a write to the sysctl file
3196 * @buffer: the user buffer
3197 * @lenp: the size of the user buffer
3198 * @ppos: file position
3200 * The bitmap is stored at table->data and the bitmap length (in bits)
3203 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3204 * large bitmaps may be represented in a compact manner. Writing into
3205 * the file will clear the bitmap then update it with the given input.
3207 * Returns 0 on success.
3209 int proc_do_large_bitmap(struct ctl_table *table, int write,
3210 void __user *buffer, size_t *lenp, loff_t *ppos)
3214 size_t left = *lenp;
3215 unsigned long bitmap_len = table->maxlen;
3216 unsigned long *bitmap = *(unsigned long **) table->data;
3217 unsigned long *tmp_bitmap = NULL;
3218 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3220 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
3229 if (left > PAGE_SIZE - 1) {
3230 left = PAGE_SIZE - 1;
3231 /* How much of the buffer we'll skip this pass */
3232 skipped = *lenp - left;
3235 p = kbuf = memdup_user_nul(buffer, left);
3237 return PTR_ERR(kbuf);
3239 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
3244 proc_skip_char(&p, &left, '\n');
3245 while (!err && left) {
3246 unsigned long val_a, val_b;
3250 /* In case we stop parsing mid-number, we can reset */
3252 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
3255 * If we consumed the entirety of a truncated buffer or
3256 * only one char is left (may be a "-"), then stop here,
3257 * reset, & come back for more.
3259 if ((left <= 1) && skipped) {
3266 if (val_a >= bitmap_len || neg) {
3278 err = proc_get_long(&p, &left, &val_b,
3279 &neg, tr_b, sizeof(tr_b),
3282 * If we consumed all of a truncated buffer or
3283 * then stop here, reset, & come back for more.
3285 if (!left && skipped) {
3292 if (val_b >= bitmap_len || neg ||
3303 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
3305 proc_skip_char(&p, &left, '\n');
3310 unsigned long bit_a, bit_b = 0;
3313 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3314 if (bit_a >= bitmap_len)
3316 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3320 err = proc_put_char(&buffer, &left, ',');
3324 err = proc_put_long(&buffer, &left, bit_a, false);
3327 if (bit_a != bit_b) {
3328 err = proc_put_char(&buffer, &left, '-');
3331 err = proc_put_long(&buffer, &left, bit_b, false);
3339 err = proc_put_char(&buffer, &left, '\n');
3345 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3347 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
3353 bitmap_free(tmp_bitmap);
3357 #else /* CONFIG_PROC_SYSCTL */
3359 int proc_dostring(struct ctl_table *table, int write,
3360 void __user *buffer, size_t *lenp, loff_t *ppos)
3365 int proc_dointvec(struct ctl_table *table, int write,
3366 void __user *buffer, size_t *lenp, loff_t *ppos)
3371 int proc_douintvec(struct ctl_table *table, int write,
3372 void __user *buffer, size_t *lenp, loff_t *ppos)
3377 int proc_dointvec_minmax(struct ctl_table *table, int write,
3378 void __user *buffer, size_t *lenp, loff_t *ppos)
3383 int proc_douintvec_minmax(struct ctl_table *table, int write,
3384 void __user *buffer, size_t *lenp, loff_t *ppos)
3389 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3390 void __user *buffer, size_t *lenp, loff_t *ppos)
3395 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3396 void __user *buffer, size_t *lenp, loff_t *ppos)
3401 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3402 void __user *buffer, size_t *lenp, loff_t *ppos)
3407 int proc_doulongvec_minmax(struct ctl_table *table, int write,
3408 void __user *buffer, size_t *lenp, loff_t *ppos)
3413 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3414 void __user *buffer,
3415 size_t *lenp, loff_t *ppos)
3420 int proc_do_large_bitmap(struct ctl_table *table, int write,
3421 void __user *buffer, size_t *lenp, loff_t *ppos)
3426 #endif /* CONFIG_PROC_SYSCTL */
3428 #if defined(CONFIG_SYSCTL)
3429 int proc_do_static_key(struct ctl_table *table, int write,
3430 void __user *buffer, size_t *lenp,
3433 struct static_key *key = (struct static_key *)table->data;
3434 static DEFINE_MUTEX(static_key_mutex);
3436 struct ctl_table tmp = {
3438 .maxlen = sizeof(val),
3439 .mode = table->mode,
3440 .extra1 = SYSCTL_ZERO,
3441 .extra2 = SYSCTL_ONE,
3444 if (write && !capable(CAP_SYS_ADMIN))
3447 mutex_lock(&static_key_mutex);
3448 val = static_key_enabled(key);
3449 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3450 if (write && !ret) {
3452 static_key_enable(key);
3454 static_key_disable(key);
3456 mutex_unlock(&static_key_mutex);
3461 * No sense putting this after each symbol definition, twice,
3462 * exception granted :-)
3464 EXPORT_SYMBOL(proc_dointvec);
3465 EXPORT_SYMBOL(proc_douintvec);
3466 EXPORT_SYMBOL(proc_dointvec_jiffies);
3467 EXPORT_SYMBOL(proc_dointvec_minmax);
3468 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3469 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3470 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3471 EXPORT_SYMBOL(proc_dostring);
3472 EXPORT_SYMBOL(proc_doulongvec_minmax);
3473 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3474 EXPORT_SYMBOL(proc_do_large_bitmap);