2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
22 #include <linux/aio.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/bitmap.h>
28 #include <linux/signal.h>
29 #include <linux/printk.h>
30 #include <linux/proc_fs.h>
31 #include <linux/security.h>
32 #include <linux/ctype.h>
33 #include <linux/kmemleak.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/kobject.h>
38 #include <linux/net.h>
39 #include <linux/sysrq.h>
40 #include <linux/highuid.h>
41 #include <linux/writeback.h>
42 #include <linux/ratelimit.h>
43 #include <linux/compaction.h>
44 #include <linux/hugetlb.h>
45 #include <linux/initrd.h>
46 #include <linux/key.h>
47 #include <linux/times.h>
48 #include <linux/limits.h>
49 #include <linux/dcache.h>
50 #include <linux/dnotify.h>
51 #include <linux/syscalls.h>
52 #include <linux/vmstat.h>
53 #include <linux/nfs_fs.h>
54 #include <linux/acpi.h>
55 #include <linux/reboot.h>
56 #include <linux/ftrace.h>
57 #include <linux/perf_event.h>
58 #include <linux/kprobes.h>
59 #include <linux/pipe_fs_i.h>
60 #include <linux/oom.h>
61 #include <linux/kmod.h>
62 #include <linux/capability.h>
63 #include <linux/binfmts.h>
64 #include <linux/sched/sysctl.h>
65 #include <linux/sched/coredump.h>
66 #include <linux/kexec.h>
67 #include <linux/bpf.h>
68 #include <linux/mount.h>
70 #include "../lib/kstrtox.h"
72 #include <linux/uaccess.h>
73 #include <asm/processor.h>
77 #include <asm/stacktrace.h>
81 #include <asm/setup.h>
83 #ifdef CONFIG_BSD_PROCESS_ACCT
84 #include <linux/acct.h>
86 #ifdef CONFIG_RT_MUTEXES
87 #include <linux/rtmutex.h>
89 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
90 #include <linux/lockdep.h>
92 #ifdef CONFIG_CHR_DEV_SG
95 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
96 #include <linux/stackleak.h>
98 #ifdef CONFIG_LOCKUP_DETECTOR
99 #include <linux/nmi.h>
102 #if defined(CONFIG_SYSCTL)
104 /* External variables not in a header file. */
105 extern int suid_dumpable
;
106 #ifdef CONFIG_COREDUMP
107 extern int core_uses_pid
;
108 extern char core_pattern
[];
109 extern unsigned int core_pipe_limit
;
112 extern int pid_max_min
, pid_max_max
;
113 extern int percpu_pagelist_fraction
;
114 extern int latencytop_enabled
;
115 extern unsigned int sysctl_nr_open_min
, sysctl_nr_open_max
;
117 extern int sysctl_nr_trim_pages
;
120 /* Constants used for minimum and maximum */
121 #ifdef CONFIG_LOCKUP_DETECTOR
122 static int sixty
= 60;
125 static int __maybe_unused neg_one
= -1;
128 static int __maybe_unused one
= 1;
129 static int __maybe_unused two
= 2;
130 static int __maybe_unused four
= 4;
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 lenght will be ignored. Multiple writes will append
200 * These write modes control how current file position affects the behavior of
201 * updating sysctl values through the proc interface on each write.
203 enum sysctl_writes_mode
{
204 SYSCTL_WRITES_LEGACY
= -1,
205 SYSCTL_WRITES_WARN
= 0,
206 SYSCTL_WRITES_STRICT
= 1,
209 static enum sysctl_writes_mode sysctl_writes_strict
= SYSCTL_WRITES_STRICT
;
211 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
212 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
213 static int proc_taint(struct ctl_table
*table
, int write
,
214 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
218 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
219 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
222 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
223 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
224 #ifdef CONFIG_COREDUMP
225 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
226 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
228 static int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
229 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
230 #ifdef CONFIG_BPF_SYSCALL
231 static int proc_dointvec_minmax_bpf_stats(struct ctl_table
*table
, int write
,
232 void __user
*buffer
, size_t *lenp
,
236 #ifdef CONFIG_MAGIC_SYSRQ
237 /* Note: sysrq code uses its own private copy */
238 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
240 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
241 void __user
*buffer
, size_t *lenp
,
246 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
251 sysrq_toggle_support(__sysrq_enabled
);
258 static struct ctl_table kern_table
[];
259 static struct ctl_table vm_table
[];
260 static struct ctl_table fs_table
[];
261 static struct ctl_table debug_table
[];
262 static struct ctl_table dev_table
[];
263 extern struct ctl_table random_table
[];
265 extern struct ctl_table epoll_table
[];
268 #ifdef CONFIG_FW_LOADER_USER_HELPER
269 extern struct ctl_table firmware_config_table
[];
272 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
273 int sysctl_legacy_va_layout
;
276 /* The default sysctl tables: */
278 static struct ctl_table sysctl_base_table
[] = {
280 .procname
= "kernel",
297 .child
= debug_table
,
307 #ifdef CONFIG_SCHED_DEBUG
308 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
309 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
310 static int min_wakeup_granularity_ns
; /* 0 usecs */
311 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
313 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
314 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
315 #endif /* CONFIG_SMP */
316 #endif /* CONFIG_SCHED_DEBUG */
318 #ifdef CONFIG_COMPACTION
319 static int min_extfrag_threshold
;
320 static int max_extfrag_threshold
= 1000;
323 static struct ctl_table kern_table
[] = {
325 .procname
= "sched_child_runs_first",
326 .data
= &sysctl_sched_child_runs_first
,
327 .maxlen
= sizeof(unsigned int),
329 .proc_handler
= proc_dointvec
,
331 #ifdef CONFIG_SCHED_DEBUG
333 .procname
= "sched_min_granularity_ns",
334 .data
= &sysctl_sched_min_granularity
,
335 .maxlen
= sizeof(unsigned int),
337 .proc_handler
= sched_proc_update_handler
,
338 .extra1
= &min_sched_granularity_ns
,
339 .extra2
= &max_sched_granularity_ns
,
342 .procname
= "sched_latency_ns",
343 .data
= &sysctl_sched_latency
,
344 .maxlen
= sizeof(unsigned int),
346 .proc_handler
= sched_proc_update_handler
,
347 .extra1
= &min_sched_granularity_ns
,
348 .extra2
= &max_sched_granularity_ns
,
351 .procname
= "sched_wakeup_granularity_ns",
352 .data
= &sysctl_sched_wakeup_granularity
,
353 .maxlen
= sizeof(unsigned int),
355 .proc_handler
= sched_proc_update_handler
,
356 .extra1
= &min_wakeup_granularity_ns
,
357 .extra2
= &max_wakeup_granularity_ns
,
361 .procname
= "sched_tunable_scaling",
362 .data
= &sysctl_sched_tunable_scaling
,
363 .maxlen
= sizeof(enum sched_tunable_scaling
),
365 .proc_handler
= sched_proc_update_handler
,
366 .extra1
= &min_sched_tunable_scaling
,
367 .extra2
= &max_sched_tunable_scaling
,
370 .procname
= "sched_migration_cost_ns",
371 .data
= &sysctl_sched_migration_cost
,
372 .maxlen
= sizeof(unsigned int),
374 .proc_handler
= proc_dointvec
,
377 .procname
= "sched_nr_migrate",
378 .data
= &sysctl_sched_nr_migrate
,
379 .maxlen
= sizeof(unsigned int),
381 .proc_handler
= proc_dointvec
,
383 #ifdef CONFIG_SCHEDSTATS
385 .procname
= "sched_schedstats",
387 .maxlen
= sizeof(unsigned int),
389 .proc_handler
= sysctl_schedstats
,
393 #endif /* CONFIG_SCHEDSTATS */
394 #endif /* CONFIG_SMP */
395 #ifdef CONFIG_NUMA_BALANCING
397 .procname
= "numa_balancing_scan_delay_ms",
398 .data
= &sysctl_numa_balancing_scan_delay
,
399 .maxlen
= sizeof(unsigned int),
401 .proc_handler
= proc_dointvec
,
404 .procname
= "numa_balancing_scan_period_min_ms",
405 .data
= &sysctl_numa_balancing_scan_period_min
,
406 .maxlen
= sizeof(unsigned int),
408 .proc_handler
= proc_dointvec
,
411 .procname
= "numa_balancing_scan_period_max_ms",
412 .data
= &sysctl_numa_balancing_scan_period_max
,
413 .maxlen
= sizeof(unsigned int),
415 .proc_handler
= proc_dointvec
,
418 .procname
= "numa_balancing_scan_size_mb",
419 .data
= &sysctl_numa_balancing_scan_size
,
420 .maxlen
= sizeof(unsigned int),
422 .proc_handler
= proc_dointvec_minmax
,
426 .procname
= "numa_balancing",
427 .data
= NULL
, /* filled in by handler */
428 .maxlen
= sizeof(unsigned int),
430 .proc_handler
= sysctl_numa_balancing
,
434 #endif /* CONFIG_NUMA_BALANCING */
435 #endif /* CONFIG_SCHED_DEBUG */
437 .procname
= "sched_rt_period_us",
438 .data
= &sysctl_sched_rt_period
,
439 .maxlen
= sizeof(unsigned int),
441 .proc_handler
= sched_rt_handler
,
444 .procname
= "sched_rt_runtime_us",
445 .data
= &sysctl_sched_rt_runtime
,
446 .maxlen
= sizeof(int),
448 .proc_handler
= sched_rt_handler
,
451 .procname
= "sched_rr_timeslice_ms",
452 .data
= &sysctl_sched_rr_timeslice
,
453 .maxlen
= sizeof(int),
455 .proc_handler
= sched_rr_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
,
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
,
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
,
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
,
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
,
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
,
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
738 .data
= &__sysrq_enabled
,
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
,
796 #ifdef CONFIG_MATHEMU
798 .procname
= "ieee_emulation_warnings",
799 .data
= &sysctl_ieee_emulation_warnings
,
800 .maxlen
= sizeof(int),
802 .proc_handler
= proc_dointvec
,
806 .procname
= "userprocess_debug",
807 .data
= &show_unhandled_signals
,
808 .maxlen
= sizeof(int),
810 .proc_handler
= proc_dointvec
,
814 .procname
= "pid_max",
816 .maxlen
= sizeof (int),
818 .proc_handler
= proc_dointvec_minmax
,
819 .extra1
= &pid_max_min
,
820 .extra2
= &pid_max_max
,
823 .procname
= "panic_on_oops",
824 .data
= &panic_on_oops
,
825 .maxlen
= sizeof(int),
827 .proc_handler
= proc_dointvec
,
830 .procname
= "panic_print",
831 .data
= &panic_print
,
832 .maxlen
= sizeof(unsigned long),
834 .proc_handler
= proc_doulongvec_minmax
,
836 #if defined CONFIG_PRINTK
838 .procname
= "printk",
839 .data
= &console_loglevel
,
840 .maxlen
= 4*sizeof(int),
842 .proc_handler
= proc_dointvec
,
845 .procname
= "printk_ratelimit",
846 .data
= &printk_ratelimit_state
.interval
,
847 .maxlen
= sizeof(int),
849 .proc_handler
= proc_dointvec_jiffies
,
852 .procname
= "printk_ratelimit_burst",
853 .data
= &printk_ratelimit_state
.burst
,
854 .maxlen
= sizeof(int),
856 .proc_handler
= proc_dointvec
,
859 .procname
= "printk_delay",
860 .data
= &printk_delay_msec
,
861 .maxlen
= sizeof(int),
863 .proc_handler
= proc_dointvec_minmax
,
865 .extra2
= &ten_thousand
,
868 .procname
= "printk_devkmsg",
869 .data
= devkmsg_log_str
,
870 .maxlen
= DEVKMSG_STR_MAX_SIZE
,
872 .proc_handler
= devkmsg_sysctl_set_loglvl
,
875 .procname
= "dmesg_restrict",
876 .data
= &dmesg_restrict
,
877 .maxlen
= sizeof(int),
879 .proc_handler
= proc_dointvec_minmax_sysadmin
,
884 .procname
= "kptr_restrict",
885 .data
= &kptr_restrict
,
886 .maxlen
= sizeof(int),
888 .proc_handler
= proc_dointvec_minmax_sysadmin
,
894 .procname
= "ngroups_max",
895 .data
= &ngroups_max
,
896 .maxlen
= sizeof (int),
898 .proc_handler
= proc_dointvec
,
901 .procname
= "cap_last_cap",
902 .data
= (void *)&cap_last_cap
,
903 .maxlen
= sizeof(int),
905 .proc_handler
= proc_dointvec
,
907 #if defined(CONFIG_LOCKUP_DETECTOR)
909 .procname
= "watchdog",
910 .data
= &watchdog_user_enabled
,
911 .maxlen
= sizeof(int),
913 .proc_handler
= proc_watchdog
,
918 .procname
= "watchdog_thresh",
919 .data
= &watchdog_thresh
,
920 .maxlen
= sizeof(int),
922 .proc_handler
= proc_watchdog_thresh
,
927 .procname
= "nmi_watchdog",
928 .data
= &nmi_watchdog_user_enabled
,
929 .maxlen
= sizeof(int),
930 .mode
= NMI_WATCHDOG_SYSCTL_PERM
,
931 .proc_handler
= proc_nmi_watchdog
,
936 .procname
= "watchdog_cpumask",
937 .data
= &watchdog_cpumask_bits
,
940 .proc_handler
= proc_watchdog_cpumask
,
942 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
944 .procname
= "soft_watchdog",
945 .data
= &soft_watchdog_user_enabled
,
946 .maxlen
= sizeof(int),
948 .proc_handler
= proc_soft_watchdog
,
953 .procname
= "softlockup_panic",
954 .data
= &softlockup_panic
,
955 .maxlen
= sizeof(int),
957 .proc_handler
= proc_dointvec_minmax
,
963 .procname
= "softlockup_all_cpu_backtrace",
964 .data
= &sysctl_softlockup_all_cpu_backtrace
,
965 .maxlen
= sizeof(int),
967 .proc_handler
= proc_dointvec_minmax
,
971 #endif /* CONFIG_SMP */
973 #ifdef CONFIG_HARDLOCKUP_DETECTOR
975 .procname
= "hardlockup_panic",
976 .data
= &hardlockup_panic
,
977 .maxlen
= sizeof(int),
979 .proc_handler
= proc_dointvec_minmax
,
985 .procname
= "hardlockup_all_cpu_backtrace",
986 .data
= &sysctl_hardlockup_all_cpu_backtrace
,
987 .maxlen
= sizeof(int),
989 .proc_handler
= proc_dointvec_minmax
,
993 #endif /* CONFIG_SMP */
997 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
999 .procname
= "unknown_nmi_panic",
1000 .data
= &unknown_nmi_panic
,
1001 .maxlen
= sizeof (int),
1003 .proc_handler
= proc_dointvec
,
1006 #if defined(CONFIG_X86)
1008 .procname
= "panic_on_unrecovered_nmi",
1009 .data
= &panic_on_unrecovered_nmi
,
1010 .maxlen
= sizeof(int),
1012 .proc_handler
= proc_dointvec
,
1015 .procname
= "panic_on_io_nmi",
1016 .data
= &panic_on_io_nmi
,
1017 .maxlen
= sizeof(int),
1019 .proc_handler
= proc_dointvec
,
1021 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1023 .procname
= "panic_on_stackoverflow",
1024 .data
= &sysctl_panic_on_stackoverflow
,
1025 .maxlen
= sizeof(int),
1027 .proc_handler
= proc_dointvec
,
1031 .procname
= "bootloader_type",
1032 .data
= &bootloader_type
,
1033 .maxlen
= sizeof (int),
1035 .proc_handler
= proc_dointvec
,
1038 .procname
= "bootloader_version",
1039 .data
= &bootloader_version
,
1040 .maxlen
= sizeof (int),
1042 .proc_handler
= proc_dointvec
,
1045 .procname
= "io_delay_type",
1046 .data
= &io_delay_type
,
1047 .maxlen
= sizeof(int),
1049 .proc_handler
= proc_dointvec
,
1052 #if defined(CONFIG_MMU)
1054 .procname
= "randomize_va_space",
1055 .data
= &randomize_va_space
,
1056 .maxlen
= sizeof(int),
1058 .proc_handler
= proc_dointvec
,
1061 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1063 .procname
= "spin_retry",
1064 .data
= &spin_retry
,
1065 .maxlen
= sizeof (int),
1067 .proc_handler
= proc_dointvec
,
1070 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1072 .procname
= "acpi_video_flags",
1073 .data
= &acpi_realmode_flags
,
1074 .maxlen
= sizeof (unsigned long),
1076 .proc_handler
= proc_doulongvec_minmax
,
1079 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1081 .procname
= "ignore-unaligned-usertrap",
1082 .data
= &no_unaligned_warning
,
1083 .maxlen
= sizeof (int),
1085 .proc_handler
= proc_dointvec
,
1090 .procname
= "unaligned-dump-stack",
1091 .data
= &unaligned_dump_stack
,
1092 .maxlen
= sizeof (int),
1094 .proc_handler
= proc_dointvec
,
1097 #ifdef CONFIG_DETECT_HUNG_TASK
1099 .procname
= "hung_task_panic",
1100 .data
= &sysctl_hung_task_panic
,
1101 .maxlen
= sizeof(int),
1103 .proc_handler
= proc_dointvec_minmax
,
1108 .procname
= "hung_task_check_count",
1109 .data
= &sysctl_hung_task_check_count
,
1110 .maxlen
= sizeof(int),
1112 .proc_handler
= proc_dointvec_minmax
,
1116 .procname
= "hung_task_timeout_secs",
1117 .data
= &sysctl_hung_task_timeout_secs
,
1118 .maxlen
= sizeof(unsigned long),
1120 .proc_handler
= proc_dohung_task_timeout_secs
,
1121 .extra2
= &hung_task_timeout_max
,
1124 .procname
= "hung_task_check_interval_secs",
1125 .data
= &sysctl_hung_task_check_interval_secs
,
1126 .maxlen
= sizeof(unsigned long),
1128 .proc_handler
= proc_dohung_task_timeout_secs
,
1129 .extra2
= &hung_task_timeout_max
,
1132 .procname
= "hung_task_warnings",
1133 .data
= &sysctl_hung_task_warnings
,
1134 .maxlen
= sizeof(int),
1136 .proc_handler
= proc_dointvec_minmax
,
1140 #ifdef CONFIG_RT_MUTEXES
1142 .procname
= "max_lock_depth",
1143 .data
= &max_lock_depth
,
1144 .maxlen
= sizeof(int),
1146 .proc_handler
= proc_dointvec
,
1150 .procname
= "poweroff_cmd",
1151 .data
= &poweroff_cmd
,
1152 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1154 .proc_handler
= proc_dostring
,
1160 .child
= key_sysctls
,
1163 #ifdef CONFIG_PERF_EVENTS
1165 * User-space scripts rely on the existence of this file
1166 * as a feature check for perf_events being enabled.
1168 * So it's an ABI, do not remove!
1171 .procname
= "perf_event_paranoid",
1172 .data
= &sysctl_perf_event_paranoid
,
1173 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1175 .proc_handler
= proc_dointvec
,
1178 .procname
= "perf_event_mlock_kb",
1179 .data
= &sysctl_perf_event_mlock
,
1180 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1182 .proc_handler
= proc_dointvec
,
1185 .procname
= "perf_event_max_sample_rate",
1186 .data
= &sysctl_perf_event_sample_rate
,
1187 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1189 .proc_handler
= perf_proc_update_handler
,
1193 .procname
= "perf_cpu_time_max_percent",
1194 .data
= &sysctl_perf_cpu_time_max_percent
,
1195 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1197 .proc_handler
= perf_cpu_time_max_percent_handler
,
1199 .extra2
= &one_hundred
,
1202 .procname
= "perf_event_max_stack",
1203 .data
= &sysctl_perf_event_max_stack
,
1204 .maxlen
= sizeof(sysctl_perf_event_max_stack
),
1206 .proc_handler
= perf_event_max_stack_handler
,
1208 .extra2
= &six_hundred_forty_kb
,
1211 .procname
= "perf_event_max_contexts_per_stack",
1212 .data
= &sysctl_perf_event_max_contexts_per_stack
,
1213 .maxlen
= sizeof(sysctl_perf_event_max_contexts_per_stack
),
1215 .proc_handler
= perf_event_max_stack_handler
,
1217 .extra2
= &one_thousand
,
1221 .procname
= "panic_on_warn",
1222 .data
= &panic_on_warn
,
1223 .maxlen
= sizeof(int),
1225 .proc_handler
= proc_dointvec_minmax
,
1229 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1231 .procname
= "timer_migration",
1232 .data
= &sysctl_timer_migration
,
1233 .maxlen
= sizeof(unsigned int),
1235 .proc_handler
= timer_migration_handler
,
1240 #ifdef CONFIG_BPF_SYSCALL
1242 .procname
= "unprivileged_bpf_disabled",
1243 .data
= &sysctl_unprivileged_bpf_disabled
,
1244 .maxlen
= sizeof(sysctl_unprivileged_bpf_disabled
),
1246 /* only handle a transition from default "0" to "1" */
1247 .proc_handler
= proc_dointvec_minmax
,
1252 .procname
= "bpf_stats_enabled",
1253 .data
= &sysctl_bpf_stats_enabled
,
1254 .maxlen
= sizeof(sysctl_bpf_stats_enabled
),
1256 .proc_handler
= proc_dointvec_minmax_bpf_stats
,
1261 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1263 .procname
= "panic_on_rcu_stall",
1264 .data
= &sysctl_panic_on_rcu_stall
,
1265 .maxlen
= sizeof(sysctl_panic_on_rcu_stall
),
1267 .proc_handler
= proc_dointvec_minmax
,
1272 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1274 .procname
= "stack_erasing",
1276 .maxlen
= sizeof(int),
1278 .proc_handler
= stack_erasing_sysctl
,
1286 static struct ctl_table vm_table
[] = {
1288 .procname
= "overcommit_memory",
1289 .data
= &sysctl_overcommit_memory
,
1290 .maxlen
= sizeof(sysctl_overcommit_memory
),
1292 .proc_handler
= proc_dointvec_minmax
,
1297 .procname
= "panic_on_oom",
1298 .data
= &sysctl_panic_on_oom
,
1299 .maxlen
= sizeof(sysctl_panic_on_oom
),
1301 .proc_handler
= proc_dointvec_minmax
,
1306 .procname
= "oom_kill_allocating_task",
1307 .data
= &sysctl_oom_kill_allocating_task
,
1308 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1310 .proc_handler
= proc_dointvec
,
1313 .procname
= "oom_dump_tasks",
1314 .data
= &sysctl_oom_dump_tasks
,
1315 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1317 .proc_handler
= proc_dointvec
,
1320 .procname
= "overcommit_ratio",
1321 .data
= &sysctl_overcommit_ratio
,
1322 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1324 .proc_handler
= overcommit_ratio_handler
,
1327 .procname
= "overcommit_kbytes",
1328 .data
= &sysctl_overcommit_kbytes
,
1329 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1331 .proc_handler
= overcommit_kbytes_handler
,
1334 .procname
= "page-cluster",
1335 .data
= &page_cluster
,
1336 .maxlen
= sizeof(int),
1338 .proc_handler
= proc_dointvec_minmax
,
1342 .procname
= "dirty_background_ratio",
1343 .data
= &dirty_background_ratio
,
1344 .maxlen
= sizeof(dirty_background_ratio
),
1346 .proc_handler
= dirty_background_ratio_handler
,
1348 .extra2
= &one_hundred
,
1351 .procname
= "dirty_background_bytes",
1352 .data
= &dirty_background_bytes
,
1353 .maxlen
= sizeof(dirty_background_bytes
),
1355 .proc_handler
= dirty_background_bytes_handler
,
1359 .procname
= "dirty_ratio",
1360 .data
= &vm_dirty_ratio
,
1361 .maxlen
= sizeof(vm_dirty_ratio
),
1363 .proc_handler
= dirty_ratio_handler
,
1365 .extra2
= &one_hundred
,
1368 .procname
= "dirty_bytes",
1369 .data
= &vm_dirty_bytes
,
1370 .maxlen
= sizeof(vm_dirty_bytes
),
1372 .proc_handler
= dirty_bytes_handler
,
1373 .extra1
= &dirty_bytes_min
,
1376 .procname
= "dirty_writeback_centisecs",
1377 .data
= &dirty_writeback_interval
,
1378 .maxlen
= sizeof(dirty_writeback_interval
),
1380 .proc_handler
= dirty_writeback_centisecs_handler
,
1383 .procname
= "dirty_expire_centisecs",
1384 .data
= &dirty_expire_interval
,
1385 .maxlen
= sizeof(dirty_expire_interval
),
1387 .proc_handler
= proc_dointvec_minmax
,
1391 .procname
= "dirtytime_expire_seconds",
1392 .data
= &dirtytime_expire_interval
,
1393 .maxlen
= sizeof(dirtytime_expire_interval
),
1395 .proc_handler
= dirtytime_interval_handler
,
1399 .procname
= "swappiness",
1400 .data
= &vm_swappiness
,
1401 .maxlen
= sizeof(vm_swappiness
),
1403 .proc_handler
= proc_dointvec_minmax
,
1405 .extra2
= &one_hundred
,
1407 #ifdef CONFIG_HUGETLB_PAGE
1409 .procname
= "nr_hugepages",
1411 .maxlen
= sizeof(unsigned long),
1413 .proc_handler
= hugetlb_sysctl_handler
,
1417 .procname
= "nr_hugepages_mempolicy",
1419 .maxlen
= sizeof(unsigned long),
1421 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1424 .procname
= "numa_stat",
1425 .data
= &sysctl_vm_numa_stat
,
1426 .maxlen
= sizeof(int),
1428 .proc_handler
= sysctl_vm_numa_stat_handler
,
1434 .procname
= "hugetlb_shm_group",
1435 .data
= &sysctl_hugetlb_shm_group
,
1436 .maxlen
= sizeof(gid_t
),
1438 .proc_handler
= proc_dointvec
,
1441 .procname
= "nr_overcommit_hugepages",
1443 .maxlen
= sizeof(unsigned long),
1445 .proc_handler
= hugetlb_overcommit_handler
,
1449 .procname
= "lowmem_reserve_ratio",
1450 .data
= &sysctl_lowmem_reserve_ratio
,
1451 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1453 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1456 .procname
= "drop_caches",
1457 .data
= &sysctl_drop_caches
,
1458 .maxlen
= sizeof(int),
1460 .proc_handler
= drop_caches_sysctl_handler
,
1464 #ifdef CONFIG_COMPACTION
1466 .procname
= "compact_memory",
1467 .data
= &sysctl_compact_memory
,
1468 .maxlen
= sizeof(int),
1470 .proc_handler
= sysctl_compaction_handler
,
1473 .procname
= "extfrag_threshold",
1474 .data
= &sysctl_extfrag_threshold
,
1475 .maxlen
= sizeof(int),
1477 .proc_handler
= proc_dointvec_minmax
,
1478 .extra1
= &min_extfrag_threshold
,
1479 .extra2
= &max_extfrag_threshold
,
1482 .procname
= "compact_unevictable_allowed",
1483 .data
= &sysctl_compact_unevictable_allowed
,
1484 .maxlen
= sizeof(int),
1486 .proc_handler
= proc_dointvec
,
1491 #endif /* CONFIG_COMPACTION */
1493 .procname
= "min_free_kbytes",
1494 .data
= &min_free_kbytes
,
1495 .maxlen
= sizeof(min_free_kbytes
),
1497 .proc_handler
= min_free_kbytes_sysctl_handler
,
1501 .procname
= "watermark_boost_factor",
1502 .data
= &watermark_boost_factor
,
1503 .maxlen
= sizeof(watermark_boost_factor
),
1505 .proc_handler
= watermark_boost_factor_sysctl_handler
,
1509 .procname
= "watermark_scale_factor",
1510 .data
= &watermark_scale_factor
,
1511 .maxlen
= sizeof(watermark_scale_factor
),
1513 .proc_handler
= watermark_scale_factor_sysctl_handler
,
1515 .extra2
= &one_thousand
,
1518 .procname
= "percpu_pagelist_fraction",
1519 .data
= &percpu_pagelist_fraction
,
1520 .maxlen
= sizeof(percpu_pagelist_fraction
),
1522 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1527 .procname
= "max_map_count",
1528 .data
= &sysctl_max_map_count
,
1529 .maxlen
= sizeof(sysctl_max_map_count
),
1531 .proc_handler
= proc_dointvec_minmax
,
1536 .procname
= "nr_trim_pages",
1537 .data
= &sysctl_nr_trim_pages
,
1538 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1540 .proc_handler
= proc_dointvec_minmax
,
1545 .procname
= "laptop_mode",
1546 .data
= &laptop_mode
,
1547 .maxlen
= sizeof(laptop_mode
),
1549 .proc_handler
= proc_dointvec_jiffies
,
1552 .procname
= "block_dump",
1553 .data
= &block_dump
,
1554 .maxlen
= sizeof(block_dump
),
1556 .proc_handler
= proc_dointvec
,
1560 .procname
= "vfs_cache_pressure",
1561 .data
= &sysctl_vfs_cache_pressure
,
1562 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1564 .proc_handler
= proc_dointvec
,
1567 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1569 .procname
= "legacy_va_layout",
1570 .data
= &sysctl_legacy_va_layout
,
1571 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1573 .proc_handler
= proc_dointvec
,
1579 .procname
= "zone_reclaim_mode",
1580 .data
= &node_reclaim_mode
,
1581 .maxlen
= sizeof(node_reclaim_mode
),
1583 .proc_handler
= proc_dointvec
,
1587 .procname
= "min_unmapped_ratio",
1588 .data
= &sysctl_min_unmapped_ratio
,
1589 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1591 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1593 .extra2
= &one_hundred
,
1596 .procname
= "min_slab_ratio",
1597 .data
= &sysctl_min_slab_ratio
,
1598 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1600 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1602 .extra2
= &one_hundred
,
1607 .procname
= "stat_interval",
1608 .data
= &sysctl_stat_interval
,
1609 .maxlen
= sizeof(sysctl_stat_interval
),
1611 .proc_handler
= proc_dointvec_jiffies
,
1614 .procname
= "stat_refresh",
1618 .proc_handler
= vmstat_refresh
,
1623 .procname
= "mmap_min_addr",
1624 .data
= &dac_mmap_min_addr
,
1625 .maxlen
= sizeof(unsigned long),
1627 .proc_handler
= mmap_min_addr_handler
,
1632 .procname
= "numa_zonelist_order",
1633 .data
= &numa_zonelist_order
,
1634 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1636 .proc_handler
= numa_zonelist_order_handler
,
1639 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1640 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1642 .procname
= "vdso_enabled",
1643 #ifdef CONFIG_X86_32
1644 .data
= &vdso32_enabled
,
1645 .maxlen
= sizeof(vdso32_enabled
),
1647 .data
= &vdso_enabled
,
1648 .maxlen
= sizeof(vdso_enabled
),
1651 .proc_handler
= proc_dointvec
,
1655 #ifdef CONFIG_HIGHMEM
1657 .procname
= "highmem_is_dirtyable",
1658 .data
= &vm_highmem_is_dirtyable
,
1659 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1661 .proc_handler
= proc_dointvec_minmax
,
1666 #ifdef CONFIG_MEMORY_FAILURE
1668 .procname
= "memory_failure_early_kill",
1669 .data
= &sysctl_memory_failure_early_kill
,
1670 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1672 .proc_handler
= proc_dointvec_minmax
,
1677 .procname
= "memory_failure_recovery",
1678 .data
= &sysctl_memory_failure_recovery
,
1679 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1681 .proc_handler
= proc_dointvec_minmax
,
1687 .procname
= "user_reserve_kbytes",
1688 .data
= &sysctl_user_reserve_kbytes
,
1689 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1691 .proc_handler
= proc_doulongvec_minmax
,
1694 .procname
= "admin_reserve_kbytes",
1695 .data
= &sysctl_admin_reserve_kbytes
,
1696 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1698 .proc_handler
= proc_doulongvec_minmax
,
1700 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1702 .procname
= "mmap_rnd_bits",
1703 .data
= &mmap_rnd_bits
,
1704 .maxlen
= sizeof(mmap_rnd_bits
),
1706 .proc_handler
= proc_dointvec_minmax
,
1707 .extra1
= (void *)&mmap_rnd_bits_min
,
1708 .extra2
= (void *)&mmap_rnd_bits_max
,
1711 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1713 .procname
= "mmap_rnd_compat_bits",
1714 .data
= &mmap_rnd_compat_bits
,
1715 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1717 .proc_handler
= proc_dointvec_minmax
,
1718 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1719 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1725 static struct ctl_table fs_table
[] = {
1727 .procname
= "inode-nr",
1728 .data
= &inodes_stat
,
1729 .maxlen
= 2*sizeof(long),
1731 .proc_handler
= proc_nr_inodes
,
1734 .procname
= "inode-state",
1735 .data
= &inodes_stat
,
1736 .maxlen
= 7*sizeof(long),
1738 .proc_handler
= proc_nr_inodes
,
1741 .procname
= "file-nr",
1742 .data
= &files_stat
,
1743 .maxlen
= sizeof(files_stat
),
1745 .proc_handler
= proc_nr_files
,
1748 .procname
= "file-max",
1749 .data
= &files_stat
.max_files
,
1750 .maxlen
= sizeof(files_stat
.max_files
),
1752 .proc_handler
= proc_doulongvec_minmax
,
1754 .extra2
= &long_max
,
1757 .procname
= "nr_open",
1758 .data
= &sysctl_nr_open
,
1759 .maxlen
= sizeof(unsigned int),
1761 .proc_handler
= proc_dointvec_minmax
,
1762 .extra1
= &sysctl_nr_open_min
,
1763 .extra2
= &sysctl_nr_open_max
,
1766 .procname
= "dentry-state",
1767 .data
= &dentry_stat
,
1768 .maxlen
= 6*sizeof(long),
1770 .proc_handler
= proc_nr_dentry
,
1773 .procname
= "overflowuid",
1774 .data
= &fs_overflowuid
,
1775 .maxlen
= sizeof(int),
1777 .proc_handler
= proc_dointvec_minmax
,
1778 .extra1
= &minolduid
,
1779 .extra2
= &maxolduid
,
1782 .procname
= "overflowgid",
1783 .data
= &fs_overflowgid
,
1784 .maxlen
= sizeof(int),
1786 .proc_handler
= proc_dointvec_minmax
,
1787 .extra1
= &minolduid
,
1788 .extra2
= &maxolduid
,
1790 #ifdef CONFIG_FILE_LOCKING
1792 .procname
= "leases-enable",
1793 .data
= &leases_enable
,
1794 .maxlen
= sizeof(int),
1796 .proc_handler
= proc_dointvec
,
1799 #ifdef CONFIG_DNOTIFY
1801 .procname
= "dir-notify-enable",
1802 .data
= &dir_notify_enable
,
1803 .maxlen
= sizeof(int),
1805 .proc_handler
= proc_dointvec
,
1809 #ifdef CONFIG_FILE_LOCKING
1811 .procname
= "lease-break-time",
1812 .data
= &lease_break_time
,
1813 .maxlen
= sizeof(int),
1815 .proc_handler
= proc_dointvec
,
1820 .procname
= "aio-nr",
1822 .maxlen
= sizeof(aio_nr
),
1824 .proc_handler
= proc_doulongvec_minmax
,
1827 .procname
= "aio-max-nr",
1828 .data
= &aio_max_nr
,
1829 .maxlen
= sizeof(aio_max_nr
),
1831 .proc_handler
= proc_doulongvec_minmax
,
1833 #endif /* CONFIG_AIO */
1834 #ifdef CONFIG_INOTIFY_USER
1836 .procname
= "inotify",
1838 .child
= inotify_table
,
1843 .procname
= "epoll",
1845 .child
= epoll_table
,
1850 .procname
= "protected_symlinks",
1851 .data
= &sysctl_protected_symlinks
,
1852 .maxlen
= sizeof(int),
1854 .proc_handler
= proc_dointvec_minmax
,
1859 .procname
= "protected_hardlinks",
1860 .data
= &sysctl_protected_hardlinks
,
1861 .maxlen
= sizeof(int),
1863 .proc_handler
= proc_dointvec_minmax
,
1868 .procname
= "protected_fifos",
1869 .data
= &sysctl_protected_fifos
,
1870 .maxlen
= sizeof(int),
1872 .proc_handler
= proc_dointvec_minmax
,
1877 .procname
= "protected_regular",
1878 .data
= &sysctl_protected_regular
,
1879 .maxlen
= sizeof(int),
1881 .proc_handler
= proc_dointvec_minmax
,
1886 .procname
= "suid_dumpable",
1887 .data
= &suid_dumpable
,
1888 .maxlen
= sizeof(int),
1890 .proc_handler
= proc_dointvec_minmax_coredump
,
1894 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1896 .procname
= "binfmt_misc",
1898 .child
= sysctl_mount_point
,
1902 .procname
= "pipe-max-size",
1903 .data
= &pipe_max_size
,
1904 .maxlen
= sizeof(pipe_max_size
),
1906 .proc_handler
= proc_dopipe_max_size
,
1909 .procname
= "pipe-user-pages-hard",
1910 .data
= &pipe_user_pages_hard
,
1911 .maxlen
= sizeof(pipe_user_pages_hard
),
1913 .proc_handler
= proc_doulongvec_minmax
,
1916 .procname
= "pipe-user-pages-soft",
1917 .data
= &pipe_user_pages_soft
,
1918 .maxlen
= sizeof(pipe_user_pages_soft
),
1920 .proc_handler
= proc_doulongvec_minmax
,
1923 .procname
= "mount-max",
1924 .data
= &sysctl_mount_max
,
1925 .maxlen
= sizeof(unsigned int),
1927 .proc_handler
= proc_dointvec_minmax
,
1933 static struct ctl_table debug_table
[] = {
1934 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1936 .procname
= "exception-trace",
1937 .data
= &show_unhandled_signals
,
1938 .maxlen
= sizeof(int),
1940 .proc_handler
= proc_dointvec
1943 #if defined(CONFIG_OPTPROBES)
1945 .procname
= "kprobes-optimization",
1946 .data
= &sysctl_kprobes_optimization
,
1947 .maxlen
= sizeof(int),
1949 .proc_handler
= proc_kprobes_optimization_handler
,
1957 static struct ctl_table dev_table
[] = {
1961 int __init
sysctl_init(void)
1963 struct ctl_table_header
*hdr
;
1965 hdr
= register_sysctl_table(sysctl_base_table
);
1966 kmemleak_not_leak(hdr
);
1970 #endif /* CONFIG_SYSCTL */
1976 #ifdef CONFIG_PROC_SYSCTL
1978 static int _proc_do_string(char *data
, int maxlen
, int write
,
1979 char __user
*buffer
,
1980 size_t *lenp
, loff_t
*ppos
)
1986 if (!data
|| !maxlen
|| !*lenp
) {
1992 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
1993 /* Only continue writes not past the end of buffer. */
1995 if (len
> maxlen
- 1)
2002 /* Start writing from beginning of buffer. */
2008 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
2009 if (get_user(c
, p
++))
2011 if (c
== 0 || c
== '\n')
2032 if (copy_to_user(buffer
, data
, len
))
2035 if (put_user('\n', buffer
+ len
))
2045 static void warn_sysctl_write(struct ctl_table
*table
)
2047 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2048 "This will not be supported in the future. To silence this\n"
2049 "warning, set kernel.sysctl_writes_strict = -1\n",
2050 current
->comm
, table
->procname
);
2054 * proc_first_pos_non_zero_ignore - check if first position is allowed
2055 * @ppos: file position
2056 * @table: the sysctl table
2058 * Returns true if the first position is non-zero and the sysctl_writes_strict
2059 * mode indicates this is not allowed for numeric input types. String proc
2060 * handlers can ignore the return value.
2062 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
2063 struct ctl_table
*table
)
2068 switch (sysctl_writes_strict
) {
2069 case SYSCTL_WRITES_STRICT
:
2071 case SYSCTL_WRITES_WARN
:
2072 warn_sysctl_write(table
);
2080 * proc_dostring - read a string sysctl
2081 * @table: the sysctl table
2082 * @write: %TRUE if this is a write to the sysctl file
2083 * @buffer: the user buffer
2084 * @lenp: the size of the user buffer
2085 * @ppos: file position
2087 * Reads/writes a string from/to the user buffer. If the kernel
2088 * buffer provided is not large enough to hold the string, the
2089 * string is truncated. The copied string is %NULL-terminated.
2090 * If the string is being read by the user process, it is copied
2091 * and a newline '\n' is added. It is truncated if the buffer is
2094 * Returns 0 on success.
2096 int proc_dostring(struct ctl_table
*table
, int write
,
2097 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2100 proc_first_pos_non_zero_ignore(ppos
, table
);
2102 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2103 (char __user
*)buffer
, lenp
, ppos
);
2106 static size_t proc_skip_spaces(char **buf
)
2109 char *tmp
= skip_spaces(*buf
);
2115 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2126 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2129 * @cp: kernel buffer containing the string to parse
2130 * @endp: pointer to store the trailing characters
2131 * @base: the base to use
2132 * @res: where the parsed integer will be stored
2134 * In case of success 0 is returned and @res will contain the parsed integer,
2135 * @endp will hold any trailing characters.
2136 * This function will fail the parse on overflow. If there wasn't an overflow
2137 * the function will defer the decision what characters count as invalid to the
2140 static int strtoul_lenient(const char *cp
, char **endp
, unsigned int base
,
2143 unsigned long long result
;
2146 cp
= _parse_integer_fixup_radix(cp
, &base
);
2147 rv
= _parse_integer(cp
, base
, &result
);
2148 if ((rv
& KSTRTOX_OVERFLOW
) || (result
!= (unsigned long)result
))
2156 *res
= (unsigned long)result
;
2160 #define TMPBUFLEN 22
2162 * proc_get_long - reads an ASCII formatted integer from a user buffer
2164 * @buf: a kernel buffer
2165 * @size: size of the kernel buffer
2166 * @val: this is where the number will be stored
2167 * @neg: set to %TRUE if number is negative
2168 * @perm_tr: a vector which contains the allowed trailers
2169 * @perm_tr_len: size of the perm_tr vector
2170 * @tr: pointer to store the trailer character
2172 * In case of success %0 is returned and @buf and @size are updated with
2173 * the amount of bytes read. If @tr is non-NULL and a trailing
2174 * character exists (size is non-zero after returning from this
2175 * function), @tr is updated with the trailing character.
2177 static int proc_get_long(char **buf
, size_t *size
,
2178 unsigned long *val
, bool *neg
,
2179 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2182 char *p
, tmp
[TMPBUFLEN
];
2188 if (len
> TMPBUFLEN
- 1)
2189 len
= TMPBUFLEN
- 1;
2191 memcpy(tmp
, *buf
, len
);
2195 if (*p
== '-' && *size
> 1) {
2203 if (strtoul_lenient(p
, &p
, 0, val
))
2208 /* We don't know if the next char is whitespace thus we may accept
2209 * invalid integers (e.g. 1234...a) or two integers instead of one
2210 * (e.g. 123...1). So lets not allow such large numbers. */
2211 if (len
== TMPBUFLEN
- 1)
2214 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2217 if (tr
&& (len
< *size
))
2227 * proc_put_long - converts an integer to a decimal ASCII formatted string
2229 * @buf: the user buffer
2230 * @size: the size of the user buffer
2231 * @val: the integer to be converted
2232 * @neg: sign of the number, %TRUE for negative
2234 * In case of success %0 is returned and @buf and @size are updated with
2235 * the amount of bytes written.
2237 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2241 char tmp
[TMPBUFLEN
], *p
= tmp
;
2243 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2247 if (copy_to_user(*buf
, tmp
, len
))
2255 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2258 char __user
**buffer
= (char __user
**)buf
;
2259 if (put_user(c
, *buffer
))
2261 (*size
)--, (*buffer
)++;
2267 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2269 int write
, void *data
)
2273 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2277 if (*lvalp
> (unsigned long) INT_MAX
)
2285 *lvalp
= -(unsigned long)val
;
2288 *lvalp
= (unsigned long)val
;
2294 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2296 int write
, void *data
)
2299 if (*lvalp
> UINT_MAX
)
2303 unsigned int val
= *valp
;
2304 *lvalp
= (unsigned long)val
;
2309 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2311 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2312 int write
, void __user
*buffer
,
2313 size_t *lenp
, loff_t
*ppos
,
2314 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2315 int write
, void *data
),
2318 int *i
, vleft
, first
= 1, err
= 0;
2320 char *kbuf
= NULL
, *p
;
2322 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2327 i
= (int *) tbl_data
;
2328 vleft
= table
->maxlen
/ sizeof(*i
);
2332 conv
= do_proc_dointvec_conv
;
2335 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2338 if (left
> PAGE_SIZE
- 1)
2339 left
= PAGE_SIZE
- 1;
2340 p
= kbuf
= memdup_user_nul(buffer
, left
);
2342 return PTR_ERR(kbuf
);
2345 for (; left
&& vleft
--; i
++, first
=0) {
2350 left
-= proc_skip_spaces(&p
);
2354 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2356 sizeof(proc_wspace_sep
), NULL
);
2359 if (conv(&neg
, &lval
, i
, 1, data
)) {
2364 if (conv(&neg
, &lval
, i
, 0, data
)) {
2369 err
= proc_put_char(&buffer
, &left
, '\t');
2372 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2378 if (!write
&& !first
&& left
&& !err
)
2379 err
= proc_put_char(&buffer
, &left
, '\n');
2380 if (write
&& !err
&& left
)
2381 left
-= proc_skip_spaces(&p
);
2385 return err
? : -EINVAL
;
2393 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2394 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2395 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2396 int write
, void *data
),
2399 return __do_proc_dointvec(table
->data
, table
, write
,
2400 buffer
, lenp
, ppos
, conv
, data
);
2403 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2404 struct ctl_table
*table
,
2405 void __user
*buffer
,
2406 size_t *lenp
, loff_t
*ppos
,
2407 int (*conv
)(unsigned long *lvalp
,
2409 int write
, void *data
),
2416 char *kbuf
= NULL
, *p
;
2420 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2423 if (left
> PAGE_SIZE
- 1)
2424 left
= PAGE_SIZE
- 1;
2426 p
= kbuf
= memdup_user_nul(buffer
, left
);
2430 left
-= proc_skip_spaces(&p
);
2436 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2438 sizeof(proc_wspace_sep
), NULL
);
2444 if (conv(&lval
, tbl_data
, 1, data
)) {
2450 left
-= proc_skip_spaces(&p
);
2459 /* This is in keeping with old __do_proc_dointvec() */
2465 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2466 size_t *lenp
, loff_t
*ppos
,
2467 int (*conv
)(unsigned long *lvalp
,
2469 int write
, void *data
),
2478 if (conv(&lval
, tbl_data
, 0, data
)) {
2483 err
= proc_put_long(&buffer
, &left
, lval
, false);
2487 err
= proc_put_char(&buffer
, &left
, '\n');
2496 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2497 int write
, void __user
*buffer
,
2498 size_t *lenp
, loff_t
*ppos
,
2499 int (*conv
)(unsigned long *lvalp
,
2501 int write
, void *data
),
2504 unsigned int *i
, vleft
;
2506 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2511 i
= (unsigned int *) tbl_data
;
2512 vleft
= table
->maxlen
/ sizeof(*i
);
2515 * Arrays are not supported, keep this simple. *Do not* add
2524 conv
= do_proc_douintvec_conv
;
2527 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2529 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2532 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2533 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2534 int (*conv
)(unsigned long *lvalp
,
2536 int write
, void *data
),
2539 return __do_proc_douintvec(table
->data
, table
, write
,
2540 buffer
, lenp
, ppos
, conv
, data
);
2544 * proc_dointvec - read a vector of integers
2545 * @table: the sysctl table
2546 * @write: %TRUE if this is a write to the sysctl file
2547 * @buffer: the user buffer
2548 * @lenp: the size of the user buffer
2549 * @ppos: file position
2551 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2552 * values from/to the user buffer, treated as an ASCII string.
2554 * Returns 0 on success.
2556 int proc_dointvec(struct ctl_table
*table
, int write
,
2557 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2559 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2563 * proc_douintvec - read a vector of unsigned integers
2564 * @table: the sysctl table
2565 * @write: %TRUE if this is a write to the sysctl file
2566 * @buffer: the user buffer
2567 * @lenp: the size of the user buffer
2568 * @ppos: file position
2570 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2571 * values from/to the user buffer, treated as an ASCII string.
2573 * Returns 0 on success.
2575 int proc_douintvec(struct ctl_table
*table
, int write
,
2576 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2578 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2579 do_proc_douintvec_conv
, NULL
);
2583 * Taint values can only be increased
2584 * This means we can safely use a temporary.
2586 static int proc_taint(struct ctl_table
*table
, int write
,
2587 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2590 unsigned long tmptaint
= get_taint();
2593 if (write
&& !capable(CAP_SYS_ADMIN
))
2598 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2604 * Poor man's atomic or. Not worth adding a primitive
2605 * to everyone's atomic.h for this
2608 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2609 if ((tmptaint
>> i
) & 1)
2610 add_taint(i
, LOCKDEP_STILL_OK
);
2617 #ifdef CONFIG_PRINTK
2618 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2619 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2621 if (write
&& !capable(CAP_SYS_ADMIN
))
2624 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2629 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2630 * @min: pointer to minimum allowable value
2631 * @max: pointer to maximum allowable value
2633 * The do_proc_dointvec_minmax_conv_param structure provides the
2634 * minimum and maximum values for doing range checking for those sysctl
2635 * parameters that use the proc_dointvec_minmax() handler.
2637 struct do_proc_dointvec_minmax_conv_param
{
2642 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2644 int write
, void *data
)
2647 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2649 * If writing, first do so via a temporary local int so we can
2650 * bounds-check it before touching *valp.
2652 int *ip
= write
? &tmp
: valp
;
2654 ret
= do_proc_dointvec_conv(negp
, lvalp
, ip
, write
, data
);
2659 if ((param
->min
&& *param
->min
> tmp
) ||
2660 (param
->max
&& *param
->max
< tmp
))
2669 * proc_dointvec_minmax - read a vector of integers with min/max values
2670 * @table: the sysctl table
2671 * @write: %TRUE if this is a write to the sysctl file
2672 * @buffer: the user buffer
2673 * @lenp: the size of the user buffer
2674 * @ppos: file position
2676 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2677 * values from/to the user buffer, treated as an ASCII string.
2679 * This routine will ensure the values are within the range specified by
2680 * table->extra1 (min) and table->extra2 (max).
2682 * Returns 0 on success or -EINVAL on write when the range check fails.
2684 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2685 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2687 struct do_proc_dointvec_minmax_conv_param param
= {
2688 .min
= (int *) table
->extra1
,
2689 .max
= (int *) table
->extra2
,
2691 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2692 do_proc_dointvec_minmax_conv
, ¶m
);
2696 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2697 * @min: pointer to minimum allowable value
2698 * @max: pointer to maximum allowable value
2700 * The do_proc_douintvec_minmax_conv_param structure provides the
2701 * minimum and maximum values for doing range checking for those sysctl
2702 * parameters that use the proc_douintvec_minmax() handler.
2704 struct do_proc_douintvec_minmax_conv_param
{
2709 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp
,
2711 int write
, void *data
)
2715 struct do_proc_douintvec_minmax_conv_param
*param
= data
;
2716 /* write via temporary local uint for bounds-checking */
2717 unsigned int *up
= write
? &tmp
: valp
;
2719 ret
= do_proc_douintvec_conv(lvalp
, up
, write
, data
);
2724 if ((param
->min
&& *param
->min
> tmp
) ||
2725 (param
->max
&& *param
->max
< tmp
))
2735 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2736 * @table: the sysctl table
2737 * @write: %TRUE if this is a write to the sysctl file
2738 * @buffer: the user buffer
2739 * @lenp: the size of the user buffer
2740 * @ppos: file position
2742 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2743 * values from/to the user buffer, treated as an ASCII string. Negative
2744 * strings are not allowed.
2746 * This routine will ensure the values are within the range specified by
2747 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2748 * check for UINT_MAX to avoid having to support wrap around uses from
2751 * Returns 0 on success or -ERANGE on write when the range check fails.
2753 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
2754 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2756 struct do_proc_douintvec_minmax_conv_param param
= {
2757 .min
= (unsigned int *) table
->extra1
,
2758 .max
= (unsigned int *) table
->extra2
,
2760 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2761 do_proc_douintvec_minmax_conv
, ¶m
);
2764 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp
,
2766 int write
, void *data
)
2771 val
= round_pipe_size(*lvalp
);
2777 unsigned int val
= *valp
;
2778 *lvalp
= (unsigned long) val
;
2784 static int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
2785 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2787 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2788 do_proc_dopipe_max_size_conv
, NULL
);
2791 static void validate_coredump_safety(void)
2793 #ifdef CONFIG_COREDUMP
2794 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2795 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2797 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2798 "Pipe handler or fully qualified core dump path required.\n"
2799 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2805 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2806 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2808 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2810 validate_coredump_safety();
2814 #ifdef CONFIG_COREDUMP
2815 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2816 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2818 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2820 validate_coredump_safety();
2825 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2826 void __user
*buffer
,
2827 size_t *lenp
, loff_t
*ppos
,
2828 unsigned long convmul
,
2829 unsigned long convdiv
)
2831 unsigned long *i
, *min
, *max
;
2832 int vleft
, first
= 1, err
= 0;
2834 char *kbuf
= NULL
, *p
;
2836 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2841 i
= (unsigned long *) data
;
2842 min
= (unsigned long *) table
->extra1
;
2843 max
= (unsigned long *) table
->extra2
;
2844 vleft
= table
->maxlen
/ sizeof(unsigned long);
2848 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2851 if (left
> PAGE_SIZE
- 1)
2852 left
= PAGE_SIZE
- 1;
2853 p
= kbuf
= memdup_user_nul(buffer
, left
);
2855 return PTR_ERR(kbuf
);
2858 for (; left
&& vleft
--; i
++, first
= 0) {
2864 left
-= proc_skip_spaces(&p
);
2868 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2870 sizeof(proc_wspace_sep
), NULL
);
2875 val
= convmul
* val
/ convdiv
;
2876 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2880 val
= convdiv
* (*i
) / convmul
;
2882 err
= proc_put_char(&buffer
, &left
, '\t');
2886 err
= proc_put_long(&buffer
, &left
, val
, false);
2892 if (!write
&& !first
&& left
&& !err
)
2893 err
= proc_put_char(&buffer
, &left
, '\n');
2895 left
-= proc_skip_spaces(&p
);
2899 return err
? : -EINVAL
;
2907 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2908 void __user
*buffer
,
2909 size_t *lenp
, loff_t
*ppos
,
2910 unsigned long convmul
,
2911 unsigned long convdiv
)
2913 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2914 buffer
, lenp
, ppos
, convmul
, convdiv
);
2918 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2919 * @table: the sysctl table
2920 * @write: %TRUE if this is a write to the sysctl file
2921 * @buffer: the user buffer
2922 * @lenp: the size of the user buffer
2923 * @ppos: file position
2925 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2926 * values from/to the user buffer, treated as an ASCII string.
2928 * This routine will ensure the values are within the range specified by
2929 * table->extra1 (min) and table->extra2 (max).
2931 * Returns 0 on success.
2933 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2934 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2936 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2940 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2941 * @table: the sysctl table
2942 * @write: %TRUE if this is a write to the sysctl file
2943 * @buffer: the user buffer
2944 * @lenp: the size of the user buffer
2945 * @ppos: file position
2947 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2948 * values from/to the user buffer, treated as an ASCII string. The values
2949 * are treated as milliseconds, and converted to jiffies when they are stored.
2951 * This routine will ensure the values are within the range specified by
2952 * table->extra1 (min) and table->extra2 (max).
2954 * Returns 0 on success.
2956 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2957 void __user
*buffer
,
2958 size_t *lenp
, loff_t
*ppos
)
2960 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2961 lenp
, ppos
, HZ
, 1000l);
2965 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2967 int write
, void *data
)
2970 if (*lvalp
> INT_MAX
/ HZ
)
2972 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2978 lval
= -(unsigned long)val
;
2981 lval
= (unsigned long)val
;
2988 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2990 int write
, void *data
)
2993 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2995 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
3001 lval
= -(unsigned long)val
;
3004 lval
= (unsigned long)val
;
3006 *lvalp
= jiffies_to_clock_t(lval
);
3011 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
3013 int write
, void *data
)
3016 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
3026 lval
= -(unsigned long)val
;
3029 lval
= (unsigned long)val
;
3031 *lvalp
= jiffies_to_msecs(lval
);
3037 * proc_dointvec_jiffies - read a vector of integers as seconds
3038 * @table: the sysctl table
3039 * @write: %TRUE if this is a write to the sysctl file
3040 * @buffer: the user buffer
3041 * @lenp: the size of the user buffer
3042 * @ppos: file position
3044 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3045 * values from/to the user buffer, treated as an ASCII string.
3046 * The values read are assumed to be in seconds, and are converted into
3049 * Returns 0 on success.
3051 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3052 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3054 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
3055 do_proc_dointvec_jiffies_conv
,NULL
);
3059 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3060 * @table: the sysctl table
3061 * @write: %TRUE if this is a write to the sysctl file
3062 * @buffer: the user buffer
3063 * @lenp: the size of the user buffer
3064 * @ppos: pointer to the file position
3066 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3067 * values from/to the user buffer, treated as an ASCII string.
3068 * The values read are assumed to be in 1/USER_HZ seconds, and
3069 * are converted into jiffies.
3071 * Returns 0 on success.
3073 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3074 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3076 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
3077 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
3081 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3082 * @table: the sysctl table
3083 * @write: %TRUE if this is a write to the sysctl file
3084 * @buffer: the user buffer
3085 * @lenp: the size of the user buffer
3086 * @ppos: file position
3087 * @ppos: the current position in the file
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 1/1000 seconds, and
3092 * are converted into jiffies.
3094 * Returns 0 on success.
3096 int proc_dointvec_ms_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_ms_jiffies_conv
, NULL
);
3103 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
3104 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3106 struct pid
*new_pid
;
3110 tmp
= pid_vnr(cad_pid
);
3112 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
3113 lenp
, ppos
, NULL
, NULL
);
3117 new_pid
= find_get_pid(tmp
);
3121 put_pid(xchg(&cad_pid
, new_pid
));
3126 * proc_do_large_bitmap - read/write from/to a large bitmap
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
3133 * The bitmap is stored at table->data and the bitmap length (in bits)
3136 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3137 * large bitmaps may be represented in a compact manner. Writing into
3138 * the file will clear the bitmap then update it with the given input.
3140 * Returns 0 on success.
3142 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3143 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3147 size_t left
= *lenp
;
3148 unsigned long bitmap_len
= table
->maxlen
;
3149 unsigned long *bitmap
= *(unsigned long **) table
->data
;
3150 unsigned long *tmp_bitmap
= NULL
;
3151 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
3153 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3161 if (left
> PAGE_SIZE
- 1)
3162 left
= PAGE_SIZE
- 1;
3164 p
= kbuf
= memdup_user_nul(buffer
, left
);
3166 return PTR_ERR(kbuf
);
3168 tmp_bitmap
= kcalloc(BITS_TO_LONGS(bitmap_len
),
3169 sizeof(unsigned long),
3175 proc_skip_char(&p
, &left
, '\n');
3176 while (!err
&& left
) {
3177 unsigned long val_a
, val_b
;
3180 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3184 if (val_a
>= bitmap_len
|| neg
) {
3196 err
= proc_get_long(&p
, &left
, &val_b
,
3197 &neg
, tr_b
, sizeof(tr_b
),
3201 if (val_b
>= bitmap_len
|| neg
||
3212 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3214 proc_skip_char(&p
, &left
, '\n');
3218 unsigned long bit_a
, bit_b
= 0;
3221 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3222 if (bit_a
>= bitmap_len
)
3224 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3228 err
= proc_put_char(&buffer
, &left
, ',');
3232 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3235 if (bit_a
!= bit_b
) {
3236 err
= proc_put_char(&buffer
, &left
, '-');
3239 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3247 err
= proc_put_char(&buffer
, &left
, '\n');
3253 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3255 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3265 #else /* CONFIG_PROC_SYSCTL */
3267 int proc_dostring(struct ctl_table
*table
, int write
,
3268 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3273 int proc_dointvec(struct ctl_table
*table
, int write
,
3274 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3279 int proc_douintvec(struct ctl_table
*table
, int write
,
3280 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3285 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3286 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3291 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3292 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3297 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3298 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3303 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3304 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3309 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3310 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3315 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3316 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3321 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3322 void __user
*buffer
,
3323 size_t *lenp
, loff_t
*ppos
)
3329 #endif /* CONFIG_PROC_SYSCTL */
3331 #if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL)
3332 static int proc_dointvec_minmax_bpf_stats(struct ctl_table
*table
, int write
,
3333 void __user
*buffer
, size_t *lenp
,
3336 int ret
, bpf_stats
= *(int *)table
->data
;
3337 struct ctl_table tmp
= *table
;
3339 if (write
&& !capable(CAP_SYS_ADMIN
))
3342 tmp
.data
= &bpf_stats
;
3343 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
3344 if (write
&& !ret
) {
3345 *(int *)table
->data
= bpf_stats
;
3347 static_branch_enable(&bpf_stats_enabled_key
);
3349 static_branch_disable(&bpf_stats_enabled_key
);
3355 * No sense putting this after each symbol definition, twice,
3356 * exception granted :-)
3358 EXPORT_SYMBOL(proc_dointvec
);
3359 EXPORT_SYMBOL(proc_douintvec
);
3360 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3361 EXPORT_SYMBOL(proc_dointvec_minmax
);
3362 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3363 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3364 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3365 EXPORT_SYMBOL(proc_dostring
);
3366 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3367 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);