xref: /openbmc/linux/kernel/sysctl.c (revision c31bcc8fb89fc2812663900589c6325ba35d9a65)
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 
851da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL)
861da177e4SLinus Torvalds 
87c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and  maximum */
88c4f3b63fSRavikiran G Thirumalai 
89c5dfd78eSArnaldo Carvalho de Melo #ifdef CONFIG_PERF_EVENTS
90d73840ecSXiaoming Ni static const int six_hundred_forty_kb = 640 * 1024;
91c5dfd78eSArnaldo Carvalho de Melo #endif
92c4f3b63fSRavikiran G Thirumalai 
939e4a5bdaSAndrea Righi 
94f628867dSStephen Kitt static const int ngroups_max = NGROUPS_MAX;
9573efc039SDan Ballard static const int cap_last_cap = CAP_LAST_CAP;
961da177e4SLinus Torvalds 
97d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
98f4aacea2SKees Cook 
99a19ac337SLuis R. Rodriguez /**
100a19ac337SLuis R. Rodriguez  * enum sysctl_writes_mode - supported sysctl write modes
101a19ac337SLuis R. Rodriguez  *
102a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
103a19ac337SLuis R. Rodriguez  *	to be written, and multiple writes on the same sysctl file descriptor
104a19ac337SLuis R. Rodriguez  *	will rewrite the sysctl value, regardless of file position. No warning
105a19ac337SLuis R. Rodriguez  *	is issued when the initial position is not 0.
106a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
107a19ac337SLuis R. Rodriguez  *	not 0.
108a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
109a19ac337SLuis R. Rodriguez  *	file position 0 and the value must be fully contained in the buffer
110a19ac337SLuis R. Rodriguez  *	sent to the write syscall. If dealing with strings respect the file
111a19ac337SLuis R. Rodriguez  *	position, but restrict this to the max length of the buffer, anything
11265f50f25SWeitao Hou  *	passed the max length will be ignored. Multiple writes will append
113a19ac337SLuis R. Rodriguez  *	to the buffer.
114a19ac337SLuis R. Rodriguez  *
115a19ac337SLuis R. Rodriguez  * These write modes control how current file position affects the behavior of
116a19ac337SLuis R. Rodriguez  * updating sysctl values through the proc interface on each write.
117a19ac337SLuis R. Rodriguez  */
118a19ac337SLuis R. Rodriguez enum sysctl_writes_mode {
119a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_LEGACY		= -1,
120a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_WARN		= 0,
121a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_STRICT		= 1,
122a19ac337SLuis R. Rodriguez };
123f4aacea2SKees Cook 
124a19ac337SLuis R. Rodriguez static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
125f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */
126ceb18132SLuis R. Rodriguez 
12767f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
12867f3977fSAlexandre Ghiti     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
1291da177e4SLinus Torvalds int sysctl_legacy_va_layout;
1301da177e4SLinus Torvalds #endif
1311da177e4SLinus Torvalds 
1325e771905SMel Gorman #ifdef CONFIG_COMPACTION
1332452dcb9SXiaoming Ni /* min_extfrag_threshold is SYSCTL_ZERO */;
134d73840ecSXiaoming Ni static const int max_extfrag_threshold = 1000;
1355e771905SMel Gorman #endif
1365e771905SMel Gorman 
137f461d2dcSChristoph Hellwig #endif /* CONFIG_SYSCTL */
138f461d2dcSChristoph Hellwig 
139f461d2dcSChristoph Hellwig /*
140f461d2dcSChristoph Hellwig  * /proc/sys support
141f461d2dcSChristoph Hellwig  */
142f461d2dcSChristoph Hellwig 
143f461d2dcSChristoph Hellwig #ifdef CONFIG_PROC_SYSCTL
144f461d2dcSChristoph Hellwig 
145f461d2dcSChristoph Hellwig static int _proc_do_string(char *data, int maxlen, int write,
14632927393SChristoph Hellwig 		char *buffer, size_t *lenp, loff_t *ppos)
147f461d2dcSChristoph Hellwig {
148f461d2dcSChristoph Hellwig 	size_t len;
14932927393SChristoph Hellwig 	char c, *p;
150f461d2dcSChristoph Hellwig 
151f461d2dcSChristoph Hellwig 	if (!data || !maxlen || !*lenp) {
152f461d2dcSChristoph Hellwig 		*lenp = 0;
153f461d2dcSChristoph Hellwig 		return 0;
154f461d2dcSChristoph Hellwig 	}
155f461d2dcSChristoph Hellwig 
156f461d2dcSChristoph Hellwig 	if (write) {
157f461d2dcSChristoph Hellwig 		if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
158f461d2dcSChristoph Hellwig 			/* Only continue writes not past the end of buffer. */
159f461d2dcSChristoph Hellwig 			len = strlen(data);
160f461d2dcSChristoph Hellwig 			if (len > maxlen - 1)
161f461d2dcSChristoph Hellwig 				len = maxlen - 1;
162f461d2dcSChristoph Hellwig 
163f461d2dcSChristoph Hellwig 			if (*ppos > len)
164f461d2dcSChristoph Hellwig 				return 0;
165f461d2dcSChristoph Hellwig 			len = *ppos;
166f461d2dcSChristoph Hellwig 		} else {
167f461d2dcSChristoph Hellwig 			/* Start writing from beginning of buffer. */
168f461d2dcSChristoph Hellwig 			len = 0;
169f461d2dcSChristoph Hellwig 		}
170f461d2dcSChristoph Hellwig 
171f461d2dcSChristoph Hellwig 		*ppos += *lenp;
172f461d2dcSChristoph Hellwig 		p = buffer;
173f461d2dcSChristoph Hellwig 		while ((p - buffer) < *lenp && len < maxlen - 1) {
17432927393SChristoph Hellwig 			c = *(p++);
175f461d2dcSChristoph Hellwig 			if (c == 0 || c == '\n')
176f461d2dcSChristoph Hellwig 				break;
177f461d2dcSChristoph Hellwig 			data[len++] = c;
178f461d2dcSChristoph Hellwig 		}
179f461d2dcSChristoph Hellwig 		data[len] = 0;
180f461d2dcSChristoph Hellwig 	} else {
181f461d2dcSChristoph Hellwig 		len = strlen(data);
182f461d2dcSChristoph Hellwig 		if (len > maxlen)
183f461d2dcSChristoph Hellwig 			len = maxlen;
184f461d2dcSChristoph Hellwig 
185f461d2dcSChristoph Hellwig 		if (*ppos > len) {
186f461d2dcSChristoph Hellwig 			*lenp = 0;
187f461d2dcSChristoph Hellwig 			return 0;
188f461d2dcSChristoph Hellwig 		}
189f461d2dcSChristoph Hellwig 
190f461d2dcSChristoph Hellwig 		data += *ppos;
191f461d2dcSChristoph Hellwig 		len  -= *ppos;
192f461d2dcSChristoph Hellwig 
193f461d2dcSChristoph Hellwig 		if (len > *lenp)
194f461d2dcSChristoph Hellwig 			len = *lenp;
195f461d2dcSChristoph Hellwig 		if (len)
19632927393SChristoph Hellwig 			memcpy(buffer, data, len);
197f461d2dcSChristoph Hellwig 		if (len < *lenp) {
19832927393SChristoph Hellwig 			buffer[len] = '\n';
199f461d2dcSChristoph Hellwig 			len++;
200f461d2dcSChristoph Hellwig 		}
201f461d2dcSChristoph Hellwig 		*lenp = len;
202f461d2dcSChristoph Hellwig 		*ppos += len;
203f461d2dcSChristoph Hellwig 	}
204f461d2dcSChristoph Hellwig 	return 0;
205f461d2dcSChristoph Hellwig }
206f461d2dcSChristoph Hellwig 
207f461d2dcSChristoph Hellwig static void warn_sysctl_write(struct ctl_table *table)
208f461d2dcSChristoph Hellwig {
209f461d2dcSChristoph Hellwig 	pr_warn_once("%s wrote to %s when file position was not 0!\n"
210f461d2dcSChristoph Hellwig 		"This will not be supported in the future. To silence this\n"
211f461d2dcSChristoph Hellwig 		"warning, set kernel.sysctl_writes_strict = -1\n",
212f461d2dcSChristoph Hellwig 		current->comm, table->procname);
213f461d2dcSChristoph Hellwig }
214f461d2dcSChristoph Hellwig 
215f461d2dcSChristoph Hellwig /**
216f461d2dcSChristoph Hellwig  * proc_first_pos_non_zero_ignore - check if first position is allowed
217f461d2dcSChristoph Hellwig  * @ppos: file position
218f461d2dcSChristoph Hellwig  * @table: the sysctl table
219f461d2dcSChristoph Hellwig  *
220f461d2dcSChristoph Hellwig  * Returns true if the first position is non-zero and the sysctl_writes_strict
221f461d2dcSChristoph Hellwig  * mode indicates this is not allowed for numeric input types. String proc
222f461d2dcSChristoph Hellwig  * handlers can ignore the return value.
223f461d2dcSChristoph Hellwig  */
224f461d2dcSChristoph Hellwig static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
225f461d2dcSChristoph Hellwig 					   struct ctl_table *table)
226f461d2dcSChristoph Hellwig {
227f461d2dcSChristoph Hellwig 	if (!*ppos)
228f461d2dcSChristoph Hellwig 		return false;
229f461d2dcSChristoph Hellwig 
230f461d2dcSChristoph Hellwig 	switch (sysctl_writes_strict) {
231f461d2dcSChristoph Hellwig 	case SYSCTL_WRITES_STRICT:
232f461d2dcSChristoph Hellwig 		return true;
233f461d2dcSChristoph Hellwig 	case SYSCTL_WRITES_WARN:
234f461d2dcSChristoph Hellwig 		warn_sysctl_write(table);
235f461d2dcSChristoph Hellwig 		return false;
236f461d2dcSChristoph Hellwig 	default:
237f461d2dcSChristoph Hellwig 		return false;
238f461d2dcSChristoph Hellwig 	}
239f461d2dcSChristoph Hellwig }
240f461d2dcSChristoph Hellwig 
241f461d2dcSChristoph Hellwig /**
242f461d2dcSChristoph Hellwig  * proc_dostring - read a string sysctl
243f461d2dcSChristoph Hellwig  * @table: the sysctl table
244f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
245f461d2dcSChristoph Hellwig  * @buffer: the user buffer
246f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
247f461d2dcSChristoph Hellwig  * @ppos: file position
248f461d2dcSChristoph Hellwig  *
249f461d2dcSChristoph Hellwig  * Reads/writes a string from/to the user buffer. If the kernel
250f461d2dcSChristoph Hellwig  * buffer provided is not large enough to hold the string, the
251f461d2dcSChristoph Hellwig  * string is truncated. The copied string is %NULL-terminated.
252f461d2dcSChristoph Hellwig  * If the string is being read by the user process, it is copied
253f461d2dcSChristoph Hellwig  * and a newline '\n' is added. It is truncated if the buffer is
254f461d2dcSChristoph Hellwig  * not large enough.
255f461d2dcSChristoph Hellwig  *
256f461d2dcSChristoph Hellwig  * Returns 0 on success.
257f461d2dcSChristoph Hellwig  */
258f461d2dcSChristoph Hellwig int proc_dostring(struct ctl_table *table, int write,
25932927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
260f461d2dcSChristoph Hellwig {
261f461d2dcSChristoph Hellwig 	if (write)
262f461d2dcSChristoph Hellwig 		proc_first_pos_non_zero_ignore(ppos, table);
263f461d2dcSChristoph Hellwig 
26432927393SChristoph Hellwig 	return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
26532927393SChristoph Hellwig 			ppos);
266f461d2dcSChristoph Hellwig }
267f461d2dcSChristoph Hellwig 
268f461d2dcSChristoph Hellwig static size_t proc_skip_spaces(char **buf)
269f461d2dcSChristoph Hellwig {
270f461d2dcSChristoph Hellwig 	size_t ret;
271f461d2dcSChristoph Hellwig 	char *tmp = skip_spaces(*buf);
272f461d2dcSChristoph Hellwig 	ret = tmp - *buf;
273f461d2dcSChristoph Hellwig 	*buf = tmp;
274f461d2dcSChristoph Hellwig 	return ret;
275f461d2dcSChristoph Hellwig }
276f461d2dcSChristoph Hellwig 
277f461d2dcSChristoph Hellwig static void proc_skip_char(char **buf, size_t *size, const char v)
278f461d2dcSChristoph Hellwig {
279f461d2dcSChristoph Hellwig 	while (*size) {
280f461d2dcSChristoph Hellwig 		if (**buf != v)
281f461d2dcSChristoph Hellwig 			break;
282f461d2dcSChristoph Hellwig 		(*size)--;
283f461d2dcSChristoph Hellwig 		(*buf)++;
284f461d2dcSChristoph Hellwig 	}
285f461d2dcSChristoph Hellwig }
286f461d2dcSChristoph Hellwig 
287f461d2dcSChristoph Hellwig /**
288f461d2dcSChristoph Hellwig  * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
289f461d2dcSChristoph Hellwig  *                   fail on overflow
290f461d2dcSChristoph Hellwig  *
291f461d2dcSChristoph Hellwig  * @cp: kernel buffer containing the string to parse
292f461d2dcSChristoph Hellwig  * @endp: pointer to store the trailing characters
293f461d2dcSChristoph Hellwig  * @base: the base to use
294f461d2dcSChristoph Hellwig  * @res: where the parsed integer will be stored
295f461d2dcSChristoph Hellwig  *
296f461d2dcSChristoph Hellwig  * In case of success 0 is returned and @res will contain the parsed integer,
297f461d2dcSChristoph Hellwig  * @endp will hold any trailing characters.
298f461d2dcSChristoph Hellwig  * This function will fail the parse on overflow. If there wasn't an overflow
299f461d2dcSChristoph Hellwig  * the function will defer the decision what characters count as invalid to the
300f461d2dcSChristoph Hellwig  * caller.
301f461d2dcSChristoph Hellwig  */
302f461d2dcSChristoph Hellwig static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
303f461d2dcSChristoph Hellwig 			   unsigned long *res)
304f461d2dcSChristoph Hellwig {
305f461d2dcSChristoph Hellwig 	unsigned long long result;
306f461d2dcSChristoph Hellwig 	unsigned int rv;
307f461d2dcSChristoph Hellwig 
308f461d2dcSChristoph Hellwig 	cp = _parse_integer_fixup_radix(cp, &base);
309f461d2dcSChristoph Hellwig 	rv = _parse_integer(cp, base, &result);
310f461d2dcSChristoph Hellwig 	if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
311f461d2dcSChristoph Hellwig 		return -ERANGE;
312f461d2dcSChristoph Hellwig 
313f461d2dcSChristoph Hellwig 	cp += rv;
314f461d2dcSChristoph Hellwig 
315f461d2dcSChristoph Hellwig 	if (endp)
316f461d2dcSChristoph Hellwig 		*endp = (char *)cp;
317f461d2dcSChristoph Hellwig 
318f461d2dcSChristoph Hellwig 	*res = (unsigned long)result;
319f461d2dcSChristoph Hellwig 	return 0;
320f461d2dcSChristoph Hellwig }
321f461d2dcSChristoph Hellwig 
322f461d2dcSChristoph Hellwig #define TMPBUFLEN 22
323f461d2dcSChristoph Hellwig /**
324f461d2dcSChristoph Hellwig  * proc_get_long - reads an ASCII formatted integer from a user buffer
325f461d2dcSChristoph Hellwig  *
326f461d2dcSChristoph Hellwig  * @buf: a kernel buffer
327f461d2dcSChristoph Hellwig  * @size: size of the kernel buffer
328f461d2dcSChristoph Hellwig  * @val: this is where the number will be stored
329f461d2dcSChristoph Hellwig  * @neg: set to %TRUE if number is negative
330f461d2dcSChristoph Hellwig  * @perm_tr: a vector which contains the allowed trailers
331f461d2dcSChristoph Hellwig  * @perm_tr_len: size of the perm_tr vector
332f461d2dcSChristoph Hellwig  * @tr: pointer to store the trailer character
333f461d2dcSChristoph Hellwig  *
334f461d2dcSChristoph Hellwig  * In case of success %0 is returned and @buf and @size are updated with
335f461d2dcSChristoph Hellwig  * the amount of bytes read. If @tr is non-NULL and a trailing
336f461d2dcSChristoph Hellwig  * character exists (size is non-zero after returning from this
337f461d2dcSChristoph Hellwig  * function), @tr is updated with the trailing character.
338f461d2dcSChristoph Hellwig  */
339f461d2dcSChristoph Hellwig static int proc_get_long(char **buf, size_t *size,
340f461d2dcSChristoph Hellwig 			  unsigned long *val, bool *neg,
341f461d2dcSChristoph Hellwig 			  const char *perm_tr, unsigned perm_tr_len, char *tr)
342f461d2dcSChristoph Hellwig {
343f461d2dcSChristoph Hellwig 	int len;
344f461d2dcSChristoph Hellwig 	char *p, tmp[TMPBUFLEN];
345f461d2dcSChristoph Hellwig 
346f461d2dcSChristoph Hellwig 	if (!*size)
347f461d2dcSChristoph Hellwig 		return -EINVAL;
348f461d2dcSChristoph Hellwig 
349f461d2dcSChristoph Hellwig 	len = *size;
350f461d2dcSChristoph Hellwig 	if (len > TMPBUFLEN - 1)
351f461d2dcSChristoph Hellwig 		len = TMPBUFLEN - 1;
352f461d2dcSChristoph Hellwig 
353f461d2dcSChristoph Hellwig 	memcpy(tmp, *buf, len);
354f461d2dcSChristoph Hellwig 
355f461d2dcSChristoph Hellwig 	tmp[len] = 0;
356f461d2dcSChristoph Hellwig 	p = tmp;
357f461d2dcSChristoph Hellwig 	if (*p == '-' && *size > 1) {
358f461d2dcSChristoph Hellwig 		*neg = true;
359f461d2dcSChristoph Hellwig 		p++;
360f461d2dcSChristoph Hellwig 	} else
361f461d2dcSChristoph Hellwig 		*neg = false;
362f461d2dcSChristoph Hellwig 	if (!isdigit(*p))
363f461d2dcSChristoph Hellwig 		return -EINVAL;
364f461d2dcSChristoph Hellwig 
365f461d2dcSChristoph Hellwig 	if (strtoul_lenient(p, &p, 0, val))
366f461d2dcSChristoph Hellwig 		return -EINVAL;
367f461d2dcSChristoph Hellwig 
368f461d2dcSChristoph Hellwig 	len = p - tmp;
369f461d2dcSChristoph Hellwig 
370f461d2dcSChristoph Hellwig 	/* We don't know if the next char is whitespace thus we may accept
371f461d2dcSChristoph Hellwig 	 * invalid integers (e.g. 1234...a) or two integers instead of one
372f461d2dcSChristoph Hellwig 	 * (e.g. 123...1). So lets not allow such large numbers. */
373f461d2dcSChristoph Hellwig 	if (len == TMPBUFLEN - 1)
374f461d2dcSChristoph Hellwig 		return -EINVAL;
375f461d2dcSChristoph Hellwig 
376f461d2dcSChristoph Hellwig 	if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
377f461d2dcSChristoph Hellwig 		return -EINVAL;
378f461d2dcSChristoph Hellwig 
379f461d2dcSChristoph Hellwig 	if (tr && (len < *size))
380f461d2dcSChristoph Hellwig 		*tr = *p;
381f461d2dcSChristoph Hellwig 
382f461d2dcSChristoph Hellwig 	*buf += len;
383f461d2dcSChristoph Hellwig 	*size -= len;
384f461d2dcSChristoph Hellwig 
385f461d2dcSChristoph Hellwig 	return 0;
386f461d2dcSChristoph Hellwig }
387f461d2dcSChristoph Hellwig 
388f461d2dcSChristoph Hellwig /**
389f461d2dcSChristoph Hellwig  * proc_put_long - converts an integer to a decimal ASCII formatted string
390f461d2dcSChristoph Hellwig  *
391f461d2dcSChristoph Hellwig  * @buf: the user buffer
392f461d2dcSChristoph Hellwig  * @size: the size of the user buffer
393f461d2dcSChristoph Hellwig  * @val: the integer to be converted
394f461d2dcSChristoph Hellwig  * @neg: sign of the number, %TRUE for negative
395f461d2dcSChristoph Hellwig  *
39632927393SChristoph Hellwig  * In case of success @buf and @size are updated with the amount of bytes
39732927393SChristoph Hellwig  * written.
398f461d2dcSChristoph Hellwig  */
39932927393SChristoph Hellwig static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
400f461d2dcSChristoph Hellwig {
401f461d2dcSChristoph Hellwig 	int len;
402f461d2dcSChristoph Hellwig 	char tmp[TMPBUFLEN], *p = tmp;
403f461d2dcSChristoph Hellwig 
404f461d2dcSChristoph Hellwig 	sprintf(p, "%s%lu", neg ? "-" : "", val);
405f461d2dcSChristoph Hellwig 	len = strlen(tmp);
406f461d2dcSChristoph Hellwig 	if (len > *size)
407f461d2dcSChristoph Hellwig 		len = *size;
40832927393SChristoph Hellwig 	memcpy(*buf, tmp, len);
409f461d2dcSChristoph Hellwig 	*size -= len;
410f461d2dcSChristoph Hellwig 	*buf += len;
411f461d2dcSChristoph Hellwig }
412f461d2dcSChristoph Hellwig #undef TMPBUFLEN
413f461d2dcSChristoph Hellwig 
41432927393SChristoph Hellwig static void proc_put_char(void **buf, size_t *size, char c)
415f461d2dcSChristoph Hellwig {
416f461d2dcSChristoph Hellwig 	if (*size) {
41732927393SChristoph Hellwig 		char **buffer = (char **)buf;
41832927393SChristoph Hellwig 		**buffer = c;
41932927393SChristoph Hellwig 
42032927393SChristoph Hellwig 		(*size)--;
42132927393SChristoph Hellwig 		(*buffer)++;
422f461d2dcSChristoph Hellwig 		*buf = *buffer;
423f461d2dcSChristoph Hellwig 	}
424f461d2dcSChristoph Hellwig }
425f461d2dcSChristoph Hellwig 
426a2071573SJia He static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp,
427a2071573SJia He 				int *valp,
428a2071573SJia He 				int write, void *data)
429a2071573SJia He {
430a2071573SJia He 	if (write) {
431a2071573SJia He 		*(bool *)valp = *lvalp;
432a2071573SJia He 	} else {
433a2071573SJia He 		int val = *(bool *)valp;
434a2071573SJia He 
435a2071573SJia He 		*lvalp = (unsigned long)val;
436a2071573SJia He 		*negp = false;
437a2071573SJia He 	}
438a2071573SJia He 	return 0;
439a2071573SJia He }
440a2071573SJia He 
441f461d2dcSChristoph Hellwig static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
442f461d2dcSChristoph Hellwig 				 int *valp,
443f461d2dcSChristoph Hellwig 				 int write, void *data)
444f461d2dcSChristoph Hellwig {
445f461d2dcSChristoph Hellwig 	if (write) {
446f461d2dcSChristoph Hellwig 		if (*negp) {
447f461d2dcSChristoph Hellwig 			if (*lvalp > (unsigned long) INT_MAX + 1)
448f461d2dcSChristoph Hellwig 				return -EINVAL;
4491f1be04bSKuniyuki Iwashima 			WRITE_ONCE(*valp, -*lvalp);
450f461d2dcSChristoph Hellwig 		} else {
451f461d2dcSChristoph Hellwig 			if (*lvalp > (unsigned long) INT_MAX)
452f461d2dcSChristoph Hellwig 				return -EINVAL;
4531f1be04bSKuniyuki Iwashima 			WRITE_ONCE(*valp, *lvalp);
454f461d2dcSChristoph Hellwig 		}
455f461d2dcSChristoph Hellwig 	} else {
4561f1be04bSKuniyuki Iwashima 		int val = READ_ONCE(*valp);
457f461d2dcSChristoph Hellwig 		if (val < 0) {
458f461d2dcSChristoph Hellwig 			*negp = true;
459f461d2dcSChristoph Hellwig 			*lvalp = -(unsigned long)val;
460f461d2dcSChristoph Hellwig 		} else {
461f461d2dcSChristoph Hellwig 			*negp = false;
462f461d2dcSChristoph Hellwig 			*lvalp = (unsigned long)val;
463f461d2dcSChristoph Hellwig 		}
464f461d2dcSChristoph Hellwig 	}
465f461d2dcSChristoph Hellwig 	return 0;
466f461d2dcSChristoph Hellwig }
467f461d2dcSChristoph Hellwig 
468f461d2dcSChristoph Hellwig static int do_proc_douintvec_conv(unsigned long *lvalp,
469f461d2dcSChristoph Hellwig 				  unsigned int *valp,
470f461d2dcSChristoph Hellwig 				  int write, void *data)
471f461d2dcSChristoph Hellwig {
472f461d2dcSChristoph Hellwig 	if (write) {
473f461d2dcSChristoph Hellwig 		if (*lvalp > UINT_MAX)
474f461d2dcSChristoph Hellwig 			return -EINVAL;
4754762b532SKuniyuki Iwashima 		WRITE_ONCE(*valp, *lvalp);
476f461d2dcSChristoph Hellwig 	} else {
4774762b532SKuniyuki Iwashima 		unsigned int val = READ_ONCE(*valp);
478f461d2dcSChristoph Hellwig 		*lvalp = (unsigned long)val;
479f461d2dcSChristoph Hellwig 	}
480f461d2dcSChristoph Hellwig 	return 0;
481f461d2dcSChristoph Hellwig }
482f461d2dcSChristoph Hellwig 
483f461d2dcSChristoph Hellwig static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
484f461d2dcSChristoph Hellwig 
485f461d2dcSChristoph Hellwig static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
48632927393SChristoph Hellwig 		  int write, void *buffer,
487f461d2dcSChristoph Hellwig 		  size_t *lenp, loff_t *ppos,
488f461d2dcSChristoph Hellwig 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
489f461d2dcSChristoph Hellwig 			      int write, void *data),
490f461d2dcSChristoph Hellwig 		  void *data)
491f461d2dcSChristoph Hellwig {
492f461d2dcSChristoph Hellwig 	int *i, vleft, first = 1, err = 0;
493f461d2dcSChristoph Hellwig 	size_t left;
49432927393SChristoph Hellwig 	char *p;
495f461d2dcSChristoph Hellwig 
496f461d2dcSChristoph Hellwig 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
497f461d2dcSChristoph Hellwig 		*lenp = 0;
498f461d2dcSChristoph Hellwig 		return 0;
499f461d2dcSChristoph Hellwig 	}
500f461d2dcSChristoph Hellwig 
501f461d2dcSChristoph Hellwig 	i = (int *) tbl_data;
502f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(*i);
503f461d2dcSChristoph Hellwig 	left = *lenp;
504f461d2dcSChristoph Hellwig 
505f461d2dcSChristoph Hellwig 	if (!conv)
506f461d2dcSChristoph Hellwig 		conv = do_proc_dointvec_conv;
507f461d2dcSChristoph Hellwig 
508f461d2dcSChristoph Hellwig 	if (write) {
509f461d2dcSChristoph Hellwig 		if (proc_first_pos_non_zero_ignore(ppos, table))
510f461d2dcSChristoph Hellwig 			goto out;
511f461d2dcSChristoph Hellwig 
512f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1)
513f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
51432927393SChristoph Hellwig 		p = buffer;
515f461d2dcSChristoph Hellwig 	}
516f461d2dcSChristoph Hellwig 
517f461d2dcSChristoph Hellwig 	for (; left && vleft--; i++, first=0) {
518f461d2dcSChristoph Hellwig 		unsigned long lval;
519f461d2dcSChristoph Hellwig 		bool neg;
520f461d2dcSChristoph Hellwig 
521f461d2dcSChristoph Hellwig 		if (write) {
522f461d2dcSChristoph Hellwig 			left -= proc_skip_spaces(&p);
523f461d2dcSChristoph Hellwig 
524f461d2dcSChristoph Hellwig 			if (!left)
525f461d2dcSChristoph Hellwig 				break;
526f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &lval, &neg,
527f461d2dcSChristoph Hellwig 					     proc_wspace_sep,
528f461d2dcSChristoph Hellwig 					     sizeof(proc_wspace_sep), NULL);
529f461d2dcSChristoph Hellwig 			if (err)
530f461d2dcSChristoph Hellwig 				break;
531f461d2dcSChristoph Hellwig 			if (conv(&neg, &lval, i, 1, data)) {
532f461d2dcSChristoph Hellwig 				err = -EINVAL;
533f461d2dcSChristoph Hellwig 				break;
534f461d2dcSChristoph Hellwig 			}
535f461d2dcSChristoph Hellwig 		} else {
536f461d2dcSChristoph Hellwig 			if (conv(&neg, &lval, i, 0, data)) {
537f461d2dcSChristoph Hellwig 				err = -EINVAL;
538f461d2dcSChristoph Hellwig 				break;
539f461d2dcSChristoph Hellwig 			}
540f461d2dcSChristoph Hellwig 			if (!first)
54132927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '\t');
54232927393SChristoph Hellwig 			proc_put_long(&buffer, &left, lval, neg);
543f461d2dcSChristoph Hellwig 		}
544f461d2dcSChristoph Hellwig 	}
545f461d2dcSChristoph Hellwig 
546f461d2dcSChristoph Hellwig 	if (!write && !first && left && !err)
54732927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
548f461d2dcSChristoph Hellwig 	if (write && !err && left)
549f461d2dcSChristoph Hellwig 		left -= proc_skip_spaces(&p);
55032927393SChristoph Hellwig 	if (write && first)
551f461d2dcSChristoph Hellwig 		return err ? : -EINVAL;
552f461d2dcSChristoph Hellwig 	*lenp -= left;
553f461d2dcSChristoph Hellwig out:
554f461d2dcSChristoph Hellwig 	*ppos += *lenp;
555f461d2dcSChristoph Hellwig 	return err;
556f461d2dcSChristoph Hellwig }
557f461d2dcSChristoph Hellwig 
558f461d2dcSChristoph Hellwig static int do_proc_dointvec(struct ctl_table *table, int write,
55932927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos,
560f461d2dcSChristoph Hellwig 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
561f461d2dcSChristoph Hellwig 			      int write, void *data),
562f461d2dcSChristoph Hellwig 		  void *data)
563f461d2dcSChristoph Hellwig {
564f461d2dcSChristoph Hellwig 	return __do_proc_dointvec(table->data, table, write,
565f461d2dcSChristoph Hellwig 			buffer, lenp, ppos, conv, data);
566f461d2dcSChristoph Hellwig }
567f461d2dcSChristoph Hellwig 
568f461d2dcSChristoph Hellwig static int do_proc_douintvec_w(unsigned int *tbl_data,
569f461d2dcSChristoph Hellwig 			       struct ctl_table *table,
57032927393SChristoph Hellwig 			       void *buffer,
571f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
572f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
573f461d2dcSChristoph Hellwig 					   unsigned int *valp,
574f461d2dcSChristoph Hellwig 					   int write, void *data),
575f461d2dcSChristoph Hellwig 			       void *data)
576f461d2dcSChristoph Hellwig {
577f461d2dcSChristoph Hellwig 	unsigned long lval;
578f461d2dcSChristoph Hellwig 	int err = 0;
579f461d2dcSChristoph Hellwig 	size_t left;
580f461d2dcSChristoph Hellwig 	bool neg;
58132927393SChristoph Hellwig 	char *p = buffer;
582f461d2dcSChristoph Hellwig 
583f461d2dcSChristoph Hellwig 	left = *lenp;
584f461d2dcSChristoph Hellwig 
585f461d2dcSChristoph Hellwig 	if (proc_first_pos_non_zero_ignore(ppos, table))
586f461d2dcSChristoph Hellwig 		goto bail_early;
587f461d2dcSChristoph Hellwig 
588f461d2dcSChristoph Hellwig 	if (left > PAGE_SIZE - 1)
589f461d2dcSChristoph Hellwig 		left = PAGE_SIZE - 1;
590f461d2dcSChristoph Hellwig 
591f461d2dcSChristoph Hellwig 	left -= proc_skip_spaces(&p);
592f461d2dcSChristoph Hellwig 	if (!left) {
593f461d2dcSChristoph Hellwig 		err = -EINVAL;
594f461d2dcSChristoph Hellwig 		goto out_free;
595f461d2dcSChristoph Hellwig 	}
596f461d2dcSChristoph Hellwig 
597f461d2dcSChristoph Hellwig 	err = proc_get_long(&p, &left, &lval, &neg,
598f461d2dcSChristoph Hellwig 			     proc_wspace_sep,
599f461d2dcSChristoph Hellwig 			     sizeof(proc_wspace_sep), NULL);
600f461d2dcSChristoph Hellwig 	if (err || neg) {
601f461d2dcSChristoph Hellwig 		err = -EINVAL;
602f461d2dcSChristoph Hellwig 		goto out_free;
603f461d2dcSChristoph Hellwig 	}
604f461d2dcSChristoph Hellwig 
605f461d2dcSChristoph Hellwig 	if (conv(&lval, tbl_data, 1, data)) {
606f461d2dcSChristoph Hellwig 		err = -EINVAL;
607f461d2dcSChristoph Hellwig 		goto out_free;
608f461d2dcSChristoph Hellwig 	}
609f461d2dcSChristoph Hellwig 
610f461d2dcSChristoph Hellwig 	if (!err && left)
611f461d2dcSChristoph Hellwig 		left -= proc_skip_spaces(&p);
612f461d2dcSChristoph Hellwig 
613f461d2dcSChristoph Hellwig out_free:
614f461d2dcSChristoph Hellwig 	if (err)
615f461d2dcSChristoph Hellwig 		return -EINVAL;
616f461d2dcSChristoph Hellwig 
617f461d2dcSChristoph Hellwig 	return 0;
618f461d2dcSChristoph Hellwig 
619f461d2dcSChristoph Hellwig 	/* This is in keeping with old __do_proc_dointvec() */
620f461d2dcSChristoph Hellwig bail_early:
621f461d2dcSChristoph Hellwig 	*ppos += *lenp;
622f461d2dcSChristoph Hellwig 	return err;
623f461d2dcSChristoph Hellwig }
624f461d2dcSChristoph Hellwig 
62532927393SChristoph Hellwig static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
626f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
627f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
628f461d2dcSChristoph Hellwig 					   unsigned int *valp,
629f461d2dcSChristoph Hellwig 					   int write, void *data),
630f461d2dcSChristoph Hellwig 			       void *data)
631f461d2dcSChristoph Hellwig {
632f461d2dcSChristoph Hellwig 	unsigned long lval;
633f461d2dcSChristoph Hellwig 	int err = 0;
634f461d2dcSChristoph Hellwig 	size_t left;
635f461d2dcSChristoph Hellwig 
636f461d2dcSChristoph Hellwig 	left = *lenp;
637f461d2dcSChristoph Hellwig 
638f461d2dcSChristoph Hellwig 	if (conv(&lval, tbl_data, 0, data)) {
639f461d2dcSChristoph Hellwig 		err = -EINVAL;
640f461d2dcSChristoph Hellwig 		goto out;
641f461d2dcSChristoph Hellwig 	}
642f461d2dcSChristoph Hellwig 
64332927393SChristoph Hellwig 	proc_put_long(&buffer, &left, lval, false);
64432927393SChristoph Hellwig 	if (!left)
645f461d2dcSChristoph Hellwig 		goto out;
646f461d2dcSChristoph Hellwig 
64732927393SChristoph Hellwig 	proc_put_char(&buffer, &left, '\n');
648f461d2dcSChristoph Hellwig 
649f461d2dcSChristoph Hellwig out:
650f461d2dcSChristoph Hellwig 	*lenp -= left;
651f461d2dcSChristoph Hellwig 	*ppos += *lenp;
652f461d2dcSChristoph Hellwig 
653f461d2dcSChristoph Hellwig 	return err;
654f461d2dcSChristoph Hellwig }
655f461d2dcSChristoph Hellwig 
656f461d2dcSChristoph Hellwig static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
65732927393SChristoph Hellwig 			       int write, void *buffer,
658f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
659f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
660f461d2dcSChristoph Hellwig 					   unsigned int *valp,
661f461d2dcSChristoph Hellwig 					   int write, void *data),
662f461d2dcSChristoph Hellwig 			       void *data)
663f461d2dcSChristoph Hellwig {
664f461d2dcSChristoph Hellwig 	unsigned int *i, vleft;
665f461d2dcSChristoph Hellwig 
666f461d2dcSChristoph Hellwig 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
667f461d2dcSChristoph Hellwig 		*lenp = 0;
668f461d2dcSChristoph Hellwig 		return 0;
669f461d2dcSChristoph Hellwig 	}
670f461d2dcSChristoph Hellwig 
671f461d2dcSChristoph Hellwig 	i = (unsigned int *) tbl_data;
672f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(*i);
673f461d2dcSChristoph Hellwig 
674f461d2dcSChristoph Hellwig 	/*
675f461d2dcSChristoph Hellwig 	 * Arrays are not supported, keep this simple. *Do not* add
676f461d2dcSChristoph Hellwig 	 * support for them.
677f461d2dcSChristoph Hellwig 	 */
678f461d2dcSChristoph Hellwig 	if (vleft != 1) {
679f461d2dcSChristoph Hellwig 		*lenp = 0;
680f461d2dcSChristoph Hellwig 		return -EINVAL;
681f461d2dcSChristoph Hellwig 	}
682f461d2dcSChristoph Hellwig 
683f461d2dcSChristoph Hellwig 	if (!conv)
684f461d2dcSChristoph Hellwig 		conv = do_proc_douintvec_conv;
685f461d2dcSChristoph Hellwig 
686f461d2dcSChristoph Hellwig 	if (write)
687f461d2dcSChristoph Hellwig 		return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
688f461d2dcSChristoph Hellwig 					   conv, data);
689f461d2dcSChristoph Hellwig 	return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
690f461d2dcSChristoph Hellwig }
691f461d2dcSChristoph Hellwig 
6921998f193SLuis Chamberlain int do_proc_douintvec(struct ctl_table *table, int write,
69332927393SChristoph Hellwig 		      void *buffer, size_t *lenp, loff_t *ppos,
694f461d2dcSChristoph Hellwig 		      int (*conv)(unsigned long *lvalp,
695f461d2dcSChristoph Hellwig 				  unsigned int *valp,
696f461d2dcSChristoph Hellwig 				  int write, void *data),
697f461d2dcSChristoph Hellwig 		      void *data)
698f461d2dcSChristoph Hellwig {
699f461d2dcSChristoph Hellwig 	return __do_proc_douintvec(table->data, table, write,
700f461d2dcSChristoph Hellwig 				   buffer, lenp, ppos, conv, data);
701f461d2dcSChristoph Hellwig }
702f461d2dcSChristoph Hellwig 
703f461d2dcSChristoph Hellwig /**
704a2071573SJia He  * proc_dobool - read/write a bool
705a2071573SJia He  * @table: the sysctl table
706a2071573SJia He  * @write: %TRUE if this is a write to the sysctl file
707a2071573SJia He  * @buffer: the user buffer
708a2071573SJia He  * @lenp: the size of the user buffer
709a2071573SJia He  * @ppos: file position
710a2071573SJia He  *
711a2071573SJia He  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
712a2071573SJia He  * values from/to the user buffer, treated as an ASCII string.
713a2071573SJia He  *
714a2071573SJia He  * Returns 0 on success.
715a2071573SJia He  */
716a2071573SJia He int proc_dobool(struct ctl_table *table, int write, void *buffer,
717a2071573SJia He 		size_t *lenp, loff_t *ppos)
718a2071573SJia He {
719a2071573SJia He 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
720a2071573SJia He 				do_proc_dobool_conv, NULL);
721a2071573SJia He }
722a2071573SJia He 
723a2071573SJia He /**
724f461d2dcSChristoph Hellwig  * proc_dointvec - read a vector of integers
725f461d2dcSChristoph Hellwig  * @table: the sysctl table
726f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
727f461d2dcSChristoph Hellwig  * @buffer: the user buffer
728f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
729f461d2dcSChristoph Hellwig  * @ppos: file position
730f461d2dcSChristoph Hellwig  *
731f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
732f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
733f461d2dcSChristoph Hellwig  *
734f461d2dcSChristoph Hellwig  * Returns 0 on success.
735f461d2dcSChristoph Hellwig  */
73632927393SChristoph Hellwig int proc_dointvec(struct ctl_table *table, int write, void *buffer,
73732927393SChristoph Hellwig 		  size_t *lenp, loff_t *ppos)
738f461d2dcSChristoph Hellwig {
739f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
740f461d2dcSChristoph Hellwig }
741f461d2dcSChristoph Hellwig 
742f461d2dcSChristoph Hellwig #ifdef CONFIG_COMPACTION
743f461d2dcSChristoph Hellwig static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
74432927393SChristoph Hellwig 		int write, void *buffer, size_t *lenp, loff_t *ppos)
745f461d2dcSChristoph Hellwig {
746f461d2dcSChristoph Hellwig 	int ret, old;
747f461d2dcSChristoph Hellwig 
748f461d2dcSChristoph Hellwig 	if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
749f461d2dcSChristoph Hellwig 		return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
750f461d2dcSChristoph Hellwig 
751f461d2dcSChristoph Hellwig 	old = *(int *)table->data;
752f461d2dcSChristoph Hellwig 	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
753f461d2dcSChristoph Hellwig 	if (ret)
754f461d2dcSChristoph Hellwig 		return ret;
755f461d2dcSChristoph Hellwig 	if (old != *(int *)table->data)
756f461d2dcSChristoph Hellwig 		pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
757f461d2dcSChristoph Hellwig 			     table->procname, current->comm,
758f461d2dcSChristoph Hellwig 			     task_pid_nr(current));
759f461d2dcSChristoph Hellwig 	return ret;
760f461d2dcSChristoph Hellwig }
761f461d2dcSChristoph Hellwig #endif
762f461d2dcSChristoph Hellwig 
763f461d2dcSChristoph Hellwig /**
764f461d2dcSChristoph Hellwig  * proc_douintvec - read a vector of unsigned integers
765f461d2dcSChristoph Hellwig  * @table: the sysctl table
766f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
767f461d2dcSChristoph Hellwig  * @buffer: the user buffer
768f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
769f461d2dcSChristoph Hellwig  * @ppos: file position
770f461d2dcSChristoph Hellwig  *
771f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
772f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
773f461d2dcSChristoph Hellwig  *
774f461d2dcSChristoph Hellwig  * Returns 0 on success.
775f461d2dcSChristoph Hellwig  */
77632927393SChristoph Hellwig int proc_douintvec(struct ctl_table *table, int write, void *buffer,
77732927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
778f461d2dcSChristoph Hellwig {
779f461d2dcSChristoph Hellwig 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
780f461d2dcSChristoph Hellwig 				 do_proc_douintvec_conv, NULL);
781f461d2dcSChristoph Hellwig }
782f461d2dcSChristoph Hellwig 
783f461d2dcSChristoph Hellwig /*
784f461d2dcSChristoph Hellwig  * Taint values can only be increased
785f461d2dcSChristoph Hellwig  * This means we can safely use a temporary.
786f461d2dcSChristoph Hellwig  */
787f461d2dcSChristoph Hellwig static int proc_taint(struct ctl_table *table, int write,
78832927393SChristoph Hellwig 			       void *buffer, size_t *lenp, loff_t *ppos)
789f461d2dcSChristoph Hellwig {
790f461d2dcSChristoph Hellwig 	struct ctl_table t;
791f461d2dcSChristoph Hellwig 	unsigned long tmptaint = get_taint();
792f461d2dcSChristoph Hellwig 	int err;
793f461d2dcSChristoph Hellwig 
794f461d2dcSChristoph Hellwig 	if (write && !capable(CAP_SYS_ADMIN))
795f461d2dcSChristoph Hellwig 		return -EPERM;
796f461d2dcSChristoph Hellwig 
797f461d2dcSChristoph Hellwig 	t = *table;
798f461d2dcSChristoph Hellwig 	t.data = &tmptaint;
799f461d2dcSChristoph Hellwig 	err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
800f461d2dcSChristoph Hellwig 	if (err < 0)
801f461d2dcSChristoph Hellwig 		return err;
802f461d2dcSChristoph Hellwig 
803f461d2dcSChristoph Hellwig 	if (write) {
804db38d5c1SRafael Aquini 		int i;
805db38d5c1SRafael Aquini 
806db38d5c1SRafael Aquini 		/*
807db38d5c1SRafael Aquini 		 * If we are relying on panic_on_taint not producing
808db38d5c1SRafael Aquini 		 * false positives due to userspace input, bail out
809db38d5c1SRafael Aquini 		 * before setting the requested taint flags.
810db38d5c1SRafael Aquini 		 */
811db38d5c1SRafael Aquini 		if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
812db38d5c1SRafael Aquini 			return -EINVAL;
813db38d5c1SRafael Aquini 
814f461d2dcSChristoph Hellwig 		/*
815f461d2dcSChristoph Hellwig 		 * Poor man's atomic or. Not worth adding a primitive
816f461d2dcSChristoph Hellwig 		 * to everyone's atomic.h for this
817f461d2dcSChristoph Hellwig 		 */
818e77132e7SRafael Aquini 		for (i = 0; i < TAINT_FLAGS_COUNT; i++)
819e77132e7SRafael Aquini 			if ((1UL << i) & tmptaint)
820f461d2dcSChristoph Hellwig 				add_taint(i, LOCKDEP_STILL_OK);
821f461d2dcSChristoph Hellwig 	}
822f461d2dcSChristoph Hellwig 
823f461d2dcSChristoph Hellwig 	return err;
824f461d2dcSChristoph Hellwig }
825f461d2dcSChristoph Hellwig 
826f461d2dcSChristoph Hellwig /**
827f461d2dcSChristoph Hellwig  * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
828f461d2dcSChristoph Hellwig  * @min: pointer to minimum allowable value
829f461d2dcSChristoph Hellwig  * @max: pointer to maximum allowable value
830f461d2dcSChristoph Hellwig  *
831f461d2dcSChristoph Hellwig  * The do_proc_dointvec_minmax_conv_param structure provides the
832f461d2dcSChristoph Hellwig  * minimum and maximum values for doing range checking for those sysctl
833f461d2dcSChristoph Hellwig  * parameters that use the proc_dointvec_minmax() handler.
834f461d2dcSChristoph Hellwig  */
835f461d2dcSChristoph Hellwig struct do_proc_dointvec_minmax_conv_param {
836f461d2dcSChristoph Hellwig 	int *min;
837f461d2dcSChristoph Hellwig 	int *max;
838f461d2dcSChristoph Hellwig };
839f461d2dcSChristoph Hellwig 
840f461d2dcSChristoph Hellwig static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
841f461d2dcSChristoph Hellwig 					int *valp,
842f461d2dcSChristoph Hellwig 					int write, void *data)
843f461d2dcSChristoph Hellwig {
844f461d2dcSChristoph Hellwig 	int tmp, ret;
845f461d2dcSChristoph Hellwig 	struct do_proc_dointvec_minmax_conv_param *param = data;
846f461d2dcSChristoph Hellwig 	/*
847f461d2dcSChristoph Hellwig 	 * If writing, first do so via a temporary local int so we can
848f461d2dcSChristoph Hellwig 	 * bounds-check it before touching *valp.
849f461d2dcSChristoph Hellwig 	 */
850f461d2dcSChristoph Hellwig 	int *ip = write ? &tmp : valp;
851f461d2dcSChristoph Hellwig 
852f461d2dcSChristoph Hellwig 	ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
853f461d2dcSChristoph Hellwig 	if (ret)
854f461d2dcSChristoph Hellwig 		return ret;
855f461d2dcSChristoph Hellwig 
856f461d2dcSChristoph Hellwig 	if (write) {
857f461d2dcSChristoph Hellwig 		if ((param->min && *param->min > tmp) ||
858f461d2dcSChristoph Hellwig 		    (param->max && *param->max < tmp))
859f461d2dcSChristoph Hellwig 			return -EINVAL;
860f613d86dSKuniyuki Iwashima 		WRITE_ONCE(*valp, tmp);
861f461d2dcSChristoph Hellwig 	}
862f461d2dcSChristoph Hellwig 
863f461d2dcSChristoph Hellwig 	return 0;
864f461d2dcSChristoph Hellwig }
865f461d2dcSChristoph Hellwig 
866f461d2dcSChristoph Hellwig /**
867f461d2dcSChristoph Hellwig  * proc_dointvec_minmax - read a vector of integers with min/max values
868f461d2dcSChristoph Hellwig  * @table: the sysctl table
869f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
870f461d2dcSChristoph Hellwig  * @buffer: the user buffer
871f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
872f461d2dcSChristoph Hellwig  * @ppos: file position
873f461d2dcSChristoph Hellwig  *
874f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
875f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
876f461d2dcSChristoph Hellwig  *
877f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
878f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max).
879f461d2dcSChristoph Hellwig  *
880f461d2dcSChristoph Hellwig  * Returns 0 on success or -EINVAL on write when the range check fails.
881f461d2dcSChristoph Hellwig  */
882f461d2dcSChristoph Hellwig int proc_dointvec_minmax(struct ctl_table *table, int write,
88332927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
884f461d2dcSChristoph Hellwig {
885f461d2dcSChristoph Hellwig 	struct do_proc_dointvec_minmax_conv_param param = {
886f461d2dcSChristoph Hellwig 		.min = (int *) table->extra1,
887f461d2dcSChristoph Hellwig 		.max = (int *) table->extra2,
888f461d2dcSChristoph Hellwig 	};
889f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
890f461d2dcSChristoph Hellwig 				do_proc_dointvec_minmax_conv, &param);
891f461d2dcSChristoph Hellwig }
892f461d2dcSChristoph Hellwig 
893f461d2dcSChristoph Hellwig /**
894f461d2dcSChristoph Hellwig  * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
895f461d2dcSChristoph Hellwig  * @min: pointer to minimum allowable value
896f461d2dcSChristoph Hellwig  * @max: pointer to maximum allowable value
897f461d2dcSChristoph Hellwig  *
898f461d2dcSChristoph Hellwig  * The do_proc_douintvec_minmax_conv_param structure provides the
899f461d2dcSChristoph Hellwig  * minimum and maximum values for doing range checking for those sysctl
900f461d2dcSChristoph Hellwig  * parameters that use the proc_douintvec_minmax() handler.
901f461d2dcSChristoph Hellwig  */
902f461d2dcSChristoph Hellwig struct do_proc_douintvec_minmax_conv_param {
903f461d2dcSChristoph Hellwig 	unsigned int *min;
904f461d2dcSChristoph Hellwig 	unsigned int *max;
905f461d2dcSChristoph Hellwig };
906f461d2dcSChristoph Hellwig 
907f461d2dcSChristoph Hellwig static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
908f461d2dcSChristoph Hellwig 					 unsigned int *valp,
909f461d2dcSChristoph Hellwig 					 int write, void *data)
910f461d2dcSChristoph Hellwig {
911f461d2dcSChristoph Hellwig 	int ret;
912f461d2dcSChristoph Hellwig 	unsigned int tmp;
913f461d2dcSChristoph Hellwig 	struct do_proc_douintvec_minmax_conv_param *param = data;
914f461d2dcSChristoph Hellwig 	/* write via temporary local uint for bounds-checking */
915f461d2dcSChristoph Hellwig 	unsigned int *up = write ? &tmp : valp;
916f461d2dcSChristoph Hellwig 
917f461d2dcSChristoph Hellwig 	ret = do_proc_douintvec_conv(lvalp, up, write, data);
918f461d2dcSChristoph Hellwig 	if (ret)
919f461d2dcSChristoph Hellwig 		return ret;
920f461d2dcSChristoph Hellwig 
921f461d2dcSChristoph Hellwig 	if (write) {
922f461d2dcSChristoph Hellwig 		if ((param->min && *param->min > tmp) ||
923f461d2dcSChristoph Hellwig 		    (param->max && *param->max < tmp))
924f461d2dcSChristoph Hellwig 			return -ERANGE;
925f461d2dcSChristoph Hellwig 
9262d3b559dSKuniyuki Iwashima 		WRITE_ONCE(*valp, tmp);
927f461d2dcSChristoph Hellwig 	}
928f461d2dcSChristoph Hellwig 
929f461d2dcSChristoph Hellwig 	return 0;
930f461d2dcSChristoph Hellwig }
931f461d2dcSChristoph Hellwig 
932f461d2dcSChristoph Hellwig /**
933f461d2dcSChristoph Hellwig  * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
934f461d2dcSChristoph Hellwig  * @table: the sysctl table
935f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
936f461d2dcSChristoph Hellwig  * @buffer: the user buffer
937f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
938f461d2dcSChristoph Hellwig  * @ppos: file position
939f461d2dcSChristoph Hellwig  *
940f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
941f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string. Negative
942f461d2dcSChristoph Hellwig  * strings are not allowed.
943f461d2dcSChristoph Hellwig  *
944f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
945f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max). There is a final sanity
946f461d2dcSChristoph Hellwig  * check for UINT_MAX to avoid having to support wrap around uses from
947f461d2dcSChristoph Hellwig  * userspace.
948f461d2dcSChristoph Hellwig  *
949f461d2dcSChristoph Hellwig  * Returns 0 on success or -ERANGE on write when the range check fails.
950f461d2dcSChristoph Hellwig  */
951f461d2dcSChristoph Hellwig int proc_douintvec_minmax(struct ctl_table *table, int write,
95232927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
953f461d2dcSChristoph Hellwig {
954f461d2dcSChristoph Hellwig 	struct do_proc_douintvec_minmax_conv_param param = {
955f461d2dcSChristoph Hellwig 		.min = (unsigned int *) table->extra1,
956f461d2dcSChristoph Hellwig 		.max = (unsigned int *) table->extra2,
957f461d2dcSChristoph Hellwig 	};
958f461d2dcSChristoph Hellwig 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
959f461d2dcSChristoph Hellwig 				 do_proc_douintvec_minmax_conv, &param);
960f461d2dcSChristoph Hellwig }
961f461d2dcSChristoph Hellwig 
962cb944413SEric Dumazet /**
963cb944413SEric Dumazet  * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
964cb944413SEric Dumazet  * @table: the sysctl table
965cb944413SEric Dumazet  * @write: %TRUE if this is a write to the sysctl file
966cb944413SEric Dumazet  * @buffer: the user buffer
967cb944413SEric Dumazet  * @lenp: the size of the user buffer
968cb944413SEric Dumazet  * @ppos: file position
969cb944413SEric Dumazet  *
970cb944413SEric Dumazet  * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
971cb944413SEric Dumazet  * values from/to the user buffer, treated as an ASCII string. Negative
972cb944413SEric Dumazet  * strings are not allowed.
973cb944413SEric Dumazet  *
974cb944413SEric Dumazet  * This routine will ensure the values are within the range specified by
975cb944413SEric Dumazet  * table->extra1 (min) and table->extra2 (max).
976cb944413SEric Dumazet  *
977cb944413SEric Dumazet  * Returns 0 on success or an error on write when the range check fails.
978cb944413SEric Dumazet  */
979cb944413SEric Dumazet int proc_dou8vec_minmax(struct ctl_table *table, int write,
980cb944413SEric Dumazet 			void *buffer, size_t *lenp, loff_t *ppos)
981cb944413SEric Dumazet {
982cb944413SEric Dumazet 	struct ctl_table tmp;
983cb944413SEric Dumazet 	unsigned int min = 0, max = 255U, val;
984cb944413SEric Dumazet 	u8 *data = table->data;
985cb944413SEric Dumazet 	struct do_proc_douintvec_minmax_conv_param param = {
986cb944413SEric Dumazet 		.min = &min,
987cb944413SEric Dumazet 		.max = &max,
988cb944413SEric Dumazet 	};
989cb944413SEric Dumazet 	int res;
990cb944413SEric Dumazet 
991cb944413SEric Dumazet 	/* Do not support arrays yet. */
992cb944413SEric Dumazet 	if (table->maxlen != sizeof(u8))
993cb944413SEric Dumazet 		return -EINVAL;
994cb944413SEric Dumazet 
995cb944413SEric Dumazet 	if (table->extra1) {
996cb944413SEric Dumazet 		min = *(unsigned int *) table->extra1;
997cb944413SEric Dumazet 		if (min > 255U)
998cb944413SEric Dumazet 			return -EINVAL;
999cb944413SEric Dumazet 	}
1000cb944413SEric Dumazet 	if (table->extra2) {
1001cb944413SEric Dumazet 		max = *(unsigned int *) table->extra2;
1002cb944413SEric Dumazet 		if (max > 255U)
1003cb944413SEric Dumazet 			return -EINVAL;
1004cb944413SEric Dumazet 	}
1005cb944413SEric Dumazet 
1006cb944413SEric Dumazet 	tmp = *table;
1007cb944413SEric Dumazet 
1008cb944413SEric Dumazet 	tmp.maxlen = sizeof(val);
1009cb944413SEric Dumazet 	tmp.data = &val;
1010cb944413SEric Dumazet 	val = *data;
1011cb944413SEric Dumazet 	res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
1012cb944413SEric Dumazet 				do_proc_douintvec_minmax_conv, &param);
1013cb944413SEric Dumazet 	if (res)
1014cb944413SEric Dumazet 		return res;
1015cb944413SEric Dumazet 	if (write)
1016cb944413SEric Dumazet 		*data = val;
1017cb944413SEric Dumazet 	return 0;
1018cb944413SEric Dumazet }
1019cb944413SEric Dumazet EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
1020cb944413SEric Dumazet 
1021f461d2dcSChristoph Hellwig #ifdef CONFIG_MAGIC_SYSRQ
1022f461d2dcSChristoph Hellwig static int sysrq_sysctl_handler(struct ctl_table *table, int write,
102332927393SChristoph Hellwig 				void *buffer, size_t *lenp, loff_t *ppos)
1024f461d2dcSChristoph Hellwig {
1025f461d2dcSChristoph Hellwig 	int tmp, ret;
1026f461d2dcSChristoph Hellwig 
1027f461d2dcSChristoph Hellwig 	tmp = sysrq_mask();
1028f461d2dcSChristoph Hellwig 
1029f461d2dcSChristoph Hellwig 	ret = __do_proc_dointvec(&tmp, table, write, buffer,
1030f461d2dcSChristoph Hellwig 			       lenp, ppos, NULL, NULL);
1031f461d2dcSChristoph Hellwig 	if (ret || !write)
1032f461d2dcSChristoph Hellwig 		return ret;
1033f461d2dcSChristoph Hellwig 
1034f461d2dcSChristoph Hellwig 	if (write)
1035f461d2dcSChristoph Hellwig 		sysrq_toggle_support(tmp);
1036f461d2dcSChristoph Hellwig 
1037f461d2dcSChristoph Hellwig 	return 0;
1038f461d2dcSChristoph Hellwig }
1039f461d2dcSChristoph Hellwig #endif
1040f461d2dcSChristoph Hellwig 
104132927393SChristoph Hellwig static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
104232927393SChristoph Hellwig 		int write, void *buffer, size_t *lenp, loff_t *ppos,
104332927393SChristoph Hellwig 		unsigned long convmul, unsigned long convdiv)
1044f461d2dcSChristoph Hellwig {
1045f461d2dcSChristoph Hellwig 	unsigned long *i, *min, *max;
1046f461d2dcSChristoph Hellwig 	int vleft, first = 1, err = 0;
1047f461d2dcSChristoph Hellwig 	size_t left;
104832927393SChristoph Hellwig 	char *p;
1049f461d2dcSChristoph Hellwig 
1050f461d2dcSChristoph Hellwig 	if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1051f461d2dcSChristoph Hellwig 		*lenp = 0;
1052f461d2dcSChristoph Hellwig 		return 0;
1053f461d2dcSChristoph Hellwig 	}
1054f461d2dcSChristoph Hellwig 
1055f461d2dcSChristoph Hellwig 	i = (unsigned long *) data;
1056f461d2dcSChristoph Hellwig 	min = (unsigned long *) table->extra1;
1057f461d2dcSChristoph Hellwig 	max = (unsigned long *) table->extra2;
1058f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(unsigned long);
1059f461d2dcSChristoph Hellwig 	left = *lenp;
1060f461d2dcSChristoph Hellwig 
1061f461d2dcSChristoph Hellwig 	if (write) {
1062f461d2dcSChristoph Hellwig 		if (proc_first_pos_non_zero_ignore(ppos, table))
1063f461d2dcSChristoph Hellwig 			goto out;
1064f461d2dcSChristoph Hellwig 
1065f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1)
1066f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
106732927393SChristoph Hellwig 		p = buffer;
1068f461d2dcSChristoph Hellwig 	}
1069f461d2dcSChristoph Hellwig 
1070f461d2dcSChristoph Hellwig 	for (; left && vleft--; i++, first = 0) {
1071f461d2dcSChristoph Hellwig 		unsigned long val;
1072f461d2dcSChristoph Hellwig 
1073f461d2dcSChristoph Hellwig 		if (write) {
1074f461d2dcSChristoph Hellwig 			bool neg;
1075f461d2dcSChristoph Hellwig 
1076f461d2dcSChristoph Hellwig 			left -= proc_skip_spaces(&p);
1077f461d2dcSChristoph Hellwig 			if (!left)
1078f461d2dcSChristoph Hellwig 				break;
1079f461d2dcSChristoph Hellwig 
1080f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &val, &neg,
1081f461d2dcSChristoph Hellwig 					     proc_wspace_sep,
1082f461d2dcSChristoph Hellwig 					     sizeof(proc_wspace_sep), NULL);
10831622ed7dSBaokun Li 			if (err || neg) {
10841622ed7dSBaokun Li 				err = -EINVAL;
1085f461d2dcSChristoph Hellwig 				break;
10861622ed7dSBaokun Li 			}
10871622ed7dSBaokun Li 
1088f461d2dcSChristoph Hellwig 			val = convmul * val / convdiv;
1089f461d2dcSChristoph Hellwig 			if ((min && val < *min) || (max && val > *max)) {
1090f461d2dcSChristoph Hellwig 				err = -EINVAL;
1091f461d2dcSChristoph Hellwig 				break;
1092f461d2dcSChristoph Hellwig 			}
1093*c31bcc8fSKuniyuki Iwashima 			WRITE_ONCE(*i, val);
1094f461d2dcSChristoph Hellwig 		} else {
1095*c31bcc8fSKuniyuki Iwashima 			val = convdiv * READ_ONCE(*i) / convmul;
109632927393SChristoph Hellwig 			if (!first)
109732927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '\t');
109832927393SChristoph Hellwig 			proc_put_long(&buffer, &left, val, false);
1099f461d2dcSChristoph Hellwig 		}
1100f461d2dcSChristoph Hellwig 	}
1101f461d2dcSChristoph Hellwig 
1102f461d2dcSChristoph Hellwig 	if (!write && !first && left && !err)
110332927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
1104f461d2dcSChristoph Hellwig 	if (write && !err)
1105f461d2dcSChristoph Hellwig 		left -= proc_skip_spaces(&p);
110632927393SChristoph Hellwig 	if (write && first)
1107f461d2dcSChristoph Hellwig 		return err ? : -EINVAL;
1108f461d2dcSChristoph Hellwig 	*lenp -= left;
1109f461d2dcSChristoph Hellwig out:
1110f461d2dcSChristoph Hellwig 	*ppos += *lenp;
1111f461d2dcSChristoph Hellwig 	return err;
1112f461d2dcSChristoph Hellwig }
1113f461d2dcSChristoph Hellwig 
1114f461d2dcSChristoph Hellwig static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
111532927393SChristoph Hellwig 		void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1116f461d2dcSChristoph Hellwig 		unsigned long convdiv)
1117f461d2dcSChristoph Hellwig {
1118f461d2dcSChristoph Hellwig 	return __do_proc_doulongvec_minmax(table->data, table, write,
1119f461d2dcSChristoph Hellwig 			buffer, lenp, ppos, convmul, convdiv);
1120f461d2dcSChristoph Hellwig }
1121f461d2dcSChristoph Hellwig 
1122f461d2dcSChristoph Hellwig /**
1123f461d2dcSChristoph Hellwig  * proc_doulongvec_minmax - read a vector of long integers with min/max values
1124f461d2dcSChristoph Hellwig  * @table: the sysctl table
1125f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1126f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1127f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1128f461d2dcSChristoph Hellwig  * @ppos: file position
1129f461d2dcSChristoph Hellwig  *
1130f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1131f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1132f461d2dcSChristoph Hellwig  *
1133f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
1134f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max).
1135f461d2dcSChristoph Hellwig  *
1136f461d2dcSChristoph Hellwig  * Returns 0 on success.
1137f461d2dcSChristoph Hellwig  */
1138f461d2dcSChristoph Hellwig int proc_doulongvec_minmax(struct ctl_table *table, int write,
113932927393SChristoph Hellwig 			   void *buffer, size_t *lenp, loff_t *ppos)
1140f461d2dcSChristoph Hellwig {
1141f461d2dcSChristoph Hellwig     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1142f461d2dcSChristoph Hellwig }
1143f461d2dcSChristoph Hellwig 
1144f461d2dcSChristoph Hellwig /**
1145f461d2dcSChristoph Hellwig  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1146f461d2dcSChristoph Hellwig  * @table: the sysctl table
1147f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1148f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1149f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1150f461d2dcSChristoph Hellwig  * @ppos: file position
1151f461d2dcSChristoph Hellwig  *
1152f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1153f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string. The values
1154f461d2dcSChristoph Hellwig  * are treated as milliseconds, and converted to jiffies when they are stored.
1155f461d2dcSChristoph Hellwig  *
1156f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
1157f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max).
1158f461d2dcSChristoph Hellwig  *
1159f461d2dcSChristoph Hellwig  * Returns 0 on success.
1160f461d2dcSChristoph Hellwig  */
1161f461d2dcSChristoph Hellwig int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
116232927393SChristoph Hellwig 				      void *buffer, size_t *lenp, loff_t *ppos)
1163f461d2dcSChristoph Hellwig {
1164f461d2dcSChristoph Hellwig     return do_proc_doulongvec_minmax(table, write, buffer,
1165f461d2dcSChristoph Hellwig 				     lenp, ppos, HZ, 1000l);
1166f461d2dcSChristoph Hellwig }
1167f461d2dcSChristoph Hellwig 
1168f461d2dcSChristoph Hellwig 
1169f461d2dcSChristoph Hellwig static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1170f461d2dcSChristoph Hellwig 					 int *valp,
1171f461d2dcSChristoph Hellwig 					 int write, void *data)
1172f461d2dcSChristoph Hellwig {
1173f461d2dcSChristoph Hellwig 	if (write) {
1174f461d2dcSChristoph Hellwig 		if (*lvalp > INT_MAX / HZ)
1175f461d2dcSChristoph Hellwig 			return 1;
1176f461d2dcSChristoph Hellwig 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1177f461d2dcSChristoph Hellwig 	} else {
1178f461d2dcSChristoph Hellwig 		int val = *valp;
1179f461d2dcSChristoph Hellwig 		unsigned long lval;
1180f461d2dcSChristoph Hellwig 		if (val < 0) {
1181f461d2dcSChristoph Hellwig 			*negp = true;
1182f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1183f461d2dcSChristoph Hellwig 		} else {
1184f461d2dcSChristoph Hellwig 			*negp = false;
1185f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1186f461d2dcSChristoph Hellwig 		}
1187f461d2dcSChristoph Hellwig 		*lvalp = lval / HZ;
1188f461d2dcSChristoph Hellwig 	}
1189f461d2dcSChristoph Hellwig 	return 0;
1190f461d2dcSChristoph Hellwig }
1191f461d2dcSChristoph Hellwig 
1192f461d2dcSChristoph Hellwig static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1193f461d2dcSChristoph Hellwig 						int *valp,
1194f461d2dcSChristoph Hellwig 						int write, void *data)
1195f461d2dcSChristoph Hellwig {
1196f461d2dcSChristoph Hellwig 	if (write) {
1197f461d2dcSChristoph Hellwig 		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1198f461d2dcSChristoph Hellwig 			return 1;
1199f461d2dcSChristoph Hellwig 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1200f461d2dcSChristoph Hellwig 	} else {
1201f461d2dcSChristoph Hellwig 		int val = *valp;
1202f461d2dcSChristoph Hellwig 		unsigned long lval;
1203f461d2dcSChristoph Hellwig 		if (val < 0) {
1204f461d2dcSChristoph Hellwig 			*negp = true;
1205f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1206f461d2dcSChristoph Hellwig 		} else {
1207f461d2dcSChristoph Hellwig 			*negp = false;
1208f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1209f461d2dcSChristoph Hellwig 		}
1210f461d2dcSChristoph Hellwig 		*lvalp = jiffies_to_clock_t(lval);
1211f461d2dcSChristoph Hellwig 	}
1212f461d2dcSChristoph Hellwig 	return 0;
1213f461d2dcSChristoph Hellwig }
1214f461d2dcSChristoph Hellwig 
1215f461d2dcSChristoph Hellwig static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1216f461d2dcSChristoph Hellwig 					    int *valp,
1217f461d2dcSChristoph Hellwig 					    int write, void *data)
1218f461d2dcSChristoph Hellwig {
1219f461d2dcSChristoph Hellwig 	if (write) {
1220f461d2dcSChristoph Hellwig 		unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1221f461d2dcSChristoph Hellwig 
1222f461d2dcSChristoph Hellwig 		if (jif > INT_MAX)
1223f461d2dcSChristoph Hellwig 			return 1;
1224f461d2dcSChristoph Hellwig 		*valp = (int)jif;
1225f461d2dcSChristoph Hellwig 	} else {
1226f461d2dcSChristoph Hellwig 		int val = *valp;
1227f461d2dcSChristoph Hellwig 		unsigned long lval;
1228f461d2dcSChristoph Hellwig 		if (val < 0) {
1229f461d2dcSChristoph Hellwig 			*negp = true;
1230f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1231f461d2dcSChristoph Hellwig 		} else {
1232f461d2dcSChristoph Hellwig 			*negp = false;
1233f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1234f461d2dcSChristoph Hellwig 		}
1235f461d2dcSChristoph Hellwig 		*lvalp = jiffies_to_msecs(lval);
1236f461d2dcSChristoph Hellwig 	}
1237f461d2dcSChristoph Hellwig 	return 0;
1238f461d2dcSChristoph Hellwig }
1239f461d2dcSChristoph Hellwig 
1240f461d2dcSChristoph Hellwig /**
1241f461d2dcSChristoph Hellwig  * proc_dointvec_jiffies - read a vector of integers as seconds
1242f461d2dcSChristoph Hellwig  * @table: the sysctl table
1243f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1244f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1245f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1246f461d2dcSChristoph Hellwig  * @ppos: file position
1247f461d2dcSChristoph Hellwig  *
1248f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1249f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1250f461d2dcSChristoph Hellwig  * The values read are assumed to be in seconds, and are converted into
1251f461d2dcSChristoph Hellwig  * jiffies.
1252f461d2dcSChristoph Hellwig  *
1253f461d2dcSChristoph Hellwig  * Returns 0 on success.
1254f461d2dcSChristoph Hellwig  */
1255f461d2dcSChristoph Hellwig int proc_dointvec_jiffies(struct ctl_table *table, int write,
125632927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
1257f461d2dcSChristoph Hellwig {
1258f461d2dcSChristoph Hellwig     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1259f461d2dcSChristoph Hellwig 		    	    do_proc_dointvec_jiffies_conv,NULL);
1260f461d2dcSChristoph Hellwig }
1261f461d2dcSChristoph Hellwig 
1262f461d2dcSChristoph Hellwig /**
1263f461d2dcSChristoph Hellwig  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1264f461d2dcSChristoph Hellwig  * @table: the sysctl table
1265f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1266f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1267f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1268f461d2dcSChristoph Hellwig  * @ppos: pointer to the file position
1269f461d2dcSChristoph Hellwig  *
1270f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1271f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1272f461d2dcSChristoph Hellwig  * The values read are assumed to be in 1/USER_HZ seconds, and
1273f461d2dcSChristoph Hellwig  * are converted into jiffies.
1274f461d2dcSChristoph Hellwig  *
1275f461d2dcSChristoph Hellwig  * Returns 0 on success.
1276f461d2dcSChristoph Hellwig  */
1277f461d2dcSChristoph Hellwig int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
127832927393SChristoph Hellwig 				 void *buffer, size_t *lenp, loff_t *ppos)
1279f461d2dcSChristoph Hellwig {
1280f461d2dcSChristoph Hellwig     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1281f461d2dcSChristoph Hellwig 		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);
1282f461d2dcSChristoph Hellwig }
1283f461d2dcSChristoph Hellwig 
1284f461d2dcSChristoph Hellwig /**
1285f461d2dcSChristoph Hellwig  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1286f461d2dcSChristoph Hellwig  * @table: the sysctl table
1287f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1288f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1289f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1290f461d2dcSChristoph Hellwig  * @ppos: file position
1291f461d2dcSChristoph Hellwig  * @ppos: the current position in the file
1292f461d2dcSChristoph Hellwig  *
1293f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1294f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1295f461d2dcSChristoph Hellwig  * The values read are assumed to be in 1/1000 seconds, and
1296f461d2dcSChristoph Hellwig  * are converted into jiffies.
1297f461d2dcSChristoph Hellwig  *
1298f461d2dcSChristoph Hellwig  * Returns 0 on success.
1299f461d2dcSChristoph Hellwig  */
130032927393SChristoph Hellwig int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
130132927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
1302f461d2dcSChristoph Hellwig {
1303f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
1304f461d2dcSChristoph Hellwig 				do_proc_dointvec_ms_jiffies_conv, NULL);
1305f461d2dcSChristoph Hellwig }
1306f461d2dcSChristoph Hellwig 
130732927393SChristoph Hellwig static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
130832927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
1309f461d2dcSChristoph Hellwig {
1310f461d2dcSChristoph Hellwig 	struct pid *new_pid;
1311f461d2dcSChristoph Hellwig 	pid_t tmp;
1312f461d2dcSChristoph Hellwig 	int r;
1313f461d2dcSChristoph Hellwig 
1314f461d2dcSChristoph Hellwig 	tmp = pid_vnr(cad_pid);
1315f461d2dcSChristoph Hellwig 
1316f461d2dcSChristoph Hellwig 	r = __do_proc_dointvec(&tmp, table, write, buffer,
1317f461d2dcSChristoph Hellwig 			       lenp, ppos, NULL, NULL);
1318f461d2dcSChristoph Hellwig 	if (r || !write)
1319f461d2dcSChristoph Hellwig 		return r;
1320f461d2dcSChristoph Hellwig 
1321f461d2dcSChristoph Hellwig 	new_pid = find_get_pid(tmp);
1322f461d2dcSChristoph Hellwig 	if (!new_pid)
1323f461d2dcSChristoph Hellwig 		return -ESRCH;
1324f461d2dcSChristoph Hellwig 
1325f461d2dcSChristoph Hellwig 	put_pid(xchg(&cad_pid, new_pid));
1326f461d2dcSChristoph Hellwig 	return 0;
1327f461d2dcSChristoph Hellwig }
1328f461d2dcSChristoph Hellwig 
1329f461d2dcSChristoph Hellwig /**
1330f461d2dcSChristoph Hellwig  * proc_do_large_bitmap - read/write from/to a large bitmap
1331f461d2dcSChristoph Hellwig  * @table: the sysctl table
1332f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1333f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1334f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1335f461d2dcSChristoph Hellwig  * @ppos: file position
1336f461d2dcSChristoph Hellwig  *
1337f461d2dcSChristoph Hellwig  * The bitmap is stored at table->data and the bitmap length (in bits)
1338f461d2dcSChristoph Hellwig  * in table->maxlen.
1339f461d2dcSChristoph Hellwig  *
1340f461d2dcSChristoph Hellwig  * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1341f461d2dcSChristoph Hellwig  * large bitmaps may be represented in a compact manner. Writing into
1342f461d2dcSChristoph Hellwig  * the file will clear the bitmap then update it with the given input.
1343f461d2dcSChristoph Hellwig  *
1344f461d2dcSChristoph Hellwig  * Returns 0 on success.
1345f461d2dcSChristoph Hellwig  */
1346f461d2dcSChristoph Hellwig int proc_do_large_bitmap(struct ctl_table *table, int write,
134732927393SChristoph Hellwig 			 void *buffer, size_t *lenp, loff_t *ppos)
1348f461d2dcSChristoph Hellwig {
1349f461d2dcSChristoph Hellwig 	int err = 0;
1350f461d2dcSChristoph Hellwig 	size_t left = *lenp;
1351f461d2dcSChristoph Hellwig 	unsigned long bitmap_len = table->maxlen;
1352f461d2dcSChristoph Hellwig 	unsigned long *bitmap = *(unsigned long **) table->data;
1353f461d2dcSChristoph Hellwig 	unsigned long *tmp_bitmap = NULL;
1354f461d2dcSChristoph Hellwig 	char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1355f461d2dcSChristoph Hellwig 
1356f461d2dcSChristoph Hellwig 	if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1357f461d2dcSChristoph Hellwig 		*lenp = 0;
1358f461d2dcSChristoph Hellwig 		return 0;
1359f461d2dcSChristoph Hellwig 	}
1360f461d2dcSChristoph Hellwig 
1361f461d2dcSChristoph Hellwig 	if (write) {
136232927393SChristoph Hellwig 		char *p = buffer;
1363f461d2dcSChristoph Hellwig 		size_t skipped = 0;
1364f461d2dcSChristoph Hellwig 
1365f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1) {
1366f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
1367f461d2dcSChristoph Hellwig 			/* How much of the buffer we'll skip this pass */
1368f461d2dcSChristoph Hellwig 			skipped = *lenp - left;
1369f461d2dcSChristoph Hellwig 		}
1370f461d2dcSChristoph Hellwig 
1371f461d2dcSChristoph Hellwig 		tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
137232927393SChristoph Hellwig 		if (!tmp_bitmap)
1373f461d2dcSChristoph Hellwig 			return -ENOMEM;
1374f461d2dcSChristoph Hellwig 		proc_skip_char(&p, &left, '\n');
1375f461d2dcSChristoph Hellwig 		while (!err && left) {
1376f461d2dcSChristoph Hellwig 			unsigned long val_a, val_b;
1377f461d2dcSChristoph Hellwig 			bool neg;
1378f461d2dcSChristoph Hellwig 			size_t saved_left;
1379f461d2dcSChristoph Hellwig 
1380f461d2dcSChristoph Hellwig 			/* In case we stop parsing mid-number, we can reset */
1381f461d2dcSChristoph Hellwig 			saved_left = left;
1382f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1383f461d2dcSChristoph Hellwig 					     sizeof(tr_a), &c);
1384f461d2dcSChristoph Hellwig 			/*
1385f461d2dcSChristoph Hellwig 			 * If we consumed the entirety of a truncated buffer or
1386f461d2dcSChristoph Hellwig 			 * only one char is left (may be a "-"), then stop here,
1387f461d2dcSChristoph Hellwig 			 * reset, & come back for more.
1388f461d2dcSChristoph Hellwig 			 */
1389f461d2dcSChristoph Hellwig 			if ((left <= 1) && skipped) {
1390f461d2dcSChristoph Hellwig 				left = saved_left;
1391f461d2dcSChristoph Hellwig 				break;
1392f461d2dcSChristoph Hellwig 			}
1393f461d2dcSChristoph Hellwig 
1394f461d2dcSChristoph Hellwig 			if (err)
1395f461d2dcSChristoph Hellwig 				break;
1396f461d2dcSChristoph Hellwig 			if (val_a >= bitmap_len || neg) {
1397f461d2dcSChristoph Hellwig 				err = -EINVAL;
1398f461d2dcSChristoph Hellwig 				break;
1399f461d2dcSChristoph Hellwig 			}
1400f461d2dcSChristoph Hellwig 
1401f461d2dcSChristoph Hellwig 			val_b = val_a;
1402f461d2dcSChristoph Hellwig 			if (left) {
1403f461d2dcSChristoph Hellwig 				p++;
1404f461d2dcSChristoph Hellwig 				left--;
1405f461d2dcSChristoph Hellwig 			}
1406f461d2dcSChristoph Hellwig 
1407f461d2dcSChristoph Hellwig 			if (c == '-') {
1408f461d2dcSChristoph Hellwig 				err = proc_get_long(&p, &left, &val_b,
1409f461d2dcSChristoph Hellwig 						     &neg, tr_b, sizeof(tr_b),
1410f461d2dcSChristoph Hellwig 						     &c);
1411f461d2dcSChristoph Hellwig 				/*
1412f461d2dcSChristoph Hellwig 				 * If we consumed all of a truncated buffer or
1413f461d2dcSChristoph Hellwig 				 * then stop here, reset, & come back for more.
1414f461d2dcSChristoph Hellwig 				 */
1415f461d2dcSChristoph Hellwig 				if (!left && skipped) {
1416f461d2dcSChristoph Hellwig 					left = saved_left;
1417f461d2dcSChristoph Hellwig 					break;
1418f461d2dcSChristoph Hellwig 				}
1419f461d2dcSChristoph Hellwig 
1420f461d2dcSChristoph Hellwig 				if (err)
1421f461d2dcSChristoph Hellwig 					break;
1422f461d2dcSChristoph Hellwig 				if (val_b >= bitmap_len || neg ||
1423f461d2dcSChristoph Hellwig 				    val_a > val_b) {
1424f461d2dcSChristoph Hellwig 					err = -EINVAL;
1425f461d2dcSChristoph Hellwig 					break;
1426f461d2dcSChristoph Hellwig 				}
1427f461d2dcSChristoph Hellwig 				if (left) {
1428f461d2dcSChristoph Hellwig 					p++;
1429f461d2dcSChristoph Hellwig 					left--;
1430f461d2dcSChristoph Hellwig 				}
1431f461d2dcSChristoph Hellwig 			}
1432f461d2dcSChristoph Hellwig 
1433f461d2dcSChristoph Hellwig 			bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1434f461d2dcSChristoph Hellwig 			proc_skip_char(&p, &left, '\n');
1435f461d2dcSChristoph Hellwig 		}
1436f461d2dcSChristoph Hellwig 		left += skipped;
1437f461d2dcSChristoph Hellwig 	} else {
1438f461d2dcSChristoph Hellwig 		unsigned long bit_a, bit_b = 0;
14399a52c5f3SJiapeng Chong 		bool first = 1;
1440f461d2dcSChristoph Hellwig 
1441f461d2dcSChristoph Hellwig 		while (left) {
1442f461d2dcSChristoph Hellwig 			bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1443f461d2dcSChristoph Hellwig 			if (bit_a >= bitmap_len)
1444f461d2dcSChristoph Hellwig 				break;
1445f461d2dcSChristoph Hellwig 			bit_b = find_next_zero_bit(bitmap, bitmap_len,
1446f461d2dcSChristoph Hellwig 						   bit_a + 1) - 1;
1447f461d2dcSChristoph Hellwig 
144832927393SChristoph Hellwig 			if (!first)
144932927393SChristoph Hellwig 				proc_put_char(&buffer, &left, ',');
145032927393SChristoph Hellwig 			proc_put_long(&buffer, &left, bit_a, false);
1451f461d2dcSChristoph Hellwig 			if (bit_a != bit_b) {
145232927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '-');
145332927393SChristoph Hellwig 				proc_put_long(&buffer, &left, bit_b, false);
1454f461d2dcSChristoph Hellwig 			}
1455f461d2dcSChristoph Hellwig 
1456f461d2dcSChristoph Hellwig 			first = 0; bit_b++;
1457f461d2dcSChristoph Hellwig 		}
145832927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
1459f461d2dcSChristoph Hellwig 	}
1460f461d2dcSChristoph Hellwig 
1461f461d2dcSChristoph Hellwig 	if (!err) {
1462f461d2dcSChristoph Hellwig 		if (write) {
1463f461d2dcSChristoph Hellwig 			if (*ppos)
1464f461d2dcSChristoph Hellwig 				bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1465f461d2dcSChristoph Hellwig 			else
1466f461d2dcSChristoph Hellwig 				bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1467f461d2dcSChristoph Hellwig 		}
1468f461d2dcSChristoph Hellwig 		*lenp -= left;
1469f461d2dcSChristoph Hellwig 		*ppos += *lenp;
1470f461d2dcSChristoph Hellwig 	}
1471f461d2dcSChristoph Hellwig 
1472f461d2dcSChristoph Hellwig 	bitmap_free(tmp_bitmap);
1473f461d2dcSChristoph Hellwig 	return err;
1474f461d2dcSChristoph Hellwig }
1475f461d2dcSChristoph Hellwig 
1476f461d2dcSChristoph Hellwig #else /* CONFIG_PROC_SYSCTL */
1477f461d2dcSChristoph Hellwig 
1478f461d2dcSChristoph Hellwig int proc_dostring(struct ctl_table *table, int write,
147932927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1480f461d2dcSChristoph Hellwig {
1481f461d2dcSChristoph Hellwig 	return -ENOSYS;
1482f461d2dcSChristoph Hellwig }
1483f461d2dcSChristoph Hellwig 
1484a2071573SJia He int proc_dobool(struct ctl_table *table, int write,
1485a2071573SJia He 		void *buffer, size_t *lenp, loff_t *ppos)
1486a2071573SJia He {
1487a2071573SJia He 	return -ENOSYS;
1488a2071573SJia He }
1489a2071573SJia He 
1490f461d2dcSChristoph Hellwig int proc_dointvec(struct ctl_table *table, int write,
149132927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1492f461d2dcSChristoph Hellwig {
1493f461d2dcSChristoph Hellwig 	return -ENOSYS;
1494f461d2dcSChristoph Hellwig }
1495f461d2dcSChristoph Hellwig 
1496f461d2dcSChristoph Hellwig int proc_douintvec(struct ctl_table *table, int write,
149732927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1498f461d2dcSChristoph Hellwig {
1499f461d2dcSChristoph Hellwig 	return -ENOSYS;
1500f461d2dcSChristoph Hellwig }
1501f461d2dcSChristoph Hellwig 
1502f461d2dcSChristoph Hellwig int proc_dointvec_minmax(struct ctl_table *table, int write,
150332927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1504f461d2dcSChristoph Hellwig {
1505f461d2dcSChristoph Hellwig 	return -ENOSYS;
1506f461d2dcSChristoph Hellwig }
1507f461d2dcSChristoph Hellwig 
1508f461d2dcSChristoph Hellwig int proc_douintvec_minmax(struct ctl_table *table, int write,
150932927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
1510f461d2dcSChristoph Hellwig {
1511f461d2dcSChristoph Hellwig 	return -ENOSYS;
1512f461d2dcSChristoph Hellwig }
1513f461d2dcSChristoph Hellwig 
1514cb944413SEric Dumazet int proc_dou8vec_minmax(struct ctl_table *table, int write,
1515cb944413SEric Dumazet 			void *buffer, size_t *lenp, loff_t *ppos)
1516cb944413SEric Dumazet {
1517cb944413SEric Dumazet 	return -ENOSYS;
1518cb944413SEric Dumazet }
1519cb944413SEric Dumazet 
1520f461d2dcSChristoph Hellwig int proc_dointvec_jiffies(struct ctl_table *table, int write,
152132927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1522f461d2dcSChristoph Hellwig {
1523f461d2dcSChristoph Hellwig 	return -ENOSYS;
1524f461d2dcSChristoph Hellwig }
1525f461d2dcSChristoph Hellwig 
1526f461d2dcSChristoph Hellwig int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
152732927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1528f461d2dcSChristoph Hellwig {
1529f461d2dcSChristoph Hellwig 	return -ENOSYS;
1530f461d2dcSChristoph Hellwig }
1531f461d2dcSChristoph Hellwig 
1532f461d2dcSChristoph Hellwig int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
153332927393SChristoph Hellwig 			     void *buffer, size_t *lenp, loff_t *ppos)
1534f461d2dcSChristoph Hellwig {
1535f461d2dcSChristoph Hellwig 	return -ENOSYS;
1536f461d2dcSChristoph Hellwig }
1537f461d2dcSChristoph Hellwig 
1538f461d2dcSChristoph Hellwig int proc_doulongvec_minmax(struct ctl_table *table, int write,
153932927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1540f461d2dcSChristoph Hellwig {
1541f461d2dcSChristoph Hellwig 	return -ENOSYS;
1542f461d2dcSChristoph Hellwig }
1543f461d2dcSChristoph Hellwig 
1544f461d2dcSChristoph Hellwig int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
154532927393SChristoph Hellwig 				      void *buffer, size_t *lenp, loff_t *ppos)
1546f461d2dcSChristoph Hellwig {
1547f461d2dcSChristoph Hellwig 	return -ENOSYS;
1548f461d2dcSChristoph Hellwig }
1549f461d2dcSChristoph Hellwig 
1550f461d2dcSChristoph Hellwig int proc_do_large_bitmap(struct ctl_table *table, int write,
155132927393SChristoph Hellwig 			 void *buffer, size_t *lenp, loff_t *ppos)
1552f461d2dcSChristoph Hellwig {
1553f461d2dcSChristoph Hellwig 	return -ENOSYS;
1554f461d2dcSChristoph Hellwig }
1555f461d2dcSChristoph Hellwig 
1556f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */
1557f461d2dcSChristoph Hellwig 
1558f461d2dcSChristoph Hellwig #if defined(CONFIG_SYSCTL)
1559f461d2dcSChristoph Hellwig int proc_do_static_key(struct ctl_table *table, int write,
156032927393SChristoph Hellwig 		       void *buffer, size_t *lenp, loff_t *ppos)
1561f461d2dcSChristoph Hellwig {
1562f461d2dcSChristoph Hellwig 	struct static_key *key = (struct static_key *)table->data;
1563f461d2dcSChristoph Hellwig 	static DEFINE_MUTEX(static_key_mutex);
1564f461d2dcSChristoph Hellwig 	int val, ret;
1565f461d2dcSChristoph Hellwig 	struct ctl_table tmp = {
1566f461d2dcSChristoph Hellwig 		.data   = &val,
1567f461d2dcSChristoph Hellwig 		.maxlen = sizeof(val),
1568f461d2dcSChristoph Hellwig 		.mode   = table->mode,
1569f461d2dcSChristoph Hellwig 		.extra1 = SYSCTL_ZERO,
1570f461d2dcSChristoph Hellwig 		.extra2 = SYSCTL_ONE,
1571f461d2dcSChristoph Hellwig 	};
1572f461d2dcSChristoph Hellwig 
1573f461d2dcSChristoph Hellwig 	if (write && !capable(CAP_SYS_ADMIN))
1574f461d2dcSChristoph Hellwig 		return -EPERM;
1575f461d2dcSChristoph Hellwig 
1576f461d2dcSChristoph Hellwig 	mutex_lock(&static_key_mutex);
1577f461d2dcSChristoph Hellwig 	val = static_key_enabled(key);
1578f461d2dcSChristoph Hellwig 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1579f461d2dcSChristoph Hellwig 	if (write && !ret) {
1580f461d2dcSChristoph Hellwig 		if (val)
1581f461d2dcSChristoph Hellwig 			static_key_enable(key);
1582f461d2dcSChristoph Hellwig 		else
1583f461d2dcSChristoph Hellwig 			static_key_disable(key);
1584f461d2dcSChristoph Hellwig 	}
1585f461d2dcSChristoph Hellwig 	mutex_unlock(&static_key_mutex);
1586f461d2dcSChristoph Hellwig 	return ret;
1587f461d2dcSChristoph Hellwig }
1588f461d2dcSChristoph Hellwig 
1589d8217f07SEric W. Biederman static struct ctl_table kern_table[] = {
1590b7cc6ec7SMel Gorman #ifdef CONFIG_NUMA_BALANCING
15913a7053b3SMel Gorman 	{
159254a43d54SAndi Kleen 		.procname	= "numa_balancing",
159354a43d54SAndi Kleen 		.data		= NULL, /* filled in by handler */
159454a43d54SAndi Kleen 		.maxlen		= sizeof(unsigned int),
159554a43d54SAndi Kleen 		.mode		= 0644,
159654a43d54SAndi Kleen 		.proc_handler	= sysctl_numa_balancing,
1597eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
1598c574bbe9SHuang Ying 		.extra2		= SYSCTL_FOUR,
159954a43d54SAndi Kleen 	},
1600cbee9f88SPeter Zijlstra #endif /* CONFIG_NUMA_BALANCING */
16011799e35dSIngo Molnar 	{
16021da177e4SLinus Torvalds 		.procname	= "panic",
16031da177e4SLinus Torvalds 		.data		= &panic_timeout,
16041da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
16051da177e4SLinus Torvalds 		.mode		= 0644,
16066d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
16071da177e4SLinus Torvalds 	},
160834f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL
16091da177e4SLinus Torvalds 	{
16101da177e4SLinus Torvalds 		.procname	= "tainted",
161125ddbb18SAndi Kleen 		.maxlen 	= sizeof(long),
161234f5a398STheodore Ts'o 		.mode		= 0644,
16136d456111SEric W. Biederman 		.proc_handler	= proc_taint,
16141da177e4SLinus Torvalds 	},
1615f4aacea2SKees Cook 	{
1616f4aacea2SKees Cook 		.procname	= "sysctl_writes_strict",
1617f4aacea2SKees Cook 		.data		= &sysctl_writes_strict,
1618f4aacea2SKees Cook 		.maxlen		= sizeof(int),
1619f4aacea2SKees Cook 		.mode		= 0644,
1620f4aacea2SKees Cook 		.proc_handler	= proc_dointvec_minmax,
162178e36f3bSXiaoming Ni 		.extra1		= SYSCTL_NEG_ONE,
1622eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
1623f4aacea2SKees Cook 	},
162434f5a398STheodore Ts'o #endif
162545807a1dSIngo Molnar 	{
162645807a1dSIngo Molnar 		.procname	= "print-fatal-signals",
162745807a1dSIngo Molnar 		.data		= &print_fatal_signals,
162845807a1dSIngo Molnar 		.maxlen		= sizeof(int),
162945807a1dSIngo Molnar 		.mode		= 0644,
16306d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
163145807a1dSIngo Molnar 	},
163272c57ed5SDavid S. Miller #ifdef CONFIG_SPARC
16331da177e4SLinus Torvalds 	{
16341da177e4SLinus Torvalds 		.procname	= "reboot-cmd",
16351da177e4SLinus Torvalds 		.data		= reboot_command,
16361da177e4SLinus Torvalds 		.maxlen		= 256,
16371da177e4SLinus Torvalds 		.mode		= 0644,
16386d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
16391da177e4SLinus Torvalds 	},
16401da177e4SLinus Torvalds 	{
16411da177e4SLinus Torvalds 		.procname	= "stop-a",
16421da177e4SLinus Torvalds 		.data		= &stop_a_enabled,
16431da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
16441da177e4SLinus Torvalds 		.mode		= 0644,
16456d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
16461da177e4SLinus Torvalds 	},
16471da177e4SLinus Torvalds 	{
16481da177e4SLinus Torvalds 		.procname	= "scons-poweroff",
16491da177e4SLinus Torvalds 		.data		= &scons_pwroff,
16501da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
16511da177e4SLinus Torvalds 		.mode		= 0644,
16526d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
16531da177e4SLinus Torvalds 	},
16541da177e4SLinus Torvalds #endif
16550871420fSDavid S. Miller #ifdef CONFIG_SPARC64
16560871420fSDavid S. Miller 	{
16570871420fSDavid S. Miller 		.procname	= "tsb-ratio",
16580871420fSDavid S. Miller 		.data		= &sysctl_tsb_ratio,
16590871420fSDavid S. Miller 		.maxlen		= sizeof (int),
16600871420fSDavid S. Miller 		.mode		= 0644,
16616d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
16620871420fSDavid S. Miller 	},
16630871420fSDavid S. Miller #endif
1664b67114dbSHelge Deller #ifdef CONFIG_PARISC
16651da177e4SLinus Torvalds 	{
16661da177e4SLinus Torvalds 		.procname	= "soft-power",
16671da177e4SLinus Torvalds 		.data		= &pwrsw_enabled,
16681da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
16691da177e4SLinus Torvalds 		.mode		= 0644,
16706d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
16711da177e4SLinus Torvalds 	},
1672bf14e3b9SVineet Gupta #endif
1673bf14e3b9SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
16741da177e4SLinus Torvalds 	{
16751da177e4SLinus Torvalds 		.procname	= "unaligned-trap",
16761da177e4SLinus Torvalds 		.data		= &unaligned_enabled,
16771da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
16781da177e4SLinus Torvalds 		.mode		= 0644,
16796d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
16801da177e4SLinus Torvalds 	},
16811da177e4SLinus Torvalds #endif
1682f38f1d2aSSteven Rostedt #ifdef CONFIG_STACK_TRACER
1683f38f1d2aSSteven Rostedt 	{
1684f38f1d2aSSteven Rostedt 		.procname	= "stack_tracer_enabled",
1685f38f1d2aSSteven Rostedt 		.data		= &stack_tracer_enabled,
1686f38f1d2aSSteven Rostedt 		.maxlen		= sizeof(int),
1687f38f1d2aSSteven Rostedt 		.mode		= 0644,
16886d456111SEric W. Biederman 		.proc_handler	= stack_trace_sysctl,
1689f38f1d2aSSteven Rostedt 	},
1690f38f1d2aSSteven Rostedt #endif
1691944ac425SSteven Rostedt #ifdef CONFIG_TRACING
1692944ac425SSteven Rostedt 	{
16933299b4ddSPeter Zijlstra 		.procname	= "ftrace_dump_on_oops",
1694944ac425SSteven Rostedt 		.data		= &ftrace_dump_on_oops,
1695944ac425SSteven Rostedt 		.maxlen		= sizeof(int),
1696944ac425SSteven Rostedt 		.mode		= 0644,
16976d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1698944ac425SSteven Rostedt 	},
1699de7edd31SSteven Rostedt (Red Hat) 	{
1700de7edd31SSteven Rostedt (Red Hat) 		.procname	= "traceoff_on_warning",
1701de7edd31SSteven Rostedt (Red Hat) 		.data		= &__disable_trace_on_warning,
1702de7edd31SSteven Rostedt (Red Hat) 		.maxlen		= sizeof(__disable_trace_on_warning),
1703de7edd31SSteven Rostedt (Red Hat) 		.mode		= 0644,
1704de7edd31SSteven Rostedt (Red Hat) 		.proc_handler	= proc_dointvec,
1705de7edd31SSteven Rostedt (Red Hat) 	},
17060daa2302SSteven Rostedt (Red Hat) 	{
17070daa2302SSteven Rostedt (Red Hat) 		.procname	= "tracepoint_printk",
17080daa2302SSteven Rostedt (Red Hat) 		.data		= &tracepoint_printk,
17090daa2302SSteven Rostedt (Red Hat) 		.maxlen		= sizeof(tracepoint_printk),
17100daa2302SSteven Rostedt (Red Hat) 		.mode		= 0644,
171142391745SSteven Rostedt (Red Hat) 		.proc_handler	= tracepoint_printk_sysctl,
17120daa2302SSteven Rostedt (Red Hat) 	},
1713944ac425SSteven Rostedt #endif
1714a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES
17151da177e4SLinus Torvalds 	{
17161da177e4SLinus Torvalds 		.procname	= "modprobe",
17171da177e4SLinus Torvalds 		.data		= &modprobe_path,
17181da177e4SLinus Torvalds 		.maxlen		= KMOD_PATH_LEN,
17191da177e4SLinus Torvalds 		.mode		= 0644,
17206d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
17211da177e4SLinus Torvalds 	},
17223d43321bSKees Cook 	{
17233d43321bSKees Cook 		.procname	= "modules_disabled",
17243d43321bSKees Cook 		.data		= &modules_disabled,
17253d43321bSKees Cook 		.maxlen		= sizeof(int),
17263d43321bSKees Cook 		.mode		= 0644,
17273d43321bSKees Cook 		/* only handle a transition from default "0" to "1" */
17286d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
1729eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
1730eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
17313d43321bSKees Cook 	},
17321da177e4SLinus Torvalds #endif
173386d56134SMichael Marineau #ifdef CONFIG_UEVENT_HELPER
17341da177e4SLinus Torvalds 	{
17351da177e4SLinus Torvalds 		.procname	= "hotplug",
1736312c004dSKay Sievers 		.data		= &uevent_helper,
1737312c004dSKay Sievers 		.maxlen		= UEVENT_HELPER_PATH_LEN,
17381da177e4SLinus Torvalds 		.mode		= 0644,
17396d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
17401da177e4SLinus Torvalds 	},
174186d56134SMichael Marineau #endif
17421da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ
17431da177e4SLinus Torvalds 	{
17441da177e4SLinus Torvalds 		.procname	= "sysrq",
1745eaee4172SDmitry Safonov 		.data		= NULL,
17461da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
17471da177e4SLinus Torvalds 		.mode		= 0644,
174897f5f0cdSDmitry Torokhov 		.proc_handler	= sysrq_sysctl_handler,
17491da177e4SLinus Torvalds 	},
17501da177e4SLinus Torvalds #endif
1751d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
17521da177e4SLinus Torvalds 	{
17531da177e4SLinus Torvalds 		.procname	= "cad_pid",
17549ec52099SCedric Le Goater 		.data		= NULL,
17551da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
17561da177e4SLinus Torvalds 		.mode		= 0600,
17576d456111SEric W. Biederman 		.proc_handler	= proc_do_cad_pid,
17581da177e4SLinus Torvalds 	},
1759d6f8ff73SRandy Dunlap #endif
17601da177e4SLinus Torvalds 	{
17611da177e4SLinus Torvalds 		.procname	= "threads-max",
176216db3d3fSHeinrich Schuchardt 		.data		= NULL,
17631da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
17641da177e4SLinus Torvalds 		.mode		= 0644,
176516db3d3fSHeinrich Schuchardt 		.proc_handler	= sysctl_max_threads,
17661da177e4SLinus Torvalds 	},
17671da177e4SLinus Torvalds 	{
176817f60a7dSEric Paris 		.procname	= "usermodehelper",
176917f60a7dSEric Paris 		.mode		= 0555,
177017f60a7dSEric Paris 		.child		= usermodehelper_table,
177117f60a7dSEric Paris 	},
177217f60a7dSEric Paris 	{
17731da177e4SLinus Torvalds 		.procname	= "overflowuid",
17741da177e4SLinus Torvalds 		.data		= &overflowuid,
17751da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
17761da177e4SLinus Torvalds 		.mode		= 0644,
17776d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
17782452dcb9SXiaoming Ni 		.extra1		= SYSCTL_ZERO,
177954771613SLuis Chamberlain 		.extra2		= SYSCTL_MAXOLDUID,
17801da177e4SLinus Torvalds 	},
17811da177e4SLinus Torvalds 	{
17821da177e4SLinus Torvalds 		.procname	= "overflowgid",
17831da177e4SLinus Torvalds 		.data		= &overflowgid,
17841da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
17851da177e4SLinus Torvalds 		.mode		= 0644,
17866d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
17872452dcb9SXiaoming Ni 		.extra1		= SYSCTL_ZERO,
178854771613SLuis Chamberlain 		.extra2		= SYSCTL_MAXOLDUID,
17891da177e4SLinus Torvalds 	},
1790347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
17911da177e4SLinus Torvalds 	{
17921da177e4SLinus Torvalds 		.procname	= "userprocess_debug",
1793ab3c68eeSHeiko Carstens 		.data		= &show_unhandled_signals,
17941da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
17951da177e4SLinus Torvalds 		.mode		= 0644,
17966d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
17971da177e4SLinus Torvalds 	},
17981da177e4SLinus Torvalds #endif
17991da177e4SLinus Torvalds 	{
18001da177e4SLinus Torvalds 		.procname	= "pid_max",
18011da177e4SLinus Torvalds 		.data		= &pid_max,
18021da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
18031da177e4SLinus Torvalds 		.mode		= 0644,
18046d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
18051da177e4SLinus Torvalds 		.extra1		= &pid_max_min,
18061da177e4SLinus Torvalds 		.extra2		= &pid_max_max,
18071da177e4SLinus Torvalds 	},
18081da177e4SLinus Torvalds 	{
18091da177e4SLinus Torvalds 		.procname	= "panic_on_oops",
18101da177e4SLinus Torvalds 		.data		= &panic_on_oops,
18111da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
18121da177e4SLinus Torvalds 		.mode		= 0644,
18136d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18141da177e4SLinus Torvalds 	},
181581c9d43fSFeng Tang 	{
181681c9d43fSFeng Tang 		.procname	= "panic_print",
181781c9d43fSFeng Tang 		.data		= &panic_print,
181881c9d43fSFeng Tang 		.maxlen		= sizeof(unsigned long),
181981c9d43fSFeng Tang 		.mode		= 0644,
182081c9d43fSFeng Tang 		.proc_handler	= proc_doulongvec_minmax,
182181c9d43fSFeng Tang 	},
1822eaf06b24SDan Rosenberg 	{
18231da177e4SLinus Torvalds 		.procname	= "ngroups_max",
1824f628867dSStephen Kitt 		.data		= (void *)&ngroups_max,
18251da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
18261da177e4SLinus Torvalds 		.mode		= 0444,
18276d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18281da177e4SLinus Torvalds 	},
182973efc039SDan Ballard 	{
183073efc039SDan Ballard 		.procname	= "cap_last_cap",
183173efc039SDan Ballard 		.data		= (void *)&cap_last_cap,
183273efc039SDan Ballard 		.maxlen		= sizeof(int),
183373efc039SDan Ballard 		.mode		= 0444,
183473efc039SDan Ballard 		.proc_handler	= proc_dointvec,
183573efc039SDan Ballard 	},
18365dc30558SDon Zickus #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
18375dc30558SDon Zickus 	{
18385dc30558SDon Zickus 		.procname       = "unknown_nmi_panic",
18395dc30558SDon Zickus 		.data           = &unknown_nmi_panic,
18405dc30558SDon Zickus 		.maxlen         = sizeof (int),
18415dc30558SDon Zickus 		.mode           = 0644,
18425dc30558SDon Zickus 		.proc_handler   = proc_dointvec,
18435dc30558SDon Zickus 	},
1844504d7cf1SDon Zickus #endif
1845b6522fa4SXiaoming Ni 
1846b6522fa4SXiaoming Ni #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
1847b6522fa4SXiaoming Ni 	defined(CONFIG_DEBUG_STACKOVERFLOW)
1848b6522fa4SXiaoming Ni 	{
1849b6522fa4SXiaoming Ni 		.procname	= "panic_on_stackoverflow",
1850b6522fa4SXiaoming Ni 		.data		= &sysctl_panic_on_stackoverflow,
1851b6522fa4SXiaoming Ni 		.maxlen		= sizeof(int),
1852b6522fa4SXiaoming Ni 		.mode		= 0644,
1853b6522fa4SXiaoming Ni 		.proc_handler	= proc_dointvec,
1854b6522fa4SXiaoming Ni 	},
1855b6522fa4SXiaoming Ni #endif
18561da177e4SLinus Torvalds #if defined(CONFIG_X86)
18571da177e4SLinus Torvalds 	{
18588da5addaSDon Zickus 		.procname	= "panic_on_unrecovered_nmi",
18598da5addaSDon Zickus 		.data		= &panic_on_unrecovered_nmi,
18608da5addaSDon Zickus 		.maxlen		= sizeof(int),
18618da5addaSDon Zickus 		.mode		= 0644,
18626d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18638da5addaSDon Zickus 	},
18648da5addaSDon Zickus 	{
18655211a242SKurt Garloff 		.procname	= "panic_on_io_nmi",
18665211a242SKurt Garloff 		.data		= &panic_on_io_nmi,
18675211a242SKurt Garloff 		.maxlen		= sizeof(int),
18685211a242SKurt Garloff 		.mode		= 0644,
18696d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18705211a242SKurt Garloff 	},
18715211a242SKurt Garloff 	{
18721da177e4SLinus Torvalds 		.procname	= "bootloader_type",
18731da177e4SLinus Torvalds 		.data		= &bootloader_type,
18741da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
18751da177e4SLinus Torvalds 		.mode		= 0444,
18766d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18771da177e4SLinus Torvalds 	},
18780741f4d2SChuck Ebbert 	{
18795031296cSH. Peter Anvin 		.procname	= "bootloader_version",
18805031296cSH. Peter Anvin 		.data		= &bootloader_version,
18815031296cSH. Peter Anvin 		.maxlen		= sizeof (int),
18825031296cSH. Peter Anvin 		.mode		= 0444,
18836d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18845031296cSH. Peter Anvin 	},
18855031296cSH. Peter Anvin 	{
18866e7c4025SIngo Molnar 		.procname	= "io_delay_type",
18876e7c4025SIngo Molnar 		.data		= &io_delay_type,
18886e7c4025SIngo Molnar 		.maxlen		= sizeof(int),
18896e7c4025SIngo Molnar 		.mode		= 0644,
18906d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18916e7c4025SIngo Molnar 	},
18921da177e4SLinus Torvalds #endif
18937a9166e3SLuke Yang #if defined(CONFIG_MMU)
18941da177e4SLinus Torvalds 	{
18951da177e4SLinus Torvalds 		.procname	= "randomize_va_space",
18961da177e4SLinus Torvalds 		.data		= &randomize_va_space,
18971da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
18981da177e4SLinus Torvalds 		.mode		= 0644,
18996d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19001da177e4SLinus Torvalds 	},
19017a9166e3SLuke Yang #endif
19020152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1903951f22d5SMartin Schwidefsky 	{
1904951f22d5SMartin Schwidefsky 		.procname	= "spin_retry",
1905951f22d5SMartin Schwidefsky 		.data		= &spin_retry,
1906951f22d5SMartin Schwidefsky 		.maxlen		= sizeof (int),
1907951f22d5SMartin Schwidefsky 		.mode		= 0644,
19086d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1909951f22d5SMartin Schwidefsky 	},
1910951f22d5SMartin Schwidefsky #endif
1911673d5b43SLen Brown #if	defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1912c255d844SPavel Machek 	{
1913c255d844SPavel Machek 		.procname	= "acpi_video_flags",
191477afcf78SPavel Machek 		.data		= &acpi_realmode_flags,
1915c255d844SPavel Machek 		.maxlen		= sizeof (unsigned long),
1916c255d844SPavel Machek 		.mode		= 0644,
19176d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
1918c255d844SPavel Machek 	},
1919c255d844SPavel Machek #endif
1920b6fca725SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1921d2b176edSJes Sorensen 	{
1922d2b176edSJes Sorensen 		.procname	= "ignore-unaligned-usertrap",
1923d2b176edSJes Sorensen 		.data		= &no_unaligned_warning,
1924d2b176edSJes Sorensen 		.maxlen		= sizeof (int),
1925d2b176edSJes Sorensen 		.mode		= 0644,
19266d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1927d2b176edSJes Sorensen 	},
1928b6fca725SVineet Gupta #endif
1929b6fca725SVineet Gupta #ifdef CONFIG_IA64
193088fc241fSDoug Chapman 	{
193188fc241fSDoug Chapman 		.procname	= "unaligned-dump-stack",
193288fc241fSDoug Chapman 		.data		= &unaligned_dump_stack,
193388fc241fSDoug Chapman 		.maxlen		= sizeof (int),
193488fc241fSDoug Chapman 		.mode		= 0644,
19356d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
193688fc241fSDoug Chapman 	},
1937d2b176edSJes Sorensen #endif
193823f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
193923f78d4aSIngo Molnar 	{
194023f78d4aSIngo Molnar 		.procname	= "max_lock_depth",
194123f78d4aSIngo Molnar 		.data		= &max_lock_depth,
194223f78d4aSIngo Molnar 		.maxlen		= sizeof(int),
194323f78d4aSIngo Molnar 		.mode		= 0644,
19446d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
194523f78d4aSIngo Molnar 	},
194623f78d4aSIngo Molnar #endif
19470b77f5bfSDavid Howells #ifdef CONFIG_KEYS
19480b77f5bfSDavid Howells 	{
19490b77f5bfSDavid Howells 		.procname	= "keys",
19500b77f5bfSDavid Howells 		.mode		= 0555,
19510b77f5bfSDavid Howells 		.child		= key_sysctls,
19520b77f5bfSDavid Howells 	},
19530b77f5bfSDavid Howells #endif
1954cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS
1955aa4a2218SVince Weaver 	/*
1956aa4a2218SVince Weaver 	 * User-space scripts rely on the existence of this file
1957aa4a2218SVince Weaver 	 * as a feature check for perf_events being enabled.
1958aa4a2218SVince Weaver 	 *
1959aa4a2218SVince Weaver 	 * So it's an ABI, do not remove!
1960aa4a2218SVince Weaver 	 */
19611ccd1549SPeter Zijlstra 	{
1962cdd6c482SIngo Molnar 		.procname	= "perf_event_paranoid",
1963cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_paranoid,
1964cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_paranoid),
19651ccd1549SPeter Zijlstra 		.mode		= 0644,
19666d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19671ccd1549SPeter Zijlstra 	},
1968c5078f78SPeter Zijlstra 	{
1969cdd6c482SIngo Molnar 		.procname	= "perf_event_mlock_kb",
1970cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_mlock,
1971cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_mlock),
1972c5078f78SPeter Zijlstra 		.mode		= 0644,
19736d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1974c5078f78SPeter Zijlstra 	},
1975a78ac325SPeter Zijlstra 	{
1976cdd6c482SIngo Molnar 		.procname	= "perf_event_max_sample_rate",
1977cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_sample_rate,
1978cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_sample_rate),
1979a78ac325SPeter Zijlstra 		.mode		= 0644,
1980163ec435SPeter Zijlstra 		.proc_handler	= perf_proc_update_handler,
1981eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
1982a78ac325SPeter Zijlstra 	},
198314c63f17SDave Hansen 	{
198414c63f17SDave Hansen 		.procname	= "perf_cpu_time_max_percent",
198514c63f17SDave Hansen 		.data		= &sysctl_perf_cpu_time_max_percent,
198614c63f17SDave Hansen 		.maxlen		= sizeof(sysctl_perf_cpu_time_max_percent),
198714c63f17SDave Hansen 		.mode		= 0644,
198814c63f17SDave Hansen 		.proc_handler	= perf_cpu_time_max_percent_handler,
1989eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
199078e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_HUNDRED,
199114c63f17SDave Hansen 	},
1992c5dfd78eSArnaldo Carvalho de Melo 	{
1993c5dfd78eSArnaldo Carvalho de Melo 		.procname	= "perf_event_max_stack",
1994a831100aSArnaldo Carvalho de Melo 		.data		= &sysctl_perf_event_max_stack,
1995c5dfd78eSArnaldo Carvalho de Melo 		.maxlen		= sizeof(sysctl_perf_event_max_stack),
1996c5dfd78eSArnaldo Carvalho de Melo 		.mode		= 0644,
1997c5dfd78eSArnaldo Carvalho de Melo 		.proc_handler	= perf_event_max_stack_handler,
1998eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
1999d73840ecSXiaoming Ni 		.extra2		= (void *)&six_hundred_forty_kb,
2000c5dfd78eSArnaldo Carvalho de Melo 	},
2001c85b0334SArnaldo Carvalho de Melo 	{
2002c85b0334SArnaldo Carvalho de Melo 		.procname	= "perf_event_max_contexts_per_stack",
2003c85b0334SArnaldo Carvalho de Melo 		.data		= &sysctl_perf_event_max_contexts_per_stack,
2004c85b0334SArnaldo Carvalho de Melo 		.maxlen		= sizeof(sysctl_perf_event_max_contexts_per_stack),
2005c85b0334SArnaldo Carvalho de Melo 		.mode		= 0644,
2006c85b0334SArnaldo Carvalho de Melo 		.proc_handler	= perf_event_max_stack_handler,
2007eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
200878e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_THOUSAND,
2009c85b0334SArnaldo Carvalho de Melo 	},
20101ccd1549SPeter Zijlstra #endif
20119e3961a0SPrarit Bhargava 	{
20129e3961a0SPrarit Bhargava 		.procname	= "panic_on_warn",
20139e3961a0SPrarit Bhargava 		.data		= &panic_on_warn,
20149e3961a0SPrarit Bhargava 		.maxlen		= sizeof(int),
20159e3961a0SPrarit Bhargava 		.mode		= 0644,
20169e3961a0SPrarit Bhargava 		.proc_handler	= proc_dointvec_minmax,
2017eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2018eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
20199e3961a0SPrarit Bhargava 	},
2020b3e627d3SLai Jiangshan #if defined(CONFIG_TREE_RCU)
2021088e9d25SDaniel Bristot de Oliveira 	{
2022088e9d25SDaniel Bristot de Oliveira 		.procname	= "panic_on_rcu_stall",
2023088e9d25SDaniel Bristot de Oliveira 		.data		= &sysctl_panic_on_rcu_stall,
2024088e9d25SDaniel Bristot de Oliveira 		.maxlen		= sizeof(sysctl_panic_on_rcu_stall),
2025088e9d25SDaniel Bristot de Oliveira 		.mode		= 0644,
2026088e9d25SDaniel Bristot de Oliveira 		.proc_handler	= proc_dointvec_minmax,
2027eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2028eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2029088e9d25SDaniel Bristot de Oliveira 	},
2030088e9d25SDaniel Bristot de Oliveira #endif
2031dfe56404Schao #if defined(CONFIG_TREE_RCU)
2032dfe56404Schao 	{
2033dfe56404Schao 		.procname	= "max_rcu_stall_to_panic",
2034dfe56404Schao 		.data		= &sysctl_max_rcu_stall_to_panic,
2035dfe56404Schao 		.maxlen		= sizeof(sysctl_max_rcu_stall_to_panic),
2036dfe56404Schao 		.mode		= 0644,
2037dfe56404Schao 		.proc_handler	= proc_dointvec_minmax,
2038dfe56404Schao 		.extra1		= SYSCTL_ONE,
2039dfe56404Schao 		.extra2		= SYSCTL_INT_MAX,
2040dfe56404Schao 	},
2041dfe56404Schao #endif
20426fce56ecSEric W. Biederman 	{ }
20431da177e4SLinus Torvalds };
20441da177e4SLinus Torvalds 
2045d8217f07SEric W. Biederman static struct ctl_table vm_table[] = {
20461da177e4SLinus Torvalds 	{
20471da177e4SLinus Torvalds 		.procname	= "overcommit_memory",
20481da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_memory,
20491da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_memory),
20501da177e4SLinus Torvalds 		.mode		= 0644,
205156f3547bSFeng Tang 		.proc_handler	= overcommit_policy_handler,
2052eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
205378e36f3bSXiaoming Ni 		.extra2		= SYSCTL_TWO,
20541da177e4SLinus Torvalds 	},
20551da177e4SLinus Torvalds 	{
20561da177e4SLinus Torvalds 		.procname	= "overcommit_ratio",
20571da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_ratio,
20581da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_ratio),
20591da177e4SLinus Torvalds 		.mode		= 0644,
206049f0ce5fSJerome Marchand 		.proc_handler	= overcommit_ratio_handler,
206149f0ce5fSJerome Marchand 	},
206249f0ce5fSJerome Marchand 	{
206349f0ce5fSJerome Marchand 		.procname	= "overcommit_kbytes",
206449f0ce5fSJerome Marchand 		.data		= &sysctl_overcommit_kbytes,
206549f0ce5fSJerome Marchand 		.maxlen		= sizeof(sysctl_overcommit_kbytes),
206649f0ce5fSJerome Marchand 		.mode		= 0644,
206749f0ce5fSJerome Marchand 		.proc_handler	= overcommit_kbytes_handler,
20681da177e4SLinus Torvalds 	},
20691da177e4SLinus Torvalds 	{
20701da177e4SLinus Torvalds 		.procname	= "page-cluster",
20711da177e4SLinus Torvalds 		.data		= &page_cluster,
20721da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
20731da177e4SLinus Torvalds 		.mode		= 0644,
2074cb16e95fSPetr Holasek 		.proc_handler	= proc_dointvec_minmax,
2075eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
20761da177e4SLinus Torvalds 	},
20771da177e4SLinus Torvalds 	{
20781efff914STheodore Ts'o 		.procname	= "dirtytime_expire_seconds",
20791efff914STheodore Ts'o 		.data		= &dirtytime_expire_interval,
20802d87b309SRandy Dunlap 		.maxlen		= sizeof(dirtytime_expire_interval),
20811efff914STheodore Ts'o 		.mode		= 0644,
20821efff914STheodore Ts'o 		.proc_handler	= dirtytime_interval_handler,
2083eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
20841efff914STheodore Ts'o 	},
20851efff914STheodore Ts'o 	{
20861da177e4SLinus Torvalds 		.procname	= "swappiness",
20871da177e4SLinus Torvalds 		.data		= &vm_swappiness,
20881da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_swappiness),
20891da177e4SLinus Torvalds 		.mode		= 0644,
20906d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2091eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
209278e36f3bSXiaoming Ni 		.extra2		= SYSCTL_TWO_HUNDRED,
20931da177e4SLinus Torvalds 	},
20941da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE
20951da177e4SLinus Torvalds 	{
20961da177e4SLinus Torvalds 		.procname	= "nr_hugepages",
2097e5ff2159SAndi Kleen 		.data		= NULL,
20981da177e4SLinus Torvalds 		.maxlen		= sizeof(unsigned long),
20991da177e4SLinus Torvalds 		.mode		= 0644,
21006d456111SEric W. Biederman 		.proc_handler	= hugetlb_sysctl_handler,
21011da177e4SLinus Torvalds 	},
210206808b08SLee Schermerhorn #ifdef CONFIG_NUMA
210306808b08SLee Schermerhorn 	{
210406808b08SLee Schermerhorn 		.procname       = "nr_hugepages_mempolicy",
210506808b08SLee Schermerhorn 		.data           = NULL,
210606808b08SLee Schermerhorn 		.maxlen         = sizeof(unsigned long),
210706808b08SLee Schermerhorn 		.mode           = 0644,
210806808b08SLee Schermerhorn 		.proc_handler   = &hugetlb_mempolicy_sysctl_handler,
210906808b08SLee Schermerhorn 	},
21104518085eSKemi Wang 	{
21114518085eSKemi Wang 		.procname		= "numa_stat",
21124518085eSKemi Wang 		.data			= &sysctl_vm_numa_stat,
21134518085eSKemi Wang 		.maxlen			= sizeof(int),
21144518085eSKemi Wang 		.mode			= 0644,
21154518085eSKemi Wang 		.proc_handler	= sysctl_vm_numa_stat_handler,
2116eec4844fSMatteo Croce 		.extra1			= SYSCTL_ZERO,
2117eec4844fSMatteo Croce 		.extra2			= SYSCTL_ONE,
21184518085eSKemi Wang 	},
211906808b08SLee Schermerhorn #endif
21201da177e4SLinus Torvalds 	 {
21211da177e4SLinus Torvalds 		.procname	= "hugetlb_shm_group",
21221da177e4SLinus Torvalds 		.data		= &sysctl_hugetlb_shm_group,
21231da177e4SLinus Torvalds 		.maxlen		= sizeof(gid_t),
21241da177e4SLinus Torvalds 		.mode		= 0644,
21256d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
21261da177e4SLinus Torvalds 	 },
2127396faf03SMel Gorman 	{
2128d1c3fb1fSNishanth Aravamudan 		.procname	= "nr_overcommit_hugepages",
2129e5ff2159SAndi Kleen 		.data		= NULL,
2130e5ff2159SAndi Kleen 		.maxlen		= sizeof(unsigned long),
2131d1c3fb1fSNishanth Aravamudan 		.mode		= 0644,
21326d456111SEric W. Biederman 		.proc_handler	= hugetlb_overcommit_handler,
2133d1c3fb1fSNishanth Aravamudan 	},
21341da177e4SLinus Torvalds #endif
21351da177e4SLinus Torvalds 	{
21361da177e4SLinus Torvalds 		.procname	= "lowmem_reserve_ratio",
21371da177e4SLinus Torvalds 		.data		= &sysctl_lowmem_reserve_ratio,
21381da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
21391da177e4SLinus Torvalds 		.mode		= 0644,
21406d456111SEric W. Biederman 		.proc_handler	= lowmem_reserve_ratio_sysctl_handler,
21411da177e4SLinus Torvalds 	},
21421da177e4SLinus Torvalds 	{
21439d0243bcSAndrew Morton 		.procname	= "drop_caches",
21449d0243bcSAndrew Morton 		.data		= &sysctl_drop_caches,
21459d0243bcSAndrew Morton 		.maxlen		= sizeof(int),
2146204cb79aSJohannes Weiner 		.mode		= 0200,
21479d0243bcSAndrew Morton 		.proc_handler	= drop_caches_sysctl_handler,
2148eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
214978e36f3bSXiaoming Ni 		.extra2		= SYSCTL_FOUR,
21509d0243bcSAndrew Morton 	},
215176ab0f53SMel Gorman #ifdef CONFIG_COMPACTION
215276ab0f53SMel Gorman 	{
215376ab0f53SMel Gorman 		.procname	= "compact_memory",
2154ef498438SPintu Kumar 		.data		= NULL,
215576ab0f53SMel Gorman 		.maxlen		= sizeof(int),
215676ab0f53SMel Gorman 		.mode		= 0200,
215776ab0f53SMel Gorman 		.proc_handler	= sysctl_compaction_handler,
215876ab0f53SMel Gorman 	},
21595e771905SMel Gorman 	{
2160facdaa91SNitin Gupta 		.procname	= "compaction_proactiveness",
2161facdaa91SNitin Gupta 		.data		= &sysctl_compaction_proactiveness,
2162d34c0a75SNitin Gupta 		.maxlen		= sizeof(sysctl_compaction_proactiveness),
2163facdaa91SNitin Gupta 		.mode		= 0644,
216465d759c8SCharan Teja Reddy 		.proc_handler	= compaction_proactiveness_sysctl_handler,
2165facdaa91SNitin Gupta 		.extra1		= SYSCTL_ZERO,
216678e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_HUNDRED,
2167facdaa91SNitin Gupta 	},
2168facdaa91SNitin Gupta 	{
21695e771905SMel Gorman 		.procname	= "extfrag_threshold",
21705e771905SMel Gorman 		.data		= &sysctl_extfrag_threshold,
21715e771905SMel Gorman 		.maxlen		= sizeof(int),
21725e771905SMel Gorman 		.mode		= 0644,
21736b7e5cadSMatthew Wilcox 		.proc_handler	= proc_dointvec_minmax,
21742452dcb9SXiaoming Ni 		.extra1		= SYSCTL_ZERO,
2175d73840ecSXiaoming Ni 		.extra2		= (void *)&max_extfrag_threshold,
21765e771905SMel Gorman 	},
21775bbe3547SEric B Munson 	{
21785bbe3547SEric B Munson 		.procname	= "compact_unevictable_allowed",
21795bbe3547SEric B Munson 		.data		= &sysctl_compact_unevictable_allowed,
21805bbe3547SEric B Munson 		.maxlen		= sizeof(int),
21815bbe3547SEric B Munson 		.mode		= 0644,
21826923aa0dSSebastian Andrzej Siewior 		.proc_handler	= proc_dointvec_minmax_warn_RT_change,
2183eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2184eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
21855bbe3547SEric B Munson 	},
21865e771905SMel Gorman 
218776ab0f53SMel Gorman #endif /* CONFIG_COMPACTION */
21889d0243bcSAndrew Morton 	{
21891da177e4SLinus Torvalds 		.procname	= "min_free_kbytes",
21901da177e4SLinus Torvalds 		.data		= &min_free_kbytes,
21911da177e4SLinus Torvalds 		.maxlen		= sizeof(min_free_kbytes),
21921da177e4SLinus Torvalds 		.mode		= 0644,
21936d456111SEric W. Biederman 		.proc_handler	= min_free_kbytes_sysctl_handler,
2194eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
21951da177e4SLinus Torvalds 	},
21968ad4b1fbSRohit Seth 	{
21971c30844dSMel Gorman 		.procname	= "watermark_boost_factor",
21981c30844dSMel Gorman 		.data		= &watermark_boost_factor,
21991c30844dSMel Gorman 		.maxlen		= sizeof(watermark_boost_factor),
22001c30844dSMel Gorman 		.mode		= 0644,
220126363af5SChristoph Hellwig 		.proc_handler	= proc_dointvec_minmax,
2202eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
22031c30844dSMel Gorman 	},
22041c30844dSMel Gorman 	{
2205795ae7a0SJohannes Weiner 		.procname	= "watermark_scale_factor",
2206795ae7a0SJohannes Weiner 		.data		= &watermark_scale_factor,
2207795ae7a0SJohannes Weiner 		.maxlen		= sizeof(watermark_scale_factor),
2208795ae7a0SJohannes Weiner 		.mode		= 0644,
2209795ae7a0SJohannes Weiner 		.proc_handler	= watermark_scale_factor_sysctl_handler,
2210eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
221178e36f3bSXiaoming Ni 		.extra2		= SYSCTL_THREE_THOUSAND,
2212795ae7a0SJohannes Weiner 	},
2213795ae7a0SJohannes Weiner 	{
221474f44822SMel Gorman 		.procname	= "percpu_pagelist_high_fraction",
221574f44822SMel Gorman 		.data		= &percpu_pagelist_high_fraction,
221674f44822SMel Gorman 		.maxlen		= sizeof(percpu_pagelist_high_fraction),
22178ad4b1fbSRohit Seth 		.mode		= 0644,
221874f44822SMel Gorman 		.proc_handler	= percpu_pagelist_high_fraction_sysctl_handler,
2219eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
22208ad4b1fbSRohit Seth 	},
22215ef64cc8SLinus Torvalds 	{
22225ef64cc8SLinus Torvalds 		.procname	= "page_lock_unfairness",
22235ef64cc8SLinus Torvalds 		.data		= &sysctl_page_lock_unfairness,
22245ef64cc8SLinus Torvalds 		.maxlen		= sizeof(sysctl_page_lock_unfairness),
22255ef64cc8SLinus Torvalds 		.mode		= 0644,
22265ef64cc8SLinus Torvalds 		.proc_handler	= proc_dointvec_minmax,
22275ef64cc8SLinus Torvalds 		.extra1		= SYSCTL_ZERO,
22285ef64cc8SLinus Torvalds 	},
22291da177e4SLinus Torvalds #ifdef CONFIG_MMU
22301da177e4SLinus Torvalds 	{
22311da177e4SLinus Torvalds 		.procname	= "max_map_count",
22321da177e4SLinus Torvalds 		.data		= &sysctl_max_map_count,
22331da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_max_map_count),
22341da177e4SLinus Torvalds 		.mode		= 0644,
22353e26120cSWANG Cong 		.proc_handler	= proc_dointvec_minmax,
2236eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
22371da177e4SLinus Torvalds 	},
2238dd8632a1SPaul Mundt #else
2239dd8632a1SPaul Mundt 	{
2240dd8632a1SPaul Mundt 		.procname	= "nr_trim_pages",
2241dd8632a1SPaul Mundt 		.data		= &sysctl_nr_trim_pages,
2242dd8632a1SPaul Mundt 		.maxlen		= sizeof(sysctl_nr_trim_pages),
2243dd8632a1SPaul Mundt 		.mode		= 0644,
22446d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2245eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2246dd8632a1SPaul Mundt 	},
22471da177e4SLinus Torvalds #endif
22481da177e4SLinus Torvalds 	{
22491da177e4SLinus Torvalds 		.procname	= "vfs_cache_pressure",
22501da177e4SLinus Torvalds 		.data		= &sysctl_vfs_cache_pressure,
22511da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
22521da177e4SLinus Torvalds 		.mode		= 0644,
22533b3376f2SLin Feng 		.proc_handler	= proc_dointvec_minmax,
2254eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
22551da177e4SLinus Torvalds 	},
225667f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
225767f3977fSAlexandre Ghiti     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
22581da177e4SLinus Torvalds 	{
22591da177e4SLinus Torvalds 		.procname	= "legacy_va_layout",
22601da177e4SLinus Torvalds 		.data		= &sysctl_legacy_va_layout,
22611da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_legacy_va_layout),
22621da177e4SLinus Torvalds 		.mode		= 0644,
22633b3376f2SLin Feng 		.proc_handler	= proc_dointvec_minmax,
2264eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
22651da177e4SLinus Torvalds 	},
22661da177e4SLinus Torvalds #endif
22671743660bSChristoph Lameter #ifdef CONFIG_NUMA
22681743660bSChristoph Lameter 	{
22691743660bSChristoph Lameter 		.procname	= "zone_reclaim_mode",
2270a5f5f91dSMel Gorman 		.data		= &node_reclaim_mode,
2271a5f5f91dSMel Gorman 		.maxlen		= sizeof(node_reclaim_mode),
22721743660bSChristoph Lameter 		.mode		= 0644,
22733b3376f2SLin Feng 		.proc_handler	= proc_dointvec_minmax,
2274eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
22751743660bSChristoph Lameter 	},
22769614634fSChristoph Lameter 	{
22779614634fSChristoph Lameter 		.procname	= "min_unmapped_ratio",
22789614634fSChristoph Lameter 		.data		= &sysctl_min_unmapped_ratio,
22799614634fSChristoph Lameter 		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
22809614634fSChristoph Lameter 		.mode		= 0644,
22816d456111SEric W. Biederman 		.proc_handler	= sysctl_min_unmapped_ratio_sysctl_handler,
2282eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
228378e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_HUNDRED,
22849614634fSChristoph Lameter 	},
22850ff38490SChristoph Lameter 	{
22860ff38490SChristoph Lameter 		.procname	= "min_slab_ratio",
22870ff38490SChristoph Lameter 		.data		= &sysctl_min_slab_ratio,
22880ff38490SChristoph Lameter 		.maxlen		= sizeof(sysctl_min_slab_ratio),
22890ff38490SChristoph Lameter 		.mode		= 0644,
22906d456111SEric W. Biederman 		.proc_handler	= sysctl_min_slab_ratio_sysctl_handler,
2291eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
229278e36f3bSXiaoming Ni 		.extra2		= SYSCTL_ONE_HUNDRED,
22930ff38490SChristoph Lameter 	},
22941743660bSChristoph Lameter #endif
229577461ab3SChristoph Lameter #ifdef CONFIG_SMP
229677461ab3SChristoph Lameter 	{
229777461ab3SChristoph Lameter 		.procname	= "stat_interval",
229877461ab3SChristoph Lameter 		.data		= &sysctl_stat_interval,
229977461ab3SChristoph Lameter 		.maxlen		= sizeof(sysctl_stat_interval),
230077461ab3SChristoph Lameter 		.mode		= 0644,
23016d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_jiffies,
230277461ab3SChristoph Lameter 	},
230352b6f46bSHugh Dickins 	{
230452b6f46bSHugh Dickins 		.procname	= "stat_refresh",
230552b6f46bSHugh Dickins 		.data		= NULL,
230652b6f46bSHugh Dickins 		.maxlen		= 0,
230752b6f46bSHugh Dickins 		.mode		= 0600,
230852b6f46bSHugh Dickins 		.proc_handler	= vmstat_refresh,
230952b6f46bSHugh Dickins 	},
231077461ab3SChristoph Lameter #endif
23116e141546SDavid Howells #ifdef CONFIG_MMU
2312ed032189SEric Paris 	{
2313ed032189SEric Paris 		.procname	= "mmap_min_addr",
2314788084abSEric Paris 		.data		= &dac_mmap_min_addr,
2315ed032189SEric Paris 		.maxlen		= sizeof(unsigned long),
2316ed032189SEric Paris 		.mode		= 0644,
23176d456111SEric W. Biederman 		.proc_handler	= mmap_min_addr_handler,
2318ed032189SEric Paris 	},
23196e141546SDavid Howells #endif
2320f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA
2321f0c0b2b8SKAMEZAWA Hiroyuki 	{
2322f0c0b2b8SKAMEZAWA Hiroyuki 		.procname	= "numa_zonelist_order",
2323f0c0b2b8SKAMEZAWA Hiroyuki 		.data		= &numa_zonelist_order,
2324f0c0b2b8SKAMEZAWA Hiroyuki 		.maxlen		= NUMA_ZONELIST_ORDER_LEN,
2325f0c0b2b8SKAMEZAWA Hiroyuki 		.mode		= 0644,
23266d456111SEric W. Biederman 		.proc_handler	= numa_zonelist_order_handler,
2327f0c0b2b8SKAMEZAWA Hiroyuki 	},
2328f0c0b2b8SKAMEZAWA Hiroyuki #endif
23292b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
23305c36e657SPaul Mundt    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
2331e6e5494cSIngo Molnar 	{
2332e6e5494cSIngo Molnar 		.procname	= "vdso_enabled",
23333d7ee969SAndy Lutomirski #ifdef CONFIG_X86_32
23343d7ee969SAndy Lutomirski 		.data		= &vdso32_enabled,
23353d7ee969SAndy Lutomirski 		.maxlen		= sizeof(vdso32_enabled),
23363d7ee969SAndy Lutomirski #else
2337e6e5494cSIngo Molnar 		.data		= &vdso_enabled,
2338e6e5494cSIngo Molnar 		.maxlen		= sizeof(vdso_enabled),
23393d7ee969SAndy Lutomirski #endif
2340e6e5494cSIngo Molnar 		.mode		= 0644,
23416d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2342eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2343e6e5494cSIngo Molnar 	},
2344e6e5494cSIngo Molnar #endif
23456a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE
23466a46079cSAndi Kleen 	{
23476a46079cSAndi Kleen 		.procname	= "memory_failure_early_kill",
23486a46079cSAndi Kleen 		.data		= &sysctl_memory_failure_early_kill,
23496a46079cSAndi Kleen 		.maxlen		= sizeof(sysctl_memory_failure_early_kill),
23506a46079cSAndi Kleen 		.mode		= 0644,
23516d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2352eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2353eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
23546a46079cSAndi Kleen 	},
23556a46079cSAndi Kleen 	{
23566a46079cSAndi Kleen 		.procname	= "memory_failure_recovery",
23576a46079cSAndi Kleen 		.data		= &sysctl_memory_failure_recovery,
23586a46079cSAndi Kleen 		.maxlen		= sizeof(sysctl_memory_failure_recovery),
23596a46079cSAndi Kleen 		.mode		= 0644,
23606d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2361eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2362eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
23636a46079cSAndi Kleen 	},
23646a46079cSAndi Kleen #endif
2365c9b1d098SAndrew Shewmaker 	{
2366c9b1d098SAndrew Shewmaker 		.procname	= "user_reserve_kbytes",
2367c9b1d098SAndrew Shewmaker 		.data		= &sysctl_user_reserve_kbytes,
2368c9b1d098SAndrew Shewmaker 		.maxlen		= sizeof(sysctl_user_reserve_kbytes),
2369c9b1d098SAndrew Shewmaker 		.mode		= 0644,
2370c9b1d098SAndrew Shewmaker 		.proc_handler	= proc_doulongvec_minmax,
2371c9b1d098SAndrew Shewmaker 	},
23724eeab4f5SAndrew Shewmaker 	{
23734eeab4f5SAndrew Shewmaker 		.procname	= "admin_reserve_kbytes",
23744eeab4f5SAndrew Shewmaker 		.data		= &sysctl_admin_reserve_kbytes,
23754eeab4f5SAndrew Shewmaker 		.maxlen		= sizeof(sysctl_admin_reserve_kbytes),
23764eeab4f5SAndrew Shewmaker 		.mode		= 0644,
23774eeab4f5SAndrew Shewmaker 		.proc_handler	= proc_doulongvec_minmax,
23784eeab4f5SAndrew Shewmaker 	},
2379d07e2259SDaniel Cashman #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
2380d07e2259SDaniel Cashman 	{
2381d07e2259SDaniel Cashman 		.procname	= "mmap_rnd_bits",
2382d07e2259SDaniel Cashman 		.data		= &mmap_rnd_bits,
2383d07e2259SDaniel Cashman 		.maxlen		= sizeof(mmap_rnd_bits),
2384d07e2259SDaniel Cashman 		.mode		= 0600,
2385d07e2259SDaniel Cashman 		.proc_handler	= proc_dointvec_minmax,
2386d07e2259SDaniel Cashman 		.extra1		= (void *)&mmap_rnd_bits_min,
2387d07e2259SDaniel Cashman 		.extra2		= (void *)&mmap_rnd_bits_max,
2388d07e2259SDaniel Cashman 	},
2389d07e2259SDaniel Cashman #endif
2390d07e2259SDaniel Cashman #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
2391d07e2259SDaniel Cashman 	{
2392d07e2259SDaniel Cashman 		.procname	= "mmap_rnd_compat_bits",
2393d07e2259SDaniel Cashman 		.data		= &mmap_rnd_compat_bits,
2394d07e2259SDaniel Cashman 		.maxlen		= sizeof(mmap_rnd_compat_bits),
2395d07e2259SDaniel Cashman 		.mode		= 0600,
2396d07e2259SDaniel Cashman 		.proc_handler	= proc_dointvec_minmax,
2397d07e2259SDaniel Cashman 		.extra1		= (void *)&mmap_rnd_compat_bits_min,
2398d07e2259SDaniel Cashman 		.extra2		= (void *)&mmap_rnd_compat_bits_max,
2399d07e2259SDaniel Cashman 	},
2400d07e2259SDaniel Cashman #endif
2401cefdca0aSPeter Xu #ifdef CONFIG_USERFAULTFD
2402cefdca0aSPeter Xu 	{
2403cefdca0aSPeter Xu 		.procname	= "unprivileged_userfaultfd",
2404cefdca0aSPeter Xu 		.data		= &sysctl_unprivileged_userfaultfd,
2405cefdca0aSPeter Xu 		.maxlen		= sizeof(sysctl_unprivileged_userfaultfd),
2406cefdca0aSPeter Xu 		.mode		= 0644,
2407cefdca0aSPeter Xu 		.proc_handler	= proc_dointvec_minmax,
2408eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2409eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2410cefdca0aSPeter Xu 	},
2411cefdca0aSPeter Xu #endif
24126fce56ecSEric W. Biederman 	{ }
24131da177e4SLinus Torvalds };
24141da177e4SLinus Torvalds 
2415d8217f07SEric W. Biederman static struct ctl_table debug_table[] = {
24167ac57a89SCatalin Marinas #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
2417abd4f750SMasoud Asgharifard Sharbiani 	{
2418abd4f750SMasoud Asgharifard Sharbiani 		.procname	= "exception-trace",
2419abd4f750SMasoud Asgharifard Sharbiani 		.data		= &show_unhandled_signals,
2420abd4f750SMasoud Asgharifard Sharbiani 		.maxlen		= sizeof(int),
2421abd4f750SMasoud Asgharifard Sharbiani 		.mode		= 0644,
2422abd4f750SMasoud Asgharifard Sharbiani 		.proc_handler	= proc_dointvec
2423abd4f750SMasoud Asgharifard Sharbiani 	},
2424abd4f750SMasoud Asgharifard Sharbiani #endif
24256fce56ecSEric W. Biederman 	{ }
24261da177e4SLinus Torvalds };
24271da177e4SLinus Torvalds 
2428d8217f07SEric W. Biederman static struct ctl_table dev_table[] = {
24296fce56ecSEric W. Biederman 	{ }
24301da177e4SLinus Torvalds };
24311da177e4SLinus Torvalds 
243251cb8dfcSLuis Chamberlain DECLARE_SYSCTL_BASE(kernel, kern_table);
243351cb8dfcSLuis Chamberlain DECLARE_SYSCTL_BASE(vm, vm_table);
243451cb8dfcSLuis Chamberlain DECLARE_SYSCTL_BASE(debug, debug_table);
243551cb8dfcSLuis Chamberlain DECLARE_SYSCTL_BASE(dev, dev_table);
2436f461d2dcSChristoph Hellwig 
2437d8c0418aSLuis Chamberlain int __init sysctl_init_bases(void)
2438330d57fbSAl Viro {
243951cb8dfcSLuis Chamberlain 	register_sysctl_base(kernel);
244051cb8dfcSLuis Chamberlain 	register_sysctl_base(vm);
244151cb8dfcSLuis Chamberlain 	register_sysctl_base(debug);
244251cb8dfcSLuis Chamberlain 	register_sysctl_base(dev);
2443fd4b616bSSteven Rostedt 
2444330d57fbSAl Viro 	return 0;
2445f7e6ced4SAl Viro }
2446b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */
24471da177e4SLinus Torvalds /*
24481da177e4SLinus Torvalds  * No sense putting this after each symbol definition, twice,
24491da177e4SLinus Torvalds  * exception granted :-)
24501da177e4SLinus Torvalds  */
2451a2071573SJia He EXPORT_SYMBOL(proc_dobool);
24521da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec);
2453e7d316a0SSubash Abhinov Kasiviswanathan EXPORT_SYMBOL(proc_douintvec);
24541da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies);
24551da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax);
245661d9b56aSLuis R. Rodriguez EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
24571da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
24581da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
24591da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring);
24601da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax);
24611da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
24620bc19985SStephen Suryaputra EXPORT_SYMBOL(proc_do_large_bitmap);
2463