• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/aio.h>
24 #include <linux/mm.h>
25 #include <linux/swap.h>
26 #include <linux/slab.h>
27 #include <linux/sysctl.h>
28 #include <linux/bitmap.h>
29 #include <linux/signal.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/fs.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/kobject.h>
39 #include <linux/net.h>
40 #include <linux/sysrq.h>
41 #include <linux/highuid.h>
42 #include <linux/writeback.h>
43 #include <linux/ratelimit.h>
44 #include <linux/compaction.h>
45 #include <linux/hugetlb.h>
46 #include <linux/initrd.h>
47 #include <linux/key.h>
48 #include <linux/times.h>
49 #include <linux/limits.h>
50 #include <linux/dcache.h>
51 #include <linux/dnotify.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/kprobes.h>
60 #include <linux/pipe_fs_i.h>
61 #include <linux/oom.h>
62 #include <linux/kmod.h>
63 #include <linux/capability.h>
64 #include <linux/binfmts.h>
65 #include <linux/sched/sysctl.h>
66 #include <linux/sched/coredump.h>
67 #include <linux/kexec.h>
68 #include <linux/bpf.h>
69 #include <linux/mount.h>
70 #include <linux/userfaultfd_k.h>
71 #include <linux/coredump.h>
72 #include <linux/latencytop.h>
73 #include <linux/pid.h>
74 
75 #include "../lib/kstrtox.h"
76 
77 #include <linux/uaccess.h>
78 #include <asm/processor.h>
79 
80 #ifdef CONFIG_X86
81 #include <asm/nmi.h>
82 #include <asm/stacktrace.h>
83 #include <asm/io.h>
84 #endif
85 #ifdef CONFIG_SPARC
86 #include <asm/setup.h>
87 #endif
88 #ifdef CONFIG_BSD_PROCESS_ACCT
89 #include <linux/acct.h>
90 #endif
91 #ifdef CONFIG_RT_MUTEXES
92 #include <linux/rtmutex.h>
93 #endif
94 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
95 #include <linux/lockdep.h>
96 #endif
97 #ifdef CONFIG_CHR_DEV_SG
98 #include <scsi/sg.h>
99 #endif
100 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
101 #include <linux/stackleak.h>
102 #endif
103 #ifdef CONFIG_LOCKUP_DETECTOR
104 #include <linux/nmi.h>
105 #endif
106 
107 #if defined(CONFIG_SYSCTL)
108 
109 /* Constants used for minimum and  maximum */
110 #ifdef CONFIG_LOCKUP_DETECTOR
111 static int sixty = 60;
112 #endif
113 
114 static int __maybe_unused neg_one = -1;
115 static int __maybe_unused two = 2;
116 static int __maybe_unused four = 4;
117 static unsigned long zero_ul;
118 static unsigned long one_ul = 1;
119 static unsigned long long_max = LONG_MAX;
120 static int one_hundred = 100;
121 static int two_hundred = 200;
122 static int one_thousand = 1000;
123 #ifdef CONFIG_PRINTK
124 static int ten_thousand = 10000;
125 #endif
126 #ifdef CONFIG_PERF_EVENTS
127 static int six_hundred_forty_kb = 640 * 1024;
128 #endif
129 
130 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
131 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
132 
133 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
134 static int maxolduid = 65535;
135 static int minolduid;
136 
137 static int ngroups_max = NGROUPS_MAX;
138 static const int cap_last_cap = CAP_LAST_CAP;
139 
140 /*
141  * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
142  * and hung_task_check_interval_secs
143  */
144 #ifdef CONFIG_DETECT_HUNG_TASK
145 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
146 #endif
147 
148 #ifdef CONFIG_INOTIFY_USER
149 #include <linux/inotify.h>
150 #endif
151 
152 #ifdef CONFIG_PROC_SYSCTL
153 
154 /**
155  * enum sysctl_writes_mode - supported sysctl write modes
156  *
157  * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
158  *	to be written, and multiple writes on the same sysctl file descriptor
159  *	will rewrite the sysctl value, regardless of file position. No warning
160  *	is issued when the initial position is not 0.
161  * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
162  *	not 0.
163  * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
164  *	file position 0 and the value must be fully contained in the buffer
165  *	sent to the write syscall. If dealing with strings respect the file
166  *	position, but restrict this to the max length of the buffer, anything
167  *	passed the max length will be ignored. Multiple writes will append
168  *	to the buffer.
169  *
170  * These write modes control how current file position affects the behavior of
171  * updating sysctl values through the proc interface on each write.
172  */
173 enum sysctl_writes_mode {
174 	SYSCTL_WRITES_LEGACY		= -1,
175 	SYSCTL_WRITES_WARN		= 0,
176 	SYSCTL_WRITES_STRICT		= 1,
177 };
178 
179 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
180 #endif /* CONFIG_PROC_SYSCTL */
181 
182 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
183     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
184 int sysctl_legacy_va_layout;
185 #endif
186 
187 #ifdef CONFIG_SCHED_DEBUG
188 static int min_sched_granularity_ns = 100000;		/* 100 usecs */
189 static int max_sched_granularity_ns = NSEC_PER_SEC;	/* 1 second */
190 static int min_wakeup_granularity_ns;			/* 0 usecs */
191 static int max_wakeup_granularity_ns = NSEC_PER_SEC;	/* 1 second */
192 #ifdef CONFIG_SMP
193 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
194 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
195 #endif /* CONFIG_SMP */
196 #endif /* CONFIG_SCHED_DEBUG */
197 
198 #ifdef CONFIG_COMPACTION
199 static int min_extfrag_threshold;
200 static int max_extfrag_threshold = 1000;
201 #endif
202 
203 #endif /* CONFIG_SYSCTL */
204 
205 #if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL)
bpf_stats_handler(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)206 static int bpf_stats_handler(struct ctl_table *table, int write,
207 			     void *buffer, size_t *lenp, loff_t *ppos)
208 {
209 	struct static_key *key = (struct static_key *)table->data;
210 	static int saved_val;
211 	int val, ret;
212 	struct ctl_table tmp = {
213 		.data   = &val,
214 		.maxlen = sizeof(val),
215 		.mode   = table->mode,
216 		.extra1 = SYSCTL_ZERO,
217 		.extra2 = SYSCTL_ONE,
218 	};
219 
220 	if (write && !capable(CAP_SYS_ADMIN))
221 		return -EPERM;
222 
223 	mutex_lock(&bpf_stats_enabled_mutex);
224 	val = saved_val;
225 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
226 	if (write && !ret && val != saved_val) {
227 		if (val)
228 			static_key_slow_inc(key);
229 		else
230 			static_key_slow_dec(key);
231 		saved_val = val;
232 	}
233 	mutex_unlock(&bpf_stats_enabled_mutex);
234 	return ret;
235 }
236 
unpriv_ebpf_notify(int new_state)237 void __weak unpriv_ebpf_notify(int new_state)
238 {
239 }
240 
bpf_unpriv_handler(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)241 static int bpf_unpriv_handler(struct ctl_table *table, int write,
242 			      void *buffer, size_t *lenp, loff_t *ppos)
243 {
244 	int ret, unpriv_enable = *(int *)table->data;
245 	bool locked_state = unpriv_enable == 1;
246 	struct ctl_table tmp = *table;
247 
248 	if (write && !capable(CAP_SYS_ADMIN))
249 		return -EPERM;
250 
251 	tmp.data = &unpriv_enable;
252 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
253 	if (write && !ret) {
254 		if (locked_state && unpriv_enable != 1)
255 			return -EPERM;
256 		*(int *)table->data = unpriv_enable;
257 	}
258 
259 	unpriv_ebpf_notify(unpriv_enable);
260 
261 	return ret;
262 }
263 #endif /* CONFIG_BPF_SYSCALL && CONFIG_SYSCTL */
264 
265 /*
266  * /proc/sys support
267  */
268 
269 #ifdef CONFIG_PROC_SYSCTL
270 
_proc_do_string(char * data,int maxlen,int write,char * buffer,size_t * lenp,loff_t * ppos)271 static int _proc_do_string(char *data, int maxlen, int write,
272 		char *buffer, size_t *lenp, loff_t *ppos)
273 {
274 	size_t len;
275 	char c, *p;
276 
277 	if (!data || !maxlen || !*lenp) {
278 		*lenp = 0;
279 		return 0;
280 	}
281 
282 	if (write) {
283 		if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
284 			/* Only continue writes not past the end of buffer. */
285 			len = strlen(data);
286 			if (len > maxlen - 1)
287 				len = maxlen - 1;
288 
289 			if (*ppos > len)
290 				return 0;
291 			len = *ppos;
292 		} else {
293 			/* Start writing from beginning of buffer. */
294 			len = 0;
295 		}
296 
297 		*ppos += *lenp;
298 		p = buffer;
299 		while ((p - buffer) < *lenp && len < maxlen - 1) {
300 			c = *(p++);
301 			if (c == 0 || c == '\n')
302 				break;
303 			data[len++] = c;
304 		}
305 		data[len] = 0;
306 	} else {
307 		len = strlen(data);
308 		if (len > maxlen)
309 			len = maxlen;
310 
311 		if (*ppos > len) {
312 			*lenp = 0;
313 			return 0;
314 		}
315 
316 		data += *ppos;
317 		len  -= *ppos;
318 
319 		if (len > *lenp)
320 			len = *lenp;
321 		if (len)
322 			memcpy(buffer, data, len);
323 		if (len < *lenp) {
324 			buffer[len] = '\n';
325 			len++;
326 		}
327 		*lenp = len;
328 		*ppos += len;
329 	}
330 	return 0;
331 }
332 
warn_sysctl_write(struct ctl_table * table)333 static void warn_sysctl_write(struct ctl_table *table)
334 {
335 	pr_warn_once("%s wrote to %s when file position was not 0!\n"
336 		"This will not be supported in the future. To silence this\n"
337 		"warning, set kernel.sysctl_writes_strict = -1\n",
338 		current->comm, table->procname);
339 }
340 
341 /**
342  * proc_first_pos_non_zero_ignore - check if first position is allowed
343  * @ppos: file position
344  * @table: the sysctl table
345  *
346  * Returns true if the first position is non-zero and the sysctl_writes_strict
347  * mode indicates this is not allowed for numeric input types. String proc
348  * handlers can ignore the return value.
349  */
proc_first_pos_non_zero_ignore(loff_t * ppos,struct ctl_table * table)350 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
351 					   struct ctl_table *table)
352 {
353 	if (!*ppos)
354 		return false;
355 
356 	switch (sysctl_writes_strict) {
357 	case SYSCTL_WRITES_STRICT:
358 		return true;
359 	case SYSCTL_WRITES_WARN:
360 		warn_sysctl_write(table);
361 		return false;
362 	default:
363 		return false;
364 	}
365 }
366 
367 /**
368  * proc_dostring - read a string sysctl
369  * @table: the sysctl table
370  * @write: %TRUE if this is a write to the sysctl file
371  * @buffer: the user buffer
372  * @lenp: the size of the user buffer
373  * @ppos: file position
374  *
375  * Reads/writes a string from/to the user buffer. If the kernel
376  * buffer provided is not large enough to hold the string, the
377  * string is truncated. The copied string is %NULL-terminated.
378  * If the string is being read by the user process, it is copied
379  * and a newline '\n' is added. It is truncated if the buffer is
380  * not large enough.
381  *
382  * Returns 0 on success.
383  */
proc_dostring(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)384 int proc_dostring(struct ctl_table *table, int write,
385 		  void *buffer, size_t *lenp, loff_t *ppos)
386 {
387 	if (write)
388 		proc_first_pos_non_zero_ignore(ppos, table);
389 
390 	return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
391 			ppos);
392 }
393 
proc_skip_spaces(char ** buf,size_t * size)394 static void proc_skip_spaces(char **buf, size_t *size)
395 {
396 	while (*size) {
397 		if (!isspace(**buf))
398 			break;
399 		(*size)--;
400 		(*buf)++;
401 	}
402 }
403 
proc_skip_char(char ** buf,size_t * size,const char v)404 static void proc_skip_char(char **buf, size_t *size, const char v)
405 {
406 	while (*size) {
407 		if (**buf != v)
408 			break;
409 		(*size)--;
410 		(*buf)++;
411 	}
412 }
413 
414 /**
415  * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
416  *                   fail on overflow
417  *
418  * @cp: kernel buffer containing the string to parse
419  * @endp: pointer to store the trailing characters
420  * @base: the base to use
421  * @res: where the parsed integer will be stored
422  *
423  * In case of success 0 is returned and @res will contain the parsed integer,
424  * @endp will hold any trailing characters.
425  * This function will fail the parse on overflow. If there wasn't an overflow
426  * the function will defer the decision what characters count as invalid to the
427  * caller.
428  */
strtoul_lenient(const char * cp,char ** endp,unsigned int base,unsigned long * res)429 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
430 			   unsigned long *res)
431 {
432 	unsigned long long result;
433 	unsigned int rv;
434 
435 	cp = _parse_integer_fixup_radix(cp, &base);
436 	rv = _parse_integer(cp, base, &result);
437 	if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
438 		return -ERANGE;
439 
440 	cp += rv;
441 
442 	if (endp)
443 		*endp = (char *)cp;
444 
445 	*res = (unsigned long)result;
446 	return 0;
447 }
448 
449 #define TMPBUFLEN 22
450 /**
451  * proc_get_long - reads an ASCII formatted integer from a user buffer
452  *
453  * @buf: a kernel buffer
454  * @size: size of the kernel buffer
455  * @val: this is where the number will be stored
456  * @neg: set to %TRUE if number is negative
457  * @perm_tr: a vector which contains the allowed trailers
458  * @perm_tr_len: size of the perm_tr vector
459  * @tr: pointer to store the trailer character
460  *
461  * In case of success %0 is returned and @buf and @size are updated with
462  * the amount of bytes read. If @tr is non-NULL and a trailing
463  * character exists (size is non-zero after returning from this
464  * function), @tr is updated with the trailing character.
465  */
proc_get_long(char ** buf,size_t * size,unsigned long * val,bool * neg,const char * perm_tr,unsigned perm_tr_len,char * tr)466 static int proc_get_long(char **buf, size_t *size,
467 			  unsigned long *val, bool *neg,
468 			  const char *perm_tr, unsigned perm_tr_len, char *tr)
469 {
470 	char *p, tmp[TMPBUFLEN];
471 	ssize_t len = *size;
472 
473 	if (len <= 0)
474 		return -EINVAL;
475 
476 	if (len > TMPBUFLEN - 1)
477 		len = TMPBUFLEN - 1;
478 
479 	memcpy(tmp, *buf, len);
480 
481 	tmp[len] = 0;
482 	p = tmp;
483 	if (*p == '-' && *size > 1) {
484 		*neg = true;
485 		p++;
486 	} else
487 		*neg = false;
488 	if (!isdigit(*p))
489 		return -EINVAL;
490 
491 	if (strtoul_lenient(p, &p, 0, val))
492 		return -EINVAL;
493 
494 	len = p - tmp;
495 
496 	/* We don't know if the next char is whitespace thus we may accept
497 	 * invalid integers (e.g. 1234...a) or two integers instead of one
498 	 * (e.g. 123...1). So lets not allow such large numbers. */
499 	if (len == TMPBUFLEN - 1)
500 		return -EINVAL;
501 
502 	if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
503 		return -EINVAL;
504 
505 	if (tr && (len < *size))
506 		*tr = *p;
507 
508 	*buf += len;
509 	*size -= len;
510 
511 	return 0;
512 }
513 
514 /**
515  * proc_put_long - converts an integer to a decimal ASCII formatted string
516  *
517  * @buf: the user buffer
518  * @size: the size of the user buffer
519  * @val: the integer to be converted
520  * @neg: sign of the number, %TRUE for negative
521  *
522  * In case of success @buf and @size are updated with the amount of bytes
523  * written.
524  */
proc_put_long(void ** buf,size_t * size,unsigned long val,bool neg)525 static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
526 {
527 	int len;
528 	char tmp[TMPBUFLEN], *p = tmp;
529 
530 	sprintf(p, "%s%lu", neg ? "-" : "", val);
531 	len = strlen(tmp);
532 	if (len > *size)
533 		len = *size;
534 	memcpy(*buf, tmp, len);
535 	*size -= len;
536 	*buf += len;
537 }
538 #undef TMPBUFLEN
539 
proc_put_char(void ** buf,size_t * size,char c)540 static void proc_put_char(void **buf, size_t *size, char c)
541 {
542 	if (*size) {
543 		char **buffer = (char **)buf;
544 		**buffer = c;
545 
546 		(*size)--;
547 		(*buffer)++;
548 		*buf = *buffer;
549 	}
550 }
551 
do_proc_dointvec_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)552 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
553 				 int *valp,
554 				 int write, void *data)
555 {
556 	if (write) {
557 		if (*negp) {
558 			if (*lvalp > (unsigned long) INT_MAX + 1)
559 				return -EINVAL;
560 			*valp = -*lvalp;
561 		} else {
562 			if (*lvalp > (unsigned long) INT_MAX)
563 				return -EINVAL;
564 			*valp = *lvalp;
565 		}
566 	} else {
567 		int val = *valp;
568 		if (val < 0) {
569 			*negp = true;
570 			*lvalp = -(unsigned long)val;
571 		} else {
572 			*negp = false;
573 			*lvalp = (unsigned long)val;
574 		}
575 	}
576 	return 0;
577 }
578 
do_proc_douintvec_conv(unsigned long * lvalp,unsigned int * valp,int write,void * data)579 static int do_proc_douintvec_conv(unsigned long *lvalp,
580 				  unsigned int *valp,
581 				  int write, void *data)
582 {
583 	if (write) {
584 		if (*lvalp > UINT_MAX)
585 			return -EINVAL;
586 		*valp = *lvalp;
587 	} else {
588 		unsigned int val = *valp;
589 		*lvalp = (unsigned long)val;
590 	}
591 	return 0;
592 }
593 
594 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
595 
__do_proc_dointvec(void * tbl_data,struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(bool * negp,unsigned long * lvalp,int * valp,int write,void * data),void * data)596 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
597 		  int write, void *buffer,
598 		  size_t *lenp, loff_t *ppos,
599 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
600 			      int write, void *data),
601 		  void *data)
602 {
603 	int *i, vleft, first = 1, err = 0;
604 	size_t left;
605 	char *p;
606 
607 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
608 		*lenp = 0;
609 		return 0;
610 	}
611 
612 	i = (int *) tbl_data;
613 	vleft = table->maxlen / sizeof(*i);
614 	left = *lenp;
615 
616 	if (!conv)
617 		conv = do_proc_dointvec_conv;
618 
619 	if (write) {
620 		if (proc_first_pos_non_zero_ignore(ppos, table))
621 			goto out;
622 
623 		if (left > PAGE_SIZE - 1)
624 			left = PAGE_SIZE - 1;
625 		p = buffer;
626 	}
627 
628 	for (; left && vleft--; i++, first=0) {
629 		unsigned long lval;
630 		bool neg;
631 
632 		if (write) {
633 			proc_skip_spaces(&p, &left);
634 
635 			if (!left)
636 				break;
637 			err = proc_get_long(&p, &left, &lval, &neg,
638 					     proc_wspace_sep,
639 					     sizeof(proc_wspace_sep), NULL);
640 			if (err)
641 				break;
642 			if (conv(&neg, &lval, i, 1, data)) {
643 				err = -EINVAL;
644 				break;
645 			}
646 		} else {
647 			if (conv(&neg, &lval, i, 0, data)) {
648 				err = -EINVAL;
649 				break;
650 			}
651 			if (!first)
652 				proc_put_char(&buffer, &left, '\t');
653 			proc_put_long(&buffer, &left, lval, neg);
654 		}
655 	}
656 
657 	if (!write && !first && left && !err)
658 		proc_put_char(&buffer, &left, '\n');
659 	if (write && !err && left)
660 		proc_skip_spaces(&p, &left);
661 	if (write && first)
662 		return err ? : -EINVAL;
663 	*lenp -= left;
664 out:
665 	*ppos += *lenp;
666 	return err;
667 }
668 
do_proc_dointvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(bool * negp,unsigned long * lvalp,int * valp,int write,void * data),void * data)669 static int do_proc_dointvec(struct ctl_table *table, int write,
670 		  void *buffer, size_t *lenp, loff_t *ppos,
671 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
672 			      int write, void *data),
673 		  void *data)
674 {
675 	return __do_proc_dointvec(table->data, table, write,
676 			buffer, lenp, ppos, conv, data);
677 }
678 
do_proc_douintvec_w(unsigned int * tbl_data,struct ctl_table * table,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(unsigned long * lvalp,unsigned int * valp,int write,void * data),void * data)679 static int do_proc_douintvec_w(unsigned int *tbl_data,
680 			       struct ctl_table *table,
681 			       void *buffer,
682 			       size_t *lenp, loff_t *ppos,
683 			       int (*conv)(unsigned long *lvalp,
684 					   unsigned int *valp,
685 					   int write, void *data),
686 			       void *data)
687 {
688 	unsigned long lval;
689 	int err = 0;
690 	size_t left;
691 	bool neg;
692 	char *p = buffer;
693 
694 	left = *lenp;
695 
696 	if (proc_first_pos_non_zero_ignore(ppos, table))
697 		goto bail_early;
698 
699 	if (left > PAGE_SIZE - 1)
700 		left = PAGE_SIZE - 1;
701 
702 	proc_skip_spaces(&p, &left);
703 	if (!left) {
704 		err = -EINVAL;
705 		goto out_free;
706 	}
707 
708 	err = proc_get_long(&p, &left, &lval, &neg,
709 			     proc_wspace_sep,
710 			     sizeof(proc_wspace_sep), NULL);
711 	if (err || neg) {
712 		err = -EINVAL;
713 		goto out_free;
714 	}
715 
716 	if (conv(&lval, tbl_data, 1, data)) {
717 		err = -EINVAL;
718 		goto out_free;
719 	}
720 
721 	if (!err && left)
722 		proc_skip_spaces(&p, &left);
723 
724 out_free:
725 	if (err)
726 		return -EINVAL;
727 
728 	return 0;
729 
730 	/* This is in keeping with old __do_proc_dointvec() */
731 bail_early:
732 	*ppos += *lenp;
733 	return err;
734 }
735 
do_proc_douintvec_r(unsigned int * tbl_data,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(unsigned long * lvalp,unsigned int * valp,int write,void * data),void * data)736 static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
737 			       size_t *lenp, loff_t *ppos,
738 			       int (*conv)(unsigned long *lvalp,
739 					   unsigned int *valp,
740 					   int write, void *data),
741 			       void *data)
742 {
743 	unsigned long lval;
744 	int err = 0;
745 	size_t left;
746 
747 	left = *lenp;
748 
749 	if (conv(&lval, tbl_data, 0, data)) {
750 		err = -EINVAL;
751 		goto out;
752 	}
753 
754 	proc_put_long(&buffer, &left, lval, false);
755 	if (!left)
756 		goto out;
757 
758 	proc_put_char(&buffer, &left, '\n');
759 
760 out:
761 	*lenp -= left;
762 	*ppos += *lenp;
763 
764 	return err;
765 }
766 
__do_proc_douintvec(void * tbl_data,struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(unsigned long * lvalp,unsigned int * valp,int write,void * data),void * data)767 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
768 			       int write, void *buffer,
769 			       size_t *lenp, loff_t *ppos,
770 			       int (*conv)(unsigned long *lvalp,
771 					   unsigned int *valp,
772 					   int write, void *data),
773 			       void *data)
774 {
775 	unsigned int *i, vleft;
776 
777 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
778 		*lenp = 0;
779 		return 0;
780 	}
781 
782 	i = (unsigned int *) tbl_data;
783 	vleft = table->maxlen / sizeof(*i);
784 
785 	/*
786 	 * Arrays are not supported, keep this simple. *Do not* add
787 	 * support for them.
788 	 */
789 	if (vleft != 1) {
790 		*lenp = 0;
791 		return -EINVAL;
792 	}
793 
794 	if (!conv)
795 		conv = do_proc_douintvec_conv;
796 
797 	if (write)
798 		return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
799 					   conv, data);
800 	return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
801 }
802 
do_proc_douintvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(unsigned long * lvalp,unsigned int * valp,int write,void * data),void * data)803 static int do_proc_douintvec(struct ctl_table *table, int write,
804 			     void *buffer, size_t *lenp, loff_t *ppos,
805 			     int (*conv)(unsigned long *lvalp,
806 					 unsigned int *valp,
807 					 int write, void *data),
808 			     void *data)
809 {
810 	return __do_proc_douintvec(table->data, table, write,
811 				   buffer, lenp, ppos, conv, data);
812 }
813 
814 /**
815  * proc_dointvec - read a vector of integers
816  * @table: the sysctl table
817  * @write: %TRUE if this is a write to the sysctl file
818  * @buffer: the user buffer
819  * @lenp: the size of the user buffer
820  * @ppos: file position
821  *
822  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
823  * values from/to the user buffer, treated as an ASCII string.
824  *
825  * Returns 0 on success.
826  */
proc_dointvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)827 int proc_dointvec(struct ctl_table *table, int write, void *buffer,
828 		  size_t *lenp, loff_t *ppos)
829 {
830 	return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
831 }
832 
833 #ifdef CONFIG_COMPACTION
proc_dointvec_minmax_warn_RT_change(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)834 static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
835 		int write, void *buffer, size_t *lenp, loff_t *ppos)
836 {
837 	int ret, old;
838 
839 	if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
840 		return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
841 
842 	old = *(int *)table->data;
843 	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
844 	if (ret)
845 		return ret;
846 	if (old != *(int *)table->data)
847 		pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
848 			     table->procname, current->comm,
849 			     task_pid_nr(current));
850 	return ret;
851 }
852 #endif
853 
854 /**
855  * proc_douintvec - read a vector of unsigned integers
856  * @table: the sysctl table
857  * @write: %TRUE if this is a write to the sysctl file
858  * @buffer: the user buffer
859  * @lenp: the size of the user buffer
860  * @ppos: file position
861  *
862  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
863  * values from/to the user buffer, treated as an ASCII string.
864  *
865  * Returns 0 on success.
866  */
proc_douintvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)867 int proc_douintvec(struct ctl_table *table, int write, void *buffer,
868 		size_t *lenp, loff_t *ppos)
869 {
870 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
871 				 do_proc_douintvec_conv, NULL);
872 }
873 
874 /*
875  * Taint values can only be increased
876  * This means we can safely use a temporary.
877  */
proc_taint(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)878 static int proc_taint(struct ctl_table *table, int write,
879 			       void *buffer, size_t *lenp, loff_t *ppos)
880 {
881 	struct ctl_table t;
882 	unsigned long tmptaint = get_taint();
883 	int err;
884 
885 	if (write && !capable(CAP_SYS_ADMIN))
886 		return -EPERM;
887 
888 	t = *table;
889 	t.data = &tmptaint;
890 	err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
891 	if (err < 0)
892 		return err;
893 
894 	if (write) {
895 		int i;
896 
897 		/*
898 		 * If we are relying on panic_on_taint not producing
899 		 * false positives due to userspace input, bail out
900 		 * before setting the requested taint flags.
901 		 */
902 		if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
903 			return -EINVAL;
904 
905 		/*
906 		 * Poor man's atomic or. Not worth adding a primitive
907 		 * to everyone's atomic.h for this
908 		 */
909 		for (i = 0; i < TAINT_FLAGS_COUNT; i++)
910 			if ((1UL << i) & tmptaint)
911 				add_taint(i, LOCKDEP_STILL_OK);
912 	}
913 
914 	return err;
915 }
916 
917 #ifdef CONFIG_PRINTK
proc_dointvec_minmax_sysadmin(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)918 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
919 				void *buffer, size_t *lenp, loff_t *ppos)
920 {
921 	if (write && !capable(CAP_SYS_ADMIN))
922 		return -EPERM;
923 
924 	return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
925 }
926 #endif
927 
928 /**
929  * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
930  * @min: pointer to minimum allowable value
931  * @max: pointer to maximum allowable value
932  *
933  * The do_proc_dointvec_minmax_conv_param structure provides the
934  * minimum and maximum values for doing range checking for those sysctl
935  * parameters that use the proc_dointvec_minmax() handler.
936  */
937 struct do_proc_dointvec_minmax_conv_param {
938 	int *min;
939 	int *max;
940 };
941 
do_proc_dointvec_minmax_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)942 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
943 					int *valp,
944 					int write, void *data)
945 {
946 	int tmp, ret;
947 	struct do_proc_dointvec_minmax_conv_param *param = data;
948 	/*
949 	 * If writing, first do so via a temporary local int so we can
950 	 * bounds-check it before touching *valp.
951 	 */
952 	int *ip = write ? &tmp : valp;
953 
954 	ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
955 	if (ret)
956 		return ret;
957 
958 	if (write) {
959 		if ((param->min && *param->min > tmp) ||
960 		    (param->max && *param->max < tmp))
961 			return -EINVAL;
962 		*valp = tmp;
963 	}
964 
965 	return 0;
966 }
967 
968 /**
969  * proc_dointvec_minmax - read a vector of integers with min/max values
970  * @table: the sysctl table
971  * @write: %TRUE if this is a write to the sysctl file
972  * @buffer: the user buffer
973  * @lenp: the size of the user buffer
974  * @ppos: file position
975  *
976  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
977  * values from/to the user buffer, treated as an ASCII string.
978  *
979  * This routine will ensure the values are within the range specified by
980  * table->extra1 (min) and table->extra2 (max).
981  *
982  * Returns 0 on success or -EINVAL on write when the range check fails.
983  */
proc_dointvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)984 int proc_dointvec_minmax(struct ctl_table *table, int write,
985 		  void *buffer, size_t *lenp, loff_t *ppos)
986 {
987 	struct do_proc_dointvec_minmax_conv_param param = {
988 		.min = (int *) table->extra1,
989 		.max = (int *) table->extra2,
990 	};
991 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
992 				do_proc_dointvec_minmax_conv, &param);
993 }
994 
995 /**
996  * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
997  * @min: pointer to minimum allowable value
998  * @max: pointer to maximum allowable value
999  *
1000  * The do_proc_douintvec_minmax_conv_param structure provides the
1001  * minimum and maximum values for doing range checking for those sysctl
1002  * parameters that use the proc_douintvec_minmax() handler.
1003  */
1004 struct do_proc_douintvec_minmax_conv_param {
1005 	unsigned int *min;
1006 	unsigned int *max;
1007 };
1008 
do_proc_douintvec_minmax_conv(unsigned long * lvalp,unsigned int * valp,int write,void * data)1009 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
1010 					 unsigned int *valp,
1011 					 int write, void *data)
1012 {
1013 	int ret;
1014 	unsigned int tmp;
1015 	struct do_proc_douintvec_minmax_conv_param *param = data;
1016 	/* write via temporary local uint for bounds-checking */
1017 	unsigned int *up = write ? &tmp : valp;
1018 
1019 	ret = do_proc_douintvec_conv(lvalp, up, write, data);
1020 	if (ret)
1021 		return ret;
1022 
1023 	if (write) {
1024 		if ((param->min && *param->min > tmp) ||
1025 		    (param->max && *param->max < tmp))
1026 			return -ERANGE;
1027 
1028 		*valp = tmp;
1029 	}
1030 
1031 	return 0;
1032 }
1033 
1034 /**
1035  * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
1036  * @table: the sysctl table
1037  * @write: %TRUE if this is a write to the sysctl file
1038  * @buffer: the user buffer
1039  * @lenp: the size of the user buffer
1040  * @ppos: file position
1041  *
1042  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
1043  * values from/to the user buffer, treated as an ASCII string. Negative
1044  * strings are not allowed.
1045  *
1046  * This routine will ensure the values are within the range specified by
1047  * table->extra1 (min) and table->extra2 (max). There is a final sanity
1048  * check for UINT_MAX to avoid having to support wrap around uses from
1049  * userspace.
1050  *
1051  * Returns 0 on success or -ERANGE on write when the range check fails.
1052  */
proc_douintvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1053 int proc_douintvec_minmax(struct ctl_table *table, int write,
1054 			  void *buffer, size_t *lenp, loff_t *ppos)
1055 {
1056 	struct do_proc_douintvec_minmax_conv_param param = {
1057 		.min = (unsigned int *) table->extra1,
1058 		.max = (unsigned int *) table->extra2,
1059 	};
1060 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
1061 				 do_proc_douintvec_minmax_conv, &param);
1062 }
1063 
do_proc_dopipe_max_size_conv(unsigned long * lvalp,unsigned int * valp,int write,void * data)1064 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
1065 					unsigned int *valp,
1066 					int write, void *data)
1067 {
1068 	if (write) {
1069 		unsigned int val;
1070 
1071 		val = round_pipe_size(*lvalp);
1072 		if (val == 0)
1073 			return -EINVAL;
1074 
1075 		*valp = val;
1076 	} else {
1077 		unsigned int val = *valp;
1078 		*lvalp = (unsigned long) val;
1079 	}
1080 
1081 	return 0;
1082 }
1083 
proc_dopipe_max_size(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1084 static int proc_dopipe_max_size(struct ctl_table *table, int write,
1085 				void *buffer, size_t *lenp, loff_t *ppos)
1086 {
1087 	return do_proc_douintvec(table, write, buffer, lenp, ppos,
1088 				 do_proc_dopipe_max_size_conv, NULL);
1089 }
1090 
validate_coredump_safety(void)1091 static void validate_coredump_safety(void)
1092 {
1093 #ifdef CONFIG_COREDUMP
1094 	if (suid_dumpable == SUID_DUMP_ROOT &&
1095 	    core_pattern[0] != '/' && core_pattern[0] != '|') {
1096 		printk(KERN_WARNING
1097 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
1098 "Pipe handler or fully qualified core dump path required.\n"
1099 "Set kernel.core_pattern before fs.suid_dumpable.\n"
1100 		);
1101 	}
1102 #endif
1103 }
1104 
proc_dointvec_minmax_coredump(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1105 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
1106 		void *buffer, size_t *lenp, loff_t *ppos)
1107 {
1108 	int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1109 	if (!error)
1110 		validate_coredump_safety();
1111 	return error;
1112 }
1113 
1114 #ifdef CONFIG_COREDUMP
proc_dostring_coredump(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1115 static int proc_dostring_coredump(struct ctl_table *table, int write,
1116 		  void *buffer, size_t *lenp, loff_t *ppos)
1117 {
1118 	int error = proc_dostring(table, write, buffer, lenp, ppos);
1119 	if (!error)
1120 		validate_coredump_safety();
1121 	return error;
1122 }
1123 #endif
1124 
1125 #ifdef CONFIG_MAGIC_SYSRQ
sysrq_sysctl_handler(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1126 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
1127 				void *buffer, size_t *lenp, loff_t *ppos)
1128 {
1129 	int tmp, ret;
1130 
1131 	tmp = sysrq_mask();
1132 
1133 	ret = __do_proc_dointvec(&tmp, table, write, buffer,
1134 			       lenp, ppos, NULL, NULL);
1135 	if (ret || !write)
1136 		return ret;
1137 
1138 	if (write)
1139 		sysrq_toggle_support(tmp);
1140 
1141 	return 0;
1142 }
1143 #endif
1144 
__do_proc_doulongvec_minmax(void * data,struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,unsigned long convmul,unsigned long convdiv)1145 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
1146 		int write, void *buffer, size_t *lenp, loff_t *ppos,
1147 		unsigned long convmul, unsigned long convdiv)
1148 {
1149 	unsigned long *i, *min, *max;
1150 	int vleft, first = 1, err = 0;
1151 	size_t left;
1152 	char *p;
1153 
1154 	if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1155 		*lenp = 0;
1156 		return 0;
1157 	}
1158 
1159 	i = (unsigned long *) data;
1160 	min = (unsigned long *) table->extra1;
1161 	max = (unsigned long *) table->extra2;
1162 	vleft = table->maxlen / sizeof(unsigned long);
1163 	left = *lenp;
1164 
1165 	if (write) {
1166 		if (proc_first_pos_non_zero_ignore(ppos, table))
1167 			goto out;
1168 
1169 		if (left > PAGE_SIZE - 1)
1170 			left = PAGE_SIZE - 1;
1171 		p = buffer;
1172 	}
1173 
1174 	for (; left && vleft--; i++, first = 0) {
1175 		unsigned long val;
1176 
1177 		if (write) {
1178 			bool neg;
1179 
1180 			proc_skip_spaces(&p, &left);
1181 			if (!left)
1182 				break;
1183 
1184 			err = proc_get_long(&p, &left, &val, &neg,
1185 					     proc_wspace_sep,
1186 					     sizeof(proc_wspace_sep), NULL);
1187 			if (err)
1188 				break;
1189 			if (neg)
1190 				continue;
1191 			val = convmul * val / convdiv;
1192 			if ((min && val < *min) || (max && val > *max)) {
1193 				err = -EINVAL;
1194 				break;
1195 			}
1196 			*i = val;
1197 		} else {
1198 			val = convdiv * (*i) / convmul;
1199 			if (!first)
1200 				proc_put_char(&buffer, &left, '\t');
1201 			proc_put_long(&buffer, &left, val, false);
1202 		}
1203 	}
1204 
1205 	if (!write && !first && left && !err)
1206 		proc_put_char(&buffer, &left, '\n');
1207 	if (write && !err)
1208 		proc_skip_spaces(&p, &left);
1209 	if (write && first)
1210 		return err ? : -EINVAL;
1211 	*lenp -= left;
1212 out:
1213 	*ppos += *lenp;
1214 	return err;
1215 }
1216 
do_proc_doulongvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,unsigned long convmul,unsigned long convdiv)1217 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
1218 		void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1219 		unsigned long convdiv)
1220 {
1221 	return __do_proc_doulongvec_minmax(table->data, table, write,
1222 			buffer, lenp, ppos, convmul, convdiv);
1223 }
1224 
1225 /**
1226  * proc_doulongvec_minmax - read a vector of long integers with min/max values
1227  * @table: the sysctl table
1228  * @write: %TRUE if this is a write to the sysctl file
1229  * @buffer: the user buffer
1230  * @lenp: the size of the user buffer
1231  * @ppos: file position
1232  *
1233  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1234  * values from/to the user buffer, treated as an ASCII string.
1235  *
1236  * This routine will ensure the values are within the range specified by
1237  * table->extra1 (min) and table->extra2 (max).
1238  *
1239  * Returns 0 on success.
1240  */
proc_doulongvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1241 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1242 			   void *buffer, size_t *lenp, loff_t *ppos)
1243 {
1244     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1245 }
1246 
1247 /**
1248  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1249  * @table: the sysctl table
1250  * @write: %TRUE if this is a write to the sysctl file
1251  * @buffer: the user buffer
1252  * @lenp: the size of the user buffer
1253  * @ppos: file position
1254  *
1255  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1256  * values from/to the user buffer, treated as an ASCII string. The values
1257  * are treated as milliseconds, and converted to jiffies when they are stored.
1258  *
1259  * This routine will ensure the values are within the range specified by
1260  * table->extra1 (min) and table->extra2 (max).
1261  *
1262  * Returns 0 on success.
1263  */
proc_doulongvec_ms_jiffies_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1264 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1265 				      void *buffer, size_t *lenp, loff_t *ppos)
1266 {
1267     return do_proc_doulongvec_minmax(table, write, buffer,
1268 				     lenp, ppos, HZ, 1000l);
1269 }
1270 
1271 
do_proc_dointvec_jiffies_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)1272 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1273 					 int *valp,
1274 					 int write, void *data)
1275 {
1276 	if (write) {
1277 		if (*lvalp > INT_MAX / HZ)
1278 			return 1;
1279 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1280 	} else {
1281 		int val = *valp;
1282 		unsigned long lval;
1283 		if (val < 0) {
1284 			*negp = true;
1285 			lval = -(unsigned long)val;
1286 		} else {
1287 			*negp = false;
1288 			lval = (unsigned long)val;
1289 		}
1290 		*lvalp = lval / HZ;
1291 	}
1292 	return 0;
1293 }
1294 
do_proc_dointvec_userhz_jiffies_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)1295 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1296 						int *valp,
1297 						int write, void *data)
1298 {
1299 	if (write) {
1300 		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1301 			return 1;
1302 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1303 	} else {
1304 		int val = *valp;
1305 		unsigned long lval;
1306 		if (val < 0) {
1307 			*negp = true;
1308 			lval = -(unsigned long)val;
1309 		} else {
1310 			*negp = false;
1311 			lval = (unsigned long)val;
1312 		}
1313 		*lvalp = jiffies_to_clock_t(lval);
1314 	}
1315 	return 0;
1316 }
1317 
do_proc_dointvec_ms_jiffies_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)1318 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1319 					    int *valp,
1320 					    int write, void *data)
1321 {
1322 	if (write) {
1323 		unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1324 
1325 		if (jif > INT_MAX)
1326 			return 1;
1327 		*valp = (int)jif;
1328 	} else {
1329 		int val = *valp;
1330 		unsigned long lval;
1331 		if (val < 0) {
1332 			*negp = true;
1333 			lval = -(unsigned long)val;
1334 		} else {
1335 			*negp = false;
1336 			lval = (unsigned long)val;
1337 		}
1338 		*lvalp = jiffies_to_msecs(lval);
1339 	}
1340 	return 0;
1341 }
1342 
1343 /**
1344  * proc_dointvec_jiffies - read a vector of integers as seconds
1345  * @table: the sysctl table
1346  * @write: %TRUE if this is a write to the sysctl file
1347  * @buffer: the user buffer
1348  * @lenp: the size of the user buffer
1349  * @ppos: file position
1350  *
1351  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1352  * values from/to the user buffer, treated as an ASCII string.
1353  * The values read are assumed to be in seconds, and are converted into
1354  * jiffies.
1355  *
1356  * Returns 0 on success.
1357  */
proc_dointvec_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1358 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1359 			  void *buffer, size_t *lenp, loff_t *ppos)
1360 {
1361     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1362 		    	    do_proc_dointvec_jiffies_conv,NULL);
1363 }
1364 
1365 /**
1366  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1367  * @table: the sysctl table
1368  * @write: %TRUE if this is a write to the sysctl file
1369  * @buffer: the user buffer
1370  * @lenp: the size of the user buffer
1371  * @ppos: pointer to the file position
1372  *
1373  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1374  * values from/to the user buffer, treated as an ASCII string.
1375  * The values read are assumed to be in 1/USER_HZ seconds, and
1376  * are converted into jiffies.
1377  *
1378  * Returns 0 on success.
1379  */
proc_dointvec_userhz_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1380 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1381 				 void *buffer, size_t *lenp, loff_t *ppos)
1382 {
1383     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1384 		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);
1385 }
1386 
1387 /**
1388  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1389  * @table: the sysctl table
1390  * @write: %TRUE if this is a write to the sysctl file
1391  * @buffer: the user buffer
1392  * @lenp: the size of the user buffer
1393  * @ppos: file position
1394  * @ppos: the current position in the file
1395  *
1396  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1397  * values from/to the user buffer, treated as an ASCII string.
1398  * The values read are assumed to be in 1/1000 seconds, and
1399  * are converted into jiffies.
1400  *
1401  * Returns 0 on success.
1402  */
proc_dointvec_ms_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1403 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
1404 		size_t *lenp, loff_t *ppos)
1405 {
1406 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
1407 				do_proc_dointvec_ms_jiffies_conv, NULL);
1408 }
1409 
proc_do_cad_pid(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1410 static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
1411 		size_t *lenp, loff_t *ppos)
1412 {
1413 	struct pid *new_pid;
1414 	pid_t tmp;
1415 	int r;
1416 
1417 	tmp = pid_vnr(cad_pid);
1418 
1419 	r = __do_proc_dointvec(&tmp, table, write, buffer,
1420 			       lenp, ppos, NULL, NULL);
1421 	if (r || !write)
1422 		return r;
1423 
1424 	new_pid = find_get_pid(tmp);
1425 	if (!new_pid)
1426 		return -ESRCH;
1427 
1428 	put_pid(xchg(&cad_pid, new_pid));
1429 	return 0;
1430 }
1431 
1432 /**
1433  * proc_do_large_bitmap - read/write from/to a large bitmap
1434  * @table: the sysctl table
1435  * @write: %TRUE if this is a write to the sysctl file
1436  * @buffer: the user buffer
1437  * @lenp: the size of the user buffer
1438  * @ppos: file position
1439  *
1440  * The bitmap is stored at table->data and the bitmap length (in bits)
1441  * in table->maxlen.
1442  *
1443  * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1444  * large bitmaps may be represented in a compact manner. Writing into
1445  * the file will clear the bitmap then update it with the given input.
1446  *
1447  * Returns 0 on success.
1448  */
proc_do_large_bitmap(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1449 int proc_do_large_bitmap(struct ctl_table *table, int write,
1450 			 void *buffer, size_t *lenp, loff_t *ppos)
1451 {
1452 	int err = 0;
1453 	bool first = 1;
1454 	size_t left = *lenp;
1455 	unsigned long bitmap_len = table->maxlen;
1456 	unsigned long *bitmap = *(unsigned long **) table->data;
1457 	unsigned long *tmp_bitmap = NULL;
1458 	char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1459 
1460 	if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1461 		*lenp = 0;
1462 		return 0;
1463 	}
1464 
1465 	if (write) {
1466 		char *p = buffer;
1467 		size_t skipped = 0;
1468 
1469 		if (left > PAGE_SIZE - 1) {
1470 			left = PAGE_SIZE - 1;
1471 			/* How much of the buffer we'll skip this pass */
1472 			skipped = *lenp - left;
1473 		}
1474 
1475 		tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
1476 		if (!tmp_bitmap)
1477 			return -ENOMEM;
1478 		proc_skip_char(&p, &left, '\n');
1479 		while (!err && left) {
1480 			unsigned long val_a, val_b;
1481 			bool neg;
1482 			size_t saved_left;
1483 
1484 			/* In case we stop parsing mid-number, we can reset */
1485 			saved_left = left;
1486 			err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1487 					     sizeof(tr_a), &c);
1488 			/*
1489 			 * If we consumed the entirety of a truncated buffer or
1490 			 * only one char is left (may be a "-"), then stop here,
1491 			 * reset, & come back for more.
1492 			 */
1493 			if ((left <= 1) && skipped) {
1494 				left = saved_left;
1495 				break;
1496 			}
1497 
1498 			if (err)
1499 				break;
1500 			if (val_a >= bitmap_len || neg) {
1501 				err = -EINVAL;
1502 				break;
1503 			}
1504 
1505 			val_b = val_a;
1506 			if (left) {
1507 				p++;
1508 				left--;
1509 			}
1510 
1511 			if (c == '-') {
1512 				err = proc_get_long(&p, &left, &val_b,
1513 						     &neg, tr_b, sizeof(tr_b),
1514 						     &c);
1515 				/*
1516 				 * If we consumed all of a truncated buffer or
1517 				 * then stop here, reset, & come back for more.
1518 				 */
1519 				if (!left && skipped) {
1520 					left = saved_left;
1521 					break;
1522 				}
1523 
1524 				if (err)
1525 					break;
1526 				if (val_b >= bitmap_len || neg ||
1527 				    val_a > val_b) {
1528 					err = -EINVAL;
1529 					break;
1530 				}
1531 				if (left) {
1532 					p++;
1533 					left--;
1534 				}
1535 			}
1536 
1537 			bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1538 			first = 0;
1539 			proc_skip_char(&p, &left, '\n');
1540 		}
1541 		left += skipped;
1542 	} else {
1543 		unsigned long bit_a, bit_b = 0;
1544 
1545 		while (left) {
1546 			bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1547 			if (bit_a >= bitmap_len)
1548 				break;
1549 			bit_b = find_next_zero_bit(bitmap, bitmap_len,
1550 						   bit_a + 1) - 1;
1551 
1552 			if (!first)
1553 				proc_put_char(&buffer, &left, ',');
1554 			proc_put_long(&buffer, &left, bit_a, false);
1555 			if (bit_a != bit_b) {
1556 				proc_put_char(&buffer, &left, '-');
1557 				proc_put_long(&buffer, &left, bit_b, false);
1558 			}
1559 
1560 			first = 0; bit_b++;
1561 		}
1562 		proc_put_char(&buffer, &left, '\n');
1563 	}
1564 
1565 	if (!err) {
1566 		if (write) {
1567 			if (*ppos)
1568 				bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1569 			else
1570 				bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1571 		}
1572 		*lenp -= left;
1573 		*ppos += *lenp;
1574 	}
1575 
1576 	bitmap_free(tmp_bitmap);
1577 	return err;
1578 }
1579 
1580 #else /* CONFIG_PROC_SYSCTL */
1581 
proc_dostring(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1582 int proc_dostring(struct ctl_table *table, int write,
1583 		  void *buffer, size_t *lenp, loff_t *ppos)
1584 {
1585 	return -ENOSYS;
1586 }
1587 
proc_dointvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1588 int proc_dointvec(struct ctl_table *table, int write,
1589 		  void *buffer, size_t *lenp, loff_t *ppos)
1590 {
1591 	return -ENOSYS;
1592 }
1593 
proc_douintvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1594 int proc_douintvec(struct ctl_table *table, int write,
1595 		  void *buffer, size_t *lenp, loff_t *ppos)
1596 {
1597 	return -ENOSYS;
1598 }
1599 
proc_dointvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1600 int proc_dointvec_minmax(struct ctl_table *table, int write,
1601 		    void *buffer, size_t *lenp, loff_t *ppos)
1602 {
1603 	return -ENOSYS;
1604 }
1605 
proc_douintvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1606 int proc_douintvec_minmax(struct ctl_table *table, int write,
1607 			  void *buffer, size_t *lenp, loff_t *ppos)
1608 {
1609 	return -ENOSYS;
1610 }
1611 
proc_dointvec_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1612 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1613 		    void *buffer, size_t *lenp, loff_t *ppos)
1614 {
1615 	return -ENOSYS;
1616 }
1617 
proc_dointvec_userhz_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1618 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1619 		    void *buffer, size_t *lenp, loff_t *ppos)
1620 {
1621 	return -ENOSYS;
1622 }
1623 
proc_dointvec_ms_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1624 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1625 			     void *buffer, size_t *lenp, loff_t *ppos)
1626 {
1627 	return -ENOSYS;
1628 }
1629 
proc_doulongvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1630 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1631 		    void *buffer, size_t *lenp, loff_t *ppos)
1632 {
1633 	return -ENOSYS;
1634 }
1635 
proc_doulongvec_ms_jiffies_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1636 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1637 				      void *buffer, size_t *lenp, loff_t *ppos)
1638 {
1639 	return -ENOSYS;
1640 }
1641 
proc_do_large_bitmap(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1642 int proc_do_large_bitmap(struct ctl_table *table, int write,
1643 			 void *buffer, size_t *lenp, loff_t *ppos)
1644 {
1645 	return -ENOSYS;
1646 }
1647 
1648 #endif /* CONFIG_PROC_SYSCTL */
1649 
1650 #if defined(CONFIG_SYSCTL)
proc_do_static_key(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1651 int proc_do_static_key(struct ctl_table *table, int write,
1652 		       void *buffer, size_t *lenp, loff_t *ppos)
1653 {
1654 	struct static_key *key = (struct static_key *)table->data;
1655 	static DEFINE_MUTEX(static_key_mutex);
1656 	int val, ret;
1657 	struct ctl_table tmp = {
1658 		.data   = &val,
1659 		.maxlen = sizeof(val),
1660 		.mode   = table->mode,
1661 		.extra1 = SYSCTL_ZERO,
1662 		.extra2 = SYSCTL_ONE,
1663 	};
1664 
1665 	if (write && !capable(CAP_SYS_ADMIN))
1666 		return -EPERM;
1667 
1668 	mutex_lock(&static_key_mutex);
1669 	val = static_key_enabled(key);
1670 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1671 	if (write && !ret) {
1672 		if (val)
1673 			static_key_enable(key);
1674 		else
1675 			static_key_disable(key);
1676 	}
1677 	mutex_unlock(&static_key_mutex);
1678 	return ret;
1679 }
1680 
1681 static struct ctl_table kern_table[] = {
1682 	{
1683 		.procname	= "sched_child_runs_first",
1684 		.data		= &sysctl_sched_child_runs_first,
1685 		.maxlen		= sizeof(unsigned int),
1686 		.mode		= 0644,
1687 		.proc_handler	= proc_dointvec,
1688 	},
1689 #ifdef CONFIG_SCHED_RT_CAS
1690 	{
1691 		.procname	= "sched_enable_rt_cas",
1692 		.data		= &sysctl_sched_enable_rt_cas,
1693 		.maxlen		= sizeof(unsigned int),
1694 		.mode		= 0644,
1695 		.proc_handler	= proc_dointvec,
1696 	},
1697 #endif
1698 #ifdef CONFIG_SCHED_RT_ACTIVE_LB
1699 	{
1700 		.procname	= "sched_enable_rt_active_lb",
1701 		.data		= &sysctl_sched_enable_rt_active_lb,
1702 		.maxlen		= sizeof(unsigned int),
1703 		.mode		= 0644,
1704 		.proc_handler	= proc_dointvec,
1705 	},
1706 #endif
1707 #ifdef CONFIG_SCHED_WALT
1708 	{
1709 		.procname	= "sched_use_walt_cpu_util",
1710 		.data		= &sysctl_sched_use_walt_cpu_util,
1711 		.maxlen		= sizeof(unsigned int),
1712 		.mode		= 0644,
1713 		.proc_handler	= proc_dointvec_minmax,
1714 		.extra1		= SYSCTL_ZERO,
1715 		.extra2		= SYSCTL_ONE,
1716 	},
1717 	{
1718 		.procname	= "sched_use_walt_task_util",
1719 		.data		= &sysctl_sched_use_walt_task_util,
1720 		.maxlen		= sizeof(unsigned int),
1721 		.mode		= 0644,
1722 		.proc_handler	= proc_dointvec_minmax,
1723 		.extra1		= SYSCTL_ZERO,
1724 		.extra2		= SYSCTL_ONE,
1725 	},
1726 	{
1727 		.procname	= "sched_walt_init_task_load_pct",
1728 		.data		= &sysctl_sched_walt_init_task_load_pct,
1729 		.maxlen		= sizeof(unsigned int),
1730 		.mode		= 0644,
1731 		.proc_handler	= sysctl_sched_walt_init_task_load_pct_sysctl_handler,
1732 	},
1733 	{
1734 		.procname	= "sched_cpu_high_irqload",
1735 		.data		= &sysctl_sched_cpu_high_irqload,
1736 		.maxlen		= sizeof(unsigned int),
1737 		.mode		= 0644,
1738 		.proc_handler	= proc_dointvec,
1739 	},
1740 #endif
1741 #ifdef CONFIG_SCHED_DEBUG
1742 	{
1743 		.procname	= "sched_min_granularity_ns",
1744 		.data		= &sysctl_sched_min_granularity,
1745 		.maxlen		= sizeof(unsigned int),
1746 		.mode		= 0644,
1747 		.proc_handler	= sched_proc_update_handler,
1748 		.extra1		= &min_sched_granularity_ns,
1749 		.extra2		= &max_sched_granularity_ns,
1750 	},
1751 	{
1752 		.procname	= "sched_latency_ns",
1753 		.data		= &sysctl_sched_latency,
1754 		.maxlen		= sizeof(unsigned int),
1755 		.mode		= 0644,
1756 		.proc_handler	= sched_proc_update_handler,
1757 		.extra1		= &min_sched_granularity_ns,
1758 		.extra2		= &max_sched_granularity_ns,
1759 	},
1760 	{
1761 		.procname	= "sched_wakeup_granularity_ns",
1762 		.data		= &sysctl_sched_wakeup_granularity,
1763 		.maxlen		= sizeof(unsigned int),
1764 		.mode		= 0644,
1765 		.proc_handler	= sched_proc_update_handler,
1766 		.extra1		= &min_wakeup_granularity_ns,
1767 		.extra2		= &max_wakeup_granularity_ns,
1768 	},
1769 #ifdef CONFIG_SMP
1770 	{
1771 		.procname	= "sched_tunable_scaling",
1772 		.data		= &sysctl_sched_tunable_scaling,
1773 		.maxlen		= sizeof(enum sched_tunable_scaling),
1774 		.mode		= 0644,
1775 		.proc_handler	= sched_proc_update_handler,
1776 		.extra1		= &min_sched_tunable_scaling,
1777 		.extra2		= &max_sched_tunable_scaling,
1778 	},
1779 	{
1780 		.procname	= "sched_migration_cost_ns",
1781 		.data		= &sysctl_sched_migration_cost,
1782 		.maxlen		= sizeof(unsigned int),
1783 		.mode		= 0644,
1784 		.proc_handler	= proc_dointvec,
1785 	},
1786 	{
1787 		.procname	= "sched_nr_migrate",
1788 		.data		= &sysctl_sched_nr_migrate,
1789 		.maxlen		= sizeof(unsigned int),
1790 		.mode		= 0644,
1791 		.proc_handler	= proc_dointvec,
1792 	},
1793 #ifdef CONFIG_SCHEDSTATS
1794 	{
1795 		.procname	= "sched_schedstats",
1796 		.data		= NULL,
1797 		.maxlen		= sizeof(unsigned int),
1798 		.mode		= 0644,
1799 		.proc_handler	= sysctl_schedstats,
1800 		.extra1		= SYSCTL_ZERO,
1801 		.extra2		= SYSCTL_ONE,
1802 	},
1803 #endif /* CONFIG_SCHEDSTATS */
1804 #endif /* CONFIG_SMP */
1805 #ifdef CONFIG_NUMA_BALANCING
1806 	{
1807 		.procname	= "numa_balancing_scan_delay_ms",
1808 		.data		= &sysctl_numa_balancing_scan_delay,
1809 		.maxlen		= sizeof(unsigned int),
1810 		.mode		= 0644,
1811 		.proc_handler	= proc_dointvec,
1812 	},
1813 	{
1814 		.procname	= "numa_balancing_scan_period_min_ms",
1815 		.data		= &sysctl_numa_balancing_scan_period_min,
1816 		.maxlen		= sizeof(unsigned int),
1817 		.mode		= 0644,
1818 		.proc_handler	= proc_dointvec,
1819 	},
1820 	{
1821 		.procname	= "numa_balancing_scan_period_max_ms",
1822 		.data		= &sysctl_numa_balancing_scan_period_max,
1823 		.maxlen		= sizeof(unsigned int),
1824 		.mode		= 0644,
1825 		.proc_handler	= proc_dointvec,
1826 	},
1827 	{
1828 		.procname	= "numa_balancing_scan_size_mb",
1829 		.data		= &sysctl_numa_balancing_scan_size,
1830 		.maxlen		= sizeof(unsigned int),
1831 		.mode		= 0644,
1832 		.proc_handler	= proc_dointvec_minmax,
1833 		.extra1		= SYSCTL_ONE,
1834 	},
1835 	{
1836 		.procname	= "numa_balancing",
1837 		.data		= NULL, /* filled in by handler */
1838 		.maxlen		= sizeof(unsigned int),
1839 		.mode		= 0644,
1840 		.proc_handler	= sysctl_numa_balancing,
1841 		.extra1		= SYSCTL_ZERO,
1842 		.extra2		= SYSCTL_ONE,
1843 	},
1844 #endif /* CONFIG_NUMA_BALANCING */
1845 #endif /* CONFIG_SCHED_DEBUG */
1846 	{
1847 		.procname	= "sched_rt_period_us",
1848 		.data		= &sysctl_sched_rt_period,
1849 		.maxlen		= sizeof(unsigned int),
1850 		.mode		= 0644,
1851 		.proc_handler	= sched_rt_handler,
1852 	},
1853 	{
1854 		.procname	= "sched_rt_runtime_us",
1855 		.data		= &sysctl_sched_rt_runtime,
1856 		.maxlen		= sizeof(int),
1857 		.mode		= 0644,
1858 		.proc_handler	= sched_rt_handler,
1859 	},
1860 	{
1861 		.procname	= "sched_deadline_period_max_us",
1862 		.data		= &sysctl_sched_dl_period_max,
1863 		.maxlen		= sizeof(unsigned int),
1864 		.mode		= 0644,
1865 		.proc_handler	= proc_dointvec,
1866 	},
1867 	{
1868 		.procname	= "sched_deadline_period_min_us",
1869 		.data		= &sysctl_sched_dl_period_min,
1870 		.maxlen		= sizeof(unsigned int),
1871 		.mode		= 0644,
1872 		.proc_handler	= proc_dointvec,
1873 	},
1874 	{
1875 		.procname	= "sched_rr_timeslice_ms",
1876 		.data		= &sysctl_sched_rr_timeslice,
1877 		.maxlen		= sizeof(int),
1878 		.mode		= 0644,
1879 		.proc_handler	= sched_rr_handler,
1880 	},
1881 #ifdef CONFIG_UCLAMP_TASK
1882 	{
1883 		.procname	= "sched_util_clamp_min",
1884 		.data		= &sysctl_sched_uclamp_util_min,
1885 		.maxlen		= sizeof(unsigned int),
1886 		.mode		= 0644,
1887 		.proc_handler	= sysctl_sched_uclamp_handler,
1888 	},
1889 	{
1890 		.procname	= "sched_util_clamp_max",
1891 		.data		= &sysctl_sched_uclamp_util_max,
1892 		.maxlen		= sizeof(unsigned int),
1893 		.mode		= 0644,
1894 		.proc_handler	= sysctl_sched_uclamp_handler,
1895 	},
1896 	{
1897 		.procname	= "sched_util_clamp_min_rt_default",
1898 		.data		= &sysctl_sched_uclamp_util_min_rt_default,
1899 		.maxlen		= sizeof(unsigned int),
1900 		.mode		= 0644,
1901 		.proc_handler	= sysctl_sched_uclamp_handler,
1902 	},
1903 #endif
1904 #ifdef CONFIG_SCHED_AUTOGROUP
1905 	{
1906 		.procname	= "sched_autogroup_enabled",
1907 		.data		= &sysctl_sched_autogroup_enabled,
1908 		.maxlen		= sizeof(unsigned int),
1909 		.mode		= 0644,
1910 		.proc_handler	= proc_dointvec_minmax,
1911 		.extra1		= SYSCTL_ZERO,
1912 		.extra2		= SYSCTL_ONE,
1913 	},
1914 #endif
1915 #ifdef CONFIG_CFS_BANDWIDTH
1916 	{
1917 		.procname	= "sched_cfs_bandwidth_slice_us",
1918 		.data		= &sysctl_sched_cfs_bandwidth_slice,
1919 		.maxlen		= sizeof(unsigned int),
1920 		.mode		= 0644,
1921 		.proc_handler	= proc_dointvec_minmax,
1922 		.extra1		= SYSCTL_ONE,
1923 	},
1924 #endif
1925 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
1926 	{
1927 		.procname	= "sched_energy_aware",
1928 		.data		= &sysctl_sched_energy_aware,
1929 		.maxlen		= sizeof(unsigned int),
1930 		.mode		= 0644,
1931 		.proc_handler	= sched_energy_aware_handler,
1932 		.extra1		= SYSCTL_ZERO,
1933 		.extra2		= SYSCTL_ONE,
1934 	},
1935 #endif
1936 #ifdef CONFIG_PROVE_LOCKING
1937 	{
1938 		.procname	= "prove_locking",
1939 		.data		= &prove_locking,
1940 		.maxlen		= sizeof(int),
1941 		.mode		= 0644,
1942 		.proc_handler	= proc_dointvec,
1943 	},
1944 #endif
1945 #ifdef CONFIG_LOCK_STAT
1946 	{
1947 		.procname	= "lock_stat",
1948 		.data		= &lock_stat,
1949 		.maxlen		= sizeof(int),
1950 		.mode		= 0644,
1951 		.proc_handler	= proc_dointvec,
1952 	},
1953 #endif
1954 	{
1955 		.procname	= "panic",
1956 		.data		= &panic_timeout,
1957 		.maxlen		= sizeof(int),
1958 		.mode		= 0644,
1959 		.proc_handler	= proc_dointvec,
1960 	},
1961 #ifdef CONFIG_COREDUMP
1962 	{
1963 		.procname	= "core_uses_pid",
1964 		.data		= &core_uses_pid,
1965 		.maxlen		= sizeof(int),
1966 		.mode		= 0644,
1967 		.proc_handler	= proc_dointvec,
1968 	},
1969 	{
1970 		.procname	= "core_pattern",
1971 		.data		= core_pattern,
1972 		.maxlen		= CORENAME_MAX_SIZE,
1973 		.mode		= 0644,
1974 		.proc_handler	= proc_dostring_coredump,
1975 	},
1976 	{
1977 		.procname	= "core_pipe_limit",
1978 		.data		= &core_pipe_limit,
1979 		.maxlen		= sizeof(unsigned int),
1980 		.mode		= 0644,
1981 		.proc_handler	= proc_dointvec,
1982 	},
1983 #endif
1984 #ifdef CONFIG_PROC_SYSCTL
1985 	{
1986 		.procname	= "tainted",
1987 		.maxlen 	= sizeof(long),
1988 		.mode		= 0644,
1989 		.proc_handler	= proc_taint,
1990 	},
1991 	{
1992 		.procname	= "sysctl_writes_strict",
1993 		.data		= &sysctl_writes_strict,
1994 		.maxlen		= sizeof(int),
1995 		.mode		= 0644,
1996 		.proc_handler	= proc_dointvec_minmax,
1997 		.extra1		= &neg_one,
1998 		.extra2		= SYSCTL_ONE,
1999 	},
2000 #endif
2001 #ifdef CONFIG_LATENCYTOP
2002 	{
2003 		.procname	= "latencytop",
2004 		.data		= &latencytop_enabled,
2005 		.maxlen		= sizeof(int),
2006 		.mode		= 0644,
2007 		.proc_handler	= sysctl_latencytop,
2008 	},
2009 #endif
2010 #ifdef CONFIG_BLK_DEV_INITRD
2011 	{
2012 		.procname	= "real-root-dev",
2013 		.data		= &real_root_dev,
2014 		.maxlen		= sizeof(int),
2015 		.mode		= 0644,
2016 		.proc_handler	= proc_dointvec,
2017 	},
2018 #endif
2019 	{
2020 		.procname	= "print-fatal-signals",
2021 		.data		= &print_fatal_signals,
2022 		.maxlen		= sizeof(int),
2023 		.mode		= 0644,
2024 		.proc_handler	= proc_dointvec,
2025 	},
2026 #ifdef CONFIG_SPARC
2027 	{
2028 		.procname	= "reboot-cmd",
2029 		.data		= reboot_command,
2030 		.maxlen		= 256,
2031 		.mode		= 0644,
2032 		.proc_handler	= proc_dostring,
2033 	},
2034 	{
2035 		.procname	= "stop-a",
2036 		.data		= &stop_a_enabled,
2037 		.maxlen		= sizeof (int),
2038 		.mode		= 0644,
2039 		.proc_handler	= proc_dointvec,
2040 	},
2041 	{
2042 		.procname	= "scons-poweroff",
2043 		.data		= &scons_pwroff,
2044 		.maxlen		= sizeof (int),
2045 		.mode		= 0644,
2046 		.proc_handler	= proc_dointvec,
2047 	},
2048 #endif
2049 #ifdef CONFIG_SPARC64
2050 	{
2051 		.procname	= "tsb-ratio",
2052 		.data		= &sysctl_tsb_ratio,
2053 		.maxlen		= sizeof (int),
2054 		.mode		= 0644,
2055 		.proc_handler	= proc_dointvec,
2056 	},
2057 #endif
2058 #ifdef CONFIG_PARISC
2059 	{
2060 		.procname	= "soft-power",
2061 		.data		= &pwrsw_enabled,
2062 		.maxlen		= sizeof (int),
2063 		.mode		= 0644,
2064 		.proc_handler	= proc_dointvec,
2065 	},
2066 #endif
2067 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
2068 	{
2069 		.procname	= "unaligned-trap",
2070 		.data		= &unaligned_enabled,
2071 		.maxlen		= sizeof (int),
2072 		.mode		= 0644,
2073 		.proc_handler	= proc_dointvec,
2074 	},
2075 #endif
2076 	{
2077 		.procname	= "ctrl-alt-del",
2078 		.data		= &C_A_D,
2079 		.maxlen		= sizeof(int),
2080 		.mode		= 0644,
2081 		.proc_handler	= proc_dointvec,
2082 	},
2083 #ifdef CONFIG_FUNCTION_TRACER
2084 	{
2085 		.procname	= "ftrace_enabled",
2086 		.data		= &ftrace_enabled,
2087 		.maxlen		= sizeof(int),
2088 		.mode		= 0644,
2089 		.proc_handler	= ftrace_enable_sysctl,
2090 	},
2091 #endif
2092 #ifdef CONFIG_STACK_TRACER
2093 	{
2094 		.procname	= "stack_tracer_enabled",
2095 		.data		= &stack_tracer_enabled,
2096 		.maxlen		= sizeof(int),
2097 		.mode		= 0644,
2098 		.proc_handler	= stack_trace_sysctl,
2099 	},
2100 #endif
2101 #ifdef CONFIG_TRACING
2102 	{
2103 		.procname	= "ftrace_dump_on_oops",
2104 		.data		= &ftrace_dump_on_oops,
2105 		.maxlen		= sizeof(int),
2106 		.mode		= 0644,
2107 		.proc_handler	= proc_dointvec,
2108 	},
2109 	{
2110 		.procname	= "traceoff_on_warning",
2111 		.data		= &__disable_trace_on_warning,
2112 		.maxlen		= sizeof(__disable_trace_on_warning),
2113 		.mode		= 0644,
2114 		.proc_handler	= proc_dointvec,
2115 	},
2116 	{
2117 		.procname	= "tracepoint_printk",
2118 		.data		= &tracepoint_printk,
2119 		.maxlen		= sizeof(tracepoint_printk),
2120 		.mode		= 0644,
2121 		.proc_handler	= tracepoint_printk_sysctl,
2122 	},
2123 #endif
2124 #ifdef CONFIG_KEXEC_CORE
2125 	{
2126 		.procname	= "kexec_load_disabled",
2127 		.data		= &kexec_load_disabled,
2128 		.maxlen		= sizeof(int),
2129 		.mode		= 0644,
2130 		/* only handle a transition from default "0" to "1" */
2131 		.proc_handler	= proc_dointvec_minmax,
2132 		.extra1		= SYSCTL_ONE,
2133 		.extra2		= SYSCTL_ONE,
2134 	},
2135 #endif
2136 #ifdef CONFIG_MODULES
2137 	{
2138 		.procname	= "modprobe",
2139 		.data		= &modprobe_path,
2140 		.maxlen		= KMOD_PATH_LEN,
2141 		.mode		= 0644,
2142 		.proc_handler	= proc_dostring,
2143 	},
2144 	{
2145 		.procname	= "modules_disabled",
2146 		.data		= &modules_disabled,
2147 		.maxlen		= sizeof(int),
2148 		.mode		= 0644,
2149 		/* only handle a transition from default "0" to "1" */
2150 		.proc_handler	= proc_dointvec_minmax,
2151 		.extra1		= SYSCTL_ONE,
2152 		.extra2		= SYSCTL_ONE,
2153 	},
2154 #endif
2155 #ifdef CONFIG_UEVENT_HELPER
2156 	{
2157 		.procname	= "hotplug",
2158 		.data		= &uevent_helper,
2159 		.maxlen		= UEVENT_HELPER_PATH_LEN,
2160 		.mode		= 0644,
2161 		.proc_handler	= proc_dostring,
2162 	},
2163 #endif
2164 #ifdef CONFIG_CHR_DEV_SG
2165 	{
2166 		.procname	= "sg-big-buff",
2167 		.data		= &sg_big_buff,
2168 		.maxlen		= sizeof (int),
2169 		.mode		= 0444,
2170 		.proc_handler	= proc_dointvec,
2171 	},
2172 #endif
2173 #ifdef CONFIG_BSD_PROCESS_ACCT
2174 	{
2175 		.procname	= "acct",
2176 		.data		= &acct_parm,
2177 		.maxlen		= 3*sizeof(int),
2178 		.mode		= 0644,
2179 		.proc_handler	= proc_dointvec,
2180 	},
2181 #endif
2182 #ifdef CONFIG_MAGIC_SYSRQ
2183 	{
2184 		.procname	= "sysrq",
2185 		.data		= NULL,
2186 		.maxlen		= sizeof (int),
2187 		.mode		= 0644,
2188 		.proc_handler	= sysrq_sysctl_handler,
2189 	},
2190 #endif
2191 #ifdef CONFIG_PROC_SYSCTL
2192 	{
2193 		.procname	= "cad_pid",
2194 		.data		= NULL,
2195 		.maxlen		= sizeof (int),
2196 		.mode		= 0600,
2197 		.proc_handler	= proc_do_cad_pid,
2198 	},
2199 #endif
2200 	{
2201 		.procname	= "threads-max",
2202 		.data		= NULL,
2203 		.maxlen		= sizeof(int),
2204 		.mode		= 0644,
2205 		.proc_handler	= sysctl_max_threads,
2206 	},
2207 	{
2208 		.procname	= "random",
2209 		.mode		= 0555,
2210 		.child		= random_table,
2211 	},
2212 	{
2213 		.procname	= "usermodehelper",
2214 		.mode		= 0555,
2215 		.child		= usermodehelper_table,
2216 	},
2217 #ifdef CONFIG_FW_LOADER_USER_HELPER
2218 	{
2219 		.procname	= "firmware_config",
2220 		.mode		= 0555,
2221 		.child		= firmware_config_table,
2222 	},
2223 #endif
2224 	{
2225 		.procname	= "overflowuid",
2226 		.data		= &overflowuid,
2227 		.maxlen		= sizeof(int),
2228 		.mode		= 0644,
2229 		.proc_handler	= proc_dointvec_minmax,
2230 		.extra1		= &minolduid,
2231 		.extra2		= &maxolduid,
2232 	},
2233 	{
2234 		.procname	= "overflowgid",
2235 		.data		= &overflowgid,
2236 		.maxlen		= sizeof(int),
2237 		.mode		= 0644,
2238 		.proc_handler	= proc_dointvec_minmax,
2239 		.extra1		= &minolduid,
2240 		.extra2		= &maxolduid,
2241 	},
2242 #ifdef CONFIG_S390
2243 	{
2244 		.procname	= "userprocess_debug",
2245 		.data		= &show_unhandled_signals,
2246 		.maxlen		= sizeof(int),
2247 		.mode		= 0644,
2248 		.proc_handler	= proc_dointvec,
2249 	},
2250 #endif
2251 #ifdef CONFIG_SMP
2252 	{
2253 		.procname	= "oops_all_cpu_backtrace",
2254 		.data		= &sysctl_oops_all_cpu_backtrace,
2255 		.maxlen		= sizeof(int),
2256 		.mode		= 0644,
2257 		.proc_handler	= proc_dointvec_minmax,
2258 		.extra1		= SYSCTL_ZERO,
2259 		.extra2		= SYSCTL_ONE,
2260 	},
2261 #endif /* CONFIG_SMP */
2262 	{
2263 		.procname	= "pid_max",
2264 		.data		= &pid_max,
2265 		.maxlen		= sizeof (int),
2266 		.mode		= 0644,
2267 		.proc_handler	= proc_dointvec_minmax,
2268 		.extra1		= &pid_max_min,
2269 		.extra2		= &pid_max_max,
2270 	},
2271 	{
2272 		.procname	= "panic_on_oops",
2273 		.data		= &panic_on_oops,
2274 		.maxlen		= sizeof(int),
2275 		.mode		= 0644,
2276 		.proc_handler	= proc_dointvec,
2277 	},
2278 	{
2279 		.procname	= "panic_print",
2280 		.data		= &panic_print,
2281 		.maxlen		= sizeof(unsigned long),
2282 		.mode		= 0644,
2283 		.proc_handler	= proc_doulongvec_minmax,
2284 	},
2285 #if defined CONFIG_PRINTK
2286 	{
2287 		.procname	= "printk",
2288 		.data		= &console_loglevel,
2289 		.maxlen		= 4*sizeof(int),
2290 		.mode		= 0644,
2291 		.proc_handler	= proc_dointvec,
2292 	},
2293 	{
2294 		.procname	= "printk_ratelimit",
2295 		.data		= &printk_ratelimit_state.interval,
2296 		.maxlen		= sizeof(int),
2297 		.mode		= 0644,
2298 		.proc_handler	= proc_dointvec_jiffies,
2299 	},
2300 	{
2301 		.procname	= "printk_ratelimit_burst",
2302 		.data		= &printk_ratelimit_state.burst,
2303 		.maxlen		= sizeof(int),
2304 		.mode		= 0644,
2305 		.proc_handler	= proc_dointvec,
2306 	},
2307 	{
2308 		.procname	= "printk_delay",
2309 		.data		= &printk_delay_msec,
2310 		.maxlen		= sizeof(int),
2311 		.mode		= 0644,
2312 		.proc_handler	= proc_dointvec_minmax,
2313 		.extra1		= SYSCTL_ZERO,
2314 		.extra2		= &ten_thousand,
2315 	},
2316 	{
2317 		.procname	= "printk_devkmsg",
2318 		.data		= devkmsg_log_str,
2319 		.maxlen		= DEVKMSG_STR_MAX_SIZE,
2320 		.mode		= 0644,
2321 		.proc_handler	= devkmsg_sysctl_set_loglvl,
2322 	},
2323 	{
2324 		.procname	= "dmesg_restrict",
2325 		.data		= &dmesg_restrict,
2326 		.maxlen		= sizeof(int),
2327 		.mode		= 0644,
2328 		.proc_handler	= proc_dointvec_minmax_sysadmin,
2329 		.extra1		= SYSCTL_ZERO,
2330 		.extra2		= SYSCTL_ONE,
2331 	},
2332 	{
2333 		.procname	= "kptr_restrict",
2334 		.data		= &kptr_restrict,
2335 		.maxlen		= sizeof(int),
2336 		.mode		= 0644,
2337 		.proc_handler	= proc_dointvec_minmax_sysadmin,
2338 		.extra1		= SYSCTL_ZERO,
2339 		.extra2		= &two,
2340 	},
2341 #endif
2342 	{
2343 		.procname	= "ngroups_max",
2344 		.data		= &ngroups_max,
2345 		.maxlen		= sizeof (int),
2346 		.mode		= 0444,
2347 		.proc_handler	= proc_dointvec,
2348 	},
2349 	{
2350 		.procname	= "cap_last_cap",
2351 		.data		= (void *)&cap_last_cap,
2352 		.maxlen		= sizeof(int),
2353 		.mode		= 0444,
2354 		.proc_handler	= proc_dointvec,
2355 	},
2356 #if defined(CONFIG_LOCKUP_DETECTOR)
2357 	{
2358 		.procname       = "watchdog",
2359 		.data		= &watchdog_user_enabled,
2360 		.maxlen		= sizeof(int),
2361 		.mode		= 0644,
2362 		.proc_handler   = proc_watchdog,
2363 		.extra1		= SYSCTL_ZERO,
2364 		.extra2		= SYSCTL_ONE,
2365 	},
2366 	{
2367 		.procname	= "watchdog_thresh",
2368 		.data		= &watchdog_thresh,
2369 		.maxlen		= sizeof(int),
2370 		.mode		= 0644,
2371 		.proc_handler	= proc_watchdog_thresh,
2372 		.extra1		= SYSCTL_ZERO,
2373 		.extra2		= &sixty,
2374 	},
2375 	{
2376 		.procname       = "nmi_watchdog",
2377 		.data		= &nmi_watchdog_user_enabled,
2378 		.maxlen		= sizeof(int),
2379 		.mode		= NMI_WATCHDOG_SYSCTL_PERM,
2380 		.proc_handler   = proc_nmi_watchdog,
2381 		.extra1		= SYSCTL_ZERO,
2382 		.extra2		= SYSCTL_ONE,
2383 	},
2384 	{
2385 		.procname	= "watchdog_cpumask",
2386 		.data		= &watchdog_cpumask_bits,
2387 		.maxlen		= NR_CPUS,
2388 		.mode		= 0644,
2389 		.proc_handler	= proc_watchdog_cpumask,
2390 	},
2391 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
2392 	{
2393 		.procname       = "soft_watchdog",
2394 		.data		= &soft_watchdog_user_enabled,
2395 		.maxlen		= sizeof(int),
2396 		.mode		= 0644,
2397 		.proc_handler   = proc_soft_watchdog,
2398 		.extra1		= SYSCTL_ZERO,
2399 		.extra2		= SYSCTL_ONE,
2400 	},
2401 	{
2402 		.procname	= "softlockup_panic",
2403 		.data		= &softlockup_panic,
2404 		.maxlen		= sizeof(int),
2405 		.mode		= 0644,
2406 		.proc_handler	= proc_dointvec_minmax,
2407 		.extra1		= SYSCTL_ZERO,
2408 		.extra2		= SYSCTL_ONE,
2409 	},
2410 #ifdef CONFIG_SMP
2411 	{
2412 		.procname	= "softlockup_all_cpu_backtrace",
2413 		.data		= &sysctl_softlockup_all_cpu_backtrace,
2414 		.maxlen		= sizeof(int),
2415 		.mode		= 0644,
2416 		.proc_handler	= proc_dointvec_minmax,
2417 		.extra1		= SYSCTL_ZERO,
2418 		.extra2		= SYSCTL_ONE,
2419 	},
2420 #endif /* CONFIG_SMP */
2421 #endif
2422 #ifdef CONFIG_HARDLOCKUP_DETECTOR
2423 	{
2424 		.procname	= "hardlockup_panic",
2425 		.data		= &hardlockup_panic,
2426 		.maxlen		= sizeof(int),
2427 		.mode		= 0644,
2428 		.proc_handler	= proc_dointvec_minmax,
2429 		.extra1		= SYSCTL_ZERO,
2430 		.extra2		= SYSCTL_ONE,
2431 	},
2432 #ifdef CONFIG_SMP
2433 	{
2434 		.procname	= "hardlockup_all_cpu_backtrace",
2435 		.data		= &sysctl_hardlockup_all_cpu_backtrace,
2436 		.maxlen		= sizeof(int),
2437 		.mode		= 0644,
2438 		.proc_handler	= proc_dointvec_minmax,
2439 		.extra1		= SYSCTL_ZERO,
2440 		.extra2		= SYSCTL_ONE,
2441 	},
2442 #endif /* CONFIG_SMP */
2443 #endif
2444 #endif
2445 
2446 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
2447 	{
2448 		.procname       = "unknown_nmi_panic",
2449 		.data           = &unknown_nmi_panic,
2450 		.maxlen         = sizeof (int),
2451 		.mode           = 0644,
2452 		.proc_handler   = proc_dointvec,
2453 	},
2454 #endif
2455 
2456 #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
2457 	defined(CONFIG_DEBUG_STACKOVERFLOW)
2458 	{
2459 		.procname	= "panic_on_stackoverflow",
2460 		.data		= &sysctl_panic_on_stackoverflow,
2461 		.maxlen		= sizeof(int),
2462 		.mode		= 0644,
2463 		.proc_handler	= proc_dointvec,
2464 	},
2465 #endif
2466 #if defined(CONFIG_X86)
2467 	{
2468 		.procname	= "panic_on_unrecovered_nmi",
2469 		.data		= &panic_on_unrecovered_nmi,
2470 		.maxlen		= sizeof(int),
2471 		.mode		= 0644,
2472 		.proc_handler	= proc_dointvec,
2473 	},
2474 	{
2475 		.procname	= "panic_on_io_nmi",
2476 		.data		= &panic_on_io_nmi,
2477 		.maxlen		= sizeof(int),
2478 		.mode		= 0644,
2479 		.proc_handler	= proc_dointvec,
2480 	},
2481 	{
2482 		.procname	= "bootloader_type",
2483 		.data		= &bootloader_type,
2484 		.maxlen		= sizeof (int),
2485 		.mode		= 0444,
2486 		.proc_handler	= proc_dointvec,
2487 	},
2488 	{
2489 		.procname	= "bootloader_version",
2490 		.data		= &bootloader_version,
2491 		.maxlen		= sizeof (int),
2492 		.mode		= 0444,
2493 		.proc_handler	= proc_dointvec,
2494 	},
2495 	{
2496 		.procname	= "io_delay_type",
2497 		.data		= &io_delay_type,
2498 		.maxlen		= sizeof(int),
2499 		.mode		= 0644,
2500 		.proc_handler	= proc_dointvec,
2501 	},
2502 #endif
2503 #if defined(CONFIG_MMU)
2504 	{
2505 		.procname	= "randomize_va_space",
2506 		.data		= &randomize_va_space,
2507 		.maxlen		= sizeof(int),
2508 		.mode		= 0644,
2509 		.proc_handler	= proc_dointvec,
2510 	},
2511 #endif
2512 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
2513 	{
2514 		.procname	= "spin_retry",
2515 		.data		= &spin_retry,
2516 		.maxlen		= sizeof (int),
2517 		.mode		= 0644,
2518 		.proc_handler	= proc_dointvec,
2519 	},
2520 #endif
2521 #if	defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
2522 	{
2523 		.procname	= "acpi_video_flags",
2524 		.data		= &acpi_realmode_flags,
2525 		.maxlen		= sizeof (unsigned long),
2526 		.mode		= 0644,
2527 		.proc_handler	= proc_doulongvec_minmax,
2528 	},
2529 #endif
2530 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
2531 	{
2532 		.procname	= "ignore-unaligned-usertrap",
2533 		.data		= &no_unaligned_warning,
2534 		.maxlen		= sizeof (int),
2535 		.mode		= 0644,
2536 		.proc_handler	= proc_dointvec,
2537 	},
2538 #endif
2539 #ifdef CONFIG_IA64
2540 	{
2541 		.procname	= "unaligned-dump-stack",
2542 		.data		= &unaligned_dump_stack,
2543 		.maxlen		= sizeof (int),
2544 		.mode		= 0644,
2545 		.proc_handler	= proc_dointvec,
2546 	},
2547 #endif
2548 #ifdef CONFIG_DETECT_HUNG_TASK
2549 #ifdef CONFIG_SMP
2550 	{
2551 		.procname	= "hung_task_all_cpu_backtrace",
2552 		.data		= &sysctl_hung_task_all_cpu_backtrace,
2553 		.maxlen		= sizeof(int),
2554 		.mode		= 0644,
2555 		.proc_handler	= proc_dointvec_minmax,
2556 		.extra1		= SYSCTL_ZERO,
2557 		.extra2		= SYSCTL_ONE,
2558 	},
2559 #endif /* CONFIG_SMP */
2560 	{
2561 		.procname	= "hung_task_panic",
2562 		.data		= &sysctl_hung_task_panic,
2563 		.maxlen		= sizeof(int),
2564 		.mode		= 0644,
2565 		.proc_handler	= proc_dointvec_minmax,
2566 		.extra1		= SYSCTL_ZERO,
2567 		.extra2		= SYSCTL_ONE,
2568 	},
2569 	{
2570 		.procname	= "hung_task_check_count",
2571 		.data		= &sysctl_hung_task_check_count,
2572 		.maxlen		= sizeof(int),
2573 		.mode		= 0644,
2574 		.proc_handler	= proc_dointvec_minmax,
2575 		.extra1		= SYSCTL_ZERO,
2576 	},
2577 	{
2578 		.procname	= "hung_task_timeout_secs",
2579 		.data		= &sysctl_hung_task_timeout_secs,
2580 		.maxlen		= sizeof(unsigned long),
2581 		.mode		= 0644,
2582 		.proc_handler	= proc_dohung_task_timeout_secs,
2583 		.extra2		= &hung_task_timeout_max,
2584 	},
2585 	{
2586 		.procname	= "hung_task_check_interval_secs",
2587 		.data		= &sysctl_hung_task_check_interval_secs,
2588 		.maxlen		= sizeof(unsigned long),
2589 		.mode		= 0644,
2590 		.proc_handler	= proc_dohung_task_timeout_secs,
2591 		.extra2		= &hung_task_timeout_max,
2592 	},
2593 	{
2594 		.procname	= "hung_task_warnings",
2595 		.data		= &sysctl_hung_task_warnings,
2596 		.maxlen		= sizeof(int),
2597 		.mode		= 0644,
2598 		.proc_handler	= proc_dointvec_minmax,
2599 		.extra1		= &neg_one,
2600 	},
2601 #endif
2602 #ifdef CONFIG_RT_MUTEXES
2603 	{
2604 		.procname	= "max_lock_depth",
2605 		.data		= &max_lock_depth,
2606 		.maxlen		= sizeof(int),
2607 		.mode		= 0644,
2608 		.proc_handler	= proc_dointvec,
2609 	},
2610 #endif
2611 	{
2612 		.procname	= "poweroff_cmd",
2613 		.data		= &poweroff_cmd,
2614 		.maxlen		= POWEROFF_CMD_PATH_LEN,
2615 		.mode		= 0644,
2616 		.proc_handler	= proc_dostring,
2617 	},
2618 #ifdef CONFIG_KEYS
2619 	{
2620 		.procname	= "keys",
2621 		.mode		= 0555,
2622 		.child		= key_sysctls,
2623 	},
2624 #endif
2625 #ifdef CONFIG_PERF_EVENTS
2626 	/*
2627 	 * User-space scripts rely on the existence of this file
2628 	 * as a feature check for perf_events being enabled.
2629 	 *
2630 	 * So it's an ABI, do not remove!
2631 	 */
2632 	{
2633 		.procname	= "perf_event_paranoid",
2634 		.data		= &sysctl_perf_event_paranoid,
2635 		.maxlen		= sizeof(sysctl_perf_event_paranoid),
2636 		.mode		= 0644,
2637 		.proc_handler	= proc_dointvec,
2638 	},
2639 	{
2640 		.procname	= "perf_event_mlock_kb",
2641 		.data		= &sysctl_perf_event_mlock,
2642 		.maxlen		= sizeof(sysctl_perf_event_mlock),
2643 		.mode		= 0644,
2644 		.proc_handler	= proc_dointvec,
2645 	},
2646 	{
2647 		.procname	= "perf_event_max_sample_rate",
2648 		.data		= &sysctl_perf_event_sample_rate,
2649 		.maxlen		= sizeof(sysctl_perf_event_sample_rate),
2650 		.mode		= 0644,
2651 		.proc_handler	= perf_proc_update_handler,
2652 		.extra1		= SYSCTL_ONE,
2653 	},
2654 	{
2655 		.procname	= "perf_cpu_time_max_percent",
2656 		.data		= &sysctl_perf_cpu_time_max_percent,
2657 		.maxlen		= sizeof(sysctl_perf_cpu_time_max_percent),
2658 		.mode		= 0644,
2659 		.proc_handler	= perf_cpu_time_max_percent_handler,
2660 		.extra1		= SYSCTL_ZERO,
2661 		.extra2		= &one_hundred,
2662 	},
2663 	{
2664 		.procname	= "perf_event_max_stack",
2665 		.data		= &sysctl_perf_event_max_stack,
2666 		.maxlen		= sizeof(sysctl_perf_event_max_stack),
2667 		.mode		= 0644,
2668 		.proc_handler	= perf_event_max_stack_handler,
2669 		.extra1		= SYSCTL_ZERO,
2670 		.extra2		= &six_hundred_forty_kb,
2671 	},
2672 	{
2673 		.procname	= "perf_event_max_contexts_per_stack",
2674 		.data		= &sysctl_perf_event_max_contexts_per_stack,
2675 		.maxlen		= sizeof(sysctl_perf_event_max_contexts_per_stack),
2676 		.mode		= 0644,
2677 		.proc_handler	= perf_event_max_stack_handler,
2678 		.extra1		= SYSCTL_ZERO,
2679 		.extra2		= &one_thousand,
2680 	},
2681 #endif
2682 	{
2683 		.procname	= "panic_on_warn",
2684 		.data		= &panic_on_warn,
2685 		.maxlen		= sizeof(int),
2686 		.mode		= 0644,
2687 		.proc_handler	= proc_dointvec_minmax,
2688 		.extra1		= SYSCTL_ZERO,
2689 		.extra2		= SYSCTL_ONE,
2690 	},
2691 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
2692 	{
2693 		.procname	= "timer_migration",
2694 		.data		= &sysctl_timer_migration,
2695 		.maxlen		= sizeof(unsigned int),
2696 		.mode		= 0644,
2697 		.proc_handler	= timer_migration_handler,
2698 		.extra1		= SYSCTL_ZERO,
2699 		.extra2		= SYSCTL_ONE,
2700 	},
2701 #endif
2702 #ifdef CONFIG_BPF_SYSCALL
2703 	{
2704 		.procname	= "unprivileged_bpf_disabled",
2705 		.data		= &sysctl_unprivileged_bpf_disabled,
2706 		.maxlen		= sizeof(sysctl_unprivileged_bpf_disabled),
2707 		.mode		= 0644,
2708 		.proc_handler	= bpf_unpriv_handler,
2709 		.extra1		= SYSCTL_ZERO,
2710 		.extra2		= &two,
2711 	},
2712 	{
2713 		.procname	= "bpf_stats_enabled",
2714 		.data		= &bpf_stats_enabled_key.key,
2715 		.maxlen		= sizeof(bpf_stats_enabled_key),
2716 		.mode		= 0644,
2717 		.proc_handler	= bpf_stats_handler,
2718 	},
2719 #endif
2720 #if defined(CONFIG_TREE_RCU)
2721 	{
2722 		.procname	= "panic_on_rcu_stall",
2723 		.data		= &sysctl_panic_on_rcu_stall,
2724 		.maxlen		= sizeof(sysctl_panic_on_rcu_stall),
2725 		.mode		= 0644,
2726 		.proc_handler	= proc_dointvec_minmax,
2727 		.extra1		= SYSCTL_ZERO,
2728 		.extra2		= SYSCTL_ONE,
2729 	},
2730 #endif
2731 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
2732 	{
2733 		.procname	= "stack_erasing",
2734 		.data		= NULL,
2735 		.maxlen		= sizeof(int),
2736 		.mode		= 0600,
2737 		.proc_handler	= stack_erasing_sysctl,
2738 		.extra1		= SYSCTL_ZERO,
2739 		.extra2		= SYSCTL_ONE,
2740 	},
2741 #endif
2742 	{ }
2743 };
2744 
2745 static struct ctl_table vm_table[] = {
2746 	{
2747 		.procname	= "overcommit_memory",
2748 		.data		= &sysctl_overcommit_memory,
2749 		.maxlen		= sizeof(sysctl_overcommit_memory),
2750 		.mode		= 0644,
2751 		.proc_handler	= overcommit_policy_handler,
2752 		.extra1		= SYSCTL_ZERO,
2753 		.extra2		= &two,
2754 	},
2755 	{
2756 		.procname	= "panic_on_oom",
2757 		.data		= &sysctl_panic_on_oom,
2758 		.maxlen		= sizeof(sysctl_panic_on_oom),
2759 		.mode		= 0644,
2760 		.proc_handler	= proc_dointvec_minmax,
2761 		.extra1		= SYSCTL_ZERO,
2762 		.extra2		= &two,
2763 	},
2764 	{
2765 		.procname	= "oom_kill_allocating_task",
2766 		.data		= &sysctl_oom_kill_allocating_task,
2767 		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
2768 		.mode		= 0644,
2769 		.proc_handler	= proc_dointvec,
2770 	},
2771 	{
2772 		.procname	= "oom_dump_tasks",
2773 		.data		= &sysctl_oom_dump_tasks,
2774 		.maxlen		= sizeof(sysctl_oom_dump_tasks),
2775 		.mode		= 0644,
2776 		.proc_handler	= proc_dointvec,
2777 	},
2778 	{
2779 		.procname	= "overcommit_ratio",
2780 		.data		= &sysctl_overcommit_ratio,
2781 		.maxlen		= sizeof(sysctl_overcommit_ratio),
2782 		.mode		= 0644,
2783 		.proc_handler	= overcommit_ratio_handler,
2784 	},
2785 	{
2786 		.procname	= "overcommit_kbytes",
2787 		.data		= &sysctl_overcommit_kbytes,
2788 		.maxlen		= sizeof(sysctl_overcommit_kbytes),
2789 		.mode		= 0644,
2790 		.proc_handler	= overcommit_kbytes_handler,
2791 	},
2792 	{
2793 		.procname	= "page-cluster",
2794 		.data		= &page_cluster,
2795 		.maxlen		= sizeof(int),
2796 		.mode		= 0644,
2797 		.proc_handler	= proc_dointvec_minmax,
2798 		.extra1		= SYSCTL_ZERO,
2799 	},
2800 	{
2801 		.procname	= "dirty_background_ratio",
2802 		.data		= &dirty_background_ratio,
2803 		.maxlen		= sizeof(dirty_background_ratio),
2804 		.mode		= 0644,
2805 		.proc_handler	= dirty_background_ratio_handler,
2806 		.extra1		= SYSCTL_ZERO,
2807 		.extra2		= &one_hundred,
2808 	},
2809 	{
2810 		.procname	= "dirty_background_bytes",
2811 		.data		= &dirty_background_bytes,
2812 		.maxlen		= sizeof(dirty_background_bytes),
2813 		.mode		= 0644,
2814 		.proc_handler	= dirty_background_bytes_handler,
2815 		.extra1		= &one_ul,
2816 	},
2817 	{
2818 		.procname	= "dirty_ratio",
2819 		.data		= &vm_dirty_ratio,
2820 		.maxlen		= sizeof(vm_dirty_ratio),
2821 		.mode		= 0644,
2822 		.proc_handler	= dirty_ratio_handler,
2823 		.extra1		= SYSCTL_ZERO,
2824 		.extra2		= &one_hundred,
2825 	},
2826 	{
2827 		.procname	= "dirty_bytes",
2828 		.data		= &vm_dirty_bytes,
2829 		.maxlen		= sizeof(vm_dirty_bytes),
2830 		.mode		= 0644,
2831 		.proc_handler	= dirty_bytes_handler,
2832 		.extra1		= &dirty_bytes_min,
2833 	},
2834 	{
2835 		.procname	= "dirty_writeback_centisecs",
2836 		.data		= &dirty_writeback_interval,
2837 		.maxlen		= sizeof(dirty_writeback_interval),
2838 		.mode		= 0644,
2839 		.proc_handler	= dirty_writeback_centisecs_handler,
2840 	},
2841 	{
2842 		.procname	= "dirty_expire_centisecs",
2843 		.data		= &dirty_expire_interval,
2844 		.maxlen		= sizeof(dirty_expire_interval),
2845 		.mode		= 0644,
2846 		.proc_handler	= proc_dointvec_minmax,
2847 		.extra1		= SYSCTL_ZERO,
2848 	},
2849 	{
2850 		.procname	= "dirtytime_expire_seconds",
2851 		.data		= &dirtytime_expire_interval,
2852 		.maxlen		= sizeof(dirtytime_expire_interval),
2853 		.mode		= 0644,
2854 		.proc_handler	= dirtytime_interval_handler,
2855 		.extra1		= SYSCTL_ZERO,
2856 	},
2857 	{
2858 		.procname	= "swappiness",
2859 		.data		= &vm_swappiness,
2860 		.maxlen		= sizeof(vm_swappiness),
2861 		.mode		= 0644,
2862 		.proc_handler	= proc_dointvec_minmax,
2863 		.extra1		= SYSCTL_ZERO,
2864 		.extra2		= &two_hundred,
2865 	},
2866 #ifdef CONFIG_HUGETLB_PAGE
2867 	{
2868 		.procname	= "nr_hugepages",
2869 		.data		= NULL,
2870 		.maxlen		= sizeof(unsigned long),
2871 		.mode		= 0644,
2872 		.proc_handler	= hugetlb_sysctl_handler,
2873 	},
2874 #ifdef CONFIG_NUMA
2875 	{
2876 		.procname       = "nr_hugepages_mempolicy",
2877 		.data           = NULL,
2878 		.maxlen         = sizeof(unsigned long),
2879 		.mode           = 0644,
2880 		.proc_handler   = &hugetlb_mempolicy_sysctl_handler,
2881 	},
2882 	{
2883 		.procname		= "numa_stat",
2884 		.data			= &sysctl_vm_numa_stat,
2885 		.maxlen			= sizeof(int),
2886 		.mode			= 0644,
2887 		.proc_handler	= sysctl_vm_numa_stat_handler,
2888 		.extra1			= SYSCTL_ZERO,
2889 		.extra2			= SYSCTL_ONE,
2890 	},
2891 #endif
2892 	 {
2893 		.procname	= "hugetlb_shm_group",
2894 		.data		= &sysctl_hugetlb_shm_group,
2895 		.maxlen		= sizeof(gid_t),
2896 		.mode		= 0644,
2897 		.proc_handler	= proc_dointvec,
2898 	 },
2899 	{
2900 		.procname	= "nr_overcommit_hugepages",
2901 		.data		= NULL,
2902 		.maxlen		= sizeof(unsigned long),
2903 		.mode		= 0644,
2904 		.proc_handler	= hugetlb_overcommit_handler,
2905 	},
2906 #endif
2907 	{
2908 		.procname	= "lowmem_reserve_ratio",
2909 		.data		= &sysctl_lowmem_reserve_ratio,
2910 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
2911 		.mode		= 0644,
2912 		.proc_handler	= lowmem_reserve_ratio_sysctl_handler,
2913 	},
2914 	{
2915 		.procname	= "drop_caches",
2916 		.data		= &sysctl_drop_caches,
2917 		.maxlen		= sizeof(int),
2918 		.mode		= 0200,
2919 		.proc_handler	= drop_caches_sysctl_handler,
2920 		.extra1		= SYSCTL_ONE,
2921 		.extra2		= &four,
2922 	},
2923 #ifdef CONFIG_COMPACTION
2924 	{
2925 		.procname	= "compact_memory",
2926 		.data		= &sysctl_compact_memory,
2927 		.maxlen		= sizeof(int),
2928 		.mode		= 0200,
2929 		.proc_handler	= sysctl_compaction_handler,
2930 	},
2931 	{
2932 		.procname	= "compaction_proactiveness",
2933 		.data		= &sysctl_compaction_proactiveness,
2934 		.maxlen		= sizeof(sysctl_compaction_proactiveness),
2935 		.mode		= 0644,
2936 		.proc_handler	= proc_dointvec_minmax,
2937 		.extra1		= SYSCTL_ZERO,
2938 		.extra2		= &one_hundred,
2939 	},
2940 	{
2941 		.procname	= "extfrag_threshold",
2942 		.data		= &sysctl_extfrag_threshold,
2943 		.maxlen		= sizeof(int),
2944 		.mode		= 0644,
2945 		.proc_handler	= proc_dointvec_minmax,
2946 		.extra1		= &min_extfrag_threshold,
2947 		.extra2		= &max_extfrag_threshold,
2948 	},
2949 	{
2950 		.procname	= "compact_unevictable_allowed",
2951 		.data		= &sysctl_compact_unevictable_allowed,
2952 		.maxlen		= sizeof(int),
2953 		.mode		= 0644,
2954 		.proc_handler	= proc_dointvec_minmax_warn_RT_change,
2955 		.extra1		= SYSCTL_ZERO,
2956 		.extra2		= SYSCTL_ONE,
2957 	},
2958 
2959 #endif /* CONFIG_COMPACTION */
2960 	{
2961 		.procname	= "min_free_kbytes",
2962 		.data		= &min_free_kbytes,
2963 		.maxlen		= sizeof(min_free_kbytes),
2964 		.mode		= 0644,
2965 		.proc_handler	= min_free_kbytes_sysctl_handler,
2966 		.extra1		= SYSCTL_ZERO,
2967 	},
2968 	{
2969 		.procname	= "watermark_boost_factor",
2970 		.data		= &watermark_boost_factor,
2971 		.maxlen		= sizeof(watermark_boost_factor),
2972 		.mode		= 0644,
2973 		.proc_handler	= proc_dointvec_minmax,
2974 		.extra1		= SYSCTL_ZERO,
2975 	},
2976 	{
2977 		.procname	= "watermark_scale_factor",
2978 		.data		= &watermark_scale_factor,
2979 		.maxlen		= sizeof(watermark_scale_factor),
2980 		.mode		= 0644,
2981 		.proc_handler	= watermark_scale_factor_sysctl_handler,
2982 		.extra1		= SYSCTL_ONE,
2983 		.extra2		= &one_thousand,
2984 	},
2985 	{
2986 		.procname	= "percpu_pagelist_fraction",
2987 		.data		= &percpu_pagelist_fraction,
2988 		.maxlen		= sizeof(percpu_pagelist_fraction),
2989 		.mode		= 0644,
2990 		.proc_handler	= percpu_pagelist_fraction_sysctl_handler,
2991 		.extra1		= SYSCTL_ZERO,
2992 	},
2993 	{
2994 		.procname	= "page_lock_unfairness",
2995 		.data		= &sysctl_page_lock_unfairness,
2996 		.maxlen		= sizeof(sysctl_page_lock_unfairness),
2997 		.mode		= 0644,
2998 		.proc_handler	= proc_dointvec_minmax,
2999 		.extra1		= SYSCTL_ZERO,
3000 	},
3001 #ifdef CONFIG_MMU
3002 	{
3003 		.procname	= "max_map_count",
3004 		.data		= &sysctl_max_map_count,
3005 		.maxlen		= sizeof(sysctl_max_map_count),
3006 		.mode		= 0644,
3007 		.proc_handler	= proc_dointvec_minmax,
3008 		.extra1		= SYSCTL_ZERO,
3009 	},
3010 #else
3011 	{
3012 		.procname	= "nr_trim_pages",
3013 		.data		= &sysctl_nr_trim_pages,
3014 		.maxlen		= sizeof(sysctl_nr_trim_pages),
3015 		.mode		= 0644,
3016 		.proc_handler	= proc_dointvec_minmax,
3017 		.extra1		= SYSCTL_ZERO,
3018 	},
3019 #endif
3020 	{
3021 		.procname	= "laptop_mode",
3022 		.data		= &laptop_mode,
3023 		.maxlen		= sizeof(laptop_mode),
3024 		.mode		= 0644,
3025 		.proc_handler	= proc_dointvec_jiffies,
3026 	},
3027 	{
3028 		.procname	= "vfs_cache_pressure",
3029 		.data		= &sysctl_vfs_cache_pressure,
3030 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
3031 		.mode		= 0644,
3032 		.proc_handler	= proc_dointvec_minmax,
3033 		.extra1		= SYSCTL_ZERO,
3034 	},
3035 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
3036     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
3037 	{
3038 		.procname	= "legacy_va_layout",
3039 		.data		= &sysctl_legacy_va_layout,
3040 		.maxlen		= sizeof(sysctl_legacy_va_layout),
3041 		.mode		= 0644,
3042 		.proc_handler	= proc_dointvec_minmax,
3043 		.extra1		= SYSCTL_ZERO,
3044 	},
3045 #endif
3046 #ifdef CONFIG_NUMA
3047 	{
3048 		.procname	= "zone_reclaim_mode",
3049 		.data		= &node_reclaim_mode,
3050 		.maxlen		= sizeof(node_reclaim_mode),
3051 		.mode		= 0644,
3052 		.proc_handler	= proc_dointvec_minmax,
3053 		.extra1		= SYSCTL_ZERO,
3054 	},
3055 	{
3056 		.procname	= "min_unmapped_ratio",
3057 		.data		= &sysctl_min_unmapped_ratio,
3058 		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
3059 		.mode		= 0644,
3060 		.proc_handler	= sysctl_min_unmapped_ratio_sysctl_handler,
3061 		.extra1		= SYSCTL_ZERO,
3062 		.extra2		= &one_hundred,
3063 	},
3064 	{
3065 		.procname	= "min_slab_ratio",
3066 		.data		= &sysctl_min_slab_ratio,
3067 		.maxlen		= sizeof(sysctl_min_slab_ratio),
3068 		.mode		= 0644,
3069 		.proc_handler	= sysctl_min_slab_ratio_sysctl_handler,
3070 		.extra1		= SYSCTL_ZERO,
3071 		.extra2		= &one_hundred,
3072 	},
3073 #endif
3074 #ifdef CONFIG_SMP
3075 	{
3076 		.procname	= "stat_interval",
3077 		.data		= &sysctl_stat_interval,
3078 		.maxlen		= sizeof(sysctl_stat_interval),
3079 		.mode		= 0644,
3080 		.proc_handler	= proc_dointvec_jiffies,
3081 	},
3082 	{
3083 		.procname	= "stat_refresh",
3084 		.data		= NULL,
3085 		.maxlen		= 0,
3086 		.mode		= 0600,
3087 		.proc_handler	= vmstat_refresh,
3088 	},
3089 #endif
3090 #ifdef CONFIG_MMU
3091 	{
3092 		.procname	= "mmap_min_addr",
3093 		.data		= &dac_mmap_min_addr,
3094 		.maxlen		= sizeof(unsigned long),
3095 		.mode		= 0644,
3096 		.proc_handler	= mmap_min_addr_handler,
3097 	},
3098 #endif
3099 #ifdef CONFIG_NUMA
3100 	{
3101 		.procname	= "numa_zonelist_order",
3102 		.data		= &numa_zonelist_order,
3103 		.maxlen		= NUMA_ZONELIST_ORDER_LEN,
3104 		.mode		= 0644,
3105 		.proc_handler	= numa_zonelist_order_handler,
3106 	},
3107 #endif
3108 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
3109    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
3110 	{
3111 		.procname	= "vdso_enabled",
3112 #ifdef CONFIG_X86_32
3113 		.data		= &vdso32_enabled,
3114 		.maxlen		= sizeof(vdso32_enabled),
3115 #else
3116 		.data		= &vdso_enabled,
3117 		.maxlen		= sizeof(vdso_enabled),
3118 #endif
3119 		.mode		= 0644,
3120 		.proc_handler	= proc_dointvec,
3121 		.extra1		= SYSCTL_ZERO,
3122 	},
3123 #endif
3124 #ifdef CONFIG_HIGHMEM
3125 	{
3126 		.procname	= "highmem_is_dirtyable",
3127 		.data		= &vm_highmem_is_dirtyable,
3128 		.maxlen		= sizeof(vm_highmem_is_dirtyable),
3129 		.mode		= 0644,
3130 		.proc_handler	= proc_dointvec_minmax,
3131 		.extra1		= SYSCTL_ZERO,
3132 		.extra2		= SYSCTL_ONE,
3133 	},
3134 #endif
3135 #ifdef CONFIG_MEMORY_FAILURE
3136 	{
3137 		.procname	= "memory_failure_early_kill",
3138 		.data		= &sysctl_memory_failure_early_kill,
3139 		.maxlen		= sizeof(sysctl_memory_failure_early_kill),
3140 		.mode		= 0644,
3141 		.proc_handler	= proc_dointvec_minmax,
3142 		.extra1		= SYSCTL_ZERO,
3143 		.extra2		= SYSCTL_ONE,
3144 	},
3145 	{
3146 		.procname	= "memory_failure_recovery",
3147 		.data		= &sysctl_memory_failure_recovery,
3148 		.maxlen		= sizeof(sysctl_memory_failure_recovery),
3149 		.mode		= 0644,
3150 		.proc_handler	= proc_dointvec_minmax,
3151 		.extra1		= SYSCTL_ZERO,
3152 		.extra2		= SYSCTL_ONE,
3153 	},
3154 #endif
3155 	{
3156 		.procname	= "user_reserve_kbytes",
3157 		.data		= &sysctl_user_reserve_kbytes,
3158 		.maxlen		= sizeof(sysctl_user_reserve_kbytes),
3159 		.mode		= 0644,
3160 		.proc_handler	= proc_doulongvec_minmax,
3161 	},
3162 	{
3163 		.procname	= "admin_reserve_kbytes",
3164 		.data		= &sysctl_admin_reserve_kbytes,
3165 		.maxlen		= sizeof(sysctl_admin_reserve_kbytes),
3166 		.mode		= 0644,
3167 		.proc_handler	= proc_doulongvec_minmax,
3168 	},
3169 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
3170 	{
3171 		.procname	= "mmap_rnd_bits",
3172 		.data		= &mmap_rnd_bits,
3173 		.maxlen		= sizeof(mmap_rnd_bits),
3174 		.mode		= 0600,
3175 		.proc_handler	= proc_dointvec_minmax,
3176 		.extra1		= (void *)&mmap_rnd_bits_min,
3177 		.extra2		= (void *)&mmap_rnd_bits_max,
3178 	},
3179 #endif
3180 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
3181 	{
3182 		.procname	= "mmap_rnd_compat_bits",
3183 		.data		= &mmap_rnd_compat_bits,
3184 		.maxlen		= sizeof(mmap_rnd_compat_bits),
3185 		.mode		= 0600,
3186 		.proc_handler	= proc_dointvec_minmax,
3187 		.extra1		= (void *)&mmap_rnd_compat_bits_min,
3188 		.extra2		= (void *)&mmap_rnd_compat_bits_max,
3189 	},
3190 #endif
3191 #ifdef CONFIG_USERFAULTFD
3192 	{
3193 		.procname	= "unprivileged_userfaultfd",
3194 		.data		= &sysctl_unprivileged_userfaultfd,
3195 		.maxlen		= sizeof(sysctl_unprivileged_userfaultfd),
3196 		.mode		= 0644,
3197 		.proc_handler	= proc_dointvec_minmax,
3198 		.extra1		= SYSCTL_ZERO,
3199 		.extra2		= SYSCTL_ONE,
3200 	},
3201 #endif
3202 	{ }
3203 };
3204 
3205 static struct ctl_table fs_table[] = {
3206 	{
3207 		.procname	= "inode-nr",
3208 		.data		= &inodes_stat,
3209 		.maxlen		= 2*sizeof(long),
3210 		.mode		= 0444,
3211 		.proc_handler	= proc_nr_inodes,
3212 	},
3213 	{
3214 		.procname	= "inode-state",
3215 		.data		= &inodes_stat,
3216 		.maxlen		= 7*sizeof(long),
3217 		.mode		= 0444,
3218 		.proc_handler	= proc_nr_inodes,
3219 	},
3220 	{
3221 		.procname	= "file-nr",
3222 		.data		= &files_stat,
3223 		.maxlen		= sizeof(files_stat),
3224 		.mode		= 0444,
3225 		.proc_handler	= proc_nr_files,
3226 	},
3227 	{
3228 		.procname	= "file-max",
3229 		.data		= &files_stat.max_files,
3230 		.maxlen		= sizeof(files_stat.max_files),
3231 		.mode		= 0644,
3232 		.proc_handler	= proc_doulongvec_minmax,
3233 		.extra1		= &zero_ul,
3234 		.extra2		= &long_max,
3235 	},
3236 	{
3237 		.procname	= "nr_open",
3238 		.data		= &sysctl_nr_open,
3239 		.maxlen		= sizeof(unsigned int),
3240 		.mode		= 0644,
3241 		.proc_handler	= proc_dointvec_minmax,
3242 		.extra1		= &sysctl_nr_open_min,
3243 		.extra2		= &sysctl_nr_open_max,
3244 	},
3245 	{
3246 		.procname	= "dentry-state",
3247 		.data		= &dentry_stat,
3248 		.maxlen		= 6*sizeof(long),
3249 		.mode		= 0444,
3250 		.proc_handler	= proc_nr_dentry,
3251 	},
3252 	{
3253 		.procname	= "overflowuid",
3254 		.data		= &fs_overflowuid,
3255 		.maxlen		= sizeof(int),
3256 		.mode		= 0644,
3257 		.proc_handler	= proc_dointvec_minmax,
3258 		.extra1		= &minolduid,
3259 		.extra2		= &maxolduid,
3260 	},
3261 	{
3262 		.procname	= "overflowgid",
3263 		.data		= &fs_overflowgid,
3264 		.maxlen		= sizeof(int),
3265 		.mode		= 0644,
3266 		.proc_handler	= proc_dointvec_minmax,
3267 		.extra1		= &minolduid,
3268 		.extra2		= &maxolduid,
3269 	},
3270 #ifdef CONFIG_FILE_LOCKING
3271 	{
3272 		.procname	= "leases-enable",
3273 		.data		= &leases_enable,
3274 		.maxlen		= sizeof(int),
3275 		.mode		= 0644,
3276 		.proc_handler	= proc_dointvec,
3277 	},
3278 #endif
3279 #ifdef CONFIG_DNOTIFY
3280 	{
3281 		.procname	= "dir-notify-enable",
3282 		.data		= &dir_notify_enable,
3283 		.maxlen		= sizeof(int),
3284 		.mode		= 0644,
3285 		.proc_handler	= proc_dointvec,
3286 	},
3287 #endif
3288 #ifdef CONFIG_MMU
3289 #ifdef CONFIG_FILE_LOCKING
3290 	{
3291 		.procname	= "lease-break-time",
3292 		.data		= &lease_break_time,
3293 		.maxlen		= sizeof(int),
3294 		.mode		= 0644,
3295 		.proc_handler	= proc_dointvec,
3296 	},
3297 #endif
3298 #ifdef CONFIG_AIO
3299 	{
3300 		.procname	= "aio-nr",
3301 		.data		= &aio_nr,
3302 		.maxlen		= sizeof(aio_nr),
3303 		.mode		= 0444,
3304 		.proc_handler	= proc_doulongvec_minmax,
3305 	},
3306 	{
3307 		.procname	= "aio-max-nr",
3308 		.data		= &aio_max_nr,
3309 		.maxlen		= sizeof(aio_max_nr),
3310 		.mode		= 0644,
3311 		.proc_handler	= proc_doulongvec_minmax,
3312 	},
3313 #endif /* CONFIG_AIO */
3314 #ifdef CONFIG_INOTIFY_USER
3315 	{
3316 		.procname	= "inotify",
3317 		.mode		= 0555,
3318 		.child		= inotify_table,
3319 	},
3320 #endif
3321 #ifdef CONFIG_EPOLL
3322 	{
3323 		.procname	= "epoll",
3324 		.mode		= 0555,
3325 		.child		= epoll_table,
3326 	},
3327 #endif
3328 #endif
3329 	{
3330 		.procname	= "protected_symlinks",
3331 		.data		= &sysctl_protected_symlinks,
3332 		.maxlen		= sizeof(int),
3333 		.mode		= 0600,
3334 		.proc_handler	= proc_dointvec_minmax,
3335 		.extra1		= SYSCTL_ZERO,
3336 		.extra2		= SYSCTL_ONE,
3337 	},
3338 	{
3339 		.procname	= "protected_hardlinks",
3340 		.data		= &sysctl_protected_hardlinks,
3341 		.maxlen		= sizeof(int),
3342 		.mode		= 0600,
3343 		.proc_handler	= proc_dointvec_minmax,
3344 		.extra1		= SYSCTL_ZERO,
3345 		.extra2		= SYSCTL_ONE,
3346 	},
3347 	{
3348 		.procname	= "protected_fifos",
3349 		.data		= &sysctl_protected_fifos,
3350 		.maxlen		= sizeof(int),
3351 		.mode		= 0600,
3352 		.proc_handler	= proc_dointvec_minmax,
3353 		.extra1		= SYSCTL_ZERO,
3354 		.extra2		= &two,
3355 	},
3356 	{
3357 		.procname	= "protected_regular",
3358 		.data		= &sysctl_protected_regular,
3359 		.maxlen		= sizeof(int),
3360 		.mode		= 0600,
3361 		.proc_handler	= proc_dointvec_minmax,
3362 		.extra1		= SYSCTL_ZERO,
3363 		.extra2		= &two,
3364 	},
3365 	{
3366 		.procname	= "suid_dumpable",
3367 		.data		= &suid_dumpable,
3368 		.maxlen		= sizeof(int),
3369 		.mode		= 0644,
3370 		.proc_handler	= proc_dointvec_minmax_coredump,
3371 		.extra1		= SYSCTL_ZERO,
3372 		.extra2		= &two,
3373 	},
3374 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
3375 	{
3376 		.procname	= "binfmt_misc",
3377 		.mode		= 0555,
3378 		.child		= sysctl_mount_point,
3379 	},
3380 #endif
3381 	{
3382 		.procname	= "pipe-max-size",
3383 		.data		= &pipe_max_size,
3384 		.maxlen		= sizeof(pipe_max_size),
3385 		.mode		= 0644,
3386 		.proc_handler	= proc_dopipe_max_size,
3387 	},
3388 	{
3389 		.procname	= "pipe-user-pages-hard",
3390 		.data		= &pipe_user_pages_hard,
3391 		.maxlen		= sizeof(pipe_user_pages_hard),
3392 		.mode		= 0644,
3393 		.proc_handler	= proc_doulongvec_minmax,
3394 	},
3395 	{
3396 		.procname	= "pipe-user-pages-soft",
3397 		.data		= &pipe_user_pages_soft,
3398 		.maxlen		= sizeof(pipe_user_pages_soft),
3399 		.mode		= 0644,
3400 		.proc_handler	= proc_doulongvec_minmax,
3401 	},
3402 	{
3403 		.procname	= "mount-max",
3404 		.data		= &sysctl_mount_max,
3405 		.maxlen		= sizeof(unsigned int),
3406 		.mode		= 0644,
3407 		.proc_handler	= proc_dointvec_minmax,
3408 		.extra1		= SYSCTL_ONE,
3409 	},
3410 	{ }
3411 };
3412 
3413 static struct ctl_table debug_table[] = {
3414 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
3415 	{
3416 		.procname	= "exception-trace",
3417 		.data		= &show_unhandled_signals,
3418 		.maxlen		= sizeof(int),
3419 		.mode		= 0644,
3420 		.proc_handler	= proc_dointvec
3421 	},
3422 #endif
3423 #if defined(CONFIG_OPTPROBES)
3424 	{
3425 		.procname	= "kprobes-optimization",
3426 		.data		= &sysctl_kprobes_optimization,
3427 		.maxlen		= sizeof(int),
3428 		.mode		= 0644,
3429 		.proc_handler	= proc_kprobes_optimization_handler,
3430 		.extra1		= SYSCTL_ZERO,
3431 		.extra2		= SYSCTL_ONE,
3432 	},
3433 #endif
3434 	{ }
3435 };
3436 
3437 static struct ctl_table dev_table[] = {
3438 	{ }
3439 };
3440 
3441 static struct ctl_table sysctl_base_table[] = {
3442 	{
3443 		.procname	= "kernel",
3444 		.mode		= 0555,
3445 		.child		= kern_table,
3446 	},
3447 	{
3448 		.procname	= "vm",
3449 		.mode		= 0555,
3450 		.child		= vm_table,
3451 	},
3452 	{
3453 		.procname	= "fs",
3454 		.mode		= 0555,
3455 		.child		= fs_table,
3456 	},
3457 	{
3458 		.procname	= "debug",
3459 		.mode		= 0555,
3460 		.child		= debug_table,
3461 	},
3462 	{
3463 		.procname	= "dev",
3464 		.mode		= 0555,
3465 		.child		= dev_table,
3466 	},
3467 	{ }
3468 };
3469 
sysctl_init(void)3470 int __init sysctl_init(void)
3471 {
3472 	struct ctl_table_header *hdr;
3473 
3474 	hdr = register_sysctl_table(sysctl_base_table);
3475 	kmemleak_not_leak(hdr);
3476 	return 0;
3477 }
3478 #endif /* CONFIG_SYSCTL */
3479 /*
3480  * No sense putting this after each symbol definition, twice,
3481  * exception granted :-)
3482  */
3483 EXPORT_SYMBOL(proc_dointvec);
3484 EXPORT_SYMBOL(proc_douintvec);
3485 EXPORT_SYMBOL(proc_dointvec_jiffies);
3486 EXPORT_SYMBOL(proc_dointvec_minmax);
3487 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3488 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3489 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3490 EXPORT_SYMBOL(proc_dostring);
3491 EXPORT_SYMBOL(proc_doulongvec_minmax);
3492 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3493 EXPORT_SYMBOL(proc_do_large_bitmap);
3494