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
;
113 #ifdef CONFIG_USER_NS
114 extern int unprivileged_userns_clone
;
117 extern int pid_max_min
, pid_max_max
;
118 extern int percpu_pagelist_fraction
;
119 extern int latencytop_enabled
;
120 extern unsigned int sysctl_nr_open_min
, sysctl_nr_open_max
;
122 extern int sysctl_nr_trim_pages
;
125 /* Constants used for minimum and maximum */
126 #ifdef CONFIG_LOCKUP_DETECTOR
127 static int sixty
= 60;
130 static int __maybe_unused neg_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 length 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
,
388 .extra1
= SYSCTL_ZERO
,
389 .extra2
= SYSCTL_ONE
,
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
,
421 .extra1
= SYSCTL_ONE
,
424 .procname
= "numa_balancing",
425 .data
= NULL
, /* filled in by handler */
426 .maxlen
= sizeof(unsigned int),
428 .proc_handler
= sysctl_numa_balancing
,
429 .extra1
= SYSCTL_ZERO
,
430 .extra2
= SYSCTL_ONE
,
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
,
478 .extra1
= SYSCTL_ZERO
,
479 .extra2
= SYSCTL_ONE
,
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
,
489 .extra1
= SYSCTL_ONE
,
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
,
499 .extra1
= SYSCTL_ZERO
,
500 .extra2
= SYSCTL_ONE
,
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_USER_NS
553 .procname
= "unprivileged_userns_clone",
554 .data
= &unprivileged_userns_clone
,
555 .maxlen
= sizeof(int),
557 .proc_handler
= proc_dointvec
,
560 #ifdef CONFIG_PROC_SYSCTL
562 .procname
= "tainted",
563 .maxlen
= sizeof(long),
565 .proc_handler
= proc_taint
,
568 .procname
= "sysctl_writes_strict",
569 .data
= &sysctl_writes_strict
,
570 .maxlen
= sizeof(int),
572 .proc_handler
= proc_dointvec_minmax
,
574 .extra2
= SYSCTL_ONE
,
577 #ifdef CONFIG_LATENCYTOP
579 .procname
= "latencytop",
580 .data
= &latencytop_enabled
,
581 .maxlen
= sizeof(int),
583 .proc_handler
= sysctl_latencytop
,
586 #ifdef CONFIG_BLK_DEV_INITRD
588 .procname
= "real-root-dev",
589 .data
= &real_root_dev
,
590 .maxlen
= sizeof(int),
592 .proc_handler
= proc_dointvec
,
596 .procname
= "print-fatal-signals",
597 .data
= &print_fatal_signals
,
598 .maxlen
= sizeof(int),
600 .proc_handler
= proc_dointvec
,
604 .procname
= "reboot-cmd",
605 .data
= reboot_command
,
608 .proc_handler
= proc_dostring
,
611 .procname
= "stop-a",
612 .data
= &stop_a_enabled
,
613 .maxlen
= sizeof (int),
615 .proc_handler
= proc_dointvec
,
618 .procname
= "scons-poweroff",
619 .data
= &scons_pwroff
,
620 .maxlen
= sizeof (int),
622 .proc_handler
= proc_dointvec
,
625 #ifdef CONFIG_SPARC64
627 .procname
= "tsb-ratio",
628 .data
= &sysctl_tsb_ratio
,
629 .maxlen
= sizeof (int),
631 .proc_handler
= proc_dointvec
,
636 .procname
= "soft-power",
637 .data
= &pwrsw_enabled
,
638 .maxlen
= sizeof (int),
640 .proc_handler
= proc_dointvec
,
643 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
645 .procname
= "unaligned-trap",
646 .data
= &unaligned_enabled
,
647 .maxlen
= sizeof (int),
649 .proc_handler
= proc_dointvec
,
653 .procname
= "ctrl-alt-del",
655 .maxlen
= sizeof(int),
657 .proc_handler
= proc_dointvec
,
659 #ifdef CONFIG_FUNCTION_TRACER
661 .procname
= "ftrace_enabled",
662 .data
= &ftrace_enabled
,
663 .maxlen
= sizeof(int),
665 .proc_handler
= ftrace_enable_sysctl
,
668 #ifdef CONFIG_STACK_TRACER
670 .procname
= "stack_tracer_enabled",
671 .data
= &stack_tracer_enabled
,
672 .maxlen
= sizeof(int),
674 .proc_handler
= stack_trace_sysctl
,
677 #ifdef CONFIG_TRACING
679 .procname
= "ftrace_dump_on_oops",
680 .data
= &ftrace_dump_on_oops
,
681 .maxlen
= sizeof(int),
683 .proc_handler
= proc_dointvec
,
686 .procname
= "traceoff_on_warning",
687 .data
= &__disable_trace_on_warning
,
688 .maxlen
= sizeof(__disable_trace_on_warning
),
690 .proc_handler
= proc_dointvec
,
693 .procname
= "tracepoint_printk",
694 .data
= &tracepoint_printk
,
695 .maxlen
= sizeof(tracepoint_printk
),
697 .proc_handler
= tracepoint_printk_sysctl
,
700 #ifdef CONFIG_KEXEC_CORE
702 .procname
= "kexec_load_disabled",
703 .data
= &kexec_load_disabled
,
704 .maxlen
= sizeof(int),
706 /* only handle a transition from default "0" to "1" */
707 .proc_handler
= proc_dointvec_minmax
,
708 .extra1
= SYSCTL_ONE
,
709 .extra2
= SYSCTL_ONE
,
712 #ifdef CONFIG_MODULES
714 .procname
= "modprobe",
715 .data
= &modprobe_path
,
716 .maxlen
= KMOD_PATH_LEN
,
718 .proc_handler
= proc_dostring
,
721 .procname
= "modules_disabled",
722 .data
= &modules_disabled
,
723 .maxlen
= sizeof(int),
725 /* only handle a transition from default "0" to "1" */
726 .proc_handler
= proc_dointvec_minmax
,
727 .extra1
= SYSCTL_ONE
,
728 .extra2
= SYSCTL_ONE
,
731 #ifdef CONFIG_UEVENT_HELPER
733 .procname
= "hotplug",
734 .data
= &uevent_helper
,
735 .maxlen
= UEVENT_HELPER_PATH_LEN
,
737 .proc_handler
= proc_dostring
,
740 #ifdef CONFIG_CHR_DEV_SG
742 .procname
= "sg-big-buff",
743 .data
= &sg_big_buff
,
744 .maxlen
= sizeof (int),
746 .proc_handler
= proc_dointvec
,
749 #ifdef CONFIG_BSD_PROCESS_ACCT
753 .maxlen
= 3*sizeof(int),
755 .proc_handler
= proc_dointvec
,
758 #ifdef CONFIG_MAGIC_SYSRQ
761 .data
= &__sysrq_enabled
,
762 .maxlen
= sizeof (int),
764 .proc_handler
= sysrq_sysctl_handler
,
767 #ifdef CONFIG_PROC_SYSCTL
769 .procname
= "cad_pid",
771 .maxlen
= sizeof (int),
773 .proc_handler
= proc_do_cad_pid
,
777 .procname
= "threads-max",
779 .maxlen
= sizeof(int),
781 .proc_handler
= sysctl_max_threads
,
784 .procname
= "random",
786 .child
= random_table
,
789 .procname
= "usermodehelper",
791 .child
= usermodehelper_table
,
793 #ifdef CONFIG_FW_LOADER_USER_HELPER
795 .procname
= "firmware_config",
797 .child
= firmware_config_table
,
801 .procname
= "overflowuid",
802 .data
= &overflowuid
,
803 .maxlen
= sizeof(int),
805 .proc_handler
= proc_dointvec_minmax
,
806 .extra1
= &minolduid
,
807 .extra2
= &maxolduid
,
810 .procname
= "overflowgid",
811 .data
= &overflowgid
,
812 .maxlen
= sizeof(int),
814 .proc_handler
= proc_dointvec_minmax
,
815 .extra1
= &minolduid
,
816 .extra2
= &maxolduid
,
819 #ifdef CONFIG_MATHEMU
821 .procname
= "ieee_emulation_warnings",
822 .data
= &sysctl_ieee_emulation_warnings
,
823 .maxlen
= sizeof(int),
825 .proc_handler
= proc_dointvec
,
829 .procname
= "userprocess_debug",
830 .data
= &show_unhandled_signals
,
831 .maxlen
= sizeof(int),
833 .proc_handler
= proc_dointvec
,
837 .procname
= "pid_max",
839 .maxlen
= sizeof (int),
841 .proc_handler
= proc_dointvec_minmax
,
842 .extra1
= &pid_max_min
,
843 .extra2
= &pid_max_max
,
846 .procname
= "panic_on_oops",
847 .data
= &panic_on_oops
,
848 .maxlen
= sizeof(int),
850 .proc_handler
= proc_dointvec
,
853 .procname
= "panic_print",
854 .data
= &panic_print
,
855 .maxlen
= sizeof(unsigned long),
857 .proc_handler
= proc_doulongvec_minmax
,
859 #if defined CONFIG_PRINTK
861 .procname
= "printk",
862 .data
= &console_loglevel
,
863 .maxlen
= 4*sizeof(int),
865 .proc_handler
= proc_dointvec
,
868 .procname
= "printk_ratelimit",
869 .data
= &printk_ratelimit_state
.interval
,
870 .maxlen
= sizeof(int),
872 .proc_handler
= proc_dointvec_jiffies
,
875 .procname
= "printk_ratelimit_burst",
876 .data
= &printk_ratelimit_state
.burst
,
877 .maxlen
= sizeof(int),
879 .proc_handler
= proc_dointvec
,
882 .procname
= "printk_delay",
883 .data
= &printk_delay_msec
,
884 .maxlen
= sizeof(int),
886 .proc_handler
= proc_dointvec_minmax
,
887 .extra1
= SYSCTL_ZERO
,
888 .extra2
= &ten_thousand
,
891 .procname
= "printk_devkmsg",
892 .data
= devkmsg_log_str
,
893 .maxlen
= DEVKMSG_STR_MAX_SIZE
,
895 .proc_handler
= devkmsg_sysctl_set_loglvl
,
898 .procname
= "dmesg_restrict",
899 .data
= &dmesg_restrict
,
900 .maxlen
= sizeof(int),
902 .proc_handler
= proc_dointvec_minmax_sysadmin
,
903 .extra1
= SYSCTL_ZERO
,
904 .extra2
= SYSCTL_ONE
,
907 .procname
= "kptr_restrict",
908 .data
= &kptr_restrict
,
909 .maxlen
= sizeof(int),
911 .proc_handler
= proc_dointvec_minmax_sysadmin
,
912 .extra1
= SYSCTL_ZERO
,
917 .procname
= "ngroups_max",
918 .data
= &ngroups_max
,
919 .maxlen
= sizeof (int),
921 .proc_handler
= proc_dointvec
,
924 .procname
= "cap_last_cap",
925 .data
= (void *)&cap_last_cap
,
926 .maxlen
= sizeof(int),
928 .proc_handler
= proc_dointvec
,
930 #if defined(CONFIG_LOCKUP_DETECTOR)
932 .procname
= "watchdog",
933 .data
= &watchdog_user_enabled
,
934 .maxlen
= sizeof(int),
936 .proc_handler
= proc_watchdog
,
937 .extra1
= SYSCTL_ZERO
,
938 .extra2
= SYSCTL_ONE
,
941 .procname
= "watchdog_thresh",
942 .data
= &watchdog_thresh
,
943 .maxlen
= sizeof(int),
945 .proc_handler
= proc_watchdog_thresh
,
946 .extra1
= SYSCTL_ZERO
,
950 .procname
= "nmi_watchdog",
951 .data
= &nmi_watchdog_user_enabled
,
952 .maxlen
= sizeof(int),
953 .mode
= NMI_WATCHDOG_SYSCTL_PERM
,
954 .proc_handler
= proc_nmi_watchdog
,
955 .extra1
= SYSCTL_ZERO
,
956 .extra2
= SYSCTL_ONE
,
959 .procname
= "watchdog_cpumask",
960 .data
= &watchdog_cpumask_bits
,
963 .proc_handler
= proc_watchdog_cpumask
,
965 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
967 .procname
= "soft_watchdog",
968 .data
= &soft_watchdog_user_enabled
,
969 .maxlen
= sizeof(int),
971 .proc_handler
= proc_soft_watchdog
,
972 .extra1
= SYSCTL_ZERO
,
973 .extra2
= SYSCTL_ONE
,
976 .procname
= "softlockup_panic",
977 .data
= &softlockup_panic
,
978 .maxlen
= sizeof(int),
980 .proc_handler
= proc_dointvec_minmax
,
981 .extra1
= SYSCTL_ZERO
,
982 .extra2
= SYSCTL_ONE
,
986 .procname
= "softlockup_all_cpu_backtrace",
987 .data
= &sysctl_softlockup_all_cpu_backtrace
,
988 .maxlen
= sizeof(int),
990 .proc_handler
= proc_dointvec_minmax
,
991 .extra1
= SYSCTL_ZERO
,
992 .extra2
= SYSCTL_ONE
,
994 #endif /* CONFIG_SMP */
996 #ifdef CONFIG_HARDLOCKUP_DETECTOR
998 .procname
= "hardlockup_panic",
999 .data
= &hardlockup_panic
,
1000 .maxlen
= sizeof(int),
1002 .proc_handler
= proc_dointvec_minmax
,
1003 .extra1
= SYSCTL_ZERO
,
1004 .extra2
= SYSCTL_ONE
,
1008 .procname
= "hardlockup_all_cpu_backtrace",
1009 .data
= &sysctl_hardlockup_all_cpu_backtrace
,
1010 .maxlen
= sizeof(int),
1012 .proc_handler
= proc_dointvec_minmax
,
1013 .extra1
= SYSCTL_ZERO
,
1014 .extra2
= SYSCTL_ONE
,
1016 #endif /* CONFIG_SMP */
1020 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1022 .procname
= "unknown_nmi_panic",
1023 .data
= &unknown_nmi_panic
,
1024 .maxlen
= sizeof (int),
1026 .proc_handler
= proc_dointvec
,
1029 #if defined(CONFIG_X86)
1031 .procname
= "panic_on_unrecovered_nmi",
1032 .data
= &panic_on_unrecovered_nmi
,
1033 .maxlen
= sizeof(int),
1035 .proc_handler
= proc_dointvec
,
1038 .procname
= "panic_on_io_nmi",
1039 .data
= &panic_on_io_nmi
,
1040 .maxlen
= sizeof(int),
1042 .proc_handler
= proc_dointvec
,
1044 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1046 .procname
= "panic_on_stackoverflow",
1047 .data
= &sysctl_panic_on_stackoverflow
,
1048 .maxlen
= sizeof(int),
1050 .proc_handler
= proc_dointvec
,
1054 .procname
= "bootloader_type",
1055 .data
= &bootloader_type
,
1056 .maxlen
= sizeof (int),
1058 .proc_handler
= proc_dointvec
,
1061 .procname
= "bootloader_version",
1062 .data
= &bootloader_version
,
1063 .maxlen
= sizeof (int),
1065 .proc_handler
= proc_dointvec
,
1068 .procname
= "io_delay_type",
1069 .data
= &io_delay_type
,
1070 .maxlen
= sizeof(int),
1072 .proc_handler
= proc_dointvec
,
1075 #if defined(CONFIG_MMU)
1077 .procname
= "randomize_va_space",
1078 .data
= &randomize_va_space
,
1079 .maxlen
= sizeof(int),
1081 .proc_handler
= proc_dointvec
,
1084 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1086 .procname
= "spin_retry",
1087 .data
= &spin_retry
,
1088 .maxlen
= sizeof (int),
1090 .proc_handler
= proc_dointvec
,
1093 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1095 .procname
= "acpi_video_flags",
1096 .data
= &acpi_realmode_flags
,
1097 .maxlen
= sizeof (unsigned long),
1099 .proc_handler
= proc_doulongvec_minmax
,
1102 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1104 .procname
= "ignore-unaligned-usertrap",
1105 .data
= &no_unaligned_warning
,
1106 .maxlen
= sizeof (int),
1108 .proc_handler
= proc_dointvec
,
1113 .procname
= "unaligned-dump-stack",
1114 .data
= &unaligned_dump_stack
,
1115 .maxlen
= sizeof (int),
1117 .proc_handler
= proc_dointvec
,
1120 #ifdef CONFIG_DETECT_HUNG_TASK
1122 .procname
= "hung_task_panic",
1123 .data
= &sysctl_hung_task_panic
,
1124 .maxlen
= sizeof(int),
1126 .proc_handler
= proc_dointvec_minmax
,
1127 .extra1
= SYSCTL_ZERO
,
1128 .extra2
= SYSCTL_ONE
,
1131 .procname
= "hung_task_check_count",
1132 .data
= &sysctl_hung_task_check_count
,
1133 .maxlen
= sizeof(int),
1135 .proc_handler
= proc_dointvec_minmax
,
1136 .extra1
= SYSCTL_ZERO
,
1139 .procname
= "hung_task_timeout_secs",
1140 .data
= &sysctl_hung_task_timeout_secs
,
1141 .maxlen
= sizeof(unsigned long),
1143 .proc_handler
= proc_dohung_task_timeout_secs
,
1144 .extra2
= &hung_task_timeout_max
,
1147 .procname
= "hung_task_check_interval_secs",
1148 .data
= &sysctl_hung_task_check_interval_secs
,
1149 .maxlen
= sizeof(unsigned long),
1151 .proc_handler
= proc_dohung_task_timeout_secs
,
1152 .extra2
= &hung_task_timeout_max
,
1155 .procname
= "hung_task_warnings",
1156 .data
= &sysctl_hung_task_warnings
,
1157 .maxlen
= sizeof(int),
1159 .proc_handler
= proc_dointvec_minmax
,
1163 #ifdef CONFIG_RT_MUTEXES
1165 .procname
= "max_lock_depth",
1166 .data
= &max_lock_depth
,
1167 .maxlen
= sizeof(int),
1169 .proc_handler
= proc_dointvec
,
1173 .procname
= "poweroff_cmd",
1174 .data
= &poweroff_cmd
,
1175 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1177 .proc_handler
= proc_dostring
,
1183 .child
= key_sysctls
,
1186 #ifdef CONFIG_PERF_EVENTS
1188 * User-space scripts rely on the existence of this file
1189 * as a feature check for perf_events being enabled.
1191 * So it's an ABI, do not remove!
1194 .procname
= "perf_event_paranoid",
1195 .data
= &sysctl_perf_event_paranoid
,
1196 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1198 .proc_handler
= proc_dointvec
,
1201 .procname
= "perf_event_mlock_kb",
1202 .data
= &sysctl_perf_event_mlock
,
1203 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1205 .proc_handler
= proc_dointvec
,
1208 .procname
= "perf_event_max_sample_rate",
1209 .data
= &sysctl_perf_event_sample_rate
,
1210 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1212 .proc_handler
= perf_proc_update_handler
,
1213 .extra1
= SYSCTL_ONE
,
1216 .procname
= "perf_cpu_time_max_percent",
1217 .data
= &sysctl_perf_cpu_time_max_percent
,
1218 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1220 .proc_handler
= perf_cpu_time_max_percent_handler
,
1221 .extra1
= SYSCTL_ZERO
,
1222 .extra2
= &one_hundred
,
1225 .procname
= "perf_event_max_stack",
1226 .data
= &sysctl_perf_event_max_stack
,
1227 .maxlen
= sizeof(sysctl_perf_event_max_stack
),
1229 .proc_handler
= perf_event_max_stack_handler
,
1230 .extra1
= SYSCTL_ZERO
,
1231 .extra2
= &six_hundred_forty_kb
,
1234 .procname
= "perf_event_max_contexts_per_stack",
1235 .data
= &sysctl_perf_event_max_contexts_per_stack
,
1236 .maxlen
= sizeof(sysctl_perf_event_max_contexts_per_stack
),
1238 .proc_handler
= perf_event_max_stack_handler
,
1239 .extra1
= SYSCTL_ZERO
,
1240 .extra2
= &one_thousand
,
1244 .procname
= "panic_on_warn",
1245 .data
= &panic_on_warn
,
1246 .maxlen
= sizeof(int),
1248 .proc_handler
= proc_dointvec_minmax
,
1249 .extra1
= SYSCTL_ZERO
,
1250 .extra2
= SYSCTL_ONE
,
1252 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1254 .procname
= "timer_migration",
1255 .data
= &sysctl_timer_migration
,
1256 .maxlen
= sizeof(unsigned int),
1258 .proc_handler
= timer_migration_handler
,
1259 .extra1
= SYSCTL_ZERO
,
1260 .extra2
= SYSCTL_ONE
,
1263 #ifdef CONFIG_BPF_SYSCALL
1265 .procname
= "unprivileged_bpf_disabled",
1266 .data
= &sysctl_unprivileged_bpf_disabled
,
1267 .maxlen
= sizeof(sysctl_unprivileged_bpf_disabled
),
1269 /* only handle a transition from default "0" to "1" */
1270 .proc_handler
= proc_dointvec_minmax
,
1271 .extra1
= SYSCTL_ONE
,
1272 .extra2
= SYSCTL_ONE
,
1275 .procname
= "bpf_stats_enabled",
1276 .data
= &bpf_stats_enabled_key
.key
,
1277 .maxlen
= sizeof(bpf_stats_enabled_key
),
1279 .proc_handler
= proc_do_static_key
,
1282 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1284 .procname
= "panic_on_rcu_stall",
1285 .data
= &sysctl_panic_on_rcu_stall
,
1286 .maxlen
= sizeof(sysctl_panic_on_rcu_stall
),
1288 .proc_handler
= proc_dointvec_minmax
,
1289 .extra1
= SYSCTL_ZERO
,
1290 .extra2
= SYSCTL_ONE
,
1293 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1295 .procname
= "stack_erasing",
1297 .maxlen
= sizeof(int),
1299 .proc_handler
= stack_erasing_sysctl
,
1300 .extra1
= SYSCTL_ZERO
,
1301 .extra2
= SYSCTL_ONE
,
1307 static struct ctl_table vm_table
[] = {
1309 .procname
= "overcommit_memory",
1310 .data
= &sysctl_overcommit_memory
,
1311 .maxlen
= sizeof(sysctl_overcommit_memory
),
1313 .proc_handler
= proc_dointvec_minmax
,
1314 .extra1
= SYSCTL_ZERO
,
1318 .procname
= "panic_on_oom",
1319 .data
= &sysctl_panic_on_oom
,
1320 .maxlen
= sizeof(sysctl_panic_on_oom
),
1322 .proc_handler
= proc_dointvec_minmax
,
1323 .extra1
= SYSCTL_ZERO
,
1327 .procname
= "oom_kill_allocating_task",
1328 .data
= &sysctl_oom_kill_allocating_task
,
1329 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1331 .proc_handler
= proc_dointvec
,
1334 .procname
= "oom_dump_tasks",
1335 .data
= &sysctl_oom_dump_tasks
,
1336 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1338 .proc_handler
= proc_dointvec
,
1341 .procname
= "overcommit_ratio",
1342 .data
= &sysctl_overcommit_ratio
,
1343 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1345 .proc_handler
= overcommit_ratio_handler
,
1348 .procname
= "overcommit_kbytes",
1349 .data
= &sysctl_overcommit_kbytes
,
1350 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1352 .proc_handler
= overcommit_kbytes_handler
,
1355 .procname
= "page-cluster",
1356 .data
= &page_cluster
,
1357 .maxlen
= sizeof(int),
1359 .proc_handler
= proc_dointvec_minmax
,
1360 .extra1
= SYSCTL_ZERO
,
1363 .procname
= "dirty_background_ratio",
1364 .data
= &dirty_background_ratio
,
1365 .maxlen
= sizeof(dirty_background_ratio
),
1367 .proc_handler
= dirty_background_ratio_handler
,
1368 .extra1
= SYSCTL_ZERO
,
1369 .extra2
= &one_hundred
,
1372 .procname
= "dirty_background_bytes",
1373 .data
= &dirty_background_bytes
,
1374 .maxlen
= sizeof(dirty_background_bytes
),
1376 .proc_handler
= dirty_background_bytes_handler
,
1380 .procname
= "dirty_ratio",
1381 .data
= &vm_dirty_ratio
,
1382 .maxlen
= sizeof(vm_dirty_ratio
),
1384 .proc_handler
= dirty_ratio_handler
,
1385 .extra1
= SYSCTL_ZERO
,
1386 .extra2
= &one_hundred
,
1389 .procname
= "dirty_bytes",
1390 .data
= &vm_dirty_bytes
,
1391 .maxlen
= sizeof(vm_dirty_bytes
),
1393 .proc_handler
= dirty_bytes_handler
,
1394 .extra1
= &dirty_bytes_min
,
1397 .procname
= "dirty_writeback_centisecs",
1398 .data
= &dirty_writeback_interval
,
1399 .maxlen
= sizeof(dirty_writeback_interval
),
1401 .proc_handler
= dirty_writeback_centisecs_handler
,
1404 .procname
= "dirty_expire_centisecs",
1405 .data
= &dirty_expire_interval
,
1406 .maxlen
= sizeof(dirty_expire_interval
),
1408 .proc_handler
= proc_dointvec_minmax
,
1409 .extra1
= SYSCTL_ZERO
,
1412 .procname
= "dirtytime_expire_seconds",
1413 .data
= &dirtytime_expire_interval
,
1414 .maxlen
= sizeof(dirtytime_expire_interval
),
1416 .proc_handler
= dirtytime_interval_handler
,
1417 .extra1
= SYSCTL_ZERO
,
1420 .procname
= "swappiness",
1421 .data
= &vm_swappiness
,
1422 .maxlen
= sizeof(vm_swappiness
),
1424 .proc_handler
= proc_dointvec_minmax
,
1425 .extra1
= SYSCTL_ZERO
,
1426 .extra2
= &one_hundred
,
1428 #ifdef CONFIG_HUGETLB_PAGE
1430 .procname
= "nr_hugepages",
1432 .maxlen
= sizeof(unsigned long),
1434 .proc_handler
= hugetlb_sysctl_handler
,
1438 .procname
= "nr_hugepages_mempolicy",
1440 .maxlen
= sizeof(unsigned long),
1442 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1445 .procname
= "numa_stat",
1446 .data
= &sysctl_vm_numa_stat
,
1447 .maxlen
= sizeof(int),
1449 .proc_handler
= sysctl_vm_numa_stat_handler
,
1450 .extra1
= SYSCTL_ZERO
,
1451 .extra2
= SYSCTL_ONE
,
1455 .procname
= "hugetlb_shm_group",
1456 .data
= &sysctl_hugetlb_shm_group
,
1457 .maxlen
= sizeof(gid_t
),
1459 .proc_handler
= proc_dointvec
,
1462 .procname
= "nr_overcommit_hugepages",
1464 .maxlen
= sizeof(unsigned long),
1466 .proc_handler
= hugetlb_overcommit_handler
,
1470 .procname
= "lowmem_reserve_ratio",
1471 .data
= &sysctl_lowmem_reserve_ratio
,
1472 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1474 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1477 .procname
= "drop_caches",
1478 .data
= &sysctl_drop_caches
,
1479 .maxlen
= sizeof(int),
1481 .proc_handler
= drop_caches_sysctl_handler
,
1482 .extra1
= SYSCTL_ONE
,
1485 #ifdef CONFIG_COMPACTION
1487 .procname
= "compact_memory",
1488 .data
= &sysctl_compact_memory
,
1489 .maxlen
= sizeof(int),
1491 .proc_handler
= sysctl_compaction_handler
,
1494 .procname
= "extfrag_threshold",
1495 .data
= &sysctl_extfrag_threshold
,
1496 .maxlen
= sizeof(int),
1498 .proc_handler
= proc_dointvec_minmax
,
1499 .extra1
= &min_extfrag_threshold
,
1500 .extra2
= &max_extfrag_threshold
,
1503 .procname
= "compact_unevictable_allowed",
1504 .data
= &sysctl_compact_unevictable_allowed
,
1505 .maxlen
= sizeof(int),
1507 .proc_handler
= proc_dointvec
,
1508 .extra1
= SYSCTL_ZERO
,
1509 .extra2
= SYSCTL_ONE
,
1512 #endif /* CONFIG_COMPACTION */
1514 .procname
= "min_free_kbytes",
1515 .data
= &min_free_kbytes
,
1516 .maxlen
= sizeof(min_free_kbytes
),
1518 .proc_handler
= min_free_kbytes_sysctl_handler
,
1519 .extra1
= SYSCTL_ZERO
,
1522 .procname
= "watermark_boost_factor",
1523 .data
= &watermark_boost_factor
,
1524 .maxlen
= sizeof(watermark_boost_factor
),
1526 .proc_handler
= watermark_boost_factor_sysctl_handler
,
1527 .extra1
= SYSCTL_ZERO
,
1530 .procname
= "watermark_scale_factor",
1531 .data
= &watermark_scale_factor
,
1532 .maxlen
= sizeof(watermark_scale_factor
),
1534 .proc_handler
= watermark_scale_factor_sysctl_handler
,
1535 .extra1
= SYSCTL_ONE
,
1536 .extra2
= &one_thousand
,
1539 .procname
= "percpu_pagelist_fraction",
1540 .data
= &percpu_pagelist_fraction
,
1541 .maxlen
= sizeof(percpu_pagelist_fraction
),
1543 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1544 .extra1
= SYSCTL_ZERO
,
1548 .procname
= "max_map_count",
1549 .data
= &sysctl_max_map_count
,
1550 .maxlen
= sizeof(sysctl_max_map_count
),
1552 .proc_handler
= proc_dointvec_minmax
,
1553 .extra1
= SYSCTL_ZERO
,
1557 .procname
= "nr_trim_pages",
1558 .data
= &sysctl_nr_trim_pages
,
1559 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1561 .proc_handler
= proc_dointvec_minmax
,
1562 .extra1
= SYSCTL_ZERO
,
1566 .procname
= "laptop_mode",
1567 .data
= &laptop_mode
,
1568 .maxlen
= sizeof(laptop_mode
),
1570 .proc_handler
= proc_dointvec_jiffies
,
1573 .procname
= "block_dump",
1574 .data
= &block_dump
,
1575 .maxlen
= sizeof(block_dump
),
1577 .proc_handler
= proc_dointvec
,
1578 .extra1
= SYSCTL_ZERO
,
1581 .procname
= "vfs_cache_pressure",
1582 .data
= &sysctl_vfs_cache_pressure
,
1583 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1585 .proc_handler
= proc_dointvec
,
1586 .extra1
= SYSCTL_ZERO
,
1588 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1590 .procname
= "legacy_va_layout",
1591 .data
= &sysctl_legacy_va_layout
,
1592 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1594 .proc_handler
= proc_dointvec
,
1595 .extra1
= SYSCTL_ZERO
,
1600 .procname
= "zone_reclaim_mode",
1601 .data
= &node_reclaim_mode
,
1602 .maxlen
= sizeof(node_reclaim_mode
),
1604 .proc_handler
= proc_dointvec
,
1605 .extra1
= SYSCTL_ZERO
,
1608 .procname
= "min_unmapped_ratio",
1609 .data
= &sysctl_min_unmapped_ratio
,
1610 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1612 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1613 .extra1
= SYSCTL_ZERO
,
1614 .extra2
= &one_hundred
,
1617 .procname
= "min_slab_ratio",
1618 .data
= &sysctl_min_slab_ratio
,
1619 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1621 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1622 .extra1
= SYSCTL_ZERO
,
1623 .extra2
= &one_hundred
,
1628 .procname
= "stat_interval",
1629 .data
= &sysctl_stat_interval
,
1630 .maxlen
= sizeof(sysctl_stat_interval
),
1632 .proc_handler
= proc_dointvec_jiffies
,
1635 .procname
= "stat_refresh",
1639 .proc_handler
= vmstat_refresh
,
1644 .procname
= "mmap_min_addr",
1645 .data
= &dac_mmap_min_addr
,
1646 .maxlen
= sizeof(unsigned long),
1648 .proc_handler
= mmap_min_addr_handler
,
1653 .procname
= "numa_zonelist_order",
1654 .data
= &numa_zonelist_order
,
1655 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1657 .proc_handler
= numa_zonelist_order_handler
,
1660 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1661 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1663 .procname
= "vdso_enabled",
1664 #ifdef CONFIG_X86_32
1665 .data
= &vdso32_enabled
,
1666 .maxlen
= sizeof(vdso32_enabled
),
1668 .data
= &vdso_enabled
,
1669 .maxlen
= sizeof(vdso_enabled
),
1672 .proc_handler
= proc_dointvec
,
1673 .extra1
= SYSCTL_ZERO
,
1676 #ifdef CONFIG_HIGHMEM
1678 .procname
= "highmem_is_dirtyable",
1679 .data
= &vm_highmem_is_dirtyable
,
1680 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1682 .proc_handler
= proc_dointvec_minmax
,
1683 .extra1
= SYSCTL_ZERO
,
1684 .extra2
= SYSCTL_ONE
,
1687 #ifdef CONFIG_MEMORY_FAILURE
1689 .procname
= "memory_failure_early_kill",
1690 .data
= &sysctl_memory_failure_early_kill
,
1691 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1693 .proc_handler
= proc_dointvec_minmax
,
1694 .extra1
= SYSCTL_ZERO
,
1695 .extra2
= SYSCTL_ONE
,
1698 .procname
= "memory_failure_recovery",
1699 .data
= &sysctl_memory_failure_recovery
,
1700 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1702 .proc_handler
= proc_dointvec_minmax
,
1703 .extra1
= SYSCTL_ZERO
,
1704 .extra2
= SYSCTL_ONE
,
1708 .procname
= "user_reserve_kbytes",
1709 .data
= &sysctl_user_reserve_kbytes
,
1710 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1712 .proc_handler
= proc_doulongvec_minmax
,
1715 .procname
= "admin_reserve_kbytes",
1716 .data
= &sysctl_admin_reserve_kbytes
,
1717 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1719 .proc_handler
= proc_doulongvec_minmax
,
1721 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1723 .procname
= "mmap_rnd_bits",
1724 .data
= &mmap_rnd_bits
,
1725 .maxlen
= sizeof(mmap_rnd_bits
),
1727 .proc_handler
= proc_dointvec_minmax
,
1728 .extra1
= (void *)&mmap_rnd_bits_min
,
1729 .extra2
= (void *)&mmap_rnd_bits_max
,
1732 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1734 .procname
= "mmap_rnd_compat_bits",
1735 .data
= &mmap_rnd_compat_bits
,
1736 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1738 .proc_handler
= proc_dointvec_minmax
,
1739 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1740 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1743 #ifdef CONFIG_USERFAULTFD
1745 .procname
= "unprivileged_userfaultfd",
1746 .data
= &sysctl_unprivileged_userfaultfd
,
1747 .maxlen
= sizeof(sysctl_unprivileged_userfaultfd
),
1749 .proc_handler
= proc_dointvec_minmax
,
1750 .extra1
= SYSCTL_ZERO
,
1751 .extra2
= SYSCTL_ONE
,
1757 static struct ctl_table fs_table
[] = {
1759 .procname
= "inode-nr",
1760 .data
= &inodes_stat
,
1761 .maxlen
= 2*sizeof(long),
1763 .proc_handler
= proc_nr_inodes
,
1766 .procname
= "inode-state",
1767 .data
= &inodes_stat
,
1768 .maxlen
= 7*sizeof(long),
1770 .proc_handler
= proc_nr_inodes
,
1773 .procname
= "file-nr",
1774 .data
= &files_stat
,
1775 .maxlen
= sizeof(files_stat
),
1777 .proc_handler
= proc_nr_files
,
1780 .procname
= "file-max",
1781 .data
= &files_stat
.max_files
,
1782 .maxlen
= sizeof(files_stat
.max_files
),
1784 .proc_handler
= proc_doulongvec_minmax
,
1786 .extra2
= &long_max
,
1789 .procname
= "nr_open",
1790 .data
= &sysctl_nr_open
,
1791 .maxlen
= sizeof(unsigned int),
1793 .proc_handler
= proc_dointvec_minmax
,
1794 .extra1
= &sysctl_nr_open_min
,
1795 .extra2
= &sysctl_nr_open_max
,
1798 .procname
= "dentry-state",
1799 .data
= &dentry_stat
,
1800 .maxlen
= 6*sizeof(long),
1802 .proc_handler
= proc_nr_dentry
,
1805 .procname
= "overflowuid",
1806 .data
= &fs_overflowuid
,
1807 .maxlen
= sizeof(int),
1809 .proc_handler
= proc_dointvec_minmax
,
1810 .extra1
= &minolduid
,
1811 .extra2
= &maxolduid
,
1814 .procname
= "overflowgid",
1815 .data
= &fs_overflowgid
,
1816 .maxlen
= sizeof(int),
1818 .proc_handler
= proc_dointvec_minmax
,
1819 .extra1
= &minolduid
,
1820 .extra2
= &maxolduid
,
1822 #ifdef CONFIG_FILE_LOCKING
1824 .procname
= "leases-enable",
1825 .data
= &leases_enable
,
1826 .maxlen
= sizeof(int),
1828 .proc_handler
= proc_dointvec
,
1831 #ifdef CONFIG_DNOTIFY
1833 .procname
= "dir-notify-enable",
1834 .data
= &dir_notify_enable
,
1835 .maxlen
= sizeof(int),
1837 .proc_handler
= proc_dointvec
,
1841 #ifdef CONFIG_FILE_LOCKING
1843 .procname
= "lease-break-time",
1844 .data
= &lease_break_time
,
1845 .maxlen
= sizeof(int),
1847 .proc_handler
= proc_dointvec
,
1852 .procname
= "aio-nr",
1854 .maxlen
= sizeof(aio_nr
),
1856 .proc_handler
= proc_doulongvec_minmax
,
1859 .procname
= "aio-max-nr",
1860 .data
= &aio_max_nr
,
1861 .maxlen
= sizeof(aio_max_nr
),
1863 .proc_handler
= proc_doulongvec_minmax
,
1865 #endif /* CONFIG_AIO */
1866 #ifdef CONFIG_INOTIFY_USER
1868 .procname
= "inotify",
1870 .child
= inotify_table
,
1875 .procname
= "epoll",
1877 .child
= epoll_table
,
1882 .procname
= "protected_symlinks",
1883 .data
= &sysctl_protected_symlinks
,
1884 .maxlen
= sizeof(int),
1886 .proc_handler
= proc_dointvec_minmax
,
1887 .extra1
= SYSCTL_ZERO
,
1888 .extra2
= SYSCTL_ONE
,
1891 .procname
= "protected_hardlinks",
1892 .data
= &sysctl_protected_hardlinks
,
1893 .maxlen
= sizeof(int),
1895 .proc_handler
= proc_dointvec_minmax
,
1896 .extra1
= SYSCTL_ZERO
,
1897 .extra2
= SYSCTL_ONE
,
1900 .procname
= "protected_fifos",
1901 .data
= &sysctl_protected_fifos
,
1902 .maxlen
= sizeof(int),
1904 .proc_handler
= proc_dointvec_minmax
,
1905 .extra1
= SYSCTL_ZERO
,
1909 .procname
= "protected_regular",
1910 .data
= &sysctl_protected_regular
,
1911 .maxlen
= sizeof(int),
1913 .proc_handler
= proc_dointvec_minmax
,
1914 .extra1
= SYSCTL_ZERO
,
1918 .procname
= "suid_dumpable",
1919 .data
= &suid_dumpable
,
1920 .maxlen
= sizeof(int),
1922 .proc_handler
= proc_dointvec_minmax_coredump
,
1923 .extra1
= SYSCTL_ZERO
,
1926 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1928 .procname
= "binfmt_misc",
1930 .child
= sysctl_mount_point
,
1934 .procname
= "pipe-max-size",
1935 .data
= &pipe_max_size
,
1936 .maxlen
= sizeof(pipe_max_size
),
1938 .proc_handler
= proc_dopipe_max_size
,
1941 .procname
= "pipe-user-pages-hard",
1942 .data
= &pipe_user_pages_hard
,
1943 .maxlen
= sizeof(pipe_user_pages_hard
),
1945 .proc_handler
= proc_doulongvec_minmax
,
1948 .procname
= "pipe-user-pages-soft",
1949 .data
= &pipe_user_pages_soft
,
1950 .maxlen
= sizeof(pipe_user_pages_soft
),
1952 .proc_handler
= proc_doulongvec_minmax
,
1955 .procname
= "mount-max",
1956 .data
= &sysctl_mount_max
,
1957 .maxlen
= sizeof(unsigned int),
1959 .proc_handler
= proc_dointvec_minmax
,
1960 .extra1
= SYSCTL_ONE
,
1965 static struct ctl_table debug_table
[] = {
1966 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1968 .procname
= "exception-trace",
1969 .data
= &show_unhandled_signals
,
1970 .maxlen
= sizeof(int),
1972 .proc_handler
= proc_dointvec
1975 #if defined(CONFIG_OPTPROBES)
1977 .procname
= "kprobes-optimization",
1978 .data
= &sysctl_kprobes_optimization
,
1979 .maxlen
= sizeof(int),
1981 .proc_handler
= proc_kprobes_optimization_handler
,
1982 .extra1
= SYSCTL_ZERO
,
1983 .extra2
= SYSCTL_ONE
,
1989 static struct ctl_table dev_table
[] = {
1993 int __init
sysctl_init(void)
1995 struct ctl_table_header
*hdr
;
1997 hdr
= register_sysctl_table(sysctl_base_table
);
1998 kmemleak_not_leak(hdr
);
2002 #endif /* CONFIG_SYSCTL */
2008 #ifdef CONFIG_PROC_SYSCTL
2010 static int _proc_do_string(char *data
, int maxlen
, int write
,
2011 char __user
*buffer
,
2012 size_t *lenp
, loff_t
*ppos
)
2018 if (!data
|| !maxlen
|| !*lenp
) {
2024 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
2025 /* Only continue writes not past the end of buffer. */
2027 if (len
> maxlen
- 1)
2034 /* Start writing from beginning of buffer. */
2040 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
2041 if (get_user(c
, p
++))
2043 if (c
== 0 || c
== '\n')
2064 if (copy_to_user(buffer
, data
, len
))
2067 if (put_user('\n', buffer
+ len
))
2077 static void warn_sysctl_write(struct ctl_table
*table
)
2079 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2080 "This will not be supported in the future. To silence this\n"
2081 "warning, set kernel.sysctl_writes_strict = -1\n",
2082 current
->comm
, table
->procname
);
2086 * proc_first_pos_non_zero_ignore - check if first position is allowed
2087 * @ppos: file position
2088 * @table: the sysctl table
2090 * Returns true if the first position is non-zero and the sysctl_writes_strict
2091 * mode indicates this is not allowed for numeric input types. String proc
2092 * handlers can ignore the return value.
2094 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
2095 struct ctl_table
*table
)
2100 switch (sysctl_writes_strict
) {
2101 case SYSCTL_WRITES_STRICT
:
2103 case SYSCTL_WRITES_WARN
:
2104 warn_sysctl_write(table
);
2112 * proc_dostring - read a string sysctl
2113 * @table: the sysctl table
2114 * @write: %TRUE if this is a write to the sysctl file
2115 * @buffer: the user buffer
2116 * @lenp: the size of the user buffer
2117 * @ppos: file position
2119 * Reads/writes a string from/to the user buffer. If the kernel
2120 * buffer provided is not large enough to hold the string, the
2121 * string is truncated. The copied string is %NULL-terminated.
2122 * If the string is being read by the user process, it is copied
2123 * and a newline '\n' is added. It is truncated if the buffer is
2126 * Returns 0 on success.
2128 int proc_dostring(struct ctl_table
*table
, int write
,
2129 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2132 proc_first_pos_non_zero_ignore(ppos
, table
);
2134 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2135 (char __user
*)buffer
, lenp
, ppos
);
2138 static size_t proc_skip_spaces(char **buf
)
2141 char *tmp
= skip_spaces(*buf
);
2147 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2158 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2161 * @cp: kernel buffer containing the string to parse
2162 * @endp: pointer to store the trailing characters
2163 * @base: the base to use
2164 * @res: where the parsed integer will be stored
2166 * In case of success 0 is returned and @res will contain the parsed integer,
2167 * @endp will hold any trailing characters.
2168 * This function will fail the parse on overflow. If there wasn't an overflow
2169 * the function will defer the decision what characters count as invalid to the
2172 static int strtoul_lenient(const char *cp
, char **endp
, unsigned int base
,
2175 unsigned long long result
;
2178 cp
= _parse_integer_fixup_radix(cp
, &base
);
2179 rv
= _parse_integer(cp
, base
, &result
);
2180 if ((rv
& KSTRTOX_OVERFLOW
) || (result
!= (unsigned long)result
))
2188 *res
= (unsigned long)result
;
2192 #define TMPBUFLEN 22
2194 * proc_get_long - reads an ASCII formatted integer from a user buffer
2196 * @buf: a kernel buffer
2197 * @size: size of the kernel buffer
2198 * @val: this is where the number will be stored
2199 * @neg: set to %TRUE if number is negative
2200 * @perm_tr: a vector which contains the allowed trailers
2201 * @perm_tr_len: size of the perm_tr vector
2202 * @tr: pointer to store the trailer character
2204 * In case of success %0 is returned and @buf and @size are updated with
2205 * the amount of bytes read. If @tr is non-NULL and a trailing
2206 * character exists (size is non-zero after returning from this
2207 * function), @tr is updated with the trailing character.
2209 static int proc_get_long(char **buf
, size_t *size
,
2210 unsigned long *val
, bool *neg
,
2211 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2214 char *p
, tmp
[TMPBUFLEN
];
2220 if (len
> TMPBUFLEN
- 1)
2221 len
= TMPBUFLEN
- 1;
2223 memcpy(tmp
, *buf
, len
);
2227 if (*p
== '-' && *size
> 1) {
2235 if (strtoul_lenient(p
, &p
, 0, val
))
2240 /* We don't know if the next char is whitespace thus we may accept
2241 * invalid integers (e.g. 1234...a) or two integers instead of one
2242 * (e.g. 123...1). So lets not allow such large numbers. */
2243 if (len
== TMPBUFLEN
- 1)
2246 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2249 if (tr
&& (len
< *size
))
2259 * proc_put_long - converts an integer to a decimal ASCII formatted string
2261 * @buf: the user buffer
2262 * @size: the size of the user buffer
2263 * @val: the integer to be converted
2264 * @neg: sign of the number, %TRUE for negative
2266 * In case of success %0 is returned and @buf and @size are updated with
2267 * the amount of bytes written.
2269 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2273 char tmp
[TMPBUFLEN
], *p
= tmp
;
2275 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2279 if (copy_to_user(*buf
, tmp
, len
))
2287 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2290 char __user
**buffer
= (char __user
**)buf
;
2291 if (put_user(c
, *buffer
))
2293 (*size
)--, (*buffer
)++;
2299 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2301 int write
, void *data
)
2305 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2309 if (*lvalp
> (unsigned long) INT_MAX
)
2317 *lvalp
= -(unsigned long)val
;
2320 *lvalp
= (unsigned long)val
;
2326 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2328 int write
, void *data
)
2331 if (*lvalp
> UINT_MAX
)
2335 unsigned int val
= *valp
;
2336 *lvalp
= (unsigned long)val
;
2341 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2343 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2344 int write
, void __user
*buffer
,
2345 size_t *lenp
, loff_t
*ppos
,
2346 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2347 int write
, void *data
),
2350 int *i
, vleft
, first
= 1, err
= 0;
2352 char *kbuf
= NULL
, *p
;
2354 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2359 i
= (int *) tbl_data
;
2360 vleft
= table
->maxlen
/ sizeof(*i
);
2364 conv
= do_proc_dointvec_conv
;
2367 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2370 if (left
> PAGE_SIZE
- 1)
2371 left
= PAGE_SIZE
- 1;
2372 p
= kbuf
= memdup_user_nul(buffer
, left
);
2374 return PTR_ERR(kbuf
);
2377 for (; left
&& vleft
--; i
++, first
=0) {
2382 left
-= proc_skip_spaces(&p
);
2386 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2388 sizeof(proc_wspace_sep
), NULL
);
2391 if (conv(&neg
, &lval
, i
, 1, data
)) {
2396 if (conv(&neg
, &lval
, i
, 0, data
)) {
2401 err
= proc_put_char(&buffer
, &left
, '\t');
2404 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2410 if (!write
&& !first
&& left
&& !err
)
2411 err
= proc_put_char(&buffer
, &left
, '\n');
2412 if (write
&& !err
&& left
)
2413 left
-= proc_skip_spaces(&p
);
2417 return err
? : -EINVAL
;
2425 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2426 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2427 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2428 int write
, void *data
),
2431 return __do_proc_dointvec(table
->data
, table
, write
,
2432 buffer
, lenp
, ppos
, conv
, data
);
2435 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2436 struct ctl_table
*table
,
2437 void __user
*buffer
,
2438 size_t *lenp
, loff_t
*ppos
,
2439 int (*conv
)(unsigned long *lvalp
,
2441 int write
, void *data
),
2448 char *kbuf
= NULL
, *p
;
2452 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2455 if (left
> PAGE_SIZE
- 1)
2456 left
= PAGE_SIZE
- 1;
2458 p
= kbuf
= memdup_user_nul(buffer
, left
);
2462 left
-= proc_skip_spaces(&p
);
2468 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2470 sizeof(proc_wspace_sep
), NULL
);
2476 if (conv(&lval
, tbl_data
, 1, data
)) {
2482 left
-= proc_skip_spaces(&p
);
2491 /* This is in keeping with old __do_proc_dointvec() */
2497 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2498 size_t *lenp
, loff_t
*ppos
,
2499 int (*conv
)(unsigned long *lvalp
,
2501 int write
, void *data
),
2510 if (conv(&lval
, tbl_data
, 0, data
)) {
2515 err
= proc_put_long(&buffer
, &left
, lval
, false);
2519 err
= proc_put_char(&buffer
, &left
, '\n');
2528 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2529 int write
, void __user
*buffer
,
2530 size_t *lenp
, loff_t
*ppos
,
2531 int (*conv
)(unsigned long *lvalp
,
2533 int write
, void *data
),
2536 unsigned int *i
, vleft
;
2538 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2543 i
= (unsigned int *) tbl_data
;
2544 vleft
= table
->maxlen
/ sizeof(*i
);
2547 * Arrays are not supported, keep this simple. *Do not* add
2556 conv
= do_proc_douintvec_conv
;
2559 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2561 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2564 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2565 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2566 int (*conv
)(unsigned long *lvalp
,
2568 int write
, void *data
),
2571 return __do_proc_douintvec(table
->data
, table
, write
,
2572 buffer
, lenp
, ppos
, conv
, data
);
2576 * proc_dointvec - read a vector of integers
2577 * @table: the sysctl table
2578 * @write: %TRUE if this is a write to the sysctl file
2579 * @buffer: the user buffer
2580 * @lenp: the size of the user buffer
2581 * @ppos: file position
2583 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2584 * values from/to the user buffer, treated as an ASCII string.
2586 * Returns 0 on success.
2588 int proc_dointvec(struct ctl_table
*table
, int write
,
2589 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2591 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2595 * proc_douintvec - read a vector of unsigned integers
2596 * @table: the sysctl table
2597 * @write: %TRUE if this is a write to the sysctl file
2598 * @buffer: the user buffer
2599 * @lenp: the size of the user buffer
2600 * @ppos: file position
2602 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2603 * values from/to the user buffer, treated as an ASCII string.
2605 * Returns 0 on success.
2607 int proc_douintvec(struct ctl_table
*table
, int write
,
2608 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2610 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2611 do_proc_douintvec_conv
, NULL
);
2615 * Taint values can only be increased
2616 * This means we can safely use a temporary.
2618 static int proc_taint(struct ctl_table
*table
, int write
,
2619 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2622 unsigned long tmptaint
= get_taint();
2625 if (write
&& !capable(CAP_SYS_ADMIN
))
2630 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2636 * Poor man's atomic or. Not worth adding a primitive
2637 * to everyone's atomic.h for this
2640 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2641 if ((tmptaint
>> i
) & 1)
2642 add_taint(i
, LOCKDEP_STILL_OK
);
2649 #ifdef CONFIG_PRINTK
2650 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2651 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2653 if (write
&& !capable(CAP_SYS_ADMIN
))
2656 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2661 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2662 * @min: pointer to minimum allowable value
2663 * @max: pointer to maximum allowable value
2665 * The do_proc_dointvec_minmax_conv_param structure provides the
2666 * minimum and maximum values for doing range checking for those sysctl
2667 * parameters that use the proc_dointvec_minmax() handler.
2669 struct do_proc_dointvec_minmax_conv_param
{
2674 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2676 int write
, void *data
)
2679 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2681 * If writing, first do so via a temporary local int so we can
2682 * bounds-check it before touching *valp.
2684 int *ip
= write
? &tmp
: valp
;
2686 ret
= do_proc_dointvec_conv(negp
, lvalp
, ip
, write
, data
);
2691 if ((param
->min
&& *param
->min
> tmp
) ||
2692 (param
->max
&& *param
->max
< tmp
))
2701 * proc_dointvec_minmax - read a vector of integers with min/max values
2702 * @table: the sysctl table
2703 * @write: %TRUE if this is a write to the sysctl file
2704 * @buffer: the user buffer
2705 * @lenp: the size of the user buffer
2706 * @ppos: file position
2708 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2709 * values from/to the user buffer, treated as an ASCII string.
2711 * This routine will ensure the values are within the range specified by
2712 * table->extra1 (min) and table->extra2 (max).
2714 * Returns 0 on success or -EINVAL on write when the range check fails.
2716 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2717 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2719 struct do_proc_dointvec_minmax_conv_param param
= {
2720 .min
= (int *) table
->extra1
,
2721 .max
= (int *) table
->extra2
,
2723 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2724 do_proc_dointvec_minmax_conv
, ¶m
);
2728 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2729 * @min: pointer to minimum allowable value
2730 * @max: pointer to maximum allowable value
2732 * The do_proc_douintvec_minmax_conv_param structure provides the
2733 * minimum and maximum values for doing range checking for those sysctl
2734 * parameters that use the proc_douintvec_minmax() handler.
2736 struct do_proc_douintvec_minmax_conv_param
{
2741 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp
,
2743 int write
, void *data
)
2747 struct do_proc_douintvec_minmax_conv_param
*param
= data
;
2748 /* write via temporary local uint for bounds-checking */
2749 unsigned int *up
= write
? &tmp
: valp
;
2751 ret
= do_proc_douintvec_conv(lvalp
, up
, write
, data
);
2756 if ((param
->min
&& *param
->min
> tmp
) ||
2757 (param
->max
&& *param
->max
< tmp
))
2767 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2768 * @table: the sysctl table
2769 * @write: %TRUE if this is a write to the sysctl file
2770 * @buffer: the user buffer
2771 * @lenp: the size of the user buffer
2772 * @ppos: file position
2774 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2775 * values from/to the user buffer, treated as an ASCII string. Negative
2776 * strings are not allowed.
2778 * This routine will ensure the values are within the range specified by
2779 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2780 * check for UINT_MAX to avoid having to support wrap around uses from
2783 * Returns 0 on success or -ERANGE on write when the range check fails.
2785 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
2786 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2788 struct do_proc_douintvec_minmax_conv_param param
= {
2789 .min
= (unsigned int *) table
->extra1
,
2790 .max
= (unsigned int *) table
->extra2
,
2792 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2793 do_proc_douintvec_minmax_conv
, ¶m
);
2796 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp
,
2798 int write
, void *data
)
2803 val
= round_pipe_size(*lvalp
);
2809 unsigned int val
= *valp
;
2810 *lvalp
= (unsigned long) val
;
2816 static int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
2817 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2819 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2820 do_proc_dopipe_max_size_conv
, NULL
);
2823 static void validate_coredump_safety(void)
2825 #ifdef CONFIG_COREDUMP
2826 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2827 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2829 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2830 "Pipe handler or fully qualified core dump path required.\n"
2831 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2837 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2838 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2840 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2842 validate_coredump_safety();
2846 #ifdef CONFIG_COREDUMP
2847 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2848 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2850 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2852 validate_coredump_safety();
2857 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2858 void __user
*buffer
,
2859 size_t *lenp
, loff_t
*ppos
,
2860 unsigned long convmul
,
2861 unsigned long convdiv
)
2863 unsigned long *i
, *min
, *max
;
2864 int vleft
, first
= 1, err
= 0;
2866 char *kbuf
= NULL
, *p
;
2868 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2873 i
= (unsigned long *) data
;
2874 min
= (unsigned long *) table
->extra1
;
2875 max
= (unsigned long *) table
->extra2
;
2876 vleft
= table
->maxlen
/ sizeof(unsigned long);
2880 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2883 if (left
> PAGE_SIZE
- 1)
2884 left
= PAGE_SIZE
- 1;
2885 p
= kbuf
= memdup_user_nul(buffer
, left
);
2887 return PTR_ERR(kbuf
);
2890 for (; left
&& vleft
--; i
++, first
= 0) {
2896 left
-= proc_skip_spaces(&p
);
2900 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2902 sizeof(proc_wspace_sep
), NULL
);
2907 val
= convmul
* val
/ convdiv
;
2908 if ((min
&& val
< *min
) || (max
&& val
> *max
)) {
2914 val
= convdiv
* (*i
) / convmul
;
2916 err
= proc_put_char(&buffer
, &left
, '\t');
2920 err
= proc_put_long(&buffer
, &left
, val
, false);
2926 if (!write
&& !first
&& left
&& !err
)
2927 err
= proc_put_char(&buffer
, &left
, '\n');
2929 left
-= proc_skip_spaces(&p
);
2933 return err
? : -EINVAL
;
2941 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2942 void __user
*buffer
,
2943 size_t *lenp
, loff_t
*ppos
,
2944 unsigned long convmul
,
2945 unsigned long convdiv
)
2947 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2948 buffer
, lenp
, ppos
, convmul
, convdiv
);
2952 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2953 * @table: the sysctl table
2954 * @write: %TRUE if this is a write to the sysctl file
2955 * @buffer: the user buffer
2956 * @lenp: the size of the user buffer
2957 * @ppos: file position
2959 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2960 * values from/to the user buffer, treated as an ASCII string.
2962 * This routine will ensure the values are within the range specified by
2963 * table->extra1 (min) and table->extra2 (max).
2965 * Returns 0 on success.
2967 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2968 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2970 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2974 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2975 * @table: the sysctl table
2976 * @write: %TRUE if this is a write to the sysctl file
2977 * @buffer: the user buffer
2978 * @lenp: the size of the user buffer
2979 * @ppos: file position
2981 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2982 * values from/to the user buffer, treated as an ASCII string. The values
2983 * are treated as milliseconds, and converted to jiffies when they are stored.
2985 * This routine will ensure the values are within the range specified by
2986 * table->extra1 (min) and table->extra2 (max).
2988 * Returns 0 on success.
2990 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2991 void __user
*buffer
,
2992 size_t *lenp
, loff_t
*ppos
)
2994 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2995 lenp
, ppos
, HZ
, 1000l);
2999 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
3001 int write
, void *data
)
3004 if (*lvalp
> INT_MAX
/ HZ
)
3006 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
3012 lval
= -(unsigned long)val
;
3015 lval
= (unsigned long)val
;
3022 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
3024 int write
, void *data
)
3027 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
3029 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
3035 lval
= -(unsigned long)val
;
3038 lval
= (unsigned long)val
;
3040 *lvalp
= jiffies_to_clock_t(lval
);
3045 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
3047 int write
, void *data
)
3050 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
3060 lval
= -(unsigned long)val
;
3063 lval
= (unsigned long)val
;
3065 *lvalp
= jiffies_to_msecs(lval
);
3071 * proc_dointvec_jiffies - read a vector of integers as seconds
3072 * @table: the sysctl table
3073 * @write: %TRUE if this is a write to the sysctl file
3074 * @buffer: the user buffer
3075 * @lenp: the size of the user buffer
3076 * @ppos: file position
3078 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3079 * values from/to the user buffer, treated as an ASCII string.
3080 * The values read are assumed to be in seconds, and are converted into
3083 * Returns 0 on success.
3085 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3086 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3088 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
3089 do_proc_dointvec_jiffies_conv
,NULL
);
3093 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3094 * @table: the sysctl table
3095 * @write: %TRUE if this is a write to the sysctl file
3096 * @buffer: the user buffer
3097 * @lenp: the size of the user buffer
3098 * @ppos: pointer to the file position
3100 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3101 * values from/to the user buffer, treated as an ASCII string.
3102 * The values read are assumed to be in 1/USER_HZ seconds, and
3103 * are converted into jiffies.
3105 * Returns 0 on success.
3107 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3108 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3110 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
3111 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
3115 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3116 * @table: the sysctl table
3117 * @write: %TRUE if this is a write to the sysctl file
3118 * @buffer: the user buffer
3119 * @lenp: the size of the user buffer
3120 * @ppos: file position
3121 * @ppos: the current position in the file
3123 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3124 * values from/to the user buffer, treated as an ASCII string.
3125 * The values read are assumed to be in 1/1000 seconds, and
3126 * are converted into jiffies.
3128 * Returns 0 on success.
3130 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3131 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3133 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
3134 do_proc_dointvec_ms_jiffies_conv
, NULL
);
3137 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
3138 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3140 struct pid
*new_pid
;
3144 tmp
= pid_vnr(cad_pid
);
3146 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
3147 lenp
, ppos
, NULL
, NULL
);
3151 new_pid
= find_get_pid(tmp
);
3155 put_pid(xchg(&cad_pid
, new_pid
));
3160 * proc_do_large_bitmap - read/write from/to a large bitmap
3161 * @table: the sysctl table
3162 * @write: %TRUE if this is a write to the sysctl file
3163 * @buffer: the user buffer
3164 * @lenp: the size of the user buffer
3165 * @ppos: file position
3167 * The bitmap is stored at table->data and the bitmap length (in bits)
3170 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3171 * large bitmaps may be represented in a compact manner. Writing into
3172 * the file will clear the bitmap then update it with the given input.
3174 * Returns 0 on success.
3176 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3177 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3181 size_t left
= *lenp
;
3182 unsigned long bitmap_len
= table
->maxlen
;
3183 unsigned long *bitmap
= *(unsigned long **) table
->data
;
3184 unsigned long *tmp_bitmap
= NULL
;
3185 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
3187 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3196 if (left
> PAGE_SIZE
- 1) {
3197 left
= PAGE_SIZE
- 1;
3198 /* How much of the buffer we'll skip this pass */
3199 skipped
= *lenp
- left
;
3202 p
= kbuf
= memdup_user_nul(buffer
, left
);
3204 return PTR_ERR(kbuf
);
3206 tmp_bitmap
= bitmap_zalloc(bitmap_len
, GFP_KERNEL
);
3211 proc_skip_char(&p
, &left
, '\n');
3212 while (!err
&& left
) {
3213 unsigned long val_a
, val_b
;
3217 /* In case we stop parsing mid-number, we can reset */
3219 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3222 * If we consumed the entirety of a truncated buffer or
3223 * only one char is left (may be a "-"), then stop here,
3224 * reset, & come back for more.
3226 if ((left
<= 1) && skipped
) {
3233 if (val_a
>= bitmap_len
|| neg
) {
3245 err
= proc_get_long(&p
, &left
, &val_b
,
3246 &neg
, tr_b
, sizeof(tr_b
),
3249 * If we consumed all of a truncated buffer or
3250 * then stop here, reset, & come back for more.
3252 if (!left
&& skipped
) {
3259 if (val_b
>= bitmap_len
|| neg
||
3270 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3272 proc_skip_char(&p
, &left
, '\n');
3277 unsigned long bit_a
, bit_b
= 0;
3280 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3281 if (bit_a
>= bitmap_len
)
3283 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3287 err
= proc_put_char(&buffer
, &left
, ',');
3291 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3294 if (bit_a
!= bit_b
) {
3295 err
= proc_put_char(&buffer
, &left
, '-');
3298 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3306 err
= proc_put_char(&buffer
, &left
, '\n');
3312 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3314 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3320 bitmap_free(tmp_bitmap
);
3324 #else /* CONFIG_PROC_SYSCTL */
3326 int proc_dostring(struct ctl_table
*table
, int write
,
3327 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3332 int proc_dointvec(struct ctl_table
*table
, int write
,
3333 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3338 int proc_douintvec(struct ctl_table
*table
, int write
,
3339 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3344 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3345 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3350 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3351 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3356 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3357 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3362 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3363 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3368 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3369 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3374 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3375 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3380 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3381 void __user
*buffer
,
3382 size_t *lenp
, loff_t
*ppos
)
3387 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3388 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3393 #endif /* CONFIG_PROC_SYSCTL */
3395 #if defined(CONFIG_SYSCTL)
3396 int proc_do_static_key(struct ctl_table
*table
, int write
,
3397 void __user
*buffer
, size_t *lenp
,
3400 struct static_key
*key
= (struct static_key
*)table
->data
;
3401 static DEFINE_MUTEX(static_key_mutex
);
3403 struct ctl_table tmp
= {
3405 .maxlen
= sizeof(val
),
3406 .mode
= table
->mode
,
3407 .extra1
= SYSCTL_ZERO
,
3408 .extra2
= SYSCTL_ONE
,
3411 if (write
&& !capable(CAP_SYS_ADMIN
))
3414 mutex_lock(&static_key_mutex
);
3415 val
= static_key_enabled(key
);
3416 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
3417 if (write
&& !ret
) {
3419 static_key_enable(key
);
3421 static_key_disable(key
);
3423 mutex_unlock(&static_key_mutex
);
3428 * No sense putting this after each symbol definition, twice,
3429 * exception granted :-)
3431 EXPORT_SYMBOL(proc_dointvec
);
3432 EXPORT_SYMBOL(proc_douintvec
);
3433 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3434 EXPORT_SYMBOL(proc_dointvec_minmax
);
3435 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3436 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3437 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3438 EXPORT_SYMBOL(proc_dostring
);
3439 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3440 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3441 EXPORT_SYMBOL(proc_do_large_bitmap
);