blob: 3fb1405f3f8c912e477c02345e5eefaa0a7357fe [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * sysctl.c: General linux system control interface
3 *
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
12 * Horn.
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
16 * Wendling.
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
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080022#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/mm.h>
24#include <linux/swap.h>
25#include <linux/slab.h>
26#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070027#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080028#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080029#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070031#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/ctype.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070033#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070034#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/init.h>
36#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010037#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030038#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/sysrq.h>
40#include <linux/highuid.h>
41#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020042#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070043#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070046#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/times.h>
48#include <linux/limits.h>
49#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020050#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070052#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080053#include <linux/nfs_fs.h>
54#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070055#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020056#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020057#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050058#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020059#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070060#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040061#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070062#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000063#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060064#include <linux/sched/sysctl.h>
Ingo Molnarf7ccbae2017-02-08 18:51:30 +010065#include <linux/sched/coredump.h>
Kees Cook79847542014-01-23 15:55:59 -080066#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070067#include <linux/bpf.h>
Eric W. Biedermand2921682016-09-28 00:27:17 -050068#include <linux/mount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Christian Brauner7f2923c2019-03-07 16:29:40 -080070#include "../lib/kstrtox.h"
71
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080072#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#include <asm/processor.h>
74
Andi Kleen29cbc782006-09-30 01:47:55 +020075#ifdef CONFIG_X86
76#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010077#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010078#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020079#endif
David Howellsd550bbd2012-03-28 18:30:03 +010080#ifdef CONFIG_SPARC
81#include <asm/setup.h>
82#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080083#ifdef CONFIG_BSD_PROCESS_ACCT
84#include <linux/acct.h>
85#endif
Dave Young4f0e0562010-03-10 15:24:09 -080086#ifdef CONFIG_RT_MUTEXES
87#include <linux/rtmutex.h>
88#endif
Dave Young2edf5e42010-03-10 15:24:10 -080089#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
90#include <linux/lockdep.h>
91#endif
Dave Young15485a42010-03-10 15:24:07 -080092#ifdef CONFIG_CHR_DEV_SG
93#include <scsi/sg.h>
94#endif
Alexander Popov964c9df2018-08-17 01:17:03 +030095#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
96#include <linux/stackleak.h>
97#endif
Don Zickus58687ac2010-05-07 17:11:44 -040098#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -050099#include <linux/nmi.h>
100#endif
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#if defined(CONFIG_SYSCTL)
103
104/* External variables not in a header file. */
Alan Coxd6e71142005-06-23 00:09:43 -0700105extern int suid_dumpable;
Alex Kelly046d6622012-10-04 17:15:23 -0700106#ifdef CONFIG_COREDUMP
107extern int core_uses_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108extern char core_pattern[];
Neil Hormana2939802009-09-23 15:56:56 -0700109extern unsigned int core_pipe_limit;
Alex Kelly046d6622012-10-04 17:15:23 -0700110#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111extern int pid_max;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112extern int pid_max_min, pid_max_max;
Rohit Seth8ad4b1f2006-01-08 01:00:40 -0800113extern int percpu_pagelist_fraction;
Arjan van de Ven97455122008-01-25 21:08:34 +0100114extern int latencytop_enabled;
Alexey Dobriyan9b80a182016-09-02 00:38:52 +0300115extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
Paul Mundtdd8632a2009-01-08 12:04:47 +0000116#ifndef CONFIG_MMU
117extern int sysctl_nr_trim_pages;
118#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700120/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400121#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700122static int sixty = 60;
123#endif
124
Aaron Tomlin270750db2014-01-20 17:34:13 +0000125static int __maybe_unused neg_one = -1;
126
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700127static int zero;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700128static int __maybe_unused one = 1;
129static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700130static int __maybe_unused four = 4;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800131static unsigned long one_ul = 1;
Christian Brauner32a5ad92019-03-07 16:29:43 -0800132static unsigned long long_max = LONG_MAX;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700133static int one_hundred = 100;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700134static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700135#ifdef CONFIG_PRINTK
136static int ten_thousand = 10000;
137#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300138#ifdef CONFIG_PERF_EVENTS
139static int six_hundred_forty_kb = 640 * 1024;
140#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700141
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700142/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
143static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
146static int maxolduid = 65535;
147static int minolduid;
148
149static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700150static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Dmitry Vyukova2e51442018-08-21 21:55:52 -0700152/*
153 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
154 * and hung_task_check_interval_secs
155 */
Liu Hua80df2842014-04-07 15:38:57 -0700156#ifdef CONFIG_DETECT_HUNG_TASK
157static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
158#endif
159
Dave Youngd14f1722010-02-25 20:28:57 -0500160#ifdef CONFIG_INOTIFY_USER
161#include <linux/inotify.h>
162#endif
David S. Miller72c57ed2008-09-11 23:29:54 -0700163#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#endif
165
166#ifdef __hppa__
167extern int pwrsw_enabled;
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530168#endif
169
170#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171extern int unaligned_enabled;
172#endif
173
Jes Sorensend2b176e2006-02-28 09:42:23 -0800174#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -0800175extern int unaligned_dump_stack;
Jes Sorensend2b176e2006-02-28 09:42:23 -0800176#endif
177
Vineet Guptab6fca722013-01-09 20:06:28 +0530178#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
179extern int no_unaligned_warning;
180#endif
181
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700182#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700183
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700184/**
185 * enum sysctl_writes_mode - supported sysctl write modes
186 *
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
192 * not 0.
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
198 * to the buffer.
199 *
200 * These write modes control how current file position affects the behavior of
201 * updating sysctl values through the proc interface on each write.
202 */
203enum sysctl_writes_mode {
204 SYSCTL_WRITES_LEGACY = -1,
205 SYSCTL_WRITES_WARN = 0,
206 SYSCTL_WRITES_STRICT = 1,
207};
Kees Cookf4aacea2014-06-06 14:37:19 -0700208
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700209static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Kees Cookf4aacea2014-06-06 14:37:19 -0700210
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700211static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700212 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700213static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800214 void __user *buffer, size_t *lenp, loff_t *ppos);
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700215#endif
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700216
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700217#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700218static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700219 void __user *buffer, size_t *lenp, loff_t *ppos);
220#endif
221
Kees Cook54b50192012-07-30 14:39:18 -0700222static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
223 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700224#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -0700225static int proc_dostring_coredump(struct ctl_table *table, int write,
226 void __user *buffer, size_t *lenp, loff_t *ppos);
Alex Kelly046d6622012-10-04 17:15:23 -0700227#endif
Eric Biggers319e0a22018-02-06 15:41:49 -0800228static int proc_dopipe_max_size(struct ctl_table *table, int write,
229 void __user *buffer, size_t *lenp, loff_t *ppos);
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -0800230#ifdef CONFIG_BPF_SYSCALL
Alexei Starovoitov492ecee2019-02-25 14:28:39 -0800231static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write,
232 void __user *buffer, size_t *lenp,
233 loff_t *ppos);
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -0800234#endif
Kees Cook54b50192012-07-30 14:39:18 -0700235
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700236#ifdef CONFIG_MAGIC_SYSRQ
Randy Dunlap5f733e82018-08-21 22:01:06 -0700237/* Note: sysrq code uses its own private copy */
Ben Hutchings8eaede42013-10-07 01:05:46 +0100238static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700239
Joe Perches6f8fd1d2014-06-06 14:38:08 -0700240static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700241 void __user *buffer, size_t *lenp,
242 loff_t *ppos)
243{
244 int error;
245
246 error = proc_dointvec(table, write, buffer, lenp, ppos);
247 if (error)
248 return error;
249
250 if (write)
251 sysrq_toggle_support(__sysrq_enabled);
252
253 return 0;
254}
255
256#endif
257
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700258static struct ctl_table kern_table[];
259static struct ctl_table vm_table[];
260static struct ctl_table fs_table[];
261static struct ctl_table debug_table[];
262static struct ctl_table dev_table[];
263extern struct ctl_table random_table[];
Davide Libenzi7ef99642008-12-01 13:13:55 -0800264#ifdef CONFIG_EPOLL
265extern struct ctl_table epoll_table[];
266#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800268#ifdef CONFIG_FW_LOADER_USER_HELPER
269extern struct ctl_table firmware_config_table[];
270#endif
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
273int sysctl_legacy_va_layout;
274#endif
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276/* The default sysctl tables: */
277
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -0800278static struct ctl_table sysctl_base_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 .procname = "kernel",
281 .mode = 0555,
282 .child = kern_table,
283 },
284 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 .procname = "vm",
286 .mode = 0555,
287 .child = vm_table,
288 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 .procname = "fs",
291 .mode = 0555,
292 .child = fs_table,
293 },
294 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 .procname = "debug",
296 .mode = 0555,
297 .child = debug_table,
298 },
299 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 .procname = "dev",
301 .mode = 0555,
302 .child = dev_table,
303 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -0700304 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305};
306
Ingo Molnar77e54a12007-07-09 18:52:00 +0200307#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100308static int min_sched_granularity_ns = 100000; /* 100 usecs */
309static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
310static int min_wakeup_granularity_ns; /* 0 usecs */
311static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200312#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100313static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
314static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200315#endif /* CONFIG_SMP */
316#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200317
Mel Gorman5e771902010-05-24 14:32:31 -0700318#ifdef CONFIG_COMPACTION
319static int min_extfrag_threshold;
320static int max_extfrag_threshold = 1000;
321#endif
322
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700323static struct ctl_table kern_table[] = {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200324 {
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200325 .procname = "sched_child_runs_first",
326 .data = &sysctl_sched_child_runs_first,
327 .maxlen = sizeof(unsigned int),
328 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800329 .proc_handler = proc_dointvec,
Mike Galbraith2bba22c2009-09-09 15:41:37 +0200330 },
Ingo Molnar77e54a12007-07-09 18:52:00 +0200331#ifdef CONFIG_SCHED_DEBUG
332 {
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100333 .procname = "sched_min_granularity_ns",
334 .data = &sysctl_sched_min_granularity,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800337 .proc_handler = sched_proc_update_handler,
Peter Zijlstrab2be5e92007-11-09 22:39:37 +0100338 .extra1 = &min_sched_granularity_ns,
339 .extra2 = &max_sched_granularity_ns,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200340 },
341 {
Peter Zijlstra21805082007-08-25 18:41:53 +0200342 .procname = "sched_latency_ns",
343 .data = &sysctl_sched_latency,
344 .maxlen = sizeof(unsigned int),
345 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800346 .proc_handler = sched_proc_update_handler,
Peter Zijlstra21805082007-08-25 18:41:53 +0200347 .extra1 = &min_sched_granularity_ns,
348 .extra2 = &max_sched_granularity_ns,
349 },
350 {
Ingo Molnar77e54a12007-07-09 18:52:00 +0200351 .procname = "sched_wakeup_granularity_ns",
352 .data = &sysctl_sched_wakeup_granularity,
353 .maxlen = sizeof(unsigned int),
354 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800355 .proc_handler = sched_proc_update_handler,
Ingo Molnar77e54a12007-07-09 18:52:00 +0200356 .extra1 = &min_wakeup_granularity_ns,
357 .extra2 = &max_wakeup_granularity_ns,
358 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200359#ifdef CONFIG_SMP
Ingo Molnar77e54a12007-07-09 18:52:00 +0200360 {
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100361 .procname = "sched_tunable_scaling",
362 .data = &sysctl_sched_tunable_scaling,
363 .maxlen = sizeof(enum sched_tunable_scaling),
364 .mode = 0644,
Linus Torvalds702a7c72009-12-12 11:34:10 -0800365 .proc_handler = sched_proc_update_handler,
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100366 .extra1 = &min_sched_tunable_scaling,
367 .extra2 = &max_sched_tunable_scaling,
Peter Zijlstra2398f2c2008-06-27 13:41:35 +0200368 },
369 {
Namhyung Kimd00535d2012-08-16 11:15:30 +0900370 .procname = "sched_migration_cost_ns",
Ingo Molnarda84d962007-10-15 17:00:18 +0200371 .data = &sysctl_sched_migration_cost,
372 .maxlen = sizeof(unsigned int),
373 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800374 .proc_handler = proc_dointvec,
Ingo Molnarda84d962007-10-15 17:00:18 +0200375 },
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100376 {
Peter Zijlstrab82d9fd2007-11-09 22:39:39 +0100377 .procname = "sched_nr_migrate",
378 .data = &sysctl_sched_nr_migrate,
379 .maxlen = sizeof(unsigned int),
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100380 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800381 .proc_handler = proc_dointvec,
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100382 },
Mel Gormancb251762016-02-05 09:08:36 +0000383#ifdef CONFIG_SCHEDSTATS
384 {
385 .procname = "sched_schedstats",
386 .data = NULL,
387 .maxlen = sizeof(unsigned int),
388 .mode = 0644,
389 .proc_handler = sysctl_schedstats,
390 .extra1 = &zero,
391 .extra2 = &one,
392 },
393#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200394#endif /* CONFIG_SMP */
395#ifdef CONFIG_NUMA_BALANCING
396 {
Peter Zijlstra4b96a292012-10-25 14:16:47 +0200397 .procname = "numa_balancing_scan_delay_ms",
398 .data = &sysctl_numa_balancing_scan_delay,
399 .maxlen = sizeof(unsigned int),
400 .mode = 0644,
401 .proc_handler = proc_dointvec,
402 },
403 {
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200404 .procname = "numa_balancing_scan_period_min_ms",
405 .data = &sysctl_numa_balancing_scan_period_min,
406 .maxlen = sizeof(unsigned int),
407 .mode = 0644,
408 .proc_handler = proc_dointvec,
409 },
410 {
411 .procname = "numa_balancing_scan_period_max_ms",
412 .data = &sysctl_numa_balancing_scan_period_max,
413 .maxlen = sizeof(unsigned int),
414 .mode = 0644,
415 .proc_handler = proc_dointvec,
416 },
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200417 {
418 .procname = "numa_balancing_scan_size_mb",
419 .data = &sysctl_numa_balancing_scan_size,
420 .maxlen = sizeof(unsigned int),
421 .mode = 0644,
Kirill Tkhai64192652014-10-16 14:39:37 +0400422 .proc_handler = proc_dointvec_minmax,
423 .extra1 = &one,
Peter Zijlstra6e5fb222012-10-25 14:16:45 +0200424 },
Mel Gorman3a7053b2013-10-07 11:29:00 +0100425 {
Andi Kleen54a43d52014-01-23 15:53:13 -0800426 .procname = "numa_balancing",
427 .data = NULL, /* filled in by handler */
428 .maxlen = sizeof(unsigned int),
429 .mode = 0644,
430 .proc_handler = sysctl_numa_balancing,
431 .extra1 = &zero,
432 .extra2 = &one,
433 },
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200434#endif /* CONFIG_NUMA_BALANCING */
435#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar1799e352007-09-19 23:34:46 +0200436 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100437 .procname = "sched_rt_period_us",
438 .data = &sysctl_sched_rt_period,
439 .maxlen = sizeof(unsigned int),
440 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800441 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100442 },
443 {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100444 .procname = "sched_rt_runtime_us",
445 .data = &sysctl_sched_rt_runtime,
446 .maxlen = sizeof(int),
447 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800448 .proc_handler = sched_rt_handler,
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100449 },
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600450 {
451 .procname = "sched_rr_timeslice_ms",
Shile Zhang975e1552017-01-28 22:00:49 +0800452 .data = &sysctl_sched_rr_timeslice,
Clark Williamsce0dbbb2013-02-07 09:47:04 -0600453 .maxlen = sizeof(int),
454 .mode = 0644,
455 .proc_handler = sched_rr_handler,
456 },
Mike Galbraith5091faa2010-11-30 14:18:03 +0100457#ifdef CONFIG_SCHED_AUTOGROUP
458 {
459 .procname = "sched_autogroup_enabled",
460 .data = &sysctl_sched_autogroup_enabled,
461 .maxlen = sizeof(unsigned int),
462 .mode = 0644,
Yong Zhang1747b212011-02-20 15:08:12 +0800463 .proc_handler = proc_dointvec_minmax,
Mike Galbraith5091faa2010-11-30 14:18:03 +0100464 .extra1 = &zero,
465 .extra2 = &one,
466 },
467#endif
Paul Turnerec12cb72011-07-21 09:43:30 -0700468#ifdef CONFIG_CFS_BANDWIDTH
469 {
470 .procname = "sched_cfs_bandwidth_slice_us",
471 .data = &sysctl_sched_cfs_bandwidth_slice,
472 .maxlen = sizeof(unsigned int),
473 .mode = 0644,
474 .proc_handler = proc_dointvec_minmax,
475 .extra1 = &one,
476 },
477#endif
Quentin Perret8d5d0cf2018-12-03 09:56:23 +0000478#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
479 {
480 .procname = "sched_energy_aware",
481 .data = &sysctl_sched_energy_aware,
482 .maxlen = sizeof(unsigned int),
483 .mode = 0644,
484 .proc_handler = sched_energy_aware_handler,
485 .extra1 = &zero,
486 .extra2 = &one,
487 },
488#endif
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700489#ifdef CONFIG_PROVE_LOCKING
490 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700491 .procname = "prove_locking",
492 .data = &prove_locking,
493 .maxlen = sizeof(int),
494 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800495 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700496 },
497#endif
498#ifdef CONFIG_LOCK_STAT
499 {
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700500 .procname = "lock_stat",
501 .data = &lock_stat,
502 .maxlen = sizeof(int),
503 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800504 .proc_handler = proc_dointvec,
Peter Zijlstraf20786f2007-07-19 01:48:56 -0700505 },
506#endif
Ingo Molnar77e54a12007-07-09 18:52:00 +0200507 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 .procname = "panic",
509 .data = &panic_timeout,
510 .maxlen = sizeof(int),
511 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800512 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 },
Alex Kelly046d6622012-10-04 17:15:23 -0700514#ifdef CONFIG_COREDUMP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 .procname = "core_uses_pid",
517 .data = &core_uses_pid,
518 .maxlen = sizeof(int),
519 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800520 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 },
522 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 .procname = "core_pattern",
524 .data = core_pattern,
Dan Aloni71ce92f2007-05-16 22:11:16 -0700525 .maxlen = CORENAME_MAX_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -0700527 .proc_handler = proc_dostring_coredump,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 },
Neil Hormana2939802009-09-23 15:56:56 -0700529 {
Neil Hormana2939802009-09-23 15:56:56 -0700530 .procname = "core_pipe_limit",
531 .data = &core_pipe_limit,
532 .maxlen = sizeof(unsigned int),
533 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800534 .proc_handler = proc_dointvec,
Neil Hormana2939802009-09-23 15:56:56 -0700535 },
Alex Kelly046d6622012-10-04 17:15:23 -0700536#endif
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800537#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 .procname = "tainted",
Andi Kleen25ddbb12008-10-15 22:01:41 -0700540 .maxlen = sizeof(long),
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800541 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800542 .proc_handler = proc_taint,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 },
Kees Cookf4aacea2014-06-06 14:37:19 -0700544 {
545 .procname = "sysctl_writes_strict",
546 .data = &sysctl_writes_strict,
547 .maxlen = sizeof(int),
548 .mode = 0644,
549 .proc_handler = proc_dointvec_minmax,
550 .extra1 = &neg_one,
551 .extra2 = &one,
552 },
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800553#endif
Arjan van de Ven97455122008-01-25 21:08:34 +0100554#ifdef CONFIG_LATENCYTOP
555 {
556 .procname = "latencytop",
557 .data = &latencytop_enabled,
558 .maxlen = sizeof(int),
559 .mode = 0644,
Mel Gormancb251762016-02-05 09:08:36 +0000560 .proc_handler = sysctl_latencytop,
Arjan van de Ven97455122008-01-25 21:08:34 +0100561 },
562#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563#ifdef CONFIG_BLK_DEV_INITRD
564 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 .procname = "real-root-dev",
566 .data = &real_root_dev,
567 .maxlen = sizeof(int),
568 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800569 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 },
571#endif
Ingo Molnar45807a12007-07-15 23:40:10 -0700572 {
Ingo Molnar45807a12007-07-15 23:40:10 -0700573 .procname = "print-fatal-signals",
574 .data = &print_fatal_signals,
575 .maxlen = sizeof(int),
576 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800577 .proc_handler = proc_dointvec,
Ingo Molnar45807a12007-07-15 23:40:10 -0700578 },
David S. Miller72c57ed2008-09-11 23:29:54 -0700579#ifdef CONFIG_SPARC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 .procname = "reboot-cmd",
582 .data = reboot_command,
583 .maxlen = 256,
584 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800585 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 },
587 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 .procname = "stop-a",
589 .data = &stop_a_enabled,
590 .maxlen = sizeof (int),
591 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800592 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 },
594 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 .procname = "scons-poweroff",
596 .data = &scons_pwroff,
597 .maxlen = sizeof (int),
598 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800599 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 },
601#endif
David S. Miller08714202008-11-16 23:49:24 -0800602#ifdef CONFIG_SPARC64
603 {
David S. Miller08714202008-11-16 23:49:24 -0800604 .procname = "tsb-ratio",
605 .data = &sysctl_tsb_ratio,
606 .maxlen = sizeof (int),
607 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800608 .proc_handler = proc_dointvec,
David S. Miller08714202008-11-16 23:49:24 -0800609 },
610#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611#ifdef __hppa__
612 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 .procname = "soft-power",
614 .data = &pwrsw_enabled,
615 .maxlen = sizeof (int),
616 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800617 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 },
Vineet Guptabf14e3b2013-01-18 15:12:24 +0530619#endif
620#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 .procname = "unaligned-trap",
623 .data = &unaligned_enabled,
624 .maxlen = sizeof (int),
625 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800626 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 },
628#endif
629 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 .procname = "ctrl-alt-del",
631 .data = &C_A_D,
632 .maxlen = sizeof(int),
633 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800634 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 },
Steven Rostedt606576c2008-10-06 19:06:12 -0400636#ifdef CONFIG_FUNCTION_TRACER
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200637 {
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200638 .procname = "ftrace_enabled",
639 .data = &ftrace_enabled,
640 .maxlen = sizeof(int),
641 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800642 .proc_handler = ftrace_enable_sysctl,
Steven Rostedtb0fc4942008-05-12 21:20:43 +0200643 },
644#endif
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500645#ifdef CONFIG_STACK_TRACER
646 {
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500647 .procname = "stack_tracer_enabled",
648 .data = &stack_tracer_enabled,
649 .maxlen = sizeof(int),
650 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800651 .proc_handler = stack_trace_sysctl,
Steven Rostedtf38f1d22008-12-16 23:06:40 -0500652 },
653#endif
Steven Rostedt944ac422008-10-23 19:26:08 -0400654#ifdef CONFIG_TRACING
655 {
Peter Zijlstra3299b4d2008-11-04 11:58:21 +0100656 .procname = "ftrace_dump_on_oops",
Steven Rostedt944ac422008-10-23 19:26:08 -0400657 .data = &ftrace_dump_on_oops,
658 .maxlen = sizeof(int),
659 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800660 .proc_handler = proc_dointvec,
Steven Rostedt944ac422008-10-23 19:26:08 -0400661 },
Steven Rostedt (Red Hat)de7edd32013-06-14 16:21:43 -0400662 {
663 .procname = "traceoff_on_warning",
664 .data = &__disable_trace_on_warning,
665 .maxlen = sizeof(__disable_trace_on_warning),
666 .mode = 0644,
667 .proc_handler = proc_dointvec,
668 },
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500669 {
670 .procname = "tracepoint_printk",
671 .data = &tracepoint_printk,
672 .maxlen = sizeof(tracepoint_printk),
673 .mode = 0644,
Steven Rostedt (Red Hat)423917452016-11-23 15:52:45 -0500674 .proc_handler = tracepoint_printk_sysctl,
Steven Rostedt (Red Hat)0daa23022014-12-12 22:27:10 -0500675 },
Steven Rostedt944ac422008-10-23 19:26:08 -0400676#endif
Dave Young2965faa2015-09-09 15:38:55 -0700677#ifdef CONFIG_KEXEC_CORE
Kees Cook79847542014-01-23 15:55:59 -0800678 {
679 .procname = "kexec_load_disabled",
680 .data = &kexec_load_disabled,
681 .maxlen = sizeof(int),
682 .mode = 0644,
683 /* only handle a transition from default "0" to "1" */
684 .proc_handler = proc_dointvec_minmax,
685 .extra1 = &one,
686 .extra2 = &one,
687 },
688#endif
Johannes Berga1ef5ad2008-07-08 19:00:17 +0200689#ifdef CONFIG_MODULES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 .procname = "modprobe",
692 .data = &modprobe_path,
693 .maxlen = KMOD_PATH_LEN,
694 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800695 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 },
Kees Cook3d433212009-04-02 15:49:29 -0700697 {
Kees Cook3d433212009-04-02 15:49:29 -0700698 .procname = "modules_disabled",
699 .data = &modules_disabled,
700 .maxlen = sizeof(int),
701 .mode = 0644,
702 /* only handle a transition from default "0" to "1" */
Eric W. Biederman6d456112009-11-16 03:11:48 -0800703 .proc_handler = proc_dointvec_minmax,
Kees Cook3d433212009-04-02 15:49:29 -0700704 .extra1 = &one,
705 .extra2 = &one,
706 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707#endif
Michael Marineau86d56132014-04-10 14:09:31 -0700708#ifdef CONFIG_UEVENT_HELPER
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 .procname = "hotplug",
Kay Sievers312c0042005-11-16 09:00:00 +0100711 .data = &uevent_helper,
712 .maxlen = UEVENT_HELPER_PATH_LEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800714 .proc_handler = proc_dostring,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 },
Michael Marineau86d56132014-04-10 14:09:31 -0700716#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717#ifdef CONFIG_CHR_DEV_SG
718 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 .procname = "sg-big-buff",
720 .data = &sg_big_buff,
721 .maxlen = sizeof (int),
722 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800723 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 },
725#endif
726#ifdef CONFIG_BSD_PROCESS_ACCT
727 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 .procname = "acct",
729 .data = &acct_parm,
730 .maxlen = 3*sizeof(int),
731 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800732 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 },
734#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735#ifdef CONFIG_MAGIC_SYSRQ
736 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 .procname = "sysrq",
Ingo Molnar5d6f6472006-12-13 00:34:36 -0800738 .data = &__sysrq_enabled,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 .maxlen = sizeof (int),
740 .mode = 0644,
Dmitry Torokhov97f5f0c2010-03-21 22:31:26 -0700741 .proc_handler = sysrq_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 },
743#endif
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700744#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 .procname = "cad_pid",
Cedric Le Goater9ec52092006-10-02 02:19:00 -0700747 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 .maxlen = sizeof (int),
749 .mode = 0600,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800750 .proc_handler = proc_do_cad_pid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 },
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700752#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 .procname = "threads-max",
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700755 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 .maxlen = sizeof(int),
757 .mode = 0644,
Heinrich Schuchardt16db3d32015-04-16 12:47:50 -0700758 .proc_handler = sysctl_max_threads,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 },
760 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 .procname = "random",
762 .mode = 0555,
763 .child = random_table,
764 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 {
Eric Paris17f60a72011-04-01 17:07:50 -0400766 .procname = "usermodehelper",
767 .mode = 0555,
768 .child = usermodehelper_table,
769 },
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800770#ifdef CONFIG_FW_LOADER_USER_HELPER
771 {
772 .procname = "firmware_config",
773 .mode = 0555,
774 .child = firmware_config_table,
775 },
776#endif
Eric Paris17f60a72011-04-01 17:07:50 -0400777 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 .procname = "overflowuid",
779 .data = &overflowuid,
780 .maxlen = sizeof(int),
781 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800782 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 .extra1 = &minolduid,
784 .extra2 = &maxolduid,
785 },
786 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 .procname = "overflowgid",
788 .data = &overflowgid,
789 .maxlen = sizeof(int),
790 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800791 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 .extra1 = &minolduid,
793 .extra2 = &maxolduid,
794 },
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800795#ifdef CONFIG_S390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796#ifdef CONFIG_MATHEMU
797 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 .procname = "ieee_emulation_warnings",
799 .data = &sysctl_ieee_emulation_warnings,
800 .maxlen = sizeof(int),
801 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800802 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 },
804#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 .procname = "userprocess_debug",
Heiko Carstensab3c68e2010-05-17 10:00:21 +0200807 .data = &show_unhandled_signals,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 .maxlen = sizeof(int),
809 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800810 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 },
812#endif
813 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 .procname = "pid_max",
815 .data = &pid_max,
816 .maxlen = sizeof (int),
817 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800818 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 .extra1 = &pid_max_min,
820 .extra2 = &pid_max_max,
821 },
822 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 .procname = "panic_on_oops",
824 .data = &panic_on_oops,
825 .maxlen = sizeof(int),
826 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800827 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 },
Feng Tang81c9d432019-01-03 15:28:20 -0800829 {
830 .procname = "panic_print",
831 .data = &panic_print,
832 .maxlen = sizeof(unsigned long),
833 .mode = 0644,
834 .proc_handler = proc_doulongvec_minmax,
835 },
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800836#if defined CONFIG_PRINTK
837 {
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800838 .procname = "printk",
839 .data = &console_loglevel,
840 .maxlen = 4*sizeof(int),
841 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800842 .proc_handler = proc_dointvec,
Joe Perches7ef3d2f2008-02-08 04:21:25 -0800843 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 .procname = "printk_ratelimit",
Dave Young717115e2008-07-25 01:45:58 -0700846 .data = &printk_ratelimit_state.interval,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 .maxlen = sizeof(int),
848 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800849 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 },
851 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 .procname = "printk_ratelimit_burst",
Dave Young717115e2008-07-25 01:45:58 -0700853 .data = &printk_ratelimit_state.burst,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 .maxlen = sizeof(int),
855 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800856 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 },
Dave Youngaf913222009-09-22 16:43:33 -0700858 {
Dave Youngaf913222009-09-22 16:43:33 -0700859 .procname = "printk_delay",
860 .data = &printk_delay_msec,
861 .maxlen = sizeof(int),
862 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800863 .proc_handler = proc_dointvec_minmax,
Dave Youngaf913222009-09-22 16:43:33 -0700864 .extra1 = &zero,
865 .extra2 = &ten_thousand,
866 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 {
Borislav Petkov750afe72016-08-02 14:04:07 -0700868 .procname = "printk_devkmsg",
869 .data = devkmsg_log_str,
870 .maxlen = DEVKMSG_STR_MAX_SIZE,
871 .mode = 0644,
872 .proc_handler = devkmsg_sysctl_set_loglvl,
873 },
874 {
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800875 .procname = "dmesg_restrict",
876 .data = &dmesg_restrict,
877 .maxlen = sizeof(int),
878 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700879 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800880 .extra1 = &zero,
881 .extra2 = &one,
882 },
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800883 {
884 .procname = "kptr_restrict",
885 .data = &kptr_restrict,
886 .maxlen = sizeof(int),
887 .mode = 0644,
Kees Cook620f6e82012-04-04 11:40:19 -0700888 .proc_handler = proc_dointvec_minmax_sysadmin,
Dan Rosenberg455cd5a2011-01-12 16:59:41 -0800889 .extra1 = &zero,
890 .extra2 = &two,
891 },
Joe Perchesdf6e61d2010-11-15 21:17:27 -0800892#endif
Dan Rosenbergeaf06b22010-11-11 14:05:18 -0800893 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 .procname = "ngroups_max",
895 .data = &ngroups_max,
896 .maxlen = sizeof (int),
897 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800898 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 },
Dan Ballard73efc032011-10-31 17:11:20 -0700900 {
901 .procname = "cap_last_cap",
902 .data = (void *)&cap_last_cap,
903 .maxlen = sizeof(int),
904 .mode = 0444,
905 .proc_handler = proc_dointvec,
906 },
Don Zickus58687ac2010-05-07 17:11:44 -0400907#if defined(CONFIG_LOCKUP_DETECTOR)
Don Zickus504d7cf2010-02-12 17:19:19 -0500908 {
Don Zickus58687ac2010-05-07 17:11:44 -0400909 .procname = "watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200910 .data = &watchdog_user_enabled,
911 .maxlen = sizeof(int),
912 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700913 .proc_handler = proc_watchdog,
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700914 .extra1 = &zero,
915 .extra2 = &one,
Don Zickus58687ac2010-05-07 17:11:44 -0400916 },
917 {
918 .procname = "watchdog_thresh",
Mandeep Singh Baines586692a2011-05-22 22:10:22 -0700919 .data = &watchdog_thresh,
Don Zickus58687ac2010-05-07 17:11:44 -0400920 .maxlen = sizeof(int),
921 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700922 .proc_handler = proc_watchdog_thresh,
Li Zefana6572f82013-05-17 10:31:04 +0800923 .extra1 = &zero,
Don Zickus58687ac2010-05-07 17:11:44 -0400924 .extra2 = &sixty,
Don Zickus504d7cf2010-02-12 17:19:19 -0500925 },
Don Zickus2508ce12010-05-07 17:11:46 -0400926 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700927 .procname = "nmi_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200928 .data = &nmi_watchdog_user_enabled,
929 .maxlen = sizeof(int),
Thomas Gleixner51d40522017-09-12 21:37:14 +0200930 .mode = NMI_WATCHDOG_SYSCTL_PERM,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700931 .proc_handler = proc_nmi_watchdog,
932 .extra1 = &zero,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700933 .extra2 = &one,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700934 },
935 {
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700936 .procname = "watchdog_cpumask",
937 .data = &watchdog_cpumask_bits,
938 .maxlen = NR_CPUS,
939 .mode = 0644,
940 .proc_handler = proc_watchdog_cpumask,
941 },
942#ifdef CONFIG_SOFTLOCKUP_DETECTOR
943 {
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700944 .procname = "soft_watchdog",
Thomas Gleixner7feeb9c2017-09-12 21:37:15 +0200945 .data = &soft_watchdog_user_enabled,
946 .maxlen = sizeof(int),
947 .mode = 0644,
Ulrich Obergfell195daf62015-04-14 15:44:13 -0700948 .proc_handler = proc_soft_watchdog,
949 .extra1 = &zero,
950 .extra2 = &one,
951 },
952 {
Don Zickus2508ce12010-05-07 17:11:46 -0400953 .procname = "softlockup_panic",
954 .data = &softlockup_panic,
955 .maxlen = sizeof(int),
956 .mode = 0644,
957 .proc_handler = proc_dointvec_minmax,
958 .extra1 = &zero,
959 .extra2 = &one,
960 },
Aaron Tomlined235872014-06-23 13:22:05 -0700961#ifdef CONFIG_SMP
962 {
963 .procname = "softlockup_all_cpu_backtrace",
964 .data = &sysctl_softlockup_all_cpu_backtrace,
965 .maxlen = sizeof(int),
966 .mode = 0644,
967 .proc_handler = proc_dointvec_minmax,
968 .extra1 = &zero,
969 .extra2 = &one,
970 },
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700971#endif /* CONFIG_SMP */
972#endif
973#ifdef CONFIG_HARDLOCKUP_DETECTOR
974 {
975 .procname = "hardlockup_panic",
976 .data = &hardlockup_panic,
977 .maxlen = sizeof(int),
978 .mode = 0644,
979 .proc_handler = proc_dointvec_minmax,
980 .extra1 = &zero,
981 .extra2 = &one,
982 },
983#ifdef CONFIG_SMP
Jiri Kosina55537872015-11-05 18:44:41 -0800984 {
985 .procname = "hardlockup_all_cpu_backtrace",
986 .data = &sysctl_hardlockup_all_cpu_backtrace,
987 .maxlen = sizeof(int),
988 .mode = 0644,
989 .proc_handler = proc_dointvec_minmax,
990 .extra1 = &zero,
991 .extra2 = &one,
992 },
Aaron Tomlined235872014-06-23 13:22:05 -0700993#endif /* CONFIG_SMP */
Don Zickus5dc30552010-11-29 17:07:17 -0500994#endif
Nicholas Piggin05a4a952017-07-12 14:35:46 -0700995#endif
996
Don Zickus5dc30552010-11-29 17:07:17 -0500997#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
998 {
999 .procname = "unknown_nmi_panic",
1000 .data = &unknown_nmi_panic,
1001 .maxlen = sizeof (int),
1002 .mode = 0644,
1003 .proc_handler = proc_dointvec,
1004 },
Don Zickus504d7cf2010-02-12 17:19:19 -05001005#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006#if defined(CONFIG_X86)
1007 {
Don Zickus8da5add2006-09-26 10:52:27 +02001008 .procname = "panic_on_unrecovered_nmi",
1009 .data = &panic_on_unrecovered_nmi,
1010 .maxlen = sizeof(int),
1011 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001012 .proc_handler = proc_dointvec,
Don Zickus8da5add2006-09-26 10:52:27 +02001013 },
1014 {
Kurt Garloff5211a242009-06-24 14:32:11 -07001015 .procname = "panic_on_io_nmi",
1016 .data = &panic_on_io_nmi,
1017 .maxlen = sizeof(int),
1018 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001019 .proc_handler = proc_dointvec,
Kurt Garloff5211a242009-06-24 14:32:11 -07001020 },
Mitsuo Hayasaka55af7792011-11-29 15:08:36 +09001021#ifdef CONFIG_DEBUG_STACKOVERFLOW
1022 {
1023 .procname = "panic_on_stackoverflow",
1024 .data = &sysctl_panic_on_stackoverflow,
1025 .maxlen = sizeof(int),
1026 .mode = 0644,
1027 .proc_handler = proc_dointvec,
1028 },
1029#endif
Kurt Garloff5211a242009-06-24 14:32:11 -07001030 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 .procname = "bootloader_type",
1032 .data = &bootloader_type,
1033 .maxlen = sizeof (int),
1034 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001035 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 },
Chuck Ebbert0741f4d2006-12-07 02:14:11 +01001037 {
H. Peter Anvin50312962009-05-07 16:54:11 -07001038 .procname = "bootloader_version",
1039 .data = &bootloader_version,
1040 .maxlen = sizeof (int),
1041 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001042 .proc_handler = proc_dointvec,
H. Peter Anvin50312962009-05-07 16:54:11 -07001043 },
1044 {
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001045 .procname = "io_delay_type",
1046 .data = &io_delay_type,
1047 .maxlen = sizeof(int),
1048 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001049 .proc_handler = proc_dointvec,
Ingo Molnar6e7c4022008-01-30 13:30:05 +01001050 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051#endif
Luke Yang7a9166e2006-02-20 18:28:07 -08001052#if defined(CONFIG_MMU)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 .procname = "randomize_va_space",
1055 .data = &randomize_va_space,
1056 .maxlen = sizeof(int),
1057 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001058 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 },
Luke Yang7a9166e2006-02-20 18:28:07 -08001060#endif
Martin Schwidefsky0152fb32006-01-14 13:21:00 -08001061#if defined(CONFIG_S390) && defined(CONFIG_SMP)
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001062 {
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001063 .procname = "spin_retry",
1064 .data = &spin_retry,
1065 .maxlen = sizeof (int),
1066 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001067 .proc_handler = proc_dointvec,
Martin Schwidefsky951f22d2005-07-27 11:44:57 -07001068 },
1069#endif
Len Brown673d5b42007-07-28 03:33:16 -04001070#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
Pavel Machekc255d842006-02-20 18:27:58 -08001071 {
Pavel Machekc255d842006-02-20 18:27:58 -08001072 .procname = "acpi_video_flags",
Pavel Machek77afcf72007-07-19 01:47:41 -07001073 .data = &acpi_realmode_flags,
Pavel Machekc255d842006-02-20 18:27:58 -08001074 .maxlen = sizeof (unsigned long),
1075 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001076 .proc_handler = proc_doulongvec_minmax,
Pavel Machekc255d842006-02-20 18:27:58 -08001077 },
1078#endif
Vineet Guptab6fca722013-01-09 20:06:28 +05301079#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
Jes Sorensend2b176e2006-02-28 09:42:23 -08001080 {
Jes Sorensend2b176e2006-02-28 09:42:23 -08001081 .procname = "ignore-unaligned-usertrap",
1082 .data = &no_unaligned_warning,
1083 .maxlen = sizeof (int),
1084 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001085 .proc_handler = proc_dointvec,
Jes Sorensend2b176e2006-02-28 09:42:23 -08001086 },
Vineet Guptab6fca722013-01-09 20:06:28 +05301087#endif
1088#ifdef CONFIG_IA64
Doug Chapman88fc2412009-01-15 10:38:56 -08001089 {
Doug Chapman88fc2412009-01-15 10:38:56 -08001090 .procname = "unaligned-dump-stack",
1091 .data = &unaligned_dump_stack,
1092 .maxlen = sizeof (int),
1093 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001094 .proc_handler = proc_dointvec,
Doug Chapman88fc2412009-01-15 10:38:56 -08001095 },
Jes Sorensend2b176e2006-02-28 09:42:23 -08001096#endif
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001097#ifdef CONFIG_DETECT_HUNG_TASK
1098 {
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001099 .procname = "hung_task_panic",
1100 .data = &sysctl_hung_task_panic,
1101 .maxlen = sizeof(int),
1102 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001103 .proc_handler = proc_dointvec_minmax,
Mandeep Singh Bainese162b392009-01-15 11:08:40 -08001104 .extra1 = &zero,
1105 .extra2 = &one,
1106 },
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001107 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001108 .procname = "hung_task_check_count",
1109 .data = &sysctl_hung_task_check_count,
Li Zefancd646472013-09-23 16:43:58 +08001110 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001111 .mode = 0644,
Li Zefancd646472013-09-23 16:43:58 +08001112 .proc_handler = proc_dointvec_minmax,
1113 .extra1 = &zero,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001114 },
1115 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001116 .procname = "hung_task_timeout_secs",
1117 .data = &sysctl_hung_task_timeout_secs,
Ingo Molnar90739082008-01-25 21:08:34 +01001118 .maxlen = sizeof(unsigned long),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001119 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001120 .proc_handler = proc_dohung_task_timeout_secs,
Liu Hua80df2842014-04-07 15:38:57 -07001121 .extra2 = &hung_task_timeout_max,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001122 },
1123 {
Dmitry Vyukova2e51442018-08-21 21:55:52 -07001124 .procname = "hung_task_check_interval_secs",
1125 .data = &sysctl_hung_task_check_interval_secs,
1126 .maxlen = sizeof(unsigned long),
1127 .mode = 0644,
1128 .proc_handler = proc_dohung_task_timeout_secs,
1129 .extra2 = &hung_task_timeout_max,
1130 },
1131 {
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001132 .procname = "hung_task_warnings",
1133 .data = &sysctl_hung_task_warnings,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001134 .maxlen = sizeof(int),
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001135 .mode = 0644,
Aaron Tomlin270750db2014-01-20 17:34:13 +00001136 .proc_handler = proc_dointvec_minmax,
1137 .extra1 = &neg_one,
Ingo Molnar82a1fcb2008-01-25 21:08:02 +01001138 },
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -07001139#endif
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001140#ifdef CONFIG_RT_MUTEXES
1141 {
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001142 .procname = "max_lock_depth",
1143 .data = &max_lock_depth,
1144 .maxlen = sizeof(int),
1145 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001146 .proc_handler = proc_dointvec,
Ingo Molnar23f78d4a2006-06-27 02:54:53 -07001147 },
1148#endif
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001149 {
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001150 .procname = "poweroff_cmd",
1151 .data = &poweroff_cmd,
1152 .maxlen = POWEROFF_CMD_PATH_LEN,
1153 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001154 .proc_handler = proc_dostring,
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -07001155 },
David Howells0b77f5b2008-04-29 01:01:32 -07001156#ifdef CONFIG_KEYS
1157 {
David Howells0b77f5b2008-04-29 01:01:32 -07001158 .procname = "keys",
1159 .mode = 0555,
1160 .child = key_sysctls,
1161 },
1162#endif
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001163#ifdef CONFIG_PERF_EVENTS
Vince Weaveraa4a2212011-06-03 17:54:40 -04001164 /*
1165 * User-space scripts rely on the existence of this file
1166 * as a feature check for perf_events being enabled.
1167 *
1168 * So it's an ABI, do not remove!
1169 */
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001170 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001171 .procname = "perf_event_paranoid",
1172 .data = &sysctl_perf_event_paranoid,
1173 .maxlen = sizeof(sysctl_perf_event_paranoid),
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001174 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001175 .proc_handler = proc_dointvec,
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001176 },
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001177 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001178 .procname = "perf_event_mlock_kb",
1179 .data = &sysctl_perf_event_mlock,
1180 .maxlen = sizeof(sysctl_perf_event_mlock),
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001181 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001182 .proc_handler = proc_dointvec,
Peter Zijlstrac5078f72009-05-05 17:50:24 +02001183 },
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001184 {
Ingo Molnarcdd6c482009-09-21 12:02:48 +02001185 .procname = "perf_event_max_sample_rate",
1186 .data = &sysctl_perf_event_sample_rate,
1187 .maxlen = sizeof(sysctl_perf_event_sample_rate),
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001188 .mode = 0644,
Peter Zijlstra163ec432011-02-16 11:22:34 +01001189 .proc_handler = perf_proc_update_handler,
Knut Petersen723478c2013-09-25 14:29:37 +02001190 .extra1 = &one,
Peter Zijlstraa78ac322009-05-25 17:39:05 +02001191 },
Dave Hansen14c63f12013-06-21 08:51:36 -07001192 {
1193 .procname = "perf_cpu_time_max_percent",
1194 .data = &sysctl_perf_cpu_time_max_percent,
1195 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1196 .mode = 0644,
1197 .proc_handler = perf_cpu_time_max_percent_handler,
1198 .extra1 = &zero,
1199 .extra2 = &one_hundred,
1200 },
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001201 {
1202 .procname = "perf_event_max_stack",
Arnaldo Carvalho de Meloa8311002016-05-10 16:34:53 -03001203 .data = &sysctl_perf_event_max_stack,
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -03001204 .maxlen = sizeof(sysctl_perf_event_max_stack),
1205 .mode = 0644,
1206 .proc_handler = perf_event_max_stack_handler,
1207 .extra1 = &zero,
1208 .extra2 = &six_hundred_forty_kb,
1209 },
Arnaldo Carvalho de Meloc85b0332016-05-12 13:06:21 -03001210 {
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),
1214 .mode = 0644,
1215 .proc_handler = perf_event_max_stack_handler,
1216 .extra1 = &zero,
1217 .extra2 = &one_thousand,
1218 },
Peter Zijlstra1ccd1542009-04-09 10:53:45 +02001219#endif
Prarit Bhargava9e3961a2014-12-10 15:45:50 -08001220 {
1221 .procname = "panic_on_warn",
1222 .data = &panic_on_warn,
1223 .maxlen = sizeof(int),
1224 .mode = 0644,
1225 .proc_handler = proc_dointvec_minmax,
1226 .extra1 = &zero,
1227 .extra2 = &one,
1228 },
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001229#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1230 {
1231 .procname = "timer_migration",
1232 .data = &sysctl_timer_migration,
1233 .maxlen = sizeof(unsigned int),
1234 .mode = 0644,
1235 .proc_handler = timer_migration_handler,
Myungho Jungb94bf592017-04-19 15:24:50 -07001236 .extra1 = &zero,
1237 .extra2 = &one,
Thomas Gleixnerbc7a34b2015-05-26 22:50:33 +00001238 },
1239#endif
Alexei Starovoitov1be7f752015-10-07 22:23:21 -07001240#ifdef CONFIG_BPF_SYSCALL
1241 {
1242 .procname = "unprivileged_bpf_disabled",
1243 .data = &sysctl_unprivileged_bpf_disabled,
1244 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
1245 .mode = 0644,
1246 /* only handle a transition from default "0" to "1" */
1247 .proc_handler = proc_dointvec_minmax,
1248 .extra1 = &one,
1249 .extra2 = &one,
1250 },
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001251 {
1252 .procname = "bpf_stats_enabled",
1253 .data = &sysctl_bpf_stats_enabled,
1254 .maxlen = sizeof(sysctl_bpf_stats_enabled),
1255 .mode = 0644,
1256 .proc_handler = proc_dointvec_minmax_bpf_stats,
1257 .extra1 = &zero,
1258 .extra2 = &one,
1259 },
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -08001260#endif
Daniel Bristot de Oliveira088e9d22016-06-02 13:51:41 -03001261#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1262 {
1263 .procname = "panic_on_rcu_stall",
1264 .data = &sysctl_panic_on_rcu_stall,
1265 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
1266 .mode = 0644,
1267 .proc_handler = proc_dointvec_minmax,
1268 .extra1 = &zero,
1269 .extra2 = &one,
1270 },
1271#endif
Alexander Popov964c9df2018-08-17 01:17:03 +03001272#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1273 {
1274 .procname = "stack_erasing",
1275 .data = NULL,
1276 .maxlen = sizeof(int),
1277 .mode = 0600,
1278 .proc_handler = stack_erasing_sysctl,
1279 .extra1 = &zero,
1280 .extra2 = &one,
1281 },
1282#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001283 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284};
1285
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001286static struct ctl_table vm_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 .procname = "overcommit_memory",
1289 .data = &sysctl_overcommit_memory,
1290 .maxlen = sizeof(sysctl_overcommit_memory),
1291 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001292 .proc_handler = proc_dointvec_minmax,
1293 .extra1 = &zero,
1294 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 },
1296 {
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001297 .procname = "panic_on_oom",
1298 .data = &sysctl_panic_on_oom,
1299 .maxlen = sizeof(sysctl_panic_on_oom),
1300 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001301 .proc_handler = proc_dointvec_minmax,
1302 .extra1 = &zero,
1303 .extra2 = &two,
KAMEZAWA Hiroyukifadd8fb2006-06-23 02:03:13 -07001304 },
1305 {
David Rientjesfe071d72007-10-16 23:25:56 -07001306 .procname = "oom_kill_allocating_task",
1307 .data = &sysctl_oom_kill_allocating_task,
1308 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1309 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001310 .proc_handler = proc_dointvec,
David Rientjesfe071d72007-10-16 23:25:56 -07001311 },
1312 {
David Rientjesfef1bdd2008-02-07 00:14:07 -08001313 .procname = "oom_dump_tasks",
1314 .data = &sysctl_oom_dump_tasks,
1315 .maxlen = sizeof(sysctl_oom_dump_tasks),
1316 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001317 .proc_handler = proc_dointvec,
David Rientjesfef1bdd2008-02-07 00:14:07 -08001318 },
1319 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 .procname = "overcommit_ratio",
1321 .data = &sysctl_overcommit_ratio,
1322 .maxlen = sizeof(sysctl_overcommit_ratio),
1323 .mode = 0644,
Jerome Marchand49f0ce52014-01-21 15:49:14 -08001324 .proc_handler = overcommit_ratio_handler,
1325 },
1326 {
1327 .procname = "overcommit_kbytes",
1328 .data = &sysctl_overcommit_kbytes,
1329 .maxlen = sizeof(sysctl_overcommit_kbytes),
1330 .mode = 0644,
1331 .proc_handler = overcommit_kbytes_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 },
1333 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 .procname = "page-cluster",
1335 .data = &page_cluster,
1336 .maxlen = sizeof(int),
1337 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001338 .proc_handler = proc_dointvec_minmax,
1339 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 },
1341 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 .procname = "dirty_background_ratio",
1343 .data = &dirty_background_ratio,
1344 .maxlen = sizeof(dirty_background_ratio),
1345 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001346 .proc_handler = dirty_background_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 .extra1 = &zero,
1348 .extra2 = &one_hundred,
1349 },
1350 {
David Rientjes2da02992009-01-06 14:39:31 -08001351 .procname = "dirty_background_bytes",
1352 .data = &dirty_background_bytes,
1353 .maxlen = sizeof(dirty_background_bytes),
1354 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001355 .proc_handler = dirty_background_bytes_handler,
Sven Wegenerfc3501d2009-02-11 13:04:23 -08001356 .extra1 = &one_ul,
David Rientjes2da02992009-01-06 14:39:31 -08001357 },
1358 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 .procname = "dirty_ratio",
1360 .data = &vm_dirty_ratio,
1361 .maxlen = sizeof(vm_dirty_ratio),
1362 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001363 .proc_handler = dirty_ratio_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 .extra1 = &zero,
1365 .extra2 = &one_hundred,
1366 },
1367 {
David Rientjes2da02992009-01-06 14:39:31 -08001368 .procname = "dirty_bytes",
1369 .data = &vm_dirty_bytes,
1370 .maxlen = sizeof(vm_dirty_bytes),
1371 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001372 .proc_handler = dirty_bytes_handler,
Andrea Righi9e4a5bd2009-04-30 15:08:57 -07001373 .extra1 = &dirty_bytes_min,
David Rientjes2da02992009-01-06 14:39:31 -08001374 },
1375 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 .procname = "dirty_writeback_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001377 .data = &dirty_writeback_interval,
1378 .maxlen = sizeof(dirty_writeback_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001380 .proc_handler = dirty_writeback_centisecs_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 },
1382 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 .procname = "dirty_expire_centisecs",
Bart Samwelf6ef9432006-03-24 03:15:48 -08001384 .data = &dirty_expire_interval,
1385 .maxlen = sizeof(dirty_expire_interval),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 .mode = 0644,
Petr Holasekcb16e952011-03-23 16:43:09 -07001387 .proc_handler = proc_dointvec_minmax,
1388 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 },
1390 {
Theodore Ts'o1efff912015-03-17 12:23:32 -04001391 .procname = "dirtytime_expire_seconds",
1392 .data = &dirtytime_expire_interval,
Randy Dunlap2d87b302018-04-10 16:35:14 -07001393 .maxlen = sizeof(dirtytime_expire_interval),
Theodore Ts'o1efff912015-03-17 12:23:32 -04001394 .mode = 0644,
1395 .proc_handler = dirtytime_interval_handler,
1396 .extra1 = &zero,
1397 },
1398 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 .procname = "swappiness",
1400 .data = &vm_swappiness,
1401 .maxlen = sizeof(vm_swappiness),
1402 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001403 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 .extra1 = &zero,
1405 .extra2 = &one_hundred,
1406 },
1407#ifdef CONFIG_HUGETLB_PAGE
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001408 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 .procname = "nr_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001410 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 .maxlen = sizeof(unsigned long),
1412 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001413 .proc_handler = hugetlb_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001414 },
1415#ifdef CONFIG_NUMA
1416 {
1417 .procname = "nr_hugepages_mempolicy",
1418 .data = NULL,
1419 .maxlen = sizeof(unsigned long),
1420 .mode = 0644,
1421 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001422 },
Kemi Wang45180852017-11-15 17:38:22 -08001423 {
1424 .procname = "numa_stat",
1425 .data = &sysctl_vm_numa_stat,
1426 .maxlen = sizeof(int),
1427 .mode = 0644,
1428 .proc_handler = sysctl_vm_numa_stat_handler,
1429 .extra1 = &zero,
1430 .extra2 = &one,
1431 },
Lee Schermerhorn06808b02009-12-14 17:58:21 -08001432#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 .procname = "hugetlb_shm_group",
1435 .data = &sysctl_hugetlb_shm_group,
1436 .maxlen = sizeof(gid_t),
1437 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001438 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 },
Adam Litke54f9f802007-10-16 01:26:20 -07001440 {
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001441 .procname = "nr_overcommit_hugepages",
Andi Kleene5ff2152008-07-23 21:27:42 -07001442 .data = NULL,
1443 .maxlen = sizeof(unsigned long),
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001444 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001445 .proc_handler = hugetlb_overcommit_handler,
Nishanth Aravamudand1c3fb12007-12-17 16:20:12 -08001446 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447#endif
1448 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 .procname = "lowmem_reserve_ratio",
1450 .data = &sysctl_lowmem_reserve_ratio,
1451 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1452 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001453 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 },
1455 {
Andrew Morton9d0243b2006-01-08 01:00:39 -08001456 .procname = "drop_caches",
1457 .data = &sysctl_drop_caches,
1458 .maxlen = sizeof(int),
1459 .mode = 0644,
1460 .proc_handler = drop_caches_sysctl_handler,
Petr Holasekcb16e952011-03-23 16:43:09 -07001461 .extra1 = &one,
Dave Hansen5509a5d2014-04-03 14:48:19 -07001462 .extra2 = &four,
Andrew Morton9d0243b2006-01-08 01:00:39 -08001463 },
Mel Gorman76ab0f52010-05-24 14:32:28 -07001464#ifdef CONFIG_COMPACTION
1465 {
1466 .procname = "compact_memory",
1467 .data = &sysctl_compact_memory,
1468 .maxlen = sizeof(int),
1469 .mode = 0200,
1470 .proc_handler = sysctl_compaction_handler,
1471 },
Mel Gorman5e771902010-05-24 14:32:31 -07001472 {
1473 .procname = "extfrag_threshold",
1474 .data = &sysctl_extfrag_threshold,
1475 .maxlen = sizeof(int),
1476 .mode = 0644,
Matthew Wilcox6b7e5ca2019-03-05 15:43:41 -08001477 .proc_handler = proc_dointvec_minmax,
Mel Gorman5e771902010-05-24 14:32:31 -07001478 .extra1 = &min_extfrag_threshold,
1479 .extra2 = &max_extfrag_threshold,
1480 },
Eric B Munson5bbe3542015-04-15 16:13:20 -07001481 {
1482 .procname = "compact_unevictable_allowed",
1483 .data = &sysctl_compact_unevictable_allowed,
1484 .maxlen = sizeof(int),
1485 .mode = 0644,
1486 .proc_handler = proc_dointvec,
1487 .extra1 = &zero,
1488 .extra2 = &one,
1489 },
Mel Gorman5e771902010-05-24 14:32:31 -07001490
Mel Gorman76ab0f52010-05-24 14:32:28 -07001491#endif /* CONFIG_COMPACTION */
Andrew Morton9d0243b2006-01-08 01:00:39 -08001492 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 .procname = "min_free_kbytes",
1494 .data = &min_free_kbytes,
1495 .maxlen = sizeof(min_free_kbytes),
1496 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001497 .proc_handler = min_free_kbytes_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 .extra1 = &zero,
1499 },
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001500 {
Mel Gorman1c308442018-12-28 00:35:52 -08001501 .procname = "watermark_boost_factor",
1502 .data = &watermark_boost_factor,
1503 .maxlen = sizeof(watermark_boost_factor),
1504 .mode = 0644,
1505 .proc_handler = watermark_boost_factor_sysctl_handler,
1506 .extra1 = &zero,
1507 },
1508 {
Johannes Weiner795ae7a2016-03-17 14:19:14 -07001509 .procname = "watermark_scale_factor",
1510 .data = &watermark_scale_factor,
1511 .maxlen = sizeof(watermark_scale_factor),
1512 .mode = 0644,
1513 .proc_handler = watermark_scale_factor_sysctl_handler,
1514 .extra1 = &one,
1515 .extra2 = &one_thousand,
1516 },
1517 {
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001518 .procname = "percpu_pagelist_fraction",
1519 .data = &percpu_pagelist_fraction,
1520 .maxlen = sizeof(percpu_pagelist_fraction),
1521 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001522 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
David Rientjes7cd2b0a2014-06-23 13:22:04 -07001523 .extra1 = &zero,
Rohit Seth8ad4b1f2006-01-08 01:00:40 -08001524 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525#ifdef CONFIG_MMU
1526 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 .procname = "max_map_count",
1528 .data = &sysctl_max_map_count,
1529 .maxlen = sizeof(sysctl_max_map_count),
1530 .mode = 0644,
WANG Cong3e261202009-12-17 15:27:05 -08001531 .proc_handler = proc_dointvec_minmax,
Amerigo Wang70da2342009-12-14 17:59:52 -08001532 .extra1 = &zero,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 },
Paul Mundtdd8632a2009-01-08 12:04:47 +00001534#else
1535 {
Paul Mundtdd8632a2009-01-08 12:04:47 +00001536 .procname = "nr_trim_pages",
1537 .data = &sysctl_nr_trim_pages,
1538 .maxlen = sizeof(sysctl_nr_trim_pages),
1539 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001540 .proc_handler = proc_dointvec_minmax,
Paul Mundtdd8632a2009-01-08 12:04:47 +00001541 .extra1 = &zero,
1542 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543#endif
1544 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 .procname = "laptop_mode",
1546 .data = &laptop_mode,
1547 .maxlen = sizeof(laptop_mode),
1548 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001549 .proc_handler = proc_dointvec_jiffies,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 },
1551 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 .procname = "block_dump",
1553 .data = &block_dump,
1554 .maxlen = sizeof(block_dump),
1555 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001556 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 .extra1 = &zero,
1558 },
1559 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 .procname = "vfs_cache_pressure",
1561 .data = &sysctl_vfs_cache_pressure,
1562 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1563 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001564 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 .extra1 = &zero,
1566 },
1567#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1568 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 .procname = "legacy_va_layout",
1570 .data = &sysctl_legacy_va_layout,
1571 .maxlen = sizeof(sysctl_legacy_va_layout),
1572 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001573 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 .extra1 = &zero,
1575 },
1576#endif
Christoph Lameter17436602006-01-18 17:42:32 -08001577#ifdef CONFIG_NUMA
1578 {
Christoph Lameter17436602006-01-18 17:42:32 -08001579 .procname = "zone_reclaim_mode",
Mel Gormana5f5f912016-07-28 15:46:32 -07001580 .data = &node_reclaim_mode,
1581 .maxlen = sizeof(node_reclaim_mode),
Christoph Lameter17436602006-01-18 17:42:32 -08001582 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001583 .proc_handler = proc_dointvec,
Christoph Lameterc84db232006-02-01 03:05:29 -08001584 .extra1 = &zero,
Christoph Lameter17436602006-01-18 17:42:32 -08001585 },
Christoph Lameter96146342006-07-03 00:24:13 -07001586 {
Christoph Lameter96146342006-07-03 00:24:13 -07001587 .procname = "min_unmapped_ratio",
1588 .data = &sysctl_min_unmapped_ratio,
1589 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1590 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001591 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
Christoph Lameter96146342006-07-03 00:24:13 -07001592 .extra1 = &zero,
1593 .extra2 = &one_hundred,
1594 },
Christoph Lameter0ff38492006-09-25 23:31:52 -07001595 {
Christoph Lameter0ff38492006-09-25 23:31:52 -07001596 .procname = "min_slab_ratio",
1597 .data = &sysctl_min_slab_ratio,
1598 .maxlen = sizeof(sysctl_min_slab_ratio),
1599 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001600 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
Christoph Lameter0ff38492006-09-25 23:31:52 -07001601 .extra1 = &zero,
1602 .extra2 = &one_hundred,
1603 },
Christoph Lameter17436602006-01-18 17:42:32 -08001604#endif
Christoph Lameter77461ab2007-05-09 02:35:13 -07001605#ifdef CONFIG_SMP
1606 {
Christoph Lameter77461ab2007-05-09 02:35:13 -07001607 .procname = "stat_interval",
1608 .data = &sysctl_stat_interval,
1609 .maxlen = sizeof(sysctl_stat_interval),
1610 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001611 .proc_handler = proc_dointvec_jiffies,
Christoph Lameter77461ab2007-05-09 02:35:13 -07001612 },
Hugh Dickins52b6f462016-05-19 17:12:50 -07001613 {
1614 .procname = "stat_refresh",
1615 .data = NULL,
1616 .maxlen = 0,
1617 .mode = 0600,
1618 .proc_handler = vmstat_refresh,
1619 },
Christoph Lameter77461ab2007-05-09 02:35:13 -07001620#endif
David Howells6e141542009-12-15 19:27:45 +00001621#ifdef CONFIG_MMU
Eric Parised032182007-06-28 15:55:21 -04001622 {
Eric Parised032182007-06-28 15:55:21 -04001623 .procname = "mmap_min_addr",
Eric Paris788084a2009-07-31 12:54:11 -04001624 .data = &dac_mmap_min_addr,
1625 .maxlen = sizeof(unsigned long),
Eric Parised032182007-06-28 15:55:21 -04001626 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001627 .proc_handler = mmap_min_addr_handler,
Eric Parised032182007-06-28 15:55:21 -04001628 },
David Howells6e141542009-12-15 19:27:45 +00001629#endif
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001630#ifdef CONFIG_NUMA
1631 {
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001632 .procname = "numa_zonelist_order",
1633 .data = &numa_zonelist_order,
1634 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1635 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001636 .proc_handler = numa_zonelist_order_handler,
KAMEZAWA Hiroyukif0c0b2b2007-07-15 23:38:01 -07001637 },
1638#endif
Al Viro2b8232c2007-10-13 08:16:04 +01001639#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
Paul Mundt5c36e652007-03-01 10:07:42 +09001640 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
Ingo Molnare6e54942006-06-27 02:53:50 -07001641 {
Ingo Molnare6e54942006-06-27 02:53:50 -07001642 .procname = "vdso_enabled",
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001643#ifdef CONFIG_X86_32
1644 .data = &vdso32_enabled,
1645 .maxlen = sizeof(vdso32_enabled),
1646#else
Ingo Molnare6e54942006-06-27 02:53:50 -07001647 .data = &vdso_enabled,
1648 .maxlen = sizeof(vdso_enabled),
Andy Lutomirski3d7ee962014-05-05 12:19:32 -07001649#endif
Ingo Molnare6e54942006-06-27 02:53:50 -07001650 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001651 .proc_handler = proc_dointvec,
Ingo Molnare6e54942006-06-27 02:53:50 -07001652 .extra1 = &zero,
1653 },
1654#endif
Bron Gondwana195cf4532008-02-04 22:29:20 -08001655#ifdef CONFIG_HIGHMEM
1656 {
Bron Gondwana195cf4532008-02-04 22:29:20 -08001657 .procname = "highmem_is_dirtyable",
1658 .data = &vm_highmem_is_dirtyable,
1659 .maxlen = sizeof(vm_highmem_is_dirtyable),
1660 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001661 .proc_handler = proc_dointvec_minmax,
Bron Gondwana195cf4532008-02-04 22:29:20 -08001662 .extra1 = &zero,
1663 .extra2 = &one,
1664 },
1665#endif
Andi Kleen6a460792009-09-16 11:50:15 +02001666#ifdef CONFIG_MEMORY_FAILURE
1667 {
Andi Kleen6a460792009-09-16 11:50:15 +02001668 .procname = "memory_failure_early_kill",
1669 .data = &sysctl_memory_failure_early_kill,
1670 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1671 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001672 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001673 .extra1 = &zero,
1674 .extra2 = &one,
1675 },
1676 {
Andi Kleen6a460792009-09-16 11:50:15 +02001677 .procname = "memory_failure_recovery",
1678 .data = &sysctl_memory_failure_recovery,
1679 .maxlen = sizeof(sysctl_memory_failure_recovery),
1680 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001681 .proc_handler = proc_dointvec_minmax,
Andi Kleen6a460792009-09-16 11:50:15 +02001682 .extra1 = &zero,
1683 .extra2 = &one,
1684 },
1685#endif
Andrew Shewmakerc9b1d092013-04-29 15:08:10 -07001686 {
1687 .procname = "user_reserve_kbytes",
1688 .data = &sysctl_user_reserve_kbytes,
1689 .maxlen = sizeof(sysctl_user_reserve_kbytes),
1690 .mode = 0644,
1691 .proc_handler = proc_doulongvec_minmax,
1692 },
Andrew Shewmaker4eeab4f2013-04-29 15:08:11 -07001693 {
1694 .procname = "admin_reserve_kbytes",
1695 .data = &sysctl_admin_reserve_kbytes,
1696 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
1697 .mode = 0644,
1698 .proc_handler = proc_doulongvec_minmax,
1699 },
Daniel Cashmand07e2252016-01-14 15:19:53 -08001700#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1701 {
1702 .procname = "mmap_rnd_bits",
1703 .data = &mmap_rnd_bits,
1704 .maxlen = sizeof(mmap_rnd_bits),
1705 .mode = 0600,
1706 .proc_handler = proc_dointvec_minmax,
1707 .extra1 = (void *)&mmap_rnd_bits_min,
1708 .extra2 = (void *)&mmap_rnd_bits_max,
1709 },
1710#endif
1711#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1712 {
1713 .procname = "mmap_rnd_compat_bits",
1714 .data = &mmap_rnd_compat_bits,
1715 .maxlen = sizeof(mmap_rnd_compat_bits),
1716 .mode = 0600,
1717 .proc_handler = proc_dointvec_minmax,
1718 .extra1 = (void *)&mmap_rnd_compat_bits_min,
1719 .extra2 = (void *)&mmap_rnd_compat_bits_max,
1720 },
1721#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001722 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723};
1724
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001725static struct ctl_table fs_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 .procname = "inode-nr",
1728 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001729 .maxlen = 2*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001731 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 },
1733 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 .procname = "inode-state",
1735 .data = &inodes_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001736 .maxlen = 7*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 .mode = 0444,
Dave Chinnercffbc8a2010-10-23 05:03:02 -04001738 .proc_handler = proc_nr_inodes,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 },
1740 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 .procname = "file-nr",
1742 .data = &files_stat,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001743 .maxlen = sizeof(files_stat),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001745 .proc_handler = proc_nr_files,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 },
1747 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 .procname = "file-max",
1749 .data = &files_stat.max_files,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001750 .maxlen = sizeof(files_stat.max_files),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 .mode = 0644,
Eric Dumazet518de9b2010-10-26 14:22:44 -07001752 .proc_handler = proc_doulongvec_minmax,
Christian Brauner32a5ad92019-03-07 16:29:43 -08001753 .extra1 = &zero,
1754 .extra2 = &long_max,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 },
1756 {
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001757 .procname = "nr_open",
1758 .data = &sysctl_nr_open,
Alexey Dobriyan9b80a182016-09-02 00:38:52 +03001759 .maxlen = sizeof(unsigned int),
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001760 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001761 .proc_handler = proc_dointvec_minmax,
Al Viroeceea0b2008-05-10 10:08:32 -04001762 .extra1 = &sysctl_nr_open_min,
1763 .extra2 = &sysctl_nr_open_max,
Eric Dumazet9cfe0152008-02-06 01:37:16 -08001764 },
1765 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 .procname = "dentry-state",
1767 .data = &dentry_stat,
Glauber Costa3942c072013-08-28 10:17:53 +10001768 .maxlen = 6*sizeof(long),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 .mode = 0444,
Christoph Hellwig312d3ca2010-10-10 05:36:23 -04001770 .proc_handler = proc_nr_dentry,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 },
1772 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 .procname = "overflowuid",
1774 .data = &fs_overflowuid,
1775 .maxlen = sizeof(int),
1776 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001777 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 .extra1 = &minolduid,
1779 .extra2 = &maxolduid,
1780 },
1781 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 .procname = "overflowgid",
1783 .data = &fs_overflowgid,
1784 .maxlen = sizeof(int),
1785 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001786 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 .extra1 = &minolduid,
1788 .extra2 = &maxolduid,
1789 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001790#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 .procname = "leases-enable",
1793 .data = &leases_enable,
1794 .maxlen = sizeof(int),
1795 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001796 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001798#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799#ifdef CONFIG_DNOTIFY
1800 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 .procname = "dir-notify-enable",
1802 .data = &dir_notify_enable,
1803 .maxlen = sizeof(int),
1804 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001805 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 },
1807#endif
1808#ifdef CONFIG_MMU
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001809#ifdef CONFIG_FILE_LOCKING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 .procname = "lease-break-time",
1812 .data = &lease_break_time,
1813 .maxlen = sizeof(int),
1814 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001815 .proc_handler = proc_dointvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 },
Thomas Petazzonibfcd17a2008-08-06 15:12:22 +02001817#endif
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001818#ifdef CONFIG_AIO
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 .procname = "aio-nr",
1821 .data = &aio_nr,
1822 .maxlen = sizeof(aio_nr),
1823 .mode = 0444,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001824 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 },
1826 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 .procname = "aio-max-nr",
1828 .data = &aio_max_nr,
1829 .maxlen = sizeof(aio_max_nr),
1830 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -08001831 .proc_handler = proc_doulongvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 },
Thomas Petazzoniebf3f092008-10-15 22:05:12 -07001833#endif /* CONFIG_AIO */
Amy Griffis2d9048e2006-06-01 13:10:59 -07001834#ifdef CONFIG_INOTIFY_USER
Robert Love0399cb02005-07-13 12:38:18 -04001835 {
Robert Love0399cb02005-07-13 12:38:18 -04001836 .procname = "inotify",
1837 .mode = 0555,
1838 .child = inotify_table,
1839 },
1840#endif
Davide Libenzi7ef99642008-12-01 13:13:55 -08001841#ifdef CONFIG_EPOLL
1842 {
1843 .procname = "epoll",
1844 .mode = 0555,
1845 .child = epoll_table,
1846 },
1847#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848#endif
Alan Coxd6e71142005-06-23 00:09:43 -07001849 {
Kees Cook800179c2012-07-25 17:29:07 -07001850 .procname = "protected_symlinks",
1851 .data = &sysctl_protected_symlinks,
1852 .maxlen = sizeof(int),
1853 .mode = 0600,
1854 .proc_handler = proc_dointvec_minmax,
1855 .extra1 = &zero,
1856 .extra2 = &one,
1857 },
1858 {
1859 .procname = "protected_hardlinks",
1860 .data = &sysctl_protected_hardlinks,
1861 .maxlen = sizeof(int),
1862 .mode = 0600,
1863 .proc_handler = proc_dointvec_minmax,
1864 .extra1 = &zero,
1865 .extra2 = &one,
1866 },
1867 {
Salvatore Mesoraca30aba662018-08-23 17:00:35 -07001868 .procname = "protected_fifos",
1869 .data = &sysctl_protected_fifos,
1870 .maxlen = sizeof(int),
1871 .mode = 0600,
1872 .proc_handler = proc_dointvec_minmax,
1873 .extra1 = &zero,
1874 .extra2 = &two,
1875 },
1876 {
1877 .procname = "protected_regular",
1878 .data = &sysctl_protected_regular,
1879 .maxlen = sizeof(int),
1880 .mode = 0600,
1881 .proc_handler = proc_dointvec_minmax,
1882 .extra1 = &zero,
1883 .extra2 = &two,
1884 },
1885 {
Alan Coxd6e71142005-06-23 00:09:43 -07001886 .procname = "suid_dumpable",
1887 .data = &suid_dumpable,
1888 .maxlen = sizeof(int),
1889 .mode = 0644,
Kees Cook54b50192012-07-30 14:39:18 -07001890 .proc_handler = proc_dointvec_minmax_coredump,
Matthew Wilcox8e654fb2009-04-02 16:58:33 -07001891 .extra1 = &zero,
1892 .extra2 = &two,
Alan Coxd6e71142005-06-23 00:09:43 -07001893 },
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001894#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1895 {
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001896 .procname = "binfmt_misc",
1897 .mode = 0555,
Eric W. Biedermanf9bd6732015-05-09 22:09:14 -05001898 .child = sysctl_mount_point,
Eric W. Biederman2abc26f2007-02-14 00:34:07 -08001899 },
1900#endif
Jens Axboeb492e952010-05-19 21:03:16 +02001901 {
Jens Axboeff9da692010-06-03 14:54:39 +02001902 .procname = "pipe-max-size",
1903 .data = &pipe_max_size,
Joe Lawrence98159d92017-11-17 15:29:17 -08001904 .maxlen = sizeof(pipe_max_size),
Jens Axboeb492e952010-05-19 21:03:16 +02001905 .mode = 0644,
Eric Biggers319e0a22018-02-06 15:41:49 -08001906 .proc_handler = proc_dopipe_max_size,
Jens Axboeb492e952010-05-19 21:03:16 +02001907 },
Willy Tarreau759c0112016-01-18 16:36:09 +01001908 {
1909 .procname = "pipe-user-pages-hard",
1910 .data = &pipe_user_pages_hard,
1911 .maxlen = sizeof(pipe_user_pages_hard),
1912 .mode = 0644,
1913 .proc_handler = proc_doulongvec_minmax,
1914 },
1915 {
1916 .procname = "pipe-user-pages-soft",
1917 .data = &pipe_user_pages_soft,
1918 .maxlen = sizeof(pipe_user_pages_soft),
1919 .mode = 0644,
1920 .proc_handler = proc_doulongvec_minmax,
1921 },
Eric W. Biedermand2921682016-09-28 00:27:17 -05001922 {
1923 .procname = "mount-max",
1924 .data = &sysctl_mount_max,
1925 .maxlen = sizeof(unsigned int),
1926 .mode = 0644,
1927 .proc_handler = proc_dointvec_minmax,
1928 .extra1 = &one,
1929 },
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001930 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931};
1932
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001933static struct ctl_table debug_table[] = {
Catalin Marinas7ac57a82012-10-08 16:28:16 -07001934#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001935 {
Masoud Asgharifard Sharbianiabd4f752007-07-22 11:12:28 +02001936 .procname = "exception-trace",
1937 .data = &show_unhandled_signals,
1938 .maxlen = sizeof(int),
1939 .mode = 0644,
1940 .proc_handler = proc_dointvec
1941 },
1942#endif
Masami Hiramatsub2be84d2010-02-25 08:34:15 -05001943#if defined(CONFIG_OPTPROBES)
1944 {
1945 .procname = "kprobes-optimization",
1946 .data = &sysctl_kprobes_optimization,
1947 .maxlen = sizeof(int),
1948 .mode = 0644,
1949 .proc_handler = proc_kprobes_optimization_handler,
1950 .extra1 = &zero,
1951 .extra2 = &one,
1952 },
1953#endif
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001954 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955};
1956
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001957static struct ctl_table dev_table[] = {
Eric W. Biederman6fce56e2009-04-03 02:30:53 -07001958 { }
Robert Love0eeca282005-07-12 17:06:03 -04001959};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
Eric W. Biedermande4e83bd2012-01-06 03:34:20 -08001961int __init sysctl_init(void)
Al Viro330d57f2005-11-04 10:18:40 +00001962{
Steven Rostedtfd4b6162012-07-30 14:42:48 -07001963 struct ctl_table_header *hdr;
1964
1965 hdr = register_sysctl_table(sysctl_base_table);
1966 kmemleak_not_leak(hdr);
Eric W. Biedermand912b0c2007-02-14 00:34:13 -08001967 return 0;
1968}
1969
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001970#endif /* CONFIG_SYSCTL */
1971
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972/*
1973 * /proc/sys support
1974 */
1975
Eric W. Biedermanb89a8172006-09-27 01:51:04 -07001976#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
Kees Cookf8808302014-06-06 14:37:17 -07001978static int _proc_do_string(char *data, int maxlen, int write,
1979 char __user *buffer,
Adrian Bunkb1ba4dd2006-10-02 02:18:05 -07001980 size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001981{
1982 size_t len;
1983 char __user *p;
1984 char c;
Oleg Nesterov8d060872007-02-10 01:46:38 -08001985
1986 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001987 *lenp = 0;
1988 return 0;
1989 }
Oleg Nesterov8d060872007-02-10 01:46:38 -08001990
Sam Vilainf5dd3d62006-10-02 02:18:04 -07001991 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -07001992 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1993 /* Only continue writes not past the end of buffer. */
1994 len = strlen(data);
1995 if (len > maxlen - 1)
1996 len = maxlen - 1;
1997
1998 if (*ppos > len)
1999 return 0;
2000 len = *ppos;
2001 } else {
2002 /* Start writing from beginning of buffer. */
2003 len = 0;
2004 }
2005
Kees Cook2ca9bb42014-06-06 14:37:18 -07002006 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002007 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -07002008 while ((p - buffer) < *lenp && len < maxlen - 1) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002009 if (get_user(c, p++))
2010 return -EFAULT;
2011 if (c == 0 || c == '\n')
2012 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -07002013 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002014 }
Kees Cookf8808302014-06-06 14:37:17 -07002015 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002016 } else {
2017 len = strlen(data);
2018 if (len > maxlen)
2019 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -08002020
2021 if (*ppos > len) {
2022 *lenp = 0;
2023 return 0;
2024 }
2025
2026 data += *ppos;
2027 len -= *ppos;
2028
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002029 if (len > *lenp)
2030 len = *lenp;
2031 if (len)
Kees Cookf8808302014-06-06 14:37:17 -07002032 if (copy_to_user(buffer, data, len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002033 return -EFAULT;
2034 if (len < *lenp) {
Kees Cookf8808302014-06-06 14:37:17 -07002035 if (put_user('\n', buffer + len))
Sam Vilainf5dd3d62006-10-02 02:18:04 -07002036 return -EFAULT;
2037 len++;
2038 }
2039 *lenp = len;
2040 *ppos += len;
2041 }
2042 return 0;
2043}
2044
Kees Cookf4aacea2014-06-06 14:37:19 -07002045static void warn_sysctl_write(struct ctl_table *table)
2046{
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);
2051}
2052
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053/**
Randy Dunlap5f733e82018-08-21 22:01:06 -07002054 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002055 * @ppos: file position
2056 * @table: the sysctl table
2057 *
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
Randy Dunlap5f733e82018-08-21 22:01:06 -07002060 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002061 */
2062static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2063 struct ctl_table *table)
2064{
2065 if (!*ppos)
2066 return false;
2067
2068 switch (sysctl_writes_strict) {
2069 case SYSCTL_WRITES_STRICT:
2070 return true;
2071 case SYSCTL_WRITES_WARN:
2072 warn_sysctl_write(table);
2073 return false;
2074 default:
2075 return false;
2076 }
2077}
2078
2079/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 * proc_dostring - read a string sysctl
2081 * @table: the sysctl table
2082 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 * @buffer: the user buffer
2084 * @lenp: the size of the user buffer
2085 * @ppos: file position
2086 *
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
2092 * not large enough.
2093 *
2094 * Returns 0 on success.
2095 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002096int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 void __user *buffer, size_t *lenp, loff_t *ppos)
2098{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002099 if (write)
2100 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -07002101
Kees Cookf8808302014-06-06 14:37:17 -07002102 return _proc_do_string((char *)(table->data), table->maxlen, write,
2103 (char __user *)buffer, lenp, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104}
2105
Amerigo Wang00b7c332010-05-05 00:26:45 +00002106static size_t proc_skip_spaces(char **buf)
2107{
2108 size_t ret;
2109 char *tmp = skip_spaces(*buf);
2110 ret = tmp - *buf;
2111 *buf = tmp;
2112 return ret;
2113}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114
Octavian Purdila9f977fb2010-05-05 00:26:55 +00002115static void proc_skip_char(char **buf, size_t *size, const char v)
2116{
2117 while (*size) {
2118 if (**buf != v)
2119 break;
2120 (*size)--;
2121 (*buf)++;
2122 }
2123}
2124
Christian Brauner7f2923c2019-03-07 16:29:40 -08002125/**
2126 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2127 * fail on overflow
2128 *
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
2133 *
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
2138 * caller.
2139 */
2140static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2141 unsigned long *res)
2142{
2143 unsigned long long result;
2144 unsigned int rv;
2145
2146 cp = _parse_integer_fixup_radix(cp, &base);
2147 rv = _parse_integer(cp, base, &result);
2148 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2149 return -ERANGE;
2150
2151 cp += rv;
2152
2153 if (endp)
2154 *endp = (char *)cp;
2155
2156 *res = (unsigned long)result;
2157 return 0;
2158}
2159
Amerigo Wang00b7c332010-05-05 00:26:45 +00002160#define TMPBUFLEN 22
2161/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002162 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +00002163 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002164 * @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
Amerigo Wang00b7c332010-05-05 00:26:45 +00002171 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002172 * 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.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002176 */
2177static 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)
2180{
2181 int len;
2182 char *p, tmp[TMPBUFLEN];
2183
2184 if (!*size)
2185 return -EINVAL;
2186
2187 len = *size;
2188 if (len > TMPBUFLEN - 1)
2189 len = TMPBUFLEN - 1;
2190
2191 memcpy(tmp, *buf, len);
2192
2193 tmp[len] = 0;
2194 p = tmp;
2195 if (*p == '-' && *size > 1) {
2196 *neg = true;
2197 p++;
2198 } else
2199 *neg = false;
2200 if (!isdigit(*p))
2201 return -EINVAL;
2202
Christian Brauner7f2923c2019-03-07 16:29:40 -08002203 if (strtoul_lenient(p, &p, 0, val))
2204 return -EINVAL;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002205
2206 len = p - tmp;
2207
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)
2212 return -EINVAL;
2213
2214 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2215 return -EINVAL;
2216
2217 if (tr && (len < *size))
2218 *tr = *p;
2219
2220 *buf += len;
2221 *size -= len;
2222
2223 return 0;
2224}
2225
2226/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002227 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +00002228 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002229 * @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
Amerigo Wang00b7c332010-05-05 00:26:45 +00002233 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -07002234 * In case of success %0 is returned and @buf and @size are updated with
2235 * the amount of bytes written.
Amerigo Wang00b7c332010-05-05 00:26:45 +00002236 */
2237static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2238 bool neg)
2239{
2240 int len;
2241 char tmp[TMPBUFLEN], *p = tmp;
2242
2243 sprintf(p, "%s%lu", neg ? "-" : "", val);
2244 len = strlen(tmp);
2245 if (len > *size)
2246 len = *size;
2247 if (copy_to_user(*buf, tmp, len))
2248 return -EFAULT;
2249 *size -= len;
2250 *buf += len;
2251 return 0;
2252}
2253#undef TMPBUFLEN
2254
2255static int proc_put_char(void __user **buf, size_t *size, char c)
2256{
2257 if (*size) {
2258 char __user **buffer = (char __user **)buf;
2259 if (put_user(c, *buffer))
2260 return -EFAULT;
2261 (*size)--, (*buffer)++;
2262 *buf = *buffer;
2263 }
2264 return 0;
2265}
2266
2267static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 int *valp,
2269 int write, void *data)
2270{
2271 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -07002272 if (*negp) {
2273 if (*lvalp > (unsigned long) INT_MAX + 1)
2274 return -EINVAL;
2275 *valp = -*lvalp;
2276 } else {
2277 if (*lvalp > (unsigned long) INT_MAX)
2278 return -EINVAL;
2279 *valp = *lvalp;
2280 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 } else {
2282 int val = *valp;
2283 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002284 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002285 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002287 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 *lvalp = (unsigned long)val;
2289 }
2290 }
2291 return 0;
2292}
2293
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002294static int do_proc_douintvec_conv(unsigned long *lvalp,
2295 unsigned int *valp,
2296 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002297{
2298 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002299 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002300 return -EINVAL;
2301 *valp = *lvalp;
2302 } else {
2303 unsigned int val = *valp;
2304 *lvalp = (unsigned long)val;
2305 }
2306 return 0;
2307}
2308
Amerigo Wang00b7c332010-05-05 00:26:45 +00002309static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2310
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002311static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002312 int write, void __user *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002313 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002314 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 int write, void *data),
2316 void *data)
2317{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002318 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002319 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002320 char *kbuf = NULL, *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
Amerigo Wang00b7c332010-05-05 00:26:45 +00002322 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 *lenp = 0;
2324 return 0;
2325 }
2326
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002327 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 vleft = table->maxlen / sizeof(*i);
2329 left = *lenp;
2330
2331 if (!conv)
2332 conv = do_proc_dointvec_conv;
2333
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002335 if (proc_first_pos_non_zero_ignore(ppos, table))
2336 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002337
Amerigo Wang00b7c332010-05-05 00:26:45 +00002338 if (left > PAGE_SIZE - 1)
2339 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002340 p = kbuf = memdup_user_nul(buffer, left);
2341 if (IS_ERR(kbuf))
2342 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002343 }
2344
2345 for (; left && vleft--; i++, first=0) {
2346 unsigned long lval;
2347 bool neg;
2348
2349 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002350 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002351
J. R. Okajima563b0462010-05-25 16:10:14 -07002352 if (!left)
2353 break;
Al Viro70f6cbb2015-12-24 00:13:10 -05002354 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002355 proc_wspace_sep,
2356 sizeof(proc_wspace_sep), NULL);
2357 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002359 if (conv(&neg, &lval, i, 1, data)) {
2360 err = -EINVAL;
2361 break;
2362 }
2363 } else {
2364 if (conv(&neg, &lval, i, 0, data)) {
2365 err = -EINVAL;
2366 break;
2367 }
2368 if (!first)
2369 err = proc_put_char(&buffer, &left, '\t');
2370 if (err)
2371 break;
2372 err = proc_put_long(&buffer, &left, lval, neg);
2373 if (err)
2374 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 }
2376 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002377
2378 if (!write && !first && left && !err)
2379 err = proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -07002380 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -05002381 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002382 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002383 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002384 if (first)
2385 return err ? : -EINVAL;
2386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002388out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002390 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391}
2392
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002393static int do_proc_dointvec(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002394 void __user *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002395 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002396 int write, void *data),
2397 void *data)
2398{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002399 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002400 buffer, lenp, ppos, conv, data);
2401}
2402
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002403static 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,
2408 unsigned int *valp,
2409 int write, void *data),
2410 void *data)
2411{
2412 unsigned long lval;
2413 int err = 0;
2414 size_t left;
2415 bool neg;
2416 char *kbuf = NULL, *p;
2417
2418 left = *lenp;
2419
2420 if (proc_first_pos_non_zero_ignore(ppos, table))
2421 goto bail_early;
2422
2423 if (left > PAGE_SIZE - 1)
2424 left = PAGE_SIZE - 1;
2425
2426 p = kbuf = memdup_user_nul(buffer, left);
2427 if (IS_ERR(kbuf))
2428 return -EINVAL;
2429
2430 left -= proc_skip_spaces(&p);
2431 if (!left) {
2432 err = -EINVAL;
2433 goto out_free;
2434 }
2435
2436 err = proc_get_long(&p, &left, &lval, &neg,
2437 proc_wspace_sep,
2438 sizeof(proc_wspace_sep), NULL);
2439 if (err || neg) {
2440 err = -EINVAL;
2441 goto out_free;
2442 }
2443
2444 if (conv(&lval, tbl_data, 1, data)) {
2445 err = -EINVAL;
2446 goto out_free;
2447 }
2448
2449 if (!err && left)
2450 left -= proc_skip_spaces(&p);
2451
2452out_free:
2453 kfree(kbuf);
2454 if (err)
2455 return -EINVAL;
2456
2457 return 0;
2458
2459 /* This is in keeping with old __do_proc_dointvec() */
2460bail_early:
2461 *ppos += *lenp;
2462 return err;
2463}
2464
2465static 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,
2468 unsigned int *valp,
2469 int write, void *data),
2470 void *data)
2471{
2472 unsigned long lval;
2473 int err = 0;
2474 size_t left;
2475
2476 left = *lenp;
2477
2478 if (conv(&lval, tbl_data, 0, data)) {
2479 err = -EINVAL;
2480 goto out;
2481 }
2482
2483 err = proc_put_long(&buffer, &left, lval, false);
2484 if (err || !left)
2485 goto out;
2486
2487 err = proc_put_char(&buffer, &left, '\n');
2488
2489out:
2490 *lenp -= left;
2491 *ppos += *lenp;
2492
2493 return err;
2494}
2495
2496static 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,
2500 unsigned int *valp,
2501 int write, void *data),
2502 void *data)
2503{
2504 unsigned int *i, vleft;
2505
2506 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2507 *lenp = 0;
2508 return 0;
2509 }
2510
2511 i = (unsigned int *) tbl_data;
2512 vleft = table->maxlen / sizeof(*i);
2513
2514 /*
2515 * Arrays are not supported, keep this simple. *Do not* add
2516 * support for them.
2517 */
2518 if (vleft != 1) {
2519 *lenp = 0;
2520 return -EINVAL;
2521 }
2522
2523 if (!conv)
2524 conv = do_proc_douintvec_conv;
2525
2526 if (write)
2527 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2528 conv, data);
2529 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2530}
2531
2532static 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,
2535 unsigned int *valp,
2536 int write, void *data),
2537 void *data)
2538{
2539 return __do_proc_douintvec(table->data, table, write,
2540 buffer, lenp, ppos, conv, data);
2541}
2542
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543/**
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
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 * @buffer: the user buffer
2548 * @lenp: the size of the user buffer
2549 * @ppos: file position
2550 *
2551 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2552 * values from/to the user buffer, treated as an ASCII string.
2553 *
2554 * Returns 0 on success.
2555 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002556int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 void __user *buffer, size_t *lenp, loff_t *ppos)
2558{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07002559 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2560}
2561
2562/**
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
2569 *
2570 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2571 * values from/to the user buffer, treated as an ASCII string.
2572 *
2573 * Returns 0 on success.
2574 */
2575int proc_douintvec(struct ctl_table *table, int write,
2576 void __user *buffer, size_t *lenp, loff_t *ppos)
2577{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -07002578 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2579 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580}
2581
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002582/*
Andi Kleen25ddbb12008-10-15 22:01:41 -07002583 * Taint values can only be increased
2584 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002585 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002586static int proc_taint(struct ctl_table *table, int write,
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002587 void __user *buffer, size_t *lenp, loff_t *ppos)
2588{
Andi Kleen25ddbb12008-10-15 22:01:41 -07002589 struct ctl_table t;
2590 unsigned long tmptaint = get_taint();
2591 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002592
Bastian Blank91fcd412007-04-23 14:41:14 -07002593 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002594 return -EPERM;
2595
Andi Kleen25ddbb12008-10-15 22:01:41 -07002596 t = *table;
2597 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002598 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002599 if (err < 0)
2600 return err;
2601
2602 if (write) {
2603 /*
2604 * Poor man's atomic or. Not worth adding a primitive
2605 * to everyone's atomic.h for this
2606 */
2607 int i;
2608 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2609 if ((tmptaint >> i) & 1)
Rusty Russell373d4d02013-01-21 17:17:39 +10302610 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -07002611 }
2612 }
2613
2614 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -08002615}
2616
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002617#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -07002618static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -07002619 void __user *buffer, size_t *lenp, loff_t *ppos)
2620{
2621 if (write && !capable(CAP_SYS_ADMIN))
2622 return -EPERM;
2623
2624 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2625}
2626#endif
2627
Waiman Long24704f32018-04-10 16:35:38 -07002628/**
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
2632 *
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.
2636 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637struct do_proc_dointvec_minmax_conv_param {
2638 int *min;
2639 int *max;
2640};
2641
Amerigo Wang00b7c332010-05-05 00:26:45 +00002642static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2643 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 int write, void *data)
2645{
2646 struct do_proc_dointvec_minmax_conv_param *param = data;
2647 if (write) {
2648 int val = *negp ? -*lvalp : *lvalp;
2649 if ((param->min && *param->min > val) ||
2650 (param->max && *param->max < val))
2651 return -EINVAL;
2652 *valp = val;
2653 } else {
2654 int val = *valp;
2655 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002656 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002657 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002659 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 *lvalp = (unsigned long)val;
2661 }
2662 }
2663 return 0;
2664}
2665
2666/**
2667 * proc_dointvec_minmax - read a vector of integers with min/max values
2668 * @table: the sysctl table
2669 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 * @buffer: the user buffer
2671 * @lenp: the size of the user buffer
2672 * @ppos: file position
2673 *
2674 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2675 * values from/to the user buffer, treated as an ASCII string.
2676 *
2677 * This routine will ensure the values are within the range specified by
2678 * table->extra1 (min) and table->extra2 (max).
2679 *
Waiman Long24704f32018-04-10 16:35:38 -07002680 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002682int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 void __user *buffer, size_t *lenp, loff_t *ppos)
2684{
2685 struct do_proc_dointvec_minmax_conv_param param = {
2686 .min = (int *) table->extra1,
2687 .max = (int *) table->extra2,
2688 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002689 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 do_proc_dointvec_minmax_conv, &param);
2691}
2692
Waiman Long24704f32018-04-10 16:35:38 -07002693/**
2694 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2695 * @min: pointer to minimum allowable value
2696 * @max: pointer to maximum allowable value
2697 *
2698 * The do_proc_douintvec_minmax_conv_param structure provides the
2699 * minimum and maximum values for doing range checking for those sysctl
2700 * parameters that use the proc_douintvec_minmax() handler.
2701 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002702struct do_proc_douintvec_minmax_conv_param {
2703 unsigned int *min;
2704 unsigned int *max;
2705};
2706
2707static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2708 unsigned int *valp,
2709 int write, void *data)
2710{
2711 struct do_proc_douintvec_minmax_conv_param *param = data;
2712
2713 if (write) {
2714 unsigned int val = *lvalp;
2715
Joe Lawrencefb910c42017-11-17 15:29:28 -08002716 if (*lvalp > UINT_MAX)
2717 return -EINVAL;
2718
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002719 if ((param->min && *param->min > val) ||
2720 (param->max && *param->max < val))
2721 return -ERANGE;
2722
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002723 *valp = val;
2724 } else {
2725 unsigned int val = *valp;
2726 *lvalp = (unsigned long) val;
2727 }
2728
2729 return 0;
2730}
2731
2732/**
2733 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2734 * @table: the sysctl table
2735 * @write: %TRUE if this is a write to the sysctl file
2736 * @buffer: the user buffer
2737 * @lenp: the size of the user buffer
2738 * @ppos: file position
2739 *
2740 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2741 * values from/to the user buffer, treated as an ASCII string. Negative
2742 * strings are not allowed.
2743 *
2744 * This routine will ensure the values are within the range specified by
2745 * table->extra1 (min) and table->extra2 (max). There is a final sanity
2746 * check for UINT_MAX to avoid having to support wrap around uses from
2747 * userspace.
2748 *
Waiman Long24704f32018-04-10 16:35:38 -07002749 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07002750 */
2751int proc_douintvec_minmax(struct ctl_table *table, int write,
2752 void __user *buffer, size_t *lenp, loff_t *ppos)
2753{
2754 struct do_proc_douintvec_minmax_conv_param param = {
2755 .min = (unsigned int *) table->extra1,
2756 .max = (unsigned int *) table->extra2,
2757 };
2758 return do_proc_douintvec(table, write, buffer, lenp, ppos,
2759 do_proc_douintvec_minmax_conv, &param);
2760}
2761
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002762static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2763 unsigned int *valp,
2764 int write, void *data)
2765{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002766 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08002767 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002768
Joe Lawrencefb910c42017-11-17 15:29:28 -08002769 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002770 if (val == 0)
2771 return -EINVAL;
2772
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002773 *valp = val;
2774 } else {
2775 unsigned int val = *valp;
2776 *lvalp = (unsigned long) val;
2777 }
2778
2779 return 0;
2780}
2781
Eric Biggers319e0a22018-02-06 15:41:49 -08002782static int proc_dopipe_max_size(struct ctl_table *table, int write,
2783 void __user *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002784{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002785 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08002786 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08002787}
2788
Kees Cook54b50192012-07-30 14:39:18 -07002789static void validate_coredump_safety(void)
2790{
Alex Kelly046d6622012-10-04 17:15:23 -07002791#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08002792 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07002793 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08002794 printk(KERN_WARNING
2795"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2796"Pipe handler or fully qualified core dump path required.\n"
2797"Set kernel.core_pattern before fs.suid_dumpable.\n"
2798 );
Kees Cook54b50192012-07-30 14:39:18 -07002799 }
Alex Kelly046d6622012-10-04 17:15:23 -07002800#endif
Kees Cook54b50192012-07-30 14:39:18 -07002801}
2802
2803static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2804 void __user *buffer, size_t *lenp, loff_t *ppos)
2805{
2806 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2807 if (!error)
2808 validate_coredump_safety();
2809 return error;
2810}
2811
Alex Kelly046d6622012-10-04 17:15:23 -07002812#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07002813static int proc_dostring_coredump(struct ctl_table *table, int write,
2814 void __user *buffer, size_t *lenp, loff_t *ppos)
2815{
2816 int error = proc_dostring(table, write, buffer, lenp, ppos);
2817 if (!error)
2818 validate_coredump_safety();
2819 return error;
2820}
Alex Kelly046d6622012-10-04 17:15:23 -07002821#endif
Kees Cook54b50192012-07-30 14:39:18 -07002822
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002823static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 void __user *buffer,
2825 size_t *lenp, loff_t *ppos,
2826 unsigned long convmul,
2827 unsigned long convdiv)
2828{
Amerigo Wang00b7c332010-05-05 00:26:45 +00002829 unsigned long *i, *min, *max;
2830 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002831 size_t left;
Al Viro70f6cbb2015-12-24 00:13:10 -05002832 char *kbuf = NULL, *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002833
2834 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 *lenp = 0;
2836 return 0;
2837 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002838
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002839 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 min = (unsigned long *) table->extra1;
2841 max = (unsigned long *) table->extra2;
2842 vleft = table->maxlen / sizeof(unsigned long);
2843 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002844
2845 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07002846 if (proc_first_pos_non_zero_ignore(ppos, table))
2847 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07002848
Amerigo Wang00b7c332010-05-05 00:26:45 +00002849 if (left > PAGE_SIZE - 1)
2850 left = PAGE_SIZE - 1;
Al Viro70f6cbb2015-12-24 00:13:10 -05002851 p = kbuf = memdup_user_nul(buffer, left);
2852 if (IS_ERR(kbuf))
2853 return PTR_ERR(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002854 }
2855
Eric Dumazet27b3d802010-10-07 12:59:29 -07002856 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002857 unsigned long val;
2858
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002860 bool neg;
2861
Al Viro70f6cbb2015-12-24 00:13:10 -05002862 left -= proc_skip_spaces(&p);
Cheng Lin09be1782019-01-03 15:26:13 -08002863 if (!left)
2864 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002865
Al Viro70f6cbb2015-12-24 00:13:10 -05002866 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00002867 proc_wspace_sep,
2868 sizeof(proc_wspace_sep), NULL);
2869 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 break;
2871 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08002873 val = convmul * val / convdiv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 if ((min && val < *min) || (max && val > *max))
2875 continue;
2876 *i = val;
2877 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002878 val = convdiv * (*i) / convmul;
Chen Gang78338192013-11-12 15:11:21 -08002879 if (!first) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002880 err = proc_put_char(&buffer, &left, '\t');
Chen Gang78338192013-11-12 15:11:21 -08002881 if (err)
2882 break;
2883 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00002884 err = proc_put_long(&buffer, &left, val, false);
2885 if (err)
2886 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 }
2888 }
2889
Amerigo Wang00b7c332010-05-05 00:26:45 +00002890 if (!write && !first && left && !err)
2891 err = proc_put_char(&buffer, &left, '\n');
2892 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05002893 left -= proc_skip_spaces(&p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05002895 kfree(kbuf);
Amerigo Wang00b7c332010-05-05 00:26:45 +00002896 if (first)
2897 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07002900out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00002902 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903}
2904
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002905static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002906 void __user *buffer,
2907 size_t *lenp, loff_t *ppos,
2908 unsigned long convmul,
2909 unsigned long convdiv)
2910{
2911 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002912 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07002913}
2914
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915/**
2916 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2917 * @table: the sysctl table
2918 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 * @buffer: the user buffer
2920 * @lenp: the size of the user buffer
2921 * @ppos: file position
2922 *
2923 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2924 * values from/to the user buffer, treated as an ASCII string.
2925 *
2926 * This routine will ensure the values are within the range specified by
2927 * table->extra1 (min) and table->extra2 (max).
2928 *
2929 * Returns 0 on success.
2930 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002931int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 void __user *buffer, size_t *lenp, loff_t *ppos)
2933{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002934 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935}
2936
2937/**
2938 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2939 * @table: the sysctl table
2940 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 * @buffer: the user buffer
2942 * @lenp: the size of the user buffer
2943 * @ppos: file position
2944 *
2945 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2946 * values from/to the user buffer, treated as an ASCII string. The values
2947 * are treated as milliseconds, and converted to jiffies when they are stored.
2948 *
2949 * This routine will ensure the values are within the range specified by
2950 * table->extra1 (min) and table->extra2 (max).
2951 *
2952 * Returns 0 on success.
2953 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07002954int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 void __user *buffer,
2956 size_t *lenp, loff_t *ppos)
2957{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07002958 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 lenp, ppos, HZ, 1000l);
2960}
2961
2962
Amerigo Wang00b7c332010-05-05 00:26:45 +00002963static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 int *valp,
2965 int write, void *data)
2966{
2967 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07002968 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08002969 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2971 } else {
2972 int val = *valp;
2973 unsigned long lval;
2974 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002975 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002976 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002978 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 lval = (unsigned long)val;
2980 }
2981 *lvalp = lval / HZ;
2982 }
2983 return 0;
2984}
2985
Amerigo Wang00b7c332010-05-05 00:26:45 +00002986static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 int *valp,
2988 int write, void *data)
2989{
2990 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08002991 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2992 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2994 } else {
2995 int val = *valp;
2996 unsigned long lval;
2997 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00002998 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07002999 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003001 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 lval = (unsigned long)val;
3003 }
3004 *lvalp = jiffies_to_clock_t(lval);
3005 }
3006 return 0;
3007}
3008
Amerigo Wang00b7c332010-05-05 00:26:45 +00003009static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 int *valp,
3011 int write, void *data)
3012{
3013 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02003014 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3015
3016 if (jif > INT_MAX)
3017 return 1;
3018 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 } else {
3020 int val = *valp;
3021 unsigned long lval;
3022 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003023 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07003024 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00003026 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 lval = (unsigned long)val;
3028 }
3029 *lvalp = jiffies_to_msecs(lval);
3030 }
3031 return 0;
3032}
3033
3034/**
3035 * proc_dointvec_jiffies - read a vector of integers as seconds
3036 * @table: the sysctl table
3037 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 * @buffer: the user buffer
3039 * @lenp: the size of the user buffer
3040 * @ppos: file position
3041 *
3042 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3043 * values from/to the user buffer, treated as an ASCII string.
3044 * The values read are assumed to be in seconds, and are converted into
3045 * jiffies.
3046 *
3047 * Returns 0 on success.
3048 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003049int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 void __user *buffer, size_t *lenp, loff_t *ppos)
3051{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003052 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 do_proc_dointvec_jiffies_conv,NULL);
3054}
3055
3056/**
3057 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3058 * @table: the sysctl table
3059 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 * @buffer: the user buffer
3061 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08003062 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 *
3064 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3065 * values from/to the user buffer, treated as an ASCII string.
3066 * The values read are assumed to be in 1/USER_HZ seconds, and
3067 * are converted into jiffies.
3068 *
3069 * Returns 0 on success.
3070 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003071int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 void __user *buffer, size_t *lenp, loff_t *ppos)
3073{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003074 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 do_proc_dointvec_userhz_jiffies_conv,NULL);
3076}
3077
3078/**
3079 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3080 * @table: the sysctl table
3081 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 * @buffer: the user buffer
3083 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07003084 * @ppos: file position
3085 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07003086 *
3087 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3088 * values from/to the user buffer, treated as an ASCII string.
3089 * The values read are assumed to be in 1/1000 seconds, and
3090 * are converted into jiffies.
3091 *
3092 * Returns 0 on success.
3093 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003094int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095 void __user *buffer, size_t *lenp, loff_t *ppos)
3096{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003097 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 do_proc_dointvec_ms_jiffies_conv, NULL);
3099}
3100
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003101static int proc_do_cad_pid(struct ctl_table *table, int write,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003102 void __user *buffer, size_t *lenp, loff_t *ppos)
3103{
3104 struct pid *new_pid;
3105 pid_t tmp;
3106 int r;
3107
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08003108 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003109
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003110 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07003111 lenp, ppos, NULL, NULL);
3112 if (r || !write)
3113 return r;
3114
3115 new_pid = find_get_pid(tmp);
3116 if (!new_pid)
3117 return -ESRCH;
3118
3119 put_pid(xchg(&cad_pid, new_pid));
3120 return 0;
3121}
3122
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003123/**
3124 * proc_do_large_bitmap - read/write from/to a large bitmap
3125 * @table: the sysctl table
3126 * @write: %TRUE if this is a write to the sysctl file
3127 * @buffer: the user buffer
3128 * @lenp: the size of the user buffer
3129 * @ppos: file position
3130 *
3131 * The bitmap is stored at table->data and the bitmap length (in bits)
3132 * in table->maxlen.
3133 *
3134 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3135 * large bitmaps may be represented in a compact manner. Writing into
3136 * the file will clear the bitmap then update it with the given input.
3137 *
3138 * Returns 0 on success.
3139 */
3140int proc_do_large_bitmap(struct ctl_table *table, int write,
3141 void __user *buffer, size_t *lenp, loff_t *ppos)
3142{
3143 int err = 0;
3144 bool first = 1;
3145 size_t left = *lenp;
3146 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07003147 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003148 unsigned long *tmp_bitmap = NULL;
3149 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3150
WANG Cong122ff242014-05-12 16:04:53 -07003151 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003152 *lenp = 0;
3153 return 0;
3154 }
3155
3156 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003157 char *kbuf, *p;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003158
3159 if (left > PAGE_SIZE - 1)
3160 left = PAGE_SIZE - 1;
3161
Al Viro70f6cbb2015-12-24 00:13:10 -05003162 p = kbuf = memdup_user_nul(buffer, left);
3163 if (IS_ERR(kbuf))
3164 return PTR_ERR(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003165
Kees Cook6396bb22018-06-12 14:03:40 -07003166 tmp_bitmap = kcalloc(BITS_TO_LONGS(bitmap_len),
3167 sizeof(unsigned long),
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003168 GFP_KERNEL);
3169 if (!tmp_bitmap) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003170 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003171 return -ENOMEM;
3172 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003173 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003174 while (!err && left) {
3175 unsigned long val_a, val_b;
3176 bool neg;
3177
Al Viro70f6cbb2015-12-24 00:13:10 -05003178 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003179 sizeof(tr_a), &c);
3180 if (err)
3181 break;
3182 if (val_a >= bitmap_len || neg) {
3183 err = -EINVAL;
3184 break;
3185 }
3186
3187 val_b = val_a;
3188 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003189 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003190 left--;
3191 }
3192
3193 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05003194 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003195 &neg, tr_b, sizeof(tr_b),
3196 &c);
3197 if (err)
3198 break;
3199 if (val_b >= bitmap_len || neg ||
3200 val_a > val_b) {
3201 err = -EINVAL;
3202 break;
3203 }
3204 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05003205 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003206 left--;
3207 }
3208 }
3209
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003210 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003211 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05003212 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003213 }
Al Viro70f6cbb2015-12-24 00:13:10 -05003214 kfree(kbuf);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003215 } else {
3216 unsigned long bit_a, bit_b = 0;
3217
3218 while (left) {
3219 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3220 if (bit_a >= bitmap_len)
3221 break;
3222 bit_b = find_next_zero_bit(bitmap, bitmap_len,
3223 bit_a + 1) - 1;
3224
3225 if (!first) {
3226 err = proc_put_char(&buffer, &left, ',');
3227 if (err)
3228 break;
3229 }
3230 err = proc_put_long(&buffer, &left, bit_a, false);
3231 if (err)
3232 break;
3233 if (bit_a != bit_b) {
3234 err = proc_put_char(&buffer, &left, '-');
3235 if (err)
3236 break;
3237 err = proc_put_long(&buffer, &left, bit_b, false);
3238 if (err)
3239 break;
3240 }
3241
3242 first = 0; bit_b++;
3243 }
3244 if (!err)
3245 err = proc_put_char(&buffer, &left, '\n');
3246 }
3247
3248 if (!err) {
3249 if (write) {
3250 if (*ppos)
3251 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3252 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07003253 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003254 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003255 *lenp -= left;
3256 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003257 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08003258
3259 kfree(tmp_bitmap);
3260 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00003261}
3262
Jovi Zhang55610502011-01-12 17:00:45 -08003263#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003265int proc_dostring(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 void __user *buffer, size_t *lenp, loff_t *ppos)
3267{
3268 return -ENOSYS;
3269}
3270
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003271int proc_dointvec(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 void __user *buffer, size_t *lenp, loff_t *ppos)
3273{
3274 return -ENOSYS;
3275}
3276
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003277int proc_douintvec(struct ctl_table *table, int write,
3278 void __user *buffer, size_t *lenp, loff_t *ppos)
3279{
3280 return -ENOSYS;
3281}
3282
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003283int proc_dointvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 void __user *buffer, size_t *lenp, loff_t *ppos)
3285{
3286 return -ENOSYS;
3287}
3288
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003289int proc_douintvec_minmax(struct ctl_table *table, int write,
3290 void __user *buffer, size_t *lenp, loff_t *ppos)
3291{
3292 return -ENOSYS;
3293}
3294
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003295int proc_dointvec_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 void __user *buffer, size_t *lenp, loff_t *ppos)
3297{
3298 return -ENOSYS;
3299}
3300
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003301int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 void __user *buffer, size_t *lenp, loff_t *ppos)
3303{
3304 return -ENOSYS;
3305}
3306
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003307int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 void __user *buffer, size_t *lenp, loff_t *ppos)
3309{
3310 return -ENOSYS;
3311}
3312
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07003313int proc_doulongvec_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 void __user *buffer, size_t *lenp, loff_t *ppos)
3315{
3316 return -ENOSYS;
3317}
3318
Eric W. Biedermand8217f02007-10-18 03:05:22 -07003319int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 void __user *buffer,
3321 size_t *lenp, loff_t *ppos)
3322{
3323 return -ENOSYS;
3324}
3325
3326
Jovi Zhang55610502011-01-12 17:00:45 -08003327#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -08003329#ifdef CONFIG_BPF_SYSCALL
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08003330static int proc_dointvec_minmax_bpf_stats(struct ctl_table *table, int write,
3331 void __user *buffer, size_t *lenp,
3332 loff_t *ppos)
3333{
3334 int ret, bpf_stats = *(int *)table->data;
3335 struct ctl_table tmp = *table;
3336
3337 if (write && !capable(CAP_SYS_ADMIN))
3338 return -EPERM;
3339
3340 tmp.data = &bpf_stats;
3341 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3342 if (write && !ret) {
3343 *(int *)table->data = bpf_stats;
3344 if (bpf_stats)
3345 static_branch_enable(&bpf_stats_enabled_key);
3346 else
3347 static_branch_disable(&bpf_stats_enabled_key);
3348 }
3349 return ret;
3350}
Alexei Starovoitov3fcc5532019-02-27 18:30:44 -08003351#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352/*
3353 * No sense putting this after each symbol definition, twice,
3354 * exception granted :-)
3355 */
3356EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003357EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358EXPORT_SYMBOL(proc_dointvec_jiffies);
3359EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003360EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3362EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3363EXPORT_SYMBOL(proc_dostring);
3364EXPORT_SYMBOL(proc_doulongvec_minmax);
3365EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);