1 // SPDX-License-Identifier: GPL-2.0-only
3 * sysctl.c: General linux system control interface
5 * Begun 24 March 1995, Stephen Tweedie
6 * Added /proc support, Dec 1995
7 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
8 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
9 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
10 * Dynamic registration fixes, Stephen Tweedie.
11 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
12 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
14 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
15 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
16 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
18 * The list_for_each() macro wasn't appropriate for the sysctl loop.
19 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
22 #include <linux/module.h>
23 #include <linux/aio.h>
25 #include <linux/swap.h>
26 #include <linux/slab.h>
27 #include <linux/sysctl.h>
28 #include <linux/bitmap.h>
29 #include <linux/signal.h>
30 #include <linux/printk.h>
31 #include <linux/proc_fs.h>
32 #include <linux/security.h>
33 #include <linux/ctype.h>
34 #include <linux/kmemleak.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/kobject.h>
39 #include <linux/net.h>
40 #include <linux/sysrq.h>
41 #include <linux/highuid.h>
42 #include <linux/writeback.h>
43 #include <linux/ratelimit.h>
44 #include <linux/compaction.h>
45 #include <linux/hugetlb.h>
46 #include <linux/initrd.h>
47 #include <linux/key.h>
48 #include <linux/times.h>
49 #include <linux/limits.h>
50 #include <linux/dcache.h>
51 #include <linux/dnotify.h>
52 #include <linux/syscalls.h>
53 #include <linux/vmstat.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/acpi.h>
56 #include <linux/reboot.h>
57 #include <linux/ftrace.h>
58 #include <linux/perf_event.h>
59 #include <linux/kprobes.h>
60 #include <linux/pipe_fs_i.h>
61 #include <linux/oom.h>
62 #include <linux/kmod.h>
63 #include <linux/capability.h>
64 #include <linux/binfmts.h>
65 #include <linux/sched/sysctl.h>
66 #include <linux/sched/coredump.h>
67 #include <linux/kexec.h>
68 #include <linux/bpf.h>
69 #include <linux/mount.h>
70 #include <linux/userfaultfd_k.h>
72 #include "../lib/kstrtox.h"
74 #include <linux/uaccess.h>
75 #include <asm/processor.h>
79 #include <asm/stacktrace.h>
83 #include <asm/setup.h>
85 #ifdef CONFIG_BSD_PROCESS_ACCT
86 #include <linux/acct.h>
88 #ifdef CONFIG_RT_MUTEXES
89 #include <linux/rtmutex.h>
91 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
92 #include <linux/lockdep.h>
94 #ifdef CONFIG_CHR_DEV_SG
97 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
98 #include <linux/stackleak.h>
100 #ifdef CONFIG_LOCKUP_DETECTOR
101 #include <linux/nmi.h>
104 #if defined(CONFIG_SYSCTL)
106 /* External variables not in a header file. */
107 extern int suid_dumpable
;
108 #ifdef CONFIG_COREDUMP
109 extern int core_uses_pid
;
110 extern char core_pattern
[];
111 extern unsigned int core_pipe_limit
;
114 extern int pid_max_min
, pid_max_max
;
115 extern int percpu_pagelist_fraction
;
116 extern int latencytop_enabled
;
117 extern unsigned int sysctl_nr_open_min
, sysctl_nr_open_max
;
119 extern int sysctl_nr_trim_pages
;
122 /* Constants used for minimum and maximum */
123 #ifdef CONFIG_LOCKUP_DETECTOR
124 static int sixty
= 60;
127 static int __maybe_unused neg_one
= -1;
130 static int __maybe_unused one
= 1;
131 static int __maybe_unused two
= 2;
132 static int __maybe_unused four
= 4;
133 static unsigned long zero_ul
;
134 static unsigned long one_ul
= 1;
135 static unsigned long long_max
= LONG_MAX
;
136 static int one_hundred
= 100;
137 static int one_thousand
= 1000;
139 static int ten_thousand
= 10000;
141 #ifdef CONFIG_PERF_EVENTS
142 static int six_hundred_forty_kb
= 640 * 1024;
145 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
146 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
148 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
149 static int maxolduid
= 65535;
150 static int minolduid
;
152 static int ngroups_max
= NGROUPS_MAX
;
153 static const int cap_last_cap
= CAP_LAST_CAP
;
156 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
157 * and hung_task_check_interval_secs
159 #ifdef CONFIG_DETECT_HUNG_TASK
160 static unsigned long hung_task_timeout_max
= (LONG_MAX
/HZ
);
163 #ifdef CONFIG_INOTIFY_USER
164 #include <linux/inotify.h>
170 extern int pwrsw_enabled
;
173 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
174 extern int unaligned_enabled
;
178 extern int unaligned_dump_stack
;
181 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
182 extern int no_unaligned_warning
;
185 #ifdef CONFIG_PROC_SYSCTL
188 * enum sysctl_writes_mode - supported sysctl write modes
190 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
191 * to be written, and multiple writes on the same sysctl file descriptor
192 * will rewrite the sysctl value, regardless of file position. No warning
193 * is issued when the initial position is not 0.
194 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
196 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
197 * file position 0 and the value must be fully contained in the buffer
198 * sent to the write syscall. If dealing with strings respect the file
199 * position, but restrict this to the max length of the buffer, anything
200 * passed the max lenght will be ignored. Multiple writes will append
203 * These write modes control how current file position affects the behavior of
204 * updating sysctl values through the proc interface on each write.
206 enum sysctl_writes_mode
{
207 SYSCTL_WRITES_LEGACY
= -1,
208 SYSCTL_WRITES_WARN
= 0,
209 SYSCTL_WRITES_STRICT
= 1,
212 static enum sysctl_writes_mode sysctl_writes_strict
= SYSCTL_WRITES_STRICT
;
214 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
215 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
216 static int proc_taint(struct ctl_table
*table
, int write
,
217 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
221 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
222 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
225 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
226 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
227 #ifdef CONFIG_COREDUMP
228 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
229 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
231 static int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
232 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
234 #ifdef CONFIG_MAGIC_SYSRQ
235 /* Note: sysrq code uses its own private copy */
236 static int __sysrq_enabled
= CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE
;
238 static int sysrq_sysctl_handler(struct ctl_table
*table
, int write
,
239 void __user
*buffer
, size_t *lenp
,
244 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
249 sysrq_toggle_support(__sysrq_enabled
);
256 static struct ctl_table kern_table
[];
257 static struct ctl_table vm_table
[];
258 static struct ctl_table fs_table
[];
259 static struct ctl_table debug_table
[];
260 static struct ctl_table dev_table
[];
261 extern struct ctl_table random_table
[];
263 extern struct ctl_table epoll_table
[];
266 #ifdef CONFIG_FW_LOADER_USER_HELPER
267 extern struct ctl_table firmware_config_table
[];
270 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
271 int sysctl_legacy_va_layout
;
274 /* The default sysctl tables: */
276 static struct ctl_table sysctl_base_table
[] = {
278 .procname
= "kernel",
295 .child
= debug_table
,
305 #ifdef CONFIG_SCHED_DEBUG
306 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
307 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
308 static int min_wakeup_granularity_ns
; /* 0 usecs */
309 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
311 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
312 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
313 #endif /* CONFIG_SMP */
314 #endif /* CONFIG_SCHED_DEBUG */
316 #ifdef CONFIG_COMPACTION
317 static int min_extfrag_threshold
;
318 static int max_extfrag_threshold
= 1000;
321 static struct ctl_table kern_table
[] = {
323 .procname
= "sched_child_runs_first",
324 .data
= &sysctl_sched_child_runs_first
,
325 .maxlen
= sizeof(unsigned int),
327 .proc_handler
= proc_dointvec
,
329 #ifdef CONFIG_SCHED_DEBUG
331 .procname
= "sched_min_granularity_ns",
332 .data
= &sysctl_sched_min_granularity
,
333 .maxlen
= sizeof(unsigned int),
335 .proc_handler
= sched_proc_update_handler
,
336 .extra1
= &min_sched_granularity_ns
,
337 .extra2
= &max_sched_granularity_ns
,
340 .procname
= "sched_latency_ns",
341 .data
= &sysctl_sched_latency
,
342 .maxlen
= sizeof(unsigned int),
344 .proc_handler
= sched_proc_update_handler
,
345 .extra1
= &min_sched_granularity_ns
,
346 .extra2
= &max_sched_granularity_ns
,
349 .procname
= "sched_wakeup_granularity_ns",
350 .data
= &sysctl_sched_wakeup_granularity
,
351 .maxlen
= sizeof(unsigned int),
353 .proc_handler
= sched_proc_update_handler
,
354 .extra1
= &min_wakeup_granularity_ns
,
355 .extra2
= &max_wakeup_granularity_ns
,
359 .procname
= "sched_tunable_scaling",
360 .data
= &sysctl_sched_tunable_scaling
,
361 .maxlen
= sizeof(enum sched_tunable_scaling
),
363 .proc_handler
= sched_proc_update_handler
,
364 .extra1
= &min_sched_tunable_scaling
,
365 .extra2
= &max_sched_tunable_scaling
,
368 .procname
= "sched_migration_cost_ns",
369 .data
= &sysctl_sched_migration_cost
,
370 .maxlen
= sizeof(unsigned int),
372 .proc_handler
= proc_dointvec
,
375 .procname
= "sched_nr_migrate",
376 .data
= &sysctl_sched_nr_migrate
,
377 .maxlen
= sizeof(unsigned int),
379 .proc_handler
= proc_dointvec
,
381 #ifdef CONFIG_SCHEDSTATS
383 .procname
= "sched_schedstats",
385 .maxlen
= sizeof(unsigned int),
387 .proc_handler
= sysctl_schedstats
,
391 #endif /* CONFIG_SCHEDSTATS */
392 #endif /* CONFIG_SMP */
393 #ifdef CONFIG_NUMA_BALANCING
395 .procname
= "numa_balancing_scan_delay_ms",
396 .data
= &sysctl_numa_balancing_scan_delay
,
397 .maxlen
= sizeof(unsigned int),
399 .proc_handler
= proc_dointvec
,
402 .procname
= "numa_balancing_scan_period_min_ms",
403 .data
= &sysctl_numa_balancing_scan_period_min
,
404 .maxlen
= sizeof(unsigned int),
406 .proc_handler
= proc_dointvec
,
409 .procname
= "numa_balancing_scan_period_max_ms",
410 .data
= &sysctl_numa_balancing_scan_period_max
,
411 .maxlen
= sizeof(unsigned int),
413 .proc_handler
= proc_dointvec
,
416 .procname
= "numa_balancing_scan_size_mb",
417 .data
= &sysctl_numa_balancing_scan_size
,
418 .maxlen
= sizeof(unsigned int),
420 .proc_handler
= proc_dointvec_minmax
,
424 .procname
= "numa_balancing",
425 .data
= NULL
, /* filled in by handler */
426 .maxlen
= sizeof(unsigned int),
428 .proc_handler
= sysctl_numa_balancing
,
432 #endif /* CONFIG_NUMA_BALANCING */
433 #endif /* CONFIG_SCHED_DEBUG */
435 .procname
= "sched_rt_period_us",
436 .data
= &sysctl_sched_rt_period
,
437 .maxlen
= sizeof(unsigned int),
439 .proc_handler
= sched_rt_handler
,
442 .procname
= "sched_rt_runtime_us",
443 .data
= &sysctl_sched_rt_runtime
,
444 .maxlen
= sizeof(int),
446 .proc_handler
= sched_rt_handler
,
449 .procname
= "sched_rr_timeslice_ms",
450 .data
= &sysctl_sched_rr_timeslice
,
451 .maxlen
= sizeof(int),
453 .proc_handler
= sched_rr_handler
,
455 #ifdef CONFIG_SCHED_AUTOGROUP
457 .procname
= "sched_autogroup_enabled",
458 .data
= &sysctl_sched_autogroup_enabled
,
459 .maxlen
= sizeof(unsigned int),
461 .proc_handler
= proc_dointvec_minmax
,
466 #ifdef CONFIG_CFS_BANDWIDTH
468 .procname
= "sched_cfs_bandwidth_slice_us",
469 .data
= &sysctl_sched_cfs_bandwidth_slice
,
470 .maxlen
= sizeof(unsigned int),
472 .proc_handler
= proc_dointvec_minmax
,
476 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
478 .procname
= "sched_energy_aware",
479 .data
= &sysctl_sched_energy_aware
,
480 .maxlen
= sizeof(unsigned int),
482 .proc_handler
= sched_energy_aware_handler
,
487 #ifdef CONFIG_PROVE_LOCKING
489 .procname
= "prove_locking",
490 .data
= &prove_locking
,
491 .maxlen
= sizeof(int),
493 .proc_handler
= proc_dointvec
,
496 #ifdef CONFIG_LOCK_STAT
498 .procname
= "lock_stat",
500 .maxlen
= sizeof(int),
502 .proc_handler
= proc_dointvec
,
507 .data
= &panic_timeout
,
508 .maxlen
= sizeof(int),
510 .proc_handler
= proc_dointvec
,
512 #ifdef CONFIG_COREDUMP
514 .procname
= "core_uses_pid",
515 .data
= &core_uses_pid
,
516 .maxlen
= sizeof(int),
518 .proc_handler
= proc_dointvec
,
521 .procname
= "core_pattern",
522 .data
= core_pattern
,
523 .maxlen
= CORENAME_MAX_SIZE
,
525 .proc_handler
= proc_dostring_coredump
,
528 .procname
= "core_pipe_limit",
529 .data
= &core_pipe_limit
,
530 .maxlen
= sizeof(unsigned int),
532 .proc_handler
= proc_dointvec
,
535 #ifdef CONFIG_PROC_SYSCTL
537 .procname
= "tainted",
538 .maxlen
= sizeof(long),
540 .proc_handler
= proc_taint
,
543 .procname
= "sysctl_writes_strict",
544 .data
= &sysctl_writes_strict
,
545 .maxlen
= sizeof(int),
547 .proc_handler
= proc_dointvec_minmax
,
552 #ifdef CONFIG_LATENCYTOP
554 .procname
= "latencytop",
555 .data
= &latencytop_enabled
,
556 .maxlen
= sizeof(int),
558 .proc_handler
= sysctl_latencytop
,
561 #ifdef CONFIG_BLK_DEV_INITRD
563 .procname
= "real-root-dev",
564 .data
= &real_root_dev
,
565 .maxlen
= sizeof(int),
567 .proc_handler
= proc_dointvec
,
571 .procname
= "print-fatal-signals",
572 .data
= &print_fatal_signals
,
573 .maxlen
= sizeof(int),
575 .proc_handler
= proc_dointvec
,
579 .procname
= "reboot-cmd",
580 .data
= reboot_command
,
583 .proc_handler
= proc_dostring
,
586 .procname
= "stop-a",
587 .data
= &stop_a_enabled
,
588 .maxlen
= sizeof (int),
590 .proc_handler
= proc_dointvec
,
593 .procname
= "scons-poweroff",
594 .data
= &scons_pwroff
,
595 .maxlen
= sizeof (int),
597 .proc_handler
= proc_dointvec
,
600 #ifdef CONFIG_SPARC64
602 .procname
= "tsb-ratio",
603 .data
= &sysctl_tsb_ratio
,
604 .maxlen
= sizeof (int),
606 .proc_handler
= proc_dointvec
,
611 .procname
= "soft-power",
612 .data
= &pwrsw_enabled
,
613 .maxlen
= sizeof (int),
615 .proc_handler
= proc_dointvec
,
618 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
620 .procname
= "unaligned-trap",
621 .data
= &unaligned_enabled
,
622 .maxlen
= sizeof (int),
624 .proc_handler
= proc_dointvec
,
628 .procname
= "ctrl-alt-del",
630 .maxlen
= sizeof(int),
632 .proc_handler
= proc_dointvec
,
634 #ifdef CONFIG_FUNCTION_TRACER
636 .procname
= "ftrace_enabled",
637 .data
= &ftrace_enabled
,
638 .maxlen
= sizeof(int),
640 .proc_handler
= ftrace_enable_sysctl
,
643 #ifdef CONFIG_STACK_TRACER
645 .procname
= "stack_tracer_enabled",
646 .data
= &stack_tracer_enabled
,
647 .maxlen
= sizeof(int),
649 .proc_handler
= stack_trace_sysctl
,
652 #ifdef CONFIG_TRACING
654 .procname
= "ftrace_dump_on_oops",
655 .data
= &ftrace_dump_on_oops
,
656 .maxlen
= sizeof(int),
658 .proc_handler
= proc_dointvec
,
661 .procname
= "traceoff_on_warning",
662 .data
= &__disable_trace_on_warning
,
663 .maxlen
= sizeof(__disable_trace_on_warning
),
665 .proc_handler
= proc_dointvec
,
668 .procname
= "tracepoint_printk",
669 .data
= &tracepoint_printk
,
670 .maxlen
= sizeof(tracepoint_printk
),
672 .proc_handler
= tracepoint_printk_sysctl
,
675 #ifdef CONFIG_KEXEC_CORE
677 .procname
= "kexec_load_disabled",
678 .data
= &kexec_load_disabled
,
679 .maxlen
= sizeof(int),
681 /* only handle a transition from default "0" to "1" */
682 .proc_handler
= proc_dointvec_minmax
,
687 #ifdef CONFIG_MODULES
689 .procname
= "modprobe",
690 .data
= &modprobe_path
,
691 .maxlen
= KMOD_PATH_LEN
,
693 .proc_handler
= proc_dostring
,
696 .procname
= "modules_disabled",
697 .data
= &modules_disabled
,
698 .maxlen
= sizeof(int),
700 /* only handle a transition from default "0" to "1" */
701 .proc_handler
= proc_dointvec_minmax
,
706 #ifdef CONFIG_UEVENT_HELPER
708 .procname
= "hotplug",
709 .data
= &uevent_helper
,
710 .maxlen
= UEVENT_HELPER_PATH_LEN
,
712 .proc_handler
= proc_dostring
,
715 #ifdef CONFIG_CHR_DEV_SG
717 .procname
= "sg-big-buff",
718 .data
= &sg_big_buff
,
719 .maxlen
= sizeof (int),
721 .proc_handler
= proc_dointvec
,
724 #ifdef CONFIG_BSD_PROCESS_ACCT
728 .maxlen
= 3*sizeof(int),
730 .proc_handler
= proc_dointvec
,
733 #ifdef CONFIG_MAGIC_SYSRQ
736 .data
= &__sysrq_enabled
,
737 .maxlen
= sizeof (int),
739 .proc_handler
= sysrq_sysctl_handler
,
742 #ifdef CONFIG_PROC_SYSCTL
744 .procname
= "cad_pid",
746 .maxlen
= sizeof (int),
748 .proc_handler
= proc_do_cad_pid
,
752 .procname
= "threads-max",
754 .maxlen
= sizeof(int),
756 .proc_handler
= sysctl_max_threads
,
759 .procname
= "random",
761 .child
= random_table
,
764 .procname
= "usermodehelper",
766 .child
= usermodehelper_table
,
768 #ifdef CONFIG_FW_LOADER_USER_HELPER
770 .procname
= "firmware_config",
772 .child
= firmware_config_table
,
776 .procname
= "overflowuid",
777 .data
= &overflowuid
,
778 .maxlen
= sizeof(int),
780 .proc_handler
= proc_dointvec_minmax
,
781 .extra1
= &minolduid
,
782 .extra2
= &maxolduid
,
785 .procname
= "overflowgid",
786 .data
= &overflowgid
,
787 .maxlen
= sizeof(int),
789 .proc_handler
= proc_dointvec_minmax
,
790 .extra1
= &minolduid
,
791 .extra2
= &maxolduid
,
794 #ifdef CONFIG_MATHEMU
796 .procname
= "ieee_emulation_warnings",
797 .data
= &sysctl_ieee_emulation_warnings
,
798 .maxlen
= sizeof(int),
800 .proc_handler
= proc_dointvec
,
804 .procname
= "userprocess_debug",
805 .data
= &show_unhandled_signals
,
806 .maxlen
= sizeof(int),
808 .proc_handler
= proc_dointvec
,
812 .procname
= "pid_max",
814 .maxlen
= sizeof (int),
816 .proc_handler
= proc_dointvec_minmax
,
817 .extra1
= &pid_max_min
,
818 .extra2
= &pid_max_max
,
821 .procname
= "panic_on_oops",
822 .data
= &panic_on_oops
,
823 .maxlen
= sizeof(int),
825 .proc_handler
= proc_dointvec
,
828 .procname
= "panic_print",
829 .data
= &panic_print
,
830 .maxlen
= sizeof(unsigned long),
832 .proc_handler
= proc_doulongvec_minmax
,
834 #if defined CONFIG_PRINTK
836 .procname
= "printk",
837 .data
= &console_loglevel
,
838 .maxlen
= 4*sizeof(int),
840 .proc_handler
= proc_dointvec
,
843 .procname
= "printk_ratelimit",
844 .data
= &printk_ratelimit_state
.interval
,
845 .maxlen
= sizeof(int),
847 .proc_handler
= proc_dointvec_jiffies
,
850 .procname
= "printk_ratelimit_burst",
851 .data
= &printk_ratelimit_state
.burst
,
852 .maxlen
= sizeof(int),
854 .proc_handler
= proc_dointvec
,
857 .procname
= "printk_delay",
858 .data
= &printk_delay_msec
,
859 .maxlen
= sizeof(int),
861 .proc_handler
= proc_dointvec_minmax
,
863 .extra2
= &ten_thousand
,
866 .procname
= "printk_devkmsg",
867 .data
= devkmsg_log_str
,
868 .maxlen
= DEVKMSG_STR_MAX_SIZE
,
870 .proc_handler
= devkmsg_sysctl_set_loglvl
,
873 .procname
= "dmesg_restrict",
874 .data
= &dmesg_restrict
,
875 .maxlen
= sizeof(int),
877 .proc_handler
= proc_dointvec_minmax_sysadmin
,
882 .procname
= "kptr_restrict",
883 .data
= &kptr_restrict
,
884 .maxlen
= sizeof(int),
886 .proc_handler
= proc_dointvec_minmax_sysadmin
,
892 .procname
= "ngroups_max",
893 .data
= &ngroups_max
,
894 .maxlen
= sizeof (int),
896 .proc_handler
= proc_dointvec
,
899 .procname
= "cap_last_cap",
900 .data
= (void *)&cap_last_cap
,
901 .maxlen
= sizeof(int),
903 .proc_handler
= proc_dointvec
,
905 #if defined(CONFIG_LOCKUP_DETECTOR)
907 .procname
= "watchdog",
908 .data
= &watchdog_user_enabled
,
909 .maxlen
= sizeof(int),
911 .proc_handler
= proc_watchdog
,
916 .procname
= "watchdog_thresh",
917 .data
= &watchdog_thresh
,
918 .maxlen
= sizeof(int),
920 .proc_handler
= proc_watchdog_thresh
,
925 .procname
= "nmi_watchdog",
926 .data
= &nmi_watchdog_user_enabled
,
927 .maxlen
= sizeof(int),
928 .mode
= NMI_WATCHDOG_SYSCTL_PERM
,
929 .proc_handler
= proc_nmi_watchdog
,
934 .procname
= "watchdog_cpumask",
935 .data
= &watchdog_cpumask_bits
,
938 .proc_handler
= proc_watchdog_cpumask
,
940 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
942 .procname
= "soft_watchdog",
943 .data
= &soft_watchdog_user_enabled
,
944 .maxlen
= sizeof(int),
946 .proc_handler
= proc_soft_watchdog
,
951 .procname
= "softlockup_panic",
952 .data
= &softlockup_panic
,
953 .maxlen
= sizeof(int),
955 .proc_handler
= proc_dointvec_minmax
,
961 .procname
= "softlockup_all_cpu_backtrace",
962 .data
= &sysctl_softlockup_all_cpu_backtrace
,
963 .maxlen
= sizeof(int),
965 .proc_handler
= proc_dointvec_minmax
,
969 #endif /* CONFIG_SMP */
971 #ifdef CONFIG_HARDLOCKUP_DETECTOR
973 .procname
= "hardlockup_panic",
974 .data
= &hardlockup_panic
,
975 .maxlen
= sizeof(int),
977 .proc_handler
= proc_dointvec_minmax
,
983 .procname
= "hardlockup_all_cpu_backtrace",
984 .data
= &sysctl_hardlockup_all_cpu_backtrace
,
985 .maxlen
= sizeof(int),
987 .proc_handler
= proc_dointvec_minmax
,
991 #endif /* CONFIG_SMP */
995 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
997 .procname
= "unknown_nmi_panic",
998 .data
= &unknown_nmi_panic
,
999 .maxlen
= sizeof (int),
1001 .proc_handler
= proc_dointvec
,
1004 #if defined(CONFIG_X86)
1006 .procname
= "panic_on_unrecovered_nmi",
1007 .data
= &panic_on_unrecovered_nmi
,
1008 .maxlen
= sizeof(int),
1010 .proc_handler
= proc_dointvec
,
1013 .procname
= "panic_on_io_nmi",
1014 .data
= &panic_on_io_nmi
,
1015 .maxlen
= sizeof(int),
1017 .proc_handler
= proc_dointvec
,
1019 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1021 .procname
= "panic_on_stackoverflow",
1022 .data
= &sysctl_panic_on_stackoverflow
,
1023 .maxlen
= sizeof(int),
1025 .proc_handler
= proc_dointvec
,
1029 .procname
= "bootloader_type",
1030 .data
= &bootloader_type
,
1031 .maxlen
= sizeof (int),
1033 .proc_handler
= proc_dointvec
,
1036 .procname
= "bootloader_version",
1037 .data
= &bootloader_version
,
1038 .maxlen
= sizeof (int),
1040 .proc_handler
= proc_dointvec
,
1043 .procname
= "io_delay_type",
1044 .data
= &io_delay_type
,
1045 .maxlen
= sizeof(int),
1047 .proc_handler
= proc_dointvec
,
1050 #if defined(CONFIG_MMU)
1052 .procname
= "randomize_va_space",
1053 .data
= &randomize_va_space
,
1054 .maxlen
= sizeof(int),
1056 .proc_handler
= proc_dointvec
,
1059 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1061 .procname
= "spin_retry",
1062 .data
= &spin_retry
,
1063 .maxlen
= sizeof (int),
1065 .proc_handler
= proc_dointvec
,
1068 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1070 .procname
= "acpi_video_flags",
1071 .data
= &acpi_realmode_flags
,
1072 .maxlen
= sizeof (unsigned long),
1074 .proc_handler
= proc_doulongvec_minmax
,
1077 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1079 .procname
= "ignore-unaligned-usertrap",
1080 .data
= &no_unaligned_warning
,
1081 .maxlen
= sizeof (int),
1083 .proc_handler
= proc_dointvec
,
1088 .procname
= "unaligned-dump-stack",
1089 .data
= &unaligned_dump_stack
,
1090 .maxlen
= sizeof (int),
1092 .proc_handler
= proc_dointvec
,
1095 #ifdef CONFIG_DETECT_HUNG_TASK
1097 .procname
= "hung_task_panic",
1098 .data
= &sysctl_hung_task_panic
,
1099 .maxlen
= sizeof(int),
1101 .proc_handler
= proc_dointvec_minmax
,
1106 .procname
= "hung_task_check_count",
1107 .data
= &sysctl_hung_task_check_count
,
1108 .maxlen
= sizeof(int),
1110 .proc_handler
= proc_dointvec_minmax
,
1114 .procname
= "hung_task_timeout_secs",
1115 .data
= &sysctl_hung_task_timeout_secs
,
1116 .maxlen
= sizeof(unsigned long),
1118 .proc_handler
= proc_dohung_task_timeout_secs
,
1119 .extra2
= &hung_task_timeout_max
,
1122 .procname
= "hung_task_check_interval_secs",
1123 .data
= &sysctl_hung_task_check_interval_secs
,
1124 .maxlen
= sizeof(unsigned long),
1126 .proc_handler
= proc_dohung_task_timeout_secs
,
1127 .extra2
= &hung_task_timeout_max
,
1130 .procname
= "hung_task_warnings",
1131 .data
= &sysctl_hung_task_warnings
,
1132 .maxlen
= sizeof(int),
1134 .proc_handler
= proc_dointvec_minmax
,
1138 #ifdef CONFIG_RT_MUTEXES
1140 .procname
= "max_lock_depth",
1141 .data
= &max_lock_depth
,
1142 .maxlen
= sizeof(int),
1144 .proc_handler
= proc_dointvec
,
1148 .procname
= "poweroff_cmd",
1149 .data
= &poweroff_cmd
,
1150 .maxlen
= POWEROFF_CMD_PATH_LEN
,
1152 .proc_handler
= proc_dostring
,
1158 .child
= key_sysctls
,
1161 #ifdef CONFIG_PERF_EVENTS
1163 * User-space scripts rely on the existence of this file
1164 * as a feature check for perf_events being enabled.
1166 * So it's an ABI, do not remove!
1169 .procname
= "perf_event_paranoid",
1170 .data
= &sysctl_perf_event_paranoid
,
1171 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
1173 .proc_handler
= proc_dointvec
,
1176 .procname
= "perf_event_mlock_kb",
1177 .data
= &sysctl_perf_event_mlock
,
1178 .maxlen
= sizeof(sysctl_perf_event_mlock
),
1180 .proc_handler
= proc_dointvec
,
1183 .procname
= "perf_event_max_sample_rate",
1184 .data
= &sysctl_perf_event_sample_rate
,
1185 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
1187 .proc_handler
= perf_proc_update_handler
,
1191 .procname
= "perf_cpu_time_max_percent",
1192 .data
= &sysctl_perf_cpu_time_max_percent
,
1193 .maxlen
= sizeof(sysctl_perf_cpu_time_max_percent
),
1195 .proc_handler
= perf_cpu_time_max_percent_handler
,
1197 .extra2
= &one_hundred
,
1200 .procname
= "perf_event_max_stack",
1201 .data
= &sysctl_perf_event_max_stack
,
1202 .maxlen
= sizeof(sysctl_perf_event_max_stack
),
1204 .proc_handler
= perf_event_max_stack_handler
,
1206 .extra2
= &six_hundred_forty_kb
,
1209 .procname
= "perf_event_max_contexts_per_stack",
1210 .data
= &sysctl_perf_event_max_contexts_per_stack
,
1211 .maxlen
= sizeof(sysctl_perf_event_max_contexts_per_stack
),
1213 .proc_handler
= perf_event_max_stack_handler
,
1215 .extra2
= &one_thousand
,
1219 .procname
= "panic_on_warn",
1220 .data
= &panic_on_warn
,
1221 .maxlen
= sizeof(int),
1223 .proc_handler
= proc_dointvec_minmax
,
1227 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1229 .procname
= "timer_migration",
1230 .data
= &sysctl_timer_migration
,
1231 .maxlen
= sizeof(unsigned int),
1233 .proc_handler
= timer_migration_handler
,
1238 #ifdef CONFIG_BPF_SYSCALL
1240 .procname
= "unprivileged_bpf_disabled",
1241 .data
= &sysctl_unprivileged_bpf_disabled
,
1242 .maxlen
= sizeof(sysctl_unprivileged_bpf_disabled
),
1244 /* only handle a transition from default "0" to "1" */
1245 .proc_handler
= proc_dointvec_minmax
,
1250 .procname
= "bpf_stats_enabled",
1251 .data
= &bpf_stats_enabled_key
.key
,
1252 .maxlen
= sizeof(bpf_stats_enabled_key
),
1254 .proc_handler
= proc_do_static_key
,
1257 #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1259 .procname
= "panic_on_rcu_stall",
1260 .data
= &sysctl_panic_on_rcu_stall
,
1261 .maxlen
= sizeof(sysctl_panic_on_rcu_stall
),
1263 .proc_handler
= proc_dointvec_minmax
,
1268 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1270 .procname
= "stack_erasing",
1272 .maxlen
= sizeof(int),
1274 .proc_handler
= stack_erasing_sysctl
,
1282 static struct ctl_table vm_table
[] = {
1284 .procname
= "overcommit_memory",
1285 .data
= &sysctl_overcommit_memory
,
1286 .maxlen
= sizeof(sysctl_overcommit_memory
),
1288 .proc_handler
= proc_dointvec_minmax
,
1293 .procname
= "panic_on_oom",
1294 .data
= &sysctl_panic_on_oom
,
1295 .maxlen
= sizeof(sysctl_panic_on_oom
),
1297 .proc_handler
= proc_dointvec_minmax
,
1302 .procname
= "oom_kill_allocating_task",
1303 .data
= &sysctl_oom_kill_allocating_task
,
1304 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
1306 .proc_handler
= proc_dointvec
,
1309 .procname
= "oom_dump_tasks",
1310 .data
= &sysctl_oom_dump_tasks
,
1311 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
1313 .proc_handler
= proc_dointvec
,
1316 .procname
= "overcommit_ratio",
1317 .data
= &sysctl_overcommit_ratio
,
1318 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1320 .proc_handler
= overcommit_ratio_handler
,
1323 .procname
= "overcommit_kbytes",
1324 .data
= &sysctl_overcommit_kbytes
,
1325 .maxlen
= sizeof(sysctl_overcommit_kbytes
),
1327 .proc_handler
= overcommit_kbytes_handler
,
1330 .procname
= "page-cluster",
1331 .data
= &page_cluster
,
1332 .maxlen
= sizeof(int),
1334 .proc_handler
= proc_dointvec_minmax
,
1338 .procname
= "dirty_background_ratio",
1339 .data
= &dirty_background_ratio
,
1340 .maxlen
= sizeof(dirty_background_ratio
),
1342 .proc_handler
= dirty_background_ratio_handler
,
1344 .extra2
= &one_hundred
,
1347 .procname
= "dirty_background_bytes",
1348 .data
= &dirty_background_bytes
,
1349 .maxlen
= sizeof(dirty_background_bytes
),
1351 .proc_handler
= dirty_background_bytes_handler
,
1355 .procname
= "dirty_ratio",
1356 .data
= &vm_dirty_ratio
,
1357 .maxlen
= sizeof(vm_dirty_ratio
),
1359 .proc_handler
= dirty_ratio_handler
,
1361 .extra2
= &one_hundred
,
1364 .procname
= "dirty_bytes",
1365 .data
= &vm_dirty_bytes
,
1366 .maxlen
= sizeof(vm_dirty_bytes
),
1368 .proc_handler
= dirty_bytes_handler
,
1369 .extra1
= &dirty_bytes_min
,
1372 .procname
= "dirty_writeback_centisecs",
1373 .data
= &dirty_writeback_interval
,
1374 .maxlen
= sizeof(dirty_writeback_interval
),
1376 .proc_handler
= dirty_writeback_centisecs_handler
,
1379 .procname
= "dirty_expire_centisecs",
1380 .data
= &dirty_expire_interval
,
1381 .maxlen
= sizeof(dirty_expire_interval
),
1383 .proc_handler
= proc_dointvec_minmax
,
1387 .procname
= "dirtytime_expire_seconds",
1388 .data
= &dirtytime_expire_interval
,
1389 .maxlen
= sizeof(dirtytime_expire_interval
),
1391 .proc_handler
= dirtytime_interval_handler
,
1395 .procname
= "swappiness",
1396 .data
= &vm_swappiness
,
1397 .maxlen
= sizeof(vm_swappiness
),
1399 .proc_handler
= proc_dointvec_minmax
,
1401 .extra2
= &one_hundred
,
1403 #ifdef CONFIG_HUGETLB_PAGE
1405 .procname
= "nr_hugepages",
1407 .maxlen
= sizeof(unsigned long),
1409 .proc_handler
= hugetlb_sysctl_handler
,
1413 .procname
= "nr_hugepages_mempolicy",
1415 .maxlen
= sizeof(unsigned long),
1417 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1420 .procname
= "numa_stat",
1421 .data
= &sysctl_vm_numa_stat
,
1422 .maxlen
= sizeof(int),
1424 .proc_handler
= sysctl_vm_numa_stat_handler
,
1430 .procname
= "hugetlb_shm_group",
1431 .data
= &sysctl_hugetlb_shm_group
,
1432 .maxlen
= sizeof(gid_t
),
1434 .proc_handler
= proc_dointvec
,
1437 .procname
= "nr_overcommit_hugepages",
1439 .maxlen
= sizeof(unsigned long),
1441 .proc_handler
= hugetlb_overcommit_handler
,
1445 .procname
= "lowmem_reserve_ratio",
1446 .data
= &sysctl_lowmem_reserve_ratio
,
1447 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1449 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1452 .procname
= "drop_caches",
1453 .data
= &sysctl_drop_caches
,
1454 .maxlen
= sizeof(int),
1456 .proc_handler
= drop_caches_sysctl_handler
,
1460 #ifdef CONFIG_COMPACTION
1462 .procname
= "compact_memory",
1463 .data
= &sysctl_compact_memory
,
1464 .maxlen
= sizeof(int),
1466 .proc_handler
= sysctl_compaction_handler
,
1469 .procname
= "extfrag_threshold",
1470 .data
= &sysctl_extfrag_threshold
,
1471 .maxlen
= sizeof(int),
1473 .proc_handler
= proc_dointvec_minmax
,
1474 .extra1
= &min_extfrag_threshold
,
1475 .extra2
= &max_extfrag_threshold
,
1478 .procname
= "compact_unevictable_allowed",
1479 .data
= &sysctl_compact_unevictable_allowed
,
1480 .maxlen
= sizeof(int),
1482 .proc_handler
= proc_dointvec
,
1487 #endif /* CONFIG_COMPACTION */
1489 .procname
= "min_free_kbytes",
1490 .data
= &min_free_kbytes
,
1491 .maxlen
= sizeof(min_free_kbytes
),
1493 .proc_handler
= min_free_kbytes_sysctl_handler
,
1497 .procname
= "watermark_boost_factor",
1498 .data
= &watermark_boost_factor
,
1499 .maxlen
= sizeof(watermark_boost_factor
),
1501 .proc_handler
= watermark_boost_factor_sysctl_handler
,
1505 .procname
= "watermark_scale_factor",
1506 .data
= &watermark_scale_factor
,
1507 .maxlen
= sizeof(watermark_scale_factor
),
1509 .proc_handler
= watermark_scale_factor_sysctl_handler
,
1511 .extra2
= &one_thousand
,
1514 .procname
= "percpu_pagelist_fraction",
1515 .data
= &percpu_pagelist_fraction
,
1516 .maxlen
= sizeof(percpu_pagelist_fraction
),
1518 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1523 .procname
= "max_map_count",
1524 .data
= &sysctl_max_map_count
,
1525 .maxlen
= sizeof(sysctl_max_map_count
),
1527 .proc_handler
= proc_dointvec_minmax
,
1532 .procname
= "nr_trim_pages",
1533 .data
= &sysctl_nr_trim_pages
,
1534 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1536 .proc_handler
= proc_dointvec_minmax
,
1541 .procname
= "laptop_mode",
1542 .data
= &laptop_mode
,
1543 .maxlen
= sizeof(laptop_mode
),
1545 .proc_handler
= proc_dointvec_jiffies
,
1548 .procname
= "block_dump",
1549 .data
= &block_dump
,
1550 .maxlen
= sizeof(block_dump
),
1552 .proc_handler
= proc_dointvec
,
1556 .procname
= "vfs_cache_pressure",
1557 .data
= &sysctl_vfs_cache_pressure
,
1558 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1560 .proc_handler
= proc_dointvec
,
1563 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1565 .procname
= "legacy_va_layout",
1566 .data
= &sysctl_legacy_va_layout
,
1567 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1569 .proc_handler
= proc_dointvec
,
1575 .procname
= "zone_reclaim_mode",
1576 .data
= &node_reclaim_mode
,
1577 .maxlen
= sizeof(node_reclaim_mode
),
1579 .proc_handler
= proc_dointvec
,
1583 .procname
= "min_unmapped_ratio",
1584 .data
= &sysctl_min_unmapped_ratio
,
1585 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1587 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1589 .extra2
= &one_hundred
,
1592 .procname
= "min_slab_ratio",
1593 .data
= &sysctl_min_slab_ratio
,
1594 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1596 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1598 .extra2
= &one_hundred
,
1603 .procname
= "stat_interval",
1604 .data
= &sysctl_stat_interval
,
1605 .maxlen
= sizeof(sysctl_stat_interval
),
1607 .proc_handler
= proc_dointvec_jiffies
,
1610 .procname
= "stat_refresh",
1614 .proc_handler
= vmstat_refresh
,
1619 .procname
= "mmap_min_addr",
1620 .data
= &dac_mmap_min_addr
,
1621 .maxlen
= sizeof(unsigned long),
1623 .proc_handler
= mmap_min_addr_handler
,
1628 .procname
= "numa_zonelist_order",
1629 .data
= &numa_zonelist_order
,
1630 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1632 .proc_handler
= numa_zonelist_order_handler
,
1635 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1636 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1638 .procname
= "vdso_enabled",
1639 #ifdef CONFIG_X86_32
1640 .data
= &vdso32_enabled
,
1641 .maxlen
= sizeof(vdso32_enabled
),
1643 .data
= &vdso_enabled
,
1644 .maxlen
= sizeof(vdso_enabled
),
1647 .proc_handler
= proc_dointvec
,
1651 #ifdef CONFIG_HIGHMEM
1653 .procname
= "highmem_is_dirtyable",
1654 .data
= &vm_highmem_is_dirtyable
,
1655 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1657 .proc_handler
= proc_dointvec_minmax
,
1662 #ifdef CONFIG_MEMORY_FAILURE
1664 .procname
= "memory_failure_early_kill",
1665 .data
= &sysctl_memory_failure_early_kill
,
1666 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1668 .proc_handler
= proc_dointvec_minmax
,
1673 .procname
= "memory_failure_recovery",
1674 .data
= &sysctl_memory_failure_recovery
,
1675 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1677 .proc_handler
= proc_dointvec_minmax
,
1683 .procname
= "user_reserve_kbytes",
1684 .data
= &sysctl_user_reserve_kbytes
,
1685 .maxlen
= sizeof(sysctl_user_reserve_kbytes
),
1687 .proc_handler
= proc_doulongvec_minmax
,
1690 .procname
= "admin_reserve_kbytes",
1691 .data
= &sysctl_admin_reserve_kbytes
,
1692 .maxlen
= sizeof(sysctl_admin_reserve_kbytes
),
1694 .proc_handler
= proc_doulongvec_minmax
,
1696 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1698 .procname
= "mmap_rnd_bits",
1699 .data
= &mmap_rnd_bits
,
1700 .maxlen
= sizeof(mmap_rnd_bits
),
1702 .proc_handler
= proc_dointvec_minmax
,
1703 .extra1
= (void *)&mmap_rnd_bits_min
,
1704 .extra2
= (void *)&mmap_rnd_bits_max
,
1707 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1709 .procname
= "mmap_rnd_compat_bits",
1710 .data
= &mmap_rnd_compat_bits
,
1711 .maxlen
= sizeof(mmap_rnd_compat_bits
),
1713 .proc_handler
= proc_dointvec_minmax
,
1714 .extra1
= (void *)&mmap_rnd_compat_bits_min
,
1715 .extra2
= (void *)&mmap_rnd_compat_bits_max
,
1718 #ifdef CONFIG_USERFAULTFD
1720 .procname
= "unprivileged_userfaultfd",
1721 .data
= &sysctl_unprivileged_userfaultfd
,
1722 .maxlen
= sizeof(sysctl_unprivileged_userfaultfd
),
1724 .proc_handler
= proc_dointvec_minmax
,
1732 static struct ctl_table fs_table
[] = {
1734 .procname
= "inode-nr",
1735 .data
= &inodes_stat
,
1736 .maxlen
= 2*sizeof(long),
1738 .proc_handler
= proc_nr_inodes
,
1741 .procname
= "inode-state",
1742 .data
= &inodes_stat
,
1743 .maxlen
= 7*sizeof(long),
1745 .proc_handler
= proc_nr_inodes
,
1748 .procname
= "file-nr",
1749 .data
= &files_stat
,
1750 .maxlen
= sizeof(files_stat
),
1752 .proc_handler
= proc_nr_files
,
1755 .procname
= "file-max",
1756 .data
= &files_stat
.max_files
,
1757 .maxlen
= sizeof(files_stat
.max_files
),
1759 .proc_handler
= proc_doulongvec_minmax
,
1761 .extra2
= &long_max
,
1764 .procname
= "nr_open",
1765 .data
= &sysctl_nr_open
,
1766 .maxlen
= sizeof(unsigned int),
1768 .proc_handler
= proc_dointvec_minmax
,
1769 .extra1
= &sysctl_nr_open_min
,
1770 .extra2
= &sysctl_nr_open_max
,
1773 .procname
= "dentry-state",
1774 .data
= &dentry_stat
,
1775 .maxlen
= 6*sizeof(long),
1777 .proc_handler
= proc_nr_dentry
,
1780 .procname
= "overflowuid",
1781 .data
= &fs_overflowuid
,
1782 .maxlen
= sizeof(int),
1784 .proc_handler
= proc_dointvec_minmax
,
1785 .extra1
= &minolduid
,
1786 .extra2
= &maxolduid
,
1789 .procname
= "overflowgid",
1790 .data
= &fs_overflowgid
,
1791 .maxlen
= sizeof(int),
1793 .proc_handler
= proc_dointvec_minmax
,
1794 .extra1
= &minolduid
,
1795 .extra2
= &maxolduid
,
1797 #ifdef CONFIG_FILE_LOCKING
1799 .procname
= "leases-enable",
1800 .data
= &leases_enable
,
1801 .maxlen
= sizeof(int),
1803 .proc_handler
= proc_dointvec
,
1806 #ifdef CONFIG_DNOTIFY
1808 .procname
= "dir-notify-enable",
1809 .data
= &dir_notify_enable
,
1810 .maxlen
= sizeof(int),
1812 .proc_handler
= proc_dointvec
,
1816 #ifdef CONFIG_FILE_LOCKING
1818 .procname
= "lease-break-time",
1819 .data
= &lease_break_time
,
1820 .maxlen
= sizeof(int),
1822 .proc_handler
= proc_dointvec
,
1827 .procname
= "aio-nr",
1829 .maxlen
= sizeof(aio_nr
),
1831 .proc_handler
= proc_doulongvec_minmax
,
1834 .procname
= "aio-max-nr",
1835 .data
= &aio_max_nr
,
1836 .maxlen
= sizeof(aio_max_nr
),
1838 .proc_handler
= proc_doulongvec_minmax
,
1840 #endif /* CONFIG_AIO */
1841 #ifdef CONFIG_INOTIFY_USER
1843 .procname
= "inotify",
1845 .child
= inotify_table
,
1850 .procname
= "epoll",
1852 .child
= epoll_table
,
1857 .procname
= "protected_symlinks",
1858 .data
= &sysctl_protected_symlinks
,
1859 .maxlen
= sizeof(int),
1861 .proc_handler
= proc_dointvec_minmax
,
1866 .procname
= "protected_hardlinks",
1867 .data
= &sysctl_protected_hardlinks
,
1868 .maxlen
= sizeof(int),
1870 .proc_handler
= proc_dointvec_minmax
,
1875 .procname
= "protected_fifos",
1876 .data
= &sysctl_protected_fifos
,
1877 .maxlen
= sizeof(int),
1879 .proc_handler
= proc_dointvec_minmax
,
1884 .procname
= "protected_regular",
1885 .data
= &sysctl_protected_regular
,
1886 .maxlen
= sizeof(int),
1888 .proc_handler
= proc_dointvec_minmax
,
1893 .procname
= "suid_dumpable",
1894 .data
= &suid_dumpable
,
1895 .maxlen
= sizeof(int),
1897 .proc_handler
= proc_dointvec_minmax_coredump
,
1901 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1903 .procname
= "binfmt_misc",
1905 .child
= sysctl_mount_point
,
1909 .procname
= "pipe-max-size",
1910 .data
= &pipe_max_size
,
1911 .maxlen
= sizeof(pipe_max_size
),
1913 .proc_handler
= proc_dopipe_max_size
,
1916 .procname
= "pipe-user-pages-hard",
1917 .data
= &pipe_user_pages_hard
,
1918 .maxlen
= sizeof(pipe_user_pages_hard
),
1920 .proc_handler
= proc_doulongvec_minmax
,
1923 .procname
= "pipe-user-pages-soft",
1924 .data
= &pipe_user_pages_soft
,
1925 .maxlen
= sizeof(pipe_user_pages_soft
),
1927 .proc_handler
= proc_doulongvec_minmax
,
1930 .procname
= "mount-max",
1931 .data
= &sysctl_mount_max
,
1932 .maxlen
= sizeof(unsigned int),
1934 .proc_handler
= proc_dointvec_minmax
,
1940 static struct ctl_table debug_table
[] = {
1941 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1943 .procname
= "exception-trace",
1944 .data
= &show_unhandled_signals
,
1945 .maxlen
= sizeof(int),
1947 .proc_handler
= proc_dointvec
1950 #if defined(CONFIG_OPTPROBES)
1952 .procname
= "kprobes-optimization",
1953 .data
= &sysctl_kprobes_optimization
,
1954 .maxlen
= sizeof(int),
1956 .proc_handler
= proc_kprobes_optimization_handler
,
1964 static struct ctl_table dev_table
[] = {
1968 int __init
sysctl_init(void)
1970 struct ctl_table_header
*hdr
;
1972 hdr
= register_sysctl_table(sysctl_base_table
);
1973 kmemleak_not_leak(hdr
);
1977 #endif /* CONFIG_SYSCTL */
1983 #ifdef CONFIG_PROC_SYSCTL
1985 static int _proc_do_string(char *data
, int maxlen
, int write
,
1986 char __user
*buffer
,
1987 size_t *lenp
, loff_t
*ppos
)
1993 if (!data
|| !maxlen
|| !*lenp
) {
1999 if (sysctl_writes_strict
== SYSCTL_WRITES_STRICT
) {
2000 /* Only continue writes not past the end of buffer. */
2002 if (len
> maxlen
- 1)
2009 /* Start writing from beginning of buffer. */
2015 while ((p
- buffer
) < *lenp
&& len
< maxlen
- 1) {
2016 if (get_user(c
, p
++))
2018 if (c
== 0 || c
== '\n')
2039 if (copy_to_user(buffer
, data
, len
))
2042 if (put_user('\n', buffer
+ len
))
2052 static void warn_sysctl_write(struct ctl_table
*table
)
2054 pr_warn_once("%s wrote to %s when file position was not 0!\n"
2055 "This will not be supported in the future. To silence this\n"
2056 "warning, set kernel.sysctl_writes_strict = -1\n",
2057 current
->comm
, table
->procname
);
2061 * proc_first_pos_non_zero_ignore - check if first position is allowed
2062 * @ppos: file position
2063 * @table: the sysctl table
2065 * Returns true if the first position is non-zero and the sysctl_writes_strict
2066 * mode indicates this is not allowed for numeric input types. String proc
2067 * handlers can ignore the return value.
2069 static bool proc_first_pos_non_zero_ignore(loff_t
*ppos
,
2070 struct ctl_table
*table
)
2075 switch (sysctl_writes_strict
) {
2076 case SYSCTL_WRITES_STRICT
:
2078 case SYSCTL_WRITES_WARN
:
2079 warn_sysctl_write(table
);
2087 * proc_dostring - read a string sysctl
2088 * @table: the sysctl table
2089 * @write: %TRUE if this is a write to the sysctl file
2090 * @buffer: the user buffer
2091 * @lenp: the size of the user buffer
2092 * @ppos: file position
2094 * Reads/writes a string from/to the user buffer. If the kernel
2095 * buffer provided is not large enough to hold the string, the
2096 * string is truncated. The copied string is %NULL-terminated.
2097 * If the string is being read by the user process, it is copied
2098 * and a newline '\n' is added. It is truncated if the buffer is
2101 * Returns 0 on success.
2103 int proc_dostring(struct ctl_table
*table
, int write
,
2104 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2107 proc_first_pos_non_zero_ignore(ppos
, table
);
2109 return _proc_do_string((char *)(table
->data
), table
->maxlen
, write
,
2110 (char __user
*)buffer
, lenp
, ppos
);
2113 static size_t proc_skip_spaces(char **buf
)
2116 char *tmp
= skip_spaces(*buf
);
2122 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2133 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2136 * @cp: kernel buffer containing the string to parse
2137 * @endp: pointer to store the trailing characters
2138 * @base: the base to use
2139 * @res: where the parsed integer will be stored
2141 * In case of success 0 is returned and @res will contain the parsed integer,
2142 * @endp will hold any trailing characters.
2143 * This function will fail the parse on overflow. If there wasn't an overflow
2144 * the function will defer the decision what characters count as invalid to the
2147 static int strtoul_lenient(const char *cp
, char **endp
, unsigned int base
,
2150 unsigned long long result
;
2153 cp
= _parse_integer_fixup_radix(cp
, &base
);
2154 rv
= _parse_integer(cp
, base
, &result
);
2155 if ((rv
& KSTRTOX_OVERFLOW
) || (result
!= (unsigned long)result
))
2163 *res
= (unsigned long)result
;
2167 #define TMPBUFLEN 22
2169 * proc_get_long - reads an ASCII formatted integer from a user buffer
2171 * @buf: a kernel buffer
2172 * @size: size of the kernel buffer
2173 * @val: this is where the number will be stored
2174 * @neg: set to %TRUE if number is negative
2175 * @perm_tr: a vector which contains the allowed trailers
2176 * @perm_tr_len: size of the perm_tr vector
2177 * @tr: pointer to store the trailer character
2179 * In case of success %0 is returned and @buf and @size are updated with
2180 * the amount of bytes read. If @tr is non-NULL and a trailing
2181 * character exists (size is non-zero after returning from this
2182 * function), @tr is updated with the trailing character.
2184 static int proc_get_long(char **buf
, size_t *size
,
2185 unsigned long *val
, bool *neg
,
2186 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2189 char *p
, tmp
[TMPBUFLEN
];
2195 if (len
> TMPBUFLEN
- 1)
2196 len
= TMPBUFLEN
- 1;
2198 memcpy(tmp
, *buf
, len
);
2202 if (*p
== '-' && *size
> 1) {
2210 if (strtoul_lenient(p
, &p
, 0, val
))
2215 /* We don't know if the next char is whitespace thus we may accept
2216 * invalid integers (e.g. 1234...a) or two integers instead of one
2217 * (e.g. 123...1). So lets not allow such large numbers. */
2218 if (len
== TMPBUFLEN
- 1)
2221 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2224 if (tr
&& (len
< *size
))
2234 * proc_put_long - converts an integer to a decimal ASCII formatted string
2236 * @buf: the user buffer
2237 * @size: the size of the user buffer
2238 * @val: the integer to be converted
2239 * @neg: sign of the number, %TRUE for negative
2241 * In case of success %0 is returned and @buf and @size are updated with
2242 * the amount of bytes written.
2244 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2248 char tmp
[TMPBUFLEN
], *p
= tmp
;
2250 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2254 if (copy_to_user(*buf
, tmp
, len
))
2262 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2265 char __user
**buffer
= (char __user
**)buf
;
2266 if (put_user(c
, *buffer
))
2268 (*size
)--, (*buffer
)++;
2274 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2276 int write
, void *data
)
2280 if (*lvalp
> (unsigned long) INT_MAX
+ 1)
2284 if (*lvalp
> (unsigned long) INT_MAX
)
2292 *lvalp
= -(unsigned long)val
;
2295 *lvalp
= (unsigned long)val
;
2301 static int do_proc_douintvec_conv(unsigned long *lvalp
,
2303 int write
, void *data
)
2306 if (*lvalp
> UINT_MAX
)
2310 unsigned int val
= *valp
;
2311 *lvalp
= (unsigned long)val
;
2316 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2318 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2319 int write
, void __user
*buffer
,
2320 size_t *lenp
, loff_t
*ppos
,
2321 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2322 int write
, void *data
),
2325 int *i
, vleft
, first
= 1, err
= 0;
2327 char *kbuf
= NULL
, *p
;
2329 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2334 i
= (int *) tbl_data
;
2335 vleft
= table
->maxlen
/ sizeof(*i
);
2339 conv
= do_proc_dointvec_conv
;
2342 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2345 if (left
> PAGE_SIZE
- 1)
2346 left
= PAGE_SIZE
- 1;
2347 p
= kbuf
= memdup_user_nul(buffer
, left
);
2349 return PTR_ERR(kbuf
);
2352 for (; left
&& vleft
--; i
++, first
=0) {
2357 left
-= proc_skip_spaces(&p
);
2361 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2363 sizeof(proc_wspace_sep
), NULL
);
2366 if (conv(&neg
, &lval
, i
, 1, data
)) {
2371 if (conv(&neg
, &lval
, i
, 0, data
)) {
2376 err
= proc_put_char(&buffer
, &left
, '\t');
2379 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2385 if (!write
&& !first
&& left
&& !err
)
2386 err
= proc_put_char(&buffer
, &left
, '\n');
2387 if (write
&& !err
&& left
)
2388 left
-= proc_skip_spaces(&p
);
2392 return err
? : -EINVAL
;
2400 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2401 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2402 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2403 int write
, void *data
),
2406 return __do_proc_dointvec(table
->data
, table
, write
,
2407 buffer
, lenp
, ppos
, conv
, data
);
2410 static int do_proc_douintvec_w(unsigned int *tbl_data
,
2411 struct ctl_table
*table
,
2412 void __user
*buffer
,
2413 size_t *lenp
, loff_t
*ppos
,
2414 int (*conv
)(unsigned long *lvalp
,
2416 int write
, void *data
),
2423 char *kbuf
= NULL
, *p
;
2427 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2430 if (left
> PAGE_SIZE
- 1)
2431 left
= PAGE_SIZE
- 1;
2433 p
= kbuf
= memdup_user_nul(buffer
, left
);
2437 left
-= proc_skip_spaces(&p
);
2443 err
= proc_get_long(&p
, &left
, &lval
, &neg
,
2445 sizeof(proc_wspace_sep
), NULL
);
2451 if (conv(&lval
, tbl_data
, 1, data
)) {
2457 left
-= proc_skip_spaces(&p
);
2466 /* This is in keeping with old __do_proc_dointvec() */
2472 static int do_proc_douintvec_r(unsigned int *tbl_data
, void __user
*buffer
,
2473 size_t *lenp
, loff_t
*ppos
,
2474 int (*conv
)(unsigned long *lvalp
,
2476 int write
, void *data
),
2485 if (conv(&lval
, tbl_data
, 0, data
)) {
2490 err
= proc_put_long(&buffer
, &left
, lval
, false);
2494 err
= proc_put_char(&buffer
, &left
, '\n');
2503 static int __do_proc_douintvec(void *tbl_data
, struct ctl_table
*table
,
2504 int write
, void __user
*buffer
,
2505 size_t *lenp
, loff_t
*ppos
,
2506 int (*conv
)(unsigned long *lvalp
,
2508 int write
, void *data
),
2511 unsigned int *i
, vleft
;
2513 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2518 i
= (unsigned int *) tbl_data
;
2519 vleft
= table
->maxlen
/ sizeof(*i
);
2522 * Arrays are not supported, keep this simple. *Do not* add
2531 conv
= do_proc_douintvec_conv
;
2534 return do_proc_douintvec_w(i
, table
, buffer
, lenp
, ppos
,
2536 return do_proc_douintvec_r(i
, buffer
, lenp
, ppos
, conv
, data
);
2539 static int do_proc_douintvec(struct ctl_table
*table
, int write
,
2540 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2541 int (*conv
)(unsigned long *lvalp
,
2543 int write
, void *data
),
2546 return __do_proc_douintvec(table
->data
, table
, write
,
2547 buffer
, lenp
, ppos
, conv
, data
);
2551 * proc_dointvec - read a vector of integers
2552 * @table: the sysctl table
2553 * @write: %TRUE if this is a write to the sysctl file
2554 * @buffer: the user buffer
2555 * @lenp: the size of the user buffer
2556 * @ppos: file position
2558 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2559 * values from/to the user buffer, treated as an ASCII string.
2561 * Returns 0 on success.
2563 int proc_dointvec(struct ctl_table
*table
, int write
,
2564 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2566 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
, NULL
, NULL
);
2570 * proc_douintvec - read a vector of unsigned integers
2571 * @table: the sysctl table
2572 * @write: %TRUE if this is a write to the sysctl file
2573 * @buffer: the user buffer
2574 * @lenp: the size of the user buffer
2575 * @ppos: file position
2577 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2578 * values from/to the user buffer, treated as an ASCII string.
2580 * Returns 0 on success.
2582 int proc_douintvec(struct ctl_table
*table
, int write
,
2583 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2585 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2586 do_proc_douintvec_conv
, NULL
);
2590 * Taint values can only be increased
2591 * This means we can safely use a temporary.
2593 static int proc_taint(struct ctl_table
*table
, int write
,
2594 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2597 unsigned long tmptaint
= get_taint();
2600 if (write
&& !capable(CAP_SYS_ADMIN
))
2605 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2611 * Poor man's atomic or. Not worth adding a primitive
2612 * to everyone's atomic.h for this
2615 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2616 if ((tmptaint
>> i
) & 1)
2617 add_taint(i
, LOCKDEP_STILL_OK
);
2624 #ifdef CONFIG_PRINTK
2625 static int proc_dointvec_minmax_sysadmin(struct ctl_table
*table
, int write
,
2626 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2628 if (write
&& !capable(CAP_SYS_ADMIN
))
2631 return proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2636 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2637 * @min: pointer to minimum allowable value
2638 * @max: pointer to maximum allowable value
2640 * The do_proc_dointvec_minmax_conv_param structure provides the
2641 * minimum and maximum values for doing range checking for those sysctl
2642 * parameters that use the proc_dointvec_minmax() handler.
2644 struct do_proc_dointvec_minmax_conv_param
{
2649 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2651 int write
, void *data
)
2654 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2656 * If writing, first do so via a temporary local int so we can
2657 * bounds-check it before touching *valp.
2659 int *ip
= write
? &tmp
: valp
;
2661 ret
= do_proc_dointvec_conv(negp
, lvalp
, ip
, write
, data
);
2666 if ((param
->min
&& *param
->min
> tmp
) ||
2667 (param
->max
&& *param
->max
< tmp
))
2676 * proc_dointvec_minmax - read a vector of integers with min/max values
2677 * @table: the sysctl table
2678 * @write: %TRUE if this is a write to the sysctl file
2679 * @buffer: the user buffer
2680 * @lenp: the size of the user buffer
2681 * @ppos: file position
2683 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2684 * values from/to the user buffer, treated as an ASCII string.
2686 * This routine will ensure the values are within the range specified by
2687 * table->extra1 (min) and table->extra2 (max).
2689 * Returns 0 on success or -EINVAL on write when the range check fails.
2691 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2692 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2694 struct do_proc_dointvec_minmax_conv_param param
= {
2695 .min
= (int *) table
->extra1
,
2696 .max
= (int *) table
->extra2
,
2698 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2699 do_proc_dointvec_minmax_conv
, ¶m
);
2703 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2704 * @min: pointer to minimum allowable value
2705 * @max: pointer to maximum allowable value
2707 * The do_proc_douintvec_minmax_conv_param structure provides the
2708 * minimum and maximum values for doing range checking for those sysctl
2709 * parameters that use the proc_douintvec_minmax() handler.
2711 struct do_proc_douintvec_minmax_conv_param
{
2716 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp
,
2718 int write
, void *data
)
2722 struct do_proc_douintvec_minmax_conv_param
*param
= data
;
2723 /* write via temporary local uint for bounds-checking */
2724 unsigned int *up
= write
? &tmp
: valp
;
2726 ret
= do_proc_douintvec_conv(lvalp
, up
, write
, data
);
2731 if ((param
->min
&& *param
->min
> tmp
) ||
2732 (param
->max
&& *param
->max
< tmp
))
2742 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2743 * @table: the sysctl table
2744 * @write: %TRUE if this is a write to the sysctl file
2745 * @buffer: the user buffer
2746 * @lenp: the size of the user buffer
2747 * @ppos: file position
2749 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2750 * values from/to the user buffer, treated as an ASCII string. Negative
2751 * strings are not allowed.
2753 * This routine will ensure the values are within the range specified by
2754 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2755 * check for UINT_MAX to avoid having to support wrap around uses from
2758 * Returns 0 on success or -ERANGE on write when the range check fails.
2760 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
2761 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2763 struct do_proc_douintvec_minmax_conv_param param
= {
2764 .min
= (unsigned int *) table
->extra1
,
2765 .max
= (unsigned int *) table
->extra2
,
2767 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2768 do_proc_douintvec_minmax_conv
, ¶m
);
2771 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp
,
2773 int write
, void *data
)
2778 val
= round_pipe_size(*lvalp
);
2784 unsigned int val
= *valp
;
2785 *lvalp
= (unsigned long) val
;
2791 static int proc_dopipe_max_size(struct ctl_table
*table
, int write
,
2792 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2794 return do_proc_douintvec(table
, write
, buffer
, lenp
, ppos
,
2795 do_proc_dopipe_max_size_conv
, NULL
);
2798 static void validate_coredump_safety(void)
2800 #ifdef CONFIG_COREDUMP
2801 if (suid_dumpable
== SUID_DUMP_ROOT
&&
2802 core_pattern
[0] != '/' && core_pattern
[0] != '|') {
2804 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2805 "Pipe handler or fully qualified core dump path required.\n"
2806 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2812 static int proc_dointvec_minmax_coredump(struct ctl_table
*table
, int write
,
2813 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2815 int error
= proc_dointvec_minmax(table
, write
, buffer
, lenp
, ppos
);
2817 validate_coredump_safety();
2821 #ifdef CONFIG_COREDUMP
2822 static int proc_dostring_coredump(struct ctl_table
*table
, int write
,
2823 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2825 int error
= proc_dostring(table
, write
, buffer
, lenp
, ppos
);
2827 validate_coredump_safety();
2832 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2833 void __user
*buffer
,
2834 size_t *lenp
, loff_t
*ppos
,
2835 unsigned long convmul
,
2836 unsigned long convdiv
)
2838 unsigned long *i
, *min
, *max
;
2839 int vleft
, first
= 1, err
= 0;
2841 char *kbuf
= NULL
, *p
;
2843 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2848 i
= (unsigned long *) data
;
2849 min
= (unsigned long *) table
->extra1
;
2850 max
= (unsigned long *) table
->extra2
;
2851 vleft
= table
->maxlen
/ sizeof(unsigned long);
2855 if (proc_first_pos_non_zero_ignore(ppos
, table
))
2858 if (left
> PAGE_SIZE
- 1)
2859 left
= PAGE_SIZE
- 1;
2860 p
= kbuf
= memdup_user_nul(buffer
, left
);
2862 return PTR_ERR(kbuf
);
2865 for (; left
&& vleft
--; i
++, first
= 0) {
2871 left
-= proc_skip_spaces(&p
);
2875 err
= proc_get_long(&p
, &left
, &val
, &neg
,
2877 sizeof(proc_wspace_sep
), NULL
);
2882 val
= convmul
* val
/ convdiv
;
2883 if ((min
&& val
< *min
) || (max
&& val
> *max
)) {
2889 val
= convdiv
* (*i
) / convmul
;
2891 err
= proc_put_char(&buffer
, &left
, '\t');
2895 err
= proc_put_long(&buffer
, &left
, val
, false);
2901 if (!write
&& !first
&& left
&& !err
)
2902 err
= proc_put_char(&buffer
, &left
, '\n');
2904 left
-= proc_skip_spaces(&p
);
2908 return err
? : -EINVAL
;
2916 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2917 void __user
*buffer
,
2918 size_t *lenp
, loff_t
*ppos
,
2919 unsigned long convmul
,
2920 unsigned long convdiv
)
2922 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2923 buffer
, lenp
, ppos
, convmul
, convdiv
);
2927 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2928 * @table: the sysctl table
2929 * @write: %TRUE if this is a write to the sysctl file
2930 * @buffer: the user buffer
2931 * @lenp: the size of the user buffer
2932 * @ppos: file position
2934 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2935 * values from/to the user buffer, treated as an ASCII string.
2937 * This routine will ensure the values are within the range specified by
2938 * table->extra1 (min) and table->extra2 (max).
2940 * Returns 0 on success.
2942 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2943 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2945 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2949 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2950 * @table: the sysctl table
2951 * @write: %TRUE if this is a write to the sysctl file
2952 * @buffer: the user buffer
2953 * @lenp: the size of the user buffer
2954 * @ppos: file position
2956 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2957 * values from/to the user buffer, treated as an ASCII string. The values
2958 * are treated as milliseconds, and converted to jiffies when they are stored.
2960 * This routine will ensure the values are within the range specified by
2961 * table->extra1 (min) and table->extra2 (max).
2963 * Returns 0 on success.
2965 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2966 void __user
*buffer
,
2967 size_t *lenp
, loff_t
*ppos
)
2969 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2970 lenp
, ppos
, HZ
, 1000l);
2974 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2976 int write
, void *data
)
2979 if (*lvalp
> INT_MAX
/ HZ
)
2981 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2987 lval
= -(unsigned long)val
;
2990 lval
= (unsigned long)val
;
2997 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2999 int write
, void *data
)
3002 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
3004 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
3010 lval
= -(unsigned long)val
;
3013 lval
= (unsigned long)val
;
3015 *lvalp
= jiffies_to_clock_t(lval
);
3020 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
3022 int write
, void *data
)
3025 unsigned long jif
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
3035 lval
= -(unsigned long)val
;
3038 lval
= (unsigned long)val
;
3040 *lvalp
= jiffies_to_msecs(lval
);
3046 * proc_dointvec_jiffies - read a vector of integers as seconds
3047 * @table: the sysctl table
3048 * @write: %TRUE if this is a write to the sysctl file
3049 * @buffer: the user buffer
3050 * @lenp: the size of the user buffer
3051 * @ppos: file position
3053 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3054 * values from/to the user buffer, treated as an ASCII string.
3055 * The values read are assumed to be in seconds, and are converted into
3058 * Returns 0 on success.
3060 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3061 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3063 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
3064 do_proc_dointvec_jiffies_conv
,NULL
);
3068 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3069 * @table: the sysctl table
3070 * @write: %TRUE if this is a write to the sysctl file
3071 * @buffer: the user buffer
3072 * @lenp: the size of the user buffer
3073 * @ppos: pointer to the file position
3075 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3076 * values from/to the user buffer, treated as an ASCII string.
3077 * The values read are assumed to be in 1/USER_HZ seconds, and
3078 * are converted into jiffies.
3080 * Returns 0 on success.
3082 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3083 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3085 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
3086 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
3090 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3091 * @table: the sysctl table
3092 * @write: %TRUE if this is a write to the sysctl file
3093 * @buffer: the user buffer
3094 * @lenp: the size of the user buffer
3095 * @ppos: file position
3096 * @ppos: the current position in the file
3098 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3099 * values from/to the user buffer, treated as an ASCII string.
3100 * The values read are assumed to be in 1/1000 seconds, and
3101 * are converted into jiffies.
3103 * Returns 0 on success.
3105 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3106 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3108 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
3109 do_proc_dointvec_ms_jiffies_conv
, NULL
);
3112 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
3113 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3115 struct pid
*new_pid
;
3119 tmp
= pid_vnr(cad_pid
);
3121 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
3122 lenp
, ppos
, NULL
, NULL
);
3126 new_pid
= find_get_pid(tmp
);
3130 put_pid(xchg(&cad_pid
, new_pid
));
3135 * proc_do_large_bitmap - read/write from/to a large bitmap
3136 * @table: the sysctl table
3137 * @write: %TRUE if this is a write to the sysctl file
3138 * @buffer: the user buffer
3139 * @lenp: the size of the user buffer
3140 * @ppos: file position
3142 * The bitmap is stored at table->data and the bitmap length (in bits)
3145 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3146 * large bitmaps may be represented in a compact manner. Writing into
3147 * the file will clear the bitmap then update it with the given input.
3149 * Returns 0 on success.
3151 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3152 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3156 size_t left
= *lenp
;
3157 unsigned long bitmap_len
= table
->maxlen
;
3158 unsigned long *bitmap
= *(unsigned long **) table
->data
;
3159 unsigned long *tmp_bitmap
= NULL
;
3160 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
3162 if (!bitmap
|| !bitmap_len
|| !left
|| (*ppos
&& !write
)) {
3171 if (left
> PAGE_SIZE
- 1) {
3172 left
= PAGE_SIZE
- 1;
3173 /* How much of the buffer we'll skip this pass */
3174 skipped
= *lenp
- left
;
3177 p
= kbuf
= memdup_user_nul(buffer
, left
);
3179 return PTR_ERR(kbuf
);
3181 tmp_bitmap
= bitmap_zalloc(bitmap_len
, GFP_KERNEL
);
3186 proc_skip_char(&p
, &left
, '\n');
3187 while (!err
&& left
) {
3188 unsigned long val_a
, val_b
;
3192 /* In case we stop parsing mid-number, we can reset */
3194 err
= proc_get_long(&p
, &left
, &val_a
, &neg
, tr_a
,
3197 * If we consumed the entirety of a truncated buffer or
3198 * only one char is left (may be a "-"), then stop here,
3199 * reset, & come back for more.
3201 if ((left
<= 1) && skipped
) {
3208 if (val_a
>= bitmap_len
|| neg
) {
3220 err
= proc_get_long(&p
, &left
, &val_b
,
3221 &neg
, tr_b
, sizeof(tr_b
),
3224 * If we consumed all of a truncated buffer or
3225 * then stop here, reset, & come back for more.
3227 if (!left
&& skipped
) {
3234 if (val_b
>= bitmap_len
|| neg
||
3245 bitmap_set(tmp_bitmap
, val_a
, val_b
- val_a
+ 1);
3247 proc_skip_char(&p
, &left
, '\n');
3252 unsigned long bit_a
, bit_b
= 0;
3255 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
3256 if (bit_a
>= bitmap_len
)
3258 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
3262 err
= proc_put_char(&buffer
, &left
, ',');
3266 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
3269 if (bit_a
!= bit_b
) {
3270 err
= proc_put_char(&buffer
, &left
, '-');
3273 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
3281 err
= proc_put_char(&buffer
, &left
, '\n');
3287 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
3289 bitmap_copy(bitmap
, tmp_bitmap
, bitmap_len
);
3295 bitmap_free(tmp_bitmap
);
3299 #else /* CONFIG_PROC_SYSCTL */
3301 int proc_dostring(struct ctl_table
*table
, int write
,
3302 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3307 int proc_dointvec(struct ctl_table
*table
, int write
,
3308 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3313 int proc_douintvec(struct ctl_table
*table
, int write
,
3314 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3319 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
3320 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3325 int proc_douintvec_minmax(struct ctl_table
*table
, int write
,
3326 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3331 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
3332 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3337 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
3338 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3343 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
3344 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3349 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
3350 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3355 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
3356 void __user
*buffer
,
3357 size_t *lenp
, loff_t
*ppos
)
3362 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
3363 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3368 #endif /* CONFIG_PROC_SYSCTL */
3370 #if defined(CONFIG_SYSCTL)
3371 int proc_do_static_key(struct ctl_table
*table
, int write
,
3372 void __user
*buffer
, size_t *lenp
,
3375 struct static_key
*key
= (struct static_key
*)table
->data
;
3376 static DEFINE_MUTEX(static_key_mutex
);
3378 struct ctl_table tmp
= {
3380 .maxlen
= sizeof(val
),
3381 .mode
= table
->mode
,
3386 if (write
&& !capable(CAP_SYS_ADMIN
))
3389 mutex_lock(&static_key_mutex
);
3390 val
= static_key_enabled(key
);
3391 ret
= proc_dointvec_minmax(&tmp
, write
, buffer
, lenp
, ppos
);
3392 if (write
&& !ret
) {
3394 static_key_enable(key
);
3396 static_key_disable(key
);
3398 mutex_unlock(&static_key_mutex
);
3403 * No sense putting this after each symbol definition, twice,
3404 * exception granted :-)
3406 EXPORT_SYMBOL(proc_dointvec
);
3407 EXPORT_SYMBOL(proc_douintvec
);
3408 EXPORT_SYMBOL(proc_dointvec_jiffies
);
3409 EXPORT_SYMBOL(proc_dointvec_minmax
);
3410 EXPORT_SYMBOL_GPL(proc_douintvec_minmax
);
3411 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
3412 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
3413 EXPORT_SYMBOL(proc_dostring
);
3414 EXPORT_SYMBOL(proc_doulongvec_minmax
);
3415 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
3416 EXPORT_SYMBOL(proc_do_large_bitmap
);