xref: /openbmc/linux/kernel/sysctl.c (revision f628867da46f8867e1854e43d7200e42ec22eee2)
1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * sysctl.c: General linux system control interface
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * Begun 24 March 1995, Stephen Tweedie
61da177e4SLinus Torvalds  * Added /proc support, Dec 1995
71da177e4SLinus Torvalds  * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
81da177e4SLinus Torvalds  * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
91da177e4SLinus Torvalds  * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
101da177e4SLinus Torvalds  * Dynamic registration fixes, Stephen Tweedie.
111da177e4SLinus Torvalds  * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
121da177e4SLinus Torvalds  * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
131da177e4SLinus Torvalds  *  Horn.
141da177e4SLinus Torvalds  * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
151da177e4SLinus Torvalds  * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
161da177e4SLinus Torvalds  * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
171da177e4SLinus Torvalds  *  Wendling.
181da177e4SLinus Torvalds  * The list_for_each() macro wasn't appropriate for the sysctl loop.
191da177e4SLinus Torvalds  *  Removed it and replaced it with older style, 03/23/00, Bill Wendling
201da177e4SLinus Torvalds  */
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds #include <linux/module.h>
23e2e40f2cSChristoph Hellwig #include <linux/aio.h>
241da177e4SLinus Torvalds #include <linux/mm.h>
251da177e4SLinus Torvalds #include <linux/swap.h>
261da177e4SLinus Torvalds #include <linux/slab.h>
271da177e4SLinus Torvalds #include <linux/sysctl.h>
285a04cca6SAkinobu Mita #include <linux/bitmap.h>
29d33ed52dSDave Young #include <linux/signal.h>
30f39650deSAndy Shevchenko #include <linux/panic.h>
31455cd5abSDan Rosenberg #include <linux/printk.h>
321da177e4SLinus Torvalds #include <linux/proc_fs.h>
3372c2d582SAndrew Morgan #include <linux/security.h>
341da177e4SLinus Torvalds #include <linux/ctype.h>
35fd4b616bSSteven Rostedt #include <linux/kmemleak.h>
36b6459415SJakub Kicinski #include <linux/filter.h>
3762239ac2SAdrian Bunk #include <linux/fs.h>
381da177e4SLinus Torvalds #include <linux/init.h>
391da177e4SLinus Torvalds #include <linux/kernel.h>
400296b228SKay Sievers #include <linux/kobject.h>
4120380731SArnaldo Carvalho de Melo #include <linux/net.h>
421da177e4SLinus Torvalds #include <linux/sysrq.h>
431da177e4SLinus Torvalds #include <linux/highuid.h>
441da177e4SLinus Torvalds #include <linux/writeback.h>
453fff4c42SIngo Molnar #include <linux/ratelimit.h>
4676ab0f53SMel Gorman #include <linux/compaction.h>
471da177e4SLinus Torvalds #include <linux/hugetlb.h>
481da177e4SLinus Torvalds #include <linux/initrd.h>
490b77f5bfSDavid Howells #include <linux/key.h>
501da177e4SLinus Torvalds #include <linux/times.h>
511da177e4SLinus Torvalds #include <linux/limits.h>
521da177e4SLinus Torvalds #include <linux/dcache.h>
536e006701SAlexey Dobriyan #include <linux/dnotify.h>
541da177e4SLinus Torvalds #include <linux/syscalls.h>
55c748e134SAdrian Bunk #include <linux/vmstat.h>
56c255d844SPavel Machek #include <linux/nfs_fs.h>
57c255d844SPavel Machek #include <linux/acpi.h>
5810a0a8d4SJeremy Fitzhardinge #include <linux/reboot.h>
59b0fc494fSSteven Rostedt #include <linux/ftrace.h>
60cdd6c482SIngo Molnar #include <linux/perf_event.h>
61b2be84dfSMasami Hiramatsu #include <linux/kprobes.h>
62b492e95bSJens Axboe #include <linux/pipe_fs_i.h>
638e4228e1SDavid Rientjes #include <linux/oom.h>
6417f60a7dSEric Paris #include <linux/kmod.h>
6573efc039SDan Ballard #include <linux/capability.h>
6640401530SAl Viro #include <linux/binfmts.h>
67cf4aebc2SClark Williams #include <linux/sched/sysctl.h>
68f7ccbae4SIngo Molnar #include <linux/sched/coredump.h>
697984754bSKees Cook #include <linux/kexec.h>
701be7f75dSAlexei Starovoitov #include <linux/bpf.h>
71d2921684SEric W. Biederman #include <linux/mount.h>
72cefdca0aSPeter Xu #include <linux/userfaultfd_k.h>
732374c09bSChristoph Hellwig #include <linux/coredump.h>
742374c09bSChristoph Hellwig #include <linux/latencytop.h>
752374c09bSChristoph Hellwig #include <linux/pid.h>
760cd7c741SPeter Zijlstra #include <linux/delayacct.h>
771da177e4SLinus Torvalds 
787f2923c4SChristian Brauner #include "../lib/kstrtox.h"
797f2923c4SChristian Brauner 
807c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
811da177e4SLinus Torvalds #include <asm/processor.h>
821da177e4SLinus Torvalds 
8329cbc78bSAndi Kleen #ifdef CONFIG_X86
8429cbc78bSAndi Kleen #include <asm/nmi.h>
850741f4d2SChuck Ebbert #include <asm/stacktrace.h>
866e7c4025SIngo Molnar #include <asm/io.h>
8729cbc78bSAndi Kleen #endif
88d550bbd4SDavid Howells #ifdef CONFIG_SPARC
89d550bbd4SDavid Howells #include <asm/setup.h>
90d550bbd4SDavid Howells #endif
91c55b7c3eSDave Young #ifdef CONFIG_BSD_PROCESS_ACCT
92c55b7c3eSDave Young #include <linux/acct.h>
93c55b7c3eSDave Young #endif
944f0e056fSDave Young #ifdef CONFIG_RT_MUTEXES
954f0e056fSDave Young #include <linux/rtmutex.h>
964f0e056fSDave Young #endif
972edf5e49SDave Young #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
982edf5e49SDave Young #include <linux/lockdep.h>
992edf5e49SDave Young #endif
10015485a46SDave Young #ifdef CONFIG_CHR_DEV_SG
10115485a46SDave Young #include <scsi/sg.h>
10215485a46SDave Young #endif
103964c9dffSAlexander Popov #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
104964c9dffSAlexander Popov #include <linux/stackleak.h>
105964c9dffSAlexander Popov #endif
106504d7cf1SDon Zickus 
1071da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL)
1081da177e4SLinus Torvalds 
109c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and  maximum */
110c4f3b63fSRavikiran G Thirumalai 
1119002b214SWill Deacon static unsigned long zero_ul;
112fc3501d4SSven Wegener static unsigned long one_ul = 1;
11332a5ad9cSChristian Brauner static unsigned long long_max = LONG_MAX;
114af91322eSDave Young #ifdef CONFIG_PRINTK
115af91322eSDave Young static int ten_thousand = 10000;
116af91322eSDave Young #endif
117c5dfd78eSArnaldo Carvalho de Melo #ifdef CONFIG_PERF_EVENTS
118c5dfd78eSArnaldo Carvalho de Melo static int six_hundred_forty_kb = 640 * 1024;
119c5dfd78eSArnaldo Carvalho de Melo #endif
120c4f3b63fSRavikiran G Thirumalai 
1219e4a5bdaSAndrea Righi /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
1229e4a5bdaSAndrea Righi static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
1239e4a5bdaSAndrea Righi 
1241da177e4SLinus Torvalds /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
1251da177e4SLinus Torvalds static int maxolduid = 65535;
1261da177e4SLinus Torvalds static int minolduid;
1271da177e4SLinus Torvalds 
128*f628867dSStephen Kitt static const int ngroups_max = NGROUPS_MAX;
12973efc039SDan Ballard static const int cap_last_cap = CAP_LAST_CAP;
1301da177e4SLinus Torvalds 
13180df2847SLiu Hua 
132d14f1729SDave Young #ifdef CONFIG_INOTIFY_USER
133d14f1729SDave Young #include <linux/inotify.h>
134d14f1729SDave Young #endif
1355b8fea65SAmir Goldstein #ifdef CONFIG_FANOTIFY
1365b8fea65SAmir Goldstein #include <linux/fanotify.h>
1375b8fea65SAmir Goldstein #endif
138b6fca725SVineet Gupta 
139d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
140f4aacea2SKees Cook 
141a19ac337SLuis R. Rodriguez /**
142a19ac337SLuis R. Rodriguez  * enum sysctl_writes_mode - supported sysctl write modes
143a19ac337SLuis R. Rodriguez  *
144a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
145a19ac337SLuis R. Rodriguez  *	to be written, and multiple writes on the same sysctl file descriptor
146a19ac337SLuis R. Rodriguez  *	will rewrite the sysctl value, regardless of file position. No warning
147a19ac337SLuis R. Rodriguez  *	is issued when the initial position is not 0.
148a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
149a19ac337SLuis R. Rodriguez  *	not 0.
150a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
151a19ac337SLuis R. Rodriguez  *	file position 0 and the value must be fully contained in the buffer
152a19ac337SLuis R. Rodriguez  *	sent to the write syscall. If dealing with strings respect the file
153a19ac337SLuis R. Rodriguez  *	position, but restrict this to the max length of the buffer, anything
15465f50f25SWeitao Hou  *	passed the max length will be ignored. Multiple writes will append
155a19ac337SLuis R. Rodriguez  *	to the buffer.
156a19ac337SLuis R. Rodriguez  *
157a19ac337SLuis R. Rodriguez  * These write modes control how current file position affects the behavior of
158a19ac337SLuis R. Rodriguez  * updating sysctl values through the proc interface on each write.
159a19ac337SLuis R. Rodriguez  */
160a19ac337SLuis R. Rodriguez enum sysctl_writes_mode {
161a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_LEGACY		= -1,
162a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_WARN		= 0,
163a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_STRICT		= 1,
164a19ac337SLuis R. Rodriguez };
165f4aacea2SKees Cook 
166a19ac337SLuis R. Rodriguez static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
167f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */
168ceb18132SLuis R. Rodriguez 
16967f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
17067f3977fSAlexandre Ghiti     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
1711da177e4SLinus Torvalds int sysctl_legacy_va_layout;
1721da177e4SLinus Torvalds #endif
1731da177e4SLinus Torvalds 
1745e771905SMel Gorman #ifdef CONFIG_COMPACTION
1755e771905SMel Gorman static int min_extfrag_threshold;
1765e771905SMel Gorman static int max_extfrag_threshold = 1000;
1775e771905SMel Gorman #endif
1785e771905SMel Gorman 
179f461d2dcSChristoph Hellwig #endif /* CONFIG_SYSCTL */
180f461d2dcSChristoph Hellwig 
1815447e8e0SArnd Bergmann #if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL)
182d46edd67SSong Liu static int bpf_stats_handler(struct ctl_table *table, int write,
1837787b6fcSTobias Klauser 			     void *buffer, size_t *lenp, loff_t *ppos)
184d46edd67SSong Liu {
185d46edd67SSong Liu 	struct static_key *key = (struct static_key *)table->data;
186d46edd67SSong Liu 	static int saved_val;
187d46edd67SSong Liu 	int val, ret;
188d46edd67SSong Liu 	struct ctl_table tmp = {
189d46edd67SSong Liu 		.data   = &val,
190d46edd67SSong Liu 		.maxlen = sizeof(val),
191d46edd67SSong Liu 		.mode   = table->mode,
192d46edd67SSong Liu 		.extra1 = SYSCTL_ZERO,
193d46edd67SSong Liu 		.extra2 = SYSCTL_ONE,
194d46edd67SSong Liu 	};
195d46edd67SSong Liu 
196d46edd67SSong Liu 	if (write && !capable(CAP_SYS_ADMIN))
197d46edd67SSong Liu 		return -EPERM;
198d46edd67SSong Liu 
199d46edd67SSong Liu 	mutex_lock(&bpf_stats_enabled_mutex);
200d46edd67SSong Liu 	val = saved_val;
201d46edd67SSong Liu 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
202d46edd67SSong Liu 	if (write && !ret && val != saved_val) {
203d46edd67SSong Liu 		if (val)
204d46edd67SSong Liu 			static_key_slow_inc(key);
205d46edd67SSong Liu 		else
206d46edd67SSong Liu 			static_key_slow_dec(key);
207d46edd67SSong Liu 		saved_val = val;
208d46edd67SSong Liu 	}
209d46edd67SSong Liu 	mutex_unlock(&bpf_stats_enabled_mutex);
210d46edd67SSong Liu 	return ret;
211d46edd67SSong Liu }
21208389d88SDaniel Borkmann 
21308389d88SDaniel Borkmann static int bpf_unpriv_handler(struct ctl_table *table, int write,
21408389d88SDaniel Borkmann 			      void *buffer, size_t *lenp, loff_t *ppos)
21508389d88SDaniel Borkmann {
21608389d88SDaniel Borkmann 	int ret, unpriv_enable = *(int *)table->data;
21708389d88SDaniel Borkmann 	bool locked_state = unpriv_enable == 1;
21808389d88SDaniel Borkmann 	struct ctl_table tmp = *table;
21908389d88SDaniel Borkmann 
22008389d88SDaniel Borkmann 	if (write && !capable(CAP_SYS_ADMIN))
22108389d88SDaniel Borkmann 		return -EPERM;
22208389d88SDaniel Borkmann 
22308389d88SDaniel Borkmann 	tmp.data = &unpriv_enable;
22408389d88SDaniel Borkmann 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
22508389d88SDaniel Borkmann 	if (write && !ret) {
22608389d88SDaniel Borkmann 		if (locked_state && unpriv_enable != 1)
22708389d88SDaniel Borkmann 			return -EPERM;
22808389d88SDaniel Borkmann 		*(int *)table->data = unpriv_enable;
22908389d88SDaniel Borkmann 	}
23008389d88SDaniel Borkmann 	return ret;
23108389d88SDaniel Borkmann }
23208389d88SDaniel Borkmann #endif /* CONFIG_BPF_SYSCALL && CONFIG_SYSCTL */
233d46edd67SSong Liu 
234f461d2dcSChristoph Hellwig /*
235f461d2dcSChristoph Hellwig  * /proc/sys support
236f461d2dcSChristoph Hellwig  */
237f461d2dcSChristoph Hellwig 
238f461d2dcSChristoph Hellwig #ifdef CONFIG_PROC_SYSCTL
239f461d2dcSChristoph Hellwig 
240f461d2dcSChristoph Hellwig static int _proc_do_string(char *data, int maxlen, int write,
24132927393SChristoph Hellwig 		char *buffer, size_t *lenp, loff_t *ppos)
242f461d2dcSChristoph Hellwig {
243f461d2dcSChristoph Hellwig 	size_t len;
24432927393SChristoph Hellwig 	char c, *p;
245f461d2dcSChristoph Hellwig 
246f461d2dcSChristoph Hellwig 	if (!data || !maxlen || !*lenp) {
247f461d2dcSChristoph Hellwig 		*lenp = 0;
248f461d2dcSChristoph Hellwig 		return 0;
249f461d2dcSChristoph Hellwig 	}
250f461d2dcSChristoph Hellwig 
251f461d2dcSChristoph Hellwig 	if (write) {
252f461d2dcSChristoph Hellwig 		if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
253f461d2dcSChristoph Hellwig 			/* Only continue writes not past the end of buffer. */
254f461d2dcSChristoph Hellwig 			len = strlen(data);
255f461d2dcSChristoph Hellwig 			if (len > maxlen - 1)
256f461d2dcSChristoph Hellwig 				len = maxlen - 1;
257f461d2dcSChristoph Hellwig 
258f461d2dcSChristoph Hellwig 			if (*ppos > len)
259f461d2dcSChristoph Hellwig 				return 0;
260f461d2dcSChristoph Hellwig 			len = *ppos;
261f461d2dcSChristoph Hellwig 		} else {
262f461d2dcSChristoph Hellwig 			/* Start writing from beginning of buffer. */
263f461d2dcSChristoph Hellwig 			len = 0;
264f461d2dcSChristoph Hellwig 		}
265f461d2dcSChristoph Hellwig 
266f461d2dcSChristoph Hellwig 		*ppos += *lenp;
267f461d2dcSChristoph Hellwig 		p = buffer;
268f461d2dcSChristoph Hellwig 		while ((p - buffer) < *lenp && len < maxlen - 1) {
26932927393SChristoph Hellwig 			c = *(p++);
270f461d2dcSChristoph Hellwig 			if (c == 0 || c == '\n')
271f461d2dcSChristoph Hellwig 				break;
272f461d2dcSChristoph Hellwig 			data[len++] = c;
273f461d2dcSChristoph Hellwig 		}
274f461d2dcSChristoph Hellwig 		data[len] = 0;
275f461d2dcSChristoph Hellwig 	} else {
276f461d2dcSChristoph Hellwig 		len = strlen(data);
277f461d2dcSChristoph Hellwig 		if (len > maxlen)
278f461d2dcSChristoph Hellwig 			len = maxlen;
279f461d2dcSChristoph Hellwig 
280f461d2dcSChristoph Hellwig 		if (*ppos > len) {
281f461d2dcSChristoph Hellwig 			*lenp = 0;
282f461d2dcSChristoph Hellwig 			return 0;
283f461d2dcSChristoph Hellwig 		}
284f461d2dcSChristoph Hellwig 
285f461d2dcSChristoph Hellwig 		data += *ppos;
286f461d2dcSChristoph Hellwig 		len  -= *ppos;
287f461d2dcSChristoph Hellwig 
288f461d2dcSChristoph Hellwig 		if (len > *lenp)
289f461d2dcSChristoph Hellwig 			len = *lenp;
290f461d2dcSChristoph Hellwig 		if (len)
29132927393SChristoph Hellwig 			memcpy(buffer, data, len);
292f461d2dcSChristoph Hellwig 		if (len < *lenp) {
29332927393SChristoph Hellwig 			buffer[len] = '\n';
294f461d2dcSChristoph Hellwig 			len++;
295f461d2dcSChristoph Hellwig 		}
296f461d2dcSChristoph Hellwig 		*lenp = len;
297f461d2dcSChristoph Hellwig 		*ppos += len;
298f461d2dcSChristoph Hellwig 	}
299f461d2dcSChristoph Hellwig 	return 0;
300f461d2dcSChristoph Hellwig }
301f461d2dcSChristoph Hellwig 
302f461d2dcSChristoph Hellwig static void warn_sysctl_write(struct ctl_table *table)
303f461d2dcSChristoph Hellwig {
304f461d2dcSChristoph Hellwig 	pr_warn_once("%s wrote to %s when file position was not 0!\n"
305f461d2dcSChristoph Hellwig 		"This will not be supported in the future. To silence this\n"
306f461d2dcSChristoph Hellwig 		"warning, set kernel.sysctl_writes_strict = -1\n",
307f461d2dcSChristoph Hellwig 		current->comm, table->procname);
308f461d2dcSChristoph Hellwig }
309f461d2dcSChristoph Hellwig 
310f461d2dcSChristoph Hellwig /**
311f461d2dcSChristoph Hellwig  * proc_first_pos_non_zero_ignore - check if first position is allowed
312f461d2dcSChristoph Hellwig  * @ppos: file position
313f461d2dcSChristoph Hellwig  * @table: the sysctl table
314f461d2dcSChristoph Hellwig  *
315f461d2dcSChristoph Hellwig  * Returns true if the first position is non-zero and the sysctl_writes_strict
316f461d2dcSChristoph Hellwig  * mode indicates this is not allowed for numeric input types. String proc
317f461d2dcSChristoph Hellwig  * handlers can ignore the return value.
318f461d2dcSChristoph Hellwig  */
319f461d2dcSChristoph Hellwig static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
320f461d2dcSChristoph Hellwig 					   struct ctl_table *table)
321f461d2dcSChristoph Hellwig {
322f461d2dcSChristoph Hellwig 	if (!*ppos)
323f461d2dcSChristoph Hellwig 		return false;
324f461d2dcSChristoph Hellwig 
325f461d2dcSChristoph Hellwig 	switch (sysctl_writes_strict) {
326f461d2dcSChristoph Hellwig 	case SYSCTL_WRITES_STRICT:
327f461d2dcSChristoph Hellwig 		return true;
328f461d2dcSChristoph Hellwig 	case SYSCTL_WRITES_WARN:
329f461d2dcSChristoph Hellwig 		warn_sysctl_write(table);
330f461d2dcSChristoph Hellwig 		return false;
331f461d2dcSChristoph Hellwig 	default:
332f461d2dcSChristoph Hellwig 		return false;
333f461d2dcSChristoph Hellwig 	}
334f461d2dcSChristoph Hellwig }
335f461d2dcSChristoph Hellwig 
336f461d2dcSChristoph Hellwig /**
337f461d2dcSChristoph Hellwig  * proc_dostring - read a string sysctl
338f461d2dcSChristoph Hellwig  * @table: the sysctl table
339f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
340f461d2dcSChristoph Hellwig  * @buffer: the user buffer
341f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
342f461d2dcSChristoph Hellwig  * @ppos: file position
343f461d2dcSChristoph Hellwig  *
344f461d2dcSChristoph Hellwig  * Reads/writes a string from/to the user buffer. If the kernel
345f461d2dcSChristoph Hellwig  * buffer provided is not large enough to hold the string, the
346f461d2dcSChristoph Hellwig  * string is truncated. The copied string is %NULL-terminated.
347f461d2dcSChristoph Hellwig  * If the string is being read by the user process, it is copied
348f461d2dcSChristoph Hellwig  * and a newline '\n' is added. It is truncated if the buffer is
349f461d2dcSChristoph Hellwig  * not large enough.
350f461d2dcSChristoph Hellwig  *
351f461d2dcSChristoph Hellwig  * Returns 0 on success.
352f461d2dcSChristoph Hellwig  */
353f461d2dcSChristoph Hellwig int proc_dostring(struct ctl_table *table, int write,
35432927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
355f461d2dcSChristoph Hellwig {
356f461d2dcSChristoph Hellwig 	if (write)
357f461d2dcSChristoph Hellwig 		proc_first_pos_non_zero_ignore(ppos, table);
358f461d2dcSChristoph Hellwig 
35932927393SChristoph Hellwig 	return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
36032927393SChristoph Hellwig 			ppos);
361f461d2dcSChristoph Hellwig }
362f461d2dcSChristoph Hellwig 
363f461d2dcSChristoph Hellwig static size_t proc_skip_spaces(char **buf)
364f461d2dcSChristoph Hellwig {
365f461d2dcSChristoph Hellwig 	size_t ret;
366f461d2dcSChristoph Hellwig 	char *tmp = skip_spaces(*buf);
367f461d2dcSChristoph Hellwig 	ret = tmp - *buf;
368f461d2dcSChristoph Hellwig 	*buf = tmp;
369f461d2dcSChristoph Hellwig 	return ret;
370f461d2dcSChristoph Hellwig }
371f461d2dcSChristoph Hellwig 
372f461d2dcSChristoph Hellwig static void proc_skip_char(char **buf, size_t *size, const char v)
373f461d2dcSChristoph Hellwig {
374f461d2dcSChristoph Hellwig 	while (*size) {
375f461d2dcSChristoph Hellwig 		if (**buf != v)
376f461d2dcSChristoph Hellwig 			break;
377f461d2dcSChristoph Hellwig 		(*size)--;
378f461d2dcSChristoph Hellwig 		(*buf)++;
379f461d2dcSChristoph Hellwig 	}
380f461d2dcSChristoph Hellwig }
381f461d2dcSChristoph Hellwig 
382f461d2dcSChristoph Hellwig /**
383f461d2dcSChristoph Hellwig  * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
384f461d2dcSChristoph Hellwig  *                   fail on overflow
385f461d2dcSChristoph Hellwig  *
386f461d2dcSChristoph Hellwig  * @cp: kernel buffer containing the string to parse
387f461d2dcSChristoph Hellwig  * @endp: pointer to store the trailing characters
388f461d2dcSChristoph Hellwig  * @base: the base to use
389f461d2dcSChristoph Hellwig  * @res: where the parsed integer will be stored
390f461d2dcSChristoph Hellwig  *
391f461d2dcSChristoph Hellwig  * In case of success 0 is returned and @res will contain the parsed integer,
392f461d2dcSChristoph Hellwig  * @endp will hold any trailing characters.
393f461d2dcSChristoph Hellwig  * This function will fail the parse on overflow. If there wasn't an overflow
394f461d2dcSChristoph Hellwig  * the function will defer the decision what characters count as invalid to the
395f461d2dcSChristoph Hellwig  * caller.
396f461d2dcSChristoph Hellwig  */
397f461d2dcSChristoph Hellwig static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
398f461d2dcSChristoph Hellwig 			   unsigned long *res)
399f461d2dcSChristoph Hellwig {
400f461d2dcSChristoph Hellwig 	unsigned long long result;
401f461d2dcSChristoph Hellwig 	unsigned int rv;
402f461d2dcSChristoph Hellwig 
403f461d2dcSChristoph Hellwig 	cp = _parse_integer_fixup_radix(cp, &base);
404f461d2dcSChristoph Hellwig 	rv = _parse_integer(cp, base, &result);
405f461d2dcSChristoph Hellwig 	if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
406f461d2dcSChristoph Hellwig 		return -ERANGE;
407f461d2dcSChristoph Hellwig 
408f461d2dcSChristoph Hellwig 	cp += rv;
409f461d2dcSChristoph Hellwig 
410f461d2dcSChristoph Hellwig 	if (endp)
411f461d2dcSChristoph Hellwig 		*endp = (char *)cp;
412f461d2dcSChristoph Hellwig 
413f461d2dcSChristoph Hellwig 	*res = (unsigned long)result;
414f461d2dcSChristoph Hellwig 	return 0;
415f461d2dcSChristoph Hellwig }
416f461d2dcSChristoph Hellwig 
417f461d2dcSChristoph Hellwig #define TMPBUFLEN 22
418f461d2dcSChristoph Hellwig /**
419f461d2dcSChristoph Hellwig  * proc_get_long - reads an ASCII formatted integer from a user buffer
420f461d2dcSChristoph Hellwig  *
421f461d2dcSChristoph Hellwig  * @buf: a kernel buffer
422f461d2dcSChristoph Hellwig  * @size: size of the kernel buffer
423f461d2dcSChristoph Hellwig  * @val: this is where the number will be stored
424f461d2dcSChristoph Hellwig  * @neg: set to %TRUE if number is negative
425f461d2dcSChristoph Hellwig  * @perm_tr: a vector which contains the allowed trailers
426f461d2dcSChristoph Hellwig  * @perm_tr_len: size of the perm_tr vector
427f461d2dcSChristoph Hellwig  * @tr: pointer to store the trailer character
428f461d2dcSChristoph Hellwig  *
429f461d2dcSChristoph Hellwig  * In case of success %0 is returned and @buf and @size are updated with
430f461d2dcSChristoph Hellwig  * the amount of bytes read. If @tr is non-NULL and a trailing
431f461d2dcSChristoph Hellwig  * character exists (size is non-zero after returning from this
432f461d2dcSChristoph Hellwig  * function), @tr is updated with the trailing character.
433f461d2dcSChristoph Hellwig  */
434f461d2dcSChristoph Hellwig static int proc_get_long(char **buf, size_t *size,
435f461d2dcSChristoph Hellwig 			  unsigned long *val, bool *neg,
436f461d2dcSChristoph Hellwig 			  const char *perm_tr, unsigned perm_tr_len, char *tr)
437f461d2dcSChristoph Hellwig {
438f461d2dcSChristoph Hellwig 	int len;
439f461d2dcSChristoph Hellwig 	char *p, tmp[TMPBUFLEN];
440f461d2dcSChristoph Hellwig 
441f461d2dcSChristoph Hellwig 	if (!*size)
442f461d2dcSChristoph Hellwig 		return -EINVAL;
443f461d2dcSChristoph Hellwig 
444f461d2dcSChristoph Hellwig 	len = *size;
445f461d2dcSChristoph Hellwig 	if (len > TMPBUFLEN - 1)
446f461d2dcSChristoph Hellwig 		len = TMPBUFLEN - 1;
447f461d2dcSChristoph Hellwig 
448f461d2dcSChristoph Hellwig 	memcpy(tmp, *buf, len);
449f461d2dcSChristoph Hellwig 
450f461d2dcSChristoph Hellwig 	tmp[len] = 0;
451f461d2dcSChristoph Hellwig 	p = tmp;
452f461d2dcSChristoph Hellwig 	if (*p == '-' && *size > 1) {
453f461d2dcSChristoph Hellwig 		*neg = true;
454f461d2dcSChristoph Hellwig 		p++;
455f461d2dcSChristoph Hellwig 	} else
456f461d2dcSChristoph Hellwig 		*neg = false;
457f461d2dcSChristoph Hellwig 	if (!isdigit(*p))
458f461d2dcSChristoph Hellwig 		return -EINVAL;
459f461d2dcSChristoph Hellwig 
460f461d2dcSChristoph Hellwig 	if (strtoul_lenient(p, &p, 0, val))
461f461d2dcSChristoph Hellwig 		return -EINVAL;
462f461d2dcSChristoph Hellwig 
463f461d2dcSChristoph Hellwig 	len = p - tmp;
464f461d2dcSChristoph Hellwig 
465f461d2dcSChristoph Hellwig 	/* We don't know if the next char is whitespace thus we may accept
466f461d2dcSChristoph Hellwig 	 * invalid integers (e.g. 1234...a) or two integers instead of one
467f461d2dcSChristoph Hellwig 	 * (e.g. 123...1). So lets not allow such large numbers. */
468f461d2dcSChristoph Hellwig 	if (len == TMPBUFLEN - 1)
469f461d2dcSChristoph Hellwig 		return -EINVAL;
470f461d2dcSChristoph Hellwig 
471f461d2dcSChristoph Hellwig 	if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
472f461d2dcSChristoph Hellwig 		return -EINVAL;
473f461d2dcSChristoph Hellwig 
474f461d2dcSChristoph Hellwig 	if (tr && (len < *size))
475f461d2dcSChristoph Hellwig 		*tr = *p;
476f461d2dcSChristoph Hellwig 
477f461d2dcSChristoph Hellwig 	*buf += len;
478f461d2dcSChristoph Hellwig 	*size -= len;
479f461d2dcSChristoph Hellwig 
480f461d2dcSChristoph Hellwig 	return 0;
481f461d2dcSChristoph Hellwig }
482f461d2dcSChristoph Hellwig 
483f461d2dcSChristoph Hellwig /**
484f461d2dcSChristoph Hellwig  * proc_put_long - converts an integer to a decimal ASCII formatted string
485f461d2dcSChristoph Hellwig  *
486f461d2dcSChristoph Hellwig  * @buf: the user buffer
487f461d2dcSChristoph Hellwig  * @size: the size of the user buffer
488f461d2dcSChristoph Hellwig  * @val: the integer to be converted
489f461d2dcSChristoph Hellwig  * @neg: sign of the number, %TRUE for negative
490f461d2dcSChristoph Hellwig  *
49132927393SChristoph Hellwig  * In case of success @buf and @size are updated with the amount of bytes
49232927393SChristoph Hellwig  * written.
493f461d2dcSChristoph Hellwig  */
49432927393SChristoph Hellwig static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
495f461d2dcSChristoph Hellwig {
496f461d2dcSChristoph Hellwig 	int len;
497f461d2dcSChristoph Hellwig 	char tmp[TMPBUFLEN], *p = tmp;
498f461d2dcSChristoph Hellwig 
499f461d2dcSChristoph Hellwig 	sprintf(p, "%s%lu", neg ? "-" : "", val);
500f461d2dcSChristoph Hellwig 	len = strlen(tmp);
501f461d2dcSChristoph Hellwig 	if (len > *size)
502f461d2dcSChristoph Hellwig 		len = *size;
50332927393SChristoph Hellwig 	memcpy(*buf, tmp, len);
504f461d2dcSChristoph Hellwig 	*size -= len;
505f461d2dcSChristoph Hellwig 	*buf += len;
506f461d2dcSChristoph Hellwig }
507f461d2dcSChristoph Hellwig #undef TMPBUFLEN
508f461d2dcSChristoph Hellwig 
50932927393SChristoph Hellwig static void proc_put_char(void **buf, size_t *size, char c)
510f461d2dcSChristoph Hellwig {
511f461d2dcSChristoph Hellwig 	if (*size) {
51232927393SChristoph Hellwig 		char **buffer = (char **)buf;
51332927393SChristoph Hellwig 		**buffer = c;
51432927393SChristoph Hellwig 
51532927393SChristoph Hellwig 		(*size)--;
51632927393SChristoph Hellwig 		(*buffer)++;
517f461d2dcSChristoph Hellwig 		*buf = *buffer;
518f461d2dcSChristoph Hellwig 	}
519f461d2dcSChristoph Hellwig }
520f461d2dcSChristoph Hellwig 
521a2071573SJia He static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp,
522a2071573SJia He 				int *valp,
523a2071573SJia He 				int write, void *data)
524a2071573SJia He {
525a2071573SJia He 	if (write) {
526a2071573SJia He 		*(bool *)valp = *lvalp;
527a2071573SJia He 	} else {
528a2071573SJia He 		int val = *(bool *)valp;
529a2071573SJia He 
530a2071573SJia He 		*lvalp = (unsigned long)val;
531a2071573SJia He 		*negp = false;
532a2071573SJia He 	}
533a2071573SJia He 	return 0;
534a2071573SJia He }
535a2071573SJia He 
536f461d2dcSChristoph Hellwig static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
537f461d2dcSChristoph Hellwig 				 int *valp,
538f461d2dcSChristoph Hellwig 				 int write, void *data)
539f461d2dcSChristoph Hellwig {
540f461d2dcSChristoph Hellwig 	if (write) {
541f461d2dcSChristoph Hellwig 		if (*negp) {
542f461d2dcSChristoph Hellwig 			if (*lvalp > (unsigned long) INT_MAX + 1)
543f461d2dcSChristoph Hellwig 				return -EINVAL;
544f461d2dcSChristoph Hellwig 			*valp = -*lvalp;
545f461d2dcSChristoph Hellwig 		} else {
546f461d2dcSChristoph Hellwig 			if (*lvalp > (unsigned long) INT_MAX)
547f461d2dcSChristoph Hellwig 				return -EINVAL;
548f461d2dcSChristoph Hellwig 			*valp = *lvalp;
549f461d2dcSChristoph Hellwig 		}
550f461d2dcSChristoph Hellwig 	} else {
551f461d2dcSChristoph Hellwig 		int val = *valp;
552f461d2dcSChristoph Hellwig 		if (val < 0) {
553f461d2dcSChristoph Hellwig 			*negp = true;
554f461d2dcSChristoph Hellwig 			*lvalp = -(unsigned long)val;
555f461d2dcSChristoph Hellwig 		} else {
556f461d2dcSChristoph Hellwig 			*negp = false;
557f461d2dcSChristoph Hellwig 			*lvalp = (unsigned long)val;
558f461d2dcSChristoph Hellwig 		}
559f461d2dcSChristoph Hellwig 	}
560f461d2dcSChristoph Hellwig 	return 0;
561f461d2dcSChristoph Hellwig }
562f461d2dcSChristoph Hellwig 
563f461d2dcSChristoph Hellwig static int do_proc_douintvec_conv(unsigned long *lvalp,
564f461d2dcSChristoph Hellwig 				  unsigned int *valp,
565f461d2dcSChristoph Hellwig 				  int write, void *data)
566f461d2dcSChristoph Hellwig {
567f461d2dcSChristoph Hellwig 	if (write) {
568f461d2dcSChristoph Hellwig 		if (*lvalp > UINT_MAX)
569f461d2dcSChristoph Hellwig 			return -EINVAL;
570f461d2dcSChristoph Hellwig 		*valp = *lvalp;
571f461d2dcSChristoph Hellwig 	} else {
572f461d2dcSChristoph Hellwig 		unsigned int val = *valp;
573f461d2dcSChristoph Hellwig 		*lvalp = (unsigned long)val;
574f461d2dcSChristoph Hellwig 	}
575f461d2dcSChristoph Hellwig 	return 0;
576f461d2dcSChristoph Hellwig }
577f461d2dcSChristoph Hellwig 
578f461d2dcSChristoph Hellwig static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
579f461d2dcSChristoph Hellwig 
580f461d2dcSChristoph Hellwig static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
58132927393SChristoph Hellwig 		  int write, void *buffer,
582f461d2dcSChristoph Hellwig 		  size_t *lenp, loff_t *ppos,
583f461d2dcSChristoph Hellwig 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
584f461d2dcSChristoph Hellwig 			      int write, void *data),
585f461d2dcSChristoph Hellwig 		  void *data)
586f461d2dcSChristoph Hellwig {
587f461d2dcSChristoph Hellwig 	int *i, vleft, first = 1, err = 0;
588f461d2dcSChristoph Hellwig 	size_t left;
58932927393SChristoph Hellwig 	char *p;
590f461d2dcSChristoph Hellwig 
591f461d2dcSChristoph Hellwig 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
592f461d2dcSChristoph Hellwig 		*lenp = 0;
593f461d2dcSChristoph Hellwig 		return 0;
594f461d2dcSChristoph Hellwig 	}
595f461d2dcSChristoph Hellwig 
596f461d2dcSChristoph Hellwig 	i = (int *) tbl_data;
597f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(*i);
598f461d2dcSChristoph Hellwig 	left = *lenp;
599f461d2dcSChristoph Hellwig 
600f461d2dcSChristoph Hellwig 	if (!conv)
601f461d2dcSChristoph Hellwig 		conv = do_proc_dointvec_conv;
602f461d2dcSChristoph Hellwig 
603f461d2dcSChristoph Hellwig 	if (write) {
604f461d2dcSChristoph Hellwig 		if (proc_first_pos_non_zero_ignore(ppos, table))
605f461d2dcSChristoph Hellwig 			goto out;
606f461d2dcSChristoph Hellwig 
607f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1)
608f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
60932927393SChristoph Hellwig 		p = buffer;
610f461d2dcSChristoph Hellwig 	}
611f461d2dcSChristoph Hellwig 
612f461d2dcSChristoph Hellwig 	for (; left && vleft--; i++, first=0) {
613f461d2dcSChristoph Hellwig 		unsigned long lval;
614f461d2dcSChristoph Hellwig 		bool neg;
615f461d2dcSChristoph Hellwig 
616f461d2dcSChristoph Hellwig 		if (write) {
617f461d2dcSChristoph Hellwig 			left -= proc_skip_spaces(&p);
618f461d2dcSChristoph Hellwig 
619f461d2dcSChristoph Hellwig 			if (!left)
620f461d2dcSChristoph Hellwig 				break;
621f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &lval, &neg,
622f461d2dcSChristoph Hellwig 					     proc_wspace_sep,
623f461d2dcSChristoph Hellwig 					     sizeof(proc_wspace_sep), NULL);
624f461d2dcSChristoph Hellwig 			if (err)
625f461d2dcSChristoph Hellwig 				break;
626f461d2dcSChristoph Hellwig 			if (conv(&neg, &lval, i, 1, data)) {
627f461d2dcSChristoph Hellwig 				err = -EINVAL;
628f461d2dcSChristoph Hellwig 				break;
629f461d2dcSChristoph Hellwig 			}
630f461d2dcSChristoph Hellwig 		} else {
631f461d2dcSChristoph Hellwig 			if (conv(&neg, &lval, i, 0, data)) {
632f461d2dcSChristoph Hellwig 				err = -EINVAL;
633f461d2dcSChristoph Hellwig 				break;
634f461d2dcSChristoph Hellwig 			}
635f461d2dcSChristoph Hellwig 			if (!first)
63632927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '\t');
63732927393SChristoph Hellwig 			proc_put_long(&buffer, &left, lval, neg);
638f461d2dcSChristoph Hellwig 		}
639f461d2dcSChristoph Hellwig 	}
640f461d2dcSChristoph Hellwig 
641f461d2dcSChristoph Hellwig 	if (!write && !first && left && !err)
64232927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
643f461d2dcSChristoph Hellwig 	if (write && !err && left)
644f461d2dcSChristoph Hellwig 		left -= proc_skip_spaces(&p);
64532927393SChristoph Hellwig 	if (write && first)
646f461d2dcSChristoph Hellwig 		return err ? : -EINVAL;
647f461d2dcSChristoph Hellwig 	*lenp -= left;
648f461d2dcSChristoph Hellwig out:
649f461d2dcSChristoph Hellwig 	*ppos += *lenp;
650f461d2dcSChristoph Hellwig 	return err;
651f461d2dcSChristoph Hellwig }
652f461d2dcSChristoph Hellwig 
653f461d2dcSChristoph Hellwig static int do_proc_dointvec(struct ctl_table *table, int write,
65432927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos,
655f461d2dcSChristoph Hellwig 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
656f461d2dcSChristoph Hellwig 			      int write, void *data),
657f461d2dcSChristoph Hellwig 		  void *data)
658f461d2dcSChristoph Hellwig {
659f461d2dcSChristoph Hellwig 	return __do_proc_dointvec(table->data, table, write,
660f461d2dcSChristoph Hellwig 			buffer, lenp, ppos, conv, data);
661f461d2dcSChristoph Hellwig }
662f461d2dcSChristoph Hellwig 
663f461d2dcSChristoph Hellwig static int do_proc_douintvec_w(unsigned int *tbl_data,
664f461d2dcSChristoph Hellwig 			       struct ctl_table *table,
66532927393SChristoph Hellwig 			       void *buffer,
666f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
667f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
668f461d2dcSChristoph Hellwig 					   unsigned int *valp,
669f461d2dcSChristoph Hellwig 					   int write, void *data),
670f461d2dcSChristoph Hellwig 			       void *data)
671f461d2dcSChristoph Hellwig {
672f461d2dcSChristoph Hellwig 	unsigned long lval;
673f461d2dcSChristoph Hellwig 	int err = 0;
674f461d2dcSChristoph Hellwig 	size_t left;
675f461d2dcSChristoph Hellwig 	bool neg;
67632927393SChristoph Hellwig 	char *p = buffer;
677f461d2dcSChristoph Hellwig 
678f461d2dcSChristoph Hellwig 	left = *lenp;
679f461d2dcSChristoph Hellwig 
680f461d2dcSChristoph Hellwig 	if (proc_first_pos_non_zero_ignore(ppos, table))
681f461d2dcSChristoph Hellwig 		goto bail_early;
682f461d2dcSChristoph Hellwig 
683f461d2dcSChristoph Hellwig 	if (left > PAGE_SIZE - 1)
684f461d2dcSChristoph Hellwig 		left = PAGE_SIZE - 1;
685f461d2dcSChristoph Hellwig 
686f461d2dcSChristoph Hellwig 	left -= proc_skip_spaces(&p);
687f461d2dcSChristoph Hellwig 	if (!left) {
688f461d2dcSChristoph Hellwig 		err = -EINVAL;
689f461d2dcSChristoph Hellwig 		goto out_free;
690f461d2dcSChristoph Hellwig 	}
691f461d2dcSChristoph Hellwig 
692f461d2dcSChristoph Hellwig 	err = proc_get_long(&p, &left, &lval, &neg,
693f461d2dcSChristoph Hellwig 			     proc_wspace_sep,
694f461d2dcSChristoph Hellwig 			     sizeof(proc_wspace_sep), NULL);
695f461d2dcSChristoph Hellwig 	if (err || neg) {
696f461d2dcSChristoph Hellwig 		err = -EINVAL;
697f461d2dcSChristoph Hellwig 		goto out_free;
698f461d2dcSChristoph Hellwig 	}
699f461d2dcSChristoph Hellwig 
700f461d2dcSChristoph Hellwig 	if (conv(&lval, tbl_data, 1, data)) {
701f461d2dcSChristoph Hellwig 		err = -EINVAL;
702f461d2dcSChristoph Hellwig 		goto out_free;
703f461d2dcSChristoph Hellwig 	}
704f461d2dcSChristoph Hellwig 
705f461d2dcSChristoph Hellwig 	if (!err && left)
706f461d2dcSChristoph Hellwig 		left -= proc_skip_spaces(&p);
707f461d2dcSChristoph Hellwig 
708f461d2dcSChristoph Hellwig out_free:
709f461d2dcSChristoph Hellwig 	if (err)
710f461d2dcSChristoph Hellwig 		return -EINVAL;
711f461d2dcSChristoph Hellwig 
712f461d2dcSChristoph Hellwig 	return 0;
713f461d2dcSChristoph Hellwig 
714f461d2dcSChristoph Hellwig 	/* This is in keeping with old __do_proc_dointvec() */
715f461d2dcSChristoph Hellwig bail_early:
716f461d2dcSChristoph Hellwig 	*ppos += *lenp;
717f461d2dcSChristoph Hellwig 	return err;
718f461d2dcSChristoph Hellwig }
719f461d2dcSChristoph Hellwig 
72032927393SChristoph Hellwig static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
721f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
722f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
723f461d2dcSChristoph Hellwig 					   unsigned int *valp,
724f461d2dcSChristoph Hellwig 					   int write, void *data),
725f461d2dcSChristoph Hellwig 			       void *data)
726f461d2dcSChristoph Hellwig {
727f461d2dcSChristoph Hellwig 	unsigned long lval;
728f461d2dcSChristoph Hellwig 	int err = 0;
729f461d2dcSChristoph Hellwig 	size_t left;
730f461d2dcSChristoph Hellwig 
731f461d2dcSChristoph Hellwig 	left = *lenp;
732f461d2dcSChristoph Hellwig 
733f461d2dcSChristoph Hellwig 	if (conv(&lval, tbl_data, 0, data)) {
734f461d2dcSChristoph Hellwig 		err = -EINVAL;
735f461d2dcSChristoph Hellwig 		goto out;
736f461d2dcSChristoph Hellwig 	}
737f461d2dcSChristoph Hellwig 
73832927393SChristoph Hellwig 	proc_put_long(&buffer, &left, lval, false);
73932927393SChristoph Hellwig 	if (!left)
740f461d2dcSChristoph Hellwig 		goto out;
741f461d2dcSChristoph Hellwig 
74232927393SChristoph Hellwig 	proc_put_char(&buffer, &left, '\n');
743f461d2dcSChristoph Hellwig 
744f461d2dcSChristoph Hellwig out:
745f461d2dcSChristoph Hellwig 	*lenp -= left;
746f461d2dcSChristoph Hellwig 	*ppos += *lenp;
747f461d2dcSChristoph Hellwig 
748f461d2dcSChristoph Hellwig 	return err;
749f461d2dcSChristoph Hellwig }
750f461d2dcSChristoph Hellwig 
751f461d2dcSChristoph Hellwig static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
75232927393SChristoph Hellwig 			       int write, void *buffer,
753f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
754f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
755f461d2dcSChristoph Hellwig 					   unsigned int *valp,
756f461d2dcSChristoph Hellwig 					   int write, void *data),
757f461d2dcSChristoph Hellwig 			       void *data)
758f461d2dcSChristoph Hellwig {
759f461d2dcSChristoph Hellwig 	unsigned int *i, vleft;
760f461d2dcSChristoph Hellwig 
761f461d2dcSChristoph Hellwig 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
762f461d2dcSChristoph Hellwig 		*lenp = 0;
763f461d2dcSChristoph Hellwig 		return 0;
764f461d2dcSChristoph Hellwig 	}
765f461d2dcSChristoph Hellwig 
766f461d2dcSChristoph Hellwig 	i = (unsigned int *) tbl_data;
767f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(*i);
768f461d2dcSChristoph Hellwig 
769f461d2dcSChristoph Hellwig 	/*
770f461d2dcSChristoph Hellwig 	 * Arrays are not supported, keep this simple. *Do not* add
771f461d2dcSChristoph Hellwig 	 * support for them.
772f461d2dcSChristoph Hellwig 	 */
773f461d2dcSChristoph Hellwig 	if (vleft != 1) {
774f461d2dcSChristoph Hellwig 		*lenp = 0;
775f461d2dcSChristoph Hellwig 		return -EINVAL;
776f461d2dcSChristoph Hellwig 	}
777f461d2dcSChristoph Hellwig 
778f461d2dcSChristoph Hellwig 	if (!conv)
779f461d2dcSChristoph Hellwig 		conv = do_proc_douintvec_conv;
780f461d2dcSChristoph Hellwig 
781f461d2dcSChristoph Hellwig 	if (write)
782f461d2dcSChristoph Hellwig 		return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
783f461d2dcSChristoph Hellwig 					   conv, data);
784f461d2dcSChristoph Hellwig 	return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
785f461d2dcSChristoph Hellwig }
786f461d2dcSChristoph Hellwig 
787f461d2dcSChristoph Hellwig static int do_proc_douintvec(struct ctl_table *table, int write,
78832927393SChristoph Hellwig 			     void *buffer, size_t *lenp, loff_t *ppos,
789f461d2dcSChristoph Hellwig 			     int (*conv)(unsigned long *lvalp,
790f461d2dcSChristoph Hellwig 					 unsigned int *valp,
791f461d2dcSChristoph Hellwig 					 int write, void *data),
792f461d2dcSChristoph Hellwig 			     void *data)
793f461d2dcSChristoph Hellwig {
794f461d2dcSChristoph Hellwig 	return __do_proc_douintvec(table->data, table, write,
795f461d2dcSChristoph Hellwig 				   buffer, lenp, ppos, conv, data);
796f461d2dcSChristoph Hellwig }
797f461d2dcSChristoph Hellwig 
798f461d2dcSChristoph Hellwig /**
799a2071573SJia He  * proc_dobool - read/write a bool
800a2071573SJia He  * @table: the sysctl table
801a2071573SJia He  * @write: %TRUE if this is a write to the sysctl file
802a2071573SJia He  * @buffer: the user buffer
803a2071573SJia He  * @lenp: the size of the user buffer
804a2071573SJia He  * @ppos: file position
805a2071573SJia He  *
806a2071573SJia He  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
807a2071573SJia He  * values from/to the user buffer, treated as an ASCII string.
808a2071573SJia He  *
809a2071573SJia He  * Returns 0 on success.
810a2071573SJia He  */
811a2071573SJia He int proc_dobool(struct ctl_table *table, int write, void *buffer,
812a2071573SJia He 		size_t *lenp, loff_t *ppos)
813a2071573SJia He {
814a2071573SJia He 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
815a2071573SJia He 				do_proc_dobool_conv, NULL);
816a2071573SJia He }
817a2071573SJia He 
818a2071573SJia He /**
819f461d2dcSChristoph Hellwig  * proc_dointvec - read a vector of integers
820f461d2dcSChristoph Hellwig  * @table: the sysctl table
821f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
822f461d2dcSChristoph Hellwig  * @buffer: the user buffer
823f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
824f461d2dcSChristoph Hellwig  * @ppos: file position
825f461d2dcSChristoph Hellwig  *
826f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
827f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
828f461d2dcSChristoph Hellwig  *
829f461d2dcSChristoph Hellwig  * Returns 0 on success.
830f461d2dcSChristoph Hellwig  */
83132927393SChristoph Hellwig int proc_dointvec(struct ctl_table *table, int write, void *buffer,
83232927393SChristoph Hellwig 		  size_t *lenp, loff_t *ppos)
833f461d2dcSChristoph Hellwig {
834f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
835f461d2dcSChristoph Hellwig }
836f461d2dcSChristoph Hellwig 
837f461d2dcSChristoph Hellwig #ifdef CONFIG_COMPACTION
838f461d2dcSChristoph Hellwig static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
83932927393SChristoph Hellwig 		int write, void *buffer, size_t *lenp, loff_t *ppos)
840f461d2dcSChristoph Hellwig {
841f461d2dcSChristoph Hellwig 	int ret, old;
842f461d2dcSChristoph Hellwig 
843f461d2dcSChristoph Hellwig 	if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
844f461d2dcSChristoph Hellwig 		return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
845f461d2dcSChristoph Hellwig 
846f461d2dcSChristoph Hellwig 	old = *(int *)table->data;
847f461d2dcSChristoph Hellwig 	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
848f461d2dcSChristoph Hellwig 	if (ret)
849f461d2dcSChristoph Hellwig 		return ret;
850f461d2dcSChristoph Hellwig 	if (old != *(int *)table->data)
851f461d2dcSChristoph Hellwig 		pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
852f461d2dcSChristoph Hellwig 			     table->procname, current->comm,
853f461d2dcSChristoph Hellwig 			     task_pid_nr(current));
854f461d2dcSChristoph Hellwig 	return ret;
855f461d2dcSChristoph Hellwig }
856f461d2dcSChristoph Hellwig #endif
857f461d2dcSChristoph Hellwig 
858f461d2dcSChristoph Hellwig /**
859f461d2dcSChristoph Hellwig  * proc_douintvec - read a vector of unsigned integers
860f461d2dcSChristoph Hellwig  * @table: the sysctl table
861f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
862f461d2dcSChristoph Hellwig  * @buffer: the user buffer
863f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
864f461d2dcSChristoph Hellwig  * @ppos: file position
865f461d2dcSChristoph Hellwig  *
866f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
867f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
868f461d2dcSChristoph Hellwig  *
869f461d2dcSChristoph Hellwig  * Returns 0 on success.
870f461d2dcSChristoph Hellwig  */
87132927393SChristoph Hellwig int proc_douintvec(struct ctl_table *table, int write, void *buffer,
87232927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
873f461d2dcSChristoph Hellwig {
874f461d2dcSChristoph Hellwig 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
875f461d2dcSChristoph Hellwig 				 do_proc_douintvec_conv, NULL);
876f461d2dcSChristoph Hellwig }
877f461d2dcSChristoph Hellwig 
878f461d2dcSChristoph Hellwig /*
879f461d2dcSChristoph Hellwig  * Taint values can only be increased
880f461d2dcSChristoph Hellwig  * This means we can safely use a temporary.
881f461d2dcSChristoph Hellwig  */
882f461d2dcSChristoph Hellwig static int proc_taint(struct ctl_table *table, int write,
88332927393SChristoph Hellwig 			       void *buffer, size_t *lenp, loff_t *ppos)
884f461d2dcSChristoph Hellwig {
885f461d2dcSChristoph Hellwig 	struct ctl_table t;
886f461d2dcSChristoph Hellwig 	unsigned long tmptaint = get_taint();
887f461d2dcSChristoph Hellwig 	int err;
888f461d2dcSChristoph Hellwig 
889f461d2dcSChristoph Hellwig 	if (write && !capable(CAP_SYS_ADMIN))
890f461d2dcSChristoph Hellwig 		return -EPERM;
891f461d2dcSChristoph Hellwig 
892f461d2dcSChristoph Hellwig 	t = *table;
893f461d2dcSChristoph Hellwig 	t.data = &tmptaint;
894f461d2dcSChristoph Hellwig 	err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
895f461d2dcSChristoph Hellwig 	if (err < 0)
896f461d2dcSChristoph Hellwig 		return err;
897f461d2dcSChristoph Hellwig 
898f461d2dcSChristoph Hellwig 	if (write) {
899db38d5c1SRafael Aquini 		int i;
900db38d5c1SRafael Aquini 
901db38d5c1SRafael Aquini 		/*
902db38d5c1SRafael Aquini 		 * If we are relying on panic_on_taint not producing
903db38d5c1SRafael Aquini 		 * false positives due to userspace input, bail out
904db38d5c1SRafael Aquini 		 * before setting the requested taint flags.
905db38d5c1SRafael Aquini 		 */
906db38d5c1SRafael Aquini 		if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
907db38d5c1SRafael Aquini 			return -EINVAL;
908db38d5c1SRafael Aquini 
909f461d2dcSChristoph Hellwig 		/*
910f461d2dcSChristoph Hellwig 		 * Poor man's atomic or. Not worth adding a primitive
911f461d2dcSChristoph Hellwig 		 * to everyone's atomic.h for this
912f461d2dcSChristoph Hellwig 		 */
913e77132e7SRafael Aquini 		for (i = 0; i < TAINT_FLAGS_COUNT; i++)
914e77132e7SRafael Aquini 			if ((1UL << i) & tmptaint)
915f461d2dcSChristoph Hellwig 				add_taint(i, LOCKDEP_STILL_OK);
916f461d2dcSChristoph Hellwig 	}
917f461d2dcSChristoph Hellwig 
918f461d2dcSChristoph Hellwig 	return err;
919f461d2dcSChristoph Hellwig }
920f461d2dcSChristoph Hellwig 
921f461d2dcSChristoph Hellwig #ifdef CONFIG_PRINTK
922f461d2dcSChristoph Hellwig static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
92332927393SChristoph Hellwig 				void *buffer, size_t *lenp, loff_t *ppos)
924f461d2dcSChristoph Hellwig {
925f461d2dcSChristoph Hellwig 	if (write && !capable(CAP_SYS_ADMIN))
926f461d2dcSChristoph Hellwig 		return -EPERM;
927f461d2dcSChristoph Hellwig 
928f461d2dcSChristoph Hellwig 	return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
929f461d2dcSChristoph Hellwig }
930f461d2dcSChristoph Hellwig #endif
931f461d2dcSChristoph Hellwig 
932f461d2dcSChristoph Hellwig /**
933f461d2dcSChristoph Hellwig  * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
934f461d2dcSChristoph Hellwig  * @min: pointer to minimum allowable value
935f461d2dcSChristoph Hellwig  * @max: pointer to maximum allowable value
936f461d2dcSChristoph Hellwig  *
937f461d2dcSChristoph Hellwig  * The do_proc_dointvec_minmax_conv_param structure provides the
938f461d2dcSChristoph Hellwig  * minimum and maximum values for doing range checking for those sysctl
939f461d2dcSChristoph Hellwig  * parameters that use the proc_dointvec_minmax() handler.
940f461d2dcSChristoph Hellwig  */
941f461d2dcSChristoph Hellwig struct do_proc_dointvec_minmax_conv_param {
942f461d2dcSChristoph Hellwig 	int *min;
943f461d2dcSChristoph Hellwig 	int *max;
944f461d2dcSChristoph Hellwig };
945f461d2dcSChristoph Hellwig 
946f461d2dcSChristoph Hellwig static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
947f461d2dcSChristoph Hellwig 					int *valp,
948f461d2dcSChristoph Hellwig 					int write, void *data)
949f461d2dcSChristoph Hellwig {
950f461d2dcSChristoph Hellwig 	int tmp, ret;
951f461d2dcSChristoph Hellwig 	struct do_proc_dointvec_minmax_conv_param *param = data;
952f461d2dcSChristoph Hellwig 	/*
953f461d2dcSChristoph Hellwig 	 * If writing, first do so via a temporary local int so we can
954f461d2dcSChristoph Hellwig 	 * bounds-check it before touching *valp.
955f461d2dcSChristoph Hellwig 	 */
956f461d2dcSChristoph Hellwig 	int *ip = write ? &tmp : valp;
957f461d2dcSChristoph Hellwig 
958f461d2dcSChristoph Hellwig 	ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
959f461d2dcSChristoph Hellwig 	if (ret)
960f461d2dcSChristoph Hellwig 		return ret;
961f461d2dcSChristoph Hellwig 
962f461d2dcSChristoph Hellwig 	if (write) {
963f461d2dcSChristoph Hellwig 		if ((param->min && *param->min > tmp) ||
964f461d2dcSChristoph Hellwig 		    (param->max && *param->max < tmp))
965f461d2dcSChristoph Hellwig 			return -EINVAL;
966f461d2dcSChristoph Hellwig 		*valp = tmp;
967f461d2dcSChristoph Hellwig 	}
968f461d2dcSChristoph Hellwig 
969f461d2dcSChristoph Hellwig 	return 0;
970f461d2dcSChristoph Hellwig }
971f461d2dcSChristoph Hellwig 
972f461d2dcSChristoph Hellwig /**
973f461d2dcSChristoph Hellwig  * proc_dointvec_minmax - read a vector of integers with min/max values
974f461d2dcSChristoph Hellwig  * @table: the sysctl table
975f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
976f461d2dcSChristoph Hellwig  * @buffer: the user buffer
977f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
978f461d2dcSChristoph Hellwig  * @ppos: file position
979f461d2dcSChristoph Hellwig  *
980f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
981f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
982f461d2dcSChristoph Hellwig  *
983f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
984f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max).
985f461d2dcSChristoph Hellwig  *
986f461d2dcSChristoph Hellwig  * Returns 0 on success or -EINVAL on write when the range check fails.
987f461d2dcSChristoph Hellwig  */
988f461d2dcSChristoph Hellwig int proc_dointvec_minmax(struct ctl_table *table, int write,
98932927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
990f461d2dcSChristoph Hellwig {
991f461d2dcSChristoph Hellwig 	struct do_proc_dointvec_minmax_conv_param param = {
992f461d2dcSChristoph Hellwig 		.min = (int *) table->extra1,
993f461d2dcSChristoph Hellwig 		.max = (int *) table->extra2,
994f461d2dcSChristoph Hellwig 	};
995f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
996f461d2dcSChristoph Hellwig 				do_proc_dointvec_minmax_conv, &param);
997f461d2dcSChristoph Hellwig }
998f461d2dcSChristoph Hellwig 
999f461d2dcSChristoph Hellwig /**
1000f461d2dcSChristoph Hellwig  * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
1001f461d2dcSChristoph Hellwig  * @min: pointer to minimum allowable value
1002f461d2dcSChristoph Hellwig  * @max: pointer to maximum allowable value
1003f461d2dcSChristoph Hellwig  *
1004f461d2dcSChristoph Hellwig  * The do_proc_douintvec_minmax_conv_param structure provides the
1005f461d2dcSChristoph Hellwig  * minimum and maximum values for doing range checking for those sysctl
1006f461d2dcSChristoph Hellwig  * parameters that use the proc_douintvec_minmax() handler.
1007f461d2dcSChristoph Hellwig  */
1008f461d2dcSChristoph Hellwig struct do_proc_douintvec_minmax_conv_param {
1009f461d2dcSChristoph Hellwig 	unsigned int *min;
1010f461d2dcSChristoph Hellwig 	unsigned int *max;
1011f461d2dcSChristoph Hellwig };
1012f461d2dcSChristoph Hellwig 
1013f461d2dcSChristoph Hellwig static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
1014f461d2dcSChristoph Hellwig 					 unsigned int *valp,
1015f461d2dcSChristoph Hellwig 					 int write, void *data)
1016f461d2dcSChristoph Hellwig {
1017f461d2dcSChristoph Hellwig 	int ret;
1018f461d2dcSChristoph Hellwig 	unsigned int tmp;
1019f461d2dcSChristoph Hellwig 	struct do_proc_douintvec_minmax_conv_param *param = data;
1020f461d2dcSChristoph Hellwig 	/* write via temporary local uint for bounds-checking */
1021f461d2dcSChristoph Hellwig 	unsigned int *up = write ? &tmp : valp;
1022f461d2dcSChristoph Hellwig 
1023f461d2dcSChristoph Hellwig 	ret = do_proc_douintvec_conv(lvalp, up, write, data);
1024f461d2dcSChristoph Hellwig 	if (ret)
1025f461d2dcSChristoph Hellwig 		return ret;
1026f461d2dcSChristoph Hellwig 
1027f461d2dcSChristoph Hellwig 	if (write) {
1028f461d2dcSChristoph Hellwig 		if ((param->min && *param->min > tmp) ||
1029f461d2dcSChristoph Hellwig 		    (param->max && *param->max < tmp))
1030f461d2dcSChristoph Hellwig 			return -ERANGE;
1031f461d2dcSChristoph Hellwig 
1032f461d2dcSChristoph Hellwig 		*valp = tmp;
1033f461d2dcSChristoph Hellwig 	}
1034f461d2dcSChristoph Hellwig 
1035f461d2dcSChristoph Hellwig 	return 0;
1036f461d2dcSChristoph Hellwig }
1037f461d2dcSChristoph Hellwig 
1038f461d2dcSChristoph Hellwig /**
1039f461d2dcSChristoph Hellwig  * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
1040f461d2dcSChristoph Hellwig  * @table: the sysctl table
1041f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1042f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1043f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1044f461d2dcSChristoph Hellwig  * @ppos: file position
1045f461d2dcSChristoph Hellwig  *
1046f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
1047f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string. Negative
1048f461d2dcSChristoph Hellwig  * strings are not allowed.
1049f461d2dcSChristoph Hellwig  *
1050f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
1051f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max). There is a final sanity
1052f461d2dcSChristoph Hellwig  * check for UINT_MAX to avoid having to support wrap around uses from
1053f461d2dcSChristoph Hellwig  * userspace.
1054f461d2dcSChristoph Hellwig  *
1055f461d2dcSChristoph Hellwig  * Returns 0 on success or -ERANGE on write when the range check fails.
1056f461d2dcSChristoph Hellwig  */
1057f461d2dcSChristoph Hellwig int proc_douintvec_minmax(struct ctl_table *table, int write,
105832927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
1059f461d2dcSChristoph Hellwig {
1060f461d2dcSChristoph Hellwig 	struct do_proc_douintvec_minmax_conv_param param = {
1061f461d2dcSChristoph Hellwig 		.min = (unsigned int *) table->extra1,
1062f461d2dcSChristoph Hellwig 		.max = (unsigned int *) table->extra2,
1063f461d2dcSChristoph Hellwig 	};
1064f461d2dcSChristoph Hellwig 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
1065f461d2dcSChristoph Hellwig 				 do_proc_douintvec_minmax_conv, &param);
1066f461d2dcSChristoph Hellwig }
1067f461d2dcSChristoph Hellwig 
1068cb944413SEric Dumazet /**
1069cb944413SEric Dumazet  * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
1070cb944413SEric Dumazet  * @table: the sysctl table
1071cb944413SEric Dumazet  * @write: %TRUE if this is a write to the sysctl file
1072cb944413SEric Dumazet  * @buffer: the user buffer
1073cb944413SEric Dumazet  * @lenp: the size of the user buffer
1074cb944413SEric Dumazet  * @ppos: file position
1075cb944413SEric Dumazet  *
1076cb944413SEric Dumazet  * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
1077cb944413SEric Dumazet  * values from/to the user buffer, treated as an ASCII string. Negative
1078cb944413SEric Dumazet  * strings are not allowed.
1079cb944413SEric Dumazet  *
1080cb944413SEric Dumazet  * This routine will ensure the values are within the range specified by
1081cb944413SEric Dumazet  * table->extra1 (min) and table->extra2 (max).
1082cb944413SEric Dumazet  *
1083cb944413SEric Dumazet  * Returns 0 on success or an error on write when the range check fails.
1084cb944413SEric Dumazet  */
1085cb944413SEric Dumazet int proc_dou8vec_minmax(struct ctl_table *table, int write,
1086cb944413SEric Dumazet 			void *buffer, size_t *lenp, loff_t *ppos)
1087cb944413SEric Dumazet {
1088cb944413SEric Dumazet 	struct ctl_table tmp;
1089cb944413SEric Dumazet 	unsigned int min = 0, max = 255U, val;
1090cb944413SEric Dumazet 	u8 *data = table->data;
1091cb944413SEric Dumazet 	struct do_proc_douintvec_minmax_conv_param param = {
1092cb944413SEric Dumazet 		.min = &min,
1093cb944413SEric Dumazet 		.max = &max,
1094cb944413SEric Dumazet 	};
1095cb944413SEric Dumazet 	int res;
1096cb944413SEric Dumazet 
1097cb944413SEric Dumazet 	/* Do not support arrays yet. */
1098cb944413SEric Dumazet 	if (table->maxlen != sizeof(u8))
1099cb944413SEric Dumazet 		return -EINVAL;
1100cb944413SEric Dumazet 
1101cb944413SEric Dumazet 	if (table->extra1) {
1102cb944413SEric Dumazet 		min = *(unsigned int *) table->extra1;
1103cb944413SEric Dumazet 		if (min > 255U)
1104cb944413SEric Dumazet 			return -EINVAL;
1105cb944413SEric Dumazet 	}
1106cb944413SEric Dumazet 	if (table->extra2) {
1107cb944413SEric Dumazet 		max = *(unsigned int *) table->extra2;
1108cb944413SEric Dumazet 		if (max > 255U)
1109cb944413SEric Dumazet 			return -EINVAL;
1110cb944413SEric Dumazet 	}
1111cb944413SEric Dumazet 
1112cb944413SEric Dumazet 	tmp = *table;
1113cb944413SEric Dumazet 
1114cb944413SEric Dumazet 	tmp.maxlen = sizeof(val);
1115cb944413SEric Dumazet 	tmp.data = &val;
1116cb944413SEric Dumazet 	val = *data;
1117cb944413SEric Dumazet 	res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
1118cb944413SEric Dumazet 				do_proc_douintvec_minmax_conv, &param);
1119cb944413SEric Dumazet 	if (res)
1120cb944413SEric Dumazet 		return res;
1121cb944413SEric Dumazet 	if (write)
1122cb944413SEric Dumazet 		*data = val;
1123cb944413SEric Dumazet 	return 0;
1124cb944413SEric Dumazet }
1125cb944413SEric Dumazet EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
1126cb944413SEric Dumazet 
1127f461d2dcSChristoph Hellwig static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
1128f461d2dcSChristoph Hellwig 					unsigned int *valp,
1129f461d2dcSChristoph Hellwig 					int write, void *data)
1130f461d2dcSChristoph Hellwig {
1131f461d2dcSChristoph Hellwig 	if (write) {
1132f461d2dcSChristoph Hellwig 		unsigned int val;
1133f461d2dcSChristoph Hellwig 
1134f461d2dcSChristoph Hellwig 		val = round_pipe_size(*lvalp);
1135f461d2dcSChristoph Hellwig 		if (val == 0)
1136f461d2dcSChristoph Hellwig 			return -EINVAL;
1137f461d2dcSChristoph Hellwig 
1138f461d2dcSChristoph Hellwig 		*valp = val;
1139f461d2dcSChristoph Hellwig 	} else {
1140f461d2dcSChristoph Hellwig 		unsigned int val = *valp;
1141f461d2dcSChristoph Hellwig 		*lvalp = (unsigned long) val;
1142f461d2dcSChristoph Hellwig 	}
1143f461d2dcSChristoph Hellwig 
1144f461d2dcSChristoph Hellwig 	return 0;
1145f461d2dcSChristoph Hellwig }
1146f461d2dcSChristoph Hellwig 
1147f461d2dcSChristoph Hellwig static int proc_dopipe_max_size(struct ctl_table *table, int write,
114832927393SChristoph Hellwig 				void *buffer, size_t *lenp, loff_t *ppos)
1149f461d2dcSChristoph Hellwig {
1150f461d2dcSChristoph Hellwig 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
1151f461d2dcSChristoph Hellwig 				 do_proc_dopipe_max_size_conv, NULL);
1152f461d2dcSChristoph Hellwig }
1153f461d2dcSChristoph Hellwig 
1154f461d2dcSChristoph Hellwig static void validate_coredump_safety(void)
1155f461d2dcSChristoph Hellwig {
1156f461d2dcSChristoph Hellwig #ifdef CONFIG_COREDUMP
1157f461d2dcSChristoph Hellwig 	if (suid_dumpable == SUID_DUMP_ROOT &&
1158f461d2dcSChristoph Hellwig 	    core_pattern[0] != '/' && core_pattern[0] != '|') {
1159f461d2dcSChristoph Hellwig 		printk(KERN_WARNING
1160f461d2dcSChristoph Hellwig "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
1161f461d2dcSChristoph Hellwig "Pipe handler or fully qualified core dump path required.\n"
1162f461d2dcSChristoph Hellwig "Set kernel.core_pattern before fs.suid_dumpable.\n"
1163f461d2dcSChristoph Hellwig 		);
1164f461d2dcSChristoph Hellwig 	}
1165f461d2dcSChristoph Hellwig #endif
1166f461d2dcSChristoph Hellwig }
1167f461d2dcSChristoph Hellwig 
1168f461d2dcSChristoph Hellwig static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
116932927393SChristoph Hellwig 		void *buffer, size_t *lenp, loff_t *ppos)
1170f461d2dcSChristoph Hellwig {
1171f461d2dcSChristoph Hellwig 	int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1172f461d2dcSChristoph Hellwig 	if (!error)
1173f461d2dcSChristoph Hellwig 		validate_coredump_safety();
1174f461d2dcSChristoph Hellwig 	return error;
1175f461d2dcSChristoph Hellwig }
1176f461d2dcSChristoph Hellwig 
1177f461d2dcSChristoph Hellwig #ifdef CONFIG_COREDUMP
1178f461d2dcSChristoph Hellwig static int proc_dostring_coredump(struct ctl_table *table, int write,
117932927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1180f461d2dcSChristoph Hellwig {
1181f461d2dcSChristoph Hellwig 	int error = proc_dostring(table, write, buffer, lenp, ppos);
1182f461d2dcSChristoph Hellwig 	if (!error)
1183f461d2dcSChristoph Hellwig 		validate_coredump_safety();
1184f461d2dcSChristoph Hellwig 	return error;
1185f461d2dcSChristoph Hellwig }
1186f461d2dcSChristoph Hellwig #endif
1187f461d2dcSChristoph Hellwig 
1188f461d2dcSChristoph Hellwig #ifdef CONFIG_MAGIC_SYSRQ
1189f461d2dcSChristoph Hellwig static int sysrq_sysctl_handler(struct ctl_table *table, int write,
119032927393SChristoph Hellwig 				void *buffer, size_t *lenp, loff_t *ppos)
1191f461d2dcSChristoph Hellwig {
1192f461d2dcSChristoph Hellwig 	int tmp, ret;
1193f461d2dcSChristoph Hellwig 
1194f461d2dcSChristoph Hellwig 	tmp = sysrq_mask();
1195f461d2dcSChristoph Hellwig 
1196f461d2dcSChristoph Hellwig 	ret = __do_proc_dointvec(&tmp, table, write, buffer,
1197f461d2dcSChristoph Hellwig 			       lenp, ppos, NULL, NULL);
1198f461d2dcSChristoph Hellwig 	if (ret || !write)
1199f461d2dcSChristoph Hellwig 		return ret;
1200f461d2dcSChristoph Hellwig 
1201f461d2dcSChristoph Hellwig 	if (write)
1202f461d2dcSChristoph Hellwig 		sysrq_toggle_support(tmp);
1203f461d2dcSChristoph Hellwig 
1204f461d2dcSChristoph Hellwig 	return 0;
1205f461d2dcSChristoph Hellwig }
1206f461d2dcSChristoph Hellwig #endif
1207f461d2dcSChristoph Hellwig 
120832927393SChristoph Hellwig static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
120932927393SChristoph Hellwig 		int write, void *buffer, size_t *lenp, loff_t *ppos,
121032927393SChristoph Hellwig 		unsigned long convmul, unsigned long convdiv)
1211f461d2dcSChristoph Hellwig {
1212f461d2dcSChristoph Hellwig 	unsigned long *i, *min, *max;
1213f461d2dcSChristoph Hellwig 	int vleft, first = 1, err = 0;
1214f461d2dcSChristoph Hellwig 	size_t left;
121532927393SChristoph Hellwig 	char *p;
1216f461d2dcSChristoph Hellwig 
1217f461d2dcSChristoph Hellwig 	if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1218f461d2dcSChristoph Hellwig 		*lenp = 0;
1219f461d2dcSChristoph Hellwig 		return 0;
1220f461d2dcSChristoph Hellwig 	}
1221f461d2dcSChristoph Hellwig 
1222f461d2dcSChristoph Hellwig 	i = (unsigned long *) data;
1223f461d2dcSChristoph Hellwig 	min = (unsigned long *) table->extra1;
1224f461d2dcSChristoph Hellwig 	max = (unsigned long *) table->extra2;
1225f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(unsigned long);
1226f461d2dcSChristoph Hellwig 	left = *lenp;
1227f461d2dcSChristoph Hellwig 
1228f461d2dcSChristoph Hellwig 	if (write) {
1229f461d2dcSChristoph Hellwig 		if (proc_first_pos_non_zero_ignore(ppos, table))
1230f461d2dcSChristoph Hellwig 			goto out;
1231f461d2dcSChristoph Hellwig 
1232f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1)
1233f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
123432927393SChristoph Hellwig 		p = buffer;
1235f461d2dcSChristoph Hellwig 	}
1236f461d2dcSChristoph Hellwig 
1237f461d2dcSChristoph Hellwig 	for (; left && vleft--; i++, first = 0) {
1238f461d2dcSChristoph Hellwig 		unsigned long val;
1239f461d2dcSChristoph Hellwig 
1240f461d2dcSChristoph Hellwig 		if (write) {
1241f461d2dcSChristoph Hellwig 			bool neg;
1242f461d2dcSChristoph Hellwig 
1243f461d2dcSChristoph Hellwig 			left -= proc_skip_spaces(&p);
1244f461d2dcSChristoph Hellwig 			if (!left)
1245f461d2dcSChristoph Hellwig 				break;
1246f461d2dcSChristoph Hellwig 
1247f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &val, &neg,
1248f461d2dcSChristoph Hellwig 					     proc_wspace_sep,
1249f461d2dcSChristoph Hellwig 					     sizeof(proc_wspace_sep), NULL);
1250f461d2dcSChristoph Hellwig 			if (err)
1251f461d2dcSChristoph Hellwig 				break;
1252f461d2dcSChristoph Hellwig 			if (neg)
1253f461d2dcSChristoph Hellwig 				continue;
1254f461d2dcSChristoph Hellwig 			val = convmul * val / convdiv;
1255f461d2dcSChristoph Hellwig 			if ((min && val < *min) || (max && val > *max)) {
1256f461d2dcSChristoph Hellwig 				err = -EINVAL;
1257f461d2dcSChristoph Hellwig 				break;
1258f461d2dcSChristoph Hellwig 			}
1259f461d2dcSChristoph Hellwig 			*i = val;
1260f461d2dcSChristoph Hellwig 		} else {
1261f461d2dcSChristoph Hellwig 			val = convdiv * (*i) / convmul;
126232927393SChristoph Hellwig 			if (!first)
126332927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '\t');
126432927393SChristoph Hellwig 			proc_put_long(&buffer, &left, val, false);
1265f461d2dcSChristoph Hellwig 		}
1266f461d2dcSChristoph Hellwig 	}
1267f461d2dcSChristoph Hellwig 
1268f461d2dcSChristoph Hellwig 	if (!write && !first && left && !err)
126932927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
1270f461d2dcSChristoph Hellwig 	if (write && !err)
1271f461d2dcSChristoph Hellwig 		left -= proc_skip_spaces(&p);
127232927393SChristoph Hellwig 	if (write && first)
1273f461d2dcSChristoph Hellwig 		return err ? : -EINVAL;
1274f461d2dcSChristoph Hellwig 	*lenp -= left;
1275f461d2dcSChristoph Hellwig out:
1276f461d2dcSChristoph Hellwig 	*ppos += *lenp;
1277f461d2dcSChristoph Hellwig 	return err;
1278f461d2dcSChristoph Hellwig }
1279f461d2dcSChristoph Hellwig 
1280f461d2dcSChristoph Hellwig static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
128132927393SChristoph Hellwig 		void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1282f461d2dcSChristoph Hellwig 		unsigned long convdiv)
1283f461d2dcSChristoph Hellwig {
1284f461d2dcSChristoph Hellwig 	return __do_proc_doulongvec_minmax(table->data, table, write,
1285f461d2dcSChristoph Hellwig 			buffer, lenp, ppos, convmul, convdiv);
1286f461d2dcSChristoph Hellwig }
1287f461d2dcSChristoph Hellwig 
1288f461d2dcSChristoph Hellwig /**
1289f461d2dcSChristoph Hellwig  * proc_doulongvec_minmax - read a vector of long integers with min/max values
1290f461d2dcSChristoph Hellwig  * @table: the sysctl table
1291f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1292f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1293f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1294f461d2dcSChristoph Hellwig  * @ppos: file position
1295f461d2dcSChristoph Hellwig  *
1296f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1297f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1298f461d2dcSChristoph Hellwig  *
1299f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
1300f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max).
1301f461d2dcSChristoph Hellwig  *
1302f461d2dcSChristoph Hellwig  * Returns 0 on success.
1303f461d2dcSChristoph Hellwig  */
1304f461d2dcSChristoph Hellwig int proc_doulongvec_minmax(struct ctl_table *table, int write,
130532927393SChristoph Hellwig 			   void *buffer, size_t *lenp, loff_t *ppos)
1306f461d2dcSChristoph Hellwig {
1307f461d2dcSChristoph Hellwig     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1308f461d2dcSChristoph Hellwig }
1309f461d2dcSChristoph Hellwig 
1310f461d2dcSChristoph Hellwig /**
1311f461d2dcSChristoph Hellwig  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1312f461d2dcSChristoph Hellwig  * @table: the sysctl table
1313f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1314f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1315f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1316f461d2dcSChristoph Hellwig  * @ppos: file position
1317f461d2dcSChristoph Hellwig  *
1318f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1319f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string. The values
1320f461d2dcSChristoph Hellwig  * are treated as milliseconds, and converted to jiffies when they are stored.
1321f461d2dcSChristoph Hellwig  *
1322f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
1323f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max).
1324f461d2dcSChristoph Hellwig  *
1325f461d2dcSChristoph Hellwig  * Returns 0 on success.
1326f461d2dcSChristoph Hellwig  */
1327f461d2dcSChristoph Hellwig int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
132832927393SChristoph Hellwig 				      void *buffer, size_t *lenp, loff_t *ppos)
1329f461d2dcSChristoph Hellwig {
1330f461d2dcSChristoph Hellwig     return do_proc_doulongvec_minmax(table, write, buffer,
1331f461d2dcSChristoph Hellwig 				     lenp, ppos, HZ, 1000l);
1332f461d2dcSChristoph Hellwig }
1333f461d2dcSChristoph Hellwig 
1334f461d2dcSChristoph Hellwig 
1335f461d2dcSChristoph Hellwig static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1336f461d2dcSChristoph Hellwig 					 int *valp,
1337f461d2dcSChristoph Hellwig 					 int write, void *data)
1338f461d2dcSChristoph Hellwig {
1339f461d2dcSChristoph Hellwig 	if (write) {
1340f461d2dcSChristoph Hellwig 		if (*lvalp > INT_MAX / HZ)
1341f461d2dcSChristoph Hellwig 			return 1;
1342f461d2dcSChristoph Hellwig 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1343f461d2dcSChristoph Hellwig 	} else {
1344f461d2dcSChristoph Hellwig 		int val = *valp;
1345f461d2dcSChristoph Hellwig 		unsigned long lval;
1346f461d2dcSChristoph Hellwig 		if (val < 0) {
1347f461d2dcSChristoph Hellwig 			*negp = true;
1348f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1349f461d2dcSChristoph Hellwig 		} else {
1350f461d2dcSChristoph Hellwig 			*negp = false;
1351f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1352f461d2dcSChristoph Hellwig 		}
1353f461d2dcSChristoph Hellwig 		*lvalp = lval / HZ;
1354f461d2dcSChristoph Hellwig 	}
1355f461d2dcSChristoph Hellwig 	return 0;
1356f461d2dcSChristoph Hellwig }
1357f461d2dcSChristoph Hellwig 
1358f461d2dcSChristoph Hellwig static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1359f461d2dcSChristoph Hellwig 						int *valp,
1360f461d2dcSChristoph Hellwig 						int write, void *data)
1361f461d2dcSChristoph Hellwig {
1362f461d2dcSChristoph Hellwig 	if (write) {
1363f461d2dcSChristoph Hellwig 		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1364f461d2dcSChristoph Hellwig 			return 1;
1365f461d2dcSChristoph Hellwig 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1366f461d2dcSChristoph Hellwig 	} else {
1367f461d2dcSChristoph Hellwig 		int val = *valp;
1368f461d2dcSChristoph Hellwig 		unsigned long lval;
1369f461d2dcSChristoph Hellwig 		if (val < 0) {
1370f461d2dcSChristoph Hellwig 			*negp = true;
1371f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1372f461d2dcSChristoph Hellwig 		} else {
1373f461d2dcSChristoph Hellwig 			*negp = false;
1374f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1375f461d2dcSChristoph Hellwig 		}
1376f461d2dcSChristoph Hellwig 		*lvalp = jiffies_to_clock_t(lval);
1377f461d2dcSChristoph Hellwig 	}
1378f461d2dcSChristoph Hellwig 	return 0;
1379f461d2dcSChristoph Hellwig }
1380f461d2dcSChristoph Hellwig 
1381f461d2dcSChristoph Hellwig static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1382f461d2dcSChristoph Hellwig 					    int *valp,
1383f461d2dcSChristoph Hellwig 					    int write, void *data)
1384f461d2dcSChristoph Hellwig {
1385f461d2dcSChristoph Hellwig 	if (write) {
1386f461d2dcSChristoph Hellwig 		unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1387f461d2dcSChristoph Hellwig 
1388f461d2dcSChristoph Hellwig 		if (jif > INT_MAX)
1389f461d2dcSChristoph Hellwig 			return 1;
1390f461d2dcSChristoph Hellwig 		*valp = (int)jif;
1391f461d2dcSChristoph Hellwig 	} else {
1392f461d2dcSChristoph Hellwig 		int val = *valp;
1393f461d2dcSChristoph Hellwig 		unsigned long lval;
1394f461d2dcSChristoph Hellwig 		if (val < 0) {
1395f461d2dcSChristoph Hellwig 			*negp = true;
1396f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1397f461d2dcSChristoph Hellwig 		} else {
1398f461d2dcSChristoph Hellwig 			*negp = false;
1399f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1400f461d2dcSChristoph Hellwig 		}
1401f461d2dcSChristoph Hellwig 		*lvalp = jiffies_to_msecs(lval);
1402f461d2dcSChristoph Hellwig 	}
1403f461d2dcSChristoph Hellwig 	return 0;
1404f461d2dcSChristoph Hellwig }
1405f461d2dcSChristoph Hellwig 
1406f461d2dcSChristoph Hellwig /**
1407f461d2dcSChristoph Hellwig  * proc_dointvec_jiffies - read a vector of integers as seconds
1408f461d2dcSChristoph Hellwig  * @table: the sysctl table
1409f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1410f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1411f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1412f461d2dcSChristoph Hellwig  * @ppos: file position
1413f461d2dcSChristoph Hellwig  *
1414f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1415f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1416f461d2dcSChristoph Hellwig  * The values read are assumed to be in seconds, and are converted into
1417f461d2dcSChristoph Hellwig  * jiffies.
1418f461d2dcSChristoph Hellwig  *
1419f461d2dcSChristoph Hellwig  * Returns 0 on success.
1420f461d2dcSChristoph Hellwig  */
1421f461d2dcSChristoph Hellwig int proc_dointvec_jiffies(struct ctl_table *table, int write,
142232927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
1423f461d2dcSChristoph Hellwig {
1424f461d2dcSChristoph Hellwig     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1425f461d2dcSChristoph Hellwig 		    	    do_proc_dointvec_jiffies_conv,NULL);
1426f461d2dcSChristoph Hellwig }
1427f461d2dcSChristoph Hellwig 
1428f461d2dcSChristoph Hellwig /**
1429f461d2dcSChristoph Hellwig  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1430f461d2dcSChristoph Hellwig  * @table: the sysctl table
1431f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1432f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1433f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1434f461d2dcSChristoph Hellwig  * @ppos: pointer to the file position
1435f461d2dcSChristoph Hellwig  *
1436f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1437f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1438f461d2dcSChristoph Hellwig  * The values read are assumed to be in 1/USER_HZ seconds, and
1439f461d2dcSChristoph Hellwig  * are converted into jiffies.
1440f461d2dcSChristoph Hellwig  *
1441f461d2dcSChristoph Hellwig  * Returns 0 on success.
1442f461d2dcSChristoph Hellwig  */
1443f461d2dcSChristoph Hellwig int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
144432927393SChristoph Hellwig 				 void *buffer, size_t *lenp, loff_t *ppos)
1445f461d2dcSChristoph Hellwig {
1446f461d2dcSChristoph Hellwig     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1447f461d2dcSChristoph Hellwig 		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);
1448f461d2dcSChristoph Hellwig }
1449f461d2dcSChristoph Hellwig 
1450f461d2dcSChristoph Hellwig /**
1451f461d2dcSChristoph Hellwig  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1452f461d2dcSChristoph Hellwig  * @table: the sysctl table
1453f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1454f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1455f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1456f461d2dcSChristoph Hellwig  * @ppos: file position
1457f461d2dcSChristoph Hellwig  * @ppos: the current position in the file
1458f461d2dcSChristoph Hellwig  *
1459f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1460f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1461f461d2dcSChristoph Hellwig  * The values read are assumed to be in 1/1000 seconds, and
1462f461d2dcSChristoph Hellwig  * are converted into jiffies.
1463f461d2dcSChristoph Hellwig  *
1464f461d2dcSChristoph Hellwig  * Returns 0 on success.
1465f461d2dcSChristoph Hellwig  */
146632927393SChristoph Hellwig int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
146732927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
1468f461d2dcSChristoph Hellwig {
1469f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
1470f461d2dcSChristoph Hellwig 				do_proc_dointvec_ms_jiffies_conv, NULL);
1471f461d2dcSChristoph Hellwig }
1472f461d2dcSChristoph Hellwig 
147332927393SChristoph Hellwig static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
147432927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
1475f461d2dcSChristoph Hellwig {
1476f461d2dcSChristoph Hellwig 	struct pid *new_pid;
1477f461d2dcSChristoph Hellwig 	pid_t tmp;
1478f461d2dcSChristoph Hellwig 	int r;
1479f461d2dcSChristoph Hellwig 
1480f461d2dcSChristoph Hellwig 	tmp = pid_vnr(cad_pid);
1481f461d2dcSChristoph Hellwig 
1482f461d2dcSChristoph Hellwig 	r = __do_proc_dointvec(&tmp, table, write, buffer,
1483f461d2dcSChristoph Hellwig 			       lenp, ppos, NULL, NULL);
1484f461d2dcSChristoph Hellwig 	if (r || !write)
1485f461d2dcSChristoph Hellwig 		return r;
1486f461d2dcSChristoph Hellwig 
1487f461d2dcSChristoph Hellwig 	new_pid = find_get_pid(tmp);
1488f461d2dcSChristoph Hellwig 	if (!new_pid)
1489f461d2dcSChristoph Hellwig 		return -ESRCH;
1490f461d2dcSChristoph Hellwig 
1491f461d2dcSChristoph Hellwig 	put_pid(xchg(&cad_pid, new_pid));
1492f461d2dcSChristoph Hellwig 	return 0;
1493f461d2dcSChristoph Hellwig }
1494f461d2dcSChristoph Hellwig 
1495f461d2dcSChristoph Hellwig /**
1496f461d2dcSChristoph Hellwig  * proc_do_large_bitmap - read/write from/to a large bitmap
1497f461d2dcSChristoph Hellwig  * @table: the sysctl table
1498f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1499f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1500f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1501f461d2dcSChristoph Hellwig  * @ppos: file position
1502f461d2dcSChristoph Hellwig  *
1503f461d2dcSChristoph Hellwig  * The bitmap is stored at table->data and the bitmap length (in bits)
1504f461d2dcSChristoph Hellwig  * in table->maxlen.
1505f461d2dcSChristoph Hellwig  *
1506f461d2dcSChristoph Hellwig  * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1507f461d2dcSChristoph Hellwig  * large bitmaps may be represented in a compact manner. Writing into
1508f461d2dcSChristoph Hellwig  * the file will clear the bitmap then update it with the given input.
1509f461d2dcSChristoph Hellwig  *
1510f461d2dcSChristoph Hellwig  * Returns 0 on success.
1511f461d2dcSChristoph Hellwig  */
1512f461d2dcSChristoph Hellwig int proc_do_large_bitmap(struct ctl_table *table, int write,
151332927393SChristoph Hellwig 			 void *buffer, size_t *lenp, loff_t *ppos)
1514f461d2dcSChristoph Hellwig {
1515f461d2dcSChristoph Hellwig 	int err = 0;
1516f461d2dcSChristoph Hellwig 	size_t left = *lenp;
1517f461d2dcSChristoph Hellwig 	unsigned long bitmap_len = table->maxlen;
1518f461d2dcSChristoph Hellwig 	unsigned long *bitmap = *(unsigned long **) table->data;
1519f461d2dcSChristoph Hellwig 	unsigned long *tmp_bitmap = NULL;
1520f461d2dcSChristoph Hellwig 	char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1521f461d2dcSChristoph Hellwig 
1522f461d2dcSChristoph Hellwig 	if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1523f461d2dcSChristoph Hellwig 		*lenp = 0;
1524f461d2dcSChristoph Hellwig 		return 0;
1525f461d2dcSChristoph Hellwig 	}
1526f461d2dcSChristoph Hellwig 
1527f461d2dcSChristoph Hellwig 	if (write) {
152832927393SChristoph Hellwig 		char *p = buffer;
1529f461d2dcSChristoph Hellwig 		size_t skipped = 0;
1530f461d2dcSChristoph Hellwig 
1531f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1) {
1532f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
1533f461d2dcSChristoph Hellwig 			/* How much of the buffer we'll skip this pass */
1534f461d2dcSChristoph Hellwig 			skipped = *lenp - left;
1535f461d2dcSChristoph Hellwig 		}
1536f461d2dcSChristoph Hellwig 
1537f461d2dcSChristoph Hellwig 		tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
153832927393SChristoph Hellwig 		if (!tmp_bitmap)
1539f461d2dcSChristoph Hellwig 			return -ENOMEM;
1540f461d2dcSChristoph Hellwig 		proc_skip_char(&p, &left, '\n');
1541f461d2dcSChristoph Hellwig 		while (!err && left) {
1542f461d2dcSChristoph Hellwig 			unsigned long val_a, val_b;
1543f461d2dcSChristoph Hellwig 			bool neg;
1544f461d2dcSChristoph Hellwig 			size_t saved_left;
1545f461d2dcSChristoph Hellwig 
1546f461d2dcSChristoph Hellwig 			/* In case we stop parsing mid-number, we can reset */
1547f461d2dcSChristoph Hellwig 			saved_left = left;
1548f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1549f461d2dcSChristoph Hellwig 					     sizeof(tr_a), &c);
1550f461d2dcSChristoph Hellwig 			/*
1551f461d2dcSChristoph Hellwig 			 * If we consumed the entirety of a truncated buffer or
1552f461d2dcSChristoph Hellwig 			 * only one char is left (may be a "-"), then stop here,
1553f461d2dcSChristoph Hellwig 			 * reset, & come back for more.
1554f461d2dcSChristoph Hellwig 			 */
1555f461d2dcSChristoph Hellwig 			if ((left <= 1) && skipped) {
1556f461d2dcSChristoph Hellwig 				left = saved_left;
1557f461d2dcSChristoph Hellwig 				break;
1558f461d2dcSChristoph Hellwig 			}
1559f461d2dcSChristoph Hellwig 
1560f461d2dcSChristoph Hellwig 			if (err)
1561f461d2dcSChristoph Hellwig 				break;
1562f461d2dcSChristoph Hellwig 			if (val_a >= bitmap_len || neg) {
1563f461d2dcSChristoph Hellwig 				err = -EINVAL;
1564f461d2dcSChristoph Hellwig 				break;
1565f461d2dcSChristoph Hellwig 			}
1566f461d2dcSChristoph Hellwig 
1567f461d2dcSChristoph Hellwig 			val_b = val_a;
1568f461d2dcSChristoph Hellwig 			if (left) {
1569f461d2dcSChristoph Hellwig 				p++;
1570f461d2dcSChristoph Hellwig 				left--;
1571f461d2dcSChristoph Hellwig 			}
1572f461d2dcSChristoph Hellwig 
1573f461d2dcSChristoph Hellwig 			if (c == '-') {
1574f461d2dcSChristoph Hellwig 				err = proc_get_long(&p, &left, &val_b,
1575f461d2dcSChristoph Hellwig 						     &neg, tr_b, sizeof(tr_b),
1576f461d2dcSChristoph Hellwig 						     &c);
1577f461d2dcSChristoph Hellwig 				/*
1578f461d2dcSChristoph Hellwig 				 * If we consumed all of a truncated buffer or
1579f461d2dcSChristoph Hellwig 				 * then stop here, reset, & come back for more.
1580f461d2dcSChristoph Hellwig 				 */
1581f461d2dcSChristoph Hellwig 				if (!left && skipped) {
1582f461d2dcSChristoph Hellwig 					left = saved_left;
1583f461d2dcSChristoph Hellwig 					break;
1584f461d2dcSChristoph Hellwig 				}
1585f461d2dcSChristoph Hellwig 
1586f461d2dcSChristoph Hellwig 				if (err)
1587f461d2dcSChristoph Hellwig 					break;
1588f461d2dcSChristoph Hellwig 				if (val_b >= bitmap_len || neg ||
1589f461d2dcSChristoph Hellwig 				    val_a > val_b) {
1590f461d2dcSChristoph Hellwig 					err = -EINVAL;
1591f461d2dcSChristoph Hellwig 					break;
1592f461d2dcSChristoph Hellwig 				}
1593f461d2dcSChristoph Hellwig 				if (left) {
1594f461d2dcSChristoph Hellwig 					p++;
1595f461d2dcSChristoph Hellwig 					left--;
1596f461d2dcSChristoph Hellwig 				}
1597f461d2dcSChristoph Hellwig 			}
1598f461d2dcSChristoph Hellwig 
1599f461d2dcSChristoph Hellwig 			bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1600f461d2dcSChristoph Hellwig 			proc_skip_char(&p, &left, '\n');
1601f461d2dcSChristoph Hellwig 		}
1602f461d2dcSChristoph Hellwig 		left += skipped;
1603f461d2dcSChristoph Hellwig 	} else {
1604f461d2dcSChristoph Hellwig 		unsigned long bit_a, bit_b = 0;
16059a52c5f3SJiapeng Chong 		bool first = 1;
1606f461d2dcSChristoph Hellwig 
1607f461d2dcSChristoph Hellwig 		while (left) {
1608f461d2dcSChristoph Hellwig 			bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1609f461d2dcSChristoph Hellwig 			if (bit_a >= bitmap_len)
1610f461d2dcSChristoph Hellwig 				break;
1611f461d2dcSChristoph Hellwig 			bit_b = find_next_zero_bit(bitmap, bitmap_len,
1612f461d2dcSChristoph Hellwig 						   bit_a + 1) - 1;
1613f461d2dcSChristoph Hellwig 
161432927393SChristoph Hellwig 			if (!first)
161532927393SChristoph Hellwig 				proc_put_char(&buffer, &left, ',');
161632927393SChristoph Hellwig 			proc_put_long(&buffer, &left, bit_a, false);
1617f461d2dcSChristoph Hellwig 			if (bit_a != bit_b) {
161832927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '-');
161932927393SChristoph Hellwig 				proc_put_long(&buffer, &left, bit_b, false);
1620f461d2dcSChristoph Hellwig 			}
1621f461d2dcSChristoph Hellwig 
1622f461d2dcSChristoph Hellwig 			first = 0; bit_b++;
1623f461d2dcSChristoph Hellwig 		}
162432927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
1625f461d2dcSChristoph Hellwig 	}
1626f461d2dcSChristoph Hellwig 
1627f461d2dcSChristoph Hellwig 	if (!err) {
1628f461d2dcSChristoph Hellwig 		if (write) {
1629f461d2dcSChristoph Hellwig 			if (*ppos)
1630f461d2dcSChristoph Hellwig 				bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1631f461d2dcSChristoph Hellwig 			else
1632f461d2dcSChristoph Hellwig 				bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1633f461d2dcSChristoph Hellwig 		}
1634f461d2dcSChristoph Hellwig 		*lenp -= left;
1635f461d2dcSChristoph Hellwig 		*ppos += *lenp;
1636f461d2dcSChristoph Hellwig 	}
1637f461d2dcSChristoph Hellwig 
1638f461d2dcSChristoph Hellwig 	bitmap_free(tmp_bitmap);
1639f461d2dcSChristoph Hellwig 	return err;
1640f461d2dcSChristoph Hellwig }
1641f461d2dcSChristoph Hellwig 
1642f461d2dcSChristoph Hellwig #else /* CONFIG_PROC_SYSCTL */
1643f461d2dcSChristoph Hellwig 
1644f461d2dcSChristoph Hellwig int proc_dostring(struct ctl_table *table, int write,
164532927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1646f461d2dcSChristoph Hellwig {
1647f461d2dcSChristoph Hellwig 	return -ENOSYS;
1648f461d2dcSChristoph Hellwig }
1649f461d2dcSChristoph Hellwig 
1650a2071573SJia He int proc_dobool(struct ctl_table *table, int write,
1651a2071573SJia He 		void *buffer, size_t *lenp, loff_t *ppos)
1652a2071573SJia He {
1653a2071573SJia He 	return -ENOSYS;
1654a2071573SJia He }
1655a2071573SJia He 
1656f461d2dcSChristoph Hellwig int proc_dointvec(struct ctl_table *table, int write,
165732927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1658f461d2dcSChristoph Hellwig {
1659f461d2dcSChristoph Hellwig 	return -ENOSYS;
1660f461d2dcSChristoph Hellwig }
1661f461d2dcSChristoph Hellwig 
1662f461d2dcSChristoph Hellwig int proc_douintvec(struct ctl_table *table, int write,
166332927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1664f461d2dcSChristoph Hellwig {
1665f461d2dcSChristoph Hellwig 	return -ENOSYS;
1666f461d2dcSChristoph Hellwig }
1667f461d2dcSChristoph Hellwig 
1668f461d2dcSChristoph Hellwig int proc_dointvec_minmax(struct ctl_table *table, int write,
166932927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1670f461d2dcSChristoph Hellwig {
1671f461d2dcSChristoph Hellwig 	return -ENOSYS;
1672f461d2dcSChristoph Hellwig }
1673f461d2dcSChristoph Hellwig 
1674f461d2dcSChristoph Hellwig int proc_douintvec_minmax(struct ctl_table *table, int write,
167532927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
1676f461d2dcSChristoph Hellwig {
1677f461d2dcSChristoph Hellwig 	return -ENOSYS;
1678f461d2dcSChristoph Hellwig }
1679f461d2dcSChristoph Hellwig 
1680cb944413SEric Dumazet int proc_dou8vec_minmax(struct ctl_table *table, int write,
1681cb944413SEric Dumazet 			void *buffer, size_t *lenp, loff_t *ppos)
1682cb944413SEric Dumazet {
1683cb944413SEric Dumazet 	return -ENOSYS;
1684cb944413SEric Dumazet }
1685cb944413SEric Dumazet 
1686f461d2dcSChristoph Hellwig int proc_dointvec_jiffies(struct ctl_table *table, int write,
168732927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1688f461d2dcSChristoph Hellwig {
1689f461d2dcSChristoph Hellwig 	return -ENOSYS;
1690f461d2dcSChristoph Hellwig }
1691f461d2dcSChristoph Hellwig 
1692f461d2dcSChristoph Hellwig int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
169332927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1694f461d2dcSChristoph Hellwig {
1695f461d2dcSChristoph Hellwig 	return -ENOSYS;
1696f461d2dcSChristoph Hellwig }
1697f461d2dcSChristoph Hellwig 
1698f461d2dcSChristoph Hellwig int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
169932927393SChristoph Hellwig 			     void *buffer, size_t *lenp, loff_t *ppos)
1700f461d2dcSChristoph Hellwig {
1701f461d2dcSChristoph Hellwig 	return -ENOSYS;
1702f461d2dcSChristoph Hellwig }
1703f461d2dcSChristoph Hellwig 
1704f461d2dcSChristoph Hellwig int proc_doulongvec_minmax(struct ctl_table *table, int write,
170532927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1706f461d2dcSChristoph Hellwig {
1707f461d2dcSChristoph Hellwig 	return -ENOSYS;
1708f461d2dcSChristoph Hellwig }
1709f461d2dcSChristoph Hellwig 
1710f461d2dcSChristoph Hellwig int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
171132927393SChristoph Hellwig 				      void *buffer, size_t *lenp, loff_t *ppos)
1712f461d2dcSChristoph Hellwig {
1713f461d2dcSChristoph Hellwig 	return -ENOSYS;
1714f461d2dcSChristoph Hellwig }
1715f461d2dcSChristoph Hellwig 
1716f461d2dcSChristoph Hellwig int proc_do_large_bitmap(struct ctl_table *table, int write,
171732927393SChristoph Hellwig 			 void *buffer, size_t *lenp, loff_t *ppos)
1718f461d2dcSChristoph Hellwig {
1719f461d2dcSChristoph Hellwig 	return -ENOSYS;
1720f461d2dcSChristoph Hellwig }
1721f461d2dcSChristoph Hellwig 
1722f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */
1723f461d2dcSChristoph Hellwig 
1724f461d2dcSChristoph Hellwig #if defined(CONFIG_SYSCTL)
1725f461d2dcSChristoph Hellwig int proc_do_static_key(struct ctl_table *table, int write,
172632927393SChristoph Hellwig 		       void *buffer, size_t *lenp, loff_t *ppos)
1727f461d2dcSChristoph Hellwig {
1728f461d2dcSChristoph Hellwig 	struct static_key *key = (struct static_key *)table->data;
1729f461d2dcSChristoph Hellwig 	static DEFINE_MUTEX(static_key_mutex);
1730f461d2dcSChristoph Hellwig 	int val, ret;
1731f461d2dcSChristoph Hellwig 	struct ctl_table tmp = {
1732f461d2dcSChristoph Hellwig 		.data   = &val,
1733f461d2dcSChristoph Hellwig 		.maxlen = sizeof(val),
1734f461d2dcSChristoph Hellwig 		.mode   = table->mode,
1735f461d2dcSChristoph Hellwig 		.extra1 = SYSCTL_ZERO,
1736f461d2dcSChristoph Hellwig 		.extra2 = SYSCTL_ONE,
1737f461d2dcSChristoph Hellwig 	};
1738f461d2dcSChristoph Hellwig 
1739f461d2dcSChristoph Hellwig 	if (write && !capable(CAP_SYS_ADMIN))
1740f461d2dcSChristoph Hellwig 		return -EPERM;
1741f461d2dcSChristoph Hellwig 
1742f461d2dcSChristoph Hellwig 	mutex_lock(&static_key_mutex);
1743f461d2dcSChristoph Hellwig 	val = static_key_enabled(key);
1744f461d2dcSChristoph Hellwig 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1745f461d2dcSChristoph Hellwig 	if (write && !ret) {
1746f461d2dcSChristoph Hellwig 		if (val)
1747f461d2dcSChristoph Hellwig 			static_key_enable(key);
1748f461d2dcSChristoph Hellwig 		else
1749f461d2dcSChristoph Hellwig 			static_key_disable(key);
1750f461d2dcSChristoph Hellwig 	}
1751f461d2dcSChristoph Hellwig 	mutex_unlock(&static_key_mutex);
1752f461d2dcSChristoph Hellwig 	return ret;
1753f461d2dcSChristoph Hellwig }
1754f461d2dcSChristoph Hellwig 
1755d8217f07SEric W. Biederman static struct ctl_table kern_table[] = {
17562bba22c5SMike Galbraith 	{
17572bba22c5SMike Galbraith 		.procname	= "sched_child_runs_first",
17582bba22c5SMike Galbraith 		.data		= &sysctl_sched_child_runs_first,
17592bba22c5SMike Galbraith 		.maxlen		= sizeof(unsigned int),
17602bba22c5SMike Galbraith 		.mode		= 0644,
17616d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
17622bba22c5SMike Galbraith 	},
17631d1c2509SPeter Zijlstra #ifdef CONFIG_SCHEDSTATS
17641d1c2509SPeter Zijlstra 	{
17651d1c2509SPeter Zijlstra 		.procname	= "sched_schedstats",
17661d1c2509SPeter Zijlstra 		.data		= NULL,
17671d1c2509SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
17681d1c2509SPeter Zijlstra 		.mode		= 0644,
17691d1c2509SPeter Zijlstra 		.proc_handler	= sysctl_schedstats,
17701d1c2509SPeter Zijlstra 		.extra1		= SYSCTL_ZERO,
17711d1c2509SPeter Zijlstra 		.extra2		= SYSCTL_ONE,
17721d1c2509SPeter Zijlstra 	},
17731d1c2509SPeter Zijlstra #endif /* CONFIG_SCHEDSTATS */
17740cd7c741SPeter Zijlstra #ifdef CONFIG_TASK_DELAY_ACCT
17750cd7c741SPeter Zijlstra 	{
17760cd7c741SPeter Zijlstra 		.procname	= "task_delayacct",
17770cd7c741SPeter Zijlstra 		.data		= NULL,
17780cd7c741SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
17790cd7c741SPeter Zijlstra 		.mode		= 0644,
17800cd7c741SPeter Zijlstra 		.proc_handler	= sysctl_delayacct,
17810cd7c741SPeter Zijlstra 		.extra1		= SYSCTL_ZERO,
17820cd7c741SPeter Zijlstra 		.extra2		= SYSCTL_ONE,
17830cd7c741SPeter Zijlstra 	},
17840cd7c741SPeter Zijlstra #endif /* CONFIG_TASK_DELAY_ACCT */
1785b7cc6ec7SMel Gorman #ifdef CONFIG_NUMA_BALANCING
17863a7053b3SMel Gorman 	{
178754a43d54SAndi Kleen 		.procname	= "numa_balancing",
178854a43d54SAndi Kleen 		.data		= NULL, /* filled in by handler */
178954a43d54SAndi Kleen 		.maxlen		= sizeof(unsigned int),
179054a43d54SAndi Kleen 		.mode		= 0644,
179154a43d54SAndi Kleen 		.proc_handler	= sysctl_numa_balancing,
1792eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
1793eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
179454a43d54SAndi Kleen 	},
1795cbee9f88SPeter Zijlstra #endif /* CONFIG_NUMA_BALANCING */
17961799e35dSIngo Molnar 	{
17979f0c1e56SPeter Zijlstra 		.procname	= "sched_rt_period_us",
17989f0c1e56SPeter Zijlstra 		.data		= &sysctl_sched_rt_period,
17999f0c1e56SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
18009f0c1e56SPeter Zijlstra 		.mode		= 0644,
18016d456111SEric W. Biederman 		.proc_handler	= sched_rt_handler,
18029f0c1e56SPeter Zijlstra 	},
18039f0c1e56SPeter Zijlstra 	{
18049f0c1e56SPeter Zijlstra 		.procname	= "sched_rt_runtime_us",
18059f0c1e56SPeter Zijlstra 		.data		= &sysctl_sched_rt_runtime,
18069f0c1e56SPeter Zijlstra 		.maxlen		= sizeof(int),
18079f0c1e56SPeter Zijlstra 		.mode		= 0644,
18086d456111SEric W. Biederman 		.proc_handler	= sched_rt_handler,
18099f0c1e56SPeter Zijlstra 	},
1810ce0dbbbbSClark Williams 	{
1811b4098bfcSPeter Zijlstra 		.procname	= "sched_deadline_period_max_us",
1812b4098bfcSPeter Zijlstra 		.data		= &sysctl_sched_dl_period_max,
1813b4098bfcSPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
1814b4098bfcSPeter Zijlstra 		.mode		= 0644,
1815b4098bfcSPeter Zijlstra 		.proc_handler	= proc_dointvec,
1816b4098bfcSPeter Zijlstra 	},
1817b4098bfcSPeter Zijlstra 	{
1818b4098bfcSPeter Zijlstra 		.procname	= "sched_deadline_period_min_us",
1819b4098bfcSPeter Zijlstra 		.data		= &sysctl_sched_dl_period_min,
1820b4098bfcSPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
1821b4098bfcSPeter Zijlstra 		.mode		= 0644,
1822b4098bfcSPeter Zijlstra 		.proc_handler	= proc_dointvec,
1823b4098bfcSPeter Zijlstra 	},
1824b4098bfcSPeter Zijlstra 	{
1825ce0dbbbbSClark Williams 		.procname	= "sched_rr_timeslice_ms",
1826975e155eSShile Zhang 		.data		= &sysctl_sched_rr_timeslice,
1827ce0dbbbbSClark Williams 		.maxlen		= sizeof(int),
1828ce0dbbbbSClark Williams 		.mode		= 0644,
1829ce0dbbbbSClark Williams 		.proc_handler	= sched_rr_handler,
1830ce0dbbbbSClark Williams 	},
1831e8f14172SPatrick Bellasi #ifdef CONFIG_UCLAMP_TASK
1832e8f14172SPatrick Bellasi 	{
1833e8f14172SPatrick Bellasi 		.procname	= "sched_util_clamp_min",
1834e8f14172SPatrick Bellasi 		.data		= &sysctl_sched_uclamp_util_min,
1835e8f14172SPatrick Bellasi 		.maxlen		= sizeof(unsigned int),
1836e8f14172SPatrick Bellasi 		.mode		= 0644,
1837e8f14172SPatrick Bellasi 		.proc_handler	= sysctl_sched_uclamp_handler,
1838e8f14172SPatrick Bellasi 	},
1839e8f14172SPatrick Bellasi 	{
1840e8f14172SPatrick Bellasi 		.procname	= "sched_util_clamp_max",
1841e8f14172SPatrick Bellasi 		.data		= &sysctl_sched_uclamp_util_max,
1842e8f14172SPatrick Bellasi 		.maxlen		= sizeof(unsigned int),
1843e8f14172SPatrick Bellasi 		.mode		= 0644,
1844e8f14172SPatrick Bellasi 		.proc_handler	= sysctl_sched_uclamp_handler,
1845e8f14172SPatrick Bellasi 	},
184613685c4aSQais Yousef 	{
184713685c4aSQais Yousef 		.procname	= "sched_util_clamp_min_rt_default",
184813685c4aSQais Yousef 		.data		= &sysctl_sched_uclamp_util_min_rt_default,
184913685c4aSQais Yousef 		.maxlen		= sizeof(unsigned int),
185013685c4aSQais Yousef 		.mode		= 0644,
185113685c4aSQais Yousef 		.proc_handler	= sysctl_sched_uclamp_handler,
185213685c4aSQais Yousef 	},
1853e8f14172SPatrick Bellasi #endif
18545091faa4SMike Galbraith #ifdef CONFIG_SCHED_AUTOGROUP
18555091faa4SMike Galbraith 	{
18565091faa4SMike Galbraith 		.procname	= "sched_autogroup_enabled",
18575091faa4SMike Galbraith 		.data		= &sysctl_sched_autogroup_enabled,
18585091faa4SMike Galbraith 		.maxlen		= sizeof(unsigned int),
18595091faa4SMike Galbraith 		.mode		= 0644,
18601747b21fSYong Zhang 		.proc_handler	= proc_dointvec_minmax,
1861eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
1862eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
18635091faa4SMike Galbraith 	},
18645091faa4SMike Galbraith #endif
1865ec12cb7fSPaul Turner #ifdef CONFIG_CFS_BANDWIDTH
1866ec12cb7fSPaul Turner 	{
1867ec12cb7fSPaul Turner 		.procname	= "sched_cfs_bandwidth_slice_us",
1868ec12cb7fSPaul Turner 		.data		= &sysctl_sched_cfs_bandwidth_slice,
1869ec12cb7fSPaul Turner 		.maxlen		= sizeof(unsigned int),
1870ec12cb7fSPaul Turner 		.mode		= 0644,
1871ec12cb7fSPaul Turner 		.proc_handler	= proc_dointvec_minmax,
1872eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
1873ec12cb7fSPaul Turner 	},
1874ec12cb7fSPaul Turner #endif
18758d5d0cfbSQuentin Perret #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
18768d5d0cfbSQuentin Perret 	{
18778d5d0cfbSQuentin Perret 		.procname	= "sched_energy_aware",
18788d5d0cfbSQuentin Perret 		.data		= &sysctl_sched_energy_aware,
18798d5d0cfbSQuentin Perret 		.maxlen		= sizeof(unsigned int),
18808d5d0cfbSQuentin Perret 		.mode		= 0644,
18818d5d0cfbSQuentin Perret 		.proc_handler	= sched_energy_aware_handler,
1882eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
1883eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
18848d5d0cfbSQuentin Perret 	},
18858d5d0cfbSQuentin Perret #endif
1886f20786ffSPeter Zijlstra #ifdef CONFIG_PROVE_LOCKING
1887f20786ffSPeter Zijlstra 	{
1888f20786ffSPeter Zijlstra 		.procname	= "prove_locking",
1889f20786ffSPeter Zijlstra 		.data		= &prove_locking,
1890f20786ffSPeter Zijlstra 		.maxlen		= sizeof(int),
1891f20786ffSPeter Zijlstra 		.mode		= 0644,
18926d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1893f20786ffSPeter Zijlstra 	},
1894f20786ffSPeter Zijlstra #endif
1895f20786ffSPeter Zijlstra #ifdef CONFIG_LOCK_STAT
1896f20786ffSPeter Zijlstra 	{
1897f20786ffSPeter Zijlstra 		.procname	= "lock_stat",
1898f20786ffSPeter Zijlstra 		.data		= &lock_stat,
1899f20786ffSPeter Zijlstra 		.maxlen		= sizeof(int),
1900f20786ffSPeter Zijlstra 		.mode		= 0644,
19016d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1902f20786ffSPeter Zijlstra 	},
1903f20786ffSPeter Zijlstra #endif
190477e54a1fSIngo Molnar 	{
19051da177e4SLinus Torvalds 		.procname	= "panic",
19061da177e4SLinus Torvalds 		.data		= &panic_timeout,
19071da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
19081da177e4SLinus Torvalds 		.mode		= 0644,
19096d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19101da177e4SLinus Torvalds 	},
1911046d662fSAlex Kelly #ifdef CONFIG_COREDUMP
19121da177e4SLinus Torvalds 	{
19131da177e4SLinus Torvalds 		.procname	= "core_uses_pid",
19141da177e4SLinus Torvalds 		.data		= &core_uses_pid,
19151da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
19161da177e4SLinus Torvalds 		.mode		= 0644,
19176d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19181da177e4SLinus Torvalds 	},
19191da177e4SLinus Torvalds 	{
19201da177e4SLinus Torvalds 		.procname	= "core_pattern",
19211da177e4SLinus Torvalds 		.data		= core_pattern,
192271ce92f3SDan Aloni 		.maxlen		= CORENAME_MAX_SIZE,
19231da177e4SLinus Torvalds 		.mode		= 0644,
192454b50199SKees Cook 		.proc_handler	= proc_dostring_coredump,
19251da177e4SLinus Torvalds 	},
1926a293980cSNeil Horman 	{
1927a293980cSNeil Horman 		.procname	= "core_pipe_limit",
1928a293980cSNeil Horman 		.data		= &core_pipe_limit,
1929a293980cSNeil Horman 		.maxlen		= sizeof(unsigned int),
1930a293980cSNeil Horman 		.mode		= 0644,
19316d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1932a293980cSNeil Horman 	},
1933046d662fSAlex Kelly #endif
193434f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL
19351da177e4SLinus Torvalds 	{
19361da177e4SLinus Torvalds 		.procname	= "tainted",
193725ddbb18SAndi Kleen 		.maxlen 	= sizeof(long),
193834f5a398STheodore Ts'o 		.mode		= 0644,
19396d456111SEric W. Biederman 		.proc_handler	= proc_taint,
19401da177e4SLinus Torvalds 	},
1941f4aacea2SKees Cook 	{
1942f4aacea2SKees Cook 		.procname	= "sysctl_writes_strict",
1943f4aacea2SKees Cook 		.data		= &sysctl_writes_strict,
1944f4aacea2SKees Cook 		.maxlen		= sizeof(int),
1945f4aacea2SKees Cook 		.mode		= 0644,
1946f4aacea2SKees Cook 		.proc_handler	= proc_dointvec_minmax,
194778e36f3bSXiaoming Ni 		.extra1		= SYSCTL_NEG_ONE,
1948eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
1949f4aacea2SKees Cook 	},
195034f5a398STheodore Ts'o #endif
19519745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP
19529745512cSArjan van de Ven 	{
19539745512cSArjan van de Ven 		.procname	= "latencytop",
19549745512cSArjan van de Ven 		.data		= &latencytop_enabled,
19559745512cSArjan van de Ven 		.maxlen		= sizeof(int),
19569745512cSArjan van de Ven 		.mode		= 0644,
1957cb251765SMel Gorman 		.proc_handler	= sysctl_latencytop,
19589745512cSArjan van de Ven 	},
19599745512cSArjan van de Ven #endif
19601da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD
19611da177e4SLinus Torvalds 	{
19621da177e4SLinus Torvalds 		.procname	= "real-root-dev",
19631da177e4SLinus Torvalds 		.data		= &real_root_dev,
19641da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
19651da177e4SLinus Torvalds 		.mode		= 0644,
19666d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19671da177e4SLinus Torvalds 	},
19681da177e4SLinus Torvalds #endif
196945807a1dSIngo Molnar 	{
197045807a1dSIngo Molnar 		.procname	= "print-fatal-signals",
197145807a1dSIngo Molnar 		.data		= &print_fatal_signals,
197245807a1dSIngo Molnar 		.maxlen		= sizeof(int),
197345807a1dSIngo Molnar 		.mode		= 0644,
19746d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
197545807a1dSIngo Molnar 	},
197672c57ed5SDavid S. Miller #ifdef CONFIG_SPARC
19771da177e4SLinus Torvalds 	{
19781da177e4SLinus Torvalds 		.procname	= "reboot-cmd",
19791da177e4SLinus Torvalds 		.data		= reboot_command,
19801da177e4SLinus Torvalds 		.maxlen		= 256,
19811da177e4SLinus Torvalds 		.mode		= 0644,
19826d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
19831da177e4SLinus Torvalds 	},
19841da177e4SLinus Torvalds 	{
19851da177e4SLinus Torvalds 		.procname	= "stop-a",
19861da177e4SLinus Torvalds 		.data		= &stop_a_enabled,
19871da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
19881da177e4SLinus Torvalds 		.mode		= 0644,
19896d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19901da177e4SLinus Torvalds 	},
19911da177e4SLinus Torvalds 	{
19921da177e4SLinus Torvalds 		.procname	= "scons-poweroff",
19931da177e4SLinus Torvalds 		.data		= &scons_pwroff,
19941da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
19951da177e4SLinus Torvalds 		.mode		= 0644,
19966d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19971da177e4SLinus Torvalds 	},
19981da177e4SLinus Torvalds #endif
19990871420fSDavid S. Miller #ifdef CONFIG_SPARC64
20000871420fSDavid S. Miller 	{
20010871420fSDavid S. Miller 		.procname	= "tsb-ratio",
20020871420fSDavid S. Miller 		.data		= &sysctl_tsb_ratio,
20030871420fSDavid S. Miller 		.maxlen		= sizeof (int),
20040871420fSDavid S. Miller 		.mode		= 0644,
20056d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
20060871420fSDavid S. Miller 	},
20070871420fSDavid S. Miller #endif
2008b67114dbSHelge Deller #ifdef CONFIG_PARISC
20091da177e4SLinus Torvalds 	{
20101da177e4SLinus Torvalds 		.procname	= "soft-power",
20111da177e4SLinus Torvalds 		.data		= &pwrsw_enabled,
20121da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
20131da177e4SLinus Torvalds 		.mode		= 0644,
20146d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
20151da177e4SLinus Torvalds 	},
2016bf14e3b9SVineet Gupta #endif
2017bf14e3b9SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
20181da177e4SLinus Torvalds 	{
20191da177e4SLinus Torvalds 		.procname	= "unaligned-trap",
20201da177e4SLinus Torvalds 		.data		= &unaligned_enabled,
20211da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
20221da177e4SLinus Torvalds 		.mode		= 0644,
20236d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
20241da177e4SLinus Torvalds 	},
20251da177e4SLinus Torvalds #endif
20261da177e4SLinus Torvalds 	{
20271da177e4SLinus Torvalds 		.procname	= "ctrl-alt-del",
20281da177e4SLinus Torvalds 		.data		= &C_A_D,
20291da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
20301da177e4SLinus Torvalds 		.mode		= 0644,
20316d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
20321da177e4SLinus Torvalds 	},
2033606576ceSSteven Rostedt #ifdef CONFIG_FUNCTION_TRACER
2034b0fc494fSSteven Rostedt 	{
2035b0fc494fSSteven Rostedt 		.procname	= "ftrace_enabled",
2036b0fc494fSSteven Rostedt 		.data		= &ftrace_enabled,
2037b0fc494fSSteven Rostedt 		.maxlen		= sizeof(int),
2038b0fc494fSSteven Rostedt 		.mode		= 0644,
20396d456111SEric W. Biederman 		.proc_handler	= ftrace_enable_sysctl,
2040b0fc494fSSteven Rostedt 	},
2041b0fc494fSSteven Rostedt #endif
2042f38f1d2aSSteven Rostedt #ifdef CONFIG_STACK_TRACER
2043f38f1d2aSSteven Rostedt 	{
2044f38f1d2aSSteven Rostedt 		.procname	= "stack_tracer_enabled",
2045f38f1d2aSSteven Rostedt 		.data		= &stack_tracer_enabled,
2046f38f1d2aSSteven Rostedt 		.maxlen		= sizeof(int),
2047f38f1d2aSSteven Rostedt 		.mode		= 0644,
20486d456111SEric W. Biederman 		.proc_handler	= stack_trace_sysctl,
2049f38f1d2aSSteven Rostedt 	},
2050f38f1d2aSSteven Rostedt #endif
2051944ac425SSteven Rostedt #ifdef CONFIG_TRACING
2052944ac425SSteven Rostedt 	{
20533299b4ddSPeter Zijlstra 		.procname	= "ftrace_dump_on_oops",
2054944ac425SSteven Rostedt 		.data		= &ftrace_dump_on_oops,
2055944ac425SSteven Rostedt 		.maxlen		= sizeof(int),
2056944ac425SSteven Rostedt 		.mode		= 0644,
20576d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2058944ac425SSteven Rostedt 	},
2059de7edd31SSteven Rostedt (Red Hat) 	{
2060de7edd31SSteven Rostedt (Red Hat) 		.procname	= "traceoff_on_warning",
2061de7edd31SSteven Rostedt (Red Hat) 		.data		= &__disable_trace_on_warning,
2062de7edd31SSteven Rostedt (Red Hat) 		.maxlen		= sizeof(__disable_trace_on_warning),
2063de7edd31SSteven Rostedt (Red Hat) 		.mode		= 0644,
2064de7edd31SSteven Rostedt (Red Hat) 		.proc_handler	= proc_dointvec,
2065de7edd31SSteven Rostedt (Red Hat) 	},
20660daa2302SSteven Rostedt (Red Hat) 	{
20670daa2302SSteven Rostedt (Red Hat) 		.procname	= "tracepoint_printk",
20680daa2302SSteven Rostedt (Red Hat) 		.data		= &tracepoint_printk,
20690daa2302SSteven Rostedt (Red Hat) 		.maxlen		= sizeof(tracepoint_printk),
20700daa2302SSteven Rostedt (Red Hat) 		.mode		= 0644,
207142391745SSteven Rostedt (Red Hat) 		.proc_handler	= tracepoint_printk_sysctl,
20720daa2302SSteven Rostedt (Red Hat) 	},
2073944ac425SSteven Rostedt #endif
20742965faa5SDave Young #ifdef CONFIG_KEXEC_CORE
20757984754bSKees Cook 	{
20767984754bSKees Cook 		.procname	= "kexec_load_disabled",
20777984754bSKees Cook 		.data		= &kexec_load_disabled,
20787984754bSKees Cook 		.maxlen		= sizeof(int),
20797984754bSKees Cook 		.mode		= 0644,
20807984754bSKees Cook 		/* only handle a transition from default "0" to "1" */
20817984754bSKees Cook 		.proc_handler	= proc_dointvec_minmax,
2082eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
2083eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
20847984754bSKees Cook 	},
20857984754bSKees Cook #endif
2086a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES
20871da177e4SLinus Torvalds 	{
20881da177e4SLinus Torvalds 		.procname	= "modprobe",
20891da177e4SLinus Torvalds 		.data		= &modprobe_path,
20901da177e4SLinus Torvalds 		.maxlen		= KMOD_PATH_LEN,
20911da177e4SLinus Torvalds 		.mode		= 0644,
20926d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
20931da177e4SLinus Torvalds 	},
20943d43321bSKees Cook 	{
20953d43321bSKees Cook 		.procname	= "modules_disabled",
20963d43321bSKees Cook 		.data		= &modules_disabled,
20973d43321bSKees Cook 		.maxlen		= sizeof(int),
20983d43321bSKees Cook 		.mode		= 0644,
20993d43321bSKees Cook 		/* only handle a transition from default "0" to "1" */
21006d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2101eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
2102eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
21033d43321bSKees Cook 	},
21041da177e4SLinus Torvalds #endif
210586d56134SMichael Marineau #ifdef CONFIG_UEVENT_HELPER
21061da177e4SLinus Torvalds 	{
21071da177e4SLinus Torvalds 		.procname	= "hotplug",
2108312c004dSKay Sievers 		.data		= &uevent_helper,
2109312c004dSKay Sievers 		.maxlen		= UEVENT_HELPER_PATH_LEN,
21101da177e4SLinus Torvalds 		.mode		= 0644,
21116d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
21121da177e4SLinus Torvalds 	},
211386d56134SMichael Marineau #endif
21141da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG
21151da177e4SLinus Torvalds 	{
21161da177e4SLinus Torvalds 		.procname	= "sg-big-buff",
21171da177e4SLinus Torvalds 		.data		= &sg_big_buff,
21181da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
21191da177e4SLinus Torvalds 		.mode		= 0444,
21206d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
21211da177e4SLinus Torvalds 	},
21221da177e4SLinus Torvalds #endif
21231da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
21241da177e4SLinus Torvalds 	{
21251da177e4SLinus Torvalds 		.procname	= "acct",
21261da177e4SLinus Torvalds 		.data		= &acct_parm,
21271da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
21281da177e4SLinus Torvalds 		.mode		= 0644,
21296d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
21301da177e4SLinus Torvalds 	},
21311da177e4SLinus Torvalds #endif
21321da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ
21331da177e4SLinus Torvalds 	{
21341da177e4SLinus Torvalds 		.procname	= "sysrq",
2135eaee4172SDmitry Safonov 		.data		= NULL,
21361da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
21371da177e4SLinus Torvalds 		.mode		= 0644,
213897f5f0cdSDmitry Torokhov 		.proc_handler	= sysrq_sysctl_handler,
21391da177e4SLinus Torvalds 	},
21401da177e4SLinus Torvalds #endif
2141d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
21421da177e4SLinus Torvalds 	{
21431da177e4SLinus Torvalds 		.procname	= "cad_pid",
21449ec52099SCedric Le Goater 		.data		= NULL,
21451da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
21461da177e4SLinus Torvalds 		.mode		= 0600,
21476d456111SEric W. Biederman 		.proc_handler	= proc_do_cad_pid,
21481da177e4SLinus Torvalds 	},
2149d6f8ff73SRandy Dunlap #endif
21501da177e4SLinus Torvalds 	{
21511da177e4SLinus Torvalds 		.procname	= "threads-max",
215216db3d3fSHeinrich Schuchardt 		.data		= NULL,
21531da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21541da177e4SLinus Torvalds 		.mode		= 0644,
215516db3d3fSHeinrich Schuchardt 		.proc_handler	= sysctl_max_threads,
21561da177e4SLinus Torvalds 	},
21571da177e4SLinus Torvalds 	{
21581da177e4SLinus Torvalds 		.procname	= "random",
21591da177e4SLinus Torvalds 		.mode		= 0555,
21601da177e4SLinus Torvalds 		.child		= random_table,
21611da177e4SLinus Torvalds 	},
21621da177e4SLinus Torvalds 	{
216317f60a7dSEric Paris 		.procname	= "usermodehelper",
216417f60a7dSEric Paris 		.mode		= 0555,
216517f60a7dSEric Paris 		.child		= usermodehelper_table,
216617f60a7dSEric Paris 	},
2167ceb18132SLuis R. Rodriguez #ifdef CONFIG_FW_LOADER_USER_HELPER
2168ceb18132SLuis R. Rodriguez 	{
2169ceb18132SLuis R. Rodriguez 		.procname	= "firmware_config",
2170ceb18132SLuis R. Rodriguez 		.mode		= 0555,
2171ceb18132SLuis R. Rodriguez 		.child		= firmware_config_table,
2172ceb18132SLuis R. Rodriguez 	},
2173ceb18132SLuis R. Rodriguez #endif
217417f60a7dSEric Paris 	{
21751da177e4SLinus Torvalds 		.procname	= "overflowuid",
21761da177e4SLinus Torvalds 		.data		= &overflowuid,
21771da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21781da177e4SLinus Torvalds 		.mode		= 0644,
21796d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
21801da177e4SLinus Torvalds 		.extra1		= &minolduid,
21811da177e4SLinus Torvalds 		.extra2		= &maxolduid,
21821da177e4SLinus Torvalds 	},
21831da177e4SLinus Torvalds 	{
21841da177e4SLinus Torvalds 		.procname	= "overflowgid",
21851da177e4SLinus Torvalds 		.data		= &overflowgid,
21861da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21871da177e4SLinus Torvalds 		.mode		= 0644,
21886d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
21891da177e4SLinus Torvalds 		.extra1		= &minolduid,
21901da177e4SLinus Torvalds 		.extra2		= &maxolduid,
21911da177e4SLinus Torvalds 	},
2192347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
21931da177e4SLinus Torvalds 	{
21941da177e4SLinus Torvalds 		.procname	= "userprocess_debug",
2195ab3c68eeSHeiko Carstens 		.data		= &show_unhandled_signals,
21961da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21971da177e4SLinus Torvalds 		.mode		= 0644,
21986d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
21991da177e4SLinus Torvalds 	},
22001da177e4SLinus Torvalds #endif
220160c958d8SGuilherme G. Piccoli #ifdef CONFIG_SMP
220260c958d8SGuilherme G. Piccoli 	{
220360c958d8SGuilherme G. Piccoli 		.procname	= "oops_all_cpu_backtrace",
220460c958d8SGuilherme G. Piccoli 		.data		= &sysctl_oops_all_cpu_backtrace,
220560c958d8SGuilherme G. Piccoli 		.maxlen		= sizeof(int),
220660c958d8SGuilherme G. Piccoli 		.mode		= 0644,
220760c958d8SGuilherme G. Piccoli 		.proc_handler	= proc_dointvec_minmax,
220860c958d8SGuilherme G. Piccoli 		.extra1		= SYSCTL_ZERO,
220960c958d8SGuilherme G. Piccoli 		.extra2		= SYSCTL_ONE,
221060c958d8SGuilherme G. Piccoli 	},
221160c958d8SGuilherme G. Piccoli #endif /* CONFIG_SMP */
22121da177e4SLinus Torvalds 	{
22131da177e4SLinus Torvalds 		.procname	= "pid_max",
22141da177e4SLinus Torvalds 		.data		= &pid_max,
22151da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
22161da177e4SLinus Torvalds 		.mode		= 0644,
22176d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
22181da177e4SLinus Torvalds 		.extra1		= &pid_max_min,
22191da177e4SLinus Torvalds 		.extra2		= &pid_max_max,
22201da177e4SLinus Torvalds 	},
22211da177e4SLinus Torvalds 	{
22221da177e4SLinus Torvalds 		.procname	= "panic_on_oops",
22231da177e4SLinus Torvalds 		.data		= &panic_on_oops,
22241da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
22251da177e4SLinus Torvalds 		.mode		= 0644,
22266d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
22271da177e4SLinus Torvalds 	},
222881c9d43fSFeng Tang 	{
222981c9d43fSFeng Tang 		.procname	= "panic_print",
223081c9d43fSFeng Tang 		.data		= &panic_print,
223181c9d43fSFeng Tang 		.maxlen		= sizeof(unsigned long),
223281c9d43fSFeng Tang 		.mode		= 0644,
223381c9d43fSFeng Tang 		.proc_handler	= proc_doulongvec_minmax,
223481c9d43fSFeng Tang 	},
22357ef3d2fdSJoe Perches #if defined CONFIG_PRINTK
22367ef3d2fdSJoe Perches 	{
22377ef3d2fdSJoe Perches 		.procname	= "printk",
22387ef3d2fdSJoe Perches 		.data		= &console_loglevel,
22397ef3d2fdSJoe Perches 		.maxlen		= 4*sizeof(int),
22407ef3d2fdSJoe Perches 		.mode		= 0644,
22416d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
22427ef3d2fdSJoe Perches 	},
22431da177e4SLinus Torvalds 	{
22441da177e4SLinus Torvalds 		.procname	= "printk_ratelimit",
2245717115e1SDave Young 		.data		= &printk_ratelimit_state.interval,
22461da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
22471da177e4SLinus Torvalds 		.mode		= 0644,
22486d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_jiffies,
22491da177e4SLinus Torvalds 	},
22501da177e4SLinus Torvalds 	{
22511da177e4SLinus Torvalds 		.procname	= "printk_ratelimit_burst",
2252717115e1SDave Young 		.data		= &printk_ratelimit_state.burst,
22531da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
22541da177e4SLinus Torvalds 		.mode		= 0644,
22556d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
22561da177e4SLinus Torvalds 	},
2257af91322eSDave Young 	{
2258af91322eSDave Young 		.procname	= "printk_delay",
2259af91322eSDave Young 		.data		= &printk_delay_msec,
2260af91322eSDave Young 		.maxlen		= sizeof(int),
2261af91322eSDave Young 		.mode		= 0644,
22626d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2263eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2264af91322eSDave Young 		.extra2		= &ten_thousand,
2265af91322eSDave Young 	},
22661da177e4SLinus Torvalds 	{
2267750afe7bSBorislav Petkov 		.procname	= "printk_devkmsg",
2268750afe7bSBorislav Petkov 		.data		= devkmsg_log_str,
2269750afe7bSBorislav Petkov 		.maxlen		= DEVKMSG_STR_MAX_SIZE,
2270750afe7bSBorislav Petkov 		.mode		= 0644,
2271750afe7bSBorislav Petkov 		.proc_handler	= devkmsg_sysctl_set_loglvl,
2272750afe7bSBorislav Petkov 	},
2273750afe7bSBorislav Petkov 	{
2274eaf06b24SDan Rosenberg 		.procname	= "dmesg_restrict",
2275eaf06b24SDan Rosenberg 		.data		= &dmesg_restrict,
2276eaf06b24SDan Rosenberg 		.maxlen		= sizeof(int),
2277eaf06b24SDan Rosenberg 		.mode		= 0644,
2278620f6e8eSKees Cook 		.proc_handler	= proc_dointvec_minmax_sysadmin,
2279eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2280eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2281eaf06b24SDan Rosenberg 	},
2282455cd5abSDan Rosenberg 	{
2283455cd5abSDan Rosenberg 		.procname	= "kptr_restrict",
2284455cd5abSDan Rosenberg 		.data		= &kptr_restrict,
2285455cd5abSDan Rosenberg 		.maxlen		= sizeof(int),
2286455cd5abSDan Rosenberg 		.mode		= 0644,
2287620f6e8eSKees Cook 		.proc_handler	= proc_dointvec_minmax_sysadmin,
2288eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
228978e36f3bSXiaoming Ni 		.extra2		= SYSCTL_TWO,
2290455cd5abSDan Rosenberg 	},
2291df6e61d4SJoe Perches #endif
2292eaf06b24SDan Rosenberg 	{
22931da177e4SLinus Torvalds 		.procname	= "ngroups_max",
2294*f628867dSStephen Kitt 		.data		= (void *)&ngroups_max,
22951da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
22961da177e4SLinus Torvalds 		.mode		= 0444,
22976d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
22981da177e4SLinus Torvalds 	},
229973efc039SDan Ballard 	{
230073efc039SDan Ballard 		.procname	= "cap_last_cap",
230173efc039SDan Ballard 		.data		= (void *)&cap_last_cap,
230273efc039SDan Ballard 		.maxlen		= sizeof(int),
230373efc039SDan Ballard 		.mode		= 0444,
230473efc039SDan Ballard 		.proc_handler	= proc_dointvec,
230573efc039SDan Ballard 	},
23065dc30558SDon Zickus #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
23075dc30558SDon Zickus 	{
23085dc30558SDon Zickus 		.procname       = "unknown_nmi_panic",
23095dc30558SDon Zickus 		.data           = &unknown_nmi_panic,
23105dc30558SDon Zickus 		.maxlen         = sizeof (int),
23115dc30558SDon Zickus 		.mode           = 0644,
23125dc30558SDon Zickus 		.proc_handler   = proc_dointvec,
23135dc30558SDon Zickus 	},
2314504d7cf1SDon Zickus #endif
2315b6522fa4SXiaoming Ni 
2316b6522fa4SXiaoming Ni #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
2317b6522fa4SXiaoming Ni 	defined(CONFIG_DEBUG_STACKOVERFLOW)
2318b6522fa4SXiaoming Ni 	{
2319b6522fa4SXiaoming Ni 		.procname	= "panic_on_stackoverflow",
2320b6522fa4SXiaoming Ni 		.data		= &sysctl_panic_on_stackoverflow,
2321b6522fa4SXiaoming Ni 		.maxlen		= sizeof(int),
2322b6522fa4SXiaoming Ni 		.mode		= 0644,
2323b6522fa4SXiaoming Ni 		.proc_handler	= proc_dointvec,
2324b6522fa4SXiaoming Ni 	},
2325b6522fa4SXiaoming Ni #endif
23261da177e4SLinus Torvalds #if defined(CONFIG_X86)
23271da177e4SLinus Torvalds 	{
23288da5addaSDon Zickus 		.procname	= "panic_on_unrecovered_nmi",
23298da5addaSDon Zickus 		.data		= &panic_on_unrecovered_nmi,
23308da5addaSDon Zickus 		.maxlen		= sizeof(int),
23318da5addaSDon Zickus 		.mode		= 0644,
23326d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23338da5addaSDon Zickus 	},
23348da5addaSDon Zickus 	{
23355211a242SKurt Garloff 		.procname	= "panic_on_io_nmi",
23365211a242SKurt Garloff 		.data		= &panic_on_io_nmi,
23375211a242SKurt Garloff 		.maxlen		= sizeof(int),
23385211a242SKurt Garloff 		.mode		= 0644,
23396d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23405211a242SKurt Garloff 	},
23415211a242SKurt Garloff 	{
23421da177e4SLinus Torvalds 		.procname	= "bootloader_type",
23431da177e4SLinus Torvalds 		.data		= &bootloader_type,
23441da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
23451da177e4SLinus Torvalds 		.mode		= 0444,
23466d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23471da177e4SLinus Torvalds 	},
23480741f4d2SChuck Ebbert 	{
23495031296cSH. Peter Anvin 		.procname	= "bootloader_version",
23505031296cSH. Peter Anvin 		.data		= &bootloader_version,
23515031296cSH. Peter Anvin 		.maxlen		= sizeof (int),
23525031296cSH. Peter Anvin 		.mode		= 0444,
23536d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23545031296cSH. Peter Anvin 	},
23555031296cSH. Peter Anvin 	{
23566e7c4025SIngo Molnar 		.procname	= "io_delay_type",
23576e7c4025SIngo Molnar 		.data		= &io_delay_type,
23586e7c4025SIngo Molnar 		.maxlen		= sizeof(int),
23596e7c4025SIngo Molnar 		.mode		= 0644,
23606d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23616e7c4025SIngo Molnar 	},
23621da177e4SLinus Torvalds #endif
23637a9166e3SLuke Yang #if defined(CONFIG_MMU)
23641da177e4SLinus Torvalds 	{
23651da177e4SLinus Torvalds 		.procname	= "randomize_va_space",
23661da177e4SLinus Torvalds 		.data		= &randomize_va_space,
23671da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
23681da177e4SLinus Torvalds 		.mode		= 0644,
23696d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23701da177e4SLinus Torvalds 	},
23717a9166e3SLuke Yang #endif
23720152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP)
2373951f22d5SMartin Schwidefsky 	{
2374951f22d5SMartin Schwidefsky 		.procname	= "spin_retry",
2375951f22d5SMartin Schwidefsky 		.data		= &spin_retry,
2376951f22d5SMartin Schwidefsky 		.maxlen		= sizeof (int),
2377951f22d5SMartin Schwidefsky 		.mode		= 0644,
23786d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2379951f22d5SMartin Schwidefsky 	},
2380951f22d5SMartin Schwidefsky #endif
2381673d5b43SLen Brown #if	defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
2382c255d844SPavel Machek 	{
2383c255d844SPavel Machek 		.procname	= "acpi_video_flags",
238477afcf78SPavel Machek 		.data		= &acpi_realmode_flags,
2385c255d844SPavel Machek 		.maxlen		= sizeof (unsigned long),
2386c255d844SPavel Machek 		.mode		= 0644,
23876d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
2388c255d844SPavel Machek 	},
2389c255d844SPavel Machek #endif
2390b6fca725SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
2391d2b176edSJes Sorensen 	{
2392d2b176edSJes Sorensen 		.procname	= "ignore-unaligned-usertrap",
2393d2b176edSJes Sorensen 		.data		= &no_unaligned_warning,
2394d2b176edSJes Sorensen 		.maxlen		= sizeof (int),
2395d2b176edSJes Sorensen 		.mode		= 0644,
23966d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2397d2b176edSJes Sorensen 	},
2398b6fca725SVineet Gupta #endif
2399b6fca725SVineet Gupta #ifdef CONFIG_IA64
240088fc241fSDoug Chapman 	{
240188fc241fSDoug Chapman 		.procname	= "unaligned-dump-stack",
240288fc241fSDoug Chapman 		.data		= &unaligned_dump_stack,
240388fc241fSDoug Chapman 		.maxlen		= sizeof (int),
240488fc241fSDoug Chapman 		.mode		= 0644,
24056d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
240688fc241fSDoug Chapman 	},
2407d2b176edSJes Sorensen #endif
240823f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
240923f78d4aSIngo Molnar 	{
241023f78d4aSIngo Molnar 		.procname	= "max_lock_depth",
241123f78d4aSIngo Molnar 		.data		= &max_lock_depth,
241223f78d4aSIngo Molnar 		.maxlen		= sizeof(int),
241323f78d4aSIngo Molnar 		.mode		= 0644,
24146d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
241523f78d4aSIngo Molnar 	},
241623f78d4aSIngo Molnar #endif
241710a0a8d4SJeremy Fitzhardinge 	{
241810a0a8d4SJeremy Fitzhardinge 		.procname	= "poweroff_cmd",
241910a0a8d4SJeremy Fitzhardinge 		.data		= &poweroff_cmd,
242010a0a8d4SJeremy Fitzhardinge 		.maxlen		= POWEROFF_CMD_PATH_LEN,
242110a0a8d4SJeremy Fitzhardinge 		.mode		= 0644,
24226d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
242310a0a8d4SJeremy Fitzhardinge 	},
24240b77f5bfSDavid Howells #ifdef CONFIG_KEYS
24250b77f5bfSDavid Howells 	{
24260b77f5bfSDavid Howells 		.procname	= "keys",
24270b77f5bfSDavid Howells 		.mode		= 0555,
24280b77f5bfSDavid Howells 		.child		= key_sysctls,
24290b77f5bfSDavid Howells 	},
24300b77f5bfSDavid Howells #endif
2431cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS
2432aa4a2218SVince Weaver 	/*
2433aa4a2218SVince Weaver 	 * User-space scripts rely on the existence of this file
2434aa4a2218SVince Weaver 	 * as a feature check for perf_events being enabled.
2435aa4a2218SVince Weaver 	 *
2436aa4a2218SVince Weaver 	 * So it's an ABI, do not remove!
2437aa4a2218SVince Weaver 	 */
24381ccd1549SPeter Zijlstra 	{
2439cdd6c482SIngo Molnar 		.procname	= "perf_event_paranoid",
2440cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_paranoid,
2441cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_paranoid),
24421ccd1549SPeter Zijlstra 		.mode		= 0644,
24436d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
24441ccd1549SPeter Zijlstra 	},
2445c5078f78SPeter Zijlstra 	{
2446cdd6c482SIngo Molnar 		.procname	= "perf_event_mlock_kb",
2447cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_mlock,
2448cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_mlock),
2449c5078f78SPeter Zijlstra 		.mode		= 0644,
24506d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2451c5078f78SPeter Zijlstra 	},
2452a78ac325SPeter Zijlstra 	{
2453cdd6c482SIngo Molnar 		.procname	= "perf_event_max_sample_rate",
2454cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_sample_rate,
2455cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_sample_rate),
2456a78ac325SPeter Zijlstra 		.mode		= 0644,
2457163ec435SPeter Zijlstra 		.proc_handler	= perf_proc_update_handler,
2458eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
2459a78ac325SPeter Zijlstra 	},
246014c63f17SDave Hansen 	{
246114c63f17SDave Hansen 		.procname	= "perf_cpu_time_max_percent",
246214c63f17SDave Hansen 		.data		= &sysctl_perf_cpu_time_max_percent,
246314c63f17SDave Hansen 		.maxlen		= sizeof(sysctl_perf_cpu_time_max_percent),
246414c63f17SDave Hansen 		.mode		= 0644,
246514c63f17SDave Hansen 		.proc_handler	= perf_cpu_time_max_percent_handler,
2466eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
246778e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_HUNDRED,
246814c63f17SDave Hansen 	},
2469c5dfd78eSArnaldo Carvalho de Melo 	{
2470c5dfd78eSArnaldo Carvalho de Melo 		.procname	= "perf_event_max_stack",
2471a831100aSArnaldo Carvalho de Melo 		.data		= &sysctl_perf_event_max_stack,
2472c5dfd78eSArnaldo Carvalho de Melo 		.maxlen		= sizeof(sysctl_perf_event_max_stack),
2473c5dfd78eSArnaldo Carvalho de Melo 		.mode		= 0644,
2474c5dfd78eSArnaldo Carvalho de Melo 		.proc_handler	= perf_event_max_stack_handler,
2475eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2476c5dfd78eSArnaldo Carvalho de Melo 		.extra2		= &six_hundred_forty_kb,
2477c5dfd78eSArnaldo Carvalho de Melo 	},
2478c85b0334SArnaldo Carvalho de Melo 	{
2479c85b0334SArnaldo Carvalho de Melo 		.procname	= "perf_event_max_contexts_per_stack",
2480c85b0334SArnaldo Carvalho de Melo 		.data		= &sysctl_perf_event_max_contexts_per_stack,
2481c85b0334SArnaldo Carvalho de Melo 		.maxlen		= sizeof(sysctl_perf_event_max_contexts_per_stack),
2482c85b0334SArnaldo Carvalho de Melo 		.mode		= 0644,
2483c85b0334SArnaldo Carvalho de Melo 		.proc_handler	= perf_event_max_stack_handler,
2484eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
248578e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_THOUSAND,
2486c85b0334SArnaldo Carvalho de Melo 	},
24871ccd1549SPeter Zijlstra #endif
24889e3961a0SPrarit Bhargava 	{
24899e3961a0SPrarit Bhargava 		.procname	= "panic_on_warn",
24909e3961a0SPrarit Bhargava 		.data		= &panic_on_warn,
24919e3961a0SPrarit Bhargava 		.maxlen		= sizeof(int),
24929e3961a0SPrarit Bhargava 		.mode		= 0644,
24939e3961a0SPrarit Bhargava 		.proc_handler	= proc_dointvec_minmax,
2494eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2495eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
24969e3961a0SPrarit Bhargava 	},
2497bc7a34b8SThomas Gleixner #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
2498bc7a34b8SThomas Gleixner 	{
2499bc7a34b8SThomas Gleixner 		.procname	= "timer_migration",
2500bc7a34b8SThomas Gleixner 		.data		= &sysctl_timer_migration,
2501bc7a34b8SThomas Gleixner 		.maxlen		= sizeof(unsigned int),
2502bc7a34b8SThomas Gleixner 		.mode		= 0644,
2503bc7a34b8SThomas Gleixner 		.proc_handler	= timer_migration_handler,
2504eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2505eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2506bc7a34b8SThomas Gleixner 	},
2507bc7a34b8SThomas Gleixner #endif
25081be7f75dSAlexei Starovoitov #ifdef CONFIG_BPF_SYSCALL
25091be7f75dSAlexei Starovoitov 	{
25101be7f75dSAlexei Starovoitov 		.procname	= "unprivileged_bpf_disabled",
25111be7f75dSAlexei Starovoitov 		.data		= &sysctl_unprivileged_bpf_disabled,
25121be7f75dSAlexei Starovoitov 		.maxlen		= sizeof(sysctl_unprivileged_bpf_disabled),
25131be7f75dSAlexei Starovoitov 		.mode		= 0644,
251408389d88SDaniel Borkmann 		.proc_handler	= bpf_unpriv_handler,
251508389d88SDaniel Borkmann 		.extra1		= SYSCTL_ZERO,
251678e36f3bSXiaoming Ni 		.extra2		= SYSCTL_TWO,
25171be7f75dSAlexei Starovoitov 	},
2518492ecee8SAlexei Starovoitov 	{
2519492ecee8SAlexei Starovoitov 		.procname	= "bpf_stats_enabled",
2520a8e11e5cSEric Dumazet 		.data		= &bpf_stats_enabled_key.key,
2521a8e11e5cSEric Dumazet 		.maxlen		= sizeof(bpf_stats_enabled_key),
2522492ecee8SAlexei Starovoitov 		.mode		= 0644,
2523d46edd67SSong Liu 		.proc_handler	= bpf_stats_handler,
2524492ecee8SAlexei Starovoitov 	},
25253fcc5530SAlexei Starovoitov #endif
2526b3e627d3SLai Jiangshan #if defined(CONFIG_TREE_RCU)
2527088e9d25SDaniel Bristot de Oliveira 	{
2528088e9d25SDaniel Bristot de Oliveira 		.procname	= "panic_on_rcu_stall",
2529088e9d25SDaniel Bristot de Oliveira 		.data		= &sysctl_panic_on_rcu_stall,
2530088e9d25SDaniel Bristot de Oliveira 		.maxlen		= sizeof(sysctl_panic_on_rcu_stall),
2531088e9d25SDaniel Bristot de Oliveira 		.mode		= 0644,
2532088e9d25SDaniel Bristot de Oliveira 		.proc_handler	= proc_dointvec_minmax,
2533eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2534eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2535088e9d25SDaniel Bristot de Oliveira 	},
2536088e9d25SDaniel Bristot de Oliveira #endif
2537dfe56404Schao #if defined(CONFIG_TREE_RCU)
2538dfe56404Schao 	{
2539dfe56404Schao 		.procname	= "max_rcu_stall_to_panic",
2540dfe56404Schao 		.data		= &sysctl_max_rcu_stall_to_panic,
2541dfe56404Schao 		.maxlen		= sizeof(sysctl_max_rcu_stall_to_panic),
2542dfe56404Schao 		.mode		= 0644,
2543dfe56404Schao 		.proc_handler	= proc_dointvec_minmax,
2544dfe56404Schao 		.extra1		= SYSCTL_ONE,
2545dfe56404Schao 		.extra2		= SYSCTL_INT_MAX,
2546dfe56404Schao 	},
2547dfe56404Schao #endif
2548964c9dffSAlexander Popov #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
2549964c9dffSAlexander Popov 	{
2550964c9dffSAlexander Popov 		.procname	= "stack_erasing",
2551964c9dffSAlexander Popov 		.data		= NULL,
2552964c9dffSAlexander Popov 		.maxlen		= sizeof(int),
2553964c9dffSAlexander Popov 		.mode		= 0600,
2554964c9dffSAlexander Popov 		.proc_handler	= stack_erasing_sysctl,
2555eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2556eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2557964c9dffSAlexander Popov 	},
2558964c9dffSAlexander Popov #endif
25596fce56ecSEric W. Biederman 	{ }
25601da177e4SLinus Torvalds };
25611da177e4SLinus Torvalds 
2562d8217f07SEric W. Biederman static struct ctl_table vm_table[] = {
25631da177e4SLinus Torvalds 	{
25641da177e4SLinus Torvalds 		.procname	= "overcommit_memory",
25651da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_memory,
25661da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_memory),
25671da177e4SLinus Torvalds 		.mode		= 0644,
256856f3547bSFeng Tang 		.proc_handler	= overcommit_policy_handler,
2569eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
257078e36f3bSXiaoming Ni 		.extra2		= SYSCTL_TWO,
25711da177e4SLinus Torvalds 	},
25721da177e4SLinus Torvalds 	{
2573fadd8fbdSKAMEZAWA Hiroyuki 		.procname	= "panic_on_oom",
2574fadd8fbdSKAMEZAWA Hiroyuki 		.data		= &sysctl_panic_on_oom,
2575fadd8fbdSKAMEZAWA Hiroyuki 		.maxlen		= sizeof(sysctl_panic_on_oom),
2576fadd8fbdSKAMEZAWA Hiroyuki 		.mode		= 0644,
2577cb16e95fSPetr Holasek 		.proc_handler	= proc_dointvec_minmax,
2578eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
257978e36f3bSXiaoming Ni 		.extra2		= SYSCTL_TWO,
2580fadd8fbdSKAMEZAWA Hiroyuki 	},
2581fadd8fbdSKAMEZAWA Hiroyuki 	{
2582fe071d7eSDavid Rientjes 		.procname	= "oom_kill_allocating_task",
2583fe071d7eSDavid Rientjes 		.data		= &sysctl_oom_kill_allocating_task,
2584fe071d7eSDavid Rientjes 		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
2585fe071d7eSDavid Rientjes 		.mode		= 0644,
25866d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2587fe071d7eSDavid Rientjes 	},
2588fe071d7eSDavid Rientjes 	{
2589fef1bdd6SDavid Rientjes 		.procname	= "oom_dump_tasks",
2590fef1bdd6SDavid Rientjes 		.data		= &sysctl_oom_dump_tasks,
2591fef1bdd6SDavid Rientjes 		.maxlen		= sizeof(sysctl_oom_dump_tasks),
2592fef1bdd6SDavid Rientjes 		.mode		= 0644,
25936d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2594fef1bdd6SDavid Rientjes 	},
2595fef1bdd6SDavid Rientjes 	{
25961da177e4SLinus Torvalds 		.procname	= "overcommit_ratio",
25971da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_ratio,
25981da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_ratio),
25991da177e4SLinus Torvalds 		.mode		= 0644,
260049f0ce5fSJerome Marchand 		.proc_handler	= overcommit_ratio_handler,
260149f0ce5fSJerome Marchand 	},
260249f0ce5fSJerome Marchand 	{
260349f0ce5fSJerome Marchand 		.procname	= "overcommit_kbytes",
260449f0ce5fSJerome Marchand 		.data		= &sysctl_overcommit_kbytes,
260549f0ce5fSJerome Marchand 		.maxlen		= sizeof(sysctl_overcommit_kbytes),
260649f0ce5fSJerome Marchand 		.mode		= 0644,
260749f0ce5fSJerome Marchand 		.proc_handler	= overcommit_kbytes_handler,
26081da177e4SLinus Torvalds 	},
26091da177e4SLinus Torvalds 	{
26101da177e4SLinus Torvalds 		.procname	= "page-cluster",
26111da177e4SLinus Torvalds 		.data		= &page_cluster,
26121da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
26131da177e4SLinus Torvalds 		.mode		= 0644,
2614cb16e95fSPetr Holasek 		.proc_handler	= proc_dointvec_minmax,
2615eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
26161da177e4SLinus Torvalds 	},
26171da177e4SLinus Torvalds 	{
26181da177e4SLinus Torvalds 		.procname	= "dirty_background_ratio",
26191da177e4SLinus Torvalds 		.data		= &dirty_background_ratio,
26201da177e4SLinus Torvalds 		.maxlen		= sizeof(dirty_background_ratio),
26211da177e4SLinus Torvalds 		.mode		= 0644,
26226d456111SEric W. Biederman 		.proc_handler	= dirty_background_ratio_handler,
2623eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
262478e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_HUNDRED,
26251da177e4SLinus Torvalds 	},
26261da177e4SLinus Torvalds 	{
26272da02997SDavid Rientjes 		.procname	= "dirty_background_bytes",
26282da02997SDavid Rientjes 		.data		= &dirty_background_bytes,
26292da02997SDavid Rientjes 		.maxlen		= sizeof(dirty_background_bytes),
26302da02997SDavid Rientjes 		.mode		= 0644,
26316d456111SEric W. Biederman 		.proc_handler	= dirty_background_bytes_handler,
2632fc3501d4SSven Wegener 		.extra1		= &one_ul,
26332da02997SDavid Rientjes 	},
26342da02997SDavid Rientjes 	{
26351da177e4SLinus Torvalds 		.procname	= "dirty_ratio",
26361da177e4SLinus Torvalds 		.data		= &vm_dirty_ratio,
26371da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_dirty_ratio),
26381da177e4SLinus Torvalds 		.mode		= 0644,
26396d456111SEric W. Biederman 		.proc_handler	= dirty_ratio_handler,
2640eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
264178e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_HUNDRED,
26421da177e4SLinus Torvalds 	},
26431da177e4SLinus Torvalds 	{
26442da02997SDavid Rientjes 		.procname	= "dirty_bytes",
26452da02997SDavid Rientjes 		.data		= &vm_dirty_bytes,
26462da02997SDavid Rientjes 		.maxlen		= sizeof(vm_dirty_bytes),
26472da02997SDavid Rientjes 		.mode		= 0644,
26486d456111SEric W. Biederman 		.proc_handler	= dirty_bytes_handler,
26499e4a5bdaSAndrea Righi 		.extra1		= &dirty_bytes_min,
26502da02997SDavid Rientjes 	},
26512da02997SDavid Rientjes 	{
26521da177e4SLinus Torvalds 		.procname	= "dirty_writeback_centisecs",
2653f6ef9438SBart Samwel 		.data		= &dirty_writeback_interval,
2654f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_writeback_interval),
26551da177e4SLinus Torvalds 		.mode		= 0644,
26566d456111SEric W. Biederman 		.proc_handler	= dirty_writeback_centisecs_handler,
26571da177e4SLinus Torvalds 	},
26581da177e4SLinus Torvalds 	{
26591da177e4SLinus Torvalds 		.procname	= "dirty_expire_centisecs",
2660f6ef9438SBart Samwel 		.data		= &dirty_expire_interval,
2661f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_expire_interval),
26621da177e4SLinus Torvalds 		.mode		= 0644,
2663cb16e95fSPetr Holasek 		.proc_handler	= proc_dointvec_minmax,
2664eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
26651da177e4SLinus Torvalds 	},
26661da177e4SLinus Torvalds 	{
26671efff914STheodore Ts'o 		.procname	= "dirtytime_expire_seconds",
26681efff914STheodore Ts'o 		.data		= &dirtytime_expire_interval,
26692d87b309SRandy Dunlap 		.maxlen		= sizeof(dirtytime_expire_interval),
26701efff914STheodore Ts'o 		.mode		= 0644,
26711efff914STheodore Ts'o 		.proc_handler	= dirtytime_interval_handler,
2672eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
26731efff914STheodore Ts'o 	},
26741efff914STheodore Ts'o 	{
26751da177e4SLinus Torvalds 		.procname	= "swappiness",
26761da177e4SLinus Torvalds 		.data		= &vm_swappiness,
26771da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_swappiness),
26781da177e4SLinus Torvalds 		.mode		= 0644,
26796d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2680eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
268178e36f3bSXiaoming Ni 		.extra2		= SYSCTL_TWO_HUNDRED,
26821da177e4SLinus Torvalds 	},
26831da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE
26841da177e4SLinus Torvalds 	{
26851da177e4SLinus Torvalds 		.procname	= "nr_hugepages",
2686e5ff2159SAndi Kleen 		.data		= NULL,
26871da177e4SLinus Torvalds 		.maxlen		= sizeof(unsigned long),
26881da177e4SLinus Torvalds 		.mode		= 0644,
26896d456111SEric W. Biederman 		.proc_handler	= hugetlb_sysctl_handler,
26901da177e4SLinus Torvalds 	},
269106808b08SLee Schermerhorn #ifdef CONFIG_NUMA
269206808b08SLee Schermerhorn 	{
269306808b08SLee Schermerhorn 		.procname       = "nr_hugepages_mempolicy",
269406808b08SLee Schermerhorn 		.data           = NULL,
269506808b08SLee Schermerhorn 		.maxlen         = sizeof(unsigned long),
269606808b08SLee Schermerhorn 		.mode           = 0644,
269706808b08SLee Schermerhorn 		.proc_handler   = &hugetlb_mempolicy_sysctl_handler,
269806808b08SLee Schermerhorn 	},
26994518085eSKemi Wang 	{
27004518085eSKemi Wang 		.procname		= "numa_stat",
27014518085eSKemi Wang 		.data			= &sysctl_vm_numa_stat,
27024518085eSKemi Wang 		.maxlen			= sizeof(int),
27034518085eSKemi Wang 		.mode			= 0644,
27044518085eSKemi Wang 		.proc_handler	= sysctl_vm_numa_stat_handler,
2705eec4844fSMatteo Croce 		.extra1			= SYSCTL_ZERO,
2706eec4844fSMatteo Croce 		.extra2			= SYSCTL_ONE,
27074518085eSKemi Wang 	},
270806808b08SLee Schermerhorn #endif
27091da177e4SLinus Torvalds 	 {
27101da177e4SLinus Torvalds 		.procname	= "hugetlb_shm_group",
27111da177e4SLinus Torvalds 		.data		= &sysctl_hugetlb_shm_group,
27121da177e4SLinus Torvalds 		.maxlen		= sizeof(gid_t),
27131da177e4SLinus Torvalds 		.mode		= 0644,
27146d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
27151da177e4SLinus Torvalds 	 },
2716396faf03SMel Gorman 	{
2717d1c3fb1fSNishanth Aravamudan 		.procname	= "nr_overcommit_hugepages",
2718e5ff2159SAndi Kleen 		.data		= NULL,
2719e5ff2159SAndi Kleen 		.maxlen		= sizeof(unsigned long),
2720d1c3fb1fSNishanth Aravamudan 		.mode		= 0644,
27216d456111SEric W. Biederman 		.proc_handler	= hugetlb_overcommit_handler,
2722d1c3fb1fSNishanth Aravamudan 	},
27231da177e4SLinus Torvalds #endif
27241da177e4SLinus Torvalds 	{
27251da177e4SLinus Torvalds 		.procname	= "lowmem_reserve_ratio",
27261da177e4SLinus Torvalds 		.data		= &sysctl_lowmem_reserve_ratio,
27271da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
27281da177e4SLinus Torvalds 		.mode		= 0644,
27296d456111SEric W. Biederman 		.proc_handler	= lowmem_reserve_ratio_sysctl_handler,
27301da177e4SLinus Torvalds 	},
27311da177e4SLinus Torvalds 	{
27329d0243bcSAndrew Morton 		.procname	= "drop_caches",
27339d0243bcSAndrew Morton 		.data		= &sysctl_drop_caches,
27349d0243bcSAndrew Morton 		.maxlen		= sizeof(int),
2735204cb79aSJohannes Weiner 		.mode		= 0200,
27369d0243bcSAndrew Morton 		.proc_handler	= drop_caches_sysctl_handler,
2737eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
273878e36f3bSXiaoming Ni 		.extra2		= SYSCTL_FOUR,
27399d0243bcSAndrew Morton 	},
274076ab0f53SMel Gorman #ifdef CONFIG_COMPACTION
274176ab0f53SMel Gorman 	{
274276ab0f53SMel Gorman 		.procname	= "compact_memory",
2743ef498438SPintu Kumar 		.data		= NULL,
274476ab0f53SMel Gorman 		.maxlen		= sizeof(int),
274576ab0f53SMel Gorman 		.mode		= 0200,
274676ab0f53SMel Gorman 		.proc_handler	= sysctl_compaction_handler,
274776ab0f53SMel Gorman 	},
27485e771905SMel Gorman 	{
2749facdaa91SNitin Gupta 		.procname	= "compaction_proactiveness",
2750facdaa91SNitin Gupta 		.data		= &sysctl_compaction_proactiveness,
2751d34c0a75SNitin Gupta 		.maxlen		= sizeof(sysctl_compaction_proactiveness),
2752facdaa91SNitin Gupta 		.mode		= 0644,
275365d759c8SCharan Teja Reddy 		.proc_handler	= compaction_proactiveness_sysctl_handler,
2754facdaa91SNitin Gupta 		.extra1		= SYSCTL_ZERO,
275578e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_HUNDRED,
2756facdaa91SNitin Gupta 	},
2757facdaa91SNitin Gupta 	{
27585e771905SMel Gorman 		.procname	= "extfrag_threshold",
27595e771905SMel Gorman 		.data		= &sysctl_extfrag_threshold,
27605e771905SMel Gorman 		.maxlen		= sizeof(int),
27615e771905SMel Gorman 		.mode		= 0644,
27626b7e5cadSMatthew Wilcox 		.proc_handler	= proc_dointvec_minmax,
27635e771905SMel Gorman 		.extra1		= &min_extfrag_threshold,
27645e771905SMel Gorman 		.extra2		= &max_extfrag_threshold,
27655e771905SMel Gorman 	},
27665bbe3547SEric B Munson 	{
27675bbe3547SEric B Munson 		.procname	= "compact_unevictable_allowed",
27685bbe3547SEric B Munson 		.data		= &sysctl_compact_unevictable_allowed,
27695bbe3547SEric B Munson 		.maxlen		= sizeof(int),
27705bbe3547SEric B Munson 		.mode		= 0644,
27716923aa0dSSebastian Andrzej Siewior 		.proc_handler	= proc_dointvec_minmax_warn_RT_change,
2772eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2773eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
27745bbe3547SEric B Munson 	},
27755e771905SMel Gorman 
277676ab0f53SMel Gorman #endif /* CONFIG_COMPACTION */
27779d0243bcSAndrew Morton 	{
27781da177e4SLinus Torvalds 		.procname	= "min_free_kbytes",
27791da177e4SLinus Torvalds 		.data		= &min_free_kbytes,
27801da177e4SLinus Torvalds 		.maxlen		= sizeof(min_free_kbytes),
27811da177e4SLinus Torvalds 		.mode		= 0644,
27826d456111SEric W. Biederman 		.proc_handler	= min_free_kbytes_sysctl_handler,
2783eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
27841da177e4SLinus Torvalds 	},
27858ad4b1fbSRohit Seth 	{
27861c30844dSMel Gorman 		.procname	= "watermark_boost_factor",
27871c30844dSMel Gorman 		.data		= &watermark_boost_factor,
27881c30844dSMel Gorman 		.maxlen		= sizeof(watermark_boost_factor),
27891c30844dSMel Gorman 		.mode		= 0644,
279026363af5SChristoph Hellwig 		.proc_handler	= proc_dointvec_minmax,
2791eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
27921c30844dSMel Gorman 	},
27931c30844dSMel Gorman 	{
2794795ae7a0SJohannes Weiner 		.procname	= "watermark_scale_factor",
2795795ae7a0SJohannes Weiner 		.data		= &watermark_scale_factor,
2796795ae7a0SJohannes Weiner 		.maxlen		= sizeof(watermark_scale_factor),
2797795ae7a0SJohannes Weiner 		.mode		= 0644,
2798795ae7a0SJohannes Weiner 		.proc_handler	= watermark_scale_factor_sysctl_handler,
2799eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
280078e36f3bSXiaoming Ni 		.extra2		= SYSCTL_THREE_THOUSAND,
2801795ae7a0SJohannes Weiner 	},
2802795ae7a0SJohannes Weiner 	{
280374f44822SMel Gorman 		.procname	= "percpu_pagelist_high_fraction",
280474f44822SMel Gorman 		.data		= &percpu_pagelist_high_fraction,
280574f44822SMel Gorman 		.maxlen		= sizeof(percpu_pagelist_high_fraction),
28068ad4b1fbSRohit Seth 		.mode		= 0644,
280774f44822SMel Gorman 		.proc_handler	= percpu_pagelist_high_fraction_sysctl_handler,
2808eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28098ad4b1fbSRohit Seth 	},
28105ef64cc8SLinus Torvalds 	{
28115ef64cc8SLinus Torvalds 		.procname	= "page_lock_unfairness",
28125ef64cc8SLinus Torvalds 		.data		= &sysctl_page_lock_unfairness,
28135ef64cc8SLinus Torvalds 		.maxlen		= sizeof(sysctl_page_lock_unfairness),
28145ef64cc8SLinus Torvalds 		.mode		= 0644,
28155ef64cc8SLinus Torvalds 		.proc_handler	= proc_dointvec_minmax,
28165ef64cc8SLinus Torvalds 		.extra1		= SYSCTL_ZERO,
28175ef64cc8SLinus Torvalds 	},
28181da177e4SLinus Torvalds #ifdef CONFIG_MMU
28191da177e4SLinus Torvalds 	{
28201da177e4SLinus Torvalds 		.procname	= "max_map_count",
28211da177e4SLinus Torvalds 		.data		= &sysctl_max_map_count,
28221da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_max_map_count),
28231da177e4SLinus Torvalds 		.mode		= 0644,
28243e26120cSWANG Cong 		.proc_handler	= proc_dointvec_minmax,
2825eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28261da177e4SLinus Torvalds 	},
2827dd8632a1SPaul Mundt #else
2828dd8632a1SPaul Mundt 	{
2829dd8632a1SPaul Mundt 		.procname	= "nr_trim_pages",
2830dd8632a1SPaul Mundt 		.data		= &sysctl_nr_trim_pages,
2831dd8632a1SPaul Mundt 		.maxlen		= sizeof(sysctl_nr_trim_pages),
2832dd8632a1SPaul Mundt 		.mode		= 0644,
28336d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2834eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2835dd8632a1SPaul Mundt 	},
28361da177e4SLinus Torvalds #endif
28371da177e4SLinus Torvalds 	{
28381da177e4SLinus Torvalds 		.procname	= "laptop_mode",
28391da177e4SLinus Torvalds 		.data		= &laptop_mode,
28401da177e4SLinus Torvalds 		.maxlen		= sizeof(laptop_mode),
28411da177e4SLinus Torvalds 		.mode		= 0644,
28426d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_jiffies,
28431da177e4SLinus Torvalds 	},
28441da177e4SLinus Torvalds 	{
28451da177e4SLinus Torvalds 		.procname	= "vfs_cache_pressure",
28461da177e4SLinus Torvalds 		.data		= &sysctl_vfs_cache_pressure,
28471da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
28481da177e4SLinus Torvalds 		.mode		= 0644,
28493b3376f2SLin Feng 		.proc_handler	= proc_dointvec_minmax,
2850eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28511da177e4SLinus Torvalds 	},
285267f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
285367f3977fSAlexandre Ghiti     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
28541da177e4SLinus Torvalds 	{
28551da177e4SLinus Torvalds 		.procname	= "legacy_va_layout",
28561da177e4SLinus Torvalds 		.data		= &sysctl_legacy_va_layout,
28571da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_legacy_va_layout),
28581da177e4SLinus Torvalds 		.mode		= 0644,
28593b3376f2SLin Feng 		.proc_handler	= proc_dointvec_minmax,
2860eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28611da177e4SLinus Torvalds 	},
28621da177e4SLinus Torvalds #endif
28631743660bSChristoph Lameter #ifdef CONFIG_NUMA
28641743660bSChristoph Lameter 	{
28651743660bSChristoph Lameter 		.procname	= "zone_reclaim_mode",
2866a5f5f91dSMel Gorman 		.data		= &node_reclaim_mode,
2867a5f5f91dSMel Gorman 		.maxlen		= sizeof(node_reclaim_mode),
28681743660bSChristoph Lameter 		.mode		= 0644,
28693b3376f2SLin Feng 		.proc_handler	= proc_dointvec_minmax,
2870eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28711743660bSChristoph Lameter 	},
28729614634fSChristoph Lameter 	{
28739614634fSChristoph Lameter 		.procname	= "min_unmapped_ratio",
28749614634fSChristoph Lameter 		.data		= &sysctl_min_unmapped_ratio,
28759614634fSChristoph Lameter 		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
28769614634fSChristoph Lameter 		.mode		= 0644,
28776d456111SEric W. Biederman 		.proc_handler	= sysctl_min_unmapped_ratio_sysctl_handler,
2878eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
287978e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_HUNDRED,
28809614634fSChristoph Lameter 	},
28810ff38490SChristoph Lameter 	{
28820ff38490SChristoph Lameter 		.procname	= "min_slab_ratio",
28830ff38490SChristoph Lameter 		.data		= &sysctl_min_slab_ratio,
28840ff38490SChristoph Lameter 		.maxlen		= sizeof(sysctl_min_slab_ratio),
28850ff38490SChristoph Lameter 		.mode		= 0644,
28866d456111SEric W. Biederman 		.proc_handler	= sysctl_min_slab_ratio_sysctl_handler,
2887eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
288878e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_HUNDRED,
28890ff38490SChristoph Lameter 	},
28901743660bSChristoph Lameter #endif
289177461ab3SChristoph Lameter #ifdef CONFIG_SMP
289277461ab3SChristoph Lameter 	{
289377461ab3SChristoph Lameter 		.procname	= "stat_interval",
289477461ab3SChristoph Lameter 		.data		= &sysctl_stat_interval,
289577461ab3SChristoph Lameter 		.maxlen		= sizeof(sysctl_stat_interval),
289677461ab3SChristoph Lameter 		.mode		= 0644,
28976d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_jiffies,
289877461ab3SChristoph Lameter 	},
289952b6f46bSHugh Dickins 	{
290052b6f46bSHugh Dickins 		.procname	= "stat_refresh",
290152b6f46bSHugh Dickins 		.data		= NULL,
290252b6f46bSHugh Dickins 		.maxlen		= 0,
290352b6f46bSHugh Dickins 		.mode		= 0600,
290452b6f46bSHugh Dickins 		.proc_handler	= vmstat_refresh,
290552b6f46bSHugh Dickins 	},
290677461ab3SChristoph Lameter #endif
29076e141546SDavid Howells #ifdef CONFIG_MMU
2908ed032189SEric Paris 	{
2909ed032189SEric Paris 		.procname	= "mmap_min_addr",
2910788084abSEric Paris 		.data		= &dac_mmap_min_addr,
2911ed032189SEric Paris 		.maxlen		= sizeof(unsigned long),
2912ed032189SEric Paris 		.mode		= 0644,
29136d456111SEric W. Biederman 		.proc_handler	= mmap_min_addr_handler,
2914ed032189SEric Paris 	},
29156e141546SDavid Howells #endif
2916f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA
2917f0c0b2b8SKAMEZAWA Hiroyuki 	{
2918f0c0b2b8SKAMEZAWA Hiroyuki 		.procname	= "numa_zonelist_order",
2919f0c0b2b8SKAMEZAWA Hiroyuki 		.data		= &numa_zonelist_order,
2920f0c0b2b8SKAMEZAWA Hiroyuki 		.maxlen		= NUMA_ZONELIST_ORDER_LEN,
2921f0c0b2b8SKAMEZAWA Hiroyuki 		.mode		= 0644,
29226d456111SEric W. Biederman 		.proc_handler	= numa_zonelist_order_handler,
2923f0c0b2b8SKAMEZAWA Hiroyuki 	},
2924f0c0b2b8SKAMEZAWA Hiroyuki #endif
29252b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
29265c36e657SPaul Mundt    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
2927e6e5494cSIngo Molnar 	{
2928e6e5494cSIngo Molnar 		.procname	= "vdso_enabled",
29293d7ee969SAndy Lutomirski #ifdef CONFIG_X86_32
29303d7ee969SAndy Lutomirski 		.data		= &vdso32_enabled,
29313d7ee969SAndy Lutomirski 		.maxlen		= sizeof(vdso32_enabled),
29323d7ee969SAndy Lutomirski #else
2933e6e5494cSIngo Molnar 		.data		= &vdso_enabled,
2934e6e5494cSIngo Molnar 		.maxlen		= sizeof(vdso_enabled),
29353d7ee969SAndy Lutomirski #endif
2936e6e5494cSIngo Molnar 		.mode		= 0644,
29376d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2938eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2939e6e5494cSIngo Molnar 	},
2940e6e5494cSIngo Molnar #endif
2941195cf453SBron Gondwana #ifdef CONFIG_HIGHMEM
2942195cf453SBron Gondwana 	{
2943195cf453SBron Gondwana 		.procname	= "highmem_is_dirtyable",
2944195cf453SBron Gondwana 		.data		= &vm_highmem_is_dirtyable,
2945195cf453SBron Gondwana 		.maxlen		= sizeof(vm_highmem_is_dirtyable),
2946195cf453SBron Gondwana 		.mode		= 0644,
29476d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2948eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2949eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2950195cf453SBron Gondwana 	},
2951195cf453SBron Gondwana #endif
29526a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE
29536a46079cSAndi Kleen 	{
29546a46079cSAndi Kleen 		.procname	= "memory_failure_early_kill",
29556a46079cSAndi Kleen 		.data		= &sysctl_memory_failure_early_kill,
29566a46079cSAndi Kleen 		.maxlen		= sizeof(sysctl_memory_failure_early_kill),
29576a46079cSAndi Kleen 		.mode		= 0644,
29586d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2959eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2960eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
29616a46079cSAndi Kleen 	},
29626a46079cSAndi Kleen 	{
29636a46079cSAndi Kleen 		.procname	= "memory_failure_recovery",
29646a46079cSAndi Kleen 		.data		= &sysctl_memory_failure_recovery,
29656a46079cSAndi Kleen 		.maxlen		= sizeof(sysctl_memory_failure_recovery),
29666a46079cSAndi Kleen 		.mode		= 0644,
29676d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2968eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2969eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
29706a46079cSAndi Kleen 	},
29716a46079cSAndi Kleen #endif
2972c9b1d098SAndrew Shewmaker 	{
2973c9b1d098SAndrew Shewmaker 		.procname	= "user_reserve_kbytes",
2974c9b1d098SAndrew Shewmaker 		.data		= &sysctl_user_reserve_kbytes,
2975c9b1d098SAndrew Shewmaker 		.maxlen		= sizeof(sysctl_user_reserve_kbytes),
2976c9b1d098SAndrew Shewmaker 		.mode		= 0644,
2977c9b1d098SAndrew Shewmaker 		.proc_handler	= proc_doulongvec_minmax,
2978c9b1d098SAndrew Shewmaker 	},
29794eeab4f5SAndrew Shewmaker 	{
29804eeab4f5SAndrew Shewmaker 		.procname	= "admin_reserve_kbytes",
29814eeab4f5SAndrew Shewmaker 		.data		= &sysctl_admin_reserve_kbytes,
29824eeab4f5SAndrew Shewmaker 		.maxlen		= sizeof(sysctl_admin_reserve_kbytes),
29834eeab4f5SAndrew Shewmaker 		.mode		= 0644,
29844eeab4f5SAndrew Shewmaker 		.proc_handler	= proc_doulongvec_minmax,
29854eeab4f5SAndrew Shewmaker 	},
2986d07e2259SDaniel Cashman #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
2987d07e2259SDaniel Cashman 	{
2988d07e2259SDaniel Cashman 		.procname	= "mmap_rnd_bits",
2989d07e2259SDaniel Cashman 		.data		= &mmap_rnd_bits,
2990d07e2259SDaniel Cashman 		.maxlen		= sizeof(mmap_rnd_bits),
2991d07e2259SDaniel Cashman 		.mode		= 0600,
2992d07e2259SDaniel Cashman 		.proc_handler	= proc_dointvec_minmax,
2993d07e2259SDaniel Cashman 		.extra1		= (void *)&mmap_rnd_bits_min,
2994d07e2259SDaniel Cashman 		.extra2		= (void *)&mmap_rnd_bits_max,
2995d07e2259SDaniel Cashman 	},
2996d07e2259SDaniel Cashman #endif
2997d07e2259SDaniel Cashman #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
2998d07e2259SDaniel Cashman 	{
2999d07e2259SDaniel Cashman 		.procname	= "mmap_rnd_compat_bits",
3000d07e2259SDaniel Cashman 		.data		= &mmap_rnd_compat_bits,
3001d07e2259SDaniel Cashman 		.maxlen		= sizeof(mmap_rnd_compat_bits),
3002d07e2259SDaniel Cashman 		.mode		= 0600,
3003d07e2259SDaniel Cashman 		.proc_handler	= proc_dointvec_minmax,
3004d07e2259SDaniel Cashman 		.extra1		= (void *)&mmap_rnd_compat_bits_min,
3005d07e2259SDaniel Cashman 		.extra2		= (void *)&mmap_rnd_compat_bits_max,
3006d07e2259SDaniel Cashman 	},
3007d07e2259SDaniel Cashman #endif
3008cefdca0aSPeter Xu #ifdef CONFIG_USERFAULTFD
3009cefdca0aSPeter Xu 	{
3010cefdca0aSPeter Xu 		.procname	= "unprivileged_userfaultfd",
3011cefdca0aSPeter Xu 		.data		= &sysctl_unprivileged_userfaultfd,
3012cefdca0aSPeter Xu 		.maxlen		= sizeof(sysctl_unprivileged_userfaultfd),
3013cefdca0aSPeter Xu 		.mode		= 0644,
3014cefdca0aSPeter Xu 		.proc_handler	= proc_dointvec_minmax,
3015eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3016eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
3017cefdca0aSPeter Xu 	},
3018cefdca0aSPeter Xu #endif
30196fce56ecSEric W. Biederman 	{ }
30201da177e4SLinus Torvalds };
30211da177e4SLinus Torvalds 
3022d8217f07SEric W. Biederman static struct ctl_table fs_table[] = {
30231da177e4SLinus Torvalds 	{
30241da177e4SLinus Torvalds 		.procname	= "inode-nr",
30251da177e4SLinus Torvalds 		.data		= &inodes_stat,
30263942c07cSGlauber Costa 		.maxlen		= 2*sizeof(long),
30271da177e4SLinus Torvalds 		.mode		= 0444,
3028cffbc8aaSDave Chinner 		.proc_handler	= proc_nr_inodes,
30291da177e4SLinus Torvalds 	},
30301da177e4SLinus Torvalds 	{
30311da177e4SLinus Torvalds 		.procname	= "inode-state",
30321da177e4SLinus Torvalds 		.data		= &inodes_stat,
30333942c07cSGlauber Costa 		.maxlen		= 7*sizeof(long),
30341da177e4SLinus Torvalds 		.mode		= 0444,
3035cffbc8aaSDave Chinner 		.proc_handler	= proc_nr_inodes,
30361da177e4SLinus Torvalds 	},
30371da177e4SLinus Torvalds 	{
30381da177e4SLinus Torvalds 		.procname	= "file-nr",
30391da177e4SLinus Torvalds 		.data		= &files_stat,
3040518de9b3SEric Dumazet 		.maxlen		= sizeof(files_stat),
30411da177e4SLinus Torvalds 		.mode		= 0444,
30426d456111SEric W. Biederman 		.proc_handler	= proc_nr_files,
30431da177e4SLinus Torvalds 	},
30441da177e4SLinus Torvalds 	{
30451da177e4SLinus Torvalds 		.procname	= "file-max",
30461da177e4SLinus Torvalds 		.data		= &files_stat.max_files,
3047518de9b3SEric Dumazet 		.maxlen		= sizeof(files_stat.max_files),
30481da177e4SLinus Torvalds 		.mode		= 0644,
3049518de9b3SEric Dumazet 		.proc_handler	= proc_doulongvec_minmax,
30509002b214SWill Deacon 		.extra1		= &zero_ul,
305132a5ad9cSChristian Brauner 		.extra2		= &long_max,
30521da177e4SLinus Torvalds 	},
30531da177e4SLinus Torvalds 	{
30549cfe015aSEric Dumazet 		.procname	= "nr_open",
30559cfe015aSEric Dumazet 		.data		= &sysctl_nr_open,
30569b80a184SAlexey Dobriyan 		.maxlen		= sizeof(unsigned int),
30579cfe015aSEric Dumazet 		.mode		= 0644,
30586d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
3059eceea0b3SAl Viro 		.extra1		= &sysctl_nr_open_min,
3060eceea0b3SAl Viro 		.extra2		= &sysctl_nr_open_max,
30619cfe015aSEric Dumazet 	},
30629cfe015aSEric Dumazet 	{
30631da177e4SLinus Torvalds 		.procname	= "dentry-state",
30641da177e4SLinus Torvalds 		.data		= &dentry_stat,
30653942c07cSGlauber Costa 		.maxlen		= 6*sizeof(long),
30661da177e4SLinus Torvalds 		.mode		= 0444,
3067312d3ca8SChristoph Hellwig 		.proc_handler	= proc_nr_dentry,
30681da177e4SLinus Torvalds 	},
30691da177e4SLinus Torvalds 	{
30701da177e4SLinus Torvalds 		.procname	= "overflowuid",
30711da177e4SLinus Torvalds 		.data		= &fs_overflowuid,
30721da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
30731da177e4SLinus Torvalds 		.mode		= 0644,
30746d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
30751da177e4SLinus Torvalds 		.extra1		= &minolduid,
30761da177e4SLinus Torvalds 		.extra2		= &maxolduid,
30771da177e4SLinus Torvalds 	},
30781da177e4SLinus Torvalds 	{
30791da177e4SLinus Torvalds 		.procname	= "overflowgid",
30801da177e4SLinus Torvalds 		.data		= &fs_overflowgid,
30811da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
30821da177e4SLinus Torvalds 		.mode		= 0644,
30836d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
30841da177e4SLinus Torvalds 		.extra1		= &minolduid,
30851da177e4SLinus Torvalds 		.extra2		= &maxolduid,
30861da177e4SLinus Torvalds 	},
3087bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING
30881da177e4SLinus Torvalds 	{
30891da177e4SLinus Torvalds 		.procname	= "leases-enable",
30901da177e4SLinus Torvalds 		.data		= &leases_enable,
30911da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
30921da177e4SLinus Torvalds 		.mode		= 0644,
30936d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
30941da177e4SLinus Torvalds 	},
3095bfcd17a6SThomas Petazzoni #endif
30961da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY
30971da177e4SLinus Torvalds 	{
30981da177e4SLinus Torvalds 		.procname	= "dir-notify-enable",
30991da177e4SLinus Torvalds 		.data		= &dir_notify_enable,
31001da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
31011da177e4SLinus Torvalds 		.mode		= 0644,
31026d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
31031da177e4SLinus Torvalds 	},
31041da177e4SLinus Torvalds #endif
31051da177e4SLinus Torvalds #ifdef CONFIG_MMU
3106bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING
31071da177e4SLinus Torvalds 	{
31081da177e4SLinus Torvalds 		.procname	= "lease-break-time",
31091da177e4SLinus Torvalds 		.data		= &lease_break_time,
31101da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
31111da177e4SLinus Torvalds 		.mode		= 0644,
31126d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
31131da177e4SLinus Torvalds 	},
3114bfcd17a6SThomas Petazzoni #endif
3115ebf3f09cSThomas Petazzoni #ifdef CONFIG_AIO
31161da177e4SLinus Torvalds 	{
31171da177e4SLinus Torvalds 		.procname	= "aio-nr",
31181da177e4SLinus Torvalds 		.data		= &aio_nr,
31191da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_nr),
31201da177e4SLinus Torvalds 		.mode		= 0444,
31216d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
31221da177e4SLinus Torvalds 	},
31231da177e4SLinus Torvalds 	{
31241da177e4SLinus Torvalds 		.procname	= "aio-max-nr",
31251da177e4SLinus Torvalds 		.data		= &aio_max_nr,
31261da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_max_nr),
31271da177e4SLinus Torvalds 		.mode		= 0644,
31286d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
31291da177e4SLinus Torvalds 	},
3130ebf3f09cSThomas Petazzoni #endif /* CONFIG_AIO */
31312d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
31320399cb08SRobert Love 	{
31330399cb08SRobert Love 		.procname	= "inotify",
31340399cb08SRobert Love 		.mode		= 0555,
31350399cb08SRobert Love 		.child		= inotify_table,
31360399cb08SRobert Love 	},
31370399cb08SRobert Love #endif
31385b8fea65SAmir Goldstein #ifdef CONFIG_FANOTIFY
31395b8fea65SAmir Goldstein 	{
31405b8fea65SAmir Goldstein 		.procname	= "fanotify",
31415b8fea65SAmir Goldstein 		.mode		= 0555,
31425b8fea65SAmir Goldstein 		.child		= fanotify_table,
31435b8fea65SAmir Goldstein 	},
31445b8fea65SAmir Goldstein #endif
31457ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL
31467ef9964eSDavide Libenzi 	{
31477ef9964eSDavide Libenzi 		.procname	= "epoll",
31487ef9964eSDavide Libenzi 		.mode		= 0555,
31497ef9964eSDavide Libenzi 		.child		= epoll_table,
31507ef9964eSDavide Libenzi 	},
31517ef9964eSDavide Libenzi #endif
31521da177e4SLinus Torvalds #endif
3153d6e71144SAlan Cox 	{
3154800179c9SKees Cook 		.procname	= "protected_symlinks",
3155800179c9SKees Cook 		.data		= &sysctl_protected_symlinks,
3156800179c9SKees Cook 		.maxlen		= sizeof(int),
3157800179c9SKees Cook 		.mode		= 0600,
3158800179c9SKees Cook 		.proc_handler	= proc_dointvec_minmax,
3159eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3160eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
3161800179c9SKees Cook 	},
3162800179c9SKees Cook 	{
3163800179c9SKees Cook 		.procname	= "protected_hardlinks",
3164800179c9SKees Cook 		.data		= &sysctl_protected_hardlinks,
3165800179c9SKees Cook 		.maxlen		= sizeof(int),
3166800179c9SKees Cook 		.mode		= 0600,
3167800179c9SKees Cook 		.proc_handler	= proc_dointvec_minmax,
3168eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3169eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
3170800179c9SKees Cook 	},
3171800179c9SKees Cook 	{
317230aba665SSalvatore Mesoraca 		.procname	= "protected_fifos",
317330aba665SSalvatore Mesoraca 		.data		= &sysctl_protected_fifos,
317430aba665SSalvatore Mesoraca 		.maxlen		= sizeof(int),
317530aba665SSalvatore Mesoraca 		.mode		= 0600,
317630aba665SSalvatore Mesoraca 		.proc_handler	= proc_dointvec_minmax,
3177eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
317878e36f3bSXiaoming Ni 		.extra2		= SYSCTL_TWO,
317930aba665SSalvatore Mesoraca 	},
318030aba665SSalvatore Mesoraca 	{
318130aba665SSalvatore Mesoraca 		.procname	= "protected_regular",
318230aba665SSalvatore Mesoraca 		.data		= &sysctl_protected_regular,
318330aba665SSalvatore Mesoraca 		.maxlen		= sizeof(int),
318430aba665SSalvatore Mesoraca 		.mode		= 0600,
318530aba665SSalvatore Mesoraca 		.proc_handler	= proc_dointvec_minmax,
3186eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
318778e36f3bSXiaoming Ni 		.extra2		= SYSCTL_TWO,
318830aba665SSalvatore Mesoraca 	},
318930aba665SSalvatore Mesoraca 	{
3190d6e71144SAlan Cox 		.procname	= "suid_dumpable",
3191d6e71144SAlan Cox 		.data		= &suid_dumpable,
3192d6e71144SAlan Cox 		.maxlen		= sizeof(int),
3193d6e71144SAlan Cox 		.mode		= 0644,
319454b50199SKees Cook 		.proc_handler	= proc_dointvec_minmax_coredump,
3195eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
319678e36f3bSXiaoming Ni 		.extra2		= SYSCTL_TWO,
3197d6e71144SAlan Cox 	},
31982abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
31992abc26fcSEric W. Biederman 	{
32002abc26fcSEric W. Biederman 		.procname	= "binfmt_misc",
32012abc26fcSEric W. Biederman 		.mode		= 0555,
3202f9bd6733SEric W. Biederman 		.child		= sysctl_mount_point,
32032abc26fcSEric W. Biederman 	},
32042abc26fcSEric W. Biederman #endif
3205b492e95bSJens Axboe 	{
3206ff9da691SJens Axboe 		.procname	= "pipe-max-size",
3207ff9da691SJens Axboe 		.data		= &pipe_max_size,
320898159d97SJoe Lawrence 		.maxlen		= sizeof(pipe_max_size),
3209b492e95bSJens Axboe 		.mode		= 0644,
3210319e0a21SEric Biggers 		.proc_handler	= proc_dopipe_max_size,
3211b492e95bSJens Axboe 	},
3212759c0114SWilly Tarreau 	{
3213759c0114SWilly Tarreau 		.procname	= "pipe-user-pages-hard",
3214759c0114SWilly Tarreau 		.data		= &pipe_user_pages_hard,
3215759c0114SWilly Tarreau 		.maxlen		= sizeof(pipe_user_pages_hard),
3216759c0114SWilly Tarreau 		.mode		= 0644,
3217759c0114SWilly Tarreau 		.proc_handler	= proc_doulongvec_minmax,
3218759c0114SWilly Tarreau 	},
3219759c0114SWilly Tarreau 	{
3220759c0114SWilly Tarreau 		.procname	= "pipe-user-pages-soft",
3221759c0114SWilly Tarreau 		.data		= &pipe_user_pages_soft,
3222759c0114SWilly Tarreau 		.maxlen		= sizeof(pipe_user_pages_soft),
3223759c0114SWilly Tarreau 		.mode		= 0644,
3224759c0114SWilly Tarreau 		.proc_handler	= proc_doulongvec_minmax,
3225759c0114SWilly Tarreau 	},
3226d2921684SEric W. Biederman 	{
3227d2921684SEric W. Biederman 		.procname	= "mount-max",
3228d2921684SEric W. Biederman 		.data		= &sysctl_mount_max,
3229d2921684SEric W. Biederman 		.maxlen		= sizeof(unsigned int),
3230d2921684SEric W. Biederman 		.mode		= 0644,
3231d2921684SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
3232eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
3233d2921684SEric W. Biederman 	},
32346fce56ecSEric W. Biederman 	{ }
32351da177e4SLinus Torvalds };
32361da177e4SLinus Torvalds 
3237d8217f07SEric W. Biederman static struct ctl_table debug_table[] = {
32387ac57a89SCatalin Marinas #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
3239abd4f750SMasoud Asgharifard Sharbiani 	{
3240abd4f750SMasoud Asgharifard Sharbiani 		.procname	= "exception-trace",
3241abd4f750SMasoud Asgharifard Sharbiani 		.data		= &show_unhandled_signals,
3242abd4f750SMasoud Asgharifard Sharbiani 		.maxlen		= sizeof(int),
3243abd4f750SMasoud Asgharifard Sharbiani 		.mode		= 0644,
3244abd4f750SMasoud Asgharifard Sharbiani 		.proc_handler	= proc_dointvec
3245abd4f750SMasoud Asgharifard Sharbiani 	},
3246abd4f750SMasoud Asgharifard Sharbiani #endif
3247b2be84dfSMasami Hiramatsu #if defined(CONFIG_OPTPROBES)
3248b2be84dfSMasami Hiramatsu 	{
3249b2be84dfSMasami Hiramatsu 		.procname	= "kprobes-optimization",
3250b2be84dfSMasami Hiramatsu 		.data		= &sysctl_kprobes_optimization,
3251b2be84dfSMasami Hiramatsu 		.maxlen		= sizeof(int),
3252b2be84dfSMasami Hiramatsu 		.mode		= 0644,
3253b2be84dfSMasami Hiramatsu 		.proc_handler	= proc_kprobes_optimization_handler,
3254eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3255eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
3256b2be84dfSMasami Hiramatsu 	},
3257b2be84dfSMasami Hiramatsu #endif
32586fce56ecSEric W. Biederman 	{ }
32591da177e4SLinus Torvalds };
32601da177e4SLinus Torvalds 
3261d8217f07SEric W. Biederman static struct ctl_table dev_table[] = {
32626fce56ecSEric W. Biederman 	{ }
32631da177e4SLinus Torvalds };
32641da177e4SLinus Torvalds 
3265f461d2dcSChristoph Hellwig static struct ctl_table sysctl_base_table[] = {
3266f461d2dcSChristoph Hellwig 	{
3267f461d2dcSChristoph Hellwig 		.procname	= "kernel",
3268f461d2dcSChristoph Hellwig 		.mode		= 0555,
3269f461d2dcSChristoph Hellwig 		.child		= kern_table,
3270f461d2dcSChristoph Hellwig 	},
3271f461d2dcSChristoph Hellwig 	{
3272f461d2dcSChristoph Hellwig 		.procname	= "vm",
3273f461d2dcSChristoph Hellwig 		.mode		= 0555,
3274f461d2dcSChristoph Hellwig 		.child		= vm_table,
3275f461d2dcSChristoph Hellwig 	},
3276f461d2dcSChristoph Hellwig 	{
3277f461d2dcSChristoph Hellwig 		.procname	= "fs",
3278f461d2dcSChristoph Hellwig 		.mode		= 0555,
3279f461d2dcSChristoph Hellwig 		.child		= fs_table,
3280f461d2dcSChristoph Hellwig 	},
3281f461d2dcSChristoph Hellwig 	{
3282f461d2dcSChristoph Hellwig 		.procname	= "debug",
3283f461d2dcSChristoph Hellwig 		.mode		= 0555,
3284f461d2dcSChristoph Hellwig 		.child		= debug_table,
3285f461d2dcSChristoph Hellwig 	},
3286f461d2dcSChristoph Hellwig 	{
3287f461d2dcSChristoph Hellwig 		.procname	= "dev",
3288f461d2dcSChristoph Hellwig 		.mode		= 0555,
3289f461d2dcSChristoph Hellwig 		.child		= dev_table,
3290f461d2dcSChristoph Hellwig 	},
3291f461d2dcSChristoph Hellwig 	{ }
3292f461d2dcSChristoph Hellwig };
3293f461d2dcSChristoph Hellwig 
3294de4e83bdSEric W. Biederman int __init sysctl_init(void)
3295330d57fbSAl Viro {
3296fd4b616bSSteven Rostedt 	struct ctl_table_header *hdr;
3297fd4b616bSSteven Rostedt 
3298fd4b616bSSteven Rostedt 	hdr = register_sysctl_table(sysctl_base_table);
3299fd4b616bSSteven Rostedt 	kmemleak_not_leak(hdr);
3300330d57fbSAl Viro 	return 0;
3301f7e6ced4SAl Viro }
3302b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */
33031da177e4SLinus Torvalds /*
33041da177e4SLinus Torvalds  * No sense putting this after each symbol definition, twice,
33051da177e4SLinus Torvalds  * exception granted :-)
33061da177e4SLinus Torvalds  */
3307a2071573SJia He EXPORT_SYMBOL(proc_dobool);
33081da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec);
3309e7d316a0SSubash Abhinov Kasiviswanathan EXPORT_SYMBOL(proc_douintvec);
33101da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies);
33111da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax);
331261d9b56aSLuis R. Rodriguez EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
33131da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
33141da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
33151da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring);
33161da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax);
33171da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
33180bc19985SStephen Suryaputra EXPORT_SYMBOL(proc_do_large_bitmap);
3319