xref: /openbmc/linux/kernel/sysctl.c (revision ef4984384172e93cc95e0e8cd102536d67e8a787)
1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * sysctl.c: General linux system control interface
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * Begun 24 March 1995, Stephen Tweedie
61da177e4SLinus Torvalds  * Added /proc support, Dec 1995
71da177e4SLinus Torvalds  * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
81da177e4SLinus Torvalds  * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
91da177e4SLinus Torvalds  * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
101da177e4SLinus Torvalds  * Dynamic registration fixes, Stephen Tweedie.
111da177e4SLinus Torvalds  * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
121da177e4SLinus Torvalds  * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
131da177e4SLinus Torvalds  *  Horn.
141da177e4SLinus Torvalds  * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
151da177e4SLinus Torvalds  * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
161da177e4SLinus Torvalds  * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
171da177e4SLinus Torvalds  *  Wendling.
181da177e4SLinus Torvalds  * The list_for_each() macro wasn't appropriate for the sysctl loop.
191da177e4SLinus Torvalds  *  Removed it and replaced it with older style, 03/23/00, Bill Wendling
201da177e4SLinus Torvalds  */
211da177e4SLinus Torvalds 
221da177e4SLinus Torvalds #include <linux/module.h>
23e2e40f2cSChristoph Hellwig #include <linux/aio.h>
241da177e4SLinus Torvalds #include <linux/mm.h>
251da177e4SLinus Torvalds #include <linux/swap.h>
261da177e4SLinus Torvalds #include <linux/slab.h>
271da177e4SLinus Torvalds #include <linux/sysctl.h>
285a04cca6SAkinobu Mita #include <linux/bitmap.h>
29d33ed52dSDave Young #include <linux/signal.h>
30455cd5abSDan Rosenberg #include <linux/printk.h>
311da177e4SLinus Torvalds #include <linux/proc_fs.h>
3272c2d582SAndrew Morgan #include <linux/security.h>
331da177e4SLinus Torvalds #include <linux/ctype.h>
34fd4b616bSSteven Rostedt #include <linux/kmemleak.h>
3562239ac2SAdrian Bunk #include <linux/fs.h>
361da177e4SLinus Torvalds #include <linux/init.h>
371da177e4SLinus Torvalds #include <linux/kernel.h>
380296b228SKay Sievers #include <linux/kobject.h>
3920380731SArnaldo Carvalho de Melo #include <linux/net.h>
401da177e4SLinus Torvalds #include <linux/sysrq.h>
411da177e4SLinus Torvalds #include <linux/highuid.h>
421da177e4SLinus Torvalds #include <linux/writeback.h>
433fff4c42SIngo Molnar #include <linux/ratelimit.h>
4476ab0f53SMel Gorman #include <linux/compaction.h>
451da177e4SLinus Torvalds #include <linux/hugetlb.h>
461da177e4SLinus Torvalds #include <linux/initrd.h>
470b77f5bfSDavid Howells #include <linux/key.h>
481da177e4SLinus Torvalds #include <linux/times.h>
491da177e4SLinus Torvalds #include <linux/limits.h>
501da177e4SLinus Torvalds #include <linux/dcache.h>
516e006701SAlexey Dobriyan #include <linux/dnotify.h>
521da177e4SLinus Torvalds #include <linux/syscalls.h>
53c748e134SAdrian Bunk #include <linux/vmstat.h>
54c255d844SPavel Machek #include <linux/nfs_fs.h>
55c255d844SPavel Machek #include <linux/acpi.h>
5610a0a8d4SJeremy Fitzhardinge #include <linux/reboot.h>
57b0fc494fSSteven Rostedt #include <linux/ftrace.h>
58cdd6c482SIngo Molnar #include <linux/perf_event.h>
59b2be84dfSMasami Hiramatsu #include <linux/kprobes.h>
60b492e95bSJens Axboe #include <linux/pipe_fs_i.h>
618e4228e1SDavid Rientjes #include <linux/oom.h>
6217f60a7dSEric Paris #include <linux/kmod.h>
6373efc039SDan Ballard #include <linux/capability.h>
6440401530SAl Viro #include <linux/binfmts.h>
65cf4aebc2SClark Williams #include <linux/sched/sysctl.h>
66f7ccbae4SIngo Molnar #include <linux/sched/coredump.h>
677984754bSKees Cook #include <linux/kexec.h>
681be7f75dSAlexei Starovoitov #include <linux/bpf.h>
69d2921684SEric W. Biederman #include <linux/mount.h>
70cefdca0aSPeter Xu #include <linux/userfaultfd_k.h>
712374c09bSChristoph Hellwig #include <linux/coredump.h>
722374c09bSChristoph Hellwig #include <linux/latencytop.h>
732374c09bSChristoph Hellwig #include <linux/pid.h>
741da177e4SLinus Torvalds 
757f2923c4SChristian Brauner #include "../lib/kstrtox.h"
767f2923c4SChristian Brauner 
777c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
781da177e4SLinus Torvalds #include <asm/processor.h>
791da177e4SLinus Torvalds 
8029cbc78bSAndi Kleen #ifdef CONFIG_X86
8129cbc78bSAndi Kleen #include <asm/nmi.h>
820741f4d2SChuck Ebbert #include <asm/stacktrace.h>
836e7c4025SIngo Molnar #include <asm/io.h>
8429cbc78bSAndi Kleen #endif
85d550bbd4SDavid Howells #ifdef CONFIG_SPARC
86d550bbd4SDavid Howells #include <asm/setup.h>
87d550bbd4SDavid Howells #endif
88c55b7c3eSDave Young #ifdef CONFIG_BSD_PROCESS_ACCT
89c55b7c3eSDave Young #include <linux/acct.h>
90c55b7c3eSDave Young #endif
914f0e056fSDave Young #ifdef CONFIG_RT_MUTEXES
924f0e056fSDave Young #include <linux/rtmutex.h>
934f0e056fSDave Young #endif
942edf5e49SDave Young #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
952edf5e49SDave Young #include <linux/lockdep.h>
962edf5e49SDave Young #endif
9715485a46SDave Young #ifdef CONFIG_CHR_DEV_SG
9815485a46SDave Young #include <scsi/sg.h>
9915485a46SDave Young #endif
100964c9dffSAlexander Popov #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
101964c9dffSAlexander Popov #include <linux/stackleak.h>
102964c9dffSAlexander Popov #endif
10358687acbSDon Zickus #ifdef CONFIG_LOCKUP_DETECTOR
104504d7cf1SDon Zickus #include <linux/nmi.h>
105504d7cf1SDon Zickus #endif
106504d7cf1SDon Zickus 
1071da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL)
1081da177e4SLinus Torvalds 
109c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and  maximum */
1102508ce18SDon Zickus #ifdef CONFIG_LOCKUP_DETECTOR
111c4f3b63fSRavikiran G Thirumalai static int sixty = 60;
112c4f3b63fSRavikiran G Thirumalai #endif
113c4f3b63fSRavikiran G Thirumalai 
114270750dbSAaron Tomlin static int __maybe_unused neg_one = -1;
115cd5f9a4cSLinus Torvalds static int __maybe_unused two = 2;
1165509a5d2SDave Hansen static int __maybe_unused four = 4;
1179002b214SWill Deacon static unsigned long zero_ul;
118fc3501d4SSven Wegener static unsigned long one_ul = 1;
11932a5ad9cSChristian Brauner static unsigned long long_max = LONG_MAX;
120c4f3b63fSRavikiran G Thirumalai static int one_hundred = 100;
121c843966cSJohannes Weiner static int two_hundred = 200;
122795ae7a0SJohannes Weiner static int one_thousand = 1000;
123af91322eSDave Young #ifdef CONFIG_PRINTK
124af91322eSDave Young static int ten_thousand = 10000;
125af91322eSDave Young #endif
126c5dfd78eSArnaldo Carvalho de Melo #ifdef CONFIG_PERF_EVENTS
127c5dfd78eSArnaldo Carvalho de Melo static int six_hundred_forty_kb = 640 * 1024;
128c5dfd78eSArnaldo Carvalho de Melo #endif
129c4f3b63fSRavikiran G Thirumalai 
1309e4a5bdaSAndrea Righi /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
1319e4a5bdaSAndrea Righi static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
1329e4a5bdaSAndrea Righi 
1331da177e4SLinus Torvalds /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
1341da177e4SLinus Torvalds static int maxolduid = 65535;
1351da177e4SLinus Torvalds static int minolduid;
1361da177e4SLinus Torvalds 
1371da177e4SLinus Torvalds static int ngroups_max = NGROUPS_MAX;
13873efc039SDan Ballard static const int cap_last_cap = CAP_LAST_CAP;
1391da177e4SLinus Torvalds 
140a2e51445SDmitry Vyukov /*
141a2e51445SDmitry Vyukov  * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
142a2e51445SDmitry Vyukov  * and hung_task_check_interval_secs
143a2e51445SDmitry Vyukov  */
14480df2847SLiu Hua #ifdef CONFIG_DETECT_HUNG_TASK
14580df2847SLiu Hua static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
14680df2847SLiu Hua #endif
14780df2847SLiu Hua 
148d14f1729SDave Young #ifdef CONFIG_INOTIFY_USER
149d14f1729SDave Young #include <linux/inotify.h>
150d14f1729SDave Young #endif
1515b8fea65SAmir Goldstein #ifdef CONFIG_FANOTIFY
1525b8fea65SAmir Goldstein #include <linux/fanotify.h>
1535b8fea65SAmir Goldstein #endif
154b6fca725SVineet Gupta 
155d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
156f4aacea2SKees Cook 
157a19ac337SLuis R. Rodriguez /**
158a19ac337SLuis R. Rodriguez  * enum sysctl_writes_mode - supported sysctl write modes
159a19ac337SLuis R. Rodriguez  *
160a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
161a19ac337SLuis R. Rodriguez  *	to be written, and multiple writes on the same sysctl file descriptor
162a19ac337SLuis R. Rodriguez  *	will rewrite the sysctl value, regardless of file position. No warning
163a19ac337SLuis R. Rodriguez  *	is issued when the initial position is not 0.
164a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
165a19ac337SLuis R. Rodriguez  *	not 0.
166a19ac337SLuis R. Rodriguez  * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
167a19ac337SLuis R. Rodriguez  *	file position 0 and the value must be fully contained in the buffer
168a19ac337SLuis R. Rodriguez  *	sent to the write syscall. If dealing with strings respect the file
169a19ac337SLuis R. Rodriguez  *	position, but restrict this to the max length of the buffer, anything
17065f50f25SWeitao Hou  *	passed the max length will be ignored. Multiple writes will append
171a19ac337SLuis R. Rodriguez  *	to the buffer.
172a19ac337SLuis R. Rodriguez  *
173a19ac337SLuis R. Rodriguez  * These write modes control how current file position affects the behavior of
174a19ac337SLuis R. Rodriguez  * updating sysctl values through the proc interface on each write.
175a19ac337SLuis R. Rodriguez  */
176a19ac337SLuis R. Rodriguez enum sysctl_writes_mode {
177a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_LEGACY		= -1,
178a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_WARN		= 0,
179a19ac337SLuis R. Rodriguez 	SYSCTL_WRITES_STRICT		= 1,
180a19ac337SLuis R. Rodriguez };
181f4aacea2SKees Cook 
182a19ac337SLuis R. Rodriguez static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
183f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */
184ceb18132SLuis R. Rodriguez 
18567f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
18667f3977fSAlexandre Ghiti     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
1871da177e4SLinus Torvalds int sysctl_legacy_va_layout;
1881da177e4SLinus Torvalds #endif
1891da177e4SLinus Torvalds 
1905e771905SMel Gorman #ifdef CONFIG_COMPACTION
1915e771905SMel Gorman static int min_extfrag_threshold;
1925e771905SMel Gorman static int max_extfrag_threshold = 1000;
1935e771905SMel Gorman #endif
1945e771905SMel Gorman 
195f461d2dcSChristoph Hellwig #endif /* CONFIG_SYSCTL */
196f461d2dcSChristoph Hellwig 
1975447e8e0SArnd Bergmann #if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL)
198d46edd67SSong Liu static int bpf_stats_handler(struct ctl_table *table, int write,
1997787b6fcSTobias Klauser 			     void *buffer, size_t *lenp, loff_t *ppos)
200d46edd67SSong Liu {
201d46edd67SSong Liu 	struct static_key *key = (struct static_key *)table->data;
202d46edd67SSong Liu 	static int saved_val;
203d46edd67SSong Liu 	int val, ret;
204d46edd67SSong Liu 	struct ctl_table tmp = {
205d46edd67SSong Liu 		.data   = &val,
206d46edd67SSong Liu 		.maxlen = sizeof(val),
207d46edd67SSong Liu 		.mode   = table->mode,
208d46edd67SSong Liu 		.extra1 = SYSCTL_ZERO,
209d46edd67SSong Liu 		.extra2 = SYSCTL_ONE,
210d46edd67SSong Liu 	};
211d46edd67SSong Liu 
212d46edd67SSong Liu 	if (write && !capable(CAP_SYS_ADMIN))
213d46edd67SSong Liu 		return -EPERM;
214d46edd67SSong Liu 
215d46edd67SSong Liu 	mutex_lock(&bpf_stats_enabled_mutex);
216d46edd67SSong Liu 	val = saved_val;
217d46edd67SSong Liu 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
218d46edd67SSong Liu 	if (write && !ret && val != saved_val) {
219d46edd67SSong Liu 		if (val)
220d46edd67SSong Liu 			static_key_slow_inc(key);
221d46edd67SSong Liu 		else
222d46edd67SSong Liu 			static_key_slow_dec(key);
223d46edd67SSong Liu 		saved_val = val;
224d46edd67SSong Liu 	}
225d46edd67SSong Liu 	mutex_unlock(&bpf_stats_enabled_mutex);
226d46edd67SSong Liu 	return ret;
227d46edd67SSong Liu }
228d46edd67SSong Liu #endif
229d46edd67SSong Liu 
230f461d2dcSChristoph Hellwig /*
231f461d2dcSChristoph Hellwig  * /proc/sys support
232f461d2dcSChristoph Hellwig  */
233f461d2dcSChristoph Hellwig 
234f461d2dcSChristoph Hellwig #ifdef CONFIG_PROC_SYSCTL
235f461d2dcSChristoph Hellwig 
236f461d2dcSChristoph Hellwig static int _proc_do_string(char *data, int maxlen, int write,
23732927393SChristoph Hellwig 		char *buffer, size_t *lenp, loff_t *ppos)
238f461d2dcSChristoph Hellwig {
239f461d2dcSChristoph Hellwig 	size_t len;
24032927393SChristoph Hellwig 	char c, *p;
241f461d2dcSChristoph Hellwig 
242f461d2dcSChristoph Hellwig 	if (!data || !maxlen || !*lenp) {
243f461d2dcSChristoph Hellwig 		*lenp = 0;
244f461d2dcSChristoph Hellwig 		return 0;
245f461d2dcSChristoph Hellwig 	}
246f461d2dcSChristoph Hellwig 
247f461d2dcSChristoph Hellwig 	if (write) {
248f461d2dcSChristoph Hellwig 		if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
249f461d2dcSChristoph Hellwig 			/* Only continue writes not past the end of buffer. */
250f461d2dcSChristoph Hellwig 			len = strlen(data);
251f461d2dcSChristoph Hellwig 			if (len > maxlen - 1)
252f461d2dcSChristoph Hellwig 				len = maxlen - 1;
253f461d2dcSChristoph Hellwig 
254f461d2dcSChristoph Hellwig 			if (*ppos > len)
255f461d2dcSChristoph Hellwig 				return 0;
256f461d2dcSChristoph Hellwig 			len = *ppos;
257f461d2dcSChristoph Hellwig 		} else {
258f461d2dcSChristoph Hellwig 			/* Start writing from beginning of buffer. */
259f461d2dcSChristoph Hellwig 			len = 0;
260f461d2dcSChristoph Hellwig 		}
261f461d2dcSChristoph Hellwig 
262f461d2dcSChristoph Hellwig 		*ppos += *lenp;
263f461d2dcSChristoph Hellwig 		p = buffer;
264f461d2dcSChristoph Hellwig 		while ((p - buffer) < *lenp && len < maxlen - 1) {
26532927393SChristoph Hellwig 			c = *(p++);
266f461d2dcSChristoph Hellwig 			if (c == 0 || c == '\n')
267f461d2dcSChristoph Hellwig 				break;
268f461d2dcSChristoph Hellwig 			data[len++] = c;
269f461d2dcSChristoph Hellwig 		}
270f461d2dcSChristoph Hellwig 		data[len] = 0;
271f461d2dcSChristoph Hellwig 	} else {
272f461d2dcSChristoph Hellwig 		len = strlen(data);
273f461d2dcSChristoph Hellwig 		if (len > maxlen)
274f461d2dcSChristoph Hellwig 			len = maxlen;
275f461d2dcSChristoph Hellwig 
276f461d2dcSChristoph Hellwig 		if (*ppos > len) {
277f461d2dcSChristoph Hellwig 			*lenp = 0;
278f461d2dcSChristoph Hellwig 			return 0;
279f461d2dcSChristoph Hellwig 		}
280f461d2dcSChristoph Hellwig 
281f461d2dcSChristoph Hellwig 		data += *ppos;
282f461d2dcSChristoph Hellwig 		len  -= *ppos;
283f461d2dcSChristoph Hellwig 
284f461d2dcSChristoph Hellwig 		if (len > *lenp)
285f461d2dcSChristoph Hellwig 			len = *lenp;
286f461d2dcSChristoph Hellwig 		if (len)
28732927393SChristoph Hellwig 			memcpy(buffer, data, len);
288f461d2dcSChristoph Hellwig 		if (len < *lenp) {
28932927393SChristoph Hellwig 			buffer[len] = '\n';
290f461d2dcSChristoph Hellwig 			len++;
291f461d2dcSChristoph Hellwig 		}
292f461d2dcSChristoph Hellwig 		*lenp = len;
293f461d2dcSChristoph Hellwig 		*ppos += len;
294f461d2dcSChristoph Hellwig 	}
295f461d2dcSChristoph Hellwig 	return 0;
296f461d2dcSChristoph Hellwig }
297f461d2dcSChristoph Hellwig 
298f461d2dcSChristoph Hellwig static void warn_sysctl_write(struct ctl_table *table)
299f461d2dcSChristoph Hellwig {
300f461d2dcSChristoph Hellwig 	pr_warn_once("%s wrote to %s when file position was not 0!\n"
301f461d2dcSChristoph Hellwig 		"This will not be supported in the future. To silence this\n"
302f461d2dcSChristoph Hellwig 		"warning, set kernel.sysctl_writes_strict = -1\n",
303f461d2dcSChristoph Hellwig 		current->comm, table->procname);
304f461d2dcSChristoph Hellwig }
305f461d2dcSChristoph Hellwig 
306f461d2dcSChristoph Hellwig /**
307f461d2dcSChristoph Hellwig  * proc_first_pos_non_zero_ignore - check if first position is allowed
308f461d2dcSChristoph Hellwig  * @ppos: file position
309f461d2dcSChristoph Hellwig  * @table: the sysctl table
310f461d2dcSChristoph Hellwig  *
311f461d2dcSChristoph Hellwig  * Returns true if the first position is non-zero and the sysctl_writes_strict
312f461d2dcSChristoph Hellwig  * mode indicates this is not allowed for numeric input types. String proc
313f461d2dcSChristoph Hellwig  * handlers can ignore the return value.
314f461d2dcSChristoph Hellwig  */
315f461d2dcSChristoph Hellwig static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
316f461d2dcSChristoph Hellwig 					   struct ctl_table *table)
317f461d2dcSChristoph Hellwig {
318f461d2dcSChristoph Hellwig 	if (!*ppos)
319f461d2dcSChristoph Hellwig 		return false;
320f461d2dcSChristoph Hellwig 
321f461d2dcSChristoph Hellwig 	switch (sysctl_writes_strict) {
322f461d2dcSChristoph Hellwig 	case SYSCTL_WRITES_STRICT:
323f461d2dcSChristoph Hellwig 		return true;
324f461d2dcSChristoph Hellwig 	case SYSCTL_WRITES_WARN:
325f461d2dcSChristoph Hellwig 		warn_sysctl_write(table);
326f461d2dcSChristoph Hellwig 		return false;
327f461d2dcSChristoph Hellwig 	default:
328f461d2dcSChristoph Hellwig 		return false;
329f461d2dcSChristoph Hellwig 	}
330f461d2dcSChristoph Hellwig }
331f461d2dcSChristoph Hellwig 
332f461d2dcSChristoph Hellwig /**
333f461d2dcSChristoph Hellwig  * proc_dostring - read a string sysctl
334f461d2dcSChristoph Hellwig  * @table: the sysctl table
335f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
336f461d2dcSChristoph Hellwig  * @buffer: the user buffer
337f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
338f461d2dcSChristoph Hellwig  * @ppos: file position
339f461d2dcSChristoph Hellwig  *
340f461d2dcSChristoph Hellwig  * Reads/writes a string from/to the user buffer. If the kernel
341f461d2dcSChristoph Hellwig  * buffer provided is not large enough to hold the string, the
342f461d2dcSChristoph Hellwig  * string is truncated. The copied string is %NULL-terminated.
343f461d2dcSChristoph Hellwig  * If the string is being read by the user process, it is copied
344f461d2dcSChristoph Hellwig  * and a newline '\n' is added. It is truncated if the buffer is
345f461d2dcSChristoph Hellwig  * not large enough.
346f461d2dcSChristoph Hellwig  *
347f461d2dcSChristoph Hellwig  * Returns 0 on success.
348f461d2dcSChristoph Hellwig  */
349f461d2dcSChristoph Hellwig int proc_dostring(struct ctl_table *table, int write,
35032927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
351f461d2dcSChristoph Hellwig {
352f461d2dcSChristoph Hellwig 	if (write)
353f461d2dcSChristoph Hellwig 		proc_first_pos_non_zero_ignore(ppos, table);
354f461d2dcSChristoph Hellwig 
35532927393SChristoph Hellwig 	return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
35632927393SChristoph Hellwig 			ppos);
357f461d2dcSChristoph Hellwig }
358f461d2dcSChristoph Hellwig 
359f461d2dcSChristoph Hellwig static size_t proc_skip_spaces(char **buf)
360f461d2dcSChristoph Hellwig {
361f461d2dcSChristoph Hellwig 	size_t ret;
362f461d2dcSChristoph Hellwig 	char *tmp = skip_spaces(*buf);
363f461d2dcSChristoph Hellwig 	ret = tmp - *buf;
364f461d2dcSChristoph Hellwig 	*buf = tmp;
365f461d2dcSChristoph Hellwig 	return ret;
366f461d2dcSChristoph Hellwig }
367f461d2dcSChristoph Hellwig 
368f461d2dcSChristoph Hellwig static void proc_skip_char(char **buf, size_t *size, const char v)
369f461d2dcSChristoph Hellwig {
370f461d2dcSChristoph Hellwig 	while (*size) {
371f461d2dcSChristoph Hellwig 		if (**buf != v)
372f461d2dcSChristoph Hellwig 			break;
373f461d2dcSChristoph Hellwig 		(*size)--;
374f461d2dcSChristoph Hellwig 		(*buf)++;
375f461d2dcSChristoph Hellwig 	}
376f461d2dcSChristoph Hellwig }
377f461d2dcSChristoph Hellwig 
378f461d2dcSChristoph Hellwig /**
379f461d2dcSChristoph Hellwig  * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
380f461d2dcSChristoph Hellwig  *                   fail on overflow
381f461d2dcSChristoph Hellwig  *
382f461d2dcSChristoph Hellwig  * @cp: kernel buffer containing the string to parse
383f461d2dcSChristoph Hellwig  * @endp: pointer to store the trailing characters
384f461d2dcSChristoph Hellwig  * @base: the base to use
385f461d2dcSChristoph Hellwig  * @res: where the parsed integer will be stored
386f461d2dcSChristoph Hellwig  *
387f461d2dcSChristoph Hellwig  * In case of success 0 is returned and @res will contain the parsed integer,
388f461d2dcSChristoph Hellwig  * @endp will hold any trailing characters.
389f461d2dcSChristoph Hellwig  * This function will fail the parse on overflow. If there wasn't an overflow
390f461d2dcSChristoph Hellwig  * the function will defer the decision what characters count as invalid to the
391f461d2dcSChristoph Hellwig  * caller.
392f461d2dcSChristoph Hellwig  */
393f461d2dcSChristoph Hellwig static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
394f461d2dcSChristoph Hellwig 			   unsigned long *res)
395f461d2dcSChristoph Hellwig {
396f461d2dcSChristoph Hellwig 	unsigned long long result;
397f461d2dcSChristoph Hellwig 	unsigned int rv;
398f461d2dcSChristoph Hellwig 
399f461d2dcSChristoph Hellwig 	cp = _parse_integer_fixup_radix(cp, &base);
400f461d2dcSChristoph Hellwig 	rv = _parse_integer(cp, base, &result);
401f461d2dcSChristoph Hellwig 	if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
402f461d2dcSChristoph Hellwig 		return -ERANGE;
403f461d2dcSChristoph Hellwig 
404f461d2dcSChristoph Hellwig 	cp += rv;
405f461d2dcSChristoph Hellwig 
406f461d2dcSChristoph Hellwig 	if (endp)
407f461d2dcSChristoph Hellwig 		*endp = (char *)cp;
408f461d2dcSChristoph Hellwig 
409f461d2dcSChristoph Hellwig 	*res = (unsigned long)result;
410f461d2dcSChristoph Hellwig 	return 0;
411f461d2dcSChristoph Hellwig }
412f461d2dcSChristoph Hellwig 
413f461d2dcSChristoph Hellwig #define TMPBUFLEN 22
414f461d2dcSChristoph Hellwig /**
415f461d2dcSChristoph Hellwig  * proc_get_long - reads an ASCII formatted integer from a user buffer
416f461d2dcSChristoph Hellwig  *
417f461d2dcSChristoph Hellwig  * @buf: a kernel buffer
418f461d2dcSChristoph Hellwig  * @size: size of the kernel buffer
419f461d2dcSChristoph Hellwig  * @val: this is where the number will be stored
420f461d2dcSChristoph Hellwig  * @neg: set to %TRUE if number is negative
421f461d2dcSChristoph Hellwig  * @perm_tr: a vector which contains the allowed trailers
422f461d2dcSChristoph Hellwig  * @perm_tr_len: size of the perm_tr vector
423f461d2dcSChristoph Hellwig  * @tr: pointer to store the trailer character
424f461d2dcSChristoph Hellwig  *
425f461d2dcSChristoph Hellwig  * In case of success %0 is returned and @buf and @size are updated with
426f461d2dcSChristoph Hellwig  * the amount of bytes read. If @tr is non-NULL and a trailing
427f461d2dcSChristoph Hellwig  * character exists (size is non-zero after returning from this
428f461d2dcSChristoph Hellwig  * function), @tr is updated with the trailing character.
429f461d2dcSChristoph Hellwig  */
430f461d2dcSChristoph Hellwig static int proc_get_long(char **buf, size_t *size,
431f461d2dcSChristoph Hellwig 			  unsigned long *val, bool *neg,
432f461d2dcSChristoph Hellwig 			  const char *perm_tr, unsigned perm_tr_len, char *tr)
433f461d2dcSChristoph Hellwig {
434f461d2dcSChristoph Hellwig 	int len;
435f461d2dcSChristoph Hellwig 	char *p, tmp[TMPBUFLEN];
436f461d2dcSChristoph Hellwig 
437f461d2dcSChristoph Hellwig 	if (!*size)
438f461d2dcSChristoph Hellwig 		return -EINVAL;
439f461d2dcSChristoph Hellwig 
440f461d2dcSChristoph Hellwig 	len = *size;
441f461d2dcSChristoph Hellwig 	if (len > TMPBUFLEN - 1)
442f461d2dcSChristoph Hellwig 		len = TMPBUFLEN - 1;
443f461d2dcSChristoph Hellwig 
444f461d2dcSChristoph Hellwig 	memcpy(tmp, *buf, len);
445f461d2dcSChristoph Hellwig 
446f461d2dcSChristoph Hellwig 	tmp[len] = 0;
447f461d2dcSChristoph Hellwig 	p = tmp;
448f461d2dcSChristoph Hellwig 	if (*p == '-' && *size > 1) {
449f461d2dcSChristoph Hellwig 		*neg = true;
450f461d2dcSChristoph Hellwig 		p++;
451f461d2dcSChristoph Hellwig 	} else
452f461d2dcSChristoph Hellwig 		*neg = false;
453f461d2dcSChristoph Hellwig 	if (!isdigit(*p))
454f461d2dcSChristoph Hellwig 		return -EINVAL;
455f461d2dcSChristoph Hellwig 
456f461d2dcSChristoph Hellwig 	if (strtoul_lenient(p, &p, 0, val))
457f461d2dcSChristoph Hellwig 		return -EINVAL;
458f461d2dcSChristoph Hellwig 
459f461d2dcSChristoph Hellwig 	len = p - tmp;
460f461d2dcSChristoph Hellwig 
461f461d2dcSChristoph Hellwig 	/* We don't know if the next char is whitespace thus we may accept
462f461d2dcSChristoph Hellwig 	 * invalid integers (e.g. 1234...a) or two integers instead of one
463f461d2dcSChristoph Hellwig 	 * (e.g. 123...1). So lets not allow such large numbers. */
464f461d2dcSChristoph Hellwig 	if (len == TMPBUFLEN - 1)
465f461d2dcSChristoph Hellwig 		return -EINVAL;
466f461d2dcSChristoph Hellwig 
467f461d2dcSChristoph Hellwig 	if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
468f461d2dcSChristoph Hellwig 		return -EINVAL;
469f461d2dcSChristoph Hellwig 
470f461d2dcSChristoph Hellwig 	if (tr && (len < *size))
471f461d2dcSChristoph Hellwig 		*tr = *p;
472f461d2dcSChristoph Hellwig 
473f461d2dcSChristoph Hellwig 	*buf += len;
474f461d2dcSChristoph Hellwig 	*size -= len;
475f461d2dcSChristoph Hellwig 
476f461d2dcSChristoph Hellwig 	return 0;
477f461d2dcSChristoph Hellwig }
478f461d2dcSChristoph Hellwig 
479f461d2dcSChristoph Hellwig /**
480f461d2dcSChristoph Hellwig  * proc_put_long - converts an integer to a decimal ASCII formatted string
481f461d2dcSChristoph Hellwig  *
482f461d2dcSChristoph Hellwig  * @buf: the user buffer
483f461d2dcSChristoph Hellwig  * @size: the size of the user buffer
484f461d2dcSChristoph Hellwig  * @val: the integer to be converted
485f461d2dcSChristoph Hellwig  * @neg: sign of the number, %TRUE for negative
486f461d2dcSChristoph Hellwig  *
48732927393SChristoph Hellwig  * In case of success @buf and @size are updated with the amount of bytes
48832927393SChristoph Hellwig  * written.
489f461d2dcSChristoph Hellwig  */
49032927393SChristoph Hellwig static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
491f461d2dcSChristoph Hellwig {
492f461d2dcSChristoph Hellwig 	int len;
493f461d2dcSChristoph Hellwig 	char tmp[TMPBUFLEN], *p = tmp;
494f461d2dcSChristoph Hellwig 
495f461d2dcSChristoph Hellwig 	sprintf(p, "%s%lu", neg ? "-" : "", val);
496f461d2dcSChristoph Hellwig 	len = strlen(tmp);
497f461d2dcSChristoph Hellwig 	if (len > *size)
498f461d2dcSChristoph Hellwig 		len = *size;
49932927393SChristoph Hellwig 	memcpy(*buf, tmp, len);
500f461d2dcSChristoph Hellwig 	*size -= len;
501f461d2dcSChristoph Hellwig 	*buf += len;
502f461d2dcSChristoph Hellwig }
503f461d2dcSChristoph Hellwig #undef TMPBUFLEN
504f461d2dcSChristoph Hellwig 
50532927393SChristoph Hellwig static void proc_put_char(void **buf, size_t *size, char c)
506f461d2dcSChristoph Hellwig {
507f461d2dcSChristoph Hellwig 	if (*size) {
50832927393SChristoph Hellwig 		char **buffer = (char **)buf;
50932927393SChristoph Hellwig 		**buffer = c;
51032927393SChristoph Hellwig 
51132927393SChristoph Hellwig 		(*size)--;
51232927393SChristoph Hellwig 		(*buffer)++;
513f461d2dcSChristoph Hellwig 		*buf = *buffer;
514f461d2dcSChristoph Hellwig 	}
515f461d2dcSChristoph Hellwig }
516f461d2dcSChristoph Hellwig 
517f461d2dcSChristoph Hellwig static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
518f461d2dcSChristoph Hellwig 				 int *valp,
519f461d2dcSChristoph Hellwig 				 int write, void *data)
520f461d2dcSChristoph Hellwig {
521f461d2dcSChristoph Hellwig 	if (write) {
522f461d2dcSChristoph Hellwig 		if (*negp) {
523f461d2dcSChristoph Hellwig 			if (*lvalp > (unsigned long) INT_MAX + 1)
524f461d2dcSChristoph Hellwig 				return -EINVAL;
525f461d2dcSChristoph Hellwig 			*valp = -*lvalp;
526f461d2dcSChristoph Hellwig 		} else {
527f461d2dcSChristoph Hellwig 			if (*lvalp > (unsigned long) INT_MAX)
528f461d2dcSChristoph Hellwig 				return -EINVAL;
529f461d2dcSChristoph Hellwig 			*valp = *lvalp;
530f461d2dcSChristoph Hellwig 		}
531f461d2dcSChristoph Hellwig 	} else {
532f461d2dcSChristoph Hellwig 		int val = *valp;
533f461d2dcSChristoph Hellwig 		if (val < 0) {
534f461d2dcSChristoph Hellwig 			*negp = true;
535f461d2dcSChristoph Hellwig 			*lvalp = -(unsigned long)val;
536f461d2dcSChristoph Hellwig 		} else {
537f461d2dcSChristoph Hellwig 			*negp = false;
538f461d2dcSChristoph Hellwig 			*lvalp = (unsigned long)val;
539f461d2dcSChristoph Hellwig 		}
540f461d2dcSChristoph Hellwig 	}
541f461d2dcSChristoph Hellwig 	return 0;
542f461d2dcSChristoph Hellwig }
543f461d2dcSChristoph Hellwig 
544f461d2dcSChristoph Hellwig static int do_proc_douintvec_conv(unsigned long *lvalp,
545f461d2dcSChristoph Hellwig 				  unsigned int *valp,
546f461d2dcSChristoph Hellwig 				  int write, void *data)
547f461d2dcSChristoph Hellwig {
548f461d2dcSChristoph Hellwig 	if (write) {
549f461d2dcSChristoph Hellwig 		if (*lvalp > UINT_MAX)
550f461d2dcSChristoph Hellwig 			return -EINVAL;
551f461d2dcSChristoph Hellwig 		*valp = *lvalp;
552f461d2dcSChristoph Hellwig 	} else {
553f461d2dcSChristoph Hellwig 		unsigned int val = *valp;
554f461d2dcSChristoph Hellwig 		*lvalp = (unsigned long)val;
555f461d2dcSChristoph Hellwig 	}
556f461d2dcSChristoph Hellwig 	return 0;
557f461d2dcSChristoph Hellwig }
558f461d2dcSChristoph Hellwig 
559f461d2dcSChristoph Hellwig static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
560f461d2dcSChristoph Hellwig 
561f461d2dcSChristoph Hellwig static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
56232927393SChristoph Hellwig 		  int write, void *buffer,
563f461d2dcSChristoph Hellwig 		  size_t *lenp, loff_t *ppos,
564f461d2dcSChristoph Hellwig 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
565f461d2dcSChristoph Hellwig 			      int write, void *data),
566f461d2dcSChristoph Hellwig 		  void *data)
567f461d2dcSChristoph Hellwig {
568f461d2dcSChristoph Hellwig 	int *i, vleft, first = 1, err = 0;
569f461d2dcSChristoph Hellwig 	size_t left;
57032927393SChristoph Hellwig 	char *p;
571f461d2dcSChristoph Hellwig 
572f461d2dcSChristoph Hellwig 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
573f461d2dcSChristoph Hellwig 		*lenp = 0;
574f461d2dcSChristoph Hellwig 		return 0;
575f461d2dcSChristoph Hellwig 	}
576f461d2dcSChristoph Hellwig 
577f461d2dcSChristoph Hellwig 	i = (int *) tbl_data;
578f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(*i);
579f461d2dcSChristoph Hellwig 	left = *lenp;
580f461d2dcSChristoph Hellwig 
581f461d2dcSChristoph Hellwig 	if (!conv)
582f461d2dcSChristoph Hellwig 		conv = do_proc_dointvec_conv;
583f461d2dcSChristoph Hellwig 
584f461d2dcSChristoph Hellwig 	if (write) {
585f461d2dcSChristoph Hellwig 		if (proc_first_pos_non_zero_ignore(ppos, table))
586f461d2dcSChristoph Hellwig 			goto out;
587f461d2dcSChristoph Hellwig 
588f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1)
589f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
59032927393SChristoph Hellwig 		p = buffer;
591f461d2dcSChristoph Hellwig 	}
592f461d2dcSChristoph Hellwig 
593f461d2dcSChristoph Hellwig 	for (; left && vleft--; i++, first=0) {
594f461d2dcSChristoph Hellwig 		unsigned long lval;
595f461d2dcSChristoph Hellwig 		bool neg;
596f461d2dcSChristoph Hellwig 
597f461d2dcSChristoph Hellwig 		if (write) {
598f461d2dcSChristoph Hellwig 			left -= proc_skip_spaces(&p);
599f461d2dcSChristoph Hellwig 
600f461d2dcSChristoph Hellwig 			if (!left)
601f461d2dcSChristoph Hellwig 				break;
602f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &lval, &neg,
603f461d2dcSChristoph Hellwig 					     proc_wspace_sep,
604f461d2dcSChristoph Hellwig 					     sizeof(proc_wspace_sep), NULL);
605f461d2dcSChristoph Hellwig 			if (err)
606f461d2dcSChristoph Hellwig 				break;
607f461d2dcSChristoph Hellwig 			if (conv(&neg, &lval, i, 1, data)) {
608f461d2dcSChristoph Hellwig 				err = -EINVAL;
609f461d2dcSChristoph Hellwig 				break;
610f461d2dcSChristoph Hellwig 			}
611f461d2dcSChristoph Hellwig 		} else {
612f461d2dcSChristoph Hellwig 			if (conv(&neg, &lval, i, 0, data)) {
613f461d2dcSChristoph Hellwig 				err = -EINVAL;
614f461d2dcSChristoph Hellwig 				break;
615f461d2dcSChristoph Hellwig 			}
616f461d2dcSChristoph Hellwig 			if (!first)
61732927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '\t');
61832927393SChristoph Hellwig 			proc_put_long(&buffer, &left, lval, neg);
619f461d2dcSChristoph Hellwig 		}
620f461d2dcSChristoph Hellwig 	}
621f461d2dcSChristoph Hellwig 
622f461d2dcSChristoph Hellwig 	if (!write && !first && left && !err)
62332927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
624f461d2dcSChristoph Hellwig 	if (write && !err && left)
625f461d2dcSChristoph Hellwig 		left -= proc_skip_spaces(&p);
62632927393SChristoph Hellwig 	if (write && first)
627f461d2dcSChristoph Hellwig 		return err ? : -EINVAL;
628f461d2dcSChristoph Hellwig 	*lenp -= left;
629f461d2dcSChristoph Hellwig out:
630f461d2dcSChristoph Hellwig 	*ppos += *lenp;
631f461d2dcSChristoph Hellwig 	return err;
632f461d2dcSChristoph Hellwig }
633f461d2dcSChristoph Hellwig 
634f461d2dcSChristoph Hellwig static int do_proc_dointvec(struct ctl_table *table, int write,
63532927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos,
636f461d2dcSChristoph Hellwig 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
637f461d2dcSChristoph Hellwig 			      int write, void *data),
638f461d2dcSChristoph Hellwig 		  void *data)
639f461d2dcSChristoph Hellwig {
640f461d2dcSChristoph Hellwig 	return __do_proc_dointvec(table->data, table, write,
641f461d2dcSChristoph Hellwig 			buffer, lenp, ppos, conv, data);
642f461d2dcSChristoph Hellwig }
643f461d2dcSChristoph Hellwig 
644f461d2dcSChristoph Hellwig static int do_proc_douintvec_w(unsigned int *tbl_data,
645f461d2dcSChristoph Hellwig 			       struct ctl_table *table,
64632927393SChristoph Hellwig 			       void *buffer,
647f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
648f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
649f461d2dcSChristoph Hellwig 					   unsigned int *valp,
650f461d2dcSChristoph Hellwig 					   int write, void *data),
651f461d2dcSChristoph Hellwig 			       void *data)
652f461d2dcSChristoph Hellwig {
653f461d2dcSChristoph Hellwig 	unsigned long lval;
654f461d2dcSChristoph Hellwig 	int err = 0;
655f461d2dcSChristoph Hellwig 	size_t left;
656f461d2dcSChristoph Hellwig 	bool neg;
65732927393SChristoph Hellwig 	char *p = buffer;
658f461d2dcSChristoph Hellwig 
659f461d2dcSChristoph Hellwig 	left = *lenp;
660f461d2dcSChristoph Hellwig 
661f461d2dcSChristoph Hellwig 	if (proc_first_pos_non_zero_ignore(ppos, table))
662f461d2dcSChristoph Hellwig 		goto bail_early;
663f461d2dcSChristoph Hellwig 
664f461d2dcSChristoph Hellwig 	if (left > PAGE_SIZE - 1)
665f461d2dcSChristoph Hellwig 		left = PAGE_SIZE - 1;
666f461d2dcSChristoph Hellwig 
667f461d2dcSChristoph Hellwig 	left -= proc_skip_spaces(&p);
668f461d2dcSChristoph Hellwig 	if (!left) {
669f461d2dcSChristoph Hellwig 		err = -EINVAL;
670f461d2dcSChristoph Hellwig 		goto out_free;
671f461d2dcSChristoph Hellwig 	}
672f461d2dcSChristoph Hellwig 
673f461d2dcSChristoph Hellwig 	err = proc_get_long(&p, &left, &lval, &neg,
674f461d2dcSChristoph Hellwig 			     proc_wspace_sep,
675f461d2dcSChristoph Hellwig 			     sizeof(proc_wspace_sep), NULL);
676f461d2dcSChristoph Hellwig 	if (err || neg) {
677f461d2dcSChristoph Hellwig 		err = -EINVAL;
678f461d2dcSChristoph Hellwig 		goto out_free;
679f461d2dcSChristoph Hellwig 	}
680f461d2dcSChristoph Hellwig 
681f461d2dcSChristoph Hellwig 	if (conv(&lval, tbl_data, 1, data)) {
682f461d2dcSChristoph Hellwig 		err = -EINVAL;
683f461d2dcSChristoph Hellwig 		goto out_free;
684f461d2dcSChristoph Hellwig 	}
685f461d2dcSChristoph Hellwig 
686f461d2dcSChristoph Hellwig 	if (!err && left)
687f461d2dcSChristoph Hellwig 		left -= proc_skip_spaces(&p);
688f461d2dcSChristoph Hellwig 
689f461d2dcSChristoph Hellwig out_free:
690f461d2dcSChristoph Hellwig 	if (err)
691f461d2dcSChristoph Hellwig 		return -EINVAL;
692f461d2dcSChristoph Hellwig 
693f461d2dcSChristoph Hellwig 	return 0;
694f461d2dcSChristoph Hellwig 
695f461d2dcSChristoph Hellwig 	/* This is in keeping with old __do_proc_dointvec() */
696f461d2dcSChristoph Hellwig bail_early:
697f461d2dcSChristoph Hellwig 	*ppos += *lenp;
698f461d2dcSChristoph Hellwig 	return err;
699f461d2dcSChristoph Hellwig }
700f461d2dcSChristoph Hellwig 
70132927393SChristoph Hellwig static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
702f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
703f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
704f461d2dcSChristoph Hellwig 					   unsigned int *valp,
705f461d2dcSChristoph Hellwig 					   int write, void *data),
706f461d2dcSChristoph Hellwig 			       void *data)
707f461d2dcSChristoph Hellwig {
708f461d2dcSChristoph Hellwig 	unsigned long lval;
709f461d2dcSChristoph Hellwig 	int err = 0;
710f461d2dcSChristoph Hellwig 	size_t left;
711f461d2dcSChristoph Hellwig 
712f461d2dcSChristoph Hellwig 	left = *lenp;
713f461d2dcSChristoph Hellwig 
714f461d2dcSChristoph Hellwig 	if (conv(&lval, tbl_data, 0, data)) {
715f461d2dcSChristoph Hellwig 		err = -EINVAL;
716f461d2dcSChristoph Hellwig 		goto out;
717f461d2dcSChristoph Hellwig 	}
718f461d2dcSChristoph Hellwig 
71932927393SChristoph Hellwig 	proc_put_long(&buffer, &left, lval, false);
72032927393SChristoph Hellwig 	if (!left)
721f461d2dcSChristoph Hellwig 		goto out;
722f461d2dcSChristoph Hellwig 
72332927393SChristoph Hellwig 	proc_put_char(&buffer, &left, '\n');
724f461d2dcSChristoph Hellwig 
725f461d2dcSChristoph Hellwig out:
726f461d2dcSChristoph Hellwig 	*lenp -= left;
727f461d2dcSChristoph Hellwig 	*ppos += *lenp;
728f461d2dcSChristoph Hellwig 
729f461d2dcSChristoph Hellwig 	return err;
730f461d2dcSChristoph Hellwig }
731f461d2dcSChristoph Hellwig 
732f461d2dcSChristoph Hellwig static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
73332927393SChristoph Hellwig 			       int write, void *buffer,
734f461d2dcSChristoph Hellwig 			       size_t *lenp, loff_t *ppos,
735f461d2dcSChristoph Hellwig 			       int (*conv)(unsigned long *lvalp,
736f461d2dcSChristoph Hellwig 					   unsigned int *valp,
737f461d2dcSChristoph Hellwig 					   int write, void *data),
738f461d2dcSChristoph Hellwig 			       void *data)
739f461d2dcSChristoph Hellwig {
740f461d2dcSChristoph Hellwig 	unsigned int *i, vleft;
741f461d2dcSChristoph Hellwig 
742f461d2dcSChristoph Hellwig 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
743f461d2dcSChristoph Hellwig 		*lenp = 0;
744f461d2dcSChristoph Hellwig 		return 0;
745f461d2dcSChristoph Hellwig 	}
746f461d2dcSChristoph Hellwig 
747f461d2dcSChristoph Hellwig 	i = (unsigned int *) tbl_data;
748f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(*i);
749f461d2dcSChristoph Hellwig 
750f461d2dcSChristoph Hellwig 	/*
751f461d2dcSChristoph Hellwig 	 * Arrays are not supported, keep this simple. *Do not* add
752f461d2dcSChristoph Hellwig 	 * support for them.
753f461d2dcSChristoph Hellwig 	 */
754f461d2dcSChristoph Hellwig 	if (vleft != 1) {
755f461d2dcSChristoph Hellwig 		*lenp = 0;
756f461d2dcSChristoph Hellwig 		return -EINVAL;
757f461d2dcSChristoph Hellwig 	}
758f461d2dcSChristoph Hellwig 
759f461d2dcSChristoph Hellwig 	if (!conv)
760f461d2dcSChristoph Hellwig 		conv = do_proc_douintvec_conv;
761f461d2dcSChristoph Hellwig 
762f461d2dcSChristoph Hellwig 	if (write)
763f461d2dcSChristoph Hellwig 		return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
764f461d2dcSChristoph Hellwig 					   conv, data);
765f461d2dcSChristoph Hellwig 	return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
766f461d2dcSChristoph Hellwig }
767f461d2dcSChristoph Hellwig 
768f461d2dcSChristoph Hellwig static int do_proc_douintvec(struct ctl_table *table, int write,
76932927393SChristoph Hellwig 			     void *buffer, size_t *lenp, loff_t *ppos,
770f461d2dcSChristoph Hellwig 			     int (*conv)(unsigned long *lvalp,
771f461d2dcSChristoph Hellwig 					 unsigned int *valp,
772f461d2dcSChristoph Hellwig 					 int write, void *data),
773f461d2dcSChristoph Hellwig 			     void *data)
774f461d2dcSChristoph Hellwig {
775f461d2dcSChristoph Hellwig 	return __do_proc_douintvec(table->data, table, write,
776f461d2dcSChristoph Hellwig 				   buffer, lenp, ppos, conv, data);
777f461d2dcSChristoph Hellwig }
778f461d2dcSChristoph Hellwig 
779f461d2dcSChristoph Hellwig /**
780f461d2dcSChristoph Hellwig  * proc_dointvec - read a vector of integers
781f461d2dcSChristoph Hellwig  * @table: the sysctl table
782f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
783f461d2dcSChristoph Hellwig  * @buffer: the user buffer
784f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
785f461d2dcSChristoph Hellwig  * @ppos: file position
786f461d2dcSChristoph Hellwig  *
787f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
788f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
789f461d2dcSChristoph Hellwig  *
790f461d2dcSChristoph Hellwig  * Returns 0 on success.
791f461d2dcSChristoph Hellwig  */
79232927393SChristoph Hellwig int proc_dointvec(struct ctl_table *table, int write, void *buffer,
79332927393SChristoph Hellwig 		  size_t *lenp, loff_t *ppos)
794f461d2dcSChristoph Hellwig {
795f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
796f461d2dcSChristoph Hellwig }
797f461d2dcSChristoph Hellwig 
798f461d2dcSChristoph Hellwig #ifdef CONFIG_COMPACTION
799f461d2dcSChristoph Hellwig static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
80032927393SChristoph Hellwig 		int write, void *buffer, size_t *lenp, loff_t *ppos)
801f461d2dcSChristoph Hellwig {
802f461d2dcSChristoph Hellwig 	int ret, old;
803f461d2dcSChristoph Hellwig 
804f461d2dcSChristoph Hellwig 	if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
805f461d2dcSChristoph Hellwig 		return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
806f461d2dcSChristoph Hellwig 
807f461d2dcSChristoph Hellwig 	old = *(int *)table->data;
808f461d2dcSChristoph Hellwig 	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
809f461d2dcSChristoph Hellwig 	if (ret)
810f461d2dcSChristoph Hellwig 		return ret;
811f461d2dcSChristoph Hellwig 	if (old != *(int *)table->data)
812f461d2dcSChristoph Hellwig 		pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
813f461d2dcSChristoph Hellwig 			     table->procname, current->comm,
814f461d2dcSChristoph Hellwig 			     task_pid_nr(current));
815f461d2dcSChristoph Hellwig 	return ret;
816f461d2dcSChristoph Hellwig }
817f461d2dcSChristoph Hellwig #endif
818f461d2dcSChristoph Hellwig 
819f461d2dcSChristoph Hellwig /**
820f461d2dcSChristoph Hellwig  * proc_douintvec - read a vector of unsigned integers
821f461d2dcSChristoph Hellwig  * @table: the sysctl table
822f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
823f461d2dcSChristoph Hellwig  * @buffer: the user buffer
824f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
825f461d2dcSChristoph Hellwig  * @ppos: file position
826f461d2dcSChristoph Hellwig  *
827f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
828f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
829f461d2dcSChristoph Hellwig  *
830f461d2dcSChristoph Hellwig  * Returns 0 on success.
831f461d2dcSChristoph Hellwig  */
83232927393SChristoph Hellwig int proc_douintvec(struct ctl_table *table, int write, void *buffer,
83332927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
834f461d2dcSChristoph Hellwig {
835f461d2dcSChristoph Hellwig 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
836f461d2dcSChristoph Hellwig 				 do_proc_douintvec_conv, NULL);
837f461d2dcSChristoph Hellwig }
838f461d2dcSChristoph Hellwig 
839f461d2dcSChristoph Hellwig /*
840f461d2dcSChristoph Hellwig  * Taint values can only be increased
841f461d2dcSChristoph Hellwig  * This means we can safely use a temporary.
842f461d2dcSChristoph Hellwig  */
843f461d2dcSChristoph Hellwig static int proc_taint(struct ctl_table *table, int write,
84432927393SChristoph Hellwig 			       void *buffer, size_t *lenp, loff_t *ppos)
845f461d2dcSChristoph Hellwig {
846f461d2dcSChristoph Hellwig 	struct ctl_table t;
847f461d2dcSChristoph Hellwig 	unsigned long tmptaint = get_taint();
848f461d2dcSChristoph Hellwig 	int err;
849f461d2dcSChristoph Hellwig 
850f461d2dcSChristoph Hellwig 	if (write && !capable(CAP_SYS_ADMIN))
851f461d2dcSChristoph Hellwig 		return -EPERM;
852f461d2dcSChristoph Hellwig 
853f461d2dcSChristoph Hellwig 	t = *table;
854f461d2dcSChristoph Hellwig 	t.data = &tmptaint;
855f461d2dcSChristoph Hellwig 	err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
856f461d2dcSChristoph Hellwig 	if (err < 0)
857f461d2dcSChristoph Hellwig 		return err;
858f461d2dcSChristoph Hellwig 
859f461d2dcSChristoph Hellwig 	if (write) {
860db38d5c1SRafael Aquini 		int i;
861db38d5c1SRafael Aquini 
862db38d5c1SRafael Aquini 		/*
863db38d5c1SRafael Aquini 		 * If we are relying on panic_on_taint not producing
864db38d5c1SRafael Aquini 		 * false positives due to userspace input, bail out
865db38d5c1SRafael Aquini 		 * before setting the requested taint flags.
866db38d5c1SRafael Aquini 		 */
867db38d5c1SRafael Aquini 		if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
868db38d5c1SRafael Aquini 			return -EINVAL;
869db38d5c1SRafael Aquini 
870f461d2dcSChristoph Hellwig 		/*
871f461d2dcSChristoph Hellwig 		 * Poor man's atomic or. Not worth adding a primitive
872f461d2dcSChristoph Hellwig 		 * to everyone's atomic.h for this
873f461d2dcSChristoph Hellwig 		 */
874e77132e7SRafael Aquini 		for (i = 0; i < TAINT_FLAGS_COUNT; i++)
875e77132e7SRafael Aquini 			if ((1UL << i) & tmptaint)
876f461d2dcSChristoph Hellwig 				add_taint(i, LOCKDEP_STILL_OK);
877f461d2dcSChristoph Hellwig 	}
878f461d2dcSChristoph Hellwig 
879f461d2dcSChristoph Hellwig 	return err;
880f461d2dcSChristoph Hellwig }
881f461d2dcSChristoph Hellwig 
882f461d2dcSChristoph Hellwig #ifdef CONFIG_PRINTK
883f461d2dcSChristoph Hellwig static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88432927393SChristoph Hellwig 				void *buffer, size_t *lenp, loff_t *ppos)
885f461d2dcSChristoph Hellwig {
886f461d2dcSChristoph Hellwig 	if (write && !capable(CAP_SYS_ADMIN))
887f461d2dcSChristoph Hellwig 		return -EPERM;
888f461d2dcSChristoph Hellwig 
889f461d2dcSChristoph Hellwig 	return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
890f461d2dcSChristoph Hellwig }
891f461d2dcSChristoph Hellwig #endif
892f461d2dcSChristoph Hellwig 
893f461d2dcSChristoph Hellwig /**
894f461d2dcSChristoph Hellwig  * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_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_dointvec_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_dointvec_minmax() handler.
901f461d2dcSChristoph Hellwig  */
902f461d2dcSChristoph Hellwig struct do_proc_dointvec_minmax_conv_param {
903f461d2dcSChristoph Hellwig 	int *min;
904f461d2dcSChristoph Hellwig 	int *max;
905f461d2dcSChristoph Hellwig };
906f461d2dcSChristoph Hellwig 
907f461d2dcSChristoph Hellwig static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
908f461d2dcSChristoph Hellwig 					int *valp,
909f461d2dcSChristoph Hellwig 					int write, void *data)
910f461d2dcSChristoph Hellwig {
911f461d2dcSChristoph Hellwig 	int tmp, ret;
912f461d2dcSChristoph Hellwig 	struct do_proc_dointvec_minmax_conv_param *param = data;
913f461d2dcSChristoph Hellwig 	/*
914f461d2dcSChristoph Hellwig 	 * If writing, first do so via a temporary local int so we can
915f461d2dcSChristoph Hellwig 	 * bounds-check it before touching *valp.
916f461d2dcSChristoph Hellwig 	 */
917f461d2dcSChristoph Hellwig 	int *ip = write ? &tmp : valp;
918f461d2dcSChristoph Hellwig 
919f461d2dcSChristoph Hellwig 	ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
920f461d2dcSChristoph Hellwig 	if (ret)
921f461d2dcSChristoph Hellwig 		return ret;
922f461d2dcSChristoph Hellwig 
923f461d2dcSChristoph Hellwig 	if (write) {
924f461d2dcSChristoph Hellwig 		if ((param->min && *param->min > tmp) ||
925f461d2dcSChristoph Hellwig 		    (param->max && *param->max < tmp))
926f461d2dcSChristoph Hellwig 			return -EINVAL;
927f461d2dcSChristoph Hellwig 		*valp = tmp;
928f461d2dcSChristoph Hellwig 	}
929f461d2dcSChristoph Hellwig 
930f461d2dcSChristoph Hellwig 	return 0;
931f461d2dcSChristoph Hellwig }
932f461d2dcSChristoph Hellwig 
933f461d2dcSChristoph Hellwig /**
934f461d2dcSChristoph Hellwig  * proc_dointvec_minmax - read a vector of integers with min/max values
935f461d2dcSChristoph Hellwig  * @table: the sysctl table
936f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
937f461d2dcSChristoph Hellwig  * @buffer: the user buffer
938f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
939f461d2dcSChristoph Hellwig  * @ppos: file position
940f461d2dcSChristoph Hellwig  *
941f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
942f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
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).
946f461d2dcSChristoph Hellwig  *
947f461d2dcSChristoph Hellwig  * Returns 0 on success or -EINVAL on write when the range check fails.
948f461d2dcSChristoph Hellwig  */
949f461d2dcSChristoph Hellwig int proc_dointvec_minmax(struct ctl_table *table, int write,
95032927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
951f461d2dcSChristoph Hellwig {
952f461d2dcSChristoph Hellwig 	struct do_proc_dointvec_minmax_conv_param param = {
953f461d2dcSChristoph Hellwig 		.min = (int *) table->extra1,
954f461d2dcSChristoph Hellwig 		.max = (int *) table->extra2,
955f461d2dcSChristoph Hellwig 	};
956f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
957f461d2dcSChristoph Hellwig 				do_proc_dointvec_minmax_conv, &param);
958f461d2dcSChristoph Hellwig }
959f461d2dcSChristoph Hellwig 
960f461d2dcSChristoph Hellwig /**
961f461d2dcSChristoph Hellwig  * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
962f461d2dcSChristoph Hellwig  * @min: pointer to minimum allowable value
963f461d2dcSChristoph Hellwig  * @max: pointer to maximum allowable value
964f461d2dcSChristoph Hellwig  *
965f461d2dcSChristoph Hellwig  * The do_proc_douintvec_minmax_conv_param structure provides the
966f461d2dcSChristoph Hellwig  * minimum and maximum values for doing range checking for those sysctl
967f461d2dcSChristoph Hellwig  * parameters that use the proc_douintvec_minmax() handler.
968f461d2dcSChristoph Hellwig  */
969f461d2dcSChristoph Hellwig struct do_proc_douintvec_minmax_conv_param {
970f461d2dcSChristoph Hellwig 	unsigned int *min;
971f461d2dcSChristoph Hellwig 	unsigned int *max;
972f461d2dcSChristoph Hellwig };
973f461d2dcSChristoph Hellwig 
974f461d2dcSChristoph Hellwig static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
975f461d2dcSChristoph Hellwig 					 unsigned int *valp,
976f461d2dcSChristoph Hellwig 					 int write, void *data)
977f461d2dcSChristoph Hellwig {
978f461d2dcSChristoph Hellwig 	int ret;
979f461d2dcSChristoph Hellwig 	unsigned int tmp;
980f461d2dcSChristoph Hellwig 	struct do_proc_douintvec_minmax_conv_param *param = data;
981f461d2dcSChristoph Hellwig 	/* write via temporary local uint for bounds-checking */
982f461d2dcSChristoph Hellwig 	unsigned int *up = write ? &tmp : valp;
983f461d2dcSChristoph Hellwig 
984f461d2dcSChristoph Hellwig 	ret = do_proc_douintvec_conv(lvalp, up, write, data);
985f461d2dcSChristoph Hellwig 	if (ret)
986f461d2dcSChristoph Hellwig 		return ret;
987f461d2dcSChristoph Hellwig 
988f461d2dcSChristoph Hellwig 	if (write) {
989f461d2dcSChristoph Hellwig 		if ((param->min && *param->min > tmp) ||
990f461d2dcSChristoph Hellwig 		    (param->max && *param->max < tmp))
991f461d2dcSChristoph Hellwig 			return -ERANGE;
992f461d2dcSChristoph Hellwig 
993f461d2dcSChristoph Hellwig 		*valp = tmp;
994f461d2dcSChristoph Hellwig 	}
995f461d2dcSChristoph Hellwig 
996f461d2dcSChristoph Hellwig 	return 0;
997f461d2dcSChristoph Hellwig }
998f461d2dcSChristoph Hellwig 
999f461d2dcSChristoph Hellwig /**
1000f461d2dcSChristoph Hellwig  * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
1001f461d2dcSChristoph Hellwig  * @table: the sysctl table
1002f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1003f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1004f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1005f461d2dcSChristoph Hellwig  * @ppos: file position
1006f461d2dcSChristoph Hellwig  *
1007f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
1008f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string. Negative
1009f461d2dcSChristoph Hellwig  * strings are not allowed.
1010f461d2dcSChristoph Hellwig  *
1011f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
1012f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max). There is a final sanity
1013f461d2dcSChristoph Hellwig  * check for UINT_MAX to avoid having to support wrap around uses from
1014f461d2dcSChristoph Hellwig  * userspace.
1015f461d2dcSChristoph Hellwig  *
1016f461d2dcSChristoph Hellwig  * Returns 0 on success or -ERANGE on write when the range check fails.
1017f461d2dcSChristoph Hellwig  */
1018f461d2dcSChristoph Hellwig int proc_douintvec_minmax(struct ctl_table *table, int write,
101932927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
1020f461d2dcSChristoph Hellwig {
1021f461d2dcSChristoph Hellwig 	struct do_proc_douintvec_minmax_conv_param param = {
1022f461d2dcSChristoph Hellwig 		.min = (unsigned int *) table->extra1,
1023f461d2dcSChristoph Hellwig 		.max = (unsigned int *) table->extra2,
1024f461d2dcSChristoph Hellwig 	};
1025f461d2dcSChristoph Hellwig 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
1026f461d2dcSChristoph Hellwig 				 do_proc_douintvec_minmax_conv, &param);
1027f461d2dcSChristoph Hellwig }
1028f461d2dcSChristoph Hellwig 
1029cb944413SEric Dumazet /**
1030cb944413SEric Dumazet  * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
1031cb944413SEric Dumazet  * @table: the sysctl table
1032cb944413SEric Dumazet  * @write: %TRUE if this is a write to the sysctl file
1033cb944413SEric Dumazet  * @buffer: the user buffer
1034cb944413SEric Dumazet  * @lenp: the size of the user buffer
1035cb944413SEric Dumazet  * @ppos: file position
1036cb944413SEric Dumazet  *
1037cb944413SEric Dumazet  * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
1038cb944413SEric Dumazet  * values from/to the user buffer, treated as an ASCII string. Negative
1039cb944413SEric Dumazet  * strings are not allowed.
1040cb944413SEric Dumazet  *
1041cb944413SEric Dumazet  * This routine will ensure the values are within the range specified by
1042cb944413SEric Dumazet  * table->extra1 (min) and table->extra2 (max).
1043cb944413SEric Dumazet  *
1044cb944413SEric Dumazet  * Returns 0 on success or an error on write when the range check fails.
1045cb944413SEric Dumazet  */
1046cb944413SEric Dumazet int proc_dou8vec_minmax(struct ctl_table *table, int write,
1047cb944413SEric Dumazet 			void *buffer, size_t *lenp, loff_t *ppos)
1048cb944413SEric Dumazet {
1049cb944413SEric Dumazet 	struct ctl_table tmp;
1050cb944413SEric Dumazet 	unsigned int min = 0, max = 255U, val;
1051cb944413SEric Dumazet 	u8 *data = table->data;
1052cb944413SEric Dumazet 	struct do_proc_douintvec_minmax_conv_param param = {
1053cb944413SEric Dumazet 		.min = &min,
1054cb944413SEric Dumazet 		.max = &max,
1055cb944413SEric Dumazet 	};
1056cb944413SEric Dumazet 	int res;
1057cb944413SEric Dumazet 
1058cb944413SEric Dumazet 	/* Do not support arrays yet. */
1059cb944413SEric Dumazet 	if (table->maxlen != sizeof(u8))
1060cb944413SEric Dumazet 		return -EINVAL;
1061cb944413SEric Dumazet 
1062cb944413SEric Dumazet 	if (table->extra1) {
1063cb944413SEric Dumazet 		min = *(unsigned int *) table->extra1;
1064cb944413SEric Dumazet 		if (min > 255U)
1065cb944413SEric Dumazet 			return -EINVAL;
1066cb944413SEric Dumazet 	}
1067cb944413SEric Dumazet 	if (table->extra2) {
1068cb944413SEric Dumazet 		max = *(unsigned int *) table->extra2;
1069cb944413SEric Dumazet 		if (max > 255U)
1070cb944413SEric Dumazet 			return -EINVAL;
1071cb944413SEric Dumazet 	}
1072cb944413SEric Dumazet 
1073cb944413SEric Dumazet 	tmp = *table;
1074cb944413SEric Dumazet 
1075cb944413SEric Dumazet 	tmp.maxlen = sizeof(val);
1076cb944413SEric Dumazet 	tmp.data = &val;
1077cb944413SEric Dumazet 	val = *data;
1078cb944413SEric Dumazet 	res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
1079cb944413SEric Dumazet 				do_proc_douintvec_minmax_conv, &param);
1080cb944413SEric Dumazet 	if (res)
1081cb944413SEric Dumazet 		return res;
1082cb944413SEric Dumazet 	if (write)
1083cb944413SEric Dumazet 		*data = val;
1084cb944413SEric Dumazet 	return 0;
1085cb944413SEric Dumazet }
1086cb944413SEric Dumazet EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
1087cb944413SEric Dumazet 
1088f461d2dcSChristoph Hellwig static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
1089f461d2dcSChristoph Hellwig 					unsigned int *valp,
1090f461d2dcSChristoph Hellwig 					int write, void *data)
1091f461d2dcSChristoph Hellwig {
1092f461d2dcSChristoph Hellwig 	if (write) {
1093f461d2dcSChristoph Hellwig 		unsigned int val;
1094f461d2dcSChristoph Hellwig 
1095f461d2dcSChristoph Hellwig 		val = round_pipe_size(*lvalp);
1096f461d2dcSChristoph Hellwig 		if (val == 0)
1097f461d2dcSChristoph Hellwig 			return -EINVAL;
1098f461d2dcSChristoph Hellwig 
1099f461d2dcSChristoph Hellwig 		*valp = val;
1100f461d2dcSChristoph Hellwig 	} else {
1101f461d2dcSChristoph Hellwig 		unsigned int val = *valp;
1102f461d2dcSChristoph Hellwig 		*lvalp = (unsigned long) val;
1103f461d2dcSChristoph Hellwig 	}
1104f461d2dcSChristoph Hellwig 
1105f461d2dcSChristoph Hellwig 	return 0;
1106f461d2dcSChristoph Hellwig }
1107f461d2dcSChristoph Hellwig 
1108f461d2dcSChristoph Hellwig static int proc_dopipe_max_size(struct ctl_table *table, int write,
110932927393SChristoph Hellwig 				void *buffer, size_t *lenp, loff_t *ppos)
1110f461d2dcSChristoph Hellwig {
1111f461d2dcSChristoph Hellwig 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
1112f461d2dcSChristoph Hellwig 				 do_proc_dopipe_max_size_conv, NULL);
1113f461d2dcSChristoph Hellwig }
1114f461d2dcSChristoph Hellwig 
1115f461d2dcSChristoph Hellwig static void validate_coredump_safety(void)
1116f461d2dcSChristoph Hellwig {
1117f461d2dcSChristoph Hellwig #ifdef CONFIG_COREDUMP
1118f461d2dcSChristoph Hellwig 	if (suid_dumpable == SUID_DUMP_ROOT &&
1119f461d2dcSChristoph Hellwig 	    core_pattern[0] != '/' && core_pattern[0] != '|') {
1120f461d2dcSChristoph Hellwig 		printk(KERN_WARNING
1121f461d2dcSChristoph Hellwig "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
1122f461d2dcSChristoph Hellwig "Pipe handler or fully qualified core dump path required.\n"
1123f461d2dcSChristoph Hellwig "Set kernel.core_pattern before fs.suid_dumpable.\n"
1124f461d2dcSChristoph Hellwig 		);
1125f461d2dcSChristoph Hellwig 	}
1126f461d2dcSChristoph Hellwig #endif
1127f461d2dcSChristoph Hellwig }
1128f461d2dcSChristoph Hellwig 
1129f461d2dcSChristoph Hellwig static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
113032927393SChristoph Hellwig 		void *buffer, size_t *lenp, loff_t *ppos)
1131f461d2dcSChristoph Hellwig {
1132f461d2dcSChristoph Hellwig 	int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1133f461d2dcSChristoph Hellwig 	if (!error)
1134f461d2dcSChristoph Hellwig 		validate_coredump_safety();
1135f461d2dcSChristoph Hellwig 	return error;
1136f461d2dcSChristoph Hellwig }
1137f461d2dcSChristoph Hellwig 
1138f461d2dcSChristoph Hellwig #ifdef CONFIG_COREDUMP
1139f461d2dcSChristoph Hellwig static int proc_dostring_coredump(struct ctl_table *table, int write,
114032927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1141f461d2dcSChristoph Hellwig {
1142f461d2dcSChristoph Hellwig 	int error = proc_dostring(table, write, buffer, lenp, ppos);
1143f461d2dcSChristoph Hellwig 	if (!error)
1144f461d2dcSChristoph Hellwig 		validate_coredump_safety();
1145f461d2dcSChristoph Hellwig 	return error;
1146f461d2dcSChristoph Hellwig }
1147f461d2dcSChristoph Hellwig #endif
1148f461d2dcSChristoph Hellwig 
1149f461d2dcSChristoph Hellwig #ifdef CONFIG_MAGIC_SYSRQ
1150f461d2dcSChristoph Hellwig static int sysrq_sysctl_handler(struct ctl_table *table, int write,
115132927393SChristoph Hellwig 				void *buffer, size_t *lenp, loff_t *ppos)
1152f461d2dcSChristoph Hellwig {
1153f461d2dcSChristoph Hellwig 	int tmp, ret;
1154f461d2dcSChristoph Hellwig 
1155f461d2dcSChristoph Hellwig 	tmp = sysrq_mask();
1156f461d2dcSChristoph Hellwig 
1157f461d2dcSChristoph Hellwig 	ret = __do_proc_dointvec(&tmp, table, write, buffer,
1158f461d2dcSChristoph Hellwig 			       lenp, ppos, NULL, NULL);
1159f461d2dcSChristoph Hellwig 	if (ret || !write)
1160f461d2dcSChristoph Hellwig 		return ret;
1161f461d2dcSChristoph Hellwig 
1162f461d2dcSChristoph Hellwig 	if (write)
1163f461d2dcSChristoph Hellwig 		sysrq_toggle_support(tmp);
1164f461d2dcSChristoph Hellwig 
1165f461d2dcSChristoph Hellwig 	return 0;
1166f461d2dcSChristoph Hellwig }
1167f461d2dcSChristoph Hellwig #endif
1168f461d2dcSChristoph Hellwig 
116932927393SChristoph Hellwig static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
117032927393SChristoph Hellwig 		int write, void *buffer, size_t *lenp, loff_t *ppos,
117132927393SChristoph Hellwig 		unsigned long convmul, unsigned long convdiv)
1172f461d2dcSChristoph Hellwig {
1173f461d2dcSChristoph Hellwig 	unsigned long *i, *min, *max;
1174f461d2dcSChristoph Hellwig 	int vleft, first = 1, err = 0;
1175f461d2dcSChristoph Hellwig 	size_t left;
117632927393SChristoph Hellwig 	char *p;
1177f461d2dcSChristoph Hellwig 
1178f461d2dcSChristoph Hellwig 	if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1179f461d2dcSChristoph Hellwig 		*lenp = 0;
1180f461d2dcSChristoph Hellwig 		return 0;
1181f461d2dcSChristoph Hellwig 	}
1182f461d2dcSChristoph Hellwig 
1183f461d2dcSChristoph Hellwig 	i = (unsigned long *) data;
1184f461d2dcSChristoph Hellwig 	min = (unsigned long *) table->extra1;
1185f461d2dcSChristoph Hellwig 	max = (unsigned long *) table->extra2;
1186f461d2dcSChristoph Hellwig 	vleft = table->maxlen / sizeof(unsigned long);
1187f461d2dcSChristoph Hellwig 	left = *lenp;
1188f461d2dcSChristoph Hellwig 
1189f461d2dcSChristoph Hellwig 	if (write) {
1190f461d2dcSChristoph Hellwig 		if (proc_first_pos_non_zero_ignore(ppos, table))
1191f461d2dcSChristoph Hellwig 			goto out;
1192f461d2dcSChristoph Hellwig 
1193f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1)
1194f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
119532927393SChristoph Hellwig 		p = buffer;
1196f461d2dcSChristoph Hellwig 	}
1197f461d2dcSChristoph Hellwig 
1198f461d2dcSChristoph Hellwig 	for (; left && vleft--; i++, first = 0) {
1199f461d2dcSChristoph Hellwig 		unsigned long val;
1200f461d2dcSChristoph Hellwig 
1201f461d2dcSChristoph Hellwig 		if (write) {
1202f461d2dcSChristoph Hellwig 			bool neg;
1203f461d2dcSChristoph Hellwig 
1204f461d2dcSChristoph Hellwig 			left -= proc_skip_spaces(&p);
1205f461d2dcSChristoph Hellwig 			if (!left)
1206f461d2dcSChristoph Hellwig 				break;
1207f461d2dcSChristoph Hellwig 
1208f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &val, &neg,
1209f461d2dcSChristoph Hellwig 					     proc_wspace_sep,
1210f461d2dcSChristoph Hellwig 					     sizeof(proc_wspace_sep), NULL);
1211f461d2dcSChristoph Hellwig 			if (err)
1212f461d2dcSChristoph Hellwig 				break;
1213f461d2dcSChristoph Hellwig 			if (neg)
1214f461d2dcSChristoph Hellwig 				continue;
1215f461d2dcSChristoph Hellwig 			val = convmul * val / convdiv;
1216f461d2dcSChristoph Hellwig 			if ((min && val < *min) || (max && val > *max)) {
1217f461d2dcSChristoph Hellwig 				err = -EINVAL;
1218f461d2dcSChristoph Hellwig 				break;
1219f461d2dcSChristoph Hellwig 			}
1220f461d2dcSChristoph Hellwig 			*i = val;
1221f461d2dcSChristoph Hellwig 		} else {
1222f461d2dcSChristoph Hellwig 			val = convdiv * (*i) / convmul;
122332927393SChristoph Hellwig 			if (!first)
122432927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '\t');
122532927393SChristoph Hellwig 			proc_put_long(&buffer, &left, val, false);
1226f461d2dcSChristoph Hellwig 		}
1227f461d2dcSChristoph Hellwig 	}
1228f461d2dcSChristoph Hellwig 
1229f461d2dcSChristoph Hellwig 	if (!write && !first && left && !err)
123032927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
1231f461d2dcSChristoph Hellwig 	if (write && !err)
1232f461d2dcSChristoph Hellwig 		left -= proc_skip_spaces(&p);
123332927393SChristoph Hellwig 	if (write && first)
1234f461d2dcSChristoph Hellwig 		return err ? : -EINVAL;
1235f461d2dcSChristoph Hellwig 	*lenp -= left;
1236f461d2dcSChristoph Hellwig out:
1237f461d2dcSChristoph Hellwig 	*ppos += *lenp;
1238f461d2dcSChristoph Hellwig 	return err;
1239f461d2dcSChristoph Hellwig }
1240f461d2dcSChristoph Hellwig 
1241f461d2dcSChristoph Hellwig static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
124232927393SChristoph Hellwig 		void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1243f461d2dcSChristoph Hellwig 		unsigned long convdiv)
1244f461d2dcSChristoph Hellwig {
1245f461d2dcSChristoph Hellwig 	return __do_proc_doulongvec_minmax(table->data, table, write,
1246f461d2dcSChristoph Hellwig 			buffer, lenp, ppos, convmul, convdiv);
1247f461d2dcSChristoph Hellwig }
1248f461d2dcSChristoph Hellwig 
1249f461d2dcSChristoph Hellwig /**
1250f461d2dcSChristoph Hellwig  * proc_doulongvec_minmax - read a vector of long integers with min/max values
1251f461d2dcSChristoph Hellwig  * @table: the sysctl table
1252f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1253f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1254f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1255f461d2dcSChristoph Hellwig  * @ppos: file position
1256f461d2dcSChristoph Hellwig  *
1257f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1258f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1259f461d2dcSChristoph Hellwig  *
1260f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
1261f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max).
1262f461d2dcSChristoph Hellwig  *
1263f461d2dcSChristoph Hellwig  * Returns 0 on success.
1264f461d2dcSChristoph Hellwig  */
1265f461d2dcSChristoph Hellwig int proc_doulongvec_minmax(struct ctl_table *table, int write,
126632927393SChristoph Hellwig 			   void *buffer, size_t *lenp, loff_t *ppos)
1267f461d2dcSChristoph Hellwig {
1268f461d2dcSChristoph Hellwig     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1269f461d2dcSChristoph Hellwig }
1270f461d2dcSChristoph Hellwig 
1271f461d2dcSChristoph Hellwig /**
1272f461d2dcSChristoph Hellwig  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1273f461d2dcSChristoph Hellwig  * @table: the sysctl table
1274f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1275f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1276f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1277f461d2dcSChristoph Hellwig  * @ppos: file position
1278f461d2dcSChristoph Hellwig  *
1279f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1280f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string. The values
1281f461d2dcSChristoph Hellwig  * are treated as milliseconds, and converted to jiffies when they are stored.
1282f461d2dcSChristoph Hellwig  *
1283f461d2dcSChristoph Hellwig  * This routine will ensure the values are within the range specified by
1284f461d2dcSChristoph Hellwig  * table->extra1 (min) and table->extra2 (max).
1285f461d2dcSChristoph Hellwig  *
1286f461d2dcSChristoph Hellwig  * Returns 0 on success.
1287f461d2dcSChristoph Hellwig  */
1288f461d2dcSChristoph Hellwig int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
128932927393SChristoph Hellwig 				      void *buffer, size_t *lenp, loff_t *ppos)
1290f461d2dcSChristoph Hellwig {
1291f461d2dcSChristoph Hellwig     return do_proc_doulongvec_minmax(table, write, buffer,
1292f461d2dcSChristoph Hellwig 				     lenp, ppos, HZ, 1000l);
1293f461d2dcSChristoph Hellwig }
1294f461d2dcSChristoph Hellwig 
1295f461d2dcSChristoph Hellwig 
1296f461d2dcSChristoph Hellwig static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1297f461d2dcSChristoph Hellwig 					 int *valp,
1298f461d2dcSChristoph Hellwig 					 int write, void *data)
1299f461d2dcSChristoph Hellwig {
1300f461d2dcSChristoph Hellwig 	if (write) {
1301f461d2dcSChristoph Hellwig 		if (*lvalp > INT_MAX / HZ)
1302f461d2dcSChristoph Hellwig 			return 1;
1303f461d2dcSChristoph Hellwig 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1304f461d2dcSChristoph Hellwig 	} else {
1305f461d2dcSChristoph Hellwig 		int val = *valp;
1306f461d2dcSChristoph Hellwig 		unsigned long lval;
1307f461d2dcSChristoph Hellwig 		if (val < 0) {
1308f461d2dcSChristoph Hellwig 			*negp = true;
1309f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1310f461d2dcSChristoph Hellwig 		} else {
1311f461d2dcSChristoph Hellwig 			*negp = false;
1312f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1313f461d2dcSChristoph Hellwig 		}
1314f461d2dcSChristoph Hellwig 		*lvalp = lval / HZ;
1315f461d2dcSChristoph Hellwig 	}
1316f461d2dcSChristoph Hellwig 	return 0;
1317f461d2dcSChristoph Hellwig }
1318f461d2dcSChristoph Hellwig 
1319f461d2dcSChristoph Hellwig static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1320f461d2dcSChristoph Hellwig 						int *valp,
1321f461d2dcSChristoph Hellwig 						int write, void *data)
1322f461d2dcSChristoph Hellwig {
1323f461d2dcSChristoph Hellwig 	if (write) {
1324f461d2dcSChristoph Hellwig 		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1325f461d2dcSChristoph Hellwig 			return 1;
1326f461d2dcSChristoph Hellwig 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1327f461d2dcSChristoph Hellwig 	} else {
1328f461d2dcSChristoph Hellwig 		int val = *valp;
1329f461d2dcSChristoph Hellwig 		unsigned long lval;
1330f461d2dcSChristoph Hellwig 		if (val < 0) {
1331f461d2dcSChristoph Hellwig 			*negp = true;
1332f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1333f461d2dcSChristoph Hellwig 		} else {
1334f461d2dcSChristoph Hellwig 			*negp = false;
1335f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1336f461d2dcSChristoph Hellwig 		}
1337f461d2dcSChristoph Hellwig 		*lvalp = jiffies_to_clock_t(lval);
1338f461d2dcSChristoph Hellwig 	}
1339f461d2dcSChristoph Hellwig 	return 0;
1340f461d2dcSChristoph Hellwig }
1341f461d2dcSChristoph Hellwig 
1342f461d2dcSChristoph Hellwig static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1343f461d2dcSChristoph Hellwig 					    int *valp,
1344f461d2dcSChristoph Hellwig 					    int write, void *data)
1345f461d2dcSChristoph Hellwig {
1346f461d2dcSChristoph Hellwig 	if (write) {
1347f461d2dcSChristoph Hellwig 		unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1348f461d2dcSChristoph Hellwig 
1349f461d2dcSChristoph Hellwig 		if (jif > INT_MAX)
1350f461d2dcSChristoph Hellwig 			return 1;
1351f461d2dcSChristoph Hellwig 		*valp = (int)jif;
1352f461d2dcSChristoph Hellwig 	} else {
1353f461d2dcSChristoph Hellwig 		int val = *valp;
1354f461d2dcSChristoph Hellwig 		unsigned long lval;
1355f461d2dcSChristoph Hellwig 		if (val < 0) {
1356f461d2dcSChristoph Hellwig 			*negp = true;
1357f461d2dcSChristoph Hellwig 			lval = -(unsigned long)val;
1358f461d2dcSChristoph Hellwig 		} else {
1359f461d2dcSChristoph Hellwig 			*negp = false;
1360f461d2dcSChristoph Hellwig 			lval = (unsigned long)val;
1361f461d2dcSChristoph Hellwig 		}
1362f461d2dcSChristoph Hellwig 		*lvalp = jiffies_to_msecs(lval);
1363f461d2dcSChristoph Hellwig 	}
1364f461d2dcSChristoph Hellwig 	return 0;
1365f461d2dcSChristoph Hellwig }
1366f461d2dcSChristoph Hellwig 
1367f461d2dcSChristoph Hellwig /**
1368f461d2dcSChristoph Hellwig  * proc_dointvec_jiffies - read a vector of integers as seconds
1369f461d2dcSChristoph Hellwig  * @table: the sysctl table
1370f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1371f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1372f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1373f461d2dcSChristoph Hellwig  * @ppos: file position
1374f461d2dcSChristoph Hellwig  *
1375f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1376f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1377f461d2dcSChristoph Hellwig  * The values read are assumed to be in seconds, and are converted into
1378f461d2dcSChristoph Hellwig  * jiffies.
1379f461d2dcSChristoph Hellwig  *
1380f461d2dcSChristoph Hellwig  * Returns 0 on success.
1381f461d2dcSChristoph Hellwig  */
1382f461d2dcSChristoph Hellwig int proc_dointvec_jiffies(struct ctl_table *table, int write,
138332927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
1384f461d2dcSChristoph Hellwig {
1385f461d2dcSChristoph Hellwig     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1386f461d2dcSChristoph Hellwig 		    	    do_proc_dointvec_jiffies_conv,NULL);
1387f461d2dcSChristoph Hellwig }
1388f461d2dcSChristoph Hellwig 
1389f461d2dcSChristoph Hellwig /**
1390f461d2dcSChristoph Hellwig  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1391f461d2dcSChristoph Hellwig  * @table: the sysctl table
1392f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1393f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1394f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1395f461d2dcSChristoph Hellwig  * @ppos: pointer to the file position
1396f461d2dcSChristoph Hellwig  *
1397f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1398f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1399f461d2dcSChristoph Hellwig  * The values read are assumed to be in 1/USER_HZ seconds, and
1400f461d2dcSChristoph Hellwig  * are converted into jiffies.
1401f461d2dcSChristoph Hellwig  *
1402f461d2dcSChristoph Hellwig  * Returns 0 on success.
1403f461d2dcSChristoph Hellwig  */
1404f461d2dcSChristoph Hellwig int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
140532927393SChristoph Hellwig 				 void *buffer, size_t *lenp, loff_t *ppos)
1406f461d2dcSChristoph Hellwig {
1407f461d2dcSChristoph Hellwig     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1408f461d2dcSChristoph Hellwig 		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);
1409f461d2dcSChristoph Hellwig }
1410f461d2dcSChristoph Hellwig 
1411f461d2dcSChristoph Hellwig /**
1412f461d2dcSChristoph Hellwig  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1413f461d2dcSChristoph Hellwig  * @table: the sysctl table
1414f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1415f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1416f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1417f461d2dcSChristoph Hellwig  * @ppos: file position
1418f461d2dcSChristoph Hellwig  * @ppos: the current position in the file
1419f461d2dcSChristoph Hellwig  *
1420f461d2dcSChristoph Hellwig  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1421f461d2dcSChristoph Hellwig  * values from/to the user buffer, treated as an ASCII string.
1422f461d2dcSChristoph Hellwig  * The values read are assumed to be in 1/1000 seconds, and
1423f461d2dcSChristoph Hellwig  * are converted into jiffies.
1424f461d2dcSChristoph Hellwig  *
1425f461d2dcSChristoph Hellwig  * Returns 0 on success.
1426f461d2dcSChristoph Hellwig  */
142732927393SChristoph Hellwig int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
142832927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
1429f461d2dcSChristoph Hellwig {
1430f461d2dcSChristoph Hellwig 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
1431f461d2dcSChristoph Hellwig 				do_proc_dointvec_ms_jiffies_conv, NULL);
1432f461d2dcSChristoph Hellwig }
1433f461d2dcSChristoph Hellwig 
143432927393SChristoph Hellwig static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
143532927393SChristoph Hellwig 		size_t *lenp, loff_t *ppos)
1436f461d2dcSChristoph Hellwig {
1437f461d2dcSChristoph Hellwig 	struct pid *new_pid;
1438f461d2dcSChristoph Hellwig 	pid_t tmp;
1439f461d2dcSChristoph Hellwig 	int r;
1440f461d2dcSChristoph Hellwig 
1441f461d2dcSChristoph Hellwig 	tmp = pid_vnr(cad_pid);
1442f461d2dcSChristoph Hellwig 
1443f461d2dcSChristoph Hellwig 	r = __do_proc_dointvec(&tmp, table, write, buffer,
1444f461d2dcSChristoph Hellwig 			       lenp, ppos, NULL, NULL);
1445f461d2dcSChristoph Hellwig 	if (r || !write)
1446f461d2dcSChristoph Hellwig 		return r;
1447f461d2dcSChristoph Hellwig 
1448f461d2dcSChristoph Hellwig 	new_pid = find_get_pid(tmp);
1449f461d2dcSChristoph Hellwig 	if (!new_pid)
1450f461d2dcSChristoph Hellwig 		return -ESRCH;
1451f461d2dcSChristoph Hellwig 
1452f461d2dcSChristoph Hellwig 	put_pid(xchg(&cad_pid, new_pid));
1453f461d2dcSChristoph Hellwig 	return 0;
1454f461d2dcSChristoph Hellwig }
1455f461d2dcSChristoph Hellwig 
1456f461d2dcSChristoph Hellwig /**
1457f461d2dcSChristoph Hellwig  * proc_do_large_bitmap - read/write from/to a large bitmap
1458f461d2dcSChristoph Hellwig  * @table: the sysctl table
1459f461d2dcSChristoph Hellwig  * @write: %TRUE if this is a write to the sysctl file
1460f461d2dcSChristoph Hellwig  * @buffer: the user buffer
1461f461d2dcSChristoph Hellwig  * @lenp: the size of the user buffer
1462f461d2dcSChristoph Hellwig  * @ppos: file position
1463f461d2dcSChristoph Hellwig  *
1464f461d2dcSChristoph Hellwig  * The bitmap is stored at table->data and the bitmap length (in bits)
1465f461d2dcSChristoph Hellwig  * in table->maxlen.
1466f461d2dcSChristoph Hellwig  *
1467f461d2dcSChristoph Hellwig  * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1468f461d2dcSChristoph Hellwig  * large bitmaps may be represented in a compact manner. Writing into
1469f461d2dcSChristoph Hellwig  * the file will clear the bitmap then update it with the given input.
1470f461d2dcSChristoph Hellwig  *
1471f461d2dcSChristoph Hellwig  * Returns 0 on success.
1472f461d2dcSChristoph Hellwig  */
1473f461d2dcSChristoph Hellwig int proc_do_large_bitmap(struct ctl_table *table, int write,
147432927393SChristoph Hellwig 			 void *buffer, size_t *lenp, loff_t *ppos)
1475f461d2dcSChristoph Hellwig {
1476f461d2dcSChristoph Hellwig 	int err = 0;
1477f461d2dcSChristoph Hellwig 	bool first = 1;
1478f461d2dcSChristoph Hellwig 	size_t left = *lenp;
1479f461d2dcSChristoph Hellwig 	unsigned long bitmap_len = table->maxlen;
1480f461d2dcSChristoph Hellwig 	unsigned long *bitmap = *(unsigned long **) table->data;
1481f461d2dcSChristoph Hellwig 	unsigned long *tmp_bitmap = NULL;
1482f461d2dcSChristoph Hellwig 	char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1483f461d2dcSChristoph Hellwig 
1484f461d2dcSChristoph Hellwig 	if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1485f461d2dcSChristoph Hellwig 		*lenp = 0;
1486f461d2dcSChristoph Hellwig 		return 0;
1487f461d2dcSChristoph Hellwig 	}
1488f461d2dcSChristoph Hellwig 
1489f461d2dcSChristoph Hellwig 	if (write) {
149032927393SChristoph Hellwig 		char *p = buffer;
1491f461d2dcSChristoph Hellwig 		size_t skipped = 0;
1492f461d2dcSChristoph Hellwig 
1493f461d2dcSChristoph Hellwig 		if (left > PAGE_SIZE - 1) {
1494f461d2dcSChristoph Hellwig 			left = PAGE_SIZE - 1;
1495f461d2dcSChristoph Hellwig 			/* How much of the buffer we'll skip this pass */
1496f461d2dcSChristoph Hellwig 			skipped = *lenp - left;
1497f461d2dcSChristoph Hellwig 		}
1498f461d2dcSChristoph Hellwig 
1499f461d2dcSChristoph Hellwig 		tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
150032927393SChristoph Hellwig 		if (!tmp_bitmap)
1501f461d2dcSChristoph Hellwig 			return -ENOMEM;
1502f461d2dcSChristoph Hellwig 		proc_skip_char(&p, &left, '\n');
1503f461d2dcSChristoph Hellwig 		while (!err && left) {
1504f461d2dcSChristoph Hellwig 			unsigned long val_a, val_b;
1505f461d2dcSChristoph Hellwig 			bool neg;
1506f461d2dcSChristoph Hellwig 			size_t saved_left;
1507f461d2dcSChristoph Hellwig 
1508f461d2dcSChristoph Hellwig 			/* In case we stop parsing mid-number, we can reset */
1509f461d2dcSChristoph Hellwig 			saved_left = left;
1510f461d2dcSChristoph Hellwig 			err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1511f461d2dcSChristoph Hellwig 					     sizeof(tr_a), &c);
1512f461d2dcSChristoph Hellwig 			/*
1513f461d2dcSChristoph Hellwig 			 * If we consumed the entirety of a truncated buffer or
1514f461d2dcSChristoph Hellwig 			 * only one char is left (may be a "-"), then stop here,
1515f461d2dcSChristoph Hellwig 			 * reset, & come back for more.
1516f461d2dcSChristoph Hellwig 			 */
1517f461d2dcSChristoph Hellwig 			if ((left <= 1) && skipped) {
1518f461d2dcSChristoph Hellwig 				left = saved_left;
1519f461d2dcSChristoph Hellwig 				break;
1520f461d2dcSChristoph Hellwig 			}
1521f461d2dcSChristoph Hellwig 
1522f461d2dcSChristoph Hellwig 			if (err)
1523f461d2dcSChristoph Hellwig 				break;
1524f461d2dcSChristoph Hellwig 			if (val_a >= bitmap_len || neg) {
1525f461d2dcSChristoph Hellwig 				err = -EINVAL;
1526f461d2dcSChristoph Hellwig 				break;
1527f461d2dcSChristoph Hellwig 			}
1528f461d2dcSChristoph Hellwig 
1529f461d2dcSChristoph Hellwig 			val_b = val_a;
1530f461d2dcSChristoph Hellwig 			if (left) {
1531f461d2dcSChristoph Hellwig 				p++;
1532f461d2dcSChristoph Hellwig 				left--;
1533f461d2dcSChristoph Hellwig 			}
1534f461d2dcSChristoph Hellwig 
1535f461d2dcSChristoph Hellwig 			if (c == '-') {
1536f461d2dcSChristoph Hellwig 				err = proc_get_long(&p, &left, &val_b,
1537f461d2dcSChristoph Hellwig 						     &neg, tr_b, sizeof(tr_b),
1538f461d2dcSChristoph Hellwig 						     &c);
1539f461d2dcSChristoph Hellwig 				/*
1540f461d2dcSChristoph Hellwig 				 * If we consumed all of a truncated buffer or
1541f461d2dcSChristoph Hellwig 				 * then stop here, reset, & come back for more.
1542f461d2dcSChristoph Hellwig 				 */
1543f461d2dcSChristoph Hellwig 				if (!left && skipped) {
1544f461d2dcSChristoph Hellwig 					left = saved_left;
1545f461d2dcSChristoph Hellwig 					break;
1546f461d2dcSChristoph Hellwig 				}
1547f461d2dcSChristoph Hellwig 
1548f461d2dcSChristoph Hellwig 				if (err)
1549f461d2dcSChristoph Hellwig 					break;
1550f461d2dcSChristoph Hellwig 				if (val_b >= bitmap_len || neg ||
1551f461d2dcSChristoph Hellwig 				    val_a > val_b) {
1552f461d2dcSChristoph Hellwig 					err = -EINVAL;
1553f461d2dcSChristoph Hellwig 					break;
1554f461d2dcSChristoph Hellwig 				}
1555f461d2dcSChristoph Hellwig 				if (left) {
1556f461d2dcSChristoph Hellwig 					p++;
1557f461d2dcSChristoph Hellwig 					left--;
1558f461d2dcSChristoph Hellwig 				}
1559f461d2dcSChristoph Hellwig 			}
1560f461d2dcSChristoph Hellwig 
1561f461d2dcSChristoph Hellwig 			bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1562f461d2dcSChristoph Hellwig 			first = 0;
1563f461d2dcSChristoph Hellwig 			proc_skip_char(&p, &left, '\n');
1564f461d2dcSChristoph Hellwig 		}
1565f461d2dcSChristoph Hellwig 		left += skipped;
1566f461d2dcSChristoph Hellwig 	} else {
1567f461d2dcSChristoph Hellwig 		unsigned long bit_a, bit_b = 0;
1568f461d2dcSChristoph Hellwig 
1569f461d2dcSChristoph Hellwig 		while (left) {
1570f461d2dcSChristoph Hellwig 			bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1571f461d2dcSChristoph Hellwig 			if (bit_a >= bitmap_len)
1572f461d2dcSChristoph Hellwig 				break;
1573f461d2dcSChristoph Hellwig 			bit_b = find_next_zero_bit(bitmap, bitmap_len,
1574f461d2dcSChristoph Hellwig 						   bit_a + 1) - 1;
1575f461d2dcSChristoph Hellwig 
157632927393SChristoph Hellwig 			if (!first)
157732927393SChristoph Hellwig 				proc_put_char(&buffer, &left, ',');
157832927393SChristoph Hellwig 			proc_put_long(&buffer, &left, bit_a, false);
1579f461d2dcSChristoph Hellwig 			if (bit_a != bit_b) {
158032927393SChristoph Hellwig 				proc_put_char(&buffer, &left, '-');
158132927393SChristoph Hellwig 				proc_put_long(&buffer, &left, bit_b, false);
1582f461d2dcSChristoph Hellwig 			}
1583f461d2dcSChristoph Hellwig 
1584f461d2dcSChristoph Hellwig 			first = 0; bit_b++;
1585f461d2dcSChristoph Hellwig 		}
158632927393SChristoph Hellwig 		proc_put_char(&buffer, &left, '\n');
1587f461d2dcSChristoph Hellwig 	}
1588f461d2dcSChristoph Hellwig 
1589f461d2dcSChristoph Hellwig 	if (!err) {
1590f461d2dcSChristoph Hellwig 		if (write) {
1591f461d2dcSChristoph Hellwig 			if (*ppos)
1592f461d2dcSChristoph Hellwig 				bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1593f461d2dcSChristoph Hellwig 			else
1594f461d2dcSChristoph Hellwig 				bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1595f461d2dcSChristoph Hellwig 		}
1596f461d2dcSChristoph Hellwig 		*lenp -= left;
1597f461d2dcSChristoph Hellwig 		*ppos += *lenp;
1598f461d2dcSChristoph Hellwig 	}
1599f461d2dcSChristoph Hellwig 
1600f461d2dcSChristoph Hellwig 	bitmap_free(tmp_bitmap);
1601f461d2dcSChristoph Hellwig 	return err;
1602f461d2dcSChristoph Hellwig }
1603f461d2dcSChristoph Hellwig 
1604f461d2dcSChristoph Hellwig #else /* CONFIG_PROC_SYSCTL */
1605f461d2dcSChristoph Hellwig 
1606f461d2dcSChristoph Hellwig int proc_dostring(struct ctl_table *table, int write,
160732927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1608f461d2dcSChristoph Hellwig {
1609f461d2dcSChristoph Hellwig 	return -ENOSYS;
1610f461d2dcSChristoph Hellwig }
1611f461d2dcSChristoph Hellwig 
1612f461d2dcSChristoph Hellwig int proc_dointvec(struct ctl_table *table, int write,
161332927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1614f461d2dcSChristoph Hellwig {
1615f461d2dcSChristoph Hellwig 	return -ENOSYS;
1616f461d2dcSChristoph Hellwig }
1617f461d2dcSChristoph Hellwig 
1618f461d2dcSChristoph Hellwig int proc_douintvec(struct ctl_table *table, int write,
161932927393SChristoph Hellwig 		  void *buffer, size_t *lenp, loff_t *ppos)
1620f461d2dcSChristoph Hellwig {
1621f461d2dcSChristoph Hellwig 	return -ENOSYS;
1622f461d2dcSChristoph Hellwig }
1623f461d2dcSChristoph Hellwig 
1624f461d2dcSChristoph Hellwig int proc_dointvec_minmax(struct ctl_table *table, int write,
162532927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1626f461d2dcSChristoph Hellwig {
1627f461d2dcSChristoph Hellwig 	return -ENOSYS;
1628f461d2dcSChristoph Hellwig }
1629f461d2dcSChristoph Hellwig 
1630f461d2dcSChristoph Hellwig int proc_douintvec_minmax(struct ctl_table *table, int write,
163132927393SChristoph Hellwig 			  void *buffer, size_t *lenp, loff_t *ppos)
1632f461d2dcSChristoph Hellwig {
1633f461d2dcSChristoph Hellwig 	return -ENOSYS;
1634f461d2dcSChristoph Hellwig }
1635f461d2dcSChristoph Hellwig 
1636cb944413SEric Dumazet int proc_dou8vec_minmax(struct ctl_table *table, int write,
1637cb944413SEric Dumazet 			void *buffer, size_t *lenp, loff_t *ppos)
1638cb944413SEric Dumazet {
1639cb944413SEric Dumazet 	return -ENOSYS;
1640cb944413SEric Dumazet }
1641cb944413SEric Dumazet 
1642f461d2dcSChristoph Hellwig int proc_dointvec_jiffies(struct ctl_table *table, int write,
164332927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1644f461d2dcSChristoph Hellwig {
1645f461d2dcSChristoph Hellwig 	return -ENOSYS;
1646f461d2dcSChristoph Hellwig }
1647f461d2dcSChristoph Hellwig 
1648f461d2dcSChristoph Hellwig int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
164932927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1650f461d2dcSChristoph Hellwig {
1651f461d2dcSChristoph Hellwig 	return -ENOSYS;
1652f461d2dcSChristoph Hellwig }
1653f461d2dcSChristoph Hellwig 
1654f461d2dcSChristoph Hellwig int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
165532927393SChristoph Hellwig 			     void *buffer, size_t *lenp, loff_t *ppos)
1656f461d2dcSChristoph Hellwig {
1657f461d2dcSChristoph Hellwig 	return -ENOSYS;
1658f461d2dcSChristoph Hellwig }
1659f461d2dcSChristoph Hellwig 
1660f461d2dcSChristoph Hellwig int proc_doulongvec_minmax(struct ctl_table *table, int write,
166132927393SChristoph Hellwig 		    void *buffer, size_t *lenp, loff_t *ppos)
1662f461d2dcSChristoph Hellwig {
1663f461d2dcSChristoph Hellwig 	return -ENOSYS;
1664f461d2dcSChristoph Hellwig }
1665f461d2dcSChristoph Hellwig 
1666f461d2dcSChristoph Hellwig int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
166732927393SChristoph Hellwig 				      void *buffer, size_t *lenp, loff_t *ppos)
1668f461d2dcSChristoph Hellwig {
1669f461d2dcSChristoph Hellwig 	return -ENOSYS;
1670f461d2dcSChristoph Hellwig }
1671f461d2dcSChristoph Hellwig 
1672f461d2dcSChristoph Hellwig int proc_do_large_bitmap(struct ctl_table *table, int write,
167332927393SChristoph Hellwig 			 void *buffer, size_t *lenp, loff_t *ppos)
1674f461d2dcSChristoph Hellwig {
1675f461d2dcSChristoph Hellwig 	return -ENOSYS;
1676f461d2dcSChristoph Hellwig }
1677f461d2dcSChristoph Hellwig 
1678f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */
1679f461d2dcSChristoph Hellwig 
1680f461d2dcSChristoph Hellwig #if defined(CONFIG_SYSCTL)
1681f461d2dcSChristoph Hellwig int proc_do_static_key(struct ctl_table *table, int write,
168232927393SChristoph Hellwig 		       void *buffer, size_t *lenp, loff_t *ppos)
1683f461d2dcSChristoph Hellwig {
1684f461d2dcSChristoph Hellwig 	struct static_key *key = (struct static_key *)table->data;
1685f461d2dcSChristoph Hellwig 	static DEFINE_MUTEX(static_key_mutex);
1686f461d2dcSChristoph Hellwig 	int val, ret;
1687f461d2dcSChristoph Hellwig 	struct ctl_table tmp = {
1688f461d2dcSChristoph Hellwig 		.data   = &val,
1689f461d2dcSChristoph Hellwig 		.maxlen = sizeof(val),
1690f461d2dcSChristoph Hellwig 		.mode   = table->mode,
1691f461d2dcSChristoph Hellwig 		.extra1 = SYSCTL_ZERO,
1692f461d2dcSChristoph Hellwig 		.extra2 = SYSCTL_ONE,
1693f461d2dcSChristoph Hellwig 	};
1694f461d2dcSChristoph Hellwig 
1695f461d2dcSChristoph Hellwig 	if (write && !capable(CAP_SYS_ADMIN))
1696f461d2dcSChristoph Hellwig 		return -EPERM;
1697f461d2dcSChristoph Hellwig 
1698f461d2dcSChristoph Hellwig 	mutex_lock(&static_key_mutex);
1699f461d2dcSChristoph Hellwig 	val = static_key_enabled(key);
1700f461d2dcSChristoph Hellwig 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1701f461d2dcSChristoph Hellwig 	if (write && !ret) {
1702f461d2dcSChristoph Hellwig 		if (val)
1703f461d2dcSChristoph Hellwig 			static_key_enable(key);
1704f461d2dcSChristoph Hellwig 		else
1705f461d2dcSChristoph Hellwig 			static_key_disable(key);
1706f461d2dcSChristoph Hellwig 	}
1707f461d2dcSChristoph Hellwig 	mutex_unlock(&static_key_mutex);
1708f461d2dcSChristoph Hellwig 	return ret;
1709f461d2dcSChristoph Hellwig }
1710f461d2dcSChristoph Hellwig 
1711d8217f07SEric W. Biederman static struct ctl_table kern_table[] = {
17122bba22c5SMike Galbraith 	{
17132bba22c5SMike Galbraith 		.procname	= "sched_child_runs_first",
17142bba22c5SMike Galbraith 		.data		= &sysctl_sched_child_runs_first,
17152bba22c5SMike Galbraith 		.maxlen		= sizeof(unsigned int),
17162bba22c5SMike Galbraith 		.mode		= 0644,
17176d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
17182bba22c5SMike Galbraith 	},
17191d1c2509SPeter Zijlstra #ifdef CONFIG_SCHEDSTATS
17201d1c2509SPeter Zijlstra 	{
17211d1c2509SPeter Zijlstra 		.procname	= "sched_schedstats",
17221d1c2509SPeter Zijlstra 		.data		= NULL,
17231d1c2509SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
17241d1c2509SPeter Zijlstra 		.mode		= 0644,
17251d1c2509SPeter Zijlstra 		.proc_handler	= sysctl_schedstats,
17261d1c2509SPeter Zijlstra 		.extra1		= SYSCTL_ZERO,
17271d1c2509SPeter Zijlstra 		.extra2		= SYSCTL_ONE,
17281d1c2509SPeter Zijlstra 	},
17291d1c2509SPeter Zijlstra #endif /* CONFIG_SCHEDSTATS */
1730b7cc6ec7SMel Gorman #ifdef CONFIG_NUMA_BALANCING
17313a7053b3SMel Gorman 	{
173254a43d54SAndi Kleen 		.procname	= "numa_balancing",
173354a43d54SAndi Kleen 		.data		= NULL, /* filled in by handler */
173454a43d54SAndi Kleen 		.maxlen		= sizeof(unsigned int),
173554a43d54SAndi Kleen 		.mode		= 0644,
173654a43d54SAndi Kleen 		.proc_handler	= sysctl_numa_balancing,
1737eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
1738eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
173954a43d54SAndi Kleen 	},
1740cbee9f88SPeter Zijlstra #endif /* CONFIG_NUMA_BALANCING */
17411799e35dSIngo Molnar 	{
17429f0c1e56SPeter Zijlstra 		.procname	= "sched_rt_period_us",
17439f0c1e56SPeter Zijlstra 		.data		= &sysctl_sched_rt_period,
17449f0c1e56SPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
17459f0c1e56SPeter Zijlstra 		.mode		= 0644,
17466d456111SEric W. Biederman 		.proc_handler	= sched_rt_handler,
17479f0c1e56SPeter Zijlstra 	},
17489f0c1e56SPeter Zijlstra 	{
17499f0c1e56SPeter Zijlstra 		.procname	= "sched_rt_runtime_us",
17509f0c1e56SPeter Zijlstra 		.data		= &sysctl_sched_rt_runtime,
17519f0c1e56SPeter Zijlstra 		.maxlen		= sizeof(int),
17529f0c1e56SPeter Zijlstra 		.mode		= 0644,
17536d456111SEric W. Biederman 		.proc_handler	= sched_rt_handler,
17549f0c1e56SPeter Zijlstra 	},
1755ce0dbbbbSClark Williams 	{
1756b4098bfcSPeter Zijlstra 		.procname	= "sched_deadline_period_max_us",
1757b4098bfcSPeter Zijlstra 		.data		= &sysctl_sched_dl_period_max,
1758b4098bfcSPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
1759b4098bfcSPeter Zijlstra 		.mode		= 0644,
1760b4098bfcSPeter Zijlstra 		.proc_handler	= proc_dointvec,
1761b4098bfcSPeter Zijlstra 	},
1762b4098bfcSPeter Zijlstra 	{
1763b4098bfcSPeter Zijlstra 		.procname	= "sched_deadline_period_min_us",
1764b4098bfcSPeter Zijlstra 		.data		= &sysctl_sched_dl_period_min,
1765b4098bfcSPeter Zijlstra 		.maxlen		= sizeof(unsigned int),
1766b4098bfcSPeter Zijlstra 		.mode		= 0644,
1767b4098bfcSPeter Zijlstra 		.proc_handler	= proc_dointvec,
1768b4098bfcSPeter Zijlstra 	},
1769b4098bfcSPeter Zijlstra 	{
1770ce0dbbbbSClark Williams 		.procname	= "sched_rr_timeslice_ms",
1771975e155eSShile Zhang 		.data		= &sysctl_sched_rr_timeslice,
1772ce0dbbbbSClark Williams 		.maxlen		= sizeof(int),
1773ce0dbbbbSClark Williams 		.mode		= 0644,
1774ce0dbbbbSClark Williams 		.proc_handler	= sched_rr_handler,
1775ce0dbbbbSClark Williams 	},
1776e8f14172SPatrick Bellasi #ifdef CONFIG_UCLAMP_TASK
1777e8f14172SPatrick Bellasi 	{
1778e8f14172SPatrick Bellasi 		.procname	= "sched_util_clamp_min",
1779e8f14172SPatrick Bellasi 		.data		= &sysctl_sched_uclamp_util_min,
1780e8f14172SPatrick Bellasi 		.maxlen		= sizeof(unsigned int),
1781e8f14172SPatrick Bellasi 		.mode		= 0644,
1782e8f14172SPatrick Bellasi 		.proc_handler	= sysctl_sched_uclamp_handler,
1783e8f14172SPatrick Bellasi 	},
1784e8f14172SPatrick Bellasi 	{
1785e8f14172SPatrick Bellasi 		.procname	= "sched_util_clamp_max",
1786e8f14172SPatrick Bellasi 		.data		= &sysctl_sched_uclamp_util_max,
1787e8f14172SPatrick Bellasi 		.maxlen		= sizeof(unsigned int),
1788e8f14172SPatrick Bellasi 		.mode		= 0644,
1789e8f14172SPatrick Bellasi 		.proc_handler	= sysctl_sched_uclamp_handler,
1790e8f14172SPatrick Bellasi 	},
179113685c4aSQais Yousef 	{
179213685c4aSQais Yousef 		.procname	= "sched_util_clamp_min_rt_default",
179313685c4aSQais Yousef 		.data		= &sysctl_sched_uclamp_util_min_rt_default,
179413685c4aSQais Yousef 		.maxlen		= sizeof(unsigned int),
179513685c4aSQais Yousef 		.mode		= 0644,
179613685c4aSQais Yousef 		.proc_handler	= sysctl_sched_uclamp_handler,
179713685c4aSQais Yousef 	},
1798e8f14172SPatrick Bellasi #endif
17995091faa4SMike Galbraith #ifdef CONFIG_SCHED_AUTOGROUP
18005091faa4SMike Galbraith 	{
18015091faa4SMike Galbraith 		.procname	= "sched_autogroup_enabled",
18025091faa4SMike Galbraith 		.data		= &sysctl_sched_autogroup_enabled,
18035091faa4SMike Galbraith 		.maxlen		= sizeof(unsigned int),
18045091faa4SMike Galbraith 		.mode		= 0644,
18051747b21fSYong Zhang 		.proc_handler	= proc_dointvec_minmax,
1806eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
1807eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
18085091faa4SMike Galbraith 	},
18095091faa4SMike Galbraith #endif
1810ec12cb7fSPaul Turner #ifdef CONFIG_CFS_BANDWIDTH
1811ec12cb7fSPaul Turner 	{
1812ec12cb7fSPaul Turner 		.procname	= "sched_cfs_bandwidth_slice_us",
1813ec12cb7fSPaul Turner 		.data		= &sysctl_sched_cfs_bandwidth_slice,
1814ec12cb7fSPaul Turner 		.maxlen		= sizeof(unsigned int),
1815ec12cb7fSPaul Turner 		.mode		= 0644,
1816ec12cb7fSPaul Turner 		.proc_handler	= proc_dointvec_minmax,
1817eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
1818ec12cb7fSPaul Turner 	},
1819ec12cb7fSPaul Turner #endif
18208d5d0cfbSQuentin Perret #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
18218d5d0cfbSQuentin Perret 	{
18228d5d0cfbSQuentin Perret 		.procname	= "sched_energy_aware",
18238d5d0cfbSQuentin Perret 		.data		= &sysctl_sched_energy_aware,
18248d5d0cfbSQuentin Perret 		.maxlen		= sizeof(unsigned int),
18258d5d0cfbSQuentin Perret 		.mode		= 0644,
18268d5d0cfbSQuentin Perret 		.proc_handler	= sched_energy_aware_handler,
1827eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
1828eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
18298d5d0cfbSQuentin Perret 	},
18308d5d0cfbSQuentin Perret #endif
1831f20786ffSPeter Zijlstra #ifdef CONFIG_PROVE_LOCKING
1832f20786ffSPeter Zijlstra 	{
1833f20786ffSPeter Zijlstra 		.procname	= "prove_locking",
1834f20786ffSPeter Zijlstra 		.data		= &prove_locking,
1835f20786ffSPeter Zijlstra 		.maxlen		= sizeof(int),
1836f20786ffSPeter Zijlstra 		.mode		= 0644,
18376d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1838f20786ffSPeter Zijlstra 	},
1839f20786ffSPeter Zijlstra #endif
1840f20786ffSPeter Zijlstra #ifdef CONFIG_LOCK_STAT
1841f20786ffSPeter Zijlstra 	{
1842f20786ffSPeter Zijlstra 		.procname	= "lock_stat",
1843f20786ffSPeter Zijlstra 		.data		= &lock_stat,
1844f20786ffSPeter Zijlstra 		.maxlen		= sizeof(int),
1845f20786ffSPeter Zijlstra 		.mode		= 0644,
18466d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1847f20786ffSPeter Zijlstra 	},
1848f20786ffSPeter Zijlstra #endif
184977e54a1fSIngo Molnar 	{
18501da177e4SLinus Torvalds 		.procname	= "panic",
18511da177e4SLinus Torvalds 		.data		= &panic_timeout,
18521da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
18531da177e4SLinus Torvalds 		.mode		= 0644,
18546d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18551da177e4SLinus Torvalds 	},
1856046d662fSAlex Kelly #ifdef CONFIG_COREDUMP
18571da177e4SLinus Torvalds 	{
18581da177e4SLinus Torvalds 		.procname	= "core_uses_pid",
18591da177e4SLinus Torvalds 		.data		= &core_uses_pid,
18601da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
18611da177e4SLinus Torvalds 		.mode		= 0644,
18626d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
18631da177e4SLinus Torvalds 	},
18641da177e4SLinus Torvalds 	{
18651da177e4SLinus Torvalds 		.procname	= "core_pattern",
18661da177e4SLinus Torvalds 		.data		= core_pattern,
186771ce92f3SDan Aloni 		.maxlen		= CORENAME_MAX_SIZE,
18681da177e4SLinus Torvalds 		.mode		= 0644,
186954b50199SKees Cook 		.proc_handler	= proc_dostring_coredump,
18701da177e4SLinus Torvalds 	},
1871a293980cSNeil Horman 	{
1872a293980cSNeil Horman 		.procname	= "core_pipe_limit",
1873a293980cSNeil Horman 		.data		= &core_pipe_limit,
1874a293980cSNeil Horman 		.maxlen		= sizeof(unsigned int),
1875a293980cSNeil Horman 		.mode		= 0644,
18766d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
1877a293980cSNeil Horman 	},
1878046d662fSAlex Kelly #endif
187934f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL
18801da177e4SLinus Torvalds 	{
18811da177e4SLinus Torvalds 		.procname	= "tainted",
188225ddbb18SAndi Kleen 		.maxlen 	= sizeof(long),
188334f5a398STheodore Ts'o 		.mode		= 0644,
18846d456111SEric W. Biederman 		.proc_handler	= proc_taint,
18851da177e4SLinus Torvalds 	},
1886f4aacea2SKees Cook 	{
1887f4aacea2SKees Cook 		.procname	= "sysctl_writes_strict",
1888f4aacea2SKees Cook 		.data		= &sysctl_writes_strict,
1889f4aacea2SKees Cook 		.maxlen		= sizeof(int),
1890f4aacea2SKees Cook 		.mode		= 0644,
1891f4aacea2SKees Cook 		.proc_handler	= proc_dointvec_minmax,
1892f4aacea2SKees Cook 		.extra1		= &neg_one,
1893eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
1894f4aacea2SKees Cook 	},
189534f5a398STheodore Ts'o #endif
18969745512cSArjan van de Ven #ifdef CONFIG_LATENCYTOP
18979745512cSArjan van de Ven 	{
18989745512cSArjan van de Ven 		.procname	= "latencytop",
18999745512cSArjan van de Ven 		.data		= &latencytop_enabled,
19009745512cSArjan van de Ven 		.maxlen		= sizeof(int),
19019745512cSArjan van de Ven 		.mode		= 0644,
1902cb251765SMel Gorman 		.proc_handler	= sysctl_latencytop,
19039745512cSArjan van de Ven 	},
19049745512cSArjan van de Ven #endif
19051da177e4SLinus Torvalds #ifdef CONFIG_BLK_DEV_INITRD
19061da177e4SLinus Torvalds 	{
19071da177e4SLinus Torvalds 		.procname	= "real-root-dev",
19081da177e4SLinus Torvalds 		.data		= &real_root_dev,
19091da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
19101da177e4SLinus Torvalds 		.mode		= 0644,
19116d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19121da177e4SLinus Torvalds 	},
19131da177e4SLinus Torvalds #endif
191445807a1dSIngo Molnar 	{
191545807a1dSIngo Molnar 		.procname	= "print-fatal-signals",
191645807a1dSIngo Molnar 		.data		= &print_fatal_signals,
191745807a1dSIngo Molnar 		.maxlen		= sizeof(int),
191845807a1dSIngo Molnar 		.mode		= 0644,
19196d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
192045807a1dSIngo Molnar 	},
192172c57ed5SDavid S. Miller #ifdef CONFIG_SPARC
19221da177e4SLinus Torvalds 	{
19231da177e4SLinus Torvalds 		.procname	= "reboot-cmd",
19241da177e4SLinus Torvalds 		.data		= reboot_command,
19251da177e4SLinus Torvalds 		.maxlen		= 256,
19261da177e4SLinus Torvalds 		.mode		= 0644,
19276d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
19281da177e4SLinus Torvalds 	},
19291da177e4SLinus Torvalds 	{
19301da177e4SLinus Torvalds 		.procname	= "stop-a",
19311da177e4SLinus Torvalds 		.data		= &stop_a_enabled,
19321da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
19331da177e4SLinus Torvalds 		.mode		= 0644,
19346d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19351da177e4SLinus Torvalds 	},
19361da177e4SLinus Torvalds 	{
19371da177e4SLinus Torvalds 		.procname	= "scons-poweroff",
19381da177e4SLinus Torvalds 		.data		= &scons_pwroff,
19391da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
19401da177e4SLinus Torvalds 		.mode		= 0644,
19416d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19421da177e4SLinus Torvalds 	},
19431da177e4SLinus Torvalds #endif
19440871420fSDavid S. Miller #ifdef CONFIG_SPARC64
19450871420fSDavid S. Miller 	{
19460871420fSDavid S. Miller 		.procname	= "tsb-ratio",
19470871420fSDavid S. Miller 		.data		= &sysctl_tsb_ratio,
19480871420fSDavid S. Miller 		.maxlen		= sizeof (int),
19490871420fSDavid S. Miller 		.mode		= 0644,
19506d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19510871420fSDavid S. Miller 	},
19520871420fSDavid S. Miller #endif
1953b67114dbSHelge Deller #ifdef CONFIG_PARISC
19541da177e4SLinus Torvalds 	{
19551da177e4SLinus Torvalds 		.procname	= "soft-power",
19561da177e4SLinus Torvalds 		.data		= &pwrsw_enabled,
19571da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
19581da177e4SLinus Torvalds 		.mode		= 0644,
19596d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19601da177e4SLinus Torvalds 	},
1961bf14e3b9SVineet Gupta #endif
1962bf14e3b9SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
19631da177e4SLinus Torvalds 	{
19641da177e4SLinus Torvalds 		.procname	= "unaligned-trap",
19651da177e4SLinus Torvalds 		.data		= &unaligned_enabled,
19661da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
19671da177e4SLinus Torvalds 		.mode		= 0644,
19686d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19691da177e4SLinus Torvalds 	},
19701da177e4SLinus Torvalds #endif
19711da177e4SLinus Torvalds 	{
19721da177e4SLinus Torvalds 		.procname	= "ctrl-alt-del",
19731da177e4SLinus Torvalds 		.data		= &C_A_D,
19741da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
19751da177e4SLinus Torvalds 		.mode		= 0644,
19766d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
19771da177e4SLinus Torvalds 	},
1978606576ceSSteven Rostedt #ifdef CONFIG_FUNCTION_TRACER
1979b0fc494fSSteven Rostedt 	{
1980b0fc494fSSteven Rostedt 		.procname	= "ftrace_enabled",
1981b0fc494fSSteven Rostedt 		.data		= &ftrace_enabled,
1982b0fc494fSSteven Rostedt 		.maxlen		= sizeof(int),
1983b0fc494fSSteven Rostedt 		.mode		= 0644,
19846d456111SEric W. Biederman 		.proc_handler	= ftrace_enable_sysctl,
1985b0fc494fSSteven Rostedt 	},
1986b0fc494fSSteven Rostedt #endif
1987f38f1d2aSSteven Rostedt #ifdef CONFIG_STACK_TRACER
1988f38f1d2aSSteven Rostedt 	{
1989f38f1d2aSSteven Rostedt 		.procname	= "stack_tracer_enabled",
1990f38f1d2aSSteven Rostedt 		.data		= &stack_tracer_enabled,
1991f38f1d2aSSteven Rostedt 		.maxlen		= sizeof(int),
1992f38f1d2aSSteven Rostedt 		.mode		= 0644,
19936d456111SEric W. Biederman 		.proc_handler	= stack_trace_sysctl,
1994f38f1d2aSSteven Rostedt 	},
1995f38f1d2aSSteven Rostedt #endif
1996944ac425SSteven Rostedt #ifdef CONFIG_TRACING
1997944ac425SSteven Rostedt 	{
19983299b4ddSPeter Zijlstra 		.procname	= "ftrace_dump_on_oops",
1999944ac425SSteven Rostedt 		.data		= &ftrace_dump_on_oops,
2000944ac425SSteven Rostedt 		.maxlen		= sizeof(int),
2001944ac425SSteven Rostedt 		.mode		= 0644,
20026d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2003944ac425SSteven Rostedt 	},
2004de7edd31SSteven Rostedt (Red Hat) 	{
2005de7edd31SSteven Rostedt (Red Hat) 		.procname	= "traceoff_on_warning",
2006de7edd31SSteven Rostedt (Red Hat) 		.data		= &__disable_trace_on_warning,
2007de7edd31SSteven Rostedt (Red Hat) 		.maxlen		= sizeof(__disable_trace_on_warning),
2008de7edd31SSteven Rostedt (Red Hat) 		.mode		= 0644,
2009de7edd31SSteven Rostedt (Red Hat) 		.proc_handler	= proc_dointvec,
2010de7edd31SSteven Rostedt (Red Hat) 	},
20110daa2302SSteven Rostedt (Red Hat) 	{
20120daa2302SSteven Rostedt (Red Hat) 		.procname	= "tracepoint_printk",
20130daa2302SSteven Rostedt (Red Hat) 		.data		= &tracepoint_printk,
20140daa2302SSteven Rostedt (Red Hat) 		.maxlen		= sizeof(tracepoint_printk),
20150daa2302SSteven Rostedt (Red Hat) 		.mode		= 0644,
201642391745SSteven Rostedt (Red Hat) 		.proc_handler	= tracepoint_printk_sysctl,
20170daa2302SSteven Rostedt (Red Hat) 	},
2018944ac425SSteven Rostedt #endif
20192965faa5SDave Young #ifdef CONFIG_KEXEC_CORE
20207984754bSKees Cook 	{
20217984754bSKees Cook 		.procname	= "kexec_load_disabled",
20227984754bSKees Cook 		.data		= &kexec_load_disabled,
20237984754bSKees Cook 		.maxlen		= sizeof(int),
20247984754bSKees Cook 		.mode		= 0644,
20257984754bSKees Cook 		/* only handle a transition from default "0" to "1" */
20267984754bSKees Cook 		.proc_handler	= proc_dointvec_minmax,
2027eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
2028eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
20297984754bSKees Cook 	},
20307984754bSKees Cook #endif
2031a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES
20321da177e4SLinus Torvalds 	{
20331da177e4SLinus Torvalds 		.procname	= "modprobe",
20341da177e4SLinus Torvalds 		.data		= &modprobe_path,
20351da177e4SLinus Torvalds 		.maxlen		= KMOD_PATH_LEN,
20361da177e4SLinus Torvalds 		.mode		= 0644,
20376d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
20381da177e4SLinus Torvalds 	},
20393d43321bSKees Cook 	{
20403d43321bSKees Cook 		.procname	= "modules_disabled",
20413d43321bSKees Cook 		.data		= &modules_disabled,
20423d43321bSKees Cook 		.maxlen		= sizeof(int),
20433d43321bSKees Cook 		.mode		= 0644,
20443d43321bSKees Cook 		/* only handle a transition from default "0" to "1" */
20456d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2046eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
2047eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
20483d43321bSKees Cook 	},
20491da177e4SLinus Torvalds #endif
205086d56134SMichael Marineau #ifdef CONFIG_UEVENT_HELPER
20511da177e4SLinus Torvalds 	{
20521da177e4SLinus Torvalds 		.procname	= "hotplug",
2053312c004dSKay Sievers 		.data		= &uevent_helper,
2054312c004dSKay Sievers 		.maxlen		= UEVENT_HELPER_PATH_LEN,
20551da177e4SLinus Torvalds 		.mode		= 0644,
20566d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
20571da177e4SLinus Torvalds 	},
205886d56134SMichael Marineau #endif
20591da177e4SLinus Torvalds #ifdef CONFIG_CHR_DEV_SG
20601da177e4SLinus Torvalds 	{
20611da177e4SLinus Torvalds 		.procname	= "sg-big-buff",
20621da177e4SLinus Torvalds 		.data		= &sg_big_buff,
20631da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
20641da177e4SLinus Torvalds 		.mode		= 0444,
20656d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
20661da177e4SLinus Torvalds 	},
20671da177e4SLinus Torvalds #endif
20681da177e4SLinus Torvalds #ifdef CONFIG_BSD_PROCESS_ACCT
20691da177e4SLinus Torvalds 	{
20701da177e4SLinus Torvalds 		.procname	= "acct",
20711da177e4SLinus Torvalds 		.data		= &acct_parm,
20721da177e4SLinus Torvalds 		.maxlen		= 3*sizeof(int),
20731da177e4SLinus Torvalds 		.mode		= 0644,
20746d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
20751da177e4SLinus Torvalds 	},
20761da177e4SLinus Torvalds #endif
20771da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ
20781da177e4SLinus Torvalds 	{
20791da177e4SLinus Torvalds 		.procname	= "sysrq",
2080eaee4172SDmitry Safonov 		.data		= NULL,
20811da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
20821da177e4SLinus Torvalds 		.mode		= 0644,
208397f5f0cdSDmitry Torokhov 		.proc_handler	= sysrq_sysctl_handler,
20841da177e4SLinus Torvalds 	},
20851da177e4SLinus Torvalds #endif
2086d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL
20871da177e4SLinus Torvalds 	{
20881da177e4SLinus Torvalds 		.procname	= "cad_pid",
20899ec52099SCedric Le Goater 		.data		= NULL,
20901da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
20911da177e4SLinus Torvalds 		.mode		= 0600,
20926d456111SEric W. Biederman 		.proc_handler	= proc_do_cad_pid,
20931da177e4SLinus Torvalds 	},
2094d6f8ff73SRandy Dunlap #endif
20951da177e4SLinus Torvalds 	{
20961da177e4SLinus Torvalds 		.procname	= "threads-max",
209716db3d3fSHeinrich Schuchardt 		.data		= NULL,
20981da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
20991da177e4SLinus Torvalds 		.mode		= 0644,
210016db3d3fSHeinrich Schuchardt 		.proc_handler	= sysctl_max_threads,
21011da177e4SLinus Torvalds 	},
21021da177e4SLinus Torvalds 	{
21031da177e4SLinus Torvalds 		.procname	= "random",
21041da177e4SLinus Torvalds 		.mode		= 0555,
21051da177e4SLinus Torvalds 		.child		= random_table,
21061da177e4SLinus Torvalds 	},
21071da177e4SLinus Torvalds 	{
210817f60a7dSEric Paris 		.procname	= "usermodehelper",
210917f60a7dSEric Paris 		.mode		= 0555,
211017f60a7dSEric Paris 		.child		= usermodehelper_table,
211117f60a7dSEric Paris 	},
2112ceb18132SLuis R. Rodriguez #ifdef CONFIG_FW_LOADER_USER_HELPER
2113ceb18132SLuis R. Rodriguez 	{
2114ceb18132SLuis R. Rodriguez 		.procname	= "firmware_config",
2115ceb18132SLuis R. Rodriguez 		.mode		= 0555,
2116ceb18132SLuis R. Rodriguez 		.child		= firmware_config_table,
2117ceb18132SLuis R. Rodriguez 	},
2118ceb18132SLuis R. Rodriguez #endif
211917f60a7dSEric Paris 	{
21201da177e4SLinus Torvalds 		.procname	= "overflowuid",
21211da177e4SLinus Torvalds 		.data		= &overflowuid,
21221da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21231da177e4SLinus Torvalds 		.mode		= 0644,
21246d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
21251da177e4SLinus Torvalds 		.extra1		= &minolduid,
21261da177e4SLinus Torvalds 		.extra2		= &maxolduid,
21271da177e4SLinus Torvalds 	},
21281da177e4SLinus Torvalds 	{
21291da177e4SLinus Torvalds 		.procname	= "overflowgid",
21301da177e4SLinus Torvalds 		.data		= &overflowgid,
21311da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21321da177e4SLinus Torvalds 		.mode		= 0644,
21336d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
21341da177e4SLinus Torvalds 		.extra1		= &minolduid,
21351da177e4SLinus Torvalds 		.extra2		= &maxolduid,
21361da177e4SLinus Torvalds 	},
2137347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390
21381da177e4SLinus Torvalds 	{
21391da177e4SLinus Torvalds 		.procname	= "userprocess_debug",
2140ab3c68eeSHeiko Carstens 		.data		= &show_unhandled_signals,
21411da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21421da177e4SLinus Torvalds 		.mode		= 0644,
21436d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
21441da177e4SLinus Torvalds 	},
21451da177e4SLinus Torvalds #endif
214660c958d8SGuilherme G. Piccoli #ifdef CONFIG_SMP
214760c958d8SGuilherme G. Piccoli 	{
214860c958d8SGuilherme G. Piccoli 		.procname	= "oops_all_cpu_backtrace",
214960c958d8SGuilherme G. Piccoli 		.data		= &sysctl_oops_all_cpu_backtrace,
215060c958d8SGuilherme G. Piccoli 		.maxlen		= sizeof(int),
215160c958d8SGuilherme G. Piccoli 		.mode		= 0644,
215260c958d8SGuilherme G. Piccoli 		.proc_handler	= proc_dointvec_minmax,
215360c958d8SGuilherme G. Piccoli 		.extra1		= SYSCTL_ZERO,
215460c958d8SGuilherme G. Piccoli 		.extra2		= SYSCTL_ONE,
215560c958d8SGuilherme G. Piccoli 	},
215660c958d8SGuilherme G. Piccoli #endif /* CONFIG_SMP */
21571da177e4SLinus Torvalds 	{
21581da177e4SLinus Torvalds 		.procname	= "pid_max",
21591da177e4SLinus Torvalds 		.data		= &pid_max,
21601da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
21611da177e4SLinus Torvalds 		.mode		= 0644,
21626d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
21631da177e4SLinus Torvalds 		.extra1		= &pid_max_min,
21641da177e4SLinus Torvalds 		.extra2		= &pid_max_max,
21651da177e4SLinus Torvalds 	},
21661da177e4SLinus Torvalds 	{
21671da177e4SLinus Torvalds 		.procname	= "panic_on_oops",
21681da177e4SLinus Torvalds 		.data		= &panic_on_oops,
21691da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21701da177e4SLinus Torvalds 		.mode		= 0644,
21716d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
21721da177e4SLinus Torvalds 	},
217381c9d43fSFeng Tang 	{
217481c9d43fSFeng Tang 		.procname	= "panic_print",
217581c9d43fSFeng Tang 		.data		= &panic_print,
217681c9d43fSFeng Tang 		.maxlen		= sizeof(unsigned long),
217781c9d43fSFeng Tang 		.mode		= 0644,
217881c9d43fSFeng Tang 		.proc_handler	= proc_doulongvec_minmax,
217981c9d43fSFeng Tang 	},
21807ef3d2fdSJoe Perches #if defined CONFIG_PRINTK
21817ef3d2fdSJoe Perches 	{
21827ef3d2fdSJoe Perches 		.procname	= "printk",
21837ef3d2fdSJoe Perches 		.data		= &console_loglevel,
21847ef3d2fdSJoe Perches 		.maxlen		= 4*sizeof(int),
21857ef3d2fdSJoe Perches 		.mode		= 0644,
21866d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
21877ef3d2fdSJoe Perches 	},
21881da177e4SLinus Torvalds 	{
21891da177e4SLinus Torvalds 		.procname	= "printk_ratelimit",
2190717115e1SDave Young 		.data		= &printk_ratelimit_state.interval,
21911da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21921da177e4SLinus Torvalds 		.mode		= 0644,
21936d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_jiffies,
21941da177e4SLinus Torvalds 	},
21951da177e4SLinus Torvalds 	{
21961da177e4SLinus Torvalds 		.procname	= "printk_ratelimit_burst",
2197717115e1SDave Young 		.data		= &printk_ratelimit_state.burst,
21981da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
21991da177e4SLinus Torvalds 		.mode		= 0644,
22006d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
22011da177e4SLinus Torvalds 	},
2202af91322eSDave Young 	{
2203af91322eSDave Young 		.procname	= "printk_delay",
2204af91322eSDave Young 		.data		= &printk_delay_msec,
2205af91322eSDave Young 		.maxlen		= sizeof(int),
2206af91322eSDave Young 		.mode		= 0644,
22076d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2208eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2209af91322eSDave Young 		.extra2		= &ten_thousand,
2210af91322eSDave Young 	},
22111da177e4SLinus Torvalds 	{
2212750afe7bSBorislav Petkov 		.procname	= "printk_devkmsg",
2213750afe7bSBorislav Petkov 		.data		= devkmsg_log_str,
2214750afe7bSBorislav Petkov 		.maxlen		= DEVKMSG_STR_MAX_SIZE,
2215750afe7bSBorislav Petkov 		.mode		= 0644,
2216750afe7bSBorislav Petkov 		.proc_handler	= devkmsg_sysctl_set_loglvl,
2217750afe7bSBorislav Petkov 	},
2218750afe7bSBorislav Petkov 	{
2219eaf06b24SDan Rosenberg 		.procname	= "dmesg_restrict",
2220eaf06b24SDan Rosenberg 		.data		= &dmesg_restrict,
2221eaf06b24SDan Rosenberg 		.maxlen		= sizeof(int),
2222eaf06b24SDan Rosenberg 		.mode		= 0644,
2223620f6e8eSKees Cook 		.proc_handler	= proc_dointvec_minmax_sysadmin,
2224eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2225eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2226eaf06b24SDan Rosenberg 	},
2227455cd5abSDan Rosenberg 	{
2228455cd5abSDan Rosenberg 		.procname	= "kptr_restrict",
2229455cd5abSDan Rosenberg 		.data		= &kptr_restrict,
2230455cd5abSDan Rosenberg 		.maxlen		= sizeof(int),
2231455cd5abSDan Rosenberg 		.mode		= 0644,
2232620f6e8eSKees Cook 		.proc_handler	= proc_dointvec_minmax_sysadmin,
2233eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2234455cd5abSDan Rosenberg 		.extra2		= &two,
2235455cd5abSDan Rosenberg 	},
2236df6e61d4SJoe Perches #endif
2237eaf06b24SDan Rosenberg 	{
22381da177e4SLinus Torvalds 		.procname	= "ngroups_max",
22391da177e4SLinus Torvalds 		.data		= &ngroups_max,
22401da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
22411da177e4SLinus Torvalds 		.mode		= 0444,
22426d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
22431da177e4SLinus Torvalds 	},
224473efc039SDan Ballard 	{
224573efc039SDan Ballard 		.procname	= "cap_last_cap",
224673efc039SDan Ballard 		.data		= (void *)&cap_last_cap,
224773efc039SDan Ballard 		.maxlen		= sizeof(int),
224873efc039SDan Ballard 		.mode		= 0444,
224973efc039SDan Ballard 		.proc_handler	= proc_dointvec,
225073efc039SDan Ballard 	},
225158687acbSDon Zickus #if defined(CONFIG_LOCKUP_DETECTOR)
2252504d7cf1SDon Zickus 	{
225358687acbSDon Zickus 		.procname       = "watchdog",
22543c00ea82SFrederic Weisbecker 		.data		= &watchdog_user_enabled,
2255504d7cf1SDon Zickus 		.maxlen		= sizeof(int),
2256504d7cf1SDon Zickus 		.mode		= 0644,
2257195daf66SUlrich Obergfell 		.proc_handler   = proc_watchdog,
2258eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2259eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
226058687acbSDon Zickus 	},
226158687acbSDon Zickus 	{
226258687acbSDon Zickus 		.procname	= "watchdog_thresh",
2263586692a5SMandeep Singh Baines 		.data		= &watchdog_thresh,
226458687acbSDon Zickus 		.maxlen		= sizeof(int),
226558687acbSDon Zickus 		.mode		= 0644,
2266195daf66SUlrich Obergfell 		.proc_handler	= proc_watchdog_thresh,
2267eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
226858687acbSDon Zickus 		.extra2		= &sixty,
2269504d7cf1SDon Zickus 	},
22702508ce18SDon Zickus 	{
2271195daf66SUlrich Obergfell 		.procname       = "nmi_watchdog",
22727feeb9cdSThomas Gleixner 		.data		= &nmi_watchdog_user_enabled,
2273195daf66SUlrich Obergfell 		.maxlen		= sizeof(int),
227451d4052bSThomas Gleixner 		.mode		= NMI_WATCHDOG_SYSCTL_PERM,
2275195daf66SUlrich Obergfell 		.proc_handler   = proc_nmi_watchdog,
2276eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2277eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2278195daf66SUlrich Obergfell 	},
2279195daf66SUlrich Obergfell 	{
228005a4a952SNicholas Piggin 		.procname	= "watchdog_cpumask",
228105a4a952SNicholas Piggin 		.data		= &watchdog_cpumask_bits,
228205a4a952SNicholas Piggin 		.maxlen		= NR_CPUS,
228305a4a952SNicholas Piggin 		.mode		= 0644,
228405a4a952SNicholas Piggin 		.proc_handler	= proc_watchdog_cpumask,
228505a4a952SNicholas Piggin 	},
228605a4a952SNicholas Piggin #ifdef CONFIG_SOFTLOCKUP_DETECTOR
228705a4a952SNicholas Piggin 	{
2288195daf66SUlrich Obergfell 		.procname       = "soft_watchdog",
22897feeb9cdSThomas Gleixner 		.data		= &soft_watchdog_user_enabled,
2290195daf66SUlrich Obergfell 		.maxlen		= sizeof(int),
2291195daf66SUlrich Obergfell 		.mode		= 0644,
2292195daf66SUlrich Obergfell 		.proc_handler   = proc_soft_watchdog,
2293eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2294eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2295195daf66SUlrich Obergfell 	},
2296195daf66SUlrich Obergfell 	{
22972508ce18SDon Zickus 		.procname	= "softlockup_panic",
22982508ce18SDon Zickus 		.data		= &softlockup_panic,
22992508ce18SDon Zickus 		.maxlen		= sizeof(int),
23002508ce18SDon Zickus 		.mode		= 0644,
23012508ce18SDon Zickus 		.proc_handler	= proc_dointvec_minmax,
2302eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2303eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
23042508ce18SDon Zickus 	},
2305ed235875SAaron Tomlin #ifdef CONFIG_SMP
2306ed235875SAaron Tomlin 	{
2307ed235875SAaron Tomlin 		.procname	= "softlockup_all_cpu_backtrace",
2308ed235875SAaron Tomlin 		.data		= &sysctl_softlockup_all_cpu_backtrace,
2309ed235875SAaron Tomlin 		.maxlen		= sizeof(int),
2310ed235875SAaron Tomlin 		.mode		= 0644,
2311ed235875SAaron Tomlin 		.proc_handler	= proc_dointvec_minmax,
2312eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2313eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2314ed235875SAaron Tomlin 	},
231505a4a952SNicholas Piggin #endif /* CONFIG_SMP */
231605a4a952SNicholas Piggin #endif
231705a4a952SNicholas Piggin #ifdef CONFIG_HARDLOCKUP_DETECTOR
231805a4a952SNicholas Piggin 	{
231905a4a952SNicholas Piggin 		.procname	= "hardlockup_panic",
232005a4a952SNicholas Piggin 		.data		= &hardlockup_panic,
232105a4a952SNicholas Piggin 		.maxlen		= sizeof(int),
232205a4a952SNicholas Piggin 		.mode		= 0644,
232305a4a952SNicholas Piggin 		.proc_handler	= proc_dointvec_minmax,
2324eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2325eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
232605a4a952SNicholas Piggin 	},
232705a4a952SNicholas Piggin #ifdef CONFIG_SMP
232855537871SJiri Kosina 	{
232955537871SJiri Kosina 		.procname	= "hardlockup_all_cpu_backtrace",
233055537871SJiri Kosina 		.data		= &sysctl_hardlockup_all_cpu_backtrace,
233155537871SJiri Kosina 		.maxlen		= sizeof(int),
233255537871SJiri Kosina 		.mode		= 0644,
233355537871SJiri Kosina 		.proc_handler	= proc_dointvec_minmax,
2334eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2335eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
233655537871SJiri Kosina 	},
2337ed235875SAaron Tomlin #endif /* CONFIG_SMP */
23385dc30558SDon Zickus #endif
233905a4a952SNicholas Piggin #endif
234005a4a952SNicholas Piggin 
23415dc30558SDon Zickus #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
23425dc30558SDon Zickus 	{
23435dc30558SDon Zickus 		.procname       = "unknown_nmi_panic",
23445dc30558SDon Zickus 		.data           = &unknown_nmi_panic,
23455dc30558SDon Zickus 		.maxlen         = sizeof (int),
23465dc30558SDon Zickus 		.mode           = 0644,
23475dc30558SDon Zickus 		.proc_handler   = proc_dointvec,
23485dc30558SDon Zickus 	},
2349504d7cf1SDon Zickus #endif
2350b6522fa4SXiaoming Ni 
2351b6522fa4SXiaoming Ni #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
2352b6522fa4SXiaoming Ni 	defined(CONFIG_DEBUG_STACKOVERFLOW)
2353b6522fa4SXiaoming Ni 	{
2354b6522fa4SXiaoming Ni 		.procname	= "panic_on_stackoverflow",
2355b6522fa4SXiaoming Ni 		.data		= &sysctl_panic_on_stackoverflow,
2356b6522fa4SXiaoming Ni 		.maxlen		= sizeof(int),
2357b6522fa4SXiaoming Ni 		.mode		= 0644,
2358b6522fa4SXiaoming Ni 		.proc_handler	= proc_dointvec,
2359b6522fa4SXiaoming Ni 	},
2360b6522fa4SXiaoming Ni #endif
23611da177e4SLinus Torvalds #if defined(CONFIG_X86)
23621da177e4SLinus Torvalds 	{
23638da5addaSDon Zickus 		.procname	= "panic_on_unrecovered_nmi",
23648da5addaSDon Zickus 		.data		= &panic_on_unrecovered_nmi,
23658da5addaSDon Zickus 		.maxlen		= sizeof(int),
23668da5addaSDon Zickus 		.mode		= 0644,
23676d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23688da5addaSDon Zickus 	},
23698da5addaSDon Zickus 	{
23705211a242SKurt Garloff 		.procname	= "panic_on_io_nmi",
23715211a242SKurt Garloff 		.data		= &panic_on_io_nmi,
23725211a242SKurt Garloff 		.maxlen		= sizeof(int),
23735211a242SKurt Garloff 		.mode		= 0644,
23746d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23755211a242SKurt Garloff 	},
23765211a242SKurt Garloff 	{
23771da177e4SLinus Torvalds 		.procname	= "bootloader_type",
23781da177e4SLinus Torvalds 		.data		= &bootloader_type,
23791da177e4SLinus Torvalds 		.maxlen		= sizeof (int),
23801da177e4SLinus Torvalds 		.mode		= 0444,
23816d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23821da177e4SLinus Torvalds 	},
23830741f4d2SChuck Ebbert 	{
23845031296cSH. Peter Anvin 		.procname	= "bootloader_version",
23855031296cSH. Peter Anvin 		.data		= &bootloader_version,
23865031296cSH. Peter Anvin 		.maxlen		= sizeof (int),
23875031296cSH. Peter Anvin 		.mode		= 0444,
23886d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23895031296cSH. Peter Anvin 	},
23905031296cSH. Peter Anvin 	{
23916e7c4025SIngo Molnar 		.procname	= "io_delay_type",
23926e7c4025SIngo Molnar 		.data		= &io_delay_type,
23936e7c4025SIngo Molnar 		.maxlen		= sizeof(int),
23946e7c4025SIngo Molnar 		.mode		= 0644,
23956d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
23966e7c4025SIngo Molnar 	},
23971da177e4SLinus Torvalds #endif
23987a9166e3SLuke Yang #if defined(CONFIG_MMU)
23991da177e4SLinus Torvalds 	{
24001da177e4SLinus Torvalds 		.procname	= "randomize_va_space",
24011da177e4SLinus Torvalds 		.data		= &randomize_va_space,
24021da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
24031da177e4SLinus Torvalds 		.mode		= 0644,
24046d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
24051da177e4SLinus Torvalds 	},
24067a9166e3SLuke Yang #endif
24070152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP)
2408951f22d5SMartin Schwidefsky 	{
2409951f22d5SMartin Schwidefsky 		.procname	= "spin_retry",
2410951f22d5SMartin Schwidefsky 		.data		= &spin_retry,
2411951f22d5SMartin Schwidefsky 		.maxlen		= sizeof (int),
2412951f22d5SMartin Schwidefsky 		.mode		= 0644,
24136d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2414951f22d5SMartin Schwidefsky 	},
2415951f22d5SMartin Schwidefsky #endif
2416673d5b43SLen Brown #if	defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
2417c255d844SPavel Machek 	{
2418c255d844SPavel Machek 		.procname	= "acpi_video_flags",
241977afcf78SPavel Machek 		.data		= &acpi_realmode_flags,
2420c255d844SPavel Machek 		.maxlen		= sizeof (unsigned long),
2421c255d844SPavel Machek 		.mode		= 0644,
24226d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
2423c255d844SPavel Machek 	},
2424c255d844SPavel Machek #endif
2425b6fca725SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
2426d2b176edSJes Sorensen 	{
2427d2b176edSJes Sorensen 		.procname	= "ignore-unaligned-usertrap",
2428d2b176edSJes Sorensen 		.data		= &no_unaligned_warning,
2429d2b176edSJes Sorensen 		.maxlen		= sizeof (int),
2430d2b176edSJes Sorensen 		.mode		= 0644,
24316d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2432d2b176edSJes Sorensen 	},
2433b6fca725SVineet Gupta #endif
2434b6fca725SVineet Gupta #ifdef CONFIG_IA64
243588fc241fSDoug Chapman 	{
243688fc241fSDoug Chapman 		.procname	= "unaligned-dump-stack",
243788fc241fSDoug Chapman 		.data		= &unaligned_dump_stack,
243888fc241fSDoug Chapman 		.maxlen		= sizeof (int),
243988fc241fSDoug Chapman 		.mode		= 0644,
24406d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
244188fc241fSDoug Chapman 	},
2442d2b176edSJes Sorensen #endif
2443e162b39aSMandeep Singh Baines #ifdef CONFIG_DETECT_HUNG_TASK
24440ec9dc9bSGuilherme G. Piccoli #ifdef CONFIG_SMP
24450ec9dc9bSGuilherme G. Piccoli 	{
24460ec9dc9bSGuilherme G. Piccoli 		.procname	= "hung_task_all_cpu_backtrace",
24470ec9dc9bSGuilherme G. Piccoli 		.data		= &sysctl_hung_task_all_cpu_backtrace,
24480ec9dc9bSGuilherme G. Piccoli 		.maxlen		= sizeof(int),
24490ec9dc9bSGuilherme G. Piccoli 		.mode		= 0644,
24500ec9dc9bSGuilherme G. Piccoli 		.proc_handler	= proc_dointvec_minmax,
24510ec9dc9bSGuilherme G. Piccoli 		.extra1		= SYSCTL_ZERO,
24520ec9dc9bSGuilherme G. Piccoli 		.extra2		= SYSCTL_ONE,
24530ec9dc9bSGuilherme G. Piccoli 	},
24540ec9dc9bSGuilherme G. Piccoli #endif /* CONFIG_SMP */
2455e162b39aSMandeep Singh Baines 	{
2456e162b39aSMandeep Singh Baines 		.procname	= "hung_task_panic",
2457e162b39aSMandeep Singh Baines 		.data		= &sysctl_hung_task_panic,
2458e162b39aSMandeep Singh Baines 		.maxlen		= sizeof(int),
2459e162b39aSMandeep Singh Baines 		.mode		= 0644,
24606d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2461eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2462eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2463e162b39aSMandeep Singh Baines 	},
246482a1fcb9SIngo Molnar 	{
246582a1fcb9SIngo Molnar 		.procname	= "hung_task_check_count",
246682a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_check_count,
2467cd64647fSLi Zefan 		.maxlen		= sizeof(int),
246882a1fcb9SIngo Molnar 		.mode		= 0644,
2469cd64647fSLi Zefan 		.proc_handler	= proc_dointvec_minmax,
2470eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
247182a1fcb9SIngo Molnar 	},
247282a1fcb9SIngo Molnar 	{
247382a1fcb9SIngo Molnar 		.procname	= "hung_task_timeout_secs",
247482a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_timeout_secs,
247590739081SIngo Molnar 		.maxlen		= sizeof(unsigned long),
247682a1fcb9SIngo Molnar 		.mode		= 0644,
24776d456111SEric W. Biederman 		.proc_handler	= proc_dohung_task_timeout_secs,
247880df2847SLiu Hua 		.extra2		= &hung_task_timeout_max,
247982a1fcb9SIngo Molnar 	},
248082a1fcb9SIngo Molnar 	{
2481a2e51445SDmitry Vyukov 		.procname	= "hung_task_check_interval_secs",
2482a2e51445SDmitry Vyukov 		.data		= &sysctl_hung_task_check_interval_secs,
2483a2e51445SDmitry Vyukov 		.maxlen		= sizeof(unsigned long),
2484a2e51445SDmitry Vyukov 		.mode		= 0644,
2485a2e51445SDmitry Vyukov 		.proc_handler	= proc_dohung_task_timeout_secs,
2486a2e51445SDmitry Vyukov 		.extra2		= &hung_task_timeout_max,
2487a2e51445SDmitry Vyukov 	},
2488a2e51445SDmitry Vyukov 	{
248982a1fcb9SIngo Molnar 		.procname	= "hung_task_warnings",
249082a1fcb9SIngo Molnar 		.data		= &sysctl_hung_task_warnings,
2491270750dbSAaron Tomlin 		.maxlen		= sizeof(int),
249282a1fcb9SIngo Molnar 		.mode		= 0644,
2493270750dbSAaron Tomlin 		.proc_handler	= proc_dointvec_minmax,
2494270750dbSAaron Tomlin 		.extra1		= &neg_one,
249582a1fcb9SIngo Molnar 	},
2496c4f3b63fSRavikiran G Thirumalai #endif
249723f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES
249823f78d4aSIngo Molnar 	{
249923f78d4aSIngo Molnar 		.procname	= "max_lock_depth",
250023f78d4aSIngo Molnar 		.data		= &max_lock_depth,
250123f78d4aSIngo Molnar 		.maxlen		= sizeof(int),
250223f78d4aSIngo Molnar 		.mode		= 0644,
25036d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
250423f78d4aSIngo Molnar 	},
250523f78d4aSIngo Molnar #endif
250610a0a8d4SJeremy Fitzhardinge 	{
250710a0a8d4SJeremy Fitzhardinge 		.procname	= "poweroff_cmd",
250810a0a8d4SJeremy Fitzhardinge 		.data		= &poweroff_cmd,
250910a0a8d4SJeremy Fitzhardinge 		.maxlen		= POWEROFF_CMD_PATH_LEN,
251010a0a8d4SJeremy Fitzhardinge 		.mode		= 0644,
25116d456111SEric W. Biederman 		.proc_handler	= proc_dostring,
251210a0a8d4SJeremy Fitzhardinge 	},
25130b77f5bfSDavid Howells #ifdef CONFIG_KEYS
25140b77f5bfSDavid Howells 	{
25150b77f5bfSDavid Howells 		.procname	= "keys",
25160b77f5bfSDavid Howells 		.mode		= 0555,
25170b77f5bfSDavid Howells 		.child		= key_sysctls,
25180b77f5bfSDavid Howells 	},
25190b77f5bfSDavid Howells #endif
2520cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS
2521aa4a2218SVince Weaver 	/*
2522aa4a2218SVince Weaver 	 * User-space scripts rely on the existence of this file
2523aa4a2218SVince Weaver 	 * as a feature check for perf_events being enabled.
2524aa4a2218SVince Weaver 	 *
2525aa4a2218SVince Weaver 	 * So it's an ABI, do not remove!
2526aa4a2218SVince Weaver 	 */
25271ccd1549SPeter Zijlstra 	{
2528cdd6c482SIngo Molnar 		.procname	= "perf_event_paranoid",
2529cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_paranoid,
2530cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_paranoid),
25311ccd1549SPeter Zijlstra 		.mode		= 0644,
25326d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
25331ccd1549SPeter Zijlstra 	},
2534c5078f78SPeter Zijlstra 	{
2535cdd6c482SIngo Molnar 		.procname	= "perf_event_mlock_kb",
2536cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_mlock,
2537cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_mlock),
2538c5078f78SPeter Zijlstra 		.mode		= 0644,
25396d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2540c5078f78SPeter Zijlstra 	},
2541a78ac325SPeter Zijlstra 	{
2542cdd6c482SIngo Molnar 		.procname	= "perf_event_max_sample_rate",
2543cdd6c482SIngo Molnar 		.data		= &sysctl_perf_event_sample_rate,
2544cdd6c482SIngo Molnar 		.maxlen		= sizeof(sysctl_perf_event_sample_rate),
2545a78ac325SPeter Zijlstra 		.mode		= 0644,
2546163ec435SPeter Zijlstra 		.proc_handler	= perf_proc_update_handler,
2547eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
2548a78ac325SPeter Zijlstra 	},
254914c63f17SDave Hansen 	{
255014c63f17SDave Hansen 		.procname	= "perf_cpu_time_max_percent",
255114c63f17SDave Hansen 		.data		= &sysctl_perf_cpu_time_max_percent,
255214c63f17SDave Hansen 		.maxlen		= sizeof(sysctl_perf_cpu_time_max_percent),
255314c63f17SDave Hansen 		.mode		= 0644,
255414c63f17SDave Hansen 		.proc_handler	= perf_cpu_time_max_percent_handler,
2555eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
255614c63f17SDave Hansen 		.extra2		= &one_hundred,
255714c63f17SDave Hansen 	},
2558c5dfd78eSArnaldo Carvalho de Melo 	{
2559c5dfd78eSArnaldo Carvalho de Melo 		.procname	= "perf_event_max_stack",
2560a831100aSArnaldo Carvalho de Melo 		.data		= &sysctl_perf_event_max_stack,
2561c5dfd78eSArnaldo Carvalho de Melo 		.maxlen		= sizeof(sysctl_perf_event_max_stack),
2562c5dfd78eSArnaldo Carvalho de Melo 		.mode		= 0644,
2563c5dfd78eSArnaldo Carvalho de Melo 		.proc_handler	= perf_event_max_stack_handler,
2564eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2565c5dfd78eSArnaldo Carvalho de Melo 		.extra2		= &six_hundred_forty_kb,
2566c5dfd78eSArnaldo Carvalho de Melo 	},
2567c85b0334SArnaldo Carvalho de Melo 	{
2568c85b0334SArnaldo Carvalho de Melo 		.procname	= "perf_event_max_contexts_per_stack",
2569c85b0334SArnaldo Carvalho de Melo 		.data		= &sysctl_perf_event_max_contexts_per_stack,
2570c85b0334SArnaldo Carvalho de Melo 		.maxlen		= sizeof(sysctl_perf_event_max_contexts_per_stack),
2571c85b0334SArnaldo Carvalho de Melo 		.mode		= 0644,
2572c85b0334SArnaldo Carvalho de Melo 		.proc_handler	= perf_event_max_stack_handler,
2573eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2574c85b0334SArnaldo Carvalho de Melo 		.extra2		= &one_thousand,
2575c85b0334SArnaldo Carvalho de Melo 	},
25761ccd1549SPeter Zijlstra #endif
25779e3961a0SPrarit Bhargava 	{
25789e3961a0SPrarit Bhargava 		.procname	= "panic_on_warn",
25799e3961a0SPrarit Bhargava 		.data		= &panic_on_warn,
25809e3961a0SPrarit Bhargava 		.maxlen		= sizeof(int),
25819e3961a0SPrarit Bhargava 		.mode		= 0644,
25829e3961a0SPrarit Bhargava 		.proc_handler	= proc_dointvec_minmax,
2583eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2584eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
25859e3961a0SPrarit Bhargava 	},
2586bc7a34b8SThomas Gleixner #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
2587bc7a34b8SThomas Gleixner 	{
2588bc7a34b8SThomas Gleixner 		.procname	= "timer_migration",
2589bc7a34b8SThomas Gleixner 		.data		= &sysctl_timer_migration,
2590bc7a34b8SThomas Gleixner 		.maxlen		= sizeof(unsigned int),
2591bc7a34b8SThomas Gleixner 		.mode		= 0644,
2592bc7a34b8SThomas Gleixner 		.proc_handler	= timer_migration_handler,
2593eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2594eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2595bc7a34b8SThomas Gleixner 	},
2596bc7a34b8SThomas Gleixner #endif
25971be7f75dSAlexei Starovoitov #ifdef CONFIG_BPF_SYSCALL
25981be7f75dSAlexei Starovoitov 	{
25991be7f75dSAlexei Starovoitov 		.procname	= "unprivileged_bpf_disabled",
26001be7f75dSAlexei Starovoitov 		.data		= &sysctl_unprivileged_bpf_disabled,
26011be7f75dSAlexei Starovoitov 		.maxlen		= sizeof(sysctl_unprivileged_bpf_disabled),
26021be7f75dSAlexei Starovoitov 		.mode		= 0644,
26031be7f75dSAlexei Starovoitov 		/* only handle a transition from default "0" to "1" */
26041be7f75dSAlexei Starovoitov 		.proc_handler	= proc_dointvec_minmax,
2605eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
2606eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
26071be7f75dSAlexei Starovoitov 	},
2608492ecee8SAlexei Starovoitov 	{
2609492ecee8SAlexei Starovoitov 		.procname	= "bpf_stats_enabled",
2610a8e11e5cSEric Dumazet 		.data		= &bpf_stats_enabled_key.key,
2611a8e11e5cSEric Dumazet 		.maxlen		= sizeof(bpf_stats_enabled_key),
2612492ecee8SAlexei Starovoitov 		.mode		= 0644,
2613d46edd67SSong Liu 		.proc_handler	= bpf_stats_handler,
2614492ecee8SAlexei Starovoitov 	},
26153fcc5530SAlexei Starovoitov #endif
2616b3e627d3SLai Jiangshan #if defined(CONFIG_TREE_RCU)
2617088e9d25SDaniel Bristot de Oliveira 	{
2618088e9d25SDaniel Bristot de Oliveira 		.procname	= "panic_on_rcu_stall",
2619088e9d25SDaniel Bristot de Oliveira 		.data		= &sysctl_panic_on_rcu_stall,
2620088e9d25SDaniel Bristot de Oliveira 		.maxlen		= sizeof(sysctl_panic_on_rcu_stall),
2621088e9d25SDaniel Bristot de Oliveira 		.mode		= 0644,
2622088e9d25SDaniel Bristot de Oliveira 		.proc_handler	= proc_dointvec_minmax,
2623eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2624eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2625088e9d25SDaniel Bristot de Oliveira 	},
2626088e9d25SDaniel Bristot de Oliveira #endif
2627dfe56404Schao #if defined(CONFIG_TREE_RCU)
2628dfe56404Schao 	{
2629dfe56404Schao 		.procname	= "max_rcu_stall_to_panic",
2630dfe56404Schao 		.data		= &sysctl_max_rcu_stall_to_panic,
2631dfe56404Schao 		.maxlen		= sizeof(sysctl_max_rcu_stall_to_panic),
2632dfe56404Schao 		.mode		= 0644,
2633dfe56404Schao 		.proc_handler	= proc_dointvec_minmax,
2634dfe56404Schao 		.extra1		= SYSCTL_ONE,
2635dfe56404Schao 		.extra2		= SYSCTL_INT_MAX,
2636dfe56404Schao 	},
2637dfe56404Schao #endif
2638964c9dffSAlexander Popov #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
2639964c9dffSAlexander Popov 	{
2640964c9dffSAlexander Popov 		.procname	= "stack_erasing",
2641964c9dffSAlexander Popov 		.data		= NULL,
2642964c9dffSAlexander Popov 		.maxlen		= sizeof(int),
2643964c9dffSAlexander Popov 		.mode		= 0600,
2644964c9dffSAlexander Popov 		.proc_handler	= stack_erasing_sysctl,
2645eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2646eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
2647964c9dffSAlexander Popov 	},
2648964c9dffSAlexander Popov #endif
26496fce56ecSEric W. Biederman 	{ }
26501da177e4SLinus Torvalds };
26511da177e4SLinus Torvalds 
2652d8217f07SEric W. Biederman static struct ctl_table vm_table[] = {
26531da177e4SLinus Torvalds 	{
26541da177e4SLinus Torvalds 		.procname	= "overcommit_memory",
26551da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_memory,
26561da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_memory),
26571da177e4SLinus Torvalds 		.mode		= 0644,
265856f3547bSFeng Tang 		.proc_handler	= overcommit_policy_handler,
2659eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2660cb16e95fSPetr Holasek 		.extra2		= &two,
26611da177e4SLinus Torvalds 	},
26621da177e4SLinus Torvalds 	{
2663fadd8fbdSKAMEZAWA Hiroyuki 		.procname	= "panic_on_oom",
2664fadd8fbdSKAMEZAWA Hiroyuki 		.data		= &sysctl_panic_on_oom,
2665fadd8fbdSKAMEZAWA Hiroyuki 		.maxlen		= sizeof(sysctl_panic_on_oom),
2666fadd8fbdSKAMEZAWA Hiroyuki 		.mode		= 0644,
2667cb16e95fSPetr Holasek 		.proc_handler	= proc_dointvec_minmax,
2668eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2669cb16e95fSPetr Holasek 		.extra2		= &two,
2670fadd8fbdSKAMEZAWA Hiroyuki 	},
2671fadd8fbdSKAMEZAWA Hiroyuki 	{
2672fe071d7eSDavid Rientjes 		.procname	= "oom_kill_allocating_task",
2673fe071d7eSDavid Rientjes 		.data		= &sysctl_oom_kill_allocating_task,
2674fe071d7eSDavid Rientjes 		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
2675fe071d7eSDavid Rientjes 		.mode		= 0644,
26766d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2677fe071d7eSDavid Rientjes 	},
2678fe071d7eSDavid Rientjes 	{
2679fef1bdd6SDavid Rientjes 		.procname	= "oom_dump_tasks",
2680fef1bdd6SDavid Rientjes 		.data		= &sysctl_oom_dump_tasks,
2681fef1bdd6SDavid Rientjes 		.maxlen		= sizeof(sysctl_oom_dump_tasks),
2682fef1bdd6SDavid Rientjes 		.mode		= 0644,
26836d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
2684fef1bdd6SDavid Rientjes 	},
2685fef1bdd6SDavid Rientjes 	{
26861da177e4SLinus Torvalds 		.procname	= "overcommit_ratio",
26871da177e4SLinus Torvalds 		.data		= &sysctl_overcommit_ratio,
26881da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_overcommit_ratio),
26891da177e4SLinus Torvalds 		.mode		= 0644,
269049f0ce5fSJerome Marchand 		.proc_handler	= overcommit_ratio_handler,
269149f0ce5fSJerome Marchand 	},
269249f0ce5fSJerome Marchand 	{
269349f0ce5fSJerome Marchand 		.procname	= "overcommit_kbytes",
269449f0ce5fSJerome Marchand 		.data		= &sysctl_overcommit_kbytes,
269549f0ce5fSJerome Marchand 		.maxlen		= sizeof(sysctl_overcommit_kbytes),
269649f0ce5fSJerome Marchand 		.mode		= 0644,
269749f0ce5fSJerome Marchand 		.proc_handler	= overcommit_kbytes_handler,
26981da177e4SLinus Torvalds 	},
26991da177e4SLinus Torvalds 	{
27001da177e4SLinus Torvalds 		.procname	= "page-cluster",
27011da177e4SLinus Torvalds 		.data		= &page_cluster,
27021da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
27031da177e4SLinus Torvalds 		.mode		= 0644,
2704cb16e95fSPetr Holasek 		.proc_handler	= proc_dointvec_minmax,
2705eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
27061da177e4SLinus Torvalds 	},
27071da177e4SLinus Torvalds 	{
27081da177e4SLinus Torvalds 		.procname	= "dirty_background_ratio",
27091da177e4SLinus Torvalds 		.data		= &dirty_background_ratio,
27101da177e4SLinus Torvalds 		.maxlen		= sizeof(dirty_background_ratio),
27111da177e4SLinus Torvalds 		.mode		= 0644,
27126d456111SEric W. Biederman 		.proc_handler	= dirty_background_ratio_handler,
2713eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
27141da177e4SLinus Torvalds 		.extra2		= &one_hundred,
27151da177e4SLinus Torvalds 	},
27161da177e4SLinus Torvalds 	{
27172da02997SDavid Rientjes 		.procname	= "dirty_background_bytes",
27182da02997SDavid Rientjes 		.data		= &dirty_background_bytes,
27192da02997SDavid Rientjes 		.maxlen		= sizeof(dirty_background_bytes),
27202da02997SDavid Rientjes 		.mode		= 0644,
27216d456111SEric W. Biederman 		.proc_handler	= dirty_background_bytes_handler,
2722fc3501d4SSven Wegener 		.extra1		= &one_ul,
27232da02997SDavid Rientjes 	},
27242da02997SDavid Rientjes 	{
27251da177e4SLinus Torvalds 		.procname	= "dirty_ratio",
27261da177e4SLinus Torvalds 		.data		= &vm_dirty_ratio,
27271da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_dirty_ratio),
27281da177e4SLinus Torvalds 		.mode		= 0644,
27296d456111SEric W. Biederman 		.proc_handler	= dirty_ratio_handler,
2730eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
27311da177e4SLinus Torvalds 		.extra2		= &one_hundred,
27321da177e4SLinus Torvalds 	},
27331da177e4SLinus Torvalds 	{
27342da02997SDavid Rientjes 		.procname	= "dirty_bytes",
27352da02997SDavid Rientjes 		.data		= &vm_dirty_bytes,
27362da02997SDavid Rientjes 		.maxlen		= sizeof(vm_dirty_bytes),
27372da02997SDavid Rientjes 		.mode		= 0644,
27386d456111SEric W. Biederman 		.proc_handler	= dirty_bytes_handler,
27399e4a5bdaSAndrea Righi 		.extra1		= &dirty_bytes_min,
27402da02997SDavid Rientjes 	},
27412da02997SDavid Rientjes 	{
27421da177e4SLinus Torvalds 		.procname	= "dirty_writeback_centisecs",
2743f6ef9438SBart Samwel 		.data		= &dirty_writeback_interval,
2744f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_writeback_interval),
27451da177e4SLinus Torvalds 		.mode		= 0644,
27466d456111SEric W. Biederman 		.proc_handler	= dirty_writeback_centisecs_handler,
27471da177e4SLinus Torvalds 	},
27481da177e4SLinus Torvalds 	{
27491da177e4SLinus Torvalds 		.procname	= "dirty_expire_centisecs",
2750f6ef9438SBart Samwel 		.data		= &dirty_expire_interval,
2751f6ef9438SBart Samwel 		.maxlen		= sizeof(dirty_expire_interval),
27521da177e4SLinus Torvalds 		.mode		= 0644,
2753cb16e95fSPetr Holasek 		.proc_handler	= proc_dointvec_minmax,
2754eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
27551da177e4SLinus Torvalds 	},
27561da177e4SLinus Torvalds 	{
27571efff914STheodore Ts'o 		.procname	= "dirtytime_expire_seconds",
27581efff914STheodore Ts'o 		.data		= &dirtytime_expire_interval,
27592d87b309SRandy Dunlap 		.maxlen		= sizeof(dirtytime_expire_interval),
27601efff914STheodore Ts'o 		.mode		= 0644,
27611efff914STheodore Ts'o 		.proc_handler	= dirtytime_interval_handler,
2762eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
27631efff914STheodore Ts'o 	},
27641efff914STheodore Ts'o 	{
27651da177e4SLinus Torvalds 		.procname	= "swappiness",
27661da177e4SLinus Torvalds 		.data		= &vm_swappiness,
27671da177e4SLinus Torvalds 		.maxlen		= sizeof(vm_swappiness),
27681da177e4SLinus Torvalds 		.mode		= 0644,
27696d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2770eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2771c843966cSJohannes Weiner 		.extra2		= &two_hundred,
27721da177e4SLinus Torvalds 	},
27731da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE
27741da177e4SLinus Torvalds 	{
27751da177e4SLinus Torvalds 		.procname	= "nr_hugepages",
2776e5ff2159SAndi Kleen 		.data		= NULL,
27771da177e4SLinus Torvalds 		.maxlen		= sizeof(unsigned long),
27781da177e4SLinus Torvalds 		.mode		= 0644,
27796d456111SEric W. Biederman 		.proc_handler	= hugetlb_sysctl_handler,
27801da177e4SLinus Torvalds 	},
278106808b08SLee Schermerhorn #ifdef CONFIG_NUMA
278206808b08SLee Schermerhorn 	{
278306808b08SLee Schermerhorn 		.procname       = "nr_hugepages_mempolicy",
278406808b08SLee Schermerhorn 		.data           = NULL,
278506808b08SLee Schermerhorn 		.maxlen         = sizeof(unsigned long),
278606808b08SLee Schermerhorn 		.mode           = 0644,
278706808b08SLee Schermerhorn 		.proc_handler   = &hugetlb_mempolicy_sysctl_handler,
278806808b08SLee Schermerhorn 	},
27894518085eSKemi Wang 	{
27904518085eSKemi Wang 		.procname		= "numa_stat",
27914518085eSKemi Wang 		.data			= &sysctl_vm_numa_stat,
27924518085eSKemi Wang 		.maxlen			= sizeof(int),
27934518085eSKemi Wang 		.mode			= 0644,
27944518085eSKemi Wang 		.proc_handler	= sysctl_vm_numa_stat_handler,
2795eec4844fSMatteo Croce 		.extra1			= SYSCTL_ZERO,
2796eec4844fSMatteo Croce 		.extra2			= SYSCTL_ONE,
27974518085eSKemi Wang 	},
279806808b08SLee Schermerhorn #endif
27991da177e4SLinus Torvalds 	 {
28001da177e4SLinus Torvalds 		.procname	= "hugetlb_shm_group",
28011da177e4SLinus Torvalds 		.data		= &sysctl_hugetlb_shm_group,
28021da177e4SLinus Torvalds 		.maxlen		= sizeof(gid_t),
28031da177e4SLinus Torvalds 		.mode		= 0644,
28046d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
28051da177e4SLinus Torvalds 	 },
2806396faf03SMel Gorman 	{
2807d1c3fb1fSNishanth Aravamudan 		.procname	= "nr_overcommit_hugepages",
2808e5ff2159SAndi Kleen 		.data		= NULL,
2809e5ff2159SAndi Kleen 		.maxlen		= sizeof(unsigned long),
2810d1c3fb1fSNishanth Aravamudan 		.mode		= 0644,
28116d456111SEric W. Biederman 		.proc_handler	= hugetlb_overcommit_handler,
2812d1c3fb1fSNishanth Aravamudan 	},
28131da177e4SLinus Torvalds #endif
28141da177e4SLinus Torvalds 	{
28151da177e4SLinus Torvalds 		.procname	= "lowmem_reserve_ratio",
28161da177e4SLinus Torvalds 		.data		= &sysctl_lowmem_reserve_ratio,
28171da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
28181da177e4SLinus Torvalds 		.mode		= 0644,
28196d456111SEric W. Biederman 		.proc_handler	= lowmem_reserve_ratio_sysctl_handler,
28201da177e4SLinus Torvalds 	},
28211da177e4SLinus Torvalds 	{
28229d0243bcSAndrew Morton 		.procname	= "drop_caches",
28239d0243bcSAndrew Morton 		.data		= &sysctl_drop_caches,
28249d0243bcSAndrew Morton 		.maxlen		= sizeof(int),
2825204cb79aSJohannes Weiner 		.mode		= 0200,
28269d0243bcSAndrew Morton 		.proc_handler	= drop_caches_sysctl_handler,
2827eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
28285509a5d2SDave Hansen 		.extra2		= &four,
28299d0243bcSAndrew Morton 	},
283076ab0f53SMel Gorman #ifdef CONFIG_COMPACTION
283176ab0f53SMel Gorman 	{
283276ab0f53SMel Gorman 		.procname	= "compact_memory",
2833*ef498438SPintu Kumar 		.data		= NULL,
283476ab0f53SMel Gorman 		.maxlen		= sizeof(int),
283576ab0f53SMel Gorman 		.mode		= 0200,
283676ab0f53SMel Gorman 		.proc_handler	= sysctl_compaction_handler,
283776ab0f53SMel Gorman 	},
28385e771905SMel Gorman 	{
2839facdaa91SNitin Gupta 		.procname	= "compaction_proactiveness",
2840facdaa91SNitin Gupta 		.data		= &sysctl_compaction_proactiveness,
2841d34c0a75SNitin Gupta 		.maxlen		= sizeof(sysctl_compaction_proactiveness),
2842facdaa91SNitin Gupta 		.mode		= 0644,
2843facdaa91SNitin Gupta 		.proc_handler	= proc_dointvec_minmax,
2844facdaa91SNitin Gupta 		.extra1		= SYSCTL_ZERO,
2845facdaa91SNitin Gupta 		.extra2		= &one_hundred,
2846facdaa91SNitin Gupta 	},
2847facdaa91SNitin Gupta 	{
28485e771905SMel Gorman 		.procname	= "extfrag_threshold",
28495e771905SMel Gorman 		.data		= &sysctl_extfrag_threshold,
28505e771905SMel Gorman 		.maxlen		= sizeof(int),
28515e771905SMel Gorman 		.mode		= 0644,
28526b7e5cadSMatthew Wilcox 		.proc_handler	= proc_dointvec_minmax,
28535e771905SMel Gorman 		.extra1		= &min_extfrag_threshold,
28545e771905SMel Gorman 		.extra2		= &max_extfrag_threshold,
28555e771905SMel Gorman 	},
28565bbe3547SEric B Munson 	{
28575bbe3547SEric B Munson 		.procname	= "compact_unevictable_allowed",
28585bbe3547SEric B Munson 		.data		= &sysctl_compact_unevictable_allowed,
28595bbe3547SEric B Munson 		.maxlen		= sizeof(int),
28605bbe3547SEric B Munson 		.mode		= 0644,
28616923aa0dSSebastian Andrzej Siewior 		.proc_handler	= proc_dointvec_minmax_warn_RT_change,
2862eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2863eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
28645bbe3547SEric B Munson 	},
28655e771905SMel Gorman 
286676ab0f53SMel Gorman #endif /* CONFIG_COMPACTION */
28679d0243bcSAndrew Morton 	{
28681da177e4SLinus Torvalds 		.procname	= "min_free_kbytes",
28691da177e4SLinus Torvalds 		.data		= &min_free_kbytes,
28701da177e4SLinus Torvalds 		.maxlen		= sizeof(min_free_kbytes),
28711da177e4SLinus Torvalds 		.mode		= 0644,
28726d456111SEric W. Biederman 		.proc_handler	= min_free_kbytes_sysctl_handler,
2873eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28741da177e4SLinus Torvalds 	},
28758ad4b1fbSRohit Seth 	{
28761c30844dSMel Gorman 		.procname	= "watermark_boost_factor",
28771c30844dSMel Gorman 		.data		= &watermark_boost_factor,
28781c30844dSMel Gorman 		.maxlen		= sizeof(watermark_boost_factor),
28791c30844dSMel Gorman 		.mode		= 0644,
288026363af5SChristoph Hellwig 		.proc_handler	= proc_dointvec_minmax,
2881eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28821c30844dSMel Gorman 	},
28831c30844dSMel Gorman 	{
2884795ae7a0SJohannes Weiner 		.procname	= "watermark_scale_factor",
2885795ae7a0SJohannes Weiner 		.data		= &watermark_scale_factor,
2886795ae7a0SJohannes Weiner 		.maxlen		= sizeof(watermark_scale_factor),
2887795ae7a0SJohannes Weiner 		.mode		= 0644,
2888795ae7a0SJohannes Weiner 		.proc_handler	= watermark_scale_factor_sysctl_handler,
2889eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
2890795ae7a0SJohannes Weiner 		.extra2		= &one_thousand,
2891795ae7a0SJohannes Weiner 	},
2892795ae7a0SJohannes Weiner 	{
28938ad4b1fbSRohit Seth 		.procname	= "percpu_pagelist_fraction",
28948ad4b1fbSRohit Seth 		.data		= &percpu_pagelist_fraction,
28958ad4b1fbSRohit Seth 		.maxlen		= sizeof(percpu_pagelist_fraction),
28968ad4b1fbSRohit Seth 		.mode		= 0644,
28976d456111SEric W. Biederman 		.proc_handler	= percpu_pagelist_fraction_sysctl_handler,
2898eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
28998ad4b1fbSRohit Seth 	},
29005ef64cc8SLinus Torvalds 	{
29015ef64cc8SLinus Torvalds 		.procname	= "page_lock_unfairness",
29025ef64cc8SLinus Torvalds 		.data		= &sysctl_page_lock_unfairness,
29035ef64cc8SLinus Torvalds 		.maxlen		= sizeof(sysctl_page_lock_unfairness),
29045ef64cc8SLinus Torvalds 		.mode		= 0644,
29055ef64cc8SLinus Torvalds 		.proc_handler	= proc_dointvec_minmax,
29065ef64cc8SLinus Torvalds 		.extra1		= SYSCTL_ZERO,
29075ef64cc8SLinus Torvalds 	},
29081da177e4SLinus Torvalds #ifdef CONFIG_MMU
29091da177e4SLinus Torvalds 	{
29101da177e4SLinus Torvalds 		.procname	= "max_map_count",
29111da177e4SLinus Torvalds 		.data		= &sysctl_max_map_count,
29121da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_max_map_count),
29131da177e4SLinus Torvalds 		.mode		= 0644,
29143e26120cSWANG Cong 		.proc_handler	= proc_dointvec_minmax,
2915eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
29161da177e4SLinus Torvalds 	},
2917dd8632a1SPaul Mundt #else
2918dd8632a1SPaul Mundt 	{
2919dd8632a1SPaul Mundt 		.procname	= "nr_trim_pages",
2920dd8632a1SPaul Mundt 		.data		= &sysctl_nr_trim_pages,
2921dd8632a1SPaul Mundt 		.maxlen		= sizeof(sysctl_nr_trim_pages),
2922dd8632a1SPaul Mundt 		.mode		= 0644,
29236d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
2924eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
2925dd8632a1SPaul Mundt 	},
29261da177e4SLinus Torvalds #endif
29271da177e4SLinus Torvalds 	{
29281da177e4SLinus Torvalds 		.procname	= "laptop_mode",
29291da177e4SLinus Torvalds 		.data		= &laptop_mode,
29301da177e4SLinus Torvalds 		.maxlen		= sizeof(laptop_mode),
29311da177e4SLinus Torvalds 		.mode		= 0644,
29326d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_jiffies,
29331da177e4SLinus Torvalds 	},
29341da177e4SLinus Torvalds 	{
29351da177e4SLinus Torvalds 		.procname	= "block_dump",
29361da177e4SLinus Torvalds 		.data		= &block_dump,
29371da177e4SLinus Torvalds 		.maxlen		= sizeof(block_dump),
29381da177e4SLinus Torvalds 		.mode		= 0644,
29393b3376f2SLin Feng 		.proc_handler	= proc_dointvec_minmax,
2940eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
29411da177e4SLinus Torvalds 	},
29421da177e4SLinus Torvalds 	{
29431da177e4SLinus Torvalds 		.procname	= "vfs_cache_pressure",
29441da177e4SLinus Torvalds 		.data		= &sysctl_vfs_cache_pressure,
29451da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
29461da177e4SLinus Torvalds 		.mode		= 0644,
29473b3376f2SLin Feng 		.proc_handler	= proc_dointvec_minmax,
2948eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
29491da177e4SLinus Torvalds 	},
295067f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
295167f3977fSAlexandre Ghiti     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
29521da177e4SLinus Torvalds 	{
29531da177e4SLinus Torvalds 		.procname	= "legacy_va_layout",
29541da177e4SLinus Torvalds 		.data		= &sysctl_legacy_va_layout,
29551da177e4SLinus Torvalds 		.maxlen		= sizeof(sysctl_legacy_va_layout),
29561da177e4SLinus Torvalds 		.mode		= 0644,
29573b3376f2SLin Feng 		.proc_handler	= proc_dointvec_minmax,
2958eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
29591da177e4SLinus Torvalds 	},
29601da177e4SLinus Torvalds #endif
29611743660bSChristoph Lameter #ifdef CONFIG_NUMA
29621743660bSChristoph Lameter 	{
29631743660bSChristoph Lameter 		.procname	= "zone_reclaim_mode",
2964a5f5f91dSMel Gorman 		.data		= &node_reclaim_mode,
2965a5f5f91dSMel Gorman 		.maxlen		= sizeof(node_reclaim_mode),
29661743660bSChristoph Lameter 		.mode		= 0644,
29673b3376f2SLin Feng 		.proc_handler	= proc_dointvec_minmax,
2968eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
29691743660bSChristoph Lameter 	},
29709614634fSChristoph Lameter 	{
29719614634fSChristoph Lameter 		.procname	= "min_unmapped_ratio",
29729614634fSChristoph Lameter 		.data		= &sysctl_min_unmapped_ratio,
29739614634fSChristoph Lameter 		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
29749614634fSChristoph Lameter 		.mode		= 0644,
29756d456111SEric W. Biederman 		.proc_handler	= sysctl_min_unmapped_ratio_sysctl_handler,
2976eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
29779614634fSChristoph Lameter 		.extra2		= &one_hundred,
29789614634fSChristoph Lameter 	},
29790ff38490SChristoph Lameter 	{
29800ff38490SChristoph Lameter 		.procname	= "min_slab_ratio",
29810ff38490SChristoph Lameter 		.data		= &sysctl_min_slab_ratio,
29820ff38490SChristoph Lameter 		.maxlen		= sizeof(sysctl_min_slab_ratio),
29830ff38490SChristoph Lameter 		.mode		= 0644,
29846d456111SEric W. Biederman 		.proc_handler	= sysctl_min_slab_ratio_sysctl_handler,
2985eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
29860ff38490SChristoph Lameter 		.extra2		= &one_hundred,
29870ff38490SChristoph Lameter 	},
29881743660bSChristoph Lameter #endif
298977461ab3SChristoph Lameter #ifdef CONFIG_SMP
299077461ab3SChristoph Lameter 	{
299177461ab3SChristoph Lameter 		.procname	= "stat_interval",
299277461ab3SChristoph Lameter 		.data		= &sysctl_stat_interval,
299377461ab3SChristoph Lameter 		.maxlen		= sizeof(sysctl_stat_interval),
299477461ab3SChristoph Lameter 		.mode		= 0644,
29956d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_jiffies,
299677461ab3SChristoph Lameter 	},
299752b6f46bSHugh Dickins 	{
299852b6f46bSHugh Dickins 		.procname	= "stat_refresh",
299952b6f46bSHugh Dickins 		.data		= NULL,
300052b6f46bSHugh Dickins 		.maxlen		= 0,
300152b6f46bSHugh Dickins 		.mode		= 0600,
300252b6f46bSHugh Dickins 		.proc_handler	= vmstat_refresh,
300352b6f46bSHugh Dickins 	},
300477461ab3SChristoph Lameter #endif
30056e141546SDavid Howells #ifdef CONFIG_MMU
3006ed032189SEric Paris 	{
3007ed032189SEric Paris 		.procname	= "mmap_min_addr",
3008788084abSEric Paris 		.data		= &dac_mmap_min_addr,
3009ed032189SEric Paris 		.maxlen		= sizeof(unsigned long),
3010ed032189SEric Paris 		.mode		= 0644,
30116d456111SEric W. Biederman 		.proc_handler	= mmap_min_addr_handler,
3012ed032189SEric Paris 	},
30136e141546SDavid Howells #endif
3014f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA
3015f0c0b2b8SKAMEZAWA Hiroyuki 	{
3016f0c0b2b8SKAMEZAWA Hiroyuki 		.procname	= "numa_zonelist_order",
3017f0c0b2b8SKAMEZAWA Hiroyuki 		.data		= &numa_zonelist_order,
3018f0c0b2b8SKAMEZAWA Hiroyuki 		.maxlen		= NUMA_ZONELIST_ORDER_LEN,
3019f0c0b2b8SKAMEZAWA Hiroyuki 		.mode		= 0644,
30206d456111SEric W. Biederman 		.proc_handler	= numa_zonelist_order_handler,
3021f0c0b2b8SKAMEZAWA Hiroyuki 	},
3022f0c0b2b8SKAMEZAWA Hiroyuki #endif
30232b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
30245c36e657SPaul Mundt    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
3025e6e5494cSIngo Molnar 	{
3026e6e5494cSIngo Molnar 		.procname	= "vdso_enabled",
30273d7ee969SAndy Lutomirski #ifdef CONFIG_X86_32
30283d7ee969SAndy Lutomirski 		.data		= &vdso32_enabled,
30293d7ee969SAndy Lutomirski 		.maxlen		= sizeof(vdso32_enabled),
30303d7ee969SAndy Lutomirski #else
3031e6e5494cSIngo Molnar 		.data		= &vdso_enabled,
3032e6e5494cSIngo Molnar 		.maxlen		= sizeof(vdso_enabled),
30333d7ee969SAndy Lutomirski #endif
3034e6e5494cSIngo Molnar 		.mode		= 0644,
30356d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
3036eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3037e6e5494cSIngo Molnar 	},
3038e6e5494cSIngo Molnar #endif
3039195cf453SBron Gondwana #ifdef CONFIG_HIGHMEM
3040195cf453SBron Gondwana 	{
3041195cf453SBron Gondwana 		.procname	= "highmem_is_dirtyable",
3042195cf453SBron Gondwana 		.data		= &vm_highmem_is_dirtyable,
3043195cf453SBron Gondwana 		.maxlen		= sizeof(vm_highmem_is_dirtyable),
3044195cf453SBron Gondwana 		.mode		= 0644,
30456d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
3046eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3047eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
3048195cf453SBron Gondwana 	},
3049195cf453SBron Gondwana #endif
30506a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE
30516a46079cSAndi Kleen 	{
30526a46079cSAndi Kleen 		.procname	= "memory_failure_early_kill",
30536a46079cSAndi Kleen 		.data		= &sysctl_memory_failure_early_kill,
30546a46079cSAndi Kleen 		.maxlen		= sizeof(sysctl_memory_failure_early_kill),
30556a46079cSAndi Kleen 		.mode		= 0644,
30566d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
3057eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3058eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
30596a46079cSAndi Kleen 	},
30606a46079cSAndi Kleen 	{
30616a46079cSAndi Kleen 		.procname	= "memory_failure_recovery",
30626a46079cSAndi Kleen 		.data		= &sysctl_memory_failure_recovery,
30636a46079cSAndi Kleen 		.maxlen		= sizeof(sysctl_memory_failure_recovery),
30646a46079cSAndi Kleen 		.mode		= 0644,
30656d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
3066eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3067eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
30686a46079cSAndi Kleen 	},
30696a46079cSAndi Kleen #endif
3070c9b1d098SAndrew Shewmaker 	{
3071c9b1d098SAndrew Shewmaker 		.procname	= "user_reserve_kbytes",
3072c9b1d098SAndrew Shewmaker 		.data		= &sysctl_user_reserve_kbytes,
3073c9b1d098SAndrew Shewmaker 		.maxlen		= sizeof(sysctl_user_reserve_kbytes),
3074c9b1d098SAndrew Shewmaker 		.mode		= 0644,
3075c9b1d098SAndrew Shewmaker 		.proc_handler	= proc_doulongvec_minmax,
3076c9b1d098SAndrew Shewmaker 	},
30774eeab4f5SAndrew Shewmaker 	{
30784eeab4f5SAndrew Shewmaker 		.procname	= "admin_reserve_kbytes",
30794eeab4f5SAndrew Shewmaker 		.data		= &sysctl_admin_reserve_kbytes,
30804eeab4f5SAndrew Shewmaker 		.maxlen		= sizeof(sysctl_admin_reserve_kbytes),
30814eeab4f5SAndrew Shewmaker 		.mode		= 0644,
30824eeab4f5SAndrew Shewmaker 		.proc_handler	= proc_doulongvec_minmax,
30834eeab4f5SAndrew Shewmaker 	},
3084d07e2259SDaniel Cashman #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
3085d07e2259SDaniel Cashman 	{
3086d07e2259SDaniel Cashman 		.procname	= "mmap_rnd_bits",
3087d07e2259SDaniel Cashman 		.data		= &mmap_rnd_bits,
3088d07e2259SDaniel Cashman 		.maxlen		= sizeof(mmap_rnd_bits),
3089d07e2259SDaniel Cashman 		.mode		= 0600,
3090d07e2259SDaniel Cashman 		.proc_handler	= proc_dointvec_minmax,
3091d07e2259SDaniel Cashman 		.extra1		= (void *)&mmap_rnd_bits_min,
3092d07e2259SDaniel Cashman 		.extra2		= (void *)&mmap_rnd_bits_max,
3093d07e2259SDaniel Cashman 	},
3094d07e2259SDaniel Cashman #endif
3095d07e2259SDaniel Cashman #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
3096d07e2259SDaniel Cashman 	{
3097d07e2259SDaniel Cashman 		.procname	= "mmap_rnd_compat_bits",
3098d07e2259SDaniel Cashman 		.data		= &mmap_rnd_compat_bits,
3099d07e2259SDaniel Cashman 		.maxlen		= sizeof(mmap_rnd_compat_bits),
3100d07e2259SDaniel Cashman 		.mode		= 0600,
3101d07e2259SDaniel Cashman 		.proc_handler	= proc_dointvec_minmax,
3102d07e2259SDaniel Cashman 		.extra1		= (void *)&mmap_rnd_compat_bits_min,
3103d07e2259SDaniel Cashman 		.extra2		= (void *)&mmap_rnd_compat_bits_max,
3104d07e2259SDaniel Cashman 	},
3105d07e2259SDaniel Cashman #endif
3106cefdca0aSPeter Xu #ifdef CONFIG_USERFAULTFD
3107cefdca0aSPeter Xu 	{
3108cefdca0aSPeter Xu 		.procname	= "unprivileged_userfaultfd",
3109cefdca0aSPeter Xu 		.data		= &sysctl_unprivileged_userfaultfd,
3110cefdca0aSPeter Xu 		.maxlen		= sizeof(sysctl_unprivileged_userfaultfd),
3111cefdca0aSPeter Xu 		.mode		= 0644,
3112cefdca0aSPeter Xu 		.proc_handler	= proc_dointvec_minmax,
3113eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3114eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
3115cefdca0aSPeter Xu 	},
3116cefdca0aSPeter Xu #endif
31176fce56ecSEric W. Biederman 	{ }
31181da177e4SLinus Torvalds };
31191da177e4SLinus Torvalds 
3120d8217f07SEric W. Biederman static struct ctl_table fs_table[] = {
31211da177e4SLinus Torvalds 	{
31221da177e4SLinus Torvalds 		.procname	= "inode-nr",
31231da177e4SLinus Torvalds 		.data		= &inodes_stat,
31243942c07cSGlauber Costa 		.maxlen		= 2*sizeof(long),
31251da177e4SLinus Torvalds 		.mode		= 0444,
3126cffbc8aaSDave Chinner 		.proc_handler	= proc_nr_inodes,
31271da177e4SLinus Torvalds 	},
31281da177e4SLinus Torvalds 	{
31291da177e4SLinus Torvalds 		.procname	= "inode-state",
31301da177e4SLinus Torvalds 		.data		= &inodes_stat,
31313942c07cSGlauber Costa 		.maxlen		= 7*sizeof(long),
31321da177e4SLinus Torvalds 		.mode		= 0444,
3133cffbc8aaSDave Chinner 		.proc_handler	= proc_nr_inodes,
31341da177e4SLinus Torvalds 	},
31351da177e4SLinus Torvalds 	{
31361da177e4SLinus Torvalds 		.procname	= "file-nr",
31371da177e4SLinus Torvalds 		.data		= &files_stat,
3138518de9b3SEric Dumazet 		.maxlen		= sizeof(files_stat),
31391da177e4SLinus Torvalds 		.mode		= 0444,
31406d456111SEric W. Biederman 		.proc_handler	= proc_nr_files,
31411da177e4SLinus Torvalds 	},
31421da177e4SLinus Torvalds 	{
31431da177e4SLinus Torvalds 		.procname	= "file-max",
31441da177e4SLinus Torvalds 		.data		= &files_stat.max_files,
3145518de9b3SEric Dumazet 		.maxlen		= sizeof(files_stat.max_files),
31461da177e4SLinus Torvalds 		.mode		= 0644,
3147518de9b3SEric Dumazet 		.proc_handler	= proc_doulongvec_minmax,
31489002b214SWill Deacon 		.extra1		= &zero_ul,
314932a5ad9cSChristian Brauner 		.extra2		= &long_max,
31501da177e4SLinus Torvalds 	},
31511da177e4SLinus Torvalds 	{
31529cfe015aSEric Dumazet 		.procname	= "nr_open",
31539cfe015aSEric Dumazet 		.data		= &sysctl_nr_open,
31549b80a184SAlexey Dobriyan 		.maxlen		= sizeof(unsigned int),
31559cfe015aSEric Dumazet 		.mode		= 0644,
31566d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
3157eceea0b3SAl Viro 		.extra1		= &sysctl_nr_open_min,
3158eceea0b3SAl Viro 		.extra2		= &sysctl_nr_open_max,
31599cfe015aSEric Dumazet 	},
31609cfe015aSEric Dumazet 	{
31611da177e4SLinus Torvalds 		.procname	= "dentry-state",
31621da177e4SLinus Torvalds 		.data		= &dentry_stat,
31633942c07cSGlauber Costa 		.maxlen		= 6*sizeof(long),
31641da177e4SLinus Torvalds 		.mode		= 0444,
3165312d3ca8SChristoph Hellwig 		.proc_handler	= proc_nr_dentry,
31661da177e4SLinus Torvalds 	},
31671da177e4SLinus Torvalds 	{
31681da177e4SLinus Torvalds 		.procname	= "overflowuid",
31691da177e4SLinus Torvalds 		.data		= &fs_overflowuid,
31701da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
31711da177e4SLinus Torvalds 		.mode		= 0644,
31726d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
31731da177e4SLinus Torvalds 		.extra1		= &minolduid,
31741da177e4SLinus Torvalds 		.extra2		= &maxolduid,
31751da177e4SLinus Torvalds 	},
31761da177e4SLinus Torvalds 	{
31771da177e4SLinus Torvalds 		.procname	= "overflowgid",
31781da177e4SLinus Torvalds 		.data		= &fs_overflowgid,
31791da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
31801da177e4SLinus Torvalds 		.mode		= 0644,
31816d456111SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
31821da177e4SLinus Torvalds 		.extra1		= &minolduid,
31831da177e4SLinus Torvalds 		.extra2		= &maxolduid,
31841da177e4SLinus Torvalds 	},
3185bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING
31861da177e4SLinus Torvalds 	{
31871da177e4SLinus Torvalds 		.procname	= "leases-enable",
31881da177e4SLinus Torvalds 		.data		= &leases_enable,
31891da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
31901da177e4SLinus Torvalds 		.mode		= 0644,
31916d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
31921da177e4SLinus Torvalds 	},
3193bfcd17a6SThomas Petazzoni #endif
31941da177e4SLinus Torvalds #ifdef CONFIG_DNOTIFY
31951da177e4SLinus Torvalds 	{
31961da177e4SLinus Torvalds 		.procname	= "dir-notify-enable",
31971da177e4SLinus Torvalds 		.data		= &dir_notify_enable,
31981da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
31991da177e4SLinus Torvalds 		.mode		= 0644,
32006d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
32011da177e4SLinus Torvalds 	},
32021da177e4SLinus Torvalds #endif
32031da177e4SLinus Torvalds #ifdef CONFIG_MMU
3204bfcd17a6SThomas Petazzoni #ifdef CONFIG_FILE_LOCKING
32051da177e4SLinus Torvalds 	{
32061da177e4SLinus Torvalds 		.procname	= "lease-break-time",
32071da177e4SLinus Torvalds 		.data		= &lease_break_time,
32081da177e4SLinus Torvalds 		.maxlen		= sizeof(int),
32091da177e4SLinus Torvalds 		.mode		= 0644,
32106d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
32111da177e4SLinus Torvalds 	},
3212bfcd17a6SThomas Petazzoni #endif
3213ebf3f09cSThomas Petazzoni #ifdef CONFIG_AIO
32141da177e4SLinus Torvalds 	{
32151da177e4SLinus Torvalds 		.procname	= "aio-nr",
32161da177e4SLinus Torvalds 		.data		= &aio_nr,
32171da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_nr),
32181da177e4SLinus Torvalds 		.mode		= 0444,
32196d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
32201da177e4SLinus Torvalds 	},
32211da177e4SLinus Torvalds 	{
32221da177e4SLinus Torvalds 		.procname	= "aio-max-nr",
32231da177e4SLinus Torvalds 		.data		= &aio_max_nr,
32241da177e4SLinus Torvalds 		.maxlen		= sizeof(aio_max_nr),
32251da177e4SLinus Torvalds 		.mode		= 0644,
32266d456111SEric W. Biederman 		.proc_handler	= proc_doulongvec_minmax,
32271da177e4SLinus Torvalds 	},
3228ebf3f09cSThomas Petazzoni #endif /* CONFIG_AIO */
32292d9048e2SAmy Griffis #ifdef CONFIG_INOTIFY_USER
32300399cb08SRobert Love 	{
32310399cb08SRobert Love 		.procname	= "inotify",
32320399cb08SRobert Love 		.mode		= 0555,
32330399cb08SRobert Love 		.child		= inotify_table,
32340399cb08SRobert Love 	},
32350399cb08SRobert Love #endif
32365b8fea65SAmir Goldstein #ifdef CONFIG_FANOTIFY
32375b8fea65SAmir Goldstein 	{
32385b8fea65SAmir Goldstein 		.procname	= "fanotify",
32395b8fea65SAmir Goldstein 		.mode		= 0555,
32405b8fea65SAmir Goldstein 		.child		= fanotify_table,
32415b8fea65SAmir Goldstein 	},
32425b8fea65SAmir Goldstein #endif
32437ef9964eSDavide Libenzi #ifdef CONFIG_EPOLL
32447ef9964eSDavide Libenzi 	{
32457ef9964eSDavide Libenzi 		.procname	= "epoll",
32467ef9964eSDavide Libenzi 		.mode		= 0555,
32477ef9964eSDavide Libenzi 		.child		= epoll_table,
32487ef9964eSDavide Libenzi 	},
32497ef9964eSDavide Libenzi #endif
32501da177e4SLinus Torvalds #endif
3251d6e71144SAlan Cox 	{
3252800179c9SKees Cook 		.procname	= "protected_symlinks",
3253800179c9SKees Cook 		.data		= &sysctl_protected_symlinks,
3254800179c9SKees Cook 		.maxlen		= sizeof(int),
3255800179c9SKees Cook 		.mode		= 0600,
3256800179c9SKees Cook 		.proc_handler	= proc_dointvec_minmax,
3257eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3258eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
3259800179c9SKees Cook 	},
3260800179c9SKees Cook 	{
3261800179c9SKees Cook 		.procname	= "protected_hardlinks",
3262800179c9SKees Cook 		.data		= &sysctl_protected_hardlinks,
3263800179c9SKees Cook 		.maxlen		= sizeof(int),
3264800179c9SKees Cook 		.mode		= 0600,
3265800179c9SKees Cook 		.proc_handler	= proc_dointvec_minmax,
3266eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3267eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
3268800179c9SKees Cook 	},
3269800179c9SKees Cook 	{
327030aba665SSalvatore Mesoraca 		.procname	= "protected_fifos",
327130aba665SSalvatore Mesoraca 		.data		= &sysctl_protected_fifos,
327230aba665SSalvatore Mesoraca 		.maxlen		= sizeof(int),
327330aba665SSalvatore Mesoraca 		.mode		= 0600,
327430aba665SSalvatore Mesoraca 		.proc_handler	= proc_dointvec_minmax,
3275eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
327630aba665SSalvatore Mesoraca 		.extra2		= &two,
327730aba665SSalvatore Mesoraca 	},
327830aba665SSalvatore Mesoraca 	{
327930aba665SSalvatore Mesoraca 		.procname	= "protected_regular",
328030aba665SSalvatore Mesoraca 		.data		= &sysctl_protected_regular,
328130aba665SSalvatore Mesoraca 		.maxlen		= sizeof(int),
328230aba665SSalvatore Mesoraca 		.mode		= 0600,
328330aba665SSalvatore Mesoraca 		.proc_handler	= proc_dointvec_minmax,
3284eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
328530aba665SSalvatore Mesoraca 		.extra2		= &two,
328630aba665SSalvatore Mesoraca 	},
328730aba665SSalvatore Mesoraca 	{
3288d6e71144SAlan Cox 		.procname	= "suid_dumpable",
3289d6e71144SAlan Cox 		.data		= &suid_dumpable,
3290d6e71144SAlan Cox 		.maxlen		= sizeof(int),
3291d6e71144SAlan Cox 		.mode		= 0644,
329254b50199SKees Cook 		.proc_handler	= proc_dointvec_minmax_coredump,
3293eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
32948e654fbaSMatthew Wilcox 		.extra2		= &two,
3295d6e71144SAlan Cox 	},
32962abc26fcSEric W. Biederman #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
32972abc26fcSEric W. Biederman 	{
32982abc26fcSEric W. Biederman 		.procname	= "binfmt_misc",
32992abc26fcSEric W. Biederman 		.mode		= 0555,
3300f9bd6733SEric W. Biederman 		.child		= sysctl_mount_point,
33012abc26fcSEric W. Biederman 	},
33022abc26fcSEric W. Biederman #endif
3303b492e95bSJens Axboe 	{
3304ff9da691SJens Axboe 		.procname	= "pipe-max-size",
3305ff9da691SJens Axboe 		.data		= &pipe_max_size,
330698159d97SJoe Lawrence 		.maxlen		= sizeof(pipe_max_size),
3307b492e95bSJens Axboe 		.mode		= 0644,
3308319e0a21SEric Biggers 		.proc_handler	= proc_dopipe_max_size,
3309b492e95bSJens Axboe 	},
3310759c0114SWilly Tarreau 	{
3311759c0114SWilly Tarreau 		.procname	= "pipe-user-pages-hard",
3312759c0114SWilly Tarreau 		.data		= &pipe_user_pages_hard,
3313759c0114SWilly Tarreau 		.maxlen		= sizeof(pipe_user_pages_hard),
3314759c0114SWilly Tarreau 		.mode		= 0644,
3315759c0114SWilly Tarreau 		.proc_handler	= proc_doulongvec_minmax,
3316759c0114SWilly Tarreau 	},
3317759c0114SWilly Tarreau 	{
3318759c0114SWilly Tarreau 		.procname	= "pipe-user-pages-soft",
3319759c0114SWilly Tarreau 		.data		= &pipe_user_pages_soft,
3320759c0114SWilly Tarreau 		.maxlen		= sizeof(pipe_user_pages_soft),
3321759c0114SWilly Tarreau 		.mode		= 0644,
3322759c0114SWilly Tarreau 		.proc_handler	= proc_doulongvec_minmax,
3323759c0114SWilly Tarreau 	},
3324d2921684SEric W. Biederman 	{
3325d2921684SEric W. Biederman 		.procname	= "mount-max",
3326d2921684SEric W. Biederman 		.data		= &sysctl_mount_max,
3327d2921684SEric W. Biederman 		.maxlen		= sizeof(unsigned int),
3328d2921684SEric W. Biederman 		.mode		= 0644,
3329d2921684SEric W. Biederman 		.proc_handler	= proc_dointvec_minmax,
3330eec4844fSMatteo Croce 		.extra1		= SYSCTL_ONE,
3331d2921684SEric W. Biederman 	},
33326fce56ecSEric W. Biederman 	{ }
33331da177e4SLinus Torvalds };
33341da177e4SLinus Torvalds 
3335d8217f07SEric W. Biederman static struct ctl_table debug_table[] = {
33367ac57a89SCatalin Marinas #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
3337abd4f750SMasoud Asgharifard Sharbiani 	{
3338abd4f750SMasoud Asgharifard Sharbiani 		.procname	= "exception-trace",
3339abd4f750SMasoud Asgharifard Sharbiani 		.data		= &show_unhandled_signals,
3340abd4f750SMasoud Asgharifard Sharbiani 		.maxlen		= sizeof(int),
3341abd4f750SMasoud Asgharifard Sharbiani 		.mode		= 0644,
3342abd4f750SMasoud Asgharifard Sharbiani 		.proc_handler	= proc_dointvec
3343abd4f750SMasoud Asgharifard Sharbiani 	},
3344abd4f750SMasoud Asgharifard Sharbiani #endif
3345b2be84dfSMasami Hiramatsu #if defined(CONFIG_OPTPROBES)
3346b2be84dfSMasami Hiramatsu 	{
3347b2be84dfSMasami Hiramatsu 		.procname	= "kprobes-optimization",
3348b2be84dfSMasami Hiramatsu 		.data		= &sysctl_kprobes_optimization,
3349b2be84dfSMasami Hiramatsu 		.maxlen		= sizeof(int),
3350b2be84dfSMasami Hiramatsu 		.mode		= 0644,
3351b2be84dfSMasami Hiramatsu 		.proc_handler	= proc_kprobes_optimization_handler,
3352eec4844fSMatteo Croce 		.extra1		= SYSCTL_ZERO,
3353eec4844fSMatteo Croce 		.extra2		= SYSCTL_ONE,
3354b2be84dfSMasami Hiramatsu 	},
3355b2be84dfSMasami Hiramatsu #endif
33566fce56ecSEric W. Biederman 	{ }
33571da177e4SLinus Torvalds };
33581da177e4SLinus Torvalds 
3359d8217f07SEric W. Biederman static struct ctl_table dev_table[] = {
33606fce56ecSEric W. Biederman 	{ }
33611da177e4SLinus Torvalds };
33621da177e4SLinus Torvalds 
3363f461d2dcSChristoph Hellwig static struct ctl_table sysctl_base_table[] = {
3364f461d2dcSChristoph Hellwig 	{
3365f461d2dcSChristoph Hellwig 		.procname	= "kernel",
3366f461d2dcSChristoph Hellwig 		.mode		= 0555,
3367f461d2dcSChristoph Hellwig 		.child		= kern_table,
3368f461d2dcSChristoph Hellwig 	},
3369f461d2dcSChristoph Hellwig 	{
3370f461d2dcSChristoph Hellwig 		.procname	= "vm",
3371f461d2dcSChristoph Hellwig 		.mode		= 0555,
3372f461d2dcSChristoph Hellwig 		.child		= vm_table,
3373f461d2dcSChristoph Hellwig 	},
3374f461d2dcSChristoph Hellwig 	{
3375f461d2dcSChristoph Hellwig 		.procname	= "fs",
3376f461d2dcSChristoph Hellwig 		.mode		= 0555,
3377f461d2dcSChristoph Hellwig 		.child		= fs_table,
3378f461d2dcSChristoph Hellwig 	},
3379f461d2dcSChristoph Hellwig 	{
3380f461d2dcSChristoph Hellwig 		.procname	= "debug",
3381f461d2dcSChristoph Hellwig 		.mode		= 0555,
3382f461d2dcSChristoph Hellwig 		.child		= debug_table,
3383f461d2dcSChristoph Hellwig 	},
3384f461d2dcSChristoph Hellwig 	{
3385f461d2dcSChristoph Hellwig 		.procname	= "dev",
3386f461d2dcSChristoph Hellwig 		.mode		= 0555,
3387f461d2dcSChristoph Hellwig 		.child		= dev_table,
3388f461d2dcSChristoph Hellwig 	},
3389f461d2dcSChristoph Hellwig 	{ }
3390f461d2dcSChristoph Hellwig };
3391f461d2dcSChristoph Hellwig 
3392de4e83bdSEric W. Biederman int __init sysctl_init(void)
3393330d57fbSAl Viro {
3394fd4b616bSSteven Rostedt 	struct ctl_table_header *hdr;
3395fd4b616bSSteven Rostedt 
3396fd4b616bSSteven Rostedt 	hdr = register_sysctl_table(sysctl_base_table);
3397fd4b616bSSteven Rostedt 	kmemleak_not_leak(hdr);
3398330d57fbSAl Viro 	return 0;
3399f7e6ced4SAl Viro }
3400b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */
34011da177e4SLinus Torvalds /*
34021da177e4SLinus Torvalds  * No sense putting this after each symbol definition, twice,
34031da177e4SLinus Torvalds  * exception granted :-)
34041da177e4SLinus Torvalds  */
34051da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec);
3406e7d316a0SSubash Abhinov Kasiviswanathan EXPORT_SYMBOL(proc_douintvec);
34071da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies);
34081da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax);
340961d9b56aSLuis R. Rodriguez EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
34101da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
34111da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
34121da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring);
34131da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax);
34141da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
34150bc19985SStephen Suryaputra EXPORT_SYMBOL(proc_do_large_bitmap);
3416