1 // SPDX-License-Identifier: GPL-2.0-only
3 * sysctl.c: General linux system control interface
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
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
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
22 #include <linux/module.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/bitmap.h>
28 #include <linux/signal.h>
29 #include <linux/panic.h>
30 #include <linux/printk.h>
31 #include <linux/proc_fs.h>
32 #include <linux/security.h>
33 #include <linux/ctype.h>
34 #include <linux/kmemleak.h>
35 #include <linux/filter.h>
37 #include <linux/init.h>
38 #include <linux/kernel.h>
39 #include <linux/kobject.h>
40 #include <linux/net.h>
41 #include <linux/sysrq.h>
42 #include <linux/highuid.h>
43 #include <linux/writeback.h>
44 #include <linux/ratelimit.h>
45 #include <linux/compaction.h>
46 #include <linux/hugetlb.h>
47 #include <linux/initrd.h>
48 #include <linux/key.h>
49 #include <linux/times.h>
50 #include <linux/limits.h>
51 #include <linux/dcache.h>
52 #include <linux/syscalls.h>
53 #include <linux/vmstat.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/acpi.h>
56 #include <linux/reboot.h>
57 #include <linux/ftrace.h>
58 #include <linux/perf_event.h>
59 #include <linux/oom.h>
60 #include <linux/kmod.h>
61 #include <linux/capability.h>
62 #include <linux/binfmts.h>
63 #include <linux/sched/sysctl.h>
64 #include <linux/kexec.h>
65 #include <linux/mount.h>
66 #include <linux/userfaultfd_k.h>
67 #include <linux/latencytop.h>
68 #include <linux/pid.h>
69 #include <linux/delayacct.h>
71 #include "../lib/kstrtox.h"
73 #include <linux/uaccess.h>
74 #include <asm/processor.h>
78 #include <asm/stacktrace.h>
82 #include <asm/setup.h>
84 #ifdef CONFIG_BSD_PROCESS_ACCT
85 #include <linux/acct.h>
87 #ifdef CONFIG_RT_MUTEXES
88 #include <linux/rtmutex.h>
90 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
91 #include <linux/lockdep.h>
94 #if defined(CONFIG_SYSCTL)
96 /* Constants used for minimum and maximum */
98 #ifdef CONFIG_PERF_EVENTS
99 static const int six_hundred_forty_kb = 640 * 1024;
102 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
103 static const unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
105 static const int ngroups_max = NGROUPS_MAX;
106 static const int cap_last_cap = CAP_LAST_CAP;
108 #ifdef CONFIG_PROC_SYSCTL
111 * enum sysctl_writes_mode - supported sysctl write modes
113 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
114 * to be written, and multiple writes on the same sysctl file descriptor
115 * will rewrite the sysctl value, regardless of file position. No warning
116 * is issued when the initial position is not 0.
117 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
119 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
120 * file position 0 and the value must be fully contained in the buffer
121 * sent to the write syscall. If dealing with strings respect the file
122 * position, but restrict this to the max length of the buffer, anything
123 * passed the max length will be ignored. Multiple writes will append
126 * These write modes control how current file position affects the behavior of
127 * updating sysctl values through the proc interface on each write.
129 enum sysctl_writes_mode {
130 SYSCTL_WRITES_LEGACY = -1,
131 SYSCTL_WRITES_WARN = 0,
132 SYSCTL_WRITES_STRICT = 1,
135 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
136 #endif /* CONFIG_PROC_SYSCTL */
138 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
139 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
140 int sysctl_legacy_va_layout;
143 #ifdef CONFIG_COMPACTION
144 /* min_extfrag_threshold is SYSCTL_ZERO */;
145 static const int max_extfrag_threshold = 1000;
148 #endif /* CONFIG_SYSCTL */
154 #ifdef CONFIG_PROC_SYSCTL
156 static int _proc_do_string(char *data, int maxlen, int write,
157 char *buffer, size_t *lenp, loff_t *ppos)
162 if (!data || !maxlen || !*lenp) {
168 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
169 /* Only continue writes not past the end of buffer. */
171 if (len > maxlen - 1)
178 /* Start writing from beginning of buffer. */
184 while ((p - buffer) < *lenp && len < maxlen - 1) {
186 if (c == 0 || c == '\n')
207 memcpy(buffer, data, len);
218 static void warn_sysctl_write(struct ctl_table *table)
220 pr_warn_once("%s wrote to %s when file position was not 0!\n"
221 "This will not be supported in the future. To silence this\n"
222 "warning, set kernel.sysctl_writes_strict = -1\n",
223 current->comm, table->procname);
227 * proc_first_pos_non_zero_ignore - check if first position is allowed
228 * @ppos: file position
229 * @table: the sysctl table
231 * Returns true if the first position is non-zero and the sysctl_writes_strict
232 * mode indicates this is not allowed for numeric input types. String proc
233 * handlers can ignore the return value.
235 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
236 struct ctl_table *table)
241 switch (sysctl_writes_strict) {
242 case SYSCTL_WRITES_STRICT:
244 case SYSCTL_WRITES_WARN:
245 warn_sysctl_write(table);
253 * proc_dostring - read a string sysctl
254 * @table: the sysctl table
255 * @write: %TRUE if this is a write to the sysctl file
256 * @buffer: the user buffer
257 * @lenp: the size of the user buffer
258 * @ppos: file position
260 * Reads/writes a string from/to the user buffer. If the kernel
261 * buffer provided is not large enough to hold the string, the
262 * string is truncated. The copied string is %NULL-terminated.
263 * If the string is being read by the user process, it is copied
264 * and a newline '\n' is added. It is truncated if the buffer is
267 * Returns 0 on success.
269 int proc_dostring(struct ctl_table *table, int write,
270 void *buffer, size_t *lenp, loff_t *ppos)
273 proc_first_pos_non_zero_ignore(ppos, table);
275 return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
279 static size_t proc_skip_spaces(char **buf)
282 char *tmp = skip_spaces(*buf);
288 static void proc_skip_char(char **buf, size_t *size, const char v)
299 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
302 * @cp: kernel buffer containing the string to parse
303 * @endp: pointer to store the trailing characters
304 * @base: the base to use
305 * @res: where the parsed integer will be stored
307 * In case of success 0 is returned and @res will contain the parsed integer,
308 * @endp will hold any trailing characters.
309 * This function will fail the parse on overflow. If there wasn't an overflow
310 * the function will defer the decision what characters count as invalid to the
313 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
316 unsigned long long result;
319 cp = _parse_integer_fixup_radix(cp, &base);
320 rv = _parse_integer(cp, base, &result);
321 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
329 *res = (unsigned long)result;
335 * proc_get_long - reads an ASCII formatted integer from a user buffer
337 * @buf: a kernel buffer
338 * @size: size of the kernel buffer
339 * @val: this is where the number will be stored
340 * @neg: set to %TRUE if number is negative
341 * @perm_tr: a vector which contains the allowed trailers
342 * @perm_tr_len: size of the perm_tr vector
343 * @tr: pointer to store the trailer character
345 * In case of success %0 is returned and @buf and @size are updated with
346 * the amount of bytes read. If @tr is non-NULL and a trailing
347 * character exists (size is non-zero after returning from this
348 * function), @tr is updated with the trailing character.
350 static int proc_get_long(char **buf, size_t *size,
351 unsigned long *val, bool *neg,
352 const char *perm_tr, unsigned perm_tr_len, char *tr)
355 char *p, tmp[TMPBUFLEN];
361 if (len > TMPBUFLEN - 1)
364 memcpy(tmp, *buf, len);
368 if (*p == '-' && *size > 1) {
376 if (strtoul_lenient(p, &p, 0, val))
381 /* We don't know if the next char is whitespace thus we may accept
382 * invalid integers (e.g. 1234...a) or two integers instead of one
383 * (e.g. 123...1). So lets not allow such large numbers. */
384 if (len == TMPBUFLEN - 1)
387 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
390 if (tr && (len < *size))
400 * proc_put_long - converts an integer to a decimal ASCII formatted string
402 * @buf: the user buffer
403 * @size: the size of the user buffer
404 * @val: the integer to be converted
405 * @neg: sign of the number, %TRUE for negative
407 * In case of success @buf and @size are updated with the amount of bytes
410 static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
413 char tmp[TMPBUFLEN], *p = tmp;
415 sprintf(p, "%s%lu", neg ? "-" : "", val);
419 memcpy(*buf, tmp, len);
425 static void proc_put_char(void **buf, size_t *size, char c)
428 char **buffer = (char **)buf;
437 static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp,
439 int write, void *data)
442 *(bool *)valp = *lvalp;
444 int val = *(bool *)valp;
446 *lvalp = (unsigned long)val;
452 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
454 int write, void *data)
458 if (*lvalp > (unsigned long) INT_MAX + 1)
462 if (*lvalp > (unsigned long) INT_MAX)
470 *lvalp = -(unsigned long)val;
473 *lvalp = (unsigned long)val;
479 static int do_proc_douintvec_conv(unsigned long *lvalp,
481 int write, void *data)
484 if (*lvalp > UINT_MAX)
488 unsigned int val = *valp;
489 *lvalp = (unsigned long)val;
494 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
496 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
497 int write, void *buffer,
498 size_t *lenp, loff_t *ppos,
499 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
500 int write, void *data),
503 int *i, vleft, first = 1, err = 0;
507 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
512 i = (int *) tbl_data;
513 vleft = table->maxlen / sizeof(*i);
517 conv = do_proc_dointvec_conv;
520 if (proc_first_pos_non_zero_ignore(ppos, table))
523 if (left > PAGE_SIZE - 1)
524 left = PAGE_SIZE - 1;
528 for (; left && vleft--; i++, first=0) {
533 left -= proc_skip_spaces(&p);
537 err = proc_get_long(&p, &left, &lval, &neg,
539 sizeof(proc_wspace_sep), NULL);
542 if (conv(&neg, &lval, i, 1, data)) {
547 if (conv(&neg, &lval, i, 0, data)) {
552 proc_put_char(&buffer, &left, '\t');
553 proc_put_long(&buffer, &left, lval, neg);
557 if (!write && !first && left && !err)
558 proc_put_char(&buffer, &left, '\n');
559 if (write && !err && left)
560 left -= proc_skip_spaces(&p);
562 return err ? : -EINVAL;
569 static int do_proc_dointvec(struct ctl_table *table, int write,
570 void *buffer, size_t *lenp, loff_t *ppos,
571 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
572 int write, void *data),
575 return __do_proc_dointvec(table->data, table, write,
576 buffer, lenp, ppos, conv, data);
579 static int do_proc_douintvec_w(unsigned int *tbl_data,
580 struct ctl_table *table,
582 size_t *lenp, loff_t *ppos,
583 int (*conv)(unsigned long *lvalp,
585 int write, void *data),
596 if (proc_first_pos_non_zero_ignore(ppos, table))
599 if (left > PAGE_SIZE - 1)
600 left = PAGE_SIZE - 1;
602 left -= proc_skip_spaces(&p);
608 err = proc_get_long(&p, &left, &lval, &neg,
610 sizeof(proc_wspace_sep), NULL);
616 if (conv(&lval, tbl_data, 1, data)) {
622 left -= proc_skip_spaces(&p);
630 /* This is in keeping with old __do_proc_dointvec() */
636 static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
637 size_t *lenp, loff_t *ppos,
638 int (*conv)(unsigned long *lvalp,
640 int write, void *data),
649 if (conv(&lval, tbl_data, 0, data)) {
654 proc_put_long(&buffer, &left, lval, false);
658 proc_put_char(&buffer, &left, '\n');
667 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
668 int write, void *buffer,
669 size_t *lenp, loff_t *ppos,
670 int (*conv)(unsigned long *lvalp,
672 int write, void *data),
675 unsigned int *i, vleft;
677 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
682 i = (unsigned int *) tbl_data;
683 vleft = table->maxlen / sizeof(*i);
686 * Arrays are not supported, keep this simple. *Do not* add
695 conv = do_proc_douintvec_conv;
698 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
700 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
703 int do_proc_douintvec(struct ctl_table *table, int write,
704 void *buffer, size_t *lenp, loff_t *ppos,
705 int (*conv)(unsigned long *lvalp,
707 int write, void *data),
710 return __do_proc_douintvec(table->data, table, write,
711 buffer, lenp, ppos, conv, data);
715 * proc_dobool - read/write a bool
716 * @table: the sysctl table
717 * @write: %TRUE if this is a write to the sysctl file
718 * @buffer: the user buffer
719 * @lenp: the size of the user buffer
720 * @ppos: file position
722 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
723 * values from/to the user buffer, treated as an ASCII string.
725 * Returns 0 on success.
727 int proc_dobool(struct ctl_table *table, int write, void *buffer,
728 size_t *lenp, loff_t *ppos)
730 return do_proc_dointvec(table, write, buffer, lenp, ppos,
731 do_proc_dobool_conv, NULL);
735 * proc_dointvec - read a vector of integers
736 * @table: the sysctl table
737 * @write: %TRUE if this is a write to the sysctl file
738 * @buffer: the user buffer
739 * @lenp: the size of the user buffer
740 * @ppos: file position
742 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
743 * values from/to the user buffer, treated as an ASCII string.
745 * Returns 0 on success.
747 int proc_dointvec(struct ctl_table *table, int write, void *buffer,
748 size_t *lenp, loff_t *ppos)
750 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
753 #ifdef CONFIG_COMPACTION
754 static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
755 int write, void *buffer, size_t *lenp, loff_t *ppos)
759 if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
760 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
762 old = *(int *)table->data;
763 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
766 if (old != *(int *)table->data)
767 pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
768 table->procname, current->comm,
769 task_pid_nr(current));
775 * proc_douintvec - read a vector of unsigned integers
776 * @table: the sysctl table
777 * @write: %TRUE if this is a write to the sysctl file
778 * @buffer: the user buffer
779 * @lenp: the size of the user buffer
780 * @ppos: file position
782 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
783 * values from/to the user buffer, treated as an ASCII string.
785 * Returns 0 on success.
787 int proc_douintvec(struct ctl_table *table, int write, void *buffer,
788 size_t *lenp, loff_t *ppos)
790 return do_proc_douintvec(table, write, buffer, lenp, ppos,
791 do_proc_douintvec_conv, NULL);
795 * Taint values can only be increased
796 * This means we can safely use a temporary.
798 static int proc_taint(struct ctl_table *table, int write,
799 void *buffer, size_t *lenp, loff_t *ppos)
802 unsigned long tmptaint = get_taint();
805 if (write && !capable(CAP_SYS_ADMIN))
810 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
818 * If we are relying on panic_on_taint not producing
819 * false positives due to userspace input, bail out
820 * before setting the requested taint flags.
822 if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
826 * Poor man's atomic or. Not worth adding a primitive
827 * to everyone's atomic.h for this
829 for (i = 0; i < TAINT_FLAGS_COUNT; i++)
830 if ((1UL << i) & tmptaint)
831 add_taint(i, LOCKDEP_STILL_OK);
838 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
839 * @min: pointer to minimum allowable value
840 * @max: pointer to maximum allowable value
842 * The do_proc_dointvec_minmax_conv_param structure provides the
843 * minimum and maximum values for doing range checking for those sysctl
844 * parameters that use the proc_dointvec_minmax() handler.
846 struct do_proc_dointvec_minmax_conv_param {
851 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
853 int write, void *data)
856 struct do_proc_dointvec_minmax_conv_param *param = data;
858 * If writing, first do so via a temporary local int so we can
859 * bounds-check it before touching *valp.
861 int *ip = write ? &tmp : valp;
863 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
868 if ((param->min && *param->min > tmp) ||
869 (param->max && *param->max < tmp))
878 * proc_dointvec_minmax - read a vector of integers with min/max values
879 * @table: the sysctl table
880 * @write: %TRUE if this is a write to the sysctl file
881 * @buffer: the user buffer
882 * @lenp: the size of the user buffer
883 * @ppos: file position
885 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
886 * values from/to the user buffer, treated as an ASCII string.
888 * This routine will ensure the values are within the range specified by
889 * table->extra1 (min) and table->extra2 (max).
891 * Returns 0 on success or -EINVAL on write when the range check fails.
893 int proc_dointvec_minmax(struct ctl_table *table, int write,
894 void *buffer, size_t *lenp, loff_t *ppos)
896 struct do_proc_dointvec_minmax_conv_param param = {
897 .min = (int *) table->extra1,
898 .max = (int *) table->extra2,
900 return do_proc_dointvec(table, write, buffer, lenp, ppos,
901 do_proc_dointvec_minmax_conv, ¶m);
905 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
906 * @min: pointer to minimum allowable value
907 * @max: pointer to maximum allowable value
909 * The do_proc_douintvec_minmax_conv_param structure provides the
910 * minimum and maximum values for doing range checking for those sysctl
911 * parameters that use the proc_douintvec_minmax() handler.
913 struct do_proc_douintvec_minmax_conv_param {
918 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
920 int write, void *data)
924 struct do_proc_douintvec_minmax_conv_param *param = data;
925 /* write via temporary local uint for bounds-checking */
926 unsigned int *up = write ? &tmp : valp;
928 ret = do_proc_douintvec_conv(lvalp, up, write, data);
933 if ((param->min && *param->min > tmp) ||
934 (param->max && *param->max < tmp))
944 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
945 * @table: the sysctl table
946 * @write: %TRUE if this is a write to the sysctl file
947 * @buffer: the user buffer
948 * @lenp: the size of the user buffer
949 * @ppos: file position
951 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
952 * values from/to the user buffer, treated as an ASCII string. Negative
953 * strings are not allowed.
955 * This routine will ensure the values are within the range specified by
956 * table->extra1 (min) and table->extra2 (max). There is a final sanity
957 * check for UINT_MAX to avoid having to support wrap around uses from
960 * Returns 0 on success or -ERANGE on write when the range check fails.
962 int proc_douintvec_minmax(struct ctl_table *table, int write,
963 void *buffer, size_t *lenp, loff_t *ppos)
965 struct do_proc_douintvec_minmax_conv_param param = {
966 .min = (unsigned int *) table->extra1,
967 .max = (unsigned int *) table->extra2,
969 return do_proc_douintvec(table, write, buffer, lenp, ppos,
970 do_proc_douintvec_minmax_conv, ¶m);
974 * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
975 * @table: the sysctl table
976 * @write: %TRUE if this is a write to the sysctl file
977 * @buffer: the user buffer
978 * @lenp: the size of the user buffer
979 * @ppos: file position
981 * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
982 * values from/to the user buffer, treated as an ASCII string. Negative
983 * strings are not allowed.
985 * This routine will ensure the values are within the range specified by
986 * table->extra1 (min) and table->extra2 (max).
988 * Returns 0 on success or an error on write when the range check fails.
990 int proc_dou8vec_minmax(struct ctl_table *table, int write,
991 void *buffer, size_t *lenp, loff_t *ppos)
993 struct ctl_table tmp;
994 unsigned int min = 0, max = 255U, val;
995 u8 *data = table->data;
996 struct do_proc_douintvec_minmax_conv_param param = {
1002 /* Do not support arrays yet. */
1003 if (table->maxlen != sizeof(u8))
1006 if (table->extra1) {
1007 min = *(unsigned int *) table->extra1;
1011 if (table->extra2) {
1012 max = *(unsigned int *) table->extra2;
1019 tmp.maxlen = sizeof(val);
1022 res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
1023 do_proc_douintvec_minmax_conv, ¶m);
1030 EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
1032 #ifdef CONFIG_MAGIC_SYSRQ
1033 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
1034 void *buffer, size_t *lenp, loff_t *ppos)
1040 ret = __do_proc_dointvec(&tmp, table, write, buffer,
1041 lenp, ppos, NULL, NULL);
1046 sysrq_toggle_support(tmp);
1052 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
1053 int write, void *buffer, size_t *lenp, loff_t *ppos,
1054 unsigned long convmul, unsigned long convdiv)
1056 unsigned long *i, *min, *max;
1057 int vleft, first = 1, err = 0;
1061 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1066 i = (unsigned long *) data;
1067 min = (unsigned long *) table->extra1;
1068 max = (unsigned long *) table->extra2;
1069 vleft = table->maxlen / sizeof(unsigned long);
1073 if (proc_first_pos_non_zero_ignore(ppos, table))
1076 if (left > PAGE_SIZE - 1)
1077 left = PAGE_SIZE - 1;
1081 for (; left && vleft--; i++, first = 0) {
1087 left -= proc_skip_spaces(&p);
1091 err = proc_get_long(&p, &left, &val, &neg,
1093 sizeof(proc_wspace_sep), NULL);
1099 val = convmul * val / convdiv;
1100 if ((min && val < *min) || (max && val > *max)) {
1106 val = convdiv * (*i) / convmul;
1108 proc_put_char(&buffer, &left, '\t');
1109 proc_put_long(&buffer, &left, val, false);
1113 if (!write && !first && left && !err)
1114 proc_put_char(&buffer, &left, '\n');
1116 left -= proc_skip_spaces(&p);
1118 return err ? : -EINVAL;
1125 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
1126 void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1127 unsigned long convdiv)
1129 return __do_proc_doulongvec_minmax(table->data, table, write,
1130 buffer, lenp, ppos, convmul, convdiv);
1134 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1135 * @table: the sysctl table
1136 * @write: %TRUE if this is a write to the sysctl file
1137 * @buffer: the user buffer
1138 * @lenp: the size of the user buffer
1139 * @ppos: file position
1141 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1142 * values from/to the user buffer, treated as an ASCII string.
1144 * This routine will ensure the values are within the range specified by
1145 * table->extra1 (min) and table->extra2 (max).
1147 * Returns 0 on success.
1149 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1150 void *buffer, size_t *lenp, loff_t *ppos)
1152 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1156 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1157 * @table: the sysctl table
1158 * @write: %TRUE if this is a write to the sysctl file
1159 * @buffer: the user buffer
1160 * @lenp: the size of the user buffer
1161 * @ppos: file position
1163 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1164 * values from/to the user buffer, treated as an ASCII string. The values
1165 * are treated as milliseconds, and converted to jiffies when they are stored.
1167 * This routine will ensure the values are within the range specified by
1168 * table->extra1 (min) and table->extra2 (max).
1170 * Returns 0 on success.
1172 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1173 void *buffer, size_t *lenp, loff_t *ppos)
1175 return do_proc_doulongvec_minmax(table, write, buffer,
1176 lenp, ppos, HZ, 1000l);
1180 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1182 int write, void *data)
1185 if (*lvalp > INT_MAX / HZ)
1187 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1193 lval = -(unsigned long)val;
1196 lval = (unsigned long)val;
1203 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1205 int write, void *data)
1208 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1210 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1216 lval = -(unsigned long)val;
1219 lval = (unsigned long)val;
1221 *lvalp = jiffies_to_clock_t(lval);
1226 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1228 int write, void *data)
1231 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1241 lval = -(unsigned long)val;
1244 lval = (unsigned long)val;
1246 *lvalp = jiffies_to_msecs(lval);
1252 * proc_dointvec_jiffies - read a vector of integers as seconds
1253 * @table: the sysctl table
1254 * @write: %TRUE if this is a write to the sysctl file
1255 * @buffer: the user buffer
1256 * @lenp: the size of the user buffer
1257 * @ppos: file position
1259 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1260 * values from/to the user buffer, treated as an ASCII string.
1261 * The values read are assumed to be in seconds, and are converted into
1264 * Returns 0 on success.
1266 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1267 void *buffer, size_t *lenp, loff_t *ppos)
1269 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1270 do_proc_dointvec_jiffies_conv,NULL);
1274 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1275 * @table: the sysctl table
1276 * @write: %TRUE if this is a write to the sysctl file
1277 * @buffer: the user buffer
1278 * @lenp: the size of the user buffer
1279 * @ppos: pointer to the file position
1281 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1282 * values from/to the user buffer, treated as an ASCII string.
1283 * The values read are assumed to be in 1/USER_HZ seconds, and
1284 * are converted into jiffies.
1286 * Returns 0 on success.
1288 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1289 void *buffer, size_t *lenp, loff_t *ppos)
1291 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1292 do_proc_dointvec_userhz_jiffies_conv,NULL);
1296 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1297 * @table: the sysctl table
1298 * @write: %TRUE if this is a write to the sysctl file
1299 * @buffer: the user buffer
1300 * @lenp: the size of the user buffer
1301 * @ppos: file position
1302 * @ppos: the current position in the file
1304 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1305 * values from/to the user buffer, treated as an ASCII string.
1306 * The values read are assumed to be in 1/1000 seconds, and
1307 * are converted into jiffies.
1309 * Returns 0 on success.
1311 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
1312 size_t *lenp, loff_t *ppos)
1314 return do_proc_dointvec(table, write, buffer, lenp, ppos,
1315 do_proc_dointvec_ms_jiffies_conv, NULL);
1318 static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
1319 size_t *lenp, loff_t *ppos)
1321 struct pid *new_pid;
1325 tmp = pid_vnr(cad_pid);
1327 r = __do_proc_dointvec(&tmp, table, write, buffer,
1328 lenp, ppos, NULL, NULL);
1332 new_pid = find_get_pid(tmp);
1336 put_pid(xchg(&cad_pid, new_pid));
1341 * proc_do_large_bitmap - read/write from/to a large bitmap
1342 * @table: the sysctl table
1343 * @write: %TRUE if this is a write to the sysctl file
1344 * @buffer: the user buffer
1345 * @lenp: the size of the user buffer
1346 * @ppos: file position
1348 * The bitmap is stored at table->data and the bitmap length (in bits)
1351 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1352 * large bitmaps may be represented in a compact manner. Writing into
1353 * the file will clear the bitmap then update it with the given input.
1355 * Returns 0 on success.
1357 int proc_do_large_bitmap(struct ctl_table *table, int write,
1358 void *buffer, size_t *lenp, loff_t *ppos)
1361 size_t left = *lenp;
1362 unsigned long bitmap_len = table->maxlen;
1363 unsigned long *bitmap = *(unsigned long **) table->data;
1364 unsigned long *tmp_bitmap = NULL;
1365 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1367 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1376 if (left > PAGE_SIZE - 1) {
1377 left = PAGE_SIZE - 1;
1378 /* How much of the buffer we'll skip this pass */
1379 skipped = *lenp - left;
1382 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
1385 proc_skip_char(&p, &left, '\n');
1386 while (!err && left) {
1387 unsigned long val_a, val_b;
1391 /* In case we stop parsing mid-number, we can reset */
1393 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1396 * If we consumed the entirety of a truncated buffer or
1397 * only one char is left (may be a "-"), then stop here,
1398 * reset, & come back for more.
1400 if ((left <= 1) && skipped) {
1407 if (val_a >= bitmap_len || neg) {
1419 err = proc_get_long(&p, &left, &val_b,
1420 &neg, tr_b, sizeof(tr_b),
1423 * If we consumed all of a truncated buffer or
1424 * then stop here, reset, & come back for more.
1426 if (!left && skipped) {
1433 if (val_b >= bitmap_len || neg ||
1444 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1445 proc_skip_char(&p, &left, '\n');
1449 unsigned long bit_a, bit_b = 0;
1453 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1454 if (bit_a >= bitmap_len)
1456 bit_b = find_next_zero_bit(bitmap, bitmap_len,
1460 proc_put_char(&buffer, &left, ',');
1461 proc_put_long(&buffer, &left, bit_a, false);
1462 if (bit_a != bit_b) {
1463 proc_put_char(&buffer, &left, '-');
1464 proc_put_long(&buffer, &left, bit_b, false);
1469 proc_put_char(&buffer, &left, '\n');
1475 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1477 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1483 bitmap_free(tmp_bitmap);
1487 #else /* CONFIG_PROC_SYSCTL */
1489 int proc_dostring(struct ctl_table *table, int write,
1490 void *buffer, size_t *lenp, loff_t *ppos)
1495 int proc_dobool(struct ctl_table *table, int write,
1496 void *buffer, size_t *lenp, loff_t *ppos)
1501 int proc_dointvec(struct ctl_table *table, int write,
1502 void *buffer, size_t *lenp, loff_t *ppos)
1507 int proc_douintvec(struct ctl_table *table, int write,
1508 void *buffer, size_t *lenp, loff_t *ppos)
1513 int proc_dointvec_minmax(struct ctl_table *table, int write,
1514 void *buffer, size_t *lenp, loff_t *ppos)
1519 int proc_douintvec_minmax(struct ctl_table *table, int write,
1520 void *buffer, size_t *lenp, loff_t *ppos)
1525 int proc_dou8vec_minmax(struct ctl_table *table, int write,
1526 void *buffer, size_t *lenp, loff_t *ppos)
1531 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1532 void *buffer, size_t *lenp, loff_t *ppos)
1537 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1538 void *buffer, size_t *lenp, loff_t *ppos)
1543 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1544 void *buffer, size_t *lenp, loff_t *ppos)
1549 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1550 void *buffer, size_t *lenp, loff_t *ppos)
1555 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1556 void *buffer, size_t *lenp, loff_t *ppos)
1561 int proc_do_large_bitmap(struct ctl_table *table, int write,
1562 void *buffer, size_t *lenp, loff_t *ppos)
1567 #endif /* CONFIG_PROC_SYSCTL */
1569 #if defined(CONFIG_SYSCTL)
1570 int proc_do_static_key(struct ctl_table *table, int write,
1571 void *buffer, size_t *lenp, loff_t *ppos)
1573 struct static_key *key = (struct static_key *)table->data;
1574 static DEFINE_MUTEX(static_key_mutex);
1576 struct ctl_table tmp = {
1578 .maxlen = sizeof(val),
1579 .mode = table->mode,
1580 .extra1 = SYSCTL_ZERO,
1581 .extra2 = SYSCTL_ONE,
1584 if (write && !capable(CAP_SYS_ADMIN))
1587 mutex_lock(&static_key_mutex);
1588 val = static_key_enabled(key);
1589 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1590 if (write && !ret) {
1592 static_key_enable(key);
1594 static_key_disable(key);
1596 mutex_unlock(&static_key_mutex);
1600 static struct ctl_table kern_table[] = {
1602 .procname = "sched_child_runs_first",
1603 .data = &sysctl_sched_child_runs_first,
1604 .maxlen = sizeof(unsigned int),
1606 .proc_handler = proc_dointvec,
1608 #ifdef CONFIG_SCHEDSTATS
1610 .procname = "sched_schedstats",
1612 .maxlen = sizeof(unsigned int),
1614 .proc_handler = sysctl_schedstats,
1615 .extra1 = SYSCTL_ZERO,
1616 .extra2 = SYSCTL_ONE,
1618 #endif /* CONFIG_SCHEDSTATS */
1619 #ifdef CONFIG_TASK_DELAY_ACCT
1621 .procname = "task_delayacct",
1623 .maxlen = sizeof(unsigned int),
1625 .proc_handler = sysctl_delayacct,
1626 .extra1 = SYSCTL_ZERO,
1627 .extra2 = SYSCTL_ONE,
1629 #endif /* CONFIG_TASK_DELAY_ACCT */
1630 #ifdef CONFIG_NUMA_BALANCING
1632 .procname = "numa_balancing",
1633 .data = NULL, /* filled in by handler */
1634 .maxlen = sizeof(unsigned int),
1636 .proc_handler = sysctl_numa_balancing,
1637 .extra1 = SYSCTL_ZERO,
1638 .extra2 = SYSCTL_FOUR,
1640 #endif /* CONFIG_NUMA_BALANCING */
1642 .procname = "sched_rt_period_us",
1643 .data = &sysctl_sched_rt_period,
1644 .maxlen = sizeof(unsigned int),
1646 .proc_handler = sched_rt_handler,
1649 .procname = "sched_rt_runtime_us",
1650 .data = &sysctl_sched_rt_runtime,
1651 .maxlen = sizeof(int),
1653 .proc_handler = sched_rt_handler,
1656 .procname = "sched_deadline_period_max_us",
1657 .data = &sysctl_sched_dl_period_max,
1658 .maxlen = sizeof(unsigned int),
1660 .proc_handler = proc_dointvec,
1663 .procname = "sched_deadline_period_min_us",
1664 .data = &sysctl_sched_dl_period_min,
1665 .maxlen = sizeof(unsigned int),
1667 .proc_handler = proc_dointvec,
1670 .procname = "sched_rr_timeslice_ms",
1671 .data = &sysctl_sched_rr_timeslice,
1672 .maxlen = sizeof(int),
1674 .proc_handler = sched_rr_handler,
1676 #ifdef CONFIG_UCLAMP_TASK
1678 .procname = "sched_util_clamp_min",
1679 .data = &sysctl_sched_uclamp_util_min,
1680 .maxlen = sizeof(unsigned int),
1682 .proc_handler = sysctl_sched_uclamp_handler,
1685 .procname = "sched_util_clamp_max",
1686 .data = &sysctl_sched_uclamp_util_max,
1687 .maxlen = sizeof(unsigned int),
1689 .proc_handler = sysctl_sched_uclamp_handler,
1692 .procname = "sched_util_clamp_min_rt_default",
1693 .data = &sysctl_sched_uclamp_util_min_rt_default,
1694 .maxlen = sizeof(unsigned int),
1696 .proc_handler = sysctl_sched_uclamp_handler,
1699 #ifdef CONFIG_CFS_BANDWIDTH
1701 .procname = "sched_cfs_bandwidth_slice_us",
1702 .data = &sysctl_sched_cfs_bandwidth_slice,
1703 .maxlen = sizeof(unsigned int),
1705 .proc_handler = proc_dointvec_minmax,
1706 .extra1 = SYSCTL_ONE,
1709 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
1711 .procname = "sched_energy_aware",
1712 .data = &sysctl_sched_energy_aware,
1713 .maxlen = sizeof(unsigned int),
1715 .proc_handler = sched_energy_aware_handler,
1716 .extra1 = SYSCTL_ZERO,
1717 .extra2 = SYSCTL_ONE,
1720 #ifdef CONFIG_PROVE_LOCKING
1722 .procname = "prove_locking",
1723 .data = &prove_locking,
1724 .maxlen = sizeof(int),
1726 .proc_handler = proc_dointvec,
1729 #ifdef CONFIG_LOCK_STAT
1731 .procname = "lock_stat",
1733 .maxlen = sizeof(int),
1735 .proc_handler = proc_dointvec,
1739 .procname = "panic",
1740 .data = &panic_timeout,
1741 .maxlen = sizeof(int),
1743 .proc_handler = proc_dointvec,
1745 #ifdef CONFIG_PROC_SYSCTL
1747 .procname = "tainted",
1748 .maxlen = sizeof(long),
1750 .proc_handler = proc_taint,
1753 .procname = "sysctl_writes_strict",
1754 .data = &sysctl_writes_strict,
1755 .maxlen = sizeof(int),
1757 .proc_handler = proc_dointvec_minmax,
1758 .extra1 = SYSCTL_NEG_ONE,
1759 .extra2 = SYSCTL_ONE,
1762 #ifdef CONFIG_LATENCYTOP
1764 .procname = "latencytop",
1765 .data = &latencytop_enabled,
1766 .maxlen = sizeof(int),
1768 .proc_handler = sysctl_latencytop,
1771 #ifdef CONFIG_BLK_DEV_INITRD
1773 .procname = "real-root-dev",
1774 .data = &real_root_dev,
1775 .maxlen = sizeof(int),
1777 .proc_handler = proc_dointvec,
1781 .procname = "print-fatal-signals",
1782 .data = &print_fatal_signals,
1783 .maxlen = sizeof(int),
1785 .proc_handler = proc_dointvec,
1789 .procname = "reboot-cmd",
1790 .data = reboot_command,
1793 .proc_handler = proc_dostring,
1796 .procname = "stop-a",
1797 .data = &stop_a_enabled,
1798 .maxlen = sizeof (int),
1800 .proc_handler = proc_dointvec,
1803 .procname = "scons-poweroff",
1804 .data = &scons_pwroff,
1805 .maxlen = sizeof (int),
1807 .proc_handler = proc_dointvec,
1810 #ifdef CONFIG_SPARC64
1812 .procname = "tsb-ratio",
1813 .data = &sysctl_tsb_ratio,
1814 .maxlen = sizeof (int),
1816 .proc_handler = proc_dointvec,
1819 #ifdef CONFIG_PARISC
1821 .procname = "soft-power",
1822 .data = &pwrsw_enabled,
1823 .maxlen = sizeof (int),
1825 .proc_handler = proc_dointvec,
1828 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
1830 .procname = "unaligned-trap",
1831 .data = &unaligned_enabled,
1832 .maxlen = sizeof (int),
1834 .proc_handler = proc_dointvec,
1838 .procname = "ctrl-alt-del",
1840 .maxlen = sizeof(int),
1842 .proc_handler = proc_dointvec,
1844 #ifdef CONFIG_FUNCTION_TRACER
1846 .procname = "ftrace_enabled",
1847 .data = &ftrace_enabled,
1848 .maxlen = sizeof(int),
1850 .proc_handler = ftrace_enable_sysctl,
1853 #ifdef CONFIG_STACK_TRACER
1855 .procname = "stack_tracer_enabled",
1856 .data = &stack_tracer_enabled,
1857 .maxlen = sizeof(int),
1859 .proc_handler = stack_trace_sysctl,
1862 #ifdef CONFIG_TRACING
1864 .procname = "ftrace_dump_on_oops",
1865 .data = &ftrace_dump_on_oops,
1866 .maxlen = sizeof(int),
1868 .proc_handler = proc_dointvec,
1871 .procname = "traceoff_on_warning",
1872 .data = &__disable_trace_on_warning,
1873 .maxlen = sizeof(__disable_trace_on_warning),
1875 .proc_handler = proc_dointvec,
1878 .procname = "tracepoint_printk",
1879 .data = &tracepoint_printk,
1880 .maxlen = sizeof(tracepoint_printk),
1882 .proc_handler = tracepoint_printk_sysctl,
1885 #ifdef CONFIG_KEXEC_CORE
1887 .procname = "kexec_load_disabled",
1888 .data = &kexec_load_disabled,
1889 .maxlen = sizeof(int),
1891 /* only handle a transition from default "0" to "1" */
1892 .proc_handler = proc_dointvec_minmax,
1893 .extra1 = SYSCTL_ONE,
1894 .extra2 = SYSCTL_ONE,
1897 #ifdef CONFIG_MODULES
1899 .procname = "modprobe",
1900 .data = &modprobe_path,
1901 .maxlen = KMOD_PATH_LEN,
1903 .proc_handler = proc_dostring,
1906 .procname = "modules_disabled",
1907 .data = &modules_disabled,
1908 .maxlen = sizeof(int),
1910 /* only handle a transition from default "0" to "1" */
1911 .proc_handler = proc_dointvec_minmax,
1912 .extra1 = SYSCTL_ONE,
1913 .extra2 = SYSCTL_ONE,
1916 #ifdef CONFIG_UEVENT_HELPER
1918 .procname = "hotplug",
1919 .data = &uevent_helper,
1920 .maxlen = UEVENT_HELPER_PATH_LEN,
1922 .proc_handler = proc_dostring,
1925 #ifdef CONFIG_BSD_PROCESS_ACCT
1929 .maxlen = 3*sizeof(int),
1931 .proc_handler = proc_dointvec,
1934 #ifdef CONFIG_MAGIC_SYSRQ
1936 .procname = "sysrq",
1938 .maxlen = sizeof (int),
1940 .proc_handler = sysrq_sysctl_handler,
1943 #ifdef CONFIG_PROC_SYSCTL
1945 .procname = "cad_pid",
1947 .maxlen = sizeof (int),
1949 .proc_handler = proc_do_cad_pid,
1953 .procname = "threads-max",
1955 .maxlen = sizeof(int),
1957 .proc_handler = sysctl_max_threads,
1960 .procname = "usermodehelper",
1962 .child = usermodehelper_table,
1965 .procname = "overflowuid",
1966 .data = &overflowuid,
1967 .maxlen = sizeof(int),
1969 .proc_handler = proc_dointvec_minmax,
1970 .extra1 = SYSCTL_ZERO,
1971 .extra2 = SYSCTL_MAXOLDUID,
1974 .procname = "overflowgid",
1975 .data = &overflowgid,
1976 .maxlen = sizeof(int),
1978 .proc_handler = proc_dointvec_minmax,
1979 .extra1 = SYSCTL_ZERO,
1980 .extra2 = SYSCTL_MAXOLDUID,
1984 .procname = "userprocess_debug",
1985 .data = &show_unhandled_signals,
1986 .maxlen = sizeof(int),
1988 .proc_handler = proc_dointvec,
1993 .procname = "oops_all_cpu_backtrace",
1994 .data = &sysctl_oops_all_cpu_backtrace,
1995 .maxlen = sizeof(int),
1997 .proc_handler = proc_dointvec_minmax,
1998 .extra1 = SYSCTL_ZERO,
1999 .extra2 = SYSCTL_ONE,
2001 #endif /* CONFIG_SMP */
2003 .procname = "pid_max",
2005 .maxlen = sizeof (int),
2007 .proc_handler = proc_dointvec_minmax,
2008 .extra1 = &pid_max_min,
2009 .extra2 = &pid_max_max,
2012 .procname = "panic_on_oops",
2013 .data = &panic_on_oops,
2014 .maxlen = sizeof(int),
2016 .proc_handler = proc_dointvec,
2019 .procname = "panic_print",
2020 .data = &panic_print,
2021 .maxlen = sizeof(unsigned long),
2023 .proc_handler = proc_doulongvec_minmax,
2026 .procname = "ngroups_max",
2027 .data = (void *)&ngroups_max,
2028 .maxlen = sizeof (int),
2030 .proc_handler = proc_dointvec,
2033 .procname = "cap_last_cap",
2034 .data = (void *)&cap_last_cap,
2035 .maxlen = sizeof(int),
2037 .proc_handler = proc_dointvec,
2039 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
2041 .procname = "unknown_nmi_panic",
2042 .data = &unknown_nmi_panic,
2043 .maxlen = sizeof (int),
2045 .proc_handler = proc_dointvec,
2049 #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
2050 defined(CONFIG_DEBUG_STACKOVERFLOW)
2052 .procname = "panic_on_stackoverflow",
2053 .data = &sysctl_panic_on_stackoverflow,
2054 .maxlen = sizeof(int),
2056 .proc_handler = proc_dointvec,
2059 #if defined(CONFIG_X86)
2061 .procname = "panic_on_unrecovered_nmi",
2062 .data = &panic_on_unrecovered_nmi,
2063 .maxlen = sizeof(int),
2065 .proc_handler = proc_dointvec,
2068 .procname = "panic_on_io_nmi",
2069 .data = &panic_on_io_nmi,
2070 .maxlen = sizeof(int),
2072 .proc_handler = proc_dointvec,
2075 .procname = "bootloader_type",
2076 .data = &bootloader_type,
2077 .maxlen = sizeof (int),
2079 .proc_handler = proc_dointvec,
2082 .procname = "bootloader_version",
2083 .data = &bootloader_version,
2084 .maxlen = sizeof (int),
2086 .proc_handler = proc_dointvec,
2089 .procname = "io_delay_type",
2090 .data = &io_delay_type,
2091 .maxlen = sizeof(int),
2093 .proc_handler = proc_dointvec,
2096 #if defined(CONFIG_MMU)
2098 .procname = "randomize_va_space",
2099 .data = &randomize_va_space,
2100 .maxlen = sizeof(int),
2102 .proc_handler = proc_dointvec,
2105 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
2107 .procname = "spin_retry",
2108 .data = &spin_retry,
2109 .maxlen = sizeof (int),
2111 .proc_handler = proc_dointvec,
2114 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
2116 .procname = "acpi_video_flags",
2117 .data = &acpi_realmode_flags,
2118 .maxlen = sizeof (unsigned long),
2120 .proc_handler = proc_doulongvec_minmax,
2123 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
2125 .procname = "ignore-unaligned-usertrap",
2126 .data = &no_unaligned_warning,
2127 .maxlen = sizeof (int),
2129 .proc_handler = proc_dointvec,
2134 .procname = "unaligned-dump-stack",
2135 .data = &unaligned_dump_stack,
2136 .maxlen = sizeof (int),
2138 .proc_handler = proc_dointvec,
2141 #ifdef CONFIG_RT_MUTEXES
2143 .procname = "max_lock_depth",
2144 .data = &max_lock_depth,
2145 .maxlen = sizeof(int),
2147 .proc_handler = proc_dointvec,
2151 .procname = "poweroff_cmd",
2152 .data = &poweroff_cmd,
2153 .maxlen = POWEROFF_CMD_PATH_LEN,
2155 .proc_handler = proc_dostring,
2161 .child = key_sysctls,
2164 #ifdef CONFIG_PERF_EVENTS
2166 * User-space scripts rely on the existence of this file
2167 * as a feature check for perf_events being enabled.
2169 * So it's an ABI, do not remove!
2172 .procname = "perf_event_paranoid",
2173 .data = &sysctl_perf_event_paranoid,
2174 .maxlen = sizeof(sysctl_perf_event_paranoid),
2176 .proc_handler = proc_dointvec,
2179 .procname = "perf_event_mlock_kb",
2180 .data = &sysctl_perf_event_mlock,
2181 .maxlen = sizeof(sysctl_perf_event_mlock),
2183 .proc_handler = proc_dointvec,
2186 .procname = "perf_event_max_sample_rate",
2187 .data = &sysctl_perf_event_sample_rate,
2188 .maxlen = sizeof(sysctl_perf_event_sample_rate),
2190 .proc_handler = perf_proc_update_handler,
2191 .extra1 = SYSCTL_ONE,
2194 .procname = "perf_cpu_time_max_percent",
2195 .data = &sysctl_perf_cpu_time_max_percent,
2196 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
2198 .proc_handler = perf_cpu_time_max_percent_handler,
2199 .extra1 = SYSCTL_ZERO,
2200 .extra2 = SYSCTL_ONE_HUNDRED,
2203 .procname = "perf_event_max_stack",
2204 .data = &sysctl_perf_event_max_stack,
2205 .maxlen = sizeof(sysctl_perf_event_max_stack),
2207 .proc_handler = perf_event_max_stack_handler,
2208 .extra1 = SYSCTL_ZERO,
2209 .extra2 = (void *)&six_hundred_forty_kb,
2212 .procname = "perf_event_max_contexts_per_stack",
2213 .data = &sysctl_perf_event_max_contexts_per_stack,
2214 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
2216 .proc_handler = perf_event_max_stack_handler,
2217 .extra1 = SYSCTL_ZERO,
2218 .extra2 = SYSCTL_ONE_THOUSAND,
2222 .procname = "panic_on_warn",
2223 .data = &panic_on_warn,
2224 .maxlen = sizeof(int),
2226 .proc_handler = proc_dointvec_minmax,
2227 .extra1 = SYSCTL_ZERO,
2228 .extra2 = SYSCTL_ONE,
2230 #if defined(CONFIG_TREE_RCU)
2232 .procname = "panic_on_rcu_stall",
2233 .data = &sysctl_panic_on_rcu_stall,
2234 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
2236 .proc_handler = proc_dointvec_minmax,
2237 .extra1 = SYSCTL_ZERO,
2238 .extra2 = SYSCTL_ONE,
2241 #if defined(CONFIG_TREE_RCU)
2243 .procname = "max_rcu_stall_to_panic",
2244 .data = &sysctl_max_rcu_stall_to_panic,
2245 .maxlen = sizeof(sysctl_max_rcu_stall_to_panic),
2247 .proc_handler = proc_dointvec_minmax,
2248 .extra1 = SYSCTL_ONE,
2249 .extra2 = SYSCTL_INT_MAX,
2255 static struct ctl_table vm_table[] = {
2257 .procname = "overcommit_memory",
2258 .data = &sysctl_overcommit_memory,
2259 .maxlen = sizeof(sysctl_overcommit_memory),
2261 .proc_handler = overcommit_policy_handler,
2262 .extra1 = SYSCTL_ZERO,
2263 .extra2 = SYSCTL_TWO,
2266 .procname = "panic_on_oom",
2267 .data = &sysctl_panic_on_oom,
2268 .maxlen = sizeof(sysctl_panic_on_oom),
2270 .proc_handler = proc_dointvec_minmax,
2271 .extra1 = SYSCTL_ZERO,
2272 .extra2 = SYSCTL_TWO,
2275 .procname = "oom_kill_allocating_task",
2276 .data = &sysctl_oom_kill_allocating_task,
2277 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
2279 .proc_handler = proc_dointvec,
2282 .procname = "oom_dump_tasks",
2283 .data = &sysctl_oom_dump_tasks,
2284 .maxlen = sizeof(sysctl_oom_dump_tasks),
2286 .proc_handler = proc_dointvec,
2289 .procname = "overcommit_ratio",
2290 .data = &sysctl_overcommit_ratio,
2291 .maxlen = sizeof(sysctl_overcommit_ratio),
2293 .proc_handler = overcommit_ratio_handler,
2296 .procname = "overcommit_kbytes",
2297 .data = &sysctl_overcommit_kbytes,
2298 .maxlen = sizeof(sysctl_overcommit_kbytes),
2300 .proc_handler = overcommit_kbytes_handler,
2303 .procname = "page-cluster",
2304 .data = &page_cluster,
2305 .maxlen = sizeof(int),
2307 .proc_handler = proc_dointvec_minmax,
2308 .extra1 = SYSCTL_ZERO,
2311 .procname = "dirty_background_ratio",
2312 .data = &dirty_background_ratio,
2313 .maxlen = sizeof(dirty_background_ratio),
2315 .proc_handler = dirty_background_ratio_handler,
2316 .extra1 = SYSCTL_ZERO,
2317 .extra2 = SYSCTL_ONE_HUNDRED,
2320 .procname = "dirty_background_bytes",
2321 .data = &dirty_background_bytes,
2322 .maxlen = sizeof(dirty_background_bytes),
2324 .proc_handler = dirty_background_bytes_handler,
2325 .extra1 = SYSCTL_LONG_ONE,
2328 .procname = "dirty_ratio",
2329 .data = &vm_dirty_ratio,
2330 .maxlen = sizeof(vm_dirty_ratio),
2332 .proc_handler = dirty_ratio_handler,
2333 .extra1 = SYSCTL_ZERO,
2334 .extra2 = SYSCTL_ONE_HUNDRED,
2337 .procname = "dirty_bytes",
2338 .data = &vm_dirty_bytes,
2339 .maxlen = sizeof(vm_dirty_bytes),
2341 .proc_handler = dirty_bytes_handler,
2342 .extra1 = (void *)&dirty_bytes_min,
2345 .procname = "dirty_writeback_centisecs",
2346 .data = &dirty_writeback_interval,
2347 .maxlen = sizeof(dirty_writeback_interval),
2349 .proc_handler = dirty_writeback_centisecs_handler,
2352 .procname = "dirty_expire_centisecs",
2353 .data = &dirty_expire_interval,
2354 .maxlen = sizeof(dirty_expire_interval),
2356 .proc_handler = proc_dointvec_minmax,
2357 .extra1 = SYSCTL_ZERO,
2360 .procname = "dirtytime_expire_seconds",
2361 .data = &dirtytime_expire_interval,
2362 .maxlen = sizeof(dirtytime_expire_interval),
2364 .proc_handler = dirtytime_interval_handler,
2365 .extra1 = SYSCTL_ZERO,
2368 .procname = "swappiness",
2369 .data = &vm_swappiness,
2370 .maxlen = sizeof(vm_swappiness),
2372 .proc_handler = proc_dointvec_minmax,
2373 .extra1 = SYSCTL_ZERO,
2374 .extra2 = SYSCTL_TWO_HUNDRED,
2376 #ifdef CONFIG_HUGETLB_PAGE
2378 .procname = "nr_hugepages",
2380 .maxlen = sizeof(unsigned long),
2382 .proc_handler = hugetlb_sysctl_handler,
2386 .procname = "nr_hugepages_mempolicy",
2388 .maxlen = sizeof(unsigned long),
2390 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
2393 .procname = "numa_stat",
2394 .data = &sysctl_vm_numa_stat,
2395 .maxlen = sizeof(int),
2397 .proc_handler = sysctl_vm_numa_stat_handler,
2398 .extra1 = SYSCTL_ZERO,
2399 .extra2 = SYSCTL_ONE,
2403 .procname = "hugetlb_shm_group",
2404 .data = &sysctl_hugetlb_shm_group,
2405 .maxlen = sizeof(gid_t),
2407 .proc_handler = proc_dointvec,
2410 .procname = "nr_overcommit_hugepages",
2412 .maxlen = sizeof(unsigned long),
2414 .proc_handler = hugetlb_overcommit_handler,
2418 .procname = "lowmem_reserve_ratio",
2419 .data = &sysctl_lowmem_reserve_ratio,
2420 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
2422 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
2425 .procname = "drop_caches",
2426 .data = &sysctl_drop_caches,
2427 .maxlen = sizeof(int),
2429 .proc_handler = drop_caches_sysctl_handler,
2430 .extra1 = SYSCTL_ONE,
2431 .extra2 = SYSCTL_FOUR,
2433 #ifdef CONFIG_COMPACTION
2435 .procname = "compact_memory",
2437 .maxlen = sizeof(int),
2439 .proc_handler = sysctl_compaction_handler,
2442 .procname = "compaction_proactiveness",
2443 .data = &sysctl_compaction_proactiveness,
2444 .maxlen = sizeof(sysctl_compaction_proactiveness),
2446 .proc_handler = compaction_proactiveness_sysctl_handler,
2447 .extra1 = SYSCTL_ZERO,
2448 .extra2 = SYSCTL_ONE_HUNDRED,
2451 .procname = "extfrag_threshold",
2452 .data = &sysctl_extfrag_threshold,
2453 .maxlen = sizeof(int),
2455 .proc_handler = proc_dointvec_minmax,
2456 .extra1 = SYSCTL_ZERO,
2457 .extra2 = (void *)&max_extfrag_threshold,
2460 .procname = "compact_unevictable_allowed",
2461 .data = &sysctl_compact_unevictable_allowed,
2462 .maxlen = sizeof(int),
2464 .proc_handler = proc_dointvec_minmax_warn_RT_change,
2465 .extra1 = SYSCTL_ZERO,
2466 .extra2 = SYSCTL_ONE,
2469 #endif /* CONFIG_COMPACTION */
2471 .procname = "min_free_kbytes",
2472 .data = &min_free_kbytes,
2473 .maxlen = sizeof(min_free_kbytes),
2475 .proc_handler = min_free_kbytes_sysctl_handler,
2476 .extra1 = SYSCTL_ZERO,
2479 .procname = "watermark_boost_factor",
2480 .data = &watermark_boost_factor,
2481 .maxlen = sizeof(watermark_boost_factor),
2483 .proc_handler = proc_dointvec_minmax,
2484 .extra1 = SYSCTL_ZERO,
2487 .procname = "watermark_scale_factor",
2488 .data = &watermark_scale_factor,
2489 .maxlen = sizeof(watermark_scale_factor),
2491 .proc_handler = watermark_scale_factor_sysctl_handler,
2492 .extra1 = SYSCTL_ONE,
2493 .extra2 = SYSCTL_THREE_THOUSAND,
2496 .procname = "percpu_pagelist_high_fraction",
2497 .data = &percpu_pagelist_high_fraction,
2498 .maxlen = sizeof(percpu_pagelist_high_fraction),
2500 .proc_handler = percpu_pagelist_high_fraction_sysctl_handler,
2501 .extra1 = SYSCTL_ZERO,
2504 .procname = "page_lock_unfairness",
2505 .data = &sysctl_page_lock_unfairness,
2506 .maxlen = sizeof(sysctl_page_lock_unfairness),
2508 .proc_handler = proc_dointvec_minmax,
2509 .extra1 = SYSCTL_ZERO,
2513 .procname = "max_map_count",
2514 .data = &sysctl_max_map_count,
2515 .maxlen = sizeof(sysctl_max_map_count),
2517 .proc_handler = proc_dointvec_minmax,
2518 .extra1 = SYSCTL_ZERO,
2522 .procname = "nr_trim_pages",
2523 .data = &sysctl_nr_trim_pages,
2524 .maxlen = sizeof(sysctl_nr_trim_pages),
2526 .proc_handler = proc_dointvec_minmax,
2527 .extra1 = SYSCTL_ZERO,
2531 .procname = "laptop_mode",
2532 .data = &laptop_mode,
2533 .maxlen = sizeof(laptop_mode),
2535 .proc_handler = proc_dointvec_jiffies,
2538 .procname = "vfs_cache_pressure",
2539 .data = &sysctl_vfs_cache_pressure,
2540 .maxlen = sizeof(sysctl_vfs_cache_pressure),
2542 .proc_handler = proc_dointvec_minmax,
2543 .extra1 = SYSCTL_ZERO,
2545 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
2546 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
2548 .procname = "legacy_va_layout",
2549 .data = &sysctl_legacy_va_layout,
2550 .maxlen = sizeof(sysctl_legacy_va_layout),
2552 .proc_handler = proc_dointvec_minmax,
2553 .extra1 = SYSCTL_ZERO,
2558 .procname = "zone_reclaim_mode",
2559 .data = &node_reclaim_mode,
2560 .maxlen = sizeof(node_reclaim_mode),
2562 .proc_handler = proc_dointvec_minmax,
2563 .extra1 = SYSCTL_ZERO,
2566 .procname = "min_unmapped_ratio",
2567 .data = &sysctl_min_unmapped_ratio,
2568 .maxlen = sizeof(sysctl_min_unmapped_ratio),
2570 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
2571 .extra1 = SYSCTL_ZERO,
2572 .extra2 = SYSCTL_ONE_HUNDRED,
2575 .procname = "min_slab_ratio",
2576 .data = &sysctl_min_slab_ratio,
2577 .maxlen = sizeof(sysctl_min_slab_ratio),
2579 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
2580 .extra1 = SYSCTL_ZERO,
2581 .extra2 = SYSCTL_ONE_HUNDRED,
2586 .procname = "stat_interval",
2587 .data = &sysctl_stat_interval,
2588 .maxlen = sizeof(sysctl_stat_interval),
2590 .proc_handler = proc_dointvec_jiffies,
2593 .procname = "stat_refresh",
2597 .proc_handler = vmstat_refresh,
2602 .procname = "mmap_min_addr",
2603 .data = &dac_mmap_min_addr,
2604 .maxlen = sizeof(unsigned long),
2606 .proc_handler = mmap_min_addr_handler,
2611 .procname = "numa_zonelist_order",
2612 .data = &numa_zonelist_order,
2613 .maxlen = NUMA_ZONELIST_ORDER_LEN,
2615 .proc_handler = numa_zonelist_order_handler,
2618 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
2619 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
2621 .procname = "vdso_enabled",
2622 #ifdef CONFIG_X86_32
2623 .data = &vdso32_enabled,
2624 .maxlen = sizeof(vdso32_enabled),
2626 .data = &vdso_enabled,
2627 .maxlen = sizeof(vdso_enabled),
2630 .proc_handler = proc_dointvec,
2631 .extra1 = SYSCTL_ZERO,
2634 #ifdef CONFIG_HIGHMEM
2636 .procname = "highmem_is_dirtyable",
2637 .data = &vm_highmem_is_dirtyable,
2638 .maxlen = sizeof(vm_highmem_is_dirtyable),
2640 .proc_handler = proc_dointvec_minmax,
2641 .extra1 = SYSCTL_ZERO,
2642 .extra2 = SYSCTL_ONE,
2645 #ifdef CONFIG_MEMORY_FAILURE
2647 .procname = "memory_failure_early_kill",
2648 .data = &sysctl_memory_failure_early_kill,
2649 .maxlen = sizeof(sysctl_memory_failure_early_kill),
2651 .proc_handler = proc_dointvec_minmax,
2652 .extra1 = SYSCTL_ZERO,
2653 .extra2 = SYSCTL_ONE,
2656 .procname = "memory_failure_recovery",
2657 .data = &sysctl_memory_failure_recovery,
2658 .maxlen = sizeof(sysctl_memory_failure_recovery),
2660 .proc_handler = proc_dointvec_minmax,
2661 .extra1 = SYSCTL_ZERO,
2662 .extra2 = SYSCTL_ONE,
2666 .procname = "user_reserve_kbytes",
2667 .data = &sysctl_user_reserve_kbytes,
2668 .maxlen = sizeof(sysctl_user_reserve_kbytes),
2670 .proc_handler = proc_doulongvec_minmax,
2673 .procname = "admin_reserve_kbytes",
2674 .data = &sysctl_admin_reserve_kbytes,
2675 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
2677 .proc_handler = proc_doulongvec_minmax,
2679 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
2681 .procname = "mmap_rnd_bits",
2682 .data = &mmap_rnd_bits,
2683 .maxlen = sizeof(mmap_rnd_bits),
2685 .proc_handler = proc_dointvec_minmax,
2686 .extra1 = (void *)&mmap_rnd_bits_min,
2687 .extra2 = (void *)&mmap_rnd_bits_max,
2690 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
2692 .procname = "mmap_rnd_compat_bits",
2693 .data = &mmap_rnd_compat_bits,
2694 .maxlen = sizeof(mmap_rnd_compat_bits),
2696 .proc_handler = proc_dointvec_minmax,
2697 .extra1 = (void *)&mmap_rnd_compat_bits_min,
2698 .extra2 = (void *)&mmap_rnd_compat_bits_max,
2701 #ifdef CONFIG_USERFAULTFD
2703 .procname = "unprivileged_userfaultfd",
2704 .data = &sysctl_unprivileged_userfaultfd,
2705 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
2707 .proc_handler = proc_dointvec_minmax,
2708 .extra1 = SYSCTL_ZERO,
2709 .extra2 = SYSCTL_ONE,
2715 static struct ctl_table debug_table[] = {
2716 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
2718 .procname = "exception-trace",
2719 .data = &show_unhandled_signals,
2720 .maxlen = sizeof(int),
2722 .proc_handler = proc_dointvec
2728 static struct ctl_table dev_table[] = {
2732 DECLARE_SYSCTL_BASE(kernel, kern_table);
2733 DECLARE_SYSCTL_BASE(vm, vm_table);
2734 DECLARE_SYSCTL_BASE(debug, debug_table);
2735 DECLARE_SYSCTL_BASE(dev, dev_table);
2737 int __init sysctl_init_bases(void)
2739 register_sysctl_base(kernel);
2740 register_sysctl_base(vm);
2741 register_sysctl_base(debug);
2742 register_sysctl_base(dev);
2746 #endif /* CONFIG_SYSCTL */
2748 * No sense putting this after each symbol definition, twice,
2749 * exception granted :-)
2751 EXPORT_SYMBOL(proc_dobool);
2752 EXPORT_SYMBOL(proc_dointvec);
2753 EXPORT_SYMBOL(proc_douintvec);
2754 EXPORT_SYMBOL(proc_dointvec_jiffies);
2755 EXPORT_SYMBOL(proc_dointvec_minmax);
2756 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
2757 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2758 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2759 EXPORT_SYMBOL(proc_dostring);
2760 EXPORT_SYMBOL(proc_doulongvec_minmax);
2761 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2762 EXPORT_SYMBOL(proc_do_large_bitmap);