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/mount.h>
65 #include <linux/userfaultfd_k.h>
66 #include <linux/pid.h>
68 #include "../lib/kstrtox.h"
70 #include <linux/uaccess.h>
71 #include <asm/processor.h>
75 #include <asm/stacktrace.h>
79 #include <asm/setup.h>
81 #ifdef CONFIG_RT_MUTEXES
82 #include <linux/rtmutex.h>
85 /* shared constants to be used in various sysctls */
86 const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 };
87 EXPORT_SYMBOL(sysctl_vals);
89 const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX };
90 EXPORT_SYMBOL_GPL(sysctl_long_vals);
92 #if defined(CONFIG_SYSCTL)
94 /* Constants used for minimum and maximum */
96 #ifdef CONFIG_PERF_EVENTS
97 static const int six_hundred_forty_kb = 640 * 1024;
101 static const int ngroups_max = NGROUPS_MAX;
102 static const int cap_last_cap = CAP_LAST_CAP;
104 #ifdef CONFIG_PROC_SYSCTL
107 * enum sysctl_writes_mode - supported sysctl write modes
109 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
110 * to be written, and multiple writes on the same sysctl file descriptor
111 * will rewrite the sysctl value, regardless of file position. No warning
112 * is issued when the initial position is not 0.
113 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
115 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
116 * file position 0 and the value must be fully contained in the buffer
117 * sent to the write syscall. If dealing with strings respect the file
118 * position, but restrict this to the max length of the buffer, anything
119 * passed the max length will be ignored. Multiple writes will append
122 * These write modes control how current file position affects the behavior of
123 * updating sysctl values through the proc interface on each write.
125 enum sysctl_writes_mode {
126 SYSCTL_WRITES_LEGACY = -1,
127 SYSCTL_WRITES_WARN = 0,
128 SYSCTL_WRITES_STRICT = 1,
131 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
132 #endif /* CONFIG_PROC_SYSCTL */
134 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
135 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
136 int sysctl_legacy_va_layout;
139 #endif /* CONFIG_SYSCTL */
145 #ifdef CONFIG_PROC_SYSCTL
147 static int _proc_do_string(char *data, int maxlen, int write,
148 char *buffer, size_t *lenp, loff_t *ppos)
153 if (!data || !maxlen || !*lenp) {
159 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
160 /* Only continue writes not past the end of buffer. */
162 if (len > maxlen - 1)
169 /* Start writing from beginning of buffer. */
175 while ((p - buffer) < *lenp && len < maxlen - 1) {
177 if (c == 0 || c == '\n')
198 memcpy(buffer, data, len);
209 static void warn_sysctl_write(struct ctl_table *table)
211 pr_warn_once("%s wrote to %s when file position was not 0!\n"
212 "This will not be supported in the future. To silence this\n"
213 "warning, set kernel.sysctl_writes_strict = -1\n",
214 current->comm, table->procname);
218 * proc_first_pos_non_zero_ignore - check if first position is allowed
219 * @ppos: file position
220 * @table: the sysctl table
222 * Returns true if the first position is non-zero and the sysctl_writes_strict
223 * mode indicates this is not allowed for numeric input types. String proc
224 * handlers can ignore the return value.
226 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
227 struct ctl_table *table)
232 switch (sysctl_writes_strict) {
233 case SYSCTL_WRITES_STRICT:
235 case SYSCTL_WRITES_WARN:
236 warn_sysctl_write(table);
244 * proc_dostring - read a string sysctl
245 * @table: the sysctl table
246 * @write: %TRUE if this is a write to the sysctl file
247 * @buffer: the user buffer
248 * @lenp: the size of the user buffer
249 * @ppos: file position
251 * Reads/writes a string from/to the user buffer. If the kernel
252 * buffer provided is not large enough to hold the string, the
253 * string is truncated. The copied string is %NULL-terminated.
254 * If the string is being read by the user process, it is copied
255 * and a newline '\n' is added. It is truncated if the buffer is
258 * Returns 0 on success.
260 int proc_dostring(struct ctl_table *table, int write,
261 void *buffer, size_t *lenp, loff_t *ppos)
264 proc_first_pos_non_zero_ignore(ppos, table);
266 return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
270 static void proc_skip_spaces(char **buf, size_t *size)
280 static void proc_skip_char(char **buf, size_t *size, const char v)
291 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
294 * @cp: kernel buffer containing the string to parse
295 * @endp: pointer to store the trailing characters
296 * @base: the base to use
297 * @res: where the parsed integer will be stored
299 * In case of success 0 is returned and @res will contain the parsed integer,
300 * @endp will hold any trailing characters.
301 * This function will fail the parse on overflow. If there wasn't an overflow
302 * the function will defer the decision what characters count as invalid to the
305 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
308 unsigned long long result;
311 cp = _parse_integer_fixup_radix(cp, &base);
312 rv = _parse_integer(cp, base, &result);
313 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
321 *res = (unsigned long)result;
327 * proc_get_long - reads an ASCII formatted integer from a user buffer
329 * @buf: a kernel buffer
330 * @size: size of the kernel buffer
331 * @val: this is where the number will be stored
332 * @neg: set to %TRUE if number is negative
333 * @perm_tr: a vector which contains the allowed trailers
334 * @perm_tr_len: size of the perm_tr vector
335 * @tr: pointer to store the trailer character
337 * In case of success %0 is returned and @buf and @size are updated with
338 * the amount of bytes read. If @tr is non-NULL and a trailing
339 * character exists (size is non-zero after returning from this
340 * function), @tr is updated with the trailing character.
342 static int proc_get_long(char **buf, size_t *size,
343 unsigned long *val, bool *neg,
344 const char *perm_tr, unsigned perm_tr_len, char *tr)
346 char *p, tmp[TMPBUFLEN];
352 if (len > TMPBUFLEN - 1)
355 memcpy(tmp, *buf, len);
359 if (*p == '-' && *size > 1) {
367 if (strtoul_lenient(p, &p, 0, val))
372 /* We don't know if the next char is whitespace thus we may accept
373 * invalid integers (e.g. 1234...a) or two integers instead of one
374 * (e.g. 123...1). So lets not allow such large numbers. */
375 if (len == TMPBUFLEN - 1)
378 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
381 if (tr && (len < *size))
391 * proc_put_long - converts an integer to a decimal ASCII formatted string
393 * @buf: the user buffer
394 * @size: the size of the user buffer
395 * @val: the integer to be converted
396 * @neg: sign of the number, %TRUE for negative
398 * In case of success @buf and @size are updated with the amount of bytes
401 static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
404 char tmp[TMPBUFLEN], *p = tmp;
406 sprintf(p, "%s%lu", neg ? "-" : "", val);
410 memcpy(*buf, tmp, len);
416 static void proc_put_char(void **buf, size_t *size, char c)
419 char **buffer = (char **)buf;
428 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
430 int write, void *data)
434 if (*lvalp > (unsigned long) INT_MAX + 1)
436 WRITE_ONCE(*valp, -*lvalp);
438 if (*lvalp > (unsigned long) INT_MAX)
440 WRITE_ONCE(*valp, *lvalp);
443 int val = READ_ONCE(*valp);
446 *lvalp = -(unsigned long)val;
449 *lvalp = (unsigned long)val;
455 static int do_proc_douintvec_conv(unsigned long *lvalp,
457 int write, void *data)
460 if (*lvalp > UINT_MAX)
462 WRITE_ONCE(*valp, *lvalp);
464 unsigned int val = READ_ONCE(*valp);
465 *lvalp = (unsigned long)val;
470 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
472 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
473 int write, void *buffer,
474 size_t *lenp, loff_t *ppos,
475 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
476 int write, void *data),
479 int *i, vleft, first = 1, err = 0;
483 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
488 i = (int *) tbl_data;
489 vleft = table->maxlen / sizeof(*i);
493 conv = do_proc_dointvec_conv;
496 if (proc_first_pos_non_zero_ignore(ppos, table))
499 if (left > PAGE_SIZE - 1)
500 left = PAGE_SIZE - 1;
504 for (; left && vleft--; i++, first=0) {
509 proc_skip_spaces(&p, &left);
513 err = proc_get_long(&p, &left, &lval, &neg,
515 sizeof(proc_wspace_sep), NULL);
518 if (conv(&neg, &lval, i, 1, data)) {
523 if (conv(&neg, &lval, i, 0, data)) {
528 proc_put_char(&buffer, &left, '\t');
529 proc_put_long(&buffer, &left, lval, neg);
533 if (!write && !first && left && !err)
534 proc_put_char(&buffer, &left, '\n');
535 if (write && !err && left)
536 proc_skip_spaces(&p, &left);
538 return err ? : -EINVAL;
545 static int do_proc_dointvec(struct ctl_table *table, int write,
546 void *buffer, size_t *lenp, loff_t *ppos,
547 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
548 int write, void *data),
551 return __do_proc_dointvec(table->data, table, write,
552 buffer, lenp, ppos, conv, data);
555 static int do_proc_douintvec_w(unsigned int *tbl_data,
556 struct ctl_table *table,
558 size_t *lenp, loff_t *ppos,
559 int (*conv)(unsigned long *lvalp,
561 int write, void *data),
572 if (proc_first_pos_non_zero_ignore(ppos, table))
575 if (left > PAGE_SIZE - 1)
576 left = PAGE_SIZE - 1;
578 proc_skip_spaces(&p, &left);
584 err = proc_get_long(&p, &left, &lval, &neg,
586 sizeof(proc_wspace_sep), NULL);
592 if (conv(&lval, tbl_data, 1, data)) {
598 proc_skip_spaces(&p, &left);
606 /* This is in keeping with old __do_proc_dointvec() */
612 static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
613 size_t *lenp, loff_t *ppos,
614 int (*conv)(unsigned long *lvalp,
616 int write, void *data),
625 if (conv(&lval, tbl_data, 0, data)) {
630 proc_put_long(&buffer, &left, lval, false);
634 proc_put_char(&buffer, &left, '\n');
643 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
644 int write, void *buffer,
645 size_t *lenp, loff_t *ppos,
646 int (*conv)(unsigned long *lvalp,
648 int write, void *data),
651 unsigned int *i, vleft;
653 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
658 i = (unsigned int *) tbl_data;
659 vleft = table->maxlen / sizeof(*i);
662 * Arrays are not supported, keep this simple. *Do not* add
671 conv = do_proc_douintvec_conv;
674 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
676 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
679 int do_proc_douintvec(struct ctl_table *table, int write,
680 void *buffer, size_t *lenp, loff_t *ppos,
681 int (*conv)(unsigned long *lvalp,
683 int write, void *data),
686 return __do_proc_douintvec(table->data, table, write,
687 buffer, lenp, ppos, conv, data);
691 * proc_dobool - read/write a bool
692 * @table: the sysctl table
693 * @write: %TRUE if this is a write to the sysctl file
694 * @buffer: the user buffer
695 * @lenp: the size of the user buffer
696 * @ppos: file position
698 * Reads/writes one integer value from/to the user buffer,
699 * treated as an ASCII string.
701 * table->data must point to a bool variable and table->maxlen must
704 * Returns 0 on success.
706 int proc_dobool(struct ctl_table *table, int write, void *buffer,
707 size_t *lenp, loff_t *ppos)
709 struct ctl_table tmp;
710 bool *data = table->data;
713 /* Do not support arrays yet. */
714 if (table->maxlen != sizeof(bool))
718 tmp.maxlen = sizeof(val);
721 val = READ_ONCE(*data);
722 res = proc_dointvec(&tmp, write, buffer, lenp, ppos);
726 WRITE_ONCE(*data, val);
731 * proc_dointvec - read a vector of integers
732 * @table: the sysctl table
733 * @write: %TRUE if this is a write to the sysctl file
734 * @buffer: the user buffer
735 * @lenp: the size of the user buffer
736 * @ppos: file position
738 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
739 * values from/to the user buffer, treated as an ASCII string.
741 * Returns 0 on success.
743 int proc_dointvec(struct ctl_table *table, int write, void *buffer,
744 size_t *lenp, loff_t *ppos)
746 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
749 #ifdef CONFIG_COMPACTION
750 static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
751 int write, void *buffer, size_t *lenp, loff_t *ppos)
755 if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
756 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
758 old = *(int *)table->data;
759 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
762 if (old != *(int *)table->data)
763 pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
764 table->procname, current->comm,
765 task_pid_nr(current));
771 * proc_douintvec - read a vector of unsigned integers
772 * @table: the sysctl table
773 * @write: %TRUE if this is a write to the sysctl file
774 * @buffer: the user buffer
775 * @lenp: the size of the user buffer
776 * @ppos: file position
778 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
779 * values from/to the user buffer, treated as an ASCII string.
781 * Returns 0 on success.
783 int proc_douintvec(struct ctl_table *table, int write, void *buffer,
784 size_t *lenp, loff_t *ppos)
786 return do_proc_douintvec(table, write, buffer, lenp, ppos,
787 do_proc_douintvec_conv, NULL);
791 * Taint values can only be increased
792 * This means we can safely use a temporary.
794 static int proc_taint(struct ctl_table *table, int write,
795 void *buffer, size_t *lenp, loff_t *ppos)
798 unsigned long tmptaint = get_taint();
801 if (write && !capable(CAP_SYS_ADMIN))
806 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
814 * If we are relying on panic_on_taint not producing
815 * false positives due to userspace input, bail out
816 * before setting the requested taint flags.
818 if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
822 * Poor man's atomic or. Not worth adding a primitive
823 * to everyone's atomic.h for this
825 for (i = 0; i < TAINT_FLAGS_COUNT; i++)
826 if ((1UL << i) & tmptaint)
827 add_taint(i, LOCKDEP_STILL_OK);
834 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
835 * @min: pointer to minimum allowable value
836 * @max: pointer to maximum allowable value
838 * The do_proc_dointvec_minmax_conv_param structure provides the
839 * minimum and maximum values for doing range checking for those sysctl
840 * parameters that use the proc_dointvec_minmax() handler.
842 struct do_proc_dointvec_minmax_conv_param {
847 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
849 int write, void *data)
852 struct do_proc_dointvec_minmax_conv_param *param = data;
854 * If writing, first do so via a temporary local int so we can
855 * bounds-check it before touching *valp.
857 int *ip = write ? &tmp : valp;
859 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
864 if ((param->min && *param->min > tmp) ||
865 (param->max && *param->max < tmp))
867 WRITE_ONCE(*valp, tmp);
874 * proc_dointvec_minmax - read a vector of integers with min/max values
875 * @table: the sysctl table
876 * @write: %TRUE if this is a write to the sysctl file
877 * @buffer: the user buffer
878 * @lenp: the size of the user buffer
879 * @ppos: file position
881 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
882 * values from/to the user buffer, treated as an ASCII string.
884 * This routine will ensure the values are within the range specified by
885 * table->extra1 (min) and table->extra2 (max).
887 * Returns 0 on success or -EINVAL on write when the range check fails.
889 int proc_dointvec_minmax(struct ctl_table *table, int write,
890 void *buffer, size_t *lenp, loff_t *ppos)
892 struct do_proc_dointvec_minmax_conv_param param = {
893 .min = (int *) table->extra1,
894 .max = (int *) table->extra2,
896 return do_proc_dointvec(table, write, buffer, lenp, ppos,
897 do_proc_dointvec_minmax_conv, ¶m);
901 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
902 * @min: pointer to minimum allowable value
903 * @max: pointer to maximum allowable value
905 * The do_proc_douintvec_minmax_conv_param structure provides the
906 * minimum and maximum values for doing range checking for those sysctl
907 * parameters that use the proc_douintvec_minmax() handler.
909 struct do_proc_douintvec_minmax_conv_param {
914 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
916 int write, void *data)
920 struct do_proc_douintvec_minmax_conv_param *param = data;
921 /* write via temporary local uint for bounds-checking */
922 unsigned int *up = write ? &tmp : valp;
924 ret = do_proc_douintvec_conv(lvalp, up, write, data);
929 if ((param->min && *param->min > tmp) ||
930 (param->max && *param->max < tmp))
933 WRITE_ONCE(*valp, tmp);
940 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
941 * @table: the sysctl table
942 * @write: %TRUE if this is a write to the sysctl file
943 * @buffer: the user buffer
944 * @lenp: the size of the user buffer
945 * @ppos: file position
947 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
948 * values from/to the user buffer, treated as an ASCII string. Negative
949 * strings are not allowed.
951 * This routine will ensure the values are within the range specified by
952 * table->extra1 (min) and table->extra2 (max). There is a final sanity
953 * check for UINT_MAX to avoid having to support wrap around uses from
956 * Returns 0 on success or -ERANGE on write when the range check fails.
958 int proc_douintvec_minmax(struct ctl_table *table, int write,
959 void *buffer, size_t *lenp, loff_t *ppos)
961 struct do_proc_douintvec_minmax_conv_param param = {
962 .min = (unsigned int *) table->extra1,
963 .max = (unsigned int *) table->extra2,
965 return do_proc_douintvec(table, write, buffer, lenp, ppos,
966 do_proc_douintvec_minmax_conv, ¶m);
970 * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
971 * @table: the sysctl table
972 * @write: %TRUE if this is a write to the sysctl file
973 * @buffer: the user buffer
974 * @lenp: the size of the user buffer
975 * @ppos: file position
977 * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
978 * values from/to the user buffer, treated as an ASCII string. Negative
979 * strings are not allowed.
981 * This routine will ensure the values are within the range specified by
982 * table->extra1 (min) and table->extra2 (max).
984 * Returns 0 on success or an error on write when the range check fails.
986 int proc_dou8vec_minmax(struct ctl_table *table, int write,
987 void *buffer, size_t *lenp, loff_t *ppos)
989 struct ctl_table tmp;
990 unsigned int min = 0, max = 255U, val;
991 u8 *data = table->data;
992 struct do_proc_douintvec_minmax_conv_param param = {
998 /* Do not support arrays yet. */
999 if (table->maxlen != sizeof(u8))
1002 if (table->extra1) {
1003 min = *(unsigned int *) table->extra1;
1007 if (table->extra2) {
1008 max = *(unsigned int *) table->extra2;
1015 tmp.maxlen = sizeof(val);
1017 val = READ_ONCE(*data);
1018 res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
1019 do_proc_douintvec_minmax_conv, ¶m);
1023 WRITE_ONCE(*data, val);
1026 EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
1028 #ifdef CONFIG_MAGIC_SYSRQ
1029 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
1030 void *buffer, size_t *lenp, loff_t *ppos)
1036 ret = __do_proc_dointvec(&tmp, table, write, buffer,
1037 lenp, ppos, NULL, NULL);
1042 sysrq_toggle_support(tmp);
1048 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
1049 int write, void *buffer, size_t *lenp, loff_t *ppos,
1050 unsigned long convmul, unsigned long convdiv)
1052 unsigned long *i, *min, *max;
1053 int vleft, first = 1, err = 0;
1057 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1063 min = table->extra1;
1064 max = table->extra2;
1065 vleft = table->maxlen / sizeof(unsigned long);
1069 if (proc_first_pos_non_zero_ignore(ppos, table))
1072 if (left > PAGE_SIZE - 1)
1073 left = PAGE_SIZE - 1;
1077 for (; left && vleft--; i++, first = 0) {
1083 proc_skip_spaces(&p, &left);
1087 err = proc_get_long(&p, &left, &val, &neg,
1089 sizeof(proc_wspace_sep), NULL);
1095 val = convmul * val / convdiv;
1096 if ((min && val < *min) || (max && val > *max)) {
1100 WRITE_ONCE(*i, val);
1102 val = convdiv * READ_ONCE(*i) / convmul;
1104 proc_put_char(&buffer, &left, '\t');
1105 proc_put_long(&buffer, &left, val, false);
1109 if (!write && !first && left && !err)
1110 proc_put_char(&buffer, &left, '\n');
1112 proc_skip_spaces(&p, &left);
1114 return err ? : -EINVAL;
1121 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
1122 void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1123 unsigned long convdiv)
1125 return __do_proc_doulongvec_minmax(table->data, table, write,
1126 buffer, lenp, ppos, convmul, convdiv);
1130 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1131 * @table: the sysctl table
1132 * @write: %TRUE if this is a write to the sysctl file
1133 * @buffer: the user buffer
1134 * @lenp: the size of the user buffer
1135 * @ppos: file position
1137 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1138 * values from/to the user buffer, treated as an ASCII string.
1140 * This routine will ensure the values are within the range specified by
1141 * table->extra1 (min) and table->extra2 (max).
1143 * Returns 0 on success.
1145 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1146 void *buffer, size_t *lenp, loff_t *ppos)
1148 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1152 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1153 * @table: the sysctl table
1154 * @write: %TRUE if this is a write to the sysctl file
1155 * @buffer: the user buffer
1156 * @lenp: the size of the user buffer
1157 * @ppos: file position
1159 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1160 * values from/to the user buffer, treated as an ASCII string. The values
1161 * are treated as milliseconds, and converted to jiffies when they are stored.
1163 * This routine will ensure the values are within the range specified by
1164 * table->extra1 (min) and table->extra2 (max).
1166 * Returns 0 on success.
1168 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1169 void *buffer, size_t *lenp, loff_t *ppos)
1171 return do_proc_doulongvec_minmax(table, write, buffer,
1172 lenp, ppos, HZ, 1000l);
1176 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1178 int write, void *data)
1181 if (*lvalp > INT_MAX / HZ)
1184 WRITE_ONCE(*valp, -*lvalp * HZ);
1186 WRITE_ONCE(*valp, *lvalp * HZ);
1188 int val = READ_ONCE(*valp);
1192 lval = -(unsigned long)val;
1195 lval = (unsigned long)val;
1202 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1204 int write, void *data)
1207 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1209 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1215 lval = -(unsigned long)val;
1218 lval = (unsigned long)val;
1220 *lvalp = jiffies_to_clock_t(lval);
1225 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1227 int write, void *data)
1230 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1234 WRITE_ONCE(*valp, (int)jif);
1236 int val = READ_ONCE(*valp);
1240 lval = -(unsigned long)val;
1243 lval = (unsigned long)val;
1245 *lvalp = jiffies_to_msecs(lval);
1250 static int do_proc_dointvec_ms_jiffies_minmax_conv(bool *negp, unsigned long *lvalp,
1251 int *valp, int write, void *data)
1254 struct do_proc_dointvec_minmax_conv_param *param = data;
1256 * If writing, first do so via a temporary local int so we can
1257 * bounds-check it before touching *valp.
1259 int *ip = write ? &tmp : valp;
1261 ret = do_proc_dointvec_ms_jiffies_conv(negp, lvalp, ip, write, data);
1266 if ((param->min && *param->min > tmp) ||
1267 (param->max && *param->max < tmp))
1275 * proc_dointvec_jiffies - read a vector of integers as seconds
1276 * @table: the sysctl table
1277 * @write: %TRUE if this is a write to the sysctl file
1278 * @buffer: the user buffer
1279 * @lenp: the size of the user buffer
1280 * @ppos: file position
1282 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1283 * values from/to the user buffer, treated as an ASCII string.
1284 * The values read are assumed to be in seconds, and are converted into
1287 * Returns 0 on success.
1289 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1290 void *buffer, size_t *lenp, loff_t *ppos)
1292 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1293 do_proc_dointvec_jiffies_conv,NULL);
1296 int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1297 void *buffer, size_t *lenp, loff_t *ppos)
1299 struct do_proc_dointvec_minmax_conv_param param = {
1300 .min = (int *) table->extra1,
1301 .max = (int *) table->extra2,
1303 return do_proc_dointvec(table, write, buffer, lenp, ppos,
1304 do_proc_dointvec_ms_jiffies_minmax_conv, ¶m);
1308 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1309 * @table: the sysctl table
1310 * @write: %TRUE if this is a write to the sysctl file
1311 * @buffer: the user buffer
1312 * @lenp: the size of the user buffer
1313 * @ppos: pointer to the file position
1315 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1316 * values from/to the user buffer, treated as an ASCII string.
1317 * The values read are assumed to be in 1/USER_HZ seconds, and
1318 * are converted into jiffies.
1320 * Returns 0 on success.
1322 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1323 void *buffer, size_t *lenp, loff_t *ppos)
1325 return do_proc_dointvec(table, write, buffer, lenp, ppos,
1326 do_proc_dointvec_userhz_jiffies_conv, NULL);
1330 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1331 * @table: the sysctl table
1332 * @write: %TRUE if this is a write to the sysctl file
1333 * @buffer: the user buffer
1334 * @lenp: the size of the user buffer
1335 * @ppos: file position
1336 * @ppos: the current position in the file
1338 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1339 * values from/to the user buffer, treated as an ASCII string.
1340 * The values read are assumed to be in 1/1000 seconds, and
1341 * are converted into jiffies.
1343 * Returns 0 on success.
1345 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
1346 size_t *lenp, loff_t *ppos)
1348 return do_proc_dointvec(table, write, buffer, lenp, ppos,
1349 do_proc_dointvec_ms_jiffies_conv, NULL);
1352 static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
1353 size_t *lenp, loff_t *ppos)
1355 struct pid *new_pid;
1359 tmp = pid_vnr(cad_pid);
1361 r = __do_proc_dointvec(&tmp, table, write, buffer,
1362 lenp, ppos, NULL, NULL);
1366 new_pid = find_get_pid(tmp);
1370 put_pid(xchg(&cad_pid, new_pid));
1375 * proc_do_large_bitmap - read/write from/to a large bitmap
1376 * @table: the sysctl table
1377 * @write: %TRUE if this is a write to the sysctl file
1378 * @buffer: the user buffer
1379 * @lenp: the size of the user buffer
1380 * @ppos: file position
1382 * The bitmap is stored at table->data and the bitmap length (in bits)
1385 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1386 * large bitmaps may be represented in a compact manner. Writing into
1387 * the file will clear the bitmap then update it with the given input.
1389 * Returns 0 on success.
1391 int proc_do_large_bitmap(struct ctl_table *table, int write,
1392 void *buffer, size_t *lenp, loff_t *ppos)
1395 size_t left = *lenp;
1396 unsigned long bitmap_len = table->maxlen;
1397 unsigned long *bitmap = *(unsigned long **) table->data;
1398 unsigned long *tmp_bitmap = NULL;
1399 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1401 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1410 if (left > PAGE_SIZE - 1) {
1411 left = PAGE_SIZE - 1;
1412 /* How much of the buffer we'll skip this pass */
1413 skipped = *lenp - left;
1416 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
1419 proc_skip_char(&p, &left, '\n');
1420 while (!err && left) {
1421 unsigned long val_a, val_b;
1425 /* In case we stop parsing mid-number, we can reset */
1427 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1430 * If we consumed the entirety of a truncated buffer or
1431 * only one char is left (may be a "-"), then stop here,
1432 * reset, & come back for more.
1434 if ((left <= 1) && skipped) {
1441 if (val_a >= bitmap_len || neg) {
1453 err = proc_get_long(&p, &left, &val_b,
1454 &neg, tr_b, sizeof(tr_b),
1457 * If we consumed all of a truncated buffer or
1458 * then stop here, reset, & come back for more.
1460 if (!left && skipped) {
1467 if (val_b >= bitmap_len || neg ||
1478 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1479 proc_skip_char(&p, &left, '\n');
1483 unsigned long bit_a, bit_b = 0;
1487 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1488 if (bit_a >= bitmap_len)
1490 bit_b = find_next_zero_bit(bitmap, bitmap_len,
1494 proc_put_char(&buffer, &left, ',');
1495 proc_put_long(&buffer, &left, bit_a, false);
1496 if (bit_a != bit_b) {
1497 proc_put_char(&buffer, &left, '-');
1498 proc_put_long(&buffer, &left, bit_b, false);
1503 proc_put_char(&buffer, &left, '\n');
1509 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1511 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1517 bitmap_free(tmp_bitmap);
1521 #else /* CONFIG_PROC_SYSCTL */
1523 int proc_dostring(struct ctl_table *table, int write,
1524 void *buffer, size_t *lenp, loff_t *ppos)
1529 int proc_dobool(struct ctl_table *table, int write,
1530 void *buffer, size_t *lenp, loff_t *ppos)
1535 int proc_dointvec(struct ctl_table *table, int write,
1536 void *buffer, size_t *lenp, loff_t *ppos)
1541 int proc_douintvec(struct ctl_table *table, int write,
1542 void *buffer, size_t *lenp, loff_t *ppos)
1547 int proc_dointvec_minmax(struct ctl_table *table, int write,
1548 void *buffer, size_t *lenp, loff_t *ppos)
1553 int proc_douintvec_minmax(struct ctl_table *table, int write,
1554 void *buffer, size_t *lenp, loff_t *ppos)
1559 int proc_dou8vec_minmax(struct ctl_table *table, int write,
1560 void *buffer, size_t *lenp, loff_t *ppos)
1565 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1566 void *buffer, size_t *lenp, loff_t *ppos)
1571 int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1572 void *buffer, size_t *lenp, loff_t *ppos)
1577 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1578 void *buffer, size_t *lenp, loff_t *ppos)
1583 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1584 void *buffer, size_t *lenp, loff_t *ppos)
1589 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1590 void *buffer, size_t *lenp, loff_t *ppos)
1595 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1596 void *buffer, size_t *lenp, loff_t *ppos)
1601 int proc_do_large_bitmap(struct ctl_table *table, int write,
1602 void *buffer, size_t *lenp, loff_t *ppos)
1607 #endif /* CONFIG_PROC_SYSCTL */
1609 #if defined(CONFIG_SYSCTL)
1610 int proc_do_static_key(struct ctl_table *table, int write,
1611 void *buffer, size_t *lenp, loff_t *ppos)
1613 struct static_key *key = (struct static_key *)table->data;
1614 static DEFINE_MUTEX(static_key_mutex);
1616 struct ctl_table tmp = {
1618 .maxlen = sizeof(val),
1619 .mode = table->mode,
1620 .extra1 = SYSCTL_ZERO,
1621 .extra2 = SYSCTL_ONE,
1624 if (write && !capable(CAP_SYS_ADMIN))
1627 mutex_lock(&static_key_mutex);
1628 val = static_key_enabled(key);
1629 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1630 if (write && !ret) {
1632 static_key_enable(key);
1634 static_key_disable(key);
1636 mutex_unlock(&static_key_mutex);
1640 static struct ctl_table kern_table[] = {
1642 .procname = "panic",
1643 .data = &panic_timeout,
1644 .maxlen = sizeof(int),
1646 .proc_handler = proc_dointvec,
1648 #ifdef CONFIG_PROC_SYSCTL
1650 .procname = "tainted",
1651 .maxlen = sizeof(long),
1653 .proc_handler = proc_taint,
1656 .procname = "sysctl_writes_strict",
1657 .data = &sysctl_writes_strict,
1658 .maxlen = sizeof(int),
1660 .proc_handler = proc_dointvec_minmax,
1661 .extra1 = SYSCTL_NEG_ONE,
1662 .extra2 = SYSCTL_ONE,
1666 .procname = "print-fatal-signals",
1667 .data = &print_fatal_signals,
1668 .maxlen = sizeof(int),
1670 .proc_handler = proc_dointvec,
1674 .procname = "reboot-cmd",
1675 .data = reboot_command,
1678 .proc_handler = proc_dostring,
1681 .procname = "stop-a",
1682 .data = &stop_a_enabled,
1683 .maxlen = sizeof (int),
1685 .proc_handler = proc_dointvec,
1688 .procname = "scons-poweroff",
1689 .data = &scons_pwroff,
1690 .maxlen = sizeof (int),
1692 .proc_handler = proc_dointvec,
1695 #ifdef CONFIG_SPARC64
1697 .procname = "tsb-ratio",
1698 .data = &sysctl_tsb_ratio,
1699 .maxlen = sizeof (int),
1701 .proc_handler = proc_dointvec,
1704 #ifdef CONFIG_PARISC
1706 .procname = "soft-power",
1707 .data = &pwrsw_enabled,
1708 .maxlen = sizeof (int),
1710 .proc_handler = proc_dointvec,
1713 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
1715 .procname = "unaligned-trap",
1716 .data = &unaligned_enabled,
1717 .maxlen = sizeof (int),
1719 .proc_handler = proc_dointvec,
1722 #ifdef CONFIG_STACK_TRACER
1724 .procname = "stack_tracer_enabled",
1725 .data = &stack_tracer_enabled,
1726 .maxlen = sizeof(int),
1728 .proc_handler = stack_trace_sysctl,
1731 #ifdef CONFIG_TRACING
1733 .procname = "ftrace_dump_on_oops",
1734 .data = &ftrace_dump_on_oops,
1735 .maxlen = sizeof(int),
1737 .proc_handler = proc_dointvec,
1740 .procname = "traceoff_on_warning",
1741 .data = &__disable_trace_on_warning,
1742 .maxlen = sizeof(__disable_trace_on_warning),
1744 .proc_handler = proc_dointvec,
1747 .procname = "tracepoint_printk",
1748 .data = &tracepoint_printk,
1749 .maxlen = sizeof(tracepoint_printk),
1751 .proc_handler = tracepoint_printk_sysctl,
1754 #ifdef CONFIG_MODULES
1756 .procname = "modprobe",
1757 .data = &modprobe_path,
1758 .maxlen = KMOD_PATH_LEN,
1760 .proc_handler = proc_dostring,
1763 .procname = "modules_disabled",
1764 .data = &modules_disabled,
1765 .maxlen = sizeof(int),
1767 /* only handle a transition from default "0" to "1" */
1768 .proc_handler = proc_dointvec_minmax,
1769 .extra1 = SYSCTL_ONE,
1770 .extra2 = SYSCTL_ONE,
1773 #ifdef CONFIG_UEVENT_HELPER
1775 .procname = "hotplug",
1776 .data = &uevent_helper,
1777 .maxlen = UEVENT_HELPER_PATH_LEN,
1779 .proc_handler = proc_dostring,
1782 #ifdef CONFIG_MAGIC_SYSRQ
1784 .procname = "sysrq",
1786 .maxlen = sizeof (int),
1788 .proc_handler = sysrq_sysctl_handler,
1791 #ifdef CONFIG_PROC_SYSCTL
1793 .procname = "cad_pid",
1795 .maxlen = sizeof (int),
1797 .proc_handler = proc_do_cad_pid,
1801 .procname = "threads-max",
1803 .maxlen = sizeof(int),
1805 .proc_handler = sysctl_max_threads,
1808 .procname = "usermodehelper",
1810 .child = usermodehelper_table,
1813 .procname = "overflowuid",
1814 .data = &overflowuid,
1815 .maxlen = sizeof(int),
1817 .proc_handler = proc_dointvec_minmax,
1818 .extra1 = SYSCTL_ZERO,
1819 .extra2 = SYSCTL_MAXOLDUID,
1822 .procname = "overflowgid",
1823 .data = &overflowgid,
1824 .maxlen = sizeof(int),
1826 .proc_handler = proc_dointvec_minmax,
1827 .extra1 = SYSCTL_ZERO,
1828 .extra2 = SYSCTL_MAXOLDUID,
1832 .procname = "userprocess_debug",
1833 .data = &show_unhandled_signals,
1834 .maxlen = sizeof(int),
1836 .proc_handler = proc_dointvec,
1840 .procname = "pid_max",
1842 .maxlen = sizeof (int),
1844 .proc_handler = proc_dointvec_minmax,
1845 .extra1 = &pid_max_min,
1846 .extra2 = &pid_max_max,
1849 .procname = "panic_on_oops",
1850 .data = &panic_on_oops,
1851 .maxlen = sizeof(int),
1853 .proc_handler = proc_dointvec,
1856 .procname = "panic_print",
1857 .data = &panic_print,
1858 .maxlen = sizeof(unsigned long),
1860 .proc_handler = proc_doulongvec_minmax,
1863 .procname = "ngroups_max",
1864 .data = (void *)&ngroups_max,
1865 .maxlen = sizeof (int),
1867 .proc_handler = proc_dointvec,
1870 .procname = "cap_last_cap",
1871 .data = (void *)&cap_last_cap,
1872 .maxlen = sizeof(int),
1874 .proc_handler = proc_dointvec,
1876 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1878 .procname = "unknown_nmi_panic",
1879 .data = &unknown_nmi_panic,
1880 .maxlen = sizeof (int),
1882 .proc_handler = proc_dointvec,
1886 #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
1887 defined(CONFIG_DEBUG_STACKOVERFLOW)
1889 .procname = "panic_on_stackoverflow",
1890 .data = &sysctl_panic_on_stackoverflow,
1891 .maxlen = sizeof(int),
1893 .proc_handler = proc_dointvec,
1896 #if defined(CONFIG_X86)
1898 .procname = "panic_on_unrecovered_nmi",
1899 .data = &panic_on_unrecovered_nmi,
1900 .maxlen = sizeof(int),
1902 .proc_handler = proc_dointvec,
1905 .procname = "panic_on_io_nmi",
1906 .data = &panic_on_io_nmi,
1907 .maxlen = sizeof(int),
1909 .proc_handler = proc_dointvec,
1912 .procname = "bootloader_type",
1913 .data = &bootloader_type,
1914 .maxlen = sizeof (int),
1916 .proc_handler = proc_dointvec,
1919 .procname = "bootloader_version",
1920 .data = &bootloader_version,
1921 .maxlen = sizeof (int),
1923 .proc_handler = proc_dointvec,
1926 .procname = "io_delay_type",
1927 .data = &io_delay_type,
1928 .maxlen = sizeof(int),
1930 .proc_handler = proc_dointvec,
1933 #if defined(CONFIG_MMU)
1935 .procname = "randomize_va_space",
1936 .data = &randomize_va_space,
1937 .maxlen = sizeof(int),
1939 .proc_handler = proc_dointvec,
1942 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1944 .procname = "spin_retry",
1945 .data = &spin_retry,
1946 .maxlen = sizeof (int),
1948 .proc_handler = proc_dointvec,
1951 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1953 .procname = "acpi_video_flags",
1954 .data = &acpi_realmode_flags,
1955 .maxlen = sizeof (unsigned long),
1957 .proc_handler = proc_doulongvec_minmax,
1960 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1962 .procname = "ignore-unaligned-usertrap",
1963 .data = &no_unaligned_warning,
1964 .maxlen = sizeof (int),
1966 .proc_handler = proc_dointvec,
1971 .procname = "unaligned-dump-stack",
1972 .data = &unaligned_dump_stack,
1973 .maxlen = sizeof (int),
1975 .proc_handler = proc_dointvec,
1978 #ifdef CONFIG_RT_MUTEXES
1980 .procname = "max_lock_depth",
1981 .data = &max_lock_depth,
1982 .maxlen = sizeof(int),
1984 .proc_handler = proc_dointvec,
1991 .child = key_sysctls,
1994 #ifdef CONFIG_PERF_EVENTS
1996 * User-space scripts rely on the existence of this file
1997 * as a feature check for perf_events being enabled.
1999 * So it's an ABI, do not remove!
2002 .procname = "perf_event_paranoid",
2003 .data = &sysctl_perf_event_paranoid,
2004 .maxlen = sizeof(sysctl_perf_event_paranoid),
2006 .proc_handler = proc_dointvec,
2009 .procname = "perf_event_mlock_kb",
2010 .data = &sysctl_perf_event_mlock,
2011 .maxlen = sizeof(sysctl_perf_event_mlock),
2013 .proc_handler = proc_dointvec,
2016 .procname = "perf_event_max_sample_rate",
2017 .data = &sysctl_perf_event_sample_rate,
2018 .maxlen = sizeof(sysctl_perf_event_sample_rate),
2020 .proc_handler = perf_proc_update_handler,
2021 .extra1 = SYSCTL_ONE,
2024 .procname = "perf_cpu_time_max_percent",
2025 .data = &sysctl_perf_cpu_time_max_percent,
2026 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
2028 .proc_handler = perf_cpu_time_max_percent_handler,
2029 .extra1 = SYSCTL_ZERO,
2030 .extra2 = SYSCTL_ONE_HUNDRED,
2033 .procname = "perf_event_max_stack",
2034 .data = &sysctl_perf_event_max_stack,
2035 .maxlen = sizeof(sysctl_perf_event_max_stack),
2037 .proc_handler = perf_event_max_stack_handler,
2038 .extra1 = SYSCTL_ZERO,
2039 .extra2 = (void *)&six_hundred_forty_kb,
2042 .procname = "perf_event_max_contexts_per_stack",
2043 .data = &sysctl_perf_event_max_contexts_per_stack,
2044 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
2046 .proc_handler = perf_event_max_stack_handler,
2047 .extra1 = SYSCTL_ZERO,
2048 .extra2 = SYSCTL_ONE_THOUSAND,
2052 .procname = "panic_on_warn",
2053 .data = &panic_on_warn,
2054 .maxlen = sizeof(int),
2056 .proc_handler = proc_dointvec_minmax,
2057 .extra1 = SYSCTL_ZERO,
2058 .extra2 = SYSCTL_ONE,
2060 #ifdef CONFIG_TREE_RCU
2062 .procname = "panic_on_rcu_stall",
2063 .data = &sysctl_panic_on_rcu_stall,
2064 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
2066 .proc_handler = proc_dointvec_minmax,
2067 .extra1 = SYSCTL_ZERO,
2068 .extra2 = SYSCTL_ONE,
2071 .procname = "max_rcu_stall_to_panic",
2072 .data = &sysctl_max_rcu_stall_to_panic,
2073 .maxlen = sizeof(sysctl_max_rcu_stall_to_panic),
2075 .proc_handler = proc_dointvec_minmax,
2076 .extra1 = SYSCTL_ONE,
2077 .extra2 = SYSCTL_INT_MAX,
2083 static struct ctl_table vm_table[] = {
2085 .procname = "overcommit_memory",
2086 .data = &sysctl_overcommit_memory,
2087 .maxlen = sizeof(sysctl_overcommit_memory),
2089 .proc_handler = overcommit_policy_handler,
2090 .extra1 = SYSCTL_ZERO,
2091 .extra2 = SYSCTL_TWO,
2094 .procname = "overcommit_ratio",
2095 .data = &sysctl_overcommit_ratio,
2096 .maxlen = sizeof(sysctl_overcommit_ratio),
2098 .proc_handler = overcommit_ratio_handler,
2101 .procname = "overcommit_kbytes",
2102 .data = &sysctl_overcommit_kbytes,
2103 .maxlen = sizeof(sysctl_overcommit_kbytes),
2105 .proc_handler = overcommit_kbytes_handler,
2108 .procname = "page-cluster",
2109 .data = &page_cluster,
2110 .maxlen = sizeof(int),
2112 .proc_handler = proc_dointvec_minmax,
2113 .extra1 = SYSCTL_ZERO,
2114 .extra2 = (void *)&page_cluster_max,
2117 .procname = "dirtytime_expire_seconds",
2118 .data = &dirtytime_expire_interval,
2119 .maxlen = sizeof(dirtytime_expire_interval),
2121 .proc_handler = dirtytime_interval_handler,
2122 .extra1 = SYSCTL_ZERO,
2125 .procname = "swappiness",
2126 .data = &vm_swappiness,
2127 .maxlen = sizeof(vm_swappiness),
2129 .proc_handler = proc_dointvec_minmax,
2130 .extra1 = SYSCTL_ZERO,
2131 .extra2 = SYSCTL_TWO_HUNDRED,
2135 .procname = "numa_stat",
2136 .data = &sysctl_vm_numa_stat,
2137 .maxlen = sizeof(int),
2139 .proc_handler = sysctl_vm_numa_stat_handler,
2140 .extra1 = SYSCTL_ZERO,
2141 .extra2 = SYSCTL_ONE,
2144 #ifdef CONFIG_HUGETLB_PAGE
2146 .procname = "nr_hugepages",
2148 .maxlen = sizeof(unsigned long),
2150 .proc_handler = hugetlb_sysctl_handler,
2154 .procname = "nr_hugepages_mempolicy",
2156 .maxlen = sizeof(unsigned long),
2158 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
2162 .procname = "hugetlb_shm_group",
2163 .data = &sysctl_hugetlb_shm_group,
2164 .maxlen = sizeof(gid_t),
2166 .proc_handler = proc_dointvec,
2169 .procname = "nr_overcommit_hugepages",
2171 .maxlen = sizeof(unsigned long),
2173 .proc_handler = hugetlb_overcommit_handler,
2177 .procname = "lowmem_reserve_ratio",
2178 .data = &sysctl_lowmem_reserve_ratio,
2179 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
2181 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
2184 .procname = "drop_caches",
2185 .data = &sysctl_drop_caches,
2186 .maxlen = sizeof(int),
2188 .proc_handler = drop_caches_sysctl_handler,
2189 .extra1 = SYSCTL_ONE,
2190 .extra2 = SYSCTL_FOUR,
2192 #ifdef CONFIG_COMPACTION
2194 .procname = "compact_memory",
2196 .maxlen = sizeof(int),
2198 .proc_handler = sysctl_compaction_handler,
2201 .procname = "compaction_proactiveness",
2202 .data = &sysctl_compaction_proactiveness,
2203 .maxlen = sizeof(sysctl_compaction_proactiveness),
2205 .proc_handler = compaction_proactiveness_sysctl_handler,
2206 .extra1 = SYSCTL_ZERO,
2207 .extra2 = SYSCTL_ONE_HUNDRED,
2210 .procname = "extfrag_threshold",
2211 .data = &sysctl_extfrag_threshold,
2212 .maxlen = sizeof(int),
2214 .proc_handler = proc_dointvec_minmax,
2215 .extra1 = SYSCTL_ZERO,
2216 .extra2 = SYSCTL_ONE_THOUSAND,
2219 .procname = "compact_unevictable_allowed",
2220 .data = &sysctl_compact_unevictable_allowed,
2221 .maxlen = sizeof(int),
2223 .proc_handler = proc_dointvec_minmax_warn_RT_change,
2224 .extra1 = SYSCTL_ZERO,
2225 .extra2 = SYSCTL_ONE,
2228 #endif /* CONFIG_COMPACTION */
2230 .procname = "min_free_kbytes",
2231 .data = &min_free_kbytes,
2232 .maxlen = sizeof(min_free_kbytes),
2234 .proc_handler = min_free_kbytes_sysctl_handler,
2235 .extra1 = SYSCTL_ZERO,
2238 .procname = "watermark_boost_factor",
2239 .data = &watermark_boost_factor,
2240 .maxlen = sizeof(watermark_boost_factor),
2242 .proc_handler = proc_dointvec_minmax,
2243 .extra1 = SYSCTL_ZERO,
2246 .procname = "watermark_scale_factor",
2247 .data = &watermark_scale_factor,
2248 .maxlen = sizeof(watermark_scale_factor),
2250 .proc_handler = watermark_scale_factor_sysctl_handler,
2251 .extra1 = SYSCTL_ONE,
2252 .extra2 = SYSCTL_THREE_THOUSAND,
2255 .procname = "percpu_pagelist_high_fraction",
2256 .data = &percpu_pagelist_high_fraction,
2257 .maxlen = sizeof(percpu_pagelist_high_fraction),
2259 .proc_handler = percpu_pagelist_high_fraction_sysctl_handler,
2260 .extra1 = SYSCTL_ZERO,
2263 .procname = "page_lock_unfairness",
2264 .data = &sysctl_page_lock_unfairness,
2265 .maxlen = sizeof(sysctl_page_lock_unfairness),
2267 .proc_handler = proc_dointvec_minmax,
2268 .extra1 = SYSCTL_ZERO,
2272 .procname = "max_map_count",
2273 .data = &sysctl_max_map_count,
2274 .maxlen = sizeof(sysctl_max_map_count),
2276 .proc_handler = proc_dointvec_minmax,
2277 .extra1 = SYSCTL_ZERO,
2281 .procname = "nr_trim_pages",
2282 .data = &sysctl_nr_trim_pages,
2283 .maxlen = sizeof(sysctl_nr_trim_pages),
2285 .proc_handler = proc_dointvec_minmax,
2286 .extra1 = SYSCTL_ZERO,
2290 .procname = "vfs_cache_pressure",
2291 .data = &sysctl_vfs_cache_pressure,
2292 .maxlen = sizeof(sysctl_vfs_cache_pressure),
2294 .proc_handler = proc_dointvec_minmax,
2295 .extra1 = SYSCTL_ZERO,
2297 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
2298 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
2300 .procname = "legacy_va_layout",
2301 .data = &sysctl_legacy_va_layout,
2302 .maxlen = sizeof(sysctl_legacy_va_layout),
2304 .proc_handler = proc_dointvec_minmax,
2305 .extra1 = SYSCTL_ZERO,
2310 .procname = "zone_reclaim_mode",
2311 .data = &node_reclaim_mode,
2312 .maxlen = sizeof(node_reclaim_mode),
2314 .proc_handler = proc_dointvec_minmax,
2315 .extra1 = SYSCTL_ZERO,
2318 .procname = "min_unmapped_ratio",
2319 .data = &sysctl_min_unmapped_ratio,
2320 .maxlen = sizeof(sysctl_min_unmapped_ratio),
2322 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
2323 .extra1 = SYSCTL_ZERO,
2324 .extra2 = SYSCTL_ONE_HUNDRED,
2327 .procname = "min_slab_ratio",
2328 .data = &sysctl_min_slab_ratio,
2329 .maxlen = sizeof(sysctl_min_slab_ratio),
2331 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
2332 .extra1 = SYSCTL_ZERO,
2333 .extra2 = SYSCTL_ONE_HUNDRED,
2338 .procname = "stat_interval",
2339 .data = &sysctl_stat_interval,
2340 .maxlen = sizeof(sysctl_stat_interval),
2342 .proc_handler = proc_dointvec_jiffies,
2345 .procname = "stat_refresh",
2349 .proc_handler = vmstat_refresh,
2354 .procname = "mmap_min_addr",
2355 .data = &dac_mmap_min_addr,
2356 .maxlen = sizeof(unsigned long),
2358 .proc_handler = mmap_min_addr_handler,
2363 .procname = "numa_zonelist_order",
2364 .data = &numa_zonelist_order,
2365 .maxlen = NUMA_ZONELIST_ORDER_LEN,
2367 .proc_handler = numa_zonelist_order_handler,
2370 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
2371 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
2373 .procname = "vdso_enabled",
2374 #ifdef CONFIG_X86_32
2375 .data = &vdso32_enabled,
2376 .maxlen = sizeof(vdso32_enabled),
2378 .data = &vdso_enabled,
2379 .maxlen = sizeof(vdso_enabled),
2382 .proc_handler = proc_dointvec,
2383 .extra1 = SYSCTL_ZERO,
2386 #ifdef CONFIG_MEMORY_FAILURE
2388 .procname = "memory_failure_early_kill",
2389 .data = &sysctl_memory_failure_early_kill,
2390 .maxlen = sizeof(sysctl_memory_failure_early_kill),
2392 .proc_handler = proc_dointvec_minmax,
2393 .extra1 = SYSCTL_ZERO,
2394 .extra2 = SYSCTL_ONE,
2397 .procname = "memory_failure_recovery",
2398 .data = &sysctl_memory_failure_recovery,
2399 .maxlen = sizeof(sysctl_memory_failure_recovery),
2401 .proc_handler = proc_dointvec_minmax,
2402 .extra1 = SYSCTL_ZERO,
2403 .extra2 = SYSCTL_ONE,
2407 .procname = "user_reserve_kbytes",
2408 .data = &sysctl_user_reserve_kbytes,
2409 .maxlen = sizeof(sysctl_user_reserve_kbytes),
2411 .proc_handler = proc_doulongvec_minmax,
2414 .procname = "admin_reserve_kbytes",
2415 .data = &sysctl_admin_reserve_kbytes,
2416 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
2418 .proc_handler = proc_doulongvec_minmax,
2420 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
2422 .procname = "mmap_rnd_bits",
2423 .data = &mmap_rnd_bits,
2424 .maxlen = sizeof(mmap_rnd_bits),
2426 .proc_handler = proc_dointvec_minmax,
2427 .extra1 = (void *)&mmap_rnd_bits_min,
2428 .extra2 = (void *)&mmap_rnd_bits_max,
2431 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
2433 .procname = "mmap_rnd_compat_bits",
2434 .data = &mmap_rnd_compat_bits,
2435 .maxlen = sizeof(mmap_rnd_compat_bits),
2437 .proc_handler = proc_dointvec_minmax,
2438 .extra1 = (void *)&mmap_rnd_compat_bits_min,
2439 .extra2 = (void *)&mmap_rnd_compat_bits_max,
2442 #ifdef CONFIG_USERFAULTFD
2444 .procname = "unprivileged_userfaultfd",
2445 .data = &sysctl_unprivileged_userfaultfd,
2446 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
2448 .proc_handler = proc_dointvec_minmax,
2449 .extra1 = SYSCTL_ZERO,
2450 .extra2 = SYSCTL_ONE,
2456 static struct ctl_table debug_table[] = {
2457 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
2459 .procname = "exception-trace",
2460 .data = &show_unhandled_signals,
2461 .maxlen = sizeof(int),
2463 .proc_handler = proc_dointvec
2469 static struct ctl_table dev_table[] = {
2473 DECLARE_SYSCTL_BASE(kernel, kern_table);
2474 DECLARE_SYSCTL_BASE(vm, vm_table);
2475 DECLARE_SYSCTL_BASE(debug, debug_table);
2476 DECLARE_SYSCTL_BASE(dev, dev_table);
2478 int __init sysctl_init_bases(void)
2480 register_sysctl_base(kernel);
2481 register_sysctl_base(vm);
2482 register_sysctl_base(debug);
2483 register_sysctl_base(dev);
2487 #endif /* CONFIG_SYSCTL */
2489 * No sense putting this after each symbol definition, twice,
2490 * exception granted :-)
2492 EXPORT_SYMBOL(proc_dobool);
2493 EXPORT_SYMBOL(proc_dointvec);
2494 EXPORT_SYMBOL(proc_douintvec);
2495 EXPORT_SYMBOL(proc_dointvec_jiffies);
2496 EXPORT_SYMBOL(proc_dointvec_minmax);
2497 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
2498 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2499 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2500 EXPORT_SYMBOL(proc_dostring);
2501 EXPORT_SYMBOL(proc_doulongvec_minmax);
2502 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2503 EXPORT_SYMBOL(proc_do_large_bitmap);