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)
451 if (*lvalp > (unsigned long) INT_MAX)
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)
477 unsigned int val = *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))
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))
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);
1011 res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
1012 do_proc_douintvec_minmax_conv, ¶m);
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)) {
1095 val = convdiv * (*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)
1176 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1182 lval = -(unsigned long)val;
1185 lval = (unsigned long)val;
1192 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1194 int write, void *data)
1197 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1199 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1205 lval = -(unsigned long)val;
1208 lval = (unsigned long)val;
1210 *lvalp = jiffies_to_clock_t(lval);
1215 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1217 int write, void *data)
1220 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1230 lval = -(unsigned long)val;
1233 lval = (unsigned long)val;
1235 *lvalp = jiffies_to_msecs(lval);
1241 * proc_dointvec_jiffies - read a vector of integers as seconds
1242 * @table: the sysctl table
1243 * @write: %TRUE if this is a write to the sysctl file
1244 * @buffer: the user buffer
1245 * @lenp: the size of the user buffer
1246 * @ppos: file position
1248 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1249 * values from/to the user buffer, treated as an ASCII string.
1250 * The values read are assumed to be in seconds, and are converted into
1253 * Returns 0 on success.
1255 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1256 void *buffer, size_t *lenp, loff_t *ppos)
1258 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1259 do_proc_dointvec_jiffies_conv,NULL);
1263 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1264 * @table: the sysctl table
1265 * @write: %TRUE if this is a write to the sysctl file
1266 * @buffer: the user buffer
1267 * @lenp: the size of the user buffer
1268 * @ppos: pointer to the file position
1270 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1271 * values from/to the user buffer, treated as an ASCII string.
1272 * The values read are assumed to be in 1/USER_HZ seconds, and
1273 * are converted into jiffies.
1275 * Returns 0 on success.
1277 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1278 void *buffer, size_t *lenp, loff_t *ppos)
1280 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1281 do_proc_dointvec_userhz_jiffies_conv,NULL);
1285 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1286 * @table: the sysctl table
1287 * @write: %TRUE if this is a write to the sysctl file
1288 * @buffer: the user buffer
1289 * @lenp: the size of the user buffer
1290 * @ppos: file position
1291 * @ppos: the current position in the file
1293 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1294 * values from/to the user buffer, treated as an ASCII string.
1295 * The values read are assumed to be in 1/1000 seconds, and
1296 * are converted into jiffies.
1298 * Returns 0 on success.
1300 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
1301 size_t *lenp, loff_t *ppos)
1303 return do_proc_dointvec(table, write, buffer, lenp, ppos,
1304 do_proc_dointvec_ms_jiffies_conv, NULL);
1307 static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
1308 size_t *lenp, loff_t *ppos)
1310 struct pid *new_pid;
1314 tmp = pid_vnr(cad_pid);
1316 r = __do_proc_dointvec(&tmp, table, write, buffer,
1317 lenp, ppos, NULL, NULL);
1321 new_pid = find_get_pid(tmp);
1325 put_pid(xchg(&cad_pid, new_pid));
1330 * proc_do_large_bitmap - read/write from/to a large bitmap
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
1337 * The bitmap is stored at table->data and the bitmap length (in bits)
1340 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1341 * large bitmaps may be represented in a compact manner. Writing into
1342 * the file will clear the bitmap then update it with the given input.
1344 * Returns 0 on success.
1346 int proc_do_large_bitmap(struct ctl_table *table, int write,
1347 void *buffer, size_t *lenp, loff_t *ppos)
1350 size_t left = *lenp;
1351 unsigned long bitmap_len = table->maxlen;
1352 unsigned long *bitmap = *(unsigned long **) table->data;
1353 unsigned long *tmp_bitmap = NULL;
1354 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1356 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1365 if (left > PAGE_SIZE - 1) {
1366 left = PAGE_SIZE - 1;
1367 /* How much of the buffer we'll skip this pass */
1368 skipped = *lenp - left;
1371 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
1374 proc_skip_char(&p, &left, '\n');
1375 while (!err && left) {
1376 unsigned long val_a, val_b;
1380 /* In case we stop parsing mid-number, we can reset */
1382 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1385 * If we consumed the entirety of a truncated buffer or
1386 * only one char is left (may be a "-"), then stop here,
1387 * reset, & come back for more.
1389 if ((left <= 1) && skipped) {
1396 if (val_a >= bitmap_len || neg) {
1408 err = proc_get_long(&p, &left, &val_b,
1409 &neg, tr_b, sizeof(tr_b),
1412 * If we consumed all of a truncated buffer or
1413 * then stop here, reset, & come back for more.
1415 if (!left && skipped) {
1422 if (val_b >= bitmap_len || neg ||
1433 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1434 proc_skip_char(&p, &left, '\n');
1438 unsigned long bit_a, bit_b = 0;
1442 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1443 if (bit_a >= bitmap_len)
1445 bit_b = find_next_zero_bit(bitmap, bitmap_len,
1449 proc_put_char(&buffer, &left, ',');
1450 proc_put_long(&buffer, &left, bit_a, false);
1451 if (bit_a != bit_b) {
1452 proc_put_char(&buffer, &left, '-');
1453 proc_put_long(&buffer, &left, bit_b, false);
1458 proc_put_char(&buffer, &left, '\n');
1464 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1466 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1472 bitmap_free(tmp_bitmap);
1476 #else /* CONFIG_PROC_SYSCTL */
1478 int proc_dostring(struct ctl_table *table, int write,
1479 void *buffer, size_t *lenp, loff_t *ppos)
1484 int proc_dobool(struct ctl_table *table, int write,
1485 void *buffer, size_t *lenp, loff_t *ppos)
1490 int proc_dointvec(struct ctl_table *table, int write,
1491 void *buffer, size_t *lenp, loff_t *ppos)
1496 int proc_douintvec(struct ctl_table *table, int write,
1497 void *buffer, size_t *lenp, loff_t *ppos)
1502 int proc_dointvec_minmax(struct ctl_table *table, int write,
1503 void *buffer, size_t *lenp, loff_t *ppos)
1508 int proc_douintvec_minmax(struct ctl_table *table, int write,
1509 void *buffer, size_t *lenp, loff_t *ppos)
1514 int proc_dou8vec_minmax(struct ctl_table *table, int write,
1515 void *buffer, size_t *lenp, loff_t *ppos)
1520 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1521 void *buffer, size_t *lenp, loff_t *ppos)
1526 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1527 void *buffer, size_t *lenp, loff_t *ppos)
1532 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1533 void *buffer, size_t *lenp, loff_t *ppos)
1538 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1539 void *buffer, size_t *lenp, loff_t *ppos)
1544 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1545 void *buffer, size_t *lenp, loff_t *ppos)
1550 int proc_do_large_bitmap(struct ctl_table *table, int write,
1551 void *buffer, size_t *lenp, loff_t *ppos)
1556 #endif /* CONFIG_PROC_SYSCTL */
1558 #if defined(CONFIG_SYSCTL)
1559 int proc_do_static_key(struct ctl_table *table, int write,
1560 void *buffer, size_t *lenp, loff_t *ppos)
1562 struct static_key *key = (struct static_key *)table->data;
1563 static DEFINE_MUTEX(static_key_mutex);
1565 struct ctl_table tmp = {
1567 .maxlen = sizeof(val),
1568 .mode = table->mode,
1569 .extra1 = SYSCTL_ZERO,
1570 .extra2 = SYSCTL_ONE,
1573 if (write && !capable(CAP_SYS_ADMIN))
1576 mutex_lock(&static_key_mutex);
1577 val = static_key_enabled(key);
1578 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1579 if (write && !ret) {
1581 static_key_enable(key);
1583 static_key_disable(key);
1585 mutex_unlock(&static_key_mutex);
1589 static struct ctl_table kern_table[] = {
1590 #ifdef CONFIG_NUMA_BALANCING
1592 .procname = "numa_balancing",
1593 .data = NULL, /* filled in by handler */
1594 .maxlen = sizeof(unsigned int),
1596 .proc_handler = sysctl_numa_balancing,
1597 .extra1 = SYSCTL_ZERO,
1598 .extra2 = SYSCTL_FOUR,
1600 #endif /* CONFIG_NUMA_BALANCING */
1602 .procname = "panic",
1603 .data = &panic_timeout,
1604 .maxlen = sizeof(int),
1606 .proc_handler = proc_dointvec,
1608 #ifdef CONFIG_PROC_SYSCTL
1610 .procname = "tainted",
1611 .maxlen = sizeof(long),
1613 .proc_handler = proc_taint,
1616 .procname = "sysctl_writes_strict",
1617 .data = &sysctl_writes_strict,
1618 .maxlen = sizeof(int),
1620 .proc_handler = proc_dointvec_minmax,
1621 .extra1 = SYSCTL_NEG_ONE,
1622 .extra2 = SYSCTL_ONE,
1626 .procname = "print-fatal-signals",
1627 .data = &print_fatal_signals,
1628 .maxlen = sizeof(int),
1630 .proc_handler = proc_dointvec,
1634 .procname = "reboot-cmd",
1635 .data = reboot_command,
1638 .proc_handler = proc_dostring,
1641 .procname = "stop-a",
1642 .data = &stop_a_enabled,
1643 .maxlen = sizeof (int),
1645 .proc_handler = proc_dointvec,
1648 .procname = "scons-poweroff",
1649 .data = &scons_pwroff,
1650 .maxlen = sizeof (int),
1652 .proc_handler = proc_dointvec,
1655 #ifdef CONFIG_SPARC64
1657 .procname = "tsb-ratio",
1658 .data = &sysctl_tsb_ratio,
1659 .maxlen = sizeof (int),
1661 .proc_handler = proc_dointvec,
1664 #ifdef CONFIG_PARISC
1666 .procname = "soft-power",
1667 .data = &pwrsw_enabled,
1668 .maxlen = sizeof (int),
1670 .proc_handler = proc_dointvec,
1673 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
1675 .procname = "unaligned-trap",
1676 .data = &unaligned_enabled,
1677 .maxlen = sizeof (int),
1679 .proc_handler = proc_dointvec,
1682 #ifdef CONFIG_STACK_TRACER
1684 .procname = "stack_tracer_enabled",
1685 .data = &stack_tracer_enabled,
1686 .maxlen = sizeof(int),
1688 .proc_handler = stack_trace_sysctl,
1691 #ifdef CONFIG_TRACING
1693 .procname = "ftrace_dump_on_oops",
1694 .data = &ftrace_dump_on_oops,
1695 .maxlen = sizeof(int),
1697 .proc_handler = proc_dointvec,
1700 .procname = "traceoff_on_warning",
1701 .data = &__disable_trace_on_warning,
1702 .maxlen = sizeof(__disable_trace_on_warning),
1704 .proc_handler = proc_dointvec,
1707 .procname = "tracepoint_printk",
1708 .data = &tracepoint_printk,
1709 .maxlen = sizeof(tracepoint_printk),
1711 .proc_handler = tracepoint_printk_sysctl,
1714 #ifdef CONFIG_MODULES
1716 .procname = "modprobe",
1717 .data = &modprobe_path,
1718 .maxlen = KMOD_PATH_LEN,
1720 .proc_handler = proc_dostring,
1723 .procname = "modules_disabled",
1724 .data = &modules_disabled,
1725 .maxlen = sizeof(int),
1727 /* only handle a transition from default "0" to "1" */
1728 .proc_handler = proc_dointvec_minmax,
1729 .extra1 = SYSCTL_ONE,
1730 .extra2 = SYSCTL_ONE,
1733 #ifdef CONFIG_UEVENT_HELPER
1735 .procname = "hotplug",
1736 .data = &uevent_helper,
1737 .maxlen = UEVENT_HELPER_PATH_LEN,
1739 .proc_handler = proc_dostring,
1742 #ifdef CONFIG_MAGIC_SYSRQ
1744 .procname = "sysrq",
1746 .maxlen = sizeof (int),
1748 .proc_handler = sysrq_sysctl_handler,
1751 #ifdef CONFIG_PROC_SYSCTL
1753 .procname = "cad_pid",
1755 .maxlen = sizeof (int),
1757 .proc_handler = proc_do_cad_pid,
1761 .procname = "threads-max",
1763 .maxlen = sizeof(int),
1765 .proc_handler = sysctl_max_threads,
1768 .procname = "usermodehelper",
1770 .child = usermodehelper_table,
1773 .procname = "overflowuid",
1774 .data = &overflowuid,
1775 .maxlen = sizeof(int),
1777 .proc_handler = proc_dointvec_minmax,
1778 .extra1 = SYSCTL_ZERO,
1779 .extra2 = SYSCTL_MAXOLDUID,
1782 .procname = "overflowgid",
1783 .data = &overflowgid,
1784 .maxlen = sizeof(int),
1786 .proc_handler = proc_dointvec_minmax,
1787 .extra1 = SYSCTL_ZERO,
1788 .extra2 = SYSCTL_MAXOLDUID,
1792 .procname = "userprocess_debug",
1793 .data = &show_unhandled_signals,
1794 .maxlen = sizeof(int),
1796 .proc_handler = proc_dointvec,
1800 .procname = "pid_max",
1802 .maxlen = sizeof (int),
1804 .proc_handler = proc_dointvec_minmax,
1805 .extra1 = &pid_max_min,
1806 .extra2 = &pid_max_max,
1809 .procname = "panic_on_oops",
1810 .data = &panic_on_oops,
1811 .maxlen = sizeof(int),
1813 .proc_handler = proc_dointvec,
1816 .procname = "panic_print",
1817 .data = &panic_print,
1818 .maxlen = sizeof(unsigned long),
1820 .proc_handler = proc_doulongvec_minmax,
1823 .procname = "ngroups_max",
1824 .data = (void *)&ngroups_max,
1825 .maxlen = sizeof (int),
1827 .proc_handler = proc_dointvec,
1830 .procname = "cap_last_cap",
1831 .data = (void *)&cap_last_cap,
1832 .maxlen = sizeof(int),
1834 .proc_handler = proc_dointvec,
1836 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
1838 .procname = "unknown_nmi_panic",
1839 .data = &unknown_nmi_panic,
1840 .maxlen = sizeof (int),
1842 .proc_handler = proc_dointvec,
1846 #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
1847 defined(CONFIG_DEBUG_STACKOVERFLOW)
1849 .procname = "panic_on_stackoverflow",
1850 .data = &sysctl_panic_on_stackoverflow,
1851 .maxlen = sizeof(int),
1853 .proc_handler = proc_dointvec,
1856 #if defined(CONFIG_X86)
1858 .procname = "panic_on_unrecovered_nmi",
1859 .data = &panic_on_unrecovered_nmi,
1860 .maxlen = sizeof(int),
1862 .proc_handler = proc_dointvec,
1865 .procname = "panic_on_io_nmi",
1866 .data = &panic_on_io_nmi,
1867 .maxlen = sizeof(int),
1869 .proc_handler = proc_dointvec,
1872 .procname = "bootloader_type",
1873 .data = &bootloader_type,
1874 .maxlen = sizeof (int),
1876 .proc_handler = proc_dointvec,
1879 .procname = "bootloader_version",
1880 .data = &bootloader_version,
1881 .maxlen = sizeof (int),
1883 .proc_handler = proc_dointvec,
1886 .procname = "io_delay_type",
1887 .data = &io_delay_type,
1888 .maxlen = sizeof(int),
1890 .proc_handler = proc_dointvec,
1893 #if defined(CONFIG_MMU)
1895 .procname = "randomize_va_space",
1896 .data = &randomize_va_space,
1897 .maxlen = sizeof(int),
1899 .proc_handler = proc_dointvec,
1902 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1904 .procname = "spin_retry",
1905 .data = &spin_retry,
1906 .maxlen = sizeof (int),
1908 .proc_handler = proc_dointvec,
1911 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1913 .procname = "acpi_video_flags",
1914 .data = &acpi_realmode_flags,
1915 .maxlen = sizeof (unsigned long),
1917 .proc_handler = proc_doulongvec_minmax,
1920 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1922 .procname = "ignore-unaligned-usertrap",
1923 .data = &no_unaligned_warning,
1924 .maxlen = sizeof (int),
1926 .proc_handler = proc_dointvec,
1931 .procname = "unaligned-dump-stack",
1932 .data = &unaligned_dump_stack,
1933 .maxlen = sizeof (int),
1935 .proc_handler = proc_dointvec,
1938 #ifdef CONFIG_RT_MUTEXES
1940 .procname = "max_lock_depth",
1941 .data = &max_lock_depth,
1942 .maxlen = sizeof(int),
1944 .proc_handler = proc_dointvec,
1951 .child = key_sysctls,
1954 #ifdef CONFIG_PERF_EVENTS
1956 * User-space scripts rely on the existence of this file
1957 * as a feature check for perf_events being enabled.
1959 * So it's an ABI, do not remove!
1962 .procname = "perf_event_paranoid",
1963 .data = &sysctl_perf_event_paranoid,
1964 .maxlen = sizeof(sysctl_perf_event_paranoid),
1966 .proc_handler = proc_dointvec,
1969 .procname = "perf_event_mlock_kb",
1970 .data = &sysctl_perf_event_mlock,
1971 .maxlen = sizeof(sysctl_perf_event_mlock),
1973 .proc_handler = proc_dointvec,
1976 .procname = "perf_event_max_sample_rate",
1977 .data = &sysctl_perf_event_sample_rate,
1978 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1980 .proc_handler = perf_proc_update_handler,
1981 .extra1 = SYSCTL_ONE,
1984 .procname = "perf_cpu_time_max_percent",
1985 .data = &sysctl_perf_cpu_time_max_percent,
1986 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
1988 .proc_handler = perf_cpu_time_max_percent_handler,
1989 .extra1 = SYSCTL_ZERO,
1990 .extra2 = SYSCTL_ONE_HUNDRED,
1993 .procname = "perf_event_max_stack",
1994 .data = &sysctl_perf_event_max_stack,
1995 .maxlen = sizeof(sysctl_perf_event_max_stack),
1997 .proc_handler = perf_event_max_stack_handler,
1998 .extra1 = SYSCTL_ZERO,
1999 .extra2 = (void *)&six_hundred_forty_kb,
2002 .procname = "perf_event_max_contexts_per_stack",
2003 .data = &sysctl_perf_event_max_contexts_per_stack,
2004 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
2006 .proc_handler = perf_event_max_stack_handler,
2007 .extra1 = SYSCTL_ZERO,
2008 .extra2 = SYSCTL_ONE_THOUSAND,
2012 .procname = "panic_on_warn",
2013 .data = &panic_on_warn,
2014 .maxlen = sizeof(int),
2016 .proc_handler = proc_dointvec_minmax,
2017 .extra1 = SYSCTL_ZERO,
2018 .extra2 = SYSCTL_ONE,
2020 #if defined(CONFIG_TREE_RCU)
2022 .procname = "panic_on_rcu_stall",
2023 .data = &sysctl_panic_on_rcu_stall,
2024 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
2026 .proc_handler = proc_dointvec_minmax,
2027 .extra1 = SYSCTL_ZERO,
2028 .extra2 = SYSCTL_ONE,
2031 #if defined(CONFIG_TREE_RCU)
2033 .procname = "max_rcu_stall_to_panic",
2034 .data = &sysctl_max_rcu_stall_to_panic,
2035 .maxlen = sizeof(sysctl_max_rcu_stall_to_panic),
2037 .proc_handler = proc_dointvec_minmax,
2038 .extra1 = SYSCTL_ONE,
2039 .extra2 = SYSCTL_INT_MAX,
2045 static struct ctl_table vm_table[] = {
2047 .procname = "overcommit_memory",
2048 .data = &sysctl_overcommit_memory,
2049 .maxlen = sizeof(sysctl_overcommit_memory),
2051 .proc_handler = overcommit_policy_handler,
2052 .extra1 = SYSCTL_ZERO,
2053 .extra2 = SYSCTL_TWO,
2056 .procname = "overcommit_ratio",
2057 .data = &sysctl_overcommit_ratio,
2058 .maxlen = sizeof(sysctl_overcommit_ratio),
2060 .proc_handler = overcommit_ratio_handler,
2063 .procname = "overcommit_kbytes",
2064 .data = &sysctl_overcommit_kbytes,
2065 .maxlen = sizeof(sysctl_overcommit_kbytes),
2067 .proc_handler = overcommit_kbytes_handler,
2070 .procname = "page-cluster",
2071 .data = &page_cluster,
2072 .maxlen = sizeof(int),
2074 .proc_handler = proc_dointvec_minmax,
2075 .extra1 = SYSCTL_ZERO,
2078 .procname = "dirtytime_expire_seconds",
2079 .data = &dirtytime_expire_interval,
2080 .maxlen = sizeof(dirtytime_expire_interval),
2082 .proc_handler = dirtytime_interval_handler,
2083 .extra1 = SYSCTL_ZERO,
2086 .procname = "swappiness",
2087 .data = &vm_swappiness,
2088 .maxlen = sizeof(vm_swappiness),
2090 .proc_handler = proc_dointvec_minmax,
2091 .extra1 = SYSCTL_ZERO,
2092 .extra2 = SYSCTL_TWO_HUNDRED,
2094 #ifdef CONFIG_HUGETLB_PAGE
2096 .procname = "nr_hugepages",
2098 .maxlen = sizeof(unsigned long),
2100 .proc_handler = hugetlb_sysctl_handler,
2104 .procname = "nr_hugepages_mempolicy",
2106 .maxlen = sizeof(unsigned long),
2108 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
2111 .procname = "numa_stat",
2112 .data = &sysctl_vm_numa_stat,
2113 .maxlen = sizeof(int),
2115 .proc_handler = sysctl_vm_numa_stat_handler,
2116 .extra1 = SYSCTL_ZERO,
2117 .extra2 = SYSCTL_ONE,
2121 .procname = "hugetlb_shm_group",
2122 .data = &sysctl_hugetlb_shm_group,
2123 .maxlen = sizeof(gid_t),
2125 .proc_handler = proc_dointvec,
2128 .procname = "nr_overcommit_hugepages",
2130 .maxlen = sizeof(unsigned long),
2132 .proc_handler = hugetlb_overcommit_handler,
2136 .procname = "lowmem_reserve_ratio",
2137 .data = &sysctl_lowmem_reserve_ratio,
2138 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
2140 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
2143 .procname = "drop_caches",
2144 .data = &sysctl_drop_caches,
2145 .maxlen = sizeof(int),
2147 .proc_handler = drop_caches_sysctl_handler,
2148 .extra1 = SYSCTL_ONE,
2149 .extra2 = SYSCTL_FOUR,
2151 #ifdef CONFIG_COMPACTION
2153 .procname = "compact_memory",
2155 .maxlen = sizeof(int),
2157 .proc_handler = sysctl_compaction_handler,
2160 .procname = "compaction_proactiveness",
2161 .data = &sysctl_compaction_proactiveness,
2162 .maxlen = sizeof(sysctl_compaction_proactiveness),
2164 .proc_handler = compaction_proactiveness_sysctl_handler,
2165 .extra1 = SYSCTL_ZERO,
2166 .extra2 = SYSCTL_ONE_HUNDRED,
2169 .procname = "extfrag_threshold",
2170 .data = &sysctl_extfrag_threshold,
2171 .maxlen = sizeof(int),
2173 .proc_handler = proc_dointvec_minmax,
2174 .extra1 = SYSCTL_ZERO,
2175 .extra2 = (void *)&max_extfrag_threshold,
2178 .procname = "compact_unevictable_allowed",
2179 .data = &sysctl_compact_unevictable_allowed,
2180 .maxlen = sizeof(int),
2182 .proc_handler = proc_dointvec_minmax_warn_RT_change,
2183 .extra1 = SYSCTL_ZERO,
2184 .extra2 = SYSCTL_ONE,
2187 #endif /* CONFIG_COMPACTION */
2189 .procname = "min_free_kbytes",
2190 .data = &min_free_kbytes,
2191 .maxlen = sizeof(min_free_kbytes),
2193 .proc_handler = min_free_kbytes_sysctl_handler,
2194 .extra1 = SYSCTL_ZERO,
2197 .procname = "watermark_boost_factor",
2198 .data = &watermark_boost_factor,
2199 .maxlen = sizeof(watermark_boost_factor),
2201 .proc_handler = proc_dointvec_minmax,
2202 .extra1 = SYSCTL_ZERO,
2205 .procname = "watermark_scale_factor",
2206 .data = &watermark_scale_factor,
2207 .maxlen = sizeof(watermark_scale_factor),
2209 .proc_handler = watermark_scale_factor_sysctl_handler,
2210 .extra1 = SYSCTL_ONE,
2211 .extra2 = SYSCTL_THREE_THOUSAND,
2214 .procname = "percpu_pagelist_high_fraction",
2215 .data = &percpu_pagelist_high_fraction,
2216 .maxlen = sizeof(percpu_pagelist_high_fraction),
2218 .proc_handler = percpu_pagelist_high_fraction_sysctl_handler,
2219 .extra1 = SYSCTL_ZERO,
2222 .procname = "page_lock_unfairness",
2223 .data = &sysctl_page_lock_unfairness,
2224 .maxlen = sizeof(sysctl_page_lock_unfairness),
2226 .proc_handler = proc_dointvec_minmax,
2227 .extra1 = SYSCTL_ZERO,
2231 .procname = "max_map_count",
2232 .data = &sysctl_max_map_count,
2233 .maxlen = sizeof(sysctl_max_map_count),
2235 .proc_handler = proc_dointvec_minmax,
2236 .extra1 = SYSCTL_ZERO,
2240 .procname = "nr_trim_pages",
2241 .data = &sysctl_nr_trim_pages,
2242 .maxlen = sizeof(sysctl_nr_trim_pages),
2244 .proc_handler = proc_dointvec_minmax,
2245 .extra1 = SYSCTL_ZERO,
2249 .procname = "vfs_cache_pressure",
2250 .data = &sysctl_vfs_cache_pressure,
2251 .maxlen = sizeof(sysctl_vfs_cache_pressure),
2253 .proc_handler = proc_dointvec_minmax,
2254 .extra1 = SYSCTL_ZERO,
2256 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
2257 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
2259 .procname = "legacy_va_layout",
2260 .data = &sysctl_legacy_va_layout,
2261 .maxlen = sizeof(sysctl_legacy_va_layout),
2263 .proc_handler = proc_dointvec_minmax,
2264 .extra1 = SYSCTL_ZERO,
2269 .procname = "zone_reclaim_mode",
2270 .data = &node_reclaim_mode,
2271 .maxlen = sizeof(node_reclaim_mode),
2273 .proc_handler = proc_dointvec_minmax,
2274 .extra1 = SYSCTL_ZERO,
2277 .procname = "min_unmapped_ratio",
2278 .data = &sysctl_min_unmapped_ratio,
2279 .maxlen = sizeof(sysctl_min_unmapped_ratio),
2281 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
2282 .extra1 = SYSCTL_ZERO,
2283 .extra2 = SYSCTL_ONE_HUNDRED,
2286 .procname = "min_slab_ratio",
2287 .data = &sysctl_min_slab_ratio,
2288 .maxlen = sizeof(sysctl_min_slab_ratio),
2290 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
2291 .extra1 = SYSCTL_ZERO,
2292 .extra2 = SYSCTL_ONE_HUNDRED,
2297 .procname = "stat_interval",
2298 .data = &sysctl_stat_interval,
2299 .maxlen = sizeof(sysctl_stat_interval),
2301 .proc_handler = proc_dointvec_jiffies,
2304 .procname = "stat_refresh",
2308 .proc_handler = vmstat_refresh,
2313 .procname = "mmap_min_addr",
2314 .data = &dac_mmap_min_addr,
2315 .maxlen = sizeof(unsigned long),
2317 .proc_handler = mmap_min_addr_handler,
2322 .procname = "numa_zonelist_order",
2323 .data = &numa_zonelist_order,
2324 .maxlen = NUMA_ZONELIST_ORDER_LEN,
2326 .proc_handler = numa_zonelist_order_handler,
2329 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
2330 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
2332 .procname = "vdso_enabled",
2333 #ifdef CONFIG_X86_32
2334 .data = &vdso32_enabled,
2335 .maxlen = sizeof(vdso32_enabled),
2337 .data = &vdso_enabled,
2338 .maxlen = sizeof(vdso_enabled),
2341 .proc_handler = proc_dointvec,
2342 .extra1 = SYSCTL_ZERO,
2345 #ifdef CONFIG_MEMORY_FAILURE
2347 .procname = "memory_failure_early_kill",
2348 .data = &sysctl_memory_failure_early_kill,
2349 .maxlen = sizeof(sysctl_memory_failure_early_kill),
2351 .proc_handler = proc_dointvec_minmax,
2352 .extra1 = SYSCTL_ZERO,
2353 .extra2 = SYSCTL_ONE,
2356 .procname = "memory_failure_recovery",
2357 .data = &sysctl_memory_failure_recovery,
2358 .maxlen = sizeof(sysctl_memory_failure_recovery),
2360 .proc_handler = proc_dointvec_minmax,
2361 .extra1 = SYSCTL_ZERO,
2362 .extra2 = SYSCTL_ONE,
2366 .procname = "user_reserve_kbytes",
2367 .data = &sysctl_user_reserve_kbytes,
2368 .maxlen = sizeof(sysctl_user_reserve_kbytes),
2370 .proc_handler = proc_doulongvec_minmax,
2373 .procname = "admin_reserve_kbytes",
2374 .data = &sysctl_admin_reserve_kbytes,
2375 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
2377 .proc_handler = proc_doulongvec_minmax,
2379 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
2381 .procname = "mmap_rnd_bits",
2382 .data = &mmap_rnd_bits,
2383 .maxlen = sizeof(mmap_rnd_bits),
2385 .proc_handler = proc_dointvec_minmax,
2386 .extra1 = (void *)&mmap_rnd_bits_min,
2387 .extra2 = (void *)&mmap_rnd_bits_max,
2390 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
2392 .procname = "mmap_rnd_compat_bits",
2393 .data = &mmap_rnd_compat_bits,
2394 .maxlen = sizeof(mmap_rnd_compat_bits),
2396 .proc_handler = proc_dointvec_minmax,
2397 .extra1 = (void *)&mmap_rnd_compat_bits_min,
2398 .extra2 = (void *)&mmap_rnd_compat_bits_max,
2401 #ifdef CONFIG_USERFAULTFD
2403 .procname = "unprivileged_userfaultfd",
2404 .data = &sysctl_unprivileged_userfaultfd,
2405 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
2407 .proc_handler = proc_dointvec_minmax,
2408 .extra1 = SYSCTL_ZERO,
2409 .extra2 = SYSCTL_ONE,
2415 static struct ctl_table debug_table[] = {
2416 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
2418 .procname = "exception-trace",
2419 .data = &show_unhandled_signals,
2420 .maxlen = sizeof(int),
2422 .proc_handler = proc_dointvec
2428 static struct ctl_table dev_table[] = {
2432 DECLARE_SYSCTL_BASE(kernel, kern_table);
2433 DECLARE_SYSCTL_BASE(vm, vm_table);
2434 DECLARE_SYSCTL_BASE(debug, debug_table);
2435 DECLARE_SYSCTL_BASE(dev, dev_table);
2437 int __init sysctl_init_bases(void)
2439 register_sysctl_base(kernel);
2440 register_sysctl_base(vm);
2441 register_sysctl_base(debug);
2442 register_sysctl_base(dev);
2446 #endif /* CONFIG_SYSCTL */
2448 * No sense putting this after each symbol definition, twice,
2449 * exception granted :-)
2451 EXPORT_SYMBOL(proc_dobool);
2452 EXPORT_SYMBOL(proc_dointvec);
2453 EXPORT_SYMBOL(proc_douintvec);
2454 EXPORT_SYMBOL(proc_dointvec_jiffies);
2455 EXPORT_SYMBOL(proc_dointvec_minmax);
2456 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
2457 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2458 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2459 EXPORT_SYMBOL(proc_dostring);
2460 EXPORT_SYMBOL(proc_doulongvec_minmax);
2461 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2462 EXPORT_SYMBOL(proc_do_large_bitmap);