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;
130 static int __maybe_unused one = 1;
131 static int __maybe_unused two = 2;
132 static int __maybe_unused four = 4;
133 static unsigned long zero_ul;
134 static unsigned long one_ul = 1;
135 static unsigned long long_max = LONG_MAX;
136 static int one_hundred = 100;
137 static int one_thousand = 1000;
139 static int ten_thousand = 10000;
141 #ifdef CONFIG_PERF_EVENTS
142 static int six_hundred_forty_kb = 640 * 1024;
145 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
146 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
148 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
149 static int maxolduid = 65535;
150 static int minolduid;
152 static int ngroups_max = NGROUPS_MAX;
153 static const int cap_last_cap = CAP_LAST_CAP;
156 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
157 * and hung_task_check_interval_secs
159 #ifdef CONFIG_DETECT_HUNG_TASK
160 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
163 #ifdef CONFIG_INOTIFY_USER
164 #include <linux/inotify.h>
170 extern int pwrsw_enabled;
173 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
174 extern int unaligned_enabled;
178 extern int unaligned_dump_stack;
181 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
182 extern int no_unaligned_warning;
185 #ifdef CONFIG_PROC_SYSCTL
188 * enum sysctl_writes_mode - supported sysctl write modes
190 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
191 * to be written, and multiple writes on the same sysctl file descriptor
192 * will rewrite the sysctl value, regardless of file position. No warning
193 * is issued when the initial position is not 0.
194 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
196 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
197 * file position 0 and the value must be fully contained in the buffer
198 * sent to the write syscall. If dealing with strings respect the file
199 * position, but restrict this to the max length of the buffer, anything
200 * passed the max lenght will be ignored. Multiple writes will append
203 * These write modes control how current file position affects the behavior of
204 * updating sysctl values through the proc interface on each write.
206 enum sysctl_writes_mode {
207 SYSCTL_WRITES_LEGACY = -1,
208 SYSCTL_WRITES_WARN = 0,
209 SYSCTL_WRITES_STRICT = 1,
212 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
214 static int proc_do_cad_pid(struct ctl_table *table, int write,
215 void __user *buffer, size_t *lenp, loff_t *ppos);
216 static int proc_taint(struct ctl_table *table, int write,
217 void __user *buffer, size_t *lenp, loff_t *ppos);
221 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
222 void __user *buffer, size_t *lenp, loff_t *ppos);
225 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
226 void __user *buffer, size_t *lenp, loff_t *ppos);
227 #ifdef CONFIG_COREDUMP
228 static int proc_dostring_coredump(struct ctl_table *table, int write,
229 void __user *buffer, size_t *lenp, loff_t *ppos);
231 static int proc_dopipe_max_size(struct ctl_table *table, int write,
232 void __user *buffer, size_t *lenp, loff_t *ppos);
234 #ifdef CONFIG_MAGIC_SYSRQ
235 /* Note: sysrq code uses its own private copy */
236 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
238 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
239 void __user *buffer, size_t *lenp,
244 error = proc_dointvec(table, write, buffer, lenp, ppos);
249 sysrq_toggle_support(__sysrq_enabled);
256 static struct ctl_table kern_table[];
257 static struct ctl_table vm_table[];
258 static struct ctl_table fs_table[];
259 static struct ctl_table debug_table[];
260 static struct ctl_table dev_table[];
261 extern struct ctl_table random_table[];
263 extern struct ctl_table epoll_table[];
266 #ifdef CONFIG_FW_LOADER_USER_HELPER
267 extern struct ctl_table firmware_config_table[];
270 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
271 int sysctl_legacy_va_layout;
274 /* The default sysctl tables: */
276 static struct ctl_table sysctl_base_table[] = {
278 .procname = "kernel",
295 .child = debug_table,
305 #ifdef CONFIG_SCHED_DEBUG
306 static int min_sched_granularity_ns = 100000; /* 100 usecs */
307 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
308 static int min_wakeup_granularity_ns; /* 0 usecs */
309 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
311 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
312 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
313 #endif /* CONFIG_SMP */
314 #endif /* CONFIG_SCHED_DEBUG */
316 #ifdef CONFIG_COMPACTION
317 static int min_extfrag_threshold;
318 static int max_extfrag_threshold = 1000;
321 static struct ctl_table kern_table[] = {
323 .procname = "sched_child_runs_first",
324 .data = &sysctl_sched_child_runs_first,
325 .maxlen = sizeof(unsigned int),
327 .proc_handler = proc_dointvec,
329 #ifdef CONFIG_SCHED_DEBUG
331 .procname = "sched_min_granularity_ns",
332 .data = &sysctl_sched_min_granularity,
333 .maxlen = sizeof(unsigned int),
335 .proc_handler = sched_proc_update_handler,
336 .extra1 = &min_sched_granularity_ns,
337 .extra2 = &max_sched_granularity_ns,
340 .procname = "sched_latency_ns",
341 .data = &sysctl_sched_latency,
342 .maxlen = sizeof(unsigned int),
344 .proc_handler = sched_proc_update_handler,
345 .extra1 = &min_sched_granularity_ns,
346 .extra2 = &max_sched_granularity_ns,
349 .procname = "sched_wakeup_granularity_ns",
350 .data = &sysctl_sched_wakeup_granularity,
351 .maxlen = sizeof(unsigned int),
353 .proc_handler = sched_proc_update_handler,
354 .extra1 = &min_wakeup_granularity_ns,
355 .extra2 = &max_wakeup_granularity_ns,
359 .procname = "sched_tunable_scaling",
360 .data = &sysctl_sched_tunable_scaling,
361 .maxlen = sizeof(enum sched_tunable_scaling),
363 .proc_handler = sched_proc_update_handler,
364 .extra1 = &min_sched_tunable_scaling,
365 .extra2 = &max_sched_tunable_scaling,
368 .procname = "sched_migration_cost_ns",
369 .data = &sysctl_sched_migration_cost,
370 .maxlen = sizeof(unsigned int),
372 .proc_handler = proc_dointvec,
375 .procname = "sched_nr_migrate",
376 .data = &sysctl_sched_nr_migrate,
377 .maxlen = sizeof(unsigned int),
379 .proc_handler = proc_dointvec,
381 #ifdef CONFIG_SCHEDSTATS
383 .procname = "sched_schedstats",
385 .maxlen = sizeof(unsigned int),
387 .proc_handler = sysctl_schedstats,
391 #endif /* CONFIG_SCHEDSTATS */
392 #endif /* CONFIG_SMP */
393 #ifdef CONFIG_NUMA_BALANCING
395 .procname = "numa_balancing_scan_delay_ms",
396 .data = &sysctl_numa_balancing_scan_delay,
397 .maxlen = sizeof(unsigned int),
399 .proc_handler = proc_dointvec,
402 .procname = "numa_balancing_scan_period_min_ms",
403 .data = &sysctl_numa_balancing_scan_period_min,
404 .maxlen = sizeof(unsigned int),
406 .proc_handler = proc_dointvec,
409 .procname = "numa_balancing_scan_period_max_ms",
410 .data = &sysctl_numa_balancing_scan_period_max,
411 .maxlen = sizeof(unsigned int),
413 .proc_handler = proc_dointvec,
416 .procname = "numa_balancing_scan_size_mb",
417 .data = &sysctl_numa_balancing_scan_size,
418 .maxlen = sizeof(unsigned int),
420 .proc_handler = proc_dointvec_minmax,
424 .procname = "numa_balancing",
425 .data = NULL, /* filled in by handler */
426 .maxlen = sizeof(unsigned int),
428 .proc_handler = sysctl_numa_balancing,
432 #endif /* CONFIG_NUMA_BALANCING */
433 #endif /* CONFIG_SCHED_DEBUG */
435 .procname = "sched_rt_period_us",
436 .data = &sysctl_sched_rt_period,
437 .maxlen = sizeof(unsigned int),
439 .proc_handler = sched_rt_handler,
442 .procname = "sched_rt_runtime_us",
443 .data = &sysctl_sched_rt_runtime,
444 .maxlen = sizeof(int),
446 .proc_handler = sched_rt_handler,
449 .procname = "sched_rr_timeslice_ms",
450 .data = &sysctl_sched_rr_timeslice,
451 .maxlen = sizeof(int),
453 .proc_handler = sched_rr_handler,
455 #ifdef CONFIG_UCLAMP_TASK
457 .procname = "sched_util_clamp_min",
458 .data = &sysctl_sched_uclamp_util_min,
459 .maxlen = sizeof(unsigned int),
461 .proc_handler = sysctl_sched_uclamp_handler,
464 .procname = "sched_util_clamp_max",
465 .data = &sysctl_sched_uclamp_util_max,
466 .maxlen = sizeof(unsigned int),
468 .proc_handler = sysctl_sched_uclamp_handler,
471 #ifdef CONFIG_SCHED_AUTOGROUP
473 .procname = "sched_autogroup_enabled",
474 .data = &sysctl_sched_autogroup_enabled,
475 .maxlen = sizeof(unsigned int),
477 .proc_handler = proc_dointvec_minmax,
482 #ifdef CONFIG_CFS_BANDWIDTH
484 .procname = "sched_cfs_bandwidth_slice_us",
485 .data = &sysctl_sched_cfs_bandwidth_slice,
486 .maxlen = sizeof(unsigned int),
488 .proc_handler = proc_dointvec_minmax,
492 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
494 .procname = "sched_energy_aware",
495 .data = &sysctl_sched_energy_aware,
496 .maxlen = sizeof(unsigned int),
498 .proc_handler = sched_energy_aware_handler,
503 #ifdef CONFIG_PROVE_LOCKING
505 .procname = "prove_locking",
506 .data = &prove_locking,
507 .maxlen = sizeof(int),
509 .proc_handler = proc_dointvec,
512 #ifdef CONFIG_LOCK_STAT
514 .procname = "lock_stat",
516 .maxlen = sizeof(int),
518 .proc_handler = proc_dointvec,
523 .data = &panic_timeout,
524 .maxlen = sizeof(int),
526 .proc_handler = proc_dointvec,
528 #ifdef CONFIG_COREDUMP
530 .procname = "core_uses_pid",
531 .data = &core_uses_pid,
532 .maxlen = sizeof(int),
534 .proc_handler = proc_dointvec,
537 .procname = "core_pattern",
538 .data = core_pattern,
539 .maxlen = CORENAME_MAX_SIZE,
541 .proc_handler = proc_dostring_coredump,
544 .procname = "core_pipe_limit",
545 .data = &core_pipe_limit,
546 .maxlen = sizeof(unsigned int),
548 .proc_handler = proc_dointvec,
551 #ifdef CONFIG_PROC_SYSCTL
553 .procname = "tainted",
554 .maxlen = sizeof(long),
556 .proc_handler = proc_taint,
559 .procname = "sysctl_writes_strict",
560 .data = &sysctl_writes_strict,
561 .maxlen = sizeof(int),
563 .proc_handler = proc_dointvec_minmax,
568 #ifdef CONFIG_LATENCYTOP
570 .procname = "latencytop",
571 .data = &latencytop_enabled,
572 .maxlen = sizeof(int),
574 .proc_handler = sysctl_latencytop,
577 #ifdef CONFIG_BLK_DEV_INITRD
579 .procname = "real-root-dev",
580 .data = &real_root_dev,
581 .maxlen = sizeof(int),
583 .proc_handler = proc_dointvec,
587 .procname = "print-fatal-signals",
588 .data = &print_fatal_signals,
589 .maxlen = sizeof(int),
591 .proc_handler = proc_dointvec,
595 .procname = "reboot-cmd",
596 .data = reboot_command,
599 .proc_handler = proc_dostring,
602 .procname = "stop-a",
603 .data = &stop_a_enabled,
604 .maxlen = sizeof (int),
606 .proc_handler = proc_dointvec,
609 .procname = "scons-poweroff",
610 .data = &scons_pwroff,
611 .maxlen = sizeof (int),
613 .proc_handler = proc_dointvec,
616 #ifdef CONFIG_SPARC64
618 .procname = "tsb-ratio",
619 .data = &sysctl_tsb_ratio,
620 .maxlen = sizeof (int),
622 .proc_handler = proc_dointvec,
627 .procname = "soft-power",
628 .data = &pwrsw_enabled,
629 .maxlen = sizeof (int),
631 .proc_handler = proc_dointvec,
634 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
636 .procname = "unaligned-trap",
637 .data = &unaligned_enabled,
638 .maxlen = sizeof (int),
640 .proc_handler = proc_dointvec,
644 .procname = "ctrl-alt-del",
646 .maxlen = sizeof(int),
648 .proc_handler = proc_dointvec,
650 #ifdef CONFIG_FUNCTION_TRACER
652 .procname = "ftrace_enabled",
653 .data = &ftrace_enabled,
654 .maxlen = sizeof(int),
656 .proc_handler = ftrace_enable_sysctl,
659 #ifdef CONFIG_STACK_TRACER
661 .procname = "stack_tracer_enabled",
662 .data = &stack_tracer_enabled,
663 .maxlen = sizeof(int),
665 .proc_handler = stack_trace_sysctl,
668 #ifdef CONFIG_TRACING
670 .procname = "ftrace_dump_on_oops",
671 .data = &ftrace_dump_on_oops,
672 .maxlen = sizeof(int),
674 .proc_handler = proc_dointvec,
677 .procname = "traceoff_on_warning",
678 .data = &__disable_trace_on_warning,
679 .maxlen = sizeof(__disable_trace_on_warning),
681 .proc_handler = proc_dointvec,
684 .procname = "tracepoint_printk",
685 .data = &tracepoint_printk,
686 .maxlen = sizeof(tracepoint_printk),
688 .proc_handler = tracepoint_printk_sysctl,
691 #ifdef CONFIG_KEXEC_CORE
693 .procname = "kexec_load_disabled",
694 .data = &kexec_load_disabled,
695 .maxlen = sizeof(int),
697 /* only handle a transition from default "0" to "1" */
698 .proc_handler = proc_dointvec_minmax,
703 #ifdef CONFIG_MODULES
705 .procname = "modprobe",
706 .data = &modprobe_path,
707 .maxlen = KMOD_PATH_LEN,
709 .proc_handler = proc_dostring,
712 .procname = "modules_disabled",
713 .data = &modules_disabled,
714 .maxlen = sizeof(int),
716 /* only handle a transition from default "0" to "1" */
717 .proc_handler = proc_dointvec_minmax,
722 #ifdef CONFIG_UEVENT_HELPER
724 .procname = "hotplug",
725 .data = &uevent_helper,
726 .maxlen = UEVENT_HELPER_PATH_LEN,
728 .proc_handler = proc_dostring,
731 #ifdef CONFIG_CHR_DEV_SG
733 .procname = "sg-big-buff",
734 .data = &sg_big_buff,
735 .maxlen = sizeof (int),
737 .proc_handler = proc_dointvec,
740 #ifdef CONFIG_BSD_PROCESS_ACCT
744 .maxlen = 3*sizeof(int),
746 .proc_handler = proc_dointvec,
749 #ifdef CONFIG_MAGIC_SYSRQ
752 .data = &__sysrq_enabled,
753 .maxlen = sizeof (int),
755 .proc_handler = sysrq_sysctl_handler,
758 #ifdef CONFIG_PROC_SYSCTL
760 .procname = "cad_pid",
762 .maxlen = sizeof (int),
764 .proc_handler = proc_do_cad_pid,
768 .procname = "threads-max",
770 .maxlen = sizeof(int),
772 .proc_handler = sysctl_max_threads,
775 .procname = "random",
777 .child = random_table,
780 .procname = "usermodehelper",
782 .child = usermodehelper_table,
784 #ifdef CONFIG_FW_LOADER_USER_HELPER
786 .procname = "firmware_config",
788 .child = firmware_config_table,
792 .procname = "overflowuid",
793 .data = &overflowuid,
794 .maxlen = sizeof(int),
796 .proc_handler = proc_dointvec_minmax,
797 .extra1 = &minolduid,
798 .extra2 = &maxolduid,
801 .procname = "overflowgid",
802 .data = &overflowgid,
803 .maxlen = sizeof(int),
805 .proc_handler = proc_dointvec_minmax,
806 .extra1 = &minolduid,
807 .extra2 = &maxolduid,
810 #ifdef CONFIG_MATHEMU
812 .procname = "ieee_emulation_warnings",
813 .data = &sysctl_ieee_emulation_warnings,
814 .maxlen = sizeof(int),
816 .proc_handler = proc_dointvec,
820 .procname = "userprocess_debug",
821 .data = &show_unhandled_signals,
822 .maxlen = sizeof(int),
824 .proc_handler = proc_dointvec,
828 .procname = "pid_max",
830 .maxlen = sizeof (int),
832 .proc_handler = proc_dointvec_minmax,
833 .extra1 = &pid_max_min,
834 .extra2 = &pid_max_max,
837 .procname = "panic_on_oops",
838 .data = &panic_on_oops,
839 .maxlen = sizeof(int),
841 .proc_handler = proc_dointvec,
844 .procname = "panic_print",
845 .data = &panic_print,
846 .maxlen = sizeof(unsigned long),
848 .proc_handler = proc_doulongvec_minmax,
850 #if defined CONFIG_PRINTK
852 .procname = "printk",
853 .data = &console_loglevel,
854 .maxlen = 4*sizeof(int),
856 .proc_handler = proc_dointvec,
859 .procname = "printk_ratelimit",
860 .data = &printk_ratelimit_state.interval,
861 .maxlen = sizeof(int),
863 .proc_handler = proc_dointvec_jiffies,
866 .procname = "printk_ratelimit_burst",
867 .data = &printk_ratelimit_state.burst,
868 .maxlen = sizeof(int),
870 .proc_handler = proc_dointvec,
873 .procname = "printk_delay",
874 .data = &printk_delay_msec,
875 .maxlen = sizeof(int),
877 .proc_handler = proc_dointvec_minmax,
879 .extra2 = &ten_thousand,
882 .procname = "printk_devkmsg",
883 .data = devkmsg_log_str,
884 .maxlen = DEVKMSG_STR_MAX_SIZE,
886 .proc_handler = devkmsg_sysctl_set_loglvl,
889 .procname = "dmesg_restrict",
890 .data = &dmesg_restrict,
891 .maxlen = sizeof(int),
893 .proc_handler = proc_dointvec_minmax_sysadmin,
898 .procname = "kptr_restrict",
899 .data = &kptr_restrict,
900 .maxlen = sizeof(int),
902 .proc_handler = proc_dointvec_minmax_sysadmin,
908 .procname = "ngroups_max",
909 .data = &ngroups_max,
910 .maxlen = sizeof (int),
912 .proc_handler = proc_dointvec,
915 .procname = "cap_last_cap",
916 .data = (void *)&cap_last_cap,
917 .maxlen = sizeof(int),
919 .proc_handler = proc_dointvec,
921 #if defined(CONFIG_LOCKUP_DETECTOR)
923 .procname = "watchdog",
924 .data = &watchdog_user_enabled,
925 .maxlen = sizeof(int),
927 .proc_handler = proc_watchdog,
932 .procname = "watchdog_thresh",
933 .data = &watchdog_thresh,
934 .maxlen = sizeof(int),
936 .proc_handler = proc_watchdog_thresh,
941 .procname = "nmi_watchdog",
942 .data = &nmi_watchdog_user_enabled,
943 .maxlen = sizeof(int),
944 .mode = NMI_WATCHDOG_SYSCTL_PERM,
945 .proc_handler = proc_nmi_watchdog,
950 .procname = "watchdog_cpumask",
951 .data = &watchdog_cpumask_bits,
954 .proc_handler = proc_watchdog_cpumask,
956 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
958 .procname = "soft_watchdog",
959 .data = &soft_watchdog_user_enabled,
960 .maxlen = sizeof(int),
962 .proc_handler = proc_soft_watchdog,
967 .procname = "softlockup_panic",
968 .data = &softlockup_panic,
969 .maxlen = sizeof(int),
971 .proc_handler = proc_dointvec_minmax,
977 .procname = "softlockup_all_cpu_backtrace",
978 .data = &sysctl_softlockup_all_cpu_backtrace,
979 .maxlen = sizeof(int),
981 .proc_handler = proc_dointvec_minmax,
985 #endif /* CONFIG_SMP */
987 #ifdef CONFIG_HARDLOCKUP_DETECTOR
989 .procname = "hardlockup_panic",
990 .data = &hardlockup_panic,
991 .maxlen = sizeof(int),
993 .proc_handler = proc_dointvec_minmax,
999 .procname = "hardlockup_all_cpu_backtrace",
1000 .data = &sysctl_hardlockup_all_cpu_backtrace,
1001 .maxlen = sizeof(int),
1003 .proc_handler = proc_dointvec_minmax,
1007 #endif /* CONFIG_SMP */
1011 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1013 .procname = "unknown_nmi_panic",
1014 .data = &unknown_nmi_panic,
1015 .maxlen = sizeof (int),
1017 .proc_handler = proc_dointvec,
1020 #if defined(CONFIG_X86)
1022 .procname = "panic_on_unrecovered_nmi",
1023 .data = &panic_on_unrecovered_nmi,
1024 .maxlen = sizeof(int),
1026 .proc_handler = proc_dointvec,
1029 .procname = "panic_on_io_nmi",
1030 .data = &panic_on_io_nmi,
1031 .maxlen = sizeof(int),
1033 .proc_handler = proc_dointvec,
1035 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1037 .procname = "panic_on_stackoverflow",
1038 .data = &sysctl_panic_on_stackoverflow,
1039 .maxlen = sizeof(int),
1041 .proc_handler = proc_dointvec,
1045 .procname = "bootloader_type",
1046 .data = &bootloader_type,
1047 .maxlen = sizeof (int),
1049 .proc_handler = proc_dointvec,
1052 .procname = "bootloader_version",
1053 .data = &bootloader_version,
1054 .maxlen = sizeof (int),
1056 .proc_handler = proc_dointvec,
1059 .procname = "io_delay_type",
1060 .data = &io_delay_type,
1061 .maxlen = sizeof(int),
1063 .proc_handler = proc_dointvec,
1066 #if defined(CONFIG_MMU)
1068 .procname = "randomize_va_space",
1069 .data = &randomize_va_space,
1070 .maxlen = sizeof(int),
1072 .proc_handler = proc_dointvec,
1075 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1077 .procname = "spin_retry",
1078 .data = &spin_retry,
1079 .maxlen = sizeof (int),
1081 .proc_handler = proc_dointvec,
1084 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1086 .procname = "acpi_video_flags",
1087 .data = &acpi_realmode_flags,
1088 .maxlen = sizeof (unsigned long),
1090 .proc_handler = proc_doulongvec_minmax,
1093 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1095 .procname = "ignore-unaligned-usertrap",
1096 .data = &no_unaligned_warning,
1097 .maxlen = sizeof (int),
1099 .proc_handler = proc_dointvec,
1104 .procname = "unaligned-dump-stack",
1105 .data = &unaligned_dump_stack,
1106 .maxlen = sizeof (int),
1108 .proc_handler = proc_dointvec,
1111 #ifdef CONFIG_DETECT_HUNG_TASK
1113 .procname = "hung_task_panic",
1114 .data = &sysctl_hung_task_panic,
1115 .maxlen = sizeof(int),
1117 .proc_handler = proc_dointvec_minmax,
1122 .procname = "hung_task_check_count",
1123 .data = &sysctl_hung_task_check_count,
1124 .maxlen = sizeof(int),
1126 .proc_handler = proc_dointvec_minmax,
1130 .procname = "hung_task_timeout_secs",
1131 .data = &sysctl_hung_task_timeout_secs,
1132 .maxlen = sizeof(unsigned long),
1134 .proc_handler = proc_dohung_task_timeout_secs,
1135 .extra2 = &hung_task_timeout_max,
1138 .procname = "hung_task_check_interval_secs",
1139 .data = &sysctl_hung_task_check_interval_secs,
1140 .maxlen = sizeof(unsigned long),
1142 .proc_handler = proc_dohung_task_timeout_secs,
1143 .extra2 = &hung_task_timeout_max,
1146 .procname = "hung_task_warnings",
1147 .data = &sysctl_hung_task_warnings,
1148 .maxlen = sizeof(int),
1150 .proc_handler = proc_dointvec_minmax,
1154 #ifdef CONFIG_RT_MUTEXES
1156 .procname = "max_lock_depth",
1157 .data = &max_lock_depth,
1158 .maxlen = sizeof(int),
1160 .proc_handler = proc_dointvec,
1164 .procname = "poweroff_cmd",
1165 .data = &poweroff_cmd,
1166 .maxlen = POWEROFF_CMD_PATH_LEN,
1168 .proc_handler = proc_dostring,
1174 .child = key_sysctls,
1177 #ifdef CONFIG_PERF_EVENTS
1179 * User-space scripts rely on the existence of this file
1180 * as a feature check for perf_events being enabled.
1182 * So it's an ABI, do not remove!
1185 .procname = "perf_event_paranoid",
1186 .data = &sysctl_perf_event_paranoid,
1187 .maxlen = sizeof(sysctl_perf_event_paranoid),
1189 .proc_handler = proc_dointvec,
1192 .procname = "perf_event_mlock_kb",
1193 .data = &sysctl_perf_event_mlock,
1194 .maxlen = sizeof(sysctl_perf_event_mlock),
1196 .proc_handler = proc_dointvec,
1199 .procname = "perf_event_max_sample_rate",
1200 .data = &sysctl_perf_event_sample_rate,
1201 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1203 .proc_handler = perf_proc_update_handler,
1207 .procname = "perf_cpu_time_max_percent",
1208 .data = &sysctl_perf_cpu_time_max_percent,
1209 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1211 .proc_handler = perf_cpu_time_max_percent_handler,
1213 .extra2 = &one_hundred,
1216 .procname = "perf_event_max_stack",
1217 .data = &sysctl_perf_event_max_stack,
1218 .maxlen = sizeof(sysctl_perf_event_max_stack),
1220 .proc_handler = perf_event_max_stack_handler,
1222 .extra2 = &six_hundred_forty_kb,
1225 .procname = "perf_event_max_contexts_per_stack",
1226 .data = &sysctl_perf_event_max_contexts_per_stack,
1227 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
1229 .proc_handler = perf_event_max_stack_handler,
1231 .extra2 = &one_thousand,
1235 .procname = "panic_on_warn",
1236 .data = &panic_on_warn,
1237 .maxlen = sizeof(int),
1239 .proc_handler = proc_dointvec_minmax,
1243 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1245 .procname = "timer_migration",
1246 .data = &sysctl_timer_migration,
1247 .maxlen = sizeof(unsigned int),
1249 .proc_handler = timer_migration_handler,
1254 #ifdef CONFIG_BPF_SYSCALL
1256 .procname = "unprivileged_bpf_disabled",
1257 .data = &sysctl_unprivileged_bpf_disabled,
1258 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1260 /* only handle a transition from default "0" to "1" */
1261 .proc_handler = proc_dointvec_minmax,
1266 .procname = "bpf_stats_enabled",
1267 .data = &bpf_stats_enabled_key.key,
1268 .maxlen = sizeof(bpf_stats_enabled_key),
1270 .proc_handler = proc_do_static_key,
1273 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1275 .procname = "panic_on_rcu_stall",
1276 .data = &sysctl_panic_on_rcu_stall,
1277 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1279 .proc_handler = proc_dointvec_minmax,
1284 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1286 .procname = "stack_erasing",
1288 .maxlen = sizeof(int),
1290 .proc_handler = stack_erasing_sysctl,
1298 static struct ctl_table vm_table[] = {
1300 .procname = "overcommit_memory",
1301 .data = &sysctl_overcommit_memory,
1302 .maxlen = sizeof(sysctl_overcommit_memory),
1304 .proc_handler = proc_dointvec_minmax,
1309 .procname = "panic_on_oom",
1310 .data = &sysctl_panic_on_oom,
1311 .maxlen = sizeof(sysctl_panic_on_oom),
1313 .proc_handler = proc_dointvec_minmax,
1318 .procname = "oom_kill_allocating_task",
1319 .data = &sysctl_oom_kill_allocating_task,
1320 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1322 .proc_handler = proc_dointvec,
1325 .procname = "oom_dump_tasks",
1326 .data = &sysctl_oom_dump_tasks,
1327 .maxlen = sizeof(sysctl_oom_dump_tasks),
1329 .proc_handler = proc_dointvec,
1332 .procname = "overcommit_ratio",
1333 .data = &sysctl_overcommit_ratio,
1334 .maxlen = sizeof(sysctl_overcommit_ratio),
1336 .proc_handler = overcommit_ratio_handler,
1339 .procname = "overcommit_kbytes",
1340 .data = &sysctl_overcommit_kbytes,
1341 .maxlen = sizeof(sysctl_overcommit_kbytes),
1343 .proc_handler = overcommit_kbytes_handler,
1346 .procname = "page-cluster",
1347 .data = &page_cluster,
1348 .maxlen = sizeof(int),
1350 .proc_handler = proc_dointvec_minmax,
1354 .procname = "dirty_background_ratio",
1355 .data = &dirty_background_ratio,
1356 .maxlen = sizeof(dirty_background_ratio),
1358 .proc_handler = dirty_background_ratio_handler,
1360 .extra2 = &one_hundred,
1363 .procname = "dirty_background_bytes",
1364 .data = &dirty_background_bytes,
1365 .maxlen = sizeof(dirty_background_bytes),
1367 .proc_handler = dirty_background_bytes_handler,
1371 .procname = "dirty_ratio",
1372 .data = &vm_dirty_ratio,
1373 .maxlen = sizeof(vm_dirty_ratio),
1375 .proc_handler = dirty_ratio_handler,
1377 .extra2 = &one_hundred,
1380 .procname = "dirty_bytes",
1381 .data = &vm_dirty_bytes,
1382 .maxlen = sizeof(vm_dirty_bytes),
1384 .proc_handler = dirty_bytes_handler,
1385 .extra1 = &dirty_bytes_min,
1388 .procname = "dirty_writeback_centisecs",
1389 .data = &dirty_writeback_interval,
1390 .maxlen = sizeof(dirty_writeback_interval),
1392 .proc_handler = dirty_writeback_centisecs_handler,
1395 .procname = "dirty_expire_centisecs",
1396 .data = &dirty_expire_interval,
1397 .maxlen = sizeof(dirty_expire_interval),
1399 .proc_handler = proc_dointvec_minmax,
1403 .procname = "dirtytime_expire_seconds",
1404 .data = &dirtytime_expire_interval,
1405 .maxlen = sizeof(dirtytime_expire_interval),
1407 .proc_handler = dirtytime_interval_handler,
1411 .procname = "swappiness",
1412 .data = &vm_swappiness,
1413 .maxlen = sizeof(vm_swappiness),
1415 .proc_handler = proc_dointvec_minmax,
1417 .extra2 = &one_hundred,
1419 #ifdef CONFIG_HUGETLB_PAGE
1421 .procname = "nr_hugepages",
1423 .maxlen = sizeof(unsigned long),
1425 .proc_handler = hugetlb_sysctl_handler,
1429 .procname = "nr_hugepages_mempolicy",
1431 .maxlen = sizeof(unsigned long),
1433 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1436 .procname = "numa_stat",
1437 .data = &sysctl_vm_numa_stat,
1438 .maxlen = sizeof(int),
1440 .proc_handler = sysctl_vm_numa_stat_handler,
1446 .procname = "hugetlb_shm_group",
1447 .data = &sysctl_hugetlb_shm_group,
1448 .maxlen = sizeof(gid_t),
1450 .proc_handler = proc_dointvec,
1453 .procname = "nr_overcommit_hugepages",
1455 .maxlen = sizeof(unsigned long),
1457 .proc_handler = hugetlb_overcommit_handler,
1461 .procname = "lowmem_reserve_ratio",
1462 .data = &sysctl_lowmem_reserve_ratio,
1463 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1465 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1468 .procname = "drop_caches",
1469 .data = &sysctl_drop_caches,
1470 .maxlen = sizeof(int),
1472 .proc_handler = drop_caches_sysctl_handler,
1476 #ifdef CONFIG_COMPACTION
1478 .procname = "compact_memory",
1479 .data = &sysctl_compact_memory,
1480 .maxlen = sizeof(int),
1482 .proc_handler = sysctl_compaction_handler,
1485 .procname = "extfrag_threshold",
1486 .data = &sysctl_extfrag_threshold,
1487 .maxlen = sizeof(int),
1489 .proc_handler = proc_dointvec_minmax,
1490 .extra1 = &min_extfrag_threshold,
1491 .extra2 = &max_extfrag_threshold,
1494 .procname = "compact_unevictable_allowed",
1495 .data = &sysctl_compact_unevictable_allowed,
1496 .maxlen = sizeof(int),
1498 .proc_handler = proc_dointvec,
1503 #endif /* CONFIG_COMPACTION */
1505 .procname = "min_free_kbytes",
1506 .data = &min_free_kbytes,
1507 .maxlen = sizeof(min_free_kbytes),
1509 .proc_handler = min_free_kbytes_sysctl_handler,
1513 .procname = "watermark_boost_factor",
1514 .data = &watermark_boost_factor,
1515 .maxlen = sizeof(watermark_boost_factor),
1517 .proc_handler = watermark_boost_factor_sysctl_handler,
1521 .procname = "watermark_scale_factor",
1522 .data = &watermark_scale_factor,
1523 .maxlen = sizeof(watermark_scale_factor),
1525 .proc_handler = watermark_scale_factor_sysctl_handler,
1527 .extra2 = &one_thousand,
1530 .procname = "percpu_pagelist_fraction",
1531 .data = &percpu_pagelist_fraction,
1532 .maxlen = sizeof(percpu_pagelist_fraction),
1534 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1539 .procname = "max_map_count",
1540 .data = &sysctl_max_map_count,
1541 .maxlen = sizeof(sysctl_max_map_count),
1543 .proc_handler = proc_dointvec_minmax,
1548 .procname = "nr_trim_pages",
1549 .data = &sysctl_nr_trim_pages,
1550 .maxlen = sizeof(sysctl_nr_trim_pages),
1552 .proc_handler = proc_dointvec_minmax,
1557 .procname = "laptop_mode",
1558 .data = &laptop_mode,
1559 .maxlen = sizeof(laptop_mode),
1561 .proc_handler = proc_dointvec_jiffies,
1564 .procname = "block_dump",
1565 .data = &block_dump,
1566 .maxlen = sizeof(block_dump),
1568 .proc_handler = proc_dointvec,
1572 .procname = "vfs_cache_pressure",
1573 .data = &sysctl_vfs_cache_pressure,
1574 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1576 .proc_handler = proc_dointvec,
1579 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1581 .procname = "legacy_va_layout",
1582 .data = &sysctl_legacy_va_layout,
1583 .maxlen = sizeof(sysctl_legacy_va_layout),
1585 .proc_handler = proc_dointvec,
1591 .procname = "zone_reclaim_mode",
1592 .data = &node_reclaim_mode,
1593 .maxlen = sizeof(node_reclaim_mode),
1595 .proc_handler = proc_dointvec,
1599 .procname = "min_unmapped_ratio",
1600 .data = &sysctl_min_unmapped_ratio,
1601 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1603 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1605 .extra2 = &one_hundred,
1608 .procname = "min_slab_ratio",
1609 .data = &sysctl_min_slab_ratio,
1610 .maxlen = sizeof(sysctl_min_slab_ratio),
1612 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1614 .extra2 = &one_hundred,
1619 .procname = "stat_interval",
1620 .data = &sysctl_stat_interval,
1621 .maxlen = sizeof(sysctl_stat_interval),
1623 .proc_handler = proc_dointvec_jiffies,
1626 .procname = "stat_refresh",
1630 .proc_handler = vmstat_refresh,
1635 .procname = "mmap_min_addr",
1636 .data = &dac_mmap_min_addr,
1637 .maxlen = sizeof(unsigned long),
1639 .proc_handler = mmap_min_addr_handler,
1644 .procname = "numa_zonelist_order",
1645 .data = &numa_zonelist_order,
1646 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1648 .proc_handler = numa_zonelist_order_handler,
1651 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1652 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1654 .procname = "vdso_enabled",
1655 #ifdef CONFIG_X86_32
1656 .data = &vdso32_enabled,
1657 .maxlen = sizeof(vdso32_enabled),
1659 .data = &vdso_enabled,
1660 .maxlen = sizeof(vdso_enabled),
1663 .proc_handler = proc_dointvec,
1667 #ifdef CONFIG_HIGHMEM
1669 .procname = "highmem_is_dirtyable",
1670 .data = &vm_highmem_is_dirtyable,
1671 .maxlen = sizeof(vm_highmem_is_dirtyable),
1673 .proc_handler = proc_dointvec_minmax,
1678 #ifdef CONFIG_MEMORY_FAILURE
1680 .procname = "memory_failure_early_kill",
1681 .data = &sysctl_memory_failure_early_kill,
1682 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1684 .proc_handler = proc_dointvec_minmax,
1689 .procname = "memory_failure_recovery",
1690 .data = &sysctl_memory_failure_recovery,
1691 .maxlen = sizeof(sysctl_memory_failure_recovery),
1693 .proc_handler = proc_dointvec_minmax,
1699 .procname = "user_reserve_kbytes",
1700 .data = &sysctl_user_reserve_kbytes,
1701 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1703 .proc_handler = proc_doulongvec_minmax,
1706 .procname = "admin_reserve_kbytes",
1707 .data = &sysctl_admin_reserve_kbytes,
1708 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1710 .proc_handler = proc_doulongvec_minmax,
1712 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1714 .procname = "mmap_rnd_bits",
1715 .data = &mmap_rnd_bits,
1716 .maxlen = sizeof(mmap_rnd_bits),
1718 .proc_handler = proc_dointvec_minmax,
1719 .extra1 = (void *)&mmap_rnd_bits_min,
1720 .extra2 = (void *)&mmap_rnd_bits_max,
1723 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1725 .procname = "mmap_rnd_compat_bits",
1726 .data = &mmap_rnd_compat_bits,
1727 .maxlen = sizeof(mmap_rnd_compat_bits),
1729 .proc_handler = proc_dointvec_minmax,
1730 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1731 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1734 #ifdef CONFIG_USERFAULTFD
1736 .procname = "unprivileged_userfaultfd",
1737 .data = &sysctl_unprivileged_userfaultfd,
1738 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
1740 .proc_handler = proc_dointvec_minmax,
1748 static struct ctl_table fs_table[] = {
1750 .procname = "inode-nr",
1751 .data = &inodes_stat,
1752 .maxlen = 2*sizeof(long),
1754 .proc_handler = proc_nr_inodes,
1757 .procname = "inode-state",
1758 .data = &inodes_stat,
1759 .maxlen = 7*sizeof(long),
1761 .proc_handler = proc_nr_inodes,
1764 .procname = "file-nr",
1765 .data = &files_stat,
1766 .maxlen = sizeof(files_stat),
1768 .proc_handler = proc_nr_files,
1771 .procname = "file-max",
1772 .data = &files_stat.max_files,
1773 .maxlen = sizeof(files_stat.max_files),
1775 .proc_handler = proc_doulongvec_minmax,
1777 .extra2 = &long_max,
1780 .procname = "nr_open",
1781 .data = &sysctl_nr_open,
1782 .maxlen = sizeof(unsigned int),
1784 .proc_handler = proc_dointvec_minmax,
1785 .extra1 = &sysctl_nr_open_min,
1786 .extra2 = &sysctl_nr_open_max,
1789 .procname = "dentry-state",
1790 .data = &dentry_stat,
1791 .maxlen = 6*sizeof(long),
1793 .proc_handler = proc_nr_dentry,
1796 .procname = "overflowuid",
1797 .data = &fs_overflowuid,
1798 .maxlen = sizeof(int),
1800 .proc_handler = proc_dointvec_minmax,
1801 .extra1 = &minolduid,
1802 .extra2 = &maxolduid,
1805 .procname = "overflowgid",
1806 .data = &fs_overflowgid,
1807 .maxlen = sizeof(int),
1809 .proc_handler = proc_dointvec_minmax,
1810 .extra1 = &minolduid,
1811 .extra2 = &maxolduid,
1813 #ifdef CONFIG_FILE_LOCKING
1815 .procname = "leases-enable",
1816 .data = &leases_enable,
1817 .maxlen = sizeof(int),
1819 .proc_handler = proc_dointvec,
1822 #ifdef CONFIG_DNOTIFY
1824 .procname = "dir-notify-enable",
1825 .data = &dir_notify_enable,
1826 .maxlen = sizeof(int),
1828 .proc_handler = proc_dointvec,
1832 #ifdef CONFIG_FILE_LOCKING
1834 .procname = "lease-break-time",
1835 .data = &lease_break_time,
1836 .maxlen = sizeof(int),
1838 .proc_handler = proc_dointvec,
1843 .procname = "aio-nr",
1845 .maxlen = sizeof(aio_nr),
1847 .proc_handler = proc_doulongvec_minmax,
1850 .procname = "aio-max-nr",
1851 .data = &aio_max_nr,
1852 .maxlen = sizeof(aio_max_nr),
1854 .proc_handler = proc_doulongvec_minmax,
1856 #endif /* CONFIG_AIO */
1857 #ifdef CONFIG_INOTIFY_USER
1859 .procname = "inotify",
1861 .child = inotify_table,
1866 .procname = "epoll",
1868 .child = epoll_table,
1873 .procname = "protected_symlinks",
1874 .data = &sysctl_protected_symlinks,
1875 .maxlen = sizeof(int),
1877 .proc_handler = proc_dointvec_minmax,
1882 .procname = "protected_hardlinks",
1883 .data = &sysctl_protected_hardlinks,
1884 .maxlen = sizeof(int),
1886 .proc_handler = proc_dointvec_minmax,
1891 .procname = "protected_fifos",
1892 .data = &sysctl_protected_fifos,
1893 .maxlen = sizeof(int),
1895 .proc_handler = proc_dointvec_minmax,
1900 .procname = "protected_regular",
1901 .data = &sysctl_protected_regular,
1902 .maxlen = sizeof(int),
1904 .proc_handler = proc_dointvec_minmax,
1909 .procname = "suid_dumpable",
1910 .data = &suid_dumpable,
1911 .maxlen = sizeof(int),
1913 .proc_handler = proc_dointvec_minmax_coredump,
1917 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1919 .procname = "binfmt_misc",
1921 .child = sysctl_mount_point,
1925 .procname = "pipe-max-size",
1926 .data = &pipe_max_size,
1927 .maxlen = sizeof(pipe_max_size),
1929 .proc_handler = proc_dopipe_max_size,
1932 .procname = "pipe-user-pages-hard",
1933 .data = &pipe_user_pages_hard,
1934 .maxlen = sizeof(pipe_user_pages_hard),
1936 .proc_handler = proc_doulongvec_minmax,
1939 .procname = "pipe-user-pages-soft",
1940 .data = &pipe_user_pages_soft,
1941 .maxlen = sizeof(pipe_user_pages_soft),
1943 .proc_handler = proc_doulongvec_minmax,
1946 .procname = "mount-max",
1947 .data = &sysctl_mount_max,
1948 .maxlen = sizeof(unsigned int),
1950 .proc_handler = proc_dointvec_minmax,
1956 static struct ctl_table debug_table[] = {
1957 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1959 .procname = "exception-trace",
1960 .data = &show_unhandled_signals,
1961 .maxlen = sizeof(int),
1963 .proc_handler = proc_dointvec
1966 #if defined(CONFIG_OPTPROBES)
1968 .procname = "kprobes-optimization",
1969 .data = &sysctl_kprobes_optimization,
1970 .maxlen = sizeof(int),
1972 .proc_handler = proc_kprobes_optimization_handler,
1980 static struct ctl_table dev_table[] = {
1984 int __init sysctl_init(void)
1986 struct ctl_table_header *hdr;
1988 hdr = register_sysctl_table(sysctl_base_table);
1989 kmemleak_not_leak(hdr);
1993 #endif /* CONFIG_SYSCTL */
1999 #ifdef CONFIG_PROC_SYSCTL
2001 static int _proc_do_string(char *data, int maxlen, int write,
2002 char __user *buffer,
2003 size_t *lenp, loff_t *ppos)
2009 if (!data || !maxlen || !*lenp) {
2015 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
2016 /* Only continue writes not past the end of buffer. */
2018 if (len > maxlen - 1)
2025 /* Start writing from beginning of buffer. */
2031 while ((p - buffer) < *lenp && len < maxlen - 1) {
2032 if (get_user(c, p++))
2034 if (c == 0 || c == '\n')
2055 if (copy_to_user(buffer, data, len))
2058 if (put_user('\n', buffer + len))
2068 static void warn_sysctl_write(struct ctl_table *table)
2070 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2071 "This will not be supported in the future. To silence this\n"
2072 "warning, set kernel.sysctl_writes_strict = -1\n",
2073 current->comm, table->procname);
2077 * proc_first_pos_non_zero_ignore - check if first position is allowed
2078 * @ppos: file position
2079 * @table: the sysctl table
2081 * Returns true if the first position is non-zero and the sysctl_writes_strict
2082 * mode indicates this is not allowed for numeric input types. String proc
2083 * handlers can ignore the return value.
2085 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2086 struct ctl_table *table)
2091 switch (sysctl_writes_strict) {
2092 case SYSCTL_WRITES_STRICT:
2094 case SYSCTL_WRITES_WARN:
2095 warn_sysctl_write(table);
2103 * proc_dostring - read a string sysctl
2104 * @table: the sysctl table
2105 * @write: %TRUE if this is a write to the sysctl file
2106 * @buffer: the user buffer
2107 * @lenp: the size of the user buffer
2108 * @ppos: file position
2110 * Reads/writes a string from/to the user buffer. If the kernel
2111 * buffer provided is not large enough to hold the string, the
2112 * string is truncated. The copied string is %NULL-terminated.
2113 * If the string is being read by the user process, it is copied
2114 * and a newline '\n' is added. It is truncated if the buffer is
2117 * Returns 0 on success.
2119 int proc_dostring(struct ctl_table *table, int write,
2120 void __user *buffer, size_t *lenp, loff_t *ppos)
2123 proc_first_pos_non_zero_ignore(ppos, table);
2125 return _proc_do_string((char *)(table->data), table->maxlen, write,
2126 (char __user *)buffer, lenp, ppos);
2129 static size_t proc_skip_spaces(char **buf)
2132 char *tmp = skip_spaces(*buf);
2138 static void proc_skip_char(char **buf, size_t *size, const char v)
2149 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2152 * @cp: kernel buffer containing the string to parse
2153 * @endp: pointer to store the trailing characters
2154 * @base: the base to use
2155 * @res: where the parsed integer will be stored
2157 * In case of success 0 is returned and @res will contain the parsed integer,
2158 * @endp will hold any trailing characters.
2159 * This function will fail the parse on overflow. If there wasn't an overflow
2160 * the function will defer the decision what characters count as invalid to the
2163 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2166 unsigned long long result;
2169 cp = _parse_integer_fixup_radix(cp, &base);
2170 rv = _parse_integer(cp, base, &result);
2171 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2179 *res = (unsigned long)result;
2183 #define TMPBUFLEN 22
2185 * proc_get_long - reads an ASCII formatted integer from a user buffer
2187 * @buf: a kernel buffer
2188 * @size: size of the kernel buffer
2189 * @val: this is where the number will be stored
2190 * @neg: set to %TRUE if number is negative
2191 * @perm_tr: a vector which contains the allowed trailers
2192 * @perm_tr_len: size of the perm_tr vector
2193 * @tr: pointer to store the trailer character
2195 * In case of success %0 is returned and @buf and @size are updated with
2196 * the amount of bytes read. If @tr is non-NULL and a trailing
2197 * character exists (size is non-zero after returning from this
2198 * function), @tr is updated with the trailing character.
2200 static int proc_get_long(char **buf, size_t *size,
2201 unsigned long *val, bool *neg,
2202 const char *perm_tr, unsigned perm_tr_len, char *tr)
2205 char *p, tmp[TMPBUFLEN];
2211 if (len > TMPBUFLEN - 1)
2212 len = TMPBUFLEN - 1;
2214 memcpy(tmp, *buf, len);
2218 if (*p == '-' && *size > 1) {
2226 if (strtoul_lenient(p, &p, 0, val))
2231 /* We don't know if the next char is whitespace thus we may accept
2232 * invalid integers (e.g. 1234...a) or two integers instead of one
2233 * (e.g. 123...1). So lets not allow such large numbers. */
2234 if (len == TMPBUFLEN - 1)
2237 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2240 if (tr && (len < *size))
2250 * proc_put_long - converts an integer to a decimal ASCII formatted string
2252 * @buf: the user buffer
2253 * @size: the size of the user buffer
2254 * @val: the integer to be converted
2255 * @neg: sign of the number, %TRUE for negative
2257 * In case of success %0 is returned and @buf and @size are updated with
2258 * the amount of bytes written.
2260 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2264 char tmp[TMPBUFLEN], *p = tmp;
2266 sprintf(p, "%s%lu", neg ? "-" : "", val);
2270 if (copy_to_user(*buf, tmp, len))
2278 static int proc_put_char(void __user **buf, size_t *size, char c)
2281 char __user **buffer = (char __user **)buf;
2282 if (put_user(c, *buffer))
2284 (*size)--, (*buffer)++;
2290 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2292 int write, void *data)
2296 if (*lvalp > (unsigned long) INT_MAX + 1)
2300 if (*lvalp > (unsigned long) INT_MAX)
2308 *lvalp = -(unsigned long)val;
2311 *lvalp = (unsigned long)val;
2317 static int do_proc_douintvec_conv(unsigned long *lvalp,
2319 int write, void *data)
2322 if (*lvalp > UINT_MAX)
2326 unsigned int val = *valp;
2327 *lvalp = (unsigned long)val;
2332 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2334 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2335 int write, void __user *buffer,
2336 size_t *lenp, loff_t *ppos,
2337 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2338 int write, void *data),
2341 int *i, vleft, first = 1, err = 0;
2343 char *kbuf = NULL, *p;
2345 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2350 i = (int *) tbl_data;
2351 vleft = table->maxlen / sizeof(*i);
2355 conv = do_proc_dointvec_conv;
2358 if (proc_first_pos_non_zero_ignore(ppos, table))
2361 if (left > PAGE_SIZE - 1)
2362 left = PAGE_SIZE - 1;
2363 p = kbuf = memdup_user_nul(buffer, left);
2365 return PTR_ERR(kbuf);
2368 for (; left && vleft--; i++, first=0) {
2373 left -= proc_skip_spaces(&p);
2377 err = proc_get_long(&p, &left, &lval, &neg,
2379 sizeof(proc_wspace_sep), NULL);
2382 if (conv(&neg, &lval, i, 1, data)) {
2387 if (conv(&neg, &lval, i, 0, data)) {
2392 err = proc_put_char(&buffer, &left, '\t');
2395 err = proc_put_long(&buffer, &left, lval, neg);
2401 if (!write && !first && left && !err)
2402 err = proc_put_char(&buffer, &left, '\n');
2403 if (write && !err && left)
2404 left -= proc_skip_spaces(&p);
2408 return err ? : -EINVAL;
2416 static int do_proc_dointvec(struct ctl_table *table, int write,
2417 void __user *buffer, size_t *lenp, loff_t *ppos,
2418 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2419 int write, void *data),
2422 return __do_proc_dointvec(table->data, table, write,
2423 buffer, lenp, ppos, conv, data);
2426 static int do_proc_douintvec_w(unsigned int *tbl_data,
2427 struct ctl_table *table,
2428 void __user *buffer,
2429 size_t *lenp, loff_t *ppos,
2430 int (*conv)(unsigned long *lvalp,
2432 int write, void *data),
2439 char *kbuf = NULL, *p;
2443 if (proc_first_pos_non_zero_ignore(ppos, table))
2446 if (left > PAGE_SIZE - 1)
2447 left = PAGE_SIZE - 1;
2449 p = kbuf = memdup_user_nul(buffer, left);
2453 left -= proc_skip_spaces(&p);
2459 err = proc_get_long(&p, &left, &lval, &neg,
2461 sizeof(proc_wspace_sep), NULL);
2467 if (conv(&lval, tbl_data, 1, data)) {
2473 left -= proc_skip_spaces(&p);
2482 /* This is in keeping with old __do_proc_dointvec() */
2488 static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2489 size_t *lenp, loff_t *ppos,
2490 int (*conv)(unsigned long *lvalp,
2492 int write, void *data),
2501 if (conv(&lval, tbl_data, 0, data)) {
2506 err = proc_put_long(&buffer, &left, lval, false);
2510 err = proc_put_char(&buffer, &left, '\n');
2519 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2520 int write, void __user *buffer,
2521 size_t *lenp, loff_t *ppos,
2522 int (*conv)(unsigned long *lvalp,
2524 int write, void *data),
2527 unsigned int *i, vleft;
2529 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2534 i = (unsigned int *) tbl_data;
2535 vleft = table->maxlen / sizeof(*i);
2538 * Arrays are not supported, keep this simple. *Do not* add
2547 conv = do_proc_douintvec_conv;
2550 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2552 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2555 static int do_proc_douintvec(struct ctl_table *table, int write,
2556 void __user *buffer, size_t *lenp, loff_t *ppos,
2557 int (*conv)(unsigned long *lvalp,
2559 int write, void *data),
2562 return __do_proc_douintvec(table->data, table, write,
2563 buffer, lenp, ppos, conv, data);
2567 * proc_dointvec - read a vector of integers
2568 * @table: the sysctl table
2569 * @write: %TRUE if this is a write to the sysctl file
2570 * @buffer: the user buffer
2571 * @lenp: the size of the user buffer
2572 * @ppos: file position
2574 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2575 * values from/to the user buffer, treated as an ASCII string.
2577 * Returns 0 on success.
2579 int proc_dointvec(struct ctl_table *table, int write,
2580 void __user *buffer, size_t *lenp, loff_t *ppos)
2582 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2586 * proc_douintvec - read a vector of unsigned integers
2587 * @table: the sysctl table
2588 * @write: %TRUE if this is a write to the sysctl file
2589 * @buffer: the user buffer
2590 * @lenp: the size of the user buffer
2591 * @ppos: file position
2593 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2594 * values from/to the user buffer, treated as an ASCII string.
2596 * Returns 0 on success.
2598 int proc_douintvec(struct ctl_table *table, int write,
2599 void __user *buffer, size_t *lenp, loff_t *ppos)
2601 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2602 do_proc_douintvec_conv, NULL);
2606 * Taint values can only be increased
2607 * This means we can safely use a temporary.
2609 static int proc_taint(struct ctl_table *table, int write,
2610 void __user *buffer, size_t *lenp, loff_t *ppos)
2613 unsigned long tmptaint = get_taint();
2616 if (write && !capable(CAP_SYS_ADMIN))
2621 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2627 * Poor man's atomic or. Not worth adding a primitive
2628 * to everyone's atomic.h for this
2631 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2632 if ((tmptaint >> i) & 1)
2633 add_taint(i, LOCKDEP_STILL_OK);
2640 #ifdef CONFIG_PRINTK
2641 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2642 void __user *buffer, size_t *lenp, loff_t *ppos)
2644 if (write && !capable(CAP_SYS_ADMIN))
2647 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2652 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2653 * @min: pointer to minimum allowable value
2654 * @max: pointer to maximum allowable value
2656 * The do_proc_dointvec_minmax_conv_param structure provides the
2657 * minimum and maximum values for doing range checking for those sysctl
2658 * parameters that use the proc_dointvec_minmax() handler.
2660 struct do_proc_dointvec_minmax_conv_param {
2665 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2667 int write, void *data)
2670 struct do_proc_dointvec_minmax_conv_param *param = data;
2672 * If writing, first do so via a temporary local int so we can
2673 * bounds-check it before touching *valp.
2675 int *ip = write ? &tmp : valp;
2677 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
2682 if ((param->min && *param->min > tmp) ||
2683 (param->max && *param->max < tmp))
2692 * proc_dointvec_minmax - read a vector of integers with min/max values
2693 * @table: the sysctl table
2694 * @write: %TRUE if this is a write to the sysctl file
2695 * @buffer: the user buffer
2696 * @lenp: the size of the user buffer
2697 * @ppos: file position
2699 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2700 * values from/to the user buffer, treated as an ASCII string.
2702 * This routine will ensure the values are within the range specified by
2703 * table->extra1 (min) and table->extra2 (max).
2705 * Returns 0 on success or -EINVAL on write when the range check fails.
2707 int proc_dointvec_minmax(struct ctl_table *table, int write,
2708 void __user *buffer, size_t *lenp, loff_t *ppos)
2710 struct do_proc_dointvec_minmax_conv_param param = {
2711 .min = (int *) table->extra1,
2712 .max = (int *) table->extra2,
2714 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2715 do_proc_dointvec_minmax_conv, ¶m);
2719 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2720 * @min: pointer to minimum allowable value
2721 * @max: pointer to maximum allowable value
2723 * The do_proc_douintvec_minmax_conv_param structure provides the
2724 * minimum and maximum values for doing range checking for those sysctl
2725 * parameters that use the proc_douintvec_minmax() handler.
2727 struct do_proc_douintvec_minmax_conv_param {
2732 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2734 int write, void *data)
2738 struct do_proc_douintvec_minmax_conv_param *param = data;
2739 /* write via temporary local uint for bounds-checking */
2740 unsigned int *up = write ? &tmp : valp;
2742 ret = do_proc_douintvec_conv(lvalp, up, write, data);
2747 if ((param->min && *param->min > tmp) ||
2748 (param->max && *param->max < tmp))
2758 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2759 * @table: the sysctl table
2760 * @write: %TRUE if this is a write to the sysctl file
2761 * @buffer: the user buffer
2762 * @lenp: the size of the user buffer
2763 * @ppos: file position
2765 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2766 * values from/to the user buffer, treated as an ASCII string. Negative
2767 * strings are not allowed.
2769 * This routine will ensure the values are within the range specified by
2770 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2771 * check for UINT_MAX to avoid having to support wrap around uses from
2774 * Returns 0 on success or -ERANGE on write when the range check fails.
2776 int proc_douintvec_minmax(struct ctl_table *table, int write,
2777 void __user *buffer, size_t *lenp, loff_t *ppos)
2779 struct do_proc_douintvec_minmax_conv_param param = {
2780 .min = (unsigned int *) table->extra1,
2781 .max = (unsigned int *) table->extra2,
2783 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2784 do_proc_douintvec_minmax_conv, ¶m);
2787 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2789 int write, void *data)
2794 val = round_pipe_size(*lvalp);
2800 unsigned int val = *valp;
2801 *lvalp = (unsigned long) val;
2807 static int proc_dopipe_max_size(struct ctl_table *table, int write,
2808 void __user *buffer, size_t *lenp, loff_t *ppos)
2810 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2811 do_proc_dopipe_max_size_conv, NULL);
2814 static void validate_coredump_safety(void)
2816 #ifdef CONFIG_COREDUMP
2817 if (suid_dumpable == SUID_DUMP_ROOT &&
2818 core_pattern[0] != '/' && core_pattern[0] != '|') {
2820 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2821 "Pipe handler or fully qualified core dump path required.\n"
2822 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2828 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2829 void __user *buffer, size_t *lenp, loff_t *ppos)
2831 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2833 validate_coredump_safety();
2837 #ifdef CONFIG_COREDUMP
2838 static int proc_dostring_coredump(struct ctl_table *table, int write,
2839 void __user *buffer, size_t *lenp, loff_t *ppos)
2841 int error = proc_dostring(table, write, buffer, lenp, ppos);
2843 validate_coredump_safety();
2848 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2849 void __user *buffer,
2850 size_t *lenp, loff_t *ppos,
2851 unsigned long convmul,
2852 unsigned long convdiv)
2854 unsigned long *i, *min, *max;
2855 int vleft, first = 1, err = 0;
2857 char *kbuf = NULL, *p;
2859 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2864 i = (unsigned long *) data;
2865 min = (unsigned long *) table->extra1;
2866 max = (unsigned long *) table->extra2;
2867 vleft = table->maxlen / sizeof(unsigned long);
2871 if (proc_first_pos_non_zero_ignore(ppos, table))
2874 if (left > PAGE_SIZE - 1)
2875 left = PAGE_SIZE - 1;
2876 p = kbuf = memdup_user_nul(buffer, left);
2878 return PTR_ERR(kbuf);
2881 for (; left && vleft--; i++, first = 0) {
2887 left -= proc_skip_spaces(&p);
2891 err = proc_get_long(&p, &left, &val, &neg,
2893 sizeof(proc_wspace_sep), NULL);
2898 val = convmul * val / convdiv;
2899 if ((min && val < *min) || (max && val > *max)) {
2905 val = convdiv * (*i) / convmul;
2907 err = proc_put_char(&buffer, &left, '\t');
2911 err = proc_put_long(&buffer, &left, val, false);
2917 if (!write && !first && left && !err)
2918 err = proc_put_char(&buffer, &left, '\n');
2920 left -= proc_skip_spaces(&p);
2924 return err ? : -EINVAL;
2932 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2933 void __user *buffer,
2934 size_t *lenp, loff_t *ppos,
2935 unsigned long convmul,
2936 unsigned long convdiv)
2938 return __do_proc_doulongvec_minmax(table->data, table, write,
2939 buffer, lenp, ppos, convmul, convdiv);
2943 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2944 * @table: the sysctl table
2945 * @write: %TRUE if this is a write to the sysctl file
2946 * @buffer: the user buffer
2947 * @lenp: the size of the user buffer
2948 * @ppos: file position
2950 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2951 * values from/to the user buffer, treated as an ASCII string.
2953 * This routine will ensure the values are within the range specified by
2954 * table->extra1 (min) and table->extra2 (max).
2956 * Returns 0 on success.
2958 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2959 void __user *buffer, size_t *lenp, loff_t *ppos)
2961 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2965 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2966 * @table: the sysctl table
2967 * @write: %TRUE if this is a write to the sysctl file
2968 * @buffer: the user buffer
2969 * @lenp: the size of the user buffer
2970 * @ppos: file position
2972 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2973 * values from/to the user buffer, treated as an ASCII string. The values
2974 * are treated as milliseconds, and converted to jiffies when they are stored.
2976 * This routine will ensure the values are within the range specified by
2977 * table->extra1 (min) and table->extra2 (max).
2979 * Returns 0 on success.
2981 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2982 void __user *buffer,
2983 size_t *lenp, loff_t *ppos)
2985 return do_proc_doulongvec_minmax(table, write, buffer,
2986 lenp, ppos, HZ, 1000l);
2990 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2992 int write, void *data)
2995 if (*lvalp > INT_MAX / HZ)
2997 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
3003 lval = -(unsigned long)val;
3006 lval = (unsigned long)val;
3013 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
3015 int write, void *data)
3018 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
3020 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
3026 lval = -(unsigned long)val;
3029 lval = (unsigned long)val;
3031 *lvalp = jiffies_to_clock_t(lval);
3036 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
3038 int write, void *data)
3041 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3051 lval = -(unsigned long)val;
3054 lval = (unsigned long)val;
3056 *lvalp = jiffies_to_msecs(lval);
3062 * proc_dointvec_jiffies - read a vector of integers as seconds
3063 * @table: the sysctl table
3064 * @write: %TRUE if this is a write to the sysctl file
3065 * @buffer: the user buffer
3066 * @lenp: the size of the user buffer
3067 * @ppos: file position
3069 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3070 * values from/to the user buffer, treated as an ASCII string.
3071 * The values read are assumed to be in seconds, and are converted into
3074 * Returns 0 on success.
3076 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3077 void __user *buffer, size_t *lenp, loff_t *ppos)
3079 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3080 do_proc_dointvec_jiffies_conv,NULL);
3084 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3085 * @table: the sysctl table
3086 * @write: %TRUE if this is a write to the sysctl file
3087 * @buffer: the user buffer
3088 * @lenp: the size of the user buffer
3089 * @ppos: pointer to the file position
3091 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3092 * values from/to the user buffer, treated as an ASCII string.
3093 * The values read are assumed to be in 1/USER_HZ seconds, and
3094 * are converted into jiffies.
3096 * Returns 0 on success.
3098 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3099 void __user *buffer, size_t *lenp, loff_t *ppos)
3101 return do_proc_dointvec(table,write,buffer,lenp,ppos,
3102 do_proc_dointvec_userhz_jiffies_conv,NULL);
3106 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3107 * @table: the sysctl table
3108 * @write: %TRUE if this is a write to the sysctl file
3109 * @buffer: the user buffer
3110 * @lenp: the size of the user buffer
3111 * @ppos: file position
3112 * @ppos: the current position in the file
3114 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3115 * values from/to the user buffer, treated as an ASCII string.
3116 * The values read are assumed to be in 1/1000 seconds, and
3117 * are converted into jiffies.
3119 * Returns 0 on success.
3121 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3122 void __user *buffer, size_t *lenp, loff_t *ppos)
3124 return do_proc_dointvec(table, write, buffer, lenp, ppos,
3125 do_proc_dointvec_ms_jiffies_conv, NULL);
3128 static int proc_do_cad_pid(struct ctl_table *table, int write,
3129 void __user *buffer, size_t *lenp, loff_t *ppos)
3131 struct pid *new_pid;
3135 tmp = pid_vnr(cad_pid);
3137 r = __do_proc_dointvec(&tmp, table, write, buffer,
3138 lenp, ppos, NULL, NULL);
3142 new_pid = find_get_pid(tmp);
3146 put_pid(xchg(&cad_pid, new_pid));
3151 * proc_do_large_bitmap - read/write from/to a large bitmap
3152 * @table: the sysctl table
3153 * @write: %TRUE if this is a write to the sysctl file
3154 * @buffer: the user buffer
3155 * @lenp: the size of the user buffer
3156 * @ppos: file position
3158 * The bitmap is stored at table->data and the bitmap length (in bits)
3161 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3162 * large bitmaps may be represented in a compact manner. Writing into
3163 * the file will clear the bitmap then update it with the given input.
3165 * Returns 0 on success.
3167 int proc_do_large_bitmap(struct ctl_table *table, int write,
3168 void __user *buffer, size_t *lenp, loff_t *ppos)
3172 size_t left = *lenp;
3173 unsigned long bitmap_len = table->maxlen;
3174 unsigned long *bitmap = *(unsigned long **) table->data;
3175 unsigned long *tmp_bitmap = NULL;
3176 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3178 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
3187 if (left > PAGE_SIZE - 1) {
3188 left = PAGE_SIZE - 1;
3189 /* How much of the buffer we'll skip this pass */
3190 skipped = *lenp - left;
3193 p = kbuf = memdup_user_nul(buffer, left);
3195 return PTR_ERR(kbuf);
3197 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
3202 proc_skip_char(&p, &left, '\n');
3203 while (!err && left) {
3204 unsigned long val_a, val_b;
3208 /* In case we stop parsing mid-number, we can reset */
3210 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
3213 * If we consumed the entirety of a truncated buffer or
3214 * only one char is left (may be a "-"), then stop here,
3215 * reset, & come back for more.
3217 if ((left <= 1) && skipped) {
3224 if (val_a >= bitmap_len || neg) {
3236 err = proc_get_long(&p, &left, &val_b,
3237 &neg, tr_b, sizeof(tr_b),
3240 * If we consumed all of a truncated buffer or
3241 * then stop here, reset, & come back for more.
3243 if (!left && skipped) {
3250 if (val_b >= bitmap_len || neg ||
3261 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
3263 proc_skip_char(&p, &left, '\n');
3268 unsigned long bit_a, bit_b = 0;
3271 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3272 if (bit_a >= bitmap_len)
3274 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3278 err = proc_put_char(&buffer, &left, ',');
3282 err = proc_put_long(&buffer, &left, bit_a, false);
3285 if (bit_a != bit_b) {
3286 err = proc_put_char(&buffer, &left, '-');
3289 err = proc_put_long(&buffer, &left, bit_b, false);
3297 err = proc_put_char(&buffer, &left, '\n');
3303 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3305 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
3311 bitmap_free(tmp_bitmap);
3315 #else /* CONFIG_PROC_SYSCTL */
3317 int proc_dostring(struct ctl_table *table, int write,
3318 void __user *buffer, size_t *lenp, loff_t *ppos)
3323 int proc_dointvec(struct ctl_table *table, int write,
3324 void __user *buffer, size_t *lenp, loff_t *ppos)
3329 int proc_douintvec(struct ctl_table *table, int write,
3330 void __user *buffer, size_t *lenp, loff_t *ppos)
3335 int proc_dointvec_minmax(struct ctl_table *table, int write,
3336 void __user *buffer, size_t *lenp, loff_t *ppos)
3341 int proc_douintvec_minmax(struct ctl_table *table, int write,
3342 void __user *buffer, size_t *lenp, loff_t *ppos)
3347 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3348 void __user *buffer, size_t *lenp, loff_t *ppos)
3353 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3354 void __user *buffer, size_t *lenp, loff_t *ppos)
3359 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3360 void __user *buffer, size_t *lenp, loff_t *ppos)
3365 int proc_doulongvec_minmax(struct ctl_table *table, int write,
3366 void __user *buffer, size_t *lenp, loff_t *ppos)
3371 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3372 void __user *buffer,
3373 size_t *lenp, loff_t *ppos)
3378 int proc_do_large_bitmap(struct ctl_table *table, int write,
3379 void __user *buffer, size_t *lenp, loff_t *ppos)
3384 #endif /* CONFIG_PROC_SYSCTL */
3386 #if defined(CONFIG_SYSCTL)
3387 int proc_do_static_key(struct ctl_table *table, int write,
3388 void __user *buffer, size_t *lenp,
3391 struct static_key *key = (struct static_key *)table->data;
3392 static DEFINE_MUTEX(static_key_mutex);
3394 struct ctl_table tmp = {
3396 .maxlen = sizeof(val),
3397 .mode = table->mode,
3402 if (write && !capable(CAP_SYS_ADMIN))
3405 mutex_lock(&static_key_mutex);
3406 val = static_key_enabled(key);
3407 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3408 if (write && !ret) {
3410 static_key_enable(key);
3412 static_key_disable(key);
3414 mutex_unlock(&static_key_mutex);
3419 * No sense putting this after each symbol definition, twice,
3420 * exception granted :-)
3422 EXPORT_SYMBOL(proc_dointvec);
3423 EXPORT_SYMBOL(proc_douintvec);
3424 EXPORT_SYMBOL(proc_dointvec_jiffies);
3425 EXPORT_SYMBOL(proc_dointvec_minmax);
3426 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3427 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3428 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3429 EXPORT_SYMBOL(proc_dostring);
3430 EXPORT_SYMBOL(proc_doulongvec_minmax);
3431 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3432 EXPORT_SYMBOL(proc_do_large_bitmap);