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 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
233 void __user *buffer, size_t *lenp, loff_t *ppos);
236 static struct ctl_table kern_table[];
237 static struct ctl_table vm_table[];
238 static struct ctl_table fs_table[];
239 static struct ctl_table debug_table[];
240 static struct ctl_table dev_table[];
241 extern struct ctl_table random_table[];
243 extern struct ctl_table epoll_table[];
246 #ifdef CONFIG_FW_LOADER_USER_HELPER
247 extern struct ctl_table firmware_config_table[];
250 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
251 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
252 int sysctl_legacy_va_layout;
255 /* The default sysctl tables: */
257 static struct ctl_table sysctl_base_table[] = {
259 .procname = "kernel",
276 .child = debug_table,
286 #ifdef CONFIG_SCHED_DEBUG
287 static int min_sched_granularity_ns = 100000; /* 100 usecs */
288 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
289 static int min_wakeup_granularity_ns; /* 0 usecs */
290 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
292 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
293 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
294 #endif /* CONFIG_SMP */
295 #endif /* CONFIG_SCHED_DEBUG */
297 #ifdef CONFIG_COMPACTION
298 static int min_extfrag_threshold;
299 static int max_extfrag_threshold = 1000;
302 static struct ctl_table kern_table[] = {
304 .procname = "sched_child_runs_first",
305 .data = &sysctl_sched_child_runs_first,
306 .maxlen = sizeof(unsigned int),
308 .proc_handler = proc_dointvec,
310 #ifdef CONFIG_SCHED_DEBUG
312 .procname = "sched_min_granularity_ns",
313 .data = &sysctl_sched_min_granularity,
314 .maxlen = sizeof(unsigned int),
316 .proc_handler = sched_proc_update_handler,
317 .extra1 = &min_sched_granularity_ns,
318 .extra2 = &max_sched_granularity_ns,
321 .procname = "sched_latency_ns",
322 .data = &sysctl_sched_latency,
323 .maxlen = sizeof(unsigned int),
325 .proc_handler = sched_proc_update_handler,
326 .extra1 = &min_sched_granularity_ns,
327 .extra2 = &max_sched_granularity_ns,
330 .procname = "sched_wakeup_granularity_ns",
331 .data = &sysctl_sched_wakeup_granularity,
332 .maxlen = sizeof(unsigned int),
334 .proc_handler = sched_proc_update_handler,
335 .extra1 = &min_wakeup_granularity_ns,
336 .extra2 = &max_wakeup_granularity_ns,
340 .procname = "sched_tunable_scaling",
341 .data = &sysctl_sched_tunable_scaling,
342 .maxlen = sizeof(enum sched_tunable_scaling),
344 .proc_handler = sched_proc_update_handler,
345 .extra1 = &min_sched_tunable_scaling,
346 .extra2 = &max_sched_tunable_scaling,
349 .procname = "sched_migration_cost_ns",
350 .data = &sysctl_sched_migration_cost,
351 .maxlen = sizeof(unsigned int),
353 .proc_handler = proc_dointvec,
356 .procname = "sched_nr_migrate",
357 .data = &sysctl_sched_nr_migrate,
358 .maxlen = sizeof(unsigned int),
360 .proc_handler = proc_dointvec,
362 #ifdef CONFIG_SCHEDSTATS
364 .procname = "sched_schedstats",
366 .maxlen = sizeof(unsigned int),
368 .proc_handler = sysctl_schedstats,
369 .extra1 = SYSCTL_ZERO,
370 .extra2 = SYSCTL_ONE,
372 #endif /* CONFIG_SCHEDSTATS */
373 #endif /* CONFIG_SMP */
374 #ifdef CONFIG_NUMA_BALANCING
376 .procname = "numa_balancing_scan_delay_ms",
377 .data = &sysctl_numa_balancing_scan_delay,
378 .maxlen = sizeof(unsigned int),
380 .proc_handler = proc_dointvec,
383 .procname = "numa_balancing_scan_period_min_ms",
384 .data = &sysctl_numa_balancing_scan_period_min,
385 .maxlen = sizeof(unsigned int),
387 .proc_handler = proc_dointvec,
390 .procname = "numa_balancing_scan_period_max_ms",
391 .data = &sysctl_numa_balancing_scan_period_max,
392 .maxlen = sizeof(unsigned int),
394 .proc_handler = proc_dointvec,
397 .procname = "numa_balancing_scan_size_mb",
398 .data = &sysctl_numa_balancing_scan_size,
399 .maxlen = sizeof(unsigned int),
401 .proc_handler = proc_dointvec_minmax,
402 .extra1 = SYSCTL_ONE,
405 .procname = "numa_balancing",
406 .data = NULL, /* filled in by handler */
407 .maxlen = sizeof(unsigned int),
409 .proc_handler = sysctl_numa_balancing,
410 .extra1 = SYSCTL_ZERO,
411 .extra2 = SYSCTL_ONE,
413 #endif /* CONFIG_NUMA_BALANCING */
414 #endif /* CONFIG_SCHED_DEBUG */
416 .procname = "sched_rt_period_us",
417 .data = &sysctl_sched_rt_period,
418 .maxlen = sizeof(unsigned int),
420 .proc_handler = sched_rt_handler,
423 .procname = "sched_rt_runtime_us",
424 .data = &sysctl_sched_rt_runtime,
425 .maxlen = sizeof(int),
427 .proc_handler = sched_rt_handler,
430 .procname = "sched_rr_timeslice_ms",
431 .data = &sysctl_sched_rr_timeslice,
432 .maxlen = sizeof(int),
434 .proc_handler = sched_rr_handler,
436 #ifdef CONFIG_UCLAMP_TASK
438 .procname = "sched_util_clamp_min",
439 .data = &sysctl_sched_uclamp_util_min,
440 .maxlen = sizeof(unsigned int),
442 .proc_handler = sysctl_sched_uclamp_handler,
445 .procname = "sched_util_clamp_max",
446 .data = &sysctl_sched_uclamp_util_max,
447 .maxlen = sizeof(unsigned int),
449 .proc_handler = sysctl_sched_uclamp_handler,
452 #ifdef CONFIG_SCHED_AUTOGROUP
454 .procname = "sched_autogroup_enabled",
455 .data = &sysctl_sched_autogroup_enabled,
456 .maxlen = sizeof(unsigned int),
458 .proc_handler = proc_dointvec_minmax,
459 .extra1 = SYSCTL_ZERO,
460 .extra2 = SYSCTL_ONE,
463 #ifdef CONFIG_CFS_BANDWIDTH
465 .procname = "sched_cfs_bandwidth_slice_us",
466 .data = &sysctl_sched_cfs_bandwidth_slice,
467 .maxlen = sizeof(unsigned int),
469 .proc_handler = proc_dointvec_minmax,
470 .extra1 = SYSCTL_ONE,
473 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
475 .procname = "sched_energy_aware",
476 .data = &sysctl_sched_energy_aware,
477 .maxlen = sizeof(unsigned int),
479 .proc_handler = sched_energy_aware_handler,
480 .extra1 = SYSCTL_ZERO,
481 .extra2 = SYSCTL_ONE,
484 #ifdef CONFIG_PROVE_LOCKING
486 .procname = "prove_locking",
487 .data = &prove_locking,
488 .maxlen = sizeof(int),
490 .proc_handler = proc_dointvec,
493 #ifdef CONFIG_LOCK_STAT
495 .procname = "lock_stat",
497 .maxlen = sizeof(int),
499 .proc_handler = proc_dointvec,
504 .data = &panic_timeout,
505 .maxlen = sizeof(int),
507 .proc_handler = proc_dointvec,
509 #ifdef CONFIG_COREDUMP
511 .procname = "core_uses_pid",
512 .data = &core_uses_pid,
513 .maxlen = sizeof(int),
515 .proc_handler = proc_dointvec,
518 .procname = "core_pattern",
519 .data = core_pattern,
520 .maxlen = CORENAME_MAX_SIZE,
522 .proc_handler = proc_dostring_coredump,
525 .procname = "core_pipe_limit",
526 .data = &core_pipe_limit,
527 .maxlen = sizeof(unsigned int),
529 .proc_handler = proc_dointvec,
532 #ifdef CONFIG_PROC_SYSCTL
534 .procname = "tainted",
535 .maxlen = sizeof(long),
537 .proc_handler = proc_taint,
540 .procname = "sysctl_writes_strict",
541 .data = &sysctl_writes_strict,
542 .maxlen = sizeof(int),
544 .proc_handler = proc_dointvec_minmax,
546 .extra2 = SYSCTL_ONE,
549 #ifdef CONFIG_LATENCYTOP
551 .procname = "latencytop",
552 .data = &latencytop_enabled,
553 .maxlen = sizeof(int),
555 .proc_handler = sysctl_latencytop,
558 #ifdef CONFIG_BLK_DEV_INITRD
560 .procname = "real-root-dev",
561 .data = &real_root_dev,
562 .maxlen = sizeof(int),
564 .proc_handler = proc_dointvec,
568 .procname = "print-fatal-signals",
569 .data = &print_fatal_signals,
570 .maxlen = sizeof(int),
572 .proc_handler = proc_dointvec,
576 .procname = "reboot-cmd",
577 .data = reboot_command,
580 .proc_handler = proc_dostring,
583 .procname = "stop-a",
584 .data = &stop_a_enabled,
585 .maxlen = sizeof (int),
587 .proc_handler = proc_dointvec,
590 .procname = "scons-poweroff",
591 .data = &scons_pwroff,
592 .maxlen = sizeof (int),
594 .proc_handler = proc_dointvec,
597 #ifdef CONFIG_SPARC64
599 .procname = "tsb-ratio",
600 .data = &sysctl_tsb_ratio,
601 .maxlen = sizeof (int),
603 .proc_handler = proc_dointvec,
608 .procname = "soft-power",
609 .data = &pwrsw_enabled,
610 .maxlen = sizeof (int),
612 .proc_handler = proc_dointvec,
615 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
617 .procname = "unaligned-trap",
618 .data = &unaligned_enabled,
619 .maxlen = sizeof (int),
621 .proc_handler = proc_dointvec,
625 .procname = "ctrl-alt-del",
627 .maxlen = sizeof(int),
629 .proc_handler = proc_dointvec,
631 #ifdef CONFIG_FUNCTION_TRACER
633 .procname = "ftrace_enabled",
634 .data = &ftrace_enabled,
635 .maxlen = sizeof(int),
637 .proc_handler = ftrace_enable_sysctl,
640 #ifdef CONFIG_STACK_TRACER
642 .procname = "stack_tracer_enabled",
643 .data = &stack_tracer_enabled,
644 .maxlen = sizeof(int),
646 .proc_handler = stack_trace_sysctl,
649 #ifdef CONFIG_TRACING
651 .procname = "ftrace_dump_on_oops",
652 .data = &ftrace_dump_on_oops,
653 .maxlen = sizeof(int),
655 .proc_handler = proc_dointvec,
658 .procname = "traceoff_on_warning",
659 .data = &__disable_trace_on_warning,
660 .maxlen = sizeof(__disable_trace_on_warning),
662 .proc_handler = proc_dointvec,
665 .procname = "tracepoint_printk",
666 .data = &tracepoint_printk,
667 .maxlen = sizeof(tracepoint_printk),
669 .proc_handler = tracepoint_printk_sysctl,
672 #ifdef CONFIG_KEXEC_CORE
674 .procname = "kexec_load_disabled",
675 .data = &kexec_load_disabled,
676 .maxlen = sizeof(int),
678 /* only handle a transition from default "0" to "1" */
679 .proc_handler = proc_dointvec_minmax,
680 .extra1 = SYSCTL_ONE,
681 .extra2 = SYSCTL_ONE,
684 #ifdef CONFIG_MODULES
686 .procname = "modprobe",
687 .data = &modprobe_path,
688 .maxlen = KMOD_PATH_LEN,
690 .proc_handler = proc_dostring,
693 .procname = "modules_disabled",
694 .data = &modules_disabled,
695 .maxlen = sizeof(int),
697 /* only handle a transition from default "0" to "1" */
698 .proc_handler = proc_dointvec_minmax,
699 .extra1 = SYSCTL_ONE,
700 .extra2 = SYSCTL_ONE,
703 #ifdef CONFIG_UEVENT_HELPER
705 .procname = "hotplug",
706 .data = &uevent_helper,
707 .maxlen = UEVENT_HELPER_PATH_LEN,
709 .proc_handler = proc_dostring,
712 #ifdef CONFIG_CHR_DEV_SG
714 .procname = "sg-big-buff",
715 .data = &sg_big_buff,
716 .maxlen = sizeof (int),
718 .proc_handler = proc_dointvec,
721 #ifdef CONFIG_BSD_PROCESS_ACCT
725 .maxlen = 3*sizeof(int),
727 .proc_handler = proc_dointvec,
730 #ifdef CONFIG_MAGIC_SYSRQ
734 .maxlen = sizeof (int),
736 .proc_handler = sysrq_sysctl_handler,
739 #ifdef CONFIG_PROC_SYSCTL
741 .procname = "cad_pid",
743 .maxlen = sizeof (int),
745 .proc_handler = proc_do_cad_pid,
749 .procname = "threads-max",
751 .maxlen = sizeof(int),
753 .proc_handler = sysctl_max_threads,
756 .procname = "random",
758 .child = random_table,
761 .procname = "usermodehelper",
763 .child = usermodehelper_table,
765 #ifdef CONFIG_FW_LOADER_USER_HELPER
767 .procname = "firmware_config",
769 .child = firmware_config_table,
773 .procname = "overflowuid",
774 .data = &overflowuid,
775 .maxlen = sizeof(int),
777 .proc_handler = proc_dointvec_minmax,
778 .extra1 = &minolduid,
779 .extra2 = &maxolduid,
782 .procname = "overflowgid",
783 .data = &overflowgid,
784 .maxlen = sizeof(int),
786 .proc_handler = proc_dointvec_minmax,
787 .extra1 = &minolduid,
788 .extra2 = &maxolduid,
792 .procname = "userprocess_debug",
793 .data = &show_unhandled_signals,
794 .maxlen = sizeof(int),
796 .proc_handler = proc_dointvec,
800 .procname = "pid_max",
802 .maxlen = sizeof (int),
804 .proc_handler = proc_dointvec_minmax,
805 .extra1 = &pid_max_min,
806 .extra2 = &pid_max_max,
809 .procname = "panic_on_oops",
810 .data = &panic_on_oops,
811 .maxlen = sizeof(int),
813 .proc_handler = proc_dointvec,
816 .procname = "panic_print",
817 .data = &panic_print,
818 .maxlen = sizeof(unsigned long),
820 .proc_handler = proc_doulongvec_minmax,
822 #if defined CONFIG_PRINTK
824 .procname = "printk",
825 .data = &console_loglevel,
826 .maxlen = 4*sizeof(int),
828 .proc_handler = proc_dointvec,
831 .procname = "printk_ratelimit",
832 .data = &printk_ratelimit_state.interval,
833 .maxlen = sizeof(int),
835 .proc_handler = proc_dointvec_jiffies,
838 .procname = "printk_ratelimit_burst",
839 .data = &printk_ratelimit_state.burst,
840 .maxlen = sizeof(int),
842 .proc_handler = proc_dointvec,
845 .procname = "printk_delay",
846 .data = &printk_delay_msec,
847 .maxlen = sizeof(int),
849 .proc_handler = proc_dointvec_minmax,
850 .extra1 = SYSCTL_ZERO,
851 .extra2 = &ten_thousand,
854 .procname = "printk_devkmsg",
855 .data = devkmsg_log_str,
856 .maxlen = DEVKMSG_STR_MAX_SIZE,
858 .proc_handler = devkmsg_sysctl_set_loglvl,
861 .procname = "dmesg_restrict",
862 .data = &dmesg_restrict,
863 .maxlen = sizeof(int),
865 .proc_handler = proc_dointvec_minmax_sysadmin,
866 .extra1 = SYSCTL_ZERO,
867 .extra2 = SYSCTL_ONE,
870 .procname = "kptr_restrict",
871 .data = &kptr_restrict,
872 .maxlen = sizeof(int),
874 .proc_handler = proc_dointvec_minmax_sysadmin,
875 .extra1 = SYSCTL_ZERO,
880 .procname = "ngroups_max",
881 .data = &ngroups_max,
882 .maxlen = sizeof (int),
884 .proc_handler = proc_dointvec,
887 .procname = "cap_last_cap",
888 .data = (void *)&cap_last_cap,
889 .maxlen = sizeof(int),
891 .proc_handler = proc_dointvec,
893 #if defined(CONFIG_LOCKUP_DETECTOR)
895 .procname = "watchdog",
896 .data = &watchdog_user_enabled,
897 .maxlen = sizeof(int),
899 .proc_handler = proc_watchdog,
900 .extra1 = SYSCTL_ZERO,
901 .extra2 = SYSCTL_ONE,
904 .procname = "watchdog_thresh",
905 .data = &watchdog_thresh,
906 .maxlen = sizeof(int),
908 .proc_handler = proc_watchdog_thresh,
909 .extra1 = SYSCTL_ZERO,
913 .procname = "nmi_watchdog",
914 .data = &nmi_watchdog_user_enabled,
915 .maxlen = sizeof(int),
916 .mode = NMI_WATCHDOG_SYSCTL_PERM,
917 .proc_handler = proc_nmi_watchdog,
918 .extra1 = SYSCTL_ZERO,
919 .extra2 = SYSCTL_ONE,
922 .procname = "watchdog_cpumask",
923 .data = &watchdog_cpumask_bits,
926 .proc_handler = proc_watchdog_cpumask,
928 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
930 .procname = "soft_watchdog",
931 .data = &soft_watchdog_user_enabled,
932 .maxlen = sizeof(int),
934 .proc_handler = proc_soft_watchdog,
935 .extra1 = SYSCTL_ZERO,
936 .extra2 = SYSCTL_ONE,
939 .procname = "softlockup_panic",
940 .data = &softlockup_panic,
941 .maxlen = sizeof(int),
943 .proc_handler = proc_dointvec_minmax,
944 .extra1 = SYSCTL_ZERO,
945 .extra2 = SYSCTL_ONE,
949 .procname = "softlockup_all_cpu_backtrace",
950 .data = &sysctl_softlockup_all_cpu_backtrace,
951 .maxlen = sizeof(int),
953 .proc_handler = proc_dointvec_minmax,
954 .extra1 = SYSCTL_ZERO,
955 .extra2 = SYSCTL_ONE,
957 #endif /* CONFIG_SMP */
959 #ifdef CONFIG_HARDLOCKUP_DETECTOR
961 .procname = "hardlockup_panic",
962 .data = &hardlockup_panic,
963 .maxlen = sizeof(int),
965 .proc_handler = proc_dointvec_minmax,
966 .extra1 = SYSCTL_ZERO,
967 .extra2 = SYSCTL_ONE,
971 .procname = "hardlockup_all_cpu_backtrace",
972 .data = &sysctl_hardlockup_all_cpu_backtrace,
973 .maxlen = sizeof(int),
975 .proc_handler = proc_dointvec_minmax,
976 .extra1 = SYSCTL_ZERO,
977 .extra2 = SYSCTL_ONE,
979 #endif /* CONFIG_SMP */
983 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
985 .procname = "unknown_nmi_panic",
986 .data = &unknown_nmi_panic,
987 .maxlen = sizeof (int),
989 .proc_handler = proc_dointvec,
992 #if defined(CONFIG_X86)
994 .procname = "panic_on_unrecovered_nmi",
995 .data = &panic_on_unrecovered_nmi,
996 .maxlen = sizeof(int),
998 .proc_handler = proc_dointvec,
1001 .procname = "panic_on_io_nmi",
1002 .data = &panic_on_io_nmi,
1003 .maxlen = sizeof(int),
1005 .proc_handler = proc_dointvec,
1007 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1009 .procname = "panic_on_stackoverflow",
1010 .data = &sysctl_panic_on_stackoverflow,
1011 .maxlen = sizeof(int),
1013 .proc_handler = proc_dointvec,
1017 .procname = "bootloader_type",
1018 .data = &bootloader_type,
1019 .maxlen = sizeof (int),
1021 .proc_handler = proc_dointvec,
1024 .procname = "bootloader_version",
1025 .data = &bootloader_version,
1026 .maxlen = sizeof (int),
1028 .proc_handler = proc_dointvec,
1031 .procname = "io_delay_type",
1032 .data = &io_delay_type,
1033 .maxlen = sizeof(int),
1035 .proc_handler = proc_dointvec,
1038 #if defined(CONFIG_MMU)
1040 .procname = "randomize_va_space",
1041 .data = &randomize_va_space,
1042 .maxlen = sizeof(int),
1044 .proc_handler = proc_dointvec,
1047 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1049 .procname = "spin_retry",
1050 .data = &spin_retry,
1051 .maxlen = sizeof (int),
1053 .proc_handler = proc_dointvec,
1056 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1058 .procname = "acpi_video_flags",
1059 .data = &acpi_realmode_flags,
1060 .maxlen = sizeof (unsigned long),
1062 .proc_handler = proc_doulongvec_minmax,
1065 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1067 .procname = "ignore-unaligned-usertrap",
1068 .data = &no_unaligned_warning,
1069 .maxlen = sizeof (int),
1071 .proc_handler = proc_dointvec,
1076 .procname = "unaligned-dump-stack",
1077 .data = &unaligned_dump_stack,
1078 .maxlen = sizeof (int),
1080 .proc_handler = proc_dointvec,
1083 #ifdef CONFIG_DETECT_HUNG_TASK
1085 .procname = "hung_task_panic",
1086 .data = &sysctl_hung_task_panic,
1087 .maxlen = sizeof(int),
1089 .proc_handler = proc_dointvec_minmax,
1090 .extra1 = SYSCTL_ZERO,
1091 .extra2 = SYSCTL_ONE,
1094 .procname = "hung_task_check_count",
1095 .data = &sysctl_hung_task_check_count,
1096 .maxlen = sizeof(int),
1098 .proc_handler = proc_dointvec_minmax,
1099 .extra1 = SYSCTL_ZERO,
1102 .procname = "hung_task_timeout_secs",
1103 .data = &sysctl_hung_task_timeout_secs,
1104 .maxlen = sizeof(unsigned long),
1106 .proc_handler = proc_dohung_task_timeout_secs,
1107 .extra2 = &hung_task_timeout_max,
1110 .procname = "hung_task_check_interval_secs",
1111 .data = &sysctl_hung_task_check_interval_secs,
1112 .maxlen = sizeof(unsigned long),
1114 .proc_handler = proc_dohung_task_timeout_secs,
1115 .extra2 = &hung_task_timeout_max,
1118 .procname = "hung_task_warnings",
1119 .data = &sysctl_hung_task_warnings,
1120 .maxlen = sizeof(int),
1122 .proc_handler = proc_dointvec_minmax,
1126 #ifdef CONFIG_RT_MUTEXES
1128 .procname = "max_lock_depth",
1129 .data = &max_lock_depth,
1130 .maxlen = sizeof(int),
1132 .proc_handler = proc_dointvec,
1136 .procname = "poweroff_cmd",
1137 .data = &poweroff_cmd,
1138 .maxlen = POWEROFF_CMD_PATH_LEN,
1140 .proc_handler = proc_dostring,
1146 .child = key_sysctls,
1149 #ifdef CONFIG_PERF_EVENTS
1151 * User-space scripts rely on the existence of this file
1152 * as a feature check for perf_events being enabled.
1154 * So it's an ABI, do not remove!
1157 .procname = "perf_event_paranoid",
1158 .data = &sysctl_perf_event_paranoid,
1159 .maxlen = sizeof(sysctl_perf_event_paranoid),
1161 .proc_handler = proc_dointvec,
1164 .procname = "perf_event_mlock_kb",
1165 .data = &sysctl_perf_event_mlock,
1166 .maxlen = sizeof(sysctl_perf_event_mlock),
1168 .proc_handler = proc_dointvec,
1171 .procname = "perf_event_max_sample_rate",
1172 .data = &sysctl_perf_event_sample_rate,
1173 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1175 .proc_handler = perf_proc_update_handler,
1176 .extra1 = SYSCTL_ONE,
1179 .procname = "perf_cpu_time_max_percent",
1180 .data = &sysctl_perf_cpu_time_max_percent,
1181 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1183 .proc_handler = perf_cpu_time_max_percent_handler,
1184 .extra1 = SYSCTL_ZERO,
1185 .extra2 = &one_hundred,
1188 .procname = "perf_event_max_stack",
1189 .data = &sysctl_perf_event_max_stack,
1190 .maxlen = sizeof(sysctl_perf_event_max_stack),
1192 .proc_handler = perf_event_max_stack_handler,
1193 .extra1 = SYSCTL_ZERO,
1194 .extra2 = &six_hundred_forty_kb,
1197 .procname = "perf_event_max_contexts_per_stack",
1198 .data = &sysctl_perf_event_max_contexts_per_stack,
1199 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1201 .proc_handler = perf_event_max_stack_handler,
1202 .extra1 = SYSCTL_ZERO,
1203 .extra2 = &one_thousand,
1207 .procname = "panic_on_warn",
1208 .data = &panic_on_warn,
1209 .maxlen = sizeof(int),
1211 .proc_handler = proc_dointvec_minmax,
1212 .extra1 = SYSCTL_ZERO,
1213 .extra2 = SYSCTL_ONE,
1215 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1217 .procname = "timer_migration",
1218 .data = &sysctl_timer_migration,
1219 .maxlen = sizeof(unsigned int),
1221 .proc_handler = timer_migration_handler,
1222 .extra1 = SYSCTL_ZERO,
1223 .extra2 = SYSCTL_ONE,
1226 #ifdef CONFIG_BPF_SYSCALL
1228 .procname = "unprivileged_bpf_disabled",
1229 .data = &sysctl_unprivileged_bpf_disabled,
1230 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1232 /* only handle a transition from default "0" to "1" */
1233 .proc_handler = proc_dointvec_minmax,
1234 .extra1 = SYSCTL_ONE,
1235 .extra2 = SYSCTL_ONE,
1238 .procname = "bpf_stats_enabled",
1239 .data = &bpf_stats_enabled_key.key,
1240 .maxlen = sizeof(bpf_stats_enabled_key),
1242 .proc_handler = proc_do_static_key,
1245 #if defined(CONFIG_TREE_RCU)
1247 .procname = "panic_on_rcu_stall",
1248 .data = &sysctl_panic_on_rcu_stall,
1249 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1251 .proc_handler = proc_dointvec_minmax,
1252 .extra1 = SYSCTL_ZERO,
1253 .extra2 = SYSCTL_ONE,
1256 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1258 .procname = "stack_erasing",
1260 .maxlen = sizeof(int),
1262 .proc_handler = stack_erasing_sysctl,
1263 .extra1 = SYSCTL_ZERO,
1264 .extra2 = SYSCTL_ONE,
1270 static struct ctl_table vm_table[] = {
1272 .procname = "overcommit_memory",
1273 .data = &sysctl_overcommit_memory,
1274 .maxlen = sizeof(sysctl_overcommit_memory),
1276 .proc_handler = proc_dointvec_minmax,
1277 .extra1 = SYSCTL_ZERO,
1281 .procname = "panic_on_oom",
1282 .data = &sysctl_panic_on_oom,
1283 .maxlen = sizeof(sysctl_panic_on_oom),
1285 .proc_handler = proc_dointvec_minmax,
1286 .extra1 = SYSCTL_ZERO,
1290 .procname = "oom_kill_allocating_task",
1291 .data = &sysctl_oom_kill_allocating_task,
1292 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1294 .proc_handler = proc_dointvec,
1297 .procname = "oom_dump_tasks",
1298 .data = &sysctl_oom_dump_tasks,
1299 .maxlen = sizeof(sysctl_oom_dump_tasks),
1301 .proc_handler = proc_dointvec,
1304 .procname = "overcommit_ratio",
1305 .data = &sysctl_overcommit_ratio,
1306 .maxlen = sizeof(sysctl_overcommit_ratio),
1308 .proc_handler = overcommit_ratio_handler,
1311 .procname = "overcommit_kbytes",
1312 .data = &sysctl_overcommit_kbytes,
1313 .maxlen = sizeof(sysctl_overcommit_kbytes),
1315 .proc_handler = overcommit_kbytes_handler,
1318 .procname = "page-cluster",
1319 .data = &page_cluster,
1320 .maxlen = sizeof(int),
1322 .proc_handler = proc_dointvec_minmax,
1323 .extra1 = SYSCTL_ZERO,
1326 .procname = "dirty_background_ratio",
1327 .data = &dirty_background_ratio,
1328 .maxlen = sizeof(dirty_background_ratio),
1330 .proc_handler = dirty_background_ratio_handler,
1331 .extra1 = SYSCTL_ZERO,
1332 .extra2 = &one_hundred,
1335 .procname = "dirty_background_bytes",
1336 .data = &dirty_background_bytes,
1337 .maxlen = sizeof(dirty_background_bytes),
1339 .proc_handler = dirty_background_bytes_handler,
1343 .procname = "dirty_ratio",
1344 .data = &vm_dirty_ratio,
1345 .maxlen = sizeof(vm_dirty_ratio),
1347 .proc_handler = dirty_ratio_handler,
1348 .extra1 = SYSCTL_ZERO,
1349 .extra2 = &one_hundred,
1352 .procname = "dirty_bytes",
1353 .data = &vm_dirty_bytes,
1354 .maxlen = sizeof(vm_dirty_bytes),
1356 .proc_handler = dirty_bytes_handler,
1357 .extra1 = &dirty_bytes_min,
1360 .procname = "dirty_writeback_centisecs",
1361 .data = &dirty_writeback_interval,
1362 .maxlen = sizeof(dirty_writeback_interval),
1364 .proc_handler = dirty_writeback_centisecs_handler,
1367 .procname = "dirty_expire_centisecs",
1368 .data = &dirty_expire_interval,
1369 .maxlen = sizeof(dirty_expire_interval),
1371 .proc_handler = proc_dointvec_minmax,
1372 .extra1 = SYSCTL_ZERO,
1375 .procname = "dirtytime_expire_seconds",
1376 .data = &dirtytime_expire_interval,
1377 .maxlen = sizeof(dirtytime_expire_interval),
1379 .proc_handler = dirtytime_interval_handler,
1380 .extra1 = SYSCTL_ZERO,
1383 .procname = "swappiness",
1384 .data = &vm_swappiness,
1385 .maxlen = sizeof(vm_swappiness),
1387 .proc_handler = proc_dointvec_minmax,
1388 .extra1 = SYSCTL_ZERO,
1389 .extra2 = &one_hundred,
1391 #ifdef CONFIG_HUGETLB_PAGE
1393 .procname = "nr_hugepages",
1395 .maxlen = sizeof(unsigned long),
1397 .proc_handler = hugetlb_sysctl_handler,
1401 .procname = "nr_hugepages_mempolicy",
1403 .maxlen = sizeof(unsigned long),
1405 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1408 .procname = "numa_stat",
1409 .data = &sysctl_vm_numa_stat,
1410 .maxlen = sizeof(int),
1412 .proc_handler = sysctl_vm_numa_stat_handler,
1413 .extra1 = SYSCTL_ZERO,
1414 .extra2 = SYSCTL_ONE,
1418 .procname = "hugetlb_shm_group",
1419 .data = &sysctl_hugetlb_shm_group,
1420 .maxlen = sizeof(gid_t),
1422 .proc_handler = proc_dointvec,
1425 .procname = "nr_overcommit_hugepages",
1427 .maxlen = sizeof(unsigned long),
1429 .proc_handler = hugetlb_overcommit_handler,
1433 .procname = "lowmem_reserve_ratio",
1434 .data = &sysctl_lowmem_reserve_ratio,
1435 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1437 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1440 .procname = "drop_caches",
1441 .data = &sysctl_drop_caches,
1442 .maxlen = sizeof(int),
1444 .proc_handler = drop_caches_sysctl_handler,
1445 .extra1 = SYSCTL_ONE,
1448 #ifdef CONFIG_COMPACTION
1450 .procname = "compact_memory",
1451 .data = &sysctl_compact_memory,
1452 .maxlen = sizeof(int),
1454 .proc_handler = sysctl_compaction_handler,
1457 .procname = "extfrag_threshold",
1458 .data = &sysctl_extfrag_threshold,
1459 .maxlen = sizeof(int),
1461 .proc_handler = proc_dointvec_minmax,
1462 .extra1 = &min_extfrag_threshold,
1463 .extra2 = &max_extfrag_threshold,
1466 .procname = "compact_unevictable_allowed",
1467 .data = &sysctl_compact_unevictable_allowed,
1468 .maxlen = sizeof(int),
1470 .proc_handler = proc_dointvec,
1471 .extra1 = SYSCTL_ZERO,
1472 .extra2 = SYSCTL_ONE,
1475 #endif /* CONFIG_COMPACTION */
1477 .procname = "min_free_kbytes",
1478 .data = &min_free_kbytes,
1479 .maxlen = sizeof(min_free_kbytes),
1481 .proc_handler = min_free_kbytes_sysctl_handler,
1482 .extra1 = SYSCTL_ZERO,
1485 .procname = "watermark_boost_factor",
1486 .data = &watermark_boost_factor,
1487 .maxlen = sizeof(watermark_boost_factor),
1489 .proc_handler = watermark_boost_factor_sysctl_handler,
1490 .extra1 = SYSCTL_ZERO,
1493 .procname = "watermark_scale_factor",
1494 .data = &watermark_scale_factor,
1495 .maxlen = sizeof(watermark_scale_factor),
1497 .proc_handler = watermark_scale_factor_sysctl_handler,
1498 .extra1 = SYSCTL_ONE,
1499 .extra2 = &one_thousand,
1502 .procname = "percpu_pagelist_fraction",
1503 .data = &percpu_pagelist_fraction,
1504 .maxlen = sizeof(percpu_pagelist_fraction),
1506 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1507 .extra1 = SYSCTL_ZERO,
1511 .procname = "max_map_count",
1512 .data = &sysctl_max_map_count,
1513 .maxlen = sizeof(sysctl_max_map_count),
1515 .proc_handler = proc_dointvec_minmax,
1516 .extra1 = SYSCTL_ZERO,
1520 .procname = "nr_trim_pages",
1521 .data = &sysctl_nr_trim_pages,
1522 .maxlen = sizeof(sysctl_nr_trim_pages),
1524 .proc_handler = proc_dointvec_minmax,
1525 .extra1 = SYSCTL_ZERO,
1529 .procname = "laptop_mode",
1530 .data = &laptop_mode,
1531 .maxlen = sizeof(laptop_mode),
1533 .proc_handler = proc_dointvec_jiffies,
1536 .procname = "block_dump",
1537 .data = &block_dump,
1538 .maxlen = sizeof(block_dump),
1540 .proc_handler = proc_dointvec,
1541 .extra1 = SYSCTL_ZERO,
1544 .procname = "vfs_cache_pressure",
1545 .data = &sysctl_vfs_cache_pressure,
1546 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1548 .proc_handler = proc_dointvec,
1549 .extra1 = SYSCTL_ZERO,
1551 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
1552 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
1554 .procname = "legacy_va_layout",
1555 .data = &sysctl_legacy_va_layout,
1556 .maxlen = sizeof(sysctl_legacy_va_layout),
1558 .proc_handler = proc_dointvec,
1559 .extra1 = SYSCTL_ZERO,
1564 .procname = "zone_reclaim_mode",
1565 .data = &node_reclaim_mode,
1566 .maxlen = sizeof(node_reclaim_mode),
1568 .proc_handler = proc_dointvec,
1569 .extra1 = SYSCTL_ZERO,
1572 .procname = "min_unmapped_ratio",
1573 .data = &sysctl_min_unmapped_ratio,
1574 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1576 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1577 .extra1 = SYSCTL_ZERO,
1578 .extra2 = &one_hundred,
1581 .procname = "min_slab_ratio",
1582 .data = &sysctl_min_slab_ratio,
1583 .maxlen = sizeof(sysctl_min_slab_ratio),
1585 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1586 .extra1 = SYSCTL_ZERO,
1587 .extra2 = &one_hundred,
1592 .procname = "stat_interval",
1593 .data = &sysctl_stat_interval,
1594 .maxlen = sizeof(sysctl_stat_interval),
1596 .proc_handler = proc_dointvec_jiffies,
1599 .procname = "stat_refresh",
1603 .proc_handler = vmstat_refresh,
1608 .procname = "mmap_min_addr",
1609 .data = &dac_mmap_min_addr,
1610 .maxlen = sizeof(unsigned long),
1612 .proc_handler = mmap_min_addr_handler,
1617 .procname = "numa_zonelist_order",
1618 .data = &numa_zonelist_order,
1619 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1621 .proc_handler = numa_zonelist_order_handler,
1624 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1625 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1627 .procname = "vdso_enabled",
1628 #ifdef CONFIG_X86_32
1629 .data = &vdso32_enabled,
1630 .maxlen = sizeof(vdso32_enabled),
1632 .data = &vdso_enabled,
1633 .maxlen = sizeof(vdso_enabled),
1636 .proc_handler = proc_dointvec,
1637 .extra1 = SYSCTL_ZERO,
1640 #ifdef CONFIG_HIGHMEM
1642 .procname = "highmem_is_dirtyable",
1643 .data = &vm_highmem_is_dirtyable,
1644 .maxlen = sizeof(vm_highmem_is_dirtyable),
1646 .proc_handler = proc_dointvec_minmax,
1647 .extra1 = SYSCTL_ZERO,
1648 .extra2 = SYSCTL_ONE,
1651 #ifdef CONFIG_MEMORY_FAILURE
1653 .procname = "memory_failure_early_kill",
1654 .data = &sysctl_memory_failure_early_kill,
1655 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1657 .proc_handler = proc_dointvec_minmax,
1658 .extra1 = SYSCTL_ZERO,
1659 .extra2 = SYSCTL_ONE,
1662 .procname = "memory_failure_recovery",
1663 .data = &sysctl_memory_failure_recovery,
1664 .maxlen = sizeof(sysctl_memory_failure_recovery),
1666 .proc_handler = proc_dointvec_minmax,
1667 .extra1 = SYSCTL_ZERO,
1668 .extra2 = SYSCTL_ONE,
1672 .procname = "user_reserve_kbytes",
1673 .data = &sysctl_user_reserve_kbytes,
1674 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1676 .proc_handler = proc_doulongvec_minmax,
1679 .procname = "admin_reserve_kbytes",
1680 .data = &sysctl_admin_reserve_kbytes,
1681 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1683 .proc_handler = proc_doulongvec_minmax,
1685 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1687 .procname = "mmap_rnd_bits",
1688 .data = &mmap_rnd_bits,
1689 .maxlen = sizeof(mmap_rnd_bits),
1691 .proc_handler = proc_dointvec_minmax,
1692 .extra1 = (void *)&mmap_rnd_bits_min,
1693 .extra2 = (void *)&mmap_rnd_bits_max,
1696 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1698 .procname = "mmap_rnd_compat_bits",
1699 .data = &mmap_rnd_compat_bits,
1700 .maxlen = sizeof(mmap_rnd_compat_bits),
1702 .proc_handler = proc_dointvec_minmax,
1703 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1704 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1707 #ifdef CONFIG_USERFAULTFD
1709 .procname = "unprivileged_userfaultfd",
1710 .data = &sysctl_unprivileged_userfaultfd,
1711 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
1713 .proc_handler = proc_dointvec_minmax,
1714 .extra1 = SYSCTL_ZERO,
1715 .extra2 = SYSCTL_ONE,
1721 static struct ctl_table fs_table[] = {
1723 .procname = "inode-nr",
1724 .data = &inodes_stat,
1725 .maxlen = 2*sizeof(long),
1727 .proc_handler = proc_nr_inodes,
1730 .procname = "inode-state",
1731 .data = &inodes_stat,
1732 .maxlen = 7*sizeof(long),
1734 .proc_handler = proc_nr_inodes,
1737 .procname = "file-nr",
1738 .data = &files_stat,
1739 .maxlen = sizeof(files_stat),
1741 .proc_handler = proc_nr_files,
1744 .procname = "file-max",
1745 .data = &files_stat.max_files,
1746 .maxlen = sizeof(files_stat.max_files),
1748 .proc_handler = proc_doulongvec_minmax,
1750 .extra2 = &long_max,
1753 .procname = "nr_open",
1754 .data = &sysctl_nr_open,
1755 .maxlen = sizeof(unsigned int),
1757 .proc_handler = proc_dointvec_minmax,
1758 .extra1 = &sysctl_nr_open_min,
1759 .extra2 = &sysctl_nr_open_max,
1762 .procname = "dentry-state",
1763 .data = &dentry_stat,
1764 .maxlen = 6*sizeof(long),
1766 .proc_handler = proc_nr_dentry,
1769 .procname = "overflowuid",
1770 .data = &fs_overflowuid,
1771 .maxlen = sizeof(int),
1773 .proc_handler = proc_dointvec_minmax,
1774 .extra1 = &minolduid,
1775 .extra2 = &maxolduid,
1778 .procname = "overflowgid",
1779 .data = &fs_overflowgid,
1780 .maxlen = sizeof(int),
1782 .proc_handler = proc_dointvec_minmax,
1783 .extra1 = &minolduid,
1784 .extra2 = &maxolduid,
1786 #ifdef CONFIG_FILE_LOCKING
1788 .procname = "leases-enable",
1789 .data = &leases_enable,
1790 .maxlen = sizeof(int),
1792 .proc_handler = proc_dointvec,
1795 #ifdef CONFIG_DNOTIFY
1797 .procname = "dir-notify-enable",
1798 .data = &dir_notify_enable,
1799 .maxlen = sizeof(int),
1801 .proc_handler = proc_dointvec,
1805 #ifdef CONFIG_FILE_LOCKING
1807 .procname = "lease-break-time",
1808 .data = &lease_break_time,
1809 .maxlen = sizeof(int),
1811 .proc_handler = proc_dointvec,
1816 .procname = "aio-nr",
1818 .maxlen = sizeof(aio_nr),
1820 .proc_handler = proc_doulongvec_minmax,
1823 .procname = "aio-max-nr",
1824 .data = &aio_max_nr,
1825 .maxlen = sizeof(aio_max_nr),
1827 .proc_handler = proc_doulongvec_minmax,
1829 #endif /* CONFIG_AIO */
1830 #ifdef CONFIG_INOTIFY_USER
1832 .procname = "inotify",
1834 .child = inotify_table,
1839 .procname = "epoll",
1841 .child = epoll_table,
1846 .procname = "protected_symlinks",
1847 .data = &sysctl_protected_symlinks,
1848 .maxlen = sizeof(int),
1850 .proc_handler = proc_dointvec_minmax,
1851 .extra1 = SYSCTL_ZERO,
1852 .extra2 = SYSCTL_ONE,
1855 .procname = "protected_hardlinks",
1856 .data = &sysctl_protected_hardlinks,
1857 .maxlen = sizeof(int),
1859 .proc_handler = proc_dointvec_minmax,
1860 .extra1 = SYSCTL_ZERO,
1861 .extra2 = SYSCTL_ONE,
1864 .procname = "protected_fifos",
1865 .data = &sysctl_protected_fifos,
1866 .maxlen = sizeof(int),
1868 .proc_handler = proc_dointvec_minmax,
1869 .extra1 = SYSCTL_ZERO,
1873 .procname = "protected_regular",
1874 .data = &sysctl_protected_regular,
1875 .maxlen = sizeof(int),
1877 .proc_handler = proc_dointvec_minmax,
1878 .extra1 = SYSCTL_ZERO,
1882 .procname = "suid_dumpable",
1883 .data = &suid_dumpable,
1884 .maxlen = sizeof(int),
1886 .proc_handler = proc_dointvec_minmax_coredump,
1887 .extra1 = SYSCTL_ZERO,
1890 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1892 .procname = "binfmt_misc",
1894 .child = sysctl_mount_point,
1898 .procname = "pipe-max-size",
1899 .data = &pipe_max_size,
1900 .maxlen = sizeof(pipe_max_size),
1902 .proc_handler = proc_dopipe_max_size,
1905 .procname = "pipe-user-pages-hard",
1906 .data = &pipe_user_pages_hard,
1907 .maxlen = sizeof(pipe_user_pages_hard),
1909 .proc_handler = proc_doulongvec_minmax,
1912 .procname = "pipe-user-pages-soft",
1913 .data = &pipe_user_pages_soft,
1914 .maxlen = sizeof(pipe_user_pages_soft),
1916 .proc_handler = proc_doulongvec_minmax,
1919 .procname = "mount-max",
1920 .data = &sysctl_mount_max,
1921 .maxlen = sizeof(unsigned int),
1923 .proc_handler = proc_dointvec_minmax,
1924 .extra1 = SYSCTL_ONE,
1929 static struct ctl_table debug_table[] = {
1930 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1932 .procname = "exception-trace",
1933 .data = &show_unhandled_signals,
1934 .maxlen = sizeof(int),
1936 .proc_handler = proc_dointvec
1939 #if defined(CONFIG_OPTPROBES)
1941 .procname = "kprobes-optimization",
1942 .data = &sysctl_kprobes_optimization,
1943 .maxlen = sizeof(int),
1945 .proc_handler = proc_kprobes_optimization_handler,
1946 .extra1 = SYSCTL_ZERO,
1947 .extra2 = SYSCTL_ONE,
1953 static struct ctl_table dev_table[] = {
1957 int __init sysctl_init(void)
1959 struct ctl_table_header *hdr;
1961 hdr = register_sysctl_table(sysctl_base_table);
1962 kmemleak_not_leak(hdr);
1966 #endif /* CONFIG_SYSCTL */
1972 #ifdef CONFIG_PROC_SYSCTL
1974 static int _proc_do_string(char *data, int maxlen, int write,
1975 char __user *buffer,
1976 size_t *lenp, loff_t *ppos)
1982 if (!data || !maxlen || !*lenp) {
1988 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1989 /* Only continue writes not past the end of buffer. */
1991 if (len > maxlen - 1)
1998 /* Start writing from beginning of buffer. */
2004 while ((p - buffer) < *lenp && len < maxlen - 1) {
2005 if (get_user(c, p++))
2007 if (c == 0 || c == '\n')
2028 if (copy_to_user(buffer, data, len))
2031 if (put_user('\n', buffer + len))
2041 static void warn_sysctl_write(struct ctl_table *table)
2043 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2044 "This will not be supported in the future. To silence this\n"
2045 "warning, set kernel.sysctl_writes_strict = -1\n",
2046 current->comm, table->procname);
2050 * proc_first_pos_non_zero_ignore - check if first position is allowed
2051 * @ppos: file position
2052 * @table: the sysctl table
2054 * Returns true if the first position is non-zero and the sysctl_writes_strict
2055 * mode indicates this is not allowed for numeric input types. String proc
2056 * handlers can ignore the return value.
2058 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2059 struct ctl_table *table)
2064 switch (sysctl_writes_strict) {
2065 case SYSCTL_WRITES_STRICT:
2067 case SYSCTL_WRITES_WARN:
2068 warn_sysctl_write(table);
2076 * proc_dostring - read a string sysctl
2077 * @table: the sysctl table
2078 * @write: %TRUE if this is a write to the sysctl file
2079 * @buffer: the user buffer
2080 * @lenp: the size of the user buffer
2081 * @ppos: file position
2083 * Reads/writes a string from/to the user buffer. If the kernel
2084 * buffer provided is not large enough to hold the string, the
2085 * string is truncated. The copied string is %NULL-terminated.
2086 * If the string is being read by the user process, it is copied
2087 * and a newline '\n' is added. It is truncated if the buffer is
2090 * Returns 0 on success.
2092 int proc_dostring(struct ctl_table *table, int write,
2093 void __user *buffer, size_t *lenp, loff_t *ppos)
2096 proc_first_pos_non_zero_ignore(ppos, table);
2098 return _proc_do_string((char *)(table->data), table->maxlen, write,
2099 (char __user *)buffer, lenp, ppos);
2102 static size_t proc_skip_spaces(char **buf)
2105 char *tmp = skip_spaces(*buf);
2111 static void proc_skip_char(char **buf, size_t *size, const char v)
2122 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2125 * @cp: kernel buffer containing the string to parse
2126 * @endp: pointer to store the trailing characters
2127 * @base: the base to use
2128 * @res: where the parsed integer will be stored
2130 * In case of success 0 is returned and @res will contain the parsed integer,
2131 * @endp will hold any trailing characters.
2132 * This function will fail the parse on overflow. If there wasn't an overflow
2133 * the function will defer the decision what characters count as invalid to the
2136 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2139 unsigned long long result;
2142 cp = _parse_integer_fixup_radix(cp, &base);
2143 rv = _parse_integer(cp, base, &result);
2144 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2152 *res = (unsigned long)result;
2156 #define TMPBUFLEN 22
2158 * proc_get_long - reads an ASCII formatted integer from a user buffer
2160 * @buf: a kernel buffer
2161 * @size: size of the kernel buffer
2162 * @val: this is where the number will be stored
2163 * @neg: set to %TRUE if number is negative
2164 * @perm_tr: a vector which contains the allowed trailers
2165 * @perm_tr_len: size of the perm_tr vector
2166 * @tr: pointer to store the trailer character
2168 * In case of success %0 is returned and @buf and @size are updated with
2169 * the amount of bytes read. If @tr is non-NULL and a trailing
2170 * character exists (size is non-zero after returning from this
2171 * function), @tr is updated with the trailing character.
2173 static int proc_get_long(char **buf, size_t *size,
2174 unsigned long *val, bool *neg,
2175 const char *perm_tr, unsigned perm_tr_len, char *tr)
2178 char *p, tmp[TMPBUFLEN];
2184 if (len > TMPBUFLEN - 1)
2185 len = TMPBUFLEN - 1;
2187 memcpy(tmp, *buf, len);
2191 if (*p == '-' && *size > 1) {
2199 if (strtoul_lenient(p, &p, 0, val))
2204 /* We don't know if the next char is whitespace thus we may accept
2205 * invalid integers (e.g. 1234...a) or two integers instead of one
2206 * (e.g. 123...1). So lets not allow such large numbers. */
2207 if (len == TMPBUFLEN - 1)
2210 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2213 if (tr && (len < *size))
2223 * proc_put_long - converts an integer to a decimal ASCII formatted string
2225 * @buf: the user buffer
2226 * @size: the size of the user buffer
2227 * @val: the integer to be converted
2228 * @neg: sign of the number, %TRUE for negative
2230 * In case of success %0 is returned and @buf and @size are updated with
2231 * the amount of bytes written.
2233 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2237 char tmp[TMPBUFLEN], *p = tmp;
2239 sprintf(p, "%s%lu", neg ? "-" : "", val);
2243 if (copy_to_user(*buf, tmp, len))
2251 static int proc_put_char(void __user **buf, size_t *size, char c)
2254 char __user **buffer = (char __user **)buf;
2255 if (put_user(c, *buffer))
2257 (*size)--, (*buffer)++;
2263 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2265 int write, void *data)
2269 if (*lvalp > (unsigned long) INT_MAX + 1)
2273 if (*lvalp > (unsigned long) INT_MAX)
2281 *lvalp = -(unsigned long)val;
2284 *lvalp = (unsigned long)val;
2290 static int do_proc_douintvec_conv(unsigned long *lvalp,
2292 int write, void *data)
2295 if (*lvalp > UINT_MAX)
2299 unsigned int val = *valp;
2300 *lvalp = (unsigned long)val;
2305 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2307 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2308 int write, void __user *buffer,
2309 size_t *lenp, loff_t *ppos,
2310 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2311 int write, void *data),
2314 int *i, vleft, first = 1, err = 0;
2316 char *kbuf = NULL, *p;
2318 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2323 i = (int *) tbl_data;
2324 vleft = table->maxlen / sizeof(*i);
2328 conv = do_proc_dointvec_conv;
2331 if (proc_first_pos_non_zero_ignore(ppos, table))
2334 if (left > PAGE_SIZE - 1)
2335 left = PAGE_SIZE - 1;
2336 p = kbuf = memdup_user_nul(buffer, left);
2338 return PTR_ERR(kbuf);
2341 for (; left && vleft--; i++, first=0) {
2346 left -= proc_skip_spaces(&p);
2350 err = proc_get_long(&p, &left, &lval, &neg,
2352 sizeof(proc_wspace_sep), NULL);
2355 if (conv(&neg, &lval, i, 1, data)) {
2360 if (conv(&neg, &lval, i, 0, data)) {
2365 err = proc_put_char(&buffer, &left, '\t');
2368 err = proc_put_long(&buffer, &left, lval, neg);
2374 if (!write && !first && left && !err)
2375 err = proc_put_char(&buffer, &left, '\n');
2376 if (write && !err && left)
2377 left -= proc_skip_spaces(&p);
2381 return err ? : -EINVAL;
2389 static int do_proc_dointvec(struct ctl_table *table, int write,
2390 void __user *buffer, size_t *lenp, loff_t *ppos,
2391 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2392 int write, void *data),
2395 return __do_proc_dointvec(table->data, table, write,
2396 buffer, lenp, ppos, conv, data);
2399 static int do_proc_douintvec_w(unsigned int *tbl_data,
2400 struct ctl_table *table,
2401 void __user *buffer,
2402 size_t *lenp, loff_t *ppos,
2403 int (*conv)(unsigned long *lvalp,
2405 int write, void *data),
2412 char *kbuf = NULL, *p;
2416 if (proc_first_pos_non_zero_ignore(ppos, table))
2419 if (left > PAGE_SIZE - 1)
2420 left = PAGE_SIZE - 1;
2422 p = kbuf = memdup_user_nul(buffer, left);
2426 left -= proc_skip_spaces(&p);
2432 err = proc_get_long(&p, &left, &lval, &neg,
2434 sizeof(proc_wspace_sep), NULL);
2440 if (conv(&lval, tbl_data, 1, data)) {
2446 left -= proc_skip_spaces(&p);
2455 /* This is in keeping with old __do_proc_dointvec() */
2461 static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2462 size_t *lenp, loff_t *ppos,
2463 int (*conv)(unsigned long *lvalp,
2465 int write, void *data),
2474 if (conv(&lval, tbl_data, 0, data)) {
2479 err = proc_put_long(&buffer, &left, lval, false);
2483 err = proc_put_char(&buffer, &left, '\n');
2492 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2493 int write, void __user *buffer,
2494 size_t *lenp, loff_t *ppos,
2495 int (*conv)(unsigned long *lvalp,
2497 int write, void *data),
2500 unsigned int *i, vleft;
2502 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2507 i = (unsigned int *) tbl_data;
2508 vleft = table->maxlen / sizeof(*i);
2511 * Arrays are not supported, keep this simple. *Do not* add
2520 conv = do_proc_douintvec_conv;
2523 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2525 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2528 static int do_proc_douintvec(struct ctl_table *table, int write,
2529 void __user *buffer, size_t *lenp, loff_t *ppos,
2530 int (*conv)(unsigned long *lvalp,
2532 int write, void *data),
2535 return __do_proc_douintvec(table->data, table, write,
2536 buffer, lenp, ppos, conv, data);
2540 * proc_dointvec - read a vector of integers
2541 * @table: the sysctl table
2542 * @write: %TRUE if this is a write to the sysctl file
2543 * @buffer: the user buffer
2544 * @lenp: the size of the user buffer
2545 * @ppos: file position
2547 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2548 * values from/to the user buffer, treated as an ASCII string.
2550 * Returns 0 on success.
2552 int proc_dointvec(struct ctl_table *table, int write,
2553 void __user *buffer, size_t *lenp, loff_t *ppos)
2555 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2559 * proc_douintvec - read a vector of unsigned integers
2560 * @table: the sysctl table
2561 * @write: %TRUE if this is a write to the sysctl file
2562 * @buffer: the user buffer
2563 * @lenp: the size of the user buffer
2564 * @ppos: file position
2566 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2567 * values from/to the user buffer, treated as an ASCII string.
2569 * Returns 0 on success.
2571 int proc_douintvec(struct ctl_table *table, int write,
2572 void __user *buffer, size_t *lenp, loff_t *ppos)
2574 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2575 do_proc_douintvec_conv, NULL);
2579 * Taint values can only be increased
2580 * This means we can safely use a temporary.
2582 static int proc_taint(struct ctl_table *table, int write,
2583 void __user *buffer, size_t *lenp, loff_t *ppos)
2586 unsigned long tmptaint = get_taint();
2589 if (write && !capable(CAP_SYS_ADMIN))
2594 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2600 * Poor man's atomic or. Not worth adding a primitive
2601 * to everyone's atomic.h for this
2604 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2605 if ((tmptaint >> i) & 1)
2606 add_taint(i, LOCKDEP_STILL_OK);
2613 #ifdef CONFIG_PRINTK
2614 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2615 void __user *buffer, size_t *lenp, loff_t *ppos)
2617 if (write && !capable(CAP_SYS_ADMIN))
2620 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2625 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2626 * @min: pointer to minimum allowable value
2627 * @max: pointer to maximum allowable value
2629 * The do_proc_dointvec_minmax_conv_param structure provides the
2630 * minimum and maximum values for doing range checking for those sysctl
2631 * parameters that use the proc_dointvec_minmax() handler.
2633 struct do_proc_dointvec_minmax_conv_param {
2638 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2640 int write, void *data)
2643 struct do_proc_dointvec_minmax_conv_param *param = data;
2645 * If writing, first do so via a temporary local int so we can
2646 * bounds-check it before touching *valp.
2648 int *ip = write ? &tmp : valp;
2650 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
2655 if ((param->min && *param->min > tmp) ||
2656 (param->max && *param->max < tmp))
2665 * proc_dointvec_minmax - read a vector of integers with min/max values
2666 * @table: the sysctl table
2667 * @write: %TRUE if this is a write to the sysctl file
2668 * @buffer: the user buffer
2669 * @lenp: the size of the user buffer
2670 * @ppos: file position
2672 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2673 * values from/to the user buffer, treated as an ASCII string.
2675 * This routine will ensure the values are within the range specified by
2676 * table->extra1 (min) and table->extra2 (max).
2678 * Returns 0 on success or -EINVAL on write when the range check fails.
2680 int proc_dointvec_minmax(struct ctl_table *table, int write,
2681 void __user *buffer, size_t *lenp, loff_t *ppos)
2683 struct do_proc_dointvec_minmax_conv_param param = {
2684 .min = (int *) table->extra1,
2685 .max = (int *) table->extra2,
2687 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2688 do_proc_dointvec_minmax_conv, ¶m);
2692 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2693 * @min: pointer to minimum allowable value
2694 * @max: pointer to maximum allowable value
2696 * The do_proc_douintvec_minmax_conv_param structure provides the
2697 * minimum and maximum values for doing range checking for those sysctl
2698 * parameters that use the proc_douintvec_minmax() handler.
2700 struct do_proc_douintvec_minmax_conv_param {
2705 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2707 int write, void *data)
2711 struct do_proc_douintvec_minmax_conv_param *param = data;
2712 /* write via temporary local uint for bounds-checking */
2713 unsigned int *up = write ? &tmp : valp;
2715 ret = do_proc_douintvec_conv(lvalp, up, write, data);
2720 if ((param->min && *param->min > tmp) ||
2721 (param->max && *param->max < tmp))
2731 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2732 * @table: the sysctl table
2733 * @write: %TRUE if this is a write to the sysctl file
2734 * @buffer: the user buffer
2735 * @lenp: the size of the user buffer
2736 * @ppos: file position
2738 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2739 * values from/to the user buffer, treated as an ASCII string. Negative
2740 * strings are not allowed.
2742 * This routine will ensure the values are within the range specified by
2743 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2744 * check for UINT_MAX to avoid having to support wrap around uses from
2747 * Returns 0 on success or -ERANGE on write when the range check fails.
2749 int proc_douintvec_minmax(struct ctl_table *table, int write,
2750 void __user *buffer, size_t *lenp, loff_t *ppos)
2752 struct do_proc_douintvec_minmax_conv_param param = {
2753 .min = (unsigned int *) table->extra1,
2754 .max = (unsigned int *) table->extra2,
2756 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2757 do_proc_douintvec_minmax_conv, ¶m);
2760 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2762 int write, void *data)
2767 val = round_pipe_size(*lvalp);
2773 unsigned int val = *valp;
2774 *lvalp = (unsigned long) val;
2780 static int proc_dopipe_max_size(struct ctl_table *table, int write,
2781 void __user *buffer, size_t *lenp, loff_t *ppos)
2783 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2784 do_proc_dopipe_max_size_conv, NULL);
2787 static void validate_coredump_safety(void)
2789 #ifdef CONFIG_COREDUMP
2790 if (suid_dumpable == SUID_DUMP_ROOT &&
2791 core_pattern[0] != '/' && core_pattern[0] != '|') {
2793 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2794 "Pipe handler or fully qualified core dump path required.\n"
2795 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2801 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2802 void __user *buffer, size_t *lenp, loff_t *ppos)
2804 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2806 validate_coredump_safety();
2810 #ifdef CONFIG_COREDUMP
2811 static int proc_dostring_coredump(struct ctl_table *table, int write,
2812 void __user *buffer, size_t *lenp, loff_t *ppos)
2814 int error = proc_dostring(table, write, buffer, lenp, ppos);
2816 validate_coredump_safety();
2821 #ifdef CONFIG_MAGIC_SYSRQ
2822 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
2823 void __user *buffer, size_t *lenp, loff_t *ppos)
2829 ret = __do_proc_dointvec(&tmp, table, write, buffer,
2830 lenp, ppos, NULL, NULL);
2835 sysrq_toggle_support(tmp);
2841 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2842 void __user *buffer,
2843 size_t *lenp, loff_t *ppos,
2844 unsigned long convmul,
2845 unsigned long convdiv)
2847 unsigned long *i, *min, *max;
2848 int vleft, first = 1, err = 0;
2850 char *kbuf = NULL, *p;
2852 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2857 i = (unsigned long *) data;
2858 min = (unsigned long *) table->extra1;
2859 max = (unsigned long *) table->extra2;
2860 vleft = table->maxlen / sizeof(unsigned long);
2864 if (proc_first_pos_non_zero_ignore(ppos, table))
2867 if (left > PAGE_SIZE - 1)
2868 left = PAGE_SIZE - 1;
2869 p = kbuf = memdup_user_nul(buffer, left);
2871 return PTR_ERR(kbuf);
2874 for (; left && vleft--; i++, first = 0) {
2880 left -= proc_skip_spaces(&p);
2884 err = proc_get_long(&p, &left, &val, &neg,
2886 sizeof(proc_wspace_sep), NULL);
2891 val = convmul * val / convdiv;
2892 if ((min && val < *min) || (max && val > *max)) {
2898 val = convdiv * (*i) / convmul;
2900 err = proc_put_char(&buffer, &left, '\t');
2904 err = proc_put_long(&buffer, &left, val, false);
2910 if (!write && !first && left && !err)
2911 err = proc_put_char(&buffer, &left, '\n');
2913 left -= proc_skip_spaces(&p);
2917 return err ? : -EINVAL;
2925 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2926 void __user *buffer,
2927 size_t *lenp, loff_t *ppos,
2928 unsigned long convmul,
2929 unsigned long convdiv)
2931 return __do_proc_doulongvec_minmax(table->data, table, write,
2932 buffer, lenp, ppos, convmul, convdiv);
2936 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2937 * @table: the sysctl table
2938 * @write: %TRUE if this is a write to the sysctl file
2939 * @buffer: the user buffer
2940 * @lenp: the size of the user buffer
2941 * @ppos: file position
2943 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2944 * values from/to the user buffer, treated as an ASCII string.
2946 * This routine will ensure the values are within the range specified by
2947 * table->extra1 (min) and table->extra2 (max).
2949 * Returns 0 on success.
2951 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2952 void __user *buffer, size_t *lenp, loff_t *ppos)
2954 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2958 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2959 * @table: the sysctl table
2960 * @write: %TRUE if this is a write to the sysctl file
2961 * @buffer: the user buffer
2962 * @lenp: the size of the user buffer
2963 * @ppos: file position
2965 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2966 * values from/to the user buffer, treated as an ASCII string. The values
2967 * are treated as milliseconds, and converted to jiffies when they are stored.
2969 * This routine will ensure the values are within the range specified by
2970 * table->extra1 (min) and table->extra2 (max).
2972 * Returns 0 on success.
2974 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2975 void __user *buffer,
2976 size_t *lenp, loff_t *ppos)
2978 return do_proc_doulongvec_minmax(table, write, buffer,
2979 lenp, ppos, HZ, 1000l);
2983 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2985 int write, void *data)
2988 if (*lvalp > INT_MAX / HZ)
2990 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2996 lval = -(unsigned long)val;
2999 lval = (unsigned long)val;
3006 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
3008 int write, void *data)
3011 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
3013 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
3019 lval = -(unsigned long)val;
3022 lval = (unsigned long)val;
3024 *lvalp = jiffies_to_clock_t(lval);
3029 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
3031 int write, void *data)
3034 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3044 lval = -(unsigned long)val;
3047 lval = (unsigned long)val;
3049 *lvalp = jiffies_to_msecs(lval);
3055 * proc_dointvec_jiffies - read a vector of integers as seconds
3056 * @table: the sysctl table
3057 * @write: %TRUE if this is a write to the sysctl file
3058 * @buffer: the user buffer
3059 * @lenp: the size of the user buffer
3060 * @ppos: file position
3062 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3063 * values from/to the user buffer, treated as an ASCII string.
3064 * The values read are assumed to be in seconds, and are converted into
3067 * Returns 0 on success.
3069 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3070 void __user *buffer, size_t *lenp, loff_t *ppos)
3072 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3073 do_proc_dointvec_jiffies_conv,NULL);
3077 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3078 * @table: the sysctl table
3079 * @write: %TRUE if this is a write to the sysctl file
3080 * @buffer: the user buffer
3081 * @lenp: the size of the user buffer
3082 * @ppos: pointer to the file position
3084 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3085 * values from/to the user buffer, treated as an ASCII string.
3086 * The values read are assumed to be in 1/USER_HZ seconds, and
3087 * are converted into jiffies.
3089 * Returns 0 on success.
3091 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3092 void __user *buffer, size_t *lenp, loff_t *ppos)
3094 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3095 do_proc_dointvec_userhz_jiffies_conv,NULL);
3099 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3100 * @table: the sysctl table
3101 * @write: %TRUE if this is a write to the sysctl file
3102 * @buffer: the user buffer
3103 * @lenp: the size of the user buffer
3104 * @ppos: file position
3105 * @ppos: the current position in the file
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 1/1000 seconds, and
3110 * are converted into jiffies.
3112 * Returns 0 on success.
3114 int proc_dointvec_ms_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_ms_jiffies_conv, NULL);
3121 static int proc_do_cad_pid(struct ctl_table *table, int write,
3122 void __user *buffer, size_t *lenp, loff_t *ppos)
3124 struct pid *new_pid;
3128 tmp = pid_vnr(cad_pid);
3130 r = __do_proc_dointvec(&tmp, table, write, buffer,
3131 lenp, ppos, NULL, NULL);
3135 new_pid = find_get_pid(tmp);
3139 put_pid(xchg(&cad_pid, new_pid));
3144 * proc_do_large_bitmap - read/write from/to a large bitmap
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
3151 * The bitmap is stored at table->data and the bitmap length (in bits)
3154 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3155 * large bitmaps may be represented in a compact manner. Writing into
3156 * the file will clear the bitmap then update it with the given input.
3158 * Returns 0 on success.
3160 int proc_do_large_bitmap(struct ctl_table *table, int write,
3161 void __user *buffer, size_t *lenp, loff_t *ppos)
3165 size_t left = *lenp;
3166 unsigned long bitmap_len = table->maxlen;
3167 unsigned long *bitmap = *(unsigned long **) table->data;
3168 unsigned long *tmp_bitmap = NULL;
3169 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3171 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
3180 if (left > PAGE_SIZE - 1) {
3181 left = PAGE_SIZE - 1;
3182 /* How much of the buffer we'll skip this pass */
3183 skipped = *lenp - left;
3186 p = kbuf = memdup_user_nul(buffer, left);
3188 return PTR_ERR(kbuf);
3190 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
3195 proc_skip_char(&p, &left, '\n');
3196 while (!err && left) {
3197 unsigned long val_a, val_b;
3201 /* In case we stop parsing mid-number, we can reset */
3203 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
3206 * If we consumed the entirety of a truncated buffer or
3207 * only one char is left (may be a "-"), then stop here,
3208 * reset, & come back for more.
3210 if ((left <= 1) && skipped) {
3217 if (val_a >= bitmap_len || neg) {
3229 err = proc_get_long(&p, &left, &val_b,
3230 &neg, tr_b, sizeof(tr_b),
3233 * If we consumed all of a truncated buffer or
3234 * then stop here, reset, & come back for more.
3236 if (!left && skipped) {
3243 if (val_b >= bitmap_len || neg ||
3254 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
3256 proc_skip_char(&p, &left, '\n');
3261 unsigned long bit_a, bit_b = 0;
3264 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3265 if (bit_a >= bitmap_len)
3267 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3271 err = proc_put_char(&buffer, &left, ',');
3275 err = proc_put_long(&buffer, &left, bit_a, false);
3278 if (bit_a != bit_b) {
3279 err = proc_put_char(&buffer, &left, '-');
3282 err = proc_put_long(&buffer, &left, bit_b, false);
3290 err = proc_put_char(&buffer, &left, '\n');
3296 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3298 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
3304 bitmap_free(tmp_bitmap);
3308 #else /* CONFIG_PROC_SYSCTL */
3310 int proc_dostring(struct ctl_table *table, int write,
3311 void __user *buffer, size_t *lenp, loff_t *ppos)
3316 int proc_dointvec(struct ctl_table *table, int write,
3317 void __user *buffer, size_t *lenp, loff_t *ppos)
3322 int proc_douintvec(struct ctl_table *table, int write,
3323 void __user *buffer, size_t *lenp, loff_t *ppos)
3328 int proc_dointvec_minmax(struct ctl_table *table, int write,
3329 void __user *buffer, size_t *lenp, loff_t *ppos)
3334 int proc_douintvec_minmax(struct ctl_table *table, int write,
3335 void __user *buffer, size_t *lenp, loff_t *ppos)
3340 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3341 void __user *buffer, size_t *lenp, loff_t *ppos)
3346 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3347 void __user *buffer, size_t *lenp, loff_t *ppos)
3352 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3353 void __user *buffer, size_t *lenp, loff_t *ppos)
3358 int proc_doulongvec_minmax(struct ctl_table *table, int write,
3359 void __user *buffer, size_t *lenp, loff_t *ppos)
3364 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3365 void __user *buffer,
3366 size_t *lenp, loff_t *ppos)
3371 int proc_do_large_bitmap(struct ctl_table *table, int write,
3372 void __user *buffer, size_t *lenp, loff_t *ppos)
3377 #endif /* CONFIG_PROC_SYSCTL */
3379 #if defined(CONFIG_SYSCTL)
3380 int proc_do_static_key(struct ctl_table *table, int write,
3381 void __user *buffer, size_t *lenp,
3384 struct static_key *key = (struct static_key *)table->data;
3385 static DEFINE_MUTEX(static_key_mutex);
3387 struct ctl_table tmp = {
3389 .maxlen = sizeof(val),
3390 .mode = table->mode,
3391 .extra1 = SYSCTL_ZERO,
3392 .extra2 = SYSCTL_ONE,
3395 if (write && !capable(CAP_SYS_ADMIN))
3398 mutex_lock(&static_key_mutex);
3399 val = static_key_enabled(key);
3400 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3401 if (write && !ret) {
3403 static_key_enable(key);
3405 static_key_disable(key);
3407 mutex_unlock(&static_key_mutex);
3412 * No sense putting this after each symbol definition, twice,
3413 * exception granted :-)
3415 EXPORT_SYMBOL(proc_dointvec);
3416 EXPORT_SYMBOL(proc_douintvec);
3417 EXPORT_SYMBOL(proc_dointvec_jiffies);
3418 EXPORT_SYMBOL(proc_dointvec_minmax);
3419 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3420 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3421 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3422 EXPORT_SYMBOL(proc_dostring);
3423 EXPORT_SYMBOL(proc_doulongvec_minmax);
3424 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3425 EXPORT_SYMBOL(proc_do_large_bitmap);