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