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 #if defined(CONFIG_SYSCTL)
87 /* Constants used for minimum and maximum */
89 #ifdef CONFIG_PERF_EVENTS
90 static const int six_hundred_forty_kb = 640 * 1024;
94 static const int ngroups_max = NGROUPS_MAX;
95 static const int cap_last_cap = CAP_LAST_CAP;
97 #ifdef CONFIG_PROC_SYSCTL
100 * enum sysctl_writes_mode - supported sysctl write modes
102 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
103 * to be written, and multiple writes on the same sysctl file descriptor
104 * will rewrite the sysctl value, regardless of file position. No warning
105 * is issued when the initial position is not 0.
106 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
108 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
109 * file position 0 and the value must be fully contained in the buffer
110 * sent to the write syscall. If dealing with strings respect the file
111 * position, but restrict this to the max length of the buffer, anything
112 * passed the max length will be ignored. Multiple writes will append
115 * These write modes control how current file position affects the behavior of
116 * updating sysctl values through the proc interface on each write.
118 enum sysctl_writes_mode {
119 SYSCTL_WRITES_LEGACY = -1,
120 SYSCTL_WRITES_WARN = 0,
121 SYSCTL_WRITES_STRICT = 1,
124 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
125 #endif /* CONFIG_PROC_SYSCTL */
127 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
128 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
129 int sysctl_legacy_va_layout;
132 #ifdef CONFIG_COMPACTION
133 /* min_extfrag_threshold is SYSCTL_ZERO */;
134 static const int max_extfrag_threshold = 1000;
137 #endif /* CONFIG_SYSCTL */
143 #ifdef CONFIG_PROC_SYSCTL
145 static int _proc_do_string(char *data, int maxlen, int write,
146 char *buffer, size_t *lenp, loff_t *ppos)
151 if (!data || !maxlen || !*lenp) {
157 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
158 /* Only continue writes not past the end of buffer. */
160 if (len > maxlen - 1)
167 /* Start writing from beginning of buffer. */
173 while ((p - buffer) < *lenp && len < maxlen - 1) {
175 if (c == 0 || c == '\n')
196 memcpy(buffer, data, len);
207 static void warn_sysctl_write(struct ctl_table *table)
209 pr_warn_once("%s wrote to %s when file position was not 0!\n"
210 "This will not be supported in the future. To silence this\n"
211 "warning, set kernel.sysctl_writes_strict = -1\n",
212 current->comm, table->procname);
216 * proc_first_pos_non_zero_ignore - check if first position is allowed
217 * @ppos: file position
218 * @table: the sysctl table
220 * Returns true if the first position is non-zero and the sysctl_writes_strict
221 * mode indicates this is not allowed for numeric input types. String proc
222 * handlers can ignore the return value.
224 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
225 struct ctl_table *table)
230 switch (sysctl_writes_strict) {
231 case SYSCTL_WRITES_STRICT:
233 case SYSCTL_WRITES_WARN:
234 warn_sysctl_write(table);
242 * proc_dostring - read a string sysctl
243 * @table: the sysctl table
244 * @write: %TRUE if this is a write to the sysctl file
245 * @buffer: the user buffer
246 * @lenp: the size of the user buffer
247 * @ppos: file position
249 * Reads/writes a string from/to the user buffer. If the kernel
250 * buffer provided is not large enough to hold the string, the
251 * string is truncated. The copied string is %NULL-terminated.
252 * If the string is being read by the user process, it is copied
253 * and a newline '\n' is added. It is truncated if the buffer is
256 * Returns 0 on success.
258 int proc_dostring(struct ctl_table *table, int write,
259 void *buffer, size_t *lenp, loff_t *ppos)
262 proc_first_pos_non_zero_ignore(ppos, table);
264 return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
268 static size_t proc_skip_spaces(char **buf)
271 char *tmp = skip_spaces(*buf);
277 static void proc_skip_char(char **buf, size_t *size, const char v)
288 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
291 * @cp: kernel buffer containing the string to parse
292 * @endp: pointer to store the trailing characters
293 * @base: the base to use
294 * @res: where the parsed integer will be stored
296 * In case of success 0 is returned and @res will contain the parsed integer,
297 * @endp will hold any trailing characters.
298 * This function will fail the parse on overflow. If there wasn't an overflow
299 * the function will defer the decision what characters count as invalid to the
302 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
305 unsigned long long result;
308 cp = _parse_integer_fixup_radix(cp, &base);
309 rv = _parse_integer(cp, base, &result);
310 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
318 *res = (unsigned long)result;
324 * proc_get_long - reads an ASCII formatted integer from a user buffer
326 * @buf: a kernel buffer
327 * @size: size of the kernel buffer
328 * @val: this is where the number will be stored
329 * @neg: set to %TRUE if number is negative
330 * @perm_tr: a vector which contains the allowed trailers
331 * @perm_tr_len: size of the perm_tr vector
332 * @tr: pointer to store the trailer character
334 * In case of success %0 is returned and @buf and @size are updated with
335 * the amount of bytes read. If @tr is non-NULL and a trailing
336 * character exists (size is non-zero after returning from this
337 * function), @tr is updated with the trailing character.
339 static int proc_get_long(char **buf, size_t *size,
340 unsigned long *val, bool *neg,
341 const char *perm_tr, unsigned perm_tr_len, char *tr)
344 char *p, tmp[TMPBUFLEN];
350 if (len > TMPBUFLEN - 1)
353 memcpy(tmp, *buf, len);
357 if (*p == '-' && *size > 1) {
365 if (strtoul_lenient(p, &p, 0, val))
370 /* We don't know if the next char is whitespace thus we may accept
371 * invalid integers (e.g. 1234...a) or two integers instead of one
372 * (e.g. 123...1). So lets not allow such large numbers. */
373 if (len == TMPBUFLEN - 1)
376 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
379 if (tr && (len < *size))
389 * proc_put_long - converts an integer to a decimal ASCII formatted string
391 * @buf: the user buffer
392 * @size: the size of the user buffer
393 * @val: the integer to be converted
394 * @neg: sign of the number, %TRUE for negative
396 * In case of success @buf and @size are updated with the amount of bytes
399 static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
402 char tmp[TMPBUFLEN], *p = tmp;
404 sprintf(p, "%s%lu", neg ? "-" : "", val);
408 memcpy(*buf, tmp, len);
414 static void proc_put_char(void **buf, size_t *size, char c)
417 char **buffer = (char **)buf;
426 static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp,
428 int write, void *data)
431 *(bool *)valp = *lvalp;
433 int val = *(bool *)valp;
435 *lvalp = (unsigned long)val;
441 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
443 int write, void *data)
447 if (*lvalp > (unsigned long) INT_MAX + 1)
449 WRITE_ONCE(*valp, -*lvalp);
451 if (*lvalp > (unsigned long) INT_MAX)
453 WRITE_ONCE(*valp, *lvalp);
456 int val = READ_ONCE(*valp);
459 *lvalp = -(unsigned long)val;
462 *lvalp = (unsigned long)val;
468 static int do_proc_douintvec_conv(unsigned long *lvalp,
470 int write, void *data)
473 if (*lvalp > UINT_MAX)
475 WRITE_ONCE(*valp, *lvalp);
477 unsigned int val = READ_ONCE(*valp);
478 *lvalp = (unsigned long)val;
483 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
485 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
486 int write, void *buffer,
487 size_t *lenp, loff_t *ppos,
488 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
489 int write, void *data),
492 int *i, vleft, first = 1, err = 0;
496 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
501 i = (int *) tbl_data;
502 vleft = table->maxlen / sizeof(*i);
506 conv = do_proc_dointvec_conv;
509 if (proc_first_pos_non_zero_ignore(ppos, table))
512 if (left > PAGE_SIZE - 1)
513 left = PAGE_SIZE - 1;
517 for (; left && vleft--; i++, first=0) {
522 left -= proc_skip_spaces(&p);
526 err = proc_get_long(&p, &left, &lval, &neg,
528 sizeof(proc_wspace_sep), NULL);
531 if (conv(&neg, &lval, i, 1, data)) {
536 if (conv(&neg, &lval, i, 0, data)) {
541 proc_put_char(&buffer, &left, '\t');
542 proc_put_long(&buffer, &left, lval, neg);
546 if (!write && !first && left && !err)
547 proc_put_char(&buffer, &left, '\n');
548 if (write && !err && left)
549 left -= proc_skip_spaces(&p);
551 return err ? : -EINVAL;
558 static int do_proc_dointvec(struct ctl_table *table, int write,
559 void *buffer, size_t *lenp, loff_t *ppos,
560 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
561 int write, void *data),
564 return __do_proc_dointvec(table->data, table, write,
565 buffer, lenp, ppos, conv, data);
568 static int do_proc_douintvec_w(unsigned int *tbl_data,
569 struct ctl_table *table,
571 size_t *lenp, loff_t *ppos,
572 int (*conv)(unsigned long *lvalp,
574 int write, void *data),
585 if (proc_first_pos_non_zero_ignore(ppos, table))
588 if (left > PAGE_SIZE - 1)
589 left = PAGE_SIZE - 1;
591 left -= proc_skip_spaces(&p);
597 err = proc_get_long(&p, &left, &lval, &neg,
599 sizeof(proc_wspace_sep), NULL);
605 if (conv(&lval, tbl_data, 1, data)) {
611 left -= proc_skip_spaces(&p);
619 /* This is in keeping with old __do_proc_dointvec() */
625 static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
626 size_t *lenp, loff_t *ppos,
627 int (*conv)(unsigned long *lvalp,
629 int write, void *data),
638 if (conv(&lval, tbl_data, 0, data)) {
643 proc_put_long(&buffer, &left, lval, false);
647 proc_put_char(&buffer, &left, '\n');
656 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
657 int write, void *buffer,
658 size_t *lenp, loff_t *ppos,
659 int (*conv)(unsigned long *lvalp,
661 int write, void *data),
664 unsigned int *i, vleft;
666 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
671 i = (unsigned int *) tbl_data;
672 vleft = table->maxlen / sizeof(*i);
675 * Arrays are not supported, keep this simple. *Do not* add
684 conv = do_proc_douintvec_conv;
687 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
689 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
692 int do_proc_douintvec(struct ctl_table *table, int write,
693 void *buffer, size_t *lenp, loff_t *ppos,
694 int (*conv)(unsigned long *lvalp,
696 int write, void *data),
699 return __do_proc_douintvec(table->data, table, write,
700 buffer, lenp, ppos, conv, data);
704 * proc_dobool - read/write a bool
705 * @table: the sysctl table
706 * @write: %TRUE if this is a write to the sysctl file
707 * @buffer: the user buffer
708 * @lenp: the size of the user buffer
709 * @ppos: file position
711 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
712 * values from/to the user buffer, treated as an ASCII string.
714 * Returns 0 on success.
716 int proc_dobool(struct ctl_table *table, int write, void *buffer,
717 size_t *lenp, loff_t *ppos)
719 return do_proc_dointvec(table, write, buffer, lenp, ppos,
720 do_proc_dobool_conv, NULL);
724 * proc_dointvec - read a vector of integers
725 * @table: the sysctl table
726 * @write: %TRUE if this is a write to the sysctl file
727 * @buffer: the user buffer
728 * @lenp: the size of the user buffer
729 * @ppos: file position
731 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
732 * values from/to the user buffer, treated as an ASCII string.
734 * Returns 0 on success.
736 int proc_dointvec(struct ctl_table *table, int write, void *buffer,
737 size_t *lenp, loff_t *ppos)
739 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
742 #ifdef CONFIG_COMPACTION
743 static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
744 int write, void *buffer, size_t *lenp, loff_t *ppos)
748 if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
749 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
751 old = *(int *)table->data;
752 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
755 if (old != *(int *)table->data)
756 pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
757 table->procname, current->comm,
758 task_pid_nr(current));
764 * proc_douintvec - read a vector of unsigned integers
765 * @table: the sysctl table
766 * @write: %TRUE if this is a write to the sysctl file
767 * @buffer: the user buffer
768 * @lenp: the size of the user buffer
769 * @ppos: file position
771 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
772 * values from/to the user buffer, treated as an ASCII string.
774 * Returns 0 on success.
776 int proc_douintvec(struct ctl_table *table, int write, void *buffer,
777 size_t *lenp, loff_t *ppos)
779 return do_proc_douintvec(table, write, buffer, lenp, ppos,
780 do_proc_douintvec_conv, NULL);
784 * Taint values can only be increased
785 * This means we can safely use a temporary.
787 static int proc_taint(struct ctl_table *table, int write,
788 void *buffer, size_t *lenp, loff_t *ppos)
791 unsigned long tmptaint = get_taint();
794 if (write && !capable(CAP_SYS_ADMIN))
799 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
807 * If we are relying on panic_on_taint not producing
808 * false positives due to userspace input, bail out
809 * before setting the requested taint flags.
811 if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
815 * Poor man's atomic or. Not worth adding a primitive
816 * to everyone's atomic.h for this
818 for (i = 0; i < TAINT_FLAGS_COUNT; i++)
819 if ((1UL << i) & tmptaint)
820 add_taint(i, LOCKDEP_STILL_OK);
827 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
828 * @min: pointer to minimum allowable value
829 * @max: pointer to maximum allowable value
831 * The do_proc_dointvec_minmax_conv_param structure provides the
832 * minimum and maximum values for doing range checking for those sysctl
833 * parameters that use the proc_dointvec_minmax() handler.
835 struct do_proc_dointvec_minmax_conv_param {
840 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
842 int write, void *data)
845 struct do_proc_dointvec_minmax_conv_param *param = data;
847 * If writing, first do so via a temporary local int so we can
848 * bounds-check it before touching *valp.
850 int *ip = write ? &tmp : valp;
852 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
857 if ((param->min && *param->min > tmp) ||
858 (param->max && *param->max < tmp))
860 WRITE_ONCE(*valp, tmp);
867 * proc_dointvec_minmax - read a vector of integers with min/max values
868 * @table: the sysctl table
869 * @write: %TRUE if this is a write to the sysctl file
870 * @buffer: the user buffer
871 * @lenp: the size of the user buffer
872 * @ppos: file position
874 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
875 * values from/to the user buffer, treated as an ASCII string.
877 * This routine will ensure the values are within the range specified by
878 * table->extra1 (min) and table->extra2 (max).
880 * Returns 0 on success or -EINVAL on write when the range check fails.
882 int proc_dointvec_minmax(struct ctl_table *table, int write,
883 void *buffer, size_t *lenp, loff_t *ppos)
885 struct do_proc_dointvec_minmax_conv_param param = {
886 .min = (int *) table->extra1,
887 .max = (int *) table->extra2,
889 return do_proc_dointvec(table, write, buffer, lenp, ppos,
890 do_proc_dointvec_minmax_conv, ¶m);
894 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
895 * @min: pointer to minimum allowable value
896 * @max: pointer to maximum allowable value
898 * The do_proc_douintvec_minmax_conv_param structure provides the
899 * minimum and maximum values for doing range checking for those sysctl
900 * parameters that use the proc_douintvec_minmax() handler.
902 struct do_proc_douintvec_minmax_conv_param {
907 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
909 int write, void *data)
913 struct do_proc_douintvec_minmax_conv_param *param = data;
914 /* write via temporary local uint for bounds-checking */
915 unsigned int *up = write ? &tmp : valp;
917 ret = do_proc_douintvec_conv(lvalp, up, write, data);
922 if ((param->min && *param->min > tmp) ||
923 (param->max && *param->max < tmp))
926 WRITE_ONCE(*valp, tmp);
933 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
934 * @table: the sysctl table
935 * @write: %TRUE if this is a write to the sysctl file
936 * @buffer: the user buffer
937 * @lenp: the size of the user buffer
938 * @ppos: file position
940 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
941 * values from/to the user buffer, treated as an ASCII string. Negative
942 * strings are not allowed.
944 * This routine will ensure the values are within the range specified by
945 * table->extra1 (min) and table->extra2 (max). There is a final sanity
946 * check for UINT_MAX to avoid having to support wrap around uses from
949 * Returns 0 on success or -ERANGE on write when the range check fails.
951 int proc_douintvec_minmax(struct ctl_table *table, int write,
952 void *buffer, size_t *lenp, loff_t *ppos)
954 struct do_proc_douintvec_minmax_conv_param param = {
955 .min = (unsigned int *) table->extra1,
956 .max = (unsigned int *) table->extra2,
958 return do_proc_douintvec(table, write, buffer, lenp, ppos,
959 do_proc_douintvec_minmax_conv, ¶m);
963 * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
964 * @table: the sysctl table
965 * @write: %TRUE if this is a write to the sysctl file
966 * @buffer: the user buffer
967 * @lenp: the size of the user buffer
968 * @ppos: file position
970 * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
971 * values from/to the user buffer, treated as an ASCII string. Negative
972 * strings are not allowed.
974 * This routine will ensure the values are within the range specified by
975 * table->extra1 (min) and table->extra2 (max).
977 * Returns 0 on success or an error on write when the range check fails.
979 int proc_dou8vec_minmax(struct ctl_table *table, int write,
980 void *buffer, size_t *lenp, loff_t *ppos)
982 struct ctl_table tmp;
983 unsigned int min = 0, max = 255U, val;
984 u8 *data = table->data;
985 struct do_proc_douintvec_minmax_conv_param param = {
991 /* Do not support arrays yet. */
992 if (table->maxlen != sizeof(u8))
996 min = *(unsigned int *) table->extra1;
1000 if (table->extra2) {
1001 max = *(unsigned int *) table->extra2;
1008 tmp.maxlen = sizeof(val);
1010 val = READ_ONCE(*data);
1011 res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
1012 do_proc_douintvec_minmax_conv, ¶m);
1016 WRITE_ONCE(*data, val);
1019 EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
1021 #ifdef CONFIG_MAGIC_SYSRQ
1022 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
1023 void *buffer, size_t *lenp, loff_t *ppos)
1029 ret = __do_proc_dointvec(&tmp, table, write, buffer,
1030 lenp, ppos, NULL, NULL);
1035 sysrq_toggle_support(tmp);
1041 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
1042 int write, void *buffer, size_t *lenp, loff_t *ppos,
1043 unsigned long convmul, unsigned long convdiv)
1045 unsigned long *i, *min, *max;
1046 int vleft, first = 1, err = 0;
1050 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1055 i = (unsigned long *) data;
1056 min = (unsigned long *) table->extra1;
1057 max = (unsigned long *) table->extra2;
1058 vleft = table->maxlen / sizeof(unsigned long);
1062 if (proc_first_pos_non_zero_ignore(ppos, table))
1065 if (left > PAGE_SIZE - 1)
1066 left = PAGE_SIZE - 1;
1070 for (; left && vleft--; i++, first = 0) {
1076 left -= proc_skip_spaces(&p);
1080 err = proc_get_long(&p, &left, &val, &neg,
1082 sizeof(proc_wspace_sep), NULL);
1088 val = convmul * val / convdiv;
1089 if ((min && val < *min) || (max && val > *max)) {
1093 WRITE_ONCE(*i, val);
1095 val = convdiv * READ_ONCE(*i) / convmul;
1097 proc_put_char(&buffer, &left, '\t');
1098 proc_put_long(&buffer, &left, val, false);
1102 if (!write && !first && left && !err)
1103 proc_put_char(&buffer, &left, '\n');
1105 left -= proc_skip_spaces(&p);
1107 return err ? : -EINVAL;
1114 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
1115 void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1116 unsigned long convdiv)
1118 return __do_proc_doulongvec_minmax(table->data, table, write,
1119 buffer, lenp, ppos, convmul, convdiv);
1123 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1124 * @table: the sysctl table
1125 * @write: %TRUE if this is a write to the sysctl file
1126 * @buffer: the user buffer
1127 * @lenp: the size of the user buffer
1128 * @ppos: file position
1130 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1131 * values from/to the user buffer, treated as an ASCII string.
1133 * This routine will ensure the values are within the range specified by
1134 * table->extra1 (min) and table->extra2 (max).
1136 * Returns 0 on success.
1138 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1139 void *buffer, size_t *lenp, loff_t *ppos)
1141 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1145 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1146 * @table: the sysctl table
1147 * @write: %TRUE if this is a write to the sysctl file
1148 * @buffer: the user buffer
1149 * @lenp: the size of the user buffer
1150 * @ppos: file position
1152 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1153 * values from/to the user buffer, treated as an ASCII string. The values
1154 * are treated as milliseconds, and converted to jiffies when they are stored.
1156 * This routine will ensure the values are within the range specified by
1157 * table->extra1 (min) and table->extra2 (max).
1159 * Returns 0 on success.
1161 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1162 void *buffer, size_t *lenp, loff_t *ppos)
1164 return do_proc_doulongvec_minmax(table, write, buffer,
1165 lenp, ppos, HZ, 1000l);
1169 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1171 int write, void *data)
1174 if (*lvalp > INT_MAX / HZ)
1177 WRITE_ONCE(*valp, -*lvalp * HZ);
1179 WRITE_ONCE(*valp, *lvalp * HZ);
1181 int val = READ_ONCE(*valp);
1185 lval = -(unsigned long)val;
1188 lval = (unsigned long)val;
1195 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1197 int write, void *data)
1200 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1202 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1208 lval = -(unsigned long)val;
1211 lval = (unsigned long)val;
1213 *lvalp = jiffies_to_clock_t(lval);
1218 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1220 int write, void *data)
1223 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1227 WRITE_ONCE(*valp, (int)jif);
1229 int val = READ_ONCE(*valp);
1233 lval = -(unsigned long)val;
1236 lval = (unsigned long)val;
1238 *lvalp = jiffies_to_msecs(lval);
1243 static int do_proc_dointvec_ms_jiffies_minmax_conv(bool *negp, unsigned long *lvalp,
1244 int *valp, int write, void *data)
1247 struct do_proc_dointvec_minmax_conv_param *param = data;
1249 * If writing, first do so via a temporary local int so we can
1250 * bounds-check it before touching *valp.
1252 int *ip = write ? &tmp : valp;
1254 ret = do_proc_dointvec_ms_jiffies_conv(negp, lvalp, ip, write, data);
1259 if ((param->min && *param->min > tmp) ||
1260 (param->max && *param->max < tmp))
1268 * proc_dointvec_jiffies - read a vector of integers as seconds
1269 * @table: the sysctl table
1270 * @write: %TRUE if this is a write to the sysctl file
1271 * @buffer: the user buffer
1272 * @lenp: the size of the user buffer
1273 * @ppos: file position
1275 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1276 * values from/to the user buffer, treated as an ASCII string.
1277 * The values read are assumed to be in seconds, and are converted into
1280 * Returns 0 on success.
1282 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1283 void *buffer, size_t *lenp, loff_t *ppos)
1285 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1286 do_proc_dointvec_jiffies_conv,NULL);
1289 int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1290 void *buffer, size_t *lenp, loff_t *ppos)
1292 struct do_proc_dointvec_minmax_conv_param param = {
1293 .min = (int *) table->extra1,
1294 .max = (int *) table->extra2,
1296 return do_proc_dointvec(table, write, buffer, lenp, ppos,
1297 do_proc_dointvec_ms_jiffies_minmax_conv, ¶m);
1301 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1302 * @table: the sysctl table
1303 * @write: %TRUE if this is a write to the sysctl file
1304 * @buffer: the user buffer
1305 * @lenp: the size of the user buffer
1306 * @ppos: pointer to the file position
1308 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1309 * values from/to the user buffer, treated as an ASCII string.
1310 * The values read are assumed to be in 1/USER_HZ seconds, and
1311 * are converted into jiffies.
1313 * Returns 0 on success.
1315 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1316 void *buffer, size_t *lenp, loff_t *ppos)
1318 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1319 do_proc_dointvec_userhz_jiffies_conv,NULL);
1323 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1324 * @table: the sysctl table
1325 * @write: %TRUE if this is a write to the sysctl file
1326 * @buffer: the user buffer
1327 * @lenp: the size of the user buffer
1328 * @ppos: file position
1329 * @ppos: the current position in the file
1331 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1332 * values from/to the user buffer, treated as an ASCII string.
1333 * The values read are assumed to be in 1/1000 seconds, and
1334 * are converted into jiffies.
1336 * Returns 0 on success.
1338 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
1339 size_t *lenp, loff_t *ppos)
1341 return do_proc_dointvec(table, write, buffer, lenp, ppos,
1342 do_proc_dointvec_ms_jiffies_conv, NULL);
1345 static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
1346 size_t *lenp, loff_t *ppos)
1348 struct pid *new_pid;
1352 tmp = pid_vnr(cad_pid);
1354 r = __do_proc_dointvec(&tmp, table, write, buffer,
1355 lenp, ppos, NULL, NULL);
1359 new_pid = find_get_pid(tmp);
1363 put_pid(xchg(&cad_pid, new_pid));
1368 * proc_do_large_bitmap - read/write from/to a large bitmap
1369 * @table: the sysctl table
1370 * @write: %TRUE if this is a write to the sysctl file
1371 * @buffer: the user buffer
1372 * @lenp: the size of the user buffer
1373 * @ppos: file position
1375 * The bitmap is stored at table->data and the bitmap length (in bits)
1378 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1379 * large bitmaps may be represented in a compact manner. Writing into
1380 * the file will clear the bitmap then update it with the given input.
1382 * Returns 0 on success.
1384 int proc_do_large_bitmap(struct ctl_table *table, int write,
1385 void *buffer, size_t *lenp, loff_t *ppos)
1388 size_t left = *lenp;
1389 unsigned long bitmap_len = table->maxlen;
1390 unsigned long *bitmap = *(unsigned long **) table->data;
1391 unsigned long *tmp_bitmap = NULL;
1392 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1394 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1403 if (left > PAGE_SIZE - 1) {
1404 left = PAGE_SIZE - 1;
1405 /* How much of the buffer we'll skip this pass */
1406 skipped = *lenp - left;
1409 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
1412 proc_skip_char(&p, &left, '\n');
1413 while (!err && left) {
1414 unsigned long val_a, val_b;
1418 /* In case we stop parsing mid-number, we can reset */
1420 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1423 * If we consumed the entirety of a truncated buffer or
1424 * only one char is left (may be a "-"), then stop here,
1425 * reset, & come back for more.
1427 if ((left <= 1) && skipped) {
1434 if (val_a >= bitmap_len || neg) {
1446 err = proc_get_long(&p, &left, &val_b,
1447 &neg, tr_b, sizeof(tr_b),
1450 * If we consumed all of a truncated buffer or
1451 * then stop here, reset, & come back for more.
1453 if (!left && skipped) {
1460 if (val_b >= bitmap_len || neg ||
1471 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1472 proc_skip_char(&p, &left, '\n');
1476 unsigned long bit_a, bit_b = 0;
1480 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1481 if (bit_a >= bitmap_len)
1483 bit_b = find_next_zero_bit(bitmap, bitmap_len,
1487 proc_put_char(&buffer, &left, ',');
1488 proc_put_long(&buffer, &left, bit_a, false);
1489 if (bit_a != bit_b) {
1490 proc_put_char(&buffer, &left, '-');
1491 proc_put_long(&buffer, &left, bit_b, false);
1496 proc_put_char(&buffer, &left, '\n');
1502 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1504 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1510 bitmap_free(tmp_bitmap);
1514 #else /* CONFIG_PROC_SYSCTL */
1516 int proc_dostring(struct ctl_table *table, int write,
1517 void *buffer, size_t *lenp, loff_t *ppos)
1522 int proc_dobool(struct ctl_table *table, int write,
1523 void *buffer, size_t *lenp, loff_t *ppos)
1528 int proc_dointvec(struct ctl_table *table, int write,
1529 void *buffer, size_t *lenp, loff_t *ppos)
1534 int proc_douintvec(struct ctl_table *table, int write,
1535 void *buffer, size_t *lenp, loff_t *ppos)
1540 int proc_dointvec_minmax(struct ctl_table *table, int write,
1541 void *buffer, size_t *lenp, loff_t *ppos)
1546 int proc_douintvec_minmax(struct ctl_table *table, int write,
1547 void *buffer, size_t *lenp, loff_t *ppos)
1552 int proc_dou8vec_minmax(struct ctl_table *table, int write,
1553 void *buffer, size_t *lenp, loff_t *ppos)
1558 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1559 void *buffer, size_t *lenp, loff_t *ppos)
1564 int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1565 void *buffer, size_t *lenp, loff_t *ppos)
1570 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1571 void *buffer, size_t *lenp, loff_t *ppos)
1576 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1577 void *buffer, size_t *lenp, loff_t *ppos)
1582 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1583 void *buffer, size_t *lenp, loff_t *ppos)
1588 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1589 void *buffer, size_t *lenp, loff_t *ppos)
1594 int proc_do_large_bitmap(struct ctl_table *table, int write,
1595 void *buffer, size_t *lenp, loff_t *ppos)
1600 #endif /* CONFIG_PROC_SYSCTL */
1602 #if defined(CONFIG_SYSCTL)
1603 int proc_do_static_key(struct ctl_table *table, int write,
1604 void *buffer, size_t *lenp, loff_t *ppos)
1606 struct static_key *key = (struct static_key *)table->data;
1607 static DEFINE_MUTEX(static_key_mutex);
1609 struct ctl_table tmp = {
1611 .maxlen = sizeof(val),
1612 .mode = table->mode,
1613 .extra1 = SYSCTL_ZERO,
1614 .extra2 = SYSCTL_ONE,
1617 if (write && !capable(CAP_SYS_ADMIN))
1620 mutex_lock(&static_key_mutex);
1621 val = static_key_enabled(key);
1622 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1623 if (write && !ret) {
1625 static_key_enable(key);
1627 static_key_disable(key);
1629 mutex_unlock(&static_key_mutex);
1633 static struct ctl_table kern_table[] = {
1634 #ifdef CONFIG_NUMA_BALANCING
1636 .procname = "numa_balancing",
1637 .data = NULL, /* filled in by handler */
1638 .maxlen = sizeof(unsigned int),
1640 .proc_handler = sysctl_numa_balancing,
1641 .extra1 = SYSCTL_ZERO,
1642 .extra2 = SYSCTL_FOUR,
1644 #endif /* CONFIG_NUMA_BALANCING */
1646 .procname = "panic",
1647 .data = &panic_timeout,
1648 .maxlen = sizeof(int),
1650 .proc_handler = proc_dointvec,
1652 #ifdef CONFIG_PROC_SYSCTL
1654 .procname = "tainted",
1655 .maxlen = sizeof(long),
1657 .proc_handler = proc_taint,
1660 .procname = "sysctl_writes_strict",
1661 .data = &sysctl_writes_strict,
1662 .maxlen = sizeof(int),
1664 .proc_handler = proc_dointvec_minmax,
1665 .extra1 = SYSCTL_NEG_ONE,
1666 .extra2 = SYSCTL_ONE,
1670 .procname = "print-fatal-signals",
1671 .data = &print_fatal_signals,
1672 .maxlen = sizeof(int),
1674 .proc_handler = proc_dointvec,
1678 .procname = "reboot-cmd",
1679 .data = reboot_command,
1682 .proc_handler = proc_dostring,
1685 .procname = "stop-a",
1686 .data = &stop_a_enabled,
1687 .maxlen = sizeof (int),
1689 .proc_handler = proc_dointvec,
1692 .procname = "scons-poweroff",
1693 .data = &scons_pwroff,
1694 .maxlen = sizeof (int),
1696 .proc_handler = proc_dointvec,
1699 #ifdef CONFIG_SPARC64
1701 .procname = "tsb-ratio",
1702 .data = &sysctl_tsb_ratio,
1703 .maxlen = sizeof (int),
1705 .proc_handler = proc_dointvec,
1708 #ifdef CONFIG_PARISC
1710 .procname = "soft-power",
1711 .data = &pwrsw_enabled,
1712 .maxlen = sizeof (int),
1714 .proc_handler = proc_dointvec,
1717 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
1719 .procname = "unaligned-trap",
1720 .data = &unaligned_enabled,
1721 .maxlen = sizeof (int),
1723 .proc_handler = proc_dointvec,
1726 #ifdef CONFIG_STACK_TRACER
1728 .procname = "stack_tracer_enabled",
1729 .data = &stack_tracer_enabled,
1730 .maxlen = sizeof(int),
1732 .proc_handler = stack_trace_sysctl,
1735 #ifdef CONFIG_TRACING
1737 .procname = "ftrace_dump_on_oops",
1738 .data = &ftrace_dump_on_oops,
1739 .maxlen = sizeof(int),
1741 .proc_handler = proc_dointvec,
1744 .procname = "traceoff_on_warning",
1745 .data = &__disable_trace_on_warning,
1746 .maxlen = sizeof(__disable_trace_on_warning),
1748 .proc_handler = proc_dointvec,
1751 .procname = "tracepoint_printk",
1752 .data = &tracepoint_printk,
1753 .maxlen = sizeof(tracepoint_printk),
1755 .proc_handler = tracepoint_printk_sysctl,
1758 #ifdef CONFIG_MODULES
1760 .procname = "modprobe",
1761 .data = &modprobe_path,
1762 .maxlen = KMOD_PATH_LEN,
1764 .proc_handler = proc_dostring,
1767 .procname = "modules_disabled",
1768 .data = &modules_disabled,
1769 .maxlen = sizeof(int),
1771 /* only handle a transition from default "0" to "1" */
1772 .proc_handler = proc_dointvec_minmax,
1773 .extra1 = SYSCTL_ONE,
1774 .extra2 = SYSCTL_ONE,
1777 #ifdef CONFIG_UEVENT_HELPER
1779 .procname = "hotplug",
1780 .data = &uevent_helper,
1781 .maxlen = UEVENT_HELPER_PATH_LEN,
1783 .proc_handler = proc_dostring,
1786 #ifdef CONFIG_MAGIC_SYSRQ
1788 .procname = "sysrq",
1790 .maxlen = sizeof (int),
1792 .proc_handler = sysrq_sysctl_handler,
1795 #ifdef CONFIG_PROC_SYSCTL
1797 .procname = "cad_pid",
1799 .maxlen = sizeof (int),
1801 .proc_handler = proc_do_cad_pid,
1805 .procname = "threads-max",
1807 .maxlen = sizeof(int),
1809 .proc_handler = sysctl_max_threads,
1812 .procname = "usermodehelper",
1814 .child = usermodehelper_table,
1817 .procname = "overflowuid",
1818 .data = &overflowuid,
1819 .maxlen = sizeof(int),
1821 .proc_handler = proc_dointvec_minmax,
1822 .extra1 = SYSCTL_ZERO,
1823 .extra2 = SYSCTL_MAXOLDUID,
1826 .procname = "overflowgid",
1827 .data = &overflowgid,
1828 .maxlen = sizeof(int),
1830 .proc_handler = proc_dointvec_minmax,
1831 .extra1 = SYSCTL_ZERO,
1832 .extra2 = SYSCTL_MAXOLDUID,
1836 .procname = "userprocess_debug",
1837 .data = &show_unhandled_signals,
1838 .maxlen = sizeof(int),
1840 .proc_handler = proc_dointvec,
1844 .procname = "pid_max",
1846 .maxlen = sizeof (int),
1848 .proc_handler = proc_dointvec_minmax,
1849 .extra1 = &pid_max_min,
1850 .extra2 = &pid_max_max,
1853 .procname = "panic_on_oops",
1854 .data = &panic_on_oops,
1855 .maxlen = sizeof(int),
1857 .proc_handler = proc_dointvec,
1860 .procname = "panic_print",
1861 .data = &panic_print,
1862 .maxlen = sizeof(unsigned long),
1864 .proc_handler = proc_doulongvec_minmax,
1867 .procname = "ngroups_max",
1868 .data = (void *)&ngroups_max,
1869 .maxlen = sizeof (int),
1871 .proc_handler = proc_dointvec,
1874 .procname = "cap_last_cap",
1875 .data = (void *)&cap_last_cap,
1876 .maxlen = sizeof(int),
1878 .proc_handler = proc_dointvec,
1880 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1882 .procname = "unknown_nmi_panic",
1883 .data = &unknown_nmi_panic,
1884 .maxlen = sizeof (int),
1886 .proc_handler = proc_dointvec,
1890 #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
1891 defined(CONFIG_DEBUG_STACKOVERFLOW)
1893 .procname = "panic_on_stackoverflow",
1894 .data = &sysctl_panic_on_stackoverflow,
1895 .maxlen = sizeof(int),
1897 .proc_handler = proc_dointvec,
1900 #if defined(CONFIG_X86)
1902 .procname = "panic_on_unrecovered_nmi",
1903 .data = &panic_on_unrecovered_nmi,
1904 .maxlen = sizeof(int),
1906 .proc_handler = proc_dointvec,
1909 .procname = "panic_on_io_nmi",
1910 .data = &panic_on_io_nmi,
1911 .maxlen = sizeof(int),
1913 .proc_handler = proc_dointvec,
1916 .procname = "bootloader_type",
1917 .data = &bootloader_type,
1918 .maxlen = sizeof (int),
1920 .proc_handler = proc_dointvec,
1923 .procname = "bootloader_version",
1924 .data = &bootloader_version,
1925 .maxlen = sizeof (int),
1927 .proc_handler = proc_dointvec,
1930 .procname = "io_delay_type",
1931 .data = &io_delay_type,
1932 .maxlen = sizeof(int),
1934 .proc_handler = proc_dointvec,
1937 #if defined(CONFIG_MMU)
1939 .procname = "randomize_va_space",
1940 .data = &randomize_va_space,
1941 .maxlen = sizeof(int),
1943 .proc_handler = proc_dointvec,
1946 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1948 .procname = "spin_retry",
1949 .data = &spin_retry,
1950 .maxlen = sizeof (int),
1952 .proc_handler = proc_dointvec,
1955 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1957 .procname = "acpi_video_flags",
1958 .data = &acpi_realmode_flags,
1959 .maxlen = sizeof (unsigned long),
1961 .proc_handler = proc_doulongvec_minmax,
1964 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1966 .procname = "ignore-unaligned-usertrap",
1967 .data = &no_unaligned_warning,
1968 .maxlen = sizeof (int),
1970 .proc_handler = proc_dointvec,
1975 .procname = "unaligned-dump-stack",
1976 .data = &unaligned_dump_stack,
1977 .maxlen = sizeof (int),
1979 .proc_handler = proc_dointvec,
1982 #ifdef CONFIG_RT_MUTEXES
1984 .procname = "max_lock_depth",
1985 .data = &max_lock_depth,
1986 .maxlen = sizeof(int),
1988 .proc_handler = proc_dointvec,
1995 .child = key_sysctls,
1998 #ifdef CONFIG_PERF_EVENTS
2000 * User-space scripts rely on the existence of this file
2001 * as a feature check for perf_events being enabled.
2003 * So it's an ABI, do not remove!
2006 .procname = "perf_event_paranoid",
2007 .data = &sysctl_perf_event_paranoid,
2008 .maxlen = sizeof(sysctl_perf_event_paranoid),
2010 .proc_handler = proc_dointvec,
2013 .procname = "perf_event_mlock_kb",
2014 .data = &sysctl_perf_event_mlock,
2015 .maxlen = sizeof(sysctl_perf_event_mlock),
2017 .proc_handler = proc_dointvec,
2020 .procname = "perf_event_max_sample_rate",
2021 .data = &sysctl_perf_event_sample_rate,
2022 .maxlen = sizeof(sysctl_perf_event_sample_rate),
2024 .proc_handler = perf_proc_update_handler,
2025 .extra1 = SYSCTL_ONE,
2028 .procname = "perf_cpu_time_max_percent",
2029 .data = &sysctl_perf_cpu_time_max_percent,
2030 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
2032 .proc_handler = perf_cpu_time_max_percent_handler,
2033 .extra1 = SYSCTL_ZERO,
2034 .extra2 = SYSCTL_ONE_HUNDRED,
2037 .procname = "perf_event_max_stack",
2038 .data = &sysctl_perf_event_max_stack,
2039 .maxlen = sizeof(sysctl_perf_event_max_stack),
2041 .proc_handler = perf_event_max_stack_handler,
2042 .extra1 = SYSCTL_ZERO,
2043 .extra2 = (void *)&six_hundred_forty_kb,
2046 .procname = "perf_event_max_contexts_per_stack",
2047 .data = &sysctl_perf_event_max_contexts_per_stack,
2048 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
2050 .proc_handler = perf_event_max_stack_handler,
2051 .extra1 = SYSCTL_ZERO,
2052 .extra2 = SYSCTL_ONE_THOUSAND,
2056 .procname = "panic_on_warn",
2057 .data = &panic_on_warn,
2058 .maxlen = sizeof(int),
2060 .proc_handler = proc_dointvec_minmax,
2061 .extra1 = SYSCTL_ZERO,
2062 .extra2 = SYSCTL_ONE,
2064 #if defined(CONFIG_TREE_RCU)
2066 .procname = "panic_on_rcu_stall",
2067 .data = &sysctl_panic_on_rcu_stall,
2068 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
2070 .proc_handler = proc_dointvec_minmax,
2071 .extra1 = SYSCTL_ZERO,
2072 .extra2 = SYSCTL_ONE,
2075 #if defined(CONFIG_TREE_RCU)
2077 .procname = "max_rcu_stall_to_panic",
2078 .data = &sysctl_max_rcu_stall_to_panic,
2079 .maxlen = sizeof(sysctl_max_rcu_stall_to_panic),
2081 .proc_handler = proc_dointvec_minmax,
2082 .extra1 = SYSCTL_ONE,
2083 .extra2 = SYSCTL_INT_MAX,
2089 static struct ctl_table vm_table[] = {
2091 .procname = "overcommit_memory",
2092 .data = &sysctl_overcommit_memory,
2093 .maxlen = sizeof(sysctl_overcommit_memory),
2095 .proc_handler = overcommit_policy_handler,
2096 .extra1 = SYSCTL_ZERO,
2097 .extra2 = SYSCTL_TWO,
2100 .procname = "overcommit_ratio",
2101 .data = &sysctl_overcommit_ratio,
2102 .maxlen = sizeof(sysctl_overcommit_ratio),
2104 .proc_handler = overcommit_ratio_handler,
2107 .procname = "overcommit_kbytes",
2108 .data = &sysctl_overcommit_kbytes,
2109 .maxlen = sizeof(sysctl_overcommit_kbytes),
2111 .proc_handler = overcommit_kbytes_handler,
2114 .procname = "page-cluster",
2115 .data = &page_cluster,
2116 .maxlen = sizeof(int),
2118 .proc_handler = proc_dointvec_minmax,
2119 .extra1 = SYSCTL_ZERO,
2122 .procname = "dirtytime_expire_seconds",
2123 .data = &dirtytime_expire_interval,
2124 .maxlen = sizeof(dirtytime_expire_interval),
2126 .proc_handler = dirtytime_interval_handler,
2127 .extra1 = SYSCTL_ZERO,
2130 .procname = "swappiness",
2131 .data = &vm_swappiness,
2132 .maxlen = sizeof(vm_swappiness),
2134 .proc_handler = proc_dointvec_minmax,
2135 .extra1 = SYSCTL_ZERO,
2136 .extra2 = SYSCTL_TWO_HUNDRED,
2140 .procname = "numa_stat",
2141 .data = &sysctl_vm_numa_stat,
2142 .maxlen = sizeof(int),
2144 .proc_handler = sysctl_vm_numa_stat_handler,
2145 .extra1 = SYSCTL_ZERO,
2146 .extra2 = SYSCTL_ONE,
2149 #ifdef CONFIG_HUGETLB_PAGE
2151 .procname = "nr_hugepages",
2153 .maxlen = sizeof(unsigned long),
2155 .proc_handler = hugetlb_sysctl_handler,
2159 .procname = "nr_hugepages_mempolicy",
2161 .maxlen = sizeof(unsigned long),
2163 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
2167 .procname = "hugetlb_shm_group",
2168 .data = &sysctl_hugetlb_shm_group,
2169 .maxlen = sizeof(gid_t),
2171 .proc_handler = proc_dointvec,
2174 .procname = "nr_overcommit_hugepages",
2176 .maxlen = sizeof(unsigned long),
2178 .proc_handler = hugetlb_overcommit_handler,
2182 .procname = "lowmem_reserve_ratio",
2183 .data = &sysctl_lowmem_reserve_ratio,
2184 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
2186 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
2189 .procname = "drop_caches",
2190 .data = &sysctl_drop_caches,
2191 .maxlen = sizeof(int),
2193 .proc_handler = drop_caches_sysctl_handler,
2194 .extra1 = SYSCTL_ONE,
2195 .extra2 = SYSCTL_FOUR,
2197 #ifdef CONFIG_COMPACTION
2199 .procname = "compact_memory",
2201 .maxlen = sizeof(int),
2203 .proc_handler = sysctl_compaction_handler,
2206 .procname = "compaction_proactiveness",
2207 .data = &sysctl_compaction_proactiveness,
2208 .maxlen = sizeof(sysctl_compaction_proactiveness),
2210 .proc_handler = compaction_proactiveness_sysctl_handler,
2211 .extra1 = SYSCTL_ZERO,
2212 .extra2 = SYSCTL_ONE_HUNDRED,
2215 .procname = "extfrag_threshold",
2216 .data = &sysctl_extfrag_threshold,
2217 .maxlen = sizeof(int),
2219 .proc_handler = proc_dointvec_minmax,
2220 .extra1 = SYSCTL_ZERO,
2221 .extra2 = (void *)&max_extfrag_threshold,
2224 .procname = "compact_unevictable_allowed",
2225 .data = &sysctl_compact_unevictable_allowed,
2226 .maxlen = sizeof(int),
2228 .proc_handler = proc_dointvec_minmax_warn_RT_change,
2229 .extra1 = SYSCTL_ZERO,
2230 .extra2 = SYSCTL_ONE,
2233 #endif /* CONFIG_COMPACTION */
2235 .procname = "min_free_kbytes",
2236 .data = &min_free_kbytes,
2237 .maxlen = sizeof(min_free_kbytes),
2239 .proc_handler = min_free_kbytes_sysctl_handler,
2240 .extra1 = SYSCTL_ZERO,
2243 .procname = "watermark_boost_factor",
2244 .data = &watermark_boost_factor,
2245 .maxlen = sizeof(watermark_boost_factor),
2247 .proc_handler = proc_dointvec_minmax,
2248 .extra1 = SYSCTL_ZERO,
2251 .procname = "watermark_scale_factor",
2252 .data = &watermark_scale_factor,
2253 .maxlen = sizeof(watermark_scale_factor),
2255 .proc_handler = watermark_scale_factor_sysctl_handler,
2256 .extra1 = SYSCTL_ONE,
2257 .extra2 = SYSCTL_THREE_THOUSAND,
2260 .procname = "percpu_pagelist_high_fraction",
2261 .data = &percpu_pagelist_high_fraction,
2262 .maxlen = sizeof(percpu_pagelist_high_fraction),
2264 .proc_handler = percpu_pagelist_high_fraction_sysctl_handler,
2265 .extra1 = SYSCTL_ZERO,
2268 .procname = "page_lock_unfairness",
2269 .data = &sysctl_page_lock_unfairness,
2270 .maxlen = sizeof(sysctl_page_lock_unfairness),
2272 .proc_handler = proc_dointvec_minmax,
2273 .extra1 = SYSCTL_ZERO,
2277 .procname = "max_map_count",
2278 .data = &sysctl_max_map_count,
2279 .maxlen = sizeof(sysctl_max_map_count),
2281 .proc_handler = proc_dointvec_minmax,
2282 .extra1 = SYSCTL_ZERO,
2286 .procname = "nr_trim_pages",
2287 .data = &sysctl_nr_trim_pages,
2288 .maxlen = sizeof(sysctl_nr_trim_pages),
2290 .proc_handler = proc_dointvec_minmax,
2291 .extra1 = SYSCTL_ZERO,
2295 .procname = "vfs_cache_pressure",
2296 .data = &sysctl_vfs_cache_pressure,
2297 .maxlen = sizeof(sysctl_vfs_cache_pressure),
2299 .proc_handler = proc_dointvec_minmax,
2300 .extra1 = SYSCTL_ZERO,
2302 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
2303 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
2305 .procname = "legacy_va_layout",
2306 .data = &sysctl_legacy_va_layout,
2307 .maxlen = sizeof(sysctl_legacy_va_layout),
2309 .proc_handler = proc_dointvec_minmax,
2310 .extra1 = SYSCTL_ZERO,
2315 .procname = "zone_reclaim_mode",
2316 .data = &node_reclaim_mode,
2317 .maxlen = sizeof(node_reclaim_mode),
2319 .proc_handler = proc_dointvec_minmax,
2320 .extra1 = SYSCTL_ZERO,
2323 .procname = "min_unmapped_ratio",
2324 .data = &sysctl_min_unmapped_ratio,
2325 .maxlen = sizeof(sysctl_min_unmapped_ratio),
2327 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
2328 .extra1 = SYSCTL_ZERO,
2329 .extra2 = SYSCTL_ONE_HUNDRED,
2332 .procname = "min_slab_ratio",
2333 .data = &sysctl_min_slab_ratio,
2334 .maxlen = sizeof(sysctl_min_slab_ratio),
2336 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
2337 .extra1 = SYSCTL_ZERO,
2338 .extra2 = SYSCTL_ONE_HUNDRED,
2343 .procname = "stat_interval",
2344 .data = &sysctl_stat_interval,
2345 .maxlen = sizeof(sysctl_stat_interval),
2347 .proc_handler = proc_dointvec_jiffies,
2350 .procname = "stat_refresh",
2354 .proc_handler = vmstat_refresh,
2359 .procname = "mmap_min_addr",
2360 .data = &dac_mmap_min_addr,
2361 .maxlen = sizeof(unsigned long),
2363 .proc_handler = mmap_min_addr_handler,
2368 .procname = "numa_zonelist_order",
2369 .data = &numa_zonelist_order,
2370 .maxlen = NUMA_ZONELIST_ORDER_LEN,
2372 .proc_handler = numa_zonelist_order_handler,
2375 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
2376 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
2378 .procname = "vdso_enabled",
2379 #ifdef CONFIG_X86_32
2380 .data = &vdso32_enabled,
2381 .maxlen = sizeof(vdso32_enabled),
2383 .data = &vdso_enabled,
2384 .maxlen = sizeof(vdso_enabled),
2387 .proc_handler = proc_dointvec,
2388 .extra1 = SYSCTL_ZERO,
2391 #ifdef CONFIG_MEMORY_FAILURE
2393 .procname = "memory_failure_early_kill",
2394 .data = &sysctl_memory_failure_early_kill,
2395 .maxlen = sizeof(sysctl_memory_failure_early_kill),
2397 .proc_handler = proc_dointvec_minmax,
2398 .extra1 = SYSCTL_ZERO,
2399 .extra2 = SYSCTL_ONE,
2402 .procname = "memory_failure_recovery",
2403 .data = &sysctl_memory_failure_recovery,
2404 .maxlen = sizeof(sysctl_memory_failure_recovery),
2406 .proc_handler = proc_dointvec_minmax,
2407 .extra1 = SYSCTL_ZERO,
2408 .extra2 = SYSCTL_ONE,
2412 .procname = "user_reserve_kbytes",
2413 .data = &sysctl_user_reserve_kbytes,
2414 .maxlen = sizeof(sysctl_user_reserve_kbytes),
2416 .proc_handler = proc_doulongvec_minmax,
2419 .procname = "admin_reserve_kbytes",
2420 .data = &sysctl_admin_reserve_kbytes,
2421 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
2423 .proc_handler = proc_doulongvec_minmax,
2425 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
2427 .procname = "mmap_rnd_bits",
2428 .data = &mmap_rnd_bits,
2429 .maxlen = sizeof(mmap_rnd_bits),
2431 .proc_handler = proc_dointvec_minmax,
2432 .extra1 = (void *)&mmap_rnd_bits_min,
2433 .extra2 = (void *)&mmap_rnd_bits_max,
2436 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
2438 .procname = "mmap_rnd_compat_bits",
2439 .data = &mmap_rnd_compat_bits,
2440 .maxlen = sizeof(mmap_rnd_compat_bits),
2442 .proc_handler = proc_dointvec_minmax,
2443 .extra1 = (void *)&mmap_rnd_compat_bits_min,
2444 .extra2 = (void *)&mmap_rnd_compat_bits_max,
2447 #ifdef CONFIG_USERFAULTFD
2449 .procname = "unprivileged_userfaultfd",
2450 .data = &sysctl_unprivileged_userfaultfd,
2451 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
2453 .proc_handler = proc_dointvec_minmax,
2454 .extra1 = SYSCTL_ZERO,
2455 .extra2 = SYSCTL_ONE,
2461 static struct ctl_table debug_table[] = {
2462 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
2464 .procname = "exception-trace",
2465 .data = &show_unhandled_signals,
2466 .maxlen = sizeof(int),
2468 .proc_handler = proc_dointvec
2474 static struct ctl_table dev_table[] = {
2478 DECLARE_SYSCTL_BASE(kernel, kern_table);
2479 DECLARE_SYSCTL_BASE(vm, vm_table);
2480 DECLARE_SYSCTL_BASE(debug, debug_table);
2481 DECLARE_SYSCTL_BASE(dev, dev_table);
2483 int __init sysctl_init_bases(void)
2485 register_sysctl_base(kernel);
2486 register_sysctl_base(vm);
2487 register_sysctl_base(debug);
2488 register_sysctl_base(dev);
2492 #endif /* CONFIG_SYSCTL */
2494 * No sense putting this after each symbol definition, twice,
2495 * exception granted :-)
2497 EXPORT_SYMBOL(proc_dobool);
2498 EXPORT_SYMBOL(proc_dointvec);
2499 EXPORT_SYMBOL(proc_douintvec);
2500 EXPORT_SYMBOL(proc_dointvec_jiffies);
2501 EXPORT_SYMBOL(proc_dointvec_minmax);
2502 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
2503 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2504 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2505 EXPORT_SYMBOL(proc_dostring);
2506 EXPORT_SYMBOL(proc_doulongvec_minmax);
2507 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2508 EXPORT_SYMBOL(proc_do_large_bitmap);