xref: /openbmc/linux/kernel/sysctl.c (revision c9933d49)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * sysctl.c: General linux system control interface
4  *
5  * Begun 24 March 1995, Stephen Tweedie
6  * Added /proc support, Dec 1995
7  * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
8  * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
9  * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
10  * Dynamic registration fixes, Stephen Tweedie.
11  * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
12  * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13  *  Horn.
14  * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
15  * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
16  * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17  *  Wendling.
18  * The list_for_each() macro wasn't appropriate for the sysctl loop.
19  *  Removed it and replaced it with older style, 03/23/00, Bill Wendling
20  */
21 
22 #include <linux/module.h>
23 #include <linux/mm.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/bitmap.h>
28 #include <linux/signal.h>
29 #include <linux/panic.h>
30 #include <linux/printk.h>
31 #include <linux/proc_fs.h>
32 #include <linux/security.h>
33 #include <linux/ctype.h>
34 #include <linux/kmemleak.h>
35 #include <linux/filter.h>
36 #include <linux/fs.h>
37 #include <linux/init.h>
38 #include <linux/kernel.h>
39 #include <linux/kobject.h>
40 #include <linux/net.h>
41 #include <linux/sysrq.h>
42 #include <linux/highuid.h>
43 #include <linux/writeback.h>
44 #include <linux/ratelimit.h>
45 #include <linux/compaction.h>
46 #include <linux/hugetlb.h>
47 #include <linux/initrd.h>
48 #include <linux/key.h>
49 #include <linux/times.h>
50 #include <linux/limits.h>
51 #include <linux/dcache.h>
52 #include <linux/syscalls.h>
53 #include <linux/vmstat.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/acpi.h>
56 #include <linux/reboot.h>
57 #include <linux/ftrace.h>
58 #include <linux/perf_event.h>
59 #include <linux/oom.h>
60 #include <linux/kmod.h>
61 #include <linux/capability.h>
62 #include <linux/binfmts.h>
63 #include <linux/sched/sysctl.h>
64 #include <linux/kexec.h>
65 #include <linux/mount.h>
66 #include <linux/userfaultfd_k.h>
67 #include <linux/latencytop.h>
68 #include <linux/pid.h>
69 #include <linux/delayacct.h>
70 
71 #include "../lib/kstrtox.h"
72 
73 #include <linux/uaccess.h>
74 #include <asm/processor.h>
75 
76 #ifdef CONFIG_X86
77 #include <asm/nmi.h>
78 #include <asm/stacktrace.h>
79 #include <asm/io.h>
80 #endif
81 #ifdef CONFIG_SPARC
82 #include <asm/setup.h>
83 #endif
84 #ifdef CONFIG_BSD_PROCESS_ACCT
85 #include <linux/acct.h>
86 #endif
87 #ifdef CONFIG_RT_MUTEXES
88 #include <linux/rtmutex.h>
89 #endif
90 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
91 #include <linux/lockdep.h>
92 #endif
93 
94 #if defined(CONFIG_SYSCTL)
95 
96 /* Constants used for minimum and  maximum */
97 
98 #ifdef CONFIG_PERF_EVENTS
99 static const int six_hundred_forty_kb = 640 * 1024;
100 #endif
101 
102 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
103 static const unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
104 
105 static const int ngroups_max = NGROUPS_MAX;
106 static const int cap_last_cap = CAP_LAST_CAP;
107 
108 #ifdef CONFIG_PROC_SYSCTL
109 
110 /**
111  * enum sysctl_writes_mode - supported sysctl write modes
112  *
113  * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
114  *	to be written, and multiple writes on the same sysctl file descriptor
115  *	will rewrite the sysctl value, regardless of file position. No warning
116  *	is issued when the initial position is not 0.
117  * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
118  *	not 0.
119  * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
120  *	file position 0 and the value must be fully contained in the buffer
121  *	sent to the write syscall. If dealing with strings respect the file
122  *	position, but restrict this to the max length of the buffer, anything
123  *	passed the max length will be ignored. Multiple writes will append
124  *	to the buffer.
125  *
126  * These write modes control how current file position affects the behavior of
127  * updating sysctl values through the proc interface on each write.
128  */
129 enum sysctl_writes_mode {
130 	SYSCTL_WRITES_LEGACY		= -1,
131 	SYSCTL_WRITES_WARN		= 0,
132 	SYSCTL_WRITES_STRICT		= 1,
133 };
134 
135 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
136 #endif /* CONFIG_PROC_SYSCTL */
137 
138 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
139     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
140 int sysctl_legacy_va_layout;
141 #endif
142 
143 #ifdef CONFIG_COMPACTION
144 /* min_extfrag_threshold is SYSCTL_ZERO */;
145 static const int max_extfrag_threshold = 1000;
146 #endif
147 
148 #endif /* CONFIG_SYSCTL */
149 
150 /*
151  * /proc/sys support
152  */
153 
154 #ifdef CONFIG_PROC_SYSCTL
155 
156 static int _proc_do_string(char *data, int maxlen, int write,
157 		char *buffer, size_t *lenp, loff_t *ppos)
158 {
159 	size_t len;
160 	char c, *p;
161 
162 	if (!data || !maxlen || !*lenp) {
163 		*lenp = 0;
164 		return 0;
165 	}
166 
167 	if (write) {
168 		if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
169 			/* Only continue writes not past the end of buffer. */
170 			len = strlen(data);
171 			if (len > maxlen - 1)
172 				len = maxlen - 1;
173 
174 			if (*ppos > len)
175 				return 0;
176 			len = *ppos;
177 		} else {
178 			/* Start writing from beginning of buffer. */
179 			len = 0;
180 		}
181 
182 		*ppos += *lenp;
183 		p = buffer;
184 		while ((p - buffer) < *lenp && len < maxlen - 1) {
185 			c = *(p++);
186 			if (c == 0 || c == '\n')
187 				break;
188 			data[len++] = c;
189 		}
190 		data[len] = 0;
191 	} else {
192 		len = strlen(data);
193 		if (len > maxlen)
194 			len = maxlen;
195 
196 		if (*ppos > len) {
197 			*lenp = 0;
198 			return 0;
199 		}
200 
201 		data += *ppos;
202 		len  -= *ppos;
203 
204 		if (len > *lenp)
205 			len = *lenp;
206 		if (len)
207 			memcpy(buffer, data, len);
208 		if (len < *lenp) {
209 			buffer[len] = '\n';
210 			len++;
211 		}
212 		*lenp = len;
213 		*ppos += len;
214 	}
215 	return 0;
216 }
217 
218 static void warn_sysctl_write(struct ctl_table *table)
219 {
220 	pr_warn_once("%s wrote to %s when file position was not 0!\n"
221 		"This will not be supported in the future. To silence this\n"
222 		"warning, set kernel.sysctl_writes_strict = -1\n",
223 		current->comm, table->procname);
224 }
225 
226 /**
227  * proc_first_pos_non_zero_ignore - check if first position is allowed
228  * @ppos: file position
229  * @table: the sysctl table
230  *
231  * Returns true if the first position is non-zero and the sysctl_writes_strict
232  * mode indicates this is not allowed for numeric input types. String proc
233  * handlers can ignore the return value.
234  */
235 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
236 					   struct ctl_table *table)
237 {
238 	if (!*ppos)
239 		return false;
240 
241 	switch (sysctl_writes_strict) {
242 	case SYSCTL_WRITES_STRICT:
243 		return true;
244 	case SYSCTL_WRITES_WARN:
245 		warn_sysctl_write(table);
246 		return false;
247 	default:
248 		return false;
249 	}
250 }
251 
252 /**
253  * proc_dostring - read a string sysctl
254  * @table: the sysctl table
255  * @write: %TRUE if this is a write to the sysctl file
256  * @buffer: the user buffer
257  * @lenp: the size of the user buffer
258  * @ppos: file position
259  *
260  * Reads/writes a string from/to the user buffer. If the kernel
261  * buffer provided is not large enough to hold the string, the
262  * string is truncated. The copied string is %NULL-terminated.
263  * If the string is being read by the user process, it is copied
264  * and a newline '\n' is added. It is truncated if the buffer is
265  * not large enough.
266  *
267  * Returns 0 on success.
268  */
269 int proc_dostring(struct ctl_table *table, int write,
270 		  void *buffer, size_t *lenp, loff_t *ppos)
271 {
272 	if (write)
273 		proc_first_pos_non_zero_ignore(ppos, table);
274 
275 	return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
276 			ppos);
277 }
278 
279 static size_t proc_skip_spaces(char **buf)
280 {
281 	size_t ret;
282 	char *tmp = skip_spaces(*buf);
283 	ret = tmp - *buf;
284 	*buf = tmp;
285 	return ret;
286 }
287 
288 static void proc_skip_char(char **buf, size_t *size, const char v)
289 {
290 	while (*size) {
291 		if (**buf != v)
292 			break;
293 		(*size)--;
294 		(*buf)++;
295 	}
296 }
297 
298 /**
299  * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
300  *                   fail on overflow
301  *
302  * @cp: kernel buffer containing the string to parse
303  * @endp: pointer to store the trailing characters
304  * @base: the base to use
305  * @res: where the parsed integer will be stored
306  *
307  * In case of success 0 is returned and @res will contain the parsed integer,
308  * @endp will hold any trailing characters.
309  * This function will fail the parse on overflow. If there wasn't an overflow
310  * the function will defer the decision what characters count as invalid to the
311  * caller.
312  */
313 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
314 			   unsigned long *res)
315 {
316 	unsigned long long result;
317 	unsigned int rv;
318 
319 	cp = _parse_integer_fixup_radix(cp, &base);
320 	rv = _parse_integer(cp, base, &result);
321 	if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
322 		return -ERANGE;
323 
324 	cp += rv;
325 
326 	if (endp)
327 		*endp = (char *)cp;
328 
329 	*res = (unsigned long)result;
330 	return 0;
331 }
332 
333 #define TMPBUFLEN 22
334 /**
335  * proc_get_long - reads an ASCII formatted integer from a user buffer
336  *
337  * @buf: a kernel buffer
338  * @size: size of the kernel buffer
339  * @val: this is where the number will be stored
340  * @neg: set to %TRUE if number is negative
341  * @perm_tr: a vector which contains the allowed trailers
342  * @perm_tr_len: size of the perm_tr vector
343  * @tr: pointer to store the trailer character
344  *
345  * In case of success %0 is returned and @buf and @size are updated with
346  * the amount of bytes read. If @tr is non-NULL and a trailing
347  * character exists (size is non-zero after returning from this
348  * function), @tr is updated with the trailing character.
349  */
350 static int proc_get_long(char **buf, size_t *size,
351 			  unsigned long *val, bool *neg,
352 			  const char *perm_tr, unsigned perm_tr_len, char *tr)
353 {
354 	int len;
355 	char *p, tmp[TMPBUFLEN];
356 
357 	if (!*size)
358 		return -EINVAL;
359 
360 	len = *size;
361 	if (len > TMPBUFLEN - 1)
362 		len = TMPBUFLEN - 1;
363 
364 	memcpy(tmp, *buf, len);
365 
366 	tmp[len] = 0;
367 	p = tmp;
368 	if (*p == '-' && *size > 1) {
369 		*neg = true;
370 		p++;
371 	} else
372 		*neg = false;
373 	if (!isdigit(*p))
374 		return -EINVAL;
375 
376 	if (strtoul_lenient(p, &p, 0, val))
377 		return -EINVAL;
378 
379 	len = p - tmp;
380 
381 	/* We don't know if the next char is whitespace thus we may accept
382 	 * invalid integers (e.g. 1234...a) or two integers instead of one
383 	 * (e.g. 123...1). So lets not allow such large numbers. */
384 	if (len == TMPBUFLEN - 1)
385 		return -EINVAL;
386 
387 	if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
388 		return -EINVAL;
389 
390 	if (tr && (len < *size))
391 		*tr = *p;
392 
393 	*buf += len;
394 	*size -= len;
395 
396 	return 0;
397 }
398 
399 /**
400  * proc_put_long - converts an integer to a decimal ASCII formatted string
401  *
402  * @buf: the user buffer
403  * @size: the size of the user buffer
404  * @val: the integer to be converted
405  * @neg: sign of the number, %TRUE for negative
406  *
407  * In case of success @buf and @size are updated with the amount of bytes
408  * written.
409  */
410 static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
411 {
412 	int len;
413 	char tmp[TMPBUFLEN], *p = tmp;
414 
415 	sprintf(p, "%s%lu", neg ? "-" : "", val);
416 	len = strlen(tmp);
417 	if (len > *size)
418 		len = *size;
419 	memcpy(*buf, tmp, len);
420 	*size -= len;
421 	*buf += len;
422 }
423 #undef TMPBUFLEN
424 
425 static void proc_put_char(void **buf, size_t *size, char c)
426 {
427 	if (*size) {
428 		char **buffer = (char **)buf;
429 		**buffer = c;
430 
431 		(*size)--;
432 		(*buffer)++;
433 		*buf = *buffer;
434 	}
435 }
436 
437 static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp,
438 				int *valp,
439 				int write, void *data)
440 {
441 	if (write) {
442 		*(bool *)valp = *lvalp;
443 	} else {
444 		int val = *(bool *)valp;
445 
446 		*lvalp = (unsigned long)val;
447 		*negp = false;
448 	}
449 	return 0;
450 }
451 
452 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
453 				 int *valp,
454 				 int write, void *data)
455 {
456 	if (write) {
457 		if (*negp) {
458 			if (*lvalp > (unsigned long) INT_MAX + 1)
459 				return -EINVAL;
460 			*valp = -*lvalp;
461 		} else {
462 			if (*lvalp > (unsigned long) INT_MAX)
463 				return -EINVAL;
464 			*valp = *lvalp;
465 		}
466 	} else {
467 		int val = *valp;
468 		if (val < 0) {
469 			*negp = true;
470 			*lvalp = -(unsigned long)val;
471 		} else {
472 			*negp = false;
473 			*lvalp = (unsigned long)val;
474 		}
475 	}
476 	return 0;
477 }
478 
479 static int do_proc_douintvec_conv(unsigned long *lvalp,
480 				  unsigned int *valp,
481 				  int write, void *data)
482 {
483 	if (write) {
484 		if (*lvalp > UINT_MAX)
485 			return -EINVAL;
486 		*valp = *lvalp;
487 	} else {
488 		unsigned int val = *valp;
489 		*lvalp = (unsigned long)val;
490 	}
491 	return 0;
492 }
493 
494 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
495 
496 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
497 		  int write, void *buffer,
498 		  size_t *lenp, loff_t *ppos,
499 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
500 			      int write, void *data),
501 		  void *data)
502 {
503 	int *i, vleft, first = 1, err = 0;
504 	size_t left;
505 	char *p;
506 
507 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
508 		*lenp = 0;
509 		return 0;
510 	}
511 
512 	i = (int *) tbl_data;
513 	vleft = table->maxlen / sizeof(*i);
514 	left = *lenp;
515 
516 	if (!conv)
517 		conv = do_proc_dointvec_conv;
518 
519 	if (write) {
520 		if (proc_first_pos_non_zero_ignore(ppos, table))
521 			goto out;
522 
523 		if (left > PAGE_SIZE - 1)
524 			left = PAGE_SIZE - 1;
525 		p = buffer;
526 	}
527 
528 	for (; left && vleft--; i++, first=0) {
529 		unsigned long lval;
530 		bool neg;
531 
532 		if (write) {
533 			left -= proc_skip_spaces(&p);
534 
535 			if (!left)
536 				break;
537 			err = proc_get_long(&p, &left, &lval, &neg,
538 					     proc_wspace_sep,
539 					     sizeof(proc_wspace_sep), NULL);
540 			if (err)
541 				break;
542 			if (conv(&neg, &lval, i, 1, data)) {
543 				err = -EINVAL;
544 				break;
545 			}
546 		} else {
547 			if (conv(&neg, &lval, i, 0, data)) {
548 				err = -EINVAL;
549 				break;
550 			}
551 			if (!first)
552 				proc_put_char(&buffer, &left, '\t');
553 			proc_put_long(&buffer, &left, lval, neg);
554 		}
555 	}
556 
557 	if (!write && !first && left && !err)
558 		proc_put_char(&buffer, &left, '\n');
559 	if (write && !err && left)
560 		left -= proc_skip_spaces(&p);
561 	if (write && first)
562 		return err ? : -EINVAL;
563 	*lenp -= left;
564 out:
565 	*ppos += *lenp;
566 	return err;
567 }
568 
569 static int do_proc_dointvec(struct ctl_table *table, int write,
570 		  void *buffer, size_t *lenp, loff_t *ppos,
571 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
572 			      int write, void *data),
573 		  void *data)
574 {
575 	return __do_proc_dointvec(table->data, table, write,
576 			buffer, lenp, ppos, conv, data);
577 }
578 
579 static int do_proc_douintvec_w(unsigned int *tbl_data,
580 			       struct ctl_table *table,
581 			       void *buffer,
582 			       size_t *lenp, loff_t *ppos,
583 			       int (*conv)(unsigned long *lvalp,
584 					   unsigned int *valp,
585 					   int write, void *data),
586 			       void *data)
587 {
588 	unsigned long lval;
589 	int err = 0;
590 	size_t left;
591 	bool neg;
592 	char *p = buffer;
593 
594 	left = *lenp;
595 
596 	if (proc_first_pos_non_zero_ignore(ppos, table))
597 		goto bail_early;
598 
599 	if (left > PAGE_SIZE - 1)
600 		left = PAGE_SIZE - 1;
601 
602 	left -= proc_skip_spaces(&p);
603 	if (!left) {
604 		err = -EINVAL;
605 		goto out_free;
606 	}
607 
608 	err = proc_get_long(&p, &left, &lval, &neg,
609 			     proc_wspace_sep,
610 			     sizeof(proc_wspace_sep), NULL);
611 	if (err || neg) {
612 		err = -EINVAL;
613 		goto out_free;
614 	}
615 
616 	if (conv(&lval, tbl_data, 1, data)) {
617 		err = -EINVAL;
618 		goto out_free;
619 	}
620 
621 	if (!err && left)
622 		left -= proc_skip_spaces(&p);
623 
624 out_free:
625 	if (err)
626 		return -EINVAL;
627 
628 	return 0;
629 
630 	/* This is in keeping with old __do_proc_dointvec() */
631 bail_early:
632 	*ppos += *lenp;
633 	return err;
634 }
635 
636 static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
637 			       size_t *lenp, loff_t *ppos,
638 			       int (*conv)(unsigned long *lvalp,
639 					   unsigned int *valp,
640 					   int write, void *data),
641 			       void *data)
642 {
643 	unsigned long lval;
644 	int err = 0;
645 	size_t left;
646 
647 	left = *lenp;
648 
649 	if (conv(&lval, tbl_data, 0, data)) {
650 		err = -EINVAL;
651 		goto out;
652 	}
653 
654 	proc_put_long(&buffer, &left, lval, false);
655 	if (!left)
656 		goto out;
657 
658 	proc_put_char(&buffer, &left, '\n');
659 
660 out:
661 	*lenp -= left;
662 	*ppos += *lenp;
663 
664 	return err;
665 }
666 
667 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
668 			       int write, void *buffer,
669 			       size_t *lenp, loff_t *ppos,
670 			       int (*conv)(unsigned long *lvalp,
671 					   unsigned int *valp,
672 					   int write, void *data),
673 			       void *data)
674 {
675 	unsigned int *i, vleft;
676 
677 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
678 		*lenp = 0;
679 		return 0;
680 	}
681 
682 	i = (unsigned int *) tbl_data;
683 	vleft = table->maxlen / sizeof(*i);
684 
685 	/*
686 	 * Arrays are not supported, keep this simple. *Do not* add
687 	 * support for them.
688 	 */
689 	if (vleft != 1) {
690 		*lenp = 0;
691 		return -EINVAL;
692 	}
693 
694 	if (!conv)
695 		conv = do_proc_douintvec_conv;
696 
697 	if (write)
698 		return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
699 					   conv, data);
700 	return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
701 }
702 
703 int do_proc_douintvec(struct ctl_table *table, int write,
704 		      void *buffer, size_t *lenp, loff_t *ppos,
705 		      int (*conv)(unsigned long *lvalp,
706 				  unsigned int *valp,
707 				  int write, void *data),
708 		      void *data)
709 {
710 	return __do_proc_douintvec(table->data, table, write,
711 				   buffer, lenp, ppos, conv, data);
712 }
713 
714 /**
715  * proc_dobool - read/write a bool
716  * @table: the sysctl table
717  * @write: %TRUE if this is a write to the sysctl file
718  * @buffer: the user buffer
719  * @lenp: the size of the user buffer
720  * @ppos: file position
721  *
722  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
723  * values from/to the user buffer, treated as an ASCII string.
724  *
725  * Returns 0 on success.
726  */
727 int proc_dobool(struct ctl_table *table, int write, void *buffer,
728 		size_t *lenp, loff_t *ppos)
729 {
730 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
731 				do_proc_dobool_conv, NULL);
732 }
733 
734 /**
735  * proc_dointvec - read a vector of integers
736  * @table: the sysctl table
737  * @write: %TRUE if this is a write to the sysctl file
738  * @buffer: the user buffer
739  * @lenp: the size of the user buffer
740  * @ppos: file position
741  *
742  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
743  * values from/to the user buffer, treated as an ASCII string.
744  *
745  * Returns 0 on success.
746  */
747 int proc_dointvec(struct ctl_table *table, int write, void *buffer,
748 		  size_t *lenp, loff_t *ppos)
749 {
750 	return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
751 }
752 
753 #ifdef CONFIG_COMPACTION
754 static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
755 		int write, void *buffer, size_t *lenp, loff_t *ppos)
756 {
757 	int ret, old;
758 
759 	if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
760 		return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
761 
762 	old = *(int *)table->data;
763 	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
764 	if (ret)
765 		return ret;
766 	if (old != *(int *)table->data)
767 		pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
768 			     table->procname, current->comm,
769 			     task_pid_nr(current));
770 	return ret;
771 }
772 #endif
773 
774 /**
775  * proc_douintvec - read a vector of unsigned integers
776  * @table: the sysctl table
777  * @write: %TRUE if this is a write to the sysctl file
778  * @buffer: the user buffer
779  * @lenp: the size of the user buffer
780  * @ppos: file position
781  *
782  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
783  * values from/to the user buffer, treated as an ASCII string.
784  *
785  * Returns 0 on success.
786  */
787 int proc_douintvec(struct ctl_table *table, int write, void *buffer,
788 		size_t *lenp, loff_t *ppos)
789 {
790 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
791 				 do_proc_douintvec_conv, NULL);
792 }
793 
794 /*
795  * Taint values can only be increased
796  * This means we can safely use a temporary.
797  */
798 static int proc_taint(struct ctl_table *table, int write,
799 			       void *buffer, size_t *lenp, loff_t *ppos)
800 {
801 	struct ctl_table t;
802 	unsigned long tmptaint = get_taint();
803 	int err;
804 
805 	if (write && !capable(CAP_SYS_ADMIN))
806 		return -EPERM;
807 
808 	t = *table;
809 	t.data = &tmptaint;
810 	err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
811 	if (err < 0)
812 		return err;
813 
814 	if (write) {
815 		int i;
816 
817 		/*
818 		 * If we are relying on panic_on_taint not producing
819 		 * false positives due to userspace input, bail out
820 		 * before setting the requested taint flags.
821 		 */
822 		if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
823 			return -EINVAL;
824 
825 		/*
826 		 * Poor man's atomic or. Not worth adding a primitive
827 		 * to everyone's atomic.h for this
828 		 */
829 		for (i = 0; i < TAINT_FLAGS_COUNT; i++)
830 			if ((1UL << i) & tmptaint)
831 				add_taint(i, LOCKDEP_STILL_OK);
832 	}
833 
834 	return err;
835 }
836 
837 /**
838  * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
839  * @min: pointer to minimum allowable value
840  * @max: pointer to maximum allowable value
841  *
842  * The do_proc_dointvec_minmax_conv_param structure provides the
843  * minimum and maximum values for doing range checking for those sysctl
844  * parameters that use the proc_dointvec_minmax() handler.
845  */
846 struct do_proc_dointvec_minmax_conv_param {
847 	int *min;
848 	int *max;
849 };
850 
851 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
852 					int *valp,
853 					int write, void *data)
854 {
855 	int tmp, ret;
856 	struct do_proc_dointvec_minmax_conv_param *param = data;
857 	/*
858 	 * If writing, first do so via a temporary local int so we can
859 	 * bounds-check it before touching *valp.
860 	 */
861 	int *ip = write ? &tmp : valp;
862 
863 	ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
864 	if (ret)
865 		return ret;
866 
867 	if (write) {
868 		if ((param->min && *param->min > tmp) ||
869 		    (param->max && *param->max < tmp))
870 			return -EINVAL;
871 		*valp = tmp;
872 	}
873 
874 	return 0;
875 }
876 
877 /**
878  * proc_dointvec_minmax - read a vector of integers with min/max values
879  * @table: the sysctl table
880  * @write: %TRUE if this is a write to the sysctl file
881  * @buffer: the user buffer
882  * @lenp: the size of the user buffer
883  * @ppos: file position
884  *
885  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
886  * values from/to the user buffer, treated as an ASCII string.
887  *
888  * This routine will ensure the values are within the range specified by
889  * table->extra1 (min) and table->extra2 (max).
890  *
891  * Returns 0 on success or -EINVAL on write when the range check fails.
892  */
893 int proc_dointvec_minmax(struct ctl_table *table, int write,
894 		  void *buffer, size_t *lenp, loff_t *ppos)
895 {
896 	struct do_proc_dointvec_minmax_conv_param param = {
897 		.min = (int *) table->extra1,
898 		.max = (int *) table->extra2,
899 	};
900 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
901 				do_proc_dointvec_minmax_conv, &param);
902 }
903 
904 /**
905  * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
906  * @min: pointer to minimum allowable value
907  * @max: pointer to maximum allowable value
908  *
909  * The do_proc_douintvec_minmax_conv_param structure provides the
910  * minimum and maximum values for doing range checking for those sysctl
911  * parameters that use the proc_douintvec_minmax() handler.
912  */
913 struct do_proc_douintvec_minmax_conv_param {
914 	unsigned int *min;
915 	unsigned int *max;
916 };
917 
918 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
919 					 unsigned int *valp,
920 					 int write, void *data)
921 {
922 	int ret;
923 	unsigned int tmp;
924 	struct do_proc_douintvec_minmax_conv_param *param = data;
925 	/* write via temporary local uint for bounds-checking */
926 	unsigned int *up = write ? &tmp : valp;
927 
928 	ret = do_proc_douintvec_conv(lvalp, up, write, data);
929 	if (ret)
930 		return ret;
931 
932 	if (write) {
933 		if ((param->min && *param->min > tmp) ||
934 		    (param->max && *param->max < tmp))
935 			return -ERANGE;
936 
937 		*valp = tmp;
938 	}
939 
940 	return 0;
941 }
942 
943 /**
944  * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
945  * @table: the sysctl table
946  * @write: %TRUE if this is a write to the sysctl file
947  * @buffer: the user buffer
948  * @lenp: the size of the user buffer
949  * @ppos: file position
950  *
951  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
952  * values from/to the user buffer, treated as an ASCII string. Negative
953  * strings are not allowed.
954  *
955  * This routine will ensure the values are within the range specified by
956  * table->extra1 (min) and table->extra2 (max). There is a final sanity
957  * check for UINT_MAX to avoid having to support wrap around uses from
958  * userspace.
959  *
960  * Returns 0 on success or -ERANGE on write when the range check fails.
961  */
962 int proc_douintvec_minmax(struct ctl_table *table, int write,
963 			  void *buffer, size_t *lenp, loff_t *ppos)
964 {
965 	struct do_proc_douintvec_minmax_conv_param param = {
966 		.min = (unsigned int *) table->extra1,
967 		.max = (unsigned int *) table->extra2,
968 	};
969 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
970 				 do_proc_douintvec_minmax_conv, &param);
971 }
972 
973 /**
974  * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
975  * @table: the sysctl table
976  * @write: %TRUE if this is a write to the sysctl file
977  * @buffer: the user buffer
978  * @lenp: the size of the user buffer
979  * @ppos: file position
980  *
981  * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
982  * values from/to the user buffer, treated as an ASCII string. Negative
983  * strings are not allowed.
984  *
985  * This routine will ensure the values are within the range specified by
986  * table->extra1 (min) and table->extra2 (max).
987  *
988  * Returns 0 on success or an error on write when the range check fails.
989  */
990 int proc_dou8vec_minmax(struct ctl_table *table, int write,
991 			void *buffer, size_t *lenp, loff_t *ppos)
992 {
993 	struct ctl_table tmp;
994 	unsigned int min = 0, max = 255U, val;
995 	u8 *data = table->data;
996 	struct do_proc_douintvec_minmax_conv_param param = {
997 		.min = &min,
998 		.max = &max,
999 	};
1000 	int res;
1001 
1002 	/* Do not support arrays yet. */
1003 	if (table->maxlen != sizeof(u8))
1004 		return -EINVAL;
1005 
1006 	if (table->extra1) {
1007 		min = *(unsigned int *) table->extra1;
1008 		if (min > 255U)
1009 			return -EINVAL;
1010 	}
1011 	if (table->extra2) {
1012 		max = *(unsigned int *) table->extra2;
1013 		if (max > 255U)
1014 			return -EINVAL;
1015 	}
1016 
1017 	tmp = *table;
1018 
1019 	tmp.maxlen = sizeof(val);
1020 	tmp.data = &val;
1021 	val = *data;
1022 	res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
1023 				do_proc_douintvec_minmax_conv, &param);
1024 	if (res)
1025 		return res;
1026 	if (write)
1027 		*data = val;
1028 	return 0;
1029 }
1030 EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
1031 
1032 #ifdef CONFIG_MAGIC_SYSRQ
1033 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
1034 				void *buffer, size_t *lenp, loff_t *ppos)
1035 {
1036 	int tmp, ret;
1037 
1038 	tmp = sysrq_mask();
1039 
1040 	ret = __do_proc_dointvec(&tmp, table, write, buffer,
1041 			       lenp, ppos, NULL, NULL);
1042 	if (ret || !write)
1043 		return ret;
1044 
1045 	if (write)
1046 		sysrq_toggle_support(tmp);
1047 
1048 	return 0;
1049 }
1050 #endif
1051 
1052 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
1053 		int write, void *buffer, size_t *lenp, loff_t *ppos,
1054 		unsigned long convmul, unsigned long convdiv)
1055 {
1056 	unsigned long *i, *min, *max;
1057 	int vleft, first = 1, err = 0;
1058 	size_t left;
1059 	char *p;
1060 
1061 	if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1062 		*lenp = 0;
1063 		return 0;
1064 	}
1065 
1066 	i = (unsigned long *) data;
1067 	min = (unsigned long *) table->extra1;
1068 	max = (unsigned long *) table->extra2;
1069 	vleft = table->maxlen / sizeof(unsigned long);
1070 	left = *lenp;
1071 
1072 	if (write) {
1073 		if (proc_first_pos_non_zero_ignore(ppos, table))
1074 			goto out;
1075 
1076 		if (left > PAGE_SIZE - 1)
1077 			left = PAGE_SIZE - 1;
1078 		p = buffer;
1079 	}
1080 
1081 	for (; left && vleft--; i++, first = 0) {
1082 		unsigned long val;
1083 
1084 		if (write) {
1085 			bool neg;
1086 
1087 			left -= proc_skip_spaces(&p);
1088 			if (!left)
1089 				break;
1090 
1091 			err = proc_get_long(&p, &left, &val, &neg,
1092 					     proc_wspace_sep,
1093 					     sizeof(proc_wspace_sep), NULL);
1094 			if (err || neg) {
1095 				err = -EINVAL;
1096 				break;
1097 			}
1098 
1099 			val = convmul * val / convdiv;
1100 			if ((min && val < *min) || (max && val > *max)) {
1101 				err = -EINVAL;
1102 				break;
1103 			}
1104 			*i = val;
1105 		} else {
1106 			val = convdiv * (*i) / convmul;
1107 			if (!first)
1108 				proc_put_char(&buffer, &left, '\t');
1109 			proc_put_long(&buffer, &left, val, false);
1110 		}
1111 	}
1112 
1113 	if (!write && !first && left && !err)
1114 		proc_put_char(&buffer, &left, '\n');
1115 	if (write && !err)
1116 		left -= proc_skip_spaces(&p);
1117 	if (write && first)
1118 		return err ? : -EINVAL;
1119 	*lenp -= left;
1120 out:
1121 	*ppos += *lenp;
1122 	return err;
1123 }
1124 
1125 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
1126 		void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1127 		unsigned long convdiv)
1128 {
1129 	return __do_proc_doulongvec_minmax(table->data, table, write,
1130 			buffer, lenp, ppos, convmul, convdiv);
1131 }
1132 
1133 /**
1134  * proc_doulongvec_minmax - read a vector of long integers with min/max values
1135  * @table: the sysctl table
1136  * @write: %TRUE if this is a write to the sysctl file
1137  * @buffer: the user buffer
1138  * @lenp: the size of the user buffer
1139  * @ppos: file position
1140  *
1141  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1142  * values from/to the user buffer, treated as an ASCII string.
1143  *
1144  * This routine will ensure the values are within the range specified by
1145  * table->extra1 (min) and table->extra2 (max).
1146  *
1147  * Returns 0 on success.
1148  */
1149 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1150 			   void *buffer, size_t *lenp, loff_t *ppos)
1151 {
1152     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1153 }
1154 
1155 /**
1156  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1157  * @table: the sysctl table
1158  * @write: %TRUE if this is a write to the sysctl file
1159  * @buffer: the user buffer
1160  * @lenp: the size of the user buffer
1161  * @ppos: file position
1162  *
1163  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1164  * values from/to the user buffer, treated as an ASCII string. The values
1165  * are treated as milliseconds, and converted to jiffies when they are stored.
1166  *
1167  * This routine will ensure the values are within the range specified by
1168  * table->extra1 (min) and table->extra2 (max).
1169  *
1170  * Returns 0 on success.
1171  */
1172 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1173 				      void *buffer, size_t *lenp, loff_t *ppos)
1174 {
1175     return do_proc_doulongvec_minmax(table, write, buffer,
1176 				     lenp, ppos, HZ, 1000l);
1177 }
1178 
1179 
1180 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1181 					 int *valp,
1182 					 int write, void *data)
1183 {
1184 	if (write) {
1185 		if (*lvalp > INT_MAX / HZ)
1186 			return 1;
1187 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1188 	} else {
1189 		int val = *valp;
1190 		unsigned long lval;
1191 		if (val < 0) {
1192 			*negp = true;
1193 			lval = -(unsigned long)val;
1194 		} else {
1195 			*negp = false;
1196 			lval = (unsigned long)val;
1197 		}
1198 		*lvalp = lval / HZ;
1199 	}
1200 	return 0;
1201 }
1202 
1203 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1204 						int *valp,
1205 						int write, void *data)
1206 {
1207 	if (write) {
1208 		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1209 			return 1;
1210 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1211 	} else {
1212 		int val = *valp;
1213 		unsigned long lval;
1214 		if (val < 0) {
1215 			*negp = true;
1216 			lval = -(unsigned long)val;
1217 		} else {
1218 			*negp = false;
1219 			lval = (unsigned long)val;
1220 		}
1221 		*lvalp = jiffies_to_clock_t(lval);
1222 	}
1223 	return 0;
1224 }
1225 
1226 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1227 					    int *valp,
1228 					    int write, void *data)
1229 {
1230 	if (write) {
1231 		unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1232 
1233 		if (jif > INT_MAX)
1234 			return 1;
1235 		*valp = (int)jif;
1236 	} else {
1237 		int val = *valp;
1238 		unsigned long lval;
1239 		if (val < 0) {
1240 			*negp = true;
1241 			lval = -(unsigned long)val;
1242 		} else {
1243 			*negp = false;
1244 			lval = (unsigned long)val;
1245 		}
1246 		*lvalp = jiffies_to_msecs(lval);
1247 	}
1248 	return 0;
1249 }
1250 
1251 /**
1252  * proc_dointvec_jiffies - read a vector of integers as seconds
1253  * @table: the sysctl table
1254  * @write: %TRUE if this is a write to the sysctl file
1255  * @buffer: the user buffer
1256  * @lenp: the size of the user buffer
1257  * @ppos: file position
1258  *
1259  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1260  * values from/to the user buffer, treated as an ASCII string.
1261  * The values read are assumed to be in seconds, and are converted into
1262  * jiffies.
1263  *
1264  * Returns 0 on success.
1265  */
1266 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1267 			  void *buffer, size_t *lenp, loff_t *ppos)
1268 {
1269     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1270 		    	    do_proc_dointvec_jiffies_conv,NULL);
1271 }
1272 
1273 /**
1274  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1275  * @table: the sysctl table
1276  * @write: %TRUE if this is a write to the sysctl file
1277  * @buffer: the user buffer
1278  * @lenp: the size of the user buffer
1279  * @ppos: pointer to the file position
1280  *
1281  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1282  * values from/to the user buffer, treated as an ASCII string.
1283  * The values read are assumed to be in 1/USER_HZ seconds, and
1284  * are converted into jiffies.
1285  *
1286  * Returns 0 on success.
1287  */
1288 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1289 				 void *buffer, size_t *lenp, loff_t *ppos)
1290 {
1291     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1292 		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);
1293 }
1294 
1295 /**
1296  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1297  * @table: the sysctl table
1298  * @write: %TRUE if this is a write to the sysctl file
1299  * @buffer: the user buffer
1300  * @lenp: the size of the user buffer
1301  * @ppos: file position
1302  * @ppos: the current position in the file
1303  *
1304  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1305  * values from/to the user buffer, treated as an ASCII string.
1306  * The values read are assumed to be in 1/1000 seconds, and
1307  * are converted into jiffies.
1308  *
1309  * Returns 0 on success.
1310  */
1311 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
1312 		size_t *lenp, loff_t *ppos)
1313 {
1314 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
1315 				do_proc_dointvec_ms_jiffies_conv, NULL);
1316 }
1317 
1318 static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
1319 		size_t *lenp, loff_t *ppos)
1320 {
1321 	struct pid *new_pid;
1322 	pid_t tmp;
1323 	int r;
1324 
1325 	tmp = pid_vnr(cad_pid);
1326 
1327 	r = __do_proc_dointvec(&tmp, table, write, buffer,
1328 			       lenp, ppos, NULL, NULL);
1329 	if (r || !write)
1330 		return r;
1331 
1332 	new_pid = find_get_pid(tmp);
1333 	if (!new_pid)
1334 		return -ESRCH;
1335 
1336 	put_pid(xchg(&cad_pid, new_pid));
1337 	return 0;
1338 }
1339 
1340 /**
1341  * proc_do_large_bitmap - read/write from/to a large bitmap
1342  * @table: the sysctl table
1343  * @write: %TRUE if this is a write to the sysctl file
1344  * @buffer: the user buffer
1345  * @lenp: the size of the user buffer
1346  * @ppos: file position
1347  *
1348  * The bitmap is stored at table->data and the bitmap length (in bits)
1349  * in table->maxlen.
1350  *
1351  * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1352  * large bitmaps may be represented in a compact manner. Writing into
1353  * the file will clear the bitmap then update it with the given input.
1354  *
1355  * Returns 0 on success.
1356  */
1357 int proc_do_large_bitmap(struct ctl_table *table, int write,
1358 			 void *buffer, size_t *lenp, loff_t *ppos)
1359 {
1360 	int err = 0;
1361 	size_t left = *lenp;
1362 	unsigned long bitmap_len = table->maxlen;
1363 	unsigned long *bitmap = *(unsigned long **) table->data;
1364 	unsigned long *tmp_bitmap = NULL;
1365 	char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1366 
1367 	if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1368 		*lenp = 0;
1369 		return 0;
1370 	}
1371 
1372 	if (write) {
1373 		char *p = buffer;
1374 		size_t skipped = 0;
1375 
1376 		if (left > PAGE_SIZE - 1) {
1377 			left = PAGE_SIZE - 1;
1378 			/* How much of the buffer we'll skip this pass */
1379 			skipped = *lenp - left;
1380 		}
1381 
1382 		tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
1383 		if (!tmp_bitmap)
1384 			return -ENOMEM;
1385 		proc_skip_char(&p, &left, '\n');
1386 		while (!err && left) {
1387 			unsigned long val_a, val_b;
1388 			bool neg;
1389 			size_t saved_left;
1390 
1391 			/* In case we stop parsing mid-number, we can reset */
1392 			saved_left = left;
1393 			err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1394 					     sizeof(tr_a), &c);
1395 			/*
1396 			 * If we consumed the entirety of a truncated buffer or
1397 			 * only one char is left (may be a "-"), then stop here,
1398 			 * reset, & come back for more.
1399 			 */
1400 			if ((left <= 1) && skipped) {
1401 				left = saved_left;
1402 				break;
1403 			}
1404 
1405 			if (err)
1406 				break;
1407 			if (val_a >= bitmap_len || neg) {
1408 				err = -EINVAL;
1409 				break;
1410 			}
1411 
1412 			val_b = val_a;
1413 			if (left) {
1414 				p++;
1415 				left--;
1416 			}
1417 
1418 			if (c == '-') {
1419 				err = proc_get_long(&p, &left, &val_b,
1420 						     &neg, tr_b, sizeof(tr_b),
1421 						     &c);
1422 				/*
1423 				 * If we consumed all of a truncated buffer or
1424 				 * then stop here, reset, & come back for more.
1425 				 */
1426 				if (!left && skipped) {
1427 					left = saved_left;
1428 					break;
1429 				}
1430 
1431 				if (err)
1432 					break;
1433 				if (val_b >= bitmap_len || neg ||
1434 				    val_a > val_b) {
1435 					err = -EINVAL;
1436 					break;
1437 				}
1438 				if (left) {
1439 					p++;
1440 					left--;
1441 				}
1442 			}
1443 
1444 			bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1445 			proc_skip_char(&p, &left, '\n');
1446 		}
1447 		left += skipped;
1448 	} else {
1449 		unsigned long bit_a, bit_b = 0;
1450 		bool first = 1;
1451 
1452 		while (left) {
1453 			bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1454 			if (bit_a >= bitmap_len)
1455 				break;
1456 			bit_b = find_next_zero_bit(bitmap, bitmap_len,
1457 						   bit_a + 1) - 1;
1458 
1459 			if (!first)
1460 				proc_put_char(&buffer, &left, ',');
1461 			proc_put_long(&buffer, &left, bit_a, false);
1462 			if (bit_a != bit_b) {
1463 				proc_put_char(&buffer, &left, '-');
1464 				proc_put_long(&buffer, &left, bit_b, false);
1465 			}
1466 
1467 			first = 0; bit_b++;
1468 		}
1469 		proc_put_char(&buffer, &left, '\n');
1470 	}
1471 
1472 	if (!err) {
1473 		if (write) {
1474 			if (*ppos)
1475 				bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1476 			else
1477 				bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1478 		}
1479 		*lenp -= left;
1480 		*ppos += *lenp;
1481 	}
1482 
1483 	bitmap_free(tmp_bitmap);
1484 	return err;
1485 }
1486 
1487 #else /* CONFIG_PROC_SYSCTL */
1488 
1489 int proc_dostring(struct ctl_table *table, int write,
1490 		  void *buffer, size_t *lenp, loff_t *ppos)
1491 {
1492 	return -ENOSYS;
1493 }
1494 
1495 int proc_dobool(struct ctl_table *table, int write,
1496 		void *buffer, size_t *lenp, loff_t *ppos)
1497 {
1498 	return -ENOSYS;
1499 }
1500 
1501 int proc_dointvec(struct ctl_table *table, int write,
1502 		  void *buffer, size_t *lenp, loff_t *ppos)
1503 {
1504 	return -ENOSYS;
1505 }
1506 
1507 int proc_douintvec(struct ctl_table *table, int write,
1508 		  void *buffer, size_t *lenp, loff_t *ppos)
1509 {
1510 	return -ENOSYS;
1511 }
1512 
1513 int proc_dointvec_minmax(struct ctl_table *table, int write,
1514 		    void *buffer, size_t *lenp, loff_t *ppos)
1515 {
1516 	return -ENOSYS;
1517 }
1518 
1519 int proc_douintvec_minmax(struct ctl_table *table, int write,
1520 			  void *buffer, size_t *lenp, loff_t *ppos)
1521 {
1522 	return -ENOSYS;
1523 }
1524 
1525 int proc_dou8vec_minmax(struct ctl_table *table, int write,
1526 			void *buffer, size_t *lenp, loff_t *ppos)
1527 {
1528 	return -ENOSYS;
1529 }
1530 
1531 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1532 		    void *buffer, size_t *lenp, loff_t *ppos)
1533 {
1534 	return -ENOSYS;
1535 }
1536 
1537 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1538 		    void *buffer, size_t *lenp, loff_t *ppos)
1539 {
1540 	return -ENOSYS;
1541 }
1542 
1543 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1544 			     void *buffer, size_t *lenp, loff_t *ppos)
1545 {
1546 	return -ENOSYS;
1547 }
1548 
1549 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1550 		    void *buffer, size_t *lenp, loff_t *ppos)
1551 {
1552 	return -ENOSYS;
1553 }
1554 
1555 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1556 				      void *buffer, size_t *lenp, loff_t *ppos)
1557 {
1558 	return -ENOSYS;
1559 }
1560 
1561 int proc_do_large_bitmap(struct ctl_table *table, int write,
1562 			 void *buffer, size_t *lenp, loff_t *ppos)
1563 {
1564 	return -ENOSYS;
1565 }
1566 
1567 #endif /* CONFIG_PROC_SYSCTL */
1568 
1569 #if defined(CONFIG_SYSCTL)
1570 int proc_do_static_key(struct ctl_table *table, int write,
1571 		       void *buffer, size_t *lenp, loff_t *ppos)
1572 {
1573 	struct static_key *key = (struct static_key *)table->data;
1574 	static DEFINE_MUTEX(static_key_mutex);
1575 	int val, ret;
1576 	struct ctl_table tmp = {
1577 		.data   = &val,
1578 		.maxlen = sizeof(val),
1579 		.mode   = table->mode,
1580 		.extra1 = SYSCTL_ZERO,
1581 		.extra2 = SYSCTL_ONE,
1582 	};
1583 
1584 	if (write && !capable(CAP_SYS_ADMIN))
1585 		return -EPERM;
1586 
1587 	mutex_lock(&static_key_mutex);
1588 	val = static_key_enabled(key);
1589 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1590 	if (write && !ret) {
1591 		if (val)
1592 			static_key_enable(key);
1593 		else
1594 			static_key_disable(key);
1595 	}
1596 	mutex_unlock(&static_key_mutex);
1597 	return ret;
1598 }
1599 
1600 static struct ctl_table kern_table[] = {
1601 	{
1602 		.procname	= "sched_child_runs_first",
1603 		.data		= &sysctl_sched_child_runs_first,
1604 		.maxlen		= sizeof(unsigned int),
1605 		.mode		= 0644,
1606 		.proc_handler	= proc_dointvec,
1607 	},
1608 #ifdef CONFIG_SCHEDSTATS
1609 	{
1610 		.procname	= "sched_schedstats",
1611 		.data		= NULL,
1612 		.maxlen		= sizeof(unsigned int),
1613 		.mode		= 0644,
1614 		.proc_handler	= sysctl_schedstats,
1615 		.extra1		= SYSCTL_ZERO,
1616 		.extra2		= SYSCTL_ONE,
1617 	},
1618 #endif /* CONFIG_SCHEDSTATS */
1619 #ifdef CONFIG_TASK_DELAY_ACCT
1620 	{
1621 		.procname	= "task_delayacct",
1622 		.data		= NULL,
1623 		.maxlen		= sizeof(unsigned int),
1624 		.mode		= 0644,
1625 		.proc_handler	= sysctl_delayacct,
1626 		.extra1		= SYSCTL_ZERO,
1627 		.extra2		= SYSCTL_ONE,
1628 	},
1629 #endif /* CONFIG_TASK_DELAY_ACCT */
1630 #ifdef CONFIG_NUMA_BALANCING
1631 	{
1632 		.procname	= "numa_balancing",
1633 		.data		= NULL, /* filled in by handler */
1634 		.maxlen		= sizeof(unsigned int),
1635 		.mode		= 0644,
1636 		.proc_handler	= sysctl_numa_balancing,
1637 		.extra1		= SYSCTL_ZERO,
1638 		.extra2		= SYSCTL_FOUR,
1639 	},
1640 #endif /* CONFIG_NUMA_BALANCING */
1641 	{
1642 		.procname	= "sched_rt_period_us",
1643 		.data		= &sysctl_sched_rt_period,
1644 		.maxlen		= sizeof(unsigned int),
1645 		.mode		= 0644,
1646 		.proc_handler	= sched_rt_handler,
1647 	},
1648 	{
1649 		.procname	= "sched_rt_runtime_us",
1650 		.data		= &sysctl_sched_rt_runtime,
1651 		.maxlen		= sizeof(int),
1652 		.mode		= 0644,
1653 		.proc_handler	= sched_rt_handler,
1654 	},
1655 	{
1656 		.procname	= "sched_deadline_period_max_us",
1657 		.data		= &sysctl_sched_dl_period_max,
1658 		.maxlen		= sizeof(unsigned int),
1659 		.mode		= 0644,
1660 		.proc_handler	= proc_dointvec,
1661 	},
1662 	{
1663 		.procname	= "sched_deadline_period_min_us",
1664 		.data		= &sysctl_sched_dl_period_min,
1665 		.maxlen		= sizeof(unsigned int),
1666 		.mode		= 0644,
1667 		.proc_handler	= proc_dointvec,
1668 	},
1669 	{
1670 		.procname	= "sched_rr_timeslice_ms",
1671 		.data		= &sysctl_sched_rr_timeslice,
1672 		.maxlen		= sizeof(int),
1673 		.mode		= 0644,
1674 		.proc_handler	= sched_rr_handler,
1675 	},
1676 #ifdef CONFIG_UCLAMP_TASK
1677 	{
1678 		.procname	= "sched_util_clamp_min",
1679 		.data		= &sysctl_sched_uclamp_util_min,
1680 		.maxlen		= sizeof(unsigned int),
1681 		.mode		= 0644,
1682 		.proc_handler	= sysctl_sched_uclamp_handler,
1683 	},
1684 	{
1685 		.procname	= "sched_util_clamp_max",
1686 		.data		= &sysctl_sched_uclamp_util_max,
1687 		.maxlen		= sizeof(unsigned int),
1688 		.mode		= 0644,
1689 		.proc_handler	= sysctl_sched_uclamp_handler,
1690 	},
1691 	{
1692 		.procname	= "sched_util_clamp_min_rt_default",
1693 		.data		= &sysctl_sched_uclamp_util_min_rt_default,
1694 		.maxlen		= sizeof(unsigned int),
1695 		.mode		= 0644,
1696 		.proc_handler	= sysctl_sched_uclamp_handler,
1697 	},
1698 #endif
1699 #ifdef CONFIG_CFS_BANDWIDTH
1700 	{
1701 		.procname	= "sched_cfs_bandwidth_slice_us",
1702 		.data		= &sysctl_sched_cfs_bandwidth_slice,
1703 		.maxlen		= sizeof(unsigned int),
1704 		.mode		= 0644,
1705 		.proc_handler	= proc_dointvec_minmax,
1706 		.extra1		= SYSCTL_ONE,
1707 	},
1708 #endif
1709 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
1710 	{
1711 		.procname	= "sched_energy_aware",
1712 		.data		= &sysctl_sched_energy_aware,
1713 		.maxlen		= sizeof(unsigned int),
1714 		.mode		= 0644,
1715 		.proc_handler	= sched_energy_aware_handler,
1716 		.extra1		= SYSCTL_ZERO,
1717 		.extra2		= SYSCTL_ONE,
1718 	},
1719 #endif
1720 #ifdef CONFIG_PROVE_LOCKING
1721 	{
1722 		.procname	= "prove_locking",
1723 		.data		= &prove_locking,
1724 		.maxlen		= sizeof(int),
1725 		.mode		= 0644,
1726 		.proc_handler	= proc_dointvec,
1727 	},
1728 #endif
1729 #ifdef CONFIG_LOCK_STAT
1730 	{
1731 		.procname	= "lock_stat",
1732 		.data		= &lock_stat,
1733 		.maxlen		= sizeof(int),
1734 		.mode		= 0644,
1735 		.proc_handler	= proc_dointvec,
1736 	},
1737 #endif
1738 	{
1739 		.procname	= "panic",
1740 		.data		= &panic_timeout,
1741 		.maxlen		= sizeof(int),
1742 		.mode		= 0644,
1743 		.proc_handler	= proc_dointvec,
1744 	},
1745 #ifdef CONFIG_PROC_SYSCTL
1746 	{
1747 		.procname	= "tainted",
1748 		.maxlen 	= sizeof(long),
1749 		.mode		= 0644,
1750 		.proc_handler	= proc_taint,
1751 	},
1752 	{
1753 		.procname	= "sysctl_writes_strict",
1754 		.data		= &sysctl_writes_strict,
1755 		.maxlen		= sizeof(int),
1756 		.mode		= 0644,
1757 		.proc_handler	= proc_dointvec_minmax,
1758 		.extra1		= SYSCTL_NEG_ONE,
1759 		.extra2		= SYSCTL_ONE,
1760 	},
1761 #endif
1762 #ifdef CONFIG_LATENCYTOP
1763 	{
1764 		.procname	= "latencytop",
1765 		.data		= &latencytop_enabled,
1766 		.maxlen		= sizeof(int),
1767 		.mode		= 0644,
1768 		.proc_handler	= sysctl_latencytop,
1769 	},
1770 #endif
1771 #ifdef CONFIG_BLK_DEV_INITRD
1772 	{
1773 		.procname	= "real-root-dev",
1774 		.data		= &real_root_dev,
1775 		.maxlen		= sizeof(int),
1776 		.mode		= 0644,
1777 		.proc_handler	= proc_dointvec,
1778 	},
1779 #endif
1780 	{
1781 		.procname	= "print-fatal-signals",
1782 		.data		= &print_fatal_signals,
1783 		.maxlen		= sizeof(int),
1784 		.mode		= 0644,
1785 		.proc_handler	= proc_dointvec,
1786 	},
1787 #ifdef CONFIG_SPARC
1788 	{
1789 		.procname	= "reboot-cmd",
1790 		.data		= reboot_command,
1791 		.maxlen		= 256,
1792 		.mode		= 0644,
1793 		.proc_handler	= proc_dostring,
1794 	},
1795 	{
1796 		.procname	= "stop-a",
1797 		.data		= &stop_a_enabled,
1798 		.maxlen		= sizeof (int),
1799 		.mode		= 0644,
1800 		.proc_handler	= proc_dointvec,
1801 	},
1802 	{
1803 		.procname	= "scons-poweroff",
1804 		.data		= &scons_pwroff,
1805 		.maxlen		= sizeof (int),
1806 		.mode		= 0644,
1807 		.proc_handler	= proc_dointvec,
1808 	},
1809 #endif
1810 #ifdef CONFIG_SPARC64
1811 	{
1812 		.procname	= "tsb-ratio",
1813 		.data		= &sysctl_tsb_ratio,
1814 		.maxlen		= sizeof (int),
1815 		.mode		= 0644,
1816 		.proc_handler	= proc_dointvec,
1817 	},
1818 #endif
1819 #ifdef CONFIG_PARISC
1820 	{
1821 		.procname	= "soft-power",
1822 		.data		= &pwrsw_enabled,
1823 		.maxlen		= sizeof (int),
1824 		.mode		= 0644,
1825 		.proc_handler	= proc_dointvec,
1826 	},
1827 #endif
1828 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
1829 	{
1830 		.procname	= "unaligned-trap",
1831 		.data		= &unaligned_enabled,
1832 		.maxlen		= sizeof (int),
1833 		.mode		= 0644,
1834 		.proc_handler	= proc_dointvec,
1835 	},
1836 #endif
1837 	{
1838 		.procname	= "ctrl-alt-del",
1839 		.data		= &C_A_D,
1840 		.maxlen		= sizeof(int),
1841 		.mode		= 0644,
1842 		.proc_handler	= proc_dointvec,
1843 	},
1844 #ifdef CONFIG_FUNCTION_TRACER
1845 	{
1846 		.procname	= "ftrace_enabled",
1847 		.data		= &ftrace_enabled,
1848 		.maxlen		= sizeof(int),
1849 		.mode		= 0644,
1850 		.proc_handler	= ftrace_enable_sysctl,
1851 	},
1852 #endif
1853 #ifdef CONFIG_STACK_TRACER
1854 	{
1855 		.procname	= "stack_tracer_enabled",
1856 		.data		= &stack_tracer_enabled,
1857 		.maxlen		= sizeof(int),
1858 		.mode		= 0644,
1859 		.proc_handler	= stack_trace_sysctl,
1860 	},
1861 #endif
1862 #ifdef CONFIG_TRACING
1863 	{
1864 		.procname	= "ftrace_dump_on_oops",
1865 		.data		= &ftrace_dump_on_oops,
1866 		.maxlen		= sizeof(int),
1867 		.mode		= 0644,
1868 		.proc_handler	= proc_dointvec,
1869 	},
1870 	{
1871 		.procname	= "traceoff_on_warning",
1872 		.data		= &__disable_trace_on_warning,
1873 		.maxlen		= sizeof(__disable_trace_on_warning),
1874 		.mode		= 0644,
1875 		.proc_handler	= proc_dointvec,
1876 	},
1877 	{
1878 		.procname	= "tracepoint_printk",
1879 		.data		= &tracepoint_printk,
1880 		.maxlen		= sizeof(tracepoint_printk),
1881 		.mode		= 0644,
1882 		.proc_handler	= tracepoint_printk_sysctl,
1883 	},
1884 #endif
1885 #ifdef CONFIG_KEXEC_CORE
1886 	{
1887 		.procname	= "kexec_load_disabled",
1888 		.data		= &kexec_load_disabled,
1889 		.maxlen		= sizeof(int),
1890 		.mode		= 0644,
1891 		/* only handle a transition from default "0" to "1" */
1892 		.proc_handler	= proc_dointvec_minmax,
1893 		.extra1		= SYSCTL_ONE,
1894 		.extra2		= SYSCTL_ONE,
1895 	},
1896 #endif
1897 #ifdef CONFIG_MODULES
1898 	{
1899 		.procname	= "modprobe",
1900 		.data		= &modprobe_path,
1901 		.maxlen		= KMOD_PATH_LEN,
1902 		.mode		= 0644,
1903 		.proc_handler	= proc_dostring,
1904 	},
1905 	{
1906 		.procname	= "modules_disabled",
1907 		.data		= &modules_disabled,
1908 		.maxlen		= sizeof(int),
1909 		.mode		= 0644,
1910 		/* only handle a transition from default "0" to "1" */
1911 		.proc_handler	= proc_dointvec_minmax,
1912 		.extra1		= SYSCTL_ONE,
1913 		.extra2		= SYSCTL_ONE,
1914 	},
1915 #endif
1916 #ifdef CONFIG_UEVENT_HELPER
1917 	{
1918 		.procname	= "hotplug",
1919 		.data		= &uevent_helper,
1920 		.maxlen		= UEVENT_HELPER_PATH_LEN,
1921 		.mode		= 0644,
1922 		.proc_handler	= proc_dostring,
1923 	},
1924 #endif
1925 #ifdef CONFIG_BSD_PROCESS_ACCT
1926 	{
1927 		.procname	= "acct",
1928 		.data		= &acct_parm,
1929 		.maxlen		= 3*sizeof(int),
1930 		.mode		= 0644,
1931 		.proc_handler	= proc_dointvec,
1932 	},
1933 #endif
1934 #ifdef CONFIG_MAGIC_SYSRQ
1935 	{
1936 		.procname	= "sysrq",
1937 		.data		= NULL,
1938 		.maxlen		= sizeof (int),
1939 		.mode		= 0644,
1940 		.proc_handler	= sysrq_sysctl_handler,
1941 	},
1942 #endif
1943 #ifdef CONFIG_PROC_SYSCTL
1944 	{
1945 		.procname	= "cad_pid",
1946 		.data		= NULL,
1947 		.maxlen		= sizeof (int),
1948 		.mode		= 0600,
1949 		.proc_handler	= proc_do_cad_pid,
1950 	},
1951 #endif
1952 	{
1953 		.procname	= "threads-max",
1954 		.data		= NULL,
1955 		.maxlen		= sizeof(int),
1956 		.mode		= 0644,
1957 		.proc_handler	= sysctl_max_threads,
1958 	},
1959 	{
1960 		.procname	= "usermodehelper",
1961 		.mode		= 0555,
1962 		.child		= usermodehelper_table,
1963 	},
1964 	{
1965 		.procname	= "overflowuid",
1966 		.data		= &overflowuid,
1967 		.maxlen		= sizeof(int),
1968 		.mode		= 0644,
1969 		.proc_handler	= proc_dointvec_minmax,
1970 		.extra1		= SYSCTL_ZERO,
1971 		.extra2		= SYSCTL_MAXOLDUID,
1972 	},
1973 	{
1974 		.procname	= "overflowgid",
1975 		.data		= &overflowgid,
1976 		.maxlen		= sizeof(int),
1977 		.mode		= 0644,
1978 		.proc_handler	= proc_dointvec_minmax,
1979 		.extra1		= SYSCTL_ZERO,
1980 		.extra2		= SYSCTL_MAXOLDUID,
1981 	},
1982 #ifdef CONFIG_S390
1983 	{
1984 		.procname	= "userprocess_debug",
1985 		.data		= &show_unhandled_signals,
1986 		.maxlen		= sizeof(int),
1987 		.mode		= 0644,
1988 		.proc_handler	= proc_dointvec,
1989 	},
1990 #endif
1991 #ifdef CONFIG_SMP
1992 	{
1993 		.procname	= "oops_all_cpu_backtrace",
1994 		.data		= &sysctl_oops_all_cpu_backtrace,
1995 		.maxlen		= sizeof(int),
1996 		.mode		= 0644,
1997 		.proc_handler	= proc_dointvec_minmax,
1998 		.extra1		= SYSCTL_ZERO,
1999 		.extra2		= SYSCTL_ONE,
2000 	},
2001 #endif /* CONFIG_SMP */
2002 	{
2003 		.procname	= "pid_max",
2004 		.data		= &pid_max,
2005 		.maxlen		= sizeof (int),
2006 		.mode		= 0644,
2007 		.proc_handler	= proc_dointvec_minmax,
2008 		.extra1		= &pid_max_min,
2009 		.extra2		= &pid_max_max,
2010 	},
2011 	{
2012 		.procname	= "panic_on_oops",
2013 		.data		= &panic_on_oops,
2014 		.maxlen		= sizeof(int),
2015 		.mode		= 0644,
2016 		.proc_handler	= proc_dointvec,
2017 	},
2018 	{
2019 		.procname	= "panic_print",
2020 		.data		= &panic_print,
2021 		.maxlen		= sizeof(unsigned long),
2022 		.mode		= 0644,
2023 		.proc_handler	= proc_doulongvec_minmax,
2024 	},
2025 	{
2026 		.procname	= "ngroups_max",
2027 		.data		= (void *)&ngroups_max,
2028 		.maxlen		= sizeof (int),
2029 		.mode		= 0444,
2030 		.proc_handler	= proc_dointvec,
2031 	},
2032 	{
2033 		.procname	= "cap_last_cap",
2034 		.data		= (void *)&cap_last_cap,
2035 		.maxlen		= sizeof(int),
2036 		.mode		= 0444,
2037 		.proc_handler	= proc_dointvec,
2038 	},
2039 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
2040 	{
2041 		.procname       = "unknown_nmi_panic",
2042 		.data           = &unknown_nmi_panic,
2043 		.maxlen         = sizeof (int),
2044 		.mode           = 0644,
2045 		.proc_handler   = proc_dointvec,
2046 	},
2047 #endif
2048 
2049 #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
2050 	defined(CONFIG_DEBUG_STACKOVERFLOW)
2051 	{
2052 		.procname	= "panic_on_stackoverflow",
2053 		.data		= &sysctl_panic_on_stackoverflow,
2054 		.maxlen		= sizeof(int),
2055 		.mode		= 0644,
2056 		.proc_handler	= proc_dointvec,
2057 	},
2058 #endif
2059 #if defined(CONFIG_X86)
2060 	{
2061 		.procname	= "panic_on_unrecovered_nmi",
2062 		.data		= &panic_on_unrecovered_nmi,
2063 		.maxlen		= sizeof(int),
2064 		.mode		= 0644,
2065 		.proc_handler	= proc_dointvec,
2066 	},
2067 	{
2068 		.procname	= "panic_on_io_nmi",
2069 		.data		= &panic_on_io_nmi,
2070 		.maxlen		= sizeof(int),
2071 		.mode		= 0644,
2072 		.proc_handler	= proc_dointvec,
2073 	},
2074 	{
2075 		.procname	= "bootloader_type",
2076 		.data		= &bootloader_type,
2077 		.maxlen		= sizeof (int),
2078 		.mode		= 0444,
2079 		.proc_handler	= proc_dointvec,
2080 	},
2081 	{
2082 		.procname	= "bootloader_version",
2083 		.data		= &bootloader_version,
2084 		.maxlen		= sizeof (int),
2085 		.mode		= 0444,
2086 		.proc_handler	= proc_dointvec,
2087 	},
2088 	{
2089 		.procname	= "io_delay_type",
2090 		.data		= &io_delay_type,
2091 		.maxlen		= sizeof(int),
2092 		.mode		= 0644,
2093 		.proc_handler	= proc_dointvec,
2094 	},
2095 #endif
2096 #if defined(CONFIG_MMU)
2097 	{
2098 		.procname	= "randomize_va_space",
2099 		.data		= &randomize_va_space,
2100 		.maxlen		= sizeof(int),
2101 		.mode		= 0644,
2102 		.proc_handler	= proc_dointvec,
2103 	},
2104 #endif
2105 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
2106 	{
2107 		.procname	= "spin_retry",
2108 		.data		= &spin_retry,
2109 		.maxlen		= sizeof (int),
2110 		.mode		= 0644,
2111 		.proc_handler	= proc_dointvec,
2112 	},
2113 #endif
2114 #if	defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
2115 	{
2116 		.procname	= "acpi_video_flags",
2117 		.data		= &acpi_realmode_flags,
2118 		.maxlen		= sizeof (unsigned long),
2119 		.mode		= 0644,
2120 		.proc_handler	= proc_doulongvec_minmax,
2121 	},
2122 #endif
2123 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
2124 	{
2125 		.procname	= "ignore-unaligned-usertrap",
2126 		.data		= &no_unaligned_warning,
2127 		.maxlen		= sizeof (int),
2128 		.mode		= 0644,
2129 		.proc_handler	= proc_dointvec,
2130 	},
2131 #endif
2132 #ifdef CONFIG_IA64
2133 	{
2134 		.procname	= "unaligned-dump-stack",
2135 		.data		= &unaligned_dump_stack,
2136 		.maxlen		= sizeof (int),
2137 		.mode		= 0644,
2138 		.proc_handler	= proc_dointvec,
2139 	},
2140 #endif
2141 #ifdef CONFIG_RT_MUTEXES
2142 	{
2143 		.procname	= "max_lock_depth",
2144 		.data		= &max_lock_depth,
2145 		.maxlen		= sizeof(int),
2146 		.mode		= 0644,
2147 		.proc_handler	= proc_dointvec,
2148 	},
2149 #endif
2150 	{
2151 		.procname	= "poweroff_cmd",
2152 		.data		= &poweroff_cmd,
2153 		.maxlen		= POWEROFF_CMD_PATH_LEN,
2154 		.mode		= 0644,
2155 		.proc_handler	= proc_dostring,
2156 	},
2157 #ifdef CONFIG_KEYS
2158 	{
2159 		.procname	= "keys",
2160 		.mode		= 0555,
2161 		.child		= key_sysctls,
2162 	},
2163 #endif
2164 #ifdef CONFIG_PERF_EVENTS
2165 	/*
2166 	 * User-space scripts rely on the existence of this file
2167 	 * as a feature check for perf_events being enabled.
2168 	 *
2169 	 * So it's an ABI, do not remove!
2170 	 */
2171 	{
2172 		.procname	= "perf_event_paranoid",
2173 		.data		= &sysctl_perf_event_paranoid,
2174 		.maxlen		= sizeof(sysctl_perf_event_paranoid),
2175 		.mode		= 0644,
2176 		.proc_handler	= proc_dointvec,
2177 	},
2178 	{
2179 		.procname	= "perf_event_mlock_kb",
2180 		.data		= &sysctl_perf_event_mlock,
2181 		.maxlen		= sizeof(sysctl_perf_event_mlock),
2182 		.mode		= 0644,
2183 		.proc_handler	= proc_dointvec,
2184 	},
2185 	{
2186 		.procname	= "perf_event_max_sample_rate",
2187 		.data		= &sysctl_perf_event_sample_rate,
2188 		.maxlen		= sizeof(sysctl_perf_event_sample_rate),
2189 		.mode		= 0644,
2190 		.proc_handler	= perf_proc_update_handler,
2191 		.extra1		= SYSCTL_ONE,
2192 	},
2193 	{
2194 		.procname	= "perf_cpu_time_max_percent",
2195 		.data		= &sysctl_perf_cpu_time_max_percent,
2196 		.maxlen		= sizeof(sysctl_perf_cpu_time_max_percent),
2197 		.mode		= 0644,
2198 		.proc_handler	= perf_cpu_time_max_percent_handler,
2199 		.extra1		= SYSCTL_ZERO,
2200 		.extra2		= SYSCTL_ONE_HUNDRED,
2201 	},
2202 	{
2203 		.procname	= "perf_event_max_stack",
2204 		.data		= &sysctl_perf_event_max_stack,
2205 		.maxlen		= sizeof(sysctl_perf_event_max_stack),
2206 		.mode		= 0644,
2207 		.proc_handler	= perf_event_max_stack_handler,
2208 		.extra1		= SYSCTL_ZERO,
2209 		.extra2		= (void *)&six_hundred_forty_kb,
2210 	},
2211 	{
2212 		.procname	= "perf_event_max_contexts_per_stack",
2213 		.data		= &sysctl_perf_event_max_contexts_per_stack,
2214 		.maxlen		= sizeof(sysctl_perf_event_max_contexts_per_stack),
2215 		.mode		= 0644,
2216 		.proc_handler	= perf_event_max_stack_handler,
2217 		.extra1		= SYSCTL_ZERO,
2218 		.extra2		= SYSCTL_ONE_THOUSAND,
2219 	},
2220 #endif
2221 	{
2222 		.procname	= "panic_on_warn",
2223 		.data		= &panic_on_warn,
2224 		.maxlen		= sizeof(int),
2225 		.mode		= 0644,
2226 		.proc_handler	= proc_dointvec_minmax,
2227 		.extra1		= SYSCTL_ZERO,
2228 		.extra2		= SYSCTL_ONE,
2229 	},
2230 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
2231 	{
2232 		.procname	= "timer_migration",
2233 		.data		= &sysctl_timer_migration,
2234 		.maxlen		= sizeof(unsigned int),
2235 		.mode		= 0644,
2236 		.proc_handler	= timer_migration_handler,
2237 		.extra1		= SYSCTL_ZERO,
2238 		.extra2		= SYSCTL_ONE,
2239 	},
2240 #endif
2241 #if defined(CONFIG_TREE_RCU)
2242 	{
2243 		.procname	= "panic_on_rcu_stall",
2244 		.data		= &sysctl_panic_on_rcu_stall,
2245 		.maxlen		= sizeof(sysctl_panic_on_rcu_stall),
2246 		.mode		= 0644,
2247 		.proc_handler	= proc_dointvec_minmax,
2248 		.extra1		= SYSCTL_ZERO,
2249 		.extra2		= SYSCTL_ONE,
2250 	},
2251 #endif
2252 #if defined(CONFIG_TREE_RCU)
2253 	{
2254 		.procname	= "max_rcu_stall_to_panic",
2255 		.data		= &sysctl_max_rcu_stall_to_panic,
2256 		.maxlen		= sizeof(sysctl_max_rcu_stall_to_panic),
2257 		.mode		= 0644,
2258 		.proc_handler	= proc_dointvec_minmax,
2259 		.extra1		= SYSCTL_ONE,
2260 		.extra2		= SYSCTL_INT_MAX,
2261 	},
2262 #endif
2263 	{ }
2264 };
2265 
2266 static struct ctl_table vm_table[] = {
2267 	{
2268 		.procname	= "overcommit_memory",
2269 		.data		= &sysctl_overcommit_memory,
2270 		.maxlen		= sizeof(sysctl_overcommit_memory),
2271 		.mode		= 0644,
2272 		.proc_handler	= overcommit_policy_handler,
2273 		.extra1		= SYSCTL_ZERO,
2274 		.extra2		= SYSCTL_TWO,
2275 	},
2276 	{
2277 		.procname	= "panic_on_oom",
2278 		.data		= &sysctl_panic_on_oom,
2279 		.maxlen		= sizeof(sysctl_panic_on_oom),
2280 		.mode		= 0644,
2281 		.proc_handler	= proc_dointvec_minmax,
2282 		.extra1		= SYSCTL_ZERO,
2283 		.extra2		= SYSCTL_TWO,
2284 	},
2285 	{
2286 		.procname	= "oom_kill_allocating_task",
2287 		.data		= &sysctl_oom_kill_allocating_task,
2288 		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
2289 		.mode		= 0644,
2290 		.proc_handler	= proc_dointvec,
2291 	},
2292 	{
2293 		.procname	= "oom_dump_tasks",
2294 		.data		= &sysctl_oom_dump_tasks,
2295 		.maxlen		= sizeof(sysctl_oom_dump_tasks),
2296 		.mode		= 0644,
2297 		.proc_handler	= proc_dointvec,
2298 	},
2299 	{
2300 		.procname	= "overcommit_ratio",
2301 		.data		= &sysctl_overcommit_ratio,
2302 		.maxlen		= sizeof(sysctl_overcommit_ratio),
2303 		.mode		= 0644,
2304 		.proc_handler	= overcommit_ratio_handler,
2305 	},
2306 	{
2307 		.procname	= "overcommit_kbytes",
2308 		.data		= &sysctl_overcommit_kbytes,
2309 		.maxlen		= sizeof(sysctl_overcommit_kbytes),
2310 		.mode		= 0644,
2311 		.proc_handler	= overcommit_kbytes_handler,
2312 	},
2313 	{
2314 		.procname	= "page-cluster",
2315 		.data		= &page_cluster,
2316 		.maxlen		= sizeof(int),
2317 		.mode		= 0644,
2318 		.proc_handler	= proc_dointvec_minmax,
2319 		.extra1		= SYSCTL_ZERO,
2320 	},
2321 	{
2322 		.procname	= "dirty_background_ratio",
2323 		.data		= &dirty_background_ratio,
2324 		.maxlen		= sizeof(dirty_background_ratio),
2325 		.mode		= 0644,
2326 		.proc_handler	= dirty_background_ratio_handler,
2327 		.extra1		= SYSCTL_ZERO,
2328 		.extra2		= SYSCTL_ONE_HUNDRED,
2329 	},
2330 	{
2331 		.procname	= "dirty_background_bytes",
2332 		.data		= &dirty_background_bytes,
2333 		.maxlen		= sizeof(dirty_background_bytes),
2334 		.mode		= 0644,
2335 		.proc_handler	= dirty_background_bytes_handler,
2336 		.extra1		= SYSCTL_LONG_ONE,
2337 	},
2338 	{
2339 		.procname	= "dirty_ratio",
2340 		.data		= &vm_dirty_ratio,
2341 		.maxlen		= sizeof(vm_dirty_ratio),
2342 		.mode		= 0644,
2343 		.proc_handler	= dirty_ratio_handler,
2344 		.extra1		= SYSCTL_ZERO,
2345 		.extra2		= SYSCTL_ONE_HUNDRED,
2346 	},
2347 	{
2348 		.procname	= "dirty_bytes",
2349 		.data		= &vm_dirty_bytes,
2350 		.maxlen		= sizeof(vm_dirty_bytes),
2351 		.mode		= 0644,
2352 		.proc_handler	= dirty_bytes_handler,
2353 		.extra1		= (void *)&dirty_bytes_min,
2354 	},
2355 	{
2356 		.procname	= "dirty_writeback_centisecs",
2357 		.data		= &dirty_writeback_interval,
2358 		.maxlen		= sizeof(dirty_writeback_interval),
2359 		.mode		= 0644,
2360 		.proc_handler	= dirty_writeback_centisecs_handler,
2361 	},
2362 	{
2363 		.procname	= "dirty_expire_centisecs",
2364 		.data		= &dirty_expire_interval,
2365 		.maxlen		= sizeof(dirty_expire_interval),
2366 		.mode		= 0644,
2367 		.proc_handler	= proc_dointvec_minmax,
2368 		.extra1		= SYSCTL_ZERO,
2369 	},
2370 	{
2371 		.procname	= "dirtytime_expire_seconds",
2372 		.data		= &dirtytime_expire_interval,
2373 		.maxlen		= sizeof(dirtytime_expire_interval),
2374 		.mode		= 0644,
2375 		.proc_handler	= dirtytime_interval_handler,
2376 		.extra1		= SYSCTL_ZERO,
2377 	},
2378 	{
2379 		.procname	= "swappiness",
2380 		.data		= &vm_swappiness,
2381 		.maxlen		= sizeof(vm_swappiness),
2382 		.mode		= 0644,
2383 		.proc_handler	= proc_dointvec_minmax,
2384 		.extra1		= SYSCTL_ZERO,
2385 		.extra2		= SYSCTL_TWO_HUNDRED,
2386 	},
2387 #ifdef CONFIG_HUGETLB_PAGE
2388 	{
2389 		.procname	= "nr_hugepages",
2390 		.data		= NULL,
2391 		.maxlen		= sizeof(unsigned long),
2392 		.mode		= 0644,
2393 		.proc_handler	= hugetlb_sysctl_handler,
2394 	},
2395 #ifdef CONFIG_NUMA
2396 	{
2397 		.procname       = "nr_hugepages_mempolicy",
2398 		.data           = NULL,
2399 		.maxlen         = sizeof(unsigned long),
2400 		.mode           = 0644,
2401 		.proc_handler   = &hugetlb_mempolicy_sysctl_handler,
2402 	},
2403 	{
2404 		.procname		= "numa_stat",
2405 		.data			= &sysctl_vm_numa_stat,
2406 		.maxlen			= sizeof(int),
2407 		.mode			= 0644,
2408 		.proc_handler	= sysctl_vm_numa_stat_handler,
2409 		.extra1			= SYSCTL_ZERO,
2410 		.extra2			= SYSCTL_ONE,
2411 	},
2412 #endif
2413 	 {
2414 		.procname	= "hugetlb_shm_group",
2415 		.data		= &sysctl_hugetlb_shm_group,
2416 		.maxlen		= sizeof(gid_t),
2417 		.mode		= 0644,
2418 		.proc_handler	= proc_dointvec,
2419 	 },
2420 	{
2421 		.procname	= "nr_overcommit_hugepages",
2422 		.data		= NULL,
2423 		.maxlen		= sizeof(unsigned long),
2424 		.mode		= 0644,
2425 		.proc_handler	= hugetlb_overcommit_handler,
2426 	},
2427 #endif
2428 	{
2429 		.procname	= "lowmem_reserve_ratio",
2430 		.data		= &sysctl_lowmem_reserve_ratio,
2431 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
2432 		.mode		= 0644,
2433 		.proc_handler	= lowmem_reserve_ratio_sysctl_handler,
2434 	},
2435 	{
2436 		.procname	= "drop_caches",
2437 		.data		= &sysctl_drop_caches,
2438 		.maxlen		= sizeof(int),
2439 		.mode		= 0200,
2440 		.proc_handler	= drop_caches_sysctl_handler,
2441 		.extra1		= SYSCTL_ONE,
2442 		.extra2		= SYSCTL_FOUR,
2443 	},
2444 #ifdef CONFIG_COMPACTION
2445 	{
2446 		.procname	= "compact_memory",
2447 		.data		= NULL,
2448 		.maxlen		= sizeof(int),
2449 		.mode		= 0200,
2450 		.proc_handler	= sysctl_compaction_handler,
2451 	},
2452 	{
2453 		.procname	= "compaction_proactiveness",
2454 		.data		= &sysctl_compaction_proactiveness,
2455 		.maxlen		= sizeof(sysctl_compaction_proactiveness),
2456 		.mode		= 0644,
2457 		.proc_handler	= compaction_proactiveness_sysctl_handler,
2458 		.extra1		= SYSCTL_ZERO,
2459 		.extra2		= SYSCTL_ONE_HUNDRED,
2460 	},
2461 	{
2462 		.procname	= "extfrag_threshold",
2463 		.data		= &sysctl_extfrag_threshold,
2464 		.maxlen		= sizeof(int),
2465 		.mode		= 0644,
2466 		.proc_handler	= proc_dointvec_minmax,
2467 		.extra1		= SYSCTL_ZERO,
2468 		.extra2		= (void *)&max_extfrag_threshold,
2469 	},
2470 	{
2471 		.procname	= "compact_unevictable_allowed",
2472 		.data		= &sysctl_compact_unevictable_allowed,
2473 		.maxlen		= sizeof(int),
2474 		.mode		= 0644,
2475 		.proc_handler	= proc_dointvec_minmax_warn_RT_change,
2476 		.extra1		= SYSCTL_ZERO,
2477 		.extra2		= SYSCTL_ONE,
2478 	},
2479 
2480 #endif /* CONFIG_COMPACTION */
2481 	{
2482 		.procname	= "min_free_kbytes",
2483 		.data		= &min_free_kbytes,
2484 		.maxlen		= sizeof(min_free_kbytes),
2485 		.mode		= 0644,
2486 		.proc_handler	= min_free_kbytes_sysctl_handler,
2487 		.extra1		= SYSCTL_ZERO,
2488 	},
2489 	{
2490 		.procname	= "watermark_boost_factor",
2491 		.data		= &watermark_boost_factor,
2492 		.maxlen		= sizeof(watermark_boost_factor),
2493 		.mode		= 0644,
2494 		.proc_handler	= proc_dointvec_minmax,
2495 		.extra1		= SYSCTL_ZERO,
2496 	},
2497 	{
2498 		.procname	= "watermark_scale_factor",
2499 		.data		= &watermark_scale_factor,
2500 		.maxlen		= sizeof(watermark_scale_factor),
2501 		.mode		= 0644,
2502 		.proc_handler	= watermark_scale_factor_sysctl_handler,
2503 		.extra1		= SYSCTL_ONE,
2504 		.extra2		= SYSCTL_THREE_THOUSAND,
2505 	},
2506 	{
2507 		.procname	= "percpu_pagelist_high_fraction",
2508 		.data		= &percpu_pagelist_high_fraction,
2509 		.maxlen		= sizeof(percpu_pagelist_high_fraction),
2510 		.mode		= 0644,
2511 		.proc_handler	= percpu_pagelist_high_fraction_sysctl_handler,
2512 		.extra1		= SYSCTL_ZERO,
2513 	},
2514 	{
2515 		.procname	= "page_lock_unfairness",
2516 		.data		= &sysctl_page_lock_unfairness,
2517 		.maxlen		= sizeof(sysctl_page_lock_unfairness),
2518 		.mode		= 0644,
2519 		.proc_handler	= proc_dointvec_minmax,
2520 		.extra1		= SYSCTL_ZERO,
2521 	},
2522 #ifdef CONFIG_MMU
2523 	{
2524 		.procname	= "max_map_count",
2525 		.data		= &sysctl_max_map_count,
2526 		.maxlen		= sizeof(sysctl_max_map_count),
2527 		.mode		= 0644,
2528 		.proc_handler	= proc_dointvec_minmax,
2529 		.extra1		= SYSCTL_ZERO,
2530 	},
2531 #else
2532 	{
2533 		.procname	= "nr_trim_pages",
2534 		.data		= &sysctl_nr_trim_pages,
2535 		.maxlen		= sizeof(sysctl_nr_trim_pages),
2536 		.mode		= 0644,
2537 		.proc_handler	= proc_dointvec_minmax,
2538 		.extra1		= SYSCTL_ZERO,
2539 	},
2540 #endif
2541 	{
2542 		.procname	= "laptop_mode",
2543 		.data		= &laptop_mode,
2544 		.maxlen		= sizeof(laptop_mode),
2545 		.mode		= 0644,
2546 		.proc_handler	= proc_dointvec_jiffies,
2547 	},
2548 	{
2549 		.procname	= "vfs_cache_pressure",
2550 		.data		= &sysctl_vfs_cache_pressure,
2551 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
2552 		.mode		= 0644,
2553 		.proc_handler	= proc_dointvec_minmax,
2554 		.extra1		= SYSCTL_ZERO,
2555 	},
2556 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
2557     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
2558 	{
2559 		.procname	= "legacy_va_layout",
2560 		.data		= &sysctl_legacy_va_layout,
2561 		.maxlen		= sizeof(sysctl_legacy_va_layout),
2562 		.mode		= 0644,
2563 		.proc_handler	= proc_dointvec_minmax,
2564 		.extra1		= SYSCTL_ZERO,
2565 	},
2566 #endif
2567 #ifdef CONFIG_NUMA
2568 	{
2569 		.procname	= "zone_reclaim_mode",
2570 		.data		= &node_reclaim_mode,
2571 		.maxlen		= sizeof(node_reclaim_mode),
2572 		.mode		= 0644,
2573 		.proc_handler	= proc_dointvec_minmax,
2574 		.extra1		= SYSCTL_ZERO,
2575 	},
2576 	{
2577 		.procname	= "min_unmapped_ratio",
2578 		.data		= &sysctl_min_unmapped_ratio,
2579 		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
2580 		.mode		= 0644,
2581 		.proc_handler	= sysctl_min_unmapped_ratio_sysctl_handler,
2582 		.extra1		= SYSCTL_ZERO,
2583 		.extra2		= SYSCTL_ONE_HUNDRED,
2584 	},
2585 	{
2586 		.procname	= "min_slab_ratio",
2587 		.data		= &sysctl_min_slab_ratio,
2588 		.maxlen		= sizeof(sysctl_min_slab_ratio),
2589 		.mode		= 0644,
2590 		.proc_handler	= sysctl_min_slab_ratio_sysctl_handler,
2591 		.extra1		= SYSCTL_ZERO,
2592 		.extra2		= SYSCTL_ONE_HUNDRED,
2593 	},
2594 #endif
2595 #ifdef CONFIG_SMP
2596 	{
2597 		.procname	= "stat_interval",
2598 		.data		= &sysctl_stat_interval,
2599 		.maxlen		= sizeof(sysctl_stat_interval),
2600 		.mode		= 0644,
2601 		.proc_handler	= proc_dointvec_jiffies,
2602 	},
2603 	{
2604 		.procname	= "stat_refresh",
2605 		.data		= NULL,
2606 		.maxlen		= 0,
2607 		.mode		= 0600,
2608 		.proc_handler	= vmstat_refresh,
2609 	},
2610 #endif
2611 #ifdef CONFIG_MMU
2612 	{
2613 		.procname	= "mmap_min_addr",
2614 		.data		= &dac_mmap_min_addr,
2615 		.maxlen		= sizeof(unsigned long),
2616 		.mode		= 0644,
2617 		.proc_handler	= mmap_min_addr_handler,
2618 	},
2619 #endif
2620 #ifdef CONFIG_NUMA
2621 	{
2622 		.procname	= "numa_zonelist_order",
2623 		.data		= &numa_zonelist_order,
2624 		.maxlen		= NUMA_ZONELIST_ORDER_LEN,
2625 		.mode		= 0644,
2626 		.proc_handler	= numa_zonelist_order_handler,
2627 	},
2628 #endif
2629 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
2630    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
2631 	{
2632 		.procname	= "vdso_enabled",
2633 #ifdef CONFIG_X86_32
2634 		.data		= &vdso32_enabled,
2635 		.maxlen		= sizeof(vdso32_enabled),
2636 #else
2637 		.data		= &vdso_enabled,
2638 		.maxlen		= sizeof(vdso_enabled),
2639 #endif
2640 		.mode		= 0644,
2641 		.proc_handler	= proc_dointvec,
2642 		.extra1		= SYSCTL_ZERO,
2643 	},
2644 #endif
2645 #ifdef CONFIG_HIGHMEM
2646 	{
2647 		.procname	= "highmem_is_dirtyable",
2648 		.data		= &vm_highmem_is_dirtyable,
2649 		.maxlen		= sizeof(vm_highmem_is_dirtyable),
2650 		.mode		= 0644,
2651 		.proc_handler	= proc_dointvec_minmax,
2652 		.extra1		= SYSCTL_ZERO,
2653 		.extra2		= SYSCTL_ONE,
2654 	},
2655 #endif
2656 #ifdef CONFIG_MEMORY_FAILURE
2657 	{
2658 		.procname	= "memory_failure_early_kill",
2659 		.data		= &sysctl_memory_failure_early_kill,
2660 		.maxlen		= sizeof(sysctl_memory_failure_early_kill),
2661 		.mode		= 0644,
2662 		.proc_handler	= proc_dointvec_minmax,
2663 		.extra1		= SYSCTL_ZERO,
2664 		.extra2		= SYSCTL_ONE,
2665 	},
2666 	{
2667 		.procname	= "memory_failure_recovery",
2668 		.data		= &sysctl_memory_failure_recovery,
2669 		.maxlen		= sizeof(sysctl_memory_failure_recovery),
2670 		.mode		= 0644,
2671 		.proc_handler	= proc_dointvec_minmax,
2672 		.extra1		= SYSCTL_ZERO,
2673 		.extra2		= SYSCTL_ONE,
2674 	},
2675 #endif
2676 	{
2677 		.procname	= "user_reserve_kbytes",
2678 		.data		= &sysctl_user_reserve_kbytes,
2679 		.maxlen		= sizeof(sysctl_user_reserve_kbytes),
2680 		.mode		= 0644,
2681 		.proc_handler	= proc_doulongvec_minmax,
2682 	},
2683 	{
2684 		.procname	= "admin_reserve_kbytes",
2685 		.data		= &sysctl_admin_reserve_kbytes,
2686 		.maxlen		= sizeof(sysctl_admin_reserve_kbytes),
2687 		.mode		= 0644,
2688 		.proc_handler	= proc_doulongvec_minmax,
2689 	},
2690 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
2691 	{
2692 		.procname	= "mmap_rnd_bits",
2693 		.data		= &mmap_rnd_bits,
2694 		.maxlen		= sizeof(mmap_rnd_bits),
2695 		.mode		= 0600,
2696 		.proc_handler	= proc_dointvec_minmax,
2697 		.extra1		= (void *)&mmap_rnd_bits_min,
2698 		.extra2		= (void *)&mmap_rnd_bits_max,
2699 	},
2700 #endif
2701 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
2702 	{
2703 		.procname	= "mmap_rnd_compat_bits",
2704 		.data		= &mmap_rnd_compat_bits,
2705 		.maxlen		= sizeof(mmap_rnd_compat_bits),
2706 		.mode		= 0600,
2707 		.proc_handler	= proc_dointvec_minmax,
2708 		.extra1		= (void *)&mmap_rnd_compat_bits_min,
2709 		.extra2		= (void *)&mmap_rnd_compat_bits_max,
2710 	},
2711 #endif
2712 #ifdef CONFIG_USERFAULTFD
2713 	{
2714 		.procname	= "unprivileged_userfaultfd",
2715 		.data		= &sysctl_unprivileged_userfaultfd,
2716 		.maxlen		= sizeof(sysctl_unprivileged_userfaultfd),
2717 		.mode		= 0644,
2718 		.proc_handler	= proc_dointvec_minmax,
2719 		.extra1		= SYSCTL_ZERO,
2720 		.extra2		= SYSCTL_ONE,
2721 	},
2722 #endif
2723 	{ }
2724 };
2725 
2726 static struct ctl_table debug_table[] = {
2727 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
2728 	{
2729 		.procname	= "exception-trace",
2730 		.data		= &show_unhandled_signals,
2731 		.maxlen		= sizeof(int),
2732 		.mode		= 0644,
2733 		.proc_handler	= proc_dointvec
2734 	},
2735 #endif
2736 	{ }
2737 };
2738 
2739 static struct ctl_table dev_table[] = {
2740 	{ }
2741 };
2742 
2743 DECLARE_SYSCTL_BASE(kernel, kern_table);
2744 DECLARE_SYSCTL_BASE(vm, vm_table);
2745 DECLARE_SYSCTL_BASE(debug, debug_table);
2746 DECLARE_SYSCTL_BASE(dev, dev_table);
2747 
2748 int __init sysctl_init_bases(void)
2749 {
2750 	register_sysctl_base(kernel);
2751 	register_sysctl_base(vm);
2752 	register_sysctl_base(debug);
2753 	register_sysctl_base(dev);
2754 
2755 	return 0;
2756 }
2757 #endif /* CONFIG_SYSCTL */
2758 /*
2759  * No sense putting this after each symbol definition, twice,
2760  * exception granted :-)
2761  */
2762 EXPORT_SYMBOL(proc_dobool);
2763 EXPORT_SYMBOL(proc_dointvec);
2764 EXPORT_SYMBOL(proc_douintvec);
2765 EXPORT_SYMBOL(proc_dointvec_jiffies);
2766 EXPORT_SYMBOL(proc_dointvec_minmax);
2767 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
2768 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2769 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2770 EXPORT_SYMBOL(proc_dostring);
2771 EXPORT_SYMBOL(proc_doulongvec_minmax);
2772 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2773 EXPORT_SYMBOL(proc_do_large_bitmap);
2774