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,
470 .procname = "sched_rt_runtime_us",
471 .data = &sysctl_sched_rt_runtime,
472 .maxlen = sizeof(int),
474 .proc_handler = sched_rt_handler,
477 .procname = "sched_rr_timeslice_ms",
478 .data = &sysctl_sched_rr_timeslice,
479 .maxlen = sizeof(int),
481 .proc_handler = sched_rr_handler,
483 #ifdef CONFIG_UCLAMP_TASK
485 .procname = "sched_util_clamp_min",
486 .data = &sysctl_sched_uclamp_util_min,
487 .maxlen = sizeof(unsigned int),
489 .proc_handler = sysctl_sched_uclamp_handler,
492 .procname = "sched_util_clamp_max",
493 .data = &sysctl_sched_uclamp_util_max,
494 .maxlen = sizeof(unsigned int),
496 .proc_handler = sysctl_sched_uclamp_handler,
499 #ifdef CONFIG_SCHED_AUTOGROUP
501 .procname = "sched_autogroup_enabled",
502 .data = &sysctl_sched_autogroup_enabled,
503 .maxlen = sizeof(unsigned int),
505 .proc_handler = proc_dointvec_minmax,
506 .extra1 = SYSCTL_ZERO,
507 .extra2 = SYSCTL_ONE,
510 #ifdef CONFIG_CFS_BANDWIDTH
512 .procname = "sched_cfs_bandwidth_slice_us",
513 .data = &sysctl_sched_cfs_bandwidth_slice,
514 .maxlen = sizeof(unsigned int),
516 .proc_handler = proc_dointvec_minmax,
517 .extra1 = SYSCTL_ONE,
520 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
522 .procname = "sched_energy_aware",
523 .data = &sysctl_sched_energy_aware,
524 .maxlen = sizeof(unsigned int),
526 .proc_handler = sched_energy_aware_handler,
527 .extra1 = SYSCTL_ZERO,
528 .extra2 = SYSCTL_ONE,
531 #ifdef CONFIG_PROVE_LOCKING
533 .procname = "prove_locking",
534 .data = &prove_locking,
535 .maxlen = sizeof(int),
537 .proc_handler = proc_dointvec,
540 #ifdef CONFIG_LOCK_STAT
542 .procname = "lock_stat",
544 .maxlen = sizeof(int),
546 .proc_handler = proc_dointvec,
551 .data = &panic_timeout,
552 .maxlen = sizeof(int),
554 .proc_handler = proc_dointvec,
556 #ifdef CONFIG_COREDUMP
558 .procname = "core_uses_pid",
559 .data = &core_uses_pid,
560 .maxlen = sizeof(int),
562 .proc_handler = proc_dointvec,
565 .procname = "core_pattern",
566 .data = core_pattern,
567 .maxlen = CORENAME_MAX_SIZE,
569 .proc_handler = proc_dostring_coredump,
572 .procname = "core_pipe_limit",
573 .data = &core_pipe_limit,
574 .maxlen = sizeof(unsigned int),
576 .proc_handler = proc_dointvec,
579 #ifdef CONFIG_PROC_SYSCTL
581 .procname = "tainted",
582 .maxlen = sizeof(long),
584 .proc_handler = proc_taint,
587 .procname = "sysctl_writes_strict",
588 .data = &sysctl_writes_strict,
589 .maxlen = sizeof(int),
591 .proc_handler = proc_dointvec_minmax,
593 .extra2 = SYSCTL_ONE,
596 #ifdef CONFIG_LATENCYTOP
598 .procname = "latencytop",
599 .data = &latencytop_enabled,
600 .maxlen = sizeof(int),
602 .proc_handler = sysctl_latencytop,
605 #ifdef CONFIG_BLK_DEV_INITRD
607 .procname = "real-root-dev",
608 .data = &real_root_dev,
609 .maxlen = sizeof(int),
611 .proc_handler = proc_dointvec,
615 .procname = "print-fatal-signals",
616 .data = &print_fatal_signals,
617 .maxlen = sizeof(int),
619 .proc_handler = proc_dointvec,
623 .procname = "reboot-cmd",
624 .data = reboot_command,
627 .proc_handler = proc_dostring,
630 .procname = "stop-a",
631 .data = &stop_a_enabled,
632 .maxlen = sizeof (int),
634 .proc_handler = proc_dointvec,
637 .procname = "scons-poweroff",
638 .data = &scons_pwroff,
639 .maxlen = sizeof (int),
641 .proc_handler = proc_dointvec,
644 #ifdef CONFIG_SPARC64
646 .procname = "tsb-ratio",
647 .data = &sysctl_tsb_ratio,
648 .maxlen = sizeof (int),
650 .proc_handler = proc_dointvec,
655 .procname = "soft-power",
656 .data = &pwrsw_enabled,
657 .maxlen = sizeof (int),
659 .proc_handler = proc_dointvec,
662 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
664 .procname = "unaligned-trap",
665 .data = &unaligned_enabled,
666 .maxlen = sizeof (int),
668 .proc_handler = proc_dointvec,
672 .procname = "ctrl-alt-del",
674 .maxlen = sizeof(int),
676 .proc_handler = proc_dointvec,
678 #ifdef CONFIG_FUNCTION_TRACER
680 .procname = "ftrace_enabled",
681 .data = &ftrace_enabled,
682 .maxlen = sizeof(int),
684 .proc_handler = ftrace_enable_sysctl,
687 #ifdef CONFIG_STACK_TRACER
689 .procname = "stack_tracer_enabled",
690 .data = &stack_tracer_enabled,
691 .maxlen = sizeof(int),
693 .proc_handler = stack_trace_sysctl,
696 #ifdef CONFIG_TRACING
698 .procname = "ftrace_dump_on_oops",
699 .data = &ftrace_dump_on_oops,
700 .maxlen = sizeof(int),
702 .proc_handler = proc_dointvec,
705 .procname = "traceoff_on_warning",
706 .data = &__disable_trace_on_warning,
707 .maxlen = sizeof(__disable_trace_on_warning),
709 .proc_handler = proc_dointvec,
712 .procname = "tracepoint_printk",
713 .data = &tracepoint_printk,
714 .maxlen = sizeof(tracepoint_printk),
716 .proc_handler = tracepoint_printk_sysctl,
719 #ifdef CONFIG_KEXEC_CORE
721 .procname = "kexec_load_disabled",
722 .data = &kexec_load_disabled,
723 .maxlen = sizeof(int),
725 /* only handle a transition from default "0" to "1" */
726 .proc_handler = proc_dointvec_minmax,
727 .extra1 = SYSCTL_ONE,
728 .extra2 = SYSCTL_ONE,
731 #ifdef CONFIG_MODULES
733 .procname = "modprobe",
734 .data = &modprobe_path,
735 .maxlen = KMOD_PATH_LEN,
737 .proc_handler = proc_dostring,
740 .procname = "modules_disabled",
741 .data = &modules_disabled,
742 .maxlen = sizeof(int),
744 /* only handle a transition from default "0" to "1" */
745 .proc_handler = proc_dointvec_minmax,
746 .extra1 = SYSCTL_ONE,
747 .extra2 = SYSCTL_ONE,
750 #ifdef CONFIG_UEVENT_HELPER
752 .procname = "hotplug",
753 .data = &uevent_helper,
754 .maxlen = UEVENT_HELPER_PATH_LEN,
756 .proc_handler = proc_dostring,
759 #ifdef CONFIG_CHR_DEV_SG
761 .procname = "sg-big-buff",
762 .data = &sg_big_buff,
763 .maxlen = sizeof (int),
765 .proc_handler = proc_dointvec,
768 #ifdef CONFIG_BSD_PROCESS_ACCT
772 .maxlen = 3*sizeof(int),
774 .proc_handler = proc_dointvec,
777 #ifdef CONFIG_MAGIC_SYSRQ
780 .data = &__sysrq_enabled,
781 .maxlen = sizeof (int),
783 .proc_handler = sysrq_sysctl_handler,
786 #ifdef CONFIG_PROC_SYSCTL
788 .procname = "cad_pid",
790 .maxlen = sizeof (int),
792 .proc_handler = proc_do_cad_pid,
796 .procname = "threads-max",
798 .maxlen = sizeof(int),
800 .proc_handler = sysctl_max_threads,
803 .procname = "random",
805 .child = random_table,
808 .procname = "usermodehelper",
810 .child = usermodehelper_table,
812 #ifdef CONFIG_FW_LOADER_USER_HELPER
814 .procname = "firmware_config",
816 .child = firmware_config_table,
820 .procname = "overflowuid",
821 .data = &overflowuid,
822 .maxlen = sizeof(int),
824 .proc_handler = proc_dointvec_minmax,
825 .extra1 = &minolduid,
826 .extra2 = &maxolduid,
829 .procname = "overflowgid",
830 .data = &overflowgid,
831 .maxlen = sizeof(int),
833 .proc_handler = proc_dointvec_minmax,
834 .extra1 = &minolduid,
835 .extra2 = &maxolduid,
838 #ifdef CONFIG_MATHEMU
840 .procname = "ieee_emulation_warnings",
841 .data = &sysctl_ieee_emulation_warnings,
842 .maxlen = sizeof(int),
844 .proc_handler = proc_dointvec,
848 .procname = "userprocess_debug",
849 .data = &show_unhandled_signals,
850 .maxlen = sizeof(int),
852 .proc_handler = proc_dointvec,
856 .procname = "pid_max",
858 .maxlen = sizeof (int),
860 .proc_handler = proc_dointvec_minmax,
861 .extra1 = &pid_max_min,
862 .extra2 = &pid_max_max,
865 .procname = "panic_on_oops",
866 .data = &panic_on_oops,
867 .maxlen = sizeof(int),
869 .proc_handler = proc_dointvec,
872 .procname = "panic_print",
873 .data = &panic_print,
874 .maxlen = sizeof(unsigned long),
876 .proc_handler = proc_doulongvec_minmax,
878 #if defined CONFIG_PRINTK
880 .procname = "printk",
881 .data = &console_loglevel,
882 .maxlen = 4*sizeof(int),
884 .proc_handler = proc_dointvec,
887 .procname = "printk_ratelimit",
888 .data = &printk_ratelimit_state.interval,
889 .maxlen = sizeof(int),
891 .proc_handler = proc_dointvec_jiffies,
894 .procname = "printk_ratelimit_burst",
895 .data = &printk_ratelimit_state.burst,
896 .maxlen = sizeof(int),
898 .proc_handler = proc_dointvec,
901 .procname = "printk_delay",
902 .data = &printk_delay_msec,
903 .maxlen = sizeof(int),
905 .proc_handler = proc_dointvec_minmax,
906 .extra1 = SYSCTL_ZERO,
907 .extra2 = &ten_thousand,
910 .procname = "printk_devkmsg",
911 .data = devkmsg_log_str,
912 .maxlen = DEVKMSG_STR_MAX_SIZE,
914 .proc_handler = devkmsg_sysctl_set_loglvl,
917 .procname = "dmesg_restrict",
918 .data = &dmesg_restrict,
919 .maxlen = sizeof(int),
921 .proc_handler = proc_dointvec_minmax_sysadmin,
922 .extra1 = SYSCTL_ZERO,
923 .extra2 = SYSCTL_ONE,
926 .procname = "kptr_restrict",
927 .data = &kptr_restrict,
928 .maxlen = sizeof(int),
930 .proc_handler = proc_dointvec_minmax_sysadmin,
931 .extra1 = SYSCTL_ZERO,
936 .procname = "ngroups_max",
937 .data = &ngroups_max,
938 .maxlen = sizeof (int),
940 .proc_handler = proc_dointvec,
943 .procname = "cap_last_cap",
944 .data = (void *)&cap_last_cap,
945 .maxlen = sizeof(int),
947 .proc_handler = proc_dointvec,
949 #if defined(CONFIG_LOCKUP_DETECTOR)
951 .procname = "watchdog",
952 .data = &watchdog_user_enabled,
953 .maxlen = sizeof(int),
955 .proc_handler = proc_watchdog,
956 .extra1 = SYSCTL_ZERO,
957 .extra2 = SYSCTL_ONE,
960 .procname = "watchdog_thresh",
961 .data = &watchdog_thresh,
962 .maxlen = sizeof(int),
964 .proc_handler = proc_watchdog_thresh,
965 .extra1 = SYSCTL_ZERO,
969 .procname = "nmi_watchdog",
970 .data = &nmi_watchdog_user_enabled,
971 .maxlen = sizeof(int),
972 .mode = NMI_WATCHDOG_SYSCTL_PERM,
973 .proc_handler = proc_nmi_watchdog,
974 .extra1 = SYSCTL_ZERO,
975 .extra2 = SYSCTL_ONE,
978 .procname = "watchdog_cpumask",
979 .data = &watchdog_cpumask_bits,
982 .proc_handler = proc_watchdog_cpumask,
984 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
986 .procname = "soft_watchdog",
987 .data = &soft_watchdog_user_enabled,
988 .maxlen = sizeof(int),
990 .proc_handler = proc_soft_watchdog,
991 .extra1 = SYSCTL_ZERO,
992 .extra2 = SYSCTL_ONE,
995 .procname = "softlockup_panic",
996 .data = &softlockup_panic,
997 .maxlen = sizeof(int),
999 .proc_handler = proc_dointvec_minmax,
1000 .extra1 = SYSCTL_ZERO,
1001 .extra2 = SYSCTL_ONE,
1005 .procname = "softlockup_all_cpu_backtrace",
1006 .data = &sysctl_softlockup_all_cpu_backtrace,
1007 .maxlen = sizeof(int),
1009 .proc_handler = proc_dointvec_minmax,
1010 .extra1 = SYSCTL_ZERO,
1011 .extra2 = SYSCTL_ONE,
1013 #endif /* CONFIG_SMP */
1015 #ifdef CONFIG_HARDLOCKUP_DETECTOR
1017 .procname = "hardlockup_panic",
1018 .data = &hardlockup_panic,
1019 .maxlen = sizeof(int),
1021 .proc_handler = proc_dointvec_minmax,
1022 .extra1 = SYSCTL_ZERO,
1023 .extra2 = SYSCTL_ONE,
1027 .procname = "hardlockup_all_cpu_backtrace",
1028 .data = &sysctl_hardlockup_all_cpu_backtrace,
1029 .maxlen = sizeof(int),
1031 .proc_handler = proc_dointvec_minmax,
1032 .extra1 = SYSCTL_ZERO,
1033 .extra2 = SYSCTL_ONE,
1035 #endif /* CONFIG_SMP */
1039 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1041 .procname = "unknown_nmi_panic",
1042 .data = &unknown_nmi_panic,
1043 .maxlen = sizeof (int),
1045 .proc_handler = proc_dointvec,
1048 #if defined(CONFIG_X86)
1050 .procname = "panic_on_unrecovered_nmi",
1051 .data = &panic_on_unrecovered_nmi,
1052 .maxlen = sizeof(int),
1054 .proc_handler = proc_dointvec,
1057 .procname = "panic_on_io_nmi",
1058 .data = &panic_on_io_nmi,
1059 .maxlen = sizeof(int),
1061 .proc_handler = proc_dointvec,
1063 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1065 .procname = "panic_on_stackoverflow",
1066 .data = &sysctl_panic_on_stackoverflow,
1067 .maxlen = sizeof(int),
1069 .proc_handler = proc_dointvec,
1073 .procname = "bootloader_type",
1074 .data = &bootloader_type,
1075 .maxlen = sizeof (int),
1077 .proc_handler = proc_dointvec,
1080 .procname = "bootloader_version",
1081 .data = &bootloader_version,
1082 .maxlen = sizeof (int),
1084 .proc_handler = proc_dointvec,
1087 .procname = "io_delay_type",
1088 .data = &io_delay_type,
1089 .maxlen = sizeof(int),
1091 .proc_handler = proc_dointvec,
1094 #if defined(CONFIG_MMU)
1096 .procname = "randomize_va_space",
1097 .data = &randomize_va_space,
1098 .maxlen = sizeof(int),
1100 .proc_handler = proc_dointvec,
1103 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1105 .procname = "spin_retry",
1106 .data = &spin_retry,
1107 .maxlen = sizeof (int),
1109 .proc_handler = proc_dointvec,
1112 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1114 .procname = "acpi_video_flags",
1115 .data = &acpi_realmode_flags,
1116 .maxlen = sizeof (unsigned long),
1118 .proc_handler = proc_doulongvec_minmax,
1121 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1123 .procname = "ignore-unaligned-usertrap",
1124 .data = &no_unaligned_warning,
1125 .maxlen = sizeof (int),
1127 .proc_handler = proc_dointvec,
1132 .procname = "unaligned-dump-stack",
1133 .data = &unaligned_dump_stack,
1134 .maxlen = sizeof (int),
1136 .proc_handler = proc_dointvec,
1139 #ifdef CONFIG_DETECT_HUNG_TASK
1141 .procname = "hung_task_panic",
1142 .data = &sysctl_hung_task_panic,
1143 .maxlen = sizeof(int),
1145 .proc_handler = proc_dointvec_minmax,
1146 .extra1 = SYSCTL_ZERO,
1147 .extra2 = SYSCTL_ONE,
1150 .procname = "hung_task_check_count",
1151 .data = &sysctl_hung_task_check_count,
1152 .maxlen = sizeof(int),
1154 .proc_handler = proc_dointvec_minmax,
1155 .extra1 = SYSCTL_ZERO,
1158 .procname = "hung_task_timeout_secs",
1159 .data = &sysctl_hung_task_timeout_secs,
1160 .maxlen = sizeof(unsigned long),
1162 .proc_handler = proc_dohung_task_timeout_secs,
1163 .extra2 = &hung_task_timeout_max,
1166 .procname = "hung_task_check_interval_secs",
1167 .data = &sysctl_hung_task_check_interval_secs,
1168 .maxlen = sizeof(unsigned long),
1170 .proc_handler = proc_dohung_task_timeout_secs,
1171 .extra2 = &hung_task_timeout_max,
1174 .procname = "hung_task_warnings",
1175 .data = &sysctl_hung_task_warnings,
1176 .maxlen = sizeof(int),
1178 .proc_handler = proc_dointvec_minmax,
1182 #ifdef CONFIG_RT_MUTEXES
1184 .procname = "max_lock_depth",
1185 .data = &max_lock_depth,
1186 .maxlen = sizeof(int),
1188 .proc_handler = proc_dointvec,
1192 .procname = "poweroff_cmd",
1193 .data = &poweroff_cmd,
1194 .maxlen = POWEROFF_CMD_PATH_LEN,
1196 .proc_handler = proc_dostring,
1202 .child = key_sysctls,
1205 #ifdef CONFIG_PERF_EVENTS
1207 * User-space scripts rely on the existence of this file
1208 * as a feature check for perf_events being enabled.
1210 * So it's an ABI, do not remove!
1213 .procname = "perf_event_paranoid",
1214 .data = &sysctl_perf_event_paranoid,
1215 .maxlen = sizeof(sysctl_perf_event_paranoid),
1217 .proc_handler = proc_dointvec,
1220 .procname = "perf_event_mlock_kb",
1221 .data = &sysctl_perf_event_mlock,
1222 .maxlen = sizeof(sysctl_perf_event_mlock),
1224 .proc_handler = proc_dointvec,
1227 .procname = "perf_event_max_sample_rate",
1228 .data = &sysctl_perf_event_sample_rate,
1229 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1231 .proc_handler = perf_proc_update_handler,
1232 .extra1 = SYSCTL_ONE,
1235 .procname = "perf_cpu_time_max_percent",
1236 .data = &sysctl_perf_cpu_time_max_percent,
1237 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1239 .proc_handler = perf_cpu_time_max_percent_handler,
1240 .extra1 = SYSCTL_ZERO,
1241 .extra2 = &one_hundred,
1244 .procname = "perf_event_max_stack",
1245 .data = &sysctl_perf_event_max_stack,
1246 .maxlen = sizeof(sysctl_perf_event_max_stack),
1248 .proc_handler = perf_event_max_stack_handler,
1249 .extra1 = SYSCTL_ZERO,
1250 .extra2 = &six_hundred_forty_kb,
1253 .procname = "perf_event_max_contexts_per_stack",
1254 .data = &sysctl_perf_event_max_contexts_per_stack,
1255 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1257 .proc_handler = perf_event_max_stack_handler,
1258 .extra1 = SYSCTL_ZERO,
1259 .extra2 = &one_thousand,
1263 .procname = "panic_on_warn",
1264 .data = &panic_on_warn,
1265 .maxlen = sizeof(int),
1267 .proc_handler = proc_dointvec_minmax,
1268 .extra1 = SYSCTL_ZERO,
1269 .extra2 = SYSCTL_ONE,
1271 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1273 .procname = "timer_migration",
1274 .data = &sysctl_timer_migration,
1275 .maxlen = sizeof(unsigned int),
1277 .proc_handler = timer_migration_handler,
1278 .extra1 = SYSCTL_ZERO,
1279 .extra2 = SYSCTL_ONE,
1282 #ifdef CONFIG_BPF_SYSCALL
1284 .procname = "unprivileged_bpf_disabled",
1285 .data = &sysctl_unprivileged_bpf_disabled,
1286 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1288 .proc_handler = bpf_unpriv_handler,
1289 .extra1 = SYSCTL_ZERO,
1293 .procname = "bpf_stats_enabled",
1294 .data = &bpf_stats_enabled_key.key,
1295 .maxlen = sizeof(bpf_stats_enabled_key),
1297 .proc_handler = proc_do_static_key,
1300 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1302 .procname = "panic_on_rcu_stall",
1303 .data = &sysctl_panic_on_rcu_stall,
1304 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1306 .proc_handler = proc_dointvec_minmax,
1307 .extra1 = SYSCTL_ZERO,
1308 .extra2 = SYSCTL_ONE,
1311 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1313 .procname = "stack_erasing",
1315 .maxlen = sizeof(int),
1317 .proc_handler = stack_erasing_sysctl,
1318 .extra1 = SYSCTL_ZERO,
1319 .extra2 = SYSCTL_ONE,
1325 static struct ctl_table vm_table[] = {
1327 .procname = "overcommit_memory",
1328 .data = &sysctl_overcommit_memory,
1329 .maxlen = sizeof(sysctl_overcommit_memory),
1331 .proc_handler = proc_dointvec_minmax,
1332 .extra1 = SYSCTL_ZERO,
1336 .procname = "panic_on_oom",
1337 .data = &sysctl_panic_on_oom,
1338 .maxlen = sizeof(sysctl_panic_on_oom),
1340 .proc_handler = proc_dointvec_minmax,
1341 .extra1 = SYSCTL_ZERO,
1345 .procname = "oom_kill_allocating_task",
1346 .data = &sysctl_oom_kill_allocating_task,
1347 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1349 .proc_handler = proc_dointvec,
1352 .procname = "oom_dump_tasks",
1353 .data = &sysctl_oom_dump_tasks,
1354 .maxlen = sizeof(sysctl_oom_dump_tasks),
1356 .proc_handler = proc_dointvec,
1359 .procname = "overcommit_ratio",
1360 .data = &sysctl_overcommit_ratio,
1361 .maxlen = sizeof(sysctl_overcommit_ratio),
1363 .proc_handler = overcommit_ratio_handler,
1366 .procname = "overcommit_kbytes",
1367 .data = &sysctl_overcommit_kbytes,
1368 .maxlen = sizeof(sysctl_overcommit_kbytes),
1370 .proc_handler = overcommit_kbytes_handler,
1373 .procname = "page-cluster",
1374 .data = &page_cluster,
1375 .maxlen = sizeof(int),
1377 .proc_handler = proc_dointvec_minmax,
1378 .extra1 = SYSCTL_ZERO,
1381 .procname = "dirty_background_ratio",
1382 .data = &dirty_background_ratio,
1383 .maxlen = sizeof(dirty_background_ratio),
1385 .proc_handler = dirty_background_ratio_handler,
1386 .extra1 = SYSCTL_ZERO,
1387 .extra2 = &one_hundred,
1390 .procname = "dirty_background_bytes",
1391 .data = &dirty_background_bytes,
1392 .maxlen = sizeof(dirty_background_bytes),
1394 .proc_handler = dirty_background_bytes_handler,
1398 .procname = "dirty_ratio",
1399 .data = &vm_dirty_ratio,
1400 .maxlen = sizeof(vm_dirty_ratio),
1402 .proc_handler = dirty_ratio_handler,
1403 .extra1 = SYSCTL_ZERO,
1404 .extra2 = &one_hundred,
1407 .procname = "dirty_bytes",
1408 .data = &vm_dirty_bytes,
1409 .maxlen = sizeof(vm_dirty_bytes),
1411 .proc_handler = dirty_bytes_handler,
1412 .extra1 = &dirty_bytes_min,
1415 .procname = "dirty_writeback_centisecs",
1416 .data = &dirty_writeback_interval,
1417 .maxlen = sizeof(dirty_writeback_interval),
1419 .proc_handler = dirty_writeback_centisecs_handler,
1422 .procname = "dirty_expire_centisecs",
1423 .data = &dirty_expire_interval,
1424 .maxlen = sizeof(dirty_expire_interval),
1426 .proc_handler = proc_dointvec_minmax,
1427 .extra1 = SYSCTL_ZERO,
1430 .procname = "dirtytime_expire_seconds",
1431 .data = &dirtytime_expire_interval,
1432 .maxlen = sizeof(dirtytime_expire_interval),
1434 .proc_handler = dirtytime_interval_handler,
1435 .extra1 = SYSCTL_ZERO,
1438 .procname = "swappiness",
1439 .data = &vm_swappiness,
1440 .maxlen = sizeof(vm_swappiness),
1442 .proc_handler = proc_dointvec_minmax,
1443 .extra1 = SYSCTL_ZERO,
1444 .extra2 = &one_hundred,
1448 .procname = "numa_stat",
1449 .data = &sysctl_vm_numa_stat,
1450 .maxlen = sizeof(int),
1452 .proc_handler = sysctl_vm_numa_stat_handler,
1453 .extra1 = SYSCTL_ZERO,
1454 .extra2 = SYSCTL_ONE,
1457 #ifdef CONFIG_HUGETLB_PAGE
1459 .procname = "nr_hugepages",
1461 .maxlen = sizeof(unsigned long),
1463 .proc_handler = hugetlb_sysctl_handler,
1467 .procname = "nr_hugepages_mempolicy",
1469 .maxlen = sizeof(unsigned long),
1471 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1475 .procname = "hugetlb_shm_group",
1476 .data = &sysctl_hugetlb_shm_group,
1477 .maxlen = sizeof(gid_t),
1479 .proc_handler = proc_dointvec,
1482 .procname = "nr_overcommit_hugepages",
1484 .maxlen = sizeof(unsigned long),
1486 .proc_handler = hugetlb_overcommit_handler,
1490 .procname = "lowmem_reserve_ratio",
1491 .data = &sysctl_lowmem_reserve_ratio,
1492 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1494 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1497 .procname = "drop_caches",
1498 .data = &sysctl_drop_caches,
1499 .maxlen = sizeof(int),
1501 .proc_handler = drop_caches_sysctl_handler,
1502 .extra1 = SYSCTL_ONE,
1505 #ifdef CONFIG_COMPACTION
1507 .procname = "compact_memory",
1508 .data = &sysctl_compact_memory,
1509 .maxlen = sizeof(int),
1511 .proc_handler = sysctl_compaction_handler,
1514 .procname = "extfrag_threshold",
1515 .data = &sysctl_extfrag_threshold,
1516 .maxlen = sizeof(int),
1518 .proc_handler = proc_dointvec_minmax,
1519 .extra1 = &min_extfrag_threshold,
1520 .extra2 = &max_extfrag_threshold,
1523 .procname = "compact_unevictable_allowed",
1524 .data = &sysctl_compact_unevictable_allowed,
1525 .maxlen = sizeof(int),
1527 .proc_handler = proc_dointvec,
1528 .extra1 = SYSCTL_ZERO,
1529 .extra2 = SYSCTL_ONE,
1532 #endif /* CONFIG_COMPACTION */
1534 .procname = "min_free_kbytes",
1535 .data = &min_free_kbytes,
1536 .maxlen = sizeof(min_free_kbytes),
1538 .proc_handler = min_free_kbytes_sysctl_handler,
1539 .extra1 = SYSCTL_ZERO,
1542 .procname = "watermark_boost_factor",
1543 .data = &watermark_boost_factor,
1544 .maxlen = sizeof(watermark_boost_factor),
1546 .proc_handler = watermark_boost_factor_sysctl_handler,
1547 .extra1 = SYSCTL_ZERO,
1550 .procname = "watermark_scale_factor",
1551 .data = &watermark_scale_factor,
1552 .maxlen = sizeof(watermark_scale_factor),
1554 .proc_handler = watermark_scale_factor_sysctl_handler,
1555 .extra1 = SYSCTL_ONE,
1556 .extra2 = &one_thousand,
1559 .procname = "percpu_pagelist_fraction",
1560 .data = &percpu_pagelist_fraction,
1561 .maxlen = sizeof(percpu_pagelist_fraction),
1563 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1564 .extra1 = SYSCTL_ZERO,
1567 .procname = "page_lock_unfairness",
1568 .data = &sysctl_page_lock_unfairness,
1569 .maxlen = sizeof(sysctl_page_lock_unfairness),
1571 .proc_handler = proc_dointvec_minmax,
1572 .extra1 = SYSCTL_ZERO,
1576 .procname = "max_map_count",
1577 .data = &sysctl_max_map_count,
1578 .maxlen = sizeof(sysctl_max_map_count),
1580 .proc_handler = proc_dointvec_minmax,
1581 .extra1 = SYSCTL_ZERO,
1585 .procname = "nr_trim_pages",
1586 .data = &sysctl_nr_trim_pages,
1587 .maxlen = sizeof(sysctl_nr_trim_pages),
1589 .proc_handler = proc_dointvec_minmax,
1590 .extra1 = SYSCTL_ZERO,
1594 .procname = "laptop_mode",
1595 .data = &laptop_mode,
1596 .maxlen = sizeof(laptop_mode),
1598 .proc_handler = proc_dointvec_jiffies,
1601 .procname = "block_dump",
1602 .data = &block_dump,
1603 .maxlen = sizeof(block_dump),
1605 .proc_handler = proc_dointvec_minmax,
1606 .extra1 = SYSCTL_ZERO,
1609 .procname = "vfs_cache_pressure",
1610 .data = &sysctl_vfs_cache_pressure,
1611 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1613 .proc_handler = proc_dointvec_minmax,
1614 .extra1 = SYSCTL_ZERO,
1616 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
1617 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
1619 .procname = "legacy_va_layout",
1620 .data = &sysctl_legacy_va_layout,
1621 .maxlen = sizeof(sysctl_legacy_va_layout),
1623 .proc_handler = proc_dointvec_minmax,
1624 .extra1 = SYSCTL_ZERO,
1629 .procname = "zone_reclaim_mode",
1630 .data = &node_reclaim_mode,
1631 .maxlen = sizeof(node_reclaim_mode),
1633 .proc_handler = proc_dointvec_minmax,
1634 .extra1 = SYSCTL_ZERO,
1637 .procname = "min_unmapped_ratio",
1638 .data = &sysctl_min_unmapped_ratio,
1639 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1641 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1642 .extra1 = SYSCTL_ZERO,
1643 .extra2 = &one_hundred,
1646 .procname = "min_slab_ratio",
1647 .data = &sysctl_min_slab_ratio,
1648 .maxlen = sizeof(sysctl_min_slab_ratio),
1650 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1651 .extra1 = SYSCTL_ZERO,
1652 .extra2 = &one_hundred,
1657 .procname = "stat_interval",
1658 .data = &sysctl_stat_interval,
1659 .maxlen = sizeof(sysctl_stat_interval),
1661 .proc_handler = proc_dointvec_jiffies,
1664 .procname = "stat_refresh",
1668 .proc_handler = vmstat_refresh,
1673 .procname = "mmap_min_addr",
1674 .data = &dac_mmap_min_addr,
1675 .maxlen = sizeof(unsigned long),
1677 .proc_handler = mmap_min_addr_handler,
1682 .procname = "numa_zonelist_order",
1683 .data = &numa_zonelist_order,
1684 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1686 .proc_handler = numa_zonelist_order_handler,
1689 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1690 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1692 .procname = "vdso_enabled",
1693 #ifdef CONFIG_X86_32
1694 .data = &vdso32_enabled,
1695 .maxlen = sizeof(vdso32_enabled),
1697 .data = &vdso_enabled,
1698 .maxlen = sizeof(vdso_enabled),
1701 .proc_handler = proc_dointvec,
1702 .extra1 = SYSCTL_ZERO,
1705 #ifdef CONFIG_HIGHMEM
1707 .procname = "highmem_is_dirtyable",
1708 .data = &vm_highmem_is_dirtyable,
1709 .maxlen = sizeof(vm_highmem_is_dirtyable),
1711 .proc_handler = proc_dointvec_minmax,
1712 .extra1 = SYSCTL_ZERO,
1713 .extra2 = SYSCTL_ONE,
1716 #ifdef CONFIG_MEMORY_FAILURE
1718 .procname = "memory_failure_early_kill",
1719 .data = &sysctl_memory_failure_early_kill,
1720 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1722 .proc_handler = proc_dointvec_minmax,
1723 .extra1 = SYSCTL_ZERO,
1724 .extra2 = SYSCTL_ONE,
1727 .procname = "memory_failure_recovery",
1728 .data = &sysctl_memory_failure_recovery,
1729 .maxlen = sizeof(sysctl_memory_failure_recovery),
1731 .proc_handler = proc_dointvec_minmax,
1732 .extra1 = SYSCTL_ZERO,
1733 .extra2 = SYSCTL_ONE,
1737 .procname = "user_reserve_kbytes",
1738 .data = &sysctl_user_reserve_kbytes,
1739 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1741 .proc_handler = proc_doulongvec_minmax,
1744 .procname = "admin_reserve_kbytes",
1745 .data = &sysctl_admin_reserve_kbytes,
1746 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1748 .proc_handler = proc_doulongvec_minmax,
1750 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1752 .procname = "mmap_rnd_bits",
1753 .data = &mmap_rnd_bits,
1754 .maxlen = sizeof(mmap_rnd_bits),
1756 .proc_handler = proc_dointvec_minmax,
1757 .extra1 = (void *)&mmap_rnd_bits_min,
1758 .extra2 = (void *)&mmap_rnd_bits_max,
1761 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1763 .procname = "mmap_rnd_compat_bits",
1764 .data = &mmap_rnd_compat_bits,
1765 .maxlen = sizeof(mmap_rnd_compat_bits),
1767 .proc_handler = proc_dointvec_minmax,
1768 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1769 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1772 #ifdef CONFIG_USERFAULTFD
1774 .procname = "unprivileged_userfaultfd",
1775 .data = &sysctl_unprivileged_userfaultfd,
1776 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
1778 .proc_handler = proc_dointvec_minmax,
1779 .extra1 = SYSCTL_ZERO,
1780 .extra2 = SYSCTL_ONE,
1786 static struct ctl_table fs_table[] = {
1788 .procname = "inode-nr",
1789 .data = &inodes_stat,
1790 .maxlen = 2*sizeof(long),
1792 .proc_handler = proc_nr_inodes,
1795 .procname = "inode-state",
1796 .data = &inodes_stat,
1797 .maxlen = 7*sizeof(long),
1799 .proc_handler = proc_nr_inodes,
1802 .procname = "file-nr",
1803 .data = &files_stat,
1804 .maxlen = sizeof(files_stat),
1806 .proc_handler = proc_nr_files,
1809 .procname = "file-max",
1810 .data = &files_stat.max_files,
1811 .maxlen = sizeof(files_stat.max_files),
1813 .proc_handler = proc_doulongvec_minmax,
1815 .extra2 = &long_max,
1818 .procname = "nr_open",
1819 .data = &sysctl_nr_open,
1820 .maxlen = sizeof(unsigned int),
1822 .proc_handler = proc_dointvec_minmax,
1823 .extra1 = &sysctl_nr_open_min,
1824 .extra2 = &sysctl_nr_open_max,
1827 .procname = "dentry-state",
1828 .data = &dentry_stat,
1829 .maxlen = 6*sizeof(long),
1831 .proc_handler = proc_nr_dentry,
1834 .procname = "overflowuid",
1835 .data = &fs_overflowuid,
1836 .maxlen = sizeof(int),
1838 .proc_handler = proc_dointvec_minmax,
1839 .extra1 = &minolduid,
1840 .extra2 = &maxolduid,
1843 .procname = "overflowgid",
1844 .data = &fs_overflowgid,
1845 .maxlen = sizeof(int),
1847 .proc_handler = proc_dointvec_minmax,
1848 .extra1 = &minolduid,
1849 .extra2 = &maxolduid,
1851 #ifdef CONFIG_FILE_LOCKING
1853 .procname = "leases-enable",
1854 .data = &leases_enable,
1855 .maxlen = sizeof(int),
1857 .proc_handler = proc_dointvec,
1860 #ifdef CONFIG_DNOTIFY
1862 .procname = "dir-notify-enable",
1863 .data = &dir_notify_enable,
1864 .maxlen = sizeof(int),
1866 .proc_handler = proc_dointvec,
1870 #ifdef CONFIG_FILE_LOCKING
1872 .procname = "lease-break-time",
1873 .data = &lease_break_time,
1874 .maxlen = sizeof(int),
1876 .proc_handler = proc_dointvec,
1881 .procname = "aio-nr",
1883 .maxlen = sizeof(aio_nr),
1885 .proc_handler = proc_doulongvec_minmax,
1888 .procname = "aio-max-nr",
1889 .data = &aio_max_nr,
1890 .maxlen = sizeof(aio_max_nr),
1892 .proc_handler = proc_doulongvec_minmax,
1894 #endif /* CONFIG_AIO */
1895 #ifdef CONFIG_INOTIFY_USER
1897 .procname = "inotify",
1899 .child = inotify_table,
1904 .procname = "epoll",
1906 .child = epoll_table,
1911 .procname = "protected_symlinks",
1912 .data = &sysctl_protected_symlinks,
1913 .maxlen = sizeof(int),
1915 .proc_handler = proc_dointvec_minmax,
1916 .extra1 = SYSCTL_ZERO,
1917 .extra2 = SYSCTL_ONE,
1920 .procname = "protected_hardlinks",
1921 .data = &sysctl_protected_hardlinks,
1922 .maxlen = sizeof(int),
1924 .proc_handler = proc_dointvec_minmax,
1925 .extra1 = SYSCTL_ZERO,
1926 .extra2 = SYSCTL_ONE,
1929 .procname = "protected_fifos",
1930 .data = &sysctl_protected_fifos,
1931 .maxlen = sizeof(int),
1933 .proc_handler = proc_dointvec_minmax,
1934 .extra1 = SYSCTL_ZERO,
1938 .procname = "protected_regular",
1939 .data = &sysctl_protected_regular,
1940 .maxlen = sizeof(int),
1942 .proc_handler = proc_dointvec_minmax,
1943 .extra1 = SYSCTL_ZERO,
1947 .procname = "suid_dumpable",
1948 .data = &suid_dumpable,
1949 .maxlen = sizeof(int),
1951 .proc_handler = proc_dointvec_minmax_coredump,
1952 .extra1 = SYSCTL_ZERO,
1955 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1957 .procname = "binfmt_misc",
1959 .child = sysctl_mount_point,
1963 .procname = "pipe-max-size",
1964 .data = &pipe_max_size,
1965 .maxlen = sizeof(pipe_max_size),
1967 .proc_handler = proc_dopipe_max_size,
1970 .procname = "pipe-user-pages-hard",
1971 .data = &pipe_user_pages_hard,
1972 .maxlen = sizeof(pipe_user_pages_hard),
1974 .proc_handler = proc_doulongvec_minmax,
1977 .procname = "pipe-user-pages-soft",
1978 .data = &pipe_user_pages_soft,
1979 .maxlen = sizeof(pipe_user_pages_soft),
1981 .proc_handler = proc_doulongvec_minmax,
1984 .procname = "mount-max",
1985 .data = &sysctl_mount_max,
1986 .maxlen = sizeof(unsigned int),
1988 .proc_handler = proc_dointvec_minmax,
1989 .extra1 = SYSCTL_ONE,
1994 static struct ctl_table debug_table[] = {
1995 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1997 .procname = "exception-trace",
1998 .data = &show_unhandled_signals,
1999 .maxlen = sizeof(int),
2001 .proc_handler = proc_dointvec
2004 #if defined(CONFIG_OPTPROBES)
2006 .procname = "kprobes-optimization",
2007 .data = &sysctl_kprobes_optimization,
2008 .maxlen = sizeof(int),
2010 .proc_handler = proc_kprobes_optimization_handler,
2011 .extra1 = SYSCTL_ZERO,
2012 .extra2 = SYSCTL_ONE,
2018 static struct ctl_table dev_table[] = {
2022 int __init sysctl_init(void)
2024 struct ctl_table_header *hdr;
2026 hdr = register_sysctl_table(sysctl_base_table);
2027 kmemleak_not_leak(hdr);
2031 #endif /* CONFIG_SYSCTL */
2037 #ifdef CONFIG_PROC_SYSCTL
2039 static int _proc_do_string(char *data, int maxlen, int write,
2040 char __user *buffer,
2041 size_t *lenp, loff_t *ppos)
2047 if (!data || !maxlen || !*lenp) {
2053 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
2054 /* Only continue writes not past the end of buffer. */
2056 if (len > maxlen - 1)
2063 /* Start writing from beginning of buffer. */
2069 while ((p - buffer) < *lenp && len < maxlen - 1) {
2070 if (get_user(c, p++))
2072 if (c == 0 || c == '\n')
2093 if (copy_to_user(buffer, data, len))
2096 if (put_user('\n', buffer + len))
2106 static void warn_sysctl_write(struct ctl_table *table)
2108 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2109 "This will not be supported in the future. To silence this\n"
2110 "warning, set kernel.sysctl_writes_strict = -1\n",
2111 current->comm, table->procname);
2115 * proc_first_pos_non_zero_ignore - check if first position is allowed
2116 * @ppos: file position
2117 * @table: the sysctl table
2119 * Returns true if the first position is non-zero and the sysctl_writes_strict
2120 * mode indicates this is not allowed for numeric input types. String proc
2121 * handlers can ignore the return value.
2123 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2124 struct ctl_table *table)
2129 switch (sysctl_writes_strict) {
2130 case SYSCTL_WRITES_STRICT:
2132 case SYSCTL_WRITES_WARN:
2133 warn_sysctl_write(table);
2141 * proc_dostring - read a string sysctl
2142 * @table: the sysctl table
2143 * @write: %TRUE if this is a write to the sysctl file
2144 * @buffer: the user buffer
2145 * @lenp: the size of the user buffer
2146 * @ppos: file position
2148 * Reads/writes a string from/to the user buffer. If the kernel
2149 * buffer provided is not large enough to hold the string, the
2150 * string is truncated. The copied string is %NULL-terminated.
2151 * If the string is being read by the user process, it is copied
2152 * and a newline '\n' is added. It is truncated if the buffer is
2155 * Returns 0 on success.
2157 int proc_dostring(struct ctl_table *table, int write,
2158 void __user *buffer, size_t *lenp, loff_t *ppos)
2161 proc_first_pos_non_zero_ignore(ppos, table);
2163 return _proc_do_string((char *)(table->data), table->maxlen, write,
2164 (char __user *)buffer, lenp, ppos);
2167 static void proc_skip_spaces(char **buf, size_t *size)
2170 if (!isspace(**buf))
2177 static void proc_skip_char(char **buf, size_t *size, const char v)
2188 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2191 * @cp: kernel buffer containing the string to parse
2192 * @endp: pointer to store the trailing characters
2193 * @base: the base to use
2194 * @res: where the parsed integer will be stored
2196 * In case of success 0 is returned and @res will contain the parsed integer,
2197 * @endp will hold any trailing characters.
2198 * This function will fail the parse on overflow. If there wasn't an overflow
2199 * the function will defer the decision what characters count as invalid to the
2202 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2205 unsigned long long result;
2208 cp = _parse_integer_fixup_radix(cp, &base);
2209 rv = _parse_integer(cp, base, &result);
2210 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2218 *res = (unsigned long)result;
2222 #define TMPBUFLEN 22
2224 * proc_get_long - reads an ASCII formatted integer from a user buffer
2226 * @buf: a kernel buffer
2227 * @size: size of the kernel buffer
2228 * @val: this is where the number will be stored
2229 * @neg: set to %TRUE if number is negative
2230 * @perm_tr: a vector which contains the allowed trailers
2231 * @perm_tr_len: size of the perm_tr vector
2232 * @tr: pointer to store the trailer character
2234 * In case of success %0 is returned and @buf and @size are updated with
2235 * the amount of bytes read. If @tr is non-NULL and a trailing
2236 * character exists (size is non-zero after returning from this
2237 * function), @tr is updated with the trailing character.
2239 static int proc_get_long(char **buf, size_t *size,
2240 unsigned long *val, bool *neg,
2241 const char *perm_tr, unsigned perm_tr_len, char *tr)
2243 char *p, tmp[TMPBUFLEN];
2244 ssize_t len = *size;
2249 if (len > TMPBUFLEN - 1)
2250 len = TMPBUFLEN - 1;
2252 memcpy(tmp, *buf, len);
2256 if (*p == '-' && *size > 1) {
2264 if (strtoul_lenient(p, &p, 0, val))
2269 /* We don't know if the next char is whitespace thus we may accept
2270 * invalid integers (e.g. 1234...a) or two integers instead of one
2271 * (e.g. 123...1). So lets not allow such large numbers. */
2272 if (len == TMPBUFLEN - 1)
2275 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2278 if (tr && (len < *size))
2288 * proc_put_long - converts an integer to a decimal ASCII formatted string
2290 * @buf: the user buffer
2291 * @size: the size of the user buffer
2292 * @val: the integer to be converted
2293 * @neg: sign of the number, %TRUE for negative
2295 * In case of success %0 is returned and @buf and @size are updated with
2296 * the amount of bytes written.
2298 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2302 char tmp[TMPBUFLEN], *p = tmp;
2304 sprintf(p, "%s%lu", neg ? "-" : "", val);
2308 if (copy_to_user(*buf, tmp, len))
2316 static int proc_put_char(void __user **buf, size_t *size, char c)
2319 char __user **buffer = (char __user **)buf;
2320 if (put_user(c, *buffer))
2322 (*size)--, (*buffer)++;
2328 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2330 int write, void *data)
2334 if (*lvalp > (unsigned long) INT_MAX + 1)
2338 if (*lvalp > (unsigned long) INT_MAX)
2346 *lvalp = -(unsigned long)val;
2349 *lvalp = (unsigned long)val;
2355 static int do_proc_douintvec_conv(unsigned long *lvalp,
2357 int write, void *data)
2360 if (*lvalp > UINT_MAX)
2364 unsigned int val = *valp;
2365 *lvalp = (unsigned long)val;
2370 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2372 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2373 int write, void __user *buffer,
2374 size_t *lenp, loff_t *ppos,
2375 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2376 int write, void *data),
2379 int *i, vleft, first = 1, err = 0;
2381 char *kbuf = NULL, *p;
2383 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2388 i = (int *) tbl_data;
2389 vleft = table->maxlen / sizeof(*i);
2393 conv = do_proc_dointvec_conv;
2396 if (proc_first_pos_non_zero_ignore(ppos, table))
2399 if (left > PAGE_SIZE - 1)
2400 left = PAGE_SIZE - 1;
2401 p = kbuf = memdup_user_nul(buffer, left);
2403 return PTR_ERR(kbuf);
2406 for (; left && vleft--; i++, first=0) {
2411 proc_skip_spaces(&p, &left);
2415 err = proc_get_long(&p, &left, &lval, &neg,
2417 sizeof(proc_wspace_sep), NULL);
2420 if (conv(&neg, &lval, i, 1, data)) {
2425 if (conv(&neg, &lval, i, 0, data)) {
2430 err = proc_put_char(&buffer, &left, '\t');
2433 err = proc_put_long(&buffer, &left, lval, neg);
2439 if (!write && !first && left && !err)
2440 err = proc_put_char(&buffer, &left, '\n');
2441 if (write && !err && left)
2442 proc_skip_spaces(&p, &left);
2446 return err ? : -EINVAL;
2454 static int do_proc_dointvec(struct ctl_table *table, int write,
2455 void __user *buffer, size_t *lenp, loff_t *ppos,
2456 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2457 int write, void *data),
2460 return __do_proc_dointvec(table->data, table, write,
2461 buffer, lenp, ppos, conv, data);
2464 static int do_proc_douintvec_w(unsigned int *tbl_data,
2465 struct ctl_table *table,
2466 void __user *buffer,
2467 size_t *lenp, loff_t *ppos,
2468 int (*conv)(unsigned long *lvalp,
2470 int write, void *data),
2477 char *kbuf = NULL, *p;
2481 if (proc_first_pos_non_zero_ignore(ppos, table))
2484 if (left > PAGE_SIZE - 1)
2485 left = PAGE_SIZE - 1;
2487 p = kbuf = memdup_user_nul(buffer, left);
2491 proc_skip_spaces(&p, &left);
2497 err = proc_get_long(&p, &left, &lval, &neg,
2499 sizeof(proc_wspace_sep), NULL);
2505 if (conv(&lval, tbl_data, 1, data)) {
2511 proc_skip_spaces(&p, &left);
2520 /* This is in keeping with old __do_proc_dointvec() */
2526 static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2527 size_t *lenp, loff_t *ppos,
2528 int (*conv)(unsigned long *lvalp,
2530 int write, void *data),
2539 if (conv(&lval, tbl_data, 0, data)) {
2544 err = proc_put_long(&buffer, &left, lval, false);
2548 err = proc_put_char(&buffer, &left, '\n');
2557 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2558 int write, void __user *buffer,
2559 size_t *lenp, loff_t *ppos,
2560 int (*conv)(unsigned long *lvalp,
2562 int write, void *data),
2565 unsigned int *i, vleft;
2567 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2572 i = (unsigned int *) tbl_data;
2573 vleft = table->maxlen / sizeof(*i);
2576 * Arrays are not supported, keep this simple. *Do not* add
2585 conv = do_proc_douintvec_conv;
2588 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2590 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2593 static int do_proc_douintvec(struct ctl_table *table, int write,
2594 void __user *buffer, size_t *lenp, loff_t *ppos,
2595 int (*conv)(unsigned long *lvalp,
2597 int write, void *data),
2600 return __do_proc_douintvec(table->data, table, write,
2601 buffer, lenp, ppos, conv, data);
2605 * proc_dointvec - read a vector of integers
2606 * @table: the sysctl table
2607 * @write: %TRUE if this is a write to the sysctl file
2608 * @buffer: the user buffer
2609 * @lenp: the size of the user buffer
2610 * @ppos: file position
2612 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2613 * values from/to the user buffer, treated as an ASCII string.
2615 * Returns 0 on success.
2617 int proc_dointvec(struct ctl_table *table, int write,
2618 void __user *buffer, size_t *lenp, loff_t *ppos)
2620 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2624 * proc_douintvec - read a vector of unsigned integers
2625 * @table: the sysctl table
2626 * @write: %TRUE if this is a write to the sysctl file
2627 * @buffer: the user buffer
2628 * @lenp: the size of the user buffer
2629 * @ppos: file position
2631 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2632 * values from/to the user buffer, treated as an ASCII string.
2634 * Returns 0 on success.
2636 int proc_douintvec(struct ctl_table *table, int write,
2637 void __user *buffer, size_t *lenp, loff_t *ppos)
2639 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2640 do_proc_douintvec_conv, NULL);
2644 * Taint values can only be increased
2645 * This means we can safely use a temporary.
2647 static int proc_taint(struct ctl_table *table, int write,
2648 void __user *buffer, size_t *lenp, loff_t *ppos)
2651 unsigned long tmptaint = get_taint();
2654 if (write && !capable(CAP_SYS_ADMIN))
2659 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2665 * Poor man's atomic or. Not worth adding a primitive
2666 * to everyone's atomic.h for this
2669 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2670 if ((tmptaint >> i) & 1)
2671 add_taint(i, LOCKDEP_STILL_OK);
2678 #ifdef CONFIG_PRINTK
2679 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2680 void __user *buffer, size_t *lenp, loff_t *ppos)
2682 if (write && !capable(CAP_SYS_ADMIN))
2685 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2690 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2691 * @min: pointer to minimum allowable value
2692 * @max: pointer to maximum allowable value
2694 * The do_proc_dointvec_minmax_conv_param structure provides the
2695 * minimum and maximum values for doing range checking for those sysctl
2696 * parameters that use the proc_dointvec_minmax() handler.
2698 struct do_proc_dointvec_minmax_conv_param {
2703 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2705 int write, void *data)
2708 struct do_proc_dointvec_minmax_conv_param *param = data;
2710 * If writing, first do so via a temporary local int so we can
2711 * bounds-check it before touching *valp.
2713 int *ip = write ? &tmp : valp;
2715 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
2720 if ((param->min && *param->min > tmp) ||
2721 (param->max && *param->max < tmp))
2730 * proc_dointvec_minmax - read a vector of integers with min/max values
2731 * @table: the sysctl table
2732 * @write: %TRUE if this is a write to the sysctl file
2733 * @buffer: the user buffer
2734 * @lenp: the size of the user buffer
2735 * @ppos: file position
2737 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2738 * values from/to the user buffer, treated as an ASCII string.
2740 * This routine will ensure the values are within the range specified by
2741 * table->extra1 (min) and table->extra2 (max).
2743 * Returns 0 on success or -EINVAL on write when the range check fails.
2745 int proc_dointvec_minmax(struct ctl_table *table, int write,
2746 void __user *buffer, size_t *lenp, loff_t *ppos)
2748 struct do_proc_dointvec_minmax_conv_param param = {
2749 .min = (int *) table->extra1,
2750 .max = (int *) table->extra2,
2752 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2753 do_proc_dointvec_minmax_conv, ¶m);
2757 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2758 * @min: pointer to minimum allowable value
2759 * @max: pointer to maximum allowable value
2761 * The do_proc_douintvec_minmax_conv_param structure provides the
2762 * minimum and maximum values for doing range checking for those sysctl
2763 * parameters that use the proc_douintvec_minmax() handler.
2765 struct do_proc_douintvec_minmax_conv_param {
2770 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2772 int write, void *data)
2776 struct do_proc_douintvec_minmax_conv_param *param = data;
2777 /* write via temporary local uint for bounds-checking */
2778 unsigned int *up = write ? &tmp : valp;
2780 ret = do_proc_douintvec_conv(lvalp, up, write, data);
2785 if ((param->min && *param->min > tmp) ||
2786 (param->max && *param->max < tmp))
2796 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2797 * @table: the sysctl table
2798 * @write: %TRUE if this is a write to the sysctl file
2799 * @buffer: the user buffer
2800 * @lenp: the size of the user buffer
2801 * @ppos: file position
2803 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2804 * values from/to the user buffer, treated as an ASCII string. Negative
2805 * strings are not allowed.
2807 * This routine will ensure the values are within the range specified by
2808 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2809 * check for UINT_MAX to avoid having to support wrap around uses from
2812 * Returns 0 on success or -ERANGE on write when the range check fails.
2814 int proc_douintvec_minmax(struct ctl_table *table, int write,
2815 void __user *buffer, size_t *lenp, loff_t *ppos)
2817 struct do_proc_douintvec_minmax_conv_param param = {
2818 .min = (unsigned int *) table->extra1,
2819 .max = (unsigned int *) table->extra2,
2821 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2822 do_proc_douintvec_minmax_conv, ¶m);
2825 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2827 int write, void *data)
2832 val = round_pipe_size(*lvalp);
2838 unsigned int val = *valp;
2839 *lvalp = (unsigned long) val;
2845 static int proc_dopipe_max_size(struct ctl_table *table, int write,
2846 void __user *buffer, size_t *lenp, loff_t *ppos)
2848 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2849 do_proc_dopipe_max_size_conv, NULL);
2852 static void validate_coredump_safety(void)
2854 #ifdef CONFIG_COREDUMP
2855 if (suid_dumpable == SUID_DUMP_ROOT &&
2856 core_pattern[0] != '/' && core_pattern[0] != '|') {
2858 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2859 "Pipe handler or fully qualified core dump path required.\n"
2860 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2866 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2867 void __user *buffer, size_t *lenp, loff_t *ppos)
2869 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2871 validate_coredump_safety();
2875 #ifdef CONFIG_COREDUMP
2876 static int proc_dostring_coredump(struct ctl_table *table, int write,
2877 void __user *buffer, size_t *lenp, loff_t *ppos)
2879 int error = proc_dostring(table, write, buffer, lenp, ppos);
2881 validate_coredump_safety();
2886 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2887 void __user *buffer,
2888 size_t *lenp, loff_t *ppos,
2889 unsigned long convmul,
2890 unsigned long convdiv)
2892 unsigned long *i, *min, *max;
2893 int vleft, first = 1, err = 0;
2895 char *kbuf = NULL, *p;
2897 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2902 i = (unsigned long *) data;
2903 min = (unsigned long *) table->extra1;
2904 max = (unsigned long *) table->extra2;
2905 vleft = table->maxlen / sizeof(unsigned long);
2909 if (proc_first_pos_non_zero_ignore(ppos, table))
2912 if (left > PAGE_SIZE - 1)
2913 left = PAGE_SIZE - 1;
2914 p = kbuf = memdup_user_nul(buffer, left);
2916 return PTR_ERR(kbuf);
2919 for (; left && vleft--; i++, first = 0) {
2925 proc_skip_spaces(&p, &left);
2929 err = proc_get_long(&p, &left, &val, &neg,
2931 sizeof(proc_wspace_sep), NULL);
2936 val = convmul * val / convdiv;
2937 if ((min && val < *min) || (max && val > *max)) {
2943 val = convdiv * (*i) / convmul;
2945 err = proc_put_char(&buffer, &left, '\t');
2949 err = proc_put_long(&buffer, &left, val, false);
2955 if (!write && !first && left && !err)
2956 err = proc_put_char(&buffer, &left, '\n');
2958 proc_skip_spaces(&p, &left);
2962 return err ? : -EINVAL;
2970 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2971 void __user *buffer,
2972 size_t *lenp, loff_t *ppos,
2973 unsigned long convmul,
2974 unsigned long convdiv)
2976 return __do_proc_doulongvec_minmax(table->data, table, write,
2977 buffer, lenp, ppos, convmul, convdiv);
2981 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2982 * @table: the sysctl table
2983 * @write: %TRUE if this is a write to the sysctl file
2984 * @buffer: the user buffer
2985 * @lenp: the size of the user buffer
2986 * @ppos: file position
2988 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2989 * values from/to the user buffer, treated as an ASCII string.
2991 * This routine will ensure the values are within the range specified by
2992 * table->extra1 (min) and table->extra2 (max).
2994 * Returns 0 on success.
2996 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2997 void __user *buffer, size_t *lenp, loff_t *ppos)
2999 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
3003 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
3004 * @table: the sysctl table
3005 * @write: %TRUE if this is a write to the sysctl file
3006 * @buffer: the user buffer
3007 * @lenp: the size of the user buffer
3008 * @ppos: file position
3010 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
3011 * values from/to the user buffer, treated as an ASCII string. The values
3012 * are treated as milliseconds, and converted to jiffies when they are stored.
3014 * This routine will ensure the values are within the range specified by
3015 * table->extra1 (min) and table->extra2 (max).
3017 * Returns 0 on success.
3019 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3020 void __user *buffer,
3021 size_t *lenp, loff_t *ppos)
3023 return do_proc_doulongvec_minmax(table, write, buffer,
3024 lenp, ppos, HZ, 1000l);
3028 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
3030 int write, void *data)
3033 if (*lvalp > INT_MAX / HZ)
3035 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
3041 lval = -(unsigned long)val;
3044 lval = (unsigned long)val;
3051 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
3053 int write, void *data)
3056 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
3058 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
3064 lval = -(unsigned long)val;
3067 lval = (unsigned long)val;
3069 *lvalp = jiffies_to_clock_t(lval);
3074 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
3076 int write, void *data)
3079 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3089 lval = -(unsigned long)val;
3092 lval = (unsigned long)val;
3094 *lvalp = jiffies_to_msecs(lval);
3100 * proc_dointvec_jiffies - read a vector of integers as seconds
3101 * @table: the sysctl table
3102 * @write: %TRUE if this is a write to the sysctl file
3103 * @buffer: the user buffer
3104 * @lenp: the size of the user buffer
3105 * @ppos: file position
3107 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3108 * values from/to the user buffer, treated as an ASCII string.
3109 * The values read are assumed to be in seconds, and are converted into
3112 * Returns 0 on success.
3114 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3115 void __user *buffer, size_t *lenp, loff_t *ppos)
3117 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3118 do_proc_dointvec_jiffies_conv,NULL);
3122 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3123 * @table: the sysctl table
3124 * @write: %TRUE if this is a write to the sysctl file
3125 * @buffer: the user buffer
3126 * @lenp: the size of the user buffer
3127 * @ppos: pointer to the file position
3129 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3130 * values from/to the user buffer, treated as an ASCII string.
3131 * The values read are assumed to be in 1/USER_HZ seconds, and
3132 * are converted into jiffies.
3134 * Returns 0 on success.
3136 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3137 void __user *buffer, size_t *lenp, loff_t *ppos)
3139 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3140 do_proc_dointvec_userhz_jiffies_conv,NULL);
3144 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3145 * @table: the sysctl table
3146 * @write: %TRUE if this is a write to the sysctl file
3147 * @buffer: the user buffer
3148 * @lenp: the size of the user buffer
3149 * @ppos: file position
3150 * @ppos: the current position in the file
3152 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3153 * values from/to the user buffer, treated as an ASCII string.
3154 * The values read are assumed to be in 1/1000 seconds, and
3155 * are converted into jiffies.
3157 * Returns 0 on success.
3159 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3160 void __user *buffer, size_t *lenp, loff_t *ppos)
3162 return do_proc_dointvec(table, write, buffer, lenp, ppos,
3163 do_proc_dointvec_ms_jiffies_conv, NULL);
3166 static int proc_do_cad_pid(struct ctl_table *table, int write,
3167 void __user *buffer, size_t *lenp, loff_t *ppos)
3169 struct pid *new_pid;
3173 tmp = pid_vnr(cad_pid);
3175 r = __do_proc_dointvec(&tmp, table, write, buffer,
3176 lenp, ppos, NULL, NULL);
3180 new_pid = find_get_pid(tmp);
3184 put_pid(xchg(&cad_pid, new_pid));
3189 * proc_do_large_bitmap - read/write from/to a large bitmap
3190 * @table: the sysctl table
3191 * @write: %TRUE if this is a write to the sysctl file
3192 * @buffer: the user buffer
3193 * @lenp: the size of the user buffer
3194 * @ppos: file position
3196 * The bitmap is stored at table->data and the bitmap length (in bits)
3199 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3200 * large bitmaps may be represented in a compact manner. Writing into
3201 * the file will clear the bitmap then update it with the given input.
3203 * Returns 0 on success.
3205 int proc_do_large_bitmap(struct ctl_table *table, int write,
3206 void __user *buffer, size_t *lenp, loff_t *ppos)
3210 size_t left = *lenp;
3211 unsigned long bitmap_len = table->maxlen;
3212 unsigned long *bitmap = *(unsigned long **) table->data;
3213 unsigned long *tmp_bitmap = NULL;
3214 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3216 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
3225 if (left > PAGE_SIZE - 1) {
3226 left = PAGE_SIZE - 1;
3227 /* How much of the buffer we'll skip this pass */
3228 skipped = *lenp - left;
3231 p = kbuf = memdup_user_nul(buffer, left);
3233 return PTR_ERR(kbuf);
3235 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
3240 proc_skip_char(&p, &left, '\n');
3241 while (!err && left) {
3242 unsigned long val_a, val_b;
3246 /* In case we stop parsing mid-number, we can reset */
3248 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
3251 * If we consumed the entirety of a truncated buffer or
3252 * only one char is left (may be a "-"), then stop here,
3253 * reset, & come back for more.
3255 if ((left <= 1) && skipped) {
3262 if (val_a >= bitmap_len || neg) {
3274 err = proc_get_long(&p, &left, &val_b,
3275 &neg, tr_b, sizeof(tr_b),
3278 * If we consumed all of a truncated buffer or
3279 * then stop here, reset, & come back for more.
3281 if (!left && skipped) {
3288 if (val_b >= bitmap_len || neg ||
3299 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
3301 proc_skip_char(&p, &left, '\n');
3306 unsigned long bit_a, bit_b = 0;
3309 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3310 if (bit_a >= bitmap_len)
3312 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3316 err = proc_put_char(&buffer, &left, ',');
3320 err = proc_put_long(&buffer, &left, bit_a, false);
3323 if (bit_a != bit_b) {
3324 err = proc_put_char(&buffer, &left, '-');
3327 err = proc_put_long(&buffer, &left, bit_b, false);
3335 err = proc_put_char(&buffer, &left, '\n');
3341 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3343 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
3349 bitmap_free(tmp_bitmap);
3353 #else /* CONFIG_PROC_SYSCTL */
3355 int proc_dostring(struct ctl_table *table, int write,
3356 void __user *buffer, size_t *lenp, loff_t *ppos)
3361 int proc_dointvec(struct ctl_table *table, int write,
3362 void __user *buffer, size_t *lenp, loff_t *ppos)
3367 int proc_douintvec(struct ctl_table *table, int write,
3368 void __user *buffer, size_t *lenp, loff_t *ppos)
3373 int proc_dointvec_minmax(struct ctl_table *table, int write,
3374 void __user *buffer, size_t *lenp, loff_t *ppos)
3379 int proc_douintvec_minmax(struct ctl_table *table, int write,
3380 void __user *buffer, size_t *lenp, loff_t *ppos)
3385 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3386 void __user *buffer, size_t *lenp, loff_t *ppos)
3391 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3392 void __user *buffer, size_t *lenp, loff_t *ppos)
3397 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3398 void __user *buffer, size_t *lenp, loff_t *ppos)
3403 int proc_doulongvec_minmax(struct ctl_table *table, int write,
3404 void __user *buffer, size_t *lenp, loff_t *ppos)
3409 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3410 void __user *buffer,
3411 size_t *lenp, loff_t *ppos)
3416 int proc_do_large_bitmap(struct ctl_table *table, int write,
3417 void __user *buffer, size_t *lenp, loff_t *ppos)
3422 #endif /* CONFIG_PROC_SYSCTL */
3424 #if defined(CONFIG_SYSCTL)
3425 int proc_do_static_key(struct ctl_table *table, int write,
3426 void __user *buffer, size_t *lenp,
3429 struct static_key *key = (struct static_key *)table->data;
3430 static DEFINE_MUTEX(static_key_mutex);
3432 struct ctl_table tmp = {
3434 .maxlen = sizeof(val),
3435 .mode = table->mode,
3436 .extra1 = SYSCTL_ZERO,
3437 .extra2 = SYSCTL_ONE,
3440 if (write && !capable(CAP_SYS_ADMIN))
3443 mutex_lock(&static_key_mutex);
3444 val = static_key_enabled(key);
3445 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3446 if (write && !ret) {
3448 static_key_enable(key);
3450 static_key_disable(key);
3452 mutex_unlock(&static_key_mutex);
3457 * No sense putting this after each symbol definition, twice,
3458 * exception granted :-)
3460 EXPORT_SYMBOL(proc_dointvec);
3461 EXPORT_SYMBOL(proc_douintvec);
3462 EXPORT_SYMBOL(proc_dointvec_jiffies);
3463 EXPORT_SYMBOL(proc_dointvec_minmax);
3464 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3465 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3466 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3467 EXPORT_SYMBOL(proc_dostring);
3468 EXPORT_SYMBOL(proc_doulongvec_minmax);
3469 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3470 EXPORT_SYMBOL(proc_do_large_bitmap);