blob: 62fbd09b5dc1c03eca02f0f99af6b9e0d1df44ac [file] [log] [blame]
Thomas Gleixner457c8992019-05-19 13:08:55 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * sysctl.c: General linux system control interface
4 *
5 * Begun 24 March 1995, Stephen Tweedie
6 * Added /proc support, Dec 1995
7 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
8 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
9 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
10 * Dynamic registration fixes, Stephen Tweedie.
11 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
12 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Horn.
14 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
15 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
16 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * Wendling.
18 * The list_for_each() macro wasn't appropriate for the sysctl loop.
19 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
20 */
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/module.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080023#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/mm.h>
25#include <linux/swap.h>
26#include <linux/slab.h>
27#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070028#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080029#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080030#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070032#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/ctype.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070034#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070035#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/init.h>
37#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010038#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030039#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/sysrq.h>
41#include <linux/highuid.h>
42#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020043#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070044#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070047#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/times.h>
49#include <linux/limits.h>
50#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020051#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070053#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080054#include <linux/nfs_fs.h>
55#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070056#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020057#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020058#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050059#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020060#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070061#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040062#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070063#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000064#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060065#include <linux/sched/sysctl.h>
Ingo Molnarf7ccbae2017-02-08 18:51:30 +010066#include <linux/sched/coredump.h>
Kees Cook79847542014-01-23 15:55:59 -080067#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070068#include <linux/bpf.h>
Eric W. Biedermand2921682016-09-28 00:27:17 -050069#include <linux/mount.h>
Peter Xucefdca02019-05-13 17:16:41 -070070#include <linux/userfaultfd_k.h>
Christoph Hellwig2374c092020-04-24 08:43:36 +020071#include <linux/coredump.h>
72#include <linux/latencytop.h>
73#include <linux/pid.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Christian Brauner7f2923c2019-03-07 16:29:40 -080075#include "../lib/kstrtox.h"
76
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080077#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#include <asm/processor.h>
79
Andi Kleen29cbc782006-09-30 01:47:55 +020080#ifdef CONFIG_X86
81#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010082#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010083#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020084#endif
David Howellsd550bbd2012-03-28 18:30:03 +010085#ifdef CONFIG_SPARC
86#include <asm/setup.h>
87#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080088#ifdef CONFIG_BSD_PROCESS_ACCT
89#include <linux/acct.h>
90#endif
Dave Young4f0e0562010-03-10 15:24:09 -080091#ifdef CONFIG_RT_MUTEXES
92#include <linux/rtmutex.h>
93#endif
Dave Young2edf5e42010-03-10 15:24:10 -080094#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
95#include <linux/lockdep.h>
96#endif
Dave Young15485a42010-03-10 15:24:07 -080097#ifdef CONFIG_CHR_DEV_SG
98#include <scsi/sg.h>
99#endif
Alexander Popov964c9df2018-08-17 01:17:03 +0300100#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
101#include <linux/stackleak.h>
102#endif
Don Zickus58687ac2010-05-07 17:11:44 -0400103#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -0500104#include <linux/nmi.h>
105#endif
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107#if defined(CONFIG_SYSCTL)
108
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700109/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400110#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700111static int sixty = 60;
112#endif
113
Aaron Tomlin270750db2014-01-20 17:34:13 +0000114static int __maybe_unused neg_one = -1;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700115static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700116static int __maybe_unused four = 4;
Will Deacon9002b212019-04-05 18:39:38 -0700117static unsigned long zero_ul;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800118static unsigned long one_ul = 1;
Christian Brauner32a5ad92019-03-07 16:29:43 -0800119static unsigned long long_max = LONG_MAX;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700120static int one_hundred = 100;
Johannes Weinerc8439662020-06-03 16:02:37 -0700121static int two_hundred = 200;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700122static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700123#ifdef CONFIG_PRINTK
124static int ten_thousand = 10000;
125#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300126#ifdef CONFIG_PERF_EVENTS
127static int six_hundred_forty_kb = 640 * 1024;
128#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700129
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700130/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
131static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
134static int maxolduid = 65535;
135static int minolduid;
136
137static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700138static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Dmitry Vyukova2e51442018-08-21 21:55:52 -0700140/*
141 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
142 * and hung_task_check_interval_secs
143 */
Liu Hua80df2842014-04-07 15:38:57 -0700144#ifdef CONFIG_DETECT_HUNG_TASK
145static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
146#endif
147
Dave Youngd14f1722010-02-25 20:28:57 -0500148#ifdef CONFIG_INOTIFY_USER
149#include <linux/inotify.h>
150#endif
Vineet Guptab6fca722013-01-09 20:06:28 +0530151
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700152#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700153
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700154/**
155 * enum sysctl_writes_mode - supported sysctl write modes
156 *
157 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
Weitao Hou65f50f22019-07-16 16:26:54 -0700158 * to be written, and multiple writes on the same sysctl file descriptor
159 * will rewrite the sysctl value, regardless of file position. No warning
160 * is issued when the initial position is not 0.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700161 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
Weitao Hou65f50f22019-07-16 16:26:54 -0700162 * not 0.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700163 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
Weitao Hou65f50f22019-07-16 16:26:54 -0700164 * file position 0 and the value must be fully contained in the buffer
165 * sent to the write syscall. If dealing with strings respect the file
166 * position, but restrict this to the max length of the buffer, anything
167 * passed the max length will be ignored. Multiple writes will append
168 * to the buffer.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700169 *
170 * These write modes control how current file position affects the behavior of
171 * updating sysctl values through the proc interface on each write.
172 */
173enum sysctl_writes_mode {
174 SYSCTL_WRITES_LEGACY = -1,
175 SYSCTL_WRITES_WARN = 0,
176 SYSCTL_WRITES_STRICT = 1,
177};
Kees Cookf4aacea2014-06-06 14:37:19 -0700178
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700179static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Christoph Hellwigf461d2d2020-04-24 08:43:37 +0200180#endif /* CONFIG_PROC_SYSCTL */
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800181
Alexandre Ghiti67f39772019-09-23 15:38:47 -0700182#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
183 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184int sysctl_legacy_va_layout;
185#endif
186
Ingo Molnar77e54a12007-07-09 18:52:00 +0200187#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100188static int min_sched_granularity_ns = 100000; /* 100 usecs */
189static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
190static int min_wakeup_granularity_ns; /* 0 usecs */
191static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200192#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100193static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
194static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200195#endif /* CONFIG_SMP */
196#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200197
Mel Gorman5e771902010-05-24 14:32:31 -0700198#ifdef CONFIG_COMPACTION
199static int min_extfrag_threshold;
200static int max_extfrag_threshold = 1000;
201#endif
202
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700203#endif /* CONFIG_SYSCTL */
204
Arnd Bergmann5447e8e2020-05-05 16:07:12 +0200205#if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL)
Song Liud46edd62020-04-30 00:15:04 -0700206static int bpf_stats_handler(struct ctl_table *table, int write,
Tobias Klauser7787b6f2020-08-24 16:20:47 +0200207 void *buffer, size_t *lenp, loff_t *ppos)
Song Liud46edd62020-04-30 00:15:04 -0700208{
209 struct static_key *key = (struct static_key *)table->data;
210 static int saved_val;
211 int val, ret;
212 struct ctl_table tmp = {
213 .data = &val,
214 .maxlen = sizeof(val),
215 .mode = table->mode,
216 .extra1 = SYSCTL_ZERO,
217 .extra2 = SYSCTL_ONE,
218 };
219
220 if (write && !capable(CAP_SYS_ADMIN))
221 return -EPERM;
222
223 mutex_lock(&bpf_stats_enabled_mutex);
224 val = saved_val;
225 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
226 if (write && !ret && val != saved_val) {
227 if (val)
228 static_key_slow_inc(key);
229 else
230 static_key_slow_dec(key);
231 saved_val = val;
232 }
233 mutex_unlock(&bpf_stats_enabled_mutex);
234 return ret;
235}
236#endif
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238/*
239 * /proc/sys support
240 */
241
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700242#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Kees Cookf8808302014-06-06 14:37:17 -0700244static int _proc_do_string(char *data, int maxlen, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200245 char *buffer, size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700246{
247 size_t len;
Christoph Hellwig32927392020-04-24 08:43:38 +0200248 char c, *p;
Oleg Nesterov8d060872007-02-10 01:46:38 -0800249
250 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700251 *lenp = 0;
252 return 0;
253 }
Oleg Nesterov8d060872007-02-10 01:46:38 -0800254
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700255 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -0700256 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
257 /* Only continue writes not past the end of buffer. */
258 len = strlen(data);
259 if (len > maxlen - 1)
260 len = maxlen - 1;
261
262 if (*ppos > len)
263 return 0;
264 len = *ppos;
265 } else {
266 /* Start writing from beginning of buffer. */
267 len = 0;
268 }
269
Kees Cook2ca9bb42014-06-06 14:37:18 -0700270 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700271 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -0700272 while ((p - buffer) < *lenp && len < maxlen - 1) {
Christoph Hellwig32927392020-04-24 08:43:38 +0200273 c = *(p++);
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700274 if (c == 0 || c == '\n')
275 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -0700276 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700277 }
Kees Cookf8808302014-06-06 14:37:17 -0700278 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700279 } else {
280 len = strlen(data);
281 if (len > maxlen)
282 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -0800283
284 if (*ppos > len) {
285 *lenp = 0;
286 return 0;
287 }
288
289 data += *ppos;
290 len -= *ppos;
291
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700292 if (len > *lenp)
293 len = *lenp;
294 if (len)
Christoph Hellwig32927392020-04-24 08:43:38 +0200295 memcpy(buffer, data, len);
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700296 if (len < *lenp) {
Christoph Hellwig32927392020-04-24 08:43:38 +0200297 buffer[len] = '\n';
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700298 len++;
299 }
300 *lenp = len;
301 *ppos += len;
302 }
303 return 0;
304}
305
Kees Cookf4aacea2014-06-06 14:37:19 -0700306static void warn_sysctl_write(struct ctl_table *table)
307{
308 pr_warn_once("%s wrote to %s when file position was not 0!\n"
309 "This will not be supported in the future. To silence this\n"
310 "warning, set kernel.sysctl_writes_strict = -1\n",
311 current->comm, table->procname);
312}
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314/**
Randy Dunlap5f733e82018-08-21 22:01:06 -0700315 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700316 * @ppos: file position
317 * @table: the sysctl table
318 *
319 * Returns true if the first position is non-zero and the sysctl_writes_strict
320 * mode indicates this is not allowed for numeric input types. String proc
Randy Dunlap5f733e82018-08-21 22:01:06 -0700321 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700322 */
323static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
324 struct ctl_table *table)
325{
326 if (!*ppos)
327 return false;
328
329 switch (sysctl_writes_strict) {
330 case SYSCTL_WRITES_STRICT:
331 return true;
332 case SYSCTL_WRITES_WARN:
333 warn_sysctl_write(table);
334 return false;
335 default:
336 return false;
337 }
338}
339
340/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 * proc_dostring - read a string sysctl
342 * @table: the sysctl table
343 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 * @buffer: the user buffer
345 * @lenp: the size of the user buffer
346 * @ppos: file position
347 *
348 * Reads/writes a string from/to the user buffer. If the kernel
349 * buffer provided is not large enough to hold the string, the
350 * string is truncated. The copied string is %NULL-terminated.
351 * If the string is being read by the user process, it is copied
352 * and a newline '\n' is added. It is truncated if the buffer is
353 * not large enough.
354 *
355 * Returns 0 on success.
356 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700357int proc_dostring(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200358 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700360 if (write)
361 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -0700362
Christoph Hellwig32927392020-04-24 08:43:38 +0200363 return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
364 ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365}
366
Amerigo Wang00b7c332010-05-05 00:26:45 +0000367static size_t proc_skip_spaces(char **buf)
368{
369 size_t ret;
370 char *tmp = skip_spaces(*buf);
371 ret = tmp - *buf;
372 *buf = tmp;
373 return ret;
374}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Octavian Purdila9f977fb2010-05-05 00:26:55 +0000376static void proc_skip_char(char **buf, size_t *size, const char v)
377{
378 while (*size) {
379 if (**buf != v)
380 break;
381 (*size)--;
382 (*buf)++;
383 }
384}
385
Christian Brauner7f2923c2019-03-07 16:29:40 -0800386/**
387 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
388 * fail on overflow
389 *
390 * @cp: kernel buffer containing the string to parse
391 * @endp: pointer to store the trailing characters
392 * @base: the base to use
393 * @res: where the parsed integer will be stored
394 *
395 * In case of success 0 is returned and @res will contain the parsed integer,
396 * @endp will hold any trailing characters.
397 * This function will fail the parse on overflow. If there wasn't an overflow
398 * the function will defer the decision what characters count as invalid to the
399 * caller.
400 */
401static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
402 unsigned long *res)
403{
404 unsigned long long result;
405 unsigned int rv;
406
407 cp = _parse_integer_fixup_radix(cp, &base);
408 rv = _parse_integer(cp, base, &result);
409 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
410 return -ERANGE;
411
412 cp += rv;
413
414 if (endp)
415 *endp = (char *)cp;
416
417 *res = (unsigned long)result;
418 return 0;
419}
420
Amerigo Wang00b7c332010-05-05 00:26:45 +0000421#define TMPBUFLEN 22
422/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700423 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +0000424 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700425 * @buf: a kernel buffer
426 * @size: size of the kernel buffer
427 * @val: this is where the number will be stored
428 * @neg: set to %TRUE if number is negative
429 * @perm_tr: a vector which contains the allowed trailers
430 * @perm_tr_len: size of the perm_tr vector
431 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +0000432 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700433 * In case of success %0 is returned and @buf and @size are updated with
434 * the amount of bytes read. If @tr is non-NULL and a trailing
435 * character exists (size is non-zero after returning from this
436 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +0000437 */
438static int proc_get_long(char **buf, size_t *size,
439 unsigned long *val, bool *neg,
440 const char *perm_tr, unsigned perm_tr_len, char *tr)
441{
442 int len;
443 char *p, tmp[TMPBUFLEN];
444
445 if (!*size)
446 return -EINVAL;
447
448 len = *size;
449 if (len > TMPBUFLEN - 1)
450 len = TMPBUFLEN - 1;
451
452 memcpy(tmp, *buf, len);
453
454 tmp[len] = 0;
455 p = tmp;
456 if (*p == '-' && *size > 1) {
457 *neg = true;
458 p++;
459 } else
460 *neg = false;
461 if (!isdigit(*p))
462 return -EINVAL;
463
Christian Brauner7f2923c2019-03-07 16:29:40 -0800464 if (strtoul_lenient(p, &p, 0, val))
465 return -EINVAL;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000466
467 len = p - tmp;
468
469 /* We don't know if the next char is whitespace thus we may accept
470 * invalid integers (e.g. 1234...a) or two integers instead of one
471 * (e.g. 123...1). So lets not allow such large numbers. */
472 if (len == TMPBUFLEN - 1)
473 return -EINVAL;
474
475 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
476 return -EINVAL;
477
478 if (tr && (len < *size))
479 *tr = *p;
480
481 *buf += len;
482 *size -= len;
483
484 return 0;
485}
486
487/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700488 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +0000489 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700490 * @buf: the user buffer
491 * @size: the size of the user buffer
492 * @val: the integer to be converted
493 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +0000494 *
Christoph Hellwig32927392020-04-24 08:43:38 +0200495 * In case of success @buf and @size are updated with the amount of bytes
496 * written.
Amerigo Wang00b7c332010-05-05 00:26:45 +0000497 */
Christoph Hellwig32927392020-04-24 08:43:38 +0200498static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
Amerigo Wang00b7c332010-05-05 00:26:45 +0000499{
500 int len;
501 char tmp[TMPBUFLEN], *p = tmp;
502
503 sprintf(p, "%s%lu", neg ? "-" : "", val);
504 len = strlen(tmp);
505 if (len > *size)
506 len = *size;
Christoph Hellwig32927392020-04-24 08:43:38 +0200507 memcpy(*buf, tmp, len);
Amerigo Wang00b7c332010-05-05 00:26:45 +0000508 *size -= len;
509 *buf += len;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000510}
511#undef TMPBUFLEN
512
Christoph Hellwig32927392020-04-24 08:43:38 +0200513static void proc_put_char(void **buf, size_t *size, char c)
Amerigo Wang00b7c332010-05-05 00:26:45 +0000514{
515 if (*size) {
Christoph Hellwig32927392020-04-24 08:43:38 +0200516 char **buffer = (char **)buf;
517 **buffer = c;
518
519 (*size)--;
520 (*buffer)++;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000521 *buf = *buffer;
522 }
Amerigo Wang00b7c332010-05-05 00:26:45 +0000523}
524
525static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 int *valp,
527 int write, void *data)
528{
529 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -0700530 if (*negp) {
531 if (*lvalp > (unsigned long) INT_MAX + 1)
532 return -EINVAL;
533 *valp = -*lvalp;
534 } else {
535 if (*lvalp > (unsigned long) INT_MAX)
536 return -EINVAL;
537 *valp = *lvalp;
538 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 } else {
540 int val = *valp;
541 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +0000542 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -0700543 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +0000545 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 *lvalp = (unsigned long)val;
547 }
548 }
549 return 0;
550}
551
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700552static int do_proc_douintvec_conv(unsigned long *lvalp,
553 unsigned int *valp,
554 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700555{
556 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700557 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700558 return -EINVAL;
559 *valp = *lvalp;
560 } else {
561 unsigned int val = *valp;
562 *lvalp = (unsigned long)val;
563 }
564 return 0;
565}
566
Amerigo Wang00b7c332010-05-05 00:26:45 +0000567static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
568
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700569static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200570 int write, void *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700571 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +0000572 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 int write, void *data),
574 void *data)
575{
Amerigo Wang00b7c332010-05-05 00:26:45 +0000576 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000577 size_t left;
Christoph Hellwig32927392020-04-24 08:43:38 +0200578 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Amerigo Wang00b7c332010-05-05 00:26:45 +0000580 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 *lenp = 0;
582 return 0;
583 }
584
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700585 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 vleft = table->maxlen / sizeof(*i);
587 left = *lenp;
588
589 if (!conv)
590 conv = do_proc_dointvec_conv;
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700593 if (proc_first_pos_non_zero_ignore(ppos, table))
594 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -0700595
Amerigo Wang00b7c332010-05-05 00:26:45 +0000596 if (left > PAGE_SIZE - 1)
597 left = PAGE_SIZE - 1;
Christoph Hellwig32927392020-04-24 08:43:38 +0200598 p = buffer;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000599 }
600
601 for (; left && vleft--; i++, first=0) {
602 unsigned long lval;
603 bool neg;
604
605 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -0500606 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +0000607
J. R. Okajima563b0462010-05-25 16:10:14 -0700608 if (!left)
609 break;
Al Viro70f6cbb2015-12-24 00:13:10 -0500610 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +0000611 proc_wspace_sep,
612 sizeof(proc_wspace_sep), NULL);
613 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000615 if (conv(&neg, &lval, i, 1, data)) {
616 err = -EINVAL;
617 break;
618 }
619 } else {
620 if (conv(&neg, &lval, i, 0, data)) {
621 err = -EINVAL;
622 break;
623 }
624 if (!first)
Christoph Hellwig32927392020-04-24 08:43:38 +0200625 proc_put_char(&buffer, &left, '\t');
626 proc_put_long(&buffer, &left, lval, neg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 }
628 }
Amerigo Wang00b7c332010-05-05 00:26:45 +0000629
630 if (!write && !first && left && !err)
Christoph Hellwig32927392020-04-24 08:43:38 +0200631 proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -0700632 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -0500633 left -= proc_skip_spaces(&p);
Christoph Hellwig32927392020-04-24 08:43:38 +0200634 if (write && first)
635 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -0700637out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000639 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640}
641
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700642static int do_proc_dointvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200643 void *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +0000644 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700645 int write, void *data),
646 void *data)
647{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700648 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700649 buffer, lenp, ppos, conv, data);
650}
651
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700652static int do_proc_douintvec_w(unsigned int *tbl_data,
653 struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200654 void *buffer,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700655 size_t *lenp, loff_t *ppos,
656 int (*conv)(unsigned long *lvalp,
657 unsigned int *valp,
658 int write, void *data),
659 void *data)
660{
661 unsigned long lval;
662 int err = 0;
663 size_t left;
664 bool neg;
Christoph Hellwig32927392020-04-24 08:43:38 +0200665 char *p = buffer;
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700666
667 left = *lenp;
668
669 if (proc_first_pos_non_zero_ignore(ppos, table))
670 goto bail_early;
671
672 if (left > PAGE_SIZE - 1)
673 left = PAGE_SIZE - 1;
674
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700675 left -= proc_skip_spaces(&p);
676 if (!left) {
677 err = -EINVAL;
678 goto out_free;
679 }
680
681 err = proc_get_long(&p, &left, &lval, &neg,
682 proc_wspace_sep,
683 sizeof(proc_wspace_sep), NULL);
684 if (err || neg) {
685 err = -EINVAL;
686 goto out_free;
687 }
688
689 if (conv(&lval, tbl_data, 1, data)) {
690 err = -EINVAL;
691 goto out_free;
692 }
693
694 if (!err && left)
695 left -= proc_skip_spaces(&p);
696
697out_free:
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700698 if (err)
699 return -EINVAL;
700
701 return 0;
702
703 /* This is in keeping with old __do_proc_dointvec() */
704bail_early:
705 *ppos += *lenp;
706 return err;
707}
708
Christoph Hellwig32927392020-04-24 08:43:38 +0200709static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700710 size_t *lenp, loff_t *ppos,
711 int (*conv)(unsigned long *lvalp,
712 unsigned int *valp,
713 int write, void *data),
714 void *data)
715{
716 unsigned long lval;
717 int err = 0;
718 size_t left;
719
720 left = *lenp;
721
722 if (conv(&lval, tbl_data, 0, data)) {
723 err = -EINVAL;
724 goto out;
725 }
726
Christoph Hellwig32927392020-04-24 08:43:38 +0200727 proc_put_long(&buffer, &left, lval, false);
728 if (!left)
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700729 goto out;
730
Christoph Hellwig32927392020-04-24 08:43:38 +0200731 proc_put_char(&buffer, &left, '\n');
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700732
733out:
734 *lenp -= left;
735 *ppos += *lenp;
736
737 return err;
738}
739
740static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200741 int write, void *buffer,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700742 size_t *lenp, loff_t *ppos,
743 int (*conv)(unsigned long *lvalp,
744 unsigned int *valp,
745 int write, void *data),
746 void *data)
747{
748 unsigned int *i, vleft;
749
750 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
751 *lenp = 0;
752 return 0;
753 }
754
755 i = (unsigned int *) tbl_data;
756 vleft = table->maxlen / sizeof(*i);
757
758 /*
759 * Arrays are not supported, keep this simple. *Do not* add
760 * support for them.
761 */
762 if (vleft != 1) {
763 *lenp = 0;
764 return -EINVAL;
765 }
766
767 if (!conv)
768 conv = do_proc_douintvec_conv;
769
770 if (write)
771 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
772 conv, data);
773 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
774}
775
776static int do_proc_douintvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200777 void *buffer, size_t *lenp, loff_t *ppos,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700778 int (*conv)(unsigned long *lvalp,
779 unsigned int *valp,
780 int write, void *data),
781 void *data)
782{
783 return __do_proc_douintvec(table->data, table, write,
784 buffer, lenp, ppos, conv, data);
785}
786
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787/**
788 * proc_dointvec - read a vector of integers
789 * @table: the sysctl table
790 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 * @buffer: the user buffer
792 * @lenp: the size of the user buffer
793 * @ppos: file position
794 *
795 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
796 * values from/to the user buffer, treated as an ASCII string.
797 *
798 * Returns 0 on success.
799 */
Christoph Hellwig32927392020-04-24 08:43:38 +0200800int proc_dointvec(struct ctl_table *table, int write, void *buffer,
801 size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700803 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
804}
805
Sebastian Andrzej Siewior6923aa02020-04-01 21:10:42 -0700806#ifdef CONFIG_COMPACTION
807static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200808 int write, void *buffer, size_t *lenp, loff_t *ppos)
Sebastian Andrzej Siewior6923aa02020-04-01 21:10:42 -0700809{
810 int ret, old;
811
812 if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
813 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
814
815 old = *(int *)table->data;
816 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
817 if (ret)
818 return ret;
819 if (old != *(int *)table->data)
820 pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
821 table->procname, current->comm,
822 task_pid_nr(current));
823 return ret;
824}
825#endif
826
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700827/**
828 * proc_douintvec - read a vector of unsigned integers
829 * @table: the sysctl table
830 * @write: %TRUE if this is a write to the sysctl file
831 * @buffer: the user buffer
832 * @lenp: the size of the user buffer
833 * @ppos: file position
834 *
835 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
836 * values from/to the user buffer, treated as an ASCII string.
837 *
838 * Returns 0 on success.
839 */
Christoph Hellwig32927392020-04-24 08:43:38 +0200840int proc_douintvec(struct ctl_table *table, int write, void *buffer,
841 size_t *lenp, loff_t *ppos)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700842{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700843 return do_proc_douintvec(table, write, buffer, lenp, ppos,
844 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845}
846
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800847/*
Andi Kleen25ddbb12008-10-15 22:01:41 -0700848 * Taint values can only be increased
849 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800850 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700851static int proc_taint(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200852 void *buffer, size_t *lenp, loff_t *ppos)
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800853{
Andi Kleen25ddbb12008-10-15 22:01:41 -0700854 struct ctl_table t;
855 unsigned long tmptaint = get_taint();
856 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800857
Bastian Blank91fcd412007-04-23 14:41:14 -0700858 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800859 return -EPERM;
860
Andi Kleen25ddbb12008-10-15 22:01:41 -0700861 t = *table;
862 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700863 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700864 if (err < 0)
865 return err;
866
867 if (write) {
Rafael Aquinidb38d5c2020-06-07 21:40:17 -0700868 int i;
869
870 /*
871 * If we are relying on panic_on_taint not producing
872 * false positives due to userspace input, bail out
873 * before setting the requested taint flags.
874 */
875 if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
876 return -EINVAL;
877
Andi Kleen25ddbb12008-10-15 22:01:41 -0700878 /*
879 * Poor man's atomic or. Not worth adding a primitive
880 * to everyone's atomic.h for this
881 */
Rafael Aquinie77132e2020-06-07 21:40:51 -0700882 for (i = 0; i < TAINT_FLAGS_COUNT; i++)
883 if ((1UL << i) & tmptaint)
Rusty Russell373d4d02013-01-21 17:17:39 +1030884 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700885 }
886
887 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800888}
889
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700890#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700891static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200892 void *buffer, size_t *lenp, loff_t *ppos)
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700893{
894 if (write && !capable(CAP_SYS_ADMIN))
895 return -EPERM;
896
897 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
898}
899#endif
900
Waiman Long24704f32018-04-10 16:35:38 -0700901/**
902 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
903 * @min: pointer to minimum allowable value
904 * @max: pointer to maximum allowable value
905 *
906 * The do_proc_dointvec_minmax_conv_param structure provides the
907 * minimum and maximum values for doing range checking for those sysctl
908 * parameters that use the proc_dointvec_minmax() handler.
909 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910struct do_proc_dointvec_minmax_conv_param {
911 int *min;
912 int *max;
913};
914
Amerigo Wang00b7c332010-05-05 00:26:45 +0000915static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
916 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 int write, void *data)
918{
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700919 int tmp, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 struct do_proc_dointvec_minmax_conv_param *param = data;
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700921 /*
922 * If writing, first do so via a temporary local int so we can
923 * bounds-check it before touching *valp.
924 */
925 int *ip = write ? &tmp : valp;
926
927 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
928 if (ret)
929 return ret;
930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 if (write) {
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700932 if ((param->min && *param->min > tmp) ||
933 (param->max && *param->max < tmp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 return -EINVAL;
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700935 *valp = tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 }
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 return 0;
939}
940
941/**
942 * proc_dointvec_minmax - read a vector of integers with min/max values
943 * @table: the sysctl table
944 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 * @buffer: the user buffer
946 * @lenp: the size of the user buffer
947 * @ppos: file position
948 *
949 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
950 * values from/to the user buffer, treated as an ASCII string.
951 *
952 * This routine will ensure the values are within the range specified by
953 * table->extra1 (min) and table->extra2 (max).
954 *
Waiman Long24704f32018-04-10 16:35:38 -0700955 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700957int proc_dointvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200958 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959{
960 struct do_proc_dointvec_minmax_conv_param param = {
961 .min = (int *) table->extra1,
962 .max = (int *) table->extra2,
963 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700964 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 do_proc_dointvec_minmax_conv, &param);
966}
967
Waiman Long24704f32018-04-10 16:35:38 -0700968/**
969 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
970 * @min: pointer to minimum allowable value
971 * @max: pointer to maximum allowable value
972 *
973 * The do_proc_douintvec_minmax_conv_param structure provides the
974 * minimum and maximum values for doing range checking for those sysctl
975 * parameters that use the proc_douintvec_minmax() handler.
976 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -0700977struct do_proc_douintvec_minmax_conv_param {
978 unsigned int *min;
979 unsigned int *max;
980};
981
982static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
983 unsigned int *valp,
984 int write, void *data)
985{
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700986 int ret;
987 unsigned int tmp;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -0700988 struct do_proc_douintvec_minmax_conv_param *param = data;
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700989 /* write via temporary local uint for bounds-checking */
990 unsigned int *up = write ? &tmp : valp;
991
992 ret = do_proc_douintvec_conv(lvalp, up, write, data);
993 if (ret)
994 return ret;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -0700995
996 if (write) {
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700997 if ((param->min && *param->min > tmp) ||
998 (param->max && *param->max < tmp))
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -0700999 return -ERANGE;
1000
Zev Weiss2bc4fc62019-03-11 23:28:06 -07001001 *valp = tmp;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001002 }
1003
1004 return 0;
1005}
1006
1007/**
1008 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
1009 * @table: the sysctl table
1010 * @write: %TRUE if this is a write to the sysctl file
1011 * @buffer: the user buffer
1012 * @lenp: the size of the user buffer
1013 * @ppos: file position
1014 *
1015 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
1016 * values from/to the user buffer, treated as an ASCII string. Negative
1017 * strings are not allowed.
1018 *
1019 * This routine will ensure the values are within the range specified by
1020 * table->extra1 (min) and table->extra2 (max). There is a final sanity
1021 * check for UINT_MAX to avoid having to support wrap around uses from
1022 * userspace.
1023 *
Waiman Long24704f32018-04-10 16:35:38 -07001024 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001025 */
1026int proc_douintvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001027 void *buffer, size_t *lenp, loff_t *ppos)
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001028{
1029 struct do_proc_douintvec_minmax_conv_param param = {
1030 .min = (unsigned int *) table->extra1,
1031 .max = (unsigned int *) table->extra2,
1032 };
1033 return do_proc_douintvec(table, write, buffer, lenp, ppos,
1034 do_proc_douintvec_minmax_conv, &param);
1035}
1036
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001037static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
1038 unsigned int *valp,
1039 int write, void *data)
1040{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001041 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08001042 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001043
Joe Lawrencefb910c42017-11-17 15:29:28 -08001044 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001045 if (val == 0)
1046 return -EINVAL;
1047
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001048 *valp = val;
1049 } else {
1050 unsigned int val = *valp;
1051 *lvalp = (unsigned long) val;
1052 }
1053
1054 return 0;
1055}
1056
Eric Biggers319e0a22018-02-06 15:41:49 -08001057static int proc_dopipe_max_size(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001058 void *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001059{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001060 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08001061 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001062}
1063
Kees Cook54b50192012-07-30 14:39:18 -07001064static void validate_coredump_safety(void)
1065{
Alex Kelly046d6622012-10-04 17:15:23 -07001066#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08001067 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07001068 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08001069 printk(KERN_WARNING
1070"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
1071"Pipe handler or fully qualified core dump path required.\n"
1072"Set kernel.core_pattern before fs.suid_dumpable.\n"
1073 );
Kees Cook54b50192012-07-30 14:39:18 -07001074 }
Alex Kelly046d6622012-10-04 17:15:23 -07001075#endif
Kees Cook54b50192012-07-30 14:39:18 -07001076}
1077
1078static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001079 void *buffer, size_t *lenp, loff_t *ppos)
Kees Cook54b50192012-07-30 14:39:18 -07001080{
1081 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1082 if (!error)
1083 validate_coredump_safety();
1084 return error;
1085}
1086
Alex Kelly046d6622012-10-04 17:15:23 -07001087#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07001088static int proc_dostring_coredump(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001089 void *buffer, size_t *lenp, loff_t *ppos)
Kees Cook54b50192012-07-30 14:39:18 -07001090{
1091 int error = proc_dostring(table, write, buffer, lenp, ppos);
1092 if (!error)
1093 validate_coredump_safety();
1094 return error;
1095}
Alex Kelly046d6622012-10-04 17:15:23 -07001096#endif
Kees Cook54b50192012-07-30 14:39:18 -07001097
Dmitry Safonoveaee4172020-03-02 17:51:34 +00001098#ifdef CONFIG_MAGIC_SYSRQ
1099static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001100 void *buffer, size_t *lenp, loff_t *ppos)
Dmitry Safonoveaee4172020-03-02 17:51:34 +00001101{
1102 int tmp, ret;
1103
1104 tmp = sysrq_mask();
1105
1106 ret = __do_proc_dointvec(&tmp, table, write, buffer,
1107 lenp, ppos, NULL, NULL);
1108 if (ret || !write)
1109 return ret;
1110
1111 if (write)
1112 sysrq_toggle_support(tmp);
1113
1114 return 0;
1115}
1116#endif
1117
Christoph Hellwig32927392020-04-24 08:43:38 +02001118static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
1119 int write, void *buffer, size_t *lenp, loff_t *ppos,
1120 unsigned long convmul, unsigned long convdiv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121{
Amerigo Wang00b7c332010-05-05 00:26:45 +00001122 unsigned long *i, *min, *max;
1123 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001124 size_t left;
Christoph Hellwig32927392020-04-24 08:43:38 +02001125 char *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001126
1127 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 *lenp = 0;
1129 return 0;
1130 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00001131
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001132 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 min = (unsigned long *) table->extra1;
1134 max = (unsigned long *) table->extra2;
1135 vleft = table->maxlen / sizeof(unsigned long);
1136 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001137
1138 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07001139 if (proc_first_pos_non_zero_ignore(ppos, table))
1140 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07001141
Amerigo Wang00b7c332010-05-05 00:26:45 +00001142 if (left > PAGE_SIZE - 1)
1143 left = PAGE_SIZE - 1;
Christoph Hellwig32927392020-04-24 08:43:38 +02001144 p = buffer;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001145 }
1146
Eric Dumazet27b3d802010-10-07 12:59:29 -07001147 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001148 unsigned long val;
1149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001151 bool neg;
1152
Al Viro70f6cbb2015-12-24 00:13:10 -05001153 left -= proc_skip_spaces(&p);
Cheng Lin09be1782019-01-03 15:26:13 -08001154 if (!left)
1155 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001156
Al Viro70f6cbb2015-12-24 00:13:10 -05001157 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00001158 proc_wspace_sep,
1159 sizeof(proc_wspace_sep), NULL);
1160 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 break;
1162 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08001164 val = convmul * val / convdiv;
Christian Braunere260ad02019-05-14 15:44:55 -07001165 if ((min && val < *min) || (max && val > *max)) {
1166 err = -EINVAL;
1167 break;
1168 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 *i = val;
1170 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001171 val = convdiv * (*i) / convmul;
Christoph Hellwig32927392020-04-24 08:43:38 +02001172 if (!first)
1173 proc_put_char(&buffer, &left, '\t');
1174 proc_put_long(&buffer, &left, val, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 }
1176 }
1177
Amerigo Wang00b7c332010-05-05 00:26:45 +00001178 if (!write && !first && left && !err)
Christoph Hellwig32927392020-04-24 08:43:38 +02001179 proc_put_char(&buffer, &left, '\n');
Amerigo Wang00b7c332010-05-05 00:26:45 +00001180 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05001181 left -= proc_skip_spaces(&p);
Christoph Hellwig32927392020-04-24 08:43:38 +02001182 if (write && first)
1183 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07001185out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001187 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188}
1189
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001190static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001191 void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1192 unsigned long convdiv)
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001193{
1194 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001195 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001196}
1197
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198/**
1199 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1200 * @table: the sysctl table
1201 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 * @buffer: the user buffer
1203 * @lenp: the size of the user buffer
1204 * @ppos: file position
1205 *
1206 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1207 * values from/to the user buffer, treated as an ASCII string.
1208 *
1209 * This routine will ensure the values are within the range specified by
1210 * table->extra1 (min) and table->extra2 (max).
1211 *
1212 * Returns 0 on success.
1213 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001214int proc_doulongvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001215 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001217 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218}
1219
1220/**
1221 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1222 * @table: the sysctl table
1223 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 * @buffer: the user buffer
1225 * @lenp: the size of the user buffer
1226 * @ppos: file position
1227 *
1228 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1229 * values from/to the user buffer, treated as an ASCII string. The values
1230 * are treated as milliseconds, and converted to jiffies when they are stored.
1231 *
1232 * This routine will ensure the values are within the range specified by
1233 * table->extra1 (min) and table->extra2 (max).
1234 *
1235 * Returns 0 on success.
1236 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001237int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001238 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001240 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 lenp, ppos, HZ, 1000l);
1242}
1243
1244
Amerigo Wang00b7c332010-05-05 00:26:45 +00001245static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 int *valp,
1247 int write, void *data)
1248{
1249 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07001250 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08001251 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1253 } else {
1254 int val = *valp;
1255 unsigned long lval;
1256 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001257 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07001258 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001260 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 lval = (unsigned long)val;
1262 }
1263 *lvalp = lval / HZ;
1264 }
1265 return 0;
1266}
1267
Amerigo Wang00b7c332010-05-05 00:26:45 +00001268static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 int *valp,
1270 int write, void *data)
1271{
1272 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08001273 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1274 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1276 } else {
1277 int val = *valp;
1278 unsigned long lval;
1279 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001280 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07001281 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001283 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 lval = (unsigned long)val;
1285 }
1286 *lvalp = jiffies_to_clock_t(lval);
1287 }
1288 return 0;
1289}
1290
Amerigo Wang00b7c332010-05-05 00:26:45 +00001291static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 int *valp,
1293 int write, void *data)
1294{
1295 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02001296 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1297
1298 if (jif > INT_MAX)
1299 return 1;
1300 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 } else {
1302 int val = *valp;
1303 unsigned long lval;
1304 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001305 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07001306 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001308 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 lval = (unsigned long)val;
1310 }
1311 *lvalp = jiffies_to_msecs(lval);
1312 }
1313 return 0;
1314}
1315
1316/**
1317 * proc_dointvec_jiffies - read a vector of integers as seconds
1318 * @table: the sysctl table
1319 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 * @buffer: the user buffer
1321 * @lenp: the size of the user buffer
1322 * @ppos: file position
1323 *
1324 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1325 * values from/to the user buffer, treated as an ASCII string.
1326 * The values read are assumed to be in seconds, and are converted into
1327 * jiffies.
1328 *
1329 * Returns 0 on success.
1330 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001331int proc_dointvec_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001332 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001334 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 do_proc_dointvec_jiffies_conv,NULL);
1336}
1337
1338/**
1339 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1340 * @table: the sysctl table
1341 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 * @buffer: the user buffer
1343 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08001344 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 *
1346 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1347 * values from/to the user buffer, treated as an ASCII string.
1348 * The values read are assumed to be in 1/USER_HZ seconds, and
1349 * are converted into jiffies.
1350 *
1351 * Returns 0 on success.
1352 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001353int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001354 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001356 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 do_proc_dointvec_userhz_jiffies_conv,NULL);
1358}
1359
1360/**
1361 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1362 * @table: the sysctl table
1363 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 * @buffer: the user buffer
1365 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07001366 * @ppos: file position
1367 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 *
1369 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1370 * values from/to the user buffer, treated as an ASCII string.
1371 * The values read are assumed to be in 1/1000 seconds, and
1372 * are converted into jiffies.
1373 *
1374 * Returns 0 on success.
1375 */
Christoph Hellwig32927392020-04-24 08:43:38 +02001376int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
1377 size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001379 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 do_proc_dointvec_ms_jiffies_conv, NULL);
1381}
1382
Christoph Hellwig32927392020-04-24 08:43:38 +02001383static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
1384 size_t *lenp, loff_t *ppos)
Cedric Le Goater9ec52092006-10-02 02:19:00 -07001385{
1386 struct pid *new_pid;
1387 pid_t tmp;
1388 int r;
1389
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08001390 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07001391
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001392 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07001393 lenp, ppos, NULL, NULL);
1394 if (r || !write)
1395 return r;
1396
1397 new_pid = find_get_pid(tmp);
1398 if (!new_pid)
1399 return -ESRCH;
1400
1401 put_pid(xchg(&cad_pid, new_pid));
1402 return 0;
1403}
1404
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001405/**
1406 * proc_do_large_bitmap - read/write from/to a large bitmap
1407 * @table: the sysctl table
1408 * @write: %TRUE if this is a write to the sysctl file
1409 * @buffer: the user buffer
1410 * @lenp: the size of the user buffer
1411 * @ppos: file position
1412 *
1413 * The bitmap is stored at table->data and the bitmap length (in bits)
1414 * in table->maxlen.
1415 *
1416 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1417 * large bitmaps may be represented in a compact manner. Writing into
1418 * the file will clear the bitmap then update it with the given input.
1419 *
1420 * Returns 0 on success.
1421 */
1422int proc_do_large_bitmap(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001423 void *buffer, size_t *lenp, loff_t *ppos)
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001424{
1425 int err = 0;
1426 bool first = 1;
1427 size_t left = *lenp;
1428 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07001429 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001430 unsigned long *tmp_bitmap = NULL;
1431 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1432
WANG Cong122ff242014-05-12 16:04:53 -07001433 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001434 *lenp = 0;
1435 return 0;
1436 }
1437
1438 if (write) {
Christoph Hellwig32927392020-04-24 08:43:38 +02001439 char *p = buffer;
Eric Sandeen3116ad32019-05-14 15:45:13 -07001440 size_t skipped = 0;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001441
Eric Sandeen3116ad32019-05-14 15:45:13 -07001442 if (left > PAGE_SIZE - 1) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001443 left = PAGE_SIZE - 1;
Eric Sandeen3116ad32019-05-14 15:45:13 -07001444 /* How much of the buffer we'll skip this pass */
1445 skipped = *lenp - left;
1446 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001447
Andy Shevchenko475dae32019-05-14 15:44:52 -07001448 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
Christoph Hellwig32927392020-04-24 08:43:38 +02001449 if (!tmp_bitmap)
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001450 return -ENOMEM;
Al Viro70f6cbb2015-12-24 00:13:10 -05001451 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001452 while (!err && left) {
1453 unsigned long val_a, val_b;
1454 bool neg;
Eric Sandeen3116ad32019-05-14 15:45:13 -07001455 size_t saved_left;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001456
Eric Sandeen3116ad32019-05-14 15:45:13 -07001457 /* In case we stop parsing mid-number, we can reset */
1458 saved_left = left;
Al Viro70f6cbb2015-12-24 00:13:10 -05001459 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001460 sizeof(tr_a), &c);
Eric Sandeen3116ad32019-05-14 15:45:13 -07001461 /*
1462 * If we consumed the entirety of a truncated buffer or
1463 * only one char is left (may be a "-"), then stop here,
1464 * reset, & come back for more.
1465 */
1466 if ((left <= 1) && skipped) {
1467 left = saved_left;
1468 break;
1469 }
1470
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001471 if (err)
1472 break;
1473 if (val_a >= bitmap_len || neg) {
1474 err = -EINVAL;
1475 break;
1476 }
1477
1478 val_b = val_a;
1479 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05001480 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001481 left--;
1482 }
1483
1484 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05001485 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001486 &neg, tr_b, sizeof(tr_b),
1487 &c);
Eric Sandeen3116ad32019-05-14 15:45:13 -07001488 /*
1489 * If we consumed all of a truncated buffer or
1490 * then stop here, reset, & come back for more.
1491 */
1492 if (!left && skipped) {
1493 left = saved_left;
1494 break;
1495 }
1496
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001497 if (err)
1498 break;
1499 if (val_b >= bitmap_len || neg ||
1500 val_a > val_b) {
1501 err = -EINVAL;
1502 break;
1503 }
1504 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05001505 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001506 left--;
1507 }
1508 }
1509
Akinobu Mita5a04cca2012-03-28 14:42:50 -07001510 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001511 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05001512 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001513 }
Eric Sandeen3116ad32019-05-14 15:45:13 -07001514 left += skipped;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001515 } else {
1516 unsigned long bit_a, bit_b = 0;
1517
1518 while (left) {
1519 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1520 if (bit_a >= bitmap_len)
1521 break;
1522 bit_b = find_next_zero_bit(bitmap, bitmap_len,
1523 bit_a + 1) - 1;
1524
Christoph Hellwig32927392020-04-24 08:43:38 +02001525 if (!first)
1526 proc_put_char(&buffer, &left, ',');
1527 proc_put_long(&buffer, &left, bit_a, false);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001528 if (bit_a != bit_b) {
Christoph Hellwig32927392020-04-24 08:43:38 +02001529 proc_put_char(&buffer, &left, '-');
1530 proc_put_long(&buffer, &left, bit_b, false);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001531 }
1532
1533 first = 0; bit_b++;
1534 }
Christoph Hellwig32927392020-04-24 08:43:38 +02001535 proc_put_char(&buffer, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001536 }
1537
1538 if (!err) {
1539 if (write) {
1540 if (*ppos)
1541 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1542 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07001543 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001544 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001545 *lenp -= left;
1546 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001547 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08001548
Andy Shevchenko475dae32019-05-14 15:44:52 -07001549 bitmap_free(tmp_bitmap);
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08001550 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001551}
1552
Jovi Zhang55610502011-01-12 17:00:45 -08001553#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001555int proc_dostring(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001556 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
1558 return -ENOSYS;
1559}
1560
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001561int proc_dointvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001562 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563{
1564 return -ENOSYS;
1565}
1566
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07001567int proc_douintvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001568 void *buffer, size_t *lenp, loff_t *ppos)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07001569{
1570 return -ENOSYS;
1571}
1572
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001573int proc_dointvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001574 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575{
1576 return -ENOSYS;
1577}
1578
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001579int proc_douintvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001580 void *buffer, size_t *lenp, loff_t *ppos)
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001581{
1582 return -ENOSYS;
1583}
1584
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001585int proc_dointvec_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001586 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587{
1588 return -ENOSYS;
1589}
1590
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001591int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001592 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593{
1594 return -ENOSYS;
1595}
1596
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001597int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001598 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599{
1600 return -ENOSYS;
1601}
1602
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001603int proc_doulongvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001604 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605{
1606 return -ENOSYS;
1607}
1608
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001609int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001610 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611{
Christoph Hellwig32927392020-04-24 08:43:38 +02001612 return -ENOSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613}
1614
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04001615int proc_do_large_bitmap(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001616 void *buffer, size_t *lenp, loff_t *ppos)
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04001617{
1618 return -ENOSYS;
1619}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
Jovi Zhang55610502011-01-12 17:00:45 -08001621#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001623#if defined(CONFIG_SYSCTL)
1624int proc_do_static_key(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001625 void *buffer, size_t *lenp, loff_t *ppos)
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001626{
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001627 struct static_key *key = (struct static_key *)table->data;
1628 static DEFINE_MUTEX(static_key_mutex);
1629 int val, ret;
1630 struct ctl_table tmp = {
1631 .data = &val,
1632 .maxlen = sizeof(val),
1633 .mode = table->mode,
Matteo Croceeec48442019-07-18 15:58:50 -07001634 .extra1 = SYSCTL_ZERO,
1635 .extra2 = SYSCTL_ONE,
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001636 };
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001637
1638 if (write && !capable(CAP_SYS_ADMIN))
1639 return -EPERM;
1640
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001641 mutex_lock(&static_key_mutex);
1642 val = static_key_enabled(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001643 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1644 if (write && !ret) {
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001645 if (val)
1646 static_key_enable(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001647 else
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001648 static_key_disable(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001649 }
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001650 mutex_unlock(&static_key_mutex);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001651 return ret;
1652}
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02001653
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654static struct ctl_table kern_table[] = {
1655 {
1656 .procname = "sched_child_runs_first",
1657 .data = &sysctl_sched_child_runs_first,
1658 .maxlen = sizeof(unsigned int),
1659 .mode = 0644,
1660 .proc_handler = proc_dointvec,
1661 },
1662#ifdef CONFIG_SCHED_DEBUG
1663 {
1664 .procname = "sched_min_granularity_ns",
1665 .data = &sysctl_sched_min_granularity,
1666 .maxlen = sizeof(unsigned int),
1667 .mode = 0644,
1668 .proc_handler = sched_proc_update_handler,
1669 .extra1 = &min_sched_granularity_ns,
1670 .extra2 = &max_sched_granularity_ns,
1671 },
1672 {
1673 .procname = "sched_latency_ns",
1674 .data = &sysctl_sched_latency,
1675 .maxlen = sizeof(unsigned int),
1676 .mode = 0644,
1677 .proc_handler = sched_proc_update_handler,
1678 .extra1 = &min_sched_granularity_ns,
1679 .extra2 = &max_sched_granularity_ns,
1680 },
1681 {
1682 .procname = "sched_wakeup_granularity_ns",
1683 .data = &sysctl_sched_wakeup_granularity,
1684 .maxlen = sizeof(unsigned int),
1685 .mode = 0644,
1686 .proc_handler = sched_proc_update_handler,
1687 .extra1 = &min_wakeup_granularity_ns,
1688 .extra2 = &max_wakeup_granularity_ns,
1689 },
1690#ifdef CONFIG_SMP
1691 {
1692 .procname = "sched_tunable_scaling",
1693 .data = &sysctl_sched_tunable_scaling,
1694 .maxlen = sizeof(enum sched_tunable_scaling),
1695 .mode = 0644,
1696 .proc_handler = sched_proc_update_handler,
1697 .extra1 = &min_sched_tunable_scaling,
1698 .extra2 = &max_sched_tunable_scaling,
1699 },
1700 {
1701 .procname = "sched_migration_cost_ns",
1702 .data = &sysctl_sched_migration_cost,
1703 .maxlen = sizeof(unsigned int),
1704 .mode = 0644,
1705 .proc_handler = proc_dointvec,
1706 },
1707 {
1708 .procname = "sched_nr_migrate",
1709 .data = &sysctl_sched_nr_migrate,
1710 .maxlen = sizeof(unsigned int),
1711 .mode = 0644,
1712 .proc_handler = proc_dointvec,
1713 },
1714#ifdef CONFIG_SCHEDSTATS
1715 {
1716 .procname = "sched_schedstats",
1717 .data = NULL,
1718 .maxlen = sizeof(unsigned int),
1719 .mode = 0644,
1720 .proc_handler = sysctl_schedstats,
1721 .extra1 = SYSCTL_ZERO,
1722 .extra2 = SYSCTL_ONE,
1723 },
1724#endif /* CONFIG_SCHEDSTATS */
1725#endif /* CONFIG_SMP */
1726#ifdef CONFIG_NUMA_BALANCING
1727 {
1728 .procname = "numa_balancing_scan_delay_ms",
1729 .data = &sysctl_numa_balancing_scan_delay,
1730 .maxlen = sizeof(unsigned int),
1731 .mode = 0644,
1732 .proc_handler = proc_dointvec,
1733 },
1734 {
1735 .procname = "numa_balancing_scan_period_min_ms",
1736 .data = &sysctl_numa_balancing_scan_period_min,
1737 .maxlen = sizeof(unsigned int),
1738 .mode = 0644,
1739 .proc_handler = proc_dointvec,
1740 },
1741 {
1742 .procname = "numa_balancing_scan_period_max_ms",
1743 .data = &sysctl_numa_balancing_scan_period_max,
1744 .maxlen = sizeof(unsigned int),
1745 .mode = 0644,
1746 .proc_handler = proc_dointvec,
1747 },
1748 {
1749 .procname = "numa_balancing_scan_size_mb",
1750 .data = &sysctl_numa_balancing_scan_size,
1751 .maxlen = sizeof(unsigned int),
1752 .mode = 0644,
1753 .proc_handler = proc_dointvec_minmax,
1754 .extra1 = SYSCTL_ONE,
1755 },
1756 {
1757 .procname = "numa_balancing",
1758 .data = NULL, /* filled in by handler */
1759 .maxlen = sizeof(unsigned int),
1760 .mode = 0644,
1761 .proc_handler = sysctl_numa_balancing,
1762 .extra1 = SYSCTL_ZERO,
1763 .extra2 = SYSCTL_ONE,
1764 },
1765#endif /* CONFIG_NUMA_BALANCING */
1766#endif /* CONFIG_SCHED_DEBUG */
1767 {
1768 .procname = "sched_rt_period_us",
1769 .data = &sysctl_sched_rt_period,
1770 .maxlen = sizeof(unsigned int),
1771 .mode = 0644,
1772 .proc_handler = sched_rt_handler,
1773 },
1774 {
1775 .procname = "sched_rt_runtime_us",
1776 .data = &sysctl_sched_rt_runtime,
1777 .maxlen = sizeof(int),
1778 .mode = 0644,
1779 .proc_handler = sched_rt_handler,
1780 },
1781 {
Peter Zijlstrab4098bf2019-07-26 16:54:10 +02001782 .procname = "sched_deadline_period_max_us",
1783 .data = &sysctl_sched_dl_period_max,
1784 .maxlen = sizeof(unsigned int),
1785 .mode = 0644,
1786 .proc_handler = proc_dointvec,
1787 },
1788 {
1789 .procname = "sched_deadline_period_min_us",
1790 .data = &sysctl_sched_dl_period_min,
1791 .maxlen = sizeof(unsigned int),
1792 .mode = 0644,
1793 .proc_handler = proc_dointvec,
1794 },
1795 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 .procname = "sched_rr_timeslice_ms",
1797 .data = &sysctl_sched_rr_timeslice,
1798 .maxlen = sizeof(int),
1799 .mode = 0644,
1800 .proc_handler = sched_rr_handler,
1801 },
1802#ifdef CONFIG_UCLAMP_TASK
1803 {
1804 .procname = "sched_util_clamp_min",
1805 .data = &sysctl_sched_uclamp_util_min,
1806 .maxlen = sizeof(unsigned int),
1807 .mode = 0644,
1808 .proc_handler = sysctl_sched_uclamp_handler,
1809 },
1810 {
1811 .procname = "sched_util_clamp_max",
1812 .data = &sysctl_sched_uclamp_util_max,
1813 .maxlen = sizeof(unsigned int),
1814 .mode = 0644,
1815 .proc_handler = sysctl_sched_uclamp_handler,
1816 },
Qais Yousef13685c42020-07-16 12:03:45 +01001817 {
1818 .procname = "sched_util_clamp_min_rt_default",
1819 .data = &sysctl_sched_uclamp_util_min_rt_default,
1820 .maxlen = sizeof(unsigned int),
1821 .mode = 0644,
1822 .proc_handler = sysctl_sched_uclamp_handler,
1823 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824#endif
1825#ifdef CONFIG_SCHED_AUTOGROUP
1826 {
1827 .procname = "sched_autogroup_enabled",
1828 .data = &sysctl_sched_autogroup_enabled,
1829 .maxlen = sizeof(unsigned int),
1830 .mode = 0644,
1831 .proc_handler = proc_dointvec_minmax,
1832 .extra1 = SYSCTL_ZERO,
1833 .extra2 = SYSCTL_ONE,
1834 },
1835#endif
1836#ifdef CONFIG_CFS_BANDWIDTH
1837 {
1838 .procname = "sched_cfs_bandwidth_slice_us",
1839 .data = &sysctl_sched_cfs_bandwidth_slice,
1840 .maxlen = sizeof(unsigned int),
1841 .mode = 0644,
1842 .proc_handler = proc_dointvec_minmax,
1843 .extra1 = SYSCTL_ONE,
1844 },
1845#endif
1846#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
1847 {
1848 .procname = "sched_energy_aware",
1849 .data = &sysctl_sched_energy_aware,
1850 .maxlen = sizeof(unsigned int),
1851 .mode = 0644,
1852 .proc_handler = sched_energy_aware_handler,
1853 .extra1 = SYSCTL_ZERO,
1854 .extra2 = SYSCTL_ONE,
1855 },
1856#endif
1857#ifdef CONFIG_PROVE_LOCKING
1858 {
1859 .procname = "prove_locking",
1860 .data = &prove_locking,
1861 .maxlen = sizeof(int),
1862 .mode = 0644,
1863 .proc_handler = proc_dointvec,
1864 },
1865#endif
1866#ifdef CONFIG_LOCK_STAT
1867 {
1868 .procname = "lock_stat",
1869 .data = &lock_stat,
1870 .maxlen = sizeof(int),
1871 .mode = 0644,
1872 .proc_handler = proc_dointvec,
1873 },
1874#endif
1875 {
1876 .procname = "panic",
1877 .data = &panic_timeout,
1878 .maxlen = sizeof(int),
1879 .mode = 0644,
1880 .proc_handler = proc_dointvec,
1881 },
1882#ifdef CONFIG_COREDUMP
1883 {
1884 .procname = "core_uses_pid",
1885 .data = &core_uses_pid,
1886 .maxlen = sizeof(int),
1887 .mode = 0644,
1888 .proc_handler = proc_dointvec,
1889 },
1890 {
1891 .procname = "core_pattern",
1892 .data = core_pattern,
1893 .maxlen = CORENAME_MAX_SIZE,
1894 .mode = 0644,
1895 .proc_handler = proc_dostring_coredump,
1896 },
1897 {
1898 .procname = "core_pipe_limit",
1899 .data = &core_pipe_limit,
1900 .maxlen = sizeof(unsigned int),
1901 .mode = 0644,
1902 .proc_handler = proc_dointvec,
1903 },
1904#endif
1905#ifdef CONFIG_PROC_SYSCTL
1906 {
1907 .procname = "tainted",
1908 .maxlen = sizeof(long),
1909 .mode = 0644,
1910 .proc_handler = proc_taint,
1911 },
1912 {
1913 .procname = "sysctl_writes_strict",
1914 .data = &sysctl_writes_strict,
1915 .maxlen = sizeof(int),
1916 .mode = 0644,
1917 .proc_handler = proc_dointvec_minmax,
1918 .extra1 = &neg_one,
1919 .extra2 = SYSCTL_ONE,
1920 },
1921#endif
1922#ifdef CONFIG_LATENCYTOP
1923 {
1924 .procname = "latencytop",
1925 .data = &latencytop_enabled,
1926 .maxlen = sizeof(int),
1927 .mode = 0644,
1928 .proc_handler = sysctl_latencytop,
1929 },
1930#endif
1931#ifdef CONFIG_BLK_DEV_INITRD
1932 {
1933 .procname = "real-root-dev",
1934 .data = &real_root_dev,
1935 .maxlen = sizeof(int),
1936 .mode = 0644,
1937 .proc_handler = proc_dointvec,
1938 },
1939#endif
1940 {
1941 .procname = "print-fatal-signals",
1942 .data = &print_fatal_signals,
1943 .maxlen = sizeof(int),
1944 .mode = 0644,
1945 .proc_handler = proc_dointvec,
1946 },
1947#ifdef CONFIG_SPARC
1948 {
1949 .procname = "reboot-cmd",
1950 .data = reboot_command,
1951 .maxlen = 256,
1952 .mode = 0644,
1953 .proc_handler = proc_dostring,
1954 },
1955 {
1956 .procname = "stop-a",
1957 .data = &stop_a_enabled,
1958 .maxlen = sizeof (int),
1959 .mode = 0644,
1960 .proc_handler = proc_dointvec,
1961 },
1962 {
1963 .procname = "scons-poweroff",
1964 .data = &scons_pwroff,
1965 .maxlen = sizeof (int),
1966 .mode = 0644,
1967 .proc_handler = proc_dointvec,
1968 },
1969#endif
1970#ifdef CONFIG_SPARC64
1971 {
1972 .procname = "tsb-ratio",
1973 .data = &sysctl_tsb_ratio,
1974 .maxlen = sizeof (int),
1975 .mode = 0644,
1976 .proc_handler = proc_dointvec,
1977 },
1978#endif
1979#ifdef CONFIG_PARISC
1980 {
1981 .procname = "soft-power",
1982 .data = &pwrsw_enabled,
1983 .maxlen = sizeof (int),
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02001984 .mode = 0644,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 .proc_handler = proc_dointvec,
1986 },
1987#endif
1988#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
1989 {
1990 .procname = "unaligned-trap",
1991 .data = &unaligned_enabled,
1992 .maxlen = sizeof (int),
1993 .mode = 0644,
1994 .proc_handler = proc_dointvec,
1995 },
1996#endif
1997 {
1998 .procname = "ctrl-alt-del",
1999 .data = &C_A_D,
2000 .maxlen = sizeof(int),
2001 .mode = 0644,
2002 .proc_handler = proc_dointvec,
2003 },
2004#ifdef CONFIG_FUNCTION_TRACER
2005 {
2006 .procname = "ftrace_enabled",
2007 .data = &ftrace_enabled,
2008 .maxlen = sizeof(int),
2009 .mode = 0644,
2010 .proc_handler = ftrace_enable_sysctl,
2011 },
2012#endif
2013#ifdef CONFIG_STACK_TRACER
2014 {
2015 .procname = "stack_tracer_enabled",
2016 .data = &stack_tracer_enabled,
2017 .maxlen = sizeof(int),
2018 .mode = 0644,
2019 .proc_handler = stack_trace_sysctl,
2020 },
2021#endif
2022#ifdef CONFIG_TRACING
2023 {
2024 .procname = "ftrace_dump_on_oops",
2025 .data = &ftrace_dump_on_oops,
2026 .maxlen = sizeof(int),
2027 .mode = 0644,
2028 .proc_handler = proc_dointvec,
2029 },
2030 {
2031 .procname = "traceoff_on_warning",
2032 .data = &__disable_trace_on_warning,
2033 .maxlen = sizeof(__disable_trace_on_warning),
2034 .mode = 0644,
2035 .proc_handler = proc_dointvec,
2036 },
2037 {
2038 .procname = "tracepoint_printk",
2039 .data = &tracepoint_printk,
2040 .maxlen = sizeof(tracepoint_printk),
2041 .mode = 0644,
2042 .proc_handler = tracepoint_printk_sysctl,
2043 },
2044#endif
2045#ifdef CONFIG_KEXEC_CORE
2046 {
2047 .procname = "kexec_load_disabled",
2048 .data = &kexec_load_disabled,
2049 .maxlen = sizeof(int),
2050 .mode = 0644,
2051 /* only handle a transition from default "0" to "1" */
2052 .proc_handler = proc_dointvec_minmax,
2053 .extra1 = SYSCTL_ONE,
2054 .extra2 = SYSCTL_ONE,
2055 },
2056#endif
2057#ifdef CONFIG_MODULES
2058 {
2059 .procname = "modprobe",
2060 .data = &modprobe_path,
2061 .maxlen = KMOD_PATH_LEN,
2062 .mode = 0644,
2063 .proc_handler = proc_dostring,
2064 },
2065 {
2066 .procname = "modules_disabled",
2067 .data = &modules_disabled,
2068 .maxlen = sizeof(int),
2069 .mode = 0644,
2070 /* only handle a transition from default "0" to "1" */
2071 .proc_handler = proc_dointvec_minmax,
2072 .extra1 = SYSCTL_ONE,
2073 .extra2 = SYSCTL_ONE,
2074 },
2075#endif
2076#ifdef CONFIG_UEVENT_HELPER
2077 {
2078 .procname = "hotplug",
2079 .data = &uevent_helper,
2080 .maxlen = UEVENT_HELPER_PATH_LEN,
2081 .mode = 0644,
2082 .proc_handler = proc_dostring,
2083 },
2084#endif
2085#ifdef CONFIG_CHR_DEV_SG
2086 {
2087 .procname = "sg-big-buff",
2088 .data = &sg_big_buff,
2089 .maxlen = sizeof (int),
2090 .mode = 0444,
2091 .proc_handler = proc_dointvec,
2092 },
2093#endif
2094#ifdef CONFIG_BSD_PROCESS_ACCT
2095 {
2096 .procname = "acct",
2097 .data = &acct_parm,
2098 .maxlen = 3*sizeof(int),
2099 .mode = 0644,
2100 .proc_handler = proc_dointvec,
2101 },
2102#endif
2103#ifdef CONFIG_MAGIC_SYSRQ
2104 {
2105 .procname = "sysrq",
2106 .data = NULL,
2107 .maxlen = sizeof (int),
2108 .mode = 0644,
2109 .proc_handler = sysrq_sysctl_handler,
2110 },
2111#endif
2112#ifdef CONFIG_PROC_SYSCTL
2113 {
2114 .procname = "cad_pid",
2115 .data = NULL,
2116 .maxlen = sizeof (int),
2117 .mode = 0600,
2118 .proc_handler = proc_do_cad_pid,
2119 },
2120#endif
2121 {
2122 .procname = "threads-max",
2123 .data = NULL,
2124 .maxlen = sizeof(int),
2125 .mode = 0644,
2126 .proc_handler = sysctl_max_threads,
2127 },
2128 {
2129 .procname = "random",
2130 .mode = 0555,
2131 .child = random_table,
2132 },
2133 {
2134 .procname = "usermodehelper",
2135 .mode = 0555,
2136 .child = usermodehelper_table,
2137 },
2138#ifdef CONFIG_FW_LOADER_USER_HELPER
2139 {
2140 .procname = "firmware_config",
2141 .mode = 0555,
2142 .child = firmware_config_table,
2143 },
2144#endif
2145 {
2146 .procname = "overflowuid",
2147 .data = &overflowuid,
2148 .maxlen = sizeof(int),
2149 .mode = 0644,
2150 .proc_handler = proc_dointvec_minmax,
2151 .extra1 = &minolduid,
2152 .extra2 = &maxolduid,
2153 },
2154 {
2155 .procname = "overflowgid",
2156 .data = &overflowgid,
2157 .maxlen = sizeof(int),
2158 .mode = 0644,
2159 .proc_handler = proc_dointvec_minmax,
2160 .extra1 = &minolduid,
2161 .extra2 = &maxolduid,
2162 },
2163#ifdef CONFIG_S390
2164 {
2165 .procname = "userprocess_debug",
2166 .data = &show_unhandled_signals,
2167 .maxlen = sizeof(int),
2168 .mode = 0644,
2169 .proc_handler = proc_dointvec,
2170 },
2171#endif
Guilherme G. Piccoli60c958d2020-06-07 21:40:48 -07002172#ifdef CONFIG_SMP
2173 {
2174 .procname = "oops_all_cpu_backtrace",
2175 .data = &sysctl_oops_all_cpu_backtrace,
2176 .maxlen = sizeof(int),
2177 .mode = 0644,
2178 .proc_handler = proc_dointvec_minmax,
2179 .extra1 = SYSCTL_ZERO,
2180 .extra2 = SYSCTL_ONE,
2181 },
2182#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 {
2184 .procname = "pid_max",
2185 .data = &pid_max,
2186 .maxlen = sizeof (int),
2187 .mode = 0644,
2188 .proc_handler = proc_dointvec_minmax,
2189 .extra1 = &pid_max_min,
2190 .extra2 = &pid_max_max,
2191 },
2192 {
2193 .procname = "panic_on_oops",
2194 .data = &panic_on_oops,
2195 .maxlen = sizeof(int),
2196 .mode = 0644,
2197 .proc_handler = proc_dointvec,
2198 },
2199 {
2200 .procname = "panic_print",
2201 .data = &panic_print,
2202 .maxlen = sizeof(unsigned long),
2203 .mode = 0644,
2204 .proc_handler = proc_doulongvec_minmax,
2205 },
2206#if defined CONFIG_PRINTK
2207 {
2208 .procname = "printk",
2209 .data = &console_loglevel,
2210 .maxlen = 4*sizeof(int),
2211 .mode = 0644,
2212 .proc_handler = proc_dointvec,
2213 },
2214 {
2215 .procname = "printk_ratelimit",
2216 .data = &printk_ratelimit_state.interval,
2217 .maxlen = sizeof(int),
2218 .mode = 0644,
2219 .proc_handler = proc_dointvec_jiffies,
2220 },
2221 {
2222 .procname = "printk_ratelimit_burst",
2223 .data = &printk_ratelimit_state.burst,
2224 .maxlen = sizeof(int),
2225 .mode = 0644,
2226 .proc_handler = proc_dointvec,
2227 },
2228 {
2229 .procname = "printk_delay",
2230 .data = &printk_delay_msec,
2231 .maxlen = sizeof(int),
2232 .mode = 0644,
2233 .proc_handler = proc_dointvec_minmax,
2234 .extra1 = SYSCTL_ZERO,
2235 .extra2 = &ten_thousand,
2236 },
2237 {
2238 .procname = "printk_devkmsg",
2239 .data = devkmsg_log_str,
2240 .maxlen = DEVKMSG_STR_MAX_SIZE,
2241 .mode = 0644,
2242 .proc_handler = devkmsg_sysctl_set_loglvl,
2243 },
2244 {
2245 .procname = "dmesg_restrict",
2246 .data = &dmesg_restrict,
2247 .maxlen = sizeof(int),
2248 .mode = 0644,
2249 .proc_handler = proc_dointvec_minmax_sysadmin,
2250 .extra1 = SYSCTL_ZERO,
2251 .extra2 = SYSCTL_ONE,
2252 },
2253 {
2254 .procname = "kptr_restrict",
2255 .data = &kptr_restrict,
2256 .maxlen = sizeof(int),
2257 .mode = 0644,
2258 .proc_handler = proc_dointvec_minmax_sysadmin,
2259 .extra1 = SYSCTL_ZERO,
2260 .extra2 = &two,
2261 },
2262#endif
2263 {
2264 .procname = "ngroups_max",
2265 .data = &ngroups_max,
2266 .maxlen = sizeof (int),
2267 .mode = 0444,
2268 .proc_handler = proc_dointvec,
2269 },
2270 {
2271 .procname = "cap_last_cap",
2272 .data = (void *)&cap_last_cap,
2273 .maxlen = sizeof(int),
2274 .mode = 0444,
2275 .proc_handler = proc_dointvec,
2276 },
2277#if defined(CONFIG_LOCKUP_DETECTOR)
2278 {
2279 .procname = "watchdog",
2280 .data = &watchdog_user_enabled,
2281 .maxlen = sizeof(int),
2282 .mode = 0644,
2283 .proc_handler = proc_watchdog,
2284 .extra1 = SYSCTL_ZERO,
2285 .extra2 = SYSCTL_ONE,
2286 },
2287 {
2288 .procname = "watchdog_thresh",
2289 .data = &watchdog_thresh,
2290 .maxlen = sizeof(int),
2291 .mode = 0644,
2292 .proc_handler = proc_watchdog_thresh,
2293 .extra1 = SYSCTL_ZERO,
2294 .extra2 = &sixty,
2295 },
2296 {
2297 .procname = "nmi_watchdog",
2298 .data = &nmi_watchdog_user_enabled,
2299 .maxlen = sizeof(int),
2300 .mode = NMI_WATCHDOG_SYSCTL_PERM,
2301 .proc_handler = proc_nmi_watchdog,
2302 .extra1 = SYSCTL_ZERO,
2303 .extra2 = SYSCTL_ONE,
2304 },
2305 {
2306 .procname = "watchdog_cpumask",
2307 .data = &watchdog_cpumask_bits,
2308 .maxlen = NR_CPUS,
2309 .mode = 0644,
2310 .proc_handler = proc_watchdog_cpumask,
2311 },
2312#ifdef CONFIG_SOFTLOCKUP_DETECTOR
2313 {
2314 .procname = "soft_watchdog",
2315 .data = &soft_watchdog_user_enabled,
2316 .maxlen = sizeof(int),
2317 .mode = 0644,
2318 .proc_handler = proc_soft_watchdog,
2319 .extra1 = SYSCTL_ZERO,
2320 .extra2 = SYSCTL_ONE,
2321 },
2322 {
2323 .procname = "softlockup_panic",
2324 .data = &softlockup_panic,
2325 .maxlen = sizeof(int),
2326 .mode = 0644,
2327 .proc_handler = proc_dointvec_minmax,
2328 .extra1 = SYSCTL_ZERO,
2329 .extra2 = SYSCTL_ONE,
2330 },
2331#ifdef CONFIG_SMP
2332 {
2333 .procname = "softlockup_all_cpu_backtrace",
2334 .data = &sysctl_softlockup_all_cpu_backtrace,
2335 .maxlen = sizeof(int),
2336 .mode = 0644,
2337 .proc_handler = proc_dointvec_minmax,
2338 .extra1 = SYSCTL_ZERO,
2339 .extra2 = SYSCTL_ONE,
2340 },
2341#endif /* CONFIG_SMP */
2342#endif
2343#ifdef CONFIG_HARDLOCKUP_DETECTOR
2344 {
2345 .procname = "hardlockup_panic",
2346 .data = &hardlockup_panic,
2347 .maxlen = sizeof(int),
2348 .mode = 0644,
2349 .proc_handler = proc_dointvec_minmax,
2350 .extra1 = SYSCTL_ZERO,
2351 .extra2 = SYSCTL_ONE,
2352 },
2353#ifdef CONFIG_SMP
2354 {
2355 .procname = "hardlockup_all_cpu_backtrace",
2356 .data = &sysctl_hardlockup_all_cpu_backtrace,
2357 .maxlen = sizeof(int),
2358 .mode = 0644,
2359 .proc_handler = proc_dointvec_minmax,
2360 .extra1 = SYSCTL_ZERO,
2361 .extra2 = SYSCTL_ONE,
2362 },
2363#endif /* CONFIG_SMP */
2364#endif
2365#endif
2366
2367#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
2368 {
2369 .procname = "unknown_nmi_panic",
2370 .data = &unknown_nmi_panic,
2371 .maxlen = sizeof (int),
2372 .mode = 0644,
2373 .proc_handler = proc_dointvec,
2374 },
2375#endif
Xiaoming Nib6522fa2020-04-11 21:06:19 +08002376
2377#if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
2378 defined(CONFIG_DEBUG_STACKOVERFLOW)
2379 {
2380 .procname = "panic_on_stackoverflow",
2381 .data = &sysctl_panic_on_stackoverflow,
2382 .maxlen = sizeof(int),
2383 .mode = 0644,
2384 .proc_handler = proc_dointvec,
2385 },
2386#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387#if defined(CONFIG_X86)
2388 {
2389 .procname = "panic_on_unrecovered_nmi",
2390 .data = &panic_on_unrecovered_nmi,
2391 .maxlen = sizeof(int),
2392 .mode = 0644,
2393 .proc_handler = proc_dointvec,
2394 },
2395 {
2396 .procname = "panic_on_io_nmi",
2397 .data = &panic_on_io_nmi,
2398 .maxlen = sizeof(int),
2399 .mode = 0644,
2400 .proc_handler = proc_dointvec,
2401 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 {
2403 .procname = "bootloader_type",
2404 .data = &bootloader_type,
2405 .maxlen = sizeof (int),
2406 .mode = 0444,
2407 .proc_handler = proc_dointvec,
2408 },
2409 {
2410 .procname = "bootloader_version",
2411 .data = &bootloader_version,
2412 .maxlen = sizeof (int),
2413 .mode = 0444,
2414 .proc_handler = proc_dointvec,
2415 },
2416 {
2417 .procname = "io_delay_type",
2418 .data = &io_delay_type,
2419 .maxlen = sizeof(int),
2420 .mode = 0644,
2421 .proc_handler = proc_dointvec,
2422 },
2423#endif
2424#if defined(CONFIG_MMU)
2425 {
2426 .procname = "randomize_va_space",
2427 .data = &randomize_va_space,
2428 .maxlen = sizeof(int),
2429 .mode = 0644,
2430 .proc_handler = proc_dointvec,
2431 },
2432#endif
2433#if defined(CONFIG_S390) && defined(CONFIG_SMP)
2434 {
2435 .procname = "spin_retry",
2436 .data = &spin_retry,
2437 .maxlen = sizeof (int),
2438 .mode = 0644,
2439 .proc_handler = proc_dointvec,
2440 },
2441#endif
2442#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
2443 {
2444 .procname = "acpi_video_flags",
2445 .data = &acpi_realmode_flags,
2446 .maxlen = sizeof (unsigned long),
2447 .mode = 0644,
2448 .proc_handler = proc_doulongvec_minmax,
2449 },
2450#endif
2451#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
2452 {
2453 .procname = "ignore-unaligned-usertrap",
2454 .data = &no_unaligned_warning,
2455 .maxlen = sizeof (int),
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02002456 .mode = 0644,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 .proc_handler = proc_dointvec,
2458 },
2459#endif
2460#ifdef CONFIG_IA64
2461 {
2462 .procname = "unaligned-dump-stack",
2463 .data = &unaligned_dump_stack,
2464 .maxlen = sizeof (int),
2465 .mode = 0644,
2466 .proc_handler = proc_dointvec,
2467 },
2468#endif
2469#ifdef CONFIG_DETECT_HUNG_TASK
Guilherme G. Piccoli0ec9dc92020-06-07 21:40:45 -07002470#ifdef CONFIG_SMP
2471 {
2472 .procname = "hung_task_all_cpu_backtrace",
2473 .data = &sysctl_hung_task_all_cpu_backtrace,
2474 .maxlen = sizeof(int),
2475 .mode = 0644,
2476 .proc_handler = proc_dointvec_minmax,
2477 .extra1 = SYSCTL_ZERO,
2478 .extra2 = SYSCTL_ONE,
2479 },
2480#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 {
2482 .procname = "hung_task_panic",
2483 .data = &sysctl_hung_task_panic,
2484 .maxlen = sizeof(int),
2485 .mode = 0644,
2486 .proc_handler = proc_dointvec_minmax,
2487 .extra1 = SYSCTL_ZERO,
2488 .extra2 = SYSCTL_ONE,
2489 },
2490 {
2491 .procname = "hung_task_check_count",
2492 .data = &sysctl_hung_task_check_count,
2493 .maxlen = sizeof(int),
2494 .mode = 0644,
2495 .proc_handler = proc_dointvec_minmax,
2496 .extra1 = SYSCTL_ZERO,
2497 },
2498 {
2499 .procname = "hung_task_timeout_secs",
2500 .data = &sysctl_hung_task_timeout_secs,
2501 .maxlen = sizeof(unsigned long),
2502 .mode = 0644,
2503 .proc_handler = proc_dohung_task_timeout_secs,
2504 .extra2 = &hung_task_timeout_max,
2505 },
2506 {
2507 .procname = "hung_task_check_interval_secs",
2508 .data = &sysctl_hung_task_check_interval_secs,
2509 .maxlen = sizeof(unsigned long),
2510 .mode = 0644,
2511 .proc_handler = proc_dohung_task_timeout_secs,
2512 .extra2 = &hung_task_timeout_max,
2513 },
2514 {
2515 .procname = "hung_task_warnings",
2516 .data = &sysctl_hung_task_warnings,
2517 .maxlen = sizeof(int),
2518 .mode = 0644,
2519 .proc_handler = proc_dointvec_minmax,
2520 .extra1 = &neg_one,
2521 },
2522#endif
2523#ifdef CONFIG_RT_MUTEXES
2524 {
2525 .procname = "max_lock_depth",
2526 .data = &max_lock_depth,
2527 .maxlen = sizeof(int),
2528 .mode = 0644,
2529 .proc_handler = proc_dointvec,
2530 },
2531#endif
2532 {
2533 .procname = "poweroff_cmd",
2534 .data = &poweroff_cmd,
2535 .maxlen = POWEROFF_CMD_PATH_LEN,
2536 .mode = 0644,
2537 .proc_handler = proc_dostring,
2538 },
2539#ifdef CONFIG_KEYS
2540 {
2541 .procname = "keys",
2542 .mode = 0555,
2543 .child = key_sysctls,
2544 },
2545#endif
2546#ifdef CONFIG_PERF_EVENTS
2547 /*
2548 * User-space scripts rely on the existence of this file
2549 * as a feature check for perf_events being enabled.
2550 *
2551 * So it's an ABI, do not remove!
2552 */
2553 {
2554 .procname = "perf_event_paranoid",
2555 .data = &sysctl_perf_event_paranoid,
2556 .maxlen = sizeof(sysctl_perf_event_paranoid),
2557 .mode = 0644,
2558 .proc_handler = proc_dointvec,
2559 },
2560 {
2561 .procname = "perf_event_mlock_kb",
2562 .data = &sysctl_perf_event_mlock,
2563 .maxlen = sizeof(sysctl_perf_event_mlock),
2564 .mode = 0644,
2565 .proc_handler = proc_dointvec,
2566 },
2567 {
2568 .procname = "perf_event_max_sample_rate",
2569 .data = &sysctl_perf_event_sample_rate,
2570 .maxlen = sizeof(sysctl_perf_event_sample_rate),
2571 .mode = 0644,
2572 .proc_handler = perf_proc_update_handler,
2573 .extra1 = SYSCTL_ONE,
2574 },
2575 {
2576 .procname = "perf_cpu_time_max_percent",
2577 .data = &sysctl_perf_cpu_time_max_percent,
2578 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
2579 .mode = 0644,
2580 .proc_handler = perf_cpu_time_max_percent_handler,
2581 .extra1 = SYSCTL_ZERO,
2582 .extra2 = &one_hundred,
2583 },
2584 {
2585 .procname = "perf_event_max_stack",
2586 .data = &sysctl_perf_event_max_stack,
2587 .maxlen = sizeof(sysctl_perf_event_max_stack),
2588 .mode = 0644,
2589 .proc_handler = perf_event_max_stack_handler,
2590 .extra1 = SYSCTL_ZERO,
2591 .extra2 = &six_hundred_forty_kb,
2592 },
2593 {
2594 .procname = "perf_event_max_contexts_per_stack",
2595 .data = &sysctl_perf_event_max_contexts_per_stack,
2596 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
2597 .mode = 0644,
2598 .proc_handler = perf_event_max_stack_handler,
2599 .extra1 = SYSCTL_ZERO,
2600 .extra2 = &one_thousand,
2601 },
2602#endif
2603 {
2604 .procname = "panic_on_warn",
2605 .data = &panic_on_warn,
2606 .maxlen = sizeof(int),
2607 .mode = 0644,
2608 .proc_handler = proc_dointvec_minmax,
2609 .extra1 = SYSCTL_ZERO,
2610 .extra2 = SYSCTL_ONE,
2611 },
2612#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
2613 {
2614 .procname = "timer_migration",
2615 .data = &sysctl_timer_migration,
2616 .maxlen = sizeof(unsigned int),
2617 .mode = 0644,
2618 .proc_handler = timer_migration_handler,
2619 .extra1 = SYSCTL_ZERO,
2620 .extra2 = SYSCTL_ONE,
2621 },
2622#endif
2623#ifdef CONFIG_BPF_SYSCALL
2624 {
2625 .procname = "unprivileged_bpf_disabled",
2626 .data = &sysctl_unprivileged_bpf_disabled,
2627 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
2628 .mode = 0644,
2629 /* only handle a transition from default "0" to "1" */
2630 .proc_handler = proc_dointvec_minmax,
2631 .extra1 = SYSCTL_ONE,
2632 .extra2 = SYSCTL_ONE,
2633 },
2634 {
2635 .procname = "bpf_stats_enabled",
2636 .data = &bpf_stats_enabled_key.key,
2637 .maxlen = sizeof(bpf_stats_enabled_key),
2638 .mode = 0644,
Song Liud46edd62020-04-30 00:15:04 -07002639 .proc_handler = bpf_stats_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 },
2641#endif
2642#if defined(CONFIG_TREE_RCU)
2643 {
2644 .procname = "panic_on_rcu_stall",
2645 .data = &sysctl_panic_on_rcu_stall,
2646 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
2647 .mode = 0644,
2648 .proc_handler = proc_dointvec_minmax,
2649 .extra1 = SYSCTL_ZERO,
2650 .extra2 = SYSCTL_ONE,
2651 },
2652#endif
chaodfe56402020-08-30 23:41:17 -07002653#if defined(CONFIG_TREE_RCU)
2654 {
2655 .procname = "max_rcu_stall_to_panic",
2656 .data = &sysctl_max_rcu_stall_to_panic,
2657 .maxlen = sizeof(sysctl_max_rcu_stall_to_panic),
2658 .mode = 0644,
2659 .proc_handler = proc_dointvec_minmax,
2660 .extra1 = SYSCTL_ONE,
2661 .extra2 = SYSCTL_INT_MAX,
2662 },
2663#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
2665 {
2666 .procname = "stack_erasing",
2667 .data = NULL,
2668 .maxlen = sizeof(int),
2669 .mode = 0600,
2670 .proc_handler = stack_erasing_sysctl,
2671 .extra1 = SYSCTL_ZERO,
2672 .extra2 = SYSCTL_ONE,
2673 },
2674#endif
2675 { }
2676};
2677
2678static struct ctl_table vm_table[] = {
2679 {
2680 .procname = "overcommit_memory",
2681 .data = &sysctl_overcommit_memory,
2682 .maxlen = sizeof(sysctl_overcommit_memory),
2683 .mode = 0644,
Feng Tang56f35472020-08-06 23:23:15 -07002684 .proc_handler = overcommit_policy_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 .extra1 = SYSCTL_ZERO,
2686 .extra2 = &two,
2687 },
2688 {
2689 .procname = "panic_on_oom",
2690 .data = &sysctl_panic_on_oom,
2691 .maxlen = sizeof(sysctl_panic_on_oom),
2692 .mode = 0644,
2693 .proc_handler = proc_dointvec_minmax,
2694 .extra1 = SYSCTL_ZERO,
2695 .extra2 = &two,
2696 },
2697 {
2698 .procname = "oom_kill_allocating_task",
2699 .data = &sysctl_oom_kill_allocating_task,
2700 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
2701 .mode = 0644,
2702 .proc_handler = proc_dointvec,
2703 },
2704 {
2705 .procname = "oom_dump_tasks",
2706 .data = &sysctl_oom_dump_tasks,
2707 .maxlen = sizeof(sysctl_oom_dump_tasks),
2708 .mode = 0644,
2709 .proc_handler = proc_dointvec,
2710 },
2711 {
2712 .procname = "overcommit_ratio",
2713 .data = &sysctl_overcommit_ratio,
2714 .maxlen = sizeof(sysctl_overcommit_ratio),
2715 .mode = 0644,
2716 .proc_handler = overcommit_ratio_handler,
2717 },
2718 {
2719 .procname = "overcommit_kbytes",
2720 .data = &sysctl_overcommit_kbytes,
2721 .maxlen = sizeof(sysctl_overcommit_kbytes),
2722 .mode = 0644,
2723 .proc_handler = overcommit_kbytes_handler,
2724 },
2725 {
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02002726 .procname = "page-cluster",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 .data = &page_cluster,
2728 .maxlen = sizeof(int),
2729 .mode = 0644,
2730 .proc_handler = proc_dointvec_minmax,
2731 .extra1 = SYSCTL_ZERO,
2732 },
2733 {
2734 .procname = "dirty_background_ratio",
2735 .data = &dirty_background_ratio,
2736 .maxlen = sizeof(dirty_background_ratio),
2737 .mode = 0644,
2738 .proc_handler = dirty_background_ratio_handler,
2739 .extra1 = SYSCTL_ZERO,
2740 .extra2 = &one_hundred,
2741 },
2742 {
2743 .procname = "dirty_background_bytes",
2744 .data = &dirty_background_bytes,
2745 .maxlen = sizeof(dirty_background_bytes),
2746 .mode = 0644,
2747 .proc_handler = dirty_background_bytes_handler,
2748 .extra1 = &one_ul,
2749 },
2750 {
2751 .procname = "dirty_ratio",
2752 .data = &vm_dirty_ratio,
2753 .maxlen = sizeof(vm_dirty_ratio),
2754 .mode = 0644,
2755 .proc_handler = dirty_ratio_handler,
2756 .extra1 = SYSCTL_ZERO,
2757 .extra2 = &one_hundred,
2758 },
2759 {
2760 .procname = "dirty_bytes",
2761 .data = &vm_dirty_bytes,
2762 .maxlen = sizeof(vm_dirty_bytes),
2763 .mode = 0644,
2764 .proc_handler = dirty_bytes_handler,
2765 .extra1 = &dirty_bytes_min,
2766 },
2767 {
2768 .procname = "dirty_writeback_centisecs",
2769 .data = &dirty_writeback_interval,
2770 .maxlen = sizeof(dirty_writeback_interval),
2771 .mode = 0644,
2772 .proc_handler = dirty_writeback_centisecs_handler,
2773 },
2774 {
2775 .procname = "dirty_expire_centisecs",
2776 .data = &dirty_expire_interval,
2777 .maxlen = sizeof(dirty_expire_interval),
2778 .mode = 0644,
2779 .proc_handler = proc_dointvec_minmax,
2780 .extra1 = SYSCTL_ZERO,
2781 },
2782 {
2783 .procname = "dirtytime_expire_seconds",
2784 .data = &dirtytime_expire_interval,
2785 .maxlen = sizeof(dirtytime_expire_interval),
2786 .mode = 0644,
2787 .proc_handler = dirtytime_interval_handler,
2788 .extra1 = SYSCTL_ZERO,
2789 },
2790 {
2791 .procname = "swappiness",
2792 .data = &vm_swappiness,
2793 .maxlen = sizeof(vm_swappiness),
2794 .mode = 0644,
2795 .proc_handler = proc_dointvec_minmax,
2796 .extra1 = SYSCTL_ZERO,
Johannes Weinerc8439662020-06-03 16:02:37 -07002797 .extra2 = &two_hundred,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 },
2799#ifdef CONFIG_HUGETLB_PAGE
2800 {
2801 .procname = "nr_hugepages",
2802 .data = NULL,
2803 .maxlen = sizeof(unsigned long),
2804 .mode = 0644,
2805 .proc_handler = hugetlb_sysctl_handler,
2806 },
2807#ifdef CONFIG_NUMA
2808 {
2809 .procname = "nr_hugepages_mempolicy",
2810 .data = NULL,
2811 .maxlen = sizeof(unsigned long),
2812 .mode = 0644,
2813 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
2814 },
2815 {
2816 .procname = "numa_stat",
2817 .data = &sysctl_vm_numa_stat,
2818 .maxlen = sizeof(int),
2819 .mode = 0644,
2820 .proc_handler = sysctl_vm_numa_stat_handler,
2821 .extra1 = SYSCTL_ZERO,
2822 .extra2 = SYSCTL_ONE,
2823 },
2824#endif
2825 {
2826 .procname = "hugetlb_shm_group",
2827 .data = &sysctl_hugetlb_shm_group,
2828 .maxlen = sizeof(gid_t),
2829 .mode = 0644,
2830 .proc_handler = proc_dointvec,
2831 },
2832 {
2833 .procname = "nr_overcommit_hugepages",
2834 .data = NULL,
2835 .maxlen = sizeof(unsigned long),
2836 .mode = 0644,
2837 .proc_handler = hugetlb_overcommit_handler,
2838 },
2839#endif
2840 {
2841 .procname = "lowmem_reserve_ratio",
2842 .data = &sysctl_lowmem_reserve_ratio,
2843 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
2844 .mode = 0644,
2845 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
2846 },
2847 {
2848 .procname = "drop_caches",
2849 .data = &sysctl_drop_caches,
2850 .maxlen = sizeof(int),
2851 .mode = 0200,
2852 .proc_handler = drop_caches_sysctl_handler,
2853 .extra1 = SYSCTL_ONE,
2854 .extra2 = &four,
2855 },
2856#ifdef CONFIG_COMPACTION
2857 {
2858 .procname = "compact_memory",
2859 .data = &sysctl_compact_memory,
2860 .maxlen = sizeof(int),
2861 .mode = 0200,
2862 .proc_handler = sysctl_compaction_handler,
2863 },
2864 {
Nitin Guptafacdaa92020-08-11 18:31:00 -07002865 .procname = "compaction_proactiveness",
2866 .data = &sysctl_compaction_proactiveness,
Nitin Guptad34c0a72020-08-11 18:31:07 -07002867 .maxlen = sizeof(sysctl_compaction_proactiveness),
Nitin Guptafacdaa92020-08-11 18:31:00 -07002868 .mode = 0644,
2869 .proc_handler = proc_dointvec_minmax,
2870 .extra1 = SYSCTL_ZERO,
2871 .extra2 = &one_hundred,
2872 },
2873 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 .procname = "extfrag_threshold",
2875 .data = &sysctl_extfrag_threshold,
2876 .maxlen = sizeof(int),
2877 .mode = 0644,
2878 .proc_handler = proc_dointvec_minmax,
2879 .extra1 = &min_extfrag_threshold,
2880 .extra2 = &max_extfrag_threshold,
2881 },
2882 {
2883 .procname = "compact_unevictable_allowed",
2884 .data = &sysctl_compact_unevictable_allowed,
2885 .maxlen = sizeof(int),
2886 .mode = 0644,
2887 .proc_handler = proc_dointvec_minmax_warn_RT_change,
2888 .extra1 = SYSCTL_ZERO,
2889 .extra2 = SYSCTL_ONE,
2890 },
2891
2892#endif /* CONFIG_COMPACTION */
2893 {
2894 .procname = "min_free_kbytes",
2895 .data = &min_free_kbytes,
2896 .maxlen = sizeof(min_free_kbytes),
2897 .mode = 0644,
2898 .proc_handler = min_free_kbytes_sysctl_handler,
2899 .extra1 = SYSCTL_ZERO,
2900 },
2901 {
2902 .procname = "watermark_boost_factor",
2903 .data = &watermark_boost_factor,
2904 .maxlen = sizeof(watermark_boost_factor),
2905 .mode = 0644,
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02002906 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 .extra1 = SYSCTL_ZERO,
2908 },
2909 {
2910 .procname = "watermark_scale_factor",
2911 .data = &watermark_scale_factor,
2912 .maxlen = sizeof(watermark_scale_factor),
2913 .mode = 0644,
2914 .proc_handler = watermark_scale_factor_sysctl_handler,
2915 .extra1 = SYSCTL_ONE,
2916 .extra2 = &one_thousand,
2917 },
2918 {
2919 .procname = "percpu_pagelist_fraction",
2920 .data = &percpu_pagelist_fraction,
2921 .maxlen = sizeof(percpu_pagelist_fraction),
2922 .mode = 0644,
2923 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
2924 .extra1 = SYSCTL_ZERO,
2925 },
Linus Torvalds5ef64cc2020-09-13 14:05:35 -07002926 {
2927 .procname = "page_lock_unfairness",
2928 .data = &sysctl_page_lock_unfairness,
2929 .maxlen = sizeof(sysctl_page_lock_unfairness),
2930 .mode = 0644,
2931 .proc_handler = proc_dointvec_minmax,
2932 .extra1 = SYSCTL_ZERO,
2933 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934#ifdef CONFIG_MMU
2935 {
2936 .procname = "max_map_count",
2937 .data = &sysctl_max_map_count,
2938 .maxlen = sizeof(sysctl_max_map_count),
2939 .mode = 0644,
2940 .proc_handler = proc_dointvec_minmax,
2941 .extra1 = SYSCTL_ZERO,
2942 },
2943#else
2944 {
2945 .procname = "nr_trim_pages",
2946 .data = &sysctl_nr_trim_pages,
2947 .maxlen = sizeof(sysctl_nr_trim_pages),
2948 .mode = 0644,
2949 .proc_handler = proc_dointvec_minmax,
2950 .extra1 = SYSCTL_ZERO,
2951 },
2952#endif
2953 {
2954 .procname = "laptop_mode",
2955 .data = &laptop_mode,
2956 .maxlen = sizeof(laptop_mode),
2957 .mode = 0644,
2958 .proc_handler = proc_dointvec_jiffies,
2959 },
2960 {
2961 .procname = "block_dump",
2962 .data = &block_dump,
2963 .maxlen = sizeof(block_dump),
2964 .mode = 0644,
Lin Feng3b3376f2021-02-25 17:20:53 -08002965 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 .extra1 = SYSCTL_ZERO,
2967 },
2968 {
2969 .procname = "vfs_cache_pressure",
2970 .data = &sysctl_vfs_cache_pressure,
2971 .maxlen = sizeof(sysctl_vfs_cache_pressure),
2972 .mode = 0644,
Lin Feng3b3376f2021-02-25 17:20:53 -08002973 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 .extra1 = SYSCTL_ZERO,
2975 },
2976#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
2977 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
2978 {
2979 .procname = "legacy_va_layout",
2980 .data = &sysctl_legacy_va_layout,
2981 .maxlen = sizeof(sysctl_legacy_va_layout),
2982 .mode = 0644,
Lin Feng3b3376f2021-02-25 17:20:53 -08002983 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 .extra1 = SYSCTL_ZERO,
2985 },
2986#endif
2987#ifdef CONFIG_NUMA
2988 {
2989 .procname = "zone_reclaim_mode",
2990 .data = &node_reclaim_mode,
2991 .maxlen = sizeof(node_reclaim_mode),
2992 .mode = 0644,
Lin Feng3b3376f2021-02-25 17:20:53 -08002993 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 .extra1 = SYSCTL_ZERO,
2995 },
2996 {
2997 .procname = "min_unmapped_ratio",
2998 .data = &sysctl_min_unmapped_ratio,
2999 .maxlen = sizeof(sysctl_min_unmapped_ratio),
3000 .mode = 0644,
3001 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
3002 .extra1 = SYSCTL_ZERO,
3003 .extra2 = &one_hundred,
3004 },
3005 {
3006 .procname = "min_slab_ratio",
3007 .data = &sysctl_min_slab_ratio,
3008 .maxlen = sizeof(sysctl_min_slab_ratio),
3009 .mode = 0644,
3010 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
3011 .extra1 = SYSCTL_ZERO,
3012 .extra2 = &one_hundred,
3013 },
3014#endif
3015#ifdef CONFIG_SMP
3016 {
3017 .procname = "stat_interval",
3018 .data = &sysctl_stat_interval,
3019 .maxlen = sizeof(sysctl_stat_interval),
3020 .mode = 0644,
3021 .proc_handler = proc_dointvec_jiffies,
3022 },
3023 {
3024 .procname = "stat_refresh",
3025 .data = NULL,
3026 .maxlen = 0,
3027 .mode = 0600,
3028 .proc_handler = vmstat_refresh,
3029 },
3030#endif
3031#ifdef CONFIG_MMU
3032 {
3033 .procname = "mmap_min_addr",
3034 .data = &dac_mmap_min_addr,
3035 .maxlen = sizeof(unsigned long),
3036 .mode = 0644,
3037 .proc_handler = mmap_min_addr_handler,
3038 },
3039#endif
3040#ifdef CONFIG_NUMA
3041 {
3042 .procname = "numa_zonelist_order",
3043 .data = &numa_zonelist_order,
3044 .maxlen = NUMA_ZONELIST_ORDER_LEN,
3045 .mode = 0644,
3046 .proc_handler = numa_zonelist_order_handler,
3047 },
3048#endif
3049#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
3050 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
3051 {
3052 .procname = "vdso_enabled",
3053#ifdef CONFIG_X86_32
3054 .data = &vdso32_enabled,
3055 .maxlen = sizeof(vdso32_enabled),
3056#else
3057 .data = &vdso_enabled,
3058 .maxlen = sizeof(vdso_enabled),
3059#endif
3060 .mode = 0644,
3061 .proc_handler = proc_dointvec,
3062 .extra1 = SYSCTL_ZERO,
3063 },
3064#endif
3065#ifdef CONFIG_HIGHMEM
3066 {
3067 .procname = "highmem_is_dirtyable",
3068 .data = &vm_highmem_is_dirtyable,
3069 .maxlen = sizeof(vm_highmem_is_dirtyable),
3070 .mode = 0644,
3071 .proc_handler = proc_dointvec_minmax,
3072 .extra1 = SYSCTL_ZERO,
3073 .extra2 = SYSCTL_ONE,
3074 },
3075#endif
3076#ifdef CONFIG_MEMORY_FAILURE
3077 {
3078 .procname = "memory_failure_early_kill",
3079 .data = &sysctl_memory_failure_early_kill,
3080 .maxlen = sizeof(sysctl_memory_failure_early_kill),
3081 .mode = 0644,
3082 .proc_handler = proc_dointvec_minmax,
3083 .extra1 = SYSCTL_ZERO,
3084 .extra2 = SYSCTL_ONE,
3085 },
3086 {
3087 .procname = "memory_failure_recovery",
3088 .data = &sysctl_memory_failure_recovery,
3089 .maxlen = sizeof(sysctl_memory_failure_recovery),
3090 .mode = 0644,
3091 .proc_handler = proc_dointvec_minmax,
3092 .extra1 = SYSCTL_ZERO,
3093 .extra2 = SYSCTL_ONE,
3094 },
3095#endif
3096 {
3097 .procname = "user_reserve_kbytes",
3098 .data = &sysctl_user_reserve_kbytes,
3099 .maxlen = sizeof(sysctl_user_reserve_kbytes),
3100 .mode = 0644,
3101 .proc_handler = proc_doulongvec_minmax,
3102 },
3103 {
3104 .procname = "admin_reserve_kbytes",
3105 .data = &sysctl_admin_reserve_kbytes,
3106 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
3107 .mode = 0644,
3108 .proc_handler = proc_doulongvec_minmax,
3109 },
3110#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
3111 {
3112 .procname = "mmap_rnd_bits",
3113 .data = &mmap_rnd_bits,
3114 .maxlen = sizeof(mmap_rnd_bits),
3115 .mode = 0600,
3116 .proc_handler = proc_dointvec_minmax,
3117 .extra1 = (void *)&mmap_rnd_bits_min,
3118 .extra2 = (void *)&mmap_rnd_bits_max,
3119 },
3120#endif
3121#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
3122 {
3123 .procname = "mmap_rnd_compat_bits",
3124 .data = &mmap_rnd_compat_bits,
3125 .maxlen = sizeof(mmap_rnd_compat_bits),
3126 .mode = 0600,
3127 .proc_handler = proc_dointvec_minmax,
3128 .extra1 = (void *)&mmap_rnd_compat_bits_min,
3129 .extra2 = (void *)&mmap_rnd_compat_bits_max,
3130 },
3131#endif
3132#ifdef CONFIG_USERFAULTFD
3133 {
3134 .procname = "unprivileged_userfaultfd",
3135 .data = &sysctl_unprivileged_userfaultfd,
3136 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
3137 .mode = 0644,
3138 .proc_handler = proc_dointvec_minmax,
3139 .extra1 = SYSCTL_ZERO,
3140 .extra2 = SYSCTL_ONE,
3141 },
3142#endif
3143 { }
3144};
3145
3146static struct ctl_table fs_table[] = {
3147 {
3148 .procname = "inode-nr",
3149 .data = &inodes_stat,
3150 .maxlen = 2*sizeof(long),
3151 .mode = 0444,
3152 .proc_handler = proc_nr_inodes,
3153 },
3154 {
3155 .procname = "inode-state",
3156 .data = &inodes_stat,
3157 .maxlen = 7*sizeof(long),
3158 .mode = 0444,
3159 .proc_handler = proc_nr_inodes,
3160 },
3161 {
3162 .procname = "file-nr",
3163 .data = &files_stat,
3164 .maxlen = sizeof(files_stat),
3165 .mode = 0444,
3166 .proc_handler = proc_nr_files,
3167 },
3168 {
3169 .procname = "file-max",
3170 .data = &files_stat.max_files,
3171 .maxlen = sizeof(files_stat.max_files),
3172 .mode = 0644,
3173 .proc_handler = proc_doulongvec_minmax,
3174 .extra1 = &zero_ul,
3175 .extra2 = &long_max,
3176 },
3177 {
3178 .procname = "nr_open",
3179 .data = &sysctl_nr_open,
3180 .maxlen = sizeof(unsigned int),
3181 .mode = 0644,
3182 .proc_handler = proc_dointvec_minmax,
3183 .extra1 = &sysctl_nr_open_min,
3184 .extra2 = &sysctl_nr_open_max,
3185 },
3186 {
3187 .procname = "dentry-state",
3188 .data = &dentry_stat,
3189 .maxlen = 6*sizeof(long),
3190 .mode = 0444,
3191 .proc_handler = proc_nr_dentry,
3192 },
3193 {
3194 .procname = "overflowuid",
3195 .data = &fs_overflowuid,
3196 .maxlen = sizeof(int),
3197 .mode = 0644,
3198 .proc_handler = proc_dointvec_minmax,
3199 .extra1 = &minolduid,
3200 .extra2 = &maxolduid,
3201 },
3202 {
3203 .procname = "overflowgid",
3204 .data = &fs_overflowgid,
3205 .maxlen = sizeof(int),
3206 .mode = 0644,
3207 .proc_handler = proc_dointvec_minmax,
3208 .extra1 = &minolduid,
3209 .extra2 = &maxolduid,
3210 },
3211#ifdef CONFIG_FILE_LOCKING
3212 {
3213 .procname = "leases-enable",
3214 .data = &leases_enable,
3215 .maxlen = sizeof(int),
3216 .mode = 0644,
3217 .proc_handler = proc_dointvec,
3218 },
3219#endif
3220#ifdef CONFIG_DNOTIFY
3221 {
3222 .procname = "dir-notify-enable",
3223 .data = &dir_notify_enable,
3224 .maxlen = sizeof(int),
3225 .mode = 0644,
3226 .proc_handler = proc_dointvec,
3227 },
3228#endif
3229#ifdef CONFIG_MMU
3230#ifdef CONFIG_FILE_LOCKING
3231 {
3232 .procname = "lease-break-time",
3233 .data = &lease_break_time,
3234 .maxlen = sizeof(int),
3235 .mode = 0644,
3236 .proc_handler = proc_dointvec,
3237 },
3238#endif
3239#ifdef CONFIG_AIO
3240 {
3241 .procname = "aio-nr",
3242 .data = &aio_nr,
3243 .maxlen = sizeof(aio_nr),
3244 .mode = 0444,
3245 .proc_handler = proc_doulongvec_minmax,
3246 },
3247 {
3248 .procname = "aio-max-nr",
3249 .data = &aio_max_nr,
3250 .maxlen = sizeof(aio_max_nr),
3251 .mode = 0644,
3252 .proc_handler = proc_doulongvec_minmax,
3253 },
3254#endif /* CONFIG_AIO */
3255#ifdef CONFIG_INOTIFY_USER
3256 {
3257 .procname = "inotify",
3258 .mode = 0555,
3259 .child = inotify_table,
3260 },
3261#endif
3262#ifdef CONFIG_EPOLL
3263 {
3264 .procname = "epoll",
3265 .mode = 0555,
3266 .child = epoll_table,
3267 },
3268#endif
3269#endif
3270 {
3271 .procname = "protected_symlinks",
3272 .data = &sysctl_protected_symlinks,
3273 .maxlen = sizeof(int),
3274 .mode = 0600,
3275 .proc_handler = proc_dointvec_minmax,
3276 .extra1 = SYSCTL_ZERO,
3277 .extra2 = SYSCTL_ONE,
3278 },
3279 {
3280 .procname = "protected_hardlinks",
3281 .data = &sysctl_protected_hardlinks,
3282 .maxlen = sizeof(int),
3283 .mode = 0600,
3284 .proc_handler = proc_dointvec_minmax,
3285 .extra1 = SYSCTL_ZERO,
3286 .extra2 = SYSCTL_ONE,
3287 },
3288 {
3289 .procname = "protected_fifos",
3290 .data = &sysctl_protected_fifos,
3291 .maxlen = sizeof(int),
3292 .mode = 0600,
3293 .proc_handler = proc_dointvec_minmax,
3294 .extra1 = SYSCTL_ZERO,
3295 .extra2 = &two,
3296 },
3297 {
3298 .procname = "protected_regular",
3299 .data = &sysctl_protected_regular,
3300 .maxlen = sizeof(int),
3301 .mode = 0600,
3302 .proc_handler = proc_dointvec_minmax,
3303 .extra1 = SYSCTL_ZERO,
3304 .extra2 = &two,
3305 },
3306 {
3307 .procname = "suid_dumpable",
3308 .data = &suid_dumpable,
3309 .maxlen = sizeof(int),
3310 .mode = 0644,
3311 .proc_handler = proc_dointvec_minmax_coredump,
3312 .extra1 = SYSCTL_ZERO,
3313 .extra2 = &two,
3314 },
3315#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
3316 {
3317 .procname = "binfmt_misc",
3318 .mode = 0555,
3319 .child = sysctl_mount_point,
3320 },
3321#endif
3322 {
3323 .procname = "pipe-max-size",
3324 .data = &pipe_max_size,
3325 .maxlen = sizeof(pipe_max_size),
3326 .mode = 0644,
3327 .proc_handler = proc_dopipe_max_size,
3328 },
3329 {
3330 .procname = "pipe-user-pages-hard",
3331 .data = &pipe_user_pages_hard,
3332 .maxlen = sizeof(pipe_user_pages_hard),
3333 .mode = 0644,
3334 .proc_handler = proc_doulongvec_minmax,
3335 },
3336 {
3337 .procname = "pipe-user-pages-soft",
3338 .data = &pipe_user_pages_soft,
3339 .maxlen = sizeof(pipe_user_pages_soft),
3340 .mode = 0644,
3341 .proc_handler = proc_doulongvec_minmax,
3342 },
3343 {
3344 .procname = "mount-max",
3345 .data = &sysctl_mount_max,
3346 .maxlen = sizeof(unsigned int),
3347 .mode = 0644,
3348 .proc_handler = proc_dointvec_minmax,
3349 .extra1 = SYSCTL_ONE,
3350 },
3351 { }
3352};
3353
3354static struct ctl_table debug_table[] = {
3355#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
3356 {
3357 .procname = "exception-trace",
3358 .data = &show_unhandled_signals,
3359 .maxlen = sizeof(int),
3360 .mode = 0644,
3361 .proc_handler = proc_dointvec
3362 },
3363#endif
3364#if defined(CONFIG_OPTPROBES)
3365 {
3366 .procname = "kprobes-optimization",
3367 .data = &sysctl_kprobes_optimization,
3368 .maxlen = sizeof(int),
3369 .mode = 0644,
3370 .proc_handler = proc_kprobes_optimization_handler,
3371 .extra1 = SYSCTL_ZERO,
3372 .extra2 = SYSCTL_ONE,
3373 },
3374#endif
3375 { }
3376};
3377
3378static struct ctl_table dev_table[] = {
3379 { }
3380};
3381
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02003382static struct ctl_table sysctl_base_table[] = {
3383 {
3384 .procname = "kernel",
3385 .mode = 0555,
3386 .child = kern_table,
3387 },
3388 {
3389 .procname = "vm",
3390 .mode = 0555,
3391 .child = vm_table,
3392 },
3393 {
3394 .procname = "fs",
3395 .mode = 0555,
3396 .child = fs_table,
3397 },
3398 {
3399 .procname = "debug",
3400 .mode = 0555,
3401 .child = debug_table,
3402 },
3403 {
3404 .procname = "dev",
3405 .mode = 0555,
3406 .child = dev_table,
3407 },
3408 { }
3409};
3410
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411int __init sysctl_init(void)
3412{
3413 struct ctl_table_header *hdr;
3414
3415 hdr = register_sysctl_table(sysctl_base_table);
3416 kmemleak_not_leak(hdr);
3417 return 0;
3418}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419#endif /* CONFIG_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420/*
3421 * No sense putting this after each symbol definition, twice,
3422 * exception granted :-)
3423 */
3424EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003425EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426EXPORT_SYMBOL(proc_dointvec_jiffies);
3427EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003428EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3430EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3431EXPORT_SYMBOL(proc_dostring);
3432EXPORT_SYMBOL(proc_doulongvec_minmax);
3433EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04003434EXPORT_SYMBOL(proc_do_large_bitmap);