blob: 8832440a4938ed05a043d3baffddabf54f79d8f2 [file] [log] [blame]
Thomas Gleixner457c8992019-05-19 13:08:55 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * sysctl.c: General linux system control interface
4 *
5 * Begun 24 March 1995, Stephen Tweedie
6 * Added /proc support, Dec 1995
7 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
8 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
9 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
10 * Dynamic registration fixes, Stephen Tweedie.
11 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
12 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Horn.
14 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
15 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
16 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * Wendling.
18 * The list_for_each() macro wasn't appropriate for the sysctl loop.
19 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
20 */
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/module.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080023#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/mm.h>
25#include <linux/swap.h>
26#include <linux/slab.h>
27#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070028#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080029#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080030#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070032#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/ctype.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070034#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070035#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/init.h>
37#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010038#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030039#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/sysrq.h>
41#include <linux/highuid.h>
42#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020043#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070044#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070047#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/times.h>
49#include <linux/limits.h>
50#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020051#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070053#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080054#include <linux/nfs_fs.h>
55#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070056#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020057#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020058#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050059#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020060#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070061#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040062#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070063#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000064#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060065#include <linux/sched/sysctl.h>
Ingo Molnarf7ccbae2017-02-08 18:51:30 +010066#include <linux/sched/coredump.h>
Kees Cook79847542014-01-23 15:55:59 -080067#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070068#include <linux/bpf.h>
Eric W. Biedermand2921682016-09-28 00:27:17 -050069#include <linux/mount.h>
Peter Xucefdca02019-05-13 17:16:41 -070070#include <linux/userfaultfd_k.h>
Christoph Hellwig2374c09b2020-04-24 08:43:36 +020071#include <linux/coredump.h>
72#include <linux/latencytop.h>
73#include <linux/pid.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Christian Brauner7f2923c2019-03-07 16:29:40 -080075#include "../lib/kstrtox.h"
76
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080077#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#include <asm/processor.h>
79
Andi Kleen29cbc782006-09-30 01:47:55 +020080#ifdef CONFIG_X86
81#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010082#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010083#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020084#endif
David Howellsd550bbd2012-03-28 18:30:03 +010085#ifdef CONFIG_SPARC
86#include <asm/setup.h>
87#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080088#ifdef CONFIG_BSD_PROCESS_ACCT
89#include <linux/acct.h>
90#endif
Dave Young4f0e0562010-03-10 15:24:09 -080091#ifdef CONFIG_RT_MUTEXES
92#include <linux/rtmutex.h>
93#endif
Dave Young2edf5e42010-03-10 15:24:10 -080094#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
95#include <linux/lockdep.h>
96#endif
Dave Young15485a42010-03-10 15:24:07 -080097#ifdef CONFIG_CHR_DEV_SG
98#include <scsi/sg.h>
99#endif
Alexander Popov964c9df2018-08-17 01:17:03 +0300100#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
101#include <linux/stackleak.h>
102#endif
Don Zickus58687ac2010-05-07 17:11:44 -0400103#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -0500104#include <linux/nmi.h>
105#endif
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107#if defined(CONFIG_SYSCTL)
108
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700109/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400110#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700111static int sixty = 60;
112#endif
113
Aaron Tomlin270750db2014-01-20 17:34:13 +0000114static int __maybe_unused neg_one = -1;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700115static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700116static int __maybe_unused four = 4;
Will Deacon9002b212019-04-05 18:39:38 -0700117static unsigned long zero_ul;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800118static unsigned long one_ul = 1;
Christian Brauner32a5ad92019-03-07 16:29:43 -0800119static unsigned long long_max = LONG_MAX;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700120static int one_hundred = 100;
Johannes Weinerc8439662020-06-03 16:02:37 -0700121static int two_hundred = 200;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700122static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700123#ifdef CONFIG_PRINTK
124static int ten_thousand = 10000;
125#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300126#ifdef CONFIG_PERF_EVENTS
127static int six_hundred_forty_kb = 640 * 1024;
128#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700129
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700130/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
131static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
134static int maxolduid = 65535;
135static int minolduid;
136
137static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700138static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Dmitry Vyukova2e51442018-08-21 21:55:52 -0700140/*
141 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
142 * and hung_task_check_interval_secs
143 */
Liu Hua80df2842014-04-07 15:38:57 -0700144#ifdef CONFIG_DETECT_HUNG_TASK
145static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
146#endif
147
Dave Youngd14f1722010-02-25 20:28:57 -0500148#ifdef CONFIG_INOTIFY_USER
149#include <linux/inotify.h>
150#endif
Vineet Guptab6fca722013-01-09 20:06:28 +0530151
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700152#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700153
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700154/**
155 * enum sysctl_writes_mode - supported sysctl write modes
156 *
157 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
Weitao Hou65f50f22019-07-16 16:26:54 -0700158 * to be written, and multiple writes on the same sysctl file descriptor
159 * will rewrite the sysctl value, regardless of file position. No warning
160 * is issued when the initial position is not 0.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700161 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
Weitao Hou65f50f22019-07-16 16:26:54 -0700162 * not 0.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700163 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
Weitao Hou65f50f22019-07-16 16:26:54 -0700164 * file position 0 and the value must be fully contained in the buffer
165 * sent to the write syscall. If dealing with strings respect the file
166 * position, but restrict this to the max length of the buffer, anything
167 * passed the max length will be ignored. Multiple writes will append
168 * to the buffer.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700169 *
170 * These write modes control how current file position affects the behavior of
171 * updating sysctl values through the proc interface on each write.
172 */
173enum sysctl_writes_mode {
174 SYSCTL_WRITES_LEGACY = -1,
175 SYSCTL_WRITES_WARN = 0,
176 SYSCTL_WRITES_STRICT = 1,
177};
Kees Cookf4aacea2014-06-06 14:37:19 -0700178
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700179static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Christoph Hellwigf461d2d2020-04-24 08:43:37 +0200180#endif /* CONFIG_PROC_SYSCTL */
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800181
Alexandre Ghiti67f39772019-09-23 15:38:47 -0700182#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
183 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184int sysctl_legacy_va_layout;
185#endif
186
Ingo Molnar77e54a12007-07-09 18:52:00 +0200187#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100188static int min_sched_granularity_ns = 100000; /* 100 usecs */
189static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
190static int min_wakeup_granularity_ns; /* 0 usecs */
191static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200192#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100193static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
194static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200195#endif /* CONFIG_SMP */
196#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200197
Mel Gorman5e771902010-05-24 14:32:31 -0700198#ifdef CONFIG_COMPACTION
199static int min_extfrag_threshold;
200static int max_extfrag_threshold = 1000;
201#endif
202
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700203#endif /* CONFIG_SYSCTL */
204
Arnd Bergmann5447e8e2020-05-05 16:07:12 +0200205#if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL)
Song Liud46edd62020-04-30 00:15:04 -0700206static int bpf_stats_handler(struct ctl_table *table, int write,
Tobias Klauser7787b6f2020-08-24 16:20:47 +0200207 void *buffer, size_t *lenp, loff_t *ppos)
Song Liud46edd62020-04-30 00:15:04 -0700208{
209 struct static_key *key = (struct static_key *)table->data;
210 static int saved_val;
211 int val, ret;
212 struct ctl_table tmp = {
213 .data = &val,
214 .maxlen = sizeof(val),
215 .mode = table->mode,
216 .extra1 = SYSCTL_ZERO,
217 .extra2 = SYSCTL_ONE,
218 };
219
220 if (write && !capable(CAP_SYS_ADMIN))
221 return -EPERM;
222
223 mutex_lock(&bpf_stats_enabled_mutex);
224 val = saved_val;
225 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
226 if (write && !ret && val != saved_val) {
227 if (val)
228 static_key_slow_inc(key);
229 else
230 static_key_slow_dec(key);
231 saved_val = val;
232 }
233 mutex_unlock(&bpf_stats_enabled_mutex);
234 return ret;
235}
Daniel Borkmann8c15bfb32021-05-11 22:35:17 +0200236
Josh Poimboeufafc2d632022-02-18 11:49:08 -0800237void __weak unpriv_ebpf_notify(int new_state)
238{
239}
240
Daniel Borkmann8c15bfb32021-05-11 22:35:17 +0200241static int bpf_unpriv_handler(struct ctl_table *table, int write,
242 void *buffer, size_t *lenp, loff_t *ppos)
243{
244 int ret, unpriv_enable = *(int *)table->data;
245 bool locked_state = unpriv_enable == 1;
246 struct ctl_table tmp = *table;
247
248 if (write && !capable(CAP_SYS_ADMIN))
249 return -EPERM;
250
251 tmp.data = &unpriv_enable;
252 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
253 if (write && !ret) {
254 if (locked_state && unpriv_enable != 1)
255 return -EPERM;
256 *(int *)table->data = unpriv_enable;
257 }
Josh Poimboeufafc2d632022-02-18 11:49:08 -0800258
259 unpriv_ebpf_notify(unpriv_enable);
260
Daniel Borkmann8c15bfb32021-05-11 22:35:17 +0200261 return ret;
262}
263#endif /* CONFIG_BPF_SYSCALL && CONFIG_SYSCTL */
Song Liud46edd62020-04-30 00:15:04 -0700264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265/*
266 * /proc/sys support
267 */
268
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700269#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Kees Cookf8808302014-06-06 14:37:17 -0700271static int _proc_do_string(char *data, int maxlen, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200272 char *buffer, size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700273{
274 size_t len;
Christoph Hellwig32927392020-04-24 08:43:38 +0200275 char c, *p;
Oleg Nesterov8d060872007-02-10 01:46:38 -0800276
277 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700278 *lenp = 0;
279 return 0;
280 }
Oleg Nesterov8d060872007-02-10 01:46:38 -0800281
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700282 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -0700283 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
284 /* Only continue writes not past the end of buffer. */
285 len = strlen(data);
286 if (len > maxlen - 1)
287 len = maxlen - 1;
288
289 if (*ppos > len)
290 return 0;
291 len = *ppos;
292 } else {
293 /* Start writing from beginning of buffer. */
294 len = 0;
295 }
296
Kees Cook2ca9bb42014-06-06 14:37:18 -0700297 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700298 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -0700299 while ((p - buffer) < *lenp && len < maxlen - 1) {
Christoph Hellwig32927392020-04-24 08:43:38 +0200300 c = *(p++);
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700301 if (c == 0 || c == '\n')
302 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -0700303 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700304 }
Kees Cookf8808302014-06-06 14:37:17 -0700305 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700306 } else {
307 len = strlen(data);
308 if (len > maxlen)
309 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -0800310
311 if (*ppos > len) {
312 *lenp = 0;
313 return 0;
314 }
315
316 data += *ppos;
317 len -= *ppos;
318
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700319 if (len > *lenp)
320 len = *lenp;
321 if (len)
Christoph Hellwig32927392020-04-24 08:43:38 +0200322 memcpy(buffer, data, len);
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700323 if (len < *lenp) {
Christoph Hellwig32927392020-04-24 08:43:38 +0200324 buffer[len] = '\n';
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700325 len++;
326 }
327 *lenp = len;
328 *ppos += len;
329 }
330 return 0;
331}
332
Kees Cookf4aacea2014-06-06 14:37:19 -0700333static void warn_sysctl_write(struct ctl_table *table)
334{
335 pr_warn_once("%s wrote to %s when file position was not 0!\n"
336 "This will not be supported in the future. To silence this\n"
337 "warning, set kernel.sysctl_writes_strict = -1\n",
338 current->comm, table->procname);
339}
340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341/**
Randy Dunlap5f733e82018-08-21 22:01:06 -0700342 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700343 * @ppos: file position
344 * @table: the sysctl table
345 *
346 * Returns true if the first position is non-zero and the sysctl_writes_strict
347 * mode indicates this is not allowed for numeric input types. String proc
Randy Dunlap5f733e82018-08-21 22:01:06 -0700348 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700349 */
350static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
351 struct ctl_table *table)
352{
353 if (!*ppos)
354 return false;
355
356 switch (sysctl_writes_strict) {
357 case SYSCTL_WRITES_STRICT:
358 return true;
359 case SYSCTL_WRITES_WARN:
360 warn_sysctl_write(table);
361 return false;
362 default:
363 return false;
364 }
365}
366
367/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 * proc_dostring - read a string sysctl
369 * @table: the sysctl table
370 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 * @buffer: the user buffer
372 * @lenp: the size of the user buffer
373 * @ppos: file position
374 *
375 * Reads/writes a string from/to the user buffer. If the kernel
376 * buffer provided is not large enough to hold the string, the
377 * string is truncated. The copied string is %NULL-terminated.
378 * If the string is being read by the user process, it is copied
379 * and a newline '\n' is added. It is truncated if the buffer is
380 * not large enough.
381 *
382 * Returns 0 on success.
383 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700384int proc_dostring(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200385 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700387 if (write)
388 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -0700389
Christoph Hellwig32927392020-04-24 08:43:38 +0200390 return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
391 ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392}
393
Amerigo Wang00b7c332010-05-05 00:26:45 +0000394static size_t proc_skip_spaces(char **buf)
395{
396 size_t ret;
397 char *tmp = skip_spaces(*buf);
398 ret = tmp - *buf;
399 *buf = tmp;
400 return ret;
401}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Octavian Purdila9f977fb2010-05-05 00:26:55 +0000403static void proc_skip_char(char **buf, size_t *size, const char v)
404{
405 while (*size) {
406 if (**buf != v)
407 break;
408 (*size)--;
409 (*buf)++;
410 }
411}
412
Christian Brauner7f2923c2019-03-07 16:29:40 -0800413/**
414 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
415 * fail on overflow
416 *
417 * @cp: kernel buffer containing the string to parse
418 * @endp: pointer to store the trailing characters
419 * @base: the base to use
420 * @res: where the parsed integer will be stored
421 *
422 * In case of success 0 is returned and @res will contain the parsed integer,
423 * @endp will hold any trailing characters.
424 * This function will fail the parse on overflow. If there wasn't an overflow
425 * the function will defer the decision what characters count as invalid to the
426 * caller.
427 */
428static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
429 unsigned long *res)
430{
431 unsigned long long result;
432 unsigned int rv;
433
434 cp = _parse_integer_fixup_radix(cp, &base);
435 rv = _parse_integer(cp, base, &result);
436 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
437 return -ERANGE;
438
439 cp += rv;
440
441 if (endp)
442 *endp = (char *)cp;
443
444 *res = (unsigned long)result;
445 return 0;
446}
447
Amerigo Wang00b7c332010-05-05 00:26:45 +0000448#define TMPBUFLEN 22
449/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700450 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +0000451 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700452 * @buf: a kernel buffer
453 * @size: size of the kernel buffer
454 * @val: this is where the number will be stored
455 * @neg: set to %TRUE if number is negative
456 * @perm_tr: a vector which contains the allowed trailers
457 * @perm_tr_len: size of the perm_tr vector
458 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +0000459 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700460 * In case of success %0 is returned and @buf and @size are updated with
461 * the amount of bytes read. If @tr is non-NULL and a trailing
462 * character exists (size is non-zero after returning from this
463 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +0000464 */
465static int proc_get_long(char **buf, size_t *size,
466 unsigned long *val, bool *neg,
467 const char *perm_tr, unsigned perm_tr_len, char *tr)
468{
469 int len;
470 char *p, tmp[TMPBUFLEN];
471
472 if (!*size)
473 return -EINVAL;
474
475 len = *size;
476 if (len > TMPBUFLEN - 1)
477 len = TMPBUFLEN - 1;
478
479 memcpy(tmp, *buf, len);
480
481 tmp[len] = 0;
482 p = tmp;
483 if (*p == '-' && *size > 1) {
484 *neg = true;
485 p++;
486 } else
487 *neg = false;
488 if (!isdigit(*p))
489 return -EINVAL;
490
Christian Brauner7f2923c2019-03-07 16:29:40 -0800491 if (strtoul_lenient(p, &p, 0, val))
492 return -EINVAL;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000493
494 len = p - tmp;
495
496 /* We don't know if the next char is whitespace thus we may accept
497 * invalid integers (e.g. 1234...a) or two integers instead of one
498 * (e.g. 123...1). So lets not allow such large numbers. */
499 if (len == TMPBUFLEN - 1)
500 return -EINVAL;
501
502 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
503 return -EINVAL;
504
505 if (tr && (len < *size))
506 *tr = *p;
507
508 *buf += len;
509 *size -= len;
510
511 return 0;
512}
513
514/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700515 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +0000516 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700517 * @buf: the user buffer
518 * @size: the size of the user buffer
519 * @val: the integer to be converted
520 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +0000521 *
Christoph Hellwig32927392020-04-24 08:43:38 +0200522 * In case of success @buf and @size are updated with the amount of bytes
523 * written.
Amerigo Wang00b7c332010-05-05 00:26:45 +0000524 */
Christoph Hellwig32927392020-04-24 08:43:38 +0200525static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
Amerigo Wang00b7c332010-05-05 00:26:45 +0000526{
527 int len;
528 char tmp[TMPBUFLEN], *p = tmp;
529
530 sprintf(p, "%s%lu", neg ? "-" : "", val);
531 len = strlen(tmp);
532 if (len > *size)
533 len = *size;
Christoph Hellwig32927392020-04-24 08:43:38 +0200534 memcpy(*buf, tmp, len);
Amerigo Wang00b7c332010-05-05 00:26:45 +0000535 *size -= len;
536 *buf += len;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000537}
538#undef TMPBUFLEN
539
Christoph Hellwig32927392020-04-24 08:43:38 +0200540static void proc_put_char(void **buf, size_t *size, char c)
Amerigo Wang00b7c332010-05-05 00:26:45 +0000541{
542 if (*size) {
Christoph Hellwig32927392020-04-24 08:43:38 +0200543 char **buffer = (char **)buf;
544 **buffer = c;
545
546 (*size)--;
547 (*buffer)++;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000548 *buf = *buffer;
549 }
Amerigo Wang00b7c332010-05-05 00:26:45 +0000550}
551
552static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 int *valp,
554 int write, void *data)
555{
556 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -0700557 if (*negp) {
558 if (*lvalp > (unsigned long) INT_MAX + 1)
559 return -EINVAL;
560 *valp = -*lvalp;
561 } else {
562 if (*lvalp > (unsigned long) INT_MAX)
563 return -EINVAL;
564 *valp = *lvalp;
565 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 } else {
567 int val = *valp;
568 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +0000569 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -0700570 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +0000572 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 *lvalp = (unsigned long)val;
574 }
575 }
576 return 0;
577}
578
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700579static int do_proc_douintvec_conv(unsigned long *lvalp,
580 unsigned int *valp,
581 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700582{
583 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700584 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700585 return -EINVAL;
586 *valp = *lvalp;
587 } else {
588 unsigned int val = *valp;
589 *lvalp = (unsigned long)val;
590 }
591 return 0;
592}
593
Amerigo Wang00b7c332010-05-05 00:26:45 +0000594static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
595
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700596static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200597 int write, void *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700598 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +0000599 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 int write, void *data),
601 void *data)
602{
Amerigo Wang00b7c332010-05-05 00:26:45 +0000603 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000604 size_t left;
Christoph Hellwig32927392020-04-24 08:43:38 +0200605 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Amerigo Wang00b7c332010-05-05 00:26:45 +0000607 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 *lenp = 0;
609 return 0;
610 }
611
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700612 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 vleft = table->maxlen / sizeof(*i);
614 left = *lenp;
615
616 if (!conv)
617 conv = do_proc_dointvec_conv;
618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700620 if (proc_first_pos_non_zero_ignore(ppos, table))
621 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -0700622
Amerigo Wang00b7c332010-05-05 00:26:45 +0000623 if (left > PAGE_SIZE - 1)
624 left = PAGE_SIZE - 1;
Christoph Hellwig32927392020-04-24 08:43:38 +0200625 p = buffer;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000626 }
627
628 for (; left && vleft--; i++, first=0) {
629 unsigned long lval;
630 bool neg;
631
632 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -0500633 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +0000634
J. R. Okajima563b0462010-05-25 16:10:14 -0700635 if (!left)
636 break;
Al Viro70f6cbb2015-12-24 00:13:10 -0500637 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +0000638 proc_wspace_sep,
639 sizeof(proc_wspace_sep), NULL);
640 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000642 if (conv(&neg, &lval, i, 1, data)) {
643 err = -EINVAL;
644 break;
645 }
646 } else {
647 if (conv(&neg, &lval, i, 0, data)) {
648 err = -EINVAL;
649 break;
650 }
651 if (!first)
Christoph Hellwig32927392020-04-24 08:43:38 +0200652 proc_put_char(&buffer, &left, '\t');
653 proc_put_long(&buffer, &left, lval, neg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 }
655 }
Amerigo Wang00b7c332010-05-05 00:26:45 +0000656
657 if (!write && !first && left && !err)
Christoph Hellwig32927392020-04-24 08:43:38 +0200658 proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -0700659 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -0500660 left -= proc_skip_spaces(&p);
Christoph Hellwig32927392020-04-24 08:43:38 +0200661 if (write && first)
662 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -0700664out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000666 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667}
668
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700669static int do_proc_dointvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200670 void *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +0000671 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700672 int write, void *data),
673 void *data)
674{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700675 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700676 buffer, lenp, ppos, conv, data);
677}
678
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700679static int do_proc_douintvec_w(unsigned int *tbl_data,
680 struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200681 void *buffer,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700682 size_t *lenp, loff_t *ppos,
683 int (*conv)(unsigned long *lvalp,
684 unsigned int *valp,
685 int write, void *data),
686 void *data)
687{
688 unsigned long lval;
689 int err = 0;
690 size_t left;
691 bool neg;
Christoph Hellwig32927392020-04-24 08:43:38 +0200692 char *p = buffer;
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700693
694 left = *lenp;
695
696 if (proc_first_pos_non_zero_ignore(ppos, table))
697 goto bail_early;
698
699 if (left > PAGE_SIZE - 1)
700 left = PAGE_SIZE - 1;
701
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700702 left -= proc_skip_spaces(&p);
703 if (!left) {
704 err = -EINVAL;
705 goto out_free;
706 }
707
708 err = proc_get_long(&p, &left, &lval, &neg,
709 proc_wspace_sep,
710 sizeof(proc_wspace_sep), NULL);
711 if (err || neg) {
712 err = -EINVAL;
713 goto out_free;
714 }
715
716 if (conv(&lval, tbl_data, 1, data)) {
717 err = -EINVAL;
718 goto out_free;
719 }
720
721 if (!err && left)
722 left -= proc_skip_spaces(&p);
723
724out_free:
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700725 if (err)
726 return -EINVAL;
727
728 return 0;
729
730 /* This is in keeping with old __do_proc_dointvec() */
731bail_early:
732 *ppos += *lenp;
733 return err;
734}
735
Christoph Hellwig32927392020-04-24 08:43:38 +0200736static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700737 size_t *lenp, loff_t *ppos,
738 int (*conv)(unsigned long *lvalp,
739 unsigned int *valp,
740 int write, void *data),
741 void *data)
742{
743 unsigned long lval;
744 int err = 0;
745 size_t left;
746
747 left = *lenp;
748
749 if (conv(&lval, tbl_data, 0, data)) {
750 err = -EINVAL;
751 goto out;
752 }
753
Christoph Hellwig32927392020-04-24 08:43:38 +0200754 proc_put_long(&buffer, &left, lval, false);
755 if (!left)
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700756 goto out;
757
Christoph Hellwig32927392020-04-24 08:43:38 +0200758 proc_put_char(&buffer, &left, '\n');
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700759
760out:
761 *lenp -= left;
762 *ppos += *lenp;
763
764 return err;
765}
766
767static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200768 int write, void *buffer,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700769 size_t *lenp, loff_t *ppos,
770 int (*conv)(unsigned long *lvalp,
771 unsigned int *valp,
772 int write, void *data),
773 void *data)
774{
775 unsigned int *i, vleft;
776
777 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
778 *lenp = 0;
779 return 0;
780 }
781
782 i = (unsigned int *) tbl_data;
783 vleft = table->maxlen / sizeof(*i);
784
785 /*
786 * Arrays are not supported, keep this simple. *Do not* add
787 * support for them.
788 */
789 if (vleft != 1) {
790 *lenp = 0;
791 return -EINVAL;
792 }
793
794 if (!conv)
795 conv = do_proc_douintvec_conv;
796
797 if (write)
798 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
799 conv, data);
800 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
801}
802
803static int do_proc_douintvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200804 void *buffer, size_t *lenp, loff_t *ppos,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700805 int (*conv)(unsigned long *lvalp,
806 unsigned int *valp,
807 int write, void *data),
808 void *data)
809{
810 return __do_proc_douintvec(table->data, table, write,
811 buffer, lenp, ppos, conv, data);
812}
813
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814/**
815 * proc_dointvec - read a vector of integers
816 * @table: the sysctl table
817 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 * @buffer: the user buffer
819 * @lenp: the size of the user buffer
820 * @ppos: file position
821 *
822 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
823 * values from/to the user buffer, treated as an ASCII string.
824 *
825 * Returns 0 on success.
826 */
Christoph Hellwig32927392020-04-24 08:43:38 +0200827int proc_dointvec(struct ctl_table *table, int write, void *buffer,
828 size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700830 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
831}
832
Sebastian Andrzej Siewior6923aa02020-04-01 21:10:42 -0700833#ifdef CONFIG_COMPACTION
834static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200835 int write, void *buffer, size_t *lenp, loff_t *ppos)
Sebastian Andrzej Siewior6923aa02020-04-01 21:10:42 -0700836{
837 int ret, old;
838
839 if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
840 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
841
842 old = *(int *)table->data;
843 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
844 if (ret)
845 return ret;
846 if (old != *(int *)table->data)
847 pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
848 table->procname, current->comm,
849 task_pid_nr(current));
850 return ret;
851}
852#endif
853
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700854/**
855 * proc_douintvec - read a vector of unsigned integers
856 * @table: the sysctl table
857 * @write: %TRUE if this is a write to the sysctl file
858 * @buffer: the user buffer
859 * @lenp: the size of the user buffer
860 * @ppos: file position
861 *
862 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
863 * values from/to the user buffer, treated as an ASCII string.
864 *
865 * Returns 0 on success.
866 */
Christoph Hellwig32927392020-04-24 08:43:38 +0200867int proc_douintvec(struct ctl_table *table, int write, void *buffer,
868 size_t *lenp, loff_t *ppos)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700869{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700870 return do_proc_douintvec(table, write, buffer, lenp, ppos,
871 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872}
873
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800874/*
Andi Kleen25ddbb12008-10-15 22:01:41 -0700875 * Taint values can only be increased
876 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800877 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700878static int proc_taint(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200879 void *buffer, size_t *lenp, loff_t *ppos)
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800880{
Andi Kleen25ddbb12008-10-15 22:01:41 -0700881 struct ctl_table t;
882 unsigned long tmptaint = get_taint();
883 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800884
Bastian Blank91fcd412007-04-23 14:41:14 -0700885 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800886 return -EPERM;
887
Andi Kleen25ddbb12008-10-15 22:01:41 -0700888 t = *table;
889 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700890 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700891 if (err < 0)
892 return err;
893
894 if (write) {
Rafael Aquinidb38d5c2020-06-07 21:40:17 -0700895 int i;
896
897 /*
898 * If we are relying on panic_on_taint not producing
899 * false positives due to userspace input, bail out
900 * before setting the requested taint flags.
901 */
902 if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
903 return -EINVAL;
904
Andi Kleen25ddbb12008-10-15 22:01:41 -0700905 /*
906 * Poor man's atomic or. Not worth adding a primitive
907 * to everyone's atomic.h for this
908 */
Rafael Aquinie77132e2020-06-07 21:40:51 -0700909 for (i = 0; i < TAINT_FLAGS_COUNT; i++)
910 if ((1UL << i) & tmptaint)
Rusty Russell373d4d02013-01-21 17:17:39 +1030911 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700912 }
913
914 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800915}
916
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700917#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700918static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200919 void *buffer, size_t *lenp, loff_t *ppos)
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700920{
921 if (write && !capable(CAP_SYS_ADMIN))
922 return -EPERM;
923
924 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
925}
926#endif
927
Waiman Long24704f32018-04-10 16:35:38 -0700928/**
929 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
930 * @min: pointer to minimum allowable value
931 * @max: pointer to maximum allowable value
932 *
933 * The do_proc_dointvec_minmax_conv_param structure provides the
934 * minimum and maximum values for doing range checking for those sysctl
935 * parameters that use the proc_dointvec_minmax() handler.
936 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937struct do_proc_dointvec_minmax_conv_param {
938 int *min;
939 int *max;
940};
941
Amerigo Wang00b7c332010-05-05 00:26:45 +0000942static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
943 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 int write, void *data)
945{
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700946 int tmp, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 struct do_proc_dointvec_minmax_conv_param *param = data;
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700948 /*
949 * If writing, first do so via a temporary local int so we can
950 * bounds-check it before touching *valp.
951 */
952 int *ip = write ? &tmp : valp;
953
954 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
955 if (ret)
956 return ret;
957
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 if (write) {
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700959 if ((param->min && *param->min > tmp) ||
960 (param->max && *param->max < tmp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 return -EINVAL;
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700962 *valp = tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 }
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700964
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 return 0;
966}
967
968/**
969 * proc_dointvec_minmax - read a vector of integers with min/max values
970 * @table: the sysctl table
971 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 * @buffer: the user buffer
973 * @lenp: the size of the user buffer
974 * @ppos: file position
975 *
976 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
977 * values from/to the user buffer, treated as an ASCII string.
978 *
979 * This routine will ensure the values are within the range specified by
980 * table->extra1 (min) and table->extra2 (max).
981 *
Waiman Long24704f32018-04-10 16:35:38 -0700982 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700984int proc_dointvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200985 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986{
987 struct do_proc_dointvec_minmax_conv_param param = {
988 .min = (int *) table->extra1,
989 .max = (int *) table->extra2,
990 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700991 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 do_proc_dointvec_minmax_conv, &param);
993}
994
Waiman Long24704f32018-04-10 16:35:38 -0700995/**
996 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
997 * @min: pointer to minimum allowable value
998 * @max: pointer to maximum allowable value
999 *
1000 * The do_proc_douintvec_minmax_conv_param structure provides the
1001 * minimum and maximum values for doing range checking for those sysctl
1002 * parameters that use the proc_douintvec_minmax() handler.
1003 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001004struct do_proc_douintvec_minmax_conv_param {
1005 unsigned int *min;
1006 unsigned int *max;
1007};
1008
1009static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
1010 unsigned int *valp,
1011 int write, void *data)
1012{
Zev Weiss2bc4fc62019-03-11 23:28:06 -07001013 int ret;
1014 unsigned int tmp;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001015 struct do_proc_douintvec_minmax_conv_param *param = data;
Zev Weiss2bc4fc62019-03-11 23:28:06 -07001016 /* write via temporary local uint for bounds-checking */
1017 unsigned int *up = write ? &tmp : valp;
1018
1019 ret = do_proc_douintvec_conv(lvalp, up, write, data);
1020 if (ret)
1021 return ret;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001022
1023 if (write) {
Zev Weiss2bc4fc62019-03-11 23:28:06 -07001024 if ((param->min && *param->min > tmp) ||
1025 (param->max && *param->max < tmp))
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001026 return -ERANGE;
1027
Zev Weiss2bc4fc62019-03-11 23:28:06 -07001028 *valp = tmp;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001029 }
1030
1031 return 0;
1032}
1033
1034/**
1035 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
1036 * @table: the sysctl table
1037 * @write: %TRUE if this is a write to the sysctl file
1038 * @buffer: the user buffer
1039 * @lenp: the size of the user buffer
1040 * @ppos: file position
1041 *
1042 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
1043 * values from/to the user buffer, treated as an ASCII string. Negative
1044 * strings are not allowed.
1045 *
1046 * This routine will ensure the values are within the range specified by
1047 * table->extra1 (min) and table->extra2 (max). There is a final sanity
1048 * check for UINT_MAX to avoid having to support wrap around uses from
1049 * userspace.
1050 *
Waiman Long24704f32018-04-10 16:35:38 -07001051 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001052 */
1053int proc_douintvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001054 void *buffer, size_t *lenp, loff_t *ppos)
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001055{
1056 struct do_proc_douintvec_minmax_conv_param param = {
1057 .min = (unsigned int *) table->extra1,
1058 .max = (unsigned int *) table->extra2,
1059 };
1060 return do_proc_douintvec(table, write, buffer, lenp, ppos,
1061 do_proc_douintvec_minmax_conv, &param);
1062}
1063
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001064static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
1065 unsigned int *valp,
1066 int write, void *data)
1067{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001068 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08001069 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001070
Joe Lawrencefb910c42017-11-17 15:29:28 -08001071 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001072 if (val == 0)
1073 return -EINVAL;
1074
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001075 *valp = val;
1076 } else {
1077 unsigned int val = *valp;
1078 *lvalp = (unsigned long) val;
1079 }
1080
1081 return 0;
1082}
1083
Eric Biggers319e0a22018-02-06 15:41:49 -08001084static int proc_dopipe_max_size(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001085 void *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001086{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001087 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08001088 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001089}
1090
Kees Cook54b50192012-07-30 14:39:18 -07001091static void validate_coredump_safety(void)
1092{
Alex Kelly046d6622012-10-04 17:15:23 -07001093#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08001094 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07001095 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08001096 printk(KERN_WARNING
1097"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
1098"Pipe handler or fully qualified core dump path required.\n"
1099"Set kernel.core_pattern before fs.suid_dumpable.\n"
1100 );
Kees Cook54b50192012-07-30 14:39:18 -07001101 }
Alex Kelly046d6622012-10-04 17:15:23 -07001102#endif
Kees Cook54b50192012-07-30 14:39:18 -07001103}
1104
1105static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001106 void *buffer, size_t *lenp, loff_t *ppos)
Kees Cook54b50192012-07-30 14:39:18 -07001107{
1108 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1109 if (!error)
1110 validate_coredump_safety();
1111 return error;
1112}
1113
Alex Kelly046d6622012-10-04 17:15:23 -07001114#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07001115static int proc_dostring_coredump(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001116 void *buffer, size_t *lenp, loff_t *ppos)
Kees Cook54b50192012-07-30 14:39:18 -07001117{
1118 int error = proc_dostring(table, write, buffer, lenp, ppos);
1119 if (!error)
1120 validate_coredump_safety();
1121 return error;
1122}
Alex Kelly046d6622012-10-04 17:15:23 -07001123#endif
Kees Cook54b50192012-07-30 14:39:18 -07001124
Dmitry Safonoveaee4172020-03-02 17:51:34 +00001125#ifdef CONFIG_MAGIC_SYSRQ
1126static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001127 void *buffer, size_t *lenp, loff_t *ppos)
Dmitry Safonoveaee4172020-03-02 17:51:34 +00001128{
1129 int tmp, ret;
1130
1131 tmp = sysrq_mask();
1132
1133 ret = __do_proc_dointvec(&tmp, table, write, buffer,
1134 lenp, ppos, NULL, NULL);
1135 if (ret || !write)
1136 return ret;
1137
1138 if (write)
1139 sysrq_toggle_support(tmp);
1140
1141 return 0;
1142}
1143#endif
1144
Christoph Hellwig32927392020-04-24 08:43:38 +02001145static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
1146 int write, void *buffer, size_t *lenp, loff_t *ppos,
1147 unsigned long convmul, unsigned long convdiv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
Amerigo Wang00b7c332010-05-05 00:26:45 +00001149 unsigned long *i, *min, *max;
1150 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001151 size_t left;
Christoph Hellwig32927392020-04-24 08:43:38 +02001152 char *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001153
1154 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 *lenp = 0;
1156 return 0;
1157 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00001158
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001159 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 min = (unsigned long *) table->extra1;
1161 max = (unsigned long *) table->extra2;
1162 vleft = table->maxlen / sizeof(unsigned long);
1163 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001164
1165 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07001166 if (proc_first_pos_non_zero_ignore(ppos, table))
1167 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07001168
Amerigo Wang00b7c332010-05-05 00:26:45 +00001169 if (left > PAGE_SIZE - 1)
1170 left = PAGE_SIZE - 1;
Christoph Hellwig32927392020-04-24 08:43:38 +02001171 p = buffer;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001172 }
1173
Eric Dumazet27b3d802010-10-07 12:59:29 -07001174 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001175 unsigned long val;
1176
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001178 bool neg;
1179
Al Viro70f6cbb2015-12-24 00:13:10 -05001180 left -= proc_skip_spaces(&p);
Cheng Lin09be1782019-01-03 15:26:13 -08001181 if (!left)
1182 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001183
Al Viro70f6cbb2015-12-24 00:13:10 -05001184 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00001185 proc_wspace_sep,
1186 sizeof(proc_wspace_sep), NULL);
1187 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 break;
1189 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08001191 val = convmul * val / convdiv;
Christian Braunere260ad02019-05-14 15:44:55 -07001192 if ((min && val < *min) || (max && val > *max)) {
1193 err = -EINVAL;
1194 break;
1195 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 *i = val;
1197 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001198 val = convdiv * (*i) / convmul;
Christoph Hellwig32927392020-04-24 08:43:38 +02001199 if (!first)
1200 proc_put_char(&buffer, &left, '\t');
1201 proc_put_long(&buffer, &left, val, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 }
1203 }
1204
Amerigo Wang00b7c332010-05-05 00:26:45 +00001205 if (!write && !first && left && !err)
Christoph Hellwig32927392020-04-24 08:43:38 +02001206 proc_put_char(&buffer, &left, '\n');
Amerigo Wang00b7c332010-05-05 00:26:45 +00001207 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05001208 left -= proc_skip_spaces(&p);
Christoph Hellwig32927392020-04-24 08:43:38 +02001209 if (write && first)
1210 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07001212out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001214 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}
1216
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001217static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001218 void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1219 unsigned long convdiv)
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001220{
1221 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001222 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001223}
1224
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225/**
1226 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1227 * @table: the sysctl table
1228 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 * @buffer: the user buffer
1230 * @lenp: the size of the user buffer
1231 * @ppos: file position
1232 *
1233 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1234 * values from/to the user buffer, treated as an ASCII string.
1235 *
1236 * This routine will ensure the values are within the range specified by
1237 * table->extra1 (min) and table->extra2 (max).
1238 *
1239 * Returns 0 on success.
1240 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001241int proc_doulongvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001242 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001244 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245}
1246
1247/**
1248 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1249 * @table: the sysctl table
1250 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 * @buffer: the user buffer
1252 * @lenp: the size of the user buffer
1253 * @ppos: file position
1254 *
1255 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1256 * values from/to the user buffer, treated as an ASCII string. The values
1257 * are treated as milliseconds, and converted to jiffies when they are stored.
1258 *
1259 * This routine will ensure the values are within the range specified by
1260 * table->extra1 (min) and table->extra2 (max).
1261 *
1262 * Returns 0 on success.
1263 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001264int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001265 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001267 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 lenp, ppos, HZ, 1000l);
1269}
1270
1271
Amerigo Wang00b7c332010-05-05 00:26:45 +00001272static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 int *valp,
1274 int write, void *data)
1275{
1276 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07001277 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08001278 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1280 } else {
1281 int val = *valp;
1282 unsigned long lval;
1283 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001284 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07001285 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001287 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 lval = (unsigned long)val;
1289 }
1290 *lvalp = lval / HZ;
1291 }
1292 return 0;
1293}
1294
Amerigo Wang00b7c332010-05-05 00:26:45 +00001295static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 int *valp,
1297 int write, void *data)
1298{
1299 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08001300 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1301 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1303 } else {
1304 int val = *valp;
1305 unsigned long lval;
1306 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001307 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07001308 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001310 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 lval = (unsigned long)val;
1312 }
1313 *lvalp = jiffies_to_clock_t(lval);
1314 }
1315 return 0;
1316}
1317
Amerigo Wang00b7c332010-05-05 00:26:45 +00001318static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 int *valp,
1320 int write, void *data)
1321{
1322 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02001323 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1324
1325 if (jif > INT_MAX)
1326 return 1;
1327 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 } else {
1329 int val = *valp;
1330 unsigned long lval;
1331 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001332 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07001333 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001335 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 lval = (unsigned long)val;
1337 }
1338 *lvalp = jiffies_to_msecs(lval);
1339 }
1340 return 0;
1341}
1342
1343/**
1344 * proc_dointvec_jiffies - read a vector of integers as seconds
1345 * @table: the sysctl table
1346 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 * @buffer: the user buffer
1348 * @lenp: the size of the user buffer
1349 * @ppos: file position
1350 *
1351 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1352 * values from/to the user buffer, treated as an ASCII string.
1353 * The values read are assumed to be in seconds, and are converted into
1354 * jiffies.
1355 *
1356 * Returns 0 on success.
1357 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001358int proc_dointvec_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001359 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001361 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 do_proc_dointvec_jiffies_conv,NULL);
1363}
1364
1365/**
1366 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1367 * @table: the sysctl table
1368 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 * @buffer: the user buffer
1370 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08001371 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 *
1373 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1374 * values from/to the user buffer, treated as an ASCII string.
1375 * The values read are assumed to be in 1/USER_HZ seconds, and
1376 * are converted into jiffies.
1377 *
1378 * Returns 0 on success.
1379 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001380int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001381 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001383 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 do_proc_dointvec_userhz_jiffies_conv,NULL);
1385}
1386
1387/**
1388 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1389 * @table: the sysctl table
1390 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 * @buffer: the user buffer
1392 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07001393 * @ppos: file position
1394 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 *
1396 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1397 * values from/to the user buffer, treated as an ASCII string.
1398 * The values read are assumed to be in 1/1000 seconds, and
1399 * are converted into jiffies.
1400 *
1401 * Returns 0 on success.
1402 */
Christoph Hellwig32927392020-04-24 08:43:38 +02001403int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
1404 size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001406 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 do_proc_dointvec_ms_jiffies_conv, NULL);
1408}
1409
Christoph Hellwig32927392020-04-24 08:43:38 +02001410static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
1411 size_t *lenp, loff_t *ppos)
Cedric Le Goater9ec52092006-10-02 02:19:00 -07001412{
1413 struct pid *new_pid;
1414 pid_t tmp;
1415 int r;
1416
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08001417 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07001418
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001419 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07001420 lenp, ppos, NULL, NULL);
1421 if (r || !write)
1422 return r;
1423
1424 new_pid = find_get_pid(tmp);
1425 if (!new_pid)
1426 return -ESRCH;
1427
1428 put_pid(xchg(&cad_pid, new_pid));
1429 return 0;
1430}
1431
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001432/**
1433 * proc_do_large_bitmap - read/write from/to a large bitmap
1434 * @table: the sysctl table
1435 * @write: %TRUE if this is a write to the sysctl file
1436 * @buffer: the user buffer
1437 * @lenp: the size of the user buffer
1438 * @ppos: file position
1439 *
1440 * The bitmap is stored at table->data and the bitmap length (in bits)
1441 * in table->maxlen.
1442 *
1443 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1444 * large bitmaps may be represented in a compact manner. Writing into
1445 * the file will clear the bitmap then update it with the given input.
1446 *
1447 * Returns 0 on success.
1448 */
1449int proc_do_large_bitmap(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001450 void *buffer, size_t *lenp, loff_t *ppos)
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001451{
1452 int err = 0;
1453 bool first = 1;
1454 size_t left = *lenp;
1455 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07001456 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001457 unsigned long *tmp_bitmap = NULL;
1458 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1459
WANG Cong122ff242014-05-12 16:04:53 -07001460 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001461 *lenp = 0;
1462 return 0;
1463 }
1464
1465 if (write) {
Christoph Hellwig32927392020-04-24 08:43:38 +02001466 char *p = buffer;
Eric Sandeen3116ad32019-05-14 15:45:13 -07001467 size_t skipped = 0;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001468
Eric Sandeen3116ad32019-05-14 15:45:13 -07001469 if (left > PAGE_SIZE - 1) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001470 left = PAGE_SIZE - 1;
Eric Sandeen3116ad32019-05-14 15:45:13 -07001471 /* How much of the buffer we'll skip this pass */
1472 skipped = *lenp - left;
1473 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001474
Andy Shevchenko475dae32019-05-14 15:44:52 -07001475 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
Christoph Hellwig32927392020-04-24 08:43:38 +02001476 if (!tmp_bitmap)
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001477 return -ENOMEM;
Al Viro70f6cbb2015-12-24 00:13:10 -05001478 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001479 while (!err && left) {
1480 unsigned long val_a, val_b;
1481 bool neg;
Eric Sandeen3116ad32019-05-14 15:45:13 -07001482 size_t saved_left;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001483
Eric Sandeen3116ad32019-05-14 15:45:13 -07001484 /* In case we stop parsing mid-number, we can reset */
1485 saved_left = left;
Al Viro70f6cbb2015-12-24 00:13:10 -05001486 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001487 sizeof(tr_a), &c);
Eric Sandeen3116ad32019-05-14 15:45:13 -07001488 /*
1489 * If we consumed the entirety of a truncated buffer or
1490 * only one char is left (may be a "-"), then stop here,
1491 * reset, & come back for more.
1492 */
1493 if ((left <= 1) && skipped) {
1494 left = saved_left;
1495 break;
1496 }
1497
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001498 if (err)
1499 break;
1500 if (val_a >= bitmap_len || neg) {
1501 err = -EINVAL;
1502 break;
1503 }
1504
1505 val_b = val_a;
1506 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05001507 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001508 left--;
1509 }
1510
1511 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05001512 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001513 &neg, tr_b, sizeof(tr_b),
1514 &c);
Eric Sandeen3116ad32019-05-14 15:45:13 -07001515 /*
1516 * If we consumed all of a truncated buffer or
1517 * then stop here, reset, & come back for more.
1518 */
1519 if (!left && skipped) {
1520 left = saved_left;
1521 break;
1522 }
1523
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001524 if (err)
1525 break;
1526 if (val_b >= bitmap_len || neg ||
1527 val_a > val_b) {
1528 err = -EINVAL;
1529 break;
1530 }
1531 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05001532 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001533 left--;
1534 }
1535 }
1536
Akinobu Mita5a04cca2012-03-28 14:42:50 -07001537 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001538 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05001539 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001540 }
Eric Sandeen3116ad32019-05-14 15:45:13 -07001541 left += skipped;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001542 } else {
1543 unsigned long bit_a, bit_b = 0;
1544
1545 while (left) {
1546 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1547 if (bit_a >= bitmap_len)
1548 break;
1549 bit_b = find_next_zero_bit(bitmap, bitmap_len,
1550 bit_a + 1) - 1;
1551
Christoph Hellwig32927392020-04-24 08:43:38 +02001552 if (!first)
1553 proc_put_char(&buffer, &left, ',');
1554 proc_put_long(&buffer, &left, bit_a, false);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001555 if (bit_a != bit_b) {
Christoph Hellwig32927392020-04-24 08:43:38 +02001556 proc_put_char(&buffer, &left, '-');
1557 proc_put_long(&buffer, &left, bit_b, false);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001558 }
1559
1560 first = 0; bit_b++;
1561 }
Christoph Hellwig32927392020-04-24 08:43:38 +02001562 proc_put_char(&buffer, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001563 }
1564
1565 if (!err) {
1566 if (write) {
1567 if (*ppos)
1568 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1569 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07001570 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001571 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001572 *lenp -= left;
1573 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001574 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08001575
Andy Shevchenko475dae32019-05-14 15:44:52 -07001576 bitmap_free(tmp_bitmap);
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08001577 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001578}
1579
Jovi Zhang55610502011-01-12 17:00:45 -08001580#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001582int proc_dostring(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001583 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584{
1585 return -ENOSYS;
1586}
1587
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001588int proc_dointvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001589 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590{
1591 return -ENOSYS;
1592}
1593
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07001594int proc_douintvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001595 void *buffer, size_t *lenp, loff_t *ppos)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07001596{
1597 return -ENOSYS;
1598}
1599
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001600int proc_dointvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001601 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602{
1603 return -ENOSYS;
1604}
1605
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001606int proc_douintvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001607 void *buffer, size_t *lenp, loff_t *ppos)
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001608{
1609 return -ENOSYS;
1610}
1611
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001612int proc_dointvec_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001613 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614{
1615 return -ENOSYS;
1616}
1617
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001618int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001619 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620{
1621 return -ENOSYS;
1622}
1623
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001624int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001625 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626{
1627 return -ENOSYS;
1628}
1629
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001630int proc_doulongvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001631 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632{
1633 return -ENOSYS;
1634}
1635
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001636int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001637 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638{
Christoph Hellwig32927392020-04-24 08:43:38 +02001639 return -ENOSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640}
1641
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04001642int proc_do_large_bitmap(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001643 void *buffer, size_t *lenp, loff_t *ppos)
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04001644{
1645 return -ENOSYS;
1646}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
Jovi Zhang55610502011-01-12 17:00:45 -08001648#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001650#if defined(CONFIG_SYSCTL)
1651int proc_do_static_key(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001652 void *buffer, size_t *lenp, loff_t *ppos)
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001653{
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001654 struct static_key *key = (struct static_key *)table->data;
1655 static DEFINE_MUTEX(static_key_mutex);
1656 int val, ret;
1657 struct ctl_table tmp = {
1658 .data = &val,
1659 .maxlen = sizeof(val),
1660 .mode = table->mode,
Matteo Croceeec48442019-07-18 15:58:50 -07001661 .extra1 = SYSCTL_ZERO,
1662 .extra2 = SYSCTL_ONE,
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001663 };
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001664
1665 if (write && !capable(CAP_SYS_ADMIN))
1666 return -EPERM;
1667
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001668 mutex_lock(&static_key_mutex);
1669 val = static_key_enabled(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001670 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1671 if (write && !ret) {
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001672 if (val)
1673 static_key_enable(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001674 else
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001675 static_key_disable(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001676 }
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001677 mutex_unlock(&static_key_mutex);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001678 return ret;
1679}
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02001680
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681static struct ctl_table kern_table[] = {
1682 {
1683 .procname = "sched_child_runs_first",
1684 .data = &sysctl_sched_child_runs_first,
1685 .maxlen = sizeof(unsigned int),
1686 .mode = 0644,
1687 .proc_handler = proc_dointvec,
1688 },
1689#ifdef CONFIG_SCHED_DEBUG
1690 {
1691 .procname = "sched_min_granularity_ns",
1692 .data = &sysctl_sched_min_granularity,
1693 .maxlen = sizeof(unsigned int),
1694 .mode = 0644,
1695 .proc_handler = sched_proc_update_handler,
1696 .extra1 = &min_sched_granularity_ns,
1697 .extra2 = &max_sched_granularity_ns,
1698 },
1699 {
1700 .procname = "sched_latency_ns",
1701 .data = &sysctl_sched_latency,
1702 .maxlen = sizeof(unsigned int),
1703 .mode = 0644,
1704 .proc_handler = sched_proc_update_handler,
1705 .extra1 = &min_sched_granularity_ns,
1706 .extra2 = &max_sched_granularity_ns,
1707 },
1708 {
1709 .procname = "sched_wakeup_granularity_ns",
1710 .data = &sysctl_sched_wakeup_granularity,
1711 .maxlen = sizeof(unsigned int),
1712 .mode = 0644,
1713 .proc_handler = sched_proc_update_handler,
1714 .extra1 = &min_wakeup_granularity_ns,
1715 .extra2 = &max_wakeup_granularity_ns,
1716 },
1717#ifdef CONFIG_SMP
1718 {
1719 .procname = "sched_tunable_scaling",
1720 .data = &sysctl_sched_tunable_scaling,
1721 .maxlen = sizeof(enum sched_tunable_scaling),
1722 .mode = 0644,
1723 .proc_handler = sched_proc_update_handler,
1724 .extra1 = &min_sched_tunable_scaling,
1725 .extra2 = &max_sched_tunable_scaling,
1726 },
1727 {
1728 .procname = "sched_migration_cost_ns",
1729 .data = &sysctl_sched_migration_cost,
1730 .maxlen = sizeof(unsigned int),
1731 .mode = 0644,
1732 .proc_handler = proc_dointvec,
1733 },
1734 {
1735 .procname = "sched_nr_migrate",
1736 .data = &sysctl_sched_nr_migrate,
1737 .maxlen = sizeof(unsigned int),
1738 .mode = 0644,
1739 .proc_handler = proc_dointvec,
1740 },
1741#ifdef CONFIG_SCHEDSTATS
1742 {
1743 .procname = "sched_schedstats",
1744 .data = NULL,
1745 .maxlen = sizeof(unsigned int),
1746 .mode = 0644,
1747 .proc_handler = sysctl_schedstats,
1748 .extra1 = SYSCTL_ZERO,
1749 .extra2 = SYSCTL_ONE,
1750 },
1751#endif /* CONFIG_SCHEDSTATS */
1752#endif /* CONFIG_SMP */
1753#ifdef CONFIG_NUMA_BALANCING
1754 {
1755 .procname = "numa_balancing_scan_delay_ms",
1756 .data = &sysctl_numa_balancing_scan_delay,
1757 .maxlen = sizeof(unsigned int),
1758 .mode = 0644,
1759 .proc_handler = proc_dointvec,
1760 },
1761 {
1762 .procname = "numa_balancing_scan_period_min_ms",
1763 .data = &sysctl_numa_balancing_scan_period_min,
1764 .maxlen = sizeof(unsigned int),
1765 .mode = 0644,
1766 .proc_handler = proc_dointvec,
1767 },
1768 {
1769 .procname = "numa_balancing_scan_period_max_ms",
1770 .data = &sysctl_numa_balancing_scan_period_max,
1771 .maxlen = sizeof(unsigned int),
1772 .mode = 0644,
1773 .proc_handler = proc_dointvec,
1774 },
1775 {
1776 .procname = "numa_balancing_scan_size_mb",
1777 .data = &sysctl_numa_balancing_scan_size,
1778 .maxlen = sizeof(unsigned int),
1779 .mode = 0644,
1780 .proc_handler = proc_dointvec_minmax,
1781 .extra1 = SYSCTL_ONE,
1782 },
1783 {
1784 .procname = "numa_balancing",
1785 .data = NULL, /* filled in by handler */
1786 .maxlen = sizeof(unsigned int),
1787 .mode = 0644,
1788 .proc_handler = sysctl_numa_balancing,
1789 .extra1 = SYSCTL_ZERO,
1790 .extra2 = SYSCTL_ONE,
1791 },
1792#endif /* CONFIG_NUMA_BALANCING */
1793#endif /* CONFIG_SCHED_DEBUG */
1794 {
1795 .procname = "sched_rt_period_us",
1796 .data = &sysctl_sched_rt_period,
1797 .maxlen = sizeof(unsigned int),
1798 .mode = 0644,
1799 .proc_handler = sched_rt_handler,
1800 },
1801 {
1802 .procname = "sched_rt_runtime_us",
1803 .data = &sysctl_sched_rt_runtime,
1804 .maxlen = sizeof(int),
1805 .mode = 0644,
1806 .proc_handler = sched_rt_handler,
1807 },
1808 {
Peter Zijlstrab4098bf2019-07-26 16:54:10 +02001809 .procname = "sched_deadline_period_max_us",
1810 .data = &sysctl_sched_dl_period_max,
1811 .maxlen = sizeof(unsigned int),
1812 .mode = 0644,
1813 .proc_handler = proc_dointvec,
1814 },
1815 {
1816 .procname = "sched_deadline_period_min_us",
1817 .data = &sysctl_sched_dl_period_min,
1818 .maxlen = sizeof(unsigned int),
1819 .mode = 0644,
1820 .proc_handler = proc_dointvec,
1821 },
1822 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 .procname = "sched_rr_timeslice_ms",
1824 .data = &sysctl_sched_rr_timeslice,
1825 .maxlen = sizeof(int),
1826 .mode = 0644,
1827 .proc_handler = sched_rr_handler,
1828 },
1829#ifdef CONFIG_UCLAMP_TASK
1830 {
1831 .procname = "sched_util_clamp_min",
1832 .data = &sysctl_sched_uclamp_util_min,
1833 .maxlen = sizeof(unsigned int),
1834 .mode = 0644,
1835 .proc_handler = sysctl_sched_uclamp_handler,
1836 },
1837 {
1838 .procname = "sched_util_clamp_max",
1839 .data = &sysctl_sched_uclamp_util_max,
1840 .maxlen = sizeof(unsigned int),
1841 .mode = 0644,
1842 .proc_handler = sysctl_sched_uclamp_handler,
1843 },
Qais Yousef13685c42020-07-16 12:03:45 +01001844 {
1845 .procname = "sched_util_clamp_min_rt_default",
1846 .data = &sysctl_sched_uclamp_util_min_rt_default,
1847 .maxlen = sizeof(unsigned int),
1848 .mode = 0644,
1849 .proc_handler = sysctl_sched_uclamp_handler,
1850 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851#endif
1852#ifdef CONFIG_SCHED_AUTOGROUP
1853 {
1854 .procname = "sched_autogroup_enabled",
1855 .data = &sysctl_sched_autogroup_enabled,
1856 .maxlen = sizeof(unsigned int),
1857 .mode = 0644,
1858 .proc_handler = proc_dointvec_minmax,
1859 .extra1 = SYSCTL_ZERO,
1860 .extra2 = SYSCTL_ONE,
1861 },
1862#endif
1863#ifdef CONFIG_CFS_BANDWIDTH
1864 {
1865 .procname = "sched_cfs_bandwidth_slice_us",
1866 .data = &sysctl_sched_cfs_bandwidth_slice,
1867 .maxlen = sizeof(unsigned int),
1868 .mode = 0644,
1869 .proc_handler = proc_dointvec_minmax,
1870 .extra1 = SYSCTL_ONE,
1871 },
1872#endif
1873#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
1874 {
1875 .procname = "sched_energy_aware",
1876 .data = &sysctl_sched_energy_aware,
1877 .maxlen = sizeof(unsigned int),
1878 .mode = 0644,
1879 .proc_handler = sched_energy_aware_handler,
1880 .extra1 = SYSCTL_ZERO,
1881 .extra2 = SYSCTL_ONE,
1882 },
1883#endif
1884#ifdef CONFIG_PROVE_LOCKING
1885 {
1886 .procname = "prove_locking",
1887 .data = &prove_locking,
1888 .maxlen = sizeof(int),
1889 .mode = 0644,
1890 .proc_handler = proc_dointvec,
1891 },
1892#endif
1893#ifdef CONFIG_LOCK_STAT
1894 {
1895 .procname = "lock_stat",
1896 .data = &lock_stat,
1897 .maxlen = sizeof(int),
1898 .mode = 0644,
1899 .proc_handler = proc_dointvec,
1900 },
1901#endif
1902 {
1903 .procname = "panic",
1904 .data = &panic_timeout,
1905 .maxlen = sizeof(int),
1906 .mode = 0644,
1907 .proc_handler = proc_dointvec,
1908 },
1909#ifdef CONFIG_COREDUMP
1910 {
1911 .procname = "core_uses_pid",
1912 .data = &core_uses_pid,
1913 .maxlen = sizeof(int),
1914 .mode = 0644,
1915 .proc_handler = proc_dointvec,
1916 },
1917 {
1918 .procname = "core_pattern",
1919 .data = core_pattern,
1920 .maxlen = CORENAME_MAX_SIZE,
1921 .mode = 0644,
1922 .proc_handler = proc_dostring_coredump,
1923 },
1924 {
1925 .procname = "core_pipe_limit",
1926 .data = &core_pipe_limit,
1927 .maxlen = sizeof(unsigned int),
1928 .mode = 0644,
1929 .proc_handler = proc_dointvec,
1930 },
1931#endif
1932#ifdef CONFIG_PROC_SYSCTL
1933 {
1934 .procname = "tainted",
1935 .maxlen = sizeof(long),
1936 .mode = 0644,
1937 .proc_handler = proc_taint,
1938 },
1939 {
1940 .procname = "sysctl_writes_strict",
1941 .data = &sysctl_writes_strict,
1942 .maxlen = sizeof(int),
1943 .mode = 0644,
1944 .proc_handler = proc_dointvec_minmax,
1945 .extra1 = &neg_one,
1946 .extra2 = SYSCTL_ONE,
1947 },
1948#endif
1949#ifdef CONFIG_LATENCYTOP
1950 {
1951 .procname = "latencytop",
1952 .data = &latencytop_enabled,
1953 .maxlen = sizeof(int),
1954 .mode = 0644,
1955 .proc_handler = sysctl_latencytop,
1956 },
1957#endif
1958#ifdef CONFIG_BLK_DEV_INITRD
1959 {
1960 .procname = "real-root-dev",
1961 .data = &real_root_dev,
1962 .maxlen = sizeof(int),
1963 .mode = 0644,
1964 .proc_handler = proc_dointvec,
1965 },
1966#endif
1967 {
1968 .procname = "print-fatal-signals",
1969 .data = &print_fatal_signals,
1970 .maxlen = sizeof(int),
1971 .mode = 0644,
1972 .proc_handler = proc_dointvec,
1973 },
1974#ifdef CONFIG_SPARC
1975 {
1976 .procname = "reboot-cmd",
1977 .data = reboot_command,
1978 .maxlen = 256,
1979 .mode = 0644,
1980 .proc_handler = proc_dostring,
1981 },
1982 {
1983 .procname = "stop-a",
1984 .data = &stop_a_enabled,
1985 .maxlen = sizeof (int),
1986 .mode = 0644,
1987 .proc_handler = proc_dointvec,
1988 },
1989 {
1990 .procname = "scons-poweroff",
1991 .data = &scons_pwroff,
1992 .maxlen = sizeof (int),
1993 .mode = 0644,
1994 .proc_handler = proc_dointvec,
1995 },
1996#endif
1997#ifdef CONFIG_SPARC64
1998 {
1999 .procname = "tsb-ratio",
2000 .data = &sysctl_tsb_ratio,
2001 .maxlen = sizeof (int),
2002 .mode = 0644,
2003 .proc_handler = proc_dointvec,
2004 },
2005#endif
2006#ifdef CONFIG_PARISC
2007 {
2008 .procname = "soft-power",
2009 .data = &pwrsw_enabled,
2010 .maxlen = sizeof (int),
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02002011 .mode = 0644,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 .proc_handler = proc_dointvec,
2013 },
2014#endif
2015#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
2016 {
2017 .procname = "unaligned-trap",
2018 .data = &unaligned_enabled,
2019 .maxlen = sizeof (int),
2020 .mode = 0644,
2021 .proc_handler = proc_dointvec,
2022 },
2023#endif
2024 {
2025 .procname = "ctrl-alt-del",
2026 .data = &C_A_D,
2027 .maxlen = sizeof(int),
2028 .mode = 0644,
2029 .proc_handler = proc_dointvec,
2030 },
2031#ifdef CONFIG_FUNCTION_TRACER
2032 {
2033 .procname = "ftrace_enabled",
2034 .data = &ftrace_enabled,
2035 .maxlen = sizeof(int),
2036 .mode = 0644,
2037 .proc_handler = ftrace_enable_sysctl,
2038 },
2039#endif
2040#ifdef CONFIG_STACK_TRACER
2041 {
2042 .procname = "stack_tracer_enabled",
2043 .data = &stack_tracer_enabled,
2044 .maxlen = sizeof(int),
2045 .mode = 0644,
2046 .proc_handler = stack_trace_sysctl,
2047 },
2048#endif
2049#ifdef CONFIG_TRACING
2050 {
2051 .procname = "ftrace_dump_on_oops",
2052 .data = &ftrace_dump_on_oops,
2053 .maxlen = sizeof(int),
2054 .mode = 0644,
2055 .proc_handler = proc_dointvec,
2056 },
2057 {
2058 .procname = "traceoff_on_warning",
2059 .data = &__disable_trace_on_warning,
2060 .maxlen = sizeof(__disable_trace_on_warning),
2061 .mode = 0644,
2062 .proc_handler = proc_dointvec,
2063 },
2064 {
2065 .procname = "tracepoint_printk",
2066 .data = &tracepoint_printk,
2067 .maxlen = sizeof(tracepoint_printk),
2068 .mode = 0644,
2069 .proc_handler = tracepoint_printk_sysctl,
2070 },
2071#endif
2072#ifdef CONFIG_KEXEC_CORE
2073 {
2074 .procname = "kexec_load_disabled",
2075 .data = &kexec_load_disabled,
2076 .maxlen = sizeof(int),
2077 .mode = 0644,
2078 /* only handle a transition from default "0" to "1" */
2079 .proc_handler = proc_dointvec_minmax,
2080 .extra1 = SYSCTL_ONE,
2081 .extra2 = SYSCTL_ONE,
2082 },
2083#endif
2084#ifdef CONFIG_MODULES
2085 {
2086 .procname = "modprobe",
2087 .data = &modprobe_path,
2088 .maxlen = KMOD_PATH_LEN,
2089 .mode = 0644,
2090 .proc_handler = proc_dostring,
2091 },
2092 {
2093 .procname = "modules_disabled",
2094 .data = &modules_disabled,
2095 .maxlen = sizeof(int),
2096 .mode = 0644,
2097 /* only handle a transition from default "0" to "1" */
2098 .proc_handler = proc_dointvec_minmax,
2099 .extra1 = SYSCTL_ONE,
2100 .extra2 = SYSCTL_ONE,
2101 },
2102#endif
2103#ifdef CONFIG_UEVENT_HELPER
2104 {
2105 .procname = "hotplug",
2106 .data = &uevent_helper,
2107 .maxlen = UEVENT_HELPER_PATH_LEN,
2108 .mode = 0644,
2109 .proc_handler = proc_dostring,
2110 },
2111#endif
2112#ifdef CONFIG_CHR_DEV_SG
2113 {
2114 .procname = "sg-big-buff",
2115 .data = &sg_big_buff,
2116 .maxlen = sizeof (int),
2117 .mode = 0444,
2118 .proc_handler = proc_dointvec,
2119 },
2120#endif
2121#ifdef CONFIG_BSD_PROCESS_ACCT
2122 {
2123 .procname = "acct",
2124 .data = &acct_parm,
2125 .maxlen = 3*sizeof(int),
2126 .mode = 0644,
2127 .proc_handler = proc_dointvec,
2128 },
2129#endif
2130#ifdef CONFIG_MAGIC_SYSRQ
2131 {
2132 .procname = "sysrq",
2133 .data = NULL,
2134 .maxlen = sizeof (int),
2135 .mode = 0644,
2136 .proc_handler = sysrq_sysctl_handler,
2137 },
2138#endif
2139#ifdef CONFIG_PROC_SYSCTL
2140 {
2141 .procname = "cad_pid",
2142 .data = NULL,
2143 .maxlen = sizeof (int),
2144 .mode = 0600,
2145 .proc_handler = proc_do_cad_pid,
2146 },
2147#endif
2148 {
2149 .procname = "threads-max",
2150 .data = NULL,
2151 .maxlen = sizeof(int),
2152 .mode = 0644,
2153 .proc_handler = sysctl_max_threads,
2154 },
2155 {
2156 .procname = "random",
2157 .mode = 0555,
2158 .child = random_table,
2159 },
2160 {
2161 .procname = "usermodehelper",
2162 .mode = 0555,
2163 .child = usermodehelper_table,
2164 },
2165#ifdef CONFIG_FW_LOADER_USER_HELPER
2166 {
2167 .procname = "firmware_config",
2168 .mode = 0555,
2169 .child = firmware_config_table,
2170 },
2171#endif
2172 {
2173 .procname = "overflowuid",
2174 .data = &overflowuid,
2175 .maxlen = sizeof(int),
2176 .mode = 0644,
2177 .proc_handler = proc_dointvec_minmax,
2178 .extra1 = &minolduid,
2179 .extra2 = &maxolduid,
2180 },
2181 {
2182 .procname = "overflowgid",
2183 .data = &overflowgid,
2184 .maxlen = sizeof(int),
2185 .mode = 0644,
2186 .proc_handler = proc_dointvec_minmax,
2187 .extra1 = &minolduid,
2188 .extra2 = &maxolduid,
2189 },
2190#ifdef CONFIG_S390
2191 {
2192 .procname = "userprocess_debug",
2193 .data = &show_unhandled_signals,
2194 .maxlen = sizeof(int),
2195 .mode = 0644,
2196 .proc_handler = proc_dointvec,
2197 },
2198#endif
Guilherme G. Piccoli60c958d2020-06-07 21:40:48 -07002199#ifdef CONFIG_SMP
2200 {
2201 .procname = "oops_all_cpu_backtrace",
2202 .data = &sysctl_oops_all_cpu_backtrace,
2203 .maxlen = sizeof(int),
2204 .mode = 0644,
2205 .proc_handler = proc_dointvec_minmax,
2206 .extra1 = SYSCTL_ZERO,
2207 .extra2 = SYSCTL_ONE,
2208 },
2209#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 {
2211 .procname = "pid_max",
2212 .data = &pid_max,
2213 .maxlen = sizeof (int),
2214 .mode = 0644,
2215 .proc_handler = proc_dointvec_minmax,
2216 .extra1 = &pid_max_min,
2217 .extra2 = &pid_max_max,
2218 },
2219 {
2220 .procname = "panic_on_oops",
2221 .data = &panic_on_oops,
2222 .maxlen = sizeof(int),
2223 .mode = 0644,
2224 .proc_handler = proc_dointvec,
2225 },
2226 {
2227 .procname = "panic_print",
2228 .data = &panic_print,
2229 .maxlen = sizeof(unsigned long),
2230 .mode = 0644,
2231 .proc_handler = proc_doulongvec_minmax,
2232 },
2233#if defined CONFIG_PRINTK
2234 {
2235 .procname = "printk",
2236 .data = &console_loglevel,
2237 .maxlen = 4*sizeof(int),
2238 .mode = 0644,
2239 .proc_handler = proc_dointvec,
2240 },
2241 {
2242 .procname = "printk_ratelimit",
2243 .data = &printk_ratelimit_state.interval,
2244 .maxlen = sizeof(int),
2245 .mode = 0644,
2246 .proc_handler = proc_dointvec_jiffies,
2247 },
2248 {
2249 .procname = "printk_ratelimit_burst",
2250 .data = &printk_ratelimit_state.burst,
2251 .maxlen = sizeof(int),
2252 .mode = 0644,
2253 .proc_handler = proc_dointvec,
2254 },
2255 {
2256 .procname = "printk_delay",
2257 .data = &printk_delay_msec,
2258 .maxlen = sizeof(int),
2259 .mode = 0644,
2260 .proc_handler = proc_dointvec_minmax,
2261 .extra1 = SYSCTL_ZERO,
2262 .extra2 = &ten_thousand,
2263 },
2264 {
2265 .procname = "printk_devkmsg",
2266 .data = devkmsg_log_str,
2267 .maxlen = DEVKMSG_STR_MAX_SIZE,
2268 .mode = 0644,
2269 .proc_handler = devkmsg_sysctl_set_loglvl,
2270 },
2271 {
2272 .procname = "dmesg_restrict",
2273 .data = &dmesg_restrict,
2274 .maxlen = sizeof(int),
2275 .mode = 0644,
2276 .proc_handler = proc_dointvec_minmax_sysadmin,
2277 .extra1 = SYSCTL_ZERO,
2278 .extra2 = SYSCTL_ONE,
2279 },
2280 {
2281 .procname = "kptr_restrict",
2282 .data = &kptr_restrict,
2283 .maxlen = sizeof(int),
2284 .mode = 0644,
2285 .proc_handler = proc_dointvec_minmax_sysadmin,
2286 .extra1 = SYSCTL_ZERO,
2287 .extra2 = &two,
2288 },
2289#endif
2290 {
2291 .procname = "ngroups_max",
2292 .data = &ngroups_max,
2293 .maxlen = sizeof (int),
2294 .mode = 0444,
2295 .proc_handler = proc_dointvec,
2296 },
2297 {
2298 .procname = "cap_last_cap",
2299 .data = (void *)&cap_last_cap,
2300 .maxlen = sizeof(int),
2301 .mode = 0444,
2302 .proc_handler = proc_dointvec,
2303 },
2304#if defined(CONFIG_LOCKUP_DETECTOR)
2305 {
2306 .procname = "watchdog",
2307 .data = &watchdog_user_enabled,
2308 .maxlen = sizeof(int),
2309 .mode = 0644,
2310 .proc_handler = proc_watchdog,
2311 .extra1 = SYSCTL_ZERO,
2312 .extra2 = SYSCTL_ONE,
2313 },
2314 {
2315 .procname = "watchdog_thresh",
2316 .data = &watchdog_thresh,
2317 .maxlen = sizeof(int),
2318 .mode = 0644,
2319 .proc_handler = proc_watchdog_thresh,
2320 .extra1 = SYSCTL_ZERO,
2321 .extra2 = &sixty,
2322 },
2323 {
2324 .procname = "nmi_watchdog",
2325 .data = &nmi_watchdog_user_enabled,
2326 .maxlen = sizeof(int),
2327 .mode = NMI_WATCHDOG_SYSCTL_PERM,
2328 .proc_handler = proc_nmi_watchdog,
2329 .extra1 = SYSCTL_ZERO,
2330 .extra2 = SYSCTL_ONE,
2331 },
2332 {
2333 .procname = "watchdog_cpumask",
2334 .data = &watchdog_cpumask_bits,
2335 .maxlen = NR_CPUS,
2336 .mode = 0644,
2337 .proc_handler = proc_watchdog_cpumask,
2338 },
2339#ifdef CONFIG_SOFTLOCKUP_DETECTOR
2340 {
2341 .procname = "soft_watchdog",
2342 .data = &soft_watchdog_user_enabled,
2343 .maxlen = sizeof(int),
2344 .mode = 0644,
2345 .proc_handler = proc_soft_watchdog,
2346 .extra1 = SYSCTL_ZERO,
2347 .extra2 = SYSCTL_ONE,
2348 },
2349 {
2350 .procname = "softlockup_panic",
2351 .data = &softlockup_panic,
2352 .maxlen = sizeof(int),
2353 .mode = 0644,
2354 .proc_handler = proc_dointvec_minmax,
2355 .extra1 = SYSCTL_ZERO,
2356 .extra2 = SYSCTL_ONE,
2357 },
2358#ifdef CONFIG_SMP
2359 {
2360 .procname = "softlockup_all_cpu_backtrace",
2361 .data = &sysctl_softlockup_all_cpu_backtrace,
2362 .maxlen = sizeof(int),
2363 .mode = 0644,
2364 .proc_handler = proc_dointvec_minmax,
2365 .extra1 = SYSCTL_ZERO,
2366 .extra2 = SYSCTL_ONE,
2367 },
2368#endif /* CONFIG_SMP */
2369#endif
2370#ifdef CONFIG_HARDLOCKUP_DETECTOR
2371 {
2372 .procname = "hardlockup_panic",
2373 .data = &hardlockup_panic,
2374 .maxlen = sizeof(int),
2375 .mode = 0644,
2376 .proc_handler = proc_dointvec_minmax,
2377 .extra1 = SYSCTL_ZERO,
2378 .extra2 = SYSCTL_ONE,
2379 },
2380#ifdef CONFIG_SMP
2381 {
2382 .procname = "hardlockup_all_cpu_backtrace",
2383 .data = &sysctl_hardlockup_all_cpu_backtrace,
2384 .maxlen = sizeof(int),
2385 .mode = 0644,
2386 .proc_handler = proc_dointvec_minmax,
2387 .extra1 = SYSCTL_ZERO,
2388 .extra2 = SYSCTL_ONE,
2389 },
2390#endif /* CONFIG_SMP */
2391#endif
2392#endif
2393
2394#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
2395 {
2396 .procname = "unknown_nmi_panic",
2397 .data = &unknown_nmi_panic,
2398 .maxlen = sizeof (int),
2399 .mode = 0644,
2400 .proc_handler = proc_dointvec,
2401 },
2402#endif
Xiaoming Nib6522fa2020-04-11 21:06:19 +08002403
2404#if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
2405 defined(CONFIG_DEBUG_STACKOVERFLOW)
2406 {
2407 .procname = "panic_on_stackoverflow",
2408 .data = &sysctl_panic_on_stackoverflow,
2409 .maxlen = sizeof(int),
2410 .mode = 0644,
2411 .proc_handler = proc_dointvec,
2412 },
2413#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414#if defined(CONFIG_X86)
2415 {
2416 .procname = "panic_on_unrecovered_nmi",
2417 .data = &panic_on_unrecovered_nmi,
2418 .maxlen = sizeof(int),
2419 .mode = 0644,
2420 .proc_handler = proc_dointvec,
2421 },
2422 {
2423 .procname = "panic_on_io_nmi",
2424 .data = &panic_on_io_nmi,
2425 .maxlen = sizeof(int),
2426 .mode = 0644,
2427 .proc_handler = proc_dointvec,
2428 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 {
2430 .procname = "bootloader_type",
2431 .data = &bootloader_type,
2432 .maxlen = sizeof (int),
2433 .mode = 0444,
2434 .proc_handler = proc_dointvec,
2435 },
2436 {
2437 .procname = "bootloader_version",
2438 .data = &bootloader_version,
2439 .maxlen = sizeof (int),
2440 .mode = 0444,
2441 .proc_handler = proc_dointvec,
2442 },
2443 {
2444 .procname = "io_delay_type",
2445 .data = &io_delay_type,
2446 .maxlen = sizeof(int),
2447 .mode = 0644,
2448 .proc_handler = proc_dointvec,
2449 },
2450#endif
2451#if defined(CONFIG_MMU)
2452 {
2453 .procname = "randomize_va_space",
2454 .data = &randomize_va_space,
2455 .maxlen = sizeof(int),
2456 .mode = 0644,
2457 .proc_handler = proc_dointvec,
2458 },
2459#endif
2460#if defined(CONFIG_S390) && defined(CONFIG_SMP)
2461 {
2462 .procname = "spin_retry",
2463 .data = &spin_retry,
2464 .maxlen = sizeof (int),
2465 .mode = 0644,
2466 .proc_handler = proc_dointvec,
2467 },
2468#endif
2469#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
2470 {
2471 .procname = "acpi_video_flags",
2472 .data = &acpi_realmode_flags,
2473 .maxlen = sizeof (unsigned long),
2474 .mode = 0644,
2475 .proc_handler = proc_doulongvec_minmax,
2476 },
2477#endif
2478#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
2479 {
2480 .procname = "ignore-unaligned-usertrap",
2481 .data = &no_unaligned_warning,
2482 .maxlen = sizeof (int),
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02002483 .mode = 0644,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 .proc_handler = proc_dointvec,
2485 },
2486#endif
2487#ifdef CONFIG_IA64
2488 {
2489 .procname = "unaligned-dump-stack",
2490 .data = &unaligned_dump_stack,
2491 .maxlen = sizeof (int),
2492 .mode = 0644,
2493 .proc_handler = proc_dointvec,
2494 },
2495#endif
2496#ifdef CONFIG_DETECT_HUNG_TASK
Guilherme G. Piccoli0ec9dc92020-06-07 21:40:45 -07002497#ifdef CONFIG_SMP
2498 {
2499 .procname = "hung_task_all_cpu_backtrace",
2500 .data = &sysctl_hung_task_all_cpu_backtrace,
2501 .maxlen = sizeof(int),
2502 .mode = 0644,
2503 .proc_handler = proc_dointvec_minmax,
2504 .extra1 = SYSCTL_ZERO,
2505 .extra2 = SYSCTL_ONE,
2506 },
2507#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 {
2509 .procname = "hung_task_panic",
2510 .data = &sysctl_hung_task_panic,
2511 .maxlen = sizeof(int),
2512 .mode = 0644,
2513 .proc_handler = proc_dointvec_minmax,
2514 .extra1 = SYSCTL_ZERO,
2515 .extra2 = SYSCTL_ONE,
2516 },
2517 {
2518 .procname = "hung_task_check_count",
2519 .data = &sysctl_hung_task_check_count,
2520 .maxlen = sizeof(int),
2521 .mode = 0644,
2522 .proc_handler = proc_dointvec_minmax,
2523 .extra1 = SYSCTL_ZERO,
2524 },
2525 {
2526 .procname = "hung_task_timeout_secs",
2527 .data = &sysctl_hung_task_timeout_secs,
2528 .maxlen = sizeof(unsigned long),
2529 .mode = 0644,
2530 .proc_handler = proc_dohung_task_timeout_secs,
2531 .extra2 = &hung_task_timeout_max,
2532 },
2533 {
2534 .procname = "hung_task_check_interval_secs",
2535 .data = &sysctl_hung_task_check_interval_secs,
2536 .maxlen = sizeof(unsigned long),
2537 .mode = 0644,
2538 .proc_handler = proc_dohung_task_timeout_secs,
2539 .extra2 = &hung_task_timeout_max,
2540 },
2541 {
2542 .procname = "hung_task_warnings",
2543 .data = &sysctl_hung_task_warnings,
2544 .maxlen = sizeof(int),
2545 .mode = 0644,
2546 .proc_handler = proc_dointvec_minmax,
2547 .extra1 = &neg_one,
2548 },
2549#endif
2550#ifdef CONFIG_RT_MUTEXES
2551 {
2552 .procname = "max_lock_depth",
2553 .data = &max_lock_depth,
2554 .maxlen = sizeof(int),
2555 .mode = 0644,
2556 .proc_handler = proc_dointvec,
2557 },
2558#endif
2559 {
2560 .procname = "poweroff_cmd",
2561 .data = &poweroff_cmd,
2562 .maxlen = POWEROFF_CMD_PATH_LEN,
2563 .mode = 0644,
2564 .proc_handler = proc_dostring,
2565 },
2566#ifdef CONFIG_KEYS
2567 {
2568 .procname = "keys",
2569 .mode = 0555,
2570 .child = key_sysctls,
2571 },
2572#endif
2573#ifdef CONFIG_PERF_EVENTS
2574 /*
2575 * User-space scripts rely on the existence of this file
2576 * as a feature check for perf_events being enabled.
2577 *
2578 * So it's an ABI, do not remove!
2579 */
2580 {
2581 .procname = "perf_event_paranoid",
2582 .data = &sysctl_perf_event_paranoid,
2583 .maxlen = sizeof(sysctl_perf_event_paranoid),
2584 .mode = 0644,
2585 .proc_handler = proc_dointvec,
2586 },
2587 {
2588 .procname = "perf_event_mlock_kb",
2589 .data = &sysctl_perf_event_mlock,
2590 .maxlen = sizeof(sysctl_perf_event_mlock),
2591 .mode = 0644,
2592 .proc_handler = proc_dointvec,
2593 },
2594 {
2595 .procname = "perf_event_max_sample_rate",
2596 .data = &sysctl_perf_event_sample_rate,
2597 .maxlen = sizeof(sysctl_perf_event_sample_rate),
2598 .mode = 0644,
2599 .proc_handler = perf_proc_update_handler,
2600 .extra1 = SYSCTL_ONE,
2601 },
2602 {
2603 .procname = "perf_cpu_time_max_percent",
2604 .data = &sysctl_perf_cpu_time_max_percent,
2605 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
2606 .mode = 0644,
2607 .proc_handler = perf_cpu_time_max_percent_handler,
2608 .extra1 = SYSCTL_ZERO,
2609 .extra2 = &one_hundred,
2610 },
2611 {
2612 .procname = "perf_event_max_stack",
2613 .data = &sysctl_perf_event_max_stack,
2614 .maxlen = sizeof(sysctl_perf_event_max_stack),
2615 .mode = 0644,
2616 .proc_handler = perf_event_max_stack_handler,
2617 .extra1 = SYSCTL_ZERO,
2618 .extra2 = &six_hundred_forty_kb,
2619 },
2620 {
2621 .procname = "perf_event_max_contexts_per_stack",
2622 .data = &sysctl_perf_event_max_contexts_per_stack,
2623 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
2624 .mode = 0644,
2625 .proc_handler = perf_event_max_stack_handler,
2626 .extra1 = SYSCTL_ZERO,
2627 .extra2 = &one_thousand,
2628 },
2629#endif
2630 {
2631 .procname = "panic_on_warn",
2632 .data = &panic_on_warn,
2633 .maxlen = sizeof(int),
2634 .mode = 0644,
2635 .proc_handler = proc_dointvec_minmax,
2636 .extra1 = SYSCTL_ZERO,
2637 .extra2 = SYSCTL_ONE,
2638 },
2639#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
2640 {
2641 .procname = "timer_migration",
2642 .data = &sysctl_timer_migration,
2643 .maxlen = sizeof(unsigned int),
2644 .mode = 0644,
2645 .proc_handler = timer_migration_handler,
2646 .extra1 = SYSCTL_ZERO,
2647 .extra2 = SYSCTL_ONE,
2648 },
2649#endif
2650#ifdef CONFIG_BPF_SYSCALL
2651 {
2652 .procname = "unprivileged_bpf_disabled",
2653 .data = &sysctl_unprivileged_bpf_disabled,
2654 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
2655 .mode = 0644,
Daniel Borkmann8c15bfb32021-05-11 22:35:17 +02002656 .proc_handler = bpf_unpriv_handler,
2657 .extra1 = SYSCTL_ZERO,
2658 .extra2 = &two,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 },
2660 {
2661 .procname = "bpf_stats_enabled",
2662 .data = &bpf_stats_enabled_key.key,
2663 .maxlen = sizeof(bpf_stats_enabled_key),
2664 .mode = 0644,
Song Liud46edd62020-04-30 00:15:04 -07002665 .proc_handler = bpf_stats_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 },
2667#endif
2668#if defined(CONFIG_TREE_RCU)
2669 {
2670 .procname = "panic_on_rcu_stall",
2671 .data = &sysctl_panic_on_rcu_stall,
2672 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
2673 .mode = 0644,
2674 .proc_handler = proc_dointvec_minmax,
2675 .extra1 = SYSCTL_ZERO,
2676 .extra2 = SYSCTL_ONE,
2677 },
2678#endif
2679#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
2680 {
2681 .procname = "stack_erasing",
2682 .data = NULL,
2683 .maxlen = sizeof(int),
2684 .mode = 0600,
2685 .proc_handler = stack_erasing_sysctl,
2686 .extra1 = SYSCTL_ZERO,
2687 .extra2 = SYSCTL_ONE,
2688 },
2689#endif
2690 { }
2691};
2692
2693static struct ctl_table vm_table[] = {
2694 {
2695 .procname = "overcommit_memory",
2696 .data = &sysctl_overcommit_memory,
2697 .maxlen = sizeof(sysctl_overcommit_memory),
2698 .mode = 0644,
Feng Tang56f35472020-08-06 23:23:15 -07002699 .proc_handler = overcommit_policy_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 .extra1 = SYSCTL_ZERO,
2701 .extra2 = &two,
2702 },
2703 {
2704 .procname = "panic_on_oom",
2705 .data = &sysctl_panic_on_oom,
2706 .maxlen = sizeof(sysctl_panic_on_oom),
2707 .mode = 0644,
2708 .proc_handler = proc_dointvec_minmax,
2709 .extra1 = SYSCTL_ZERO,
2710 .extra2 = &two,
2711 },
2712 {
2713 .procname = "oom_kill_allocating_task",
2714 .data = &sysctl_oom_kill_allocating_task,
2715 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
2716 .mode = 0644,
2717 .proc_handler = proc_dointvec,
2718 },
2719 {
2720 .procname = "oom_dump_tasks",
2721 .data = &sysctl_oom_dump_tasks,
2722 .maxlen = sizeof(sysctl_oom_dump_tasks),
2723 .mode = 0644,
2724 .proc_handler = proc_dointvec,
2725 },
2726 {
2727 .procname = "overcommit_ratio",
2728 .data = &sysctl_overcommit_ratio,
2729 .maxlen = sizeof(sysctl_overcommit_ratio),
2730 .mode = 0644,
2731 .proc_handler = overcommit_ratio_handler,
2732 },
2733 {
2734 .procname = "overcommit_kbytes",
2735 .data = &sysctl_overcommit_kbytes,
2736 .maxlen = sizeof(sysctl_overcommit_kbytes),
2737 .mode = 0644,
2738 .proc_handler = overcommit_kbytes_handler,
2739 },
2740 {
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02002741 .procname = "page-cluster",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 .data = &page_cluster,
2743 .maxlen = sizeof(int),
2744 .mode = 0644,
2745 .proc_handler = proc_dointvec_minmax,
2746 .extra1 = SYSCTL_ZERO,
2747 },
2748 {
2749 .procname = "dirty_background_ratio",
2750 .data = &dirty_background_ratio,
2751 .maxlen = sizeof(dirty_background_ratio),
2752 .mode = 0644,
2753 .proc_handler = dirty_background_ratio_handler,
2754 .extra1 = SYSCTL_ZERO,
2755 .extra2 = &one_hundred,
2756 },
2757 {
2758 .procname = "dirty_background_bytes",
2759 .data = &dirty_background_bytes,
2760 .maxlen = sizeof(dirty_background_bytes),
2761 .mode = 0644,
2762 .proc_handler = dirty_background_bytes_handler,
2763 .extra1 = &one_ul,
2764 },
2765 {
2766 .procname = "dirty_ratio",
2767 .data = &vm_dirty_ratio,
2768 .maxlen = sizeof(vm_dirty_ratio),
2769 .mode = 0644,
2770 .proc_handler = dirty_ratio_handler,
2771 .extra1 = SYSCTL_ZERO,
2772 .extra2 = &one_hundred,
2773 },
2774 {
2775 .procname = "dirty_bytes",
2776 .data = &vm_dirty_bytes,
2777 .maxlen = sizeof(vm_dirty_bytes),
2778 .mode = 0644,
2779 .proc_handler = dirty_bytes_handler,
2780 .extra1 = &dirty_bytes_min,
2781 },
2782 {
2783 .procname = "dirty_writeback_centisecs",
2784 .data = &dirty_writeback_interval,
2785 .maxlen = sizeof(dirty_writeback_interval),
2786 .mode = 0644,
2787 .proc_handler = dirty_writeback_centisecs_handler,
2788 },
2789 {
2790 .procname = "dirty_expire_centisecs",
2791 .data = &dirty_expire_interval,
2792 .maxlen = sizeof(dirty_expire_interval),
2793 .mode = 0644,
2794 .proc_handler = proc_dointvec_minmax,
2795 .extra1 = SYSCTL_ZERO,
2796 },
2797 {
2798 .procname = "dirtytime_expire_seconds",
2799 .data = &dirtytime_expire_interval,
2800 .maxlen = sizeof(dirtytime_expire_interval),
2801 .mode = 0644,
2802 .proc_handler = dirtytime_interval_handler,
2803 .extra1 = SYSCTL_ZERO,
2804 },
2805 {
2806 .procname = "swappiness",
2807 .data = &vm_swappiness,
2808 .maxlen = sizeof(vm_swappiness),
2809 .mode = 0644,
2810 .proc_handler = proc_dointvec_minmax,
2811 .extra1 = SYSCTL_ZERO,
Johannes Weinerc8439662020-06-03 16:02:37 -07002812 .extra2 = &two_hundred,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 },
2814#ifdef CONFIG_HUGETLB_PAGE
2815 {
2816 .procname = "nr_hugepages",
2817 .data = NULL,
2818 .maxlen = sizeof(unsigned long),
2819 .mode = 0644,
2820 .proc_handler = hugetlb_sysctl_handler,
2821 },
2822#ifdef CONFIG_NUMA
2823 {
2824 .procname = "nr_hugepages_mempolicy",
2825 .data = NULL,
2826 .maxlen = sizeof(unsigned long),
2827 .mode = 0644,
2828 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
2829 },
2830 {
2831 .procname = "numa_stat",
2832 .data = &sysctl_vm_numa_stat,
2833 .maxlen = sizeof(int),
2834 .mode = 0644,
2835 .proc_handler = sysctl_vm_numa_stat_handler,
2836 .extra1 = SYSCTL_ZERO,
2837 .extra2 = SYSCTL_ONE,
2838 },
2839#endif
2840 {
2841 .procname = "hugetlb_shm_group",
2842 .data = &sysctl_hugetlb_shm_group,
2843 .maxlen = sizeof(gid_t),
2844 .mode = 0644,
2845 .proc_handler = proc_dointvec,
2846 },
2847 {
2848 .procname = "nr_overcommit_hugepages",
2849 .data = NULL,
2850 .maxlen = sizeof(unsigned long),
2851 .mode = 0644,
2852 .proc_handler = hugetlb_overcommit_handler,
2853 },
2854#endif
2855 {
2856 .procname = "lowmem_reserve_ratio",
2857 .data = &sysctl_lowmem_reserve_ratio,
2858 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
2859 .mode = 0644,
2860 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
2861 },
2862 {
2863 .procname = "drop_caches",
2864 .data = &sysctl_drop_caches,
2865 .maxlen = sizeof(int),
2866 .mode = 0200,
2867 .proc_handler = drop_caches_sysctl_handler,
2868 .extra1 = SYSCTL_ONE,
2869 .extra2 = &four,
2870 },
2871#ifdef CONFIG_COMPACTION
2872 {
2873 .procname = "compact_memory",
2874 .data = &sysctl_compact_memory,
2875 .maxlen = sizeof(int),
2876 .mode = 0200,
2877 .proc_handler = sysctl_compaction_handler,
2878 },
2879 {
Nitin Guptafacdaa92020-08-11 18:31:00 -07002880 .procname = "compaction_proactiveness",
2881 .data = &sysctl_compaction_proactiveness,
Nitin Guptad34c0a72020-08-11 18:31:07 -07002882 .maxlen = sizeof(sysctl_compaction_proactiveness),
Nitin Guptafacdaa92020-08-11 18:31:00 -07002883 .mode = 0644,
2884 .proc_handler = proc_dointvec_minmax,
2885 .extra1 = SYSCTL_ZERO,
2886 .extra2 = &one_hundred,
2887 },
2888 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 .procname = "extfrag_threshold",
2890 .data = &sysctl_extfrag_threshold,
2891 .maxlen = sizeof(int),
2892 .mode = 0644,
2893 .proc_handler = proc_dointvec_minmax,
2894 .extra1 = &min_extfrag_threshold,
2895 .extra2 = &max_extfrag_threshold,
2896 },
2897 {
2898 .procname = "compact_unevictable_allowed",
2899 .data = &sysctl_compact_unevictable_allowed,
2900 .maxlen = sizeof(int),
2901 .mode = 0644,
2902 .proc_handler = proc_dointvec_minmax_warn_RT_change,
2903 .extra1 = SYSCTL_ZERO,
2904 .extra2 = SYSCTL_ONE,
2905 },
2906
2907#endif /* CONFIG_COMPACTION */
2908 {
2909 .procname = "min_free_kbytes",
2910 .data = &min_free_kbytes,
2911 .maxlen = sizeof(min_free_kbytes),
2912 .mode = 0644,
2913 .proc_handler = min_free_kbytes_sysctl_handler,
2914 .extra1 = SYSCTL_ZERO,
2915 },
2916 {
2917 .procname = "watermark_boost_factor",
2918 .data = &watermark_boost_factor,
2919 .maxlen = sizeof(watermark_boost_factor),
2920 .mode = 0644,
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02002921 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 .extra1 = SYSCTL_ZERO,
2923 },
2924 {
2925 .procname = "watermark_scale_factor",
2926 .data = &watermark_scale_factor,
2927 .maxlen = sizeof(watermark_scale_factor),
2928 .mode = 0644,
2929 .proc_handler = watermark_scale_factor_sysctl_handler,
2930 .extra1 = SYSCTL_ONE,
2931 .extra2 = &one_thousand,
2932 },
2933 {
2934 .procname = "percpu_pagelist_fraction",
2935 .data = &percpu_pagelist_fraction,
2936 .maxlen = sizeof(percpu_pagelist_fraction),
2937 .mode = 0644,
2938 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
2939 .extra1 = SYSCTL_ZERO,
2940 },
Linus Torvalds5ef64cc2020-09-13 14:05:35 -07002941 {
2942 .procname = "page_lock_unfairness",
2943 .data = &sysctl_page_lock_unfairness,
2944 .maxlen = sizeof(sysctl_page_lock_unfairness),
2945 .mode = 0644,
2946 .proc_handler = proc_dointvec_minmax,
2947 .extra1 = SYSCTL_ZERO,
2948 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949#ifdef CONFIG_MMU
2950 {
2951 .procname = "max_map_count",
2952 .data = &sysctl_max_map_count,
2953 .maxlen = sizeof(sysctl_max_map_count),
2954 .mode = 0644,
2955 .proc_handler = proc_dointvec_minmax,
2956 .extra1 = SYSCTL_ZERO,
2957 },
2958#else
2959 {
2960 .procname = "nr_trim_pages",
2961 .data = &sysctl_nr_trim_pages,
2962 .maxlen = sizeof(sysctl_nr_trim_pages),
2963 .mode = 0644,
2964 .proc_handler = proc_dointvec_minmax,
2965 .extra1 = SYSCTL_ZERO,
2966 },
2967#endif
2968 {
2969 .procname = "laptop_mode",
2970 .data = &laptop_mode,
2971 .maxlen = sizeof(laptop_mode),
2972 .mode = 0644,
2973 .proc_handler = proc_dointvec_jiffies,
2974 },
2975 {
2976 .procname = "block_dump",
2977 .data = &block_dump,
2978 .maxlen = sizeof(block_dump),
2979 .mode = 0644,
Lin Fengf49bdac2021-02-25 17:20:53 -08002980 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 .extra1 = SYSCTL_ZERO,
2982 },
2983 {
2984 .procname = "vfs_cache_pressure",
2985 .data = &sysctl_vfs_cache_pressure,
2986 .maxlen = sizeof(sysctl_vfs_cache_pressure),
2987 .mode = 0644,
Lin Fengf49bdac2021-02-25 17:20:53 -08002988 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 .extra1 = SYSCTL_ZERO,
2990 },
2991#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
2992 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
2993 {
2994 .procname = "legacy_va_layout",
2995 .data = &sysctl_legacy_va_layout,
2996 .maxlen = sizeof(sysctl_legacy_va_layout),
2997 .mode = 0644,
Lin Fengf49bdac2021-02-25 17:20:53 -08002998 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 .extra1 = SYSCTL_ZERO,
3000 },
3001#endif
3002#ifdef CONFIG_NUMA
3003 {
3004 .procname = "zone_reclaim_mode",
3005 .data = &node_reclaim_mode,
3006 .maxlen = sizeof(node_reclaim_mode),
3007 .mode = 0644,
Lin Fengf49bdac2021-02-25 17:20:53 -08003008 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 .extra1 = SYSCTL_ZERO,
3010 },
3011 {
3012 .procname = "min_unmapped_ratio",
3013 .data = &sysctl_min_unmapped_ratio,
3014 .maxlen = sizeof(sysctl_min_unmapped_ratio),
3015 .mode = 0644,
3016 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
3017 .extra1 = SYSCTL_ZERO,
3018 .extra2 = &one_hundred,
3019 },
3020 {
3021 .procname = "min_slab_ratio",
3022 .data = &sysctl_min_slab_ratio,
3023 .maxlen = sizeof(sysctl_min_slab_ratio),
3024 .mode = 0644,
3025 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
3026 .extra1 = SYSCTL_ZERO,
3027 .extra2 = &one_hundred,
3028 },
3029#endif
3030#ifdef CONFIG_SMP
3031 {
3032 .procname = "stat_interval",
3033 .data = &sysctl_stat_interval,
3034 .maxlen = sizeof(sysctl_stat_interval),
3035 .mode = 0644,
3036 .proc_handler = proc_dointvec_jiffies,
3037 },
3038 {
3039 .procname = "stat_refresh",
3040 .data = NULL,
3041 .maxlen = 0,
3042 .mode = 0600,
3043 .proc_handler = vmstat_refresh,
3044 },
3045#endif
3046#ifdef CONFIG_MMU
3047 {
3048 .procname = "mmap_min_addr",
3049 .data = &dac_mmap_min_addr,
3050 .maxlen = sizeof(unsigned long),
3051 .mode = 0644,
3052 .proc_handler = mmap_min_addr_handler,
3053 },
3054#endif
3055#ifdef CONFIG_NUMA
3056 {
3057 .procname = "numa_zonelist_order",
3058 .data = &numa_zonelist_order,
3059 .maxlen = NUMA_ZONELIST_ORDER_LEN,
3060 .mode = 0644,
3061 .proc_handler = numa_zonelist_order_handler,
3062 },
3063#endif
3064#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
3065 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
3066 {
3067 .procname = "vdso_enabled",
3068#ifdef CONFIG_X86_32
3069 .data = &vdso32_enabled,
3070 .maxlen = sizeof(vdso32_enabled),
3071#else
3072 .data = &vdso_enabled,
3073 .maxlen = sizeof(vdso_enabled),
3074#endif
3075 .mode = 0644,
3076 .proc_handler = proc_dointvec,
3077 .extra1 = SYSCTL_ZERO,
3078 },
3079#endif
3080#ifdef CONFIG_HIGHMEM
3081 {
3082 .procname = "highmem_is_dirtyable",
3083 .data = &vm_highmem_is_dirtyable,
3084 .maxlen = sizeof(vm_highmem_is_dirtyable),
3085 .mode = 0644,
3086 .proc_handler = proc_dointvec_minmax,
3087 .extra1 = SYSCTL_ZERO,
3088 .extra2 = SYSCTL_ONE,
3089 },
3090#endif
3091#ifdef CONFIG_MEMORY_FAILURE
3092 {
3093 .procname = "memory_failure_early_kill",
3094 .data = &sysctl_memory_failure_early_kill,
3095 .maxlen = sizeof(sysctl_memory_failure_early_kill),
3096 .mode = 0644,
3097 .proc_handler = proc_dointvec_minmax,
3098 .extra1 = SYSCTL_ZERO,
3099 .extra2 = SYSCTL_ONE,
3100 },
3101 {
3102 .procname = "memory_failure_recovery",
3103 .data = &sysctl_memory_failure_recovery,
3104 .maxlen = sizeof(sysctl_memory_failure_recovery),
3105 .mode = 0644,
3106 .proc_handler = proc_dointvec_minmax,
3107 .extra1 = SYSCTL_ZERO,
3108 .extra2 = SYSCTL_ONE,
3109 },
3110#endif
3111 {
3112 .procname = "user_reserve_kbytes",
3113 .data = &sysctl_user_reserve_kbytes,
3114 .maxlen = sizeof(sysctl_user_reserve_kbytes),
3115 .mode = 0644,
3116 .proc_handler = proc_doulongvec_minmax,
3117 },
3118 {
3119 .procname = "admin_reserve_kbytes",
3120 .data = &sysctl_admin_reserve_kbytes,
3121 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
3122 .mode = 0644,
3123 .proc_handler = proc_doulongvec_minmax,
3124 },
3125#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
3126 {
3127 .procname = "mmap_rnd_bits",
3128 .data = &mmap_rnd_bits,
3129 .maxlen = sizeof(mmap_rnd_bits),
3130 .mode = 0600,
3131 .proc_handler = proc_dointvec_minmax,
3132 .extra1 = (void *)&mmap_rnd_bits_min,
3133 .extra2 = (void *)&mmap_rnd_bits_max,
3134 },
3135#endif
3136#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
3137 {
3138 .procname = "mmap_rnd_compat_bits",
3139 .data = &mmap_rnd_compat_bits,
3140 .maxlen = sizeof(mmap_rnd_compat_bits),
3141 .mode = 0600,
3142 .proc_handler = proc_dointvec_minmax,
3143 .extra1 = (void *)&mmap_rnd_compat_bits_min,
3144 .extra2 = (void *)&mmap_rnd_compat_bits_max,
3145 },
3146#endif
3147#ifdef CONFIG_USERFAULTFD
3148 {
3149 .procname = "unprivileged_userfaultfd",
3150 .data = &sysctl_unprivileged_userfaultfd,
3151 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
3152 .mode = 0644,
3153 .proc_handler = proc_dointvec_minmax,
3154 .extra1 = SYSCTL_ZERO,
3155 .extra2 = SYSCTL_ONE,
3156 },
3157#endif
3158 { }
3159};
3160
3161static struct ctl_table fs_table[] = {
3162 {
3163 .procname = "inode-nr",
3164 .data = &inodes_stat,
3165 .maxlen = 2*sizeof(long),
3166 .mode = 0444,
3167 .proc_handler = proc_nr_inodes,
3168 },
3169 {
3170 .procname = "inode-state",
3171 .data = &inodes_stat,
3172 .maxlen = 7*sizeof(long),
3173 .mode = 0444,
3174 .proc_handler = proc_nr_inodes,
3175 },
3176 {
3177 .procname = "file-nr",
3178 .data = &files_stat,
3179 .maxlen = sizeof(files_stat),
3180 .mode = 0444,
3181 .proc_handler = proc_nr_files,
3182 },
3183 {
3184 .procname = "file-max",
3185 .data = &files_stat.max_files,
3186 .maxlen = sizeof(files_stat.max_files),
3187 .mode = 0644,
3188 .proc_handler = proc_doulongvec_minmax,
3189 .extra1 = &zero_ul,
3190 .extra2 = &long_max,
3191 },
3192 {
3193 .procname = "nr_open",
3194 .data = &sysctl_nr_open,
3195 .maxlen = sizeof(unsigned int),
3196 .mode = 0644,
3197 .proc_handler = proc_dointvec_minmax,
3198 .extra1 = &sysctl_nr_open_min,
3199 .extra2 = &sysctl_nr_open_max,
3200 },
3201 {
3202 .procname = "dentry-state",
3203 .data = &dentry_stat,
3204 .maxlen = 6*sizeof(long),
3205 .mode = 0444,
3206 .proc_handler = proc_nr_dentry,
3207 },
3208 {
3209 .procname = "overflowuid",
3210 .data = &fs_overflowuid,
3211 .maxlen = sizeof(int),
3212 .mode = 0644,
3213 .proc_handler = proc_dointvec_minmax,
3214 .extra1 = &minolduid,
3215 .extra2 = &maxolduid,
3216 },
3217 {
3218 .procname = "overflowgid",
3219 .data = &fs_overflowgid,
3220 .maxlen = sizeof(int),
3221 .mode = 0644,
3222 .proc_handler = proc_dointvec_minmax,
3223 .extra1 = &minolduid,
3224 .extra2 = &maxolduid,
3225 },
3226#ifdef CONFIG_FILE_LOCKING
3227 {
3228 .procname = "leases-enable",
3229 .data = &leases_enable,
3230 .maxlen = sizeof(int),
3231 .mode = 0644,
3232 .proc_handler = proc_dointvec,
3233 },
3234#endif
3235#ifdef CONFIG_DNOTIFY
3236 {
3237 .procname = "dir-notify-enable",
3238 .data = &dir_notify_enable,
3239 .maxlen = sizeof(int),
3240 .mode = 0644,
3241 .proc_handler = proc_dointvec,
3242 },
3243#endif
3244#ifdef CONFIG_MMU
3245#ifdef CONFIG_FILE_LOCKING
3246 {
3247 .procname = "lease-break-time",
3248 .data = &lease_break_time,
3249 .maxlen = sizeof(int),
3250 .mode = 0644,
3251 .proc_handler = proc_dointvec,
3252 },
3253#endif
3254#ifdef CONFIG_AIO
3255 {
3256 .procname = "aio-nr",
3257 .data = &aio_nr,
3258 .maxlen = sizeof(aio_nr),
3259 .mode = 0444,
3260 .proc_handler = proc_doulongvec_minmax,
3261 },
3262 {
3263 .procname = "aio-max-nr",
3264 .data = &aio_max_nr,
3265 .maxlen = sizeof(aio_max_nr),
3266 .mode = 0644,
3267 .proc_handler = proc_doulongvec_minmax,
3268 },
3269#endif /* CONFIG_AIO */
3270#ifdef CONFIG_INOTIFY_USER
3271 {
3272 .procname = "inotify",
3273 .mode = 0555,
3274 .child = inotify_table,
3275 },
3276#endif
3277#ifdef CONFIG_EPOLL
3278 {
3279 .procname = "epoll",
3280 .mode = 0555,
3281 .child = epoll_table,
3282 },
3283#endif
3284#endif
3285 {
3286 .procname = "protected_symlinks",
3287 .data = &sysctl_protected_symlinks,
3288 .maxlen = sizeof(int),
3289 .mode = 0600,
3290 .proc_handler = proc_dointvec_minmax,
3291 .extra1 = SYSCTL_ZERO,
3292 .extra2 = SYSCTL_ONE,
3293 },
3294 {
3295 .procname = "protected_hardlinks",
3296 .data = &sysctl_protected_hardlinks,
3297 .maxlen = sizeof(int),
3298 .mode = 0600,
3299 .proc_handler = proc_dointvec_minmax,
3300 .extra1 = SYSCTL_ZERO,
3301 .extra2 = SYSCTL_ONE,
3302 },
3303 {
3304 .procname = "protected_fifos",
3305 .data = &sysctl_protected_fifos,
3306 .maxlen = sizeof(int),
3307 .mode = 0600,
3308 .proc_handler = proc_dointvec_minmax,
3309 .extra1 = SYSCTL_ZERO,
3310 .extra2 = &two,
3311 },
3312 {
3313 .procname = "protected_regular",
3314 .data = &sysctl_protected_regular,
3315 .maxlen = sizeof(int),
3316 .mode = 0600,
3317 .proc_handler = proc_dointvec_minmax,
3318 .extra1 = SYSCTL_ZERO,
3319 .extra2 = &two,
3320 },
3321 {
3322 .procname = "suid_dumpable",
3323 .data = &suid_dumpable,
3324 .maxlen = sizeof(int),
3325 .mode = 0644,
3326 .proc_handler = proc_dointvec_minmax_coredump,
3327 .extra1 = SYSCTL_ZERO,
3328 .extra2 = &two,
3329 },
3330#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
3331 {
3332 .procname = "binfmt_misc",
3333 .mode = 0555,
3334 .child = sysctl_mount_point,
3335 },
3336#endif
3337 {
3338 .procname = "pipe-max-size",
3339 .data = &pipe_max_size,
3340 .maxlen = sizeof(pipe_max_size),
3341 .mode = 0644,
3342 .proc_handler = proc_dopipe_max_size,
3343 },
3344 {
3345 .procname = "pipe-user-pages-hard",
3346 .data = &pipe_user_pages_hard,
3347 .maxlen = sizeof(pipe_user_pages_hard),
3348 .mode = 0644,
3349 .proc_handler = proc_doulongvec_minmax,
3350 },
3351 {
3352 .procname = "pipe-user-pages-soft",
3353 .data = &pipe_user_pages_soft,
3354 .maxlen = sizeof(pipe_user_pages_soft),
3355 .mode = 0644,
3356 .proc_handler = proc_doulongvec_minmax,
3357 },
3358 {
3359 .procname = "mount-max",
3360 .data = &sysctl_mount_max,
3361 .maxlen = sizeof(unsigned int),
3362 .mode = 0644,
3363 .proc_handler = proc_dointvec_minmax,
3364 .extra1 = SYSCTL_ONE,
3365 },
3366 { }
3367};
3368
3369static struct ctl_table debug_table[] = {
3370#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
3371 {
3372 .procname = "exception-trace",
3373 .data = &show_unhandled_signals,
3374 .maxlen = sizeof(int),
3375 .mode = 0644,
3376 .proc_handler = proc_dointvec
3377 },
3378#endif
3379#if defined(CONFIG_OPTPROBES)
3380 {
3381 .procname = "kprobes-optimization",
3382 .data = &sysctl_kprobes_optimization,
3383 .maxlen = sizeof(int),
3384 .mode = 0644,
3385 .proc_handler = proc_kprobes_optimization_handler,
3386 .extra1 = SYSCTL_ZERO,
3387 .extra2 = SYSCTL_ONE,
3388 },
3389#endif
3390 { }
3391};
3392
3393static struct ctl_table dev_table[] = {
3394 { }
3395};
3396
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02003397static struct ctl_table sysctl_base_table[] = {
3398 {
3399 .procname = "kernel",
3400 .mode = 0555,
3401 .child = kern_table,
3402 },
3403 {
3404 .procname = "vm",
3405 .mode = 0555,
3406 .child = vm_table,
3407 },
3408 {
3409 .procname = "fs",
3410 .mode = 0555,
3411 .child = fs_table,
3412 },
3413 {
3414 .procname = "debug",
3415 .mode = 0555,
3416 .child = debug_table,
3417 },
3418 {
3419 .procname = "dev",
3420 .mode = 0555,
3421 .child = dev_table,
3422 },
3423 { }
3424};
3425
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426int __init sysctl_init(void)
3427{
3428 struct ctl_table_header *hdr;
3429
3430 hdr = register_sysctl_table(sysctl_base_table);
3431 kmemleak_not_leak(hdr);
3432 return 0;
3433}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434#endif /* CONFIG_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435/*
3436 * No sense putting this after each symbol definition, twice,
3437 * exception granted :-)
3438 */
3439EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003440EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441EXPORT_SYMBOL(proc_dointvec_jiffies);
3442EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003443EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3445EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3446EXPORT_SYMBOL(proc_dostring);
3447EXPORT_SYMBOL(proc_doulongvec_minmax);
3448EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04003449EXPORT_SYMBOL(proc_do_large_bitmap);