1 // SPDX-License-Identifier: GPL-2.0-only
3 * sysctl.c: General linux system control interface
5 * Begun 24 March 1995, Stephen Tweedie
6 * Added /proc support, Dec 1995
7 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
8 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
9 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
10 * Dynamic registration fixes, Stephen Tweedie.
11 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
12 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
14 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
15 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
16 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
18 * The list_for_each() macro wasn't appropriate for the sysctl loop.
19 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
22 #include <linux/module.h>
23 #include <linux/aio.h>
25 #include <linux/swap.h>
26 #include <linux/slab.h>
27 #include <linux/sysctl.h>
28 #include <linux/bitmap.h>
29 #include <linux/signal.h>
30 #include <linux/printk.h>
31 #include <linux/proc_fs.h>
32 #include <linux/security.h>
33 #include <linux/ctype.h>
34 #include <linux/kmemleak.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/kobject.h>
39 #include <linux/net.h>
40 #include <linux/sysrq.h>
41 #include <linux/highuid.h>
42 #include <linux/writeback.h>
43 #include <linux/ratelimit.h>
44 #include <linux/compaction.h>
45 #include <linux/hugetlb.h>
46 #include <linux/initrd.h>
47 #include <linux/key.h>
48 #include <linux/times.h>
49 #include <linux/limits.h>
50 #include <linux/dcache.h>
51 #include <linux/dnotify.h>
52 #include <linux/syscalls.h>
53 #include <linux/vmstat.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/acpi.h>
56 #include <linux/reboot.h>
57 #include <linux/ftrace.h>
58 #include <linux/perf_event.h>
59 #include <linux/kprobes.h>
60 #include <linux/pipe_fs_i.h>
61 #include <linux/oom.h>
62 #include <linux/kmod.h>
63 #include <linux/capability.h>
64 #include <linux/binfmts.h>
65 #include <linux/sched/sysctl.h>
66 #include <linux/sched/coredump.h>
67 #include <linux/kexec.h>
68 #include <linux/bpf.h>
69 #include <linux/mount.h>
70 #include <linux/userfaultfd_k.h>
72 #include "../lib/kstrtox.h"
74 #include <linux/uaccess.h>
75 #include <asm/processor.h>
79 #include <asm/stacktrace.h>
83 #include <asm/setup.h>
85 #ifdef CONFIG_BSD_PROCESS_ACCT
86 #include <linux/acct.h>
88 #ifdef CONFIG_RT_MUTEXES
89 #include <linux/rtmutex.h>
91 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
92 #include <linux/lockdep.h>
94 #ifdef CONFIG_CHR_DEV_SG
97 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
98 #include <linux/stackleak.h>
100 #ifdef CONFIG_LOCKUP_DETECTOR
101 #include <linux/nmi.h>
104 #if defined(CONFIG_SYSCTL)
106 /* External variables not in a header file. */
107 extern int suid_dumpable
;
108 #ifdef CONFIG_COREDUMP
109 extern int core_uses_pid
;
110 extern char core_pattern
[];
111 extern unsigned int core_pipe_limit
;
114 extern int pid_max_min
, pid_max_max
;
115 extern int percpu_pagelist_fraction
;
116 extern int latencytop_enabled
;
117 extern unsigned int sysctl_nr_open_min
, sysctl_nr_open_max
;
119 extern int sysctl_nr_trim_pages
;
122 /* Constants used for minimum and maximum */
123 #ifdef CONFIG_LOCKUP_DETECTOR
124 static int sixty
= 60;
127 static int __maybe_unused neg_one
= -1;
128 static int __maybe_unused two
= 2;
129 static int __maybe_unused four
= 4;
130 static unsigned long zero_ul
;
131 static unsigned long one_ul
= 1;
132 static unsigned long long_max
= LONG_MAX
;
133 static int one_hundred
= 100;
134 static int one_thousand
= 1000;
136 static int ten_thousand
= 10000;
138 #ifdef CONFIG_PERF_EVENTS
139 static int six_hundred_forty_kb
= 640 * 1024;
142 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
143 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
145 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
146 static int maxolduid
= 65535;
147 static int minolduid
;
149 static int ngroups_max
= NGROUPS_MAX
;
150 static const int cap_last_cap
= CAP_LAST_CAP
;
153 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
154 * and hung_task_check_interval_secs
156 #ifdef CONFIG_DETECT_HUNG_TASK
157 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
160 #ifdef CONFIG_INOTIFY_USER
161 #include <linux/inotify.h>
167 extern int pwrsw_enabled
;
170 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
171 extern int unaligned_enabled
;
175 extern int unaligned_dump_stack
;
178 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
179 extern int no_unaligned_warning
;
182 #ifdef CONFIG_PROC_SYSCTL
185 * enum sysctl_writes_mode - supported sysctl write modes
187 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
188 * to be written, and multiple writes on the same sysctl file descriptor
189 * will rewrite the sysctl value, regardless of file position. No warning
190 * is issued when the initial position is not 0.
191 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
193 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
194 * file position 0 and the value must be fully contained in the buffer
195 * sent to the write syscall. If dealing with strings respect the file
196 * position, but restrict this to the max length of the buffer, anything
197 * passed the max length will be ignored. Multiple writes will append
200 * These write modes control how current file position affects the behavior of
201 * updating sysctl values through the proc interface on each write.
203 enum sysctl_writes_mode
{
204 SYSCTL_WRITES_LEGACY
= -1,
205 SYSCTL_WRITES_WARN
= 0,
206 SYSCTL_WRITES_STRICT
= 1,
209 static enum sysctl_writes_mode sysctl_writes_strict
= SYSCTL_WRITES_STRICT
;
211 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
212 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
213 static int proc_taint(struct ctl_table
*table
, int write
,
214 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
215 #ifdef CONFIG_COMPACTION
216 static int proc_dointvec_minmax_warn_RT_change(struct ctl_table
*table
,
217 int write
, void __user
*buffer
,
218 size_t *lenp
, loff_t
*ppos
);
223 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
224 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
227 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
228 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
229 #ifdef CONFIG_COREDUMP
230 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
231 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
233 static int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
234 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
236 #ifdef CONFIG_MAGIC_SYSRQ
237 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
238 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
241 static struct ctl_table kern_table
[];
242 static struct ctl_table vm_table
[];
243 static struct ctl_table fs_table
[];
244 static struct ctl_table debug_table
[];
245 static struct ctl_table dev_table
[];
246 extern struct ctl_table random_table
[];
248 extern struct ctl_table epoll_table
[];
251 #ifdef CONFIG_FW_LOADER_USER_HELPER
252 extern struct ctl_table firmware_config_table
[];
255 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
256 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
257 int sysctl_legacy_va_layout
;
260 /* The default sysctl tables: */
262 static struct ctl_table sysctl_base_table
[] = {
264 .procname
= "kernel",
281 .child
= debug_table
,
291 #ifdef CONFIG_SCHED_DEBUG
292 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
293 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
294 static int min_wakeup_granularity_ns
; /* 0 usecs */
295 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
297 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
298 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
299 #endif /* CONFIG_SMP */
300 #endif /* CONFIG_SCHED_DEBUG */
302 #ifdef CONFIG_COMPACTION
303 static int min_extfrag_threshold
;
304 static int max_extfrag_threshold
= 1000;
307 static struct ctl_table kern_table
[] = {
309 .procname
= "sched_child_runs_first",
310 .data
= &sysctl_sched_child_runs_first
,
311 .maxlen
= sizeof(unsigned int),
313 .proc_handler
= proc_dointvec
,
315 #ifdef CONFIG_SCHED_DEBUG
317 .procname
= "sched_min_granularity_ns",
318 .data
= &sysctl_sched_min_granularity
,
319 .maxlen
= sizeof(unsigned int),
321 .proc_handler
= sched_proc_update_handler
,
322 .extra1
= &min_sched_granularity_ns
,
323 .extra2
= &max_sched_granularity_ns
,
326 .procname
= "sched_latency_ns",
327 .data
= &sysctl_sched_latency
,
328 .maxlen
= sizeof(unsigned int),
330 .proc_handler
= sched_proc_update_handler
,
331 .extra1
= &min_sched_granularity_ns
,
332 .extra2
= &max_sched_granularity_ns
,
335 .procname
= "sched_wakeup_granularity_ns",
336 .data
= &sysctl_sched_wakeup_granularity
,
337 .maxlen
= sizeof(unsigned int),
339 .proc_handler
= sched_proc_update_handler
,
340 .extra1
= &min_wakeup_granularity_ns
,
341 .extra2
= &max_wakeup_granularity_ns
,
345 .procname
= "sched_tunable_scaling",
346 .data
= &sysctl_sched_tunable_scaling
,
347 .maxlen
= sizeof(enum sched_tunable_scaling
),
349 .proc_handler
= sched_proc_update_handler
,
350 .extra1
= &min_sched_tunable_scaling
,
351 .extra2
= &max_sched_tunable_scaling
,
354 .procname
= "sched_migration_cost_ns",
355 .data
= &sysctl_sched_migration_cost
,
356 .maxlen
= sizeof(unsigned int),
358 .proc_handler
= proc_dointvec
,
361 .procname
= "sched_nr_migrate",
362 .data
= &sysctl_sched_nr_migrate
,
363 .maxlen
= sizeof(unsigned int),
365 .proc_handler
= proc_dointvec
,
367 #ifdef CONFIG_SCHEDSTATS
369 .procname
= "sched_schedstats",
371 .maxlen
= sizeof(unsigned int),
373 .proc_handler
= sysctl_schedstats
,
374 .extra1
= SYSCTL_ZERO
,
375 .extra2
= SYSCTL_ONE
,
377 #endif /* CONFIG_SCHEDSTATS */
378 #endif /* CONFIG_SMP */
379 #ifdef CONFIG_NUMA_BALANCING
381 .procname
= "numa_balancing_scan_delay_ms",
382 .data
= &sysctl_numa_balancing_scan_delay
,
383 .maxlen
= sizeof(unsigned int),
385 .proc_handler
= proc_dointvec
,
388 .procname
= "numa_balancing_scan_period_min_ms",
389 .data
= &sysctl_numa_balancing_scan_period_min
,
390 .maxlen
= sizeof(unsigned int),
392 .proc_handler
= proc_dointvec
,
395 .procname
= "numa_balancing_scan_period_max_ms",
396 .data
= &sysctl_numa_balancing_scan_period_max
,
397 .maxlen
= sizeof(unsigned int),
399 .proc_handler
= proc_dointvec
,
402 .procname
= "numa_balancing_scan_size_mb",
403 .data
= &sysctl_numa_balancing_scan_size
,
404 .maxlen
= sizeof(unsigned int),
406 .proc_handler
= proc_dointvec_minmax
,
407 .extra1
= SYSCTL_ONE
,
410 .procname
= "numa_balancing",
411 .data
= NULL
, /* filled in by handler */
412 .maxlen
= sizeof(unsigned int),
414 .proc_handler
= sysctl_numa_balancing
,
415 .extra1
= SYSCTL_ZERO
,
416 .extra2
= SYSCTL_ONE
,
418 #endif /* CONFIG_NUMA_BALANCING */
419 #endif /* CONFIG_SCHED_DEBUG */
421 .procname
= "sched_rt_period_us",
422 .data
= &sysctl_sched_rt_period
,
423 .maxlen
= sizeof(unsigned int),
425 .proc_handler
= sched_rt_handler
,
428 .procname
= "sched_rt_runtime_us",
429 .data
= &sysctl_sched_rt_runtime
,
430 .maxlen
= sizeof(int),
432 .proc_handler
= sched_rt_handler
,
435 .procname
= "sched_rr_timeslice_ms",
436 .data
= &sysctl_sched_rr_timeslice
,
437 .maxlen
= sizeof(int),
439 .proc_handler
= sched_rr_handler
,
441 #ifdef CONFIG_UCLAMP_TASK
443 .procname
= "sched_util_clamp_min",
444 .data
= &sysctl_sched_uclamp_util_min
,
445 .maxlen
= sizeof(unsigned int),
447 .proc_handler
= sysctl_sched_uclamp_handler
,
450 .procname
= "sched_util_clamp_max",
451 .data
= &sysctl_sched_uclamp_util_max
,
452 .maxlen
= sizeof(unsigned int),
454 .proc_handler
= sysctl_sched_uclamp_handler
,
457 #ifdef CONFIG_SCHED_AUTOGROUP
459 .procname
= "sched_autogroup_enabled",
460 .data
= &sysctl_sched_autogroup_enabled
,
461 .maxlen
= sizeof(unsigned int),
463 .proc_handler
= proc_dointvec_minmax
,
464 .extra1
= SYSCTL_ZERO
,
465 .extra2
= SYSCTL_ONE
,
468 #ifdef CONFIG_CFS_BANDWIDTH
470 .procname
= "sched_cfs_bandwidth_slice_us",
471 .data
= &sysctl_sched_cfs_bandwidth_slice
,
472 .maxlen
= sizeof(unsigned int),
474 .proc_handler
= proc_dointvec_minmax
,
475 .extra1
= SYSCTL_ONE
,
478 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
480 .procname
= "sched_energy_aware",
481 .data
= &sysctl_sched_energy_aware
,
482 .maxlen
= sizeof(unsigned int),
484 .proc_handler
= sched_energy_aware_handler
,
485 .extra1
= SYSCTL_ZERO
,
486 .extra2
= SYSCTL_ONE
,
489 #ifdef CONFIG_PROVE_LOCKING
491 .procname
= "prove_locking",
492 .data
= &prove_locking
,
493 .maxlen
= sizeof(int),
495 .proc_handler
= proc_dointvec
,
498 #ifdef CONFIG_LOCK_STAT
500 .procname
= "lock_stat",
502 .maxlen
= sizeof(int),
504 .proc_handler
= proc_dointvec
,
509 .data
= &panic_timeout
,
510 .maxlen
= sizeof(int),
512 .proc_handler
= proc_dointvec
,
514 #ifdef CONFIG_COREDUMP
516 .procname
= "core_uses_pid",
517 .data
= &core_uses_pid
,
518 .maxlen
= sizeof(int),
520 .proc_handler
= proc_dointvec
,
523 .procname
= "core_pattern",
524 .data
= core_pattern
,
525 .maxlen
= CORENAME_MAX_SIZE
,
527 .proc_handler
= proc_dostring_coredump
,
530 .procname
= "core_pipe_limit",
531 .data
= &core_pipe_limit
,
532 .maxlen
= sizeof(unsigned int),
534 .proc_handler
= proc_dointvec
,
537 #ifdef CONFIG_PROC_SYSCTL
539 .procname
= "tainted",
540 .maxlen
= sizeof(long),
542 .proc_handler
= proc_taint
,
545 .procname
= "sysctl_writes_strict",
546 .data
= &sysctl_writes_strict
,
547 .maxlen
= sizeof(int),
549 .proc_handler
= proc_dointvec_minmax
,
551 .extra2
= SYSCTL_ONE
,
554 #ifdef CONFIG_LATENCYTOP
556 .procname
= "latencytop",
557 .data
= &latencytop_enabled
,
558 .maxlen
= sizeof(int),
560 .proc_handler
= sysctl_latencytop
,
563 #ifdef CONFIG_BLK_DEV_INITRD
565 .procname
= "real-root-dev",
566 .data
= &real_root_dev
,
567 .maxlen
= sizeof(int),
569 .proc_handler
= proc_dointvec
,
573 .procname
= "print-fatal-signals",
574 .data
= &print_fatal_signals
,
575 .maxlen
= sizeof(int),
577 .proc_handler
= proc_dointvec
,
581 .procname
= "reboot-cmd",
582 .data
= reboot_command
,
585 .proc_handler
= proc_dostring
,
588 .procname
= "stop-a",
589 .data
= &stop_a_enabled
,
590 .maxlen
= sizeof (int),
592 .proc_handler
= proc_dointvec
,
595 .procname
= "scons-poweroff",
596 .data
= &scons_pwroff
,
597 .maxlen
= sizeof (int),
599 .proc_handler
= proc_dointvec
,
602 #ifdef CONFIG_SPARC64
604 .procname
= "tsb-ratio",
605 .data
= &sysctl_tsb_ratio
,
606 .maxlen
= sizeof (int),
608 .proc_handler
= proc_dointvec
,
613 .procname
= "soft-power",
614 .data
= &pwrsw_enabled
,
615 .maxlen
= sizeof (int),
617 .proc_handler
= proc_dointvec
,
620 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
622 .procname
= "unaligned-trap",
623 .data
= &unaligned_enabled
,
624 .maxlen
= sizeof (int),
626 .proc_handler
= proc_dointvec
,
630 .procname
= "ctrl-alt-del",
632 .maxlen
= sizeof(int),
634 .proc_handler
= proc_dointvec
,
636 #ifdef CONFIG_FUNCTION_TRACER
638 .procname
= "ftrace_enabled",
639 .data
= &ftrace_enabled
,
640 .maxlen
= sizeof(int),
642 .proc_handler
= ftrace_enable_sysctl
,
645 #ifdef CONFIG_STACK_TRACER
647 .procname
= "stack_tracer_enabled",
648 .data
= &stack_tracer_enabled
,
649 .maxlen
= sizeof(int),
651 .proc_handler
= stack_trace_sysctl
,
654 #ifdef CONFIG_TRACING
656 .procname
= "ftrace_dump_on_oops",
657 .data
= &ftrace_dump_on_oops
,
658 .maxlen
= sizeof(int),
660 .proc_handler
= proc_dointvec
,
663 .procname
= "traceoff_on_warning",
664 .data
= &__disable_trace_on_warning
,
665 .maxlen
= sizeof(__disable_trace_on_warning
),
667 .proc_handler
= proc_dointvec
,
670 .procname
= "tracepoint_printk",
671 .data
= &tracepoint_printk
,
672 .maxlen
= sizeof(tracepoint_printk
),
674 .proc_handler
= tracepoint_printk_sysctl
,
677 #ifdef CONFIG_KEXEC_CORE
679 .procname
= "kexec_load_disabled",
680 .data
= &kexec_load_disabled
,
681 .maxlen
= sizeof(int),
683 /* only handle a transition from default "0" to "1" */
684 .proc_handler
= proc_dointvec_minmax
,
685 .extra1
= SYSCTL_ONE
,
686 .extra2
= SYSCTL_ONE
,
689 #ifdef CONFIG_MODULES
691 .procname
= "modprobe",
692 .data
= &modprobe_path
,
693 .maxlen
= KMOD_PATH_LEN
,
695 .proc_handler
= proc_dostring
,
698 .procname
= "modules_disabled",
699 .data
= &modules_disabled
,
700 .maxlen
= sizeof(int),
702 /* only handle a transition from default "0" to "1" */
703 .proc_handler
= proc_dointvec_minmax
,
704 .extra1
= SYSCTL_ONE
,
705 .extra2
= SYSCTL_ONE
,
708 #ifdef CONFIG_UEVENT_HELPER
710 .procname
= "hotplug",
711 .data
= &uevent_helper
,
712 .maxlen
= UEVENT_HELPER_PATH_LEN
,
714 .proc_handler
= proc_dostring
,
717 #ifdef CONFIG_CHR_DEV_SG
719 .procname
= "sg-big-buff",
720 .data
= &sg_big_buff
,
721 .maxlen
= sizeof (int),
723 .proc_handler
= proc_dointvec
,
726 #ifdef CONFIG_BSD_PROCESS_ACCT
730 .maxlen
= 3*sizeof(int),
732 .proc_handler
= proc_dointvec
,
735 #ifdef CONFIG_MAGIC_SYSRQ
739 .maxlen
= sizeof (int),
741 .proc_handler
= sysrq_sysctl_handler
,
744 #ifdef CONFIG_PROC_SYSCTL
746 .procname
= "cad_pid",
748 .maxlen
= sizeof (int),
750 .proc_handler
= proc_do_cad_pid
,
754 .procname
= "threads-max",
756 .maxlen
= sizeof(int),
758 .proc_handler
= sysctl_max_threads
,
761 .procname
= "random",
763 .child
= random_table
,
766 .procname
= "usermodehelper",
768 .child
= usermodehelper_table
,
770 #ifdef CONFIG_FW_LOADER_USER_HELPER
772 .procname
= "firmware_config",
774 .child
= firmware_config_table
,
778 .procname
= "overflowuid",
779 .data
= &overflowuid
,
780 .maxlen
= sizeof(int),
782 .proc_handler
= proc_dointvec_minmax
,
783 .extra1
= &minolduid
,
784 .extra2
= &maxolduid
,
787 .procname
= "overflowgid",
788 .data
= &overflowgid
,
789 .maxlen
= sizeof(int),
791 .proc_handler
= proc_dointvec_minmax
,
792 .extra1
= &minolduid
,
793 .extra2
= &maxolduid
,
797 .procname
= "userprocess_debug",
798 .data
= &show_unhandled_signals
,
799 .maxlen
= sizeof(int),
801 .proc_handler
= proc_dointvec
,
805 .procname
= "pid_max",
807 .maxlen
= sizeof (int),
809 .proc_handler
= proc_dointvec_minmax
,
810 .extra1
= &pid_max_min
,
811 .extra2
= &pid_max_max
,
814 .procname
= "panic_on_oops",
815 .data
= &panic_on_oops
,
816 .maxlen
= sizeof(int),
818 .proc_handler
= proc_dointvec
,
821 .procname
= "panic_print",
822 .data
= &panic_print
,
823 .maxlen
= sizeof(unsigned long),
825 .proc_handler
= proc_doulongvec_minmax
,
827 #if defined CONFIG_PRINTK
829 .procname
= "printk",
830 .data
= &console_loglevel
,
831 .maxlen
= 4*sizeof(int),
833 .proc_handler
= proc_dointvec
,
836 .procname
= "printk_ratelimit",
837 .data
= &printk_ratelimit_state
.interval
,
838 .maxlen
= sizeof(int),
840 .proc_handler
= proc_dointvec_jiffies
,
843 .procname
= "printk_ratelimit_burst",
844 .data
= &printk_ratelimit_state
.burst
,
845 .maxlen
= sizeof(int),
847 .proc_handler
= proc_dointvec
,
850 .procname
= "printk_delay",
851 .data
= &printk_delay_msec
,
852 .maxlen
= sizeof(int),
854 .proc_handler
= proc_dointvec_minmax
,
855 .extra1
= SYSCTL_ZERO
,
856 .extra2
= &ten_thousand
,
859 .procname
= "printk_devkmsg",
860 .data
= devkmsg_log_str
,
861 .maxlen
= DEVKMSG_STR_MAX_SIZE
,
863 .proc_handler
= devkmsg_sysctl_set_loglvl
,
866 .procname
= "dmesg_restrict",
867 .data
= &dmesg_restrict
,
868 .maxlen
= sizeof(int),
870 .proc_handler
= proc_dointvec_minmax_sysadmin
,
871 .extra1
= SYSCTL_ZERO
,
872 .extra2
= SYSCTL_ONE
,
875 .procname
= "kptr_restrict",
876 .data
= &kptr_restrict
,
877 .maxlen
= sizeof(int),
879 .proc_handler
= proc_dointvec_minmax_sysadmin
,
880 .extra1
= SYSCTL_ZERO
,
885 .procname
= "ngroups_max",
886 .data
= &ngroups_max
,
887 .maxlen
= sizeof (int),
889 .proc_handler
= proc_dointvec
,
892 .procname
= "cap_last_cap",
893 .data
= (void *)&cap_last_cap
,
894 .maxlen
= sizeof(int),
896 .proc_handler
= proc_dointvec
,
898 #if defined(CONFIG_LOCKUP_DETECTOR)
900 .procname
= "watchdog",
901 .data
= &watchdog_user_enabled
,
902 .maxlen
= sizeof(int),
904 .proc_handler
= proc_watchdog
,
905 .extra1
= SYSCTL_ZERO
,
906 .extra2
= SYSCTL_ONE
,
909 .procname
= "watchdog_thresh",
910 .data
= &watchdog_thresh
,
911 .maxlen
= sizeof(int),
913 .proc_handler
= proc_watchdog_thresh
,
914 .extra1
= SYSCTL_ZERO
,
918 .procname
= "nmi_watchdog",
919 .data
= &nmi_watchdog_user_enabled
,
920 .maxlen
= sizeof(int),
921 .mode
= NMI_WATCHDOG_SYSCTL_PERM
,
922 .proc_handler
= proc_nmi_watchdog
,
923 .extra1
= SYSCTL_ZERO
,
924 .extra2
= SYSCTL_ONE
,
927 .procname
= "watchdog_cpumask",
928 .data
= &watchdog_cpumask_bits
,
931 .proc_handler
= proc_watchdog_cpumask
,
933 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
935 .procname
= "soft_watchdog",
936 .data
= &soft_watchdog_user_enabled
,
937 .maxlen
= sizeof(int),
939 .proc_handler
= proc_soft_watchdog
,
940 .extra1
= SYSCTL_ZERO
,
941 .extra2
= SYSCTL_ONE
,
944 .procname
= "softlockup_panic",
945 .data
= &softlockup_panic
,
946 .maxlen
= sizeof(int),
948 .proc_handler
= proc_dointvec_minmax
,
949 .extra1
= SYSCTL_ZERO
,
950 .extra2
= SYSCTL_ONE
,
954 .procname
= "softlockup_all_cpu_backtrace",
955 .data
= &sysctl_softlockup_all_cpu_backtrace
,
956 .maxlen
= sizeof(int),
958 .proc_handler
= proc_dointvec_minmax
,
959 .extra1
= SYSCTL_ZERO
,
960 .extra2
= SYSCTL_ONE
,
962 #endif /* CONFIG_SMP */
964 #ifdef CONFIG_HARDLOCKUP_DETECTOR
966 .procname
= "hardlockup_panic",
967 .data
= &hardlockup_panic
,
968 .maxlen
= sizeof(int),
970 .proc_handler
= proc_dointvec_minmax
,
971 .extra1
= SYSCTL_ZERO
,
972 .extra2
= SYSCTL_ONE
,
976 .procname
= "hardlockup_all_cpu_backtrace",
977 .data
= &sysctl_hardlockup_all_cpu_backtrace
,
978 .maxlen
= sizeof(int),
980 .proc_handler
= proc_dointvec_minmax
,
981 .extra1
= SYSCTL_ZERO
,
982 .extra2
= SYSCTL_ONE
,
984 #endif /* CONFIG_SMP */
988 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
990 .procname
= "unknown_nmi_panic",
991 .data
= &unknown_nmi_panic
,
992 .maxlen
= sizeof (int),
994 .proc_handler
= proc_dointvec
,
997 #if defined(CONFIG_X86)
999 .procname
= "panic_on_unrecovered_nmi",
1000 .data
= &panic_on_unrecovered_nmi
,
1001 .maxlen
= sizeof(int),
1003 .proc_handler
= proc_dointvec
,
1006 .procname
= "panic_on_io_nmi",
1007 .data
= &panic_on_io_nmi
,
1008 .maxlen
= sizeof(int),
1010 .proc_handler
= proc_dointvec
,
1012 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1014 .procname
= "panic_on_stackoverflow",
1015 .data
= &sysctl_panic_on_stackoverflow
,
1016 .maxlen
= sizeof(int),
1018 .proc_handler
= proc_dointvec
,
1022 .procname
= "bootloader_type",
1023 .data
= &bootloader_type
,
1024 .maxlen
= sizeof (int),
1026 .proc_handler
= proc_dointvec
,
1029 .procname
= "bootloader_version",
1030 .data
= &bootloader_version
,
1031 .maxlen
= sizeof (int),
1033 .proc_handler
= proc_dointvec
,
1036 .procname
= "io_delay_type",
1037 .data
= &io_delay_type
,
1038 .maxlen
= sizeof(int),
1040 .proc_handler
= proc_dointvec
,
1043 #if defined(CONFIG_MMU)
1045 .procname
= "randomize_va_space",
1046 .data
= &randomize_va_space
,
1047 .maxlen
= sizeof(int),
1049 .proc_handler
= proc_dointvec
,
1052 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1054 .procname
= "spin_retry",
1055 .data
= &spin_retry
,
1056 .maxlen
= sizeof (int),
1058 .proc_handler
= proc_dointvec
,
1061 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1063 .procname
= "acpi_video_flags",
1064 .data
= &acpi_realmode_flags
,
1065 .maxlen
= sizeof (unsigned long),
1067 .proc_handler
= proc_doulongvec_minmax
,
1070 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1072 .procname
= "ignore-unaligned-usertrap",
1073 .data
= &no_unaligned_warning
,
1074 .maxlen
= sizeof (int),
1076 .proc_handler
= proc_dointvec
,
1081 .procname
= "unaligned-dump-stack",
1082 .data
= &unaligned_dump_stack
,
1083 .maxlen
= sizeof (int),
1085 .proc_handler
= proc_dointvec
,
1088 #ifdef CONFIG_DETECT_HUNG_TASK
1090 .procname
= "hung_task_panic",
1091 .data
= &sysctl_hung_task_panic
,
1092 .maxlen
= sizeof(int),
1094 .proc_handler
= proc_dointvec_minmax
,
1095 .extra1
= SYSCTL_ZERO
,
1096 .extra2
= SYSCTL_ONE
,
1099 .procname
= "hung_task_check_count",
1100 .data
= &sysctl_hung_task_check_count
,
1101 .maxlen
= sizeof(int),
1103 .proc_handler
= proc_dointvec_minmax
,
1104 .extra1
= SYSCTL_ZERO
,
1107 .procname
= "hung_task_timeout_secs",
1108 .data
= &sysctl_hung_task_timeout_secs
,
1109 .maxlen
= sizeof(unsigned long),
1111 .proc_handler
= proc_dohung_task_timeout_secs
,
1112 .extra2
= &hung_task_timeout_max
,
1115 .procname
= "hung_task_check_interval_secs",
1116 .data
= &sysctl_hung_task_check_interval_secs
,
1117 .maxlen
= sizeof(unsigned long),
1119 .proc_handler
= proc_dohung_task_timeout_secs
,
1120 .extra2
= &hung_task_timeout_max
,
1123 .procname
= "hung_task_warnings",
1124 .data
= &sysctl_hung_task_warnings
,
1125 .maxlen
= sizeof(int),
1127 .proc_handler
= proc_dointvec_minmax
,
1131 #ifdef CONFIG_RT_MUTEXES
1133 .procname
= "max_lock_depth",
1134 .data
= &max_lock_depth
,
1135 .maxlen
= sizeof(int),
1137 .proc_handler
= proc_dointvec
,
1141 .procname
= "poweroff_cmd",
1142 .data
= &poweroff_cmd
,
1143 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1145 .proc_handler
= proc_dostring
,
1151 .child
= key_sysctls
,
1154 #ifdef CONFIG_PERF_EVENTS
1156 * User-space scripts rely on the existence of this file
1157 * as a feature check for perf_events being enabled.
1159 * So it's an ABI, do not remove!
1162 .procname
= "perf_event_paranoid",
1163 .data
= &sysctl_perf_event_paranoid
,
1164 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1166 .proc_handler
= proc_dointvec
,
1169 .procname
= "perf_event_mlock_kb",
1170 .data
= &sysctl_perf_event_mlock
,
1171 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1173 .proc_handler
= proc_dointvec
,
1176 .procname
= "perf_event_max_sample_rate",
1177 .data
= &sysctl_perf_event_sample_rate
,
1178 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1180 .proc_handler
= perf_proc_update_handler
,
1181 .extra1
= SYSCTL_ONE
,
1184 .procname
= "perf_cpu_time_max_percent",
1185 .data
= &sysctl_perf_cpu_time_max_percent
,
1186 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1188 .proc_handler
= perf_cpu_time_max_percent_handler
,
1189 .extra1
= SYSCTL_ZERO
,
1190 .extra2
= &one_hundred
,
1193 .procname
= "perf_event_max_stack",
1194 .data
= &sysctl_perf_event_max_stack
,
1195 .maxlen
= sizeof(sysctl_perf_event_max_stack
),
1197 .proc_handler
= perf_event_max_stack_handler
,
1198 .extra1
= SYSCTL_ZERO
,
1199 .extra2
= &six_hundred_forty_kb
,
1202 .procname
= "perf_event_max_contexts_per_stack",
1203 .data
= &sysctl_perf_event_max_contexts_per_stack
,
1204 .maxlen
= sizeof(sysctl_perf_event_max_contexts_per_stack
),
1206 .proc_handler
= perf_event_max_stack_handler
,
1207 .extra1
= SYSCTL_ZERO
,
1208 .extra2
= &one_thousand
,
1212 .procname
= "panic_on_warn",
1213 .data
= &panic_on_warn
,
1214 .maxlen
= sizeof(int),
1216 .proc_handler
= proc_dointvec_minmax
,
1217 .extra1
= SYSCTL_ZERO
,
1218 .extra2
= SYSCTL_ONE
,
1220 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1222 .procname
= "timer_migration",
1223 .data
= &sysctl_timer_migration
,
1224 .maxlen
= sizeof(unsigned int),
1226 .proc_handler
= timer_migration_handler
,
1227 .extra1
= SYSCTL_ZERO
,
1228 .extra2
= SYSCTL_ONE
,
1231 #ifdef CONFIG_BPF_SYSCALL
1233 .procname
= "unprivileged_bpf_disabled",
1234 .data
= &sysctl_unprivileged_bpf_disabled
,
1235 .maxlen
= sizeof(sysctl_unprivileged_bpf_disabled
),
1237 /* only handle a transition from default "0" to "1" */
1238 .proc_handler
= proc_dointvec_minmax
,
1239 .extra1
= SYSCTL_ONE
,
1240 .extra2
= SYSCTL_ONE
,
1243 .procname
= "bpf_stats_enabled",
1244 .data
= &bpf_stats_enabled_key
.key
,
1245 .maxlen
= sizeof(bpf_stats_enabled_key
),
1247 .proc_handler
= proc_do_static_key
,
1250 #if defined(CONFIG_TREE_RCU)
1252 .procname
= "panic_on_rcu_stall",
1253 .data
= &sysctl_panic_on_rcu_stall
,
1254 .maxlen
= sizeof(sysctl_panic_on_rcu_stall
),
1256 .proc_handler
= proc_dointvec_minmax
,
1257 .extra1
= SYSCTL_ZERO
,
1258 .extra2
= SYSCTL_ONE
,
1261 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1263 .procname
= "stack_erasing",
1265 .maxlen
= sizeof(int),
1267 .proc_handler
= stack_erasing_sysctl
,
1268 .extra1
= SYSCTL_ZERO
,
1269 .extra2
= SYSCTL_ONE
,
1275 static struct ctl_table vm_table
[] = {
1277 .procname
= "overcommit_memory",
1278 .data
= &sysctl_overcommit_memory
,
1279 .maxlen
= sizeof(sysctl_overcommit_memory
),
1281 .proc_handler
= proc_dointvec_minmax
,
1282 .extra1
= SYSCTL_ZERO
,
1286 .procname
= "panic_on_oom",
1287 .data
= &sysctl_panic_on_oom
,
1288 .maxlen
= sizeof(sysctl_panic_on_oom
),
1290 .proc_handler
= proc_dointvec_minmax
,
1291 .extra1
= SYSCTL_ZERO
,
1295 .procname
= "oom_kill_allocating_task",
1296 .data
= &sysctl_oom_kill_allocating_task
,
1297 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1299 .proc_handler
= proc_dointvec
,
1302 .procname
= "oom_dump_tasks",
1303 .data
= &sysctl_oom_dump_tasks
,
1304 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1306 .proc_handler
= proc_dointvec
,
1309 .procname
= "overcommit_ratio",
1310 .data
= &sysctl_overcommit_ratio
,
1311 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1313 .proc_handler
= overcommit_ratio_handler
,
1316 .procname
= "overcommit_kbytes",
1317 .data
= &sysctl_overcommit_kbytes
,
1318 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1320 .proc_handler
= overcommit_kbytes_handler
,
1323 .procname
= "page-cluster",
1324 .data
= &page_cluster
,
1325 .maxlen
= sizeof(int),
1327 .proc_handler
= proc_dointvec_minmax
,
1328 .extra1
= SYSCTL_ZERO
,
1331 .procname
= "dirty_background_ratio",
1332 .data
= &dirty_background_ratio
,
1333 .maxlen
= sizeof(dirty_background_ratio
),
1335 .proc_handler
= dirty_background_ratio_handler
,
1336 .extra1
= SYSCTL_ZERO
,
1337 .extra2
= &one_hundred
,
1340 .procname
= "dirty_background_bytes",
1341 .data
= &dirty_background_bytes
,
1342 .maxlen
= sizeof(dirty_background_bytes
),
1344 .proc_handler
= dirty_background_bytes_handler
,
1348 .procname
= "dirty_ratio",
1349 .data
= &vm_dirty_ratio
,
1350 .maxlen
= sizeof(vm_dirty_ratio
),
1352 .proc_handler
= dirty_ratio_handler
,
1353 .extra1
= SYSCTL_ZERO
,
1354 .extra2
= &one_hundred
,
1357 .procname
= "dirty_bytes",
1358 .data
= &vm_dirty_bytes
,
1359 .maxlen
= sizeof(vm_dirty_bytes
),
1361 .proc_handler
= dirty_bytes_handler
,
1362 .extra1
= &dirty_bytes_min
,
1365 .procname
= "dirty_writeback_centisecs",
1366 .data
= &dirty_writeback_interval
,
1367 .maxlen
= sizeof(dirty_writeback_interval
),
1369 .proc_handler
= dirty_writeback_centisecs_handler
,
1372 .procname
= "dirty_expire_centisecs",
1373 .data
= &dirty_expire_interval
,
1374 .maxlen
= sizeof(dirty_expire_interval
),
1376 .proc_handler
= proc_dointvec_minmax
,
1377 .extra1
= SYSCTL_ZERO
,
1380 .procname
= "dirtytime_expire_seconds",
1381 .data
= &dirtytime_expire_interval
,
1382 .maxlen
= sizeof(dirtytime_expire_interval
),
1384 .proc_handler
= dirtytime_interval_handler
,
1385 .extra1
= SYSCTL_ZERO
,
1388 .procname
= "swappiness",
1389 .data
= &vm_swappiness
,
1390 .maxlen
= sizeof(vm_swappiness
),
1392 .proc_handler
= proc_dointvec_minmax
,
1393 .extra1
= SYSCTL_ZERO
,
1394 .extra2
= &one_hundred
,
1396 #ifdef CONFIG_HUGETLB_PAGE
1398 .procname
= "nr_hugepages",
1400 .maxlen
= sizeof(unsigned long),
1402 .proc_handler
= hugetlb_sysctl_handler
,
1406 .procname
= "nr_hugepages_mempolicy",
1408 .maxlen
= sizeof(unsigned long),
1410 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1413 .procname
= "numa_stat",
1414 .data
= &sysctl_vm_numa_stat
,
1415 .maxlen
= sizeof(int),
1417 .proc_handler
= sysctl_vm_numa_stat_handler
,
1418 .extra1
= SYSCTL_ZERO
,
1419 .extra2
= SYSCTL_ONE
,
1423 .procname
= "hugetlb_shm_group",
1424 .data
= &sysctl_hugetlb_shm_group
,
1425 .maxlen
= sizeof(gid_t
),
1427 .proc_handler
= proc_dointvec
,
1430 .procname
= "nr_overcommit_hugepages",
1432 .maxlen
= sizeof(unsigned long),
1434 .proc_handler
= hugetlb_overcommit_handler
,
1438 .procname
= "lowmem_reserve_ratio",
1439 .data
= &sysctl_lowmem_reserve_ratio
,
1440 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1442 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1445 .procname
= "drop_caches",
1446 .data
= &sysctl_drop_caches
,
1447 .maxlen
= sizeof(int),
1449 .proc_handler
= drop_caches_sysctl_handler
,
1450 .extra1
= SYSCTL_ONE
,
1453 #ifdef CONFIG_COMPACTION
1455 .procname
= "compact_memory",
1456 .data
= &sysctl_compact_memory
,
1457 .maxlen
= sizeof(int),
1459 .proc_handler
= sysctl_compaction_handler
,
1462 .procname
= "extfrag_threshold",
1463 .data
= &sysctl_extfrag_threshold
,
1464 .maxlen
= sizeof(int),
1466 .proc_handler
= proc_dointvec_minmax
,
1467 .extra1
= &min_extfrag_threshold
,
1468 .extra2
= &max_extfrag_threshold
,
1471 .procname
= "compact_unevictable_allowed",
1472 .data
= &sysctl_compact_unevictable_allowed
,
1473 .maxlen
= sizeof(int),
1475 .proc_handler
= proc_dointvec_minmax_warn_RT_change
,
1476 .extra1
= SYSCTL_ZERO
,
1477 .extra2
= SYSCTL_ONE
,
1480 #endif /* CONFIG_COMPACTION */
1482 .procname
= "min_free_kbytes",
1483 .data
= &min_free_kbytes
,
1484 .maxlen
= sizeof(min_free_kbytes
),
1486 .proc_handler
= min_free_kbytes_sysctl_handler
,
1487 .extra1
= SYSCTL_ZERO
,
1490 .procname
= "watermark_boost_factor",
1491 .data
= &watermark_boost_factor
,
1492 .maxlen
= sizeof(watermark_boost_factor
),
1494 .proc_handler
= watermark_boost_factor_sysctl_handler
,
1495 .extra1
= SYSCTL_ZERO
,
1498 .procname
= "watermark_scale_factor",
1499 .data
= &watermark_scale_factor
,
1500 .maxlen
= sizeof(watermark_scale_factor
),
1502 .proc_handler
= watermark_scale_factor_sysctl_handler
,
1503 .extra1
= SYSCTL_ONE
,
1504 .extra2
= &one_thousand
,
1507 .procname
= "percpu_pagelist_fraction",
1508 .data
= &percpu_pagelist_fraction
,
1509 .maxlen
= sizeof(percpu_pagelist_fraction
),
1511 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1512 .extra1
= SYSCTL_ZERO
,
1516 .procname
= "max_map_count",
1517 .data
= &sysctl_max_map_count
,
1518 .maxlen
= sizeof(sysctl_max_map_count
),
1520 .proc_handler
= proc_dointvec_minmax
,
1521 .extra1
= SYSCTL_ZERO
,
1525 .procname
= "nr_trim_pages",
1526 .data
= &sysctl_nr_trim_pages
,
1527 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1529 .proc_handler
= proc_dointvec_minmax
,
1530 .extra1
= SYSCTL_ZERO
,
1534 .procname
= "laptop_mode",
1535 .data
= &laptop_mode
,
1536 .maxlen
= sizeof(laptop_mode
),
1538 .proc_handler
= proc_dointvec_jiffies
,
1541 .procname
= "block_dump",
1542 .data
= &block_dump
,
1543 .maxlen
= sizeof(block_dump
),
1545 .proc_handler
= proc_dointvec
,
1546 .extra1
= SYSCTL_ZERO
,
1549 .procname
= "vfs_cache_pressure",
1550 .data
= &sysctl_vfs_cache_pressure
,
1551 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1553 .proc_handler
= proc_dointvec
,
1554 .extra1
= SYSCTL_ZERO
,
1556 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
1557 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
1559 .procname
= "legacy_va_layout",
1560 .data
= &sysctl_legacy_va_layout
,
1561 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1563 .proc_handler
= proc_dointvec
,
1564 .extra1
= SYSCTL_ZERO
,
1569 .procname
= "zone_reclaim_mode",
1570 .data
= &node_reclaim_mode
,
1571 .maxlen
= sizeof(node_reclaim_mode
),
1573 .proc_handler
= proc_dointvec
,
1574 .extra1
= SYSCTL_ZERO
,
1577 .procname
= "min_unmapped_ratio",
1578 .data
= &sysctl_min_unmapped_ratio
,
1579 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1581 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1582 .extra1
= SYSCTL_ZERO
,
1583 .extra2
= &one_hundred
,
1586 .procname
= "min_slab_ratio",
1587 .data
= &sysctl_min_slab_ratio
,
1588 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1590 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1591 .extra1
= SYSCTL_ZERO
,
1592 .extra2
= &one_hundred
,
1597 .procname
= "stat_interval",
1598 .data
= &sysctl_stat_interval
,
1599 .maxlen
= sizeof(sysctl_stat_interval
),
1601 .proc_handler
= proc_dointvec_jiffies
,
1604 .procname
= "stat_refresh",
1608 .proc_handler
= vmstat_refresh
,
1613 .procname
= "mmap_min_addr",
1614 .data
= &dac_mmap_min_addr
,
1615 .maxlen
= sizeof(unsigned long),
1617 .proc_handler
= mmap_min_addr_handler
,
1622 .procname
= "numa_zonelist_order",
1623 .data
= &numa_zonelist_order
,
1624 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1626 .proc_handler
= numa_zonelist_order_handler
,
1629 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1630 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1632 .procname
= "vdso_enabled",
1633 #ifdef CONFIG_X86_32
1634 .data
= &vdso32_enabled
,
1635 .maxlen
= sizeof(vdso32_enabled
),
1637 .data
= &vdso_enabled
,
1638 .maxlen
= sizeof(vdso_enabled
),
1641 .proc_handler
= proc_dointvec
,
1642 .extra1
= SYSCTL_ZERO
,
1645 #ifdef CONFIG_HIGHMEM
1647 .procname
= "highmem_is_dirtyable",
1648 .data
= &vm_highmem_is_dirtyable
,
1649 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1651 .proc_handler
= proc_dointvec_minmax
,
1652 .extra1
= SYSCTL_ZERO
,
1653 .extra2
= SYSCTL_ONE
,
1656 #ifdef CONFIG_MEMORY_FAILURE
1658 .procname
= "memory_failure_early_kill",
1659 .data
= &sysctl_memory_failure_early_kill
,
1660 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1662 .proc_handler
= proc_dointvec_minmax
,
1663 .extra1
= SYSCTL_ZERO
,
1664 .extra2
= SYSCTL_ONE
,
1667 .procname
= "memory_failure_recovery",
1668 .data
= &sysctl_memory_failure_recovery
,
1669 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1671 .proc_handler
= proc_dointvec_minmax
,
1672 .extra1
= SYSCTL_ZERO
,
1673 .extra2
= SYSCTL_ONE
,
1677 .procname
= "user_reserve_kbytes",
1678 .data
= &sysctl_user_reserve_kbytes
,
1679 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1681 .proc_handler
= proc_doulongvec_minmax
,
1684 .procname
= "admin_reserve_kbytes",
1685 .data
= &sysctl_admin_reserve_kbytes
,
1686 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1688 .proc_handler
= proc_doulongvec_minmax
,
1690 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1692 .procname
= "mmap_rnd_bits",
1693 .data
= &mmap_rnd_bits
,
1694 .maxlen
= sizeof(mmap_rnd_bits
),
1696 .proc_handler
= proc_dointvec_minmax
,
1697 .extra1
= (void *)&mmap_rnd_bits_min
,
1698 .extra2
= (void *)&mmap_rnd_bits_max
,
1701 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1703 .procname
= "mmap_rnd_compat_bits",
1704 .data
= &mmap_rnd_compat_bits
,
1705 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1707 .proc_handler
= proc_dointvec_minmax
,
1708 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1709 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1712 #ifdef CONFIG_USERFAULTFD
1714 .procname
= "unprivileged_userfaultfd",
1715 .data
= &sysctl_unprivileged_userfaultfd
,
1716 .maxlen
= sizeof(sysctl_unprivileged_userfaultfd
),
1718 .proc_handler
= proc_dointvec_minmax
,
1719 .extra1
= SYSCTL_ZERO
,
1720 .extra2
= SYSCTL_ONE
,
1726 static struct ctl_table fs_table
[] = {
1728 .procname
= "inode-nr",
1729 .data
= &inodes_stat
,
1730 .maxlen
= 2*sizeof(long),
1732 .proc_handler
= proc_nr_inodes
,
1735 .procname
= "inode-state",
1736 .data
= &inodes_stat
,
1737 .maxlen
= 7*sizeof(long),
1739 .proc_handler
= proc_nr_inodes
,
1742 .procname
= "file-nr",
1743 .data
= &files_stat
,
1744 .maxlen
= sizeof(files_stat
),
1746 .proc_handler
= proc_nr_files
,
1749 .procname
= "file-max",
1750 .data
= &files_stat
.max_files
,
1751 .maxlen
= sizeof(files_stat
.max_files
),
1753 .proc_handler
= proc_doulongvec_minmax
,
1755 .extra2
= &long_max
,
1758 .procname
= "nr_open",
1759 .data
= &sysctl_nr_open
,
1760 .maxlen
= sizeof(unsigned int),
1762 .proc_handler
= proc_dointvec_minmax
,
1763 .extra1
= &sysctl_nr_open_min
,
1764 .extra2
= &sysctl_nr_open_max
,
1767 .procname
= "dentry-state",
1768 .data
= &dentry_stat
,
1769 .maxlen
= 6*sizeof(long),
1771 .proc_handler
= proc_nr_dentry
,
1774 .procname
= "overflowuid",
1775 .data
= &fs_overflowuid
,
1776 .maxlen
= sizeof(int),
1778 .proc_handler
= proc_dointvec_minmax
,
1779 .extra1
= &minolduid
,
1780 .extra2
= &maxolduid
,
1783 .procname
= "overflowgid",
1784 .data
= &fs_overflowgid
,
1785 .maxlen
= sizeof(int),
1787 .proc_handler
= proc_dointvec_minmax
,
1788 .extra1
= &minolduid
,
1789 .extra2
= &maxolduid
,
1791 #ifdef CONFIG_FILE_LOCKING
1793 .procname
= "leases-enable",
1794 .data
= &leases_enable
,
1795 .maxlen
= sizeof(int),
1797 .proc_handler
= proc_dointvec
,
1800 #ifdef CONFIG_DNOTIFY
1802 .procname
= "dir-notify-enable",
1803 .data
= &dir_notify_enable
,
1804 .maxlen
= sizeof(int),
1806 .proc_handler
= proc_dointvec
,
1810 #ifdef CONFIG_FILE_LOCKING
1812 .procname
= "lease-break-time",
1813 .data
= &lease_break_time
,
1814 .maxlen
= sizeof(int),
1816 .proc_handler
= proc_dointvec
,
1821 .procname
= "aio-nr",
1823 .maxlen
= sizeof(aio_nr
),
1825 .proc_handler
= proc_doulongvec_minmax
,
1828 .procname
= "aio-max-nr",
1829 .data
= &aio_max_nr
,
1830 .maxlen
= sizeof(aio_max_nr
),
1832 .proc_handler
= proc_doulongvec_minmax
,
1834 #endif /* CONFIG_AIO */
1835 #ifdef CONFIG_INOTIFY_USER
1837 .procname
= "inotify",
1839 .child
= inotify_table
,
1844 .procname
= "epoll",
1846 .child
= epoll_table
,
1851 .procname
= "protected_symlinks",
1852 .data
= &sysctl_protected_symlinks
,
1853 .maxlen
= sizeof(int),
1855 .proc_handler
= proc_dointvec_minmax
,
1856 .extra1
= SYSCTL_ZERO
,
1857 .extra2
= SYSCTL_ONE
,
1860 .procname
= "protected_hardlinks",
1861 .data
= &sysctl_protected_hardlinks
,
1862 .maxlen
= sizeof(int),
1864 .proc_handler
= proc_dointvec_minmax
,
1865 .extra1
= SYSCTL_ZERO
,
1866 .extra2
= SYSCTL_ONE
,
1869 .procname
= "protected_fifos",
1870 .data
= &sysctl_protected_fifos
,
1871 .maxlen
= sizeof(int),
1873 .proc_handler
= proc_dointvec_minmax
,
1874 .extra1
= SYSCTL_ZERO
,
1878 .procname
= "protected_regular",
1879 .data
= &sysctl_protected_regular
,
1880 .maxlen
= sizeof(int),
1882 .proc_handler
= proc_dointvec_minmax
,
1883 .extra1
= SYSCTL_ZERO
,
1887 .procname
= "suid_dumpable",
1888 .data
= &suid_dumpable
,
1889 .maxlen
= sizeof(int),
1891 .proc_handler
= proc_dointvec_minmax_coredump
,
1892 .extra1
= SYSCTL_ZERO
,
1895 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1897 .procname
= "binfmt_misc",
1899 .child
= sysctl_mount_point
,
1903 .procname
= "pipe-max-size",
1904 .data
= &pipe_max_size
,
1905 .maxlen
= sizeof(pipe_max_size
),
1907 .proc_handler
= proc_dopipe_max_size
,
1910 .procname
= "pipe-user-pages-hard",
1911 .data
= &pipe_user_pages_hard
,
1912 .maxlen
= sizeof(pipe_user_pages_hard
),
1914 .proc_handler
= proc_doulongvec_minmax
,
1917 .procname
= "pipe-user-pages-soft",
1918 .data
= &pipe_user_pages_soft
,
1919 .maxlen
= sizeof(pipe_user_pages_soft
),
1921 .proc_handler
= proc_doulongvec_minmax
,
1924 .procname
= "mount-max",
1925 .data
= &sysctl_mount_max
,
1926 .maxlen
= sizeof(unsigned int),
1928 .proc_handler
= proc_dointvec_minmax
,
1929 .extra1
= SYSCTL_ONE
,
1934 static struct ctl_table debug_table
[] = {
1935 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1937 .procname
= "exception-trace",
1938 .data
= &show_unhandled_signals
,
1939 .maxlen
= sizeof(int),
1941 .proc_handler
= proc_dointvec
1944 #if defined(CONFIG_OPTPROBES)
1946 .procname
= "kprobes-optimization",
1947 .data
= &sysctl_kprobes_optimization
,
1948 .maxlen
= sizeof(int),
1950 .proc_handler
= proc_kprobes_optimization_handler
,
1951 .extra1
= SYSCTL_ZERO
,
1952 .extra2
= SYSCTL_ONE
,
1958 static struct ctl_table dev_table
[] = {
1962 int __init
sysctl_init(void)
1964 struct ctl_table_header
*hdr
;
1966 hdr
= register_sysctl_table(sysctl_base_table
);
1967 kmemleak_not_leak(hdr
);
1971 #endif /* CONFIG_SYSCTL */
1977 #ifdef CONFIG_PROC_SYSCTL
1979 static int _proc_do_string(char *data
, int maxlen
, int write
,
1980 char __user
*buffer
,
1981 size_t *lenp
, loff_t
*ppos
)
1987 if (!data
|| !maxlen
|| !*lenp
) {
1993 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1994 /* Only continue writes not past the end of buffer. */
1996 if (len
> maxlen
- 1)
2003 /* Start writing from beginning of buffer. */
2009 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
2010 if (get_user(c
, p
++))
2012 if (c
== 0 || c
== '\n')
2033 if (copy_to_user(buffer
, data
, len
))
2036 if (put_user('\n', buffer
+ len
))
2046 static void warn_sysctl_write(struct ctl_table
*table
)
2048 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2049 "This will not be supported in the future. To silence this\n"
2050 "warning, set kernel.sysctl_writes_strict = -1\n",
2051 current
->comm
, table
->procname
);
2055 * proc_first_pos_non_zero_ignore - check if first position is allowed
2056 * @ppos: file position
2057 * @table: the sysctl table
2059 * Returns true if the first position is non-zero and the sysctl_writes_strict
2060 * mode indicates this is not allowed for numeric input types. String proc
2061 * handlers can ignore the return value.
2063 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
2064 struct ctl_table
*table
)
2069 switch (sysctl_writes_strict
) {
2070 case SYSCTL_WRITES_STRICT
:
2072 case SYSCTL_WRITES_WARN
:
2073 warn_sysctl_write(table
);
2081 * proc_dostring - read a string sysctl
2082 * @table: the sysctl table
2083 * @write: %TRUE if this is a write to the sysctl file
2084 * @buffer: the user buffer
2085 * @lenp: the size of the user buffer
2086 * @ppos: file position
2088 * Reads/writes a string from/to the user buffer. If the kernel
2089 * buffer provided is not large enough to hold the string, the
2090 * string is truncated. The copied string is %NULL-terminated.
2091 * If the string is being read by the user process, it is copied
2092 * and a newline '\n' is added. It is truncated if the buffer is
2095 * Returns 0 on success.
2097 int proc_dostring(struct ctl_table
*table
, int write
,
2098 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2101 proc_first_pos_non_zero_ignore(ppos
, table
);
2103 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2104 (char __user
*)buffer
, lenp
, ppos
);
2107 static size_t proc_skip_spaces(char **buf
)
2110 char *tmp
= skip_spaces(*buf
);
2116 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2127 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2130 * @cp: kernel buffer containing the string to parse
2131 * @endp: pointer to store the trailing characters
2132 * @base: the base to use
2133 * @res: where the parsed integer will be stored
2135 * In case of success 0 is returned and @res will contain the parsed integer,
2136 * @endp will hold any trailing characters.
2137 * This function will fail the parse on overflow. If there wasn't an overflow
2138 * the function will defer the decision what characters count as invalid to the
2141 static int strtoul_lenient(const char *cp
, char **endp
, unsigned int base
,
2144 unsigned long long result
;
2147 cp
= _parse_integer_fixup_radix(cp
, &base
);
2148 rv
= _parse_integer(cp
, base
, &result
);
2149 if ((rv
& KSTRTOX_OVERFLOW
) || (result
!= (unsigned long)result
))
2157 *res
= (unsigned long)result
;
2161 #define TMPBUFLEN 22
2163 * proc_get_long - reads an ASCII formatted integer from a user buffer
2165 * @buf: a kernel buffer
2166 * @size: size of the kernel buffer
2167 * @val: this is where the number will be stored
2168 * @neg: set to %TRUE if number is negative
2169 * @perm_tr: a vector which contains the allowed trailers
2170 * @perm_tr_len: size of the perm_tr vector
2171 * @tr: pointer to store the trailer character
2173 * In case of success %0 is returned and @buf and @size are updated with
2174 * the amount of bytes read. If @tr is non-NULL and a trailing
2175 * character exists (size is non-zero after returning from this
2176 * function), @tr is updated with the trailing character.
2178 static int proc_get_long(char **buf
, size_t *size
,
2179 unsigned long *val
, bool *neg
,
2180 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2183 char *p
, tmp
[TMPBUFLEN
];
2189 if (len
> TMPBUFLEN
- 1)
2190 len
= TMPBUFLEN
- 1;
2192 memcpy(tmp
, *buf
, len
);
2196 if (*p
== '-' && *size
> 1) {
2204 if (strtoul_lenient(p
, &p
, 0, val
))
2209 /* We don't know if the next char is whitespace thus we may accept
2210 * invalid integers (e.g. 1234...a) or two integers instead of one
2211 * (e.g. 123...1). So lets not allow such large numbers. */
2212 if (len
== TMPBUFLEN
- 1)
2215 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2218 if (tr
&& (len
< *size
))
2228 * proc_put_long - converts an integer to a decimal ASCII formatted string
2230 * @buf: the user buffer
2231 * @size: the size of the user buffer
2232 * @val: the integer to be converted
2233 * @neg: sign of the number, %TRUE for negative
2235 * In case of success %0 is returned and @buf and @size are updated with
2236 * the amount of bytes written.
2238 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2242 char tmp
[TMPBUFLEN
], *p
= tmp
;
2244 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2248 if (copy_to_user(*buf
, tmp
, len
))
2256 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2259 char __user
**buffer
= (char __user
**)buf
;
2260 if (put_user(c
, *buffer
))
2262 (*size
)--, (*buffer
)++;
2268 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2270 int write
, void *data
)
2274 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2278 if (*lvalp
> (unsigned long) INT_MAX
)
2286 *lvalp
= -(unsigned long)val
;
2289 *lvalp
= (unsigned long)val
;
2295 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2297 int write
, void *data
)
2300 if (*lvalp
> UINT_MAX
)
2304 unsigned int val
= *valp
;
2305 *lvalp
= (unsigned long)val
;
2310 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2312 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2313 int write
, void __user
*buffer
,
2314 size_t *lenp
, loff_t
*ppos
,
2315 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2316 int write
, void *data
),
2319 int *i
, vleft
, first
= 1, err
= 0;
2321 char *kbuf
= NULL
, *p
;
2323 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2328 i
= (int *) tbl_data
;
2329 vleft
= table
->maxlen
/ sizeof(*i
);
2333 conv
= do_proc_dointvec_conv
;
2336 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2339 if (left
> PAGE_SIZE
- 1)
2340 left
= PAGE_SIZE
- 1;
2341 p
= kbuf
= memdup_user_nul(buffer
, left
);
2343 return PTR_ERR(kbuf
);
2346 for (; left
&& vleft
--; i
++, first
=0) {
2351 left
-= proc_skip_spaces(&p
);
2355 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2357 sizeof(proc_wspace_sep
), NULL
);
2360 if (conv(&neg
, &lval
, i
, 1, data
)) {
2365 if (conv(&neg
, &lval
, i
, 0, data
)) {
2370 err
= proc_put_char(&buffer
, &left
, '\t');
2373 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2379 if (!write
&& !first
&& left
&& !err
)
2380 err
= proc_put_char(&buffer
, &left
, '\n');
2381 if (write
&& !err
&& left
)
2382 left
-= proc_skip_spaces(&p
);
2386 return err
? : -EINVAL
;
2394 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2395 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2396 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2397 int write
, void *data
),
2400 return __do_proc_dointvec(table
->data
, table
, write
,
2401 buffer
, lenp
, ppos
, conv
, data
);
2404 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2405 struct ctl_table
*table
,
2406 void __user
*buffer
,
2407 size_t *lenp
, loff_t
*ppos
,
2408 int (*conv
)(unsigned long *lvalp
,
2410 int write
, void *data
),
2417 char *kbuf
= NULL
, *p
;
2421 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2424 if (left
> PAGE_SIZE
- 1)
2425 left
= PAGE_SIZE
- 1;
2427 p
= kbuf
= memdup_user_nul(buffer
, left
);
2431 left
-= proc_skip_spaces(&p
);
2437 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2439 sizeof(proc_wspace_sep
), NULL
);
2445 if (conv(&lval
, tbl_data
, 1, data
)) {
2451 left
-= proc_skip_spaces(&p
);
2460 /* This is in keeping with old __do_proc_dointvec() */
2466 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2467 size_t *lenp
, loff_t
*ppos
,
2468 int (*conv
)(unsigned long *lvalp
,
2470 int write
, void *data
),
2479 if (conv(&lval
, tbl_data
, 0, data
)) {
2484 err
= proc_put_long(&buffer
, &left
, lval
, false);
2488 err
= proc_put_char(&buffer
, &left
, '\n');
2497 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2498 int write
, void __user
*buffer
,
2499 size_t *lenp
, loff_t
*ppos
,
2500 int (*conv
)(unsigned long *lvalp
,
2502 int write
, void *data
),
2505 unsigned int *i
, vleft
;
2507 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2512 i
= (unsigned int *) tbl_data
;
2513 vleft
= table
->maxlen
/ sizeof(*i
);
2516 * Arrays are not supported, keep this simple. *Do not* add
2525 conv
= do_proc_douintvec_conv
;
2528 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2530 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2533 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2534 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2535 int (*conv
)(unsigned long *lvalp
,
2537 int write
, void *data
),
2540 return __do_proc_douintvec(table
->data
, table
, write
,
2541 buffer
, lenp
, ppos
, conv
, data
);
2545 * proc_dointvec - read a vector of integers
2546 * @table: the sysctl table
2547 * @write: %TRUE if this is a write to the sysctl file
2548 * @buffer: the user buffer
2549 * @lenp: the size of the user buffer
2550 * @ppos: file position
2552 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2553 * values from/to the user buffer, treated as an ASCII string.
2555 * Returns 0 on success.
2557 int proc_dointvec(struct ctl_table
*table
, int write
,
2558 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2560 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2563 #ifdef CONFIG_COMPACTION
2564 static int proc_dointvec_minmax_warn_RT_change(struct ctl_table
*table
,
2565 int write
, void __user
*buffer
,
2566 size_t *lenp
, loff_t
*ppos
)
2570 if (!IS_ENABLED(CONFIG_PREEMPT_RT
) || !write
)
2571 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2573 old
= *(int *)table
->data
;
2574 ret
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2577 if (old
!= *(int *)table
->data
)
2578 pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
2579 table
->procname
, current
->comm
,
2580 task_pid_nr(current
));
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 #ifdef CONFIG_MAGIC_SYSRQ
2849 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
2850 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2856 ret
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2857 lenp
, ppos
, NULL
, NULL
);
2862 sysrq_toggle_support(tmp
);
2868 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2869 void __user
*buffer
,
2870 size_t *lenp
, loff_t
*ppos
,
2871 unsigned long convmul
,
2872 unsigned long convdiv
)
2874 unsigned long *i
, *min
, *max
;
2875 int vleft
, first
= 1, err
= 0;
2877 char *kbuf
= NULL
, *p
;
2879 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2884 i
= (unsigned long *) data
;
2885 min
= (unsigned long *) table
->extra1
;
2886 max
= (unsigned long *) table
->extra2
;
2887 vleft
= table
->maxlen
/ sizeof(unsigned long);
2891 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2894 if (left
> PAGE_SIZE
- 1)
2895 left
= PAGE_SIZE
- 1;
2896 p
= kbuf
= memdup_user_nul(buffer
, left
);
2898 return PTR_ERR(kbuf
);
2901 for (; left
&& vleft
--; i
++, first
= 0) {
2907 left
-= proc_skip_spaces(&p
);
2911 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2913 sizeof(proc_wspace_sep
), NULL
);
2918 val
= convmul
* val
/ convdiv
;
2919 if ((min
&& val
< *min
) || (max
&& val
> *max
)) {
2925 val
= convdiv
* (*i
) / convmul
;
2927 err
= proc_put_char(&buffer
, &left
, '\t');
2931 err
= proc_put_long(&buffer
, &left
, val
, false);
2937 if (!write
&& !first
&& left
&& !err
)
2938 err
= proc_put_char(&buffer
, &left
, '\n');
2940 left
-= proc_skip_spaces(&p
);
2944 return err
? : -EINVAL
;
2952 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2953 void __user
*buffer
,
2954 size_t *lenp
, loff_t
*ppos
,
2955 unsigned long convmul
,
2956 unsigned long convdiv
)
2958 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2959 buffer
, lenp
, ppos
, convmul
, convdiv
);
2963 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2964 * @table: the sysctl table
2965 * @write: %TRUE if this is a write to the sysctl file
2966 * @buffer: the user buffer
2967 * @lenp: the size of the user buffer
2968 * @ppos: file position
2970 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2971 * values from/to the user buffer, treated as an ASCII string.
2973 * This routine will ensure the values are within the range specified by
2974 * table->extra1 (min) and table->extra2 (max).
2976 * Returns 0 on success.
2978 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2979 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2981 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2985 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2986 * @table: the sysctl table
2987 * @write: %TRUE if this is a write to the sysctl file
2988 * @buffer: the user buffer
2989 * @lenp: the size of the user buffer
2990 * @ppos: file position
2992 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2993 * values from/to the user buffer, treated as an ASCII string. The values
2994 * are treated as milliseconds, and converted to jiffies when they are stored.
2996 * This routine will ensure the values are within the range specified by
2997 * table->extra1 (min) and table->extra2 (max).
2999 * Returns 0 on success.
3001 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3002 void __user
*buffer
,
3003 size_t *lenp
, loff_t
*ppos
)
3005 return do_proc_doulongvec_minmax(table
, write
, buffer
,
3006 lenp
, ppos
, HZ
, 1000l);
3010 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
3012 int write
, void *data
)
3015 if (*lvalp
> INT_MAX
/ HZ
)
3017 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
3023 lval
= -(unsigned long)val
;
3026 lval
= (unsigned long)val
;
3033 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
3035 int write
, void *data
)
3038 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
3040 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
3046 lval
= -(unsigned long)val
;
3049 lval
= (unsigned long)val
;
3051 *lvalp
= jiffies_to_clock_t(lval
);
3056 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
3058 int write
, void *data
)
3061 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
3071 lval
= -(unsigned long)val
;
3074 lval
= (unsigned long)val
;
3076 *lvalp
= jiffies_to_msecs(lval
);
3082 * proc_dointvec_jiffies - read a vector of integers as seconds
3083 * @table: the sysctl table
3084 * @write: %TRUE if this is a write to the sysctl file
3085 * @buffer: the user buffer
3086 * @lenp: the size of the user buffer
3087 * @ppos: file position
3089 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3090 * values from/to the user buffer, treated as an ASCII string.
3091 * The values read are assumed to be in seconds, and are converted into
3094 * Returns 0 on success.
3096 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3097 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3099 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
3100 do_proc_dointvec_jiffies_conv
,NULL
);
3104 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3105 * @table: the sysctl table
3106 * @write: %TRUE if this is a write to the sysctl file
3107 * @buffer: the user buffer
3108 * @lenp: the size of the user buffer
3109 * @ppos: pointer to the file position
3111 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3112 * values from/to the user buffer, treated as an ASCII string.
3113 * The values read are assumed to be in 1/USER_HZ seconds, and
3114 * are converted into jiffies.
3116 * Returns 0 on success.
3118 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3119 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3121 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
3122 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
3126 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3127 * @table: the sysctl table
3128 * @write: %TRUE if this is a write to the sysctl file
3129 * @buffer: the user buffer
3130 * @lenp: the size of the user buffer
3131 * @ppos: file position
3132 * @ppos: the current position in the file
3134 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3135 * values from/to the user buffer, treated as an ASCII string.
3136 * The values read are assumed to be in 1/1000 seconds, and
3137 * are converted into jiffies.
3139 * Returns 0 on success.
3141 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3142 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3144 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
3145 do_proc_dointvec_ms_jiffies_conv
, NULL
);
3148 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
3149 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3151 struct pid
*new_pid
;
3155 tmp
= pid_vnr(cad_pid
);
3157 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
3158 lenp
, ppos
, NULL
, NULL
);
3162 new_pid
= find_get_pid(tmp
);
3166 put_pid(xchg(&cad_pid
, new_pid
));
3171 * proc_do_large_bitmap - read/write from/to a large bitmap
3172 * @table: the sysctl table
3173 * @write: %TRUE if this is a write to the sysctl file
3174 * @buffer: the user buffer
3175 * @lenp: the size of the user buffer
3176 * @ppos: file position
3178 * The bitmap is stored at table->data and the bitmap length (in bits)
3181 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3182 * large bitmaps may be represented in a compact manner. Writing into
3183 * the file will clear the bitmap then update it with the given input.
3185 * Returns 0 on success.
3187 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3188 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3192 size_t left
= *lenp
;
3193 unsigned long bitmap_len
= table
->maxlen
;
3194 unsigned long *bitmap
= *(unsigned long **) table
->data
;
3195 unsigned long *tmp_bitmap
= NULL
;
3196 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
3198 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3207 if (left
> PAGE_SIZE
- 1) {
3208 left
= PAGE_SIZE
- 1;
3209 /* How much of the buffer we'll skip this pass */
3210 skipped
= *lenp
- left
;
3213 p
= kbuf
= memdup_user_nul(buffer
, left
);
3215 return PTR_ERR(kbuf
);
3217 tmp_bitmap
= bitmap_zalloc(bitmap_len
, GFP_KERNEL
);
3222 proc_skip_char(&p
, &left
, '\n');
3223 while (!err
&& left
) {
3224 unsigned long val_a
, val_b
;
3228 /* In case we stop parsing mid-number, we can reset */
3230 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3233 * If we consumed the entirety of a truncated buffer or
3234 * only one char is left (may be a "-"), then stop here,
3235 * reset, & come back for more.
3237 if ((left
<= 1) && skipped
) {
3244 if (val_a
>= bitmap_len
|| neg
) {
3256 err
= proc_get_long(&p
, &left
, &val_b
,
3257 &neg
, tr_b
, sizeof(tr_b
),
3260 * If we consumed all of a truncated buffer or
3261 * then stop here, reset, & come back for more.
3263 if (!left
&& skipped
) {
3270 if (val_b
>= bitmap_len
|| neg
||
3281 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3283 proc_skip_char(&p
, &left
, '\n');
3288 unsigned long bit_a
, bit_b
= 0;
3291 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3292 if (bit_a
>= bitmap_len
)
3294 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3298 err
= proc_put_char(&buffer
, &left
, ',');
3302 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3305 if (bit_a
!= bit_b
) {
3306 err
= proc_put_char(&buffer
, &left
, '-');
3309 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3317 err
= proc_put_char(&buffer
, &left
, '\n');
3323 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3325 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3331 bitmap_free(tmp_bitmap
);
3335 #else /* CONFIG_PROC_SYSCTL */
3337 int proc_dostring(struct ctl_table
*table
, int write
,
3338 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3343 int proc_dointvec(struct ctl_table
*table
, int write
,
3344 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3349 int proc_douintvec(struct ctl_table
*table
, int write
,
3350 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3355 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3356 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3361 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3362 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3367 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3368 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3373 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3374 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3379 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3380 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3385 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3386 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3391 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3392 void __user
*buffer
,
3393 size_t *lenp
, loff_t
*ppos
)
3398 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3399 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3404 #endif /* CONFIG_PROC_SYSCTL */
3406 #if defined(CONFIG_SYSCTL)
3407 int proc_do_static_key(struct ctl_table
*table
, int write
,
3408 void __user
*buffer
, size_t *lenp
,
3411 struct static_key
*key
= (struct static_key
*)table
->data
;
3412 static DEFINE_MUTEX(static_key_mutex
);
3414 struct ctl_table tmp
= {
3416 .maxlen
= sizeof(val
),
3417 .mode
= table
->mode
,
3418 .extra1
= SYSCTL_ZERO
,
3419 .extra2
= SYSCTL_ONE
,
3422 if (write
&& !capable(CAP_SYS_ADMIN
))
3425 mutex_lock(&static_key_mutex
);
3426 val
= static_key_enabled(key
);
3427 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
3428 if (write
&& !ret
) {
3430 static_key_enable(key
);
3432 static_key_disable(key
);
3434 mutex_unlock(&static_key_mutex
);
3439 * No sense putting this after each symbol definition, twice,
3440 * exception granted :-)
3442 EXPORT_SYMBOL(proc_dointvec
);
3443 EXPORT_SYMBOL(proc_douintvec
);
3444 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3445 EXPORT_SYMBOL(proc_dointvec_minmax
);
3446 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3447 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3448 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3449 EXPORT_SYMBOL(proc_dostring
);
3450 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3451 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3452 EXPORT_SYMBOL(proc_do_large_bitmap
);