xref: /openbmc/linux/kernel/sysctl.c (revision bce9332220bd677d83b19d21502776ad555a0e73)
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>
231da177e4SLinus Torvalds #include <linux/mm.h>
241da177e4SLinus Torvalds #include <linux/swap.h>
251da177e4SLinus Torvalds #include <linux/slab.h>
261da177e4SLinus Torvalds #include <linux/sysctl.h>
275a04cca6SAkinobu Mita #include <linux/bitmap.h>
28d33ed52dSDave Young #include <linux/signal.h>
29f39650deSAndy Shevchenko #include <linux/panic.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>
35b6459415SJakub Kicinski #include <linux/filter.h>
3662239ac2SAdrian Bunk #include <linux/fs.h>
371da177e4SLinus Torvalds #include <linux/init.h>
381da177e4SLinus Torvalds #include <linux/kernel.h>
390296b228SKay Sievers #include <linux/kobject.h>
4020380731SArnaldo Carvalho de Melo #include <linux/net.h>
411da177e4SLinus Torvalds #include <linux/sysrq.h>
421da177e4SLinus Torvalds #include <linux/highuid.h>
431da177e4SLinus Torvalds #include <linux/writeback.h>
443fff4c42SIngo Molnar #include <linux/ratelimit.h>
4576ab0f53SMel Gorman #include <linux/compaction.h>
461da177e4SLinus Torvalds #include <linux/hugetlb.h>
471da177e4SLinus Torvalds #include <linux/initrd.h>
480b77f5bfSDavid Howells #include <linux/key.h>
491da177e4SLinus Torvalds #include <linux/times.h>
501da177e4SLinus Torvalds #include <linux/limits.h>
511da177e4SLinus Torvalds #include <linux/dcache.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>
598e4228e1SDavid Rientjes #include <linux/oom.h>
6017f60a7dSEric Paris #include <linux/kmod.h>
6173efc039SDan Ballard #include <linux/capability.h>
6240401530SAl Viro #include <linux/binfmts.h>
63cf4aebc2SClark Williams #include <linux/sched/sysctl.h>
64d2921684SEric W. Biederman #include <linux/mount.h>
65cefdca0aSPeter Xu #include <linux/userfaultfd_k.h>
662374c09bSChristoph Hellwig #include <linux/pid.h>
671da177e4SLinus Torvalds 
687f2923c4SChristian Brauner #include "../lib/kstrtox.h"
697f2923c4SChristian Brauner 
707c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
711da177e4SLinus Torvalds #include <asm/processor.h>
721da177e4SLinus Torvalds 
7329cbc78bSAndi Kleen #ifdef CONFIG_X86
7429cbc78bSAndi Kleen #include <asm/nmi.h>
750741f4d2SChuck Ebbert #include <asm/stacktrace.h>
766e7c4025SIngo Molnar #include <asm/io.h>
7729cbc78bSAndi Kleen #endif
78d550bbd4SDavid Howells #ifdef CONFIG_SPARC
79d550bbd4SDavid Howells #include <asm/setup.h>
80d550bbd4SDavid Howells #endif
814f0e056fSDave Young #ifdef CONFIG_RT_MUTEXES
824f0e056fSDave Young #include <linux/rtmutex.h>
834f0e056fSDave Young #endif
84504d7cf1SDon Zickus 
85b13bc7cbSLiu Shixin /* shared constants to be used in various sysctls */
86b13bc7cbSLiu Shixin const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 };
87b13bc7cbSLiu Shixin EXPORT_SYMBOL(sysctl_vals);
88b13bc7cbSLiu Shixin 
89b13bc7cbSLiu Shixin const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX };
90b13bc7cbSLiu Shixin EXPORT_SYMBOL_GPL(sysctl_long_vals);
91b13bc7cbSLiu Shixin 
921da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL)
931da177e4SLinus Torvalds 
94c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and maximum */
95c4f3b63fSRavikiran G Thirumalai 
96c5dfd78eSArnaldo Carvalho de Melo #ifdef CONFIG_PERF_EVENTS
97d73840ecSXiaoming Ni static const int six_hundred_forty_kb = 640 * 1024;
98c5dfd78eSArnaldo Carvalho de Melo #endif
99c4f3b63fSRavikiran G Thirumalai 
1009e4a5bdaSAndrea Righi 
101f628867dSStephen Kitt static const int ngroups_max = NGROUPS_MAX;
10273efc039SDan Ballard static const int cap_last_cap = CAP_LAST_CAP;
1031da177e4SLinus Torvalds 
104d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
105f4aacea2SKees Cook 
106a19ac337SLuis R. Rodriguez /**
107a19ac337SLuis R. Rodriguez  * enum sysctl_writes_mode - supported sysctl write modes
108a19ac337SLuis R. Rodriguez  *
109a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
110a19ac337SLuis R. Rodriguez  *	to be written, and multiple writes on the same sysctl file descriptor
111a19ac337SLuis R. Rodriguez  *	will rewrite the sysctl value, regardless of file position. No warning
112a19ac337SLuis R. Rodriguez  *	is issued when the initial position is not 0.
113a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
114a19ac337SLuis R. Rodriguez  *	not 0.
115a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
116a19ac337SLuis R. Rodriguez  *	file position 0 and the value must be fully contained in the buffer
117a19ac337SLuis R. Rodriguez  *	sent to the write syscall. If dealing with strings respect the file
118a19ac337SLuis R. Rodriguez  *	position, but restrict this to the max length of the buffer, anything
11965f50f25SWeitao Hou  *	passed the max length will be ignored. Multiple writes will append
120a19ac337SLuis R. Rodriguez  *	to the buffer.
121a19ac337SLuis R. Rodriguez  *
122a19ac337SLuis R. Rodriguez  * These write modes control how current file position affects the behavior of
123a19ac337SLuis R. Rodriguez  * updating sysctl values through the proc interface on each write.
124a19ac337SLuis R. Rodriguez  */
125a19ac337SLuis R. Rodriguez enum sysctl_writes_mode {
126a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_LEGACY		= -1,
127a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_WARN		= 0,
128a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_STRICT		= 1,
129a19ac337SLuis R. Rodriguez };
130f4aacea2SKees Cook 
131a19ac337SLuis R. Rodriguez static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
132f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */
133ceb18132SLuis R. Rodriguez 
13467f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
13567f3977fSAlexandre Ghiti     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
1361da177e4SLinus Torvalds int sysctl_legacy_va_layout;
1371da177e4SLinus Torvalds #endif
1381da177e4SLinus Torvalds 
139f461d2dcSChristoph Hellwig #endif /* CONFIG_SYSCTL */
140f461d2dcSChristoph Hellwig 
141f461d2dcSChristoph Hellwig /*
142f461d2dcSChristoph Hellwig  * /proc/sys support
143f461d2dcSChristoph Hellwig  */
144f461d2dcSChristoph Hellwig 
145f461d2dcSChristoph Hellwig #ifdef CONFIG_PROC_SYSCTL
146f461d2dcSChristoph Hellwig 
147f461d2dcSChristoph Hellwig static int _proc_do_string(char *data, int maxlen, int write,
14832927393SChristoph Hellwig 		char *buffer, size_t *lenp, loff_t *ppos)
149f461d2dcSChristoph Hellwig {
150f461d2dcSChristoph Hellwig 	size_t len;
15132927393SChristoph Hellwig 	char c, *p;
152f461d2dcSChristoph Hellwig 
153f461d2dcSChristoph Hellwig 	if (!data || !maxlen || !*lenp) {
154f461d2dcSChristoph Hellwig 		*lenp = 0;
155f461d2dcSChristoph Hellwig 		return 0;
156f461d2dcSChristoph Hellwig 	}
157f461d2dcSChristoph Hellwig 
158f461d2dcSChristoph Hellwig 	if (write) {
159f461d2dcSChristoph Hellwig 		if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
160f461d2dcSChristoph Hellwig 			/* Only continue writes not past the end of buffer. */
161f461d2dcSChristoph Hellwig 			len = strlen(data);
162f461d2dcSChristoph Hellwig 			if (len > maxlen - 1)
163f461d2dcSChristoph Hellwig 				len = maxlen - 1;
164f461d2dcSChristoph Hellwig 
165f461d2dcSChristoph Hellwig 			if (*ppos > len)
166f461d2dcSChristoph Hellwig 				return 0;
167f461d2dcSChristoph Hellwig 			len = *ppos;
168f461d2dcSChristoph Hellwig 		} else {
169f461d2dcSChristoph Hellwig 			/* Start writing from beginning of buffer. */
170f461d2dcSChristoph Hellwig 			len = 0;
171f461d2dcSChristoph Hellwig 		}
172f461d2dcSChristoph Hellwig 
173f461d2dcSChristoph Hellwig 		*ppos += *lenp;
174f461d2dcSChristoph Hellwig 		p = buffer;
175f461d2dcSChristoph Hellwig 		while ((p - buffer) < *lenp && len < maxlen - 1) {
17632927393SChristoph Hellwig 			c = *(p++);
177f461d2dcSChristoph Hellwig 			if (c == 0 || c == '\n')
178f461d2dcSChristoph Hellwig 				break;
179f461d2dcSChristoph Hellwig 			data[len++] = c;
180f461d2dcSChristoph Hellwig 		}
181f461d2dcSChristoph Hellwig 		data[len] = 0;
182f461d2dcSChristoph Hellwig 	} else {
183f461d2dcSChristoph Hellwig 		len = strlen(data);
184f461d2dcSChristoph Hellwig 		if (len > maxlen)
185f461d2dcSChristoph Hellwig 			len = maxlen;
186f461d2dcSChristoph Hellwig 
187f461d2dcSChristoph Hellwig 		if (*ppos > len) {
188f461d2dcSChristoph Hellwig 			*lenp = 0;
189f461d2dcSChristoph Hellwig 			return 0;
190f461d2dcSChristoph Hellwig 		}
191f461d2dcSChristoph Hellwig 
192f461d2dcSChristoph Hellwig 		data += *ppos;
193f461d2dcSChristoph Hellwig 		len  -= *ppos;
194f461d2dcSChristoph Hellwig 
195f461d2dcSChristoph Hellwig 		if (len > *lenp)
196f461d2dcSChristoph Hellwig 			len = *lenp;
197f461d2dcSChristoph Hellwig 		if (len)
19832927393SChristoph Hellwig 			memcpy(buffer, data, len);
199f461d2dcSChristoph Hellwig 		if (len < *lenp) {
20032927393SChristoph Hellwig 			buffer[len] = '\n';
201f461d2dcSChristoph Hellwig 			len++;
202f461d2dcSChristoph Hellwig 		}
203f461d2dcSChristoph Hellwig 		*lenp = len;
204f461d2dcSChristoph Hellwig 		*ppos += len;
205f461d2dcSChristoph Hellwig 	}
206f461d2dcSChristoph Hellwig 	return 0;
207f461d2dcSChristoph Hellwig }
208f461d2dcSChristoph Hellwig 
209f461d2dcSChristoph Hellwig static void warn_sysctl_write(struct ctl_table *table)
210f461d2dcSChristoph Hellwig {
211f461d2dcSChristoph Hellwig 	pr_warn_once("%s wrote to %s when file position was not 0!\n"
212f461d2dcSChristoph Hellwig 		"This will not be supported in the future. To silence this\n"
213f461d2dcSChristoph Hellwig 		"warning, set kernel.sysctl_writes_strict = -1\n",
214f461d2dcSChristoph Hellwig 		current->comm, table->procname);
215f461d2dcSChristoph Hellwig }
216f461d2dcSChristoph Hellwig 
217f461d2dcSChristoph Hellwig /**
218f461d2dcSChristoph Hellwig  * proc_first_pos_non_zero_ignore - check if first position is allowed
219f461d2dcSChristoph Hellwig  * @ppos: file position
220f461d2dcSChristoph Hellwig  * @table: the sysctl table
221f461d2dcSChristoph Hellwig  *
222f461d2dcSChristoph Hellwig  * Returns true if the first position is non-zero and the sysctl_writes_strict
223f461d2dcSChristoph Hellwig  * mode indicates this is not allowed for numeric input types. String proc
224f461d2dcSChristoph Hellwig  * handlers can ignore the return value.
225f461d2dcSChristoph Hellwig  */
226f461d2dcSChristoph Hellwig static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
227f461d2dcSChristoph Hellwig 					   struct ctl_table *table)
228f461d2dcSChristoph Hellwig {
229f461d2dcSChristoph Hellwig 	if (!*ppos)
230f461d2dcSChristoph Hellwig 		return false;
231f461d2dcSChristoph Hellwig 
232f461d2dcSChristoph Hellwig 	switch (sysctl_writes_strict) {
233f461d2dcSChristoph Hellwig 	case SYSCTL_WRITES_STRICT:
234f461d2dcSChristoph Hellwig 		return true;
235f461d2dcSChristoph Hellwig 	case SYSCTL_WRITES_WARN:
236f461d2dcSChristoph Hellwig 		warn_sysctl_write(table);
237f461d2dcSChristoph Hellwig 		return false;
238f461d2dcSChristoph Hellwig 	default:
239f461d2dcSChristoph Hellwig 		return false;
240f461d2dcSChristoph Hellwig 	}
241f461d2dcSChristoph Hellwig }
242f461d2dcSChristoph Hellwig 
243f461d2dcSChristoph Hellwig /**
244f461d2dcSChristoph Hellwig  * proc_dostring - read a string sysctl
245f461d2dcSChristoph Hellwig  * @table: the sysctl table
246f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
247f461d2dcSChristoph Hellwig  * @buffer: the user buffer
248f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
249f461d2dcSChristoph Hellwig  * @ppos: file position
250f461d2dcSChristoph Hellwig  *
251f461d2dcSChristoph Hellwig  * Reads/writes a string from/to the user buffer. If the kernel
252f461d2dcSChristoph Hellwig  * buffer provided is not large enough to hold the string, the
253f461d2dcSChristoph Hellwig  * string is truncated. The copied string is %NULL-terminated.
254f461d2dcSChristoph Hellwig  * If the string is being read by the user process, it is copied
255f461d2dcSChristoph Hellwig  * and a newline '\n' is added. It is truncated if the buffer is
256f461d2dcSChristoph Hellwig  * not large enough.
257f461d2dcSChristoph Hellwig  *
258f461d2dcSChristoph Hellwig  * Returns 0 on success.
259f461d2dcSChristoph Hellwig  */
260f461d2dcSChristoph Hellwig int proc_dostring(struct ctl_table *table, int write,
26132927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
262f461d2dcSChristoph Hellwig {
263f461d2dcSChristoph Hellwig 	if (write)
264f461d2dcSChristoph Hellwig 		proc_first_pos_non_zero_ignore(ppos, table);
265f461d2dcSChristoph Hellwig 
26632927393SChristoph Hellwig 	return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
26732927393SChristoph Hellwig 			ppos);
268f461d2dcSChristoph Hellwig }
269f461d2dcSChristoph Hellwig 
270*bce93322SLinus Torvalds static void proc_skip_spaces(char **buf, size_t *size)
271f461d2dcSChristoph Hellwig {
272*bce93322SLinus Torvalds 	while (*size) {
273*bce93322SLinus Torvalds 		if (!isspace(**buf))
274*bce93322SLinus Torvalds 			break;
275*bce93322SLinus Torvalds 		(*size)--;
276*bce93322SLinus Torvalds 		(*buf)++;
277*bce93322SLinus Torvalds 	}
278f461d2dcSChristoph Hellwig }
279f461d2dcSChristoph Hellwig 
280f461d2dcSChristoph Hellwig static void proc_skip_char(char **buf, size_t *size, const char v)
281f461d2dcSChristoph Hellwig {
282f461d2dcSChristoph Hellwig 	while (*size) {
283f461d2dcSChristoph Hellwig 		if (**buf != v)
284f461d2dcSChristoph Hellwig 			break;
285f461d2dcSChristoph Hellwig 		(*size)--;
286f461d2dcSChristoph Hellwig 		(*buf)++;
287f461d2dcSChristoph Hellwig 	}
288f461d2dcSChristoph Hellwig }
289f461d2dcSChristoph Hellwig 
290f461d2dcSChristoph Hellwig /**
291f461d2dcSChristoph Hellwig  * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
292f461d2dcSChristoph Hellwig  *                   fail on overflow
293f461d2dcSChristoph Hellwig  *
294f461d2dcSChristoph Hellwig  * @cp: kernel buffer containing the string to parse
295f461d2dcSChristoph Hellwig  * @endp: pointer to store the trailing characters
296f461d2dcSChristoph Hellwig  * @base: the base to use
297f461d2dcSChristoph Hellwig  * @res: where the parsed integer will be stored
298f461d2dcSChristoph Hellwig  *
299f461d2dcSChristoph Hellwig  * In case of success 0 is returned and @res will contain the parsed integer,
300f461d2dcSChristoph Hellwig  * @endp will hold any trailing characters.
301f461d2dcSChristoph Hellwig  * This function will fail the parse on overflow. If there wasn't an overflow
302f461d2dcSChristoph Hellwig  * the function will defer the decision what characters count as invalid to the
303f461d2dcSChristoph Hellwig  * caller.
304f461d2dcSChristoph Hellwig  */
305f461d2dcSChristoph Hellwig static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
306f461d2dcSChristoph Hellwig 			   unsigned long *res)
307f461d2dcSChristoph Hellwig {
308f461d2dcSChristoph Hellwig 	unsigned long long result;
309f461d2dcSChristoph Hellwig 	unsigned int rv;
310f461d2dcSChristoph Hellwig 
311f461d2dcSChristoph Hellwig 	cp = _parse_integer_fixup_radix(cp, &base);
312f461d2dcSChristoph Hellwig 	rv = _parse_integer(cp, base, &result);
313f461d2dcSChristoph Hellwig 	if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
314f461d2dcSChristoph Hellwig 		return -ERANGE;
315f461d2dcSChristoph Hellwig 
316f461d2dcSChristoph Hellwig 	cp += rv;
317f461d2dcSChristoph Hellwig 
318f461d2dcSChristoph Hellwig 	if (endp)
319f461d2dcSChristoph Hellwig 		*endp = (char *)cp;
320f461d2dcSChristoph Hellwig 
321f461d2dcSChristoph Hellwig 	*res = (unsigned long)result;
322f461d2dcSChristoph Hellwig 	return 0;
323f461d2dcSChristoph Hellwig }
324f461d2dcSChristoph Hellwig 
325f461d2dcSChristoph Hellwig #define TMPBUFLEN 22
326f461d2dcSChristoph Hellwig /**
327f461d2dcSChristoph Hellwig  * proc_get_long - reads an ASCII formatted integer from a user buffer
328f461d2dcSChristoph Hellwig  *
329f461d2dcSChristoph Hellwig  * @buf: a kernel buffer
330f461d2dcSChristoph Hellwig  * @size: size of the kernel buffer
331f461d2dcSChristoph Hellwig  * @val: this is where the number will be stored
332f461d2dcSChristoph Hellwig  * @neg: set to %TRUE if number is negative
333f461d2dcSChristoph Hellwig  * @perm_tr: a vector which contains the allowed trailers
334f461d2dcSChristoph Hellwig  * @perm_tr_len: size of the perm_tr vector
335f461d2dcSChristoph Hellwig  * @tr: pointer to store the trailer character
336f461d2dcSChristoph Hellwig  *
337f461d2dcSChristoph Hellwig  * In case of success %0 is returned and @buf and @size are updated with
338f461d2dcSChristoph Hellwig  * the amount of bytes read. If @tr is non-NULL and a trailing
339f461d2dcSChristoph Hellwig  * character exists (size is non-zero after returning from this
340f461d2dcSChristoph Hellwig  * function), @tr is updated with the trailing character.
341f461d2dcSChristoph Hellwig  */
342f461d2dcSChristoph Hellwig static int proc_get_long(char **buf, size_t *size,
343f461d2dcSChristoph Hellwig 			  unsigned long *val, bool *neg,
344f461d2dcSChristoph Hellwig 			  const char *perm_tr, unsigned perm_tr_len, char *tr)
345f461d2dcSChristoph Hellwig {
346f461d2dcSChristoph Hellwig 	char *p, tmp[TMPBUFLEN];
347e6cfaf34SLinus Torvalds 	ssize_t len = *size;
348f461d2dcSChristoph Hellwig 
349e6cfaf34SLinus Torvalds 	if (len <= 0)
350f461d2dcSChristoph Hellwig 		return -EINVAL;
351f461d2dcSChristoph Hellwig 
352f461d2dcSChristoph Hellwig 	if (len > TMPBUFLEN - 1)
353f461d2dcSChristoph Hellwig 		len = TMPBUFLEN - 1;
354f461d2dcSChristoph Hellwig 
355f461d2dcSChristoph Hellwig 	memcpy(tmp, *buf, len);
356f461d2dcSChristoph Hellwig 
357f461d2dcSChristoph Hellwig 	tmp[len] = 0;
358f461d2dcSChristoph Hellwig 	p = tmp;
359f461d2dcSChristoph Hellwig 	if (*p == '-' && *size > 1) {
360f461d2dcSChristoph Hellwig 		*neg = true;
361f461d2dcSChristoph Hellwig 		p++;
362f461d2dcSChristoph Hellwig 	} else
363f461d2dcSChristoph Hellwig 		*neg = false;
364f461d2dcSChristoph Hellwig 	if (!isdigit(*p))
365f461d2dcSChristoph Hellwig 		return -EINVAL;
366f461d2dcSChristoph Hellwig 
367f461d2dcSChristoph Hellwig 	if (strtoul_lenient(p, &p, 0, val))
368f461d2dcSChristoph Hellwig 		return -EINVAL;
369f461d2dcSChristoph Hellwig 
370f461d2dcSChristoph Hellwig 	len = p - tmp;
371f461d2dcSChristoph Hellwig 
372f461d2dcSChristoph Hellwig 	/* We don't know if the next char is whitespace thus we may accept
373f461d2dcSChristoph Hellwig 	 * invalid integers (e.g. 1234...a) or two integers instead of one
374f461d2dcSChristoph Hellwig 	 * (e.g. 123...1). So lets not allow such large numbers. */
375f461d2dcSChristoph Hellwig 	if (len == TMPBUFLEN - 1)
376f461d2dcSChristoph Hellwig 		return -EINVAL;
377f461d2dcSChristoph Hellwig 
378f461d2dcSChristoph Hellwig 	if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
379f461d2dcSChristoph Hellwig 		return -EINVAL;
380f461d2dcSChristoph Hellwig 
381f461d2dcSChristoph Hellwig 	if (tr && (len < *size))
382f461d2dcSChristoph Hellwig 		*tr = *p;
383f461d2dcSChristoph Hellwig 
384f461d2dcSChristoph Hellwig 	*buf += len;
385f461d2dcSChristoph Hellwig 	*size -= len;
386f461d2dcSChristoph Hellwig 
387f461d2dcSChristoph Hellwig 	return 0;
388f461d2dcSChristoph Hellwig }
389f461d2dcSChristoph Hellwig 
390f461d2dcSChristoph Hellwig /**
391f461d2dcSChristoph Hellwig  * proc_put_long - converts an integer to a decimal ASCII formatted string
392f461d2dcSChristoph Hellwig  *
393f461d2dcSChristoph Hellwig  * @buf: the user buffer
394f461d2dcSChristoph Hellwig  * @size: the size of the user buffer
395f461d2dcSChristoph Hellwig  * @val: the integer to be converted
396f461d2dcSChristoph Hellwig  * @neg: sign of the number, %TRUE for negative
397f461d2dcSChristoph Hellwig  *
39832927393SChristoph Hellwig  * In case of success @buf and @size are updated with the amount of bytes
39932927393SChristoph Hellwig  * written.
400f461d2dcSChristoph Hellwig  */
40132927393SChristoph Hellwig static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
402f461d2dcSChristoph Hellwig {
403f461d2dcSChristoph Hellwig 	int len;
404f461d2dcSChristoph Hellwig 	char tmp[TMPBUFLEN], *p = tmp;
405f461d2dcSChristoph Hellwig 
406f461d2dcSChristoph Hellwig 	sprintf(p, "%s%lu", neg ? "-" : "", val);
407f461d2dcSChristoph Hellwig 	len = strlen(tmp);
408f461d2dcSChristoph Hellwig 	if (len > *size)
409f461d2dcSChristoph Hellwig 		len = *size;
41032927393SChristoph Hellwig 	memcpy(*buf, tmp, len);
411f461d2dcSChristoph Hellwig 	*size -= len;
412f461d2dcSChristoph Hellwig 	*buf += len;
413f461d2dcSChristoph Hellwig }
414f461d2dcSChristoph Hellwig #undef TMPBUFLEN
415f461d2dcSChristoph Hellwig 
41632927393SChristoph Hellwig static void proc_put_char(void **buf, size_t *size, char c)
417f461d2dcSChristoph Hellwig {
418f461d2dcSChristoph Hellwig 	if (*size) {
41932927393SChristoph Hellwig 		char **buffer = (char **)buf;
42032927393SChristoph Hellwig 		**buffer = c;
42132927393SChristoph Hellwig 
42232927393SChristoph Hellwig 		(*size)--;
42332927393SChristoph Hellwig 		(*buffer)++;
424f461d2dcSChristoph Hellwig 		*buf = *buffer;
425f461d2dcSChristoph Hellwig 	}
426f461d2dcSChristoph Hellwig }
427f461d2dcSChristoph Hellwig 
428a2071573SJia He static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp,
429a2071573SJia He 				int *valp,
430a2071573SJia He 				int write, void *data)
431a2071573SJia He {
432a2071573SJia He 	if (write) {
433a2071573SJia He 		*(bool *)valp = *lvalp;
434a2071573SJia He 	} else {
435a2071573SJia He 		int val = *(bool *)valp;
436a2071573SJia He 
437a2071573SJia He 		*lvalp = (unsigned long)val;
438a2071573SJia He 		*negp = false;
439a2071573SJia He 	}
440a2071573SJia He 	return 0;
441a2071573SJia He }
442a2071573SJia He 
443f461d2dcSChristoph Hellwig static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
444f461d2dcSChristoph Hellwig 				 int *valp,
445f461d2dcSChristoph Hellwig 				 int write, void *data)
446f461d2dcSChristoph Hellwig {
447f461d2dcSChristoph Hellwig 	if (write) {
448f461d2dcSChristoph Hellwig 		if (*negp) {
449f461d2dcSChristoph Hellwig 			if (*lvalp > (unsigned long) INT_MAX + 1)
450f461d2dcSChristoph Hellwig 				return -EINVAL;
4511f1be04bSKuniyuki Iwashima 			WRITE_ONCE(*valp, -*lvalp);
452f461d2dcSChristoph Hellwig 		} else {
453f461d2dcSChristoph Hellwig 			if (*lvalp > (unsigned long) INT_MAX)
454f461d2dcSChristoph Hellwig 				return -EINVAL;
4551f1be04bSKuniyuki Iwashima 			WRITE_ONCE(*valp, *lvalp);
456f461d2dcSChristoph Hellwig 		}
457f461d2dcSChristoph Hellwig 	} else {
4581f1be04bSKuniyuki Iwashima 		int val = READ_ONCE(*valp);
459f461d2dcSChristoph Hellwig 		if (val < 0) {
460f461d2dcSChristoph Hellwig 			*negp = true;
461f461d2dcSChristoph Hellwig 			*lvalp = -(unsigned long)val;
462f461d2dcSChristoph Hellwig 		} else {
463f461d2dcSChristoph Hellwig 			*negp = false;
464f461d2dcSChristoph Hellwig 			*lvalp = (unsigned long)val;
465f461d2dcSChristoph Hellwig 		}
466f461d2dcSChristoph Hellwig 	}
467f461d2dcSChristoph Hellwig 	return 0;
468f461d2dcSChristoph Hellwig }
469f461d2dcSChristoph Hellwig 
470f461d2dcSChristoph Hellwig static int do_proc_douintvec_conv(unsigned long *lvalp,
471f461d2dcSChristoph Hellwig 				  unsigned int *valp,
472f461d2dcSChristoph Hellwig 				  int write, void *data)
473f461d2dcSChristoph Hellwig {
474f461d2dcSChristoph Hellwig 	if (write) {
475f461d2dcSChristoph Hellwig 		if (*lvalp > UINT_MAX)
476f461d2dcSChristoph Hellwig 			return -EINVAL;
4774762b532SKuniyuki Iwashima 		WRITE_ONCE(*valp, *lvalp);
478f461d2dcSChristoph Hellwig 	} else {
4794762b532SKuniyuki Iwashima 		unsigned int val = READ_ONCE(*valp);
480f461d2dcSChristoph Hellwig 		*lvalp = (unsigned long)val;
481f461d2dcSChristoph Hellwig 	}
482f461d2dcSChristoph Hellwig 	return 0;
483f461d2dcSChristoph Hellwig }
484f461d2dcSChristoph Hellwig 
485f461d2dcSChristoph Hellwig static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
486f461d2dcSChristoph Hellwig 
487f461d2dcSChristoph Hellwig static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
48832927393SChristoph Hellwig 		  int write, void *buffer,
489f461d2dcSChristoph Hellwig 		  size_t *lenp, loff_t *ppos,
490f461d2dcSChristoph Hellwig 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
491f461d2dcSChristoph Hellwig 			      int write, void *data),
492f461d2dcSChristoph Hellwig 		  void *data)
493f461d2dcSChristoph Hellwig {
494f461d2dcSChristoph Hellwig 	int *i, vleft, first = 1, err = 0;
495f461d2dcSChristoph Hellwig 	size_t left;
49632927393SChristoph Hellwig 	char *p;
497f461d2dcSChristoph Hellwig 
498f461d2dcSChristoph Hellwig 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
499f461d2dcSChristoph Hellwig 		*lenp = 0;
500f461d2dcSChristoph Hellwig 		return 0;
501f461d2dcSChristoph Hellwig 	}
502f461d2dcSChristoph Hellwig 
503f461d2dcSChristoph Hellwig 	i = (int *) tbl_data;
504f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(*i);
505f461d2dcSChristoph Hellwig 	left = *lenp;
506f461d2dcSChristoph Hellwig 
507f461d2dcSChristoph Hellwig 	if (!conv)
508f461d2dcSChristoph Hellwig 		conv = do_proc_dointvec_conv;
509f461d2dcSChristoph Hellwig 
510f461d2dcSChristoph Hellwig 	if (write) {
511f461d2dcSChristoph Hellwig 		if (proc_first_pos_non_zero_ignore(ppos, table))
512f461d2dcSChristoph Hellwig 			goto out;
513f461d2dcSChristoph Hellwig 
514f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1)
515f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
51632927393SChristoph Hellwig 		p = buffer;
517f461d2dcSChristoph Hellwig 	}
518f461d2dcSChristoph Hellwig 
519f461d2dcSChristoph Hellwig 	for (; left && vleft--; i++, first=0) {
520f461d2dcSChristoph Hellwig 		unsigned long lval;
521f461d2dcSChristoph Hellwig 		bool neg;
522f461d2dcSChristoph Hellwig 
523f461d2dcSChristoph Hellwig 		if (write) {
524*bce93322SLinus Torvalds 			proc_skip_spaces(&p, &left);
525f461d2dcSChristoph Hellwig 
526f461d2dcSChristoph Hellwig 			if (!left)
527f461d2dcSChristoph Hellwig 				break;
528f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &lval, &neg,
529f461d2dcSChristoph Hellwig 					     proc_wspace_sep,
530f461d2dcSChristoph Hellwig 					     sizeof(proc_wspace_sep), NULL);
531f461d2dcSChristoph Hellwig 			if (err)
532f461d2dcSChristoph Hellwig 				break;
533f461d2dcSChristoph Hellwig 			if (conv(&neg, &lval, i, 1, data)) {
534f461d2dcSChristoph Hellwig 				err = -EINVAL;
535f461d2dcSChristoph Hellwig 				break;
536f461d2dcSChristoph Hellwig 			}
537f461d2dcSChristoph Hellwig 		} else {
538f461d2dcSChristoph Hellwig 			if (conv(&neg, &lval, i, 0, data)) {
539f461d2dcSChristoph Hellwig 				err = -EINVAL;
540f461d2dcSChristoph Hellwig 				break;
541f461d2dcSChristoph Hellwig 			}
542f461d2dcSChristoph Hellwig 			if (!first)
54332927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '\t');
54432927393SChristoph Hellwig 			proc_put_long(&buffer, &left, lval, neg);
545f461d2dcSChristoph Hellwig 		}
546f461d2dcSChristoph Hellwig 	}
547f461d2dcSChristoph Hellwig 
548f461d2dcSChristoph Hellwig 	if (!write && !first && left && !err)
54932927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
550f461d2dcSChristoph Hellwig 	if (write && !err && left)
551*bce93322SLinus Torvalds 		proc_skip_spaces(&p, &left);
55232927393SChristoph Hellwig 	if (write && first)
553f461d2dcSChristoph Hellwig 		return err ? : -EINVAL;
554f461d2dcSChristoph Hellwig 	*lenp -= left;
555f461d2dcSChristoph Hellwig out:
556f461d2dcSChristoph Hellwig 	*ppos += *lenp;
557f461d2dcSChristoph Hellwig 	return err;
558f461d2dcSChristoph Hellwig }
559f461d2dcSChristoph Hellwig 
560f461d2dcSChristoph Hellwig static int do_proc_dointvec(struct ctl_table *table, int write,
56132927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos,
562f461d2dcSChristoph Hellwig 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
563f461d2dcSChristoph Hellwig 			      int write, void *data),
564f461d2dcSChristoph Hellwig 		  void *data)
565f461d2dcSChristoph Hellwig {
566f461d2dcSChristoph Hellwig 	return __do_proc_dointvec(table->data, table, write,
567f461d2dcSChristoph Hellwig 			buffer, lenp, ppos, conv, data);
568f461d2dcSChristoph Hellwig }
569f461d2dcSChristoph Hellwig 
570f461d2dcSChristoph Hellwig static int do_proc_douintvec_w(unsigned int *tbl_data,
571f461d2dcSChristoph Hellwig 			       struct ctl_table *table,
57232927393SChristoph Hellwig 			       void *buffer,
573f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
574f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
575f461d2dcSChristoph Hellwig 					   unsigned int *valp,
576f461d2dcSChristoph Hellwig 					   int write, void *data),
577f461d2dcSChristoph Hellwig 			       void *data)
578f461d2dcSChristoph Hellwig {
579f461d2dcSChristoph Hellwig 	unsigned long lval;
580f461d2dcSChristoph Hellwig 	int err = 0;
581f461d2dcSChristoph Hellwig 	size_t left;
582f461d2dcSChristoph Hellwig 	bool neg;
58332927393SChristoph Hellwig 	char *p = buffer;
584f461d2dcSChristoph Hellwig 
585f461d2dcSChristoph Hellwig 	left = *lenp;
586f461d2dcSChristoph Hellwig 
587f461d2dcSChristoph Hellwig 	if (proc_first_pos_non_zero_ignore(ppos, table))
588f461d2dcSChristoph Hellwig 		goto bail_early;
589f461d2dcSChristoph Hellwig 
590f461d2dcSChristoph Hellwig 	if (left > PAGE_SIZE - 1)
591f461d2dcSChristoph Hellwig 		left = PAGE_SIZE - 1;
592f461d2dcSChristoph Hellwig 
593*bce93322SLinus Torvalds 	proc_skip_spaces(&p, &left);
594f461d2dcSChristoph Hellwig 	if (!left) {
595f461d2dcSChristoph Hellwig 		err = -EINVAL;
596f461d2dcSChristoph Hellwig 		goto out_free;
597f461d2dcSChristoph Hellwig 	}
598f461d2dcSChristoph Hellwig 
599f461d2dcSChristoph Hellwig 	err = proc_get_long(&p, &left, &lval, &neg,
600f461d2dcSChristoph Hellwig 			     proc_wspace_sep,
601f461d2dcSChristoph Hellwig 			     sizeof(proc_wspace_sep), NULL);
602f461d2dcSChristoph Hellwig 	if (err || neg) {
603f461d2dcSChristoph Hellwig 		err = -EINVAL;
604f461d2dcSChristoph Hellwig 		goto out_free;
605f461d2dcSChristoph Hellwig 	}
606f461d2dcSChristoph Hellwig 
607f461d2dcSChristoph Hellwig 	if (conv(&lval, tbl_data, 1, data)) {
608f461d2dcSChristoph Hellwig 		err = -EINVAL;
609f461d2dcSChristoph Hellwig 		goto out_free;
610f461d2dcSChristoph Hellwig 	}
611f461d2dcSChristoph Hellwig 
612f461d2dcSChristoph Hellwig 	if (!err && left)
613*bce93322SLinus Torvalds 		proc_skip_spaces(&p, &left);
614f461d2dcSChristoph Hellwig 
615f461d2dcSChristoph Hellwig out_free:
616f461d2dcSChristoph Hellwig 	if (err)
617f461d2dcSChristoph Hellwig 		return -EINVAL;
618f461d2dcSChristoph Hellwig 
619f461d2dcSChristoph Hellwig 	return 0;
620f461d2dcSChristoph Hellwig 
621f461d2dcSChristoph Hellwig 	/* This is in keeping with old __do_proc_dointvec() */
622f461d2dcSChristoph Hellwig bail_early:
623f461d2dcSChristoph Hellwig 	*ppos += *lenp;
624f461d2dcSChristoph Hellwig 	return err;
625f461d2dcSChristoph Hellwig }
626f461d2dcSChristoph Hellwig 
62732927393SChristoph Hellwig static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
628f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
629f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
630f461d2dcSChristoph Hellwig 					   unsigned int *valp,
631f461d2dcSChristoph Hellwig 					   int write, void *data),
632f461d2dcSChristoph Hellwig 			       void *data)
633f461d2dcSChristoph Hellwig {
634f461d2dcSChristoph Hellwig 	unsigned long lval;
635f461d2dcSChristoph Hellwig 	int err = 0;
636f461d2dcSChristoph Hellwig 	size_t left;
637f461d2dcSChristoph Hellwig 
638f461d2dcSChristoph Hellwig 	left = *lenp;
639f461d2dcSChristoph Hellwig 
640f461d2dcSChristoph Hellwig 	if (conv(&lval, tbl_data, 0, data)) {
641f461d2dcSChristoph Hellwig 		err = -EINVAL;
642f461d2dcSChristoph Hellwig 		goto out;
643f461d2dcSChristoph Hellwig 	}
644f461d2dcSChristoph Hellwig 
64532927393SChristoph Hellwig 	proc_put_long(&buffer, &left, lval, false);
64632927393SChristoph Hellwig 	if (!left)
647f461d2dcSChristoph Hellwig 		goto out;
648f461d2dcSChristoph Hellwig 
64932927393SChristoph Hellwig 	proc_put_char(&buffer, &left, '\n');
650f461d2dcSChristoph Hellwig 
651f461d2dcSChristoph Hellwig out:
652f461d2dcSChristoph Hellwig 	*lenp -= left;
653f461d2dcSChristoph Hellwig 	*ppos += *lenp;
654f461d2dcSChristoph Hellwig 
655f461d2dcSChristoph Hellwig 	return err;
656f461d2dcSChristoph Hellwig }
657f461d2dcSChristoph Hellwig 
658f461d2dcSChristoph Hellwig static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
65932927393SChristoph Hellwig 			       int write, void *buffer,
660f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
661f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
662f461d2dcSChristoph Hellwig 					   unsigned int *valp,
663f461d2dcSChristoph Hellwig 					   int write, void *data),
664f461d2dcSChristoph Hellwig 			       void *data)
665f461d2dcSChristoph Hellwig {
666f461d2dcSChristoph Hellwig 	unsigned int *i, vleft;
667f461d2dcSChristoph Hellwig 
668f461d2dcSChristoph Hellwig 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
669f461d2dcSChristoph Hellwig 		*lenp = 0;
670f461d2dcSChristoph Hellwig 		return 0;
671f461d2dcSChristoph Hellwig 	}
672f461d2dcSChristoph Hellwig 
673f461d2dcSChristoph Hellwig 	i = (unsigned int *) tbl_data;
674f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(*i);
675f461d2dcSChristoph Hellwig 
676f461d2dcSChristoph Hellwig 	/*
677f461d2dcSChristoph Hellwig 	 * Arrays are not supported, keep this simple. *Do not* add
678f461d2dcSChristoph Hellwig 	 * support for them.
679f461d2dcSChristoph Hellwig 	 */
680f461d2dcSChristoph Hellwig 	if (vleft != 1) {
681f461d2dcSChristoph Hellwig 		*lenp = 0;
682f461d2dcSChristoph Hellwig 		return -EINVAL;
683f461d2dcSChristoph Hellwig 	}
684f461d2dcSChristoph Hellwig 
685f461d2dcSChristoph Hellwig 	if (!conv)
686f461d2dcSChristoph Hellwig 		conv = do_proc_douintvec_conv;
687f461d2dcSChristoph Hellwig 
688f461d2dcSChristoph Hellwig 	if (write)
689f461d2dcSChristoph Hellwig 		return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
690f461d2dcSChristoph Hellwig 					   conv, data);
691f461d2dcSChristoph Hellwig 	return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
692f461d2dcSChristoph Hellwig }
693f461d2dcSChristoph Hellwig 
6941998f193SLuis Chamberlain int do_proc_douintvec(struct ctl_table *table, int write,
69532927393SChristoph Hellwig 		      void *buffer, size_t *lenp, loff_t *ppos,
696f461d2dcSChristoph Hellwig 		      int (*conv)(unsigned long *lvalp,
697f461d2dcSChristoph Hellwig 				  unsigned int *valp,
698f461d2dcSChristoph Hellwig 				  int write, void *data),
699f461d2dcSChristoph Hellwig 		      void *data)
700f461d2dcSChristoph Hellwig {
701f461d2dcSChristoph Hellwig 	return __do_proc_douintvec(table->data, table, write,
702f461d2dcSChristoph Hellwig 				   buffer, lenp, ppos, conv, data);
703f461d2dcSChristoph Hellwig }
704f461d2dcSChristoph Hellwig 
705f461d2dcSChristoph Hellwig /**
706a2071573SJia He  * proc_dobool - read/write a bool
707a2071573SJia He  * @table: the sysctl table
708a2071573SJia He  * @write: %TRUE if this is a write to the sysctl file
709a2071573SJia He  * @buffer: the user buffer
710a2071573SJia He  * @lenp: the size of the user buffer
711a2071573SJia He  * @ppos: file position
712a2071573SJia He  *
713a2071573SJia He  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
714a2071573SJia He  * values from/to the user buffer, treated as an ASCII string.
715a2071573SJia He  *
716a2071573SJia He  * Returns 0 on success.
717a2071573SJia He  */
718a2071573SJia He int proc_dobool(struct ctl_table *table, int write, void *buffer,
719a2071573SJia He 		size_t *lenp, loff_t *ppos)
720a2071573SJia He {
721a2071573SJia He 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
722a2071573SJia He 				do_proc_dobool_conv, NULL);
723a2071573SJia He }
724a2071573SJia He 
725a2071573SJia He /**
726f461d2dcSChristoph Hellwig  * proc_dointvec - read a vector of integers
727f461d2dcSChristoph Hellwig  * @table: the sysctl table
728f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
729f461d2dcSChristoph Hellwig  * @buffer: the user buffer
730f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
731f461d2dcSChristoph Hellwig  * @ppos: file position
732f461d2dcSChristoph Hellwig  *
733f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
734f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
735f461d2dcSChristoph Hellwig  *
736f461d2dcSChristoph Hellwig  * Returns 0 on success.
737f461d2dcSChristoph Hellwig  */
73832927393SChristoph Hellwig int proc_dointvec(struct ctl_table *table, int write, void *buffer,
73932927393SChristoph Hellwig 		  size_t *lenp, loff_t *ppos)
740f461d2dcSChristoph Hellwig {
741f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
742f461d2dcSChristoph Hellwig }
743f461d2dcSChristoph Hellwig 
744f461d2dcSChristoph Hellwig #ifdef CONFIG_COMPACTION
745f461d2dcSChristoph Hellwig static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
74632927393SChristoph Hellwig 		int write, void *buffer, size_t *lenp, loff_t *ppos)
747f461d2dcSChristoph Hellwig {
748f461d2dcSChristoph Hellwig 	int ret, old;
749f461d2dcSChristoph Hellwig 
750f461d2dcSChristoph Hellwig 	if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
751f461d2dcSChristoph Hellwig 		return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
752f461d2dcSChristoph Hellwig 
753f461d2dcSChristoph Hellwig 	old = *(int *)table->data;
754f461d2dcSChristoph Hellwig 	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
755f461d2dcSChristoph Hellwig 	if (ret)
756f461d2dcSChristoph Hellwig 		return ret;
757f461d2dcSChristoph Hellwig 	if (old != *(int *)table->data)
758f461d2dcSChristoph Hellwig 		pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
759f461d2dcSChristoph Hellwig 			     table->procname, current->comm,
760f461d2dcSChristoph Hellwig 			     task_pid_nr(current));
761f461d2dcSChristoph Hellwig 	return ret;
762f461d2dcSChristoph Hellwig }
763f461d2dcSChristoph Hellwig #endif
764f461d2dcSChristoph Hellwig 
765f461d2dcSChristoph Hellwig /**
766f461d2dcSChristoph Hellwig  * proc_douintvec - read a vector of unsigned integers
767f461d2dcSChristoph Hellwig  * @table: the sysctl table
768f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
769f461d2dcSChristoph Hellwig  * @buffer: the user buffer
770f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
771f461d2dcSChristoph Hellwig  * @ppos: file position
772f461d2dcSChristoph Hellwig  *
773f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
774f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
775f461d2dcSChristoph Hellwig  *
776f461d2dcSChristoph Hellwig  * Returns 0 on success.
777f461d2dcSChristoph Hellwig  */
77832927393SChristoph Hellwig int proc_douintvec(struct ctl_table *table, int write, void *buffer,
77932927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
780f461d2dcSChristoph Hellwig {
781f461d2dcSChristoph Hellwig 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
782f461d2dcSChristoph Hellwig 				 do_proc_douintvec_conv, NULL);
783f461d2dcSChristoph Hellwig }
784f461d2dcSChristoph Hellwig 
785f461d2dcSChristoph Hellwig /*
786f461d2dcSChristoph Hellwig  * Taint values can only be increased
787f461d2dcSChristoph Hellwig  * This means we can safely use a temporary.
788f461d2dcSChristoph Hellwig  */
789f461d2dcSChristoph Hellwig static int proc_taint(struct ctl_table *table, int write,
79032927393SChristoph Hellwig 			       void *buffer, size_t *lenp, loff_t *ppos)
791f461d2dcSChristoph Hellwig {
792f461d2dcSChristoph Hellwig 	struct ctl_table t;
793f461d2dcSChristoph Hellwig 	unsigned long tmptaint = get_taint();
794f461d2dcSChristoph Hellwig 	int err;
795f461d2dcSChristoph Hellwig 
796f461d2dcSChristoph Hellwig 	if (write && !capable(CAP_SYS_ADMIN))
797f461d2dcSChristoph Hellwig 		return -EPERM;
798f461d2dcSChristoph Hellwig 
799f461d2dcSChristoph Hellwig 	t = *table;
800f461d2dcSChristoph Hellwig 	t.data = &tmptaint;
801f461d2dcSChristoph Hellwig 	err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
802f461d2dcSChristoph Hellwig 	if (err < 0)
803f461d2dcSChristoph Hellwig 		return err;
804f461d2dcSChristoph Hellwig 
805f461d2dcSChristoph Hellwig 	if (write) {
806db38d5c1SRafael Aquini 		int i;
807db38d5c1SRafael Aquini 
808db38d5c1SRafael Aquini 		/*
809db38d5c1SRafael Aquini 		 * If we are relying on panic_on_taint not producing
810db38d5c1SRafael Aquini 		 * false positives due to userspace input, bail out
811db38d5c1SRafael Aquini 		 * before setting the requested taint flags.
812db38d5c1SRafael Aquini 		 */
813db38d5c1SRafael Aquini 		if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
814db38d5c1SRafael Aquini 			return -EINVAL;
815db38d5c1SRafael Aquini 
816f461d2dcSChristoph Hellwig 		/*
817f461d2dcSChristoph Hellwig 		 * Poor man's atomic or. Not worth adding a primitive
818f461d2dcSChristoph Hellwig 		 * to everyone's atomic.h for this
819f461d2dcSChristoph Hellwig 		 */
820e77132e7SRafael Aquini 		for (i = 0; i < TAINT_FLAGS_COUNT; i++)
821e77132e7SRafael Aquini 			if ((1UL << i) & tmptaint)
822f461d2dcSChristoph Hellwig 				add_taint(i, LOCKDEP_STILL_OK);
823f461d2dcSChristoph Hellwig 	}
824f461d2dcSChristoph Hellwig 
825f461d2dcSChristoph Hellwig 	return err;
826f461d2dcSChristoph Hellwig }
827f461d2dcSChristoph Hellwig 
828f461d2dcSChristoph Hellwig /**
829f461d2dcSChristoph Hellwig  * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
830f461d2dcSChristoph Hellwig  * @min: pointer to minimum allowable value
831f461d2dcSChristoph Hellwig  * @max: pointer to maximum allowable value
832f461d2dcSChristoph Hellwig  *
833f461d2dcSChristoph Hellwig  * The do_proc_dointvec_minmax_conv_param structure provides the
834f461d2dcSChristoph Hellwig  * minimum and maximum values for doing range checking for those sysctl
835f461d2dcSChristoph Hellwig  * parameters that use the proc_dointvec_minmax() handler.
836f461d2dcSChristoph Hellwig  */
837f461d2dcSChristoph Hellwig struct do_proc_dointvec_minmax_conv_param {
838f461d2dcSChristoph Hellwig 	int *min;
839f461d2dcSChristoph Hellwig 	int *max;
840f461d2dcSChristoph Hellwig };
841f461d2dcSChristoph Hellwig 
842f461d2dcSChristoph Hellwig static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
843f461d2dcSChristoph Hellwig 					int *valp,
844f461d2dcSChristoph Hellwig 					int write, void *data)
845f461d2dcSChristoph Hellwig {
846f461d2dcSChristoph Hellwig 	int tmp, ret;
847f461d2dcSChristoph Hellwig 	struct do_proc_dointvec_minmax_conv_param *param = data;
848f461d2dcSChristoph Hellwig 	/*
849f461d2dcSChristoph Hellwig 	 * If writing, first do so via a temporary local int so we can
850f461d2dcSChristoph Hellwig 	 * bounds-check it before touching *valp.
851f461d2dcSChristoph Hellwig 	 */
852f461d2dcSChristoph Hellwig 	int *ip = write ? &tmp : valp;
853f461d2dcSChristoph Hellwig 
854f461d2dcSChristoph Hellwig 	ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
855f461d2dcSChristoph Hellwig 	if (ret)
856f461d2dcSChristoph Hellwig 		return ret;
857f461d2dcSChristoph Hellwig 
858f461d2dcSChristoph Hellwig 	if (write) {
859f461d2dcSChristoph Hellwig 		if ((param->min && *param->min > tmp) ||
860f461d2dcSChristoph Hellwig 		    (param->max && *param->max < tmp))
861f461d2dcSChristoph Hellwig 			return -EINVAL;
862f613d86dSKuniyuki Iwashima 		WRITE_ONCE(*valp, tmp);
863f461d2dcSChristoph Hellwig 	}
864f461d2dcSChristoph Hellwig 
865f461d2dcSChristoph Hellwig 	return 0;
866f461d2dcSChristoph Hellwig }
867f461d2dcSChristoph Hellwig 
868f461d2dcSChristoph Hellwig /**
869f461d2dcSChristoph Hellwig  * proc_dointvec_minmax - read a vector of integers with min/max values
870f461d2dcSChristoph Hellwig  * @table: the sysctl table
871f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
872f461d2dcSChristoph Hellwig  * @buffer: the user buffer
873f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
874f461d2dcSChristoph Hellwig  * @ppos: file position
875f461d2dcSChristoph Hellwig  *
876f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
877f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
878f461d2dcSChristoph Hellwig  *
879f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
880f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max).
881f461d2dcSChristoph Hellwig  *
882f461d2dcSChristoph Hellwig  * Returns 0 on success or -EINVAL on write when the range check fails.
883f461d2dcSChristoph Hellwig  */
884f461d2dcSChristoph Hellwig int proc_dointvec_minmax(struct ctl_table *table, int write,
88532927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
886f461d2dcSChristoph Hellwig {
887f461d2dcSChristoph Hellwig 	struct do_proc_dointvec_minmax_conv_param param = {
888f461d2dcSChristoph Hellwig 		.min = (int *) table->extra1,
889f461d2dcSChristoph Hellwig 		.max = (int *) table->extra2,
890f461d2dcSChristoph Hellwig 	};
891f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
892f461d2dcSChristoph Hellwig 				do_proc_dointvec_minmax_conv, &param);
893f461d2dcSChristoph Hellwig }
894f461d2dcSChristoph Hellwig 
895f461d2dcSChristoph Hellwig /**
896f461d2dcSChristoph Hellwig  * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
897f461d2dcSChristoph Hellwig  * @min: pointer to minimum allowable value
898f461d2dcSChristoph Hellwig  * @max: pointer to maximum allowable value
899f461d2dcSChristoph Hellwig  *
900f461d2dcSChristoph Hellwig  * The do_proc_douintvec_minmax_conv_param structure provides the
901f461d2dcSChristoph Hellwig  * minimum and maximum values for doing range checking for those sysctl
902f461d2dcSChristoph Hellwig  * parameters that use the proc_douintvec_minmax() handler.
903f461d2dcSChristoph Hellwig  */
904f461d2dcSChristoph Hellwig struct do_proc_douintvec_minmax_conv_param {
905f461d2dcSChristoph Hellwig 	unsigned int *min;
906f461d2dcSChristoph Hellwig 	unsigned int *max;
907f461d2dcSChristoph Hellwig };
908f461d2dcSChristoph Hellwig 
909f461d2dcSChristoph Hellwig static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
910f461d2dcSChristoph Hellwig 					 unsigned int *valp,
911f461d2dcSChristoph Hellwig 					 int write, void *data)
912f461d2dcSChristoph Hellwig {
913f461d2dcSChristoph Hellwig 	int ret;
914f461d2dcSChristoph Hellwig 	unsigned int tmp;
915f461d2dcSChristoph Hellwig 	struct do_proc_douintvec_minmax_conv_param *param = data;
916f461d2dcSChristoph Hellwig 	/* write via temporary local uint for bounds-checking */
917f461d2dcSChristoph Hellwig 	unsigned int *up = write ? &tmp : valp;
918f461d2dcSChristoph Hellwig 
919f461d2dcSChristoph Hellwig 	ret = do_proc_douintvec_conv(lvalp, up, write, data);
920f461d2dcSChristoph Hellwig 	if (ret)
921f461d2dcSChristoph Hellwig 		return ret;
922f461d2dcSChristoph Hellwig 
923f461d2dcSChristoph Hellwig 	if (write) {
924f461d2dcSChristoph Hellwig 		if ((param->min && *param->min > tmp) ||
925f461d2dcSChristoph Hellwig 		    (param->max && *param->max < tmp))
926f461d2dcSChristoph Hellwig 			return -ERANGE;
927f461d2dcSChristoph Hellwig 
9282d3b559dSKuniyuki Iwashima 		WRITE_ONCE(*valp, tmp);
929f461d2dcSChristoph Hellwig 	}
930f461d2dcSChristoph Hellwig 
931f461d2dcSChristoph Hellwig 	return 0;
932f461d2dcSChristoph Hellwig }
933f461d2dcSChristoph Hellwig 
934f461d2dcSChristoph Hellwig /**
935f461d2dcSChristoph Hellwig  * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
936f461d2dcSChristoph Hellwig  * @table: the sysctl table
937f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
938f461d2dcSChristoph Hellwig  * @buffer: the user buffer
939f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
940f461d2dcSChristoph Hellwig  * @ppos: file position
941f461d2dcSChristoph Hellwig  *
942f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
943f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string. Negative
944f461d2dcSChristoph Hellwig  * strings are not allowed.
945f461d2dcSChristoph Hellwig  *
946f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
947f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max). There is a final sanity
948f461d2dcSChristoph Hellwig  * check for UINT_MAX to avoid having to support wrap around uses from
949f461d2dcSChristoph Hellwig  * userspace.
950f461d2dcSChristoph Hellwig  *
951f461d2dcSChristoph Hellwig  * Returns 0 on success or -ERANGE on write when the range check fails.
952f461d2dcSChristoph Hellwig  */
953f461d2dcSChristoph Hellwig int proc_douintvec_minmax(struct ctl_table *table, int write,
95432927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
955f461d2dcSChristoph Hellwig {
956f461d2dcSChristoph Hellwig 	struct do_proc_douintvec_minmax_conv_param param = {
957f461d2dcSChristoph Hellwig 		.min = (unsigned int *) table->extra1,
958f461d2dcSChristoph Hellwig 		.max = (unsigned int *) table->extra2,
959f461d2dcSChristoph Hellwig 	};
960f461d2dcSChristoph Hellwig 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
961f461d2dcSChristoph Hellwig 				 do_proc_douintvec_minmax_conv, &param);
962f461d2dcSChristoph Hellwig }
963f461d2dcSChristoph Hellwig 
964cb944413SEric Dumazet /**
965cb944413SEric Dumazet  * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
966cb944413SEric Dumazet  * @table: the sysctl table
967cb944413SEric Dumazet  * @write: %TRUE if this is a write to the sysctl file
968cb944413SEric Dumazet  * @buffer: the user buffer
969cb944413SEric Dumazet  * @lenp: the size of the user buffer
970cb944413SEric Dumazet  * @ppos: file position
971cb944413SEric Dumazet  *
972cb944413SEric Dumazet  * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
973cb944413SEric Dumazet  * values from/to the user buffer, treated as an ASCII string. Negative
974cb944413SEric Dumazet  * strings are not allowed.
975cb944413SEric Dumazet  *
976cb944413SEric Dumazet  * This routine will ensure the values are within the range specified by
977cb944413SEric Dumazet  * table->extra1 (min) and table->extra2 (max).
978cb944413SEric Dumazet  *
979cb944413SEric Dumazet  * Returns 0 on success or an error on write when the range check fails.
980cb944413SEric Dumazet  */
981cb944413SEric Dumazet int proc_dou8vec_minmax(struct ctl_table *table, int write,
982cb944413SEric Dumazet 			void *buffer, size_t *lenp, loff_t *ppos)
983cb944413SEric Dumazet {
984cb944413SEric Dumazet 	struct ctl_table tmp;
985cb944413SEric Dumazet 	unsigned int min = 0, max = 255U, val;
986cb944413SEric Dumazet 	u8 *data = table->data;
987cb944413SEric Dumazet 	struct do_proc_douintvec_minmax_conv_param param = {
988cb944413SEric Dumazet 		.min = &min,
989cb944413SEric Dumazet 		.max = &max,
990cb944413SEric Dumazet 	};
991cb944413SEric Dumazet 	int res;
992cb944413SEric Dumazet 
993cb944413SEric Dumazet 	/* Do not support arrays yet. */
994cb944413SEric Dumazet 	if (table->maxlen != sizeof(u8))
995cb944413SEric Dumazet 		return -EINVAL;
996cb944413SEric Dumazet 
997cb944413SEric Dumazet 	if (table->extra1) {
998cb944413SEric Dumazet 		min = *(unsigned int *) table->extra1;
999cb944413SEric Dumazet 		if (min > 255U)
1000cb944413SEric Dumazet 			return -EINVAL;
1001cb944413SEric Dumazet 	}
1002cb944413SEric Dumazet 	if (table->extra2) {
1003cb944413SEric Dumazet 		max = *(unsigned int *) table->extra2;
1004cb944413SEric Dumazet 		if (max > 255U)
1005cb944413SEric Dumazet 			return -EINVAL;
1006cb944413SEric Dumazet 	}
1007cb944413SEric Dumazet 
1008cb944413SEric Dumazet 	tmp = *table;
1009cb944413SEric Dumazet 
1010cb944413SEric Dumazet 	tmp.maxlen = sizeof(val);
1011cb944413SEric Dumazet 	tmp.data = &val;
10127dee5d77SKuniyuki Iwashima 	val = READ_ONCE(*data);
1013cb944413SEric Dumazet 	res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
1014cb944413SEric Dumazet 				do_proc_douintvec_minmax_conv, &param);
1015cb944413SEric Dumazet 	if (res)
1016cb944413SEric Dumazet 		return res;
1017cb944413SEric Dumazet 	if (write)
10187dee5d77SKuniyuki Iwashima 		WRITE_ONCE(*data, val);
1019cb944413SEric Dumazet 	return 0;
1020cb944413SEric Dumazet }
1021cb944413SEric Dumazet EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
1022cb944413SEric Dumazet 
1023f461d2dcSChristoph Hellwig #ifdef CONFIG_MAGIC_SYSRQ
1024f461d2dcSChristoph Hellwig static int sysrq_sysctl_handler(struct ctl_table *table, int write,
102532927393SChristoph Hellwig 				void *buffer, size_t *lenp, loff_t *ppos)
1026f461d2dcSChristoph Hellwig {
1027f461d2dcSChristoph Hellwig 	int tmp, ret;
1028f461d2dcSChristoph Hellwig 
1029f461d2dcSChristoph Hellwig 	tmp = sysrq_mask();
1030f461d2dcSChristoph Hellwig 
1031f461d2dcSChristoph Hellwig 	ret = __do_proc_dointvec(&tmp, table, write, buffer,
1032f461d2dcSChristoph Hellwig 			       lenp, ppos, NULL, NULL);
1033f461d2dcSChristoph Hellwig 	if (ret || !write)
1034f461d2dcSChristoph Hellwig 		return ret;
1035f461d2dcSChristoph Hellwig 
1036f461d2dcSChristoph Hellwig 	if (write)
1037f461d2dcSChristoph Hellwig 		sysrq_toggle_support(tmp);
1038f461d2dcSChristoph Hellwig 
1039f461d2dcSChristoph Hellwig 	return 0;
1040f461d2dcSChristoph Hellwig }
1041f461d2dcSChristoph Hellwig #endif
1042f461d2dcSChristoph Hellwig 
104332927393SChristoph Hellwig static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
104432927393SChristoph Hellwig 		int write, void *buffer, size_t *lenp, loff_t *ppos,
104532927393SChristoph Hellwig 		unsigned long convmul, unsigned long convdiv)
1046f461d2dcSChristoph Hellwig {
1047f461d2dcSChristoph Hellwig 	unsigned long *i, *min, *max;
1048f461d2dcSChristoph Hellwig 	int vleft, first = 1, err = 0;
1049f461d2dcSChristoph Hellwig 	size_t left;
105032927393SChristoph Hellwig 	char *p;
1051f461d2dcSChristoph Hellwig 
1052f461d2dcSChristoph Hellwig 	if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1053f461d2dcSChristoph Hellwig 		*lenp = 0;
1054f461d2dcSChristoph Hellwig 		return 0;
1055f461d2dcSChristoph Hellwig 	}
1056f461d2dcSChristoph Hellwig 
10578ebc4123SDong Chuanjian 	i = data;
10588ebc4123SDong Chuanjian 	min = table->extra1;
10598ebc4123SDong Chuanjian 	max = table->extra2;
1060f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(unsigned long);
1061f461d2dcSChristoph Hellwig 	left = *lenp;
1062f461d2dcSChristoph Hellwig 
1063f461d2dcSChristoph Hellwig 	if (write) {
1064f461d2dcSChristoph Hellwig 		if (proc_first_pos_non_zero_ignore(ppos, table))
1065f461d2dcSChristoph Hellwig 			goto out;
1066f461d2dcSChristoph Hellwig 
1067f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1)
1068f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
106932927393SChristoph Hellwig 		p = buffer;
1070f461d2dcSChristoph Hellwig 	}
1071f461d2dcSChristoph Hellwig 
1072f461d2dcSChristoph Hellwig 	for (; left && vleft--; i++, first = 0) {
1073f461d2dcSChristoph Hellwig 		unsigned long val;
1074f461d2dcSChristoph Hellwig 
1075f461d2dcSChristoph Hellwig 		if (write) {
1076f461d2dcSChristoph Hellwig 			bool neg;
1077f461d2dcSChristoph Hellwig 
1078*bce93322SLinus Torvalds 			proc_skip_spaces(&p, &left);
1079f461d2dcSChristoph Hellwig 			if (!left)
1080f461d2dcSChristoph Hellwig 				break;
1081f461d2dcSChristoph Hellwig 
1082f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &val, &neg,
1083f461d2dcSChristoph Hellwig 					     proc_wspace_sep,
1084f461d2dcSChristoph Hellwig 					     sizeof(proc_wspace_sep), NULL);
10851622ed7dSBaokun Li 			if (err || neg) {
10861622ed7dSBaokun Li 				err = -EINVAL;
1087f461d2dcSChristoph Hellwig 				break;
10881622ed7dSBaokun Li 			}
10891622ed7dSBaokun Li 
1090f461d2dcSChristoph Hellwig 			val = convmul * val / convdiv;
1091f461d2dcSChristoph Hellwig 			if ((min && val < *min) || (max && val > *max)) {
1092f461d2dcSChristoph Hellwig 				err = -EINVAL;
1093f461d2dcSChristoph Hellwig 				break;
1094f461d2dcSChristoph Hellwig 			}
1095c31bcc8fSKuniyuki Iwashima 			WRITE_ONCE(*i, val);
1096f461d2dcSChristoph Hellwig 		} else {
1097c31bcc8fSKuniyuki Iwashima 			val = convdiv * READ_ONCE(*i) / convmul;
109832927393SChristoph Hellwig 			if (!first)
109932927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '\t');
110032927393SChristoph Hellwig 			proc_put_long(&buffer, &left, val, false);
1101f461d2dcSChristoph Hellwig 		}
1102f461d2dcSChristoph Hellwig 	}
1103f461d2dcSChristoph Hellwig 
1104f461d2dcSChristoph Hellwig 	if (!write && !first && left && !err)
110532927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
1106f461d2dcSChristoph Hellwig 	if (write && !err)
1107*bce93322SLinus Torvalds 		proc_skip_spaces(&p, &left);
110832927393SChristoph Hellwig 	if (write && first)
1109f461d2dcSChristoph Hellwig 		return err ? : -EINVAL;
1110f461d2dcSChristoph Hellwig 	*lenp -= left;
1111f461d2dcSChristoph Hellwig out:
1112f461d2dcSChristoph Hellwig 	*ppos += *lenp;
1113f461d2dcSChristoph Hellwig 	return err;
1114f461d2dcSChristoph Hellwig }
1115f461d2dcSChristoph Hellwig 
1116f461d2dcSChristoph Hellwig static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
111732927393SChristoph Hellwig 		void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1118f461d2dcSChristoph Hellwig 		unsigned long convdiv)
1119f461d2dcSChristoph Hellwig {
1120f461d2dcSChristoph Hellwig 	return __do_proc_doulongvec_minmax(table->data, table, write,
1121f461d2dcSChristoph Hellwig 			buffer, lenp, ppos, convmul, convdiv);
1122f461d2dcSChristoph Hellwig }
1123f461d2dcSChristoph Hellwig 
1124f461d2dcSChristoph Hellwig /**
1125f461d2dcSChristoph Hellwig  * proc_doulongvec_minmax - read a vector of long integers with min/max values
1126f461d2dcSChristoph Hellwig  * @table: the sysctl table
1127f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1128f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1129f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1130f461d2dcSChristoph Hellwig  * @ppos: file position
1131f461d2dcSChristoph Hellwig  *
1132f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1133f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1134f461d2dcSChristoph Hellwig  *
1135f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
1136f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max).
1137f461d2dcSChristoph Hellwig  *
1138f461d2dcSChristoph Hellwig  * Returns 0 on success.
1139f461d2dcSChristoph Hellwig  */
1140f461d2dcSChristoph Hellwig int proc_doulongvec_minmax(struct ctl_table *table, int write,
114132927393SChristoph Hellwig 			   void *buffer, size_t *lenp, loff_t *ppos)
1142f461d2dcSChristoph Hellwig {
1143f461d2dcSChristoph Hellwig     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1144f461d2dcSChristoph Hellwig }
1145f461d2dcSChristoph Hellwig 
1146f461d2dcSChristoph Hellwig /**
1147f461d2dcSChristoph Hellwig  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1148f461d2dcSChristoph Hellwig  * @table: the sysctl table
1149f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1150f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1151f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1152f461d2dcSChristoph Hellwig  * @ppos: file position
1153f461d2dcSChristoph Hellwig  *
1154f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1155f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string. The values
1156f461d2dcSChristoph Hellwig  * are treated as milliseconds, and converted to jiffies when they are stored.
1157f461d2dcSChristoph Hellwig  *
1158f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
1159f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max).
1160f461d2dcSChristoph Hellwig  *
1161f461d2dcSChristoph Hellwig  * Returns 0 on success.
1162f461d2dcSChristoph Hellwig  */
1163f461d2dcSChristoph Hellwig int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
116432927393SChristoph Hellwig 				      void *buffer, size_t *lenp, loff_t *ppos)
1165f461d2dcSChristoph Hellwig {
1166f461d2dcSChristoph Hellwig     return do_proc_doulongvec_minmax(table, write, buffer,
1167f461d2dcSChristoph Hellwig 				     lenp, ppos, HZ, 1000l);
1168f461d2dcSChristoph Hellwig }
1169f461d2dcSChristoph Hellwig 
1170f461d2dcSChristoph Hellwig 
1171f461d2dcSChristoph Hellwig static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1172f461d2dcSChristoph Hellwig 					 int *valp,
1173f461d2dcSChristoph Hellwig 					 int write, void *data)
1174f461d2dcSChristoph Hellwig {
1175f461d2dcSChristoph Hellwig 	if (write) {
1176f461d2dcSChristoph Hellwig 		if (*lvalp > INT_MAX / HZ)
1177f461d2dcSChristoph Hellwig 			return 1;
1178e8778208SKuniyuki Iwashima 		if (*negp)
1179e8778208SKuniyuki Iwashima 			WRITE_ONCE(*valp, -*lvalp * HZ);
1180e8778208SKuniyuki Iwashima 		else
1181e8778208SKuniyuki Iwashima 			WRITE_ONCE(*valp, *lvalp * HZ);
1182f461d2dcSChristoph Hellwig 	} else {
1183e8778208SKuniyuki Iwashima 		int val = READ_ONCE(*valp);
1184f461d2dcSChristoph Hellwig 		unsigned long lval;
1185f461d2dcSChristoph Hellwig 		if (val < 0) {
1186f461d2dcSChristoph Hellwig 			*negp = true;
1187f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1188f461d2dcSChristoph Hellwig 		} else {
1189f461d2dcSChristoph Hellwig 			*negp = false;
1190f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1191f461d2dcSChristoph Hellwig 		}
1192f461d2dcSChristoph Hellwig 		*lvalp = lval / HZ;
1193f461d2dcSChristoph Hellwig 	}
1194f461d2dcSChristoph Hellwig 	return 0;
1195f461d2dcSChristoph Hellwig }
1196f461d2dcSChristoph Hellwig 
1197f461d2dcSChristoph Hellwig static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1198f461d2dcSChristoph Hellwig 						int *valp,
1199f461d2dcSChristoph Hellwig 						int write, void *data)
1200f461d2dcSChristoph Hellwig {
1201f461d2dcSChristoph Hellwig 	if (write) {
1202f461d2dcSChristoph Hellwig 		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1203f461d2dcSChristoph Hellwig 			return 1;
1204f461d2dcSChristoph Hellwig 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1205f461d2dcSChristoph Hellwig 	} else {
1206f461d2dcSChristoph Hellwig 		int val = *valp;
1207f461d2dcSChristoph Hellwig 		unsigned long lval;
1208f461d2dcSChristoph Hellwig 		if (val < 0) {
1209f461d2dcSChristoph Hellwig 			*negp = true;
1210f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1211f461d2dcSChristoph Hellwig 		} else {
1212f461d2dcSChristoph Hellwig 			*negp = false;
1213f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1214f461d2dcSChristoph Hellwig 		}
1215f461d2dcSChristoph Hellwig 		*lvalp = jiffies_to_clock_t(lval);
1216f461d2dcSChristoph Hellwig 	}
1217f461d2dcSChristoph Hellwig 	return 0;
1218f461d2dcSChristoph Hellwig }
1219f461d2dcSChristoph Hellwig 
1220f461d2dcSChristoph Hellwig static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1221f461d2dcSChristoph Hellwig 					    int *valp,
1222f461d2dcSChristoph Hellwig 					    int write, void *data)
1223f461d2dcSChristoph Hellwig {
1224f461d2dcSChristoph Hellwig 	if (write) {
1225f461d2dcSChristoph Hellwig 		unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1226f461d2dcSChristoph Hellwig 
1227f461d2dcSChristoph Hellwig 		if (jif > INT_MAX)
1228f461d2dcSChristoph Hellwig 			return 1;
12297d1025e5SKuniyuki Iwashima 		WRITE_ONCE(*valp, (int)jif);
1230f461d2dcSChristoph Hellwig 	} else {
12317d1025e5SKuniyuki Iwashima 		int val = READ_ONCE(*valp);
1232f461d2dcSChristoph Hellwig 		unsigned long lval;
1233f461d2dcSChristoph Hellwig 		if (val < 0) {
1234f461d2dcSChristoph Hellwig 			*negp = true;
1235f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1236f461d2dcSChristoph Hellwig 		} else {
1237f461d2dcSChristoph Hellwig 			*negp = false;
1238f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1239f461d2dcSChristoph Hellwig 		}
1240f461d2dcSChristoph Hellwig 		*lvalp = jiffies_to_msecs(lval);
1241f461d2dcSChristoph Hellwig 	}
1242f461d2dcSChristoph Hellwig 	return 0;
1243f461d2dcSChristoph Hellwig }
1244f461d2dcSChristoph Hellwig 
1245c381d02bSYuwei Wang static int do_proc_dointvec_ms_jiffies_minmax_conv(bool *negp, unsigned long *lvalp,
1246c381d02bSYuwei Wang 						int *valp, int write, void *data)
1247c381d02bSYuwei Wang {
1248c381d02bSYuwei Wang 	int tmp, ret;
1249c381d02bSYuwei Wang 	struct do_proc_dointvec_minmax_conv_param *param = data;
1250c381d02bSYuwei Wang 	/*
1251c381d02bSYuwei Wang 	 * If writing, first do so via a temporary local int so we can
1252c381d02bSYuwei Wang 	 * bounds-check it before touching *valp.
1253c381d02bSYuwei Wang 	 */
1254c381d02bSYuwei Wang 	int *ip = write ? &tmp : valp;
1255c381d02bSYuwei Wang 
1256c381d02bSYuwei Wang 	ret = do_proc_dointvec_ms_jiffies_conv(negp, lvalp, ip, write, data);
1257c381d02bSYuwei Wang 	if (ret)
1258c381d02bSYuwei Wang 		return ret;
1259c381d02bSYuwei Wang 
1260c381d02bSYuwei Wang 	if (write) {
1261c381d02bSYuwei Wang 		if ((param->min && *param->min > tmp) ||
1262c381d02bSYuwei Wang 				(param->max && *param->max < tmp))
1263c381d02bSYuwei Wang 			return -EINVAL;
1264c381d02bSYuwei Wang 		*valp = tmp;
1265c381d02bSYuwei Wang 	}
1266c381d02bSYuwei Wang 	return 0;
1267c381d02bSYuwei Wang }
1268c381d02bSYuwei Wang 
1269f461d2dcSChristoph Hellwig /**
1270f461d2dcSChristoph Hellwig  * proc_dointvec_jiffies - read a vector of integers as seconds
1271f461d2dcSChristoph Hellwig  * @table: the sysctl table
1272f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1273f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1274f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1275f461d2dcSChristoph Hellwig  * @ppos: file position
1276f461d2dcSChristoph Hellwig  *
1277f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1278f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1279f461d2dcSChristoph Hellwig  * The values read are assumed to be in seconds, and are converted into
1280f461d2dcSChristoph Hellwig  * jiffies.
1281f461d2dcSChristoph Hellwig  *
1282f461d2dcSChristoph Hellwig  * Returns 0 on success.
1283f461d2dcSChristoph Hellwig  */
1284f461d2dcSChristoph Hellwig int proc_dointvec_jiffies(struct ctl_table *table, int write,
128532927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
1286f461d2dcSChristoph Hellwig {
1287f461d2dcSChristoph Hellwig     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1288f461d2dcSChristoph Hellwig 		    	    do_proc_dointvec_jiffies_conv,NULL);
1289f461d2dcSChristoph Hellwig }
1290f461d2dcSChristoph Hellwig 
1291c381d02bSYuwei Wang int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1292c381d02bSYuwei Wang 			  void *buffer, size_t *lenp, loff_t *ppos)
1293c381d02bSYuwei Wang {
1294c381d02bSYuwei Wang 	struct do_proc_dointvec_minmax_conv_param param = {
1295c381d02bSYuwei Wang 		.min = (int *) table->extra1,
1296c381d02bSYuwei Wang 		.max = (int *) table->extra2,
1297c381d02bSYuwei Wang 	};
1298c381d02bSYuwei Wang 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
1299c381d02bSYuwei Wang 			do_proc_dointvec_ms_jiffies_minmax_conv, &param);
1300c381d02bSYuwei Wang }
1301c381d02bSYuwei Wang 
1302f461d2dcSChristoph Hellwig /**
1303f461d2dcSChristoph Hellwig  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1304f461d2dcSChristoph Hellwig  * @table: the sysctl table
1305f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1306f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1307f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1308f461d2dcSChristoph Hellwig  * @ppos: pointer to the file position
1309f461d2dcSChristoph Hellwig  *
1310f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1311f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1312f461d2dcSChristoph Hellwig  * The values read are assumed to be in 1/USER_HZ seconds, and
1313f461d2dcSChristoph Hellwig  * are converted into jiffies.
1314f461d2dcSChristoph Hellwig  *
1315f461d2dcSChristoph Hellwig  * Returns 0 on success.
1316f461d2dcSChristoph Hellwig  */
1317f461d2dcSChristoph Hellwig int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
131832927393SChristoph Hellwig 				 void *buffer, size_t *lenp, loff_t *ppos)
1319f461d2dcSChristoph Hellwig {
1320f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
1321f461d2dcSChristoph Hellwig 				do_proc_dointvec_userhz_jiffies_conv, NULL);
1322f461d2dcSChristoph Hellwig }
1323f461d2dcSChristoph Hellwig 
1324f461d2dcSChristoph Hellwig /**
1325f461d2dcSChristoph Hellwig  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1326f461d2dcSChristoph Hellwig  * @table: the sysctl table
1327f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1328f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1329f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1330f461d2dcSChristoph Hellwig  * @ppos: file position
1331f461d2dcSChristoph Hellwig  * @ppos: the current position in the file
1332f461d2dcSChristoph Hellwig  *
1333f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1334f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1335f461d2dcSChristoph Hellwig  * The values read are assumed to be in 1/1000 seconds, and
1336f461d2dcSChristoph Hellwig  * are converted into jiffies.
1337f461d2dcSChristoph Hellwig  *
1338f461d2dcSChristoph Hellwig  * Returns 0 on success.
1339f461d2dcSChristoph Hellwig  */
134032927393SChristoph Hellwig int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
134132927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
1342f461d2dcSChristoph Hellwig {
1343f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
1344f461d2dcSChristoph Hellwig 				do_proc_dointvec_ms_jiffies_conv, NULL);
1345f461d2dcSChristoph Hellwig }
1346f461d2dcSChristoph Hellwig 
134732927393SChristoph Hellwig static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
134832927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
1349f461d2dcSChristoph Hellwig {
1350f461d2dcSChristoph Hellwig 	struct pid *new_pid;
1351f461d2dcSChristoph Hellwig 	pid_t tmp;
1352f461d2dcSChristoph Hellwig 	int r;
1353f461d2dcSChristoph Hellwig 
1354f461d2dcSChristoph Hellwig 	tmp = pid_vnr(cad_pid);
1355f461d2dcSChristoph Hellwig 
1356f461d2dcSChristoph Hellwig 	r = __do_proc_dointvec(&tmp, table, write, buffer,
1357f461d2dcSChristoph Hellwig 			       lenp, ppos, NULL, NULL);
1358f461d2dcSChristoph Hellwig 	if (r || !write)
1359f461d2dcSChristoph Hellwig 		return r;
1360f461d2dcSChristoph Hellwig 
1361f461d2dcSChristoph Hellwig 	new_pid = find_get_pid(tmp);
1362f461d2dcSChristoph Hellwig 	if (!new_pid)
1363f461d2dcSChristoph Hellwig 		return -ESRCH;
1364f461d2dcSChristoph Hellwig 
1365f461d2dcSChristoph Hellwig 	put_pid(xchg(&cad_pid, new_pid));
1366f461d2dcSChristoph Hellwig 	return 0;
1367f461d2dcSChristoph Hellwig }
1368f461d2dcSChristoph Hellwig 
1369f461d2dcSChristoph Hellwig /**
1370f461d2dcSChristoph Hellwig  * proc_do_large_bitmap - read/write from/to a large bitmap
1371f461d2dcSChristoph Hellwig  * @table: the sysctl table
1372f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1373f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1374f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1375f461d2dcSChristoph Hellwig  * @ppos: file position
1376f461d2dcSChristoph Hellwig  *
1377f461d2dcSChristoph Hellwig  * The bitmap is stored at table->data and the bitmap length (in bits)
1378f461d2dcSChristoph Hellwig  * in table->maxlen.
1379f461d2dcSChristoph Hellwig  *
1380f461d2dcSChristoph Hellwig  * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1381f461d2dcSChristoph Hellwig  * large bitmaps may be represented in a compact manner. Writing into
1382f461d2dcSChristoph Hellwig  * the file will clear the bitmap then update it with the given input.
1383f461d2dcSChristoph Hellwig  *
1384f461d2dcSChristoph Hellwig  * Returns 0 on success.
1385f461d2dcSChristoph Hellwig  */
1386f461d2dcSChristoph Hellwig int proc_do_large_bitmap(struct ctl_table *table, int write,
138732927393SChristoph Hellwig 			 void *buffer, size_t *lenp, loff_t *ppos)
1388f461d2dcSChristoph Hellwig {
1389f461d2dcSChristoph Hellwig 	int err = 0;
1390f461d2dcSChristoph Hellwig 	size_t left = *lenp;
1391f461d2dcSChristoph Hellwig 	unsigned long bitmap_len = table->maxlen;
1392f461d2dcSChristoph Hellwig 	unsigned long *bitmap = *(unsigned long **) table->data;
1393f461d2dcSChristoph Hellwig 	unsigned long *tmp_bitmap = NULL;
1394f461d2dcSChristoph Hellwig 	char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1395f461d2dcSChristoph Hellwig 
1396f461d2dcSChristoph Hellwig 	if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1397f461d2dcSChristoph Hellwig 		*lenp = 0;
1398f461d2dcSChristoph Hellwig 		return 0;
1399f461d2dcSChristoph Hellwig 	}
1400f461d2dcSChristoph Hellwig 
1401f461d2dcSChristoph Hellwig 	if (write) {
140232927393SChristoph Hellwig 		char *p = buffer;
1403f461d2dcSChristoph Hellwig 		size_t skipped = 0;
1404f461d2dcSChristoph Hellwig 
1405f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1) {
1406f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
1407f461d2dcSChristoph Hellwig 			/* How much of the buffer we'll skip this pass */
1408f461d2dcSChristoph Hellwig 			skipped = *lenp - left;
1409f461d2dcSChristoph Hellwig 		}
1410f461d2dcSChristoph Hellwig 
1411f461d2dcSChristoph Hellwig 		tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
141232927393SChristoph Hellwig 		if (!tmp_bitmap)
1413f461d2dcSChristoph Hellwig 			return -ENOMEM;
1414f461d2dcSChristoph Hellwig 		proc_skip_char(&p, &left, '\n');
1415f461d2dcSChristoph Hellwig 		while (!err && left) {
1416f461d2dcSChristoph Hellwig 			unsigned long val_a, val_b;
1417f461d2dcSChristoph Hellwig 			bool neg;
1418f461d2dcSChristoph Hellwig 			size_t saved_left;
1419f461d2dcSChristoph Hellwig 
1420f461d2dcSChristoph Hellwig 			/* In case we stop parsing mid-number, we can reset */
1421f461d2dcSChristoph Hellwig 			saved_left = left;
1422f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1423f461d2dcSChristoph Hellwig 					     sizeof(tr_a), &c);
1424f461d2dcSChristoph Hellwig 			/*
1425f461d2dcSChristoph Hellwig 			 * If we consumed the entirety of a truncated buffer or
1426f461d2dcSChristoph Hellwig 			 * only one char is left (may be a "-"), then stop here,
1427f461d2dcSChristoph Hellwig 			 * reset, & come back for more.
1428f461d2dcSChristoph Hellwig 			 */
1429f461d2dcSChristoph Hellwig 			if ((left <= 1) && skipped) {
1430f461d2dcSChristoph Hellwig 				left = saved_left;
1431f461d2dcSChristoph Hellwig 				break;
1432f461d2dcSChristoph Hellwig 			}
1433f461d2dcSChristoph Hellwig 
1434f461d2dcSChristoph Hellwig 			if (err)
1435f461d2dcSChristoph Hellwig 				break;
1436f461d2dcSChristoph Hellwig 			if (val_a >= bitmap_len || neg) {
1437f461d2dcSChristoph Hellwig 				err = -EINVAL;
1438f461d2dcSChristoph Hellwig 				break;
1439f461d2dcSChristoph Hellwig 			}
1440f461d2dcSChristoph Hellwig 
1441f461d2dcSChristoph Hellwig 			val_b = val_a;
1442f461d2dcSChristoph Hellwig 			if (left) {
1443f461d2dcSChristoph Hellwig 				p++;
1444f461d2dcSChristoph Hellwig 				left--;
1445f461d2dcSChristoph Hellwig 			}
1446f461d2dcSChristoph Hellwig 
1447f461d2dcSChristoph Hellwig 			if (c == '-') {
1448f461d2dcSChristoph Hellwig 				err = proc_get_long(&p, &left, &val_b,
1449f461d2dcSChristoph Hellwig 						     &neg, tr_b, sizeof(tr_b),
1450f461d2dcSChristoph Hellwig 						     &c);
1451f461d2dcSChristoph Hellwig 				/*
1452f461d2dcSChristoph Hellwig 				 * If we consumed all of a truncated buffer or
1453f461d2dcSChristoph Hellwig 				 * then stop here, reset, & come back for more.
1454f461d2dcSChristoph Hellwig 				 */
1455f461d2dcSChristoph Hellwig 				if (!left && skipped) {
1456f461d2dcSChristoph Hellwig 					left = saved_left;
1457f461d2dcSChristoph Hellwig 					break;
1458f461d2dcSChristoph Hellwig 				}
1459f461d2dcSChristoph Hellwig 
1460f461d2dcSChristoph Hellwig 				if (err)
1461f461d2dcSChristoph Hellwig 					break;
1462f461d2dcSChristoph Hellwig 				if (val_b >= bitmap_len || neg ||
1463f461d2dcSChristoph Hellwig 				    val_a > val_b) {
1464f461d2dcSChristoph Hellwig 					err = -EINVAL;
1465f461d2dcSChristoph Hellwig 					break;
1466f461d2dcSChristoph Hellwig 				}
1467f461d2dcSChristoph Hellwig 				if (left) {
1468f461d2dcSChristoph Hellwig 					p++;
1469f461d2dcSChristoph Hellwig 					left--;
1470f461d2dcSChristoph Hellwig 				}
1471f461d2dcSChristoph Hellwig 			}
1472f461d2dcSChristoph Hellwig 
1473f461d2dcSChristoph Hellwig 			bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1474f461d2dcSChristoph Hellwig 			proc_skip_char(&p, &left, '\n');
1475f461d2dcSChristoph Hellwig 		}
1476f461d2dcSChristoph Hellwig 		left += skipped;
1477f461d2dcSChristoph Hellwig 	} else {
1478f461d2dcSChristoph Hellwig 		unsigned long bit_a, bit_b = 0;
14799a52c5f3SJiapeng Chong 		bool first = 1;
1480f461d2dcSChristoph Hellwig 
1481f461d2dcSChristoph Hellwig 		while (left) {
1482f461d2dcSChristoph Hellwig 			bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1483f461d2dcSChristoph Hellwig 			if (bit_a >= bitmap_len)
1484f461d2dcSChristoph Hellwig 				break;
1485f461d2dcSChristoph Hellwig 			bit_b = find_next_zero_bit(bitmap, bitmap_len,
1486f461d2dcSChristoph Hellwig 						   bit_a + 1) - 1;
1487f461d2dcSChristoph Hellwig 
148832927393SChristoph Hellwig 			if (!first)
148932927393SChristoph Hellwig 				proc_put_char(&buffer, &left, ',');
149032927393SChristoph Hellwig 			proc_put_long(&buffer, &left, bit_a, false);
1491f461d2dcSChristoph Hellwig 			if (bit_a != bit_b) {
149232927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '-');
149332927393SChristoph Hellwig 				proc_put_long(&buffer, &left, bit_b, false);
1494f461d2dcSChristoph Hellwig 			}
1495f461d2dcSChristoph Hellwig 
1496f461d2dcSChristoph Hellwig 			first = 0; bit_b++;
1497f461d2dcSChristoph Hellwig 		}
149832927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
1499f461d2dcSChristoph Hellwig 	}
1500f461d2dcSChristoph Hellwig 
1501f461d2dcSChristoph Hellwig 	if (!err) {
1502f461d2dcSChristoph Hellwig 		if (write) {
1503f461d2dcSChristoph Hellwig 			if (*ppos)
1504f461d2dcSChristoph Hellwig 				bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1505f461d2dcSChristoph Hellwig 			else
1506f461d2dcSChristoph Hellwig 				bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1507f461d2dcSChristoph Hellwig 		}
1508f461d2dcSChristoph Hellwig 		*lenp -= left;
1509f461d2dcSChristoph Hellwig 		*ppos += *lenp;
1510f461d2dcSChristoph Hellwig 	}
1511f461d2dcSChristoph Hellwig 
1512f461d2dcSChristoph Hellwig 	bitmap_free(tmp_bitmap);
1513f461d2dcSChristoph Hellwig 	return err;
1514f461d2dcSChristoph Hellwig }
1515f461d2dcSChristoph Hellwig 
1516f461d2dcSChristoph Hellwig #else /* CONFIG_PROC_SYSCTL */
1517f461d2dcSChristoph Hellwig 
1518f461d2dcSChristoph Hellwig int proc_dostring(struct ctl_table *table, int write,
151932927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1520f461d2dcSChristoph Hellwig {
1521f461d2dcSChristoph Hellwig 	return -ENOSYS;
1522f461d2dcSChristoph Hellwig }
1523f461d2dcSChristoph Hellwig 
1524a2071573SJia He int proc_dobool(struct ctl_table *table, int write,
1525a2071573SJia He 		void *buffer, size_t *lenp, loff_t *ppos)
1526a2071573SJia He {
1527a2071573SJia He 	return -ENOSYS;
1528a2071573SJia He }
1529a2071573SJia He 
1530f461d2dcSChristoph Hellwig int proc_dointvec(struct ctl_table *table, int write,
153132927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1532f461d2dcSChristoph Hellwig {
1533f461d2dcSChristoph Hellwig 	return -ENOSYS;
1534f461d2dcSChristoph Hellwig }
1535f461d2dcSChristoph Hellwig 
1536f461d2dcSChristoph Hellwig int proc_douintvec(struct ctl_table *table, int write,
153732927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1538f461d2dcSChristoph Hellwig {
1539f461d2dcSChristoph Hellwig 	return -ENOSYS;
1540f461d2dcSChristoph Hellwig }
1541f461d2dcSChristoph Hellwig 
1542f461d2dcSChristoph Hellwig int proc_dointvec_minmax(struct ctl_table *table, int write,
154332927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1544f461d2dcSChristoph Hellwig {
1545f461d2dcSChristoph Hellwig 	return -ENOSYS;
1546f461d2dcSChristoph Hellwig }
1547f461d2dcSChristoph Hellwig 
1548f461d2dcSChristoph Hellwig int proc_douintvec_minmax(struct ctl_table *table, int write,
154932927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
1550f461d2dcSChristoph Hellwig {
1551f461d2dcSChristoph Hellwig 	return -ENOSYS;
1552f461d2dcSChristoph Hellwig }
1553f461d2dcSChristoph Hellwig 
1554cb944413SEric Dumazet int proc_dou8vec_minmax(struct ctl_table *table, int write,
1555cb944413SEric Dumazet 			void *buffer, size_t *lenp, loff_t *ppos)
1556cb944413SEric Dumazet {
1557cb944413SEric Dumazet 	return -ENOSYS;
1558cb944413SEric Dumazet }
1559cb944413SEric Dumazet 
1560f461d2dcSChristoph Hellwig int proc_dointvec_jiffies(struct ctl_table *table, int write,
156132927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1562f461d2dcSChristoph Hellwig {
1563f461d2dcSChristoph Hellwig 	return -ENOSYS;
1564f461d2dcSChristoph Hellwig }
1565f461d2dcSChristoph Hellwig 
1566c381d02bSYuwei Wang int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1567c381d02bSYuwei Wang 				    void *buffer, size_t *lenp, loff_t *ppos)
1568c381d02bSYuwei Wang {
1569c381d02bSYuwei Wang 	return -ENOSYS;
1570c381d02bSYuwei Wang }
1571c381d02bSYuwei Wang 
1572f461d2dcSChristoph Hellwig int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
157332927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1574f461d2dcSChristoph Hellwig {
1575f461d2dcSChristoph Hellwig 	return -ENOSYS;
1576f461d2dcSChristoph Hellwig }
1577f461d2dcSChristoph Hellwig 
1578f461d2dcSChristoph Hellwig int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
157932927393SChristoph Hellwig 			     void *buffer, size_t *lenp, loff_t *ppos)
1580f461d2dcSChristoph Hellwig {
1581f461d2dcSChristoph Hellwig 	return -ENOSYS;
1582f461d2dcSChristoph Hellwig }
1583f461d2dcSChristoph Hellwig 
1584f461d2dcSChristoph Hellwig int proc_doulongvec_minmax(struct ctl_table *table, int write,
158532927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1586f461d2dcSChristoph Hellwig {
1587f461d2dcSChristoph Hellwig 	return -ENOSYS;
1588f461d2dcSChristoph Hellwig }
1589f461d2dcSChristoph Hellwig 
1590f461d2dcSChristoph Hellwig int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
159132927393SChristoph Hellwig 				      void *buffer, size_t *lenp, loff_t *ppos)
1592f461d2dcSChristoph Hellwig {
1593f461d2dcSChristoph Hellwig 	return -ENOSYS;
1594f461d2dcSChristoph Hellwig }
1595f461d2dcSChristoph Hellwig 
1596f461d2dcSChristoph Hellwig int proc_do_large_bitmap(struct ctl_table *table, int write,
159732927393SChristoph Hellwig 			 void *buffer, size_t *lenp, loff_t *ppos)
1598f461d2dcSChristoph Hellwig {
1599f461d2dcSChristoph Hellwig 	return -ENOSYS;
1600f461d2dcSChristoph Hellwig }
1601f461d2dcSChristoph Hellwig 
1602f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */
1603f461d2dcSChristoph Hellwig 
1604f461d2dcSChristoph Hellwig #if defined(CONFIG_SYSCTL)
1605f461d2dcSChristoph Hellwig int proc_do_static_key(struct ctl_table *table, int write,
160632927393SChristoph Hellwig 		       void *buffer, size_t *lenp, loff_t *ppos)
1607f461d2dcSChristoph Hellwig {
1608f461d2dcSChristoph Hellwig 	struct static_key *key = (struct static_key *)table->data;
1609f461d2dcSChristoph Hellwig 	static DEFINE_MUTEX(static_key_mutex);
1610f461d2dcSChristoph Hellwig 	int val, ret;
1611f461d2dcSChristoph Hellwig 	struct ctl_table tmp = {
1612f461d2dcSChristoph Hellwig 		.data   = &val,
1613f461d2dcSChristoph Hellwig 		.maxlen = sizeof(val),
1614f461d2dcSChristoph Hellwig 		.mode   = table->mode,
1615f461d2dcSChristoph Hellwig 		.extra1 = SYSCTL_ZERO,
1616f461d2dcSChristoph Hellwig 		.extra2 = SYSCTL_ONE,
1617f461d2dcSChristoph Hellwig 	};
1618f461d2dcSChristoph Hellwig 
1619f461d2dcSChristoph Hellwig 	if (write && !capable(CAP_SYS_ADMIN))
1620f461d2dcSChristoph Hellwig 		return -EPERM;
1621f461d2dcSChristoph Hellwig 
1622f461d2dcSChristoph Hellwig 	mutex_lock(&static_key_mutex);
1623f461d2dcSChristoph Hellwig 	val = static_key_enabled(key);
1624f461d2dcSChristoph Hellwig 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1625f461d2dcSChristoph Hellwig 	if (write && !ret) {
1626f461d2dcSChristoph Hellwig 		if (val)
1627f461d2dcSChristoph Hellwig 			static_key_enable(key);
1628f461d2dcSChristoph Hellwig 		else
1629f461d2dcSChristoph Hellwig 			static_key_disable(key);
1630f461d2dcSChristoph Hellwig 	}
1631f461d2dcSChristoph Hellwig 	mutex_unlock(&static_key_mutex);
1632f461d2dcSChristoph Hellwig 	return ret;
1633f461d2dcSChristoph Hellwig }
1634f461d2dcSChristoph Hellwig 
1635d8217f07SEric W. Biederman static struct ctl_table kern_table[] = {
1636b7cc6ec7SMel Gorman #ifdef CONFIG_NUMA_BALANCING
16373a7053b3SMel Gorman 	{
163854a43d54SAndi Kleen 		.procname	= "numa_balancing",
163954a43d54SAndi Kleen 		.data		= NULL, /* filled in by handler */
164054a43d54SAndi Kleen 		.maxlen		= sizeof(unsigned int),
164154a43d54SAndi Kleen 		.mode		= 0644,
164254a43d54SAndi Kleen 		.proc_handler	= sysctl_numa_balancing,
1643eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
1644c574bbe9SHuang Ying 		.extra2		= SYSCTL_FOUR,
164554a43d54SAndi Kleen 	},
1646c6833e10SHuang Ying 	{
1647c6833e10SHuang Ying 		.procname	= "numa_balancing_promote_rate_limit_MBps",
1648c6833e10SHuang Ying 		.data		= &sysctl_numa_balancing_promote_rate_limit,
1649c6833e10SHuang Ying 		.maxlen		= sizeof(unsigned int),
1650c6833e10SHuang Ying 		.mode		= 0644,
1651c6833e10SHuang Ying 		.proc_handler	= proc_dointvec_minmax,
1652c6833e10SHuang Ying 		.extra1		= SYSCTL_ZERO,
1653c6833e10SHuang Ying 	},
1654cbee9f88SPeter Zijlstra #endif /* CONFIG_NUMA_BALANCING */
16551799e35dSIngo Molnar 	{
16561da177e4SLinus Torvalds 		.procname	= "panic",
16571da177e4SLinus Torvalds 		.data		= &panic_timeout,
16581da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
16591da177e4SLinus Torvalds 		.mode		= 0644,
16606d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
16611da177e4SLinus Torvalds 	},
166234f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL
16631da177e4SLinus Torvalds 	{
16641da177e4SLinus Torvalds 		.procname	= "tainted",
166525ddbb18SAndi Kleen 		.maxlen 	= sizeof(long),
166634f5a398STheodore Ts'o 		.mode		= 0644,
16676d456111SEric W. Biederman 		.proc_handler	= proc_taint,
16681da177e4SLinus Torvalds 	},
1669f4aacea2SKees Cook 	{
1670f4aacea2SKees Cook 		.procname	= "sysctl_writes_strict",
1671f4aacea2SKees Cook 		.data		= &sysctl_writes_strict,
1672f4aacea2SKees Cook 		.maxlen		= sizeof(int),
1673f4aacea2SKees Cook 		.mode		= 0644,
1674f4aacea2SKees Cook 		.proc_handler	= proc_dointvec_minmax,
167578e36f3bSXiaoming Ni 		.extra1		= SYSCTL_NEG_ONE,
1676eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
1677f4aacea2SKees Cook 	},
167834f5a398STheodore Ts'o #endif
167945807a1dSIngo Molnar 	{
168045807a1dSIngo Molnar 		.procname	= "print-fatal-signals",
168145807a1dSIngo Molnar 		.data		= &print_fatal_signals,
168245807a1dSIngo Molnar 		.maxlen		= sizeof(int),
168345807a1dSIngo Molnar 		.mode		= 0644,
16846d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
168545807a1dSIngo Molnar 	},
168672c57ed5SDavid S. Miller #ifdef CONFIG_SPARC
16871da177e4SLinus Torvalds 	{
16881da177e4SLinus Torvalds 		.procname	= "reboot-cmd",
16891da177e4SLinus Torvalds 		.data		= reboot_command,
16901da177e4SLinus Torvalds 		.maxlen		= 256,
16911da177e4SLinus Torvalds 		.mode		= 0644,
16926d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
16931da177e4SLinus Torvalds 	},
16941da177e4SLinus Torvalds 	{
16951da177e4SLinus Torvalds 		.procname	= "stop-a",
16961da177e4SLinus Torvalds 		.data		= &stop_a_enabled,
16971da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
16981da177e4SLinus Torvalds 		.mode		= 0644,
16996d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
17001da177e4SLinus Torvalds 	},
17011da177e4SLinus Torvalds 	{
17021da177e4SLinus Torvalds 		.procname	= "scons-poweroff",
17031da177e4SLinus Torvalds 		.data		= &scons_pwroff,
17041da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
17051da177e4SLinus Torvalds 		.mode		= 0644,
17066d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
17071da177e4SLinus Torvalds 	},
17081da177e4SLinus Torvalds #endif
17090871420fSDavid S. Miller #ifdef CONFIG_SPARC64
17100871420fSDavid S. Miller 	{
17110871420fSDavid S. Miller 		.procname	= "tsb-ratio",
17120871420fSDavid S. Miller 		.data		= &sysctl_tsb_ratio,
17130871420fSDavid S. Miller 		.maxlen		= sizeof (int),
17140871420fSDavid S. Miller 		.mode		= 0644,
17156d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
17160871420fSDavid S. Miller 	},
17170871420fSDavid S. Miller #endif
1718b67114dbSHelge Deller #ifdef CONFIG_PARISC
17191da177e4SLinus Torvalds 	{
17201da177e4SLinus Torvalds 		.procname	= "soft-power",
17211da177e4SLinus Torvalds 		.data		= &pwrsw_enabled,
17221da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
17231da177e4SLinus Torvalds 		.mode		= 0644,
17246d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
17251da177e4SLinus Torvalds 	},
1726bf14e3b9SVineet Gupta #endif
1727bf14e3b9SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
17281da177e4SLinus Torvalds 	{
17291da177e4SLinus Torvalds 		.procname	= "unaligned-trap",
17301da177e4SLinus Torvalds 		.data		= &unaligned_enabled,
17311da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
17321da177e4SLinus Torvalds 		.mode		= 0644,
17336d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
17341da177e4SLinus Torvalds 	},
17351da177e4SLinus Torvalds #endif
1736f38f1d2aSSteven Rostedt #ifdef CONFIG_STACK_TRACER
1737f38f1d2aSSteven Rostedt 	{
1738f38f1d2aSSteven Rostedt 		.procname	= "stack_tracer_enabled",
1739f38f1d2aSSteven Rostedt 		.data		= &stack_tracer_enabled,
1740f38f1d2aSSteven Rostedt 		.maxlen		= sizeof(int),
1741f38f1d2aSSteven Rostedt 		.mode		= 0644,
17426d456111SEric W. Biederman 		.proc_handler	= stack_trace_sysctl,
1743f38f1d2aSSteven Rostedt 	},
1744f38f1d2aSSteven Rostedt #endif
1745944ac425SSteven Rostedt #ifdef CONFIG_TRACING
1746944ac425SSteven Rostedt 	{
17473299b4ddSPeter Zijlstra 		.procname	= "ftrace_dump_on_oops",
1748944ac425SSteven Rostedt 		.data		= &ftrace_dump_on_oops,
1749944ac425SSteven Rostedt 		.maxlen		= sizeof(int),
1750944ac425SSteven Rostedt 		.mode		= 0644,
17516d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1752944ac425SSteven Rostedt 	},
1753de7edd31SSteven Rostedt (Red Hat) 	{
1754de7edd31SSteven Rostedt (Red Hat) 		.procname	= "traceoff_on_warning",
1755de7edd31SSteven Rostedt (Red Hat) 		.data		= &__disable_trace_on_warning,
1756de7edd31SSteven Rostedt (Red Hat) 		.maxlen		= sizeof(__disable_trace_on_warning),
1757de7edd31SSteven Rostedt (Red Hat) 		.mode		= 0644,
1758de7edd31SSteven Rostedt (Red Hat) 		.proc_handler	= proc_dointvec,
1759de7edd31SSteven Rostedt (Red Hat) 	},
17600daa2302SSteven Rostedt (Red Hat) 	{
17610daa2302SSteven Rostedt (Red Hat) 		.procname	= "tracepoint_printk",
17620daa2302SSteven Rostedt (Red Hat) 		.data		= &tracepoint_printk,
17630daa2302SSteven Rostedt (Red Hat) 		.maxlen		= sizeof(tracepoint_printk),
17640daa2302SSteven Rostedt (Red Hat) 		.mode		= 0644,
176542391745SSteven Rostedt (Red Hat) 		.proc_handler	= tracepoint_printk_sysctl,
17660daa2302SSteven Rostedt (Red Hat) 	},
1767944ac425SSteven Rostedt #endif
1768a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES
17691da177e4SLinus Torvalds 	{
17701da177e4SLinus Torvalds 		.procname	= "modprobe",
17711da177e4SLinus Torvalds 		.data		= &modprobe_path,
17721da177e4SLinus Torvalds 		.maxlen		= KMOD_PATH_LEN,
17731da177e4SLinus Torvalds 		.mode		= 0644,
17746d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
17751da177e4SLinus Torvalds 	},
17763d43321bSKees Cook 	{
17773d43321bSKees Cook 		.procname	= "modules_disabled",
17783d43321bSKees Cook 		.data		= &modules_disabled,
17793d43321bSKees Cook 		.maxlen		= sizeof(int),
17803d43321bSKees Cook 		.mode		= 0644,
17813d43321bSKees Cook 		/* only handle a transition from default "0" to "1" */
17826d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
1783eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
1784eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
17853d43321bSKees Cook 	},
17861da177e4SLinus Torvalds #endif
178786d56134SMichael Marineau #ifdef CONFIG_UEVENT_HELPER
17881da177e4SLinus Torvalds 	{
17891da177e4SLinus Torvalds 		.procname	= "hotplug",
1790312c004dSKay Sievers 		.data		= &uevent_helper,
1791312c004dSKay Sievers 		.maxlen		= UEVENT_HELPER_PATH_LEN,
17921da177e4SLinus Torvalds 		.mode		= 0644,
17936d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
17941da177e4SLinus Torvalds 	},
179586d56134SMichael Marineau #endif
17961da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ
17971da177e4SLinus Torvalds 	{
17981da177e4SLinus Torvalds 		.procname	= "sysrq",
1799eaee4172SDmitry Safonov 		.data		= NULL,
18001da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
18011da177e4SLinus Torvalds 		.mode		= 0644,
180297f5f0cdSDmitry Torokhov 		.proc_handler	= sysrq_sysctl_handler,
18031da177e4SLinus Torvalds 	},
18041da177e4SLinus Torvalds #endif
1805d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
18061da177e4SLinus Torvalds 	{
18071da177e4SLinus Torvalds 		.procname	= "cad_pid",
18089ec52099SCedric Le Goater 		.data		= NULL,
18091da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
18101da177e4SLinus Torvalds 		.mode		= 0600,
18116d456111SEric W. Biederman 		.proc_handler	= proc_do_cad_pid,
18121da177e4SLinus Torvalds 	},
1813d6f8ff73SRandy Dunlap #endif
18141da177e4SLinus Torvalds 	{
18151da177e4SLinus Torvalds 		.procname	= "threads-max",
181616db3d3fSHeinrich Schuchardt 		.data		= NULL,
18171da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
18181da177e4SLinus Torvalds 		.mode		= 0644,
181916db3d3fSHeinrich Schuchardt 		.proc_handler	= sysctl_max_threads,
18201da177e4SLinus Torvalds 	},
18211da177e4SLinus Torvalds 	{
182217f60a7dSEric Paris 		.procname	= "usermodehelper",
182317f60a7dSEric Paris 		.mode		= 0555,
182417f60a7dSEric Paris 		.child		= usermodehelper_table,
182517f60a7dSEric Paris 	},
182617f60a7dSEric Paris 	{
18271da177e4SLinus Torvalds 		.procname	= "overflowuid",
18281da177e4SLinus Torvalds 		.data		= &overflowuid,
18291da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
18301da177e4SLinus Torvalds 		.mode		= 0644,
18316d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
18322452dcb9SXiaoming Ni 		.extra1		= SYSCTL_ZERO,
183354771613SLuis Chamberlain 		.extra2		= SYSCTL_MAXOLDUID,
18341da177e4SLinus Torvalds 	},
18351da177e4SLinus Torvalds 	{
18361da177e4SLinus Torvalds 		.procname	= "overflowgid",
18371da177e4SLinus Torvalds 		.data		= &overflowgid,
18381da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
18391da177e4SLinus Torvalds 		.mode		= 0644,
18406d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
18412452dcb9SXiaoming Ni 		.extra1		= SYSCTL_ZERO,
184254771613SLuis Chamberlain 		.extra2		= SYSCTL_MAXOLDUID,
18431da177e4SLinus Torvalds 	},
1844347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
18451da177e4SLinus Torvalds 	{
18461da177e4SLinus Torvalds 		.procname	= "userprocess_debug",
1847ab3c68eeSHeiko Carstens 		.data		= &show_unhandled_signals,
18481da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
18491da177e4SLinus Torvalds 		.mode		= 0644,
18506d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18511da177e4SLinus Torvalds 	},
18521da177e4SLinus Torvalds #endif
18531da177e4SLinus Torvalds 	{
18541da177e4SLinus Torvalds 		.procname	= "pid_max",
18551da177e4SLinus Torvalds 		.data		= &pid_max,
18561da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
18571da177e4SLinus Torvalds 		.mode		= 0644,
18586d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
18591da177e4SLinus Torvalds 		.extra1		= &pid_max_min,
18601da177e4SLinus Torvalds 		.extra2		= &pid_max_max,
18611da177e4SLinus Torvalds 	},
18621da177e4SLinus Torvalds 	{
18631da177e4SLinus Torvalds 		.procname	= "panic_on_oops",
18641da177e4SLinus Torvalds 		.data		= &panic_on_oops,
18651da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
18661da177e4SLinus Torvalds 		.mode		= 0644,
18676d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18681da177e4SLinus Torvalds 	},
186981c9d43fSFeng Tang 	{
187081c9d43fSFeng Tang 		.procname	= "panic_print",
187181c9d43fSFeng Tang 		.data		= &panic_print,
187281c9d43fSFeng Tang 		.maxlen		= sizeof(unsigned long),
187381c9d43fSFeng Tang 		.mode		= 0644,
187481c9d43fSFeng Tang 		.proc_handler	= proc_doulongvec_minmax,
187581c9d43fSFeng Tang 	},
1876eaf06b24SDan Rosenberg 	{
18771da177e4SLinus Torvalds 		.procname	= "ngroups_max",
1878f628867dSStephen Kitt 		.data		= (void *)&ngroups_max,
18791da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
18801da177e4SLinus Torvalds 		.mode		= 0444,
18816d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18821da177e4SLinus Torvalds 	},
188373efc039SDan Ballard 	{
188473efc039SDan Ballard 		.procname	= "cap_last_cap",
188573efc039SDan Ballard 		.data		= (void *)&cap_last_cap,
188673efc039SDan Ballard 		.maxlen		= sizeof(int),
188773efc039SDan Ballard 		.mode		= 0444,
188873efc039SDan Ballard 		.proc_handler	= proc_dointvec,
188973efc039SDan Ballard 	},
18905dc30558SDon Zickus #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
18915dc30558SDon Zickus 	{
18925dc30558SDon Zickus 		.procname       = "unknown_nmi_panic",
18935dc30558SDon Zickus 		.data           = &unknown_nmi_panic,
18945dc30558SDon Zickus 		.maxlen         = sizeof (int),
18955dc30558SDon Zickus 		.mode           = 0644,
18965dc30558SDon Zickus 		.proc_handler   = proc_dointvec,
18975dc30558SDon Zickus 	},
1898504d7cf1SDon Zickus #endif
1899b6522fa4SXiaoming Ni 
1900b6522fa4SXiaoming Ni #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
1901b6522fa4SXiaoming Ni 	defined(CONFIG_DEBUG_STACKOVERFLOW)
1902b6522fa4SXiaoming Ni 	{
1903b6522fa4SXiaoming Ni 		.procname	= "panic_on_stackoverflow",
1904b6522fa4SXiaoming Ni 		.data		= &sysctl_panic_on_stackoverflow,
1905b6522fa4SXiaoming Ni 		.maxlen		= sizeof(int),
1906b6522fa4SXiaoming Ni 		.mode		= 0644,
1907b6522fa4SXiaoming Ni 		.proc_handler	= proc_dointvec,
1908b6522fa4SXiaoming Ni 	},
1909b6522fa4SXiaoming Ni #endif
19101da177e4SLinus Torvalds #if defined(CONFIG_X86)
19111da177e4SLinus Torvalds 	{
19128da5addaSDon Zickus 		.procname	= "panic_on_unrecovered_nmi",
19138da5addaSDon Zickus 		.data		= &panic_on_unrecovered_nmi,
19148da5addaSDon Zickus 		.maxlen		= sizeof(int),
19158da5addaSDon Zickus 		.mode		= 0644,
19166d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19178da5addaSDon Zickus 	},
19188da5addaSDon Zickus 	{
19195211a242SKurt Garloff 		.procname	= "panic_on_io_nmi",
19205211a242SKurt Garloff 		.data		= &panic_on_io_nmi,
19215211a242SKurt Garloff 		.maxlen		= sizeof(int),
19225211a242SKurt Garloff 		.mode		= 0644,
19236d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19245211a242SKurt Garloff 	},
19255211a242SKurt Garloff 	{
19261da177e4SLinus Torvalds 		.procname	= "bootloader_type",
19271da177e4SLinus Torvalds 		.data		= &bootloader_type,
19281da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
19291da177e4SLinus Torvalds 		.mode		= 0444,
19306d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19311da177e4SLinus Torvalds 	},
19320741f4d2SChuck Ebbert 	{
19335031296cSH. Peter Anvin 		.procname	= "bootloader_version",
19345031296cSH. Peter Anvin 		.data		= &bootloader_version,
19355031296cSH. Peter Anvin 		.maxlen		= sizeof (int),
19365031296cSH. Peter Anvin 		.mode		= 0444,
19376d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19385031296cSH. Peter Anvin 	},
19395031296cSH. Peter Anvin 	{
19406e7c4025SIngo Molnar 		.procname	= "io_delay_type",
19416e7c4025SIngo Molnar 		.data		= &io_delay_type,
19426e7c4025SIngo Molnar 		.maxlen		= sizeof(int),
19436e7c4025SIngo Molnar 		.mode		= 0644,
19446d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19456e7c4025SIngo Molnar 	},
19461da177e4SLinus Torvalds #endif
19477a9166e3SLuke Yang #if defined(CONFIG_MMU)
19481da177e4SLinus Torvalds 	{
19491da177e4SLinus Torvalds 		.procname	= "randomize_va_space",
19501da177e4SLinus Torvalds 		.data		= &randomize_va_space,
19511da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
19521da177e4SLinus Torvalds 		.mode		= 0644,
19536d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19541da177e4SLinus Torvalds 	},
19557a9166e3SLuke Yang #endif
19560152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1957951f22d5SMartin Schwidefsky 	{
1958951f22d5SMartin Schwidefsky 		.procname	= "spin_retry",
1959951f22d5SMartin Schwidefsky 		.data		= &spin_retry,
1960951f22d5SMartin Schwidefsky 		.maxlen		= sizeof (int),
1961951f22d5SMartin Schwidefsky 		.mode		= 0644,
19626d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1963951f22d5SMartin Schwidefsky 	},
1964951f22d5SMartin Schwidefsky #endif
1965673d5b43SLen Brown #if	defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1966c255d844SPavel Machek 	{
1967c255d844SPavel Machek 		.procname	= "acpi_video_flags",
196877afcf78SPavel Machek 		.data		= &acpi_realmode_flags,
1969c255d844SPavel Machek 		.maxlen		= sizeof (unsigned long),
1970c255d844SPavel Machek 		.mode		= 0644,
19716d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
1972c255d844SPavel Machek 	},
1973c255d844SPavel Machek #endif
1974b6fca725SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1975d2b176edSJes Sorensen 	{
1976d2b176edSJes Sorensen 		.procname	= "ignore-unaligned-usertrap",
1977d2b176edSJes Sorensen 		.data		= &no_unaligned_warning,
1978d2b176edSJes Sorensen 		.maxlen		= sizeof (int),
1979d2b176edSJes Sorensen 		.mode		= 0644,
19806d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1981d2b176edSJes Sorensen 	},
1982b6fca725SVineet Gupta #endif
1983b6fca725SVineet Gupta #ifdef CONFIG_IA64
198488fc241fSDoug Chapman 	{
198588fc241fSDoug Chapman 		.procname	= "unaligned-dump-stack",
198688fc241fSDoug Chapman 		.data		= &unaligned_dump_stack,
198788fc241fSDoug Chapman 		.maxlen		= sizeof (int),
198888fc241fSDoug Chapman 		.mode		= 0644,
19896d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
199088fc241fSDoug Chapman 	},
1991d2b176edSJes Sorensen #endif
199223f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
199323f78d4aSIngo Molnar 	{
199423f78d4aSIngo Molnar 		.procname	= "max_lock_depth",
199523f78d4aSIngo Molnar 		.data		= &max_lock_depth,
199623f78d4aSIngo Molnar 		.maxlen		= sizeof(int),
199723f78d4aSIngo Molnar 		.mode		= 0644,
19986d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
199923f78d4aSIngo Molnar 	},
200023f78d4aSIngo Molnar #endif
20010b77f5bfSDavid Howells #ifdef CONFIG_KEYS
20020b77f5bfSDavid Howells 	{
20030b77f5bfSDavid Howells 		.procname	= "keys",
20040b77f5bfSDavid Howells 		.mode		= 0555,
20050b77f5bfSDavid Howells 		.child		= key_sysctls,
20060b77f5bfSDavid Howells 	},
20070b77f5bfSDavid Howells #endif
2008cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS
2009aa4a2218SVince Weaver 	/*
2010aa4a2218SVince Weaver 	 * User-space scripts rely on the existence of this file
2011aa4a2218SVince Weaver 	 * as a feature check for perf_events being enabled.
2012aa4a2218SVince Weaver 	 *
2013aa4a2218SVince Weaver 	 * So it's an ABI, do not remove!
2014aa4a2218SVince Weaver 	 */
20151ccd1549SPeter Zijlstra 	{
2016cdd6c482SIngo Molnar 		.procname	= "perf_event_paranoid",
2017cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_paranoid,
2018cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_paranoid),
20191ccd1549SPeter Zijlstra 		.mode		= 0644,
20206d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
20211ccd1549SPeter Zijlstra 	},
2022c5078f78SPeter Zijlstra 	{
2023cdd6c482SIngo Molnar 		.procname	= "perf_event_mlock_kb",
2024cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_mlock,
2025cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_mlock),
2026c5078f78SPeter Zijlstra 		.mode		= 0644,
20276d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2028c5078f78SPeter Zijlstra 	},
2029a78ac325SPeter Zijlstra 	{
2030cdd6c482SIngo Molnar 		.procname	= "perf_event_max_sample_rate",
2031cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_sample_rate,
2032cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_sample_rate),
2033a78ac325SPeter Zijlstra 		.mode		= 0644,
2034163ec435SPeter Zijlstra 		.proc_handler	= perf_proc_update_handler,
2035eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
2036a78ac325SPeter Zijlstra 	},
203714c63f17SDave Hansen 	{
203814c63f17SDave Hansen 		.procname	= "perf_cpu_time_max_percent",
203914c63f17SDave Hansen 		.data		= &sysctl_perf_cpu_time_max_percent,
204014c63f17SDave Hansen 		.maxlen		= sizeof(sysctl_perf_cpu_time_max_percent),
204114c63f17SDave Hansen 		.mode		= 0644,
204214c63f17SDave Hansen 		.proc_handler	= perf_cpu_time_max_percent_handler,
2043eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
204478e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_HUNDRED,
204514c63f17SDave Hansen 	},
2046c5dfd78eSArnaldo Carvalho de Melo 	{
2047c5dfd78eSArnaldo Carvalho de Melo 		.procname	= "perf_event_max_stack",
2048a831100aSArnaldo Carvalho de Melo 		.data		= &sysctl_perf_event_max_stack,
2049c5dfd78eSArnaldo Carvalho de Melo 		.maxlen		= sizeof(sysctl_perf_event_max_stack),
2050c5dfd78eSArnaldo Carvalho de Melo 		.mode		= 0644,
2051c5dfd78eSArnaldo Carvalho de Melo 		.proc_handler	= perf_event_max_stack_handler,
2052eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2053d73840ecSXiaoming Ni 		.extra2		= (void *)&six_hundred_forty_kb,
2054c5dfd78eSArnaldo Carvalho de Melo 	},
2055c85b0334SArnaldo Carvalho de Melo 	{
2056c85b0334SArnaldo Carvalho de Melo 		.procname	= "perf_event_max_contexts_per_stack",
2057c85b0334SArnaldo Carvalho de Melo 		.data		= &sysctl_perf_event_max_contexts_per_stack,
2058c85b0334SArnaldo Carvalho de Melo 		.maxlen		= sizeof(sysctl_perf_event_max_contexts_per_stack),
2059c85b0334SArnaldo Carvalho de Melo 		.mode		= 0644,
2060c85b0334SArnaldo Carvalho de Melo 		.proc_handler	= perf_event_max_stack_handler,
2061eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
206278e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_THOUSAND,
2063c85b0334SArnaldo Carvalho de Melo 	},
20641ccd1549SPeter Zijlstra #endif
20659e3961a0SPrarit Bhargava 	{
20669e3961a0SPrarit Bhargava 		.procname	= "panic_on_warn",
20679e3961a0SPrarit Bhargava 		.data		= &panic_on_warn,
20689e3961a0SPrarit Bhargava 		.maxlen		= sizeof(int),
20699e3961a0SPrarit Bhargava 		.mode		= 0644,
20709e3961a0SPrarit Bhargava 		.proc_handler	= proc_dointvec_minmax,
2071eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2072eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
20739e3961a0SPrarit Bhargava 	},
20747251ceb5SGeert Uytterhoeven #ifdef CONFIG_TREE_RCU
2075088e9d25SDaniel Bristot de Oliveira 	{
2076088e9d25SDaniel Bristot de Oliveira 		.procname	= "panic_on_rcu_stall",
2077088e9d25SDaniel Bristot de Oliveira 		.data		= &sysctl_panic_on_rcu_stall,
2078088e9d25SDaniel Bristot de Oliveira 		.maxlen		= sizeof(sysctl_panic_on_rcu_stall),
2079088e9d25SDaniel Bristot de Oliveira 		.mode		= 0644,
2080088e9d25SDaniel Bristot de Oliveira 		.proc_handler	= proc_dointvec_minmax,
2081eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2082eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2083088e9d25SDaniel Bristot de Oliveira 	},
2084dfe56404Schao 	{
2085dfe56404Schao 		.procname	= "max_rcu_stall_to_panic",
2086dfe56404Schao 		.data		= &sysctl_max_rcu_stall_to_panic,
2087dfe56404Schao 		.maxlen		= sizeof(sysctl_max_rcu_stall_to_panic),
2088dfe56404Schao 		.mode		= 0644,
2089dfe56404Schao 		.proc_handler	= proc_dointvec_minmax,
2090dfe56404Schao 		.extra1		= SYSCTL_ONE,
2091dfe56404Schao 		.extra2		= SYSCTL_INT_MAX,
2092dfe56404Schao 	},
2093dfe56404Schao #endif
20946fce56ecSEric W. Biederman 	{ }
20951da177e4SLinus Torvalds };
20961da177e4SLinus Torvalds 
2097d8217f07SEric W. Biederman static struct ctl_table vm_table[] = {
20981da177e4SLinus Torvalds 	{
20991da177e4SLinus Torvalds 		.procname	= "overcommit_memory",
21001da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_memory,
21011da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_memory),
21021da177e4SLinus Torvalds 		.mode		= 0644,
210356f3547bSFeng Tang 		.proc_handler	= overcommit_policy_handler,
2104eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
210578e36f3bSXiaoming Ni 		.extra2		= SYSCTL_TWO,
21061da177e4SLinus Torvalds 	},
21071da177e4SLinus Torvalds 	{
21081da177e4SLinus Torvalds 		.procname	= "overcommit_ratio",
21091da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_ratio,
21101da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_ratio),
21111da177e4SLinus Torvalds 		.mode		= 0644,
211249f0ce5fSJerome Marchand 		.proc_handler	= overcommit_ratio_handler,
211349f0ce5fSJerome Marchand 	},
211449f0ce5fSJerome Marchand 	{
211549f0ce5fSJerome Marchand 		.procname	= "overcommit_kbytes",
211649f0ce5fSJerome Marchand 		.data		= &sysctl_overcommit_kbytes,
211749f0ce5fSJerome Marchand 		.maxlen		= sizeof(sysctl_overcommit_kbytes),
211849f0ce5fSJerome Marchand 		.mode		= 0644,
211949f0ce5fSJerome Marchand 		.proc_handler	= overcommit_kbytes_handler,
21201da177e4SLinus Torvalds 	},
21211da177e4SLinus Torvalds 	{
21221da177e4SLinus Torvalds 		.procname	= "page-cluster",
21231da177e4SLinus Torvalds 		.data		= &page_cluster,
21241da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21251da177e4SLinus Torvalds 		.mode		= 0644,
2126cb16e95fSPetr Holasek 		.proc_handler	= proc_dointvec_minmax,
2127eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
21281da177e4SLinus Torvalds 	},
21291da177e4SLinus Torvalds 	{
21301efff914STheodore Ts'o 		.procname	= "dirtytime_expire_seconds",
21311efff914STheodore Ts'o 		.data		= &dirtytime_expire_interval,
21322d87b309SRandy Dunlap 		.maxlen		= sizeof(dirtytime_expire_interval),
21331efff914STheodore Ts'o 		.mode		= 0644,
21341efff914STheodore Ts'o 		.proc_handler	= dirtytime_interval_handler,
2135eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
21361efff914STheodore Ts'o 	},
21371efff914STheodore Ts'o 	{
21381da177e4SLinus Torvalds 		.procname	= "swappiness",
21391da177e4SLinus Torvalds 		.data		= &vm_swappiness,
21401da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_swappiness),
21411da177e4SLinus Torvalds 		.mode		= 0644,
21426d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2143eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
214478e36f3bSXiaoming Ni 		.extra2		= SYSCTL_TWO_HUNDRED,
21451da177e4SLinus Torvalds 	},
214643b5240cSMuchun Song #ifdef CONFIG_NUMA
214743b5240cSMuchun Song 	{
214843b5240cSMuchun Song 		.procname	= "numa_stat",
214943b5240cSMuchun Song 		.data		= &sysctl_vm_numa_stat,
215043b5240cSMuchun Song 		.maxlen		= sizeof(int),
215143b5240cSMuchun Song 		.mode		= 0644,
215243b5240cSMuchun Song 		.proc_handler	= sysctl_vm_numa_stat_handler,
215343b5240cSMuchun Song 		.extra1		= SYSCTL_ZERO,
215443b5240cSMuchun Song 		.extra2		= SYSCTL_ONE,
215543b5240cSMuchun Song 	},
215643b5240cSMuchun Song #endif
21571da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE
21581da177e4SLinus Torvalds 	{
21591da177e4SLinus Torvalds 		.procname	= "nr_hugepages",
2160e5ff2159SAndi Kleen 		.data		= NULL,
21611da177e4SLinus Torvalds 		.maxlen		= sizeof(unsigned long),
21621da177e4SLinus Torvalds 		.mode		= 0644,
21636d456111SEric W. Biederman 		.proc_handler	= hugetlb_sysctl_handler,
21641da177e4SLinus Torvalds 	},
216506808b08SLee Schermerhorn #ifdef CONFIG_NUMA
216606808b08SLee Schermerhorn 	{
216706808b08SLee Schermerhorn 		.procname       = "nr_hugepages_mempolicy",
216806808b08SLee Schermerhorn 		.data           = NULL,
216906808b08SLee Schermerhorn 		.maxlen         = sizeof(unsigned long),
217006808b08SLee Schermerhorn 		.mode           = 0644,
217106808b08SLee Schermerhorn 		.proc_handler   = &hugetlb_mempolicy_sysctl_handler,
217206808b08SLee Schermerhorn 	},
217306808b08SLee Schermerhorn #endif
21741da177e4SLinus Torvalds 	 {
21751da177e4SLinus Torvalds 		.procname	= "hugetlb_shm_group",
21761da177e4SLinus Torvalds 		.data		= &sysctl_hugetlb_shm_group,
21771da177e4SLinus Torvalds 		.maxlen		= sizeof(gid_t),
21781da177e4SLinus Torvalds 		.mode		= 0644,
21796d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
21801da177e4SLinus Torvalds 	 },
2181396faf03SMel Gorman 	{
2182d1c3fb1fSNishanth Aravamudan 		.procname	= "nr_overcommit_hugepages",
2183e5ff2159SAndi Kleen 		.data		= NULL,
2184e5ff2159SAndi Kleen 		.maxlen		= sizeof(unsigned long),
2185d1c3fb1fSNishanth Aravamudan 		.mode		= 0644,
21866d456111SEric W. Biederman 		.proc_handler	= hugetlb_overcommit_handler,
2187d1c3fb1fSNishanth Aravamudan 	},
21881da177e4SLinus Torvalds #endif
21891da177e4SLinus Torvalds 	{
21901da177e4SLinus Torvalds 		.procname	= "lowmem_reserve_ratio",
21911da177e4SLinus Torvalds 		.data		= &sysctl_lowmem_reserve_ratio,
21921da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
21931da177e4SLinus Torvalds 		.mode		= 0644,
21946d456111SEric W. Biederman 		.proc_handler	= lowmem_reserve_ratio_sysctl_handler,
21951da177e4SLinus Torvalds 	},
21961da177e4SLinus Torvalds 	{
21979d0243bcSAndrew Morton 		.procname	= "drop_caches",
21989d0243bcSAndrew Morton 		.data		= &sysctl_drop_caches,
21999d0243bcSAndrew Morton 		.maxlen		= sizeof(int),
2200204cb79aSJohannes Weiner 		.mode		= 0200,
22019d0243bcSAndrew Morton 		.proc_handler	= drop_caches_sysctl_handler,
2202eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
220378e36f3bSXiaoming Ni 		.extra2		= SYSCTL_FOUR,
22049d0243bcSAndrew Morton 	},
220576ab0f53SMel Gorman #ifdef CONFIG_COMPACTION
220676ab0f53SMel Gorman 	{
220776ab0f53SMel Gorman 		.procname	= "compact_memory",
2208ef498438SPintu Kumar 		.data		= NULL,
220976ab0f53SMel Gorman 		.maxlen		= sizeof(int),
221076ab0f53SMel Gorman 		.mode		= 0200,
221176ab0f53SMel Gorman 		.proc_handler	= sysctl_compaction_handler,
221276ab0f53SMel Gorman 	},
22135e771905SMel Gorman 	{
2214facdaa91SNitin Gupta 		.procname	= "compaction_proactiveness",
2215facdaa91SNitin Gupta 		.data		= &sysctl_compaction_proactiveness,
2216d34c0a75SNitin Gupta 		.maxlen		= sizeof(sysctl_compaction_proactiveness),
2217facdaa91SNitin Gupta 		.mode		= 0644,
221865d759c8SCharan Teja Reddy 		.proc_handler	= compaction_proactiveness_sysctl_handler,
2219facdaa91SNitin Gupta 		.extra1		= SYSCTL_ZERO,
222078e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_HUNDRED,
2221facdaa91SNitin Gupta 	},
2222facdaa91SNitin Gupta 	{
22235e771905SMel Gorman 		.procname	= "extfrag_threshold",
22245e771905SMel Gorman 		.data		= &sysctl_extfrag_threshold,
22255e771905SMel Gorman 		.maxlen		= sizeof(int),
22265e771905SMel Gorman 		.mode		= 0644,
22276b7e5cadSMatthew Wilcox 		.proc_handler	= proc_dointvec_minmax,
22282452dcb9SXiaoming Ni 		.extra1		= SYSCTL_ZERO,
2229feb2bd01SLiu Shixin 		.extra2		= SYSCTL_ONE_THOUSAND,
22305e771905SMel Gorman 	},
22315bbe3547SEric B Munson 	{
22325bbe3547SEric B Munson 		.procname	= "compact_unevictable_allowed",
22335bbe3547SEric B Munson 		.data		= &sysctl_compact_unevictable_allowed,
22345bbe3547SEric B Munson 		.maxlen		= sizeof(int),
22355bbe3547SEric B Munson 		.mode		= 0644,
22366923aa0dSSebastian Andrzej Siewior 		.proc_handler	= proc_dointvec_minmax_warn_RT_change,
2237eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2238eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
22395bbe3547SEric B Munson 	},
22405e771905SMel Gorman 
224176ab0f53SMel Gorman #endif /* CONFIG_COMPACTION */
22429d0243bcSAndrew Morton 	{
22431da177e4SLinus Torvalds 		.procname	= "min_free_kbytes",
22441da177e4SLinus Torvalds 		.data		= &min_free_kbytes,
22451da177e4SLinus Torvalds 		.maxlen		= sizeof(min_free_kbytes),
22461da177e4SLinus Torvalds 		.mode		= 0644,
22476d456111SEric W. Biederman 		.proc_handler	= min_free_kbytes_sysctl_handler,
2248eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
22491da177e4SLinus Torvalds 	},
22508ad4b1fbSRohit Seth 	{
22511c30844dSMel Gorman 		.procname	= "watermark_boost_factor",
22521c30844dSMel Gorman 		.data		= &watermark_boost_factor,
22531c30844dSMel Gorman 		.maxlen		= sizeof(watermark_boost_factor),
22541c30844dSMel Gorman 		.mode		= 0644,
225526363af5SChristoph Hellwig 		.proc_handler	= proc_dointvec_minmax,
2256eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
22571c30844dSMel Gorman 	},
22581c30844dSMel Gorman 	{
2259795ae7a0SJohannes Weiner 		.procname	= "watermark_scale_factor",
2260795ae7a0SJohannes Weiner 		.data		= &watermark_scale_factor,
2261795ae7a0SJohannes Weiner 		.maxlen		= sizeof(watermark_scale_factor),
2262795ae7a0SJohannes Weiner 		.mode		= 0644,
2263795ae7a0SJohannes Weiner 		.proc_handler	= watermark_scale_factor_sysctl_handler,
2264eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
226578e36f3bSXiaoming Ni 		.extra2		= SYSCTL_THREE_THOUSAND,
2266795ae7a0SJohannes Weiner 	},
2267795ae7a0SJohannes Weiner 	{
226874f44822SMel Gorman 		.procname	= "percpu_pagelist_high_fraction",
226974f44822SMel Gorman 		.data		= &percpu_pagelist_high_fraction,
227074f44822SMel Gorman 		.maxlen		= sizeof(percpu_pagelist_high_fraction),
22718ad4b1fbSRohit Seth 		.mode		= 0644,
227274f44822SMel Gorman 		.proc_handler	= percpu_pagelist_high_fraction_sysctl_handler,
2273eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
22748ad4b1fbSRohit Seth 	},
22755ef64cc8SLinus Torvalds 	{
22765ef64cc8SLinus Torvalds 		.procname	= "page_lock_unfairness",
22775ef64cc8SLinus Torvalds 		.data		= &sysctl_page_lock_unfairness,
22785ef64cc8SLinus Torvalds 		.maxlen		= sizeof(sysctl_page_lock_unfairness),
22795ef64cc8SLinus Torvalds 		.mode		= 0644,
22805ef64cc8SLinus Torvalds 		.proc_handler	= proc_dointvec_minmax,
22815ef64cc8SLinus Torvalds 		.extra1		= SYSCTL_ZERO,
22825ef64cc8SLinus Torvalds 	},
22831da177e4SLinus Torvalds #ifdef CONFIG_MMU
22841da177e4SLinus Torvalds 	{
22851da177e4SLinus Torvalds 		.procname	= "max_map_count",
22861da177e4SLinus Torvalds 		.data		= &sysctl_max_map_count,
22871da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_max_map_count),
22881da177e4SLinus Torvalds 		.mode		= 0644,
22893e26120cSWANG Cong 		.proc_handler	= proc_dointvec_minmax,
2290eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
22911da177e4SLinus Torvalds 	},
2292dd8632a1SPaul Mundt #else
2293dd8632a1SPaul Mundt 	{
2294dd8632a1SPaul Mundt 		.procname	= "nr_trim_pages",
2295dd8632a1SPaul Mundt 		.data		= &sysctl_nr_trim_pages,
2296dd8632a1SPaul Mundt 		.maxlen		= sizeof(sysctl_nr_trim_pages),
2297dd8632a1SPaul Mundt 		.mode		= 0644,
22986d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2299eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2300dd8632a1SPaul Mundt 	},
23011da177e4SLinus Torvalds #endif
23021da177e4SLinus Torvalds 	{
23031da177e4SLinus Torvalds 		.procname	= "vfs_cache_pressure",
23041da177e4SLinus Torvalds 		.data		= &sysctl_vfs_cache_pressure,
23051da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
23061da177e4SLinus Torvalds 		.mode		= 0644,
23073b3376f2SLin Feng 		.proc_handler	= proc_dointvec_minmax,
2308eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
23091da177e4SLinus Torvalds 	},
231067f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
231167f3977fSAlexandre Ghiti     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
23121da177e4SLinus Torvalds 	{
23131da177e4SLinus Torvalds 		.procname	= "legacy_va_layout",
23141da177e4SLinus Torvalds 		.data		= &sysctl_legacy_va_layout,
23151da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_legacy_va_layout),
23161da177e4SLinus Torvalds 		.mode		= 0644,
23173b3376f2SLin Feng 		.proc_handler	= proc_dointvec_minmax,
2318eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
23191da177e4SLinus Torvalds 	},
23201da177e4SLinus Torvalds #endif
23211743660bSChristoph Lameter #ifdef CONFIG_NUMA
23221743660bSChristoph Lameter 	{
23231743660bSChristoph Lameter 		.procname	= "zone_reclaim_mode",
2324a5f5f91dSMel Gorman 		.data		= &node_reclaim_mode,
2325a5f5f91dSMel Gorman 		.maxlen		= sizeof(node_reclaim_mode),
23261743660bSChristoph Lameter 		.mode		= 0644,
23273b3376f2SLin Feng 		.proc_handler	= proc_dointvec_minmax,
2328eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
23291743660bSChristoph Lameter 	},
23309614634fSChristoph Lameter 	{
23319614634fSChristoph Lameter 		.procname	= "min_unmapped_ratio",
23329614634fSChristoph Lameter 		.data		= &sysctl_min_unmapped_ratio,
23339614634fSChristoph Lameter 		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
23349614634fSChristoph Lameter 		.mode		= 0644,
23356d456111SEric W. Biederman 		.proc_handler	= sysctl_min_unmapped_ratio_sysctl_handler,
2336eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
233778e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_HUNDRED,
23389614634fSChristoph Lameter 	},
23390ff38490SChristoph Lameter 	{
23400ff38490SChristoph Lameter 		.procname	= "min_slab_ratio",
23410ff38490SChristoph Lameter 		.data		= &sysctl_min_slab_ratio,
23420ff38490SChristoph Lameter 		.maxlen		= sizeof(sysctl_min_slab_ratio),
23430ff38490SChristoph Lameter 		.mode		= 0644,
23446d456111SEric W. Biederman 		.proc_handler	= sysctl_min_slab_ratio_sysctl_handler,
2345eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
234678e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_HUNDRED,
23470ff38490SChristoph Lameter 	},
23481743660bSChristoph Lameter #endif
234977461ab3SChristoph Lameter #ifdef CONFIG_SMP
235077461ab3SChristoph Lameter 	{
235177461ab3SChristoph Lameter 		.procname	= "stat_interval",
235277461ab3SChristoph Lameter 		.data		= &sysctl_stat_interval,
235377461ab3SChristoph Lameter 		.maxlen		= sizeof(sysctl_stat_interval),
235477461ab3SChristoph Lameter 		.mode		= 0644,
23556d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_jiffies,
235677461ab3SChristoph Lameter 	},
235752b6f46bSHugh Dickins 	{
235852b6f46bSHugh Dickins 		.procname	= "stat_refresh",
235952b6f46bSHugh Dickins 		.data		= NULL,
236052b6f46bSHugh Dickins 		.maxlen		= 0,
236152b6f46bSHugh Dickins 		.mode		= 0600,
236252b6f46bSHugh Dickins 		.proc_handler	= vmstat_refresh,
236352b6f46bSHugh Dickins 	},
236477461ab3SChristoph Lameter #endif
23656e141546SDavid Howells #ifdef CONFIG_MMU
2366ed032189SEric Paris 	{
2367ed032189SEric Paris 		.procname	= "mmap_min_addr",
2368788084abSEric Paris 		.data		= &dac_mmap_min_addr,
2369ed032189SEric Paris 		.maxlen		= sizeof(unsigned long),
2370ed032189SEric Paris 		.mode		= 0644,
23716d456111SEric W. Biederman 		.proc_handler	= mmap_min_addr_handler,
2372ed032189SEric Paris 	},
23736e141546SDavid Howells #endif
2374f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA
2375f0c0b2b8SKAMEZAWA Hiroyuki 	{
2376f0c0b2b8SKAMEZAWA Hiroyuki 		.procname	= "numa_zonelist_order",
2377f0c0b2b8SKAMEZAWA Hiroyuki 		.data		= &numa_zonelist_order,
2378f0c0b2b8SKAMEZAWA Hiroyuki 		.maxlen		= NUMA_ZONELIST_ORDER_LEN,
2379f0c0b2b8SKAMEZAWA Hiroyuki 		.mode		= 0644,
23806d456111SEric W. Biederman 		.proc_handler	= numa_zonelist_order_handler,
2381f0c0b2b8SKAMEZAWA Hiroyuki 	},
2382f0c0b2b8SKAMEZAWA Hiroyuki #endif
23832b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
23845c36e657SPaul Mundt    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
2385e6e5494cSIngo Molnar 	{
2386e6e5494cSIngo Molnar 		.procname	= "vdso_enabled",
23873d7ee969SAndy Lutomirski #ifdef CONFIG_X86_32
23883d7ee969SAndy Lutomirski 		.data		= &vdso32_enabled,
23893d7ee969SAndy Lutomirski 		.maxlen		= sizeof(vdso32_enabled),
23903d7ee969SAndy Lutomirski #else
2391e6e5494cSIngo Molnar 		.data		= &vdso_enabled,
2392e6e5494cSIngo Molnar 		.maxlen		= sizeof(vdso_enabled),
23933d7ee969SAndy Lutomirski #endif
2394e6e5494cSIngo Molnar 		.mode		= 0644,
23956d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2396eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2397e6e5494cSIngo Molnar 	},
2398e6e5494cSIngo Molnar #endif
23996a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE
24006a46079cSAndi Kleen 	{
24016a46079cSAndi Kleen 		.procname	= "memory_failure_early_kill",
24026a46079cSAndi Kleen 		.data		= &sysctl_memory_failure_early_kill,
24036a46079cSAndi Kleen 		.maxlen		= sizeof(sysctl_memory_failure_early_kill),
24046a46079cSAndi Kleen 		.mode		= 0644,
24056d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2406eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2407eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
24086a46079cSAndi Kleen 	},
24096a46079cSAndi Kleen 	{
24106a46079cSAndi Kleen 		.procname	= "memory_failure_recovery",
24116a46079cSAndi Kleen 		.data		= &sysctl_memory_failure_recovery,
24126a46079cSAndi Kleen 		.maxlen		= sizeof(sysctl_memory_failure_recovery),
24136a46079cSAndi Kleen 		.mode		= 0644,
24146d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2415eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2416eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
24176a46079cSAndi Kleen 	},
24186a46079cSAndi Kleen #endif
2419c9b1d098SAndrew Shewmaker 	{
2420c9b1d098SAndrew Shewmaker 		.procname	= "user_reserve_kbytes",
2421c9b1d098SAndrew Shewmaker 		.data		= &sysctl_user_reserve_kbytes,
2422c9b1d098SAndrew Shewmaker 		.maxlen		= sizeof(sysctl_user_reserve_kbytes),
2423c9b1d098SAndrew Shewmaker 		.mode		= 0644,
2424c9b1d098SAndrew Shewmaker 		.proc_handler	= proc_doulongvec_minmax,
2425c9b1d098SAndrew Shewmaker 	},
24264eeab4f5SAndrew Shewmaker 	{
24274eeab4f5SAndrew Shewmaker 		.procname	= "admin_reserve_kbytes",
24284eeab4f5SAndrew Shewmaker 		.data		= &sysctl_admin_reserve_kbytes,
24294eeab4f5SAndrew Shewmaker 		.maxlen		= sizeof(sysctl_admin_reserve_kbytes),
24304eeab4f5SAndrew Shewmaker 		.mode		= 0644,
24314eeab4f5SAndrew Shewmaker 		.proc_handler	= proc_doulongvec_minmax,
24324eeab4f5SAndrew Shewmaker 	},
2433d07e2259SDaniel Cashman #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
2434d07e2259SDaniel Cashman 	{
2435d07e2259SDaniel Cashman 		.procname	= "mmap_rnd_bits",
2436d07e2259SDaniel Cashman 		.data		= &mmap_rnd_bits,
2437d07e2259SDaniel Cashman 		.maxlen		= sizeof(mmap_rnd_bits),
2438d07e2259SDaniel Cashman 		.mode		= 0600,
2439d07e2259SDaniel Cashman 		.proc_handler	= proc_dointvec_minmax,
2440d07e2259SDaniel Cashman 		.extra1		= (void *)&mmap_rnd_bits_min,
2441d07e2259SDaniel Cashman 		.extra2		= (void *)&mmap_rnd_bits_max,
2442d07e2259SDaniel Cashman 	},
2443d07e2259SDaniel Cashman #endif
2444d07e2259SDaniel Cashman #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
2445d07e2259SDaniel Cashman 	{
2446d07e2259SDaniel Cashman 		.procname	= "mmap_rnd_compat_bits",
2447d07e2259SDaniel Cashman 		.data		= &mmap_rnd_compat_bits,
2448d07e2259SDaniel Cashman 		.maxlen		= sizeof(mmap_rnd_compat_bits),
2449d07e2259SDaniel Cashman 		.mode		= 0600,
2450d07e2259SDaniel Cashman 		.proc_handler	= proc_dointvec_minmax,
2451d07e2259SDaniel Cashman 		.extra1		= (void *)&mmap_rnd_compat_bits_min,
2452d07e2259SDaniel Cashman 		.extra2		= (void *)&mmap_rnd_compat_bits_max,
2453d07e2259SDaniel Cashman 	},
2454d07e2259SDaniel Cashman #endif
2455cefdca0aSPeter Xu #ifdef CONFIG_USERFAULTFD
2456cefdca0aSPeter Xu 	{
2457cefdca0aSPeter Xu 		.procname	= "unprivileged_userfaultfd",
2458cefdca0aSPeter Xu 		.data		= &sysctl_unprivileged_userfaultfd,
2459cefdca0aSPeter Xu 		.maxlen		= sizeof(sysctl_unprivileged_userfaultfd),
2460cefdca0aSPeter Xu 		.mode		= 0644,
2461cefdca0aSPeter Xu 		.proc_handler	= proc_dointvec_minmax,
2462eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2463eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2464cefdca0aSPeter Xu 	},
2465cefdca0aSPeter Xu #endif
24666fce56ecSEric W. Biederman 	{ }
24671da177e4SLinus Torvalds };
24681da177e4SLinus Torvalds 
2469d8217f07SEric W. Biederman static struct ctl_table debug_table[] = {
24707ac57a89SCatalin Marinas #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
2471abd4f750SMasoud Asgharifard Sharbiani 	{
2472abd4f750SMasoud Asgharifard Sharbiani 		.procname	= "exception-trace",
2473abd4f750SMasoud Asgharifard Sharbiani 		.data		= &show_unhandled_signals,
2474abd4f750SMasoud Asgharifard Sharbiani 		.maxlen		= sizeof(int),
2475abd4f750SMasoud Asgharifard Sharbiani 		.mode		= 0644,
2476abd4f750SMasoud Asgharifard Sharbiani 		.proc_handler	= proc_dointvec
2477abd4f750SMasoud Asgharifard Sharbiani 	},
2478abd4f750SMasoud Asgharifard Sharbiani #endif
24796fce56ecSEric W. Biederman 	{ }
24801da177e4SLinus Torvalds };
24811da177e4SLinus Torvalds 
2482d8217f07SEric W. Biederman static struct ctl_table dev_table[] = {
24836fce56ecSEric W. Biederman 	{ }
24841da177e4SLinus Torvalds };
24851da177e4SLinus Torvalds 
248651cb8dfcSLuis Chamberlain DECLARE_SYSCTL_BASE(kernel, kern_table);
248751cb8dfcSLuis Chamberlain DECLARE_SYSCTL_BASE(vm, vm_table);
248851cb8dfcSLuis Chamberlain DECLARE_SYSCTL_BASE(debug, debug_table);
248951cb8dfcSLuis Chamberlain DECLARE_SYSCTL_BASE(dev, dev_table);
2490f461d2dcSChristoph Hellwig 
2491d8c0418aSLuis Chamberlain int __init sysctl_init_bases(void)
2492330d57fbSAl Viro {
249351cb8dfcSLuis Chamberlain 	register_sysctl_base(kernel);
249451cb8dfcSLuis Chamberlain 	register_sysctl_base(vm);
249551cb8dfcSLuis Chamberlain 	register_sysctl_base(debug);
249651cb8dfcSLuis Chamberlain 	register_sysctl_base(dev);
2497fd4b616bSSteven Rostedt 
2498330d57fbSAl Viro 	return 0;
2499f7e6ced4SAl Viro }
2500b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */
25011da177e4SLinus Torvalds /*
25021da177e4SLinus Torvalds  * No sense putting this after each symbol definition, twice,
25031da177e4SLinus Torvalds  * exception granted :-)
25041da177e4SLinus Torvalds  */
2505a2071573SJia He EXPORT_SYMBOL(proc_dobool);
25061da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec);
2507e7d316a0SSubash Abhinov Kasiviswanathan EXPORT_SYMBOL(proc_douintvec);
25081da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies);
25091da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax);
251061d9b56aSLuis R. Rodriguez EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
25111da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
25121da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
25131da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring);
25141da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax);
25151da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
25160bc19985SStephen Suryaputra EXPORT_SYMBOL(proc_do_large_bitmap);
2517