2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
22 #include <linux/aio.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/bitmap.h>
28 #include <linux/signal.h>
29 #include <linux/printk.h>
30 #include <linux/proc_fs.h>
31 #include <linux/security.h>
32 #include <linux/ctype.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
65 #include <linux/sched/coredump.h>
66 #include <linux/kexec.h>
67 #include <linux/bpf.h>
68 #include <linux/mount.h>
69 #include <linux/userfaultfd_k.h>
71 #include "../lib/kstrtox.h"
73 #include <linux/uaccess.h>
74 #include <asm/processor.h>
78 #include <asm/stacktrace.h>
82 #include <asm/setup.h>
84 #ifdef CONFIG_BSD_PROCESS_ACCT
85 #include <linux/acct.h>
87 #ifdef CONFIG_RT_MUTEXES
88 #include <linux/rtmutex.h>
90 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
91 #include <linux/lockdep.h>
93 #ifdef CONFIG_CHR_DEV_SG
96 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
97 #include <linux/stackleak.h>
99 #ifdef CONFIG_LOCKUP_DETECTOR
100 #include <linux/nmi.h>
103 #if defined(CONFIG_SYSCTL)
105 /* External variables not in a header file. */
106 extern int suid_dumpable;
107 #ifdef CONFIG_COREDUMP
108 extern int core_uses_pid;
109 extern char core_pattern[];
110 extern unsigned int core_pipe_limit;
113 extern int pid_max_min, pid_max_max;
114 extern int percpu_pagelist_fraction;
115 extern int latencytop_enabled;
116 extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
118 extern int sysctl_nr_trim_pages;
121 /* Constants used for minimum and maximum */
122 #ifdef CONFIG_LOCKUP_DETECTOR
123 static int sixty = 60;
126 static int __maybe_unused neg_one = -1;
129 static int __maybe_unused one = 1;
130 static int __maybe_unused two = 2;
131 static int __maybe_unused four = 4;
132 static unsigned long zero_ul;
133 static unsigned long one_ul = 1;
134 static unsigned long long_max = LONG_MAX;
135 static int one_hundred = 100;
136 static int one_thousand = 1000;
138 static int ten_thousand = 10000;
140 #ifdef CONFIG_PERF_EVENTS
141 static int six_hundred_forty_kb = 640 * 1024;
144 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
145 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
147 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
148 static int maxolduid = 65535;
149 static int minolduid;
151 static int ngroups_max = NGROUPS_MAX;
152 static const int cap_last_cap = CAP_LAST_CAP;
155 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
156 * and hung_task_check_interval_secs
158 #ifdef CONFIG_DETECT_HUNG_TASK
159 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
162 #ifdef CONFIG_INOTIFY_USER
163 #include <linux/inotify.h>
169 extern int pwrsw_enabled;
172 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
173 extern int unaligned_enabled;
177 extern int unaligned_dump_stack;
180 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
181 extern int no_unaligned_warning;
184 #ifdef CONFIG_PROC_SYSCTL
187 * enum sysctl_writes_mode - supported sysctl write modes
189 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
190 * to be written, and multiple writes on the same sysctl file descriptor
191 * will rewrite the sysctl value, regardless of file position. No warning
192 * is issued when the initial position is not 0.
193 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
195 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
196 * file position 0 and the value must be fully contained in the buffer
197 * sent to the write syscall. If dealing with strings respect the file
198 * position, but restrict this to the max length of the buffer, anything
199 * passed the max lenght will be ignored. Multiple writes will append
202 * These write modes control how current file position affects the behavior of
203 * updating sysctl values through the proc interface on each write.
205 enum sysctl_writes_mode {
206 SYSCTL_WRITES_LEGACY = -1,
207 SYSCTL_WRITES_WARN = 0,
208 SYSCTL_WRITES_STRICT = 1,
211 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
213 static int proc_do_cad_pid(struct ctl_table *table, int write,
214 void __user *buffer, size_t *lenp, loff_t *ppos);
215 static int proc_taint(struct ctl_table *table, int write,
216 void __user *buffer, size_t *lenp, loff_t *ppos);
220 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
221 void __user *buffer, size_t *lenp, loff_t *ppos);
224 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
225 void __user *buffer, size_t *lenp, loff_t *ppos);
226 #ifdef CONFIG_COREDUMP
227 static int proc_dostring_coredump(struct ctl_table *table, int write,
228 void __user *buffer, size_t *lenp, loff_t *ppos);
230 static int proc_dopipe_max_size(struct ctl_table *table, int write,
231 void __user *buffer, size_t *lenp, loff_t *ppos);
232 #ifdef CONFIG_BPF_SYSCALL
233 static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write,
234 void __user *buffer, size_t *lenp,
238 #ifdef CONFIG_MAGIC_SYSRQ
239 /* Note: sysrq code uses its own private copy */
240 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
242 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
243 void __user *buffer, size_t *lenp,
248 error = proc_dointvec(table, write, buffer, lenp, ppos);
253 sysrq_toggle_support(__sysrq_enabled);
260 static struct ctl_table kern_table[];
261 static struct ctl_table vm_table[];
262 static struct ctl_table fs_table[];
263 static struct ctl_table debug_table[];
264 static struct ctl_table dev_table[];
265 extern struct ctl_table random_table[];
267 extern struct ctl_table epoll_table[];
270 #ifdef CONFIG_FW_LOADER_USER_HELPER
271 extern struct ctl_table firmware_config_table[];
274 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
275 int sysctl_legacy_va_layout;
278 /* The default sysctl tables: */
280 static struct ctl_table sysctl_base_table[] = {
282 .procname = "kernel",
299 .child = debug_table,
309 #ifdef CONFIG_SCHED_DEBUG
310 static int min_sched_granularity_ns = 100000; /* 100 usecs */
311 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
312 static int min_wakeup_granularity_ns; /* 0 usecs */
313 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
315 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
316 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
317 #endif /* CONFIG_SMP */
318 #endif /* CONFIG_SCHED_DEBUG */
320 #ifdef CONFIG_COMPACTION
321 static int min_extfrag_threshold;
322 static int max_extfrag_threshold = 1000;
325 static struct ctl_table kern_table[] = {
327 .procname = "sched_child_runs_first",
328 .data = &sysctl_sched_child_runs_first,
329 .maxlen = sizeof(unsigned int),
331 .proc_handler = proc_dointvec,
333 #ifdef CONFIG_SCHED_DEBUG
335 .procname = "sched_min_granularity_ns",
336 .data = &sysctl_sched_min_granularity,
337 .maxlen = sizeof(unsigned int),
339 .proc_handler = sched_proc_update_handler,
340 .extra1 = &min_sched_granularity_ns,
341 .extra2 = &max_sched_granularity_ns,
344 .procname = "sched_latency_ns",
345 .data = &sysctl_sched_latency,
346 .maxlen = sizeof(unsigned int),
348 .proc_handler = sched_proc_update_handler,
349 .extra1 = &min_sched_granularity_ns,
350 .extra2 = &max_sched_granularity_ns,
353 .procname = "sched_wakeup_granularity_ns",
354 .data = &sysctl_sched_wakeup_granularity,
355 .maxlen = sizeof(unsigned int),
357 .proc_handler = sched_proc_update_handler,
358 .extra1 = &min_wakeup_granularity_ns,
359 .extra2 = &max_wakeup_granularity_ns,
363 .procname = "sched_tunable_scaling",
364 .data = &sysctl_sched_tunable_scaling,
365 .maxlen = sizeof(enum sched_tunable_scaling),
367 .proc_handler = sched_proc_update_handler,
368 .extra1 = &min_sched_tunable_scaling,
369 .extra2 = &max_sched_tunable_scaling,
372 .procname = "sched_migration_cost_ns",
373 .data = &sysctl_sched_migration_cost,
374 .maxlen = sizeof(unsigned int),
376 .proc_handler = proc_dointvec,
379 .procname = "sched_nr_migrate",
380 .data = &sysctl_sched_nr_migrate,
381 .maxlen = sizeof(unsigned int),
383 .proc_handler = proc_dointvec,
385 #ifdef CONFIG_SCHEDSTATS
387 .procname = "sched_schedstats",
389 .maxlen = sizeof(unsigned int),
391 .proc_handler = sysctl_schedstats,
395 #endif /* CONFIG_SCHEDSTATS */
396 #endif /* CONFIG_SMP */
397 #ifdef CONFIG_NUMA_BALANCING
399 .procname = "numa_balancing_scan_delay_ms",
400 .data = &sysctl_numa_balancing_scan_delay,
401 .maxlen = sizeof(unsigned int),
403 .proc_handler = proc_dointvec,
406 .procname = "numa_balancing_scan_period_min_ms",
407 .data = &sysctl_numa_balancing_scan_period_min,
408 .maxlen = sizeof(unsigned int),
410 .proc_handler = proc_dointvec,
413 .procname = "numa_balancing_scan_period_max_ms",
414 .data = &sysctl_numa_balancing_scan_period_max,
415 .maxlen = sizeof(unsigned int),
417 .proc_handler = proc_dointvec,
420 .procname = "numa_balancing_scan_size_mb",
421 .data = &sysctl_numa_balancing_scan_size,
422 .maxlen = sizeof(unsigned int),
424 .proc_handler = proc_dointvec_minmax,
428 .procname = "numa_balancing",
429 .data = NULL, /* filled in by handler */
430 .maxlen = sizeof(unsigned int),
432 .proc_handler = sysctl_numa_balancing,
436 #endif /* CONFIG_NUMA_BALANCING */
437 #endif /* CONFIG_SCHED_DEBUG */
439 .procname = "sched_rt_period_us",
440 .data = &sysctl_sched_rt_period,
441 .maxlen = sizeof(unsigned int),
443 .proc_handler = sched_rt_handler,
446 .procname = "sched_rt_runtime_us",
447 .data = &sysctl_sched_rt_runtime,
448 .maxlen = sizeof(int),
450 .proc_handler = sched_rt_handler,
453 .procname = "sched_rr_timeslice_ms",
454 .data = &sysctl_sched_rr_timeslice,
455 .maxlen = sizeof(int),
457 .proc_handler = sched_rr_handler,
459 #ifdef CONFIG_SCHED_AUTOGROUP
461 .procname = "sched_autogroup_enabled",
462 .data = &sysctl_sched_autogroup_enabled,
463 .maxlen = sizeof(unsigned int),
465 .proc_handler = proc_dointvec_minmax,
470 #ifdef CONFIG_CFS_BANDWIDTH
472 .procname = "sched_cfs_bandwidth_slice_us",
473 .data = &sysctl_sched_cfs_bandwidth_slice,
474 .maxlen = sizeof(unsigned int),
476 .proc_handler = proc_dointvec_minmax,
480 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
482 .procname = "sched_energy_aware",
483 .data = &sysctl_sched_energy_aware,
484 .maxlen = sizeof(unsigned int),
486 .proc_handler = sched_energy_aware_handler,
491 #ifdef CONFIG_PROVE_LOCKING
493 .procname = "prove_locking",
494 .data = &prove_locking,
495 .maxlen = sizeof(int),
497 .proc_handler = proc_dointvec,
500 #ifdef CONFIG_LOCK_STAT
502 .procname = "lock_stat",
504 .maxlen = sizeof(int),
506 .proc_handler = proc_dointvec,
511 .data = &panic_timeout,
512 .maxlen = sizeof(int),
514 .proc_handler = proc_dointvec,
516 #ifdef CONFIG_COREDUMP
518 .procname = "core_uses_pid",
519 .data = &core_uses_pid,
520 .maxlen = sizeof(int),
522 .proc_handler = proc_dointvec,
525 .procname = "core_pattern",
526 .data = core_pattern,
527 .maxlen = CORENAME_MAX_SIZE,
529 .proc_handler = proc_dostring_coredump,
532 .procname = "core_pipe_limit",
533 .data = &core_pipe_limit,
534 .maxlen = sizeof(unsigned int),
536 .proc_handler = proc_dointvec,
539 #ifdef CONFIG_PROC_SYSCTL
541 .procname = "tainted",
542 .maxlen = sizeof(long),
544 .proc_handler = proc_taint,
547 .procname = "sysctl_writes_strict",
548 .data = &sysctl_writes_strict,
549 .maxlen = sizeof(int),
551 .proc_handler = proc_dointvec_minmax,
556 #ifdef CONFIG_LATENCYTOP
558 .procname = "latencytop",
559 .data = &latencytop_enabled,
560 .maxlen = sizeof(int),
562 .proc_handler = sysctl_latencytop,
565 #ifdef CONFIG_BLK_DEV_INITRD
567 .procname = "real-root-dev",
568 .data = &real_root_dev,
569 .maxlen = sizeof(int),
571 .proc_handler = proc_dointvec,
575 .procname = "print-fatal-signals",
576 .data = &print_fatal_signals,
577 .maxlen = sizeof(int),
579 .proc_handler = proc_dointvec,
583 .procname = "reboot-cmd",
584 .data = reboot_command,
587 .proc_handler = proc_dostring,
590 .procname = "stop-a",
591 .data = &stop_a_enabled,
592 .maxlen = sizeof (int),
594 .proc_handler = proc_dointvec,
597 .procname = "scons-poweroff",
598 .data = &scons_pwroff,
599 .maxlen = sizeof (int),
601 .proc_handler = proc_dointvec,
604 #ifdef CONFIG_SPARC64
606 .procname = "tsb-ratio",
607 .data = &sysctl_tsb_ratio,
608 .maxlen = sizeof (int),
610 .proc_handler = proc_dointvec,
615 .procname = "soft-power",
616 .data = &pwrsw_enabled,
617 .maxlen = sizeof (int),
619 .proc_handler = proc_dointvec,
622 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
624 .procname = "unaligned-trap",
625 .data = &unaligned_enabled,
626 .maxlen = sizeof (int),
628 .proc_handler = proc_dointvec,
632 .procname = "ctrl-alt-del",
634 .maxlen = sizeof(int),
636 .proc_handler = proc_dointvec,
638 #ifdef CONFIG_FUNCTION_TRACER
640 .procname = "ftrace_enabled",
641 .data = &ftrace_enabled,
642 .maxlen = sizeof(int),
644 .proc_handler = ftrace_enable_sysctl,
647 #ifdef CONFIG_STACK_TRACER
649 .procname = "stack_tracer_enabled",
650 .data = &stack_tracer_enabled,
651 .maxlen = sizeof(int),
653 .proc_handler = stack_trace_sysctl,
656 #ifdef CONFIG_TRACING
658 .procname = "ftrace_dump_on_oops",
659 .data = &ftrace_dump_on_oops,
660 .maxlen = sizeof(int),
662 .proc_handler = proc_dointvec,
665 .procname = "traceoff_on_warning",
666 .data = &__disable_trace_on_warning,
667 .maxlen = sizeof(__disable_trace_on_warning),
669 .proc_handler = proc_dointvec,
672 .procname = "tracepoint_printk",
673 .data = &tracepoint_printk,
674 .maxlen = sizeof(tracepoint_printk),
676 .proc_handler = tracepoint_printk_sysctl,
679 #ifdef CONFIG_KEXEC_CORE
681 .procname = "kexec_load_disabled",
682 .data = &kexec_load_disabled,
683 .maxlen = sizeof(int),
685 /* only handle a transition from default "0" to "1" */
686 .proc_handler = proc_dointvec_minmax,
691 #ifdef CONFIG_MODULES
693 .procname = "modprobe",
694 .data = &modprobe_path,
695 .maxlen = KMOD_PATH_LEN,
697 .proc_handler = proc_dostring,
700 .procname = "modules_disabled",
701 .data = &modules_disabled,
702 .maxlen = sizeof(int),
704 /* only handle a transition from default "0" to "1" */
705 .proc_handler = proc_dointvec_minmax,
710 #ifdef CONFIG_UEVENT_HELPER
712 .procname = "hotplug",
713 .data = &uevent_helper,
714 .maxlen = UEVENT_HELPER_PATH_LEN,
716 .proc_handler = proc_dostring,
719 #ifdef CONFIG_CHR_DEV_SG
721 .procname = "sg-big-buff",
722 .data = &sg_big_buff,
723 .maxlen = sizeof (int),
725 .proc_handler = proc_dointvec,
728 #ifdef CONFIG_BSD_PROCESS_ACCT
732 .maxlen = 3*sizeof(int),
734 .proc_handler = proc_dointvec,
737 #ifdef CONFIG_MAGIC_SYSRQ
740 .data = &__sysrq_enabled,
741 .maxlen = sizeof (int),
743 .proc_handler = sysrq_sysctl_handler,
746 #ifdef CONFIG_PROC_SYSCTL
748 .procname = "cad_pid",
750 .maxlen = sizeof (int),
752 .proc_handler = proc_do_cad_pid,
756 .procname = "threads-max",
758 .maxlen = sizeof(int),
760 .proc_handler = sysctl_max_threads,
763 .procname = "random",
765 .child = random_table,
768 .procname = "usermodehelper",
770 .child = usermodehelper_table,
772 #ifdef CONFIG_FW_LOADER_USER_HELPER
774 .procname = "firmware_config",
776 .child = firmware_config_table,
780 .procname = "overflowuid",
781 .data = &overflowuid,
782 .maxlen = sizeof(int),
784 .proc_handler = proc_dointvec_minmax,
785 .extra1 = &minolduid,
786 .extra2 = &maxolduid,
789 .procname = "overflowgid",
790 .data = &overflowgid,
791 .maxlen = sizeof(int),
793 .proc_handler = proc_dointvec_minmax,
794 .extra1 = &minolduid,
795 .extra2 = &maxolduid,
798 #ifdef CONFIG_MATHEMU
800 .procname = "ieee_emulation_warnings",
801 .data = &sysctl_ieee_emulation_warnings,
802 .maxlen = sizeof(int),
804 .proc_handler = proc_dointvec,
808 .procname = "userprocess_debug",
809 .data = &show_unhandled_signals,
810 .maxlen = sizeof(int),
812 .proc_handler = proc_dointvec,
816 .procname = "pid_max",
818 .maxlen = sizeof (int),
820 .proc_handler = proc_dointvec_minmax,
821 .extra1 = &pid_max_min,
822 .extra2 = &pid_max_max,
825 .procname = "panic_on_oops",
826 .data = &panic_on_oops,
827 .maxlen = sizeof(int),
829 .proc_handler = proc_dointvec,
832 .procname = "panic_print",
833 .data = &panic_print,
834 .maxlen = sizeof(unsigned long),
836 .proc_handler = proc_doulongvec_minmax,
838 #if defined CONFIG_PRINTK
840 .procname = "printk",
841 .data = &console_loglevel,
842 .maxlen = 4*sizeof(int),
844 .proc_handler = proc_dointvec,
847 .procname = "printk_ratelimit",
848 .data = &printk_ratelimit_state.interval,
849 .maxlen = sizeof(int),
851 .proc_handler = proc_dointvec_jiffies,
854 .procname = "printk_ratelimit_burst",
855 .data = &printk_ratelimit_state.burst,
856 .maxlen = sizeof(int),
858 .proc_handler = proc_dointvec,
861 .procname = "printk_delay",
862 .data = &printk_delay_msec,
863 .maxlen = sizeof(int),
865 .proc_handler = proc_dointvec_minmax,
867 .extra2 = &ten_thousand,
870 .procname = "printk_devkmsg",
871 .data = devkmsg_log_str,
872 .maxlen = DEVKMSG_STR_MAX_SIZE,
874 .proc_handler = devkmsg_sysctl_set_loglvl,
877 .procname = "dmesg_restrict",
878 .data = &dmesg_restrict,
879 .maxlen = sizeof(int),
881 .proc_handler = proc_dointvec_minmax_sysadmin,
886 .procname = "kptr_restrict",
887 .data = &kptr_restrict,
888 .maxlen = sizeof(int),
890 .proc_handler = proc_dointvec_minmax_sysadmin,
896 .procname = "ngroups_max",
897 .data = &ngroups_max,
898 .maxlen = sizeof (int),
900 .proc_handler = proc_dointvec,
903 .procname = "cap_last_cap",
904 .data = (void *)&cap_last_cap,
905 .maxlen = sizeof(int),
907 .proc_handler = proc_dointvec,
909 #if defined(CONFIG_LOCKUP_DETECTOR)
911 .procname = "watchdog",
912 .data = &watchdog_user_enabled,
913 .maxlen = sizeof(int),
915 .proc_handler = proc_watchdog,
920 .procname = "watchdog_thresh",
921 .data = &watchdog_thresh,
922 .maxlen = sizeof(int),
924 .proc_handler = proc_watchdog_thresh,
929 .procname = "nmi_watchdog",
930 .data = &nmi_watchdog_user_enabled,
931 .maxlen = sizeof(int),
932 .mode = NMI_WATCHDOG_SYSCTL_PERM,
933 .proc_handler = proc_nmi_watchdog,
938 .procname = "watchdog_cpumask",
939 .data = &watchdog_cpumask_bits,
942 .proc_handler = proc_watchdog_cpumask,
944 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
946 .procname = "soft_watchdog",
947 .data = &soft_watchdog_user_enabled,
948 .maxlen = sizeof(int),
950 .proc_handler = proc_soft_watchdog,
955 .procname = "softlockup_panic",
956 .data = &softlockup_panic,
957 .maxlen = sizeof(int),
959 .proc_handler = proc_dointvec_minmax,
965 .procname = "softlockup_all_cpu_backtrace",
966 .data = &sysctl_softlockup_all_cpu_backtrace,
967 .maxlen = sizeof(int),
969 .proc_handler = proc_dointvec_minmax,
973 #endif /* CONFIG_SMP */
975 #ifdef CONFIG_HARDLOCKUP_DETECTOR
977 .procname = "hardlockup_panic",
978 .data = &hardlockup_panic,
979 .maxlen = sizeof(int),
981 .proc_handler = proc_dointvec_minmax,
987 .procname = "hardlockup_all_cpu_backtrace",
988 .data = &sysctl_hardlockup_all_cpu_backtrace,
989 .maxlen = sizeof(int),
991 .proc_handler = proc_dointvec_minmax,
995 #endif /* CONFIG_SMP */
999 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1001 .procname = "unknown_nmi_panic",
1002 .data = &unknown_nmi_panic,
1003 .maxlen = sizeof (int),
1005 .proc_handler = proc_dointvec,
1008 #if defined(CONFIG_X86)
1010 .procname = "panic_on_unrecovered_nmi",
1011 .data = &panic_on_unrecovered_nmi,
1012 .maxlen = sizeof(int),
1014 .proc_handler = proc_dointvec,
1017 .procname = "panic_on_io_nmi",
1018 .data = &panic_on_io_nmi,
1019 .maxlen = sizeof(int),
1021 .proc_handler = proc_dointvec,
1023 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1025 .procname = "panic_on_stackoverflow",
1026 .data = &sysctl_panic_on_stackoverflow,
1027 .maxlen = sizeof(int),
1029 .proc_handler = proc_dointvec,
1033 .procname = "bootloader_type",
1034 .data = &bootloader_type,
1035 .maxlen = sizeof (int),
1037 .proc_handler = proc_dointvec,
1040 .procname = "bootloader_version",
1041 .data = &bootloader_version,
1042 .maxlen = sizeof (int),
1044 .proc_handler = proc_dointvec,
1047 .procname = "io_delay_type",
1048 .data = &io_delay_type,
1049 .maxlen = sizeof(int),
1051 .proc_handler = proc_dointvec,
1054 #if defined(CONFIG_MMU)
1056 .procname = "randomize_va_space",
1057 .data = &randomize_va_space,
1058 .maxlen = sizeof(int),
1060 .proc_handler = proc_dointvec,
1063 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1065 .procname = "spin_retry",
1066 .data = &spin_retry,
1067 .maxlen = sizeof (int),
1069 .proc_handler = proc_dointvec,
1072 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1074 .procname = "acpi_video_flags",
1075 .data = &acpi_realmode_flags,
1076 .maxlen = sizeof (unsigned long),
1078 .proc_handler = proc_doulongvec_minmax,
1081 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1083 .procname = "ignore-unaligned-usertrap",
1084 .data = &no_unaligned_warning,
1085 .maxlen = sizeof (int),
1087 .proc_handler = proc_dointvec,
1092 .procname = "unaligned-dump-stack",
1093 .data = &unaligned_dump_stack,
1094 .maxlen = sizeof (int),
1096 .proc_handler = proc_dointvec,
1099 #ifdef CONFIG_DETECT_HUNG_TASK
1101 .procname = "hung_task_panic",
1102 .data = &sysctl_hung_task_panic,
1103 .maxlen = sizeof(int),
1105 .proc_handler = proc_dointvec_minmax,
1110 .procname = "hung_task_check_count",
1111 .data = &sysctl_hung_task_check_count,
1112 .maxlen = sizeof(int),
1114 .proc_handler = proc_dointvec_minmax,
1118 .procname = "hung_task_timeout_secs",
1119 .data = &sysctl_hung_task_timeout_secs,
1120 .maxlen = sizeof(unsigned long),
1122 .proc_handler = proc_dohung_task_timeout_secs,
1123 .extra2 = &hung_task_timeout_max,
1126 .procname = "hung_task_check_interval_secs",
1127 .data = &sysctl_hung_task_check_interval_secs,
1128 .maxlen = sizeof(unsigned long),
1130 .proc_handler = proc_dohung_task_timeout_secs,
1131 .extra2 = &hung_task_timeout_max,
1134 .procname = "hung_task_warnings",
1135 .data = &sysctl_hung_task_warnings,
1136 .maxlen = sizeof(int),
1138 .proc_handler = proc_dointvec_minmax,
1142 #ifdef CONFIG_RT_MUTEXES
1144 .procname = "max_lock_depth",
1145 .data = &max_lock_depth,
1146 .maxlen = sizeof(int),
1148 .proc_handler = proc_dointvec,
1152 .procname = "poweroff_cmd",
1153 .data = &poweroff_cmd,
1154 .maxlen = POWEROFF_CMD_PATH_LEN,
1156 .proc_handler = proc_dostring,
1162 .child = key_sysctls,
1165 #ifdef CONFIG_PERF_EVENTS
1167 * User-space scripts rely on the existence of this file
1168 * as a feature check for perf_events being enabled.
1170 * So it's an ABI, do not remove!
1173 .procname = "perf_event_paranoid",
1174 .data = &sysctl_perf_event_paranoid,
1175 .maxlen = sizeof(sysctl_perf_event_paranoid),
1177 .proc_handler = proc_dointvec,
1180 .procname = "perf_event_mlock_kb",
1181 .data = &sysctl_perf_event_mlock,
1182 .maxlen = sizeof(sysctl_perf_event_mlock),
1184 .proc_handler = proc_dointvec,
1187 .procname = "perf_event_max_sample_rate",
1188 .data = &sysctl_perf_event_sample_rate,
1189 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1191 .proc_handler = perf_proc_update_handler,
1195 .procname = "perf_cpu_time_max_percent",
1196 .data = &sysctl_perf_cpu_time_max_percent,
1197 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1199 .proc_handler = perf_cpu_time_max_percent_handler,
1201 .extra2 = &one_hundred,
1204 .procname = "perf_event_max_stack",
1205 .data = &sysctl_perf_event_max_stack,
1206 .maxlen = sizeof(sysctl_perf_event_max_stack),
1208 .proc_handler = perf_event_max_stack_handler,
1210 .extra2 = &six_hundred_forty_kb,
1213 .procname = "perf_event_max_contexts_per_stack",
1214 .data = &sysctl_perf_event_max_contexts_per_stack,
1215 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1217 .proc_handler = perf_event_max_stack_handler,
1219 .extra2 = &one_thousand,
1223 .procname = "panic_on_warn",
1224 .data = &panic_on_warn,
1225 .maxlen = sizeof(int),
1227 .proc_handler = proc_dointvec_minmax,
1231 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1233 .procname = "timer_migration",
1234 .data = &sysctl_timer_migration,
1235 .maxlen = sizeof(unsigned int),
1237 .proc_handler = timer_migration_handler,
1242 #ifdef CONFIG_BPF_SYSCALL
1244 .procname = "unprivileged_bpf_disabled",
1245 .data = &sysctl_unprivileged_bpf_disabled,
1246 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1248 /* only handle a transition from default "0" to "1" */
1249 .proc_handler = proc_dointvec_minmax,
1254 .procname = "bpf_stats_enabled",
1255 .data = &sysctl_bpf_stats_enabled,
1256 .maxlen = sizeof(sysctl_bpf_stats_enabled),
1258 .proc_handler = proc_dointvec_minmax_bpf_stats,
1263 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1265 .procname = "panic_on_rcu_stall",
1266 .data = &sysctl_panic_on_rcu_stall,
1267 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1269 .proc_handler = proc_dointvec_minmax,
1274 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1276 .procname = "stack_erasing",
1278 .maxlen = sizeof(int),
1280 .proc_handler = stack_erasing_sysctl,
1288 static struct ctl_table vm_table[] = {
1290 .procname = "overcommit_memory",
1291 .data = &sysctl_overcommit_memory,
1292 .maxlen = sizeof(sysctl_overcommit_memory),
1294 .proc_handler = proc_dointvec_minmax,
1299 .procname = "panic_on_oom",
1300 .data = &sysctl_panic_on_oom,
1301 .maxlen = sizeof(sysctl_panic_on_oom),
1303 .proc_handler = proc_dointvec_minmax,
1308 .procname = "oom_kill_allocating_task",
1309 .data = &sysctl_oom_kill_allocating_task,
1310 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1312 .proc_handler = proc_dointvec,
1315 .procname = "oom_dump_tasks",
1316 .data = &sysctl_oom_dump_tasks,
1317 .maxlen = sizeof(sysctl_oom_dump_tasks),
1319 .proc_handler = proc_dointvec,
1322 .procname = "overcommit_ratio",
1323 .data = &sysctl_overcommit_ratio,
1324 .maxlen = sizeof(sysctl_overcommit_ratio),
1326 .proc_handler = overcommit_ratio_handler,
1329 .procname = "overcommit_kbytes",
1330 .data = &sysctl_overcommit_kbytes,
1331 .maxlen = sizeof(sysctl_overcommit_kbytes),
1333 .proc_handler = overcommit_kbytes_handler,
1336 .procname = "page-cluster",
1337 .data = &page_cluster,
1338 .maxlen = sizeof(int),
1340 .proc_handler = proc_dointvec_minmax,
1344 .procname = "dirty_background_ratio",
1345 .data = &dirty_background_ratio,
1346 .maxlen = sizeof(dirty_background_ratio),
1348 .proc_handler = dirty_background_ratio_handler,
1350 .extra2 = &one_hundred,
1353 .procname = "dirty_background_bytes",
1354 .data = &dirty_background_bytes,
1355 .maxlen = sizeof(dirty_background_bytes),
1357 .proc_handler = dirty_background_bytes_handler,
1361 .procname = "dirty_ratio",
1362 .data = &vm_dirty_ratio,
1363 .maxlen = sizeof(vm_dirty_ratio),
1365 .proc_handler = dirty_ratio_handler,
1367 .extra2 = &one_hundred,
1370 .procname = "dirty_bytes",
1371 .data = &vm_dirty_bytes,
1372 .maxlen = sizeof(vm_dirty_bytes),
1374 .proc_handler = dirty_bytes_handler,
1375 .extra1 = &dirty_bytes_min,
1378 .procname = "dirty_writeback_centisecs",
1379 .data = &dirty_writeback_interval,
1380 .maxlen = sizeof(dirty_writeback_interval),
1382 .proc_handler = dirty_writeback_centisecs_handler,
1385 .procname = "dirty_expire_centisecs",
1386 .data = &dirty_expire_interval,
1387 .maxlen = sizeof(dirty_expire_interval),
1389 .proc_handler = proc_dointvec_minmax,
1393 .procname = "dirtytime_expire_seconds",
1394 .data = &dirtytime_expire_interval,
1395 .maxlen = sizeof(dirtytime_expire_interval),
1397 .proc_handler = dirtytime_interval_handler,
1401 .procname = "swappiness",
1402 .data = &vm_swappiness,
1403 .maxlen = sizeof(vm_swappiness),
1405 .proc_handler = proc_dointvec_minmax,
1407 .extra2 = &one_hundred,
1409 #ifdef CONFIG_HUGETLB_PAGE
1411 .procname = "nr_hugepages",
1413 .maxlen = sizeof(unsigned long),
1415 .proc_handler = hugetlb_sysctl_handler,
1419 .procname = "nr_hugepages_mempolicy",
1421 .maxlen = sizeof(unsigned long),
1423 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1426 .procname = "numa_stat",
1427 .data = &sysctl_vm_numa_stat,
1428 .maxlen = sizeof(int),
1430 .proc_handler = sysctl_vm_numa_stat_handler,
1436 .procname = "hugetlb_shm_group",
1437 .data = &sysctl_hugetlb_shm_group,
1438 .maxlen = sizeof(gid_t),
1440 .proc_handler = proc_dointvec,
1443 .procname = "nr_overcommit_hugepages",
1445 .maxlen = sizeof(unsigned long),
1447 .proc_handler = hugetlb_overcommit_handler,
1451 .procname = "lowmem_reserve_ratio",
1452 .data = &sysctl_lowmem_reserve_ratio,
1453 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1455 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1458 .procname = "drop_caches",
1459 .data = &sysctl_drop_caches,
1460 .maxlen = sizeof(int),
1462 .proc_handler = drop_caches_sysctl_handler,
1466 #ifdef CONFIG_COMPACTION
1468 .procname = "compact_memory",
1469 .data = &sysctl_compact_memory,
1470 .maxlen = sizeof(int),
1472 .proc_handler = sysctl_compaction_handler,
1475 .procname = "extfrag_threshold",
1476 .data = &sysctl_extfrag_threshold,
1477 .maxlen = sizeof(int),
1479 .proc_handler = proc_dointvec_minmax,
1480 .extra1 = &min_extfrag_threshold,
1481 .extra2 = &max_extfrag_threshold,
1484 .procname = "compact_unevictable_allowed",
1485 .data = &sysctl_compact_unevictable_allowed,
1486 .maxlen = sizeof(int),
1488 .proc_handler = proc_dointvec,
1493 #endif /* CONFIG_COMPACTION */
1495 .procname = "min_free_kbytes",
1496 .data = &min_free_kbytes,
1497 .maxlen = sizeof(min_free_kbytes),
1499 .proc_handler = min_free_kbytes_sysctl_handler,
1503 .procname = "watermark_boost_factor",
1504 .data = &watermark_boost_factor,
1505 .maxlen = sizeof(watermark_boost_factor),
1507 .proc_handler = watermark_boost_factor_sysctl_handler,
1511 .procname = "watermark_scale_factor",
1512 .data = &watermark_scale_factor,
1513 .maxlen = sizeof(watermark_scale_factor),
1515 .proc_handler = watermark_scale_factor_sysctl_handler,
1517 .extra2 = &one_thousand,
1520 .procname = "percpu_pagelist_fraction",
1521 .data = &percpu_pagelist_fraction,
1522 .maxlen = sizeof(percpu_pagelist_fraction),
1524 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1529 .procname = "max_map_count",
1530 .data = &sysctl_max_map_count,
1531 .maxlen = sizeof(sysctl_max_map_count),
1533 .proc_handler = proc_dointvec_minmax,
1538 .procname = "nr_trim_pages",
1539 .data = &sysctl_nr_trim_pages,
1540 .maxlen = sizeof(sysctl_nr_trim_pages),
1542 .proc_handler = proc_dointvec_minmax,
1547 .procname = "laptop_mode",
1548 .data = &laptop_mode,
1549 .maxlen = sizeof(laptop_mode),
1551 .proc_handler = proc_dointvec_jiffies,
1554 .procname = "block_dump",
1555 .data = &block_dump,
1556 .maxlen = sizeof(block_dump),
1558 .proc_handler = proc_dointvec,
1562 .procname = "vfs_cache_pressure",
1563 .data = &sysctl_vfs_cache_pressure,
1564 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1566 .proc_handler = proc_dointvec,
1569 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1571 .procname = "legacy_va_layout",
1572 .data = &sysctl_legacy_va_layout,
1573 .maxlen = sizeof(sysctl_legacy_va_layout),
1575 .proc_handler = proc_dointvec,
1581 .procname = "zone_reclaim_mode",
1582 .data = &node_reclaim_mode,
1583 .maxlen = sizeof(node_reclaim_mode),
1585 .proc_handler = proc_dointvec,
1589 .procname = "min_unmapped_ratio",
1590 .data = &sysctl_min_unmapped_ratio,
1591 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1593 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1595 .extra2 = &one_hundred,
1598 .procname = "min_slab_ratio",
1599 .data = &sysctl_min_slab_ratio,
1600 .maxlen = sizeof(sysctl_min_slab_ratio),
1602 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1604 .extra2 = &one_hundred,
1609 .procname = "stat_interval",
1610 .data = &sysctl_stat_interval,
1611 .maxlen = sizeof(sysctl_stat_interval),
1613 .proc_handler = proc_dointvec_jiffies,
1616 .procname = "stat_refresh",
1620 .proc_handler = vmstat_refresh,
1625 .procname = "mmap_min_addr",
1626 .data = &dac_mmap_min_addr,
1627 .maxlen = sizeof(unsigned long),
1629 .proc_handler = mmap_min_addr_handler,
1634 .procname = "numa_zonelist_order",
1635 .data = &numa_zonelist_order,
1636 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1638 .proc_handler = numa_zonelist_order_handler,
1641 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1642 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1644 .procname = "vdso_enabled",
1645 #ifdef CONFIG_X86_32
1646 .data = &vdso32_enabled,
1647 .maxlen = sizeof(vdso32_enabled),
1649 .data = &vdso_enabled,
1650 .maxlen = sizeof(vdso_enabled),
1653 .proc_handler = proc_dointvec,
1657 #ifdef CONFIG_HIGHMEM
1659 .procname = "highmem_is_dirtyable",
1660 .data = &vm_highmem_is_dirtyable,
1661 .maxlen = sizeof(vm_highmem_is_dirtyable),
1663 .proc_handler = proc_dointvec_minmax,
1668 #ifdef CONFIG_MEMORY_FAILURE
1670 .procname = "memory_failure_early_kill",
1671 .data = &sysctl_memory_failure_early_kill,
1672 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1674 .proc_handler = proc_dointvec_minmax,
1679 .procname = "memory_failure_recovery",
1680 .data = &sysctl_memory_failure_recovery,
1681 .maxlen = sizeof(sysctl_memory_failure_recovery),
1683 .proc_handler = proc_dointvec_minmax,
1689 .procname = "user_reserve_kbytes",
1690 .data = &sysctl_user_reserve_kbytes,
1691 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1693 .proc_handler = proc_doulongvec_minmax,
1696 .procname = "admin_reserve_kbytes",
1697 .data = &sysctl_admin_reserve_kbytes,
1698 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1700 .proc_handler = proc_doulongvec_minmax,
1702 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1704 .procname = "mmap_rnd_bits",
1705 .data = &mmap_rnd_bits,
1706 .maxlen = sizeof(mmap_rnd_bits),
1708 .proc_handler = proc_dointvec_minmax,
1709 .extra1 = (void *)&mmap_rnd_bits_min,
1710 .extra2 = (void *)&mmap_rnd_bits_max,
1713 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1715 .procname = "mmap_rnd_compat_bits",
1716 .data = &mmap_rnd_compat_bits,
1717 .maxlen = sizeof(mmap_rnd_compat_bits),
1719 .proc_handler = proc_dointvec_minmax,
1720 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1721 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1724 #ifdef CONFIG_USERFAULTFD
1726 .procname = "unprivileged_userfaultfd",
1727 .data = &sysctl_unprivileged_userfaultfd,
1728 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
1730 .proc_handler = proc_dointvec_minmax,
1738 static struct ctl_table fs_table[] = {
1740 .procname = "inode-nr",
1741 .data = &inodes_stat,
1742 .maxlen = 2*sizeof(long),
1744 .proc_handler = proc_nr_inodes,
1747 .procname = "inode-state",
1748 .data = &inodes_stat,
1749 .maxlen = 7*sizeof(long),
1751 .proc_handler = proc_nr_inodes,
1754 .procname = "file-nr",
1755 .data = &files_stat,
1756 .maxlen = sizeof(files_stat),
1758 .proc_handler = proc_nr_files,
1761 .procname = "file-max",
1762 .data = &files_stat.max_files,
1763 .maxlen = sizeof(files_stat.max_files),
1765 .proc_handler = proc_doulongvec_minmax,
1767 .extra2 = &long_max,
1770 .procname = "nr_open",
1771 .data = &sysctl_nr_open,
1772 .maxlen = sizeof(unsigned int),
1774 .proc_handler = proc_dointvec_minmax,
1775 .extra1 = &sysctl_nr_open_min,
1776 .extra2 = &sysctl_nr_open_max,
1779 .procname = "dentry-state",
1780 .data = &dentry_stat,
1781 .maxlen = 6*sizeof(long),
1783 .proc_handler = proc_nr_dentry,
1786 .procname = "overflowuid",
1787 .data = &fs_overflowuid,
1788 .maxlen = sizeof(int),
1790 .proc_handler = proc_dointvec_minmax,
1791 .extra1 = &minolduid,
1792 .extra2 = &maxolduid,
1795 .procname = "overflowgid",
1796 .data = &fs_overflowgid,
1797 .maxlen = sizeof(int),
1799 .proc_handler = proc_dointvec_minmax,
1800 .extra1 = &minolduid,
1801 .extra2 = &maxolduid,
1803 #ifdef CONFIG_FILE_LOCKING
1805 .procname = "leases-enable",
1806 .data = &leases_enable,
1807 .maxlen = sizeof(int),
1809 .proc_handler = proc_dointvec,
1812 #ifdef CONFIG_DNOTIFY
1814 .procname = "dir-notify-enable",
1815 .data = &dir_notify_enable,
1816 .maxlen = sizeof(int),
1818 .proc_handler = proc_dointvec,
1822 #ifdef CONFIG_FILE_LOCKING
1824 .procname = "lease-break-time",
1825 .data = &lease_break_time,
1826 .maxlen = sizeof(int),
1828 .proc_handler = proc_dointvec,
1833 .procname = "aio-nr",
1835 .maxlen = sizeof(aio_nr),
1837 .proc_handler = proc_doulongvec_minmax,
1840 .procname = "aio-max-nr",
1841 .data = &aio_max_nr,
1842 .maxlen = sizeof(aio_max_nr),
1844 .proc_handler = proc_doulongvec_minmax,
1846 #endif /* CONFIG_AIO */
1847 #ifdef CONFIG_INOTIFY_USER
1849 .procname = "inotify",
1851 .child = inotify_table,
1856 .procname = "epoll",
1858 .child = epoll_table,
1863 .procname = "protected_symlinks",
1864 .data = &sysctl_protected_symlinks,
1865 .maxlen = sizeof(int),
1867 .proc_handler = proc_dointvec_minmax,
1872 .procname = "protected_hardlinks",
1873 .data = &sysctl_protected_hardlinks,
1874 .maxlen = sizeof(int),
1876 .proc_handler = proc_dointvec_minmax,
1881 .procname = "protected_fifos",
1882 .data = &sysctl_protected_fifos,
1883 .maxlen = sizeof(int),
1885 .proc_handler = proc_dointvec_minmax,
1890 .procname = "protected_regular",
1891 .data = &sysctl_protected_regular,
1892 .maxlen = sizeof(int),
1894 .proc_handler = proc_dointvec_minmax,
1899 .procname = "suid_dumpable",
1900 .data = &suid_dumpable,
1901 .maxlen = sizeof(int),
1903 .proc_handler = proc_dointvec_minmax_coredump,
1907 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1909 .procname = "binfmt_misc",
1911 .child = sysctl_mount_point,
1915 .procname = "pipe-max-size",
1916 .data = &pipe_max_size,
1917 .maxlen = sizeof(pipe_max_size),
1919 .proc_handler = proc_dopipe_max_size,
1922 .procname = "pipe-user-pages-hard",
1923 .data = &pipe_user_pages_hard,
1924 .maxlen = sizeof(pipe_user_pages_hard),
1926 .proc_handler = proc_doulongvec_minmax,
1929 .procname = "pipe-user-pages-soft",
1930 .data = &pipe_user_pages_soft,
1931 .maxlen = sizeof(pipe_user_pages_soft),
1933 .proc_handler = proc_doulongvec_minmax,
1936 .procname = "mount-max",
1937 .data = &sysctl_mount_max,
1938 .maxlen = sizeof(unsigned int),
1940 .proc_handler = proc_dointvec_minmax,
1946 static struct ctl_table debug_table[] = {
1947 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1949 .procname = "exception-trace",
1950 .data = &show_unhandled_signals,
1951 .maxlen = sizeof(int),
1953 .proc_handler = proc_dointvec
1956 #if defined(CONFIG_OPTPROBES)
1958 .procname = "kprobes-optimization",
1959 .data = &sysctl_kprobes_optimization,
1960 .maxlen = sizeof(int),
1962 .proc_handler = proc_kprobes_optimization_handler,
1970 static struct ctl_table dev_table[] = {
1974 int __init sysctl_init(void)
1976 struct ctl_table_header *hdr;
1978 hdr = register_sysctl_table(sysctl_base_table);
1979 kmemleak_not_leak(hdr);
1983 #endif /* CONFIG_SYSCTL */
1989 #ifdef CONFIG_PROC_SYSCTL
1991 static int _proc_do_string(char *data, int maxlen, int write,
1992 char __user *buffer,
1993 size_t *lenp, loff_t *ppos)
1999 if (!data || !maxlen || !*lenp) {
2005 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
2006 /* Only continue writes not past the end of buffer. */
2008 if (len > maxlen - 1)
2015 /* Start writing from beginning of buffer. */
2021 while ((p - buffer) < *lenp && len < maxlen - 1) {
2022 if (get_user(c, p++))
2024 if (c == 0 || c == '\n')
2045 if (copy_to_user(buffer, data, len))
2048 if (put_user('\n', buffer + len))
2058 static void warn_sysctl_write(struct ctl_table *table)
2060 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2061 "This will not be supported in the future. To silence this\n"
2062 "warning, set kernel.sysctl_writes_strict = -1\n",
2063 current->comm, table->procname);
2067 * proc_first_pos_non_zero_ignore - check if first position is allowed
2068 * @ppos: file position
2069 * @table: the sysctl table
2071 * Returns true if the first position is non-zero and the sysctl_writes_strict
2072 * mode indicates this is not allowed for numeric input types. String proc
2073 * handlers can ignore the return value.
2075 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2076 struct ctl_table *table)
2081 switch (sysctl_writes_strict) {
2082 case SYSCTL_WRITES_STRICT:
2084 case SYSCTL_WRITES_WARN:
2085 warn_sysctl_write(table);
2093 * proc_dostring - read a string sysctl
2094 * @table: the sysctl table
2095 * @write: %TRUE if this is a write to the sysctl file
2096 * @buffer: the user buffer
2097 * @lenp: the size of the user buffer
2098 * @ppos: file position
2100 * Reads/writes a string from/to the user buffer. If the kernel
2101 * buffer provided is not large enough to hold the string, the
2102 * string is truncated. The copied string is %NULL-terminated.
2103 * If the string is being read by the user process, it is copied
2104 * and a newline '\n' is added. It is truncated if the buffer is
2107 * Returns 0 on success.
2109 int proc_dostring(struct ctl_table *table, int write,
2110 void __user *buffer, size_t *lenp, loff_t *ppos)
2113 proc_first_pos_non_zero_ignore(ppos, table);
2115 return _proc_do_string((char *)(table->data), table->maxlen, write,
2116 (char __user *)buffer, lenp, ppos);
2119 static size_t proc_skip_spaces(char **buf)
2122 char *tmp = skip_spaces(*buf);
2128 static void proc_skip_char(char **buf, size_t *size, const char v)
2139 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2142 * @cp: kernel buffer containing the string to parse
2143 * @endp: pointer to store the trailing characters
2144 * @base: the base to use
2145 * @res: where the parsed integer will be stored
2147 * In case of success 0 is returned and @res will contain the parsed integer,
2148 * @endp will hold any trailing characters.
2149 * This function will fail the parse on overflow. If there wasn't an overflow
2150 * the function will defer the decision what characters count as invalid to the
2153 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2156 unsigned long long result;
2159 cp = _parse_integer_fixup_radix(cp, &base);
2160 rv = _parse_integer(cp, base, &result);
2161 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2169 *res = (unsigned long)result;
2173 #define TMPBUFLEN 22
2175 * proc_get_long - reads an ASCII formatted integer from a user buffer
2177 * @buf: a kernel buffer
2178 * @size: size of the kernel buffer
2179 * @val: this is where the number will be stored
2180 * @neg: set to %TRUE if number is negative
2181 * @perm_tr: a vector which contains the allowed trailers
2182 * @perm_tr_len: size of the perm_tr vector
2183 * @tr: pointer to store the trailer character
2185 * In case of success %0 is returned and @buf and @size are updated with
2186 * the amount of bytes read. If @tr is non-NULL and a trailing
2187 * character exists (size is non-zero after returning from this
2188 * function), @tr is updated with the trailing character.
2190 static int proc_get_long(char **buf, size_t *size,
2191 unsigned long *val, bool *neg,
2192 const char *perm_tr, unsigned perm_tr_len, char *tr)
2195 char *p, tmp[TMPBUFLEN];
2201 if (len > TMPBUFLEN - 1)
2202 len = TMPBUFLEN - 1;
2204 memcpy(tmp, *buf, len);
2208 if (*p == '-' && *size > 1) {
2216 if (strtoul_lenient(p, &p, 0, val))
2221 /* We don't know if the next char is whitespace thus we may accept
2222 * invalid integers (e.g. 1234...a) or two integers instead of one
2223 * (e.g. 123...1). So lets not allow such large numbers. */
2224 if (len == TMPBUFLEN - 1)
2227 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2230 if (tr && (len < *size))
2240 * proc_put_long - converts an integer to a decimal ASCII formatted string
2242 * @buf: the user buffer
2243 * @size: the size of the user buffer
2244 * @val: the integer to be converted
2245 * @neg: sign of the number, %TRUE for negative
2247 * In case of success %0 is returned and @buf and @size are updated with
2248 * the amount of bytes written.
2250 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2254 char tmp[TMPBUFLEN], *p = tmp;
2256 sprintf(p, "%s%lu", neg ? "-" : "", val);
2260 if (copy_to_user(*buf, tmp, len))
2268 static int proc_put_char(void __user **buf, size_t *size, char c)
2271 char __user **buffer = (char __user **)buf;
2272 if (put_user(c, *buffer))
2274 (*size)--, (*buffer)++;
2280 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2282 int write, void *data)
2286 if (*lvalp > (unsigned long) INT_MAX + 1)
2290 if (*lvalp > (unsigned long) INT_MAX)
2298 *lvalp = -(unsigned long)val;
2301 *lvalp = (unsigned long)val;
2307 static int do_proc_douintvec_conv(unsigned long *lvalp,
2309 int write, void *data)
2312 if (*lvalp > UINT_MAX)
2316 unsigned int val = *valp;
2317 *lvalp = (unsigned long)val;
2322 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2324 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2325 int write, void __user *buffer,
2326 size_t *lenp, loff_t *ppos,
2327 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2328 int write, void *data),
2331 int *i, vleft, first = 1, err = 0;
2333 char *kbuf = NULL, *p;
2335 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2340 i = (int *) tbl_data;
2341 vleft = table->maxlen / sizeof(*i);
2345 conv = do_proc_dointvec_conv;
2348 if (proc_first_pos_non_zero_ignore(ppos, table))
2351 if (left > PAGE_SIZE - 1)
2352 left = PAGE_SIZE - 1;
2353 p = kbuf = memdup_user_nul(buffer, left);
2355 return PTR_ERR(kbuf);
2358 for (; left && vleft--; i++, first=0) {
2363 left -= proc_skip_spaces(&p);
2367 err = proc_get_long(&p, &left, &lval, &neg,
2369 sizeof(proc_wspace_sep), NULL);
2372 if (conv(&neg, &lval, i, 1, data)) {
2377 if (conv(&neg, &lval, i, 0, data)) {
2382 err = proc_put_char(&buffer, &left, '\t');
2385 err = proc_put_long(&buffer, &left, lval, neg);
2391 if (!write && !first && left && !err)
2392 err = proc_put_char(&buffer, &left, '\n');
2393 if (write && !err && left)
2394 left -= proc_skip_spaces(&p);
2398 return err ? : -EINVAL;
2406 static int do_proc_dointvec(struct ctl_table *table, int write,
2407 void __user *buffer, size_t *lenp, loff_t *ppos,
2408 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2409 int write, void *data),
2412 return __do_proc_dointvec(table->data, table, write,
2413 buffer, lenp, ppos, conv, data);
2416 static int do_proc_douintvec_w(unsigned int *tbl_data,
2417 struct ctl_table *table,
2418 void __user *buffer,
2419 size_t *lenp, loff_t *ppos,
2420 int (*conv)(unsigned long *lvalp,
2422 int write, void *data),
2429 char *kbuf = NULL, *p;
2433 if (proc_first_pos_non_zero_ignore(ppos, table))
2436 if (left > PAGE_SIZE - 1)
2437 left = PAGE_SIZE - 1;
2439 p = kbuf = memdup_user_nul(buffer, left);
2443 left -= proc_skip_spaces(&p);
2449 err = proc_get_long(&p, &left, &lval, &neg,
2451 sizeof(proc_wspace_sep), NULL);
2457 if (conv(&lval, tbl_data, 1, data)) {
2463 left -= proc_skip_spaces(&p);
2472 /* This is in keeping with old __do_proc_dointvec() */
2478 static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2479 size_t *lenp, loff_t *ppos,
2480 int (*conv)(unsigned long *lvalp,
2482 int write, void *data),
2491 if (conv(&lval, tbl_data, 0, data)) {
2496 err = proc_put_long(&buffer, &left, lval, false);
2500 err = proc_put_char(&buffer, &left, '\n');
2509 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2510 int write, void __user *buffer,
2511 size_t *lenp, loff_t *ppos,
2512 int (*conv)(unsigned long *lvalp,
2514 int write, void *data),
2517 unsigned int *i, vleft;
2519 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2524 i = (unsigned int *) tbl_data;
2525 vleft = table->maxlen / sizeof(*i);
2528 * Arrays are not supported, keep this simple. *Do not* add
2537 conv = do_proc_douintvec_conv;
2540 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2542 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2545 static int do_proc_douintvec(struct ctl_table *table, int write,
2546 void __user *buffer, size_t *lenp, loff_t *ppos,
2547 int (*conv)(unsigned long *lvalp,
2549 int write, void *data),
2552 return __do_proc_douintvec(table->data, table, write,
2553 buffer, lenp, ppos, conv, data);
2557 * proc_dointvec - read a vector of integers
2558 * @table: the sysctl table
2559 * @write: %TRUE if this is a write to the sysctl file
2560 * @buffer: the user buffer
2561 * @lenp: the size of the user buffer
2562 * @ppos: file position
2564 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2565 * values from/to the user buffer, treated as an ASCII string.
2567 * Returns 0 on success.
2569 int proc_dointvec(struct ctl_table *table, int write,
2570 void __user *buffer, size_t *lenp, loff_t *ppos)
2572 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2576 * proc_douintvec - read a vector of unsigned integers
2577 * @table: the sysctl table
2578 * @write: %TRUE if this is a write to the sysctl file
2579 * @buffer: the user buffer
2580 * @lenp: the size of the user buffer
2581 * @ppos: file position
2583 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2584 * values from/to the user buffer, treated as an ASCII string.
2586 * Returns 0 on success.
2588 int proc_douintvec(struct ctl_table *table, int write,
2589 void __user *buffer, size_t *lenp, loff_t *ppos)
2591 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2592 do_proc_douintvec_conv, NULL);
2596 * Taint values can only be increased
2597 * This means we can safely use a temporary.
2599 static int proc_taint(struct ctl_table *table, int write,
2600 void __user *buffer, size_t *lenp, loff_t *ppos)
2603 unsigned long tmptaint = get_taint();
2606 if (write && !capable(CAP_SYS_ADMIN))
2611 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2617 * Poor man's atomic or. Not worth adding a primitive
2618 * to everyone's atomic.h for this
2621 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2622 if ((tmptaint >> i) & 1)
2623 add_taint(i, LOCKDEP_STILL_OK);
2630 #ifdef CONFIG_PRINTK
2631 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2632 void __user *buffer, size_t *lenp, loff_t *ppos)
2634 if (write && !capable(CAP_SYS_ADMIN))
2637 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2642 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2643 * @min: pointer to minimum allowable value
2644 * @max: pointer to maximum allowable value
2646 * The do_proc_dointvec_minmax_conv_param structure provides the
2647 * minimum and maximum values for doing range checking for those sysctl
2648 * parameters that use the proc_dointvec_minmax() handler.
2650 struct do_proc_dointvec_minmax_conv_param {
2655 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2657 int write, void *data)
2660 struct do_proc_dointvec_minmax_conv_param *param = data;
2662 * If writing, first do so via a temporary local int so we can
2663 * bounds-check it before touching *valp.
2665 int *ip = write ? &tmp : valp;
2667 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
2672 if ((param->min && *param->min > tmp) ||
2673 (param->max && *param->max < tmp))
2682 * proc_dointvec_minmax - read a vector of integers with min/max values
2683 * @table: the sysctl table
2684 * @write: %TRUE if this is a write to the sysctl file
2685 * @buffer: the user buffer
2686 * @lenp: the size of the user buffer
2687 * @ppos: file position
2689 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2690 * values from/to the user buffer, treated as an ASCII string.
2692 * This routine will ensure the values are within the range specified by
2693 * table->extra1 (min) and table->extra2 (max).
2695 * Returns 0 on success or -EINVAL on write when the range check fails.
2697 int proc_dointvec_minmax(struct ctl_table *table, int write,
2698 void __user *buffer, size_t *lenp, loff_t *ppos)
2700 struct do_proc_dointvec_minmax_conv_param param = {
2701 .min = (int *) table->extra1,
2702 .max = (int *) table->extra2,
2704 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2705 do_proc_dointvec_minmax_conv, ¶m);
2709 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2710 * @min: pointer to minimum allowable value
2711 * @max: pointer to maximum allowable value
2713 * The do_proc_douintvec_minmax_conv_param structure provides the
2714 * minimum and maximum values for doing range checking for those sysctl
2715 * parameters that use the proc_douintvec_minmax() handler.
2717 struct do_proc_douintvec_minmax_conv_param {
2722 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2724 int write, void *data)
2728 struct do_proc_douintvec_minmax_conv_param *param = data;
2729 /* write via temporary local uint for bounds-checking */
2730 unsigned int *up = write ? &tmp : valp;
2732 ret = do_proc_douintvec_conv(lvalp, up, write, data);
2737 if ((param->min && *param->min > tmp) ||
2738 (param->max && *param->max < tmp))
2748 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2749 * @table: the sysctl table
2750 * @write: %TRUE if this is a write to the sysctl file
2751 * @buffer: the user buffer
2752 * @lenp: the size of the user buffer
2753 * @ppos: file position
2755 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2756 * values from/to the user buffer, treated as an ASCII string. Negative
2757 * strings are not allowed.
2759 * This routine will ensure the values are within the range specified by
2760 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2761 * check for UINT_MAX to avoid having to support wrap around uses from
2764 * Returns 0 on success or -ERANGE on write when the range check fails.
2766 int proc_douintvec_minmax(struct ctl_table *table, int write,
2767 void __user *buffer, size_t *lenp, loff_t *ppos)
2769 struct do_proc_douintvec_minmax_conv_param param = {
2770 .min = (unsigned int *) table->extra1,
2771 .max = (unsigned int *) table->extra2,
2773 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2774 do_proc_douintvec_minmax_conv, ¶m);
2777 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2779 int write, void *data)
2784 val = round_pipe_size(*lvalp);
2790 unsigned int val = *valp;
2791 *lvalp = (unsigned long) val;
2797 static int proc_dopipe_max_size(struct ctl_table *table, int write,
2798 void __user *buffer, size_t *lenp, loff_t *ppos)
2800 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2801 do_proc_dopipe_max_size_conv, NULL);
2804 static void validate_coredump_safety(void)
2806 #ifdef CONFIG_COREDUMP
2807 if (suid_dumpable == SUID_DUMP_ROOT &&
2808 core_pattern[0] != '/' && core_pattern[0] != '|') {
2810 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2811 "Pipe handler or fully qualified core dump path required.\n"
2812 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2818 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2819 void __user *buffer, size_t *lenp, loff_t *ppos)
2821 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2823 validate_coredump_safety();
2827 #ifdef CONFIG_COREDUMP
2828 static int proc_dostring_coredump(struct ctl_table *table, int write,
2829 void __user *buffer, size_t *lenp, loff_t *ppos)
2831 int error = proc_dostring(table, write, buffer, lenp, ppos);
2833 validate_coredump_safety();
2838 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2839 void __user *buffer,
2840 size_t *lenp, loff_t *ppos,
2841 unsigned long convmul,
2842 unsigned long convdiv)
2844 unsigned long *i, *min, *max;
2845 int vleft, first = 1, err = 0;
2847 char *kbuf = NULL, *p;
2849 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2854 i = (unsigned long *) data;
2855 min = (unsigned long *) table->extra1;
2856 max = (unsigned long *) table->extra2;
2857 vleft = table->maxlen / sizeof(unsigned long);
2861 if (proc_first_pos_non_zero_ignore(ppos, table))
2864 if (left > PAGE_SIZE - 1)
2865 left = PAGE_SIZE - 1;
2866 p = kbuf = memdup_user_nul(buffer, left);
2868 return PTR_ERR(kbuf);
2871 for (; left && vleft--; i++, first = 0) {
2877 left -= proc_skip_spaces(&p);
2881 err = proc_get_long(&p, &left, &val, &neg,
2883 sizeof(proc_wspace_sep), NULL);
2888 val = convmul * val / convdiv;
2889 if ((min && val < *min) || (max && val > *max))
2893 val = convdiv * (*i) / convmul;
2895 err = proc_put_char(&buffer, &left, '\t');
2899 err = proc_put_long(&buffer, &left, val, false);
2905 if (!write && !first && left && !err)
2906 err = proc_put_char(&buffer, &left, '\n');
2908 left -= proc_skip_spaces(&p);
2912 return err ? : -EINVAL;
2920 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2921 void __user *buffer,
2922 size_t *lenp, loff_t *ppos,
2923 unsigned long convmul,
2924 unsigned long convdiv)
2926 return __do_proc_doulongvec_minmax(table->data, table, write,
2927 buffer, lenp, ppos, convmul, convdiv);
2931 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2932 * @table: the sysctl table
2933 * @write: %TRUE if this is a write to the sysctl file
2934 * @buffer: the user buffer
2935 * @lenp: the size of the user buffer
2936 * @ppos: file position
2938 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2939 * values from/to the user buffer, treated as an ASCII string.
2941 * This routine will ensure the values are within the range specified by
2942 * table->extra1 (min) and table->extra2 (max).
2944 * Returns 0 on success.
2946 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2947 void __user *buffer, size_t *lenp, loff_t *ppos)
2949 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2953 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2954 * @table: the sysctl table
2955 * @write: %TRUE if this is a write to the sysctl file
2956 * @buffer: the user buffer
2957 * @lenp: the size of the user buffer
2958 * @ppos: file position
2960 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2961 * values from/to the user buffer, treated as an ASCII string. The values
2962 * are treated as milliseconds, and converted to jiffies when they are stored.
2964 * This routine will ensure the values are within the range specified by
2965 * table->extra1 (min) and table->extra2 (max).
2967 * Returns 0 on success.
2969 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2970 void __user *buffer,
2971 size_t *lenp, loff_t *ppos)
2973 return do_proc_doulongvec_minmax(table, write, buffer,
2974 lenp, ppos, HZ, 1000l);
2978 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2980 int write, void *data)
2983 if (*lvalp > INT_MAX / HZ)
2985 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2991 lval = -(unsigned long)val;
2994 lval = (unsigned long)val;
3001 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
3003 int write, void *data)
3006 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
3008 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
3014 lval = -(unsigned long)val;
3017 lval = (unsigned long)val;
3019 *lvalp = jiffies_to_clock_t(lval);
3024 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
3026 int write, void *data)
3029 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3039 lval = -(unsigned long)val;
3042 lval = (unsigned long)val;
3044 *lvalp = jiffies_to_msecs(lval);
3050 * proc_dointvec_jiffies - read a vector of integers as seconds
3051 * @table: the sysctl table
3052 * @write: %TRUE if this is a write to the sysctl file
3053 * @buffer: the user buffer
3054 * @lenp: the size of the user buffer
3055 * @ppos: file position
3057 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3058 * values from/to the user buffer, treated as an ASCII string.
3059 * The values read are assumed to be in seconds, and are converted into
3062 * Returns 0 on success.
3064 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3065 void __user *buffer, size_t *lenp, loff_t *ppos)
3067 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3068 do_proc_dointvec_jiffies_conv,NULL);
3072 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3073 * @table: the sysctl table
3074 * @write: %TRUE if this is a write to the sysctl file
3075 * @buffer: the user buffer
3076 * @lenp: the size of the user buffer
3077 * @ppos: pointer to the file position
3079 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3080 * values from/to the user buffer, treated as an ASCII string.
3081 * The values read are assumed to be in 1/USER_HZ seconds, and
3082 * are converted into jiffies.
3084 * Returns 0 on success.
3086 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3087 void __user *buffer, size_t *lenp, loff_t *ppos)
3089 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3090 do_proc_dointvec_userhz_jiffies_conv,NULL);
3094 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3095 * @table: the sysctl table
3096 * @write: %TRUE if this is a write to the sysctl file
3097 * @buffer: the user buffer
3098 * @lenp: the size of the user buffer
3099 * @ppos: file position
3100 * @ppos: the current position in the file
3102 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3103 * values from/to the user buffer, treated as an ASCII string.
3104 * The values read are assumed to be in 1/1000 seconds, and
3105 * are converted into jiffies.
3107 * Returns 0 on success.
3109 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3110 void __user *buffer, size_t *lenp, loff_t *ppos)
3112 return do_proc_dointvec(table, write, buffer, lenp, ppos,
3113 do_proc_dointvec_ms_jiffies_conv, NULL);
3116 static int proc_do_cad_pid(struct ctl_table *table, int write,
3117 void __user *buffer, size_t *lenp, loff_t *ppos)
3119 struct pid *new_pid;
3123 tmp = pid_vnr(cad_pid);
3125 r = __do_proc_dointvec(&tmp, table, write, buffer,
3126 lenp, ppos, NULL, NULL);
3130 new_pid = find_get_pid(tmp);
3134 put_pid(xchg(&cad_pid, new_pid));
3139 * proc_do_large_bitmap - read/write from/to a large bitmap
3140 * @table: the sysctl table
3141 * @write: %TRUE if this is a write to the sysctl file
3142 * @buffer: the user buffer
3143 * @lenp: the size of the user buffer
3144 * @ppos: file position
3146 * The bitmap is stored at table->data and the bitmap length (in bits)
3149 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3150 * large bitmaps may be represented in a compact manner. Writing into
3151 * the file will clear the bitmap then update it with the given input.
3153 * Returns 0 on success.
3155 int proc_do_large_bitmap(struct ctl_table *table, int write,
3156 void __user *buffer, size_t *lenp, loff_t *ppos)
3160 size_t left = *lenp;
3161 unsigned long bitmap_len = table->maxlen;
3162 unsigned long *bitmap = *(unsigned long **) table->data;
3163 unsigned long *tmp_bitmap = NULL;
3164 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3166 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
3174 if (left > PAGE_SIZE - 1)
3175 left = PAGE_SIZE - 1;
3177 p = kbuf = memdup_user_nul(buffer, left);
3179 return PTR_ERR(kbuf);
3181 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3182 sizeof(unsigned long),
3188 proc_skip_char(&p, &left, '\n');
3189 while (!err && left) {
3190 unsigned long val_a, val_b;
3193 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
3197 if (val_a >= bitmap_len || neg) {
3209 err = proc_get_long(&p, &left, &val_b,
3210 &neg, tr_b, sizeof(tr_b),
3214 if (val_b >= bitmap_len || neg ||
3225 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
3227 proc_skip_char(&p, &left, '\n');
3231 unsigned long bit_a, bit_b = 0;
3234 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3235 if (bit_a >= bitmap_len)
3237 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3241 err = proc_put_char(&buffer, &left, ',');
3245 err = proc_put_long(&buffer, &left, bit_a, false);
3248 if (bit_a != bit_b) {
3249 err = proc_put_char(&buffer, &left, '-');
3252 err = proc_put_long(&buffer, &left, bit_b, false);
3260 err = proc_put_char(&buffer, &left, '\n');
3266 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3268 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
3278 #else /* CONFIG_PROC_SYSCTL */
3280 int proc_dostring(struct ctl_table *table, int write,
3281 void __user *buffer, size_t *lenp, loff_t *ppos)
3286 int proc_dointvec(struct ctl_table *table, int write,
3287 void __user *buffer, size_t *lenp, loff_t *ppos)
3292 int proc_douintvec(struct ctl_table *table, int write,
3293 void __user *buffer, size_t *lenp, loff_t *ppos)
3298 int proc_dointvec_minmax(struct ctl_table *table, int write,
3299 void __user *buffer, size_t *lenp, loff_t *ppos)
3304 int proc_douintvec_minmax(struct ctl_table *table, int write,
3305 void __user *buffer, size_t *lenp, loff_t *ppos)
3310 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3311 void __user *buffer, size_t *lenp, loff_t *ppos)
3316 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3317 void __user *buffer, size_t *lenp, loff_t *ppos)
3322 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3323 void __user *buffer, size_t *lenp, loff_t *ppos)
3328 int proc_doulongvec_minmax(struct ctl_table *table, int write,
3329 void __user *buffer, size_t *lenp, loff_t *ppos)
3334 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3335 void __user *buffer,
3336 size_t *lenp, loff_t *ppos)
3341 int proc_do_large_bitmap(struct ctl_table *table, int write,
3342 void __user *buffer, size_t *lenp, loff_t *ppos)
3347 #endif /* CONFIG_PROC_SYSCTL */
3349 #if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL)
3350 static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write,
3351 void __user *buffer, size_t *lenp,
3354 int ret, bpf_stats = *(int *)table->data;
3355 struct ctl_table tmp = *table;
3357 if (write && !capable(CAP_SYS_ADMIN))
3360 tmp.data = &bpf_stats;
3361 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3362 if (write && !ret) {
3363 *(int *)table->data = bpf_stats;
3365 static_branch_enable(&bpf_stats_enabled_key);
3367 static_branch_disable(&bpf_stats_enabled_key);
3373 * No sense putting this after each symbol definition, twice,
3374 * exception granted :-)
3376 EXPORT_SYMBOL(proc_dointvec);
3377 EXPORT_SYMBOL(proc_douintvec);
3378 EXPORT_SYMBOL(proc_dointvec_jiffies);
3379 EXPORT_SYMBOL(proc_dointvec_minmax);
3380 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3381 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3382 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3383 EXPORT_SYMBOL(proc_dostring);
3384 EXPORT_SYMBOL(proc_doulongvec_minmax);
3385 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3386 EXPORT_SYMBOL(proc_do_large_bitmap);