blob: 083be6af29d705f371676a0bbca3b4c2546c62ee [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>
Andy Shevchenkof39650d2021-06-30 18:54:59 -070030#include <linux/panic.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080031#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070033#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <linux/ctype.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070035#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070036#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <linux/init.h>
38#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010039#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030040#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/sysrq.h>
42#include <linux/highuid.h>
43#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020044#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070045#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070048#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/times.h>
50#include <linux/limits.h>
51#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020052#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070054#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080055#include <linux/nfs_fs.h>
56#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070057#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020058#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020059#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050060#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020061#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070062#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040063#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070064#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000065#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060066#include <linux/sched/sysctl.h>
Ingo Molnarf7ccbae2017-02-08 18:51:30 +010067#include <linux/sched/coredump.h>
Kees Cook79847542014-01-23 15:55:59 -080068#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070069#include <linux/bpf.h>
Eric W. Biedermand2921682016-09-28 00:27:17 -050070#include <linux/mount.h>
Peter Xucefdca02019-05-13 17:16:41 -070071#include <linux/userfaultfd_k.h>
Christoph Hellwig2374c092020-04-24 08:43:36 +020072#include <linux/coredump.h>
73#include <linux/latencytop.h>
74#include <linux/pid.h>
Peter Zijlstra0cd7c742021-05-10 14:01:00 +020075#include <linux/delayacct.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Christian Brauner7f2923c2019-03-07 16:29:40 -080077#include "../lib/kstrtox.h"
78
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080079#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#include <asm/processor.h>
81
Andi Kleen29cbc782006-09-30 01:47:55 +020082#ifdef CONFIG_X86
83#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010084#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010085#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020086#endif
David Howellsd550bbd2012-03-28 18:30:03 +010087#ifdef CONFIG_SPARC
88#include <asm/setup.h>
89#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080090#ifdef CONFIG_BSD_PROCESS_ACCT
91#include <linux/acct.h>
92#endif
Dave Young4f0e0562010-03-10 15:24:09 -080093#ifdef CONFIG_RT_MUTEXES
94#include <linux/rtmutex.h>
95#endif
Dave Young2edf5e42010-03-10 15:24:10 -080096#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
97#include <linux/lockdep.h>
98#endif
Dave Young15485a42010-03-10 15:24:07 -080099#ifdef CONFIG_CHR_DEV_SG
100#include <scsi/sg.h>
101#endif
Alexander Popov964c9df2018-08-17 01:17:03 +0300102#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
103#include <linux/stackleak.h>
104#endif
Don Zickus58687ac2010-05-07 17:11:44 -0400105#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -0500106#include <linux/nmi.h>
107#endif
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#if defined(CONFIG_SYSCTL)
110
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700111/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400112#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700113static int sixty = 60;
114#endif
115
Aaron Tomlin270750db2014-01-20 17:34:13 +0000116static int __maybe_unused neg_one = -1;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700117static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700118static int __maybe_unused four = 4;
Will Deacon9002b212019-04-05 18:39:38 -0700119static unsigned long zero_ul;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800120static unsigned long one_ul = 1;
Christian Brauner32a5ad92019-03-07 16:29:43 -0800121static unsigned long long_max = LONG_MAX;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700122static int one_hundred = 100;
Johannes Weinerc8439662020-06-03 16:02:37 -0700123static int two_hundred = 200;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700124static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700125#ifdef CONFIG_PRINTK
126static int ten_thousand = 10000;
127#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300128#ifdef CONFIG_PERF_EVENTS
129static int six_hundred_forty_kb = 640 * 1024;
130#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700131
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700132/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
133static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
136static int maxolduid = 65535;
137static int minolduid;
138
139static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700140static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Dmitry Vyukova2e51442018-08-21 21:55:52 -0700142/*
143 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
144 * and hung_task_check_interval_secs
145 */
Liu Hua80df2842014-04-07 15:38:57 -0700146#ifdef CONFIG_DETECT_HUNG_TASK
147static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
148#endif
149
Dave Youngd14f1722010-02-25 20:28:57 -0500150#ifdef CONFIG_INOTIFY_USER
151#include <linux/inotify.h>
152#endif
Amir Goldstein5b8fea62021-03-04 13:29:20 +0200153#ifdef CONFIG_FANOTIFY
154#include <linux/fanotify.h>
155#endif
Vineet Guptab6fca722013-01-09 20:06:28 +0530156
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700157#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700158
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700159/**
160 * enum sysctl_writes_mode - supported sysctl write modes
161 *
162 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
Weitao Hou65f50f22019-07-16 16:26:54 -0700163 * to be written, and multiple writes on the same sysctl file descriptor
164 * will rewrite the sysctl value, regardless of file position. No warning
165 * is issued when the initial position is not 0.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700166 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
Weitao Hou65f50f22019-07-16 16:26:54 -0700167 * not 0.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700168 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
Weitao Hou65f50f22019-07-16 16:26:54 -0700169 * file position 0 and the value must be fully contained in the buffer
170 * sent to the write syscall. If dealing with strings respect the file
171 * position, but restrict this to the max length of the buffer, anything
172 * passed the max length will be ignored. Multiple writes will append
173 * to the buffer.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700174 *
175 * These write modes control how current file position affects the behavior of
176 * updating sysctl values through the proc interface on each write.
177 */
178enum sysctl_writes_mode {
179 SYSCTL_WRITES_LEGACY = -1,
180 SYSCTL_WRITES_WARN = 0,
181 SYSCTL_WRITES_STRICT = 1,
182};
Kees Cookf4aacea2014-06-06 14:37:19 -0700183
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700184static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Christoph Hellwigf461d2d2020-04-24 08:43:37 +0200185#endif /* CONFIG_PROC_SYSCTL */
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800186
Alexandre Ghiti67f39772019-09-23 15:38:47 -0700187#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
188 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189int sysctl_legacy_va_layout;
190#endif
191
Mel Gorman5e771902010-05-24 14:32:31 -0700192#ifdef CONFIG_COMPACTION
193static int min_extfrag_threshold;
194static int max_extfrag_threshold = 1000;
195#endif
196
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700197#endif /* CONFIG_SYSCTL */
198
Arnd Bergmann5447e8e2020-05-05 16:07:12 +0200199#if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL)
Song Liud46edd62020-04-30 00:15:04 -0700200static int bpf_stats_handler(struct ctl_table *table, int write,
Tobias Klauser7787b6f2020-08-24 16:20:47 +0200201 void *buffer, size_t *lenp, loff_t *ppos)
Song Liud46edd62020-04-30 00:15:04 -0700202{
203 struct static_key *key = (struct static_key *)table->data;
204 static int saved_val;
205 int val, ret;
206 struct ctl_table tmp = {
207 .data = &val,
208 .maxlen = sizeof(val),
209 .mode = table->mode,
210 .extra1 = SYSCTL_ZERO,
211 .extra2 = SYSCTL_ONE,
212 };
213
214 if (write && !capable(CAP_SYS_ADMIN))
215 return -EPERM;
216
217 mutex_lock(&bpf_stats_enabled_mutex);
218 val = saved_val;
219 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
220 if (write && !ret && val != saved_val) {
221 if (val)
222 static_key_slow_inc(key);
223 else
224 static_key_slow_dec(key);
225 saved_val = val;
226 }
227 mutex_unlock(&bpf_stats_enabled_mutex);
228 return ret;
229}
Daniel Borkmann08389d82021-05-11 22:35:17 +0200230
231static int bpf_unpriv_handler(struct ctl_table *table, int write,
232 void *buffer, size_t *lenp, loff_t *ppos)
233{
234 int ret, unpriv_enable = *(int *)table->data;
235 bool locked_state = unpriv_enable == 1;
236 struct ctl_table tmp = *table;
237
238 if (write && !capable(CAP_SYS_ADMIN))
239 return -EPERM;
240
241 tmp.data = &unpriv_enable;
242 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
243 if (write && !ret) {
244 if (locked_state && unpriv_enable != 1)
245 return -EPERM;
246 *(int *)table->data = unpriv_enable;
247 }
248 return ret;
249}
250#endif /* CONFIG_BPF_SYSCALL && CONFIG_SYSCTL */
Song Liud46edd62020-04-30 00:15:04 -0700251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252/*
253 * /proc/sys support
254 */
255
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700256#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Kees Cookf8808302014-06-06 14:37:17 -0700258static int _proc_do_string(char *data, int maxlen, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200259 char *buffer, size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700260{
261 size_t len;
Christoph Hellwig32927392020-04-24 08:43:38 +0200262 char c, *p;
Oleg Nesterov8d060872007-02-10 01:46:38 -0800263
264 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700265 *lenp = 0;
266 return 0;
267 }
Oleg Nesterov8d060872007-02-10 01:46:38 -0800268
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700269 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -0700270 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
271 /* Only continue writes not past the end of buffer. */
272 len = strlen(data);
273 if (len > maxlen - 1)
274 len = maxlen - 1;
275
276 if (*ppos > len)
277 return 0;
278 len = *ppos;
279 } else {
280 /* Start writing from beginning of buffer. */
281 len = 0;
282 }
283
Kees Cook2ca9bb42014-06-06 14:37:18 -0700284 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700285 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -0700286 while ((p - buffer) < *lenp && len < maxlen - 1) {
Christoph Hellwig32927392020-04-24 08:43:38 +0200287 c = *(p++);
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700288 if (c == 0 || c == '\n')
289 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -0700290 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700291 }
Kees Cookf8808302014-06-06 14:37:17 -0700292 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700293 } else {
294 len = strlen(data);
295 if (len > maxlen)
296 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -0800297
298 if (*ppos > len) {
299 *lenp = 0;
300 return 0;
301 }
302
303 data += *ppos;
304 len -= *ppos;
305
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700306 if (len > *lenp)
307 len = *lenp;
308 if (len)
Christoph Hellwig32927392020-04-24 08:43:38 +0200309 memcpy(buffer, data, len);
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700310 if (len < *lenp) {
Christoph Hellwig32927392020-04-24 08:43:38 +0200311 buffer[len] = '\n';
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700312 len++;
313 }
314 *lenp = len;
315 *ppos += len;
316 }
317 return 0;
318}
319
Kees Cookf4aacea2014-06-06 14:37:19 -0700320static void warn_sysctl_write(struct ctl_table *table)
321{
322 pr_warn_once("%s wrote to %s when file position was not 0!\n"
323 "This will not be supported in the future. To silence this\n"
324 "warning, set kernel.sysctl_writes_strict = -1\n",
325 current->comm, table->procname);
326}
327
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328/**
Randy Dunlap5f733e82018-08-21 22:01:06 -0700329 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700330 * @ppos: file position
331 * @table: the sysctl table
332 *
333 * Returns true if the first position is non-zero and the sysctl_writes_strict
334 * mode indicates this is not allowed for numeric input types. String proc
Randy Dunlap5f733e82018-08-21 22:01:06 -0700335 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700336 */
337static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
338 struct ctl_table *table)
339{
340 if (!*ppos)
341 return false;
342
343 switch (sysctl_writes_strict) {
344 case SYSCTL_WRITES_STRICT:
345 return true;
346 case SYSCTL_WRITES_WARN:
347 warn_sysctl_write(table);
348 return false;
349 default:
350 return false;
351 }
352}
353
354/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 * proc_dostring - read a string sysctl
356 * @table: the sysctl table
357 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 * @buffer: the user buffer
359 * @lenp: the size of the user buffer
360 * @ppos: file position
361 *
362 * Reads/writes a string from/to the user buffer. If the kernel
363 * buffer provided is not large enough to hold the string, the
364 * string is truncated. The copied string is %NULL-terminated.
365 * If the string is being read by the user process, it is copied
366 * and a newline '\n' is added. It is truncated if the buffer is
367 * not large enough.
368 *
369 * Returns 0 on success.
370 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700371int proc_dostring(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200372 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700374 if (write)
375 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -0700376
Christoph Hellwig32927392020-04-24 08:43:38 +0200377 return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
378 ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
380
Amerigo Wang00b7c332010-05-05 00:26:45 +0000381static size_t proc_skip_spaces(char **buf)
382{
383 size_t ret;
384 char *tmp = skip_spaces(*buf);
385 ret = tmp - *buf;
386 *buf = tmp;
387 return ret;
388}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Octavian Purdila9f977fb2010-05-05 00:26:55 +0000390static void proc_skip_char(char **buf, size_t *size, const char v)
391{
392 while (*size) {
393 if (**buf != v)
394 break;
395 (*size)--;
396 (*buf)++;
397 }
398}
399
Christian Brauner7f2923c2019-03-07 16:29:40 -0800400/**
401 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
402 * fail on overflow
403 *
404 * @cp: kernel buffer containing the string to parse
405 * @endp: pointer to store the trailing characters
406 * @base: the base to use
407 * @res: where the parsed integer will be stored
408 *
409 * In case of success 0 is returned and @res will contain the parsed integer,
410 * @endp will hold any trailing characters.
411 * This function will fail the parse on overflow. If there wasn't an overflow
412 * the function will defer the decision what characters count as invalid to the
413 * caller.
414 */
415static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
416 unsigned long *res)
417{
418 unsigned long long result;
419 unsigned int rv;
420
421 cp = _parse_integer_fixup_radix(cp, &base);
422 rv = _parse_integer(cp, base, &result);
423 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
424 return -ERANGE;
425
426 cp += rv;
427
428 if (endp)
429 *endp = (char *)cp;
430
431 *res = (unsigned long)result;
432 return 0;
433}
434
Amerigo Wang00b7c332010-05-05 00:26:45 +0000435#define TMPBUFLEN 22
436/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700437 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +0000438 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700439 * @buf: a kernel buffer
440 * @size: size of the kernel buffer
441 * @val: this is where the number will be stored
442 * @neg: set to %TRUE if number is negative
443 * @perm_tr: a vector which contains the allowed trailers
444 * @perm_tr_len: size of the perm_tr vector
445 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +0000446 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700447 * In case of success %0 is returned and @buf and @size are updated with
448 * the amount of bytes read. If @tr is non-NULL and a trailing
449 * character exists (size is non-zero after returning from this
450 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +0000451 */
452static int proc_get_long(char **buf, size_t *size,
453 unsigned long *val, bool *neg,
454 const char *perm_tr, unsigned perm_tr_len, char *tr)
455{
456 int len;
457 char *p, tmp[TMPBUFLEN];
458
459 if (!*size)
460 return -EINVAL;
461
462 len = *size;
463 if (len > TMPBUFLEN - 1)
464 len = TMPBUFLEN - 1;
465
466 memcpy(tmp, *buf, len);
467
468 tmp[len] = 0;
469 p = tmp;
470 if (*p == '-' && *size > 1) {
471 *neg = true;
472 p++;
473 } else
474 *neg = false;
475 if (!isdigit(*p))
476 return -EINVAL;
477
Christian Brauner7f2923c2019-03-07 16:29:40 -0800478 if (strtoul_lenient(p, &p, 0, val))
479 return -EINVAL;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000480
481 len = p - tmp;
482
483 /* We don't know if the next char is whitespace thus we may accept
484 * invalid integers (e.g. 1234...a) or two integers instead of one
485 * (e.g. 123...1). So lets not allow such large numbers. */
486 if (len == TMPBUFLEN - 1)
487 return -EINVAL;
488
489 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
490 return -EINVAL;
491
492 if (tr && (len < *size))
493 *tr = *p;
494
495 *buf += len;
496 *size -= len;
497
498 return 0;
499}
500
501/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700502 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +0000503 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700504 * @buf: the user buffer
505 * @size: the size of the user buffer
506 * @val: the integer to be converted
507 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +0000508 *
Christoph Hellwig32927392020-04-24 08:43:38 +0200509 * In case of success @buf and @size are updated with the amount of bytes
510 * written.
Amerigo Wang00b7c332010-05-05 00:26:45 +0000511 */
Christoph Hellwig32927392020-04-24 08:43:38 +0200512static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
Amerigo Wang00b7c332010-05-05 00:26:45 +0000513{
514 int len;
515 char tmp[TMPBUFLEN], *p = tmp;
516
517 sprintf(p, "%s%lu", neg ? "-" : "", val);
518 len = strlen(tmp);
519 if (len > *size)
520 len = *size;
Christoph Hellwig32927392020-04-24 08:43:38 +0200521 memcpy(*buf, tmp, len);
Amerigo Wang00b7c332010-05-05 00:26:45 +0000522 *size -= len;
523 *buf += len;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000524}
525#undef TMPBUFLEN
526
Christoph Hellwig32927392020-04-24 08:43:38 +0200527static void proc_put_char(void **buf, size_t *size, char c)
Amerigo Wang00b7c332010-05-05 00:26:45 +0000528{
529 if (*size) {
Christoph Hellwig32927392020-04-24 08:43:38 +0200530 char **buffer = (char **)buf;
531 **buffer = c;
532
533 (*size)--;
534 (*buffer)++;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000535 *buf = *buffer;
536 }
Amerigo Wang00b7c332010-05-05 00:26:45 +0000537}
538
Jia Hea2071572021-08-03 12:59:36 +0200539static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp,
540 int *valp,
541 int write, void *data)
542{
543 if (write) {
544 *(bool *)valp = *lvalp;
545 } else {
546 int val = *(bool *)valp;
547
548 *lvalp = (unsigned long)val;
549 *negp = false;
550 }
551 return 0;
552}
553
Amerigo Wang00b7c332010-05-05 00:26:45 +0000554static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 int *valp,
556 int write, void *data)
557{
558 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -0700559 if (*negp) {
560 if (*lvalp > (unsigned long) INT_MAX + 1)
561 return -EINVAL;
562 *valp = -*lvalp;
563 } else {
564 if (*lvalp > (unsigned long) INT_MAX)
565 return -EINVAL;
566 *valp = *lvalp;
567 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 } else {
569 int val = *valp;
570 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +0000571 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -0700572 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +0000574 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 *lvalp = (unsigned long)val;
576 }
577 }
578 return 0;
579}
580
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700581static int do_proc_douintvec_conv(unsigned long *lvalp,
582 unsigned int *valp,
583 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700584{
585 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700586 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700587 return -EINVAL;
588 *valp = *lvalp;
589 } else {
590 unsigned int val = *valp;
591 *lvalp = (unsigned long)val;
592 }
593 return 0;
594}
595
Amerigo Wang00b7c332010-05-05 00:26:45 +0000596static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
597
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700598static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200599 int write, void *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700600 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +0000601 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 int write, void *data),
603 void *data)
604{
Amerigo Wang00b7c332010-05-05 00:26:45 +0000605 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000606 size_t left;
Christoph Hellwig32927392020-04-24 08:43:38 +0200607 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Amerigo Wang00b7c332010-05-05 00:26:45 +0000609 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 *lenp = 0;
611 return 0;
612 }
613
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700614 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 vleft = table->maxlen / sizeof(*i);
616 left = *lenp;
617
618 if (!conv)
619 conv = do_proc_dointvec_conv;
620
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700622 if (proc_first_pos_non_zero_ignore(ppos, table))
623 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -0700624
Amerigo Wang00b7c332010-05-05 00:26:45 +0000625 if (left > PAGE_SIZE - 1)
626 left = PAGE_SIZE - 1;
Christoph Hellwig32927392020-04-24 08:43:38 +0200627 p = buffer;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000628 }
629
630 for (; left && vleft--; i++, first=0) {
631 unsigned long lval;
632 bool neg;
633
634 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -0500635 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +0000636
J. R. Okajima563b0462010-05-25 16:10:14 -0700637 if (!left)
638 break;
Al Viro70f6cbb2015-12-24 00:13:10 -0500639 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +0000640 proc_wspace_sep,
641 sizeof(proc_wspace_sep), NULL);
642 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000644 if (conv(&neg, &lval, i, 1, data)) {
645 err = -EINVAL;
646 break;
647 }
648 } else {
649 if (conv(&neg, &lval, i, 0, data)) {
650 err = -EINVAL;
651 break;
652 }
653 if (!first)
Christoph Hellwig32927392020-04-24 08:43:38 +0200654 proc_put_char(&buffer, &left, '\t');
655 proc_put_long(&buffer, &left, lval, neg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 }
657 }
Amerigo Wang00b7c332010-05-05 00:26:45 +0000658
659 if (!write && !first && left && !err)
Christoph Hellwig32927392020-04-24 08:43:38 +0200660 proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -0700661 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -0500662 left -= proc_skip_spaces(&p);
Christoph Hellwig32927392020-04-24 08:43:38 +0200663 if (write && first)
664 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -0700666out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000668 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669}
670
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700671static int do_proc_dointvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200672 void *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +0000673 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700674 int write, void *data),
675 void *data)
676{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700677 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700678 buffer, lenp, ppos, conv, data);
679}
680
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700681static int do_proc_douintvec_w(unsigned int *tbl_data,
682 struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200683 void *buffer,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700684 size_t *lenp, loff_t *ppos,
685 int (*conv)(unsigned long *lvalp,
686 unsigned int *valp,
687 int write, void *data),
688 void *data)
689{
690 unsigned long lval;
691 int err = 0;
692 size_t left;
693 bool neg;
Christoph Hellwig32927392020-04-24 08:43:38 +0200694 char *p = buffer;
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700695
696 left = *lenp;
697
698 if (proc_first_pos_non_zero_ignore(ppos, table))
699 goto bail_early;
700
701 if (left > PAGE_SIZE - 1)
702 left = PAGE_SIZE - 1;
703
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700704 left -= proc_skip_spaces(&p);
705 if (!left) {
706 err = -EINVAL;
707 goto out_free;
708 }
709
710 err = proc_get_long(&p, &left, &lval, &neg,
711 proc_wspace_sep,
712 sizeof(proc_wspace_sep), NULL);
713 if (err || neg) {
714 err = -EINVAL;
715 goto out_free;
716 }
717
718 if (conv(&lval, tbl_data, 1, data)) {
719 err = -EINVAL;
720 goto out_free;
721 }
722
723 if (!err && left)
724 left -= proc_skip_spaces(&p);
725
726out_free:
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700727 if (err)
728 return -EINVAL;
729
730 return 0;
731
732 /* This is in keeping with old __do_proc_dointvec() */
733bail_early:
734 *ppos += *lenp;
735 return err;
736}
737
Christoph Hellwig32927392020-04-24 08:43:38 +0200738static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700739 size_t *lenp, loff_t *ppos,
740 int (*conv)(unsigned long *lvalp,
741 unsigned int *valp,
742 int write, void *data),
743 void *data)
744{
745 unsigned long lval;
746 int err = 0;
747 size_t left;
748
749 left = *lenp;
750
751 if (conv(&lval, tbl_data, 0, data)) {
752 err = -EINVAL;
753 goto out;
754 }
755
Christoph Hellwig32927392020-04-24 08:43:38 +0200756 proc_put_long(&buffer, &left, lval, false);
757 if (!left)
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700758 goto out;
759
Christoph Hellwig32927392020-04-24 08:43:38 +0200760 proc_put_char(&buffer, &left, '\n');
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700761
762out:
763 *lenp -= left;
764 *ppos += *lenp;
765
766 return err;
767}
768
769static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200770 int write, void *buffer,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700771 size_t *lenp, loff_t *ppos,
772 int (*conv)(unsigned long *lvalp,
773 unsigned int *valp,
774 int write, void *data),
775 void *data)
776{
777 unsigned int *i, vleft;
778
779 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
780 *lenp = 0;
781 return 0;
782 }
783
784 i = (unsigned int *) tbl_data;
785 vleft = table->maxlen / sizeof(*i);
786
787 /*
788 * Arrays are not supported, keep this simple. *Do not* add
789 * support for them.
790 */
791 if (vleft != 1) {
792 *lenp = 0;
793 return -EINVAL;
794 }
795
796 if (!conv)
797 conv = do_proc_douintvec_conv;
798
799 if (write)
800 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
801 conv, data);
802 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
803}
804
805static int do_proc_douintvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200806 void *buffer, size_t *lenp, loff_t *ppos,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700807 int (*conv)(unsigned long *lvalp,
808 unsigned int *valp,
809 int write, void *data),
810 void *data)
811{
812 return __do_proc_douintvec(table->data, table, write,
813 buffer, lenp, ppos, conv, data);
814}
815
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816/**
Jia Hea2071572021-08-03 12:59:36 +0200817 * proc_dobool - read/write a bool
818 * @table: the sysctl table
819 * @write: %TRUE if this is a write to the sysctl file
820 * @buffer: the user buffer
821 * @lenp: the size of the user buffer
822 * @ppos: file position
823 *
824 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
825 * values from/to the user buffer, treated as an ASCII string.
826 *
827 * Returns 0 on success.
828 */
829int proc_dobool(struct ctl_table *table, int write, void *buffer,
830 size_t *lenp, loff_t *ppos)
831{
832 return do_proc_dointvec(table, write, buffer, lenp, ppos,
833 do_proc_dobool_conv, NULL);
834}
835
836/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 * proc_dointvec - read a vector of integers
838 * @table: the sysctl table
839 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 * @buffer: the user buffer
841 * @lenp: the size of the user buffer
842 * @ppos: file position
843 *
844 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
845 * values from/to the user buffer, treated as an ASCII string.
846 *
847 * Returns 0 on success.
848 */
Christoph Hellwig32927392020-04-24 08:43:38 +0200849int proc_dointvec(struct ctl_table *table, int write, void *buffer,
850 size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700852 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
853}
854
Sebastian Andrzej Siewior6923aa02020-04-01 21:10:42 -0700855#ifdef CONFIG_COMPACTION
856static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200857 int write, void *buffer, size_t *lenp, loff_t *ppos)
Sebastian Andrzej Siewior6923aa02020-04-01 21:10:42 -0700858{
859 int ret, old;
860
861 if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
862 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
863
864 old = *(int *)table->data;
865 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
866 if (ret)
867 return ret;
868 if (old != *(int *)table->data)
869 pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
870 table->procname, current->comm,
871 task_pid_nr(current));
872 return ret;
873}
874#endif
875
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700876/**
877 * proc_douintvec - read a vector of unsigned integers
878 * @table: the sysctl table
879 * @write: %TRUE if this is a write to the sysctl file
880 * @buffer: the user buffer
881 * @lenp: the size of the user buffer
882 * @ppos: file position
883 *
884 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
885 * values from/to the user buffer, treated as an ASCII string.
886 *
887 * Returns 0 on success.
888 */
Christoph Hellwig32927392020-04-24 08:43:38 +0200889int proc_douintvec(struct ctl_table *table, int write, void *buffer,
890 size_t *lenp, loff_t *ppos)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700891{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700892 return do_proc_douintvec(table, write, buffer, lenp, ppos,
893 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894}
895
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800896/*
Andi Kleen25ddbb12008-10-15 22:01:41 -0700897 * Taint values can only be increased
898 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800899 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700900static int proc_taint(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200901 void *buffer, size_t *lenp, loff_t *ppos)
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800902{
Andi Kleen25ddbb12008-10-15 22:01:41 -0700903 struct ctl_table t;
904 unsigned long tmptaint = get_taint();
905 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800906
Bastian Blank91fcd412007-04-23 14:41:14 -0700907 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800908 return -EPERM;
909
Andi Kleen25ddbb12008-10-15 22:01:41 -0700910 t = *table;
911 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700912 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700913 if (err < 0)
914 return err;
915
916 if (write) {
Rafael Aquinidb38d5c2020-06-07 21:40:17 -0700917 int i;
918
919 /*
920 * If we are relying on panic_on_taint not producing
921 * false positives due to userspace input, bail out
922 * before setting the requested taint flags.
923 */
924 if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
925 return -EINVAL;
926
Andi Kleen25ddbb12008-10-15 22:01:41 -0700927 /*
928 * Poor man's atomic or. Not worth adding a primitive
929 * to everyone's atomic.h for this
930 */
Rafael Aquinie77132e2020-06-07 21:40:51 -0700931 for (i = 0; i < TAINT_FLAGS_COUNT; i++)
932 if ((1UL << i) & tmptaint)
Rusty Russell373d4d02013-01-21 17:17:39 +1030933 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700934 }
935
936 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800937}
938
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700939#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700940static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200941 void *buffer, size_t *lenp, loff_t *ppos)
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700942{
943 if (write && !capable(CAP_SYS_ADMIN))
944 return -EPERM;
945
946 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
947}
948#endif
949
Waiman Long24704f32018-04-10 16:35:38 -0700950/**
951 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
952 * @min: pointer to minimum allowable value
953 * @max: pointer to maximum allowable value
954 *
955 * The do_proc_dointvec_minmax_conv_param structure provides the
956 * minimum and maximum values for doing range checking for those sysctl
957 * parameters that use the proc_dointvec_minmax() handler.
958 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959struct do_proc_dointvec_minmax_conv_param {
960 int *min;
961 int *max;
962};
963
Amerigo Wang00b7c332010-05-05 00:26:45 +0000964static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
965 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 int write, void *data)
967{
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700968 int tmp, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 struct do_proc_dointvec_minmax_conv_param *param = data;
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700970 /*
971 * If writing, first do so via a temporary local int so we can
972 * bounds-check it before touching *valp.
973 */
974 int *ip = write ? &tmp : valp;
975
976 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
977 if (ret)
978 return ret;
979
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 if (write) {
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700981 if ((param->min && *param->min > tmp) ||
982 (param->max && *param->max < tmp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 return -EINVAL;
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700984 *valp = tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 }
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700986
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 return 0;
988}
989
990/**
991 * proc_dointvec_minmax - read a vector of integers with min/max values
992 * @table: the sysctl table
993 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 * @buffer: the user buffer
995 * @lenp: the size of the user buffer
996 * @ppos: file position
997 *
998 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
999 * values from/to the user buffer, treated as an ASCII string.
1000 *
1001 * This routine will ensure the values are within the range specified by
1002 * table->extra1 (min) and table->extra2 (max).
1003 *
Waiman Long24704f32018-04-10 16:35:38 -07001004 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001006int proc_dointvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001007 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008{
1009 struct do_proc_dointvec_minmax_conv_param param = {
1010 .min = (int *) table->extra1,
1011 .max = (int *) table->extra2,
1012 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001013 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 do_proc_dointvec_minmax_conv, &param);
1015}
1016
Waiman Long24704f32018-04-10 16:35:38 -07001017/**
1018 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
1019 * @min: pointer to minimum allowable value
1020 * @max: pointer to maximum allowable value
1021 *
1022 * The do_proc_douintvec_minmax_conv_param structure provides the
1023 * minimum and maximum values for doing range checking for those sysctl
1024 * parameters that use the proc_douintvec_minmax() handler.
1025 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001026struct do_proc_douintvec_minmax_conv_param {
1027 unsigned int *min;
1028 unsigned int *max;
1029};
1030
1031static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
1032 unsigned int *valp,
1033 int write, void *data)
1034{
Zev Weiss2bc4fc62019-03-11 23:28:06 -07001035 int ret;
1036 unsigned int tmp;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001037 struct do_proc_douintvec_minmax_conv_param *param = data;
Zev Weiss2bc4fc62019-03-11 23:28:06 -07001038 /* write via temporary local uint for bounds-checking */
1039 unsigned int *up = write ? &tmp : valp;
1040
1041 ret = do_proc_douintvec_conv(lvalp, up, write, data);
1042 if (ret)
1043 return ret;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001044
1045 if (write) {
Zev Weiss2bc4fc62019-03-11 23:28:06 -07001046 if ((param->min && *param->min > tmp) ||
1047 (param->max && *param->max < tmp))
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001048 return -ERANGE;
1049
Zev Weiss2bc4fc62019-03-11 23:28:06 -07001050 *valp = tmp;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001051 }
1052
1053 return 0;
1054}
1055
1056/**
1057 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
1058 * @table: the sysctl table
1059 * @write: %TRUE if this is a write to the sysctl file
1060 * @buffer: the user buffer
1061 * @lenp: the size of the user buffer
1062 * @ppos: file position
1063 *
1064 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
1065 * values from/to the user buffer, treated as an ASCII string. Negative
1066 * strings are not allowed.
1067 *
1068 * This routine will ensure the values are within the range specified by
1069 * table->extra1 (min) and table->extra2 (max). There is a final sanity
1070 * check for UINT_MAX to avoid having to support wrap around uses from
1071 * userspace.
1072 *
Waiman Long24704f32018-04-10 16:35:38 -07001073 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001074 */
1075int proc_douintvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001076 void *buffer, size_t *lenp, loff_t *ppos)
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001077{
1078 struct do_proc_douintvec_minmax_conv_param param = {
1079 .min = (unsigned int *) table->extra1,
1080 .max = (unsigned int *) table->extra2,
1081 };
1082 return do_proc_douintvec(table, write, buffer, lenp, ppos,
1083 do_proc_douintvec_minmax_conv, &param);
1084}
1085
Eric Dumazetcb944412021-03-25 11:08:13 -07001086/**
1087 * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
1088 * @table: the sysctl table
1089 * @write: %TRUE if this is a write to the sysctl file
1090 * @buffer: the user buffer
1091 * @lenp: the size of the user buffer
1092 * @ppos: file position
1093 *
1094 * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
1095 * values from/to the user buffer, treated as an ASCII string. Negative
1096 * strings are not allowed.
1097 *
1098 * This routine will ensure the values are within the range specified by
1099 * table->extra1 (min) and table->extra2 (max).
1100 *
1101 * Returns 0 on success or an error on write when the range check fails.
1102 */
1103int proc_dou8vec_minmax(struct ctl_table *table, int write,
1104 void *buffer, size_t *lenp, loff_t *ppos)
1105{
1106 struct ctl_table tmp;
1107 unsigned int min = 0, max = 255U, val;
1108 u8 *data = table->data;
1109 struct do_proc_douintvec_minmax_conv_param param = {
1110 .min = &min,
1111 .max = &max,
1112 };
1113 int res;
1114
1115 /* Do not support arrays yet. */
1116 if (table->maxlen != sizeof(u8))
1117 return -EINVAL;
1118
1119 if (table->extra1) {
1120 min = *(unsigned int *) table->extra1;
1121 if (min > 255U)
1122 return -EINVAL;
1123 }
1124 if (table->extra2) {
1125 max = *(unsigned int *) table->extra2;
1126 if (max > 255U)
1127 return -EINVAL;
1128 }
1129
1130 tmp = *table;
1131
1132 tmp.maxlen = sizeof(val);
1133 tmp.data = &val;
1134 val = *data;
1135 res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
1136 do_proc_douintvec_minmax_conv, &param);
1137 if (res)
1138 return res;
1139 if (write)
1140 *data = val;
1141 return 0;
1142}
1143EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
1144
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001145static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
1146 unsigned int *valp,
1147 int write, void *data)
1148{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001149 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08001150 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001151
Joe Lawrencefb910c42017-11-17 15:29:28 -08001152 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001153 if (val == 0)
1154 return -EINVAL;
1155
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001156 *valp = val;
1157 } else {
1158 unsigned int val = *valp;
1159 *lvalp = (unsigned long) val;
1160 }
1161
1162 return 0;
1163}
1164
Eric Biggers319e0a22018-02-06 15:41:49 -08001165static int proc_dopipe_max_size(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001166 void *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001167{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001168 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08001169 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001170}
1171
Kees Cook54b50192012-07-30 14:39:18 -07001172static void validate_coredump_safety(void)
1173{
Alex Kelly046d6622012-10-04 17:15:23 -07001174#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08001175 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07001176 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08001177 printk(KERN_WARNING
1178"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
1179"Pipe handler or fully qualified core dump path required.\n"
1180"Set kernel.core_pattern before fs.suid_dumpable.\n"
1181 );
Kees Cook54b50192012-07-30 14:39:18 -07001182 }
Alex Kelly046d6622012-10-04 17:15:23 -07001183#endif
Kees Cook54b50192012-07-30 14:39:18 -07001184}
1185
1186static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001187 void *buffer, size_t *lenp, loff_t *ppos)
Kees Cook54b50192012-07-30 14:39:18 -07001188{
1189 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1190 if (!error)
1191 validate_coredump_safety();
1192 return error;
1193}
1194
Alex Kelly046d6622012-10-04 17:15:23 -07001195#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07001196static int proc_dostring_coredump(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001197 void *buffer, size_t *lenp, loff_t *ppos)
Kees Cook54b50192012-07-30 14:39:18 -07001198{
1199 int error = proc_dostring(table, write, buffer, lenp, ppos);
1200 if (!error)
1201 validate_coredump_safety();
1202 return error;
1203}
Alex Kelly046d6622012-10-04 17:15:23 -07001204#endif
Kees Cook54b50192012-07-30 14:39:18 -07001205
Dmitry Safonoveaee4172020-03-02 17:51:34 +00001206#ifdef CONFIG_MAGIC_SYSRQ
1207static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001208 void *buffer, size_t *lenp, loff_t *ppos)
Dmitry Safonoveaee4172020-03-02 17:51:34 +00001209{
1210 int tmp, ret;
1211
1212 tmp = sysrq_mask();
1213
1214 ret = __do_proc_dointvec(&tmp, table, write, buffer,
1215 lenp, ppos, NULL, NULL);
1216 if (ret || !write)
1217 return ret;
1218
1219 if (write)
1220 sysrq_toggle_support(tmp);
1221
1222 return 0;
1223}
1224#endif
1225
Christoph Hellwig32927392020-04-24 08:43:38 +02001226static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
1227 int write, void *buffer, size_t *lenp, loff_t *ppos,
1228 unsigned long convmul, unsigned long convdiv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229{
Amerigo Wang00b7c332010-05-05 00:26:45 +00001230 unsigned long *i, *min, *max;
1231 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001232 size_t left;
Christoph Hellwig32927392020-04-24 08:43:38 +02001233 char *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001234
1235 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 *lenp = 0;
1237 return 0;
1238 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00001239
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001240 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 min = (unsigned long *) table->extra1;
1242 max = (unsigned long *) table->extra2;
1243 vleft = table->maxlen / sizeof(unsigned long);
1244 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001245
1246 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07001247 if (proc_first_pos_non_zero_ignore(ppos, table))
1248 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07001249
Amerigo Wang00b7c332010-05-05 00:26:45 +00001250 if (left > PAGE_SIZE - 1)
1251 left = PAGE_SIZE - 1;
Christoph Hellwig32927392020-04-24 08:43:38 +02001252 p = buffer;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001253 }
1254
Eric Dumazet27b3d802010-10-07 12:59:29 -07001255 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001256 unsigned long val;
1257
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001259 bool neg;
1260
Al Viro70f6cbb2015-12-24 00:13:10 -05001261 left -= proc_skip_spaces(&p);
Cheng Lin09be1782019-01-03 15:26:13 -08001262 if (!left)
1263 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001264
Al Viro70f6cbb2015-12-24 00:13:10 -05001265 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00001266 proc_wspace_sep,
1267 sizeof(proc_wspace_sep), NULL);
1268 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 break;
1270 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08001272 val = convmul * val / convdiv;
Christian Braunere260ad02019-05-14 15:44:55 -07001273 if ((min && val < *min) || (max && val > *max)) {
1274 err = -EINVAL;
1275 break;
1276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 *i = val;
1278 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001279 val = convdiv * (*i) / convmul;
Christoph Hellwig32927392020-04-24 08:43:38 +02001280 if (!first)
1281 proc_put_char(&buffer, &left, '\t');
1282 proc_put_long(&buffer, &left, val, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 }
1284 }
1285
Amerigo Wang00b7c332010-05-05 00:26:45 +00001286 if (!write && !first && left && !err)
Christoph Hellwig32927392020-04-24 08:43:38 +02001287 proc_put_char(&buffer, &left, '\n');
Amerigo Wang00b7c332010-05-05 00:26:45 +00001288 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05001289 left -= proc_skip_spaces(&p);
Christoph Hellwig32927392020-04-24 08:43:38 +02001290 if (write && first)
1291 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07001293out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001295 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296}
1297
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001298static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001299 void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1300 unsigned long convdiv)
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001301{
1302 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001303 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001304}
1305
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306/**
1307 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1308 * @table: the sysctl table
1309 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 * @buffer: the user buffer
1311 * @lenp: the size of the user buffer
1312 * @ppos: file position
1313 *
1314 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1315 * values from/to the user buffer, treated as an ASCII string.
1316 *
1317 * This routine will ensure the values are within the range specified by
1318 * table->extra1 (min) and table->extra2 (max).
1319 *
1320 * Returns 0 on success.
1321 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001322int proc_doulongvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001323 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001325 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326}
1327
1328/**
1329 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1330 * @table: the sysctl table
1331 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 * @buffer: the user buffer
1333 * @lenp: the size of the user buffer
1334 * @ppos: file position
1335 *
1336 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1337 * values from/to the user buffer, treated as an ASCII string. The values
1338 * are treated as milliseconds, and converted to jiffies when they are stored.
1339 *
1340 * This routine will ensure the values are within the range specified by
1341 * table->extra1 (min) and table->extra2 (max).
1342 *
1343 * Returns 0 on success.
1344 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001345int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001346 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001348 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 lenp, ppos, HZ, 1000l);
1350}
1351
1352
Amerigo Wang00b7c332010-05-05 00:26:45 +00001353static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 int *valp,
1355 int write, void *data)
1356{
1357 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07001358 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08001359 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1361 } else {
1362 int val = *valp;
1363 unsigned long lval;
1364 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001365 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07001366 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001368 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 lval = (unsigned long)val;
1370 }
1371 *lvalp = lval / HZ;
1372 }
1373 return 0;
1374}
1375
Amerigo Wang00b7c332010-05-05 00:26:45 +00001376static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 int *valp,
1378 int write, void *data)
1379{
1380 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08001381 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1382 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1384 } else {
1385 int val = *valp;
1386 unsigned long lval;
1387 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001388 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07001389 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001391 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 lval = (unsigned long)val;
1393 }
1394 *lvalp = jiffies_to_clock_t(lval);
1395 }
1396 return 0;
1397}
1398
Amerigo Wang00b7c332010-05-05 00:26:45 +00001399static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 int *valp,
1401 int write, void *data)
1402{
1403 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02001404 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1405
1406 if (jif > INT_MAX)
1407 return 1;
1408 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 } else {
1410 int val = *valp;
1411 unsigned long lval;
1412 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001413 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07001414 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001416 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 lval = (unsigned long)val;
1418 }
1419 *lvalp = jiffies_to_msecs(lval);
1420 }
1421 return 0;
1422}
1423
1424/**
1425 * proc_dointvec_jiffies - read a vector of integers as seconds
1426 * @table: the sysctl table
1427 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 * @buffer: the user buffer
1429 * @lenp: the size of the user buffer
1430 * @ppos: file position
1431 *
1432 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1433 * values from/to the user buffer, treated as an ASCII string.
1434 * The values read are assumed to be in seconds, and are converted into
1435 * jiffies.
1436 *
1437 * Returns 0 on success.
1438 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001439int proc_dointvec_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001440 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001442 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 do_proc_dointvec_jiffies_conv,NULL);
1444}
1445
1446/**
1447 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1448 * @table: the sysctl table
1449 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 * @buffer: the user buffer
1451 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08001452 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 *
1454 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1455 * values from/to the user buffer, treated as an ASCII string.
1456 * The values read are assumed to be in 1/USER_HZ seconds, and
1457 * are converted into jiffies.
1458 *
1459 * Returns 0 on success.
1460 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001461int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001462 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001464 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 do_proc_dointvec_userhz_jiffies_conv,NULL);
1466}
1467
1468/**
1469 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1470 * @table: the sysctl table
1471 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 * @buffer: the user buffer
1473 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07001474 * @ppos: file position
1475 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 *
1477 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1478 * values from/to the user buffer, treated as an ASCII string.
1479 * The values read are assumed to be in 1/1000 seconds, and
1480 * are converted into jiffies.
1481 *
1482 * Returns 0 on success.
1483 */
Christoph Hellwig32927392020-04-24 08:43:38 +02001484int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
1485 size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001487 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 do_proc_dointvec_ms_jiffies_conv, NULL);
1489}
1490
Christoph Hellwig32927392020-04-24 08:43:38 +02001491static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
1492 size_t *lenp, loff_t *ppos)
Cedric Le Goater9ec52092006-10-02 02:19:00 -07001493{
1494 struct pid *new_pid;
1495 pid_t tmp;
1496 int r;
1497
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08001498 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07001499
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001500 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07001501 lenp, ppos, NULL, NULL);
1502 if (r || !write)
1503 return r;
1504
1505 new_pid = find_get_pid(tmp);
1506 if (!new_pid)
1507 return -ESRCH;
1508
1509 put_pid(xchg(&cad_pid, new_pid));
1510 return 0;
1511}
1512
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001513/**
1514 * proc_do_large_bitmap - read/write from/to a large bitmap
1515 * @table: the sysctl table
1516 * @write: %TRUE if this is a write to the sysctl file
1517 * @buffer: the user buffer
1518 * @lenp: the size of the user buffer
1519 * @ppos: file position
1520 *
1521 * The bitmap is stored at table->data and the bitmap length (in bits)
1522 * in table->maxlen.
1523 *
1524 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1525 * large bitmaps may be represented in a compact manner. Writing into
1526 * the file will clear the bitmap then update it with the given input.
1527 *
1528 * Returns 0 on success.
1529 */
1530int proc_do_large_bitmap(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001531 void *buffer, size_t *lenp, loff_t *ppos)
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001532{
1533 int err = 0;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001534 size_t left = *lenp;
1535 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07001536 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001537 unsigned long *tmp_bitmap = NULL;
1538 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1539
WANG Cong122ff242014-05-12 16:04:53 -07001540 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001541 *lenp = 0;
1542 return 0;
1543 }
1544
1545 if (write) {
Christoph Hellwig32927392020-04-24 08:43:38 +02001546 char *p = buffer;
Eric Sandeen3116ad32019-05-14 15:45:13 -07001547 size_t skipped = 0;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001548
Eric Sandeen3116ad32019-05-14 15:45:13 -07001549 if (left > PAGE_SIZE - 1) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001550 left = PAGE_SIZE - 1;
Eric Sandeen3116ad32019-05-14 15:45:13 -07001551 /* How much of the buffer we'll skip this pass */
1552 skipped = *lenp - left;
1553 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001554
Andy Shevchenko475dae32019-05-14 15:44:52 -07001555 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
Christoph Hellwig32927392020-04-24 08:43:38 +02001556 if (!tmp_bitmap)
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001557 return -ENOMEM;
Al Viro70f6cbb2015-12-24 00:13:10 -05001558 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001559 while (!err && left) {
1560 unsigned long val_a, val_b;
1561 bool neg;
Eric Sandeen3116ad32019-05-14 15:45:13 -07001562 size_t saved_left;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001563
Eric Sandeen3116ad32019-05-14 15:45:13 -07001564 /* In case we stop parsing mid-number, we can reset */
1565 saved_left = left;
Al Viro70f6cbb2015-12-24 00:13:10 -05001566 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001567 sizeof(tr_a), &c);
Eric Sandeen3116ad32019-05-14 15:45:13 -07001568 /*
1569 * If we consumed the entirety of a truncated buffer or
1570 * only one char is left (may be a "-"), then stop here,
1571 * reset, & come back for more.
1572 */
1573 if ((left <= 1) && skipped) {
1574 left = saved_left;
1575 break;
1576 }
1577
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001578 if (err)
1579 break;
1580 if (val_a >= bitmap_len || neg) {
1581 err = -EINVAL;
1582 break;
1583 }
1584
1585 val_b = val_a;
1586 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05001587 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001588 left--;
1589 }
1590
1591 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05001592 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001593 &neg, tr_b, sizeof(tr_b),
1594 &c);
Eric Sandeen3116ad32019-05-14 15:45:13 -07001595 /*
1596 * If we consumed all of a truncated buffer or
1597 * then stop here, reset, & come back for more.
1598 */
1599 if (!left && skipped) {
1600 left = saved_left;
1601 break;
1602 }
1603
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001604 if (err)
1605 break;
1606 if (val_b >= bitmap_len || neg ||
1607 val_a > val_b) {
1608 err = -EINVAL;
1609 break;
1610 }
1611 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05001612 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001613 left--;
1614 }
1615 }
1616
Akinobu Mita5a04cca2012-03-28 14:42:50 -07001617 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Al Viro70f6cbb2015-12-24 00:13:10 -05001618 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001619 }
Eric Sandeen3116ad32019-05-14 15:45:13 -07001620 left += skipped;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001621 } else {
1622 unsigned long bit_a, bit_b = 0;
Jiapeng Chong9a52c5f2021-06-30 18:54:53 -07001623 bool first = 1;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001624
1625 while (left) {
1626 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1627 if (bit_a >= bitmap_len)
1628 break;
1629 bit_b = find_next_zero_bit(bitmap, bitmap_len,
1630 bit_a + 1) - 1;
1631
Christoph Hellwig32927392020-04-24 08:43:38 +02001632 if (!first)
1633 proc_put_char(&buffer, &left, ',');
1634 proc_put_long(&buffer, &left, bit_a, false);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001635 if (bit_a != bit_b) {
Christoph Hellwig32927392020-04-24 08:43:38 +02001636 proc_put_char(&buffer, &left, '-');
1637 proc_put_long(&buffer, &left, bit_b, false);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001638 }
1639
1640 first = 0; bit_b++;
1641 }
Christoph Hellwig32927392020-04-24 08:43:38 +02001642 proc_put_char(&buffer, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001643 }
1644
1645 if (!err) {
1646 if (write) {
1647 if (*ppos)
1648 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1649 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07001650 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001651 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001652 *lenp -= left;
1653 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001654 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08001655
Andy Shevchenko475dae32019-05-14 15:44:52 -07001656 bitmap_free(tmp_bitmap);
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08001657 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001658}
1659
Jovi Zhang55610502011-01-12 17:00:45 -08001660#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001662int proc_dostring(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001663 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664{
1665 return -ENOSYS;
1666}
1667
Jia Hea2071572021-08-03 12:59:36 +02001668int proc_dobool(struct ctl_table *table, int write,
1669 void *buffer, size_t *lenp, loff_t *ppos)
1670{
1671 return -ENOSYS;
1672}
1673
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001674int proc_dointvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001675 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676{
1677 return -ENOSYS;
1678}
1679
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07001680int proc_douintvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001681 void *buffer, size_t *lenp, loff_t *ppos)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07001682{
1683 return -ENOSYS;
1684}
1685
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001686int proc_dointvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001687 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688{
1689 return -ENOSYS;
1690}
1691
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001692int proc_douintvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001693 void *buffer, size_t *lenp, loff_t *ppos)
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001694{
1695 return -ENOSYS;
1696}
1697
Eric Dumazetcb944412021-03-25 11:08:13 -07001698int proc_dou8vec_minmax(struct ctl_table *table, int write,
1699 void *buffer, size_t *lenp, loff_t *ppos)
1700{
1701 return -ENOSYS;
1702}
1703
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001704int proc_dointvec_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001705 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706{
1707 return -ENOSYS;
1708}
1709
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001710int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001711 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712{
1713 return -ENOSYS;
1714}
1715
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001716int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001717 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718{
1719 return -ENOSYS;
1720}
1721
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001722int proc_doulongvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001723 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724{
1725 return -ENOSYS;
1726}
1727
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001728int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001729 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730{
Christoph Hellwig32927392020-04-24 08:43:38 +02001731 return -ENOSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
1733
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04001734int proc_do_large_bitmap(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001735 void *buffer, size_t *lenp, loff_t *ppos)
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04001736{
1737 return -ENOSYS;
1738}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
Jovi Zhang55610502011-01-12 17:00:45 -08001740#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001742#if defined(CONFIG_SYSCTL)
1743int proc_do_static_key(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001744 void *buffer, size_t *lenp, loff_t *ppos)
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001745{
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001746 struct static_key *key = (struct static_key *)table->data;
1747 static DEFINE_MUTEX(static_key_mutex);
1748 int val, ret;
1749 struct ctl_table tmp = {
1750 .data = &val,
1751 .maxlen = sizeof(val),
1752 .mode = table->mode,
Matteo Croceeec48442019-07-18 15:58:50 -07001753 .extra1 = SYSCTL_ZERO,
1754 .extra2 = SYSCTL_ONE,
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001755 };
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001756
1757 if (write && !capable(CAP_SYS_ADMIN))
1758 return -EPERM;
1759
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001760 mutex_lock(&static_key_mutex);
1761 val = static_key_enabled(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001762 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1763 if (write && !ret) {
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001764 if (val)
1765 static_key_enable(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001766 else
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001767 static_key_disable(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001768 }
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001769 mutex_unlock(&static_key_mutex);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001770 return ret;
1771}
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02001772
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773static struct ctl_table kern_table[] = {
1774 {
1775 .procname = "sched_child_runs_first",
1776 .data = &sysctl_sched_child_runs_first,
1777 .maxlen = sizeof(unsigned int),
1778 .mode = 0644,
1779 .proc_handler = proc_dointvec,
1780 },
Peter Zijlstra1d1c2502021-03-24 19:47:43 +01001781#ifdef CONFIG_SCHEDSTATS
1782 {
1783 .procname = "sched_schedstats",
1784 .data = NULL,
1785 .maxlen = sizeof(unsigned int),
1786 .mode = 0644,
1787 .proc_handler = sysctl_schedstats,
1788 .extra1 = SYSCTL_ZERO,
1789 .extra2 = SYSCTL_ONE,
1790 },
1791#endif /* CONFIG_SCHEDSTATS */
Peter Zijlstra0cd7c742021-05-10 14:01:00 +02001792#ifdef CONFIG_TASK_DELAY_ACCT
1793 {
1794 .procname = "task_delayacct",
1795 .data = NULL,
1796 .maxlen = sizeof(unsigned int),
1797 .mode = 0644,
1798 .proc_handler = sysctl_delayacct,
1799 .extra1 = SYSCTL_ZERO,
1800 .extra2 = SYSCTL_ONE,
1801 },
1802#endif /* CONFIG_TASK_DELAY_ACCT */
Mel Gormanb7cc6ec2021-03-24 13:39:16 +00001803#ifdef CONFIG_NUMA_BALANCING
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 {
1805 .procname = "numa_balancing",
1806 .data = NULL, /* filled in by handler */
1807 .maxlen = sizeof(unsigned int),
1808 .mode = 0644,
1809 .proc_handler = sysctl_numa_balancing,
1810 .extra1 = SYSCTL_ZERO,
1811 .extra2 = SYSCTL_ONE,
1812 },
1813#endif /* CONFIG_NUMA_BALANCING */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 {
1815 .procname = "sched_rt_period_us",
1816 .data = &sysctl_sched_rt_period,
1817 .maxlen = sizeof(unsigned int),
1818 .mode = 0644,
1819 .proc_handler = sched_rt_handler,
1820 },
1821 {
1822 .procname = "sched_rt_runtime_us",
1823 .data = &sysctl_sched_rt_runtime,
1824 .maxlen = sizeof(int),
1825 .mode = 0644,
1826 .proc_handler = sched_rt_handler,
1827 },
1828 {
Peter Zijlstrab4098bf2019-07-26 16:54:10 +02001829 .procname = "sched_deadline_period_max_us",
1830 .data = &sysctl_sched_dl_period_max,
1831 .maxlen = sizeof(unsigned int),
1832 .mode = 0644,
1833 .proc_handler = proc_dointvec,
1834 },
1835 {
1836 .procname = "sched_deadline_period_min_us",
1837 .data = &sysctl_sched_dl_period_min,
1838 .maxlen = sizeof(unsigned int),
1839 .mode = 0644,
1840 .proc_handler = proc_dointvec,
1841 },
1842 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 .procname = "sched_rr_timeslice_ms",
1844 .data = &sysctl_sched_rr_timeslice,
1845 .maxlen = sizeof(int),
1846 .mode = 0644,
1847 .proc_handler = sched_rr_handler,
1848 },
1849#ifdef CONFIG_UCLAMP_TASK
1850 {
1851 .procname = "sched_util_clamp_min",
1852 .data = &sysctl_sched_uclamp_util_min,
1853 .maxlen = sizeof(unsigned int),
1854 .mode = 0644,
1855 .proc_handler = sysctl_sched_uclamp_handler,
1856 },
1857 {
1858 .procname = "sched_util_clamp_max",
1859 .data = &sysctl_sched_uclamp_util_max,
1860 .maxlen = sizeof(unsigned int),
1861 .mode = 0644,
1862 .proc_handler = sysctl_sched_uclamp_handler,
1863 },
Qais Yousef13685c42020-07-16 12:03:45 +01001864 {
1865 .procname = "sched_util_clamp_min_rt_default",
1866 .data = &sysctl_sched_uclamp_util_min_rt_default,
1867 .maxlen = sizeof(unsigned int),
1868 .mode = 0644,
1869 .proc_handler = sysctl_sched_uclamp_handler,
1870 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871#endif
1872#ifdef CONFIG_SCHED_AUTOGROUP
1873 {
1874 .procname = "sched_autogroup_enabled",
1875 .data = &sysctl_sched_autogroup_enabled,
1876 .maxlen = sizeof(unsigned int),
1877 .mode = 0644,
1878 .proc_handler = proc_dointvec_minmax,
1879 .extra1 = SYSCTL_ZERO,
1880 .extra2 = SYSCTL_ONE,
1881 },
1882#endif
1883#ifdef CONFIG_CFS_BANDWIDTH
1884 {
1885 .procname = "sched_cfs_bandwidth_slice_us",
1886 .data = &sysctl_sched_cfs_bandwidth_slice,
1887 .maxlen = sizeof(unsigned int),
1888 .mode = 0644,
1889 .proc_handler = proc_dointvec_minmax,
1890 .extra1 = SYSCTL_ONE,
1891 },
1892#endif
1893#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
1894 {
1895 .procname = "sched_energy_aware",
1896 .data = &sysctl_sched_energy_aware,
1897 .maxlen = sizeof(unsigned int),
1898 .mode = 0644,
1899 .proc_handler = sched_energy_aware_handler,
1900 .extra1 = SYSCTL_ZERO,
1901 .extra2 = SYSCTL_ONE,
1902 },
1903#endif
1904#ifdef CONFIG_PROVE_LOCKING
1905 {
1906 .procname = "prove_locking",
1907 .data = &prove_locking,
1908 .maxlen = sizeof(int),
1909 .mode = 0644,
1910 .proc_handler = proc_dointvec,
1911 },
1912#endif
1913#ifdef CONFIG_LOCK_STAT
1914 {
1915 .procname = "lock_stat",
1916 .data = &lock_stat,
1917 .maxlen = sizeof(int),
1918 .mode = 0644,
1919 .proc_handler = proc_dointvec,
1920 },
1921#endif
1922 {
1923 .procname = "panic",
1924 .data = &panic_timeout,
1925 .maxlen = sizeof(int),
1926 .mode = 0644,
1927 .proc_handler = proc_dointvec,
1928 },
1929#ifdef CONFIG_COREDUMP
1930 {
1931 .procname = "core_uses_pid",
1932 .data = &core_uses_pid,
1933 .maxlen = sizeof(int),
1934 .mode = 0644,
1935 .proc_handler = proc_dointvec,
1936 },
1937 {
1938 .procname = "core_pattern",
1939 .data = core_pattern,
1940 .maxlen = CORENAME_MAX_SIZE,
1941 .mode = 0644,
1942 .proc_handler = proc_dostring_coredump,
1943 },
1944 {
1945 .procname = "core_pipe_limit",
1946 .data = &core_pipe_limit,
1947 .maxlen = sizeof(unsigned int),
1948 .mode = 0644,
1949 .proc_handler = proc_dointvec,
1950 },
1951#endif
1952#ifdef CONFIG_PROC_SYSCTL
1953 {
1954 .procname = "tainted",
1955 .maxlen = sizeof(long),
1956 .mode = 0644,
1957 .proc_handler = proc_taint,
1958 },
1959 {
1960 .procname = "sysctl_writes_strict",
1961 .data = &sysctl_writes_strict,
1962 .maxlen = sizeof(int),
1963 .mode = 0644,
1964 .proc_handler = proc_dointvec_minmax,
1965 .extra1 = &neg_one,
1966 .extra2 = SYSCTL_ONE,
1967 },
1968#endif
1969#ifdef CONFIG_LATENCYTOP
1970 {
1971 .procname = "latencytop",
1972 .data = &latencytop_enabled,
1973 .maxlen = sizeof(int),
1974 .mode = 0644,
1975 .proc_handler = sysctl_latencytop,
1976 },
1977#endif
1978#ifdef CONFIG_BLK_DEV_INITRD
1979 {
1980 .procname = "real-root-dev",
1981 .data = &real_root_dev,
1982 .maxlen = sizeof(int),
1983 .mode = 0644,
1984 .proc_handler = proc_dointvec,
1985 },
1986#endif
1987 {
1988 .procname = "print-fatal-signals",
1989 .data = &print_fatal_signals,
1990 .maxlen = sizeof(int),
1991 .mode = 0644,
1992 .proc_handler = proc_dointvec,
1993 },
1994#ifdef CONFIG_SPARC
1995 {
1996 .procname = "reboot-cmd",
1997 .data = reboot_command,
1998 .maxlen = 256,
1999 .mode = 0644,
2000 .proc_handler = proc_dostring,
2001 },
2002 {
2003 .procname = "stop-a",
2004 .data = &stop_a_enabled,
2005 .maxlen = sizeof (int),
2006 .mode = 0644,
2007 .proc_handler = proc_dointvec,
2008 },
2009 {
2010 .procname = "scons-poweroff",
2011 .data = &scons_pwroff,
2012 .maxlen = sizeof (int),
2013 .mode = 0644,
2014 .proc_handler = proc_dointvec,
2015 },
2016#endif
2017#ifdef CONFIG_SPARC64
2018 {
2019 .procname = "tsb-ratio",
2020 .data = &sysctl_tsb_ratio,
2021 .maxlen = sizeof (int),
2022 .mode = 0644,
2023 .proc_handler = proc_dointvec,
2024 },
2025#endif
2026#ifdef CONFIG_PARISC
2027 {
2028 .procname = "soft-power",
2029 .data = &pwrsw_enabled,
2030 .maxlen = sizeof (int),
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02002031 .mode = 0644,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 .proc_handler = proc_dointvec,
2033 },
2034#endif
2035#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
2036 {
2037 .procname = "unaligned-trap",
2038 .data = &unaligned_enabled,
2039 .maxlen = sizeof (int),
2040 .mode = 0644,
2041 .proc_handler = proc_dointvec,
2042 },
2043#endif
2044 {
2045 .procname = "ctrl-alt-del",
2046 .data = &C_A_D,
2047 .maxlen = sizeof(int),
2048 .mode = 0644,
2049 .proc_handler = proc_dointvec,
2050 },
2051#ifdef CONFIG_FUNCTION_TRACER
2052 {
2053 .procname = "ftrace_enabled",
2054 .data = &ftrace_enabled,
2055 .maxlen = sizeof(int),
2056 .mode = 0644,
2057 .proc_handler = ftrace_enable_sysctl,
2058 },
2059#endif
2060#ifdef CONFIG_STACK_TRACER
2061 {
2062 .procname = "stack_tracer_enabled",
2063 .data = &stack_tracer_enabled,
2064 .maxlen = sizeof(int),
2065 .mode = 0644,
2066 .proc_handler = stack_trace_sysctl,
2067 },
2068#endif
2069#ifdef CONFIG_TRACING
2070 {
2071 .procname = "ftrace_dump_on_oops",
2072 .data = &ftrace_dump_on_oops,
2073 .maxlen = sizeof(int),
2074 .mode = 0644,
2075 .proc_handler = proc_dointvec,
2076 },
2077 {
2078 .procname = "traceoff_on_warning",
2079 .data = &__disable_trace_on_warning,
2080 .maxlen = sizeof(__disable_trace_on_warning),
2081 .mode = 0644,
2082 .proc_handler = proc_dointvec,
2083 },
2084 {
2085 .procname = "tracepoint_printk",
2086 .data = &tracepoint_printk,
2087 .maxlen = sizeof(tracepoint_printk),
2088 .mode = 0644,
2089 .proc_handler = tracepoint_printk_sysctl,
2090 },
2091#endif
2092#ifdef CONFIG_KEXEC_CORE
2093 {
2094 .procname = "kexec_load_disabled",
2095 .data = &kexec_load_disabled,
2096 .maxlen = sizeof(int),
2097 .mode = 0644,
2098 /* only handle a transition from default "0" to "1" */
2099 .proc_handler = proc_dointvec_minmax,
2100 .extra1 = SYSCTL_ONE,
2101 .extra2 = SYSCTL_ONE,
2102 },
2103#endif
2104#ifdef CONFIG_MODULES
2105 {
2106 .procname = "modprobe",
2107 .data = &modprobe_path,
2108 .maxlen = KMOD_PATH_LEN,
2109 .mode = 0644,
2110 .proc_handler = proc_dostring,
2111 },
2112 {
2113 .procname = "modules_disabled",
2114 .data = &modules_disabled,
2115 .maxlen = sizeof(int),
2116 .mode = 0644,
2117 /* only handle a transition from default "0" to "1" */
2118 .proc_handler = proc_dointvec_minmax,
2119 .extra1 = SYSCTL_ONE,
2120 .extra2 = SYSCTL_ONE,
2121 },
2122#endif
2123#ifdef CONFIG_UEVENT_HELPER
2124 {
2125 .procname = "hotplug",
2126 .data = &uevent_helper,
2127 .maxlen = UEVENT_HELPER_PATH_LEN,
2128 .mode = 0644,
2129 .proc_handler = proc_dostring,
2130 },
2131#endif
2132#ifdef CONFIG_CHR_DEV_SG
2133 {
2134 .procname = "sg-big-buff",
2135 .data = &sg_big_buff,
2136 .maxlen = sizeof (int),
2137 .mode = 0444,
2138 .proc_handler = proc_dointvec,
2139 },
2140#endif
2141#ifdef CONFIG_BSD_PROCESS_ACCT
2142 {
2143 .procname = "acct",
2144 .data = &acct_parm,
2145 .maxlen = 3*sizeof(int),
2146 .mode = 0644,
2147 .proc_handler = proc_dointvec,
2148 },
2149#endif
2150#ifdef CONFIG_MAGIC_SYSRQ
2151 {
2152 .procname = "sysrq",
2153 .data = NULL,
2154 .maxlen = sizeof (int),
2155 .mode = 0644,
2156 .proc_handler = sysrq_sysctl_handler,
2157 },
2158#endif
2159#ifdef CONFIG_PROC_SYSCTL
2160 {
2161 .procname = "cad_pid",
2162 .data = NULL,
2163 .maxlen = sizeof (int),
2164 .mode = 0600,
2165 .proc_handler = proc_do_cad_pid,
2166 },
2167#endif
2168 {
2169 .procname = "threads-max",
2170 .data = NULL,
2171 .maxlen = sizeof(int),
2172 .mode = 0644,
2173 .proc_handler = sysctl_max_threads,
2174 },
2175 {
2176 .procname = "random",
2177 .mode = 0555,
2178 .child = random_table,
2179 },
2180 {
2181 .procname = "usermodehelper",
2182 .mode = 0555,
2183 .child = usermodehelper_table,
2184 },
2185#ifdef CONFIG_FW_LOADER_USER_HELPER
2186 {
2187 .procname = "firmware_config",
2188 .mode = 0555,
2189 .child = firmware_config_table,
2190 },
2191#endif
2192 {
2193 .procname = "overflowuid",
2194 .data = &overflowuid,
2195 .maxlen = sizeof(int),
2196 .mode = 0644,
2197 .proc_handler = proc_dointvec_minmax,
2198 .extra1 = &minolduid,
2199 .extra2 = &maxolduid,
2200 },
2201 {
2202 .procname = "overflowgid",
2203 .data = &overflowgid,
2204 .maxlen = sizeof(int),
2205 .mode = 0644,
2206 .proc_handler = proc_dointvec_minmax,
2207 .extra1 = &minolduid,
2208 .extra2 = &maxolduid,
2209 },
2210#ifdef CONFIG_S390
2211 {
2212 .procname = "userprocess_debug",
2213 .data = &show_unhandled_signals,
2214 .maxlen = sizeof(int),
2215 .mode = 0644,
2216 .proc_handler = proc_dointvec,
2217 },
2218#endif
Guilherme G. Piccoli60c958d2020-06-07 21:40:48 -07002219#ifdef CONFIG_SMP
2220 {
2221 .procname = "oops_all_cpu_backtrace",
2222 .data = &sysctl_oops_all_cpu_backtrace,
2223 .maxlen = sizeof(int),
2224 .mode = 0644,
2225 .proc_handler = proc_dointvec_minmax,
2226 .extra1 = SYSCTL_ZERO,
2227 .extra2 = SYSCTL_ONE,
2228 },
2229#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 {
2231 .procname = "pid_max",
2232 .data = &pid_max,
2233 .maxlen = sizeof (int),
2234 .mode = 0644,
2235 .proc_handler = proc_dointvec_minmax,
2236 .extra1 = &pid_max_min,
2237 .extra2 = &pid_max_max,
2238 },
2239 {
2240 .procname = "panic_on_oops",
2241 .data = &panic_on_oops,
2242 .maxlen = sizeof(int),
2243 .mode = 0644,
2244 .proc_handler = proc_dointvec,
2245 },
2246 {
2247 .procname = "panic_print",
2248 .data = &panic_print,
2249 .maxlen = sizeof(unsigned long),
2250 .mode = 0644,
2251 .proc_handler = proc_doulongvec_minmax,
2252 },
2253#if defined CONFIG_PRINTK
2254 {
2255 .procname = "printk",
2256 .data = &console_loglevel,
2257 .maxlen = 4*sizeof(int),
2258 .mode = 0644,
2259 .proc_handler = proc_dointvec,
2260 },
2261 {
2262 .procname = "printk_ratelimit",
2263 .data = &printk_ratelimit_state.interval,
2264 .maxlen = sizeof(int),
2265 .mode = 0644,
2266 .proc_handler = proc_dointvec_jiffies,
2267 },
2268 {
2269 .procname = "printk_ratelimit_burst",
2270 .data = &printk_ratelimit_state.burst,
2271 .maxlen = sizeof(int),
2272 .mode = 0644,
2273 .proc_handler = proc_dointvec,
2274 },
2275 {
2276 .procname = "printk_delay",
2277 .data = &printk_delay_msec,
2278 .maxlen = sizeof(int),
2279 .mode = 0644,
2280 .proc_handler = proc_dointvec_minmax,
2281 .extra1 = SYSCTL_ZERO,
2282 .extra2 = &ten_thousand,
2283 },
2284 {
2285 .procname = "printk_devkmsg",
2286 .data = devkmsg_log_str,
2287 .maxlen = DEVKMSG_STR_MAX_SIZE,
2288 .mode = 0644,
2289 .proc_handler = devkmsg_sysctl_set_loglvl,
2290 },
2291 {
2292 .procname = "dmesg_restrict",
2293 .data = &dmesg_restrict,
2294 .maxlen = sizeof(int),
2295 .mode = 0644,
2296 .proc_handler = proc_dointvec_minmax_sysadmin,
2297 .extra1 = SYSCTL_ZERO,
2298 .extra2 = SYSCTL_ONE,
2299 },
2300 {
2301 .procname = "kptr_restrict",
2302 .data = &kptr_restrict,
2303 .maxlen = sizeof(int),
2304 .mode = 0644,
2305 .proc_handler = proc_dointvec_minmax_sysadmin,
2306 .extra1 = SYSCTL_ZERO,
2307 .extra2 = &two,
2308 },
2309#endif
2310 {
2311 .procname = "ngroups_max",
2312 .data = &ngroups_max,
2313 .maxlen = sizeof (int),
2314 .mode = 0444,
2315 .proc_handler = proc_dointvec,
2316 },
2317 {
2318 .procname = "cap_last_cap",
2319 .data = (void *)&cap_last_cap,
2320 .maxlen = sizeof(int),
2321 .mode = 0444,
2322 .proc_handler = proc_dointvec,
2323 },
2324#if defined(CONFIG_LOCKUP_DETECTOR)
2325 {
2326 .procname = "watchdog",
2327 .data = &watchdog_user_enabled,
2328 .maxlen = sizeof(int),
2329 .mode = 0644,
2330 .proc_handler = proc_watchdog,
2331 .extra1 = SYSCTL_ZERO,
2332 .extra2 = SYSCTL_ONE,
2333 },
2334 {
2335 .procname = "watchdog_thresh",
2336 .data = &watchdog_thresh,
2337 .maxlen = sizeof(int),
2338 .mode = 0644,
2339 .proc_handler = proc_watchdog_thresh,
2340 .extra1 = SYSCTL_ZERO,
2341 .extra2 = &sixty,
2342 },
2343 {
2344 .procname = "nmi_watchdog",
2345 .data = &nmi_watchdog_user_enabled,
2346 .maxlen = sizeof(int),
2347 .mode = NMI_WATCHDOG_SYSCTL_PERM,
2348 .proc_handler = proc_nmi_watchdog,
2349 .extra1 = SYSCTL_ZERO,
2350 .extra2 = SYSCTL_ONE,
2351 },
2352 {
2353 .procname = "watchdog_cpumask",
2354 .data = &watchdog_cpumask_bits,
2355 .maxlen = NR_CPUS,
2356 .mode = 0644,
2357 .proc_handler = proc_watchdog_cpumask,
2358 },
2359#ifdef CONFIG_SOFTLOCKUP_DETECTOR
2360 {
2361 .procname = "soft_watchdog",
2362 .data = &soft_watchdog_user_enabled,
2363 .maxlen = sizeof(int),
2364 .mode = 0644,
2365 .proc_handler = proc_soft_watchdog,
2366 .extra1 = SYSCTL_ZERO,
2367 .extra2 = SYSCTL_ONE,
2368 },
2369 {
2370 .procname = "softlockup_panic",
2371 .data = &softlockup_panic,
2372 .maxlen = sizeof(int),
2373 .mode = 0644,
2374 .proc_handler = proc_dointvec_minmax,
2375 .extra1 = SYSCTL_ZERO,
2376 .extra2 = SYSCTL_ONE,
2377 },
2378#ifdef CONFIG_SMP
2379 {
2380 .procname = "softlockup_all_cpu_backtrace",
2381 .data = &sysctl_softlockup_all_cpu_backtrace,
2382 .maxlen = sizeof(int),
2383 .mode = 0644,
2384 .proc_handler = proc_dointvec_minmax,
2385 .extra1 = SYSCTL_ZERO,
2386 .extra2 = SYSCTL_ONE,
2387 },
2388#endif /* CONFIG_SMP */
2389#endif
2390#ifdef CONFIG_HARDLOCKUP_DETECTOR
2391 {
2392 .procname = "hardlockup_panic",
2393 .data = &hardlockup_panic,
2394 .maxlen = sizeof(int),
2395 .mode = 0644,
2396 .proc_handler = proc_dointvec_minmax,
2397 .extra1 = SYSCTL_ZERO,
2398 .extra2 = SYSCTL_ONE,
2399 },
2400#ifdef CONFIG_SMP
2401 {
2402 .procname = "hardlockup_all_cpu_backtrace",
2403 .data = &sysctl_hardlockup_all_cpu_backtrace,
2404 .maxlen = sizeof(int),
2405 .mode = 0644,
2406 .proc_handler = proc_dointvec_minmax,
2407 .extra1 = SYSCTL_ZERO,
2408 .extra2 = SYSCTL_ONE,
2409 },
2410#endif /* CONFIG_SMP */
2411#endif
2412#endif
2413
2414#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
2415 {
2416 .procname = "unknown_nmi_panic",
2417 .data = &unknown_nmi_panic,
2418 .maxlen = sizeof (int),
2419 .mode = 0644,
2420 .proc_handler = proc_dointvec,
2421 },
2422#endif
Xiaoming Nib6522fa2020-04-11 21:06:19 +08002423
2424#if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
2425 defined(CONFIG_DEBUG_STACKOVERFLOW)
2426 {
2427 .procname = "panic_on_stackoverflow",
2428 .data = &sysctl_panic_on_stackoverflow,
2429 .maxlen = sizeof(int),
2430 .mode = 0644,
2431 .proc_handler = proc_dointvec,
2432 },
2433#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434#if defined(CONFIG_X86)
2435 {
2436 .procname = "panic_on_unrecovered_nmi",
2437 .data = &panic_on_unrecovered_nmi,
2438 .maxlen = sizeof(int),
2439 .mode = 0644,
2440 .proc_handler = proc_dointvec,
2441 },
2442 {
2443 .procname = "panic_on_io_nmi",
2444 .data = &panic_on_io_nmi,
2445 .maxlen = sizeof(int),
2446 .mode = 0644,
2447 .proc_handler = proc_dointvec,
2448 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 {
2450 .procname = "bootloader_type",
2451 .data = &bootloader_type,
2452 .maxlen = sizeof (int),
2453 .mode = 0444,
2454 .proc_handler = proc_dointvec,
2455 },
2456 {
2457 .procname = "bootloader_version",
2458 .data = &bootloader_version,
2459 .maxlen = sizeof (int),
2460 .mode = 0444,
2461 .proc_handler = proc_dointvec,
2462 },
2463 {
2464 .procname = "io_delay_type",
2465 .data = &io_delay_type,
2466 .maxlen = sizeof(int),
2467 .mode = 0644,
2468 .proc_handler = proc_dointvec,
2469 },
2470#endif
2471#if defined(CONFIG_MMU)
2472 {
2473 .procname = "randomize_va_space",
2474 .data = &randomize_va_space,
2475 .maxlen = sizeof(int),
2476 .mode = 0644,
2477 .proc_handler = proc_dointvec,
2478 },
2479#endif
2480#if defined(CONFIG_S390) && defined(CONFIG_SMP)
2481 {
2482 .procname = "spin_retry",
2483 .data = &spin_retry,
2484 .maxlen = sizeof (int),
2485 .mode = 0644,
2486 .proc_handler = proc_dointvec,
2487 },
2488#endif
2489#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
2490 {
2491 .procname = "acpi_video_flags",
2492 .data = &acpi_realmode_flags,
2493 .maxlen = sizeof (unsigned long),
2494 .mode = 0644,
2495 .proc_handler = proc_doulongvec_minmax,
2496 },
2497#endif
2498#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
2499 {
2500 .procname = "ignore-unaligned-usertrap",
2501 .data = &no_unaligned_warning,
2502 .maxlen = sizeof (int),
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02002503 .mode = 0644,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 .proc_handler = proc_dointvec,
2505 },
2506#endif
2507#ifdef CONFIG_IA64
2508 {
2509 .procname = "unaligned-dump-stack",
2510 .data = &unaligned_dump_stack,
2511 .maxlen = sizeof (int),
2512 .mode = 0644,
2513 .proc_handler = proc_dointvec,
2514 },
2515#endif
2516#ifdef CONFIG_DETECT_HUNG_TASK
Guilherme G. Piccoli0ec9dc92020-06-07 21:40:45 -07002517#ifdef CONFIG_SMP
2518 {
2519 .procname = "hung_task_all_cpu_backtrace",
2520 .data = &sysctl_hung_task_all_cpu_backtrace,
2521 .maxlen = sizeof(int),
2522 .mode = 0644,
2523 .proc_handler = proc_dointvec_minmax,
2524 .extra1 = SYSCTL_ZERO,
2525 .extra2 = SYSCTL_ONE,
2526 },
2527#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 {
2529 .procname = "hung_task_panic",
2530 .data = &sysctl_hung_task_panic,
2531 .maxlen = sizeof(int),
2532 .mode = 0644,
2533 .proc_handler = proc_dointvec_minmax,
2534 .extra1 = SYSCTL_ZERO,
2535 .extra2 = SYSCTL_ONE,
2536 },
2537 {
2538 .procname = "hung_task_check_count",
2539 .data = &sysctl_hung_task_check_count,
2540 .maxlen = sizeof(int),
2541 .mode = 0644,
2542 .proc_handler = proc_dointvec_minmax,
2543 .extra1 = SYSCTL_ZERO,
2544 },
2545 {
2546 .procname = "hung_task_timeout_secs",
2547 .data = &sysctl_hung_task_timeout_secs,
2548 .maxlen = sizeof(unsigned long),
2549 .mode = 0644,
2550 .proc_handler = proc_dohung_task_timeout_secs,
2551 .extra2 = &hung_task_timeout_max,
2552 },
2553 {
2554 .procname = "hung_task_check_interval_secs",
2555 .data = &sysctl_hung_task_check_interval_secs,
2556 .maxlen = sizeof(unsigned long),
2557 .mode = 0644,
2558 .proc_handler = proc_dohung_task_timeout_secs,
2559 .extra2 = &hung_task_timeout_max,
2560 },
2561 {
2562 .procname = "hung_task_warnings",
2563 .data = &sysctl_hung_task_warnings,
2564 .maxlen = sizeof(int),
2565 .mode = 0644,
2566 .proc_handler = proc_dointvec_minmax,
2567 .extra1 = &neg_one,
2568 },
2569#endif
2570#ifdef CONFIG_RT_MUTEXES
2571 {
2572 .procname = "max_lock_depth",
2573 .data = &max_lock_depth,
2574 .maxlen = sizeof(int),
2575 .mode = 0644,
2576 .proc_handler = proc_dointvec,
2577 },
2578#endif
2579 {
2580 .procname = "poweroff_cmd",
2581 .data = &poweroff_cmd,
2582 .maxlen = POWEROFF_CMD_PATH_LEN,
2583 .mode = 0644,
2584 .proc_handler = proc_dostring,
2585 },
2586#ifdef CONFIG_KEYS
2587 {
2588 .procname = "keys",
2589 .mode = 0555,
2590 .child = key_sysctls,
2591 },
2592#endif
2593#ifdef CONFIG_PERF_EVENTS
2594 /*
2595 * User-space scripts rely on the existence of this file
2596 * as a feature check for perf_events being enabled.
2597 *
2598 * So it's an ABI, do not remove!
2599 */
2600 {
2601 .procname = "perf_event_paranoid",
2602 .data = &sysctl_perf_event_paranoid,
2603 .maxlen = sizeof(sysctl_perf_event_paranoid),
2604 .mode = 0644,
2605 .proc_handler = proc_dointvec,
2606 },
2607 {
2608 .procname = "perf_event_mlock_kb",
2609 .data = &sysctl_perf_event_mlock,
2610 .maxlen = sizeof(sysctl_perf_event_mlock),
2611 .mode = 0644,
2612 .proc_handler = proc_dointvec,
2613 },
2614 {
2615 .procname = "perf_event_max_sample_rate",
2616 .data = &sysctl_perf_event_sample_rate,
2617 .maxlen = sizeof(sysctl_perf_event_sample_rate),
2618 .mode = 0644,
2619 .proc_handler = perf_proc_update_handler,
2620 .extra1 = SYSCTL_ONE,
2621 },
2622 {
2623 .procname = "perf_cpu_time_max_percent",
2624 .data = &sysctl_perf_cpu_time_max_percent,
2625 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
2626 .mode = 0644,
2627 .proc_handler = perf_cpu_time_max_percent_handler,
2628 .extra1 = SYSCTL_ZERO,
2629 .extra2 = &one_hundred,
2630 },
2631 {
2632 .procname = "perf_event_max_stack",
2633 .data = &sysctl_perf_event_max_stack,
2634 .maxlen = sizeof(sysctl_perf_event_max_stack),
2635 .mode = 0644,
2636 .proc_handler = perf_event_max_stack_handler,
2637 .extra1 = SYSCTL_ZERO,
2638 .extra2 = &six_hundred_forty_kb,
2639 },
2640 {
2641 .procname = "perf_event_max_contexts_per_stack",
2642 .data = &sysctl_perf_event_max_contexts_per_stack,
2643 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
2644 .mode = 0644,
2645 .proc_handler = perf_event_max_stack_handler,
2646 .extra1 = SYSCTL_ZERO,
2647 .extra2 = &one_thousand,
2648 },
2649#endif
2650 {
2651 .procname = "panic_on_warn",
2652 .data = &panic_on_warn,
2653 .maxlen = sizeof(int),
2654 .mode = 0644,
2655 .proc_handler = proc_dointvec_minmax,
2656 .extra1 = SYSCTL_ZERO,
2657 .extra2 = SYSCTL_ONE,
2658 },
2659#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
2660 {
2661 .procname = "timer_migration",
2662 .data = &sysctl_timer_migration,
2663 .maxlen = sizeof(unsigned int),
2664 .mode = 0644,
2665 .proc_handler = timer_migration_handler,
2666 .extra1 = SYSCTL_ZERO,
2667 .extra2 = SYSCTL_ONE,
2668 },
2669#endif
2670#ifdef CONFIG_BPF_SYSCALL
2671 {
2672 .procname = "unprivileged_bpf_disabled",
2673 .data = &sysctl_unprivileged_bpf_disabled,
2674 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
2675 .mode = 0644,
Daniel Borkmann08389d82021-05-11 22:35:17 +02002676 .proc_handler = bpf_unpriv_handler,
2677 .extra1 = SYSCTL_ZERO,
2678 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 },
2680 {
2681 .procname = "bpf_stats_enabled",
2682 .data = &bpf_stats_enabled_key.key,
2683 .maxlen = sizeof(bpf_stats_enabled_key),
2684 .mode = 0644,
Song Liud46edd62020-04-30 00:15:04 -07002685 .proc_handler = bpf_stats_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 },
2687#endif
2688#if defined(CONFIG_TREE_RCU)
2689 {
2690 .procname = "panic_on_rcu_stall",
2691 .data = &sysctl_panic_on_rcu_stall,
2692 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
2693 .mode = 0644,
2694 .proc_handler = proc_dointvec_minmax,
2695 .extra1 = SYSCTL_ZERO,
2696 .extra2 = SYSCTL_ONE,
2697 },
2698#endif
chaodfe56402020-08-30 23:41:17 -07002699#if defined(CONFIG_TREE_RCU)
2700 {
2701 .procname = "max_rcu_stall_to_panic",
2702 .data = &sysctl_max_rcu_stall_to_panic,
2703 .maxlen = sizeof(sysctl_max_rcu_stall_to_panic),
2704 .mode = 0644,
2705 .proc_handler = proc_dointvec_minmax,
2706 .extra1 = SYSCTL_ONE,
2707 .extra2 = SYSCTL_INT_MAX,
2708 },
2709#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
2711 {
2712 .procname = "stack_erasing",
2713 .data = NULL,
2714 .maxlen = sizeof(int),
2715 .mode = 0600,
2716 .proc_handler = stack_erasing_sysctl,
2717 .extra1 = SYSCTL_ZERO,
2718 .extra2 = SYSCTL_ONE,
2719 },
2720#endif
2721 { }
2722};
2723
2724static struct ctl_table vm_table[] = {
2725 {
2726 .procname = "overcommit_memory",
2727 .data = &sysctl_overcommit_memory,
2728 .maxlen = sizeof(sysctl_overcommit_memory),
2729 .mode = 0644,
Feng Tang56f35472020-08-06 23:23:15 -07002730 .proc_handler = overcommit_policy_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 .extra1 = SYSCTL_ZERO,
2732 .extra2 = &two,
2733 },
2734 {
2735 .procname = "panic_on_oom",
2736 .data = &sysctl_panic_on_oom,
2737 .maxlen = sizeof(sysctl_panic_on_oom),
2738 .mode = 0644,
2739 .proc_handler = proc_dointvec_minmax,
2740 .extra1 = SYSCTL_ZERO,
2741 .extra2 = &two,
2742 },
2743 {
2744 .procname = "oom_kill_allocating_task",
2745 .data = &sysctl_oom_kill_allocating_task,
2746 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
2747 .mode = 0644,
2748 .proc_handler = proc_dointvec,
2749 },
2750 {
2751 .procname = "oom_dump_tasks",
2752 .data = &sysctl_oom_dump_tasks,
2753 .maxlen = sizeof(sysctl_oom_dump_tasks),
2754 .mode = 0644,
2755 .proc_handler = proc_dointvec,
2756 },
2757 {
2758 .procname = "overcommit_ratio",
2759 .data = &sysctl_overcommit_ratio,
2760 .maxlen = sizeof(sysctl_overcommit_ratio),
2761 .mode = 0644,
2762 .proc_handler = overcommit_ratio_handler,
2763 },
2764 {
2765 .procname = "overcommit_kbytes",
2766 .data = &sysctl_overcommit_kbytes,
2767 .maxlen = sizeof(sysctl_overcommit_kbytes),
2768 .mode = 0644,
2769 .proc_handler = overcommit_kbytes_handler,
2770 },
2771 {
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02002772 .procname = "page-cluster",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 .data = &page_cluster,
2774 .maxlen = sizeof(int),
2775 .mode = 0644,
2776 .proc_handler = proc_dointvec_minmax,
2777 .extra1 = SYSCTL_ZERO,
2778 },
2779 {
2780 .procname = "dirty_background_ratio",
2781 .data = &dirty_background_ratio,
2782 .maxlen = sizeof(dirty_background_ratio),
2783 .mode = 0644,
2784 .proc_handler = dirty_background_ratio_handler,
2785 .extra1 = SYSCTL_ZERO,
2786 .extra2 = &one_hundred,
2787 },
2788 {
2789 .procname = "dirty_background_bytes",
2790 .data = &dirty_background_bytes,
2791 .maxlen = sizeof(dirty_background_bytes),
2792 .mode = 0644,
2793 .proc_handler = dirty_background_bytes_handler,
2794 .extra1 = &one_ul,
2795 },
2796 {
2797 .procname = "dirty_ratio",
2798 .data = &vm_dirty_ratio,
2799 .maxlen = sizeof(vm_dirty_ratio),
2800 .mode = 0644,
2801 .proc_handler = dirty_ratio_handler,
2802 .extra1 = SYSCTL_ZERO,
2803 .extra2 = &one_hundred,
2804 },
2805 {
2806 .procname = "dirty_bytes",
2807 .data = &vm_dirty_bytes,
2808 .maxlen = sizeof(vm_dirty_bytes),
2809 .mode = 0644,
2810 .proc_handler = dirty_bytes_handler,
2811 .extra1 = &dirty_bytes_min,
2812 },
2813 {
2814 .procname = "dirty_writeback_centisecs",
2815 .data = &dirty_writeback_interval,
2816 .maxlen = sizeof(dirty_writeback_interval),
2817 .mode = 0644,
2818 .proc_handler = dirty_writeback_centisecs_handler,
2819 },
2820 {
2821 .procname = "dirty_expire_centisecs",
2822 .data = &dirty_expire_interval,
2823 .maxlen = sizeof(dirty_expire_interval),
2824 .mode = 0644,
2825 .proc_handler = proc_dointvec_minmax,
2826 .extra1 = SYSCTL_ZERO,
2827 },
2828 {
2829 .procname = "dirtytime_expire_seconds",
2830 .data = &dirtytime_expire_interval,
2831 .maxlen = sizeof(dirtytime_expire_interval),
2832 .mode = 0644,
2833 .proc_handler = dirtytime_interval_handler,
2834 .extra1 = SYSCTL_ZERO,
2835 },
2836 {
2837 .procname = "swappiness",
2838 .data = &vm_swappiness,
2839 .maxlen = sizeof(vm_swappiness),
2840 .mode = 0644,
2841 .proc_handler = proc_dointvec_minmax,
2842 .extra1 = SYSCTL_ZERO,
Johannes Weinerc8439662020-06-03 16:02:37 -07002843 .extra2 = &two_hundred,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 },
2845#ifdef CONFIG_HUGETLB_PAGE
2846 {
2847 .procname = "nr_hugepages",
2848 .data = NULL,
2849 .maxlen = sizeof(unsigned long),
2850 .mode = 0644,
2851 .proc_handler = hugetlb_sysctl_handler,
2852 },
2853#ifdef CONFIG_NUMA
2854 {
2855 .procname = "nr_hugepages_mempolicy",
2856 .data = NULL,
2857 .maxlen = sizeof(unsigned long),
2858 .mode = 0644,
2859 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
2860 },
2861 {
2862 .procname = "numa_stat",
2863 .data = &sysctl_vm_numa_stat,
2864 .maxlen = sizeof(int),
2865 .mode = 0644,
2866 .proc_handler = sysctl_vm_numa_stat_handler,
2867 .extra1 = SYSCTL_ZERO,
2868 .extra2 = SYSCTL_ONE,
2869 },
2870#endif
2871 {
2872 .procname = "hugetlb_shm_group",
2873 .data = &sysctl_hugetlb_shm_group,
2874 .maxlen = sizeof(gid_t),
2875 .mode = 0644,
2876 .proc_handler = proc_dointvec,
2877 },
2878 {
2879 .procname = "nr_overcommit_hugepages",
2880 .data = NULL,
2881 .maxlen = sizeof(unsigned long),
2882 .mode = 0644,
2883 .proc_handler = hugetlb_overcommit_handler,
2884 },
2885#endif
2886 {
2887 .procname = "lowmem_reserve_ratio",
2888 .data = &sysctl_lowmem_reserve_ratio,
2889 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
2890 .mode = 0644,
2891 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
2892 },
2893 {
2894 .procname = "drop_caches",
2895 .data = &sysctl_drop_caches,
2896 .maxlen = sizeof(int),
2897 .mode = 0200,
2898 .proc_handler = drop_caches_sysctl_handler,
2899 .extra1 = SYSCTL_ONE,
2900 .extra2 = &four,
2901 },
2902#ifdef CONFIG_COMPACTION
2903 {
2904 .procname = "compact_memory",
Pintu Kumaref498432021-05-04 18:36:48 -07002905 .data = NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 .maxlen = sizeof(int),
2907 .mode = 0200,
2908 .proc_handler = sysctl_compaction_handler,
2909 },
2910 {
Nitin Guptafacdaa92020-08-11 18:31:00 -07002911 .procname = "compaction_proactiveness",
2912 .data = &sysctl_compaction_proactiveness,
Nitin Guptad34c0a72020-08-11 18:31:07 -07002913 .maxlen = sizeof(sysctl_compaction_proactiveness),
Nitin Guptafacdaa92020-08-11 18:31:00 -07002914 .mode = 0644,
Charan Teja Reddy65d759c2021-09-02 14:59:59 -07002915 .proc_handler = compaction_proactiveness_sysctl_handler,
Nitin Guptafacdaa92020-08-11 18:31:00 -07002916 .extra1 = SYSCTL_ZERO,
2917 .extra2 = &one_hundred,
2918 },
2919 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 .procname = "extfrag_threshold",
2921 .data = &sysctl_extfrag_threshold,
2922 .maxlen = sizeof(int),
2923 .mode = 0644,
2924 .proc_handler = proc_dointvec_minmax,
2925 .extra1 = &min_extfrag_threshold,
2926 .extra2 = &max_extfrag_threshold,
2927 },
2928 {
2929 .procname = "compact_unevictable_allowed",
2930 .data = &sysctl_compact_unevictable_allowed,
2931 .maxlen = sizeof(int),
2932 .mode = 0644,
2933 .proc_handler = proc_dointvec_minmax_warn_RT_change,
2934 .extra1 = SYSCTL_ZERO,
2935 .extra2 = SYSCTL_ONE,
2936 },
2937
2938#endif /* CONFIG_COMPACTION */
2939 {
2940 .procname = "min_free_kbytes",
2941 .data = &min_free_kbytes,
2942 .maxlen = sizeof(min_free_kbytes),
2943 .mode = 0644,
2944 .proc_handler = min_free_kbytes_sysctl_handler,
2945 .extra1 = SYSCTL_ZERO,
2946 },
2947 {
2948 .procname = "watermark_boost_factor",
2949 .data = &watermark_boost_factor,
2950 .maxlen = sizeof(watermark_boost_factor),
2951 .mode = 0644,
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02002952 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 .extra1 = SYSCTL_ZERO,
2954 },
2955 {
2956 .procname = "watermark_scale_factor",
2957 .data = &watermark_scale_factor,
2958 .maxlen = sizeof(watermark_scale_factor),
2959 .mode = 0644,
2960 .proc_handler = watermark_scale_factor_sysctl_handler,
2961 .extra1 = SYSCTL_ONE,
2962 .extra2 = &one_thousand,
2963 },
2964 {
Mel Gorman74f44822021-06-28 19:42:24 -07002965 .procname = "percpu_pagelist_high_fraction",
2966 .data = &percpu_pagelist_high_fraction,
2967 .maxlen = sizeof(percpu_pagelist_high_fraction),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 .mode = 0644,
Mel Gorman74f44822021-06-28 19:42:24 -07002969 .proc_handler = percpu_pagelist_high_fraction_sysctl_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 .extra1 = SYSCTL_ZERO,
2971 },
Linus Torvalds5ef64cc2020-09-13 14:05:35 -07002972 {
2973 .procname = "page_lock_unfairness",
2974 .data = &sysctl_page_lock_unfairness,
2975 .maxlen = sizeof(sysctl_page_lock_unfairness),
2976 .mode = 0644,
2977 .proc_handler = proc_dointvec_minmax,
2978 .extra1 = SYSCTL_ZERO,
2979 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980#ifdef CONFIG_MMU
2981 {
2982 .procname = "max_map_count",
2983 .data = &sysctl_max_map_count,
2984 .maxlen = sizeof(sysctl_max_map_count),
2985 .mode = 0644,
2986 .proc_handler = proc_dointvec_minmax,
2987 .extra1 = SYSCTL_ZERO,
2988 },
2989#else
2990 {
2991 .procname = "nr_trim_pages",
2992 .data = &sysctl_nr_trim_pages,
2993 .maxlen = sizeof(sysctl_nr_trim_pages),
2994 .mode = 0644,
2995 .proc_handler = proc_dointvec_minmax,
2996 .extra1 = SYSCTL_ZERO,
2997 },
2998#endif
2999 {
3000 .procname = "laptop_mode",
3001 .data = &laptop_mode,
3002 .maxlen = sizeof(laptop_mode),
3003 .mode = 0644,
3004 .proc_handler = proc_dointvec_jiffies,
3005 },
3006 {
3007 .procname = "vfs_cache_pressure",
3008 .data = &sysctl_vfs_cache_pressure,
3009 .maxlen = sizeof(sysctl_vfs_cache_pressure),
3010 .mode = 0644,
Lin Feng3b3376f2021-02-25 17:20:53 -08003011 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 .extra1 = SYSCTL_ZERO,
3013 },
3014#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
3015 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
3016 {
3017 .procname = "legacy_va_layout",
3018 .data = &sysctl_legacy_va_layout,
3019 .maxlen = sizeof(sysctl_legacy_va_layout),
3020 .mode = 0644,
Lin Feng3b3376f2021-02-25 17:20:53 -08003021 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 .extra1 = SYSCTL_ZERO,
3023 },
3024#endif
3025#ifdef CONFIG_NUMA
3026 {
3027 .procname = "zone_reclaim_mode",
3028 .data = &node_reclaim_mode,
3029 .maxlen = sizeof(node_reclaim_mode),
3030 .mode = 0644,
Lin Feng3b3376f2021-02-25 17:20:53 -08003031 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 .extra1 = SYSCTL_ZERO,
3033 },
3034 {
3035 .procname = "min_unmapped_ratio",
3036 .data = &sysctl_min_unmapped_ratio,
3037 .maxlen = sizeof(sysctl_min_unmapped_ratio),
3038 .mode = 0644,
3039 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
3040 .extra1 = SYSCTL_ZERO,
3041 .extra2 = &one_hundred,
3042 },
3043 {
3044 .procname = "min_slab_ratio",
3045 .data = &sysctl_min_slab_ratio,
3046 .maxlen = sizeof(sysctl_min_slab_ratio),
3047 .mode = 0644,
3048 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
3049 .extra1 = SYSCTL_ZERO,
3050 .extra2 = &one_hundred,
3051 },
3052#endif
3053#ifdef CONFIG_SMP
3054 {
3055 .procname = "stat_interval",
3056 .data = &sysctl_stat_interval,
3057 .maxlen = sizeof(sysctl_stat_interval),
3058 .mode = 0644,
3059 .proc_handler = proc_dointvec_jiffies,
3060 },
3061 {
3062 .procname = "stat_refresh",
3063 .data = NULL,
3064 .maxlen = 0,
3065 .mode = 0600,
3066 .proc_handler = vmstat_refresh,
3067 },
3068#endif
3069#ifdef CONFIG_MMU
3070 {
3071 .procname = "mmap_min_addr",
3072 .data = &dac_mmap_min_addr,
3073 .maxlen = sizeof(unsigned long),
3074 .mode = 0644,
3075 .proc_handler = mmap_min_addr_handler,
3076 },
3077#endif
3078#ifdef CONFIG_NUMA
3079 {
3080 .procname = "numa_zonelist_order",
3081 .data = &numa_zonelist_order,
3082 .maxlen = NUMA_ZONELIST_ORDER_LEN,
3083 .mode = 0644,
3084 .proc_handler = numa_zonelist_order_handler,
3085 },
3086#endif
3087#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
3088 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
3089 {
3090 .procname = "vdso_enabled",
3091#ifdef CONFIG_X86_32
3092 .data = &vdso32_enabled,
3093 .maxlen = sizeof(vdso32_enabled),
3094#else
3095 .data = &vdso_enabled,
3096 .maxlen = sizeof(vdso_enabled),
3097#endif
3098 .mode = 0644,
3099 .proc_handler = proc_dointvec,
3100 .extra1 = SYSCTL_ZERO,
3101 },
3102#endif
3103#ifdef CONFIG_HIGHMEM
3104 {
3105 .procname = "highmem_is_dirtyable",
3106 .data = &vm_highmem_is_dirtyable,
3107 .maxlen = sizeof(vm_highmem_is_dirtyable),
3108 .mode = 0644,
3109 .proc_handler = proc_dointvec_minmax,
3110 .extra1 = SYSCTL_ZERO,
3111 .extra2 = SYSCTL_ONE,
3112 },
3113#endif
3114#ifdef CONFIG_MEMORY_FAILURE
3115 {
3116 .procname = "memory_failure_early_kill",
3117 .data = &sysctl_memory_failure_early_kill,
3118 .maxlen = sizeof(sysctl_memory_failure_early_kill),
3119 .mode = 0644,
3120 .proc_handler = proc_dointvec_minmax,
3121 .extra1 = SYSCTL_ZERO,
3122 .extra2 = SYSCTL_ONE,
3123 },
3124 {
3125 .procname = "memory_failure_recovery",
3126 .data = &sysctl_memory_failure_recovery,
3127 .maxlen = sizeof(sysctl_memory_failure_recovery),
3128 .mode = 0644,
3129 .proc_handler = proc_dointvec_minmax,
3130 .extra1 = SYSCTL_ZERO,
3131 .extra2 = SYSCTL_ONE,
3132 },
3133#endif
3134 {
3135 .procname = "user_reserve_kbytes",
3136 .data = &sysctl_user_reserve_kbytes,
3137 .maxlen = sizeof(sysctl_user_reserve_kbytes),
3138 .mode = 0644,
3139 .proc_handler = proc_doulongvec_minmax,
3140 },
3141 {
3142 .procname = "admin_reserve_kbytes",
3143 .data = &sysctl_admin_reserve_kbytes,
3144 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
3145 .mode = 0644,
3146 .proc_handler = proc_doulongvec_minmax,
3147 },
3148#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
3149 {
3150 .procname = "mmap_rnd_bits",
3151 .data = &mmap_rnd_bits,
3152 .maxlen = sizeof(mmap_rnd_bits),
3153 .mode = 0600,
3154 .proc_handler = proc_dointvec_minmax,
3155 .extra1 = (void *)&mmap_rnd_bits_min,
3156 .extra2 = (void *)&mmap_rnd_bits_max,
3157 },
3158#endif
3159#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
3160 {
3161 .procname = "mmap_rnd_compat_bits",
3162 .data = &mmap_rnd_compat_bits,
3163 .maxlen = sizeof(mmap_rnd_compat_bits),
3164 .mode = 0600,
3165 .proc_handler = proc_dointvec_minmax,
3166 .extra1 = (void *)&mmap_rnd_compat_bits_min,
3167 .extra2 = (void *)&mmap_rnd_compat_bits_max,
3168 },
3169#endif
3170#ifdef CONFIG_USERFAULTFD
3171 {
3172 .procname = "unprivileged_userfaultfd",
3173 .data = &sysctl_unprivileged_userfaultfd,
3174 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
3175 .mode = 0644,
3176 .proc_handler = proc_dointvec_minmax,
3177 .extra1 = SYSCTL_ZERO,
3178 .extra2 = SYSCTL_ONE,
3179 },
3180#endif
3181 { }
3182};
3183
3184static struct ctl_table fs_table[] = {
3185 {
3186 .procname = "inode-nr",
3187 .data = &inodes_stat,
3188 .maxlen = 2*sizeof(long),
3189 .mode = 0444,
3190 .proc_handler = proc_nr_inodes,
3191 },
3192 {
3193 .procname = "inode-state",
3194 .data = &inodes_stat,
3195 .maxlen = 7*sizeof(long),
3196 .mode = 0444,
3197 .proc_handler = proc_nr_inodes,
3198 },
3199 {
3200 .procname = "file-nr",
3201 .data = &files_stat,
3202 .maxlen = sizeof(files_stat),
3203 .mode = 0444,
3204 .proc_handler = proc_nr_files,
3205 },
3206 {
3207 .procname = "file-max",
3208 .data = &files_stat.max_files,
3209 .maxlen = sizeof(files_stat.max_files),
3210 .mode = 0644,
3211 .proc_handler = proc_doulongvec_minmax,
3212 .extra1 = &zero_ul,
3213 .extra2 = &long_max,
3214 },
3215 {
3216 .procname = "nr_open",
3217 .data = &sysctl_nr_open,
3218 .maxlen = sizeof(unsigned int),
3219 .mode = 0644,
3220 .proc_handler = proc_dointvec_minmax,
3221 .extra1 = &sysctl_nr_open_min,
3222 .extra2 = &sysctl_nr_open_max,
3223 },
3224 {
3225 .procname = "dentry-state",
3226 .data = &dentry_stat,
3227 .maxlen = 6*sizeof(long),
3228 .mode = 0444,
3229 .proc_handler = proc_nr_dentry,
3230 },
3231 {
3232 .procname = "overflowuid",
3233 .data = &fs_overflowuid,
3234 .maxlen = sizeof(int),
3235 .mode = 0644,
3236 .proc_handler = proc_dointvec_minmax,
3237 .extra1 = &minolduid,
3238 .extra2 = &maxolduid,
3239 },
3240 {
3241 .procname = "overflowgid",
3242 .data = &fs_overflowgid,
3243 .maxlen = sizeof(int),
3244 .mode = 0644,
3245 .proc_handler = proc_dointvec_minmax,
3246 .extra1 = &minolduid,
3247 .extra2 = &maxolduid,
3248 },
3249#ifdef CONFIG_FILE_LOCKING
3250 {
3251 .procname = "leases-enable",
3252 .data = &leases_enable,
3253 .maxlen = sizeof(int),
3254 .mode = 0644,
3255 .proc_handler = proc_dointvec,
3256 },
3257#endif
3258#ifdef CONFIG_DNOTIFY
3259 {
3260 .procname = "dir-notify-enable",
3261 .data = &dir_notify_enable,
3262 .maxlen = sizeof(int),
3263 .mode = 0644,
3264 .proc_handler = proc_dointvec,
3265 },
3266#endif
3267#ifdef CONFIG_MMU
3268#ifdef CONFIG_FILE_LOCKING
3269 {
3270 .procname = "lease-break-time",
3271 .data = &lease_break_time,
3272 .maxlen = sizeof(int),
3273 .mode = 0644,
3274 .proc_handler = proc_dointvec,
3275 },
3276#endif
3277#ifdef CONFIG_AIO
3278 {
3279 .procname = "aio-nr",
3280 .data = &aio_nr,
3281 .maxlen = sizeof(aio_nr),
3282 .mode = 0444,
3283 .proc_handler = proc_doulongvec_minmax,
3284 },
3285 {
3286 .procname = "aio-max-nr",
3287 .data = &aio_max_nr,
3288 .maxlen = sizeof(aio_max_nr),
3289 .mode = 0644,
3290 .proc_handler = proc_doulongvec_minmax,
3291 },
3292#endif /* CONFIG_AIO */
3293#ifdef CONFIG_INOTIFY_USER
3294 {
3295 .procname = "inotify",
3296 .mode = 0555,
3297 .child = inotify_table,
3298 },
Amir Goldstein5b8fea62021-03-04 13:29:20 +02003299#endif
3300#ifdef CONFIG_FANOTIFY
3301 {
3302 .procname = "fanotify",
3303 .mode = 0555,
3304 .child = fanotify_table,
3305 },
3306#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307#ifdef CONFIG_EPOLL
3308 {
3309 .procname = "epoll",
3310 .mode = 0555,
3311 .child = epoll_table,
3312 },
3313#endif
3314#endif
3315 {
3316 .procname = "protected_symlinks",
3317 .data = &sysctl_protected_symlinks,
3318 .maxlen = sizeof(int),
3319 .mode = 0600,
3320 .proc_handler = proc_dointvec_minmax,
3321 .extra1 = SYSCTL_ZERO,
3322 .extra2 = SYSCTL_ONE,
3323 },
3324 {
3325 .procname = "protected_hardlinks",
3326 .data = &sysctl_protected_hardlinks,
3327 .maxlen = sizeof(int),
3328 .mode = 0600,
3329 .proc_handler = proc_dointvec_minmax,
3330 .extra1 = SYSCTL_ZERO,
3331 .extra2 = SYSCTL_ONE,
3332 },
3333 {
3334 .procname = "protected_fifos",
3335 .data = &sysctl_protected_fifos,
3336 .maxlen = sizeof(int),
3337 .mode = 0600,
3338 .proc_handler = proc_dointvec_minmax,
3339 .extra1 = SYSCTL_ZERO,
3340 .extra2 = &two,
3341 },
3342 {
3343 .procname = "protected_regular",
3344 .data = &sysctl_protected_regular,
3345 .maxlen = sizeof(int),
3346 .mode = 0600,
3347 .proc_handler = proc_dointvec_minmax,
3348 .extra1 = SYSCTL_ZERO,
3349 .extra2 = &two,
3350 },
3351 {
3352 .procname = "suid_dumpable",
3353 .data = &suid_dumpable,
3354 .maxlen = sizeof(int),
3355 .mode = 0644,
3356 .proc_handler = proc_dointvec_minmax_coredump,
3357 .extra1 = SYSCTL_ZERO,
3358 .extra2 = &two,
3359 },
3360#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
3361 {
3362 .procname = "binfmt_misc",
3363 .mode = 0555,
3364 .child = sysctl_mount_point,
3365 },
3366#endif
3367 {
3368 .procname = "pipe-max-size",
3369 .data = &pipe_max_size,
3370 .maxlen = sizeof(pipe_max_size),
3371 .mode = 0644,
3372 .proc_handler = proc_dopipe_max_size,
3373 },
3374 {
3375 .procname = "pipe-user-pages-hard",
3376 .data = &pipe_user_pages_hard,
3377 .maxlen = sizeof(pipe_user_pages_hard),
3378 .mode = 0644,
3379 .proc_handler = proc_doulongvec_minmax,
3380 },
3381 {
3382 .procname = "pipe-user-pages-soft",
3383 .data = &pipe_user_pages_soft,
3384 .maxlen = sizeof(pipe_user_pages_soft),
3385 .mode = 0644,
3386 .proc_handler = proc_doulongvec_minmax,
3387 },
3388 {
3389 .procname = "mount-max",
3390 .data = &sysctl_mount_max,
3391 .maxlen = sizeof(unsigned int),
3392 .mode = 0644,
3393 .proc_handler = proc_dointvec_minmax,
3394 .extra1 = SYSCTL_ONE,
3395 },
3396 { }
3397};
3398
3399static struct ctl_table debug_table[] = {
3400#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
3401 {
3402 .procname = "exception-trace",
3403 .data = &show_unhandled_signals,
3404 .maxlen = sizeof(int),
3405 .mode = 0644,
3406 .proc_handler = proc_dointvec
3407 },
3408#endif
3409#if defined(CONFIG_OPTPROBES)
3410 {
3411 .procname = "kprobes-optimization",
3412 .data = &sysctl_kprobes_optimization,
3413 .maxlen = sizeof(int),
3414 .mode = 0644,
3415 .proc_handler = proc_kprobes_optimization_handler,
3416 .extra1 = SYSCTL_ZERO,
3417 .extra2 = SYSCTL_ONE,
3418 },
3419#endif
3420 { }
3421};
3422
3423static struct ctl_table dev_table[] = {
3424 { }
3425};
3426
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02003427static struct ctl_table sysctl_base_table[] = {
3428 {
3429 .procname = "kernel",
3430 .mode = 0555,
3431 .child = kern_table,
3432 },
3433 {
3434 .procname = "vm",
3435 .mode = 0555,
3436 .child = vm_table,
3437 },
3438 {
3439 .procname = "fs",
3440 .mode = 0555,
3441 .child = fs_table,
3442 },
3443 {
3444 .procname = "debug",
3445 .mode = 0555,
3446 .child = debug_table,
3447 },
3448 {
3449 .procname = "dev",
3450 .mode = 0555,
3451 .child = dev_table,
3452 },
3453 { }
3454};
3455
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456int __init sysctl_init(void)
3457{
3458 struct ctl_table_header *hdr;
3459
3460 hdr = register_sysctl_table(sysctl_base_table);
3461 kmemleak_not_leak(hdr);
3462 return 0;
3463}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464#endif /* CONFIG_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465/*
3466 * No sense putting this after each symbol definition, twice,
3467 * exception granted :-)
3468 */
Jia Hea2071572021-08-03 12:59:36 +02003469EXPORT_SYMBOL(proc_dobool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003471EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472EXPORT_SYMBOL(proc_dointvec_jiffies);
3473EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003474EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3476EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3477EXPORT_SYMBOL(proc_dostring);
3478EXPORT_SYMBOL(proc_doulongvec_minmax);
3479EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04003480EXPORT_SYMBOL(proc_do_large_bitmap);