xref: /openbmc/linux/kernel/sysctl.c (revision 32927393dc1ccd60fb2bdc05b9e8e88753761469)
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>
30455cd5abSDan Rosenberg #include <linux/printk.h>
311da177e4SLinus Torvalds #include <linux/proc_fs.h>
3272c2d582SAndrew Morgan #include <linux/security.h>
331da177e4SLinus Torvalds #include <linux/ctype.h>
34fd4b616bSSteven Rostedt #include <linux/kmemleak.h>
3562239ac2SAdrian Bunk #include <linux/fs.h>
361da177e4SLinus Torvalds #include <linux/init.h>
371da177e4SLinus Torvalds #include <linux/kernel.h>
380296b228SKay Sievers #include <linux/kobject.h>
3920380731SArnaldo Carvalho de Melo #include <linux/net.h>
401da177e4SLinus Torvalds #include <linux/sysrq.h>
411da177e4SLinus Torvalds #include <linux/highuid.h>
421da177e4SLinus Torvalds #include <linux/writeback.h>
433fff4c42SIngo Molnar #include <linux/ratelimit.h>
4476ab0f53SMel Gorman #include <linux/compaction.h>
451da177e4SLinus Torvalds #include <linux/hugetlb.h>
461da177e4SLinus Torvalds #include <linux/initrd.h>
470b77f5bfSDavid Howells #include <linux/key.h>
481da177e4SLinus Torvalds #include <linux/times.h>
491da177e4SLinus Torvalds #include <linux/limits.h>
501da177e4SLinus Torvalds #include <linux/dcache.h>
516e006701SAlexey Dobriyan #include <linux/dnotify.h>
521da177e4SLinus Torvalds #include <linux/syscalls.h>
53c748e134SAdrian Bunk #include <linux/vmstat.h>
54c255d844SPavel Machek #include <linux/nfs_fs.h>
55c255d844SPavel Machek #include <linux/acpi.h>
5610a0a8d4SJeremy Fitzhardinge #include <linux/reboot.h>
57b0fc494fSSteven Rostedt #include <linux/ftrace.h>
58cdd6c482SIngo Molnar #include <linux/perf_event.h>
59b2be84dfSMasami Hiramatsu #include <linux/kprobes.h>
60b492e95bSJens Axboe #include <linux/pipe_fs_i.h>
618e4228e1SDavid Rientjes #include <linux/oom.h>
6217f60a7dSEric Paris #include <linux/kmod.h>
6373efc039SDan Ballard #include <linux/capability.h>
6440401530SAl Viro #include <linux/binfmts.h>
65cf4aebc2SClark Williams #include <linux/sched/sysctl.h>
66f7ccbae4SIngo Molnar #include <linux/sched/coredump.h>
677984754bSKees Cook #include <linux/kexec.h>
681be7f75dSAlexei Starovoitov #include <linux/bpf.h>
69d2921684SEric W. Biederman #include <linux/mount.h>
70cefdca0aSPeter Xu #include <linux/userfaultfd_k.h>
712374c09bSChristoph Hellwig #include <linux/coredump.h>
722374c09bSChristoph Hellwig #include <linux/latencytop.h>
732374c09bSChristoph Hellwig #include <linux/pid.h>
741da177e4SLinus Torvalds 
757f2923c4SChristian Brauner #include "../lib/kstrtox.h"
767f2923c4SChristian Brauner 
777c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
781da177e4SLinus Torvalds #include <asm/processor.h>
791da177e4SLinus Torvalds 
8029cbc78bSAndi Kleen #ifdef CONFIG_X86
8129cbc78bSAndi Kleen #include <asm/nmi.h>
820741f4d2SChuck Ebbert #include <asm/stacktrace.h>
836e7c4025SIngo Molnar #include <asm/io.h>
8429cbc78bSAndi Kleen #endif
85d550bbd4SDavid Howells #ifdef CONFIG_SPARC
86d550bbd4SDavid Howells #include <asm/setup.h>
87d550bbd4SDavid Howells #endif
88c55b7c3eSDave Young #ifdef CONFIG_BSD_PROCESS_ACCT
89c55b7c3eSDave Young #include <linux/acct.h>
90c55b7c3eSDave Young #endif
914f0e056fSDave Young #ifdef CONFIG_RT_MUTEXES
924f0e056fSDave Young #include <linux/rtmutex.h>
934f0e056fSDave Young #endif
942edf5e49SDave Young #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
952edf5e49SDave Young #include <linux/lockdep.h>
962edf5e49SDave Young #endif
9715485a46SDave Young #ifdef CONFIG_CHR_DEV_SG
9815485a46SDave Young #include <scsi/sg.h>
9915485a46SDave Young #endif
100964c9dffSAlexander Popov #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
101964c9dffSAlexander Popov #include <linux/stackleak.h>
102964c9dffSAlexander Popov #endif
10358687acbSDon Zickus #ifdef CONFIG_LOCKUP_DETECTOR
104504d7cf1SDon Zickus #include <linux/nmi.h>
105504d7cf1SDon Zickus #endif
106504d7cf1SDon Zickus 
1071da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL)
1081da177e4SLinus Torvalds 
109c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and  maximum */
1102508ce18SDon Zickus #ifdef CONFIG_LOCKUP_DETECTOR
111c4f3b63fSRavikiran G Thirumalai static int sixty = 60;
112c4f3b63fSRavikiran G Thirumalai #endif
113c4f3b63fSRavikiran G Thirumalai 
114270750dbSAaron Tomlin static int __maybe_unused neg_one = -1;
115cd5f9a4cSLinus Torvalds static int __maybe_unused two = 2;
1165509a5d2SDave Hansen static int __maybe_unused four = 4;
1179002b214SWill Deacon static unsigned long zero_ul;
118fc3501d4SSven Wegener static unsigned long one_ul = 1;
11932a5ad9cSChristian Brauner static unsigned long long_max = LONG_MAX;
120c4f3b63fSRavikiran G Thirumalai static int one_hundred = 100;
121795ae7a0SJohannes Weiner static int one_thousand = 1000;
122af91322eSDave Young #ifdef CONFIG_PRINTK
123af91322eSDave Young static int ten_thousand = 10000;
124af91322eSDave Young #endif
125c5dfd78eSArnaldo Carvalho de Melo #ifdef CONFIG_PERF_EVENTS
126c5dfd78eSArnaldo Carvalho de Melo static int six_hundred_forty_kb = 640 * 1024;
127c5dfd78eSArnaldo Carvalho de Melo #endif
128c4f3b63fSRavikiran G Thirumalai 
1299e4a5bdaSAndrea Righi /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
1309e4a5bdaSAndrea Righi static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
1319e4a5bdaSAndrea Righi 
1321da177e4SLinus Torvalds /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
1331da177e4SLinus Torvalds static int maxolduid = 65535;
1341da177e4SLinus Torvalds static int minolduid;
1351da177e4SLinus Torvalds 
1361da177e4SLinus Torvalds static int ngroups_max = NGROUPS_MAX;
13773efc039SDan Ballard static const int cap_last_cap = CAP_LAST_CAP;
1381da177e4SLinus Torvalds 
139a2e51445SDmitry Vyukov /*
140a2e51445SDmitry Vyukov  * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
141a2e51445SDmitry Vyukov  * and hung_task_check_interval_secs
142a2e51445SDmitry Vyukov  */
14380df2847SLiu Hua #ifdef CONFIG_DETECT_HUNG_TASK
14480df2847SLiu Hua static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
14580df2847SLiu Hua #endif
14680df2847SLiu Hua 
147d14f1729SDave Young #ifdef CONFIG_INOTIFY_USER
148d14f1729SDave Young #include <linux/inotify.h>
149d14f1729SDave Young #endif
150b6fca725SVineet Gupta 
151d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
152f4aacea2SKees Cook 
153a19ac337SLuis R. Rodriguez /**
154a19ac337SLuis R. Rodriguez  * enum sysctl_writes_mode - supported sysctl write modes
155a19ac337SLuis R. Rodriguez  *
156a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
157a19ac337SLuis R. Rodriguez  *	to be written, and multiple writes on the same sysctl file descriptor
158a19ac337SLuis R. Rodriguez  *	will rewrite the sysctl value, regardless of file position. No warning
159a19ac337SLuis R. Rodriguez  *	is issued when the initial position is not 0.
160a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
161a19ac337SLuis R. Rodriguez  *	not 0.
162a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
163a19ac337SLuis R. Rodriguez  *	file position 0 and the value must be fully contained in the buffer
164a19ac337SLuis R. Rodriguez  *	sent to the write syscall. If dealing with strings respect the file
165a19ac337SLuis R. Rodriguez  *	position, but restrict this to the max length of the buffer, anything
16665f50f25SWeitao Hou  *	passed the max length will be ignored. Multiple writes will append
167a19ac337SLuis R. Rodriguez  *	to the buffer.
168a19ac337SLuis R. Rodriguez  *
169a19ac337SLuis R. Rodriguez  * These write modes control how current file position affects the behavior of
170a19ac337SLuis R. Rodriguez  * updating sysctl values through the proc interface on each write.
171a19ac337SLuis R. Rodriguez  */
172a19ac337SLuis R. Rodriguez enum sysctl_writes_mode {
173a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_LEGACY		= -1,
174a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_WARN		= 0,
175a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_STRICT		= 1,
176a19ac337SLuis R. Rodriguez };
177f4aacea2SKees Cook 
178a19ac337SLuis R. Rodriguez static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
179f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */
180ceb18132SLuis R. Rodriguez 
18167f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
18267f3977fSAlexandre Ghiti     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
1831da177e4SLinus Torvalds int sysctl_legacy_va_layout;
1841da177e4SLinus Torvalds #endif
1851da177e4SLinus Torvalds 
18677e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
18773c4efd2SEric Dumazet static int min_sched_granularity_ns = 100000;		/* 100 usecs */
18873c4efd2SEric Dumazet static int max_sched_granularity_ns = NSEC_PER_SEC;	/* 1 second */
18973c4efd2SEric Dumazet static int min_wakeup_granularity_ns;			/* 0 usecs */
19073c4efd2SEric Dumazet static int max_wakeup_granularity_ns = NSEC_PER_SEC;	/* 1 second */
191cbee9f88SPeter Zijlstra #ifdef CONFIG_SMP
1921983a922SChristian Ehrhardt static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
1931983a922SChristian Ehrhardt static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
194cbee9f88SPeter Zijlstra #endif /* CONFIG_SMP */
195cbee9f88SPeter Zijlstra #endif /* CONFIG_SCHED_DEBUG */
19677e54a1fSIngo Molnar 
1975e771905SMel Gorman #ifdef CONFIG_COMPACTION
1985e771905SMel Gorman static int min_extfrag_threshold;
1995e771905SMel Gorman static int max_extfrag_threshold = 1000;
2005e771905SMel Gorman #endif
2015e771905SMel Gorman 
202f461d2dcSChristoph Hellwig #endif /* CONFIG_SYSCTL */
203f461d2dcSChristoph Hellwig 
204f461d2dcSChristoph Hellwig /*
205f461d2dcSChristoph Hellwig  * /proc/sys support
206f461d2dcSChristoph Hellwig  */
207f461d2dcSChristoph Hellwig 
208f461d2dcSChristoph Hellwig #ifdef CONFIG_PROC_SYSCTL
209f461d2dcSChristoph Hellwig 
210f461d2dcSChristoph Hellwig static int _proc_do_string(char *data, int maxlen, int write,
211*32927393SChristoph Hellwig 		char *buffer, size_t *lenp, loff_t *ppos)
212f461d2dcSChristoph Hellwig {
213f461d2dcSChristoph Hellwig 	size_t len;
214*32927393SChristoph Hellwig 	char c, *p;
215f461d2dcSChristoph Hellwig 
216f461d2dcSChristoph Hellwig 	if (!data || !maxlen || !*lenp) {
217f461d2dcSChristoph Hellwig 		*lenp = 0;
218f461d2dcSChristoph Hellwig 		return 0;
219f461d2dcSChristoph Hellwig 	}
220f461d2dcSChristoph Hellwig 
221f461d2dcSChristoph Hellwig 	if (write) {
222f461d2dcSChristoph Hellwig 		if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
223f461d2dcSChristoph Hellwig 			/* Only continue writes not past the end of buffer. */
224f461d2dcSChristoph Hellwig 			len = strlen(data);
225f461d2dcSChristoph Hellwig 			if (len > maxlen - 1)
226f461d2dcSChristoph Hellwig 				len = maxlen - 1;
227f461d2dcSChristoph Hellwig 
228f461d2dcSChristoph Hellwig 			if (*ppos > len)
229f461d2dcSChristoph Hellwig 				return 0;
230f461d2dcSChristoph Hellwig 			len = *ppos;
231f461d2dcSChristoph Hellwig 		} else {
232f461d2dcSChristoph Hellwig 			/* Start writing from beginning of buffer. */
233f461d2dcSChristoph Hellwig 			len = 0;
234f461d2dcSChristoph Hellwig 		}
235f461d2dcSChristoph Hellwig 
236f461d2dcSChristoph Hellwig 		*ppos += *lenp;
237f461d2dcSChristoph Hellwig 		p = buffer;
238f461d2dcSChristoph Hellwig 		while ((p - buffer) < *lenp && len < maxlen - 1) {
239*32927393SChristoph Hellwig 			c = *(p++);
240f461d2dcSChristoph Hellwig 			if (c == 0 || c == '\n')
241f461d2dcSChristoph Hellwig 				break;
242f461d2dcSChristoph Hellwig 			data[len++] = c;
243f461d2dcSChristoph Hellwig 		}
244f461d2dcSChristoph Hellwig 		data[len] = 0;
245f461d2dcSChristoph Hellwig 	} else {
246f461d2dcSChristoph Hellwig 		len = strlen(data);
247f461d2dcSChristoph Hellwig 		if (len > maxlen)
248f461d2dcSChristoph Hellwig 			len = maxlen;
249f461d2dcSChristoph Hellwig 
250f461d2dcSChristoph Hellwig 		if (*ppos > len) {
251f461d2dcSChristoph Hellwig 			*lenp = 0;
252f461d2dcSChristoph Hellwig 			return 0;
253f461d2dcSChristoph Hellwig 		}
254f461d2dcSChristoph Hellwig 
255f461d2dcSChristoph Hellwig 		data += *ppos;
256f461d2dcSChristoph Hellwig 		len  -= *ppos;
257f461d2dcSChristoph Hellwig 
258f461d2dcSChristoph Hellwig 		if (len > *lenp)
259f461d2dcSChristoph Hellwig 			len = *lenp;
260f461d2dcSChristoph Hellwig 		if (len)
261*32927393SChristoph Hellwig 			memcpy(buffer, data, len);
262f461d2dcSChristoph Hellwig 		if (len < *lenp) {
263*32927393SChristoph Hellwig 			buffer[len] = '\n';
264f461d2dcSChristoph Hellwig 			len++;
265f461d2dcSChristoph Hellwig 		}
266f461d2dcSChristoph Hellwig 		*lenp = len;
267f461d2dcSChristoph Hellwig 		*ppos += len;
268f461d2dcSChristoph Hellwig 	}
269f461d2dcSChristoph Hellwig 	return 0;
270f461d2dcSChristoph Hellwig }
271f461d2dcSChristoph Hellwig 
272f461d2dcSChristoph Hellwig static void warn_sysctl_write(struct ctl_table *table)
273f461d2dcSChristoph Hellwig {
274f461d2dcSChristoph Hellwig 	pr_warn_once("%s wrote to %s when file position was not 0!\n"
275f461d2dcSChristoph Hellwig 		"This will not be supported in the future. To silence this\n"
276f461d2dcSChristoph Hellwig 		"warning, set kernel.sysctl_writes_strict = -1\n",
277f461d2dcSChristoph Hellwig 		current->comm, table->procname);
278f461d2dcSChristoph Hellwig }
279f461d2dcSChristoph Hellwig 
280f461d2dcSChristoph Hellwig /**
281f461d2dcSChristoph Hellwig  * proc_first_pos_non_zero_ignore - check if first position is allowed
282f461d2dcSChristoph Hellwig  * @ppos: file position
283f461d2dcSChristoph Hellwig  * @table: the sysctl table
284f461d2dcSChristoph Hellwig  *
285f461d2dcSChristoph Hellwig  * Returns true if the first position is non-zero and the sysctl_writes_strict
286f461d2dcSChristoph Hellwig  * mode indicates this is not allowed for numeric input types. String proc
287f461d2dcSChristoph Hellwig  * handlers can ignore the return value.
288f461d2dcSChristoph Hellwig  */
289f461d2dcSChristoph Hellwig static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
290f461d2dcSChristoph Hellwig 					   struct ctl_table *table)
291f461d2dcSChristoph Hellwig {
292f461d2dcSChristoph Hellwig 	if (!*ppos)
293f461d2dcSChristoph Hellwig 		return false;
294f461d2dcSChristoph Hellwig 
295f461d2dcSChristoph Hellwig 	switch (sysctl_writes_strict) {
296f461d2dcSChristoph Hellwig 	case SYSCTL_WRITES_STRICT:
297f461d2dcSChristoph Hellwig 		return true;
298f461d2dcSChristoph Hellwig 	case SYSCTL_WRITES_WARN:
299f461d2dcSChristoph Hellwig 		warn_sysctl_write(table);
300f461d2dcSChristoph Hellwig 		return false;
301f461d2dcSChristoph Hellwig 	default:
302f461d2dcSChristoph Hellwig 		return false;
303f461d2dcSChristoph Hellwig 	}
304f461d2dcSChristoph Hellwig }
305f461d2dcSChristoph Hellwig 
306f461d2dcSChristoph Hellwig /**
307f461d2dcSChristoph Hellwig  * proc_dostring - read a string sysctl
308f461d2dcSChristoph Hellwig  * @table: the sysctl table
309f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
310f461d2dcSChristoph Hellwig  * @buffer: the user buffer
311f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
312f461d2dcSChristoph Hellwig  * @ppos: file position
313f461d2dcSChristoph Hellwig  *
314f461d2dcSChristoph Hellwig  * Reads/writes a string from/to the user buffer. If the kernel
315f461d2dcSChristoph Hellwig  * buffer provided is not large enough to hold the string, the
316f461d2dcSChristoph Hellwig  * string is truncated. The copied string is %NULL-terminated.
317f461d2dcSChristoph Hellwig  * If the string is being read by the user process, it is copied
318f461d2dcSChristoph Hellwig  * and a newline '\n' is added. It is truncated if the buffer is
319f461d2dcSChristoph Hellwig  * not large enough.
320f461d2dcSChristoph Hellwig  *
321f461d2dcSChristoph Hellwig  * Returns 0 on success.
322f461d2dcSChristoph Hellwig  */
323f461d2dcSChristoph Hellwig int proc_dostring(struct ctl_table *table, int write,
324*32927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
325f461d2dcSChristoph Hellwig {
326f461d2dcSChristoph Hellwig 	if (write)
327f461d2dcSChristoph Hellwig 		proc_first_pos_non_zero_ignore(ppos, table);
328f461d2dcSChristoph Hellwig 
329*32927393SChristoph Hellwig 	return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
330*32927393SChristoph Hellwig 			ppos);
331f461d2dcSChristoph Hellwig }
332f461d2dcSChristoph Hellwig 
333f461d2dcSChristoph Hellwig static size_t proc_skip_spaces(char **buf)
334f461d2dcSChristoph Hellwig {
335f461d2dcSChristoph Hellwig 	size_t ret;
336f461d2dcSChristoph Hellwig 	char *tmp = skip_spaces(*buf);
337f461d2dcSChristoph Hellwig 	ret = tmp - *buf;
338f461d2dcSChristoph Hellwig 	*buf = tmp;
339f461d2dcSChristoph Hellwig 	return ret;
340f461d2dcSChristoph Hellwig }
341f461d2dcSChristoph Hellwig 
342f461d2dcSChristoph Hellwig static void proc_skip_char(char **buf, size_t *size, const char v)
343f461d2dcSChristoph Hellwig {
344f461d2dcSChristoph Hellwig 	while (*size) {
345f461d2dcSChristoph Hellwig 		if (**buf != v)
346f461d2dcSChristoph Hellwig 			break;
347f461d2dcSChristoph Hellwig 		(*size)--;
348f461d2dcSChristoph Hellwig 		(*buf)++;
349f461d2dcSChristoph Hellwig 	}
350f461d2dcSChristoph Hellwig }
351f461d2dcSChristoph Hellwig 
352f461d2dcSChristoph Hellwig /**
353f461d2dcSChristoph Hellwig  * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
354f461d2dcSChristoph Hellwig  *                   fail on overflow
355f461d2dcSChristoph Hellwig  *
356f461d2dcSChristoph Hellwig  * @cp: kernel buffer containing the string to parse
357f461d2dcSChristoph Hellwig  * @endp: pointer to store the trailing characters
358f461d2dcSChristoph Hellwig  * @base: the base to use
359f461d2dcSChristoph Hellwig  * @res: where the parsed integer will be stored
360f461d2dcSChristoph Hellwig  *
361f461d2dcSChristoph Hellwig  * In case of success 0 is returned and @res will contain the parsed integer,
362f461d2dcSChristoph Hellwig  * @endp will hold any trailing characters.
363f461d2dcSChristoph Hellwig  * This function will fail the parse on overflow. If there wasn't an overflow
364f461d2dcSChristoph Hellwig  * the function will defer the decision what characters count as invalid to the
365f461d2dcSChristoph Hellwig  * caller.
366f461d2dcSChristoph Hellwig  */
367f461d2dcSChristoph Hellwig static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
368f461d2dcSChristoph Hellwig 			   unsigned long *res)
369f461d2dcSChristoph Hellwig {
370f461d2dcSChristoph Hellwig 	unsigned long long result;
371f461d2dcSChristoph Hellwig 	unsigned int rv;
372f461d2dcSChristoph Hellwig 
373f461d2dcSChristoph Hellwig 	cp = _parse_integer_fixup_radix(cp, &base);
374f461d2dcSChristoph Hellwig 	rv = _parse_integer(cp, base, &result);
375f461d2dcSChristoph Hellwig 	if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
376f461d2dcSChristoph Hellwig 		return -ERANGE;
377f461d2dcSChristoph Hellwig 
378f461d2dcSChristoph Hellwig 	cp += rv;
379f461d2dcSChristoph Hellwig 
380f461d2dcSChristoph Hellwig 	if (endp)
381f461d2dcSChristoph Hellwig 		*endp = (char *)cp;
382f461d2dcSChristoph Hellwig 
383f461d2dcSChristoph Hellwig 	*res = (unsigned long)result;
384f461d2dcSChristoph Hellwig 	return 0;
385f461d2dcSChristoph Hellwig }
386f461d2dcSChristoph Hellwig 
387f461d2dcSChristoph Hellwig #define TMPBUFLEN 22
388f461d2dcSChristoph Hellwig /**
389f461d2dcSChristoph Hellwig  * proc_get_long - reads an ASCII formatted integer from a user buffer
390f461d2dcSChristoph Hellwig  *
391f461d2dcSChristoph Hellwig  * @buf: a kernel buffer
392f461d2dcSChristoph Hellwig  * @size: size of the kernel buffer
393f461d2dcSChristoph Hellwig  * @val: this is where the number will be stored
394f461d2dcSChristoph Hellwig  * @neg: set to %TRUE if number is negative
395f461d2dcSChristoph Hellwig  * @perm_tr: a vector which contains the allowed trailers
396f461d2dcSChristoph Hellwig  * @perm_tr_len: size of the perm_tr vector
397f461d2dcSChristoph Hellwig  * @tr: pointer to store the trailer character
398f461d2dcSChristoph Hellwig  *
399f461d2dcSChristoph Hellwig  * In case of success %0 is returned and @buf and @size are updated with
400f461d2dcSChristoph Hellwig  * the amount of bytes read. If @tr is non-NULL and a trailing
401f461d2dcSChristoph Hellwig  * character exists (size is non-zero after returning from this
402f461d2dcSChristoph Hellwig  * function), @tr is updated with the trailing character.
403f461d2dcSChristoph Hellwig  */
404f461d2dcSChristoph Hellwig static int proc_get_long(char **buf, size_t *size,
405f461d2dcSChristoph Hellwig 			  unsigned long *val, bool *neg,
406f461d2dcSChristoph Hellwig 			  const char *perm_tr, unsigned perm_tr_len, char *tr)
407f461d2dcSChristoph Hellwig {
408f461d2dcSChristoph Hellwig 	int len;
409f461d2dcSChristoph Hellwig 	char *p, tmp[TMPBUFLEN];
410f461d2dcSChristoph Hellwig 
411f461d2dcSChristoph Hellwig 	if (!*size)
412f461d2dcSChristoph Hellwig 		return -EINVAL;
413f461d2dcSChristoph Hellwig 
414f461d2dcSChristoph Hellwig 	len = *size;
415f461d2dcSChristoph Hellwig 	if (len > TMPBUFLEN - 1)
416f461d2dcSChristoph Hellwig 		len = TMPBUFLEN - 1;
417f461d2dcSChristoph Hellwig 
418f461d2dcSChristoph Hellwig 	memcpy(tmp, *buf, len);
419f461d2dcSChristoph Hellwig 
420f461d2dcSChristoph Hellwig 	tmp[len] = 0;
421f461d2dcSChristoph Hellwig 	p = tmp;
422f461d2dcSChristoph Hellwig 	if (*p == '-' && *size > 1) {
423f461d2dcSChristoph Hellwig 		*neg = true;
424f461d2dcSChristoph Hellwig 		p++;
425f461d2dcSChristoph Hellwig 	} else
426f461d2dcSChristoph Hellwig 		*neg = false;
427f461d2dcSChristoph Hellwig 	if (!isdigit(*p))
428f461d2dcSChristoph Hellwig 		return -EINVAL;
429f461d2dcSChristoph Hellwig 
430f461d2dcSChristoph Hellwig 	if (strtoul_lenient(p, &p, 0, val))
431f461d2dcSChristoph Hellwig 		return -EINVAL;
432f461d2dcSChristoph Hellwig 
433f461d2dcSChristoph Hellwig 	len = p - tmp;
434f461d2dcSChristoph Hellwig 
435f461d2dcSChristoph Hellwig 	/* We don't know if the next char is whitespace thus we may accept
436f461d2dcSChristoph Hellwig 	 * invalid integers (e.g. 1234...a) or two integers instead of one
437f461d2dcSChristoph Hellwig 	 * (e.g. 123...1). So lets not allow such large numbers. */
438f461d2dcSChristoph Hellwig 	if (len == TMPBUFLEN - 1)
439f461d2dcSChristoph Hellwig 		return -EINVAL;
440f461d2dcSChristoph Hellwig 
441f461d2dcSChristoph Hellwig 	if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
442f461d2dcSChristoph Hellwig 		return -EINVAL;
443f461d2dcSChristoph Hellwig 
444f461d2dcSChristoph Hellwig 	if (tr && (len < *size))
445f461d2dcSChristoph Hellwig 		*tr = *p;
446f461d2dcSChristoph Hellwig 
447f461d2dcSChristoph Hellwig 	*buf += len;
448f461d2dcSChristoph Hellwig 	*size -= len;
449f461d2dcSChristoph Hellwig 
450f461d2dcSChristoph Hellwig 	return 0;
451f461d2dcSChristoph Hellwig }
452f461d2dcSChristoph Hellwig 
453f461d2dcSChristoph Hellwig /**
454f461d2dcSChristoph Hellwig  * proc_put_long - converts an integer to a decimal ASCII formatted string
455f461d2dcSChristoph Hellwig  *
456f461d2dcSChristoph Hellwig  * @buf: the user buffer
457f461d2dcSChristoph Hellwig  * @size: the size of the user buffer
458f461d2dcSChristoph Hellwig  * @val: the integer to be converted
459f461d2dcSChristoph Hellwig  * @neg: sign of the number, %TRUE for negative
460f461d2dcSChristoph Hellwig  *
461*32927393SChristoph Hellwig  * In case of success @buf and @size are updated with the amount of bytes
462*32927393SChristoph Hellwig  * written.
463f461d2dcSChristoph Hellwig  */
464*32927393SChristoph Hellwig static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
465f461d2dcSChristoph Hellwig {
466f461d2dcSChristoph Hellwig 	int len;
467f461d2dcSChristoph Hellwig 	char tmp[TMPBUFLEN], *p = tmp;
468f461d2dcSChristoph Hellwig 
469f461d2dcSChristoph Hellwig 	sprintf(p, "%s%lu", neg ? "-" : "", val);
470f461d2dcSChristoph Hellwig 	len = strlen(tmp);
471f461d2dcSChristoph Hellwig 	if (len > *size)
472f461d2dcSChristoph Hellwig 		len = *size;
473*32927393SChristoph Hellwig 	memcpy(*buf, tmp, len);
474f461d2dcSChristoph Hellwig 	*size -= len;
475f461d2dcSChristoph Hellwig 	*buf += len;
476f461d2dcSChristoph Hellwig }
477f461d2dcSChristoph Hellwig #undef TMPBUFLEN
478f461d2dcSChristoph Hellwig 
479*32927393SChristoph Hellwig static void proc_put_char(void **buf, size_t *size, char c)
480f461d2dcSChristoph Hellwig {
481f461d2dcSChristoph Hellwig 	if (*size) {
482*32927393SChristoph Hellwig 		char **buffer = (char **)buf;
483*32927393SChristoph Hellwig 		**buffer = c;
484*32927393SChristoph Hellwig 
485*32927393SChristoph Hellwig 		(*size)--;
486*32927393SChristoph Hellwig 		(*buffer)++;
487f461d2dcSChristoph Hellwig 		*buf = *buffer;
488f461d2dcSChristoph Hellwig 	}
489f461d2dcSChristoph Hellwig }
490f461d2dcSChristoph Hellwig 
491f461d2dcSChristoph Hellwig static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
492f461d2dcSChristoph Hellwig 				 int *valp,
493f461d2dcSChristoph Hellwig 				 int write, void *data)
494f461d2dcSChristoph Hellwig {
495f461d2dcSChristoph Hellwig 	if (write) {
496f461d2dcSChristoph Hellwig 		if (*negp) {
497f461d2dcSChristoph Hellwig 			if (*lvalp > (unsigned long) INT_MAX + 1)
498f461d2dcSChristoph Hellwig 				return -EINVAL;
499f461d2dcSChristoph Hellwig 			*valp = -*lvalp;
500f461d2dcSChristoph Hellwig 		} else {
501f461d2dcSChristoph Hellwig 			if (*lvalp > (unsigned long) INT_MAX)
502f461d2dcSChristoph Hellwig 				return -EINVAL;
503f461d2dcSChristoph Hellwig 			*valp = *lvalp;
504f461d2dcSChristoph Hellwig 		}
505f461d2dcSChristoph Hellwig 	} else {
506f461d2dcSChristoph Hellwig 		int val = *valp;
507f461d2dcSChristoph Hellwig 		if (val < 0) {
508f461d2dcSChristoph Hellwig 			*negp = true;
509f461d2dcSChristoph Hellwig 			*lvalp = -(unsigned long)val;
510f461d2dcSChristoph Hellwig 		} else {
511f461d2dcSChristoph Hellwig 			*negp = false;
512f461d2dcSChristoph Hellwig 			*lvalp = (unsigned long)val;
513f461d2dcSChristoph Hellwig 		}
514f461d2dcSChristoph Hellwig 	}
515f461d2dcSChristoph Hellwig 	return 0;
516f461d2dcSChristoph Hellwig }
517f461d2dcSChristoph Hellwig 
518f461d2dcSChristoph Hellwig static int do_proc_douintvec_conv(unsigned long *lvalp,
519f461d2dcSChristoph Hellwig 				  unsigned int *valp,
520f461d2dcSChristoph Hellwig 				  int write, void *data)
521f461d2dcSChristoph Hellwig {
522f461d2dcSChristoph Hellwig 	if (write) {
523f461d2dcSChristoph Hellwig 		if (*lvalp > UINT_MAX)
524f461d2dcSChristoph Hellwig 			return -EINVAL;
525f461d2dcSChristoph Hellwig 		*valp = *lvalp;
526f461d2dcSChristoph Hellwig 	} else {
527f461d2dcSChristoph Hellwig 		unsigned int val = *valp;
528f461d2dcSChristoph Hellwig 		*lvalp = (unsigned long)val;
529f461d2dcSChristoph Hellwig 	}
530f461d2dcSChristoph Hellwig 	return 0;
531f461d2dcSChristoph Hellwig }
532f461d2dcSChristoph Hellwig 
533f461d2dcSChristoph Hellwig static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
534f461d2dcSChristoph Hellwig 
535f461d2dcSChristoph Hellwig static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
536*32927393SChristoph Hellwig 		  int write, void *buffer,
537f461d2dcSChristoph Hellwig 		  size_t *lenp, loff_t *ppos,
538f461d2dcSChristoph Hellwig 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
539f461d2dcSChristoph Hellwig 			      int write, void *data),
540f461d2dcSChristoph Hellwig 		  void *data)
541f461d2dcSChristoph Hellwig {
542f461d2dcSChristoph Hellwig 	int *i, vleft, first = 1, err = 0;
543f461d2dcSChristoph Hellwig 	size_t left;
544*32927393SChristoph Hellwig 	char *p;
545f461d2dcSChristoph Hellwig 
546f461d2dcSChristoph Hellwig 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
547f461d2dcSChristoph Hellwig 		*lenp = 0;
548f461d2dcSChristoph Hellwig 		return 0;
549f461d2dcSChristoph Hellwig 	}
550f461d2dcSChristoph Hellwig 
551f461d2dcSChristoph Hellwig 	i = (int *) tbl_data;
552f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(*i);
553f461d2dcSChristoph Hellwig 	left = *lenp;
554f461d2dcSChristoph Hellwig 
555f461d2dcSChristoph Hellwig 	if (!conv)
556f461d2dcSChristoph Hellwig 		conv = do_proc_dointvec_conv;
557f461d2dcSChristoph Hellwig 
558f461d2dcSChristoph Hellwig 	if (write) {
559f461d2dcSChristoph Hellwig 		if (proc_first_pos_non_zero_ignore(ppos, table))
560f461d2dcSChristoph Hellwig 			goto out;
561f461d2dcSChristoph Hellwig 
562f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1)
563f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
564*32927393SChristoph Hellwig 		p = buffer;
565f461d2dcSChristoph Hellwig 	}
566f461d2dcSChristoph Hellwig 
567f461d2dcSChristoph Hellwig 	for (; left && vleft--; i++, first=0) {
568f461d2dcSChristoph Hellwig 		unsigned long lval;
569f461d2dcSChristoph Hellwig 		bool neg;
570f461d2dcSChristoph Hellwig 
571f461d2dcSChristoph Hellwig 		if (write) {
572f461d2dcSChristoph Hellwig 			left -= proc_skip_spaces(&p);
573f461d2dcSChristoph Hellwig 
574f461d2dcSChristoph Hellwig 			if (!left)
575f461d2dcSChristoph Hellwig 				break;
576f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &lval, &neg,
577f461d2dcSChristoph Hellwig 					     proc_wspace_sep,
578f461d2dcSChristoph Hellwig 					     sizeof(proc_wspace_sep), NULL);
579f461d2dcSChristoph Hellwig 			if (err)
580f461d2dcSChristoph Hellwig 				break;
581f461d2dcSChristoph Hellwig 			if (conv(&neg, &lval, i, 1, data)) {
582f461d2dcSChristoph Hellwig 				err = -EINVAL;
583f461d2dcSChristoph Hellwig 				break;
584f461d2dcSChristoph Hellwig 			}
585f461d2dcSChristoph Hellwig 		} else {
586f461d2dcSChristoph Hellwig 			if (conv(&neg, &lval, i, 0, data)) {
587f461d2dcSChristoph Hellwig 				err = -EINVAL;
588f461d2dcSChristoph Hellwig 				break;
589f461d2dcSChristoph Hellwig 			}
590f461d2dcSChristoph Hellwig 			if (!first)
591*32927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '\t');
592*32927393SChristoph Hellwig 			proc_put_long(&buffer, &left, lval, neg);
593f461d2dcSChristoph Hellwig 		}
594f461d2dcSChristoph Hellwig 	}
595f461d2dcSChristoph Hellwig 
596f461d2dcSChristoph Hellwig 	if (!write && !first && left && !err)
597*32927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
598f461d2dcSChristoph Hellwig 	if (write && !err && left)
599f461d2dcSChristoph Hellwig 		left -= proc_skip_spaces(&p);
600*32927393SChristoph Hellwig 	if (write && first)
601f461d2dcSChristoph Hellwig 		return err ? : -EINVAL;
602f461d2dcSChristoph Hellwig 	*lenp -= left;
603f461d2dcSChristoph Hellwig out:
604f461d2dcSChristoph Hellwig 	*ppos += *lenp;
605f461d2dcSChristoph Hellwig 	return err;
606f461d2dcSChristoph Hellwig }
607f461d2dcSChristoph Hellwig 
608f461d2dcSChristoph Hellwig static int do_proc_dointvec(struct ctl_table *table, int write,
609*32927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos,
610f461d2dcSChristoph Hellwig 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
611f461d2dcSChristoph Hellwig 			      int write, void *data),
612f461d2dcSChristoph Hellwig 		  void *data)
613f461d2dcSChristoph Hellwig {
614f461d2dcSChristoph Hellwig 	return __do_proc_dointvec(table->data, table, write,
615f461d2dcSChristoph Hellwig 			buffer, lenp, ppos, conv, data);
616f461d2dcSChristoph Hellwig }
617f461d2dcSChristoph Hellwig 
618f461d2dcSChristoph Hellwig static int do_proc_douintvec_w(unsigned int *tbl_data,
619f461d2dcSChristoph Hellwig 			       struct ctl_table *table,
620*32927393SChristoph Hellwig 			       void *buffer,
621f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
622f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
623f461d2dcSChristoph Hellwig 					   unsigned int *valp,
624f461d2dcSChristoph Hellwig 					   int write, void *data),
625f461d2dcSChristoph Hellwig 			       void *data)
626f461d2dcSChristoph Hellwig {
627f461d2dcSChristoph Hellwig 	unsigned long lval;
628f461d2dcSChristoph Hellwig 	int err = 0;
629f461d2dcSChristoph Hellwig 	size_t left;
630f461d2dcSChristoph Hellwig 	bool neg;
631*32927393SChristoph Hellwig 	char *p = buffer;
632f461d2dcSChristoph Hellwig 
633f461d2dcSChristoph Hellwig 	left = *lenp;
634f461d2dcSChristoph Hellwig 
635f461d2dcSChristoph Hellwig 	if (proc_first_pos_non_zero_ignore(ppos, table))
636f461d2dcSChristoph Hellwig 		goto bail_early;
637f461d2dcSChristoph Hellwig 
638f461d2dcSChristoph Hellwig 	if (left > PAGE_SIZE - 1)
639f461d2dcSChristoph Hellwig 		left = PAGE_SIZE - 1;
640f461d2dcSChristoph Hellwig 
641f461d2dcSChristoph Hellwig 	left -= proc_skip_spaces(&p);
642f461d2dcSChristoph Hellwig 	if (!left) {
643f461d2dcSChristoph Hellwig 		err = -EINVAL;
644f461d2dcSChristoph Hellwig 		goto out_free;
645f461d2dcSChristoph Hellwig 	}
646f461d2dcSChristoph Hellwig 
647f461d2dcSChristoph Hellwig 	err = proc_get_long(&p, &left, &lval, &neg,
648f461d2dcSChristoph Hellwig 			     proc_wspace_sep,
649f461d2dcSChristoph Hellwig 			     sizeof(proc_wspace_sep), NULL);
650f461d2dcSChristoph Hellwig 	if (err || neg) {
651f461d2dcSChristoph Hellwig 		err = -EINVAL;
652f461d2dcSChristoph Hellwig 		goto out_free;
653f461d2dcSChristoph Hellwig 	}
654f461d2dcSChristoph Hellwig 
655f461d2dcSChristoph Hellwig 	if (conv(&lval, tbl_data, 1, data)) {
656f461d2dcSChristoph Hellwig 		err = -EINVAL;
657f461d2dcSChristoph Hellwig 		goto out_free;
658f461d2dcSChristoph Hellwig 	}
659f461d2dcSChristoph Hellwig 
660f461d2dcSChristoph Hellwig 	if (!err && left)
661f461d2dcSChristoph Hellwig 		left -= proc_skip_spaces(&p);
662f461d2dcSChristoph Hellwig 
663f461d2dcSChristoph Hellwig out_free:
664f461d2dcSChristoph Hellwig 	if (err)
665f461d2dcSChristoph Hellwig 		return -EINVAL;
666f461d2dcSChristoph Hellwig 
667f461d2dcSChristoph Hellwig 	return 0;
668f461d2dcSChristoph Hellwig 
669f461d2dcSChristoph Hellwig 	/* This is in keeping with old __do_proc_dointvec() */
670f461d2dcSChristoph Hellwig bail_early:
671f461d2dcSChristoph Hellwig 	*ppos += *lenp;
672f461d2dcSChristoph Hellwig 	return err;
673f461d2dcSChristoph Hellwig }
674f461d2dcSChristoph Hellwig 
675*32927393SChristoph Hellwig static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
676f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
677f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
678f461d2dcSChristoph Hellwig 					   unsigned int *valp,
679f461d2dcSChristoph Hellwig 					   int write, void *data),
680f461d2dcSChristoph Hellwig 			       void *data)
681f461d2dcSChristoph Hellwig {
682f461d2dcSChristoph Hellwig 	unsigned long lval;
683f461d2dcSChristoph Hellwig 	int err = 0;
684f461d2dcSChristoph Hellwig 	size_t left;
685f461d2dcSChristoph Hellwig 
686f461d2dcSChristoph Hellwig 	left = *lenp;
687f461d2dcSChristoph Hellwig 
688f461d2dcSChristoph Hellwig 	if (conv(&lval, tbl_data, 0, data)) {
689f461d2dcSChristoph Hellwig 		err = -EINVAL;
690f461d2dcSChristoph Hellwig 		goto out;
691f461d2dcSChristoph Hellwig 	}
692f461d2dcSChristoph Hellwig 
693*32927393SChristoph Hellwig 	proc_put_long(&buffer, &left, lval, false);
694*32927393SChristoph Hellwig 	if (!left)
695f461d2dcSChristoph Hellwig 		goto out;
696f461d2dcSChristoph Hellwig 
697*32927393SChristoph Hellwig 	proc_put_char(&buffer, &left, '\n');
698f461d2dcSChristoph Hellwig 
699f461d2dcSChristoph Hellwig out:
700f461d2dcSChristoph Hellwig 	*lenp -= left;
701f461d2dcSChristoph Hellwig 	*ppos += *lenp;
702f461d2dcSChristoph Hellwig 
703f461d2dcSChristoph Hellwig 	return err;
704f461d2dcSChristoph Hellwig }
705f461d2dcSChristoph Hellwig 
706f461d2dcSChristoph Hellwig static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
707*32927393SChristoph Hellwig 			       int write, void *buffer,
708f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
709f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
710f461d2dcSChristoph Hellwig 					   unsigned int *valp,
711f461d2dcSChristoph Hellwig 					   int write, void *data),
712f461d2dcSChristoph Hellwig 			       void *data)
713f461d2dcSChristoph Hellwig {
714f461d2dcSChristoph Hellwig 	unsigned int *i, vleft;
715f461d2dcSChristoph Hellwig 
716f461d2dcSChristoph Hellwig 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
717f461d2dcSChristoph Hellwig 		*lenp = 0;
718f461d2dcSChristoph Hellwig 		return 0;
719f461d2dcSChristoph Hellwig 	}
720f461d2dcSChristoph Hellwig 
721f461d2dcSChristoph Hellwig 	i = (unsigned int *) tbl_data;
722f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(*i);
723f461d2dcSChristoph Hellwig 
724f461d2dcSChristoph Hellwig 	/*
725f461d2dcSChristoph Hellwig 	 * Arrays are not supported, keep this simple. *Do not* add
726f461d2dcSChristoph Hellwig 	 * support for them.
727f461d2dcSChristoph Hellwig 	 */
728f461d2dcSChristoph Hellwig 	if (vleft != 1) {
729f461d2dcSChristoph Hellwig 		*lenp = 0;
730f461d2dcSChristoph Hellwig 		return -EINVAL;
731f461d2dcSChristoph Hellwig 	}
732f461d2dcSChristoph Hellwig 
733f461d2dcSChristoph Hellwig 	if (!conv)
734f461d2dcSChristoph Hellwig 		conv = do_proc_douintvec_conv;
735f461d2dcSChristoph Hellwig 
736f461d2dcSChristoph Hellwig 	if (write)
737f461d2dcSChristoph Hellwig 		return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
738f461d2dcSChristoph Hellwig 					   conv, data);
739f461d2dcSChristoph Hellwig 	return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
740f461d2dcSChristoph Hellwig }
741f461d2dcSChristoph Hellwig 
742f461d2dcSChristoph Hellwig static int do_proc_douintvec(struct ctl_table *table, int write,
743*32927393SChristoph Hellwig 			     void *buffer, size_t *lenp, loff_t *ppos,
744f461d2dcSChristoph Hellwig 			     int (*conv)(unsigned long *lvalp,
745f461d2dcSChristoph Hellwig 					 unsigned int *valp,
746f461d2dcSChristoph Hellwig 					 int write, void *data),
747f461d2dcSChristoph Hellwig 			     void *data)
748f461d2dcSChristoph Hellwig {
749f461d2dcSChristoph Hellwig 	return __do_proc_douintvec(table->data, table, write,
750f461d2dcSChristoph Hellwig 				   buffer, lenp, ppos, conv, data);
751f461d2dcSChristoph Hellwig }
752f461d2dcSChristoph Hellwig 
753f461d2dcSChristoph Hellwig /**
754f461d2dcSChristoph Hellwig  * proc_dointvec - read a vector of integers
755f461d2dcSChristoph Hellwig  * @table: the sysctl table
756f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
757f461d2dcSChristoph Hellwig  * @buffer: the user buffer
758f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
759f461d2dcSChristoph Hellwig  * @ppos: file position
760f461d2dcSChristoph Hellwig  *
761f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
762f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
763f461d2dcSChristoph Hellwig  *
764f461d2dcSChristoph Hellwig  * Returns 0 on success.
765f461d2dcSChristoph Hellwig  */
766*32927393SChristoph Hellwig int proc_dointvec(struct ctl_table *table, int write, void *buffer,
767*32927393SChristoph Hellwig 		  size_t *lenp, loff_t *ppos)
768f461d2dcSChristoph Hellwig {
769f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
770f461d2dcSChristoph Hellwig }
771f461d2dcSChristoph Hellwig 
772f461d2dcSChristoph Hellwig #ifdef CONFIG_COMPACTION
773f461d2dcSChristoph Hellwig static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
774*32927393SChristoph Hellwig 		int write, void *buffer, size_t *lenp, loff_t *ppos)
775f461d2dcSChristoph Hellwig {
776f461d2dcSChristoph Hellwig 	int ret, old;
777f461d2dcSChristoph Hellwig 
778f461d2dcSChristoph Hellwig 	if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
779f461d2dcSChristoph Hellwig 		return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
780f461d2dcSChristoph Hellwig 
781f461d2dcSChristoph Hellwig 	old = *(int *)table->data;
782f461d2dcSChristoph Hellwig 	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
783f461d2dcSChristoph Hellwig 	if (ret)
784f461d2dcSChristoph Hellwig 		return ret;
785f461d2dcSChristoph Hellwig 	if (old != *(int *)table->data)
786f461d2dcSChristoph Hellwig 		pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
787f461d2dcSChristoph Hellwig 			     table->procname, current->comm,
788f461d2dcSChristoph Hellwig 			     task_pid_nr(current));
789f461d2dcSChristoph Hellwig 	return ret;
790f461d2dcSChristoph Hellwig }
791f461d2dcSChristoph Hellwig #endif
792f461d2dcSChristoph Hellwig 
793f461d2dcSChristoph Hellwig /**
794f461d2dcSChristoph Hellwig  * proc_douintvec - read a vector of unsigned integers
795f461d2dcSChristoph Hellwig  * @table: the sysctl table
796f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
797f461d2dcSChristoph Hellwig  * @buffer: the user buffer
798f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
799f461d2dcSChristoph Hellwig  * @ppos: file position
800f461d2dcSChristoph Hellwig  *
801f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
802f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
803f461d2dcSChristoph Hellwig  *
804f461d2dcSChristoph Hellwig  * Returns 0 on success.
805f461d2dcSChristoph Hellwig  */
806*32927393SChristoph Hellwig int proc_douintvec(struct ctl_table *table, int write, void *buffer,
807*32927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
808f461d2dcSChristoph Hellwig {
809f461d2dcSChristoph Hellwig 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
810f461d2dcSChristoph Hellwig 				 do_proc_douintvec_conv, NULL);
811f461d2dcSChristoph Hellwig }
812f461d2dcSChristoph Hellwig 
813f461d2dcSChristoph Hellwig /*
814f461d2dcSChristoph Hellwig  * Taint values can only be increased
815f461d2dcSChristoph Hellwig  * This means we can safely use a temporary.
816f461d2dcSChristoph Hellwig  */
817f461d2dcSChristoph Hellwig static int proc_taint(struct ctl_table *table, int write,
818*32927393SChristoph Hellwig 			       void *buffer, size_t *lenp, loff_t *ppos)
819f461d2dcSChristoph Hellwig {
820f461d2dcSChristoph Hellwig 	struct ctl_table t;
821f461d2dcSChristoph Hellwig 	unsigned long tmptaint = get_taint();
822f461d2dcSChristoph Hellwig 	int err;
823f461d2dcSChristoph Hellwig 
824f461d2dcSChristoph Hellwig 	if (write && !capable(CAP_SYS_ADMIN))
825f461d2dcSChristoph Hellwig 		return -EPERM;
826f461d2dcSChristoph Hellwig 
827f461d2dcSChristoph Hellwig 	t = *table;
828f461d2dcSChristoph Hellwig 	t.data = &tmptaint;
829f461d2dcSChristoph Hellwig 	err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
830f461d2dcSChristoph Hellwig 	if (err < 0)
831f461d2dcSChristoph Hellwig 		return err;
832f461d2dcSChristoph Hellwig 
833f461d2dcSChristoph Hellwig 	if (write) {
834f461d2dcSChristoph Hellwig 		/*
835f461d2dcSChristoph Hellwig 		 * Poor man's atomic or. Not worth adding a primitive
836f461d2dcSChristoph Hellwig 		 * to everyone's atomic.h for this
837f461d2dcSChristoph Hellwig 		 */
838f461d2dcSChristoph Hellwig 		int i;
839f461d2dcSChristoph Hellwig 		for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
840f461d2dcSChristoph Hellwig 			if ((tmptaint >> i) & 1)
841f461d2dcSChristoph Hellwig 				add_taint(i, LOCKDEP_STILL_OK);
842f461d2dcSChristoph Hellwig 		}
843f461d2dcSChristoph Hellwig 	}
844f461d2dcSChristoph Hellwig 
845f461d2dcSChristoph Hellwig 	return err;
846f461d2dcSChristoph Hellwig }
847f461d2dcSChristoph Hellwig 
848f461d2dcSChristoph Hellwig #ifdef CONFIG_PRINTK
849f461d2dcSChristoph Hellwig static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
850*32927393SChristoph Hellwig 				void *buffer, size_t *lenp, loff_t *ppos)
851f461d2dcSChristoph Hellwig {
852f461d2dcSChristoph Hellwig 	if (write && !capable(CAP_SYS_ADMIN))
853f461d2dcSChristoph Hellwig 		return -EPERM;
854f461d2dcSChristoph Hellwig 
855f461d2dcSChristoph Hellwig 	return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
856f461d2dcSChristoph Hellwig }
857f461d2dcSChristoph Hellwig #endif
858f461d2dcSChristoph Hellwig 
859f461d2dcSChristoph Hellwig /**
860f461d2dcSChristoph Hellwig  * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
861f461d2dcSChristoph Hellwig  * @min: pointer to minimum allowable value
862f461d2dcSChristoph Hellwig  * @max: pointer to maximum allowable value
863f461d2dcSChristoph Hellwig  *
864f461d2dcSChristoph Hellwig  * The do_proc_dointvec_minmax_conv_param structure provides the
865f461d2dcSChristoph Hellwig  * minimum and maximum values for doing range checking for those sysctl
866f461d2dcSChristoph Hellwig  * parameters that use the proc_dointvec_minmax() handler.
867f461d2dcSChristoph Hellwig  */
868f461d2dcSChristoph Hellwig struct do_proc_dointvec_minmax_conv_param {
869f461d2dcSChristoph Hellwig 	int *min;
870f461d2dcSChristoph Hellwig 	int *max;
871f461d2dcSChristoph Hellwig };
872f461d2dcSChristoph Hellwig 
873f461d2dcSChristoph Hellwig static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
874f461d2dcSChristoph Hellwig 					int *valp,
875f461d2dcSChristoph Hellwig 					int write, void *data)
876f461d2dcSChristoph Hellwig {
877f461d2dcSChristoph Hellwig 	int tmp, ret;
878f461d2dcSChristoph Hellwig 	struct do_proc_dointvec_minmax_conv_param *param = data;
879f461d2dcSChristoph Hellwig 	/*
880f461d2dcSChristoph Hellwig 	 * If writing, first do so via a temporary local int so we can
881f461d2dcSChristoph Hellwig 	 * bounds-check it before touching *valp.
882f461d2dcSChristoph Hellwig 	 */
883f461d2dcSChristoph Hellwig 	int *ip = write ? &tmp : valp;
884f461d2dcSChristoph Hellwig 
885f461d2dcSChristoph Hellwig 	ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
886f461d2dcSChristoph Hellwig 	if (ret)
887f461d2dcSChristoph Hellwig 		return ret;
888f461d2dcSChristoph Hellwig 
889f461d2dcSChristoph Hellwig 	if (write) {
890f461d2dcSChristoph Hellwig 		if ((param->min && *param->min > tmp) ||
891f461d2dcSChristoph Hellwig 		    (param->max && *param->max < tmp))
892f461d2dcSChristoph Hellwig 			return -EINVAL;
893f461d2dcSChristoph Hellwig 		*valp = tmp;
894f461d2dcSChristoph Hellwig 	}
895f461d2dcSChristoph Hellwig 
896f461d2dcSChristoph Hellwig 	return 0;
897f461d2dcSChristoph Hellwig }
898f461d2dcSChristoph Hellwig 
899f461d2dcSChristoph Hellwig /**
900f461d2dcSChristoph Hellwig  * proc_dointvec_minmax - read a vector of integers with min/max values
901f461d2dcSChristoph Hellwig  * @table: the sysctl table
902f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
903f461d2dcSChristoph Hellwig  * @buffer: the user buffer
904f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
905f461d2dcSChristoph Hellwig  * @ppos: file position
906f461d2dcSChristoph Hellwig  *
907f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
908f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
909f461d2dcSChristoph Hellwig  *
910f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
911f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max).
912f461d2dcSChristoph Hellwig  *
913f461d2dcSChristoph Hellwig  * Returns 0 on success or -EINVAL on write when the range check fails.
914f461d2dcSChristoph Hellwig  */
915f461d2dcSChristoph Hellwig int proc_dointvec_minmax(struct ctl_table *table, int write,
916*32927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
917f461d2dcSChristoph Hellwig {
918f461d2dcSChristoph Hellwig 	struct do_proc_dointvec_minmax_conv_param param = {
919f461d2dcSChristoph Hellwig 		.min = (int *) table->extra1,
920f461d2dcSChristoph Hellwig 		.max = (int *) table->extra2,
921f461d2dcSChristoph Hellwig 	};
922f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
923f461d2dcSChristoph Hellwig 				do_proc_dointvec_minmax_conv, &param);
924f461d2dcSChristoph Hellwig }
925f461d2dcSChristoph Hellwig 
926f461d2dcSChristoph Hellwig /**
927f461d2dcSChristoph Hellwig  * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
928f461d2dcSChristoph Hellwig  * @min: pointer to minimum allowable value
929f461d2dcSChristoph Hellwig  * @max: pointer to maximum allowable value
930f461d2dcSChristoph Hellwig  *
931f461d2dcSChristoph Hellwig  * The do_proc_douintvec_minmax_conv_param structure provides the
932f461d2dcSChristoph Hellwig  * minimum and maximum values for doing range checking for those sysctl
933f461d2dcSChristoph Hellwig  * parameters that use the proc_douintvec_minmax() handler.
934f461d2dcSChristoph Hellwig  */
935f461d2dcSChristoph Hellwig struct do_proc_douintvec_minmax_conv_param {
936f461d2dcSChristoph Hellwig 	unsigned int *min;
937f461d2dcSChristoph Hellwig 	unsigned int *max;
938f461d2dcSChristoph Hellwig };
939f461d2dcSChristoph Hellwig 
940f461d2dcSChristoph Hellwig static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
941f461d2dcSChristoph Hellwig 					 unsigned int *valp,
942f461d2dcSChristoph Hellwig 					 int write, void *data)
943f461d2dcSChristoph Hellwig {
944f461d2dcSChristoph Hellwig 	int ret;
945f461d2dcSChristoph Hellwig 	unsigned int tmp;
946f461d2dcSChristoph Hellwig 	struct do_proc_douintvec_minmax_conv_param *param = data;
947f461d2dcSChristoph Hellwig 	/* write via temporary local uint for bounds-checking */
948f461d2dcSChristoph Hellwig 	unsigned int *up = write ? &tmp : valp;
949f461d2dcSChristoph Hellwig 
950f461d2dcSChristoph Hellwig 	ret = do_proc_douintvec_conv(lvalp, up, write, data);
951f461d2dcSChristoph Hellwig 	if (ret)
952f461d2dcSChristoph Hellwig 		return ret;
953f461d2dcSChristoph Hellwig 
954f461d2dcSChristoph Hellwig 	if (write) {
955f461d2dcSChristoph Hellwig 		if ((param->min && *param->min > tmp) ||
956f461d2dcSChristoph Hellwig 		    (param->max && *param->max < tmp))
957f461d2dcSChristoph Hellwig 			return -ERANGE;
958f461d2dcSChristoph Hellwig 
959f461d2dcSChristoph Hellwig 		*valp = tmp;
960f461d2dcSChristoph Hellwig 	}
961f461d2dcSChristoph Hellwig 
962f461d2dcSChristoph Hellwig 	return 0;
963f461d2dcSChristoph Hellwig }
964f461d2dcSChristoph Hellwig 
965f461d2dcSChristoph Hellwig /**
966f461d2dcSChristoph Hellwig  * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
967f461d2dcSChristoph Hellwig  * @table: the sysctl table
968f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
969f461d2dcSChristoph Hellwig  * @buffer: the user buffer
970f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
971f461d2dcSChristoph Hellwig  * @ppos: file position
972f461d2dcSChristoph Hellwig  *
973f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
974f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string. Negative
975f461d2dcSChristoph Hellwig  * strings are not allowed.
976f461d2dcSChristoph Hellwig  *
977f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
978f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max). There is a final sanity
979f461d2dcSChristoph Hellwig  * check for UINT_MAX to avoid having to support wrap around uses from
980f461d2dcSChristoph Hellwig  * userspace.
981f461d2dcSChristoph Hellwig  *
982f461d2dcSChristoph Hellwig  * Returns 0 on success or -ERANGE on write when the range check fails.
983f461d2dcSChristoph Hellwig  */
984f461d2dcSChristoph Hellwig int proc_douintvec_minmax(struct ctl_table *table, int write,
985*32927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
986f461d2dcSChristoph Hellwig {
987f461d2dcSChristoph Hellwig 	struct do_proc_douintvec_minmax_conv_param param = {
988f461d2dcSChristoph Hellwig 		.min = (unsigned int *) table->extra1,
989f461d2dcSChristoph Hellwig 		.max = (unsigned int *) table->extra2,
990f461d2dcSChristoph Hellwig 	};
991f461d2dcSChristoph Hellwig 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
992f461d2dcSChristoph Hellwig 				 do_proc_douintvec_minmax_conv, &param);
993f461d2dcSChristoph Hellwig }
994f461d2dcSChristoph Hellwig 
995f461d2dcSChristoph Hellwig static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
996f461d2dcSChristoph Hellwig 					unsigned int *valp,
997f461d2dcSChristoph Hellwig 					int write, void *data)
998f461d2dcSChristoph Hellwig {
999f461d2dcSChristoph Hellwig 	if (write) {
1000f461d2dcSChristoph Hellwig 		unsigned int val;
1001f461d2dcSChristoph Hellwig 
1002f461d2dcSChristoph Hellwig 		val = round_pipe_size(*lvalp);
1003f461d2dcSChristoph Hellwig 		if (val == 0)
1004f461d2dcSChristoph Hellwig 			return -EINVAL;
1005f461d2dcSChristoph Hellwig 
1006f461d2dcSChristoph Hellwig 		*valp = val;
1007f461d2dcSChristoph Hellwig 	} else {
1008f461d2dcSChristoph Hellwig 		unsigned int val = *valp;
1009f461d2dcSChristoph Hellwig 		*lvalp = (unsigned long) val;
1010f461d2dcSChristoph Hellwig 	}
1011f461d2dcSChristoph Hellwig 
1012f461d2dcSChristoph Hellwig 	return 0;
1013f461d2dcSChristoph Hellwig }
1014f461d2dcSChristoph Hellwig 
1015f461d2dcSChristoph Hellwig static int proc_dopipe_max_size(struct ctl_table *table, int write,
1016*32927393SChristoph Hellwig 				void *buffer, size_t *lenp, loff_t *ppos)
1017f461d2dcSChristoph Hellwig {
1018f461d2dcSChristoph Hellwig 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
1019f461d2dcSChristoph Hellwig 				 do_proc_dopipe_max_size_conv, NULL);
1020f461d2dcSChristoph Hellwig }
1021f461d2dcSChristoph Hellwig 
1022f461d2dcSChristoph Hellwig static void validate_coredump_safety(void)
1023f461d2dcSChristoph Hellwig {
1024f461d2dcSChristoph Hellwig #ifdef CONFIG_COREDUMP
1025f461d2dcSChristoph Hellwig 	if (suid_dumpable == SUID_DUMP_ROOT &&
1026f461d2dcSChristoph Hellwig 	    core_pattern[0] != '/' && core_pattern[0] != '|') {
1027f461d2dcSChristoph Hellwig 		printk(KERN_WARNING
1028f461d2dcSChristoph Hellwig "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
1029f461d2dcSChristoph Hellwig "Pipe handler or fully qualified core dump path required.\n"
1030f461d2dcSChristoph Hellwig "Set kernel.core_pattern before fs.suid_dumpable.\n"
1031f461d2dcSChristoph Hellwig 		);
1032f461d2dcSChristoph Hellwig 	}
1033f461d2dcSChristoph Hellwig #endif
1034f461d2dcSChristoph Hellwig }
1035f461d2dcSChristoph Hellwig 
1036f461d2dcSChristoph Hellwig static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
1037*32927393SChristoph Hellwig 		void *buffer, size_t *lenp, loff_t *ppos)
1038f461d2dcSChristoph Hellwig {
1039f461d2dcSChristoph Hellwig 	int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1040f461d2dcSChristoph Hellwig 	if (!error)
1041f461d2dcSChristoph Hellwig 		validate_coredump_safety();
1042f461d2dcSChristoph Hellwig 	return error;
1043f461d2dcSChristoph Hellwig }
1044f461d2dcSChristoph Hellwig 
1045f461d2dcSChristoph Hellwig #ifdef CONFIG_COREDUMP
1046f461d2dcSChristoph Hellwig static int proc_dostring_coredump(struct ctl_table *table, int write,
1047*32927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1048f461d2dcSChristoph Hellwig {
1049f461d2dcSChristoph Hellwig 	int error = proc_dostring(table, write, buffer, lenp, ppos);
1050f461d2dcSChristoph Hellwig 	if (!error)
1051f461d2dcSChristoph Hellwig 		validate_coredump_safety();
1052f461d2dcSChristoph Hellwig 	return error;
1053f461d2dcSChristoph Hellwig }
1054f461d2dcSChristoph Hellwig #endif
1055f461d2dcSChristoph Hellwig 
1056f461d2dcSChristoph Hellwig #ifdef CONFIG_MAGIC_SYSRQ
1057f461d2dcSChristoph Hellwig static int sysrq_sysctl_handler(struct ctl_table *table, int write,
1058*32927393SChristoph Hellwig 				void *buffer, size_t *lenp, loff_t *ppos)
1059f461d2dcSChristoph Hellwig {
1060f461d2dcSChristoph Hellwig 	int tmp, ret;
1061f461d2dcSChristoph Hellwig 
1062f461d2dcSChristoph Hellwig 	tmp = sysrq_mask();
1063f461d2dcSChristoph Hellwig 
1064f461d2dcSChristoph Hellwig 	ret = __do_proc_dointvec(&tmp, table, write, buffer,
1065f461d2dcSChristoph Hellwig 			       lenp, ppos, NULL, NULL);
1066f461d2dcSChristoph Hellwig 	if (ret || !write)
1067f461d2dcSChristoph Hellwig 		return ret;
1068f461d2dcSChristoph Hellwig 
1069f461d2dcSChristoph Hellwig 	if (write)
1070f461d2dcSChristoph Hellwig 		sysrq_toggle_support(tmp);
1071f461d2dcSChristoph Hellwig 
1072f461d2dcSChristoph Hellwig 	return 0;
1073f461d2dcSChristoph Hellwig }
1074f461d2dcSChristoph Hellwig #endif
1075f461d2dcSChristoph Hellwig 
1076*32927393SChristoph Hellwig static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
1077*32927393SChristoph Hellwig 		int write, void *buffer, size_t *lenp, loff_t *ppos,
1078*32927393SChristoph Hellwig 		unsigned long convmul, unsigned long convdiv)
1079f461d2dcSChristoph Hellwig {
1080f461d2dcSChristoph Hellwig 	unsigned long *i, *min, *max;
1081f461d2dcSChristoph Hellwig 	int vleft, first = 1, err = 0;
1082f461d2dcSChristoph Hellwig 	size_t left;
1083*32927393SChristoph Hellwig 	char *p;
1084f461d2dcSChristoph Hellwig 
1085f461d2dcSChristoph Hellwig 	if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1086f461d2dcSChristoph Hellwig 		*lenp = 0;
1087f461d2dcSChristoph Hellwig 		return 0;
1088f461d2dcSChristoph Hellwig 	}
1089f461d2dcSChristoph Hellwig 
1090f461d2dcSChristoph Hellwig 	i = (unsigned long *) data;
1091f461d2dcSChristoph Hellwig 	min = (unsigned long *) table->extra1;
1092f461d2dcSChristoph Hellwig 	max = (unsigned long *) table->extra2;
1093f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(unsigned long);
1094f461d2dcSChristoph Hellwig 	left = *lenp;
1095f461d2dcSChristoph Hellwig 
1096f461d2dcSChristoph Hellwig 	if (write) {
1097f461d2dcSChristoph Hellwig 		if (proc_first_pos_non_zero_ignore(ppos, table))
1098f461d2dcSChristoph Hellwig 			goto out;
1099f461d2dcSChristoph Hellwig 
1100f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1)
1101f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
1102*32927393SChristoph Hellwig 		p = buffer;
1103f461d2dcSChristoph Hellwig 	}
1104f461d2dcSChristoph Hellwig 
1105f461d2dcSChristoph Hellwig 	for (; left && vleft--; i++, first = 0) {
1106f461d2dcSChristoph Hellwig 		unsigned long val;
1107f461d2dcSChristoph Hellwig 
1108f461d2dcSChristoph Hellwig 		if (write) {
1109f461d2dcSChristoph Hellwig 			bool neg;
1110f461d2dcSChristoph Hellwig 
1111f461d2dcSChristoph Hellwig 			left -= proc_skip_spaces(&p);
1112f461d2dcSChristoph Hellwig 			if (!left)
1113f461d2dcSChristoph Hellwig 				break;
1114f461d2dcSChristoph Hellwig 
1115f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &val, &neg,
1116f461d2dcSChristoph Hellwig 					     proc_wspace_sep,
1117f461d2dcSChristoph Hellwig 					     sizeof(proc_wspace_sep), NULL);
1118f461d2dcSChristoph Hellwig 			if (err)
1119f461d2dcSChristoph Hellwig 				break;
1120f461d2dcSChristoph Hellwig 			if (neg)
1121f461d2dcSChristoph Hellwig 				continue;
1122f461d2dcSChristoph Hellwig 			val = convmul * val / convdiv;
1123f461d2dcSChristoph Hellwig 			if ((min && val < *min) || (max && val > *max)) {
1124f461d2dcSChristoph Hellwig 				err = -EINVAL;
1125f461d2dcSChristoph Hellwig 				break;
1126f461d2dcSChristoph Hellwig 			}
1127f461d2dcSChristoph Hellwig 			*i = val;
1128f461d2dcSChristoph Hellwig 		} else {
1129f461d2dcSChristoph Hellwig 			val = convdiv * (*i) / convmul;
1130*32927393SChristoph Hellwig 			if (!first)
1131*32927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '\t');
1132*32927393SChristoph Hellwig 			proc_put_long(&buffer, &left, val, false);
1133f461d2dcSChristoph Hellwig 		}
1134f461d2dcSChristoph Hellwig 	}
1135f461d2dcSChristoph Hellwig 
1136f461d2dcSChristoph Hellwig 	if (!write && !first && left && !err)
1137*32927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
1138f461d2dcSChristoph Hellwig 	if (write && !err)
1139f461d2dcSChristoph Hellwig 		left -= proc_skip_spaces(&p);
1140*32927393SChristoph Hellwig 	if (write && first)
1141f461d2dcSChristoph Hellwig 		return err ? : -EINVAL;
1142f461d2dcSChristoph Hellwig 	*lenp -= left;
1143f461d2dcSChristoph Hellwig out:
1144f461d2dcSChristoph Hellwig 	*ppos += *lenp;
1145f461d2dcSChristoph Hellwig 	return err;
1146f461d2dcSChristoph Hellwig }
1147f461d2dcSChristoph Hellwig 
1148f461d2dcSChristoph Hellwig static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
1149*32927393SChristoph Hellwig 		void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1150f461d2dcSChristoph Hellwig 		unsigned long convdiv)
1151f461d2dcSChristoph Hellwig {
1152f461d2dcSChristoph Hellwig 	return __do_proc_doulongvec_minmax(table->data, table, write,
1153f461d2dcSChristoph Hellwig 			buffer, lenp, ppos, convmul, convdiv);
1154f461d2dcSChristoph Hellwig }
1155f461d2dcSChristoph Hellwig 
1156f461d2dcSChristoph Hellwig /**
1157f461d2dcSChristoph Hellwig  * proc_doulongvec_minmax - read a vector of long integers with min/max values
1158f461d2dcSChristoph Hellwig  * @table: the sysctl table
1159f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1160f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1161f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1162f461d2dcSChristoph Hellwig  * @ppos: file position
1163f461d2dcSChristoph Hellwig  *
1164f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1165f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1166f461d2dcSChristoph Hellwig  *
1167f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
1168f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max).
1169f461d2dcSChristoph Hellwig  *
1170f461d2dcSChristoph Hellwig  * Returns 0 on success.
1171f461d2dcSChristoph Hellwig  */
1172f461d2dcSChristoph Hellwig int proc_doulongvec_minmax(struct ctl_table *table, int write,
1173*32927393SChristoph Hellwig 			   void *buffer, size_t *lenp, loff_t *ppos)
1174f461d2dcSChristoph Hellwig {
1175f461d2dcSChristoph Hellwig     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1176f461d2dcSChristoph Hellwig }
1177f461d2dcSChristoph Hellwig 
1178f461d2dcSChristoph Hellwig /**
1179f461d2dcSChristoph Hellwig  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1180f461d2dcSChristoph Hellwig  * @table: the sysctl table
1181f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1182f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1183f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1184f461d2dcSChristoph Hellwig  * @ppos: file position
1185f461d2dcSChristoph Hellwig  *
1186f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1187f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string. The values
1188f461d2dcSChristoph Hellwig  * are treated as milliseconds, and converted to jiffies when they are stored.
1189f461d2dcSChristoph Hellwig  *
1190f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
1191f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max).
1192f461d2dcSChristoph Hellwig  *
1193f461d2dcSChristoph Hellwig  * Returns 0 on success.
1194f461d2dcSChristoph Hellwig  */
1195f461d2dcSChristoph Hellwig int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1196*32927393SChristoph Hellwig 				      void *buffer, size_t *lenp, loff_t *ppos)
1197f461d2dcSChristoph Hellwig {
1198f461d2dcSChristoph Hellwig     return do_proc_doulongvec_minmax(table, write, buffer,
1199f461d2dcSChristoph Hellwig 				     lenp, ppos, HZ, 1000l);
1200f461d2dcSChristoph Hellwig }
1201f461d2dcSChristoph Hellwig 
1202f461d2dcSChristoph Hellwig 
1203f461d2dcSChristoph Hellwig static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1204f461d2dcSChristoph Hellwig 					 int *valp,
1205f461d2dcSChristoph Hellwig 					 int write, void *data)
1206f461d2dcSChristoph Hellwig {
1207f461d2dcSChristoph Hellwig 	if (write) {
1208f461d2dcSChristoph Hellwig 		if (*lvalp > INT_MAX / HZ)
1209f461d2dcSChristoph Hellwig 			return 1;
1210f461d2dcSChristoph Hellwig 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1211f461d2dcSChristoph Hellwig 	} else {
1212f461d2dcSChristoph Hellwig 		int val = *valp;
1213f461d2dcSChristoph Hellwig 		unsigned long lval;
1214f461d2dcSChristoph Hellwig 		if (val < 0) {
1215f461d2dcSChristoph Hellwig 			*negp = true;
1216f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1217f461d2dcSChristoph Hellwig 		} else {
1218f461d2dcSChristoph Hellwig 			*negp = false;
1219f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1220f461d2dcSChristoph Hellwig 		}
1221f461d2dcSChristoph Hellwig 		*lvalp = lval / HZ;
1222f461d2dcSChristoph Hellwig 	}
1223f461d2dcSChristoph Hellwig 	return 0;
1224f461d2dcSChristoph Hellwig }
1225f461d2dcSChristoph Hellwig 
1226f461d2dcSChristoph Hellwig static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1227f461d2dcSChristoph Hellwig 						int *valp,
1228f461d2dcSChristoph Hellwig 						int write, void *data)
1229f461d2dcSChristoph Hellwig {
1230f461d2dcSChristoph Hellwig 	if (write) {
1231f461d2dcSChristoph Hellwig 		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1232f461d2dcSChristoph Hellwig 			return 1;
1233f461d2dcSChristoph Hellwig 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1234f461d2dcSChristoph Hellwig 	} else {
1235f461d2dcSChristoph Hellwig 		int val = *valp;
1236f461d2dcSChristoph Hellwig 		unsigned long lval;
1237f461d2dcSChristoph Hellwig 		if (val < 0) {
1238f461d2dcSChristoph Hellwig 			*negp = true;
1239f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1240f461d2dcSChristoph Hellwig 		} else {
1241f461d2dcSChristoph Hellwig 			*negp = false;
1242f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1243f461d2dcSChristoph Hellwig 		}
1244f461d2dcSChristoph Hellwig 		*lvalp = jiffies_to_clock_t(lval);
1245f461d2dcSChristoph Hellwig 	}
1246f461d2dcSChristoph Hellwig 	return 0;
1247f461d2dcSChristoph Hellwig }
1248f461d2dcSChristoph Hellwig 
1249f461d2dcSChristoph Hellwig static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1250f461d2dcSChristoph Hellwig 					    int *valp,
1251f461d2dcSChristoph Hellwig 					    int write, void *data)
1252f461d2dcSChristoph Hellwig {
1253f461d2dcSChristoph Hellwig 	if (write) {
1254f461d2dcSChristoph Hellwig 		unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1255f461d2dcSChristoph Hellwig 
1256f461d2dcSChristoph Hellwig 		if (jif > INT_MAX)
1257f461d2dcSChristoph Hellwig 			return 1;
1258f461d2dcSChristoph Hellwig 		*valp = (int)jif;
1259f461d2dcSChristoph Hellwig 	} else {
1260f461d2dcSChristoph Hellwig 		int val = *valp;
1261f461d2dcSChristoph Hellwig 		unsigned long lval;
1262f461d2dcSChristoph Hellwig 		if (val < 0) {
1263f461d2dcSChristoph Hellwig 			*negp = true;
1264f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1265f461d2dcSChristoph Hellwig 		} else {
1266f461d2dcSChristoph Hellwig 			*negp = false;
1267f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1268f461d2dcSChristoph Hellwig 		}
1269f461d2dcSChristoph Hellwig 		*lvalp = jiffies_to_msecs(lval);
1270f461d2dcSChristoph Hellwig 	}
1271f461d2dcSChristoph Hellwig 	return 0;
1272f461d2dcSChristoph Hellwig }
1273f461d2dcSChristoph Hellwig 
1274f461d2dcSChristoph Hellwig /**
1275f461d2dcSChristoph Hellwig  * proc_dointvec_jiffies - read a vector of integers as seconds
1276f461d2dcSChristoph Hellwig  * @table: the sysctl table
1277f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1278f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1279f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1280f461d2dcSChristoph Hellwig  * @ppos: file position
1281f461d2dcSChristoph Hellwig  *
1282f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1283f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1284f461d2dcSChristoph Hellwig  * The values read are assumed to be in seconds, and are converted into
1285f461d2dcSChristoph Hellwig  * jiffies.
1286f461d2dcSChristoph Hellwig  *
1287f461d2dcSChristoph Hellwig  * Returns 0 on success.
1288f461d2dcSChristoph Hellwig  */
1289f461d2dcSChristoph Hellwig int proc_dointvec_jiffies(struct ctl_table *table, int write,
1290*32927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
1291f461d2dcSChristoph Hellwig {
1292f461d2dcSChristoph Hellwig     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1293f461d2dcSChristoph Hellwig 		    	    do_proc_dointvec_jiffies_conv,NULL);
1294f461d2dcSChristoph Hellwig }
1295f461d2dcSChristoph Hellwig 
1296f461d2dcSChristoph Hellwig /**
1297f461d2dcSChristoph Hellwig  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1298f461d2dcSChristoph Hellwig  * @table: the sysctl table
1299f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1300f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1301f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1302f461d2dcSChristoph Hellwig  * @ppos: pointer to the file position
1303f461d2dcSChristoph Hellwig  *
1304f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1305f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1306f461d2dcSChristoph Hellwig  * The values read are assumed to be in 1/USER_HZ seconds, and
1307f461d2dcSChristoph Hellwig  * are converted into jiffies.
1308f461d2dcSChristoph Hellwig  *
1309f461d2dcSChristoph Hellwig  * Returns 0 on success.
1310f461d2dcSChristoph Hellwig  */
1311f461d2dcSChristoph Hellwig int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1312*32927393SChristoph Hellwig 				 void *buffer, size_t *lenp, loff_t *ppos)
1313f461d2dcSChristoph Hellwig {
1314f461d2dcSChristoph Hellwig     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1315f461d2dcSChristoph Hellwig 		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);
1316f461d2dcSChristoph Hellwig }
1317f461d2dcSChristoph Hellwig 
1318f461d2dcSChristoph Hellwig /**
1319f461d2dcSChristoph Hellwig  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1320f461d2dcSChristoph Hellwig  * @table: the sysctl table
1321f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1322f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1323f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1324f461d2dcSChristoph Hellwig  * @ppos: file position
1325f461d2dcSChristoph Hellwig  * @ppos: the current position in the file
1326f461d2dcSChristoph Hellwig  *
1327f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1328f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1329f461d2dcSChristoph Hellwig  * The values read are assumed to be in 1/1000 seconds, and
1330f461d2dcSChristoph Hellwig  * are converted into jiffies.
1331f461d2dcSChristoph Hellwig  *
1332f461d2dcSChristoph Hellwig  * Returns 0 on success.
1333f461d2dcSChristoph Hellwig  */
1334*32927393SChristoph Hellwig int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
1335*32927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
1336f461d2dcSChristoph Hellwig {
1337f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
1338f461d2dcSChristoph Hellwig 				do_proc_dointvec_ms_jiffies_conv, NULL);
1339f461d2dcSChristoph Hellwig }
1340f461d2dcSChristoph Hellwig 
1341*32927393SChristoph Hellwig static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
1342*32927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
1343f461d2dcSChristoph Hellwig {
1344f461d2dcSChristoph Hellwig 	struct pid *new_pid;
1345f461d2dcSChristoph Hellwig 	pid_t tmp;
1346f461d2dcSChristoph Hellwig 	int r;
1347f461d2dcSChristoph Hellwig 
1348f461d2dcSChristoph Hellwig 	tmp = pid_vnr(cad_pid);
1349f461d2dcSChristoph Hellwig 
1350f461d2dcSChristoph Hellwig 	r = __do_proc_dointvec(&tmp, table, write, buffer,
1351f461d2dcSChristoph Hellwig 			       lenp, ppos, NULL, NULL);
1352f461d2dcSChristoph Hellwig 	if (r || !write)
1353f461d2dcSChristoph Hellwig 		return r;
1354f461d2dcSChristoph Hellwig 
1355f461d2dcSChristoph Hellwig 	new_pid = find_get_pid(tmp);
1356f461d2dcSChristoph Hellwig 	if (!new_pid)
1357f461d2dcSChristoph Hellwig 		return -ESRCH;
1358f461d2dcSChristoph Hellwig 
1359f461d2dcSChristoph Hellwig 	put_pid(xchg(&cad_pid, new_pid));
1360f461d2dcSChristoph Hellwig 	return 0;
1361f461d2dcSChristoph Hellwig }
1362f461d2dcSChristoph Hellwig 
1363f461d2dcSChristoph Hellwig /**
1364f461d2dcSChristoph Hellwig  * proc_do_large_bitmap - read/write from/to a large bitmap
1365f461d2dcSChristoph Hellwig  * @table: the sysctl table
1366f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1367f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1368f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1369f461d2dcSChristoph Hellwig  * @ppos: file position
1370f461d2dcSChristoph Hellwig  *
1371f461d2dcSChristoph Hellwig  * The bitmap is stored at table->data and the bitmap length (in bits)
1372f461d2dcSChristoph Hellwig  * in table->maxlen.
1373f461d2dcSChristoph Hellwig  *
1374f461d2dcSChristoph Hellwig  * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1375f461d2dcSChristoph Hellwig  * large bitmaps may be represented in a compact manner. Writing into
1376f461d2dcSChristoph Hellwig  * the file will clear the bitmap then update it with the given input.
1377f461d2dcSChristoph Hellwig  *
1378f461d2dcSChristoph Hellwig  * Returns 0 on success.
1379f461d2dcSChristoph Hellwig  */
1380f461d2dcSChristoph Hellwig int proc_do_large_bitmap(struct ctl_table *table, int write,
1381*32927393SChristoph Hellwig 			 void *buffer, size_t *lenp, loff_t *ppos)
1382f461d2dcSChristoph Hellwig {
1383f461d2dcSChristoph Hellwig 	int err = 0;
1384f461d2dcSChristoph Hellwig 	bool first = 1;
1385f461d2dcSChristoph Hellwig 	size_t left = *lenp;
1386f461d2dcSChristoph Hellwig 	unsigned long bitmap_len = table->maxlen;
1387f461d2dcSChristoph Hellwig 	unsigned long *bitmap = *(unsigned long **) table->data;
1388f461d2dcSChristoph Hellwig 	unsigned long *tmp_bitmap = NULL;
1389f461d2dcSChristoph Hellwig 	char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1390f461d2dcSChristoph Hellwig 
1391f461d2dcSChristoph Hellwig 	if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1392f461d2dcSChristoph Hellwig 		*lenp = 0;
1393f461d2dcSChristoph Hellwig 		return 0;
1394f461d2dcSChristoph Hellwig 	}
1395f461d2dcSChristoph Hellwig 
1396f461d2dcSChristoph Hellwig 	if (write) {
1397*32927393SChristoph Hellwig 		char *p = buffer;
1398f461d2dcSChristoph Hellwig 		size_t skipped = 0;
1399f461d2dcSChristoph Hellwig 
1400f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1) {
1401f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
1402f461d2dcSChristoph Hellwig 			/* How much of the buffer we'll skip this pass */
1403f461d2dcSChristoph Hellwig 			skipped = *lenp - left;
1404f461d2dcSChristoph Hellwig 		}
1405f461d2dcSChristoph Hellwig 
1406f461d2dcSChristoph Hellwig 		tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
1407*32927393SChristoph Hellwig 		if (!tmp_bitmap)
1408f461d2dcSChristoph Hellwig 			return -ENOMEM;
1409f461d2dcSChristoph Hellwig 		proc_skip_char(&p, &left, '\n');
1410f461d2dcSChristoph Hellwig 		while (!err && left) {
1411f461d2dcSChristoph Hellwig 			unsigned long val_a, val_b;
1412f461d2dcSChristoph Hellwig 			bool neg;
1413f461d2dcSChristoph Hellwig 			size_t saved_left;
1414f461d2dcSChristoph Hellwig 
1415f461d2dcSChristoph Hellwig 			/* In case we stop parsing mid-number, we can reset */
1416f461d2dcSChristoph Hellwig 			saved_left = left;
1417f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1418f461d2dcSChristoph Hellwig 					     sizeof(tr_a), &c);
1419f461d2dcSChristoph Hellwig 			/*
1420f461d2dcSChristoph Hellwig 			 * If we consumed the entirety of a truncated buffer or
1421f461d2dcSChristoph Hellwig 			 * only one char is left (may be a "-"), then stop here,
1422f461d2dcSChristoph Hellwig 			 * reset, & come back for more.
1423f461d2dcSChristoph Hellwig 			 */
1424f461d2dcSChristoph Hellwig 			if ((left <= 1) && skipped) {
1425f461d2dcSChristoph Hellwig 				left = saved_left;
1426f461d2dcSChristoph Hellwig 				break;
1427f461d2dcSChristoph Hellwig 			}
1428f461d2dcSChristoph Hellwig 
1429f461d2dcSChristoph Hellwig 			if (err)
1430f461d2dcSChristoph Hellwig 				break;
1431f461d2dcSChristoph Hellwig 			if (val_a >= bitmap_len || neg) {
1432f461d2dcSChristoph Hellwig 				err = -EINVAL;
1433f461d2dcSChristoph Hellwig 				break;
1434f461d2dcSChristoph Hellwig 			}
1435f461d2dcSChristoph Hellwig 
1436f461d2dcSChristoph Hellwig 			val_b = val_a;
1437f461d2dcSChristoph Hellwig 			if (left) {
1438f461d2dcSChristoph Hellwig 				p++;
1439f461d2dcSChristoph Hellwig 				left--;
1440f461d2dcSChristoph Hellwig 			}
1441f461d2dcSChristoph Hellwig 
1442f461d2dcSChristoph Hellwig 			if (c == '-') {
1443f461d2dcSChristoph Hellwig 				err = proc_get_long(&p, &left, &val_b,
1444f461d2dcSChristoph Hellwig 						     &neg, tr_b, sizeof(tr_b),
1445f461d2dcSChristoph Hellwig 						     &c);
1446f461d2dcSChristoph Hellwig 				/*
1447f461d2dcSChristoph Hellwig 				 * If we consumed all of a truncated buffer or
1448f461d2dcSChristoph Hellwig 				 * then stop here, reset, & come back for more.
1449f461d2dcSChristoph Hellwig 				 */
1450f461d2dcSChristoph Hellwig 				if (!left && skipped) {
1451f461d2dcSChristoph Hellwig 					left = saved_left;
1452f461d2dcSChristoph Hellwig 					break;
1453f461d2dcSChristoph Hellwig 				}
1454f461d2dcSChristoph Hellwig 
1455f461d2dcSChristoph Hellwig 				if (err)
1456f461d2dcSChristoph Hellwig 					break;
1457f461d2dcSChristoph Hellwig 				if (val_b >= bitmap_len || neg ||
1458f461d2dcSChristoph Hellwig 				    val_a > val_b) {
1459f461d2dcSChristoph Hellwig 					err = -EINVAL;
1460f461d2dcSChristoph Hellwig 					break;
1461f461d2dcSChristoph Hellwig 				}
1462f461d2dcSChristoph Hellwig 				if (left) {
1463f461d2dcSChristoph Hellwig 					p++;
1464f461d2dcSChristoph Hellwig 					left--;
1465f461d2dcSChristoph Hellwig 				}
1466f461d2dcSChristoph Hellwig 			}
1467f461d2dcSChristoph Hellwig 
1468f461d2dcSChristoph Hellwig 			bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1469f461d2dcSChristoph Hellwig 			first = 0;
1470f461d2dcSChristoph Hellwig 			proc_skip_char(&p, &left, '\n');
1471f461d2dcSChristoph Hellwig 		}
1472f461d2dcSChristoph Hellwig 		left += skipped;
1473f461d2dcSChristoph Hellwig 	} else {
1474f461d2dcSChristoph Hellwig 		unsigned long bit_a, bit_b = 0;
1475f461d2dcSChristoph Hellwig 
1476f461d2dcSChristoph Hellwig 		while (left) {
1477f461d2dcSChristoph Hellwig 			bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1478f461d2dcSChristoph Hellwig 			if (bit_a >= bitmap_len)
1479f461d2dcSChristoph Hellwig 				break;
1480f461d2dcSChristoph Hellwig 			bit_b = find_next_zero_bit(bitmap, bitmap_len,
1481f461d2dcSChristoph Hellwig 						   bit_a + 1) - 1;
1482f461d2dcSChristoph Hellwig 
1483*32927393SChristoph Hellwig 			if (!first)
1484*32927393SChristoph Hellwig 				proc_put_char(&buffer, &left, ',');
1485*32927393SChristoph Hellwig 			proc_put_long(&buffer, &left, bit_a, false);
1486f461d2dcSChristoph Hellwig 			if (bit_a != bit_b) {
1487*32927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '-');
1488*32927393SChristoph Hellwig 				proc_put_long(&buffer, &left, bit_b, false);
1489f461d2dcSChristoph Hellwig 			}
1490f461d2dcSChristoph Hellwig 
1491f461d2dcSChristoph Hellwig 			first = 0; bit_b++;
1492f461d2dcSChristoph Hellwig 		}
1493*32927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
1494f461d2dcSChristoph Hellwig 	}
1495f461d2dcSChristoph Hellwig 
1496f461d2dcSChristoph Hellwig 	if (!err) {
1497f461d2dcSChristoph Hellwig 		if (write) {
1498f461d2dcSChristoph Hellwig 			if (*ppos)
1499f461d2dcSChristoph Hellwig 				bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1500f461d2dcSChristoph Hellwig 			else
1501f461d2dcSChristoph Hellwig 				bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1502f461d2dcSChristoph Hellwig 		}
1503f461d2dcSChristoph Hellwig 		*lenp -= left;
1504f461d2dcSChristoph Hellwig 		*ppos += *lenp;
1505f461d2dcSChristoph Hellwig 	}
1506f461d2dcSChristoph Hellwig 
1507f461d2dcSChristoph Hellwig 	bitmap_free(tmp_bitmap);
1508f461d2dcSChristoph Hellwig 	return err;
1509f461d2dcSChristoph Hellwig }
1510f461d2dcSChristoph Hellwig 
1511f461d2dcSChristoph Hellwig #else /* CONFIG_PROC_SYSCTL */
1512f461d2dcSChristoph Hellwig 
1513f461d2dcSChristoph Hellwig int proc_dostring(struct ctl_table *table, int write,
1514*32927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1515f461d2dcSChristoph Hellwig {
1516f461d2dcSChristoph Hellwig 	return -ENOSYS;
1517f461d2dcSChristoph Hellwig }
1518f461d2dcSChristoph Hellwig 
1519f461d2dcSChristoph Hellwig int proc_dointvec(struct ctl_table *table, int write,
1520*32927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1521f461d2dcSChristoph Hellwig {
1522f461d2dcSChristoph Hellwig 	return -ENOSYS;
1523f461d2dcSChristoph Hellwig }
1524f461d2dcSChristoph Hellwig 
1525f461d2dcSChristoph Hellwig int proc_douintvec(struct ctl_table *table, int write,
1526*32927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1527f461d2dcSChristoph Hellwig {
1528f461d2dcSChristoph Hellwig 	return -ENOSYS;
1529f461d2dcSChristoph Hellwig }
1530f461d2dcSChristoph Hellwig 
1531f461d2dcSChristoph Hellwig int proc_dointvec_minmax(struct ctl_table *table, int write,
1532*32927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1533f461d2dcSChristoph Hellwig {
1534f461d2dcSChristoph Hellwig 	return -ENOSYS;
1535f461d2dcSChristoph Hellwig }
1536f461d2dcSChristoph Hellwig 
1537f461d2dcSChristoph Hellwig int proc_douintvec_minmax(struct ctl_table *table, int write,
1538*32927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
1539f461d2dcSChristoph Hellwig {
1540f461d2dcSChristoph Hellwig 	return -ENOSYS;
1541f461d2dcSChristoph Hellwig }
1542f461d2dcSChristoph Hellwig 
1543f461d2dcSChristoph Hellwig int proc_dointvec_jiffies(struct ctl_table *table, int write,
1544*32927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1545f461d2dcSChristoph Hellwig {
1546f461d2dcSChristoph Hellwig 	return -ENOSYS;
1547f461d2dcSChristoph Hellwig }
1548f461d2dcSChristoph Hellwig 
1549f461d2dcSChristoph Hellwig int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1550*32927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1551f461d2dcSChristoph Hellwig {
1552f461d2dcSChristoph Hellwig 	return -ENOSYS;
1553f461d2dcSChristoph Hellwig }
1554f461d2dcSChristoph Hellwig 
1555f461d2dcSChristoph Hellwig int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1556*32927393SChristoph Hellwig 			     void *buffer, size_t *lenp, loff_t *ppos)
1557f461d2dcSChristoph Hellwig {
1558f461d2dcSChristoph Hellwig 	return -ENOSYS;
1559f461d2dcSChristoph Hellwig }
1560f461d2dcSChristoph Hellwig 
1561f461d2dcSChristoph Hellwig int proc_doulongvec_minmax(struct ctl_table *table, int write,
1562*32927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1563f461d2dcSChristoph Hellwig {
1564f461d2dcSChristoph Hellwig 	return -ENOSYS;
1565f461d2dcSChristoph Hellwig }
1566f461d2dcSChristoph Hellwig 
1567f461d2dcSChristoph Hellwig int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1568*32927393SChristoph Hellwig 				      void *buffer, size_t *lenp, loff_t *ppos)
1569f461d2dcSChristoph Hellwig {
1570f461d2dcSChristoph Hellwig 	return -ENOSYS;
1571f461d2dcSChristoph Hellwig }
1572f461d2dcSChristoph Hellwig 
1573f461d2dcSChristoph Hellwig int proc_do_large_bitmap(struct ctl_table *table, int write,
1574*32927393SChristoph Hellwig 			 void *buffer, size_t *lenp, loff_t *ppos)
1575f461d2dcSChristoph Hellwig {
1576f461d2dcSChristoph Hellwig 	return -ENOSYS;
1577f461d2dcSChristoph Hellwig }
1578f461d2dcSChristoph Hellwig 
1579f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */
1580f461d2dcSChristoph Hellwig 
1581f461d2dcSChristoph Hellwig #if defined(CONFIG_SYSCTL)
1582f461d2dcSChristoph Hellwig int proc_do_static_key(struct ctl_table *table, int write,
1583*32927393SChristoph Hellwig 		       void *buffer, size_t *lenp, loff_t *ppos)
1584f461d2dcSChristoph Hellwig {
1585f461d2dcSChristoph Hellwig 	struct static_key *key = (struct static_key *)table->data;
1586f461d2dcSChristoph Hellwig 	static DEFINE_MUTEX(static_key_mutex);
1587f461d2dcSChristoph Hellwig 	int val, ret;
1588f461d2dcSChristoph Hellwig 	struct ctl_table tmp = {
1589f461d2dcSChristoph Hellwig 		.data   = &val,
1590f461d2dcSChristoph Hellwig 		.maxlen = sizeof(val),
1591f461d2dcSChristoph Hellwig 		.mode   = table->mode,
1592f461d2dcSChristoph Hellwig 		.extra1 = SYSCTL_ZERO,
1593f461d2dcSChristoph Hellwig 		.extra2 = SYSCTL_ONE,
1594f461d2dcSChristoph Hellwig 	};
1595f461d2dcSChristoph Hellwig 
1596f461d2dcSChristoph Hellwig 	if (write && !capable(CAP_SYS_ADMIN))
1597f461d2dcSChristoph Hellwig 		return -EPERM;
1598f461d2dcSChristoph Hellwig 
1599f461d2dcSChristoph Hellwig 	mutex_lock(&static_key_mutex);
1600f461d2dcSChristoph Hellwig 	val = static_key_enabled(key);
1601f461d2dcSChristoph Hellwig 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1602f461d2dcSChristoph Hellwig 	if (write && !ret) {
1603f461d2dcSChristoph Hellwig 		if (val)
1604f461d2dcSChristoph Hellwig 			static_key_enable(key);
1605f461d2dcSChristoph Hellwig 		else
1606f461d2dcSChristoph Hellwig 			static_key_disable(key);
1607f461d2dcSChristoph Hellwig 	}
1608f461d2dcSChristoph Hellwig 	mutex_unlock(&static_key_mutex);
1609f461d2dcSChristoph Hellwig 	return ret;
1610f461d2dcSChristoph Hellwig }
1611f461d2dcSChristoph Hellwig 
1612d8217f07SEric W. Biederman static struct ctl_table kern_table[] = {
16132bba22c5SMike Galbraith 	{
16142bba22c5SMike Galbraith 		.procname	= "sched_child_runs_first",
16152bba22c5SMike Galbraith 		.data		= &sysctl_sched_child_runs_first,
16162bba22c5SMike Galbraith 		.maxlen		= sizeof(unsigned int),
16172bba22c5SMike Galbraith 		.mode		= 0644,
16186d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
16192bba22c5SMike Galbraith 	},
162077e54a1fSIngo Molnar #ifdef CONFIG_SCHED_DEBUG
162177e54a1fSIngo Molnar 	{
1622b2be5e96SPeter Zijlstra 		.procname	= "sched_min_granularity_ns",
1623b2be5e96SPeter Zijlstra 		.data		= &sysctl_sched_min_granularity,
162477e54a1fSIngo Molnar 		.maxlen		= sizeof(unsigned int),
162577e54a1fSIngo Molnar 		.mode		= 0644,
1626702a7c76SLinus Torvalds 		.proc_handler	= sched_proc_update_handler,
1627b2be5e96SPeter Zijlstra 		.extra1		= &min_sched_granularity_ns,
1628b2be5e96SPeter Zijlstra 		.extra2		= &max_sched_granularity_ns,
162977e54a1fSIngo Molnar 	},
163077e54a1fSIngo Molnar 	{
163121805085SPeter Zijlstra 		.procname	= "sched_latency_ns",
163221805085SPeter Zijlstra 		.data		= &sysctl_sched_latency,
163321805085SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
163421805085SPeter Zijlstra 		.mode		= 0644,
1635702a7c76SLinus Torvalds 		.proc_handler	= sched_proc_update_handler,
163621805085SPeter Zijlstra 		.extra1		= &min_sched_granularity_ns,
163721805085SPeter Zijlstra 		.extra2		= &max_sched_granularity_ns,
163821805085SPeter Zijlstra 	},
163921805085SPeter Zijlstra 	{
164077e54a1fSIngo Molnar 		.procname	= "sched_wakeup_granularity_ns",
164177e54a1fSIngo Molnar 		.data		= &sysctl_sched_wakeup_granularity,
164277e54a1fSIngo Molnar 		.maxlen		= sizeof(unsigned int),
164377e54a1fSIngo Molnar 		.mode		= 0644,
1644702a7c76SLinus Torvalds 		.proc_handler	= sched_proc_update_handler,
164577e54a1fSIngo Molnar 		.extra1		= &min_wakeup_granularity_ns,
164677e54a1fSIngo Molnar 		.extra2		= &max_wakeup_granularity_ns,
164777e54a1fSIngo Molnar 	},
1648cbee9f88SPeter Zijlstra #ifdef CONFIG_SMP
164977e54a1fSIngo Molnar 	{
16501983a922SChristian Ehrhardt 		.procname	= "sched_tunable_scaling",
16511983a922SChristian Ehrhardt 		.data		= &sysctl_sched_tunable_scaling,
16521983a922SChristian Ehrhardt 		.maxlen		= sizeof(enum sched_tunable_scaling),
16531983a922SChristian Ehrhardt 		.mode		= 0644,
1654702a7c76SLinus Torvalds 		.proc_handler	= sched_proc_update_handler,
16551983a922SChristian Ehrhardt 		.extra1		= &min_sched_tunable_scaling,
16561983a922SChristian Ehrhardt 		.extra2		= &max_sched_tunable_scaling,
16572398f2c6SPeter Zijlstra 	},
16582398f2c6SPeter Zijlstra 	{
1659d00535dbSNamhyung Kim 		.procname	= "sched_migration_cost_ns",
1660da84d961SIngo Molnar 		.data		= &sysctl_sched_migration_cost,
1661da84d961SIngo Molnar 		.maxlen		= sizeof(unsigned int),
1662da84d961SIngo Molnar 		.mode		= 0644,
16636d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1664da84d961SIngo Molnar 	},
1665b82d9fddSPeter Zijlstra 	{
1666b82d9fddSPeter Zijlstra 		.procname	= "sched_nr_migrate",
1667b82d9fddSPeter Zijlstra 		.data		= &sysctl_sched_nr_migrate,
1668b82d9fddSPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
1669fa85ae24SPeter Zijlstra 		.mode		= 0644,
16706d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1671fa85ae24SPeter Zijlstra 	},
1672cb251765SMel Gorman #ifdef CONFIG_SCHEDSTATS
1673cb251765SMel Gorman 	{
1674cb251765SMel Gorman 		.procname	= "sched_schedstats",
1675cb251765SMel Gorman 		.data		= NULL,
1676cb251765SMel Gorman 		.maxlen		= sizeof(unsigned int),
1677cb251765SMel Gorman 		.mode		= 0644,
1678cb251765SMel Gorman 		.proc_handler	= sysctl_schedstats,
1679eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
1680eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
1681cb251765SMel Gorman 	},
1682cb251765SMel Gorman #endif /* CONFIG_SCHEDSTATS */
1683cbee9f88SPeter Zijlstra #endif /* CONFIG_SMP */
1684cbee9f88SPeter Zijlstra #ifdef CONFIG_NUMA_BALANCING
1685cbee9f88SPeter Zijlstra 	{
16864b96a29bSPeter Zijlstra 		.procname	= "numa_balancing_scan_delay_ms",
16874b96a29bSPeter Zijlstra 		.data		= &sysctl_numa_balancing_scan_delay,
16884b96a29bSPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
16894b96a29bSPeter Zijlstra 		.mode		= 0644,
16904b96a29bSPeter Zijlstra 		.proc_handler	= proc_dointvec,
16914b96a29bSPeter Zijlstra 	},
16924b96a29bSPeter Zijlstra 	{
1693cbee9f88SPeter Zijlstra 		.procname	= "numa_balancing_scan_period_min_ms",
1694cbee9f88SPeter Zijlstra 		.data		= &sysctl_numa_balancing_scan_period_min,
1695cbee9f88SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
1696cbee9f88SPeter Zijlstra 		.mode		= 0644,
1697cbee9f88SPeter Zijlstra 		.proc_handler	= proc_dointvec,
1698cbee9f88SPeter Zijlstra 	},
1699cbee9f88SPeter Zijlstra 	{
1700cbee9f88SPeter Zijlstra 		.procname	= "numa_balancing_scan_period_max_ms",
1701cbee9f88SPeter Zijlstra 		.data		= &sysctl_numa_balancing_scan_period_max,
1702cbee9f88SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
1703cbee9f88SPeter Zijlstra 		.mode		= 0644,
1704cbee9f88SPeter Zijlstra 		.proc_handler	= proc_dointvec,
1705cbee9f88SPeter Zijlstra 	},
17066e5fb223SPeter Zijlstra 	{
17076e5fb223SPeter Zijlstra 		.procname	= "numa_balancing_scan_size_mb",
17086e5fb223SPeter Zijlstra 		.data		= &sysctl_numa_balancing_scan_size,
17096e5fb223SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
17106e5fb223SPeter Zijlstra 		.mode		= 0644,
171164192658SKirill Tkhai 		.proc_handler	= proc_dointvec_minmax,
1712eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
17136e5fb223SPeter Zijlstra 	},
17143a7053b3SMel Gorman 	{
171554a43d54SAndi Kleen 		.procname	= "numa_balancing",
171654a43d54SAndi Kleen 		.data		= NULL, /* filled in by handler */
171754a43d54SAndi Kleen 		.maxlen		= sizeof(unsigned int),
171854a43d54SAndi Kleen 		.mode		= 0644,
171954a43d54SAndi Kleen 		.proc_handler	= sysctl_numa_balancing,
1720eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
1721eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
172254a43d54SAndi Kleen 	},
1723cbee9f88SPeter Zijlstra #endif /* CONFIG_NUMA_BALANCING */
1724cbee9f88SPeter Zijlstra #endif /* CONFIG_SCHED_DEBUG */
17251799e35dSIngo Molnar 	{
17269f0c1e56SPeter Zijlstra 		.procname	= "sched_rt_period_us",
17279f0c1e56SPeter Zijlstra 		.data		= &sysctl_sched_rt_period,
17289f0c1e56SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
17299f0c1e56SPeter Zijlstra 		.mode		= 0644,
17306d456111SEric W. Biederman 		.proc_handler	= sched_rt_handler,
17319f0c1e56SPeter Zijlstra 	},
17329f0c1e56SPeter Zijlstra 	{
17339f0c1e56SPeter Zijlstra 		.procname	= "sched_rt_runtime_us",
17349f0c1e56SPeter Zijlstra 		.data		= &sysctl_sched_rt_runtime,
17359f0c1e56SPeter Zijlstra 		.maxlen		= sizeof(int),
17369f0c1e56SPeter Zijlstra 		.mode		= 0644,
17376d456111SEric W. Biederman 		.proc_handler	= sched_rt_handler,
17389f0c1e56SPeter Zijlstra 	},
1739ce0dbbbbSClark Williams 	{
1740ce0dbbbbSClark Williams 		.procname	= "sched_rr_timeslice_ms",
1741975e155eSShile Zhang 		.data		= &sysctl_sched_rr_timeslice,
1742ce0dbbbbSClark Williams 		.maxlen		= sizeof(int),
1743ce0dbbbbSClark Williams 		.mode		= 0644,
1744ce0dbbbbSClark Williams 		.proc_handler	= sched_rr_handler,
1745ce0dbbbbSClark Williams 	},
1746e8f14172SPatrick Bellasi #ifdef CONFIG_UCLAMP_TASK
1747e8f14172SPatrick Bellasi 	{
1748e8f14172SPatrick Bellasi 		.procname	= "sched_util_clamp_min",
1749e8f14172SPatrick Bellasi 		.data		= &sysctl_sched_uclamp_util_min,
1750e8f14172SPatrick Bellasi 		.maxlen		= sizeof(unsigned int),
1751e8f14172SPatrick Bellasi 		.mode		= 0644,
1752e8f14172SPatrick Bellasi 		.proc_handler	= sysctl_sched_uclamp_handler,
1753e8f14172SPatrick Bellasi 	},
1754e8f14172SPatrick Bellasi 	{
1755e8f14172SPatrick Bellasi 		.procname	= "sched_util_clamp_max",
1756e8f14172SPatrick Bellasi 		.data		= &sysctl_sched_uclamp_util_max,
1757e8f14172SPatrick Bellasi 		.maxlen		= sizeof(unsigned int),
1758e8f14172SPatrick Bellasi 		.mode		= 0644,
1759e8f14172SPatrick Bellasi 		.proc_handler	= sysctl_sched_uclamp_handler,
1760e8f14172SPatrick Bellasi 	},
1761e8f14172SPatrick Bellasi #endif
17625091faa4SMike Galbraith #ifdef CONFIG_SCHED_AUTOGROUP
17635091faa4SMike Galbraith 	{
17645091faa4SMike Galbraith 		.procname	= "sched_autogroup_enabled",
17655091faa4SMike Galbraith 		.data		= &sysctl_sched_autogroup_enabled,
17665091faa4SMike Galbraith 		.maxlen		= sizeof(unsigned int),
17675091faa4SMike Galbraith 		.mode		= 0644,
17681747b21fSYong Zhang 		.proc_handler	= proc_dointvec_minmax,
1769eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
1770eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
17715091faa4SMike Galbraith 	},
17725091faa4SMike Galbraith #endif
1773ec12cb7fSPaul Turner #ifdef CONFIG_CFS_BANDWIDTH
1774ec12cb7fSPaul Turner 	{
1775ec12cb7fSPaul Turner 		.procname	= "sched_cfs_bandwidth_slice_us",
1776ec12cb7fSPaul Turner 		.data		= &sysctl_sched_cfs_bandwidth_slice,
1777ec12cb7fSPaul Turner 		.maxlen		= sizeof(unsigned int),
1778ec12cb7fSPaul Turner 		.mode		= 0644,
1779ec12cb7fSPaul Turner 		.proc_handler	= proc_dointvec_minmax,
1780eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
1781ec12cb7fSPaul Turner 	},
1782ec12cb7fSPaul Turner #endif
17838d5d0cfbSQuentin Perret #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
17848d5d0cfbSQuentin Perret 	{
17858d5d0cfbSQuentin Perret 		.procname	= "sched_energy_aware",
17868d5d0cfbSQuentin Perret 		.data		= &sysctl_sched_energy_aware,
17878d5d0cfbSQuentin Perret 		.maxlen		= sizeof(unsigned int),
17888d5d0cfbSQuentin Perret 		.mode		= 0644,
17898d5d0cfbSQuentin Perret 		.proc_handler	= sched_energy_aware_handler,
1790eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
1791eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
17928d5d0cfbSQuentin Perret 	},
17938d5d0cfbSQuentin Perret #endif
1794f20786ffSPeter Zijlstra #ifdef CONFIG_PROVE_LOCKING
1795f20786ffSPeter Zijlstra 	{
1796f20786ffSPeter Zijlstra 		.procname	= "prove_locking",
1797f20786ffSPeter Zijlstra 		.data		= &prove_locking,
1798f20786ffSPeter Zijlstra 		.maxlen		= sizeof(int),
1799f20786ffSPeter Zijlstra 		.mode		= 0644,
18006d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1801f20786ffSPeter Zijlstra 	},
1802f20786ffSPeter Zijlstra #endif
1803f20786ffSPeter Zijlstra #ifdef CONFIG_LOCK_STAT
1804f20786ffSPeter Zijlstra 	{
1805f20786ffSPeter Zijlstra 		.procname	= "lock_stat",
1806f20786ffSPeter Zijlstra 		.data		= &lock_stat,
1807f20786ffSPeter Zijlstra 		.maxlen		= sizeof(int),
1808f20786ffSPeter Zijlstra 		.mode		= 0644,
18096d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1810f20786ffSPeter Zijlstra 	},
1811f20786ffSPeter Zijlstra #endif
181277e54a1fSIngo Molnar 	{
18131da177e4SLinus Torvalds 		.procname	= "panic",
18141da177e4SLinus Torvalds 		.data		= &panic_timeout,
18151da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
18161da177e4SLinus Torvalds 		.mode		= 0644,
18176d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18181da177e4SLinus Torvalds 	},
1819046d662fSAlex Kelly #ifdef CONFIG_COREDUMP
18201da177e4SLinus Torvalds 	{
18211da177e4SLinus Torvalds 		.procname	= "core_uses_pid",
18221da177e4SLinus Torvalds 		.data		= &core_uses_pid,
18231da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
18241da177e4SLinus Torvalds 		.mode		= 0644,
18256d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18261da177e4SLinus Torvalds 	},
18271da177e4SLinus Torvalds 	{
18281da177e4SLinus Torvalds 		.procname	= "core_pattern",
18291da177e4SLinus Torvalds 		.data		= core_pattern,
183071ce92f3SDan Aloni 		.maxlen		= CORENAME_MAX_SIZE,
18311da177e4SLinus Torvalds 		.mode		= 0644,
183254b50199SKees Cook 		.proc_handler	= proc_dostring_coredump,
18331da177e4SLinus Torvalds 	},
1834a293980cSNeil Horman 	{
1835a293980cSNeil Horman 		.procname	= "core_pipe_limit",
1836a293980cSNeil Horman 		.data		= &core_pipe_limit,
1837a293980cSNeil Horman 		.maxlen		= sizeof(unsigned int),
1838a293980cSNeil Horman 		.mode		= 0644,
18396d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1840a293980cSNeil Horman 	},
1841046d662fSAlex Kelly #endif
184234f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL
18431da177e4SLinus Torvalds 	{
18441da177e4SLinus Torvalds 		.procname	= "tainted",
184525ddbb18SAndi Kleen 		.maxlen 	= sizeof(long),
184634f5a398STheodore Ts'o 		.mode		= 0644,
18476d456111SEric W. Biederman 		.proc_handler	= proc_taint,
18481da177e4SLinus Torvalds 	},
1849f4aacea2SKees Cook 	{
1850f4aacea2SKees Cook 		.procname	= "sysctl_writes_strict",
1851f4aacea2SKees Cook 		.data		= &sysctl_writes_strict,
1852f4aacea2SKees Cook 		.maxlen		= sizeof(int),
1853f4aacea2SKees Cook 		.mode		= 0644,
1854f4aacea2SKees Cook 		.proc_handler	= proc_dointvec_minmax,
1855f4aacea2SKees Cook 		.extra1		= &neg_one,
1856eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
1857f4aacea2SKees Cook 	},
185834f5a398STheodore Ts'o #endif
18599745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP
18609745512cSArjan van de Ven 	{
18619745512cSArjan van de Ven 		.procname	= "latencytop",
18629745512cSArjan van de Ven 		.data		= &latencytop_enabled,
18639745512cSArjan van de Ven 		.maxlen		= sizeof(int),
18649745512cSArjan van de Ven 		.mode		= 0644,
1865cb251765SMel Gorman 		.proc_handler	= sysctl_latencytop,
18669745512cSArjan van de Ven 	},
18679745512cSArjan van de Ven #endif
18681da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD
18691da177e4SLinus Torvalds 	{
18701da177e4SLinus Torvalds 		.procname	= "real-root-dev",
18711da177e4SLinus Torvalds 		.data		= &real_root_dev,
18721da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
18731da177e4SLinus Torvalds 		.mode		= 0644,
18746d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18751da177e4SLinus Torvalds 	},
18761da177e4SLinus Torvalds #endif
187745807a1dSIngo Molnar 	{
187845807a1dSIngo Molnar 		.procname	= "print-fatal-signals",
187945807a1dSIngo Molnar 		.data		= &print_fatal_signals,
188045807a1dSIngo Molnar 		.maxlen		= sizeof(int),
188145807a1dSIngo Molnar 		.mode		= 0644,
18826d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
188345807a1dSIngo Molnar 	},
188472c57ed5SDavid S. Miller #ifdef CONFIG_SPARC
18851da177e4SLinus Torvalds 	{
18861da177e4SLinus Torvalds 		.procname	= "reboot-cmd",
18871da177e4SLinus Torvalds 		.data		= reboot_command,
18881da177e4SLinus Torvalds 		.maxlen		= 256,
18891da177e4SLinus Torvalds 		.mode		= 0644,
18906d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
18911da177e4SLinus Torvalds 	},
18921da177e4SLinus Torvalds 	{
18931da177e4SLinus Torvalds 		.procname	= "stop-a",
18941da177e4SLinus Torvalds 		.data		= &stop_a_enabled,
18951da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
18961da177e4SLinus Torvalds 		.mode		= 0644,
18976d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18981da177e4SLinus Torvalds 	},
18991da177e4SLinus Torvalds 	{
19001da177e4SLinus Torvalds 		.procname	= "scons-poweroff",
19011da177e4SLinus Torvalds 		.data		= &scons_pwroff,
19021da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
19031da177e4SLinus Torvalds 		.mode		= 0644,
19046d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19051da177e4SLinus Torvalds 	},
19061da177e4SLinus Torvalds #endif
19070871420fSDavid S. Miller #ifdef CONFIG_SPARC64
19080871420fSDavid S. Miller 	{
19090871420fSDavid S. Miller 		.procname	= "tsb-ratio",
19100871420fSDavid S. Miller 		.data		= &sysctl_tsb_ratio,
19110871420fSDavid S. Miller 		.maxlen		= sizeof (int),
19120871420fSDavid S. Miller 		.mode		= 0644,
19136d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19140871420fSDavid S. Miller 	},
19150871420fSDavid S. Miller #endif
1916b67114dbSHelge Deller #ifdef CONFIG_PARISC
19171da177e4SLinus Torvalds 	{
19181da177e4SLinus Torvalds 		.procname	= "soft-power",
19191da177e4SLinus Torvalds 		.data		= &pwrsw_enabled,
19201da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
19211da177e4SLinus Torvalds 		.mode		= 0644,
19226d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19231da177e4SLinus Torvalds 	},
1924bf14e3b9SVineet Gupta #endif
1925bf14e3b9SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
19261da177e4SLinus Torvalds 	{
19271da177e4SLinus Torvalds 		.procname	= "unaligned-trap",
19281da177e4SLinus Torvalds 		.data		= &unaligned_enabled,
19291da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
19301da177e4SLinus Torvalds 		.mode		= 0644,
19316d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19321da177e4SLinus Torvalds 	},
19331da177e4SLinus Torvalds #endif
19341da177e4SLinus Torvalds 	{
19351da177e4SLinus Torvalds 		.procname	= "ctrl-alt-del",
19361da177e4SLinus Torvalds 		.data		= &C_A_D,
19371da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
19381da177e4SLinus Torvalds 		.mode		= 0644,
19396d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19401da177e4SLinus Torvalds 	},
1941606576ceSSteven Rostedt #ifdef CONFIG_FUNCTION_TRACER
1942b0fc494fSSteven Rostedt 	{
1943b0fc494fSSteven Rostedt 		.procname	= "ftrace_enabled",
1944b0fc494fSSteven Rostedt 		.data		= &ftrace_enabled,
1945b0fc494fSSteven Rostedt 		.maxlen		= sizeof(int),
1946b0fc494fSSteven Rostedt 		.mode		= 0644,
19476d456111SEric W. Biederman 		.proc_handler	= ftrace_enable_sysctl,
1948b0fc494fSSteven Rostedt 	},
1949b0fc494fSSteven Rostedt #endif
1950f38f1d2aSSteven Rostedt #ifdef CONFIG_STACK_TRACER
1951f38f1d2aSSteven Rostedt 	{
1952f38f1d2aSSteven Rostedt 		.procname	= "stack_tracer_enabled",
1953f38f1d2aSSteven Rostedt 		.data		= &stack_tracer_enabled,
1954f38f1d2aSSteven Rostedt 		.maxlen		= sizeof(int),
1955f38f1d2aSSteven Rostedt 		.mode		= 0644,
19566d456111SEric W. Biederman 		.proc_handler	= stack_trace_sysctl,
1957f38f1d2aSSteven Rostedt 	},
1958f38f1d2aSSteven Rostedt #endif
1959944ac425SSteven Rostedt #ifdef CONFIG_TRACING
1960944ac425SSteven Rostedt 	{
19613299b4ddSPeter Zijlstra 		.procname	= "ftrace_dump_on_oops",
1962944ac425SSteven Rostedt 		.data		= &ftrace_dump_on_oops,
1963944ac425SSteven Rostedt 		.maxlen		= sizeof(int),
1964944ac425SSteven Rostedt 		.mode		= 0644,
19656d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1966944ac425SSteven Rostedt 	},
1967de7edd31SSteven Rostedt (Red Hat) 	{
1968de7edd31SSteven Rostedt (Red Hat) 		.procname	= "traceoff_on_warning",
1969de7edd31SSteven Rostedt (Red Hat) 		.data		= &__disable_trace_on_warning,
1970de7edd31SSteven Rostedt (Red Hat) 		.maxlen		= sizeof(__disable_trace_on_warning),
1971de7edd31SSteven Rostedt (Red Hat) 		.mode		= 0644,
1972de7edd31SSteven Rostedt (Red Hat) 		.proc_handler	= proc_dointvec,
1973de7edd31SSteven Rostedt (Red Hat) 	},
19740daa2302SSteven Rostedt (Red Hat) 	{
19750daa2302SSteven Rostedt (Red Hat) 		.procname	= "tracepoint_printk",
19760daa2302SSteven Rostedt (Red Hat) 		.data		= &tracepoint_printk,
19770daa2302SSteven Rostedt (Red Hat) 		.maxlen		= sizeof(tracepoint_printk),
19780daa2302SSteven Rostedt (Red Hat) 		.mode		= 0644,
197942391745SSteven Rostedt (Red Hat) 		.proc_handler	= tracepoint_printk_sysctl,
19800daa2302SSteven Rostedt (Red Hat) 	},
1981944ac425SSteven Rostedt #endif
19822965faa5SDave Young #ifdef CONFIG_KEXEC_CORE
19837984754bSKees Cook 	{
19847984754bSKees Cook 		.procname	= "kexec_load_disabled",
19857984754bSKees Cook 		.data		= &kexec_load_disabled,
19867984754bSKees Cook 		.maxlen		= sizeof(int),
19877984754bSKees Cook 		.mode		= 0644,
19887984754bSKees Cook 		/* only handle a transition from default "0" to "1" */
19897984754bSKees Cook 		.proc_handler	= proc_dointvec_minmax,
1990eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
1991eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
19927984754bSKees Cook 	},
19937984754bSKees Cook #endif
1994a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES
19951da177e4SLinus Torvalds 	{
19961da177e4SLinus Torvalds 		.procname	= "modprobe",
19971da177e4SLinus Torvalds 		.data		= &modprobe_path,
19981da177e4SLinus Torvalds 		.maxlen		= KMOD_PATH_LEN,
19991da177e4SLinus Torvalds 		.mode		= 0644,
20006d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
20011da177e4SLinus Torvalds 	},
20023d43321bSKees Cook 	{
20033d43321bSKees Cook 		.procname	= "modules_disabled",
20043d43321bSKees Cook 		.data		= &modules_disabled,
20053d43321bSKees Cook 		.maxlen		= sizeof(int),
20063d43321bSKees Cook 		.mode		= 0644,
20073d43321bSKees Cook 		/* only handle a transition from default "0" to "1" */
20086d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2009eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
2010eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
20113d43321bSKees Cook 	},
20121da177e4SLinus Torvalds #endif
201386d56134SMichael Marineau #ifdef CONFIG_UEVENT_HELPER
20141da177e4SLinus Torvalds 	{
20151da177e4SLinus Torvalds 		.procname	= "hotplug",
2016312c004dSKay Sievers 		.data		= &uevent_helper,
2017312c004dSKay Sievers 		.maxlen		= UEVENT_HELPER_PATH_LEN,
20181da177e4SLinus Torvalds 		.mode		= 0644,
20196d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
20201da177e4SLinus Torvalds 	},
202186d56134SMichael Marineau #endif
20221da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG
20231da177e4SLinus Torvalds 	{
20241da177e4SLinus Torvalds 		.procname	= "sg-big-buff",
20251da177e4SLinus Torvalds 		.data		= &sg_big_buff,
20261da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
20271da177e4SLinus Torvalds 		.mode		= 0444,
20286d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
20291da177e4SLinus Torvalds 	},
20301da177e4SLinus Torvalds #endif
20311da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
20321da177e4SLinus Torvalds 	{
20331da177e4SLinus Torvalds 		.procname	= "acct",
20341da177e4SLinus Torvalds 		.data		= &acct_parm,
20351da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
20361da177e4SLinus Torvalds 		.mode		= 0644,
20376d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
20381da177e4SLinus Torvalds 	},
20391da177e4SLinus Torvalds #endif
20401da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ
20411da177e4SLinus Torvalds 	{
20421da177e4SLinus Torvalds 		.procname	= "sysrq",
2043eaee4172SDmitry Safonov 		.data		= NULL,
20441da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
20451da177e4SLinus Torvalds 		.mode		= 0644,
204697f5f0cdSDmitry Torokhov 		.proc_handler	= sysrq_sysctl_handler,
20471da177e4SLinus Torvalds 	},
20481da177e4SLinus Torvalds #endif
2049d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
20501da177e4SLinus Torvalds 	{
20511da177e4SLinus Torvalds 		.procname	= "cad_pid",
20529ec52099SCedric Le Goater 		.data		= NULL,
20531da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
20541da177e4SLinus Torvalds 		.mode		= 0600,
20556d456111SEric W. Biederman 		.proc_handler	= proc_do_cad_pid,
20561da177e4SLinus Torvalds 	},
2057d6f8ff73SRandy Dunlap #endif
20581da177e4SLinus Torvalds 	{
20591da177e4SLinus Torvalds 		.procname	= "threads-max",
206016db3d3fSHeinrich Schuchardt 		.data		= NULL,
20611da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
20621da177e4SLinus Torvalds 		.mode		= 0644,
206316db3d3fSHeinrich Schuchardt 		.proc_handler	= sysctl_max_threads,
20641da177e4SLinus Torvalds 	},
20651da177e4SLinus Torvalds 	{
20661da177e4SLinus Torvalds 		.procname	= "random",
20671da177e4SLinus Torvalds 		.mode		= 0555,
20681da177e4SLinus Torvalds 		.child		= random_table,
20691da177e4SLinus Torvalds 	},
20701da177e4SLinus Torvalds 	{
207117f60a7dSEric Paris 		.procname	= "usermodehelper",
207217f60a7dSEric Paris 		.mode		= 0555,
207317f60a7dSEric Paris 		.child		= usermodehelper_table,
207417f60a7dSEric Paris 	},
2075ceb18132SLuis R. Rodriguez #ifdef CONFIG_FW_LOADER_USER_HELPER
2076ceb18132SLuis R. Rodriguez 	{
2077ceb18132SLuis R. Rodriguez 		.procname	= "firmware_config",
2078ceb18132SLuis R. Rodriguez 		.mode		= 0555,
2079ceb18132SLuis R. Rodriguez 		.child		= firmware_config_table,
2080ceb18132SLuis R. Rodriguez 	},
2081ceb18132SLuis R. Rodriguez #endif
208217f60a7dSEric Paris 	{
20831da177e4SLinus Torvalds 		.procname	= "overflowuid",
20841da177e4SLinus Torvalds 		.data		= &overflowuid,
20851da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
20861da177e4SLinus Torvalds 		.mode		= 0644,
20876d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
20881da177e4SLinus Torvalds 		.extra1		= &minolduid,
20891da177e4SLinus Torvalds 		.extra2		= &maxolduid,
20901da177e4SLinus Torvalds 	},
20911da177e4SLinus Torvalds 	{
20921da177e4SLinus Torvalds 		.procname	= "overflowgid",
20931da177e4SLinus Torvalds 		.data		= &overflowgid,
20941da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
20951da177e4SLinus Torvalds 		.mode		= 0644,
20966d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
20971da177e4SLinus Torvalds 		.extra1		= &minolduid,
20981da177e4SLinus Torvalds 		.extra2		= &maxolduid,
20991da177e4SLinus Torvalds 	},
2100347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
21011da177e4SLinus Torvalds 	{
21021da177e4SLinus Torvalds 		.procname	= "userprocess_debug",
2103ab3c68eeSHeiko Carstens 		.data		= &show_unhandled_signals,
21041da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21051da177e4SLinus Torvalds 		.mode		= 0644,
21066d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
21071da177e4SLinus Torvalds 	},
21081da177e4SLinus Torvalds #endif
21091da177e4SLinus Torvalds 	{
21101da177e4SLinus Torvalds 		.procname	= "pid_max",
21111da177e4SLinus Torvalds 		.data		= &pid_max,
21121da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
21131da177e4SLinus Torvalds 		.mode		= 0644,
21146d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
21151da177e4SLinus Torvalds 		.extra1		= &pid_max_min,
21161da177e4SLinus Torvalds 		.extra2		= &pid_max_max,
21171da177e4SLinus Torvalds 	},
21181da177e4SLinus Torvalds 	{
21191da177e4SLinus Torvalds 		.procname	= "panic_on_oops",
21201da177e4SLinus Torvalds 		.data		= &panic_on_oops,
21211da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21221da177e4SLinus Torvalds 		.mode		= 0644,
21236d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
21241da177e4SLinus Torvalds 	},
212581c9d43fSFeng Tang 	{
212681c9d43fSFeng Tang 		.procname	= "panic_print",
212781c9d43fSFeng Tang 		.data		= &panic_print,
212881c9d43fSFeng Tang 		.maxlen		= sizeof(unsigned long),
212981c9d43fSFeng Tang 		.mode		= 0644,
213081c9d43fSFeng Tang 		.proc_handler	= proc_doulongvec_minmax,
213181c9d43fSFeng Tang 	},
21327ef3d2fdSJoe Perches #if defined CONFIG_PRINTK
21337ef3d2fdSJoe Perches 	{
21347ef3d2fdSJoe Perches 		.procname	= "printk",
21357ef3d2fdSJoe Perches 		.data		= &console_loglevel,
21367ef3d2fdSJoe Perches 		.maxlen		= 4*sizeof(int),
21377ef3d2fdSJoe Perches 		.mode		= 0644,
21386d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
21397ef3d2fdSJoe Perches 	},
21401da177e4SLinus Torvalds 	{
21411da177e4SLinus Torvalds 		.procname	= "printk_ratelimit",
2142717115e1SDave Young 		.data		= &printk_ratelimit_state.interval,
21431da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21441da177e4SLinus Torvalds 		.mode		= 0644,
21456d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_jiffies,
21461da177e4SLinus Torvalds 	},
21471da177e4SLinus Torvalds 	{
21481da177e4SLinus Torvalds 		.procname	= "printk_ratelimit_burst",
2149717115e1SDave Young 		.data		= &printk_ratelimit_state.burst,
21501da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21511da177e4SLinus Torvalds 		.mode		= 0644,
21526d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
21531da177e4SLinus Torvalds 	},
2154af91322eSDave Young 	{
2155af91322eSDave Young 		.procname	= "printk_delay",
2156af91322eSDave Young 		.data		= &printk_delay_msec,
2157af91322eSDave Young 		.maxlen		= sizeof(int),
2158af91322eSDave Young 		.mode		= 0644,
21596d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2160eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2161af91322eSDave Young 		.extra2		= &ten_thousand,
2162af91322eSDave Young 	},
21631da177e4SLinus Torvalds 	{
2164750afe7bSBorislav Petkov 		.procname	= "printk_devkmsg",
2165750afe7bSBorislav Petkov 		.data		= devkmsg_log_str,
2166750afe7bSBorislav Petkov 		.maxlen		= DEVKMSG_STR_MAX_SIZE,
2167750afe7bSBorislav Petkov 		.mode		= 0644,
2168750afe7bSBorislav Petkov 		.proc_handler	= devkmsg_sysctl_set_loglvl,
2169750afe7bSBorislav Petkov 	},
2170750afe7bSBorislav Petkov 	{
2171eaf06b24SDan Rosenberg 		.procname	= "dmesg_restrict",
2172eaf06b24SDan Rosenberg 		.data		= &dmesg_restrict,
2173eaf06b24SDan Rosenberg 		.maxlen		= sizeof(int),
2174eaf06b24SDan Rosenberg 		.mode		= 0644,
2175620f6e8eSKees Cook 		.proc_handler	= proc_dointvec_minmax_sysadmin,
2176eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2177eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2178eaf06b24SDan Rosenberg 	},
2179455cd5abSDan Rosenberg 	{
2180455cd5abSDan Rosenberg 		.procname	= "kptr_restrict",
2181455cd5abSDan Rosenberg 		.data		= &kptr_restrict,
2182455cd5abSDan Rosenberg 		.maxlen		= sizeof(int),
2183455cd5abSDan Rosenberg 		.mode		= 0644,
2184620f6e8eSKees Cook 		.proc_handler	= proc_dointvec_minmax_sysadmin,
2185eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2186455cd5abSDan Rosenberg 		.extra2		= &two,
2187455cd5abSDan Rosenberg 	},
2188df6e61d4SJoe Perches #endif
2189eaf06b24SDan Rosenberg 	{
21901da177e4SLinus Torvalds 		.procname	= "ngroups_max",
21911da177e4SLinus Torvalds 		.data		= &ngroups_max,
21921da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
21931da177e4SLinus Torvalds 		.mode		= 0444,
21946d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
21951da177e4SLinus Torvalds 	},
219673efc039SDan Ballard 	{
219773efc039SDan Ballard 		.procname	= "cap_last_cap",
219873efc039SDan Ballard 		.data		= (void *)&cap_last_cap,
219973efc039SDan Ballard 		.maxlen		= sizeof(int),
220073efc039SDan Ballard 		.mode		= 0444,
220173efc039SDan Ballard 		.proc_handler	= proc_dointvec,
220273efc039SDan Ballard 	},
220358687acbSDon Zickus #if defined(CONFIG_LOCKUP_DETECTOR)
2204504d7cf1SDon Zickus 	{
220558687acbSDon Zickus 		.procname       = "watchdog",
22063c00ea82SFrederic Weisbecker 		.data		= &watchdog_user_enabled,
2207504d7cf1SDon Zickus 		.maxlen		= sizeof(int),
2208504d7cf1SDon Zickus 		.mode		= 0644,
2209195daf66SUlrich Obergfell 		.proc_handler   = proc_watchdog,
2210eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2211eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
221258687acbSDon Zickus 	},
221358687acbSDon Zickus 	{
221458687acbSDon Zickus 		.procname	= "watchdog_thresh",
2215586692a5SMandeep Singh Baines 		.data		= &watchdog_thresh,
221658687acbSDon Zickus 		.maxlen		= sizeof(int),
221758687acbSDon Zickus 		.mode		= 0644,
2218195daf66SUlrich Obergfell 		.proc_handler	= proc_watchdog_thresh,
2219eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
222058687acbSDon Zickus 		.extra2		= &sixty,
2221504d7cf1SDon Zickus 	},
22222508ce18SDon Zickus 	{
2223195daf66SUlrich Obergfell 		.procname       = "nmi_watchdog",
22247feeb9cdSThomas Gleixner 		.data		= &nmi_watchdog_user_enabled,
2225195daf66SUlrich Obergfell 		.maxlen		= sizeof(int),
222651d4052bSThomas Gleixner 		.mode		= NMI_WATCHDOG_SYSCTL_PERM,
2227195daf66SUlrich Obergfell 		.proc_handler   = proc_nmi_watchdog,
2228eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2229eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2230195daf66SUlrich Obergfell 	},
2231195daf66SUlrich Obergfell 	{
223205a4a952SNicholas Piggin 		.procname	= "watchdog_cpumask",
223305a4a952SNicholas Piggin 		.data		= &watchdog_cpumask_bits,
223405a4a952SNicholas Piggin 		.maxlen		= NR_CPUS,
223505a4a952SNicholas Piggin 		.mode		= 0644,
223605a4a952SNicholas Piggin 		.proc_handler	= proc_watchdog_cpumask,
223705a4a952SNicholas Piggin 	},
223805a4a952SNicholas Piggin #ifdef CONFIG_SOFTLOCKUP_DETECTOR
223905a4a952SNicholas Piggin 	{
2240195daf66SUlrich Obergfell 		.procname       = "soft_watchdog",
22417feeb9cdSThomas Gleixner 		.data		= &soft_watchdog_user_enabled,
2242195daf66SUlrich Obergfell 		.maxlen		= sizeof(int),
2243195daf66SUlrich Obergfell 		.mode		= 0644,
2244195daf66SUlrich Obergfell 		.proc_handler   = proc_soft_watchdog,
2245eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2246eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2247195daf66SUlrich Obergfell 	},
2248195daf66SUlrich Obergfell 	{
22492508ce18SDon Zickus 		.procname	= "softlockup_panic",
22502508ce18SDon Zickus 		.data		= &softlockup_panic,
22512508ce18SDon Zickus 		.maxlen		= sizeof(int),
22522508ce18SDon Zickus 		.mode		= 0644,
22532508ce18SDon Zickus 		.proc_handler	= proc_dointvec_minmax,
2254eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2255eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
22562508ce18SDon Zickus 	},
2257ed235875SAaron Tomlin #ifdef CONFIG_SMP
2258ed235875SAaron Tomlin 	{
2259ed235875SAaron Tomlin 		.procname	= "softlockup_all_cpu_backtrace",
2260ed235875SAaron Tomlin 		.data		= &sysctl_softlockup_all_cpu_backtrace,
2261ed235875SAaron Tomlin 		.maxlen		= sizeof(int),
2262ed235875SAaron Tomlin 		.mode		= 0644,
2263ed235875SAaron Tomlin 		.proc_handler	= proc_dointvec_minmax,
2264eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2265eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2266ed235875SAaron Tomlin 	},
226705a4a952SNicholas Piggin #endif /* CONFIG_SMP */
226805a4a952SNicholas Piggin #endif
226905a4a952SNicholas Piggin #ifdef CONFIG_HARDLOCKUP_DETECTOR
227005a4a952SNicholas Piggin 	{
227105a4a952SNicholas Piggin 		.procname	= "hardlockup_panic",
227205a4a952SNicholas Piggin 		.data		= &hardlockup_panic,
227305a4a952SNicholas Piggin 		.maxlen		= sizeof(int),
227405a4a952SNicholas Piggin 		.mode		= 0644,
227505a4a952SNicholas Piggin 		.proc_handler	= proc_dointvec_minmax,
2276eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2277eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
227805a4a952SNicholas Piggin 	},
227905a4a952SNicholas Piggin #ifdef CONFIG_SMP
228055537871SJiri Kosina 	{
228155537871SJiri Kosina 		.procname	= "hardlockup_all_cpu_backtrace",
228255537871SJiri Kosina 		.data		= &sysctl_hardlockup_all_cpu_backtrace,
228355537871SJiri Kosina 		.maxlen		= sizeof(int),
228455537871SJiri Kosina 		.mode		= 0644,
228555537871SJiri Kosina 		.proc_handler	= proc_dointvec_minmax,
2286eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2287eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
228855537871SJiri Kosina 	},
2289ed235875SAaron Tomlin #endif /* CONFIG_SMP */
22905dc30558SDon Zickus #endif
229105a4a952SNicholas Piggin #endif
229205a4a952SNicholas Piggin 
22935dc30558SDon Zickus #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
22945dc30558SDon Zickus 	{
22955dc30558SDon Zickus 		.procname       = "unknown_nmi_panic",
22965dc30558SDon Zickus 		.data           = &unknown_nmi_panic,
22975dc30558SDon Zickus 		.maxlen         = sizeof (int),
22985dc30558SDon Zickus 		.mode           = 0644,
22995dc30558SDon Zickus 		.proc_handler   = proc_dointvec,
23005dc30558SDon Zickus 	},
2301504d7cf1SDon Zickus #endif
23021da177e4SLinus Torvalds #if defined(CONFIG_X86)
23031da177e4SLinus Torvalds 	{
23048da5addaSDon Zickus 		.procname	= "panic_on_unrecovered_nmi",
23058da5addaSDon Zickus 		.data		= &panic_on_unrecovered_nmi,
23068da5addaSDon Zickus 		.maxlen		= sizeof(int),
23078da5addaSDon Zickus 		.mode		= 0644,
23086d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23098da5addaSDon Zickus 	},
23108da5addaSDon Zickus 	{
23115211a242SKurt Garloff 		.procname	= "panic_on_io_nmi",
23125211a242SKurt Garloff 		.data		= &panic_on_io_nmi,
23135211a242SKurt Garloff 		.maxlen		= sizeof(int),
23145211a242SKurt Garloff 		.mode		= 0644,
23156d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23165211a242SKurt Garloff 	},
231755af7796SMitsuo Hayasaka #ifdef CONFIG_DEBUG_STACKOVERFLOW
231855af7796SMitsuo Hayasaka 	{
231955af7796SMitsuo Hayasaka 		.procname	= "panic_on_stackoverflow",
232055af7796SMitsuo Hayasaka 		.data		= &sysctl_panic_on_stackoverflow,
232155af7796SMitsuo Hayasaka 		.maxlen		= sizeof(int),
232255af7796SMitsuo Hayasaka 		.mode		= 0644,
232355af7796SMitsuo Hayasaka 		.proc_handler	= proc_dointvec,
232455af7796SMitsuo Hayasaka 	},
232555af7796SMitsuo Hayasaka #endif
23265211a242SKurt Garloff 	{
23271da177e4SLinus Torvalds 		.procname	= "bootloader_type",
23281da177e4SLinus Torvalds 		.data		= &bootloader_type,
23291da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
23301da177e4SLinus Torvalds 		.mode		= 0444,
23316d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23321da177e4SLinus Torvalds 	},
23330741f4d2SChuck Ebbert 	{
23345031296cSH. Peter Anvin 		.procname	= "bootloader_version",
23355031296cSH. Peter Anvin 		.data		= &bootloader_version,
23365031296cSH. Peter Anvin 		.maxlen		= sizeof (int),
23375031296cSH. Peter Anvin 		.mode		= 0444,
23386d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23395031296cSH. Peter Anvin 	},
23405031296cSH. Peter Anvin 	{
23416e7c4025SIngo Molnar 		.procname	= "io_delay_type",
23426e7c4025SIngo Molnar 		.data		= &io_delay_type,
23436e7c4025SIngo Molnar 		.maxlen		= sizeof(int),
23446e7c4025SIngo Molnar 		.mode		= 0644,
23456d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23466e7c4025SIngo Molnar 	},
23471da177e4SLinus Torvalds #endif
23487a9166e3SLuke Yang #if defined(CONFIG_MMU)
23491da177e4SLinus Torvalds 	{
23501da177e4SLinus Torvalds 		.procname	= "randomize_va_space",
23511da177e4SLinus Torvalds 		.data		= &randomize_va_space,
23521da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
23531da177e4SLinus Torvalds 		.mode		= 0644,
23546d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23551da177e4SLinus Torvalds 	},
23567a9166e3SLuke Yang #endif
23570152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP)
2358951f22d5SMartin Schwidefsky 	{
2359951f22d5SMartin Schwidefsky 		.procname	= "spin_retry",
2360951f22d5SMartin Schwidefsky 		.data		= &spin_retry,
2361951f22d5SMartin Schwidefsky 		.maxlen		= sizeof (int),
2362951f22d5SMartin Schwidefsky 		.mode		= 0644,
23636d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2364951f22d5SMartin Schwidefsky 	},
2365951f22d5SMartin Schwidefsky #endif
2366673d5b43SLen Brown #if	defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
2367c255d844SPavel Machek 	{
2368c255d844SPavel Machek 		.procname	= "acpi_video_flags",
236977afcf78SPavel Machek 		.data		= &acpi_realmode_flags,
2370c255d844SPavel Machek 		.maxlen		= sizeof (unsigned long),
2371c255d844SPavel Machek 		.mode		= 0644,
23726d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
2373c255d844SPavel Machek 	},
2374c255d844SPavel Machek #endif
2375b6fca725SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
2376d2b176edSJes Sorensen 	{
2377d2b176edSJes Sorensen 		.procname	= "ignore-unaligned-usertrap",
2378d2b176edSJes Sorensen 		.data		= &no_unaligned_warning,
2379d2b176edSJes Sorensen 		.maxlen		= sizeof (int),
2380d2b176edSJes Sorensen 		.mode		= 0644,
23816d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2382d2b176edSJes Sorensen 	},
2383b6fca725SVineet Gupta #endif
2384b6fca725SVineet Gupta #ifdef CONFIG_IA64
238588fc241fSDoug Chapman 	{
238688fc241fSDoug Chapman 		.procname	= "unaligned-dump-stack",
238788fc241fSDoug Chapman 		.data		= &unaligned_dump_stack,
238888fc241fSDoug Chapman 		.maxlen		= sizeof (int),
238988fc241fSDoug Chapman 		.mode		= 0644,
23906d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
239188fc241fSDoug Chapman 	},
2392d2b176edSJes Sorensen #endif
2393e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK
2394e162b39aSMandeep Singh Baines 	{
2395e162b39aSMandeep Singh Baines 		.procname	= "hung_task_panic",
2396e162b39aSMandeep Singh Baines 		.data		= &sysctl_hung_task_panic,
2397e162b39aSMandeep Singh Baines 		.maxlen		= sizeof(int),
2398e162b39aSMandeep Singh Baines 		.mode		= 0644,
23996d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2400eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2401eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2402e162b39aSMandeep Singh Baines 	},
240382a1fcb9SIngo Molnar 	{
240482a1fcb9SIngo Molnar 		.procname	= "hung_task_check_count",
240582a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_check_count,
2406cd64647fSLi Zefan 		.maxlen		= sizeof(int),
240782a1fcb9SIngo Molnar 		.mode		= 0644,
2408cd64647fSLi Zefan 		.proc_handler	= proc_dointvec_minmax,
2409eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
241082a1fcb9SIngo Molnar 	},
241182a1fcb9SIngo Molnar 	{
241282a1fcb9SIngo Molnar 		.procname	= "hung_task_timeout_secs",
241382a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_timeout_secs,
241490739081SIngo Molnar 		.maxlen		= sizeof(unsigned long),
241582a1fcb9SIngo Molnar 		.mode		= 0644,
24166d456111SEric W. Biederman 		.proc_handler	= proc_dohung_task_timeout_secs,
241780df2847SLiu Hua 		.extra2		= &hung_task_timeout_max,
241882a1fcb9SIngo Molnar 	},
241982a1fcb9SIngo Molnar 	{
2420a2e51445SDmitry Vyukov 		.procname	= "hung_task_check_interval_secs",
2421a2e51445SDmitry Vyukov 		.data		= &sysctl_hung_task_check_interval_secs,
2422a2e51445SDmitry Vyukov 		.maxlen		= sizeof(unsigned long),
2423a2e51445SDmitry Vyukov 		.mode		= 0644,
2424a2e51445SDmitry Vyukov 		.proc_handler	= proc_dohung_task_timeout_secs,
2425a2e51445SDmitry Vyukov 		.extra2		= &hung_task_timeout_max,
2426a2e51445SDmitry Vyukov 	},
2427a2e51445SDmitry Vyukov 	{
242882a1fcb9SIngo Molnar 		.procname	= "hung_task_warnings",
242982a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_warnings,
2430270750dbSAaron Tomlin 		.maxlen		= sizeof(int),
243182a1fcb9SIngo Molnar 		.mode		= 0644,
2432270750dbSAaron Tomlin 		.proc_handler	= proc_dointvec_minmax,
2433270750dbSAaron Tomlin 		.extra1		= &neg_one,
243482a1fcb9SIngo Molnar 	},
2435c4f3b63fSRavikiran G Thirumalai #endif
243623f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
243723f78d4aSIngo Molnar 	{
243823f78d4aSIngo Molnar 		.procname	= "max_lock_depth",
243923f78d4aSIngo Molnar 		.data		= &max_lock_depth,
244023f78d4aSIngo Molnar 		.maxlen		= sizeof(int),
244123f78d4aSIngo Molnar 		.mode		= 0644,
24426d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
244323f78d4aSIngo Molnar 	},
244423f78d4aSIngo Molnar #endif
244510a0a8d4SJeremy Fitzhardinge 	{
244610a0a8d4SJeremy Fitzhardinge 		.procname	= "poweroff_cmd",
244710a0a8d4SJeremy Fitzhardinge 		.data		= &poweroff_cmd,
244810a0a8d4SJeremy Fitzhardinge 		.maxlen		= POWEROFF_CMD_PATH_LEN,
244910a0a8d4SJeremy Fitzhardinge 		.mode		= 0644,
24506d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
245110a0a8d4SJeremy Fitzhardinge 	},
24520b77f5bfSDavid Howells #ifdef CONFIG_KEYS
24530b77f5bfSDavid Howells 	{
24540b77f5bfSDavid Howells 		.procname	= "keys",
24550b77f5bfSDavid Howells 		.mode		= 0555,
24560b77f5bfSDavid Howells 		.child		= key_sysctls,
24570b77f5bfSDavid Howells 	},
24580b77f5bfSDavid Howells #endif
2459cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS
2460aa4a2218SVince Weaver 	/*
2461aa4a2218SVince Weaver 	 * User-space scripts rely on the existence of this file
2462aa4a2218SVince Weaver 	 * as a feature check for perf_events being enabled.
2463aa4a2218SVince Weaver 	 *
2464aa4a2218SVince Weaver 	 * So it's an ABI, do not remove!
2465aa4a2218SVince Weaver 	 */
24661ccd1549SPeter Zijlstra 	{
2467cdd6c482SIngo Molnar 		.procname	= "perf_event_paranoid",
2468cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_paranoid,
2469cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_paranoid),
24701ccd1549SPeter Zijlstra 		.mode		= 0644,
24716d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
24721ccd1549SPeter Zijlstra 	},
2473c5078f78SPeter Zijlstra 	{
2474cdd6c482SIngo Molnar 		.procname	= "perf_event_mlock_kb",
2475cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_mlock,
2476cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_mlock),
2477c5078f78SPeter Zijlstra 		.mode		= 0644,
24786d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2479c5078f78SPeter Zijlstra 	},
2480a78ac325SPeter Zijlstra 	{
2481cdd6c482SIngo Molnar 		.procname	= "perf_event_max_sample_rate",
2482cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_sample_rate,
2483cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_sample_rate),
2484a78ac325SPeter Zijlstra 		.mode		= 0644,
2485163ec435SPeter Zijlstra 		.proc_handler	= perf_proc_update_handler,
2486eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
2487a78ac325SPeter Zijlstra 	},
248814c63f17SDave Hansen 	{
248914c63f17SDave Hansen 		.procname	= "perf_cpu_time_max_percent",
249014c63f17SDave Hansen 		.data		= &sysctl_perf_cpu_time_max_percent,
249114c63f17SDave Hansen 		.maxlen		= sizeof(sysctl_perf_cpu_time_max_percent),
249214c63f17SDave Hansen 		.mode		= 0644,
249314c63f17SDave Hansen 		.proc_handler	= perf_cpu_time_max_percent_handler,
2494eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
249514c63f17SDave Hansen 		.extra2		= &one_hundred,
249614c63f17SDave Hansen 	},
2497c5dfd78eSArnaldo Carvalho de Melo 	{
2498c5dfd78eSArnaldo Carvalho de Melo 		.procname	= "perf_event_max_stack",
2499a831100aSArnaldo Carvalho de Melo 		.data		= &sysctl_perf_event_max_stack,
2500c5dfd78eSArnaldo Carvalho de Melo 		.maxlen		= sizeof(sysctl_perf_event_max_stack),
2501c5dfd78eSArnaldo Carvalho de Melo 		.mode		= 0644,
2502c5dfd78eSArnaldo Carvalho de Melo 		.proc_handler	= perf_event_max_stack_handler,
2503eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2504c5dfd78eSArnaldo Carvalho de Melo 		.extra2		= &six_hundred_forty_kb,
2505c5dfd78eSArnaldo Carvalho de Melo 	},
2506c85b0334SArnaldo Carvalho de Melo 	{
2507c85b0334SArnaldo Carvalho de Melo 		.procname	= "perf_event_max_contexts_per_stack",
2508c85b0334SArnaldo Carvalho de Melo 		.data		= &sysctl_perf_event_max_contexts_per_stack,
2509c85b0334SArnaldo Carvalho de Melo 		.maxlen		= sizeof(sysctl_perf_event_max_contexts_per_stack),
2510c85b0334SArnaldo Carvalho de Melo 		.mode		= 0644,
2511c85b0334SArnaldo Carvalho de Melo 		.proc_handler	= perf_event_max_stack_handler,
2512eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2513c85b0334SArnaldo Carvalho de Melo 		.extra2		= &one_thousand,
2514c85b0334SArnaldo Carvalho de Melo 	},
25151ccd1549SPeter Zijlstra #endif
25169e3961a0SPrarit Bhargava 	{
25179e3961a0SPrarit Bhargava 		.procname	= "panic_on_warn",
25189e3961a0SPrarit Bhargava 		.data		= &panic_on_warn,
25199e3961a0SPrarit Bhargava 		.maxlen		= sizeof(int),
25209e3961a0SPrarit Bhargava 		.mode		= 0644,
25219e3961a0SPrarit Bhargava 		.proc_handler	= proc_dointvec_minmax,
2522eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2523eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
25249e3961a0SPrarit Bhargava 	},
2525bc7a34b8SThomas Gleixner #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
2526bc7a34b8SThomas Gleixner 	{
2527bc7a34b8SThomas Gleixner 		.procname	= "timer_migration",
2528bc7a34b8SThomas Gleixner 		.data		= &sysctl_timer_migration,
2529bc7a34b8SThomas Gleixner 		.maxlen		= sizeof(unsigned int),
2530bc7a34b8SThomas Gleixner 		.mode		= 0644,
2531bc7a34b8SThomas Gleixner 		.proc_handler	= timer_migration_handler,
2532eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2533eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2534bc7a34b8SThomas Gleixner 	},
2535bc7a34b8SThomas Gleixner #endif
25361be7f75dSAlexei Starovoitov #ifdef CONFIG_BPF_SYSCALL
25371be7f75dSAlexei Starovoitov 	{
25381be7f75dSAlexei Starovoitov 		.procname	= "unprivileged_bpf_disabled",
25391be7f75dSAlexei Starovoitov 		.data		= &sysctl_unprivileged_bpf_disabled,
25401be7f75dSAlexei Starovoitov 		.maxlen		= sizeof(sysctl_unprivileged_bpf_disabled),
25411be7f75dSAlexei Starovoitov 		.mode		= 0644,
25421be7f75dSAlexei Starovoitov 		/* only handle a transition from default "0" to "1" */
25431be7f75dSAlexei Starovoitov 		.proc_handler	= proc_dointvec_minmax,
2544eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
2545eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
25461be7f75dSAlexei Starovoitov 	},
2547492ecee8SAlexei Starovoitov 	{
2548492ecee8SAlexei Starovoitov 		.procname	= "bpf_stats_enabled",
2549a8e11e5cSEric Dumazet 		.data		= &bpf_stats_enabled_key.key,
2550a8e11e5cSEric Dumazet 		.maxlen		= sizeof(bpf_stats_enabled_key),
2551492ecee8SAlexei Starovoitov 		.mode		= 0644,
2552a8e11e5cSEric Dumazet 		.proc_handler	= proc_do_static_key,
2553492ecee8SAlexei Starovoitov 	},
25543fcc5530SAlexei Starovoitov #endif
2555b3e627d3SLai Jiangshan #if defined(CONFIG_TREE_RCU)
2556088e9d25SDaniel Bristot de Oliveira 	{
2557088e9d25SDaniel Bristot de Oliveira 		.procname	= "panic_on_rcu_stall",
2558088e9d25SDaniel Bristot de Oliveira 		.data		= &sysctl_panic_on_rcu_stall,
2559088e9d25SDaniel Bristot de Oliveira 		.maxlen		= sizeof(sysctl_panic_on_rcu_stall),
2560088e9d25SDaniel Bristot de Oliveira 		.mode		= 0644,
2561088e9d25SDaniel Bristot de Oliveira 		.proc_handler	= proc_dointvec_minmax,
2562eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2563eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2564088e9d25SDaniel Bristot de Oliveira 	},
2565088e9d25SDaniel Bristot de Oliveira #endif
2566964c9dffSAlexander Popov #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
2567964c9dffSAlexander Popov 	{
2568964c9dffSAlexander Popov 		.procname	= "stack_erasing",
2569964c9dffSAlexander Popov 		.data		= NULL,
2570964c9dffSAlexander Popov 		.maxlen		= sizeof(int),
2571964c9dffSAlexander Popov 		.mode		= 0600,
2572964c9dffSAlexander Popov 		.proc_handler	= stack_erasing_sysctl,
2573eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2574eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2575964c9dffSAlexander Popov 	},
2576964c9dffSAlexander Popov #endif
25776fce56ecSEric W. Biederman 	{ }
25781da177e4SLinus Torvalds };
25791da177e4SLinus Torvalds 
2580d8217f07SEric W. Biederman static struct ctl_table vm_table[] = {
25811da177e4SLinus Torvalds 	{
25821da177e4SLinus Torvalds 		.procname	= "overcommit_memory",
25831da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_memory,
25841da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_memory),
25851da177e4SLinus Torvalds 		.mode		= 0644,
2586cb16e95fSPetr Holasek 		.proc_handler	= proc_dointvec_minmax,
2587eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2588cb16e95fSPetr Holasek 		.extra2		= &two,
25891da177e4SLinus Torvalds 	},
25901da177e4SLinus Torvalds 	{
2591fadd8fbdSKAMEZAWA Hiroyuki 		.procname	= "panic_on_oom",
2592fadd8fbdSKAMEZAWA Hiroyuki 		.data		= &sysctl_panic_on_oom,
2593fadd8fbdSKAMEZAWA Hiroyuki 		.maxlen		= sizeof(sysctl_panic_on_oom),
2594fadd8fbdSKAMEZAWA Hiroyuki 		.mode		= 0644,
2595cb16e95fSPetr Holasek 		.proc_handler	= proc_dointvec_minmax,
2596eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2597cb16e95fSPetr Holasek 		.extra2		= &two,
2598fadd8fbdSKAMEZAWA Hiroyuki 	},
2599fadd8fbdSKAMEZAWA Hiroyuki 	{
2600fe071d7eSDavid Rientjes 		.procname	= "oom_kill_allocating_task",
2601fe071d7eSDavid Rientjes 		.data		= &sysctl_oom_kill_allocating_task,
2602fe071d7eSDavid Rientjes 		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
2603fe071d7eSDavid Rientjes 		.mode		= 0644,
26046d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2605fe071d7eSDavid Rientjes 	},
2606fe071d7eSDavid Rientjes 	{
2607fef1bdd6SDavid Rientjes 		.procname	= "oom_dump_tasks",
2608fef1bdd6SDavid Rientjes 		.data		= &sysctl_oom_dump_tasks,
2609fef1bdd6SDavid Rientjes 		.maxlen		= sizeof(sysctl_oom_dump_tasks),
2610fef1bdd6SDavid Rientjes 		.mode		= 0644,
26116d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2612fef1bdd6SDavid Rientjes 	},
2613fef1bdd6SDavid Rientjes 	{
26141da177e4SLinus Torvalds 		.procname	= "overcommit_ratio",
26151da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_ratio,
26161da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_ratio),
26171da177e4SLinus Torvalds 		.mode		= 0644,
261849f0ce5fSJerome Marchand 		.proc_handler	= overcommit_ratio_handler,
261949f0ce5fSJerome Marchand 	},
262049f0ce5fSJerome Marchand 	{
262149f0ce5fSJerome Marchand 		.procname	= "overcommit_kbytes",
262249f0ce5fSJerome Marchand 		.data		= &sysctl_overcommit_kbytes,
262349f0ce5fSJerome Marchand 		.maxlen		= sizeof(sysctl_overcommit_kbytes),
262449f0ce5fSJerome Marchand 		.mode		= 0644,
262549f0ce5fSJerome Marchand 		.proc_handler	= overcommit_kbytes_handler,
26261da177e4SLinus Torvalds 	},
26271da177e4SLinus Torvalds 	{
26281da177e4SLinus Torvalds 		.procname	= "page-cluster",
26291da177e4SLinus Torvalds 		.data		= &page_cluster,
26301da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
26311da177e4SLinus Torvalds 		.mode		= 0644,
2632cb16e95fSPetr Holasek 		.proc_handler	= proc_dointvec_minmax,
2633eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
26341da177e4SLinus Torvalds 	},
26351da177e4SLinus Torvalds 	{
26361da177e4SLinus Torvalds 		.procname	= "dirty_background_ratio",
26371da177e4SLinus Torvalds 		.data		= &dirty_background_ratio,
26381da177e4SLinus Torvalds 		.maxlen		= sizeof(dirty_background_ratio),
26391da177e4SLinus Torvalds 		.mode		= 0644,
26406d456111SEric W. Biederman 		.proc_handler	= dirty_background_ratio_handler,
2641eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
26421da177e4SLinus Torvalds 		.extra2		= &one_hundred,
26431da177e4SLinus Torvalds 	},
26441da177e4SLinus Torvalds 	{
26452da02997SDavid Rientjes 		.procname	= "dirty_background_bytes",
26462da02997SDavid Rientjes 		.data		= &dirty_background_bytes,
26472da02997SDavid Rientjes 		.maxlen		= sizeof(dirty_background_bytes),
26482da02997SDavid Rientjes 		.mode		= 0644,
26496d456111SEric W. Biederman 		.proc_handler	= dirty_background_bytes_handler,
2650fc3501d4SSven Wegener 		.extra1		= &one_ul,
26512da02997SDavid Rientjes 	},
26522da02997SDavid Rientjes 	{
26531da177e4SLinus Torvalds 		.procname	= "dirty_ratio",
26541da177e4SLinus Torvalds 		.data		= &vm_dirty_ratio,
26551da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_dirty_ratio),
26561da177e4SLinus Torvalds 		.mode		= 0644,
26576d456111SEric W. Biederman 		.proc_handler	= dirty_ratio_handler,
2658eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
26591da177e4SLinus Torvalds 		.extra2		= &one_hundred,
26601da177e4SLinus Torvalds 	},
26611da177e4SLinus Torvalds 	{
26622da02997SDavid Rientjes 		.procname	= "dirty_bytes",
26632da02997SDavid Rientjes 		.data		= &vm_dirty_bytes,
26642da02997SDavid Rientjes 		.maxlen		= sizeof(vm_dirty_bytes),
26652da02997SDavid Rientjes 		.mode		= 0644,
26666d456111SEric W. Biederman 		.proc_handler	= dirty_bytes_handler,
26679e4a5bdaSAndrea Righi 		.extra1		= &dirty_bytes_min,
26682da02997SDavid Rientjes 	},
26692da02997SDavid Rientjes 	{
26701da177e4SLinus Torvalds 		.procname	= "dirty_writeback_centisecs",
2671f6ef9438SBart Samwel 		.data		= &dirty_writeback_interval,
2672f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_writeback_interval),
26731da177e4SLinus Torvalds 		.mode		= 0644,
26746d456111SEric W. Biederman 		.proc_handler	= dirty_writeback_centisecs_handler,
26751da177e4SLinus Torvalds 	},
26761da177e4SLinus Torvalds 	{
26771da177e4SLinus Torvalds 		.procname	= "dirty_expire_centisecs",
2678f6ef9438SBart Samwel 		.data		= &dirty_expire_interval,
2679f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_expire_interval),
26801da177e4SLinus Torvalds 		.mode		= 0644,
2681cb16e95fSPetr Holasek 		.proc_handler	= proc_dointvec_minmax,
2682eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
26831da177e4SLinus Torvalds 	},
26841da177e4SLinus Torvalds 	{
26851efff914STheodore Ts'o 		.procname	= "dirtytime_expire_seconds",
26861efff914STheodore Ts'o 		.data		= &dirtytime_expire_interval,
26872d87b309SRandy Dunlap 		.maxlen		= sizeof(dirtytime_expire_interval),
26881efff914STheodore Ts'o 		.mode		= 0644,
26891efff914STheodore Ts'o 		.proc_handler	= dirtytime_interval_handler,
2690eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
26911efff914STheodore Ts'o 	},
26921efff914STheodore Ts'o 	{
26931da177e4SLinus Torvalds 		.procname	= "swappiness",
26941da177e4SLinus Torvalds 		.data		= &vm_swappiness,
26951da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_swappiness),
26961da177e4SLinus Torvalds 		.mode		= 0644,
26976d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2698eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
26991da177e4SLinus Torvalds 		.extra2		= &one_hundred,
27001da177e4SLinus Torvalds 	},
27011da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE
27021da177e4SLinus Torvalds 	{
27031da177e4SLinus Torvalds 		.procname	= "nr_hugepages",
2704e5ff2159SAndi Kleen 		.data		= NULL,
27051da177e4SLinus Torvalds 		.maxlen		= sizeof(unsigned long),
27061da177e4SLinus Torvalds 		.mode		= 0644,
27076d456111SEric W. Biederman 		.proc_handler	= hugetlb_sysctl_handler,
27081da177e4SLinus Torvalds 	},
270906808b08SLee Schermerhorn #ifdef CONFIG_NUMA
271006808b08SLee Schermerhorn 	{
271106808b08SLee Schermerhorn 		.procname       = "nr_hugepages_mempolicy",
271206808b08SLee Schermerhorn 		.data           = NULL,
271306808b08SLee Schermerhorn 		.maxlen         = sizeof(unsigned long),
271406808b08SLee Schermerhorn 		.mode           = 0644,
271506808b08SLee Schermerhorn 		.proc_handler   = &hugetlb_mempolicy_sysctl_handler,
271606808b08SLee Schermerhorn 	},
27174518085eSKemi Wang 	{
27184518085eSKemi Wang 		.procname		= "numa_stat",
27194518085eSKemi Wang 		.data			= &sysctl_vm_numa_stat,
27204518085eSKemi Wang 		.maxlen			= sizeof(int),
27214518085eSKemi Wang 		.mode			= 0644,
27224518085eSKemi Wang 		.proc_handler	= sysctl_vm_numa_stat_handler,
2723eec4844fSMatteo Croce 		.extra1			= SYSCTL_ZERO,
2724eec4844fSMatteo Croce 		.extra2			= SYSCTL_ONE,
27254518085eSKemi Wang 	},
272606808b08SLee Schermerhorn #endif
27271da177e4SLinus Torvalds 	 {
27281da177e4SLinus Torvalds 		.procname	= "hugetlb_shm_group",
27291da177e4SLinus Torvalds 		.data		= &sysctl_hugetlb_shm_group,
27301da177e4SLinus Torvalds 		.maxlen		= sizeof(gid_t),
27311da177e4SLinus Torvalds 		.mode		= 0644,
27326d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
27331da177e4SLinus Torvalds 	 },
2734396faf03SMel Gorman 	{
2735d1c3fb1fSNishanth Aravamudan 		.procname	= "nr_overcommit_hugepages",
2736e5ff2159SAndi Kleen 		.data		= NULL,
2737e5ff2159SAndi Kleen 		.maxlen		= sizeof(unsigned long),
2738d1c3fb1fSNishanth Aravamudan 		.mode		= 0644,
27396d456111SEric W. Biederman 		.proc_handler	= hugetlb_overcommit_handler,
2740d1c3fb1fSNishanth Aravamudan 	},
27411da177e4SLinus Torvalds #endif
27421da177e4SLinus Torvalds 	{
27431da177e4SLinus Torvalds 		.procname	= "lowmem_reserve_ratio",
27441da177e4SLinus Torvalds 		.data		= &sysctl_lowmem_reserve_ratio,
27451da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
27461da177e4SLinus Torvalds 		.mode		= 0644,
27476d456111SEric W. Biederman 		.proc_handler	= lowmem_reserve_ratio_sysctl_handler,
27481da177e4SLinus Torvalds 	},
27491da177e4SLinus Torvalds 	{
27509d0243bcSAndrew Morton 		.procname	= "drop_caches",
27519d0243bcSAndrew Morton 		.data		= &sysctl_drop_caches,
27529d0243bcSAndrew Morton 		.maxlen		= sizeof(int),
2753204cb79aSJohannes Weiner 		.mode		= 0200,
27549d0243bcSAndrew Morton 		.proc_handler	= drop_caches_sysctl_handler,
2755eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
27565509a5d2SDave Hansen 		.extra2		= &four,
27579d0243bcSAndrew Morton 	},
275876ab0f53SMel Gorman #ifdef CONFIG_COMPACTION
275976ab0f53SMel Gorman 	{
276076ab0f53SMel Gorman 		.procname	= "compact_memory",
276176ab0f53SMel Gorman 		.data		= &sysctl_compact_memory,
276276ab0f53SMel Gorman 		.maxlen		= sizeof(int),
276376ab0f53SMel Gorman 		.mode		= 0200,
276476ab0f53SMel Gorman 		.proc_handler	= sysctl_compaction_handler,
276576ab0f53SMel Gorman 	},
27665e771905SMel Gorman 	{
27675e771905SMel Gorman 		.procname	= "extfrag_threshold",
27685e771905SMel Gorman 		.data		= &sysctl_extfrag_threshold,
27695e771905SMel Gorman 		.maxlen		= sizeof(int),
27705e771905SMel Gorman 		.mode		= 0644,
27716b7e5cadSMatthew Wilcox 		.proc_handler	= proc_dointvec_minmax,
27725e771905SMel Gorman 		.extra1		= &min_extfrag_threshold,
27735e771905SMel Gorman 		.extra2		= &max_extfrag_threshold,
27745e771905SMel Gorman 	},
27755bbe3547SEric B Munson 	{
27765bbe3547SEric B Munson 		.procname	= "compact_unevictable_allowed",
27775bbe3547SEric B Munson 		.data		= &sysctl_compact_unevictable_allowed,
27785bbe3547SEric B Munson 		.maxlen		= sizeof(int),
27795bbe3547SEric B Munson 		.mode		= 0644,
27806923aa0dSSebastian Andrzej Siewior 		.proc_handler	= proc_dointvec_minmax_warn_RT_change,
2781eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2782eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
27835bbe3547SEric B Munson 	},
27845e771905SMel Gorman 
278576ab0f53SMel Gorman #endif /* CONFIG_COMPACTION */
27869d0243bcSAndrew Morton 	{
27871da177e4SLinus Torvalds 		.procname	= "min_free_kbytes",
27881da177e4SLinus Torvalds 		.data		= &min_free_kbytes,
27891da177e4SLinus Torvalds 		.maxlen		= sizeof(min_free_kbytes),
27901da177e4SLinus Torvalds 		.mode		= 0644,
27916d456111SEric W. Biederman 		.proc_handler	= min_free_kbytes_sysctl_handler,
2792eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
27931da177e4SLinus Torvalds 	},
27948ad4b1fbSRohit Seth 	{
27951c30844dSMel Gorman 		.procname	= "watermark_boost_factor",
27961c30844dSMel Gorman 		.data		= &watermark_boost_factor,
27971c30844dSMel Gorman 		.maxlen		= sizeof(watermark_boost_factor),
27981c30844dSMel Gorman 		.mode		= 0644,
279926363af5SChristoph Hellwig 		.proc_handler	= proc_dointvec_minmax,
2800eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28011c30844dSMel Gorman 	},
28021c30844dSMel Gorman 	{
2803795ae7a0SJohannes Weiner 		.procname	= "watermark_scale_factor",
2804795ae7a0SJohannes Weiner 		.data		= &watermark_scale_factor,
2805795ae7a0SJohannes Weiner 		.maxlen		= sizeof(watermark_scale_factor),
2806795ae7a0SJohannes Weiner 		.mode		= 0644,
2807795ae7a0SJohannes Weiner 		.proc_handler	= watermark_scale_factor_sysctl_handler,
2808eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
2809795ae7a0SJohannes Weiner 		.extra2		= &one_thousand,
2810795ae7a0SJohannes Weiner 	},
2811795ae7a0SJohannes Weiner 	{
28128ad4b1fbSRohit Seth 		.procname	= "percpu_pagelist_fraction",
28138ad4b1fbSRohit Seth 		.data		= &percpu_pagelist_fraction,
28148ad4b1fbSRohit Seth 		.maxlen		= sizeof(percpu_pagelist_fraction),
28158ad4b1fbSRohit Seth 		.mode		= 0644,
28166d456111SEric W. Biederman 		.proc_handler	= percpu_pagelist_fraction_sysctl_handler,
2817eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28188ad4b1fbSRohit Seth 	},
28191da177e4SLinus Torvalds #ifdef CONFIG_MMU
28201da177e4SLinus Torvalds 	{
28211da177e4SLinus Torvalds 		.procname	= "max_map_count",
28221da177e4SLinus Torvalds 		.data		= &sysctl_max_map_count,
28231da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_max_map_count),
28241da177e4SLinus Torvalds 		.mode		= 0644,
28253e26120cSWANG Cong 		.proc_handler	= proc_dointvec_minmax,
2826eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28271da177e4SLinus Torvalds 	},
2828dd8632a1SPaul Mundt #else
2829dd8632a1SPaul Mundt 	{
2830dd8632a1SPaul Mundt 		.procname	= "nr_trim_pages",
2831dd8632a1SPaul Mundt 		.data		= &sysctl_nr_trim_pages,
2832dd8632a1SPaul Mundt 		.maxlen		= sizeof(sysctl_nr_trim_pages),
2833dd8632a1SPaul Mundt 		.mode		= 0644,
28346d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2835eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2836dd8632a1SPaul Mundt 	},
28371da177e4SLinus Torvalds #endif
28381da177e4SLinus Torvalds 	{
28391da177e4SLinus Torvalds 		.procname	= "laptop_mode",
28401da177e4SLinus Torvalds 		.data		= &laptop_mode,
28411da177e4SLinus Torvalds 		.maxlen		= sizeof(laptop_mode),
28421da177e4SLinus Torvalds 		.mode		= 0644,
28436d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_jiffies,
28441da177e4SLinus Torvalds 	},
28451da177e4SLinus Torvalds 	{
28461da177e4SLinus Torvalds 		.procname	= "block_dump",
28471da177e4SLinus Torvalds 		.data		= &block_dump,
28481da177e4SLinus Torvalds 		.maxlen		= sizeof(block_dump),
28491da177e4SLinus Torvalds 		.mode		= 0644,
28506d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2851eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28521da177e4SLinus Torvalds 	},
28531da177e4SLinus Torvalds 	{
28541da177e4SLinus Torvalds 		.procname	= "vfs_cache_pressure",
28551da177e4SLinus Torvalds 		.data		= &sysctl_vfs_cache_pressure,
28561da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
28571da177e4SLinus Torvalds 		.mode		= 0644,
28586d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2859eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28601da177e4SLinus Torvalds 	},
286167f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
286267f3977fSAlexandre Ghiti     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
28631da177e4SLinus Torvalds 	{
28641da177e4SLinus Torvalds 		.procname	= "legacy_va_layout",
28651da177e4SLinus Torvalds 		.data		= &sysctl_legacy_va_layout,
28661da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_legacy_va_layout),
28671da177e4SLinus Torvalds 		.mode		= 0644,
28686d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2869eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28701da177e4SLinus Torvalds 	},
28711da177e4SLinus Torvalds #endif
28721743660bSChristoph Lameter #ifdef CONFIG_NUMA
28731743660bSChristoph Lameter 	{
28741743660bSChristoph Lameter 		.procname	= "zone_reclaim_mode",
2875a5f5f91dSMel Gorman 		.data		= &node_reclaim_mode,
2876a5f5f91dSMel Gorman 		.maxlen		= sizeof(node_reclaim_mode),
28771743660bSChristoph Lameter 		.mode		= 0644,
28786d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2879eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28801743660bSChristoph Lameter 	},
28819614634fSChristoph Lameter 	{
28829614634fSChristoph Lameter 		.procname	= "min_unmapped_ratio",
28839614634fSChristoph Lameter 		.data		= &sysctl_min_unmapped_ratio,
28849614634fSChristoph Lameter 		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
28859614634fSChristoph Lameter 		.mode		= 0644,
28866d456111SEric W. Biederman 		.proc_handler	= sysctl_min_unmapped_ratio_sysctl_handler,
2887eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28889614634fSChristoph Lameter 		.extra2		= &one_hundred,
28899614634fSChristoph Lameter 	},
28900ff38490SChristoph Lameter 	{
28910ff38490SChristoph Lameter 		.procname	= "min_slab_ratio",
28920ff38490SChristoph Lameter 		.data		= &sysctl_min_slab_ratio,
28930ff38490SChristoph Lameter 		.maxlen		= sizeof(sysctl_min_slab_ratio),
28940ff38490SChristoph Lameter 		.mode		= 0644,
28956d456111SEric W. Biederman 		.proc_handler	= sysctl_min_slab_ratio_sysctl_handler,
2896eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28970ff38490SChristoph Lameter 		.extra2		= &one_hundred,
28980ff38490SChristoph Lameter 	},
28991743660bSChristoph Lameter #endif
290077461ab3SChristoph Lameter #ifdef CONFIG_SMP
290177461ab3SChristoph Lameter 	{
290277461ab3SChristoph Lameter 		.procname	= "stat_interval",
290377461ab3SChristoph Lameter 		.data		= &sysctl_stat_interval,
290477461ab3SChristoph Lameter 		.maxlen		= sizeof(sysctl_stat_interval),
290577461ab3SChristoph Lameter 		.mode		= 0644,
29066d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_jiffies,
290777461ab3SChristoph Lameter 	},
290852b6f46bSHugh Dickins 	{
290952b6f46bSHugh Dickins 		.procname	= "stat_refresh",
291052b6f46bSHugh Dickins 		.data		= NULL,
291152b6f46bSHugh Dickins 		.maxlen		= 0,
291252b6f46bSHugh Dickins 		.mode		= 0600,
291352b6f46bSHugh Dickins 		.proc_handler	= vmstat_refresh,
291452b6f46bSHugh Dickins 	},
291577461ab3SChristoph Lameter #endif
29166e141546SDavid Howells #ifdef CONFIG_MMU
2917ed032189SEric Paris 	{
2918ed032189SEric Paris 		.procname	= "mmap_min_addr",
2919788084abSEric Paris 		.data		= &dac_mmap_min_addr,
2920ed032189SEric Paris 		.maxlen		= sizeof(unsigned long),
2921ed032189SEric Paris 		.mode		= 0644,
29226d456111SEric W. Biederman 		.proc_handler	= mmap_min_addr_handler,
2923ed032189SEric Paris 	},
29246e141546SDavid Howells #endif
2925f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA
2926f0c0b2b8SKAMEZAWA Hiroyuki 	{
2927f0c0b2b8SKAMEZAWA Hiroyuki 		.procname	= "numa_zonelist_order",
2928f0c0b2b8SKAMEZAWA Hiroyuki 		.data		= &numa_zonelist_order,
2929f0c0b2b8SKAMEZAWA Hiroyuki 		.maxlen		= NUMA_ZONELIST_ORDER_LEN,
2930f0c0b2b8SKAMEZAWA Hiroyuki 		.mode		= 0644,
29316d456111SEric W. Biederman 		.proc_handler	= numa_zonelist_order_handler,
2932f0c0b2b8SKAMEZAWA Hiroyuki 	},
2933f0c0b2b8SKAMEZAWA Hiroyuki #endif
29342b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
29355c36e657SPaul Mundt    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
2936e6e5494cSIngo Molnar 	{
2937e6e5494cSIngo Molnar 		.procname	= "vdso_enabled",
29383d7ee969SAndy Lutomirski #ifdef CONFIG_X86_32
29393d7ee969SAndy Lutomirski 		.data		= &vdso32_enabled,
29403d7ee969SAndy Lutomirski 		.maxlen		= sizeof(vdso32_enabled),
29413d7ee969SAndy Lutomirski #else
2942e6e5494cSIngo Molnar 		.data		= &vdso_enabled,
2943e6e5494cSIngo Molnar 		.maxlen		= sizeof(vdso_enabled),
29443d7ee969SAndy Lutomirski #endif
2945e6e5494cSIngo Molnar 		.mode		= 0644,
29466d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2947eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2948e6e5494cSIngo Molnar 	},
2949e6e5494cSIngo Molnar #endif
2950195cf453SBron Gondwana #ifdef CONFIG_HIGHMEM
2951195cf453SBron Gondwana 	{
2952195cf453SBron Gondwana 		.procname	= "highmem_is_dirtyable",
2953195cf453SBron Gondwana 		.data		= &vm_highmem_is_dirtyable,
2954195cf453SBron Gondwana 		.maxlen		= sizeof(vm_highmem_is_dirtyable),
2955195cf453SBron Gondwana 		.mode		= 0644,
29566d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2957eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2958eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2959195cf453SBron Gondwana 	},
2960195cf453SBron Gondwana #endif
29616a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE
29626a46079cSAndi Kleen 	{
29636a46079cSAndi Kleen 		.procname	= "memory_failure_early_kill",
29646a46079cSAndi Kleen 		.data		= &sysctl_memory_failure_early_kill,
29656a46079cSAndi Kleen 		.maxlen		= sizeof(sysctl_memory_failure_early_kill),
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 	{
29726a46079cSAndi Kleen 		.procname	= "memory_failure_recovery",
29736a46079cSAndi Kleen 		.data		= &sysctl_memory_failure_recovery,
29746a46079cSAndi Kleen 		.maxlen		= sizeof(sysctl_memory_failure_recovery),
29756a46079cSAndi Kleen 		.mode		= 0644,
29766d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2977eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2978eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
29796a46079cSAndi Kleen 	},
29806a46079cSAndi Kleen #endif
2981c9b1d098SAndrew Shewmaker 	{
2982c9b1d098SAndrew Shewmaker 		.procname	= "user_reserve_kbytes",
2983c9b1d098SAndrew Shewmaker 		.data		= &sysctl_user_reserve_kbytes,
2984c9b1d098SAndrew Shewmaker 		.maxlen		= sizeof(sysctl_user_reserve_kbytes),
2985c9b1d098SAndrew Shewmaker 		.mode		= 0644,
2986c9b1d098SAndrew Shewmaker 		.proc_handler	= proc_doulongvec_minmax,
2987c9b1d098SAndrew Shewmaker 	},
29884eeab4f5SAndrew Shewmaker 	{
29894eeab4f5SAndrew Shewmaker 		.procname	= "admin_reserve_kbytes",
29904eeab4f5SAndrew Shewmaker 		.data		= &sysctl_admin_reserve_kbytes,
29914eeab4f5SAndrew Shewmaker 		.maxlen		= sizeof(sysctl_admin_reserve_kbytes),
29924eeab4f5SAndrew Shewmaker 		.mode		= 0644,
29934eeab4f5SAndrew Shewmaker 		.proc_handler	= proc_doulongvec_minmax,
29944eeab4f5SAndrew Shewmaker 	},
2995d07e2259SDaniel Cashman #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
2996d07e2259SDaniel Cashman 	{
2997d07e2259SDaniel Cashman 		.procname	= "mmap_rnd_bits",
2998d07e2259SDaniel Cashman 		.data		= &mmap_rnd_bits,
2999d07e2259SDaniel Cashman 		.maxlen		= sizeof(mmap_rnd_bits),
3000d07e2259SDaniel Cashman 		.mode		= 0600,
3001d07e2259SDaniel Cashman 		.proc_handler	= proc_dointvec_minmax,
3002d07e2259SDaniel Cashman 		.extra1		= (void *)&mmap_rnd_bits_min,
3003d07e2259SDaniel Cashman 		.extra2		= (void *)&mmap_rnd_bits_max,
3004d07e2259SDaniel Cashman 	},
3005d07e2259SDaniel Cashman #endif
3006d07e2259SDaniel Cashman #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
3007d07e2259SDaniel Cashman 	{
3008d07e2259SDaniel Cashman 		.procname	= "mmap_rnd_compat_bits",
3009d07e2259SDaniel Cashman 		.data		= &mmap_rnd_compat_bits,
3010d07e2259SDaniel Cashman 		.maxlen		= sizeof(mmap_rnd_compat_bits),
3011d07e2259SDaniel Cashman 		.mode		= 0600,
3012d07e2259SDaniel Cashman 		.proc_handler	= proc_dointvec_minmax,
3013d07e2259SDaniel Cashman 		.extra1		= (void *)&mmap_rnd_compat_bits_min,
3014d07e2259SDaniel Cashman 		.extra2		= (void *)&mmap_rnd_compat_bits_max,
3015d07e2259SDaniel Cashman 	},
3016d07e2259SDaniel Cashman #endif
3017cefdca0aSPeter Xu #ifdef CONFIG_USERFAULTFD
3018cefdca0aSPeter Xu 	{
3019cefdca0aSPeter Xu 		.procname	= "unprivileged_userfaultfd",
3020cefdca0aSPeter Xu 		.data		= &sysctl_unprivileged_userfaultfd,
3021cefdca0aSPeter Xu 		.maxlen		= sizeof(sysctl_unprivileged_userfaultfd),
3022cefdca0aSPeter Xu 		.mode		= 0644,
3023cefdca0aSPeter Xu 		.proc_handler	= proc_dointvec_minmax,
3024eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3025eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
3026cefdca0aSPeter Xu 	},
3027cefdca0aSPeter Xu #endif
30286fce56ecSEric W. Biederman 	{ }
30291da177e4SLinus Torvalds };
30301da177e4SLinus Torvalds 
3031d8217f07SEric W. Biederman static struct ctl_table fs_table[] = {
30321da177e4SLinus Torvalds 	{
30331da177e4SLinus Torvalds 		.procname	= "inode-nr",
30341da177e4SLinus Torvalds 		.data		= &inodes_stat,
30353942c07cSGlauber Costa 		.maxlen		= 2*sizeof(long),
30361da177e4SLinus Torvalds 		.mode		= 0444,
3037cffbc8aaSDave Chinner 		.proc_handler	= proc_nr_inodes,
30381da177e4SLinus Torvalds 	},
30391da177e4SLinus Torvalds 	{
30401da177e4SLinus Torvalds 		.procname	= "inode-state",
30411da177e4SLinus Torvalds 		.data		= &inodes_stat,
30423942c07cSGlauber Costa 		.maxlen		= 7*sizeof(long),
30431da177e4SLinus Torvalds 		.mode		= 0444,
3044cffbc8aaSDave Chinner 		.proc_handler	= proc_nr_inodes,
30451da177e4SLinus Torvalds 	},
30461da177e4SLinus Torvalds 	{
30471da177e4SLinus Torvalds 		.procname	= "file-nr",
30481da177e4SLinus Torvalds 		.data		= &files_stat,
3049518de9b3SEric Dumazet 		.maxlen		= sizeof(files_stat),
30501da177e4SLinus Torvalds 		.mode		= 0444,
30516d456111SEric W. Biederman 		.proc_handler	= proc_nr_files,
30521da177e4SLinus Torvalds 	},
30531da177e4SLinus Torvalds 	{
30541da177e4SLinus Torvalds 		.procname	= "file-max",
30551da177e4SLinus Torvalds 		.data		= &files_stat.max_files,
3056518de9b3SEric Dumazet 		.maxlen		= sizeof(files_stat.max_files),
30571da177e4SLinus Torvalds 		.mode		= 0644,
3058518de9b3SEric Dumazet 		.proc_handler	= proc_doulongvec_minmax,
30599002b214SWill Deacon 		.extra1		= &zero_ul,
306032a5ad9cSChristian Brauner 		.extra2		= &long_max,
30611da177e4SLinus Torvalds 	},
30621da177e4SLinus Torvalds 	{
30639cfe015aSEric Dumazet 		.procname	= "nr_open",
30649cfe015aSEric Dumazet 		.data		= &sysctl_nr_open,
30659b80a184SAlexey Dobriyan 		.maxlen		= sizeof(unsigned int),
30669cfe015aSEric Dumazet 		.mode		= 0644,
30676d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
3068eceea0b3SAl Viro 		.extra1		= &sysctl_nr_open_min,
3069eceea0b3SAl Viro 		.extra2		= &sysctl_nr_open_max,
30709cfe015aSEric Dumazet 	},
30719cfe015aSEric Dumazet 	{
30721da177e4SLinus Torvalds 		.procname	= "dentry-state",
30731da177e4SLinus Torvalds 		.data		= &dentry_stat,
30743942c07cSGlauber Costa 		.maxlen		= 6*sizeof(long),
30751da177e4SLinus Torvalds 		.mode		= 0444,
3076312d3ca8SChristoph Hellwig 		.proc_handler	= proc_nr_dentry,
30771da177e4SLinus Torvalds 	},
30781da177e4SLinus Torvalds 	{
30791da177e4SLinus Torvalds 		.procname	= "overflowuid",
30801da177e4SLinus Torvalds 		.data		= &fs_overflowuid,
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 	},
30871da177e4SLinus Torvalds 	{
30881da177e4SLinus Torvalds 		.procname	= "overflowgid",
30891da177e4SLinus Torvalds 		.data		= &fs_overflowgid,
30901da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
30911da177e4SLinus Torvalds 		.mode		= 0644,
30926d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
30931da177e4SLinus Torvalds 		.extra1		= &minolduid,
30941da177e4SLinus Torvalds 		.extra2		= &maxolduid,
30951da177e4SLinus Torvalds 	},
3096bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING
30971da177e4SLinus Torvalds 	{
30981da177e4SLinus Torvalds 		.procname	= "leases-enable",
30991da177e4SLinus Torvalds 		.data		= &leases_enable,
31001da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
31011da177e4SLinus Torvalds 		.mode		= 0644,
31026d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
31031da177e4SLinus Torvalds 	},
3104bfcd17a6SThomas Petazzoni #endif
31051da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY
31061da177e4SLinus Torvalds 	{
31071da177e4SLinus Torvalds 		.procname	= "dir-notify-enable",
31081da177e4SLinus Torvalds 		.data		= &dir_notify_enable,
31091da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
31101da177e4SLinus Torvalds 		.mode		= 0644,
31116d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
31121da177e4SLinus Torvalds 	},
31131da177e4SLinus Torvalds #endif
31141da177e4SLinus Torvalds #ifdef CONFIG_MMU
3115bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING
31161da177e4SLinus Torvalds 	{
31171da177e4SLinus Torvalds 		.procname	= "lease-break-time",
31181da177e4SLinus Torvalds 		.data		= &lease_break_time,
31191da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
31201da177e4SLinus Torvalds 		.mode		= 0644,
31216d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
31221da177e4SLinus Torvalds 	},
3123bfcd17a6SThomas Petazzoni #endif
3124ebf3f09cSThomas Petazzoni #ifdef CONFIG_AIO
31251da177e4SLinus Torvalds 	{
31261da177e4SLinus Torvalds 		.procname	= "aio-nr",
31271da177e4SLinus Torvalds 		.data		= &aio_nr,
31281da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_nr),
31291da177e4SLinus Torvalds 		.mode		= 0444,
31306d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
31311da177e4SLinus Torvalds 	},
31321da177e4SLinus Torvalds 	{
31331da177e4SLinus Torvalds 		.procname	= "aio-max-nr",
31341da177e4SLinus Torvalds 		.data		= &aio_max_nr,
31351da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_max_nr),
31361da177e4SLinus Torvalds 		.mode		= 0644,
31376d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
31381da177e4SLinus Torvalds 	},
3139ebf3f09cSThomas Petazzoni #endif /* CONFIG_AIO */
31402d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
31410399cb08SRobert Love 	{
31420399cb08SRobert Love 		.procname	= "inotify",
31430399cb08SRobert Love 		.mode		= 0555,
31440399cb08SRobert Love 		.child		= inotify_table,
31450399cb08SRobert Love 	},
31460399cb08SRobert Love #endif
31477ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL
31487ef9964eSDavide Libenzi 	{
31497ef9964eSDavide Libenzi 		.procname	= "epoll",
31507ef9964eSDavide Libenzi 		.mode		= 0555,
31517ef9964eSDavide Libenzi 		.child		= epoll_table,
31527ef9964eSDavide Libenzi 	},
31537ef9964eSDavide Libenzi #endif
31541da177e4SLinus Torvalds #endif
3155d6e71144SAlan Cox 	{
3156800179c9SKees Cook 		.procname	= "protected_symlinks",
3157800179c9SKees Cook 		.data		= &sysctl_protected_symlinks,
3158800179c9SKees Cook 		.maxlen		= sizeof(int),
3159800179c9SKees Cook 		.mode		= 0600,
3160800179c9SKees Cook 		.proc_handler	= proc_dointvec_minmax,
3161eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3162eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
3163800179c9SKees Cook 	},
3164800179c9SKees Cook 	{
3165800179c9SKees Cook 		.procname	= "protected_hardlinks",
3166800179c9SKees Cook 		.data		= &sysctl_protected_hardlinks,
3167800179c9SKees Cook 		.maxlen		= sizeof(int),
3168800179c9SKees Cook 		.mode		= 0600,
3169800179c9SKees Cook 		.proc_handler	= proc_dointvec_minmax,
3170eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3171eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
3172800179c9SKees Cook 	},
3173800179c9SKees Cook 	{
317430aba665SSalvatore Mesoraca 		.procname	= "protected_fifos",
317530aba665SSalvatore Mesoraca 		.data		= &sysctl_protected_fifos,
317630aba665SSalvatore Mesoraca 		.maxlen		= sizeof(int),
317730aba665SSalvatore Mesoraca 		.mode		= 0600,
317830aba665SSalvatore Mesoraca 		.proc_handler	= proc_dointvec_minmax,
3179eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
318030aba665SSalvatore Mesoraca 		.extra2		= &two,
318130aba665SSalvatore Mesoraca 	},
318230aba665SSalvatore Mesoraca 	{
318330aba665SSalvatore Mesoraca 		.procname	= "protected_regular",
318430aba665SSalvatore Mesoraca 		.data		= &sysctl_protected_regular,
318530aba665SSalvatore Mesoraca 		.maxlen		= sizeof(int),
318630aba665SSalvatore Mesoraca 		.mode		= 0600,
318730aba665SSalvatore Mesoraca 		.proc_handler	= proc_dointvec_minmax,
3188eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
318930aba665SSalvatore Mesoraca 		.extra2		= &two,
319030aba665SSalvatore Mesoraca 	},
319130aba665SSalvatore Mesoraca 	{
3192d6e71144SAlan Cox 		.procname	= "suid_dumpable",
3193d6e71144SAlan Cox 		.data		= &suid_dumpable,
3194d6e71144SAlan Cox 		.maxlen		= sizeof(int),
3195d6e71144SAlan Cox 		.mode		= 0644,
319654b50199SKees Cook 		.proc_handler	= proc_dointvec_minmax_coredump,
3197eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
31988e654fbaSMatthew Wilcox 		.extra2		= &two,
3199d6e71144SAlan Cox 	},
32002abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
32012abc26fcSEric W. Biederman 	{
32022abc26fcSEric W. Biederman 		.procname	= "binfmt_misc",
32032abc26fcSEric W. Biederman 		.mode		= 0555,
3204f9bd6733SEric W. Biederman 		.child		= sysctl_mount_point,
32052abc26fcSEric W. Biederman 	},
32062abc26fcSEric W. Biederman #endif
3207b492e95bSJens Axboe 	{
3208ff9da691SJens Axboe 		.procname	= "pipe-max-size",
3209ff9da691SJens Axboe 		.data		= &pipe_max_size,
321098159d97SJoe Lawrence 		.maxlen		= sizeof(pipe_max_size),
3211b492e95bSJens Axboe 		.mode		= 0644,
3212319e0a21SEric Biggers 		.proc_handler	= proc_dopipe_max_size,
3213b492e95bSJens Axboe 	},
3214759c0114SWilly Tarreau 	{
3215759c0114SWilly Tarreau 		.procname	= "pipe-user-pages-hard",
3216759c0114SWilly Tarreau 		.data		= &pipe_user_pages_hard,
3217759c0114SWilly Tarreau 		.maxlen		= sizeof(pipe_user_pages_hard),
3218759c0114SWilly Tarreau 		.mode		= 0644,
3219759c0114SWilly Tarreau 		.proc_handler	= proc_doulongvec_minmax,
3220759c0114SWilly Tarreau 	},
3221759c0114SWilly Tarreau 	{
3222759c0114SWilly Tarreau 		.procname	= "pipe-user-pages-soft",
3223759c0114SWilly Tarreau 		.data		= &pipe_user_pages_soft,
3224759c0114SWilly Tarreau 		.maxlen		= sizeof(pipe_user_pages_soft),
3225759c0114SWilly Tarreau 		.mode		= 0644,
3226759c0114SWilly Tarreau 		.proc_handler	= proc_doulongvec_minmax,
3227759c0114SWilly Tarreau 	},
3228d2921684SEric W. Biederman 	{
3229d2921684SEric W. Biederman 		.procname	= "mount-max",
3230d2921684SEric W. Biederman 		.data		= &sysctl_mount_max,
3231d2921684SEric W. Biederman 		.maxlen		= sizeof(unsigned int),
3232d2921684SEric W. Biederman 		.mode		= 0644,
3233d2921684SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
3234eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
3235d2921684SEric W. Biederman 	},
32366fce56ecSEric W. Biederman 	{ }
32371da177e4SLinus Torvalds };
32381da177e4SLinus Torvalds 
3239d8217f07SEric W. Biederman static struct ctl_table debug_table[] = {
32407ac57a89SCatalin Marinas #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
3241abd4f750SMasoud Asgharifard Sharbiani 	{
3242abd4f750SMasoud Asgharifard Sharbiani 		.procname	= "exception-trace",
3243abd4f750SMasoud Asgharifard Sharbiani 		.data		= &show_unhandled_signals,
3244abd4f750SMasoud Asgharifard Sharbiani 		.maxlen		= sizeof(int),
3245abd4f750SMasoud Asgharifard Sharbiani 		.mode		= 0644,
3246abd4f750SMasoud Asgharifard Sharbiani 		.proc_handler	= proc_dointvec
3247abd4f750SMasoud Asgharifard Sharbiani 	},
3248abd4f750SMasoud Asgharifard Sharbiani #endif
3249b2be84dfSMasami Hiramatsu #if defined(CONFIG_OPTPROBES)
3250b2be84dfSMasami Hiramatsu 	{
3251b2be84dfSMasami Hiramatsu 		.procname	= "kprobes-optimization",
3252b2be84dfSMasami Hiramatsu 		.data		= &sysctl_kprobes_optimization,
3253b2be84dfSMasami Hiramatsu 		.maxlen		= sizeof(int),
3254b2be84dfSMasami Hiramatsu 		.mode		= 0644,
3255b2be84dfSMasami Hiramatsu 		.proc_handler	= proc_kprobes_optimization_handler,
3256eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3257eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
3258b2be84dfSMasami Hiramatsu 	},
3259b2be84dfSMasami Hiramatsu #endif
32606fce56ecSEric W. Biederman 	{ }
32611da177e4SLinus Torvalds };
32621da177e4SLinus Torvalds 
3263d8217f07SEric W. Biederman static struct ctl_table dev_table[] = {
32646fce56ecSEric W. Biederman 	{ }
32651da177e4SLinus Torvalds };
32661da177e4SLinus Torvalds 
3267f461d2dcSChristoph Hellwig static struct ctl_table sysctl_base_table[] = {
3268f461d2dcSChristoph Hellwig 	{
3269f461d2dcSChristoph Hellwig 		.procname	= "kernel",
3270f461d2dcSChristoph Hellwig 		.mode		= 0555,
3271f461d2dcSChristoph Hellwig 		.child		= kern_table,
3272f461d2dcSChristoph Hellwig 	},
3273f461d2dcSChristoph Hellwig 	{
3274f461d2dcSChristoph Hellwig 		.procname	= "vm",
3275f461d2dcSChristoph Hellwig 		.mode		= 0555,
3276f461d2dcSChristoph Hellwig 		.child		= vm_table,
3277f461d2dcSChristoph Hellwig 	},
3278f461d2dcSChristoph Hellwig 	{
3279f461d2dcSChristoph Hellwig 		.procname	= "fs",
3280f461d2dcSChristoph Hellwig 		.mode		= 0555,
3281f461d2dcSChristoph Hellwig 		.child		= fs_table,
3282f461d2dcSChristoph Hellwig 	},
3283f461d2dcSChristoph Hellwig 	{
3284f461d2dcSChristoph Hellwig 		.procname	= "debug",
3285f461d2dcSChristoph Hellwig 		.mode		= 0555,
3286f461d2dcSChristoph Hellwig 		.child		= debug_table,
3287f461d2dcSChristoph Hellwig 	},
3288f461d2dcSChristoph Hellwig 	{
3289f461d2dcSChristoph Hellwig 		.procname	= "dev",
3290f461d2dcSChristoph Hellwig 		.mode		= 0555,
3291f461d2dcSChristoph Hellwig 		.child		= dev_table,
3292f461d2dcSChristoph Hellwig 	},
3293f461d2dcSChristoph Hellwig 	{ }
3294f461d2dcSChristoph Hellwig };
3295f461d2dcSChristoph Hellwig 
3296de4e83bdSEric W. Biederman int __init sysctl_init(void)
3297330d57fbSAl Viro {
3298fd4b616bSSteven Rostedt 	struct ctl_table_header *hdr;
3299fd4b616bSSteven Rostedt 
3300fd4b616bSSteven Rostedt 	hdr = register_sysctl_table(sysctl_base_table);
3301fd4b616bSSteven Rostedt 	kmemleak_not_leak(hdr);
3302330d57fbSAl Viro 	return 0;
3303f7e6ced4SAl Viro }
3304b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */
33051da177e4SLinus Torvalds /*
33061da177e4SLinus Torvalds  * No sense putting this after each symbol definition, twice,
33071da177e4SLinus Torvalds  * exception granted :-)
33081da177e4SLinus Torvalds  */
33091da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec);
3310e7d316a0SSubash Abhinov Kasiviswanathan EXPORT_SYMBOL(proc_douintvec);
33111da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies);
33121da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax);
331361d9b56aSLuis R. Rodriguez EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
33141da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
33151da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
33161da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring);
33171da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax);
33181da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
33190bc19985SStephen Suryaputra EXPORT_SYMBOL(proc_do_large_bitmap);
3320