blob: db1ce7af25632d72f116f16f82c83fca090b82d4 [file] [log] [blame]
Thomas Gleixner457c8992019-05-19 13:08:55 +01001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * sysctl.c: General linux system control interface
4 *
5 * Begun 24 March 1995, Stephen Tweedie
6 * Added /proc support, Dec 1995
7 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
8 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
9 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
10 * Dynamic registration fixes, Stephen Tweedie.
11 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
12 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Horn.
14 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
15 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
16 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * Wendling.
18 * The list_for_each() macro wasn't appropriate for the sysctl loop.
19 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
20 */
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/module.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080023#include <linux/aio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/mm.h>
25#include <linux/swap.h>
26#include <linux/slab.h>
27#include <linux/sysctl.h>
Akinobu Mita5a04cca2012-03-28 14:42:50 -070028#include <linux/bitmap.h>
Dave Youngd33ed522010-03-10 15:23:59 -080029#include <linux/signal.h>
Dan Rosenberg455cd5a2011-01-12 16:59:41 -080030#include <linux/printk.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/proc_fs.h>
Andrew Morgan72c2d582007-10-18 03:05:59 -070032#include <linux/security.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/ctype.h>
Steven Rostedtfd4b6162012-07-30 14:42:48 -070034#include <linux/kmemleak.h>
Adrian Bunk62239ac2007-07-17 04:03:45 -070035#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/init.h>
37#include <linux/kernel.h>
Kay Sievers0296b222005-11-11 05:33:52 +010038#include <linux/kobject.h>
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -030039#include <linux/net.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/sysrq.h>
41#include <linux/highuid.h>
42#include <linux/writeback.h>
Ingo Molnar3fff4c42009-09-22 16:18:09 +020043#include <linux/ratelimit.h>
Mel Gorman76ab0f52010-05-24 14:32:28 -070044#include <linux/compaction.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/hugetlb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/initrd.h>
David Howells0b77f5b2008-04-29 01:01:32 -070047#include <linux/key.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/times.h>
49#include <linux/limits.h>
50#include <linux/dcache.h>
Alexey Dobriyan6e006702010-01-20 22:27:56 +020051#include <linux/dnotify.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/syscalls.h>
Adrian Bunkc748e132008-07-23 21:27:03 -070053#include <linux/vmstat.h>
Pavel Machekc255d842006-02-20 18:27:58 -080054#include <linux/nfs_fs.h>
55#include <linux/acpi.h>
Jeremy Fitzhardinge10a0a8d2007-07-17 18:37:02 -070056#include <linux/reboot.h>
Steven Rostedtb0fc4942008-05-12 21:20:43 +020057#include <linux/ftrace.h>
Ingo Molnarcdd6c482009-09-21 12:02:48 +020058#include <linux/perf_event.h>
Masami Hiramatsub2be84d2010-02-25 08:34:15 -050059#include <linux/kprobes.h>
Jens Axboeb492e952010-05-19 21:03:16 +020060#include <linux/pipe_fs_i.h>
David Rientjes8e4228e2010-08-09 17:18:56 -070061#include <linux/oom.h>
Eric Paris17f60a72011-04-01 17:07:50 -040062#include <linux/kmod.h>
Dan Ballard73efc032011-10-31 17:11:20 -070063#include <linux/capability.h>
Al Viro40401532012-02-13 03:58:52 +000064#include <linux/binfmts.h>
Clark Williamscf4aebc22013-02-07 09:46:59 -060065#include <linux/sched/sysctl.h>
Ingo Molnarf7ccbae2017-02-08 18:51:30 +010066#include <linux/sched/coredump.h>
Kees Cook79847542014-01-23 15:55:59 -080067#include <linux/kexec.h>
Alexei Starovoitov1be7f752015-10-07 22:23:21 -070068#include <linux/bpf.h>
Eric W. Biedermand2921682016-09-28 00:27:17 -050069#include <linux/mount.h>
Peter Xucefdca02019-05-13 17:16:41 -070070#include <linux/userfaultfd_k.h>
Christoph Hellwig2374c092020-04-24 08:43:36 +020071#include <linux/coredump.h>
72#include <linux/latencytop.h>
73#include <linux/pid.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Christian Brauner7f2923c2019-03-07 16:29:40 -080075#include "../lib/kstrtox.h"
76
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080077#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#include <asm/processor.h>
79
Andi Kleen29cbc782006-09-30 01:47:55 +020080#ifdef CONFIG_X86
81#include <asm/nmi.h>
Chuck Ebbert0741f4d2006-12-07 02:14:11 +010082#include <asm/stacktrace.h>
Ingo Molnar6e7c4022008-01-30 13:30:05 +010083#include <asm/io.h>
Andi Kleen29cbc782006-09-30 01:47:55 +020084#endif
David Howellsd550bbd2012-03-28 18:30:03 +010085#ifdef CONFIG_SPARC
86#include <asm/setup.h>
87#endif
Dave Youngc55b7c32010-03-10 15:24:08 -080088#ifdef CONFIG_BSD_PROCESS_ACCT
89#include <linux/acct.h>
90#endif
Dave Young4f0e0562010-03-10 15:24:09 -080091#ifdef CONFIG_RT_MUTEXES
92#include <linux/rtmutex.h>
93#endif
Dave Young2edf5e42010-03-10 15:24:10 -080094#if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
95#include <linux/lockdep.h>
96#endif
Dave Young15485a42010-03-10 15:24:07 -080097#ifdef CONFIG_CHR_DEV_SG
98#include <scsi/sg.h>
99#endif
Alexander Popov964c9df2018-08-17 01:17:03 +0300100#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
101#include <linux/stackleak.h>
102#endif
Don Zickus58687ac2010-05-07 17:11:44 -0400103#ifdef CONFIG_LOCKUP_DETECTOR
Don Zickus504d7cf2010-02-12 17:19:19 -0500104#include <linux/nmi.h>
105#endif
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107#if defined(CONFIG_SYSCTL)
108
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700109/* Constants used for minimum and maximum */
Don Zickus2508ce12010-05-07 17:11:46 -0400110#ifdef CONFIG_LOCKUP_DETECTOR
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700111static int sixty = 60;
112#endif
113
Aaron Tomlin270750db2014-01-20 17:34:13 +0000114static int __maybe_unused neg_one = -1;
Linus Torvaldscd5f9a42009-04-06 13:38:46 -0700115static int __maybe_unused two = 2;
Dave Hansen5509a5d2014-04-03 14:48:19 -0700116static int __maybe_unused four = 4;
Will Deacon9002b212019-04-05 18:39:38 -0700117static unsigned long zero_ul;
Sven Wegenerfc3501d2009-02-11 13:04:23 -0800118static unsigned long one_ul = 1;
Christian Brauner32a5ad92019-03-07 16:29:43 -0800119static unsigned long long_max = LONG_MAX;
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700120static int one_hundred = 100;
Johannes Weinerc8439662020-06-03 16:02:37 -0700121static int two_hundred = 200;
Johannes Weiner795ae7a2016-03-17 14:19:14 -0700122static int one_thousand = 1000;
Dave Youngaf913222009-09-22 16:43:33 -0700123#ifdef CONFIG_PRINTK
124static int ten_thousand = 10000;
125#endif
Arnaldo Carvalho de Meloc5dfd782016-04-21 12:28:50 -0300126#ifdef CONFIG_PERF_EVENTS
127static int six_hundred_forty_kb = 640 * 1024;
128#endif
Ravikiran G Thirumalaic4f3b632007-10-16 23:26:09 -0700129
Andrea Righi9e4a5bd2009-04-30 15:08:57 -0700130/* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
131static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
134static int maxolduid = 65535;
135static int minolduid;
136
137static int ngroups_max = NGROUPS_MAX;
Dan Ballard73efc032011-10-31 17:11:20 -0700138static const int cap_last_cap = CAP_LAST_CAP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Dmitry Vyukova2e51442018-08-21 21:55:52 -0700140/*
141 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
142 * and hung_task_check_interval_secs
143 */
Liu Hua80df2842014-04-07 15:38:57 -0700144#ifdef CONFIG_DETECT_HUNG_TASK
145static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
146#endif
147
Dave Youngd14f1722010-02-25 20:28:57 -0500148#ifdef CONFIG_INOTIFY_USER
149#include <linux/inotify.h>
150#endif
Vineet Guptab6fca722013-01-09 20:06:28 +0530151
Randy Dunlapd6f8ff72006-10-19 23:28:34 -0700152#ifdef CONFIG_PROC_SYSCTL
Kees Cookf4aacea2014-06-06 14:37:19 -0700153
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700154/**
155 * enum sysctl_writes_mode - supported sysctl write modes
156 *
157 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
Weitao Hou65f50f22019-07-16 16:26:54 -0700158 * to be written, and multiple writes on the same sysctl file descriptor
159 * will rewrite the sysctl value, regardless of file position. No warning
160 * is issued when the initial position is not 0.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700161 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
Weitao Hou65f50f22019-07-16 16:26:54 -0700162 * not 0.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700163 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
Weitao Hou65f50f22019-07-16 16:26:54 -0700164 * file position 0 and the value must be fully contained in the buffer
165 * sent to the write syscall. If dealing with strings respect the file
166 * position, but restrict this to the max length of the buffer, anything
167 * passed the max length will be ignored. Multiple writes will append
168 * to the buffer.
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700169 *
170 * These write modes control how current file position affects the behavior of
171 * updating sysctl values through the proc interface on each write.
172 */
173enum sysctl_writes_mode {
174 SYSCTL_WRITES_LEGACY = -1,
175 SYSCTL_WRITES_WARN = 0,
176 SYSCTL_WRITES_STRICT = 1,
177};
Kees Cookf4aacea2014-06-06 14:37:19 -0700178
Luis R. Rodrigueza19ac332017-07-12 14:33:30 -0700179static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
Christoph Hellwigf461d2d2020-04-24 08:43:37 +0200180#endif /* CONFIG_PROC_SYSCTL */
Luis R. Rodriguezceb18132018-03-10 06:14:51 -0800181
Alexandre Ghiti67f39772019-09-23 15:38:47 -0700182#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
183 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184int sysctl_legacy_va_layout;
185#endif
186
Ingo Molnar77e54a12007-07-09 18:52:00 +0200187#ifdef CONFIG_SCHED_DEBUG
Eric Dumazet73c4efd2007-12-18 15:21:13 +0100188static int min_sched_granularity_ns = 100000; /* 100 usecs */
189static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
190static int min_wakeup_granularity_ns; /* 0 usecs */
191static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200192#ifdef CONFIG_SMP
Christian Ehrhardt1983a922009-11-30 12:16:47 +0100193static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
194static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
Peter Zijlstracbee9f82012-10-25 14:16:43 +0200195#endif /* CONFIG_SMP */
196#endif /* CONFIG_SCHED_DEBUG */
Ingo Molnar77e54a12007-07-09 18:52:00 +0200197
Mel Gorman5e771902010-05-24 14:32:31 -0700198#ifdef CONFIG_COMPACTION
199static int min_extfrag_threshold;
200static int max_extfrag_threshold = 1000;
201#endif
202
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700203#endif /* CONFIG_SYSCTL */
204
Arnd Bergmann5447e8e2020-05-05 16:07:12 +0200205#if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL)
Song Liud46edd62020-04-30 00:15:04 -0700206static int bpf_stats_handler(struct ctl_table *table, int write,
207 void __user *buffer, size_t *lenp,
208 loff_t *ppos)
209{
210 struct static_key *key = (struct static_key *)table->data;
211 static int saved_val;
212 int val, ret;
213 struct ctl_table tmp = {
214 .data = &val,
215 .maxlen = sizeof(val),
216 .mode = table->mode,
217 .extra1 = SYSCTL_ZERO,
218 .extra2 = SYSCTL_ONE,
219 };
220
221 if (write && !capable(CAP_SYS_ADMIN))
222 return -EPERM;
223
224 mutex_lock(&bpf_stats_enabled_mutex);
225 val = saved_val;
226 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
227 if (write && !ret && val != saved_val) {
228 if (val)
229 static_key_slow_inc(key);
230 else
231 static_key_slow_dec(key);
232 saved_val = val;
233 }
234 mutex_unlock(&bpf_stats_enabled_mutex);
235 return ret;
236}
237#endif
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239/*
240 * /proc/sys support
241 */
242
Eric W. Biedermanb89a8172006-09-27 01:51:04 -0700243#ifdef CONFIG_PROC_SYSCTL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Kees Cookf8808302014-06-06 14:37:17 -0700245static int _proc_do_string(char *data, int maxlen, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200246 char *buffer, size_t *lenp, loff_t *ppos)
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700247{
248 size_t len;
Christoph Hellwig32927392020-04-24 08:43:38 +0200249 char c, *p;
Oleg Nesterov8d060872007-02-10 01:46:38 -0800250
251 if (!data || !maxlen || !*lenp) {
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700252 *lenp = 0;
253 return 0;
254 }
Oleg Nesterov8d060872007-02-10 01:46:38 -0800255
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700256 if (write) {
Kees Cookf4aacea2014-06-06 14:37:19 -0700257 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
258 /* Only continue writes not past the end of buffer. */
259 len = strlen(data);
260 if (len > maxlen - 1)
261 len = maxlen - 1;
262
263 if (*ppos > len)
264 return 0;
265 len = *ppos;
266 } else {
267 /* Start writing from beginning of buffer. */
268 len = 0;
269 }
270
Kees Cook2ca9bb42014-06-06 14:37:18 -0700271 *ppos += *lenp;
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700272 p = buffer;
Kees Cook2ca9bb42014-06-06 14:37:18 -0700273 while ((p - buffer) < *lenp && len < maxlen - 1) {
Christoph Hellwig32927392020-04-24 08:43:38 +0200274 c = *(p++);
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700275 if (c == 0 || c == '\n')
276 break;
Kees Cook2ca9bb42014-06-06 14:37:18 -0700277 data[len++] = c;
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700278 }
Kees Cookf8808302014-06-06 14:37:17 -0700279 data[len] = 0;
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700280 } else {
281 len = strlen(data);
282 if (len > maxlen)
283 len = maxlen;
Oleg Nesterov8d060872007-02-10 01:46:38 -0800284
285 if (*ppos > len) {
286 *lenp = 0;
287 return 0;
288 }
289
290 data += *ppos;
291 len -= *ppos;
292
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700293 if (len > *lenp)
294 len = *lenp;
295 if (len)
Christoph Hellwig32927392020-04-24 08:43:38 +0200296 memcpy(buffer, data, len);
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700297 if (len < *lenp) {
Christoph Hellwig32927392020-04-24 08:43:38 +0200298 buffer[len] = '\n';
Sam Vilainf5dd3d62006-10-02 02:18:04 -0700299 len++;
300 }
301 *lenp = len;
302 *ppos += len;
303 }
304 return 0;
305}
306
Kees Cookf4aacea2014-06-06 14:37:19 -0700307static void warn_sysctl_write(struct ctl_table *table)
308{
309 pr_warn_once("%s wrote to %s when file position was not 0!\n"
310 "This will not be supported in the future. To silence this\n"
311 "warning, set kernel.sysctl_writes_strict = -1\n",
312 current->comm, table->procname);
313}
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315/**
Randy Dunlap5f733e82018-08-21 22:01:06 -0700316 * proc_first_pos_non_zero_ignore - check if first position is allowed
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700317 * @ppos: file position
318 * @table: the sysctl table
319 *
320 * Returns true if the first position is non-zero and the sysctl_writes_strict
321 * mode indicates this is not allowed for numeric input types. String proc
Randy Dunlap5f733e82018-08-21 22:01:06 -0700322 * handlers can ignore the return value.
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700323 */
324static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
325 struct ctl_table *table)
326{
327 if (!*ppos)
328 return false;
329
330 switch (sysctl_writes_strict) {
331 case SYSCTL_WRITES_STRICT:
332 return true;
333 case SYSCTL_WRITES_WARN:
334 warn_sysctl_write(table);
335 return false;
336 default:
337 return false;
338 }
339}
340
341/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 * proc_dostring - read a string sysctl
343 * @table: the sysctl table
344 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 * @buffer: the user buffer
346 * @lenp: the size of the user buffer
347 * @ppos: file position
348 *
349 * Reads/writes a string from/to the user buffer. If the kernel
350 * buffer provided is not large enough to hold the string, the
351 * string is truncated. The copied string is %NULL-terminated.
352 * If the string is being read by the user process, it is copied
353 * and a newline '\n' is added. It is truncated if the buffer is
354 * not large enough.
355 *
356 * Returns 0 on success.
357 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700358int proc_dostring(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200359 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700361 if (write)
362 proc_first_pos_non_zero_ignore(ppos, table);
Kees Cookf4aacea2014-06-06 14:37:19 -0700363
Christoph Hellwig32927392020-04-24 08:43:38 +0200364 return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
365 ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366}
367
Amerigo Wang00b7c332010-05-05 00:26:45 +0000368static size_t proc_skip_spaces(char **buf)
369{
370 size_t ret;
371 char *tmp = skip_spaces(*buf);
372 ret = tmp - *buf;
373 *buf = tmp;
374 return ret;
375}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Octavian Purdila9f977fb2010-05-05 00:26:55 +0000377static void proc_skip_char(char **buf, size_t *size, const char v)
378{
379 while (*size) {
380 if (**buf != v)
381 break;
382 (*size)--;
383 (*buf)++;
384 }
385}
386
Christian Brauner7f2923c2019-03-07 16:29:40 -0800387/**
388 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
389 * fail on overflow
390 *
391 * @cp: kernel buffer containing the string to parse
392 * @endp: pointer to store the trailing characters
393 * @base: the base to use
394 * @res: where the parsed integer will be stored
395 *
396 * In case of success 0 is returned and @res will contain the parsed integer,
397 * @endp will hold any trailing characters.
398 * This function will fail the parse on overflow. If there wasn't an overflow
399 * the function will defer the decision what characters count as invalid to the
400 * caller.
401 */
402static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
403 unsigned long *res)
404{
405 unsigned long long result;
406 unsigned int rv;
407
408 cp = _parse_integer_fixup_radix(cp, &base);
409 rv = _parse_integer(cp, base, &result);
410 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
411 return -ERANGE;
412
413 cp += rv;
414
415 if (endp)
416 *endp = (char *)cp;
417
418 *res = (unsigned long)result;
419 return 0;
420}
421
Amerigo Wang00b7c332010-05-05 00:26:45 +0000422#define TMPBUFLEN 22
423/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700424 * proc_get_long - reads an ASCII formatted integer from a user buffer
Amerigo Wang00b7c332010-05-05 00:26:45 +0000425 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700426 * @buf: a kernel buffer
427 * @size: size of the kernel buffer
428 * @val: this is where the number will be stored
429 * @neg: set to %TRUE if number is negative
430 * @perm_tr: a vector which contains the allowed trailers
431 * @perm_tr_len: size of the perm_tr vector
432 * @tr: pointer to store the trailer character
Amerigo Wang00b7c332010-05-05 00:26:45 +0000433 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700434 * In case of success %0 is returned and @buf and @size are updated with
435 * the amount of bytes read. If @tr is non-NULL and a trailing
436 * character exists (size is non-zero after returning from this
437 * function), @tr is updated with the trailing character.
Amerigo Wang00b7c332010-05-05 00:26:45 +0000438 */
439static int proc_get_long(char **buf, size_t *size,
440 unsigned long *val, bool *neg,
441 const char *perm_tr, unsigned perm_tr_len, char *tr)
442{
443 int len;
444 char *p, tmp[TMPBUFLEN];
445
446 if (!*size)
447 return -EINVAL;
448
449 len = *size;
450 if (len > TMPBUFLEN - 1)
451 len = TMPBUFLEN - 1;
452
453 memcpy(tmp, *buf, len);
454
455 tmp[len] = 0;
456 p = tmp;
457 if (*p == '-' && *size > 1) {
458 *neg = true;
459 p++;
460 } else
461 *neg = false;
462 if (!isdigit(*p))
463 return -EINVAL;
464
Christian Brauner7f2923c2019-03-07 16:29:40 -0800465 if (strtoul_lenient(p, &p, 0, val))
466 return -EINVAL;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000467
468 len = p - tmp;
469
470 /* We don't know if the next char is whitespace thus we may accept
471 * invalid integers (e.g. 1234...a) or two integers instead of one
472 * (e.g. 123...1). So lets not allow such large numbers. */
473 if (len == TMPBUFLEN - 1)
474 return -EINVAL;
475
476 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
477 return -EINVAL;
478
479 if (tr && (len < *size))
480 *tr = *p;
481
482 *buf += len;
483 *size -= len;
484
485 return 0;
486}
487
488/**
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700489 * proc_put_long - converts an integer to a decimal ASCII formatted string
Amerigo Wang00b7c332010-05-05 00:26:45 +0000490 *
Randy Dunlap0fc377b2010-05-21 11:29:53 -0700491 * @buf: the user buffer
492 * @size: the size of the user buffer
493 * @val: the integer to be converted
494 * @neg: sign of the number, %TRUE for negative
Amerigo Wang00b7c332010-05-05 00:26:45 +0000495 *
Christoph Hellwig32927392020-04-24 08:43:38 +0200496 * In case of success @buf and @size are updated with the amount of bytes
497 * written.
Amerigo Wang00b7c332010-05-05 00:26:45 +0000498 */
Christoph Hellwig32927392020-04-24 08:43:38 +0200499static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
Amerigo Wang00b7c332010-05-05 00:26:45 +0000500{
501 int len;
502 char tmp[TMPBUFLEN], *p = tmp;
503
504 sprintf(p, "%s%lu", neg ? "-" : "", val);
505 len = strlen(tmp);
506 if (len > *size)
507 len = *size;
Christoph Hellwig32927392020-04-24 08:43:38 +0200508 memcpy(*buf, tmp, len);
Amerigo Wang00b7c332010-05-05 00:26:45 +0000509 *size -= len;
510 *buf += len;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000511}
512#undef TMPBUFLEN
513
Christoph Hellwig32927392020-04-24 08:43:38 +0200514static void proc_put_char(void **buf, size_t *size, char c)
Amerigo Wang00b7c332010-05-05 00:26:45 +0000515{
516 if (*size) {
Christoph Hellwig32927392020-04-24 08:43:38 +0200517 char **buffer = (char **)buf;
518 **buffer = c;
519
520 (*size)--;
521 (*buffer)++;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000522 *buf = *buffer;
523 }
Amerigo Wang00b7c332010-05-05 00:26:45 +0000524}
525
526static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 int *valp,
528 int write, void *data)
529{
530 if (write) {
Heinrich Schuchardt230633d2015-04-16 12:48:07 -0700531 if (*negp) {
532 if (*lvalp > (unsigned long) INT_MAX + 1)
533 return -EINVAL;
534 *valp = -*lvalp;
535 } else {
536 if (*lvalp > (unsigned long) INT_MAX)
537 return -EINVAL;
538 *valp = *lvalp;
539 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 } else {
541 int val = *valp;
542 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +0000543 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -0700544 *lvalp = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +0000546 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 *lvalp = (unsigned long)val;
548 }
549 }
550 return 0;
551}
552
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700553static int do_proc_douintvec_conv(unsigned long *lvalp,
554 unsigned int *valp,
555 int write, void *data)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700556{
557 if (write) {
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700558 if (*lvalp > UINT_MAX)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700559 return -EINVAL;
560 *valp = *lvalp;
561 } else {
562 unsigned int val = *valp;
563 *lvalp = (unsigned long)val;
564 }
565 return 0;
566}
567
Amerigo Wang00b7c332010-05-05 00:26:45 +0000568static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
569
Eric W. Biedermand8217f02007-10-18 03:05:22 -0700570static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200571 int write, void *buffer,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700572 size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +0000573 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 int write, void *data),
575 void *data)
576{
Amerigo Wang00b7c332010-05-05 00:26:45 +0000577 int *i, vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000578 size_t left;
Christoph Hellwig32927392020-04-24 08:43:38 +0200579 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Amerigo Wang00b7c332010-05-05 00:26:45 +0000581 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 *lenp = 0;
583 return 0;
584 }
585
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700586 i = (int *) tbl_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 vleft = table->maxlen / sizeof(*i);
588 left = *lenp;
589
590 if (!conv)
591 conv = do_proc_dointvec_conv;
592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -0700594 if (proc_first_pos_non_zero_ignore(ppos, table))
595 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -0700596
Amerigo Wang00b7c332010-05-05 00:26:45 +0000597 if (left > PAGE_SIZE - 1)
598 left = PAGE_SIZE - 1;
Christoph Hellwig32927392020-04-24 08:43:38 +0200599 p = buffer;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000600 }
601
602 for (; left && vleft--; i++, first=0) {
603 unsigned long lval;
604 bool neg;
605
606 if (write) {
Al Viro70f6cbb2015-12-24 00:13:10 -0500607 left -= proc_skip_spaces(&p);
Amerigo Wang00b7c332010-05-05 00:26:45 +0000608
J. R. Okajima563b0462010-05-25 16:10:14 -0700609 if (!left)
610 break;
Al Viro70f6cbb2015-12-24 00:13:10 -0500611 err = proc_get_long(&p, &left, &lval, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +0000612 proc_wspace_sep,
613 sizeof(proc_wspace_sep), NULL);
614 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000616 if (conv(&neg, &lval, i, 1, data)) {
617 err = -EINVAL;
618 break;
619 }
620 } else {
621 if (conv(&neg, &lval, i, 0, data)) {
622 err = -EINVAL;
623 break;
624 }
625 if (!first)
Christoph Hellwig32927392020-04-24 08:43:38 +0200626 proc_put_char(&buffer, &left, '\t');
627 proc_put_long(&buffer, &left, lval, neg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 }
629 }
Amerigo Wang00b7c332010-05-05 00:26:45 +0000630
631 if (!write && !first && left && !err)
Christoph Hellwig32927392020-04-24 08:43:38 +0200632 proc_put_char(&buffer, &left, '\n');
J. R. Okajima563b0462010-05-25 16:10:14 -0700633 if (write && !err && left)
Al Viro70f6cbb2015-12-24 00:13:10 -0500634 left -= proc_skip_spaces(&p);
Christoph Hellwig32927392020-04-24 08:43:38 +0200635 if (write && first)
636 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -0700638out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +0000640 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641}
642
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700643static int do_proc_dointvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200644 void *buffer, size_t *lenp, loff_t *ppos,
Amerigo Wang00b7c332010-05-05 00:26:45 +0000645 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700646 int write, void *data),
647 void *data)
648{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700649 return __do_proc_dointvec(table->data, table, write,
Kirill Korotaevfcfbd542006-10-02 02:18:23 -0700650 buffer, lenp, ppos, conv, data);
651}
652
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700653static int do_proc_douintvec_w(unsigned int *tbl_data,
654 struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200655 void *buffer,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700656 size_t *lenp, loff_t *ppos,
657 int (*conv)(unsigned long *lvalp,
658 unsigned int *valp,
659 int write, void *data),
660 void *data)
661{
662 unsigned long lval;
663 int err = 0;
664 size_t left;
665 bool neg;
Christoph Hellwig32927392020-04-24 08:43:38 +0200666 char *p = buffer;
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700667
668 left = *lenp;
669
670 if (proc_first_pos_non_zero_ignore(ppos, table))
671 goto bail_early;
672
673 if (left > PAGE_SIZE - 1)
674 left = PAGE_SIZE - 1;
675
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700676 left -= proc_skip_spaces(&p);
677 if (!left) {
678 err = -EINVAL;
679 goto out_free;
680 }
681
682 err = proc_get_long(&p, &left, &lval, &neg,
683 proc_wspace_sep,
684 sizeof(proc_wspace_sep), NULL);
685 if (err || neg) {
686 err = -EINVAL;
687 goto out_free;
688 }
689
690 if (conv(&lval, tbl_data, 1, data)) {
691 err = -EINVAL;
692 goto out_free;
693 }
694
695 if (!err && left)
696 left -= proc_skip_spaces(&p);
697
698out_free:
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700699 if (err)
700 return -EINVAL;
701
702 return 0;
703
704 /* This is in keeping with old __do_proc_dointvec() */
705bail_early:
706 *ppos += *lenp;
707 return err;
708}
709
Christoph Hellwig32927392020-04-24 08:43:38 +0200710static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700711 size_t *lenp, loff_t *ppos,
712 int (*conv)(unsigned long *lvalp,
713 unsigned int *valp,
714 int write, void *data),
715 void *data)
716{
717 unsigned long lval;
718 int err = 0;
719 size_t left;
720
721 left = *lenp;
722
723 if (conv(&lval, tbl_data, 0, data)) {
724 err = -EINVAL;
725 goto out;
726 }
727
Christoph Hellwig32927392020-04-24 08:43:38 +0200728 proc_put_long(&buffer, &left, lval, false);
729 if (!left)
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700730 goto out;
731
Christoph Hellwig32927392020-04-24 08:43:38 +0200732 proc_put_char(&buffer, &left, '\n');
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700733
734out:
735 *lenp -= left;
736 *ppos += *lenp;
737
738 return err;
739}
740
741static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200742 int write, void *buffer,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700743 size_t *lenp, loff_t *ppos,
744 int (*conv)(unsigned long *lvalp,
745 unsigned int *valp,
746 int write, void *data),
747 void *data)
748{
749 unsigned int *i, vleft;
750
751 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
752 *lenp = 0;
753 return 0;
754 }
755
756 i = (unsigned int *) tbl_data;
757 vleft = table->maxlen / sizeof(*i);
758
759 /*
760 * Arrays are not supported, keep this simple. *Do not* add
761 * support for them.
762 */
763 if (vleft != 1) {
764 *lenp = 0;
765 return -EINVAL;
766 }
767
768 if (!conv)
769 conv = do_proc_douintvec_conv;
770
771 if (write)
772 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
773 conv, data);
774 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
775}
776
777static int do_proc_douintvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200778 void *buffer, size_t *lenp, loff_t *ppos,
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700779 int (*conv)(unsigned long *lvalp,
780 unsigned int *valp,
781 int write, void *data),
782 void *data)
783{
784 return __do_proc_douintvec(table->data, table, write,
785 buffer, lenp, ppos, conv, data);
786}
787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788/**
789 * proc_dointvec - read a vector of integers
790 * @table: the sysctl table
791 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 * @buffer: the user buffer
793 * @lenp: the size of the user buffer
794 * @ppos: file position
795 *
796 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
797 * values from/to the user buffer, treated as an ASCII string.
798 *
799 * Returns 0 on success.
800 */
Christoph Hellwig32927392020-04-24 08:43:38 +0200801int proc_dointvec(struct ctl_table *table, int write, void *buffer,
802 size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803{
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700804 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
805}
806
Sebastian Andrzej Siewior6923aa02020-04-01 21:10:42 -0700807#ifdef CONFIG_COMPACTION
808static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
Christoph Hellwig32927392020-04-24 08:43:38 +0200809 int write, void *buffer, size_t *lenp, loff_t *ppos)
Sebastian Andrzej Siewior6923aa02020-04-01 21:10:42 -0700810{
811 int ret, old;
812
813 if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
814 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
815
816 old = *(int *)table->data;
817 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
818 if (ret)
819 return ret;
820 if (old != *(int *)table->data)
821 pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
822 table->procname, current->comm,
823 task_pid_nr(current));
824 return ret;
825}
826#endif
827
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700828/**
829 * proc_douintvec - read a vector of unsigned integers
830 * @table: the sysctl table
831 * @write: %TRUE if this is a write to the sysctl file
832 * @buffer: the user buffer
833 * @lenp: the size of the user buffer
834 * @ppos: file position
835 *
836 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
837 * values from/to the user buffer, treated as an ASCII string.
838 *
839 * Returns 0 on success.
840 */
Christoph Hellwig32927392020-04-24 08:43:38 +0200841int proc_douintvec(struct ctl_table *table, int write, void *buffer,
842 size_t *lenp, loff_t *ppos)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -0700843{
Luis R. Rodriguez4f2fec02017-07-12 14:33:36 -0700844 return do_proc_douintvec(table, write, buffer, lenp, ppos,
845 do_proc_douintvec_conv, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846}
847
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800848/*
Andi Kleen25ddbb12008-10-15 22:01:41 -0700849 * Taint values can only be increased
850 * This means we can safely use a temporary.
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800851 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700852static int proc_taint(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200853 void *buffer, size_t *lenp, loff_t *ppos)
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800854{
Andi Kleen25ddbb12008-10-15 22:01:41 -0700855 struct ctl_table t;
856 unsigned long tmptaint = get_taint();
857 int err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800858
Bastian Blank91fcd412007-04-23 14:41:14 -0700859 if (write && !capable(CAP_SYS_ADMIN))
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800860 return -EPERM;
861
Andi Kleen25ddbb12008-10-15 22:01:41 -0700862 t = *table;
863 t.data = &tmptaint;
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700864 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700865 if (err < 0)
866 return err;
867
868 if (write) {
Rafael Aquinidb38d5c2020-06-07 21:40:17 -0700869 int i;
870
871 /*
872 * If we are relying on panic_on_taint not producing
873 * false positives due to userspace input, bail out
874 * before setting the requested taint flags.
875 */
876 if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
877 return -EINVAL;
878
Andi Kleen25ddbb12008-10-15 22:01:41 -0700879 /*
880 * Poor man's atomic or. Not worth adding a primitive
881 * to everyone's atomic.h for this
882 */
Rafael Aquinie77132e2020-06-07 21:40:51 -0700883 for (i = 0; i < TAINT_FLAGS_COUNT; i++)
884 if ((1UL << i) & tmptaint)
Rusty Russell373d4d02013-01-21 17:17:39 +1030885 add_taint(i, LOCKDEP_STILL_OK);
Andi Kleen25ddbb12008-10-15 22:01:41 -0700886 }
887
888 return err;
Theodore Ts'o34f5a392007-02-10 01:45:24 -0800889}
890
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700891#ifdef CONFIG_PRINTK
Kees Cook620f6e82012-04-04 11:40:19 -0700892static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200893 void *buffer, size_t *lenp, loff_t *ppos)
Richard Weinbergerbfdc0b42011-03-23 16:43:11 -0700894{
895 if (write && !capable(CAP_SYS_ADMIN))
896 return -EPERM;
897
898 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
899}
900#endif
901
Waiman Long24704f32018-04-10 16:35:38 -0700902/**
903 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
904 * @min: pointer to minimum allowable value
905 * @max: pointer to maximum allowable value
906 *
907 * The do_proc_dointvec_minmax_conv_param structure provides the
908 * minimum and maximum values for doing range checking for those sysctl
909 * parameters that use the proc_dointvec_minmax() handler.
910 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911struct do_proc_dointvec_minmax_conv_param {
912 int *min;
913 int *max;
914};
915
Amerigo Wang00b7c332010-05-05 00:26:45 +0000916static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
917 int *valp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 int write, void *data)
919{
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700920 int tmp, ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 struct do_proc_dointvec_minmax_conv_param *param = data;
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700922 /*
923 * If writing, first do so via a temporary local int so we can
924 * bounds-check it before touching *valp.
925 */
926 int *ip = write ? &tmp : valp;
927
928 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
929 if (ret)
930 return ret;
931
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 if (write) {
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700933 if ((param->min && *param->min > tmp) ||
934 (param->max && *param->max < tmp))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 return -EINVAL;
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700936 *valp = tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 }
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 return 0;
940}
941
942/**
943 * proc_dointvec_minmax - read a vector of integers with min/max values
944 * @table: the sysctl table
945 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 * @buffer: the user buffer
947 * @lenp: the size of the user buffer
948 * @ppos: file position
949 *
950 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
951 * values from/to the user buffer, treated as an ASCII string.
952 *
953 * This routine will ensure the values are within the range specified by
954 * table->extra1 (min) and table->extra2 (max).
955 *
Waiman Long24704f32018-04-10 16:35:38 -0700956 * Returns 0 on success or -EINVAL on write when the range check fails.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700958int proc_dointvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +0200959 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960{
961 struct do_proc_dointvec_minmax_conv_param param = {
962 .min = (int *) table->extra1,
963 .max = (int *) table->extra2,
964 };
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700965 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 do_proc_dointvec_minmax_conv, &param);
967}
968
Waiman Long24704f32018-04-10 16:35:38 -0700969/**
970 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
971 * @min: pointer to minimum allowable value
972 * @max: pointer to maximum allowable value
973 *
974 * The do_proc_douintvec_minmax_conv_param structure provides the
975 * minimum and maximum values for doing range checking for those sysctl
976 * parameters that use the proc_douintvec_minmax() handler.
977 */
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -0700978struct do_proc_douintvec_minmax_conv_param {
979 unsigned int *min;
980 unsigned int *max;
981};
982
983static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
984 unsigned int *valp,
985 int write, void *data)
986{
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700987 int ret;
988 unsigned int tmp;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -0700989 struct do_proc_douintvec_minmax_conv_param *param = data;
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700990 /* write via temporary local uint for bounds-checking */
991 unsigned int *up = write ? &tmp : valp;
992
993 ret = do_proc_douintvec_conv(lvalp, up, write, data);
994 if (ret)
995 return ret;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -0700996
997 if (write) {
Zev Weiss2bc4fc62019-03-11 23:28:06 -0700998 if ((param->min && *param->min > tmp) ||
999 (param->max && *param->max < tmp))
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001000 return -ERANGE;
1001
Zev Weiss2bc4fc62019-03-11 23:28:06 -07001002 *valp = tmp;
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001003 }
1004
1005 return 0;
1006}
1007
1008/**
1009 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
1010 * @table: the sysctl table
1011 * @write: %TRUE if this is a write to the sysctl file
1012 * @buffer: the user buffer
1013 * @lenp: the size of the user buffer
1014 * @ppos: file position
1015 *
1016 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
1017 * values from/to the user buffer, treated as an ASCII string. Negative
1018 * strings are not allowed.
1019 *
1020 * This routine will ensure the values are within the range specified by
1021 * table->extra1 (min) and table->extra2 (max). There is a final sanity
1022 * check for UINT_MAX to avoid having to support wrap around uses from
1023 * userspace.
1024 *
Waiman Long24704f32018-04-10 16:35:38 -07001025 * Returns 0 on success or -ERANGE on write when the range check fails.
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001026 */
1027int proc_douintvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001028 void *buffer, size_t *lenp, loff_t *ppos)
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001029{
1030 struct do_proc_douintvec_minmax_conv_param param = {
1031 .min = (unsigned int *) table->extra1,
1032 .max = (unsigned int *) table->extra2,
1033 };
1034 return do_proc_douintvec(table, write, buffer, lenp, ppos,
1035 do_proc_douintvec_minmax_conv, &param);
1036}
1037
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001038static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
1039 unsigned int *valp,
1040 int write, void *data)
1041{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001042 if (write) {
Joe Lawrencefb910c42017-11-17 15:29:28 -08001043 unsigned int val;
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001044
Joe Lawrencefb910c42017-11-17 15:29:28 -08001045 val = round_pipe_size(*lvalp);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001046 if (val == 0)
1047 return -EINVAL;
1048
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001049 *valp = val;
1050 } else {
1051 unsigned int val = *valp;
1052 *lvalp = (unsigned long) val;
1053 }
1054
1055 return 0;
1056}
1057
Eric Biggers319e0a22018-02-06 15:41:49 -08001058static int proc_dopipe_max_size(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001059 void *buffer, size_t *lenp, loff_t *ppos)
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001060{
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001061 return do_proc_douintvec(table, write, buffer, lenp, ppos,
Eric Biggers4c2e4be2018-02-06 15:41:45 -08001062 do_proc_dopipe_max_size_conv, NULL);
Joe Lawrence7a8d1812017-11-17 15:29:24 -08001063}
1064
Kees Cook54b50192012-07-30 14:39:18 -07001065static void validate_coredump_safety(void)
1066{
Alex Kelly046d6622012-10-04 17:15:23 -07001067#ifdef CONFIG_COREDUMP
Kees Cooke579d2c2013-02-27 17:03:15 -08001068 if (suid_dumpable == SUID_DUMP_ROOT &&
Kees Cook54b50192012-07-30 14:39:18 -07001069 core_pattern[0] != '/' && core_pattern[0] != '|') {
Alexey Dobriyan760c6a92016-12-14 15:04:14 -08001070 printk(KERN_WARNING
1071"Unsafe core_pattern used with fs.suid_dumpable=2.\n"
1072"Pipe handler or fully qualified core dump path required.\n"
1073"Set kernel.core_pattern before fs.suid_dumpable.\n"
1074 );
Kees Cook54b50192012-07-30 14:39:18 -07001075 }
Alex Kelly046d6622012-10-04 17:15:23 -07001076#endif
Kees Cook54b50192012-07-30 14:39:18 -07001077}
1078
1079static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001080 void *buffer, size_t *lenp, loff_t *ppos)
Kees Cook54b50192012-07-30 14:39:18 -07001081{
1082 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1083 if (!error)
1084 validate_coredump_safety();
1085 return error;
1086}
1087
Alex Kelly046d6622012-10-04 17:15:23 -07001088#ifdef CONFIG_COREDUMP
Kees Cook54b50192012-07-30 14:39:18 -07001089static int proc_dostring_coredump(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001090 void *buffer, size_t *lenp, loff_t *ppos)
Kees Cook54b50192012-07-30 14:39:18 -07001091{
1092 int error = proc_dostring(table, write, buffer, lenp, ppos);
1093 if (!error)
1094 validate_coredump_safety();
1095 return error;
1096}
Alex Kelly046d6622012-10-04 17:15:23 -07001097#endif
Kees Cook54b50192012-07-30 14:39:18 -07001098
Dmitry Safonoveaee4172020-03-02 17:51:34 +00001099#ifdef CONFIG_MAGIC_SYSRQ
1100static int sysrq_sysctl_handler(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001101 void *buffer, size_t *lenp, loff_t *ppos)
Dmitry Safonoveaee4172020-03-02 17:51:34 +00001102{
1103 int tmp, ret;
1104
1105 tmp = sysrq_mask();
1106
1107 ret = __do_proc_dointvec(&tmp, table, write, buffer,
1108 lenp, ppos, NULL, NULL);
1109 if (ret || !write)
1110 return ret;
1111
1112 if (write)
1113 sysrq_toggle_support(tmp);
1114
1115 return 0;
1116}
1117#endif
1118
Christoph Hellwig32927392020-04-24 08:43:38 +02001119static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
1120 int write, void *buffer, size_t *lenp, loff_t *ppos,
1121 unsigned long convmul, unsigned long convdiv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122{
Amerigo Wang00b7c332010-05-05 00:26:45 +00001123 unsigned long *i, *min, *max;
1124 int vleft, first = 1, err = 0;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001125 size_t left;
Christoph Hellwig32927392020-04-24 08:43:38 +02001126 char *p;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001127
1128 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 *lenp = 0;
1130 return 0;
1131 }
Amerigo Wang00b7c332010-05-05 00:26:45 +00001132
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001133 i = (unsigned long *) data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 min = (unsigned long *) table->extra1;
1135 max = (unsigned long *) table->extra2;
1136 vleft = table->maxlen / sizeof(unsigned long);
1137 left = *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001138
1139 if (write) {
Luis R. Rodriguezd383d482017-07-12 14:33:33 -07001140 if (proc_first_pos_non_zero_ignore(ppos, table))
1141 goto out;
Kees Cookf4aacea2014-06-06 14:37:19 -07001142
Amerigo Wang00b7c332010-05-05 00:26:45 +00001143 if (left > PAGE_SIZE - 1)
1144 left = PAGE_SIZE - 1;
Christoph Hellwig32927392020-04-24 08:43:38 +02001145 p = buffer;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001146 }
1147
Eric Dumazet27b3d802010-10-07 12:59:29 -07001148 for (; left && vleft--; i++, first = 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001149 unsigned long val;
1150
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 if (write) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001152 bool neg;
1153
Al Viro70f6cbb2015-12-24 00:13:10 -05001154 left -= proc_skip_spaces(&p);
Cheng Lin09be1782019-01-03 15:26:13 -08001155 if (!left)
1156 break;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001157
Al Viro70f6cbb2015-12-24 00:13:10 -05001158 err = proc_get_long(&p, &left, &val, &neg,
Amerigo Wang00b7c332010-05-05 00:26:45 +00001159 proc_wspace_sep,
1160 sizeof(proc_wspace_sep), NULL);
1161 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 break;
1163 if (neg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 continue;
Eric Dumazetff9f8a72017-01-25 18:20:55 -08001165 val = convmul * val / convdiv;
Christian Braunere260ad02019-05-14 15:44:55 -07001166 if ((min && val < *min) || (max && val > *max)) {
1167 err = -EINVAL;
1168 break;
1169 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 *i = val;
1171 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001172 val = convdiv * (*i) / convmul;
Christoph Hellwig32927392020-04-24 08:43:38 +02001173 if (!first)
1174 proc_put_char(&buffer, &left, '\t');
1175 proc_put_long(&buffer, &left, val, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 }
1177 }
1178
Amerigo Wang00b7c332010-05-05 00:26:45 +00001179 if (!write && !first && left && !err)
Christoph Hellwig32927392020-04-24 08:43:38 +02001180 proc_put_char(&buffer, &left, '\n');
Amerigo Wang00b7c332010-05-05 00:26:45 +00001181 if (write && !err)
Al Viro70f6cbb2015-12-24 00:13:10 -05001182 left -= proc_skip_spaces(&p);
Christoph Hellwig32927392020-04-24 08:43:38 +02001183 if (write && first)
1184 return err ? : -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 *lenp -= left;
Kees Cookf4aacea2014-06-06 14:37:19 -07001186out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 *ppos += *lenp;
Amerigo Wang00b7c332010-05-05 00:26:45 +00001188 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189}
1190
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001191static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001192 void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1193 unsigned long convdiv)
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001194{
1195 return __do_proc_doulongvec_minmax(table->data, table, write,
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001196 buffer, lenp, ppos, convmul, convdiv);
Kirill Korotaevfcfbd542006-10-02 02:18:23 -07001197}
1198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199/**
1200 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1201 * @table: the sysctl table
1202 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 * @buffer: the user buffer
1204 * @lenp: the size of the user buffer
1205 * @ppos: file position
1206 *
1207 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1208 * values from/to the user buffer, treated as an ASCII string.
1209 *
1210 * This routine will ensure the values are within the range specified by
1211 * table->extra1 (min) and table->extra2 (max).
1212 *
1213 * Returns 0 on success.
1214 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001215int proc_doulongvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001216 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001218 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219}
1220
1221/**
1222 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1223 * @table: the sysctl table
1224 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 * @buffer: the user buffer
1226 * @lenp: the size of the user buffer
1227 * @ppos: file position
1228 *
1229 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1230 * values from/to the user buffer, treated as an ASCII string. The values
1231 * are treated as milliseconds, and converted to jiffies when they are stored.
1232 *
1233 * This routine will ensure the values are within the range specified by
1234 * table->extra1 (min) and table->extra2 (max).
1235 *
1236 * Returns 0 on success.
1237 */
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001238int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001239 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001241 return do_proc_doulongvec_minmax(table, write, buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 lenp, ppos, HZ, 1000l);
1243}
1244
1245
Amerigo Wang00b7c332010-05-05 00:26:45 +00001246static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 int *valp,
1248 int write, void *data)
1249{
1250 if (write) {
Gao Feng63259452017-05-08 15:54:58 -07001251 if (*lvalp > INT_MAX / HZ)
Bart Samwelcba9f332006-03-24 03:15:50 -08001252 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1254 } else {
1255 int val = *valp;
1256 unsigned long lval;
1257 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001258 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07001259 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001261 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 lval = (unsigned long)val;
1263 }
1264 *lvalp = lval / HZ;
1265 }
1266 return 0;
1267}
1268
Amerigo Wang00b7c332010-05-05 00:26:45 +00001269static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 int *valp,
1271 int write, void *data)
1272{
1273 if (write) {
Bart Samwelcba9f332006-03-24 03:15:50 -08001274 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1275 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1277 } else {
1278 int val = *valp;
1279 unsigned long lval;
1280 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001281 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07001282 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001284 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 lval = (unsigned long)val;
1286 }
1287 *lvalp = jiffies_to_clock_t(lval);
1288 }
1289 return 0;
1290}
1291
Amerigo Wang00b7c332010-05-05 00:26:45 +00001292static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 int *valp,
1294 int write, void *data)
1295{
1296 if (write) {
Francesco Fuscod738ce82013-07-24 10:39:07 +02001297 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1298
1299 if (jif > INT_MAX)
1300 return 1;
1301 *valp = (int)jif;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 } else {
1303 int val = *valp;
1304 unsigned long lval;
1305 if (val < 0) {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001306 *negp = true;
Ilya Dryomov9a5bc722015-09-09 15:39:06 -07001307 lval = -(unsigned long)val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 } else {
Amerigo Wang00b7c332010-05-05 00:26:45 +00001309 *negp = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 lval = (unsigned long)val;
1311 }
1312 *lvalp = jiffies_to_msecs(lval);
1313 }
1314 return 0;
1315}
1316
1317/**
1318 * proc_dointvec_jiffies - read a vector of integers as seconds
1319 * @table: the sysctl table
1320 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 * @buffer: the user buffer
1322 * @lenp: the size of the user buffer
1323 * @ppos: file position
1324 *
1325 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1326 * values from/to the user buffer, treated as an ASCII string.
1327 * The values read are assumed to be in seconds, and are converted into
1328 * jiffies.
1329 *
1330 * Returns 0 on success.
1331 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001332int proc_dointvec_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001333 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001335 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 do_proc_dointvec_jiffies_conv,NULL);
1337}
1338
1339/**
1340 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1341 * @table: the sysctl table
1342 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 * @buffer: the user buffer
1344 * @lenp: the size of the user buffer
Randy Dunlap1e5d5332005-11-07 01:01:06 -08001345 * @ppos: pointer to the file position
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 *
1347 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1348 * values from/to the user buffer, treated as an ASCII string.
1349 * The values read are assumed to be in 1/USER_HZ seconds, and
1350 * are converted into jiffies.
1351 *
1352 * Returns 0 on success.
1353 */
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001354int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001355 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001357 return do_proc_dointvec(table,write,buffer,lenp,ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 do_proc_dointvec_userhz_jiffies_conv,NULL);
1359}
1360
1361/**
1362 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1363 * @table: the sysctl table
1364 * @write: %TRUE if this is a write to the sysctl file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 * @buffer: the user buffer
1366 * @lenp: the size of the user buffer
Martin Waitz67be2dd2005-05-01 08:59:26 -07001367 * @ppos: file position
1368 * @ppos: the current position in the file
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 *
1370 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1371 * values from/to the user buffer, treated as an ASCII string.
1372 * The values read are assumed to be in 1/1000 seconds, and
1373 * are converted into jiffies.
1374 *
1375 * Returns 0 on success.
1376 */
Christoph Hellwig32927392020-04-24 08:43:38 +02001377int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
1378 size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379{
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001380 return do_proc_dointvec(table, write, buffer, lenp, ppos,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 do_proc_dointvec_ms_jiffies_conv, NULL);
1382}
1383
Christoph Hellwig32927392020-04-24 08:43:38 +02001384static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
1385 size_t *lenp, loff_t *ppos)
Cedric Le Goater9ec52092006-10-02 02:19:00 -07001386{
1387 struct pid *new_pid;
1388 pid_t tmp;
1389 int r;
1390
Pavel Emelyanov6c5f3e72008-02-08 04:19:20 -08001391 tmp = pid_vnr(cad_pid);
Cedric Le Goater9ec52092006-10-02 02:19:00 -07001392
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001393 r = __do_proc_dointvec(&tmp, table, write, buffer,
Cedric Le Goater9ec52092006-10-02 02:19:00 -07001394 lenp, ppos, NULL, NULL);
1395 if (r || !write)
1396 return r;
1397
1398 new_pid = find_get_pid(tmp);
1399 if (!new_pid)
1400 return -ESRCH;
1401
1402 put_pid(xchg(&cad_pid, new_pid));
1403 return 0;
1404}
1405
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001406/**
1407 * proc_do_large_bitmap - read/write from/to a large bitmap
1408 * @table: the sysctl table
1409 * @write: %TRUE if this is a write to the sysctl file
1410 * @buffer: the user buffer
1411 * @lenp: the size of the user buffer
1412 * @ppos: file position
1413 *
1414 * The bitmap is stored at table->data and the bitmap length (in bits)
1415 * in table->maxlen.
1416 *
1417 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1418 * large bitmaps may be represented in a compact manner. Writing into
1419 * the file will clear the bitmap then update it with the given input.
1420 *
1421 * Returns 0 on success.
1422 */
1423int proc_do_large_bitmap(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001424 void *buffer, size_t *lenp, loff_t *ppos)
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001425{
1426 int err = 0;
1427 bool first = 1;
1428 size_t left = *lenp;
1429 unsigned long bitmap_len = table->maxlen;
WANG Cong122ff242014-05-12 16:04:53 -07001430 unsigned long *bitmap = *(unsigned long **) table->data;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001431 unsigned long *tmp_bitmap = NULL;
1432 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1433
WANG Cong122ff242014-05-12 16:04:53 -07001434 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001435 *lenp = 0;
1436 return 0;
1437 }
1438
1439 if (write) {
Christoph Hellwig32927392020-04-24 08:43:38 +02001440 char *p = buffer;
Eric Sandeen3116ad32019-05-14 15:45:13 -07001441 size_t skipped = 0;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001442
Eric Sandeen3116ad32019-05-14 15:45:13 -07001443 if (left > PAGE_SIZE - 1) {
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001444 left = PAGE_SIZE - 1;
Eric Sandeen3116ad32019-05-14 15:45:13 -07001445 /* How much of the buffer we'll skip this pass */
1446 skipped = *lenp - left;
1447 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001448
Andy Shevchenko475dae32019-05-14 15:44:52 -07001449 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
Christoph Hellwig32927392020-04-24 08:43:38 +02001450 if (!tmp_bitmap)
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001451 return -ENOMEM;
Al Viro70f6cbb2015-12-24 00:13:10 -05001452 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001453 while (!err && left) {
1454 unsigned long val_a, val_b;
1455 bool neg;
Eric Sandeen3116ad32019-05-14 15:45:13 -07001456 size_t saved_left;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001457
Eric Sandeen3116ad32019-05-14 15:45:13 -07001458 /* In case we stop parsing mid-number, we can reset */
1459 saved_left = left;
Al Viro70f6cbb2015-12-24 00:13:10 -05001460 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001461 sizeof(tr_a), &c);
Eric Sandeen3116ad32019-05-14 15:45:13 -07001462 /*
1463 * If we consumed the entirety of a truncated buffer or
1464 * only one char is left (may be a "-"), then stop here,
1465 * reset, & come back for more.
1466 */
1467 if ((left <= 1) && skipped) {
1468 left = saved_left;
1469 break;
1470 }
1471
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001472 if (err)
1473 break;
1474 if (val_a >= bitmap_len || neg) {
1475 err = -EINVAL;
1476 break;
1477 }
1478
1479 val_b = val_a;
1480 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05001481 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001482 left--;
1483 }
1484
1485 if (c == '-') {
Al Viro70f6cbb2015-12-24 00:13:10 -05001486 err = proc_get_long(&p, &left, &val_b,
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001487 &neg, tr_b, sizeof(tr_b),
1488 &c);
Eric Sandeen3116ad32019-05-14 15:45:13 -07001489 /*
1490 * If we consumed all of a truncated buffer or
1491 * then stop here, reset, & come back for more.
1492 */
1493 if (!left && skipped) {
1494 left = saved_left;
1495 break;
1496 }
1497
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001498 if (err)
1499 break;
1500 if (val_b >= bitmap_len || neg ||
1501 val_a > val_b) {
1502 err = -EINVAL;
1503 break;
1504 }
1505 if (left) {
Al Viro70f6cbb2015-12-24 00:13:10 -05001506 p++;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001507 left--;
1508 }
1509 }
1510
Akinobu Mita5a04cca2012-03-28 14:42:50 -07001511 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001512 first = 0;
Al Viro70f6cbb2015-12-24 00:13:10 -05001513 proc_skip_char(&p, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001514 }
Eric Sandeen3116ad32019-05-14 15:45:13 -07001515 left += skipped;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001516 } else {
1517 unsigned long bit_a, bit_b = 0;
1518
1519 while (left) {
1520 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1521 if (bit_a >= bitmap_len)
1522 break;
1523 bit_b = find_next_zero_bit(bitmap, bitmap_len,
1524 bit_a + 1) - 1;
1525
Christoph Hellwig32927392020-04-24 08:43:38 +02001526 if (!first)
1527 proc_put_char(&buffer, &left, ',');
1528 proc_put_long(&buffer, &left, bit_a, false);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001529 if (bit_a != bit_b) {
Christoph Hellwig32927392020-04-24 08:43:38 +02001530 proc_put_char(&buffer, &left, '-');
1531 proc_put_long(&buffer, &left, bit_b, false);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001532 }
1533
1534 first = 0; bit_b++;
1535 }
Christoph Hellwig32927392020-04-24 08:43:38 +02001536 proc_put_char(&buffer, &left, '\n');
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001537 }
1538
1539 if (!err) {
1540 if (write) {
1541 if (*ppos)
1542 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1543 else
Akinobu Mita5a04cca2012-03-28 14:42:50 -07001544 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001545 }
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001546 *lenp -= left;
1547 *ppos += *lenp;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001548 }
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08001549
Andy Shevchenko475dae32019-05-14 15:44:52 -07001550 bitmap_free(tmp_bitmap);
Ola N. Kaldestadf9eb2fd2017-11-17 15:30:26 -08001551 return err;
Octavian Purdila9f977fb2010-05-05 00:26:55 +00001552}
1553
Jovi Zhang55610502011-01-12 17:00:45 -08001554#else /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001556int proc_dostring(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001557 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558{
1559 return -ENOSYS;
1560}
1561
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001562int proc_dointvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001563 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564{
1565 return -ENOSYS;
1566}
1567
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07001568int proc_douintvec(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001569 void *buffer, size_t *lenp, loff_t *ppos)
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07001570{
1571 return -ENOSYS;
1572}
1573
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001574int proc_dointvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001575 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576{
1577 return -ENOSYS;
1578}
1579
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001580int proc_douintvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001581 void *buffer, size_t *lenp, loff_t *ppos)
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07001582{
1583 return -ENOSYS;
1584}
1585
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001586int proc_dointvec_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001587 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588{
1589 return -ENOSYS;
1590}
1591
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001592int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001593 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594{
1595 return -ENOSYS;
1596}
1597
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001598int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001599 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600{
1601 return -ENOSYS;
1602}
1603
Alexey Dobriyan8d65af72009-09-23 15:57:19 -07001604int proc_doulongvec_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001605 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606{
1607 return -ENOSYS;
1608}
1609
Eric W. Biedermand8217f02007-10-18 03:05:22 -07001610int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001611 void *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612{
Christoph Hellwig32927392020-04-24 08:43:38 +02001613 return -ENOSYS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614}
1615
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04001616int proc_do_large_bitmap(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001617 void *buffer, size_t *lenp, loff_t *ppos)
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04001618{
1619 return -ENOSYS;
1620}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621
Jovi Zhang55610502011-01-12 17:00:45 -08001622#endif /* CONFIG_PROC_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001624#if defined(CONFIG_SYSCTL)
1625int proc_do_static_key(struct ctl_table *table, int write,
Christoph Hellwig32927392020-04-24 08:43:38 +02001626 void *buffer, size_t *lenp, loff_t *ppos)
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001627{
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001628 struct static_key *key = (struct static_key *)table->data;
1629 static DEFINE_MUTEX(static_key_mutex);
1630 int val, ret;
1631 struct ctl_table tmp = {
1632 .data = &val,
1633 .maxlen = sizeof(val),
1634 .mode = table->mode,
Matteo Croceeec48442019-07-18 15:58:50 -07001635 .extra1 = SYSCTL_ZERO,
1636 .extra2 = SYSCTL_ONE,
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001637 };
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001638
1639 if (write && !capable(CAP_SYS_ADMIN))
1640 return -EPERM;
1641
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001642 mutex_lock(&static_key_mutex);
1643 val = static_key_enabled(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001644 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1645 if (write && !ret) {
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001646 if (val)
1647 static_key_enable(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001648 else
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001649 static_key_disable(key);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001650 }
Eric Dumazeta8e11e52019-06-14 16:22:18 -07001651 mutex_unlock(&static_key_mutex);
Alexei Starovoitov492ecee2019-02-25 14:28:39 -08001652 return ret;
1653}
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02001654
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655static struct ctl_table kern_table[] = {
1656 {
1657 .procname = "sched_child_runs_first",
1658 .data = &sysctl_sched_child_runs_first,
1659 .maxlen = sizeof(unsigned int),
1660 .mode = 0644,
1661 .proc_handler = proc_dointvec,
1662 },
1663#ifdef CONFIG_SCHED_DEBUG
1664 {
1665 .procname = "sched_min_granularity_ns",
1666 .data = &sysctl_sched_min_granularity,
1667 .maxlen = sizeof(unsigned int),
1668 .mode = 0644,
1669 .proc_handler = sched_proc_update_handler,
1670 .extra1 = &min_sched_granularity_ns,
1671 .extra2 = &max_sched_granularity_ns,
1672 },
1673 {
1674 .procname = "sched_latency_ns",
1675 .data = &sysctl_sched_latency,
1676 .maxlen = sizeof(unsigned int),
1677 .mode = 0644,
1678 .proc_handler = sched_proc_update_handler,
1679 .extra1 = &min_sched_granularity_ns,
1680 .extra2 = &max_sched_granularity_ns,
1681 },
1682 {
1683 .procname = "sched_wakeup_granularity_ns",
1684 .data = &sysctl_sched_wakeup_granularity,
1685 .maxlen = sizeof(unsigned int),
1686 .mode = 0644,
1687 .proc_handler = sched_proc_update_handler,
1688 .extra1 = &min_wakeup_granularity_ns,
1689 .extra2 = &max_wakeup_granularity_ns,
1690 },
1691#ifdef CONFIG_SMP
1692 {
1693 .procname = "sched_tunable_scaling",
1694 .data = &sysctl_sched_tunable_scaling,
1695 .maxlen = sizeof(enum sched_tunable_scaling),
1696 .mode = 0644,
1697 .proc_handler = sched_proc_update_handler,
1698 .extra1 = &min_sched_tunable_scaling,
1699 .extra2 = &max_sched_tunable_scaling,
1700 },
1701 {
1702 .procname = "sched_migration_cost_ns",
1703 .data = &sysctl_sched_migration_cost,
1704 .maxlen = sizeof(unsigned int),
1705 .mode = 0644,
1706 .proc_handler = proc_dointvec,
1707 },
1708 {
1709 .procname = "sched_nr_migrate",
1710 .data = &sysctl_sched_nr_migrate,
1711 .maxlen = sizeof(unsigned int),
1712 .mode = 0644,
1713 .proc_handler = proc_dointvec,
1714 },
1715#ifdef CONFIG_SCHEDSTATS
1716 {
1717 .procname = "sched_schedstats",
1718 .data = NULL,
1719 .maxlen = sizeof(unsigned int),
1720 .mode = 0644,
1721 .proc_handler = sysctl_schedstats,
1722 .extra1 = SYSCTL_ZERO,
1723 .extra2 = SYSCTL_ONE,
1724 },
1725#endif /* CONFIG_SCHEDSTATS */
1726#endif /* CONFIG_SMP */
1727#ifdef CONFIG_NUMA_BALANCING
1728 {
1729 .procname = "numa_balancing_scan_delay_ms",
1730 .data = &sysctl_numa_balancing_scan_delay,
1731 .maxlen = sizeof(unsigned int),
1732 .mode = 0644,
1733 .proc_handler = proc_dointvec,
1734 },
1735 {
1736 .procname = "numa_balancing_scan_period_min_ms",
1737 .data = &sysctl_numa_balancing_scan_period_min,
1738 .maxlen = sizeof(unsigned int),
1739 .mode = 0644,
1740 .proc_handler = proc_dointvec,
1741 },
1742 {
1743 .procname = "numa_balancing_scan_period_max_ms",
1744 .data = &sysctl_numa_balancing_scan_period_max,
1745 .maxlen = sizeof(unsigned int),
1746 .mode = 0644,
1747 .proc_handler = proc_dointvec,
1748 },
1749 {
1750 .procname = "numa_balancing_scan_size_mb",
1751 .data = &sysctl_numa_balancing_scan_size,
1752 .maxlen = sizeof(unsigned int),
1753 .mode = 0644,
1754 .proc_handler = proc_dointvec_minmax,
1755 .extra1 = SYSCTL_ONE,
1756 },
1757 {
1758 .procname = "numa_balancing",
1759 .data = NULL, /* filled in by handler */
1760 .maxlen = sizeof(unsigned int),
1761 .mode = 0644,
1762 .proc_handler = sysctl_numa_balancing,
1763 .extra1 = SYSCTL_ZERO,
1764 .extra2 = SYSCTL_ONE,
1765 },
1766#endif /* CONFIG_NUMA_BALANCING */
1767#endif /* CONFIG_SCHED_DEBUG */
1768 {
1769 .procname = "sched_rt_period_us",
1770 .data = &sysctl_sched_rt_period,
1771 .maxlen = sizeof(unsigned int),
1772 .mode = 0644,
1773 .proc_handler = sched_rt_handler,
1774 },
1775 {
1776 .procname = "sched_rt_runtime_us",
1777 .data = &sysctl_sched_rt_runtime,
1778 .maxlen = sizeof(int),
1779 .mode = 0644,
1780 .proc_handler = sched_rt_handler,
1781 },
1782 {
1783 .procname = "sched_rr_timeslice_ms",
1784 .data = &sysctl_sched_rr_timeslice,
1785 .maxlen = sizeof(int),
1786 .mode = 0644,
1787 .proc_handler = sched_rr_handler,
1788 },
1789#ifdef CONFIG_UCLAMP_TASK
1790 {
1791 .procname = "sched_util_clamp_min",
1792 .data = &sysctl_sched_uclamp_util_min,
1793 .maxlen = sizeof(unsigned int),
1794 .mode = 0644,
1795 .proc_handler = sysctl_sched_uclamp_handler,
1796 },
1797 {
1798 .procname = "sched_util_clamp_max",
1799 .data = &sysctl_sched_uclamp_util_max,
1800 .maxlen = sizeof(unsigned int),
1801 .mode = 0644,
1802 .proc_handler = sysctl_sched_uclamp_handler,
1803 },
1804#endif
1805#ifdef CONFIG_SCHED_AUTOGROUP
1806 {
1807 .procname = "sched_autogroup_enabled",
1808 .data = &sysctl_sched_autogroup_enabled,
1809 .maxlen = sizeof(unsigned int),
1810 .mode = 0644,
1811 .proc_handler = proc_dointvec_minmax,
1812 .extra1 = SYSCTL_ZERO,
1813 .extra2 = SYSCTL_ONE,
1814 },
1815#endif
1816#ifdef CONFIG_CFS_BANDWIDTH
1817 {
1818 .procname = "sched_cfs_bandwidth_slice_us",
1819 .data = &sysctl_sched_cfs_bandwidth_slice,
1820 .maxlen = sizeof(unsigned int),
1821 .mode = 0644,
1822 .proc_handler = proc_dointvec_minmax,
1823 .extra1 = SYSCTL_ONE,
1824 },
1825#endif
1826#if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
1827 {
1828 .procname = "sched_energy_aware",
1829 .data = &sysctl_sched_energy_aware,
1830 .maxlen = sizeof(unsigned int),
1831 .mode = 0644,
1832 .proc_handler = sched_energy_aware_handler,
1833 .extra1 = SYSCTL_ZERO,
1834 .extra2 = SYSCTL_ONE,
1835 },
1836#endif
1837#ifdef CONFIG_PROVE_LOCKING
1838 {
1839 .procname = "prove_locking",
1840 .data = &prove_locking,
1841 .maxlen = sizeof(int),
1842 .mode = 0644,
1843 .proc_handler = proc_dointvec,
1844 },
1845#endif
1846#ifdef CONFIG_LOCK_STAT
1847 {
1848 .procname = "lock_stat",
1849 .data = &lock_stat,
1850 .maxlen = sizeof(int),
1851 .mode = 0644,
1852 .proc_handler = proc_dointvec,
1853 },
1854#endif
1855 {
1856 .procname = "panic",
1857 .data = &panic_timeout,
1858 .maxlen = sizeof(int),
1859 .mode = 0644,
1860 .proc_handler = proc_dointvec,
1861 },
1862#ifdef CONFIG_COREDUMP
1863 {
1864 .procname = "core_uses_pid",
1865 .data = &core_uses_pid,
1866 .maxlen = sizeof(int),
1867 .mode = 0644,
1868 .proc_handler = proc_dointvec,
1869 },
1870 {
1871 .procname = "core_pattern",
1872 .data = core_pattern,
1873 .maxlen = CORENAME_MAX_SIZE,
1874 .mode = 0644,
1875 .proc_handler = proc_dostring_coredump,
1876 },
1877 {
1878 .procname = "core_pipe_limit",
1879 .data = &core_pipe_limit,
1880 .maxlen = sizeof(unsigned int),
1881 .mode = 0644,
1882 .proc_handler = proc_dointvec,
1883 },
1884#endif
1885#ifdef CONFIG_PROC_SYSCTL
1886 {
1887 .procname = "tainted",
1888 .maxlen = sizeof(long),
1889 .mode = 0644,
1890 .proc_handler = proc_taint,
1891 },
1892 {
1893 .procname = "sysctl_writes_strict",
1894 .data = &sysctl_writes_strict,
1895 .maxlen = sizeof(int),
1896 .mode = 0644,
1897 .proc_handler = proc_dointvec_minmax,
1898 .extra1 = &neg_one,
1899 .extra2 = SYSCTL_ONE,
1900 },
1901#endif
1902#ifdef CONFIG_LATENCYTOP
1903 {
1904 .procname = "latencytop",
1905 .data = &latencytop_enabled,
1906 .maxlen = sizeof(int),
1907 .mode = 0644,
1908 .proc_handler = sysctl_latencytop,
1909 },
1910#endif
1911#ifdef CONFIG_BLK_DEV_INITRD
1912 {
1913 .procname = "real-root-dev",
1914 .data = &real_root_dev,
1915 .maxlen = sizeof(int),
1916 .mode = 0644,
1917 .proc_handler = proc_dointvec,
1918 },
1919#endif
1920 {
1921 .procname = "print-fatal-signals",
1922 .data = &print_fatal_signals,
1923 .maxlen = sizeof(int),
1924 .mode = 0644,
1925 .proc_handler = proc_dointvec,
1926 },
1927#ifdef CONFIG_SPARC
1928 {
1929 .procname = "reboot-cmd",
1930 .data = reboot_command,
1931 .maxlen = 256,
1932 .mode = 0644,
1933 .proc_handler = proc_dostring,
1934 },
1935 {
1936 .procname = "stop-a",
1937 .data = &stop_a_enabled,
1938 .maxlen = sizeof (int),
1939 .mode = 0644,
1940 .proc_handler = proc_dointvec,
1941 },
1942 {
1943 .procname = "scons-poweroff",
1944 .data = &scons_pwroff,
1945 .maxlen = sizeof (int),
1946 .mode = 0644,
1947 .proc_handler = proc_dointvec,
1948 },
1949#endif
1950#ifdef CONFIG_SPARC64
1951 {
1952 .procname = "tsb-ratio",
1953 .data = &sysctl_tsb_ratio,
1954 .maxlen = sizeof (int),
1955 .mode = 0644,
1956 .proc_handler = proc_dointvec,
1957 },
1958#endif
1959#ifdef CONFIG_PARISC
1960 {
1961 .procname = "soft-power",
1962 .data = &pwrsw_enabled,
1963 .maxlen = sizeof (int),
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02001964 .mode = 0644,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 .proc_handler = proc_dointvec,
1966 },
1967#endif
1968#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
1969 {
1970 .procname = "unaligned-trap",
1971 .data = &unaligned_enabled,
1972 .maxlen = sizeof (int),
1973 .mode = 0644,
1974 .proc_handler = proc_dointvec,
1975 },
1976#endif
1977 {
1978 .procname = "ctrl-alt-del",
1979 .data = &C_A_D,
1980 .maxlen = sizeof(int),
1981 .mode = 0644,
1982 .proc_handler = proc_dointvec,
1983 },
1984#ifdef CONFIG_FUNCTION_TRACER
1985 {
1986 .procname = "ftrace_enabled",
1987 .data = &ftrace_enabled,
1988 .maxlen = sizeof(int),
1989 .mode = 0644,
1990 .proc_handler = ftrace_enable_sysctl,
1991 },
1992#endif
1993#ifdef CONFIG_STACK_TRACER
1994 {
1995 .procname = "stack_tracer_enabled",
1996 .data = &stack_tracer_enabled,
1997 .maxlen = sizeof(int),
1998 .mode = 0644,
1999 .proc_handler = stack_trace_sysctl,
2000 },
2001#endif
2002#ifdef CONFIG_TRACING
2003 {
2004 .procname = "ftrace_dump_on_oops",
2005 .data = &ftrace_dump_on_oops,
2006 .maxlen = sizeof(int),
2007 .mode = 0644,
2008 .proc_handler = proc_dointvec,
2009 },
2010 {
2011 .procname = "traceoff_on_warning",
2012 .data = &__disable_trace_on_warning,
2013 .maxlen = sizeof(__disable_trace_on_warning),
2014 .mode = 0644,
2015 .proc_handler = proc_dointvec,
2016 },
2017 {
2018 .procname = "tracepoint_printk",
2019 .data = &tracepoint_printk,
2020 .maxlen = sizeof(tracepoint_printk),
2021 .mode = 0644,
2022 .proc_handler = tracepoint_printk_sysctl,
2023 },
2024#endif
2025#ifdef CONFIG_KEXEC_CORE
2026 {
2027 .procname = "kexec_load_disabled",
2028 .data = &kexec_load_disabled,
2029 .maxlen = sizeof(int),
2030 .mode = 0644,
2031 /* only handle a transition from default "0" to "1" */
2032 .proc_handler = proc_dointvec_minmax,
2033 .extra1 = SYSCTL_ONE,
2034 .extra2 = SYSCTL_ONE,
2035 },
2036#endif
2037#ifdef CONFIG_MODULES
2038 {
2039 .procname = "modprobe",
2040 .data = &modprobe_path,
2041 .maxlen = KMOD_PATH_LEN,
2042 .mode = 0644,
2043 .proc_handler = proc_dostring,
2044 },
2045 {
2046 .procname = "modules_disabled",
2047 .data = &modules_disabled,
2048 .maxlen = sizeof(int),
2049 .mode = 0644,
2050 /* only handle a transition from default "0" to "1" */
2051 .proc_handler = proc_dointvec_minmax,
2052 .extra1 = SYSCTL_ONE,
2053 .extra2 = SYSCTL_ONE,
2054 },
2055#endif
2056#ifdef CONFIG_UEVENT_HELPER
2057 {
2058 .procname = "hotplug",
2059 .data = &uevent_helper,
2060 .maxlen = UEVENT_HELPER_PATH_LEN,
2061 .mode = 0644,
2062 .proc_handler = proc_dostring,
2063 },
2064#endif
2065#ifdef CONFIG_CHR_DEV_SG
2066 {
2067 .procname = "sg-big-buff",
2068 .data = &sg_big_buff,
2069 .maxlen = sizeof (int),
2070 .mode = 0444,
2071 .proc_handler = proc_dointvec,
2072 },
2073#endif
2074#ifdef CONFIG_BSD_PROCESS_ACCT
2075 {
2076 .procname = "acct",
2077 .data = &acct_parm,
2078 .maxlen = 3*sizeof(int),
2079 .mode = 0644,
2080 .proc_handler = proc_dointvec,
2081 },
2082#endif
2083#ifdef CONFIG_MAGIC_SYSRQ
2084 {
2085 .procname = "sysrq",
2086 .data = NULL,
2087 .maxlen = sizeof (int),
2088 .mode = 0644,
2089 .proc_handler = sysrq_sysctl_handler,
2090 },
2091#endif
2092#ifdef CONFIG_PROC_SYSCTL
2093 {
2094 .procname = "cad_pid",
2095 .data = NULL,
2096 .maxlen = sizeof (int),
2097 .mode = 0600,
2098 .proc_handler = proc_do_cad_pid,
2099 },
2100#endif
2101 {
2102 .procname = "threads-max",
2103 .data = NULL,
2104 .maxlen = sizeof(int),
2105 .mode = 0644,
2106 .proc_handler = sysctl_max_threads,
2107 },
2108 {
2109 .procname = "random",
2110 .mode = 0555,
2111 .child = random_table,
2112 },
2113 {
2114 .procname = "usermodehelper",
2115 .mode = 0555,
2116 .child = usermodehelper_table,
2117 },
2118#ifdef CONFIG_FW_LOADER_USER_HELPER
2119 {
2120 .procname = "firmware_config",
2121 .mode = 0555,
2122 .child = firmware_config_table,
2123 },
2124#endif
2125 {
2126 .procname = "overflowuid",
2127 .data = &overflowuid,
2128 .maxlen = sizeof(int),
2129 .mode = 0644,
2130 .proc_handler = proc_dointvec_minmax,
2131 .extra1 = &minolduid,
2132 .extra2 = &maxolduid,
2133 },
2134 {
2135 .procname = "overflowgid",
2136 .data = &overflowgid,
2137 .maxlen = sizeof(int),
2138 .mode = 0644,
2139 .proc_handler = proc_dointvec_minmax,
2140 .extra1 = &minolduid,
2141 .extra2 = &maxolduid,
2142 },
2143#ifdef CONFIG_S390
2144 {
2145 .procname = "userprocess_debug",
2146 .data = &show_unhandled_signals,
2147 .maxlen = sizeof(int),
2148 .mode = 0644,
2149 .proc_handler = proc_dointvec,
2150 },
2151#endif
Guilherme G. Piccoli60c958d2020-06-07 21:40:48 -07002152#ifdef CONFIG_SMP
2153 {
2154 .procname = "oops_all_cpu_backtrace",
2155 .data = &sysctl_oops_all_cpu_backtrace,
2156 .maxlen = sizeof(int),
2157 .mode = 0644,
2158 .proc_handler = proc_dointvec_minmax,
2159 .extra1 = SYSCTL_ZERO,
2160 .extra2 = SYSCTL_ONE,
2161 },
2162#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 {
2164 .procname = "pid_max",
2165 .data = &pid_max,
2166 .maxlen = sizeof (int),
2167 .mode = 0644,
2168 .proc_handler = proc_dointvec_minmax,
2169 .extra1 = &pid_max_min,
2170 .extra2 = &pid_max_max,
2171 },
2172 {
2173 .procname = "panic_on_oops",
2174 .data = &panic_on_oops,
2175 .maxlen = sizeof(int),
2176 .mode = 0644,
2177 .proc_handler = proc_dointvec,
2178 },
2179 {
2180 .procname = "panic_print",
2181 .data = &panic_print,
2182 .maxlen = sizeof(unsigned long),
2183 .mode = 0644,
2184 .proc_handler = proc_doulongvec_minmax,
2185 },
2186#if defined CONFIG_PRINTK
2187 {
2188 .procname = "printk",
2189 .data = &console_loglevel,
2190 .maxlen = 4*sizeof(int),
2191 .mode = 0644,
2192 .proc_handler = proc_dointvec,
2193 },
2194 {
2195 .procname = "printk_ratelimit",
2196 .data = &printk_ratelimit_state.interval,
2197 .maxlen = sizeof(int),
2198 .mode = 0644,
2199 .proc_handler = proc_dointvec_jiffies,
2200 },
2201 {
2202 .procname = "printk_ratelimit_burst",
2203 .data = &printk_ratelimit_state.burst,
2204 .maxlen = sizeof(int),
2205 .mode = 0644,
2206 .proc_handler = proc_dointvec,
2207 },
2208 {
2209 .procname = "printk_delay",
2210 .data = &printk_delay_msec,
2211 .maxlen = sizeof(int),
2212 .mode = 0644,
2213 .proc_handler = proc_dointvec_minmax,
2214 .extra1 = SYSCTL_ZERO,
2215 .extra2 = &ten_thousand,
2216 },
2217 {
2218 .procname = "printk_devkmsg",
2219 .data = devkmsg_log_str,
2220 .maxlen = DEVKMSG_STR_MAX_SIZE,
2221 .mode = 0644,
2222 .proc_handler = devkmsg_sysctl_set_loglvl,
2223 },
2224 {
2225 .procname = "dmesg_restrict",
2226 .data = &dmesg_restrict,
2227 .maxlen = sizeof(int),
2228 .mode = 0644,
2229 .proc_handler = proc_dointvec_minmax_sysadmin,
2230 .extra1 = SYSCTL_ZERO,
2231 .extra2 = SYSCTL_ONE,
2232 },
2233 {
2234 .procname = "kptr_restrict",
2235 .data = &kptr_restrict,
2236 .maxlen = sizeof(int),
2237 .mode = 0644,
2238 .proc_handler = proc_dointvec_minmax_sysadmin,
2239 .extra1 = SYSCTL_ZERO,
2240 .extra2 = &two,
2241 },
2242#endif
2243 {
2244 .procname = "ngroups_max",
2245 .data = &ngroups_max,
2246 .maxlen = sizeof (int),
2247 .mode = 0444,
2248 .proc_handler = proc_dointvec,
2249 },
2250 {
2251 .procname = "cap_last_cap",
2252 .data = (void *)&cap_last_cap,
2253 .maxlen = sizeof(int),
2254 .mode = 0444,
2255 .proc_handler = proc_dointvec,
2256 },
2257#if defined(CONFIG_LOCKUP_DETECTOR)
2258 {
2259 .procname = "watchdog",
2260 .data = &watchdog_user_enabled,
2261 .maxlen = sizeof(int),
2262 .mode = 0644,
2263 .proc_handler = proc_watchdog,
2264 .extra1 = SYSCTL_ZERO,
2265 .extra2 = SYSCTL_ONE,
2266 },
2267 {
2268 .procname = "watchdog_thresh",
2269 .data = &watchdog_thresh,
2270 .maxlen = sizeof(int),
2271 .mode = 0644,
2272 .proc_handler = proc_watchdog_thresh,
2273 .extra1 = SYSCTL_ZERO,
2274 .extra2 = &sixty,
2275 },
2276 {
2277 .procname = "nmi_watchdog",
2278 .data = &nmi_watchdog_user_enabled,
2279 .maxlen = sizeof(int),
2280 .mode = NMI_WATCHDOG_SYSCTL_PERM,
2281 .proc_handler = proc_nmi_watchdog,
2282 .extra1 = SYSCTL_ZERO,
2283 .extra2 = SYSCTL_ONE,
2284 },
2285 {
2286 .procname = "watchdog_cpumask",
2287 .data = &watchdog_cpumask_bits,
2288 .maxlen = NR_CPUS,
2289 .mode = 0644,
2290 .proc_handler = proc_watchdog_cpumask,
2291 },
2292#ifdef CONFIG_SOFTLOCKUP_DETECTOR
2293 {
2294 .procname = "soft_watchdog",
2295 .data = &soft_watchdog_user_enabled,
2296 .maxlen = sizeof(int),
2297 .mode = 0644,
2298 .proc_handler = proc_soft_watchdog,
2299 .extra1 = SYSCTL_ZERO,
2300 .extra2 = SYSCTL_ONE,
2301 },
2302 {
2303 .procname = "softlockup_panic",
2304 .data = &softlockup_panic,
2305 .maxlen = sizeof(int),
2306 .mode = 0644,
2307 .proc_handler = proc_dointvec_minmax,
2308 .extra1 = SYSCTL_ZERO,
2309 .extra2 = SYSCTL_ONE,
2310 },
2311#ifdef CONFIG_SMP
2312 {
2313 .procname = "softlockup_all_cpu_backtrace",
2314 .data = &sysctl_softlockup_all_cpu_backtrace,
2315 .maxlen = sizeof(int),
2316 .mode = 0644,
2317 .proc_handler = proc_dointvec_minmax,
2318 .extra1 = SYSCTL_ZERO,
2319 .extra2 = SYSCTL_ONE,
2320 },
2321#endif /* CONFIG_SMP */
2322#endif
2323#ifdef CONFIG_HARDLOCKUP_DETECTOR
2324 {
2325 .procname = "hardlockup_panic",
2326 .data = &hardlockup_panic,
2327 .maxlen = sizeof(int),
2328 .mode = 0644,
2329 .proc_handler = proc_dointvec_minmax,
2330 .extra1 = SYSCTL_ZERO,
2331 .extra2 = SYSCTL_ONE,
2332 },
2333#ifdef CONFIG_SMP
2334 {
2335 .procname = "hardlockup_all_cpu_backtrace",
2336 .data = &sysctl_hardlockup_all_cpu_backtrace,
2337 .maxlen = sizeof(int),
2338 .mode = 0644,
2339 .proc_handler = proc_dointvec_minmax,
2340 .extra1 = SYSCTL_ZERO,
2341 .extra2 = SYSCTL_ONE,
2342 },
2343#endif /* CONFIG_SMP */
2344#endif
2345#endif
2346
2347#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
2348 {
2349 .procname = "unknown_nmi_panic",
2350 .data = &unknown_nmi_panic,
2351 .maxlen = sizeof (int),
2352 .mode = 0644,
2353 .proc_handler = proc_dointvec,
2354 },
2355#endif
Xiaoming Nib6522fa2020-04-11 21:06:19 +08002356
2357#if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
2358 defined(CONFIG_DEBUG_STACKOVERFLOW)
2359 {
2360 .procname = "panic_on_stackoverflow",
2361 .data = &sysctl_panic_on_stackoverflow,
2362 .maxlen = sizeof(int),
2363 .mode = 0644,
2364 .proc_handler = proc_dointvec,
2365 },
2366#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367#if defined(CONFIG_X86)
2368 {
2369 .procname = "panic_on_unrecovered_nmi",
2370 .data = &panic_on_unrecovered_nmi,
2371 .maxlen = sizeof(int),
2372 .mode = 0644,
2373 .proc_handler = proc_dointvec,
2374 },
2375 {
2376 .procname = "panic_on_io_nmi",
2377 .data = &panic_on_io_nmi,
2378 .maxlen = sizeof(int),
2379 .mode = 0644,
2380 .proc_handler = proc_dointvec,
2381 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 {
2383 .procname = "bootloader_type",
2384 .data = &bootloader_type,
2385 .maxlen = sizeof (int),
2386 .mode = 0444,
2387 .proc_handler = proc_dointvec,
2388 },
2389 {
2390 .procname = "bootloader_version",
2391 .data = &bootloader_version,
2392 .maxlen = sizeof (int),
2393 .mode = 0444,
2394 .proc_handler = proc_dointvec,
2395 },
2396 {
2397 .procname = "io_delay_type",
2398 .data = &io_delay_type,
2399 .maxlen = sizeof(int),
2400 .mode = 0644,
2401 .proc_handler = proc_dointvec,
2402 },
2403#endif
2404#if defined(CONFIG_MMU)
2405 {
2406 .procname = "randomize_va_space",
2407 .data = &randomize_va_space,
2408 .maxlen = sizeof(int),
2409 .mode = 0644,
2410 .proc_handler = proc_dointvec,
2411 },
2412#endif
2413#if defined(CONFIG_S390) && defined(CONFIG_SMP)
2414 {
2415 .procname = "spin_retry",
2416 .data = &spin_retry,
2417 .maxlen = sizeof (int),
2418 .mode = 0644,
2419 .proc_handler = proc_dointvec,
2420 },
2421#endif
2422#if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
2423 {
2424 .procname = "acpi_video_flags",
2425 .data = &acpi_realmode_flags,
2426 .maxlen = sizeof (unsigned long),
2427 .mode = 0644,
2428 .proc_handler = proc_doulongvec_minmax,
2429 },
2430#endif
2431#ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
2432 {
2433 .procname = "ignore-unaligned-usertrap",
2434 .data = &no_unaligned_warning,
2435 .maxlen = sizeof (int),
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02002436 .mode = 0644,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 .proc_handler = proc_dointvec,
2438 },
2439#endif
2440#ifdef CONFIG_IA64
2441 {
2442 .procname = "unaligned-dump-stack",
2443 .data = &unaligned_dump_stack,
2444 .maxlen = sizeof (int),
2445 .mode = 0644,
2446 .proc_handler = proc_dointvec,
2447 },
2448#endif
2449#ifdef CONFIG_DETECT_HUNG_TASK
Guilherme G. Piccoli0ec9dc92020-06-07 21:40:45 -07002450#ifdef CONFIG_SMP
2451 {
2452 .procname = "hung_task_all_cpu_backtrace",
2453 .data = &sysctl_hung_task_all_cpu_backtrace,
2454 .maxlen = sizeof(int),
2455 .mode = 0644,
2456 .proc_handler = proc_dointvec_minmax,
2457 .extra1 = SYSCTL_ZERO,
2458 .extra2 = SYSCTL_ONE,
2459 },
2460#endif /* CONFIG_SMP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 {
2462 .procname = "hung_task_panic",
2463 .data = &sysctl_hung_task_panic,
2464 .maxlen = sizeof(int),
2465 .mode = 0644,
2466 .proc_handler = proc_dointvec_minmax,
2467 .extra1 = SYSCTL_ZERO,
2468 .extra2 = SYSCTL_ONE,
2469 },
2470 {
2471 .procname = "hung_task_check_count",
2472 .data = &sysctl_hung_task_check_count,
2473 .maxlen = sizeof(int),
2474 .mode = 0644,
2475 .proc_handler = proc_dointvec_minmax,
2476 .extra1 = SYSCTL_ZERO,
2477 },
2478 {
2479 .procname = "hung_task_timeout_secs",
2480 .data = &sysctl_hung_task_timeout_secs,
2481 .maxlen = sizeof(unsigned long),
2482 .mode = 0644,
2483 .proc_handler = proc_dohung_task_timeout_secs,
2484 .extra2 = &hung_task_timeout_max,
2485 },
2486 {
2487 .procname = "hung_task_check_interval_secs",
2488 .data = &sysctl_hung_task_check_interval_secs,
2489 .maxlen = sizeof(unsigned long),
2490 .mode = 0644,
2491 .proc_handler = proc_dohung_task_timeout_secs,
2492 .extra2 = &hung_task_timeout_max,
2493 },
2494 {
2495 .procname = "hung_task_warnings",
2496 .data = &sysctl_hung_task_warnings,
2497 .maxlen = sizeof(int),
2498 .mode = 0644,
2499 .proc_handler = proc_dointvec_minmax,
2500 .extra1 = &neg_one,
2501 },
2502#endif
2503#ifdef CONFIG_RT_MUTEXES
2504 {
2505 .procname = "max_lock_depth",
2506 .data = &max_lock_depth,
2507 .maxlen = sizeof(int),
2508 .mode = 0644,
2509 .proc_handler = proc_dointvec,
2510 },
2511#endif
2512 {
2513 .procname = "poweroff_cmd",
2514 .data = &poweroff_cmd,
2515 .maxlen = POWEROFF_CMD_PATH_LEN,
2516 .mode = 0644,
2517 .proc_handler = proc_dostring,
2518 },
2519#ifdef CONFIG_KEYS
2520 {
2521 .procname = "keys",
2522 .mode = 0555,
2523 .child = key_sysctls,
2524 },
2525#endif
2526#ifdef CONFIG_PERF_EVENTS
2527 /*
2528 * User-space scripts rely on the existence of this file
2529 * as a feature check for perf_events being enabled.
2530 *
2531 * So it's an ABI, do not remove!
2532 */
2533 {
2534 .procname = "perf_event_paranoid",
2535 .data = &sysctl_perf_event_paranoid,
2536 .maxlen = sizeof(sysctl_perf_event_paranoid),
2537 .mode = 0644,
2538 .proc_handler = proc_dointvec,
2539 },
2540 {
2541 .procname = "perf_event_mlock_kb",
2542 .data = &sysctl_perf_event_mlock,
2543 .maxlen = sizeof(sysctl_perf_event_mlock),
2544 .mode = 0644,
2545 .proc_handler = proc_dointvec,
2546 },
2547 {
2548 .procname = "perf_event_max_sample_rate",
2549 .data = &sysctl_perf_event_sample_rate,
2550 .maxlen = sizeof(sysctl_perf_event_sample_rate),
2551 .mode = 0644,
2552 .proc_handler = perf_proc_update_handler,
2553 .extra1 = SYSCTL_ONE,
2554 },
2555 {
2556 .procname = "perf_cpu_time_max_percent",
2557 .data = &sysctl_perf_cpu_time_max_percent,
2558 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
2559 .mode = 0644,
2560 .proc_handler = perf_cpu_time_max_percent_handler,
2561 .extra1 = SYSCTL_ZERO,
2562 .extra2 = &one_hundred,
2563 },
2564 {
2565 .procname = "perf_event_max_stack",
2566 .data = &sysctl_perf_event_max_stack,
2567 .maxlen = sizeof(sysctl_perf_event_max_stack),
2568 .mode = 0644,
2569 .proc_handler = perf_event_max_stack_handler,
2570 .extra1 = SYSCTL_ZERO,
2571 .extra2 = &six_hundred_forty_kb,
2572 },
2573 {
2574 .procname = "perf_event_max_contexts_per_stack",
2575 .data = &sysctl_perf_event_max_contexts_per_stack,
2576 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
2577 .mode = 0644,
2578 .proc_handler = perf_event_max_stack_handler,
2579 .extra1 = SYSCTL_ZERO,
2580 .extra2 = &one_thousand,
2581 },
2582#endif
2583 {
2584 .procname = "panic_on_warn",
2585 .data = &panic_on_warn,
2586 .maxlen = sizeof(int),
2587 .mode = 0644,
2588 .proc_handler = proc_dointvec_minmax,
2589 .extra1 = SYSCTL_ZERO,
2590 .extra2 = SYSCTL_ONE,
2591 },
2592#if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
2593 {
2594 .procname = "timer_migration",
2595 .data = &sysctl_timer_migration,
2596 .maxlen = sizeof(unsigned int),
2597 .mode = 0644,
2598 .proc_handler = timer_migration_handler,
2599 .extra1 = SYSCTL_ZERO,
2600 .extra2 = SYSCTL_ONE,
2601 },
2602#endif
2603#ifdef CONFIG_BPF_SYSCALL
2604 {
2605 .procname = "unprivileged_bpf_disabled",
2606 .data = &sysctl_unprivileged_bpf_disabled,
2607 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
2608 .mode = 0644,
2609 /* only handle a transition from default "0" to "1" */
2610 .proc_handler = proc_dointvec_minmax,
2611 .extra1 = SYSCTL_ONE,
2612 .extra2 = SYSCTL_ONE,
2613 },
2614 {
2615 .procname = "bpf_stats_enabled",
2616 .data = &bpf_stats_enabled_key.key,
2617 .maxlen = sizeof(bpf_stats_enabled_key),
2618 .mode = 0644,
Song Liud46edd62020-04-30 00:15:04 -07002619 .proc_handler = bpf_stats_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 },
2621#endif
2622#if defined(CONFIG_TREE_RCU)
2623 {
2624 .procname = "panic_on_rcu_stall",
2625 .data = &sysctl_panic_on_rcu_stall,
2626 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
2627 .mode = 0644,
2628 .proc_handler = proc_dointvec_minmax,
2629 .extra1 = SYSCTL_ZERO,
2630 .extra2 = SYSCTL_ONE,
2631 },
2632#endif
2633#ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
2634 {
2635 .procname = "stack_erasing",
2636 .data = NULL,
2637 .maxlen = sizeof(int),
2638 .mode = 0600,
2639 .proc_handler = stack_erasing_sysctl,
2640 .extra1 = SYSCTL_ZERO,
2641 .extra2 = SYSCTL_ONE,
2642 },
2643#endif
2644 { }
2645};
2646
2647static struct ctl_table vm_table[] = {
2648 {
2649 .procname = "overcommit_memory",
2650 .data = &sysctl_overcommit_memory,
2651 .maxlen = sizeof(sysctl_overcommit_memory),
2652 .mode = 0644,
2653 .proc_handler = proc_dointvec_minmax,
2654 .extra1 = SYSCTL_ZERO,
2655 .extra2 = &two,
2656 },
2657 {
2658 .procname = "panic_on_oom",
2659 .data = &sysctl_panic_on_oom,
2660 .maxlen = sizeof(sysctl_panic_on_oom),
2661 .mode = 0644,
2662 .proc_handler = proc_dointvec_minmax,
2663 .extra1 = SYSCTL_ZERO,
2664 .extra2 = &two,
2665 },
2666 {
2667 .procname = "oom_kill_allocating_task",
2668 .data = &sysctl_oom_kill_allocating_task,
2669 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
2670 .mode = 0644,
2671 .proc_handler = proc_dointvec,
2672 },
2673 {
2674 .procname = "oom_dump_tasks",
2675 .data = &sysctl_oom_dump_tasks,
2676 .maxlen = sizeof(sysctl_oom_dump_tasks),
2677 .mode = 0644,
2678 .proc_handler = proc_dointvec,
2679 },
2680 {
2681 .procname = "overcommit_ratio",
2682 .data = &sysctl_overcommit_ratio,
2683 .maxlen = sizeof(sysctl_overcommit_ratio),
2684 .mode = 0644,
2685 .proc_handler = overcommit_ratio_handler,
2686 },
2687 {
2688 .procname = "overcommit_kbytes",
2689 .data = &sysctl_overcommit_kbytes,
2690 .maxlen = sizeof(sysctl_overcommit_kbytes),
2691 .mode = 0644,
2692 .proc_handler = overcommit_kbytes_handler,
2693 },
2694 {
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02002695 .procname = "page-cluster",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 .data = &page_cluster,
2697 .maxlen = sizeof(int),
2698 .mode = 0644,
2699 .proc_handler = proc_dointvec_minmax,
2700 .extra1 = SYSCTL_ZERO,
2701 },
2702 {
2703 .procname = "dirty_background_ratio",
2704 .data = &dirty_background_ratio,
2705 .maxlen = sizeof(dirty_background_ratio),
2706 .mode = 0644,
2707 .proc_handler = dirty_background_ratio_handler,
2708 .extra1 = SYSCTL_ZERO,
2709 .extra2 = &one_hundred,
2710 },
2711 {
2712 .procname = "dirty_background_bytes",
2713 .data = &dirty_background_bytes,
2714 .maxlen = sizeof(dirty_background_bytes),
2715 .mode = 0644,
2716 .proc_handler = dirty_background_bytes_handler,
2717 .extra1 = &one_ul,
2718 },
2719 {
2720 .procname = "dirty_ratio",
2721 .data = &vm_dirty_ratio,
2722 .maxlen = sizeof(vm_dirty_ratio),
2723 .mode = 0644,
2724 .proc_handler = dirty_ratio_handler,
2725 .extra1 = SYSCTL_ZERO,
2726 .extra2 = &one_hundred,
2727 },
2728 {
2729 .procname = "dirty_bytes",
2730 .data = &vm_dirty_bytes,
2731 .maxlen = sizeof(vm_dirty_bytes),
2732 .mode = 0644,
2733 .proc_handler = dirty_bytes_handler,
2734 .extra1 = &dirty_bytes_min,
2735 },
2736 {
2737 .procname = "dirty_writeback_centisecs",
2738 .data = &dirty_writeback_interval,
2739 .maxlen = sizeof(dirty_writeback_interval),
2740 .mode = 0644,
2741 .proc_handler = dirty_writeback_centisecs_handler,
2742 },
2743 {
2744 .procname = "dirty_expire_centisecs",
2745 .data = &dirty_expire_interval,
2746 .maxlen = sizeof(dirty_expire_interval),
2747 .mode = 0644,
2748 .proc_handler = proc_dointvec_minmax,
2749 .extra1 = SYSCTL_ZERO,
2750 },
2751 {
2752 .procname = "dirtytime_expire_seconds",
2753 .data = &dirtytime_expire_interval,
2754 .maxlen = sizeof(dirtytime_expire_interval),
2755 .mode = 0644,
2756 .proc_handler = dirtytime_interval_handler,
2757 .extra1 = SYSCTL_ZERO,
2758 },
2759 {
2760 .procname = "swappiness",
2761 .data = &vm_swappiness,
2762 .maxlen = sizeof(vm_swappiness),
2763 .mode = 0644,
2764 .proc_handler = proc_dointvec_minmax,
2765 .extra1 = SYSCTL_ZERO,
Johannes Weinerc8439662020-06-03 16:02:37 -07002766 .extra2 = &two_hundred,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 },
2768#ifdef CONFIG_HUGETLB_PAGE
2769 {
2770 .procname = "nr_hugepages",
2771 .data = NULL,
2772 .maxlen = sizeof(unsigned long),
2773 .mode = 0644,
2774 .proc_handler = hugetlb_sysctl_handler,
2775 },
2776#ifdef CONFIG_NUMA
2777 {
2778 .procname = "nr_hugepages_mempolicy",
2779 .data = NULL,
2780 .maxlen = sizeof(unsigned long),
2781 .mode = 0644,
2782 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
2783 },
2784 {
2785 .procname = "numa_stat",
2786 .data = &sysctl_vm_numa_stat,
2787 .maxlen = sizeof(int),
2788 .mode = 0644,
2789 .proc_handler = sysctl_vm_numa_stat_handler,
2790 .extra1 = SYSCTL_ZERO,
2791 .extra2 = SYSCTL_ONE,
2792 },
2793#endif
2794 {
2795 .procname = "hugetlb_shm_group",
2796 .data = &sysctl_hugetlb_shm_group,
2797 .maxlen = sizeof(gid_t),
2798 .mode = 0644,
2799 .proc_handler = proc_dointvec,
2800 },
2801 {
2802 .procname = "nr_overcommit_hugepages",
2803 .data = NULL,
2804 .maxlen = sizeof(unsigned long),
2805 .mode = 0644,
2806 .proc_handler = hugetlb_overcommit_handler,
2807 },
2808#endif
2809 {
2810 .procname = "lowmem_reserve_ratio",
2811 .data = &sysctl_lowmem_reserve_ratio,
2812 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
2813 .mode = 0644,
2814 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
2815 },
2816 {
2817 .procname = "drop_caches",
2818 .data = &sysctl_drop_caches,
2819 .maxlen = sizeof(int),
2820 .mode = 0200,
2821 .proc_handler = drop_caches_sysctl_handler,
2822 .extra1 = SYSCTL_ONE,
2823 .extra2 = &four,
2824 },
2825#ifdef CONFIG_COMPACTION
2826 {
2827 .procname = "compact_memory",
2828 .data = &sysctl_compact_memory,
2829 .maxlen = sizeof(int),
2830 .mode = 0200,
2831 .proc_handler = sysctl_compaction_handler,
2832 },
2833 {
2834 .procname = "extfrag_threshold",
2835 .data = &sysctl_extfrag_threshold,
2836 .maxlen = sizeof(int),
2837 .mode = 0644,
2838 .proc_handler = proc_dointvec_minmax,
2839 .extra1 = &min_extfrag_threshold,
2840 .extra2 = &max_extfrag_threshold,
2841 },
2842 {
2843 .procname = "compact_unevictable_allowed",
2844 .data = &sysctl_compact_unevictable_allowed,
2845 .maxlen = sizeof(int),
2846 .mode = 0644,
2847 .proc_handler = proc_dointvec_minmax_warn_RT_change,
2848 .extra1 = SYSCTL_ZERO,
2849 .extra2 = SYSCTL_ONE,
2850 },
2851
2852#endif /* CONFIG_COMPACTION */
2853 {
2854 .procname = "min_free_kbytes",
2855 .data = &min_free_kbytes,
2856 .maxlen = sizeof(min_free_kbytes),
2857 .mode = 0644,
2858 .proc_handler = min_free_kbytes_sysctl_handler,
2859 .extra1 = SYSCTL_ZERO,
2860 },
2861 {
2862 .procname = "watermark_boost_factor",
2863 .data = &watermark_boost_factor,
2864 .maxlen = sizeof(watermark_boost_factor),
2865 .mode = 0644,
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02002866 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 .extra1 = SYSCTL_ZERO,
2868 },
2869 {
2870 .procname = "watermark_scale_factor",
2871 .data = &watermark_scale_factor,
2872 .maxlen = sizeof(watermark_scale_factor),
2873 .mode = 0644,
2874 .proc_handler = watermark_scale_factor_sysctl_handler,
2875 .extra1 = SYSCTL_ONE,
2876 .extra2 = &one_thousand,
2877 },
2878 {
2879 .procname = "percpu_pagelist_fraction",
2880 .data = &percpu_pagelist_fraction,
2881 .maxlen = sizeof(percpu_pagelist_fraction),
2882 .mode = 0644,
2883 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
2884 .extra1 = SYSCTL_ZERO,
2885 },
2886#ifdef CONFIG_MMU
2887 {
2888 .procname = "max_map_count",
2889 .data = &sysctl_max_map_count,
2890 .maxlen = sizeof(sysctl_max_map_count),
2891 .mode = 0644,
2892 .proc_handler = proc_dointvec_minmax,
2893 .extra1 = SYSCTL_ZERO,
2894 },
2895#else
2896 {
2897 .procname = "nr_trim_pages",
2898 .data = &sysctl_nr_trim_pages,
2899 .maxlen = sizeof(sysctl_nr_trim_pages),
2900 .mode = 0644,
2901 .proc_handler = proc_dointvec_minmax,
2902 .extra1 = SYSCTL_ZERO,
2903 },
2904#endif
2905 {
2906 .procname = "laptop_mode",
2907 .data = &laptop_mode,
2908 .maxlen = sizeof(laptop_mode),
2909 .mode = 0644,
2910 .proc_handler = proc_dointvec_jiffies,
2911 },
2912 {
2913 .procname = "block_dump",
2914 .data = &block_dump,
2915 .maxlen = sizeof(block_dump),
2916 .mode = 0644,
2917 .proc_handler = proc_dointvec,
2918 .extra1 = SYSCTL_ZERO,
2919 },
2920 {
2921 .procname = "vfs_cache_pressure",
2922 .data = &sysctl_vfs_cache_pressure,
2923 .maxlen = sizeof(sysctl_vfs_cache_pressure),
2924 .mode = 0644,
2925 .proc_handler = proc_dointvec,
2926 .extra1 = SYSCTL_ZERO,
2927 },
2928#if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
2929 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
2930 {
2931 .procname = "legacy_va_layout",
2932 .data = &sysctl_legacy_va_layout,
2933 .maxlen = sizeof(sysctl_legacy_va_layout),
2934 .mode = 0644,
2935 .proc_handler = proc_dointvec,
2936 .extra1 = SYSCTL_ZERO,
2937 },
2938#endif
2939#ifdef CONFIG_NUMA
2940 {
2941 .procname = "zone_reclaim_mode",
2942 .data = &node_reclaim_mode,
2943 .maxlen = sizeof(node_reclaim_mode),
2944 .mode = 0644,
2945 .proc_handler = proc_dointvec,
2946 .extra1 = SYSCTL_ZERO,
2947 },
2948 {
2949 .procname = "min_unmapped_ratio",
2950 .data = &sysctl_min_unmapped_ratio,
2951 .maxlen = sizeof(sysctl_min_unmapped_ratio),
2952 .mode = 0644,
2953 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
2954 .extra1 = SYSCTL_ZERO,
2955 .extra2 = &one_hundred,
2956 },
2957 {
2958 .procname = "min_slab_ratio",
2959 .data = &sysctl_min_slab_ratio,
2960 .maxlen = sizeof(sysctl_min_slab_ratio),
2961 .mode = 0644,
2962 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
2963 .extra1 = SYSCTL_ZERO,
2964 .extra2 = &one_hundred,
2965 },
2966#endif
2967#ifdef CONFIG_SMP
2968 {
2969 .procname = "stat_interval",
2970 .data = &sysctl_stat_interval,
2971 .maxlen = sizeof(sysctl_stat_interval),
2972 .mode = 0644,
2973 .proc_handler = proc_dointvec_jiffies,
2974 },
2975 {
2976 .procname = "stat_refresh",
2977 .data = NULL,
2978 .maxlen = 0,
2979 .mode = 0600,
2980 .proc_handler = vmstat_refresh,
2981 },
2982#endif
2983#ifdef CONFIG_MMU
2984 {
2985 .procname = "mmap_min_addr",
2986 .data = &dac_mmap_min_addr,
2987 .maxlen = sizeof(unsigned long),
2988 .mode = 0644,
2989 .proc_handler = mmap_min_addr_handler,
2990 },
2991#endif
2992#ifdef CONFIG_NUMA
2993 {
2994 .procname = "numa_zonelist_order",
2995 .data = &numa_zonelist_order,
2996 .maxlen = NUMA_ZONELIST_ORDER_LEN,
2997 .mode = 0644,
2998 .proc_handler = numa_zonelist_order_handler,
2999 },
3000#endif
3001#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
3002 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
3003 {
3004 .procname = "vdso_enabled",
3005#ifdef CONFIG_X86_32
3006 .data = &vdso32_enabled,
3007 .maxlen = sizeof(vdso32_enabled),
3008#else
3009 .data = &vdso_enabled,
3010 .maxlen = sizeof(vdso_enabled),
3011#endif
3012 .mode = 0644,
3013 .proc_handler = proc_dointvec,
3014 .extra1 = SYSCTL_ZERO,
3015 },
3016#endif
3017#ifdef CONFIG_HIGHMEM
3018 {
3019 .procname = "highmem_is_dirtyable",
3020 .data = &vm_highmem_is_dirtyable,
3021 .maxlen = sizeof(vm_highmem_is_dirtyable),
3022 .mode = 0644,
3023 .proc_handler = proc_dointvec_minmax,
3024 .extra1 = SYSCTL_ZERO,
3025 .extra2 = SYSCTL_ONE,
3026 },
3027#endif
3028#ifdef CONFIG_MEMORY_FAILURE
3029 {
3030 .procname = "memory_failure_early_kill",
3031 .data = &sysctl_memory_failure_early_kill,
3032 .maxlen = sizeof(sysctl_memory_failure_early_kill),
3033 .mode = 0644,
3034 .proc_handler = proc_dointvec_minmax,
3035 .extra1 = SYSCTL_ZERO,
3036 .extra2 = SYSCTL_ONE,
3037 },
3038 {
3039 .procname = "memory_failure_recovery",
3040 .data = &sysctl_memory_failure_recovery,
3041 .maxlen = sizeof(sysctl_memory_failure_recovery),
3042 .mode = 0644,
3043 .proc_handler = proc_dointvec_minmax,
3044 .extra1 = SYSCTL_ZERO,
3045 .extra2 = SYSCTL_ONE,
3046 },
3047#endif
3048 {
3049 .procname = "user_reserve_kbytes",
3050 .data = &sysctl_user_reserve_kbytes,
3051 .maxlen = sizeof(sysctl_user_reserve_kbytes),
3052 .mode = 0644,
3053 .proc_handler = proc_doulongvec_minmax,
3054 },
3055 {
3056 .procname = "admin_reserve_kbytes",
3057 .data = &sysctl_admin_reserve_kbytes,
3058 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
3059 .mode = 0644,
3060 .proc_handler = proc_doulongvec_minmax,
3061 },
3062#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
3063 {
3064 .procname = "mmap_rnd_bits",
3065 .data = &mmap_rnd_bits,
3066 .maxlen = sizeof(mmap_rnd_bits),
3067 .mode = 0600,
3068 .proc_handler = proc_dointvec_minmax,
3069 .extra1 = (void *)&mmap_rnd_bits_min,
3070 .extra2 = (void *)&mmap_rnd_bits_max,
3071 },
3072#endif
3073#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
3074 {
3075 .procname = "mmap_rnd_compat_bits",
3076 .data = &mmap_rnd_compat_bits,
3077 .maxlen = sizeof(mmap_rnd_compat_bits),
3078 .mode = 0600,
3079 .proc_handler = proc_dointvec_minmax,
3080 .extra1 = (void *)&mmap_rnd_compat_bits_min,
3081 .extra2 = (void *)&mmap_rnd_compat_bits_max,
3082 },
3083#endif
3084#ifdef CONFIG_USERFAULTFD
3085 {
3086 .procname = "unprivileged_userfaultfd",
3087 .data = &sysctl_unprivileged_userfaultfd,
3088 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
3089 .mode = 0644,
3090 .proc_handler = proc_dointvec_minmax,
3091 .extra1 = SYSCTL_ZERO,
3092 .extra2 = SYSCTL_ONE,
3093 },
3094#endif
3095 { }
3096};
3097
3098static struct ctl_table fs_table[] = {
3099 {
3100 .procname = "inode-nr",
3101 .data = &inodes_stat,
3102 .maxlen = 2*sizeof(long),
3103 .mode = 0444,
3104 .proc_handler = proc_nr_inodes,
3105 },
3106 {
3107 .procname = "inode-state",
3108 .data = &inodes_stat,
3109 .maxlen = 7*sizeof(long),
3110 .mode = 0444,
3111 .proc_handler = proc_nr_inodes,
3112 },
3113 {
3114 .procname = "file-nr",
3115 .data = &files_stat,
3116 .maxlen = sizeof(files_stat),
3117 .mode = 0444,
3118 .proc_handler = proc_nr_files,
3119 },
3120 {
3121 .procname = "file-max",
3122 .data = &files_stat.max_files,
3123 .maxlen = sizeof(files_stat.max_files),
3124 .mode = 0644,
3125 .proc_handler = proc_doulongvec_minmax,
3126 .extra1 = &zero_ul,
3127 .extra2 = &long_max,
3128 },
3129 {
3130 .procname = "nr_open",
3131 .data = &sysctl_nr_open,
3132 .maxlen = sizeof(unsigned int),
3133 .mode = 0644,
3134 .proc_handler = proc_dointvec_minmax,
3135 .extra1 = &sysctl_nr_open_min,
3136 .extra2 = &sysctl_nr_open_max,
3137 },
3138 {
3139 .procname = "dentry-state",
3140 .data = &dentry_stat,
3141 .maxlen = 6*sizeof(long),
3142 .mode = 0444,
3143 .proc_handler = proc_nr_dentry,
3144 },
3145 {
3146 .procname = "overflowuid",
3147 .data = &fs_overflowuid,
3148 .maxlen = sizeof(int),
3149 .mode = 0644,
3150 .proc_handler = proc_dointvec_minmax,
3151 .extra1 = &minolduid,
3152 .extra2 = &maxolduid,
3153 },
3154 {
3155 .procname = "overflowgid",
3156 .data = &fs_overflowgid,
3157 .maxlen = sizeof(int),
3158 .mode = 0644,
3159 .proc_handler = proc_dointvec_minmax,
3160 .extra1 = &minolduid,
3161 .extra2 = &maxolduid,
3162 },
3163#ifdef CONFIG_FILE_LOCKING
3164 {
3165 .procname = "leases-enable",
3166 .data = &leases_enable,
3167 .maxlen = sizeof(int),
3168 .mode = 0644,
3169 .proc_handler = proc_dointvec,
3170 },
3171#endif
3172#ifdef CONFIG_DNOTIFY
3173 {
3174 .procname = "dir-notify-enable",
3175 .data = &dir_notify_enable,
3176 .maxlen = sizeof(int),
3177 .mode = 0644,
3178 .proc_handler = proc_dointvec,
3179 },
3180#endif
3181#ifdef CONFIG_MMU
3182#ifdef CONFIG_FILE_LOCKING
3183 {
3184 .procname = "lease-break-time",
3185 .data = &lease_break_time,
3186 .maxlen = sizeof(int),
3187 .mode = 0644,
3188 .proc_handler = proc_dointvec,
3189 },
3190#endif
3191#ifdef CONFIG_AIO
3192 {
3193 .procname = "aio-nr",
3194 .data = &aio_nr,
3195 .maxlen = sizeof(aio_nr),
3196 .mode = 0444,
3197 .proc_handler = proc_doulongvec_minmax,
3198 },
3199 {
3200 .procname = "aio-max-nr",
3201 .data = &aio_max_nr,
3202 .maxlen = sizeof(aio_max_nr),
3203 .mode = 0644,
3204 .proc_handler = proc_doulongvec_minmax,
3205 },
3206#endif /* CONFIG_AIO */
3207#ifdef CONFIG_INOTIFY_USER
3208 {
3209 .procname = "inotify",
3210 .mode = 0555,
3211 .child = inotify_table,
3212 },
3213#endif
3214#ifdef CONFIG_EPOLL
3215 {
3216 .procname = "epoll",
3217 .mode = 0555,
3218 .child = epoll_table,
3219 },
3220#endif
3221#endif
3222 {
3223 .procname = "protected_symlinks",
3224 .data = &sysctl_protected_symlinks,
3225 .maxlen = sizeof(int),
3226 .mode = 0600,
3227 .proc_handler = proc_dointvec_minmax,
3228 .extra1 = SYSCTL_ZERO,
3229 .extra2 = SYSCTL_ONE,
3230 },
3231 {
3232 .procname = "protected_hardlinks",
3233 .data = &sysctl_protected_hardlinks,
3234 .maxlen = sizeof(int),
3235 .mode = 0600,
3236 .proc_handler = proc_dointvec_minmax,
3237 .extra1 = SYSCTL_ZERO,
3238 .extra2 = SYSCTL_ONE,
3239 },
3240 {
3241 .procname = "protected_fifos",
3242 .data = &sysctl_protected_fifos,
3243 .maxlen = sizeof(int),
3244 .mode = 0600,
3245 .proc_handler = proc_dointvec_minmax,
3246 .extra1 = SYSCTL_ZERO,
3247 .extra2 = &two,
3248 },
3249 {
3250 .procname = "protected_regular",
3251 .data = &sysctl_protected_regular,
3252 .maxlen = sizeof(int),
3253 .mode = 0600,
3254 .proc_handler = proc_dointvec_minmax,
3255 .extra1 = SYSCTL_ZERO,
3256 .extra2 = &two,
3257 },
3258 {
3259 .procname = "suid_dumpable",
3260 .data = &suid_dumpable,
3261 .maxlen = sizeof(int),
3262 .mode = 0644,
3263 .proc_handler = proc_dointvec_minmax_coredump,
3264 .extra1 = SYSCTL_ZERO,
3265 .extra2 = &two,
3266 },
3267#if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
3268 {
3269 .procname = "binfmt_misc",
3270 .mode = 0555,
3271 .child = sysctl_mount_point,
3272 },
3273#endif
3274 {
3275 .procname = "pipe-max-size",
3276 .data = &pipe_max_size,
3277 .maxlen = sizeof(pipe_max_size),
3278 .mode = 0644,
3279 .proc_handler = proc_dopipe_max_size,
3280 },
3281 {
3282 .procname = "pipe-user-pages-hard",
3283 .data = &pipe_user_pages_hard,
3284 .maxlen = sizeof(pipe_user_pages_hard),
3285 .mode = 0644,
3286 .proc_handler = proc_doulongvec_minmax,
3287 },
3288 {
3289 .procname = "pipe-user-pages-soft",
3290 .data = &pipe_user_pages_soft,
3291 .maxlen = sizeof(pipe_user_pages_soft),
3292 .mode = 0644,
3293 .proc_handler = proc_doulongvec_minmax,
3294 },
3295 {
3296 .procname = "mount-max",
3297 .data = &sysctl_mount_max,
3298 .maxlen = sizeof(unsigned int),
3299 .mode = 0644,
3300 .proc_handler = proc_dointvec_minmax,
3301 .extra1 = SYSCTL_ONE,
3302 },
3303 { }
3304};
3305
3306static struct ctl_table debug_table[] = {
3307#ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
3308 {
3309 .procname = "exception-trace",
3310 .data = &show_unhandled_signals,
3311 .maxlen = sizeof(int),
3312 .mode = 0644,
3313 .proc_handler = proc_dointvec
3314 },
3315#endif
3316#if defined(CONFIG_OPTPROBES)
3317 {
3318 .procname = "kprobes-optimization",
3319 .data = &sysctl_kprobes_optimization,
3320 .maxlen = sizeof(int),
3321 .mode = 0644,
3322 .proc_handler = proc_kprobes_optimization_handler,
3323 .extra1 = SYSCTL_ZERO,
3324 .extra2 = SYSCTL_ONE,
3325 },
3326#endif
3327 { }
3328};
3329
3330static struct ctl_table dev_table[] = {
3331 { }
3332};
3333
Christoph Hellwigf461d2d2020-04-24 08:43:37 +02003334static struct ctl_table sysctl_base_table[] = {
3335 {
3336 .procname = "kernel",
3337 .mode = 0555,
3338 .child = kern_table,
3339 },
3340 {
3341 .procname = "vm",
3342 .mode = 0555,
3343 .child = vm_table,
3344 },
3345 {
3346 .procname = "fs",
3347 .mode = 0555,
3348 .child = fs_table,
3349 },
3350 {
3351 .procname = "debug",
3352 .mode = 0555,
3353 .child = debug_table,
3354 },
3355 {
3356 .procname = "dev",
3357 .mode = 0555,
3358 .child = dev_table,
3359 },
3360 { }
3361};
3362
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363int __init sysctl_init(void)
3364{
3365 struct ctl_table_header *hdr;
3366
3367 hdr = register_sysctl_table(sysctl_base_table);
3368 kmemleak_not_leak(hdr);
3369 return 0;
3370}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371#endif /* CONFIG_SYSCTL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372/*
3373 * No sense putting this after each symbol definition, twice,
3374 * exception granted :-)
3375 */
3376EXPORT_SYMBOL(proc_dointvec);
Subash Abhinov Kasiviswanathane7d316a2016-08-25 15:16:51 -07003377EXPORT_SYMBOL(proc_douintvec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378EXPORT_SYMBOL(proc_dointvec_jiffies);
3379EXPORT_SYMBOL(proc_dointvec_minmax);
Luis R. Rodriguez61d9b562017-07-12 14:33:40 -07003380EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3382EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3383EXPORT_SYMBOL(proc_dostring);
3384EXPORT_SYMBOL(proc_doulongvec_minmax);
3385EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
Stephen Suryaputra0bc19982019-04-17 16:35:49 -04003386EXPORT_SYMBOL(proc_do_large_bitmap);