OSDN Git Service

Merge tag 'Smack-for-5.18' of https://github.com/cschaufler/smack-next
[uclinux-h8/linux.git] / kernel / sysctl.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * sysctl.c: General linux system control interface
4  *
5  * Begun 24 March 1995, Stephen Tweedie
6  * Added /proc support, Dec 1995
7  * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
8  * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
9  * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
10  * Dynamic registration fixes, Stephen Tweedie.
11  * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
12  * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13  *  Horn.
14  * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
15  * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
16  * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17  *  Wendling.
18  * The list_for_each() macro wasn't appropriate for the sysctl loop.
19  *  Removed it and replaced it with older style, 03/23/00, Bill Wendling
20  */
21
22 #include <linux/module.h>
23 #include <linux/mm.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>
36 #include <linux/fs.h>
37 #include <linux/init.h>
38 #include <linux/kernel.h>
39 #include <linux/kobject.h>
40 #include <linux/net.h>
41 #include <linux/sysrq.h>
42 #include <linux/highuid.h>
43 #include <linux/writeback.h>
44 #include <linux/ratelimit.h>
45 #include <linux/compaction.h>
46 #include <linux/hugetlb.h>
47 #include <linux/initrd.h>
48 #include <linux/key.h>
49 #include <linux/times.h>
50 #include <linux/limits.h>
51 #include <linux/dcache.h>
52 #include <linux/syscalls.h>
53 #include <linux/vmstat.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/acpi.h>
56 #include <linux/reboot.h>
57 #include <linux/ftrace.h>
58 #include <linux/perf_event.h>
59 #include <linux/oom.h>
60 #include <linux/kmod.h>
61 #include <linux/capability.h>
62 #include <linux/binfmts.h>
63 #include <linux/sched/sysctl.h>
64 #include <linux/kexec.h>
65 #include <linux/bpf.h>
66 #include <linux/mount.h>
67 #include <linux/userfaultfd_k.h>
68 #include <linux/latencytop.h>
69 #include <linux/pid.h>
70 #include <linux/delayacct.h>
71
72 #include "../lib/kstrtox.h"
73
74 #include <linux/uaccess.h>
75 #include <asm/processor.h>
76
77 #ifdef CONFIG_X86
78 #include <asm/nmi.h>
79 #include <asm/stacktrace.h>
80 #include <asm/io.h>
81 #endif
82 #ifdef CONFIG_SPARC
83 #include <asm/setup.h>
84 #endif
85 #ifdef CONFIG_BSD_PROCESS_ACCT
86 #include <linux/acct.h>
87 #endif
88 #ifdef CONFIG_RT_MUTEXES
89 #include <linux/rtmutex.h>
90 #endif
91 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
92 #include <linux/lockdep.h>
93 #endif
94
95 #if defined(CONFIG_SYSCTL)
96
97 /* Constants used for minimum and  maximum */
98
99 #ifdef CONFIG_PERF_EVENTS
100 static const int six_hundred_forty_kb = 640 * 1024;
101 #endif
102
103 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
104 static const unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
105
106 static const int ngroups_max = NGROUPS_MAX;
107 static const int cap_last_cap = CAP_LAST_CAP;
108
109 #ifdef CONFIG_PROC_SYSCTL
110
111 /**
112  * enum sysctl_writes_mode - supported sysctl write modes
113  *
114  * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
115  *      to be written, and multiple writes on the same sysctl file descriptor
116  *      will rewrite the sysctl value, regardless of file position. No warning
117  *      is issued when the initial position is not 0.
118  * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
119  *      not 0.
120  * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
121  *      file position 0 and the value must be fully contained in the buffer
122  *      sent to the write syscall. If dealing with strings respect the file
123  *      position, but restrict this to the max length of the buffer, anything
124  *      passed the max length will be ignored. Multiple writes will append
125  *      to the buffer.
126  *
127  * These write modes control how current file position affects the behavior of
128  * updating sysctl values through the proc interface on each write.
129  */
130 enum sysctl_writes_mode {
131         SYSCTL_WRITES_LEGACY            = -1,
132         SYSCTL_WRITES_WARN              = 0,
133         SYSCTL_WRITES_STRICT            = 1,
134 };
135
136 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
137 #endif /* CONFIG_PROC_SYSCTL */
138
139 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
140     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
141 int sysctl_legacy_va_layout;
142 #endif
143
144 #ifdef CONFIG_COMPACTION
145 /* min_extfrag_threshold is SYSCTL_ZERO */;
146 static const int max_extfrag_threshold = 1000;
147 #endif
148
149 #endif /* CONFIG_SYSCTL */
150
151 #if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL)
152 static int bpf_stats_handler(struct ctl_table *table, int write,
153                              void *buffer, size_t *lenp, loff_t *ppos)
154 {
155         struct static_key *key = (struct static_key *)table->data;
156         static int saved_val;
157         int val, ret;
158         struct ctl_table tmp = {
159                 .data   = &val,
160                 .maxlen = sizeof(val),
161                 .mode   = table->mode,
162                 .extra1 = SYSCTL_ZERO,
163                 .extra2 = SYSCTL_ONE,
164         };
165
166         if (write && !capable(CAP_SYS_ADMIN))
167                 return -EPERM;
168
169         mutex_lock(&bpf_stats_enabled_mutex);
170         val = saved_val;
171         ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
172         if (write && !ret && val != saved_val) {
173                 if (val)
174                         static_key_slow_inc(key);
175                 else
176                         static_key_slow_dec(key);
177                 saved_val = val;
178         }
179         mutex_unlock(&bpf_stats_enabled_mutex);
180         return ret;
181 }
182
183 void __weak unpriv_ebpf_notify(int new_state)
184 {
185 }
186
187 static int bpf_unpriv_handler(struct ctl_table *table, int write,
188                               void *buffer, size_t *lenp, loff_t *ppos)
189 {
190         int ret, unpriv_enable = *(int *)table->data;
191         bool locked_state = unpriv_enable == 1;
192         struct ctl_table tmp = *table;
193
194         if (write && !capable(CAP_SYS_ADMIN))
195                 return -EPERM;
196
197         tmp.data = &unpriv_enable;
198         ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
199         if (write && !ret) {
200                 if (locked_state && unpriv_enable != 1)
201                         return -EPERM;
202                 *(int *)table->data = unpriv_enable;
203         }
204
205         unpriv_ebpf_notify(unpriv_enable);
206
207         return ret;
208 }
209 #endif /* CONFIG_BPF_SYSCALL && CONFIG_SYSCTL */
210
211 /*
212  * /proc/sys support
213  */
214
215 #ifdef CONFIG_PROC_SYSCTL
216
217 static int _proc_do_string(char *data, int maxlen, int write,
218                 char *buffer, size_t *lenp, loff_t *ppos)
219 {
220         size_t len;
221         char c, *p;
222
223         if (!data || !maxlen || !*lenp) {
224                 *lenp = 0;
225                 return 0;
226         }
227
228         if (write) {
229                 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
230                         /* Only continue writes not past the end of buffer. */
231                         len = strlen(data);
232                         if (len > maxlen - 1)
233                                 len = maxlen - 1;
234
235                         if (*ppos > len)
236                                 return 0;
237                         len = *ppos;
238                 } else {
239                         /* Start writing from beginning of buffer. */
240                         len = 0;
241                 }
242
243                 *ppos += *lenp;
244                 p = buffer;
245                 while ((p - buffer) < *lenp && len < maxlen - 1) {
246                         c = *(p++);
247                         if (c == 0 || c == '\n')
248                                 break;
249                         data[len++] = c;
250                 }
251                 data[len] = 0;
252         } else {
253                 len = strlen(data);
254                 if (len > maxlen)
255                         len = maxlen;
256
257                 if (*ppos > len) {
258                         *lenp = 0;
259                         return 0;
260                 }
261
262                 data += *ppos;
263                 len  -= *ppos;
264
265                 if (len > *lenp)
266                         len = *lenp;
267                 if (len)
268                         memcpy(buffer, data, len);
269                 if (len < *lenp) {
270                         buffer[len] = '\n';
271                         len++;
272                 }
273                 *lenp = len;
274                 *ppos += len;
275         }
276         return 0;
277 }
278
279 static void warn_sysctl_write(struct ctl_table *table)
280 {
281         pr_warn_once("%s wrote to %s when file position was not 0!\n"
282                 "This will not be supported in the future. To silence this\n"
283                 "warning, set kernel.sysctl_writes_strict = -1\n",
284                 current->comm, table->procname);
285 }
286
287 /**
288  * proc_first_pos_non_zero_ignore - check if first position is allowed
289  * @ppos: file position
290  * @table: the sysctl table
291  *
292  * Returns true if the first position is non-zero and the sysctl_writes_strict
293  * mode indicates this is not allowed for numeric input types. String proc
294  * handlers can ignore the return value.
295  */
296 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
297                                            struct ctl_table *table)
298 {
299         if (!*ppos)
300                 return false;
301
302         switch (sysctl_writes_strict) {
303         case SYSCTL_WRITES_STRICT:
304                 return true;
305         case SYSCTL_WRITES_WARN:
306                 warn_sysctl_write(table);
307                 return false;
308         default:
309                 return false;
310         }
311 }
312
313 /**
314  * proc_dostring - read a string sysctl
315  * @table: the sysctl table
316  * @write: %TRUE if this is a write to the sysctl file
317  * @buffer: the user buffer
318  * @lenp: the size of the user buffer
319  * @ppos: file position
320  *
321  * Reads/writes a string from/to the user buffer. If the kernel
322  * buffer provided is not large enough to hold the string, the
323  * string is truncated. The copied string is %NULL-terminated.
324  * If the string is being read by the user process, it is copied
325  * and a newline '\n' is added. It is truncated if the buffer is
326  * not large enough.
327  *
328  * Returns 0 on success.
329  */
330 int proc_dostring(struct ctl_table *table, int write,
331                   void *buffer, size_t *lenp, loff_t *ppos)
332 {
333         if (write)
334                 proc_first_pos_non_zero_ignore(ppos, table);
335
336         return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
337                         ppos);
338 }
339
340 static size_t proc_skip_spaces(char **buf)
341 {
342         size_t ret;
343         char *tmp = skip_spaces(*buf);
344         ret = tmp - *buf;
345         *buf = tmp;
346         return ret;
347 }
348
349 static void proc_skip_char(char **buf, size_t *size, const char v)
350 {
351         while (*size) {
352                 if (**buf != v)
353                         break;
354                 (*size)--;
355                 (*buf)++;
356         }
357 }
358
359 /**
360  * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
361  *                   fail on overflow
362  *
363  * @cp: kernel buffer containing the string to parse
364  * @endp: pointer to store the trailing characters
365  * @base: the base to use
366  * @res: where the parsed integer will be stored
367  *
368  * In case of success 0 is returned and @res will contain the parsed integer,
369  * @endp will hold any trailing characters.
370  * This function will fail the parse on overflow. If there wasn't an overflow
371  * the function will defer the decision what characters count as invalid to the
372  * caller.
373  */
374 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
375                            unsigned long *res)
376 {
377         unsigned long long result;
378         unsigned int rv;
379
380         cp = _parse_integer_fixup_radix(cp, &base);
381         rv = _parse_integer(cp, base, &result);
382         if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
383                 return -ERANGE;
384
385         cp += rv;
386
387         if (endp)
388                 *endp = (char *)cp;
389
390         *res = (unsigned long)result;
391         return 0;
392 }
393
394 #define TMPBUFLEN 22
395 /**
396  * proc_get_long - reads an ASCII formatted integer from a user buffer
397  *
398  * @buf: a kernel buffer
399  * @size: size of the kernel buffer
400  * @val: this is where the number will be stored
401  * @neg: set to %TRUE if number is negative
402  * @perm_tr: a vector which contains the allowed trailers
403  * @perm_tr_len: size of the perm_tr vector
404  * @tr: pointer to store the trailer character
405  *
406  * In case of success %0 is returned and @buf and @size are updated with
407  * the amount of bytes read. If @tr is non-NULL and a trailing
408  * character exists (size is non-zero after returning from this
409  * function), @tr is updated with the trailing character.
410  */
411 static int proc_get_long(char **buf, size_t *size,
412                           unsigned long *val, bool *neg,
413                           const char *perm_tr, unsigned perm_tr_len, char *tr)
414 {
415         int len;
416         char *p, tmp[TMPBUFLEN];
417
418         if (!*size)
419                 return -EINVAL;
420
421         len = *size;
422         if (len > TMPBUFLEN - 1)
423                 len = TMPBUFLEN - 1;
424
425         memcpy(tmp, *buf, len);
426
427         tmp[len] = 0;
428         p = tmp;
429         if (*p == '-' && *size > 1) {
430                 *neg = true;
431                 p++;
432         } else
433                 *neg = false;
434         if (!isdigit(*p))
435                 return -EINVAL;
436
437         if (strtoul_lenient(p, &p, 0, val))
438                 return -EINVAL;
439
440         len = p - tmp;
441
442         /* We don't know if the next char is whitespace thus we may accept
443          * invalid integers (e.g. 1234...a) or two integers instead of one
444          * (e.g. 123...1). So lets not allow such large numbers. */
445         if (len == TMPBUFLEN - 1)
446                 return -EINVAL;
447
448         if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
449                 return -EINVAL;
450
451         if (tr && (len < *size))
452                 *tr = *p;
453
454         *buf += len;
455         *size -= len;
456
457         return 0;
458 }
459
460 /**
461  * proc_put_long - converts an integer to a decimal ASCII formatted string
462  *
463  * @buf: the user buffer
464  * @size: the size of the user buffer
465  * @val: the integer to be converted
466  * @neg: sign of the number, %TRUE for negative
467  *
468  * In case of success @buf and @size are updated with the amount of bytes
469  * written.
470  */
471 static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
472 {
473         int len;
474         char tmp[TMPBUFLEN], *p = tmp;
475
476         sprintf(p, "%s%lu", neg ? "-" : "", val);
477         len = strlen(tmp);
478         if (len > *size)
479                 len = *size;
480         memcpy(*buf, tmp, len);
481         *size -= len;
482         *buf += len;
483 }
484 #undef TMPBUFLEN
485
486 static void proc_put_char(void **buf, size_t *size, char c)
487 {
488         if (*size) {
489                 char **buffer = (char **)buf;
490                 **buffer = c;
491
492                 (*size)--;
493                 (*buffer)++;
494                 *buf = *buffer;
495         }
496 }
497
498 static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp,
499                                 int *valp,
500                                 int write, void *data)
501 {
502         if (write) {
503                 *(bool *)valp = *lvalp;
504         } else {
505                 int val = *(bool *)valp;
506
507                 *lvalp = (unsigned long)val;
508                 *negp = false;
509         }
510         return 0;
511 }
512
513 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
514                                  int *valp,
515                                  int write, void *data)
516 {
517         if (write) {
518                 if (*negp) {
519                         if (*lvalp > (unsigned long) INT_MAX + 1)
520                                 return -EINVAL;
521                         *valp = -*lvalp;
522                 } else {
523                         if (*lvalp > (unsigned long) INT_MAX)
524                                 return -EINVAL;
525                         *valp = *lvalp;
526                 }
527         } else {
528                 int val = *valp;
529                 if (val < 0) {
530                         *negp = true;
531                         *lvalp = -(unsigned long)val;
532                 } else {
533                         *negp = false;
534                         *lvalp = (unsigned long)val;
535                 }
536         }
537         return 0;
538 }
539
540 static int do_proc_douintvec_conv(unsigned long *lvalp,
541                                   unsigned int *valp,
542                                   int write, void *data)
543 {
544         if (write) {
545                 if (*lvalp > UINT_MAX)
546                         return -EINVAL;
547                 *valp = *lvalp;
548         } else {
549                 unsigned int val = *valp;
550                 *lvalp = (unsigned long)val;
551         }
552         return 0;
553 }
554
555 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
556
557 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
558                   int write, void *buffer,
559                   size_t *lenp, loff_t *ppos,
560                   int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
561                               int write, void *data),
562                   void *data)
563 {
564         int *i, vleft, first = 1, err = 0;
565         size_t left;
566         char *p;
567         
568         if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
569                 *lenp = 0;
570                 return 0;
571         }
572         
573         i = (int *) tbl_data;
574         vleft = table->maxlen / sizeof(*i);
575         left = *lenp;
576
577         if (!conv)
578                 conv = do_proc_dointvec_conv;
579
580         if (write) {
581                 if (proc_first_pos_non_zero_ignore(ppos, table))
582                         goto out;
583
584                 if (left > PAGE_SIZE - 1)
585                         left = PAGE_SIZE - 1;
586                 p = buffer;
587         }
588
589         for (; left && vleft--; i++, first=0) {
590                 unsigned long lval;
591                 bool neg;
592
593                 if (write) {
594                         left -= proc_skip_spaces(&p);
595
596                         if (!left)
597                                 break;
598                         err = proc_get_long(&p, &left, &lval, &neg,
599                                              proc_wspace_sep,
600                                              sizeof(proc_wspace_sep), NULL);
601                         if (err)
602                                 break;
603                         if (conv(&neg, &lval, i, 1, data)) {
604                                 err = -EINVAL;
605                                 break;
606                         }
607                 } else {
608                         if (conv(&neg, &lval, i, 0, data)) {
609                                 err = -EINVAL;
610                                 break;
611                         }
612                         if (!first)
613                                 proc_put_char(&buffer, &left, '\t');
614                         proc_put_long(&buffer, &left, lval, neg);
615                 }
616         }
617
618         if (!write && !first && left && !err)
619                 proc_put_char(&buffer, &left, '\n');
620         if (write && !err && left)
621                 left -= proc_skip_spaces(&p);
622         if (write && first)
623                 return err ? : -EINVAL;
624         *lenp -= left;
625 out:
626         *ppos += *lenp;
627         return err;
628 }
629
630 static int do_proc_dointvec(struct ctl_table *table, int write,
631                   void *buffer, size_t *lenp, loff_t *ppos,
632                   int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
633                               int write, void *data),
634                   void *data)
635 {
636         return __do_proc_dointvec(table->data, table, write,
637                         buffer, lenp, ppos, conv, data);
638 }
639
640 static int do_proc_douintvec_w(unsigned int *tbl_data,
641                                struct ctl_table *table,
642                                void *buffer,
643                                size_t *lenp, loff_t *ppos,
644                                int (*conv)(unsigned long *lvalp,
645                                            unsigned int *valp,
646                                            int write, void *data),
647                                void *data)
648 {
649         unsigned long lval;
650         int err = 0;
651         size_t left;
652         bool neg;
653         char *p = buffer;
654
655         left = *lenp;
656
657         if (proc_first_pos_non_zero_ignore(ppos, table))
658                 goto bail_early;
659
660         if (left > PAGE_SIZE - 1)
661                 left = PAGE_SIZE - 1;
662
663         left -= proc_skip_spaces(&p);
664         if (!left) {
665                 err = -EINVAL;
666                 goto out_free;
667         }
668
669         err = proc_get_long(&p, &left, &lval, &neg,
670                              proc_wspace_sep,
671                              sizeof(proc_wspace_sep), NULL);
672         if (err || neg) {
673                 err = -EINVAL;
674                 goto out_free;
675         }
676
677         if (conv(&lval, tbl_data, 1, data)) {
678                 err = -EINVAL;
679                 goto out_free;
680         }
681
682         if (!err && left)
683                 left -= proc_skip_spaces(&p);
684
685 out_free:
686         if (err)
687                 return -EINVAL;
688
689         return 0;
690
691         /* This is in keeping with old __do_proc_dointvec() */
692 bail_early:
693         *ppos += *lenp;
694         return err;
695 }
696
697 static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
698                                size_t *lenp, loff_t *ppos,
699                                int (*conv)(unsigned long *lvalp,
700                                            unsigned int *valp,
701                                            int write, void *data),
702                                void *data)
703 {
704         unsigned long lval;
705         int err = 0;
706         size_t left;
707
708         left = *lenp;
709
710         if (conv(&lval, tbl_data, 0, data)) {
711                 err = -EINVAL;
712                 goto out;
713         }
714
715         proc_put_long(&buffer, &left, lval, false);
716         if (!left)
717                 goto out;
718
719         proc_put_char(&buffer, &left, '\n');
720
721 out:
722         *lenp -= left;
723         *ppos += *lenp;
724
725         return err;
726 }
727
728 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
729                                int write, void *buffer,
730                                size_t *lenp, loff_t *ppos,
731                                int (*conv)(unsigned long *lvalp,
732                                            unsigned int *valp,
733                                            int write, void *data),
734                                void *data)
735 {
736         unsigned int *i, vleft;
737
738         if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
739                 *lenp = 0;
740                 return 0;
741         }
742
743         i = (unsigned int *) tbl_data;
744         vleft = table->maxlen / sizeof(*i);
745
746         /*
747          * Arrays are not supported, keep this simple. *Do not* add
748          * support for them.
749          */
750         if (vleft != 1) {
751                 *lenp = 0;
752                 return -EINVAL;
753         }
754
755         if (!conv)
756                 conv = do_proc_douintvec_conv;
757
758         if (write)
759                 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
760                                            conv, data);
761         return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
762 }
763
764 int do_proc_douintvec(struct ctl_table *table, int write,
765                       void *buffer, size_t *lenp, loff_t *ppos,
766                       int (*conv)(unsigned long *lvalp,
767                                   unsigned int *valp,
768                                   int write, void *data),
769                       void *data)
770 {
771         return __do_proc_douintvec(table->data, table, write,
772                                    buffer, lenp, ppos, conv, data);
773 }
774
775 /**
776  * proc_dobool - read/write a bool
777  * @table: the sysctl table
778  * @write: %TRUE if this is a write to the sysctl file
779  * @buffer: the user buffer
780  * @lenp: the size of the user buffer
781  * @ppos: file position
782  *
783  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
784  * values from/to the user buffer, treated as an ASCII string.
785  *
786  * Returns 0 on success.
787  */
788 int proc_dobool(struct ctl_table *table, int write, void *buffer,
789                 size_t *lenp, loff_t *ppos)
790 {
791         return do_proc_dointvec(table, write, buffer, lenp, ppos,
792                                 do_proc_dobool_conv, NULL);
793 }
794
795 /**
796  * proc_dointvec - read a vector of integers
797  * @table: the sysctl table
798  * @write: %TRUE if this is a write to the sysctl file
799  * @buffer: the user buffer
800  * @lenp: the size of the user buffer
801  * @ppos: file position
802  *
803  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
804  * values from/to the user buffer, treated as an ASCII string. 
805  *
806  * Returns 0 on success.
807  */
808 int proc_dointvec(struct ctl_table *table, int write, void *buffer,
809                   size_t *lenp, loff_t *ppos)
810 {
811         return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
812 }
813
814 #ifdef CONFIG_COMPACTION
815 static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
816                 int write, void *buffer, size_t *lenp, loff_t *ppos)
817 {
818         int ret, old;
819
820         if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
821                 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
822
823         old = *(int *)table->data;
824         ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
825         if (ret)
826                 return ret;
827         if (old != *(int *)table->data)
828                 pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
829                              table->procname, current->comm,
830                              task_pid_nr(current));
831         return ret;
832 }
833 #endif
834
835 /**
836  * proc_douintvec - read a vector of unsigned integers
837  * @table: the sysctl table
838  * @write: %TRUE if this is a write to the sysctl file
839  * @buffer: the user buffer
840  * @lenp: the size of the user buffer
841  * @ppos: file position
842  *
843  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
844  * values from/to the user buffer, treated as an ASCII string.
845  *
846  * Returns 0 on success.
847  */
848 int proc_douintvec(struct ctl_table *table, int write, void *buffer,
849                 size_t *lenp, loff_t *ppos)
850 {
851         return do_proc_douintvec(table, write, buffer, lenp, ppos,
852                                  do_proc_douintvec_conv, NULL);
853 }
854
855 /*
856  * Taint values can only be increased
857  * This means we can safely use a temporary.
858  */
859 static int proc_taint(struct ctl_table *table, int write,
860                                void *buffer, size_t *lenp, loff_t *ppos)
861 {
862         struct ctl_table t;
863         unsigned long tmptaint = get_taint();
864         int err;
865
866         if (write && !capable(CAP_SYS_ADMIN))
867                 return -EPERM;
868
869         t = *table;
870         t.data = &tmptaint;
871         err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
872         if (err < 0)
873                 return err;
874
875         if (write) {
876                 int i;
877
878                 /*
879                  * If we are relying on panic_on_taint not producing
880                  * false positives due to userspace input, bail out
881                  * before setting the requested taint flags.
882                  */
883                 if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
884                         return -EINVAL;
885
886                 /*
887                  * Poor man's atomic or. Not worth adding a primitive
888                  * to everyone's atomic.h for this
889                  */
890                 for (i = 0; i < TAINT_FLAGS_COUNT; i++)
891                         if ((1UL << i) & tmptaint)
892                                 add_taint(i, LOCKDEP_STILL_OK);
893         }
894
895         return err;
896 }
897
898 /**
899  * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
900  * @min: pointer to minimum allowable value
901  * @max: pointer to maximum allowable value
902  *
903  * The do_proc_dointvec_minmax_conv_param structure provides the
904  * minimum and maximum values for doing range checking for those sysctl
905  * parameters that use the proc_dointvec_minmax() handler.
906  */
907 struct do_proc_dointvec_minmax_conv_param {
908         int *min;
909         int *max;
910 };
911
912 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
913                                         int *valp,
914                                         int write, void *data)
915 {
916         int tmp, ret;
917         struct do_proc_dointvec_minmax_conv_param *param = data;
918         /*
919          * If writing, first do so via a temporary local int so we can
920          * bounds-check it before touching *valp.
921          */
922         int *ip = write ? &tmp : valp;
923
924         ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
925         if (ret)
926                 return ret;
927
928         if (write) {
929                 if ((param->min && *param->min > tmp) ||
930                     (param->max && *param->max < tmp))
931                         return -EINVAL;
932                 *valp = tmp;
933         }
934
935         return 0;
936 }
937
938 /**
939  * proc_dointvec_minmax - read a vector of integers with min/max values
940  * @table: the sysctl table
941  * @write: %TRUE if this is a write to the sysctl file
942  * @buffer: the user buffer
943  * @lenp: the size of the user buffer
944  * @ppos: file position
945  *
946  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
947  * values from/to the user buffer, treated as an ASCII string.
948  *
949  * This routine will ensure the values are within the range specified by
950  * table->extra1 (min) and table->extra2 (max).
951  *
952  * Returns 0 on success or -EINVAL on write when the range check fails.
953  */
954 int proc_dointvec_minmax(struct ctl_table *table, int write,
955                   void *buffer, size_t *lenp, loff_t *ppos)
956 {
957         struct do_proc_dointvec_minmax_conv_param param = {
958                 .min = (int *) table->extra1,
959                 .max = (int *) table->extra2,
960         };
961         return do_proc_dointvec(table, write, buffer, lenp, ppos,
962                                 do_proc_dointvec_minmax_conv, &param);
963 }
964
965 /**
966  * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
967  * @min: pointer to minimum allowable value
968  * @max: pointer to maximum allowable value
969  *
970  * The do_proc_douintvec_minmax_conv_param structure provides the
971  * minimum and maximum values for doing range checking for those sysctl
972  * parameters that use the proc_douintvec_minmax() handler.
973  */
974 struct do_proc_douintvec_minmax_conv_param {
975         unsigned int *min;
976         unsigned int *max;
977 };
978
979 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
980                                          unsigned int *valp,
981                                          int write, void *data)
982 {
983         int ret;
984         unsigned int tmp;
985         struct do_proc_douintvec_minmax_conv_param *param = data;
986         /* write via temporary local uint for bounds-checking */
987         unsigned int *up = write ? &tmp : valp;
988
989         ret = do_proc_douintvec_conv(lvalp, up, write, data);
990         if (ret)
991                 return ret;
992
993         if (write) {
994                 if ((param->min && *param->min > tmp) ||
995                     (param->max && *param->max < tmp))
996                         return -ERANGE;
997
998                 *valp = tmp;
999         }
1000
1001         return 0;
1002 }
1003
1004 /**
1005  * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
1006  * @table: the sysctl table
1007  * @write: %TRUE if this is a write to the sysctl file
1008  * @buffer: the user buffer
1009  * @lenp: the size of the user buffer
1010  * @ppos: file position
1011  *
1012  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
1013  * values from/to the user buffer, treated as an ASCII string. Negative
1014  * strings are not allowed.
1015  *
1016  * This routine will ensure the values are within the range specified by
1017  * table->extra1 (min) and table->extra2 (max). There is a final sanity
1018  * check for UINT_MAX to avoid having to support wrap around uses from
1019  * userspace.
1020  *
1021  * Returns 0 on success or -ERANGE on write when the range check fails.
1022  */
1023 int proc_douintvec_minmax(struct ctl_table *table, int write,
1024                           void *buffer, size_t *lenp, loff_t *ppos)
1025 {
1026         struct do_proc_douintvec_minmax_conv_param param = {
1027                 .min = (unsigned int *) table->extra1,
1028                 .max = (unsigned int *) table->extra2,
1029         };
1030         return do_proc_douintvec(table, write, buffer, lenp, ppos,
1031                                  do_proc_douintvec_minmax_conv, &param);
1032 }
1033
1034 /**
1035  * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values
1036  * @table: the sysctl table
1037  * @write: %TRUE if this is a write to the sysctl file
1038  * @buffer: the user buffer
1039  * @lenp: the size of the user buffer
1040  * @ppos: file position
1041  *
1042  * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars
1043  * values from/to the user buffer, treated as an ASCII string. Negative
1044  * strings are not allowed.
1045  *
1046  * This routine will ensure the values are within the range specified by
1047  * table->extra1 (min) and table->extra2 (max).
1048  *
1049  * Returns 0 on success or an error on write when the range check fails.
1050  */
1051 int proc_dou8vec_minmax(struct ctl_table *table, int write,
1052                         void *buffer, size_t *lenp, loff_t *ppos)
1053 {
1054         struct ctl_table tmp;
1055         unsigned int min = 0, max = 255U, val;
1056         u8 *data = table->data;
1057         struct do_proc_douintvec_minmax_conv_param param = {
1058                 .min = &min,
1059                 .max = &max,
1060         };
1061         int res;
1062
1063         /* Do not support arrays yet. */
1064         if (table->maxlen != sizeof(u8))
1065                 return -EINVAL;
1066
1067         if (table->extra1) {
1068                 min = *(unsigned int *) table->extra1;
1069                 if (min > 255U)
1070                         return -EINVAL;
1071         }
1072         if (table->extra2) {
1073                 max = *(unsigned int *) table->extra2;
1074                 if (max > 255U)
1075                         return -EINVAL;
1076         }
1077
1078         tmp = *table;
1079
1080         tmp.maxlen = sizeof(val);
1081         tmp.data = &val;
1082         val = *data;
1083         res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos,
1084                                 do_proc_douintvec_minmax_conv, &param);
1085         if (res)
1086                 return res;
1087         if (write)
1088                 *data = val;
1089         return 0;
1090 }
1091 EXPORT_SYMBOL_GPL(proc_dou8vec_minmax);
1092
1093 #ifdef CONFIG_MAGIC_SYSRQ
1094 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
1095                                 void *buffer, size_t *lenp, loff_t *ppos)
1096 {
1097         int tmp, ret;
1098
1099         tmp = sysrq_mask();
1100
1101         ret = __do_proc_dointvec(&tmp, table, write, buffer,
1102                                lenp, ppos, NULL, NULL);
1103         if (ret || !write)
1104                 return ret;
1105
1106         if (write)
1107                 sysrq_toggle_support(tmp);
1108
1109         return 0;
1110 }
1111 #endif
1112
1113 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
1114                 int write, void *buffer, size_t *lenp, loff_t *ppos,
1115                 unsigned long convmul, unsigned long convdiv)
1116 {
1117         unsigned long *i, *min, *max;
1118         int vleft, first = 1, err = 0;
1119         size_t left;
1120         char *p;
1121
1122         if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1123                 *lenp = 0;
1124                 return 0;
1125         }
1126
1127         i = (unsigned long *) data;
1128         min = (unsigned long *) table->extra1;
1129         max = (unsigned long *) table->extra2;
1130         vleft = table->maxlen / sizeof(unsigned long);
1131         left = *lenp;
1132
1133         if (write) {
1134                 if (proc_first_pos_non_zero_ignore(ppos, table))
1135                         goto out;
1136
1137                 if (left > PAGE_SIZE - 1)
1138                         left = PAGE_SIZE - 1;
1139                 p = buffer;
1140         }
1141
1142         for (; left && vleft--; i++, first = 0) {
1143                 unsigned long val;
1144
1145                 if (write) {
1146                         bool neg;
1147
1148                         left -= proc_skip_spaces(&p);
1149                         if (!left)
1150                                 break;
1151
1152                         err = proc_get_long(&p, &left, &val, &neg,
1153                                              proc_wspace_sep,
1154                                              sizeof(proc_wspace_sep), NULL);
1155                         if (err || neg) {
1156                                 err = -EINVAL;
1157                                 break;
1158                         }
1159
1160                         val = convmul * val / convdiv;
1161                         if ((min && val < *min) || (max && val > *max)) {
1162                                 err = -EINVAL;
1163                                 break;
1164                         }
1165                         *i = val;
1166                 } else {
1167                         val = convdiv * (*i) / convmul;
1168                         if (!first)
1169                                 proc_put_char(&buffer, &left, '\t');
1170                         proc_put_long(&buffer, &left, val, false);
1171                 }
1172         }
1173
1174         if (!write && !first && left && !err)
1175                 proc_put_char(&buffer, &left, '\n');
1176         if (write && !err)
1177                 left -= proc_skip_spaces(&p);
1178         if (write && first)
1179                 return err ? : -EINVAL;
1180         *lenp -= left;
1181 out:
1182         *ppos += *lenp;
1183         return err;
1184 }
1185
1186 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
1187                 void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1188                 unsigned long convdiv)
1189 {
1190         return __do_proc_doulongvec_minmax(table->data, table, write,
1191                         buffer, lenp, ppos, convmul, convdiv);
1192 }
1193
1194 /**
1195  * proc_doulongvec_minmax - read a vector of long integers with min/max values
1196  * @table: the sysctl table
1197  * @write: %TRUE if this is a write to the sysctl file
1198  * @buffer: the user buffer
1199  * @lenp: the size of the user buffer
1200  * @ppos: file position
1201  *
1202  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1203  * values from/to the user buffer, treated as an ASCII string.
1204  *
1205  * This routine will ensure the values are within the range specified by
1206  * table->extra1 (min) and table->extra2 (max).
1207  *
1208  * Returns 0 on success.
1209  */
1210 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1211                            void *buffer, size_t *lenp, loff_t *ppos)
1212 {
1213     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1214 }
1215
1216 /**
1217  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1218  * @table: the sysctl table
1219  * @write: %TRUE if this is a write to the sysctl file
1220  * @buffer: the user buffer
1221  * @lenp: the size of the user buffer
1222  * @ppos: file position
1223  *
1224  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1225  * values from/to the user buffer, treated as an ASCII string. The values
1226  * are treated as milliseconds, and converted to jiffies when they are stored.
1227  *
1228  * This routine will ensure the values are within the range specified by
1229  * table->extra1 (min) and table->extra2 (max).
1230  *
1231  * Returns 0 on success.
1232  */
1233 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1234                                       void *buffer, size_t *lenp, loff_t *ppos)
1235 {
1236     return do_proc_doulongvec_minmax(table, write, buffer,
1237                                      lenp, ppos, HZ, 1000l);
1238 }
1239
1240
1241 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1242                                          int *valp,
1243                                          int write, void *data)
1244 {
1245         if (write) {
1246                 if (*lvalp > INT_MAX / HZ)
1247                         return 1;
1248                 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1249         } else {
1250                 int val = *valp;
1251                 unsigned long lval;
1252                 if (val < 0) {
1253                         *negp = true;
1254                         lval = -(unsigned long)val;
1255                 } else {
1256                         *negp = false;
1257                         lval = (unsigned long)val;
1258                 }
1259                 *lvalp = lval / HZ;
1260         }
1261         return 0;
1262 }
1263
1264 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1265                                                 int *valp,
1266                                                 int write, void *data)
1267 {
1268         if (write) {
1269                 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1270                         return 1;
1271                 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1272         } else {
1273                 int val = *valp;
1274                 unsigned long lval;
1275                 if (val < 0) {
1276                         *negp = true;
1277                         lval = -(unsigned long)val;
1278                 } else {
1279                         *negp = false;
1280                         lval = (unsigned long)val;
1281                 }
1282                 *lvalp = jiffies_to_clock_t(lval);
1283         }
1284         return 0;
1285 }
1286
1287 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1288                                             int *valp,
1289                                             int write, void *data)
1290 {
1291         if (write) {
1292                 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1293
1294                 if (jif > INT_MAX)
1295                         return 1;
1296                 *valp = (int)jif;
1297         } else {
1298                 int val = *valp;
1299                 unsigned long lval;
1300                 if (val < 0) {
1301                         *negp = true;
1302                         lval = -(unsigned long)val;
1303                 } else {
1304                         *negp = false;
1305                         lval = (unsigned long)val;
1306                 }
1307                 *lvalp = jiffies_to_msecs(lval);
1308         }
1309         return 0;
1310 }
1311
1312 /**
1313  * proc_dointvec_jiffies - read a vector of integers as seconds
1314  * @table: the sysctl table
1315  * @write: %TRUE if this is a write to the sysctl file
1316  * @buffer: the user buffer
1317  * @lenp: the size of the user buffer
1318  * @ppos: file position
1319  *
1320  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1321  * values from/to the user buffer, treated as an ASCII string. 
1322  * The values read are assumed to be in seconds, and are converted into
1323  * jiffies.
1324  *
1325  * Returns 0 on success.
1326  */
1327 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1328                           void *buffer, size_t *lenp, loff_t *ppos)
1329 {
1330     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1331                             do_proc_dointvec_jiffies_conv,NULL);
1332 }
1333
1334 /**
1335  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1336  * @table: the sysctl table
1337  * @write: %TRUE if this is a write to the sysctl file
1338  * @buffer: the user buffer
1339  * @lenp: the size of the user buffer
1340  * @ppos: pointer to the file position
1341  *
1342  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1343  * values from/to the user buffer, treated as an ASCII string. 
1344  * The values read are assumed to be in 1/USER_HZ seconds, and 
1345  * are converted into jiffies.
1346  *
1347  * Returns 0 on success.
1348  */
1349 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1350                                  void *buffer, size_t *lenp, loff_t *ppos)
1351 {
1352     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1353                             do_proc_dointvec_userhz_jiffies_conv,NULL);
1354 }
1355
1356 /**
1357  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1358  * @table: the sysctl table
1359  * @write: %TRUE if this is a write to the sysctl file
1360  * @buffer: the user buffer
1361  * @lenp: the size of the user buffer
1362  * @ppos: file position
1363  * @ppos: the current position in the file
1364  *
1365  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1366  * values from/to the user buffer, treated as an ASCII string. 
1367  * The values read are assumed to be in 1/1000 seconds, and 
1368  * are converted into jiffies.
1369  *
1370  * Returns 0 on success.
1371  */
1372 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
1373                 size_t *lenp, loff_t *ppos)
1374 {
1375         return do_proc_dointvec(table, write, buffer, lenp, ppos,
1376                                 do_proc_dointvec_ms_jiffies_conv, NULL);
1377 }
1378
1379 static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
1380                 size_t *lenp, loff_t *ppos)
1381 {
1382         struct pid *new_pid;
1383         pid_t tmp;
1384         int r;
1385
1386         tmp = pid_vnr(cad_pid);
1387
1388         r = __do_proc_dointvec(&tmp, table, write, buffer,
1389                                lenp, ppos, NULL, NULL);
1390         if (r || !write)
1391                 return r;
1392
1393         new_pid = find_get_pid(tmp);
1394         if (!new_pid)
1395                 return -ESRCH;
1396
1397         put_pid(xchg(&cad_pid, new_pid));
1398         return 0;
1399 }
1400
1401 /**
1402  * proc_do_large_bitmap - read/write from/to a large bitmap
1403  * @table: the sysctl table
1404  * @write: %TRUE if this is a write to the sysctl file
1405  * @buffer: the user buffer
1406  * @lenp: the size of the user buffer
1407  * @ppos: file position
1408  *
1409  * The bitmap is stored at table->data and the bitmap length (in bits)
1410  * in table->maxlen.
1411  *
1412  * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1413  * large bitmaps may be represented in a compact manner. Writing into
1414  * the file will clear the bitmap then update it with the given input.
1415  *
1416  * Returns 0 on success.
1417  */
1418 int proc_do_large_bitmap(struct ctl_table *table, int write,
1419                          void *buffer, size_t *lenp, loff_t *ppos)
1420 {
1421         int err = 0;
1422         size_t left = *lenp;
1423         unsigned long bitmap_len = table->maxlen;
1424         unsigned long *bitmap = *(unsigned long **) table->data;
1425         unsigned long *tmp_bitmap = NULL;
1426         char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1427
1428         if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1429                 *lenp = 0;
1430                 return 0;
1431         }
1432
1433         if (write) {
1434                 char *p = buffer;
1435                 size_t skipped = 0;
1436
1437                 if (left > PAGE_SIZE - 1) {
1438                         left = PAGE_SIZE - 1;
1439                         /* How much of the buffer we'll skip this pass */
1440                         skipped = *lenp - left;
1441                 }
1442
1443                 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
1444                 if (!tmp_bitmap)
1445                         return -ENOMEM;
1446                 proc_skip_char(&p, &left, '\n');
1447                 while (!err && left) {
1448                         unsigned long val_a, val_b;
1449                         bool neg;
1450                         size_t saved_left;
1451
1452                         /* In case we stop parsing mid-number, we can reset */
1453                         saved_left = left;
1454                         err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1455                                              sizeof(tr_a), &c);
1456                         /*
1457                          * If we consumed the entirety of a truncated buffer or
1458                          * only one char is left (may be a "-"), then stop here,
1459                          * reset, & come back for more.
1460                          */
1461                         if ((left <= 1) && skipped) {
1462                                 left = saved_left;
1463                                 break;
1464                         }
1465
1466                         if (err)
1467                                 break;
1468                         if (val_a >= bitmap_len || neg) {
1469                                 err = -EINVAL;
1470                                 break;
1471                         }
1472
1473                         val_b = val_a;
1474                         if (left) {
1475                                 p++;
1476                                 left--;
1477                         }
1478
1479                         if (c == '-') {
1480                                 err = proc_get_long(&p, &left, &val_b,
1481                                                      &neg, tr_b, sizeof(tr_b),
1482                                                      &c);
1483                                 /*
1484                                  * If we consumed all of a truncated buffer or
1485                                  * then stop here, reset, & come back for more.
1486                                  */
1487                                 if (!left && skipped) {
1488                                         left = saved_left;
1489                                         break;
1490                                 }
1491
1492                                 if (err)
1493                                         break;
1494                                 if (val_b >= bitmap_len || neg ||
1495                                     val_a > val_b) {
1496                                         err = -EINVAL;
1497                                         break;
1498                                 }
1499                                 if (left) {
1500                                         p++;
1501                                         left--;
1502                                 }
1503                         }
1504
1505                         bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1506                         proc_skip_char(&p, &left, '\n');
1507                 }
1508                 left += skipped;
1509         } else {
1510                 unsigned long bit_a, bit_b = 0;
1511                 bool first = 1;
1512
1513                 while (left) {
1514                         bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1515                         if (bit_a >= bitmap_len)
1516                                 break;
1517                         bit_b = find_next_zero_bit(bitmap, bitmap_len,
1518                                                    bit_a + 1) - 1;
1519
1520                         if (!first)
1521                                 proc_put_char(&buffer, &left, ',');
1522                         proc_put_long(&buffer, &left, bit_a, false);
1523                         if (bit_a != bit_b) {
1524                                 proc_put_char(&buffer, &left, '-');
1525                                 proc_put_long(&buffer, &left, bit_b, false);
1526                         }
1527
1528                         first = 0; bit_b++;
1529                 }
1530                 proc_put_char(&buffer, &left, '\n');
1531         }
1532
1533         if (!err) {
1534                 if (write) {
1535                         if (*ppos)
1536                                 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1537                         else
1538                                 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1539                 }
1540                 *lenp -= left;
1541                 *ppos += *lenp;
1542         }
1543
1544         bitmap_free(tmp_bitmap);
1545         return err;
1546 }
1547
1548 #else /* CONFIG_PROC_SYSCTL */
1549
1550 int proc_dostring(struct ctl_table *table, int write,
1551                   void *buffer, size_t *lenp, loff_t *ppos)
1552 {
1553         return -ENOSYS;
1554 }
1555
1556 int proc_dobool(struct ctl_table *table, int write,
1557                 void *buffer, size_t *lenp, loff_t *ppos)
1558 {
1559         return -ENOSYS;
1560 }
1561
1562 int proc_dointvec(struct ctl_table *table, int write,
1563                   void *buffer, size_t *lenp, loff_t *ppos)
1564 {
1565         return -ENOSYS;
1566 }
1567
1568 int proc_douintvec(struct ctl_table *table, int write,
1569                   void *buffer, size_t *lenp, loff_t *ppos)
1570 {
1571         return -ENOSYS;
1572 }
1573
1574 int proc_dointvec_minmax(struct ctl_table *table, int write,
1575                     void *buffer, size_t *lenp, loff_t *ppos)
1576 {
1577         return -ENOSYS;
1578 }
1579
1580 int proc_douintvec_minmax(struct ctl_table *table, int write,
1581                           void *buffer, size_t *lenp, loff_t *ppos)
1582 {
1583         return -ENOSYS;
1584 }
1585
1586 int proc_dou8vec_minmax(struct ctl_table *table, int write,
1587                         void *buffer, size_t *lenp, loff_t *ppos)
1588 {
1589         return -ENOSYS;
1590 }
1591
1592 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1593                     void *buffer, size_t *lenp, loff_t *ppos)
1594 {
1595         return -ENOSYS;
1596 }
1597
1598 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1599                     void *buffer, size_t *lenp, loff_t *ppos)
1600 {
1601         return -ENOSYS;
1602 }
1603
1604 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1605                              void *buffer, size_t *lenp, loff_t *ppos)
1606 {
1607         return -ENOSYS;
1608 }
1609
1610 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1611                     void *buffer, size_t *lenp, loff_t *ppos)
1612 {
1613         return -ENOSYS;
1614 }
1615
1616 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1617                                       void *buffer, size_t *lenp, loff_t *ppos)
1618 {
1619         return -ENOSYS;
1620 }
1621
1622 int proc_do_large_bitmap(struct ctl_table *table, int write,
1623                          void *buffer, size_t *lenp, loff_t *ppos)
1624 {
1625         return -ENOSYS;
1626 }
1627
1628 #endif /* CONFIG_PROC_SYSCTL */
1629
1630 #if defined(CONFIG_SYSCTL)
1631 int proc_do_static_key(struct ctl_table *table, int write,
1632                        void *buffer, size_t *lenp, loff_t *ppos)
1633 {
1634         struct static_key *key = (struct static_key *)table->data;
1635         static DEFINE_MUTEX(static_key_mutex);
1636         int val, ret;
1637         struct ctl_table tmp = {
1638                 .data   = &val,
1639                 .maxlen = sizeof(val),
1640                 .mode   = table->mode,
1641                 .extra1 = SYSCTL_ZERO,
1642                 .extra2 = SYSCTL_ONE,
1643         };
1644
1645         if (write && !capable(CAP_SYS_ADMIN))
1646                 return -EPERM;
1647
1648         mutex_lock(&static_key_mutex);
1649         val = static_key_enabled(key);
1650         ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1651         if (write && !ret) {
1652                 if (val)
1653                         static_key_enable(key);
1654                 else
1655                         static_key_disable(key);
1656         }
1657         mutex_unlock(&static_key_mutex);
1658         return ret;
1659 }
1660
1661 static struct ctl_table kern_table[] = {
1662         {
1663                 .procname       = "sched_child_runs_first",
1664                 .data           = &sysctl_sched_child_runs_first,
1665                 .maxlen         = sizeof(unsigned int),
1666                 .mode           = 0644,
1667                 .proc_handler   = proc_dointvec,
1668         },
1669 #ifdef CONFIG_SCHEDSTATS
1670         {
1671                 .procname       = "sched_schedstats",
1672                 .data           = NULL,
1673                 .maxlen         = sizeof(unsigned int),
1674                 .mode           = 0644,
1675                 .proc_handler   = sysctl_schedstats,
1676                 .extra1         = SYSCTL_ZERO,
1677                 .extra2         = SYSCTL_ONE,
1678         },
1679 #endif /* CONFIG_SCHEDSTATS */
1680 #ifdef CONFIG_TASK_DELAY_ACCT
1681         {
1682                 .procname       = "task_delayacct",
1683                 .data           = NULL,
1684                 .maxlen         = sizeof(unsigned int),
1685                 .mode           = 0644,
1686                 .proc_handler   = sysctl_delayacct,
1687                 .extra1         = SYSCTL_ZERO,
1688                 .extra2         = SYSCTL_ONE,
1689         },
1690 #endif /* CONFIG_TASK_DELAY_ACCT */
1691 #ifdef CONFIG_NUMA_BALANCING
1692         {
1693                 .procname       = "numa_balancing",
1694                 .data           = NULL, /* filled in by handler */
1695                 .maxlen         = sizeof(unsigned int),
1696                 .mode           = 0644,
1697                 .proc_handler   = sysctl_numa_balancing,
1698                 .extra1         = SYSCTL_ZERO,
1699                 .extra2         = SYSCTL_ONE,
1700         },
1701 #endif /* CONFIG_NUMA_BALANCING */
1702         {
1703                 .procname       = "sched_rt_period_us",
1704                 .data           = &sysctl_sched_rt_period,
1705                 .maxlen         = sizeof(unsigned int),
1706                 .mode           = 0644,
1707                 .proc_handler   = sched_rt_handler,
1708         },
1709         {
1710                 .procname       = "sched_rt_runtime_us",
1711                 .data           = &sysctl_sched_rt_runtime,
1712                 .maxlen         = sizeof(int),
1713                 .mode           = 0644,
1714                 .proc_handler   = sched_rt_handler,
1715         },
1716         {
1717                 .procname       = "sched_deadline_period_max_us",
1718                 .data           = &sysctl_sched_dl_period_max,
1719                 .maxlen         = sizeof(unsigned int),
1720                 .mode           = 0644,
1721                 .proc_handler   = proc_dointvec,
1722         },
1723         {
1724                 .procname       = "sched_deadline_period_min_us",
1725                 .data           = &sysctl_sched_dl_period_min,
1726                 .maxlen         = sizeof(unsigned int),
1727                 .mode           = 0644,
1728                 .proc_handler   = proc_dointvec,
1729         },
1730         {
1731                 .procname       = "sched_rr_timeslice_ms",
1732                 .data           = &sysctl_sched_rr_timeslice,
1733                 .maxlen         = sizeof(int),
1734                 .mode           = 0644,
1735                 .proc_handler   = sched_rr_handler,
1736         },
1737 #ifdef CONFIG_UCLAMP_TASK
1738         {
1739                 .procname       = "sched_util_clamp_min",
1740                 .data           = &sysctl_sched_uclamp_util_min,
1741                 .maxlen         = sizeof(unsigned int),
1742                 .mode           = 0644,
1743                 .proc_handler   = sysctl_sched_uclamp_handler,
1744         },
1745         {
1746                 .procname       = "sched_util_clamp_max",
1747                 .data           = &sysctl_sched_uclamp_util_max,
1748                 .maxlen         = sizeof(unsigned int),
1749                 .mode           = 0644,
1750                 .proc_handler   = sysctl_sched_uclamp_handler,
1751         },
1752         {
1753                 .procname       = "sched_util_clamp_min_rt_default",
1754                 .data           = &sysctl_sched_uclamp_util_min_rt_default,
1755                 .maxlen         = sizeof(unsigned int),
1756                 .mode           = 0644,
1757                 .proc_handler   = sysctl_sched_uclamp_handler,
1758         },
1759 #endif
1760 #ifdef CONFIG_SCHED_AUTOGROUP
1761         {
1762                 .procname       = "sched_autogroup_enabled",
1763                 .data           = &sysctl_sched_autogroup_enabled,
1764                 .maxlen         = sizeof(unsigned int),
1765                 .mode           = 0644,
1766                 .proc_handler   = proc_dointvec_minmax,
1767                 .extra1         = SYSCTL_ZERO,
1768                 .extra2         = SYSCTL_ONE,
1769         },
1770 #endif
1771 #ifdef CONFIG_CFS_BANDWIDTH
1772         {
1773                 .procname       = "sched_cfs_bandwidth_slice_us",
1774                 .data           = &sysctl_sched_cfs_bandwidth_slice,
1775                 .maxlen         = sizeof(unsigned int),
1776                 .mode           = 0644,
1777                 .proc_handler   = proc_dointvec_minmax,
1778                 .extra1         = SYSCTL_ONE,
1779         },
1780 #endif
1781 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
1782         {
1783                 .procname       = "sched_energy_aware",
1784                 .data           = &sysctl_sched_energy_aware,
1785                 .maxlen         = sizeof(unsigned int),
1786                 .mode           = 0644,
1787                 .proc_handler   = sched_energy_aware_handler,
1788                 .extra1         = SYSCTL_ZERO,
1789                 .extra2         = SYSCTL_ONE,
1790         },
1791 #endif
1792 #ifdef CONFIG_PROVE_LOCKING
1793         {
1794                 .procname       = "prove_locking",
1795                 .data           = &prove_locking,
1796                 .maxlen         = sizeof(int),
1797                 .mode           = 0644,
1798                 .proc_handler   = proc_dointvec,
1799         },
1800 #endif
1801 #ifdef CONFIG_LOCK_STAT
1802         {
1803                 .procname       = "lock_stat",
1804                 .data           = &lock_stat,
1805                 .maxlen         = sizeof(int),
1806                 .mode           = 0644,
1807                 .proc_handler   = proc_dointvec,
1808         },
1809 #endif
1810         {
1811                 .procname       = "panic",
1812                 .data           = &panic_timeout,
1813                 .maxlen         = sizeof(int),
1814                 .mode           = 0644,
1815                 .proc_handler   = proc_dointvec,
1816         },
1817 #ifdef CONFIG_PROC_SYSCTL
1818         {
1819                 .procname       = "tainted",
1820                 .maxlen         = sizeof(long),
1821                 .mode           = 0644,
1822                 .proc_handler   = proc_taint,
1823         },
1824         {
1825                 .procname       = "sysctl_writes_strict",
1826                 .data           = &sysctl_writes_strict,
1827                 .maxlen         = sizeof(int),
1828                 .mode           = 0644,
1829                 .proc_handler   = proc_dointvec_minmax,
1830                 .extra1         = SYSCTL_NEG_ONE,
1831                 .extra2         = SYSCTL_ONE,
1832         },
1833 #endif
1834 #ifdef CONFIG_LATENCYTOP
1835         {
1836                 .procname       = "latencytop",
1837                 .data           = &latencytop_enabled,
1838                 .maxlen         = sizeof(int),
1839                 .mode           = 0644,
1840                 .proc_handler   = sysctl_latencytop,
1841         },
1842 #endif
1843 #ifdef CONFIG_BLK_DEV_INITRD
1844         {
1845                 .procname       = "real-root-dev",
1846                 .data           = &real_root_dev,
1847                 .maxlen         = sizeof(int),
1848                 .mode           = 0644,
1849                 .proc_handler   = proc_dointvec,
1850         },
1851 #endif
1852         {
1853                 .procname       = "print-fatal-signals",
1854                 .data           = &print_fatal_signals,
1855                 .maxlen         = sizeof(int),
1856                 .mode           = 0644,
1857                 .proc_handler   = proc_dointvec,
1858         },
1859 #ifdef CONFIG_SPARC
1860         {
1861                 .procname       = "reboot-cmd",
1862                 .data           = reboot_command,
1863                 .maxlen         = 256,
1864                 .mode           = 0644,
1865                 .proc_handler   = proc_dostring,
1866         },
1867         {
1868                 .procname       = "stop-a",
1869                 .data           = &stop_a_enabled,
1870                 .maxlen         = sizeof (int),
1871                 .mode           = 0644,
1872                 .proc_handler   = proc_dointvec,
1873         },
1874         {
1875                 .procname       = "scons-poweroff",
1876                 .data           = &scons_pwroff,
1877                 .maxlen         = sizeof (int),
1878                 .mode           = 0644,
1879                 .proc_handler   = proc_dointvec,
1880         },
1881 #endif
1882 #ifdef CONFIG_SPARC64
1883         {
1884                 .procname       = "tsb-ratio",
1885                 .data           = &sysctl_tsb_ratio,
1886                 .maxlen         = sizeof (int),
1887                 .mode           = 0644,
1888                 .proc_handler   = proc_dointvec,
1889         },
1890 #endif
1891 #ifdef CONFIG_PARISC
1892         {
1893                 .procname       = "soft-power",
1894                 .data           = &pwrsw_enabled,
1895                 .maxlen         = sizeof (int),
1896                 .mode           = 0644,
1897                 .proc_handler   = proc_dointvec,
1898         },
1899 #endif
1900 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
1901         {
1902                 .procname       = "unaligned-trap",
1903                 .data           = &unaligned_enabled,
1904                 .maxlen         = sizeof (int),
1905                 .mode           = 0644,
1906                 .proc_handler   = proc_dointvec,
1907         },
1908 #endif
1909         {
1910                 .procname       = "ctrl-alt-del",
1911                 .data           = &C_A_D,
1912                 .maxlen         = sizeof(int),
1913                 .mode           = 0644,
1914                 .proc_handler   = proc_dointvec,
1915         },
1916 #ifdef CONFIG_FUNCTION_TRACER
1917         {
1918                 .procname       = "ftrace_enabled",
1919                 .data           = &ftrace_enabled,
1920                 .maxlen         = sizeof(int),
1921                 .mode           = 0644,
1922                 .proc_handler   = ftrace_enable_sysctl,
1923         },
1924 #endif
1925 #ifdef CONFIG_STACK_TRACER
1926         {
1927                 .procname       = "stack_tracer_enabled",
1928                 .data           = &stack_tracer_enabled,
1929                 .maxlen         = sizeof(int),
1930                 .mode           = 0644,
1931                 .proc_handler   = stack_trace_sysctl,
1932         },
1933 #endif
1934 #ifdef CONFIG_TRACING
1935         {
1936                 .procname       = "ftrace_dump_on_oops",
1937                 .data           = &ftrace_dump_on_oops,
1938                 .maxlen         = sizeof(int),
1939                 .mode           = 0644,
1940                 .proc_handler   = proc_dointvec,
1941         },
1942         {
1943                 .procname       = "traceoff_on_warning",
1944                 .data           = &__disable_trace_on_warning,
1945                 .maxlen         = sizeof(__disable_trace_on_warning),
1946                 .mode           = 0644,
1947                 .proc_handler   = proc_dointvec,
1948         },
1949         {
1950                 .procname       = "tracepoint_printk",
1951                 .data           = &tracepoint_printk,
1952                 .maxlen         = sizeof(tracepoint_printk),
1953                 .mode           = 0644,
1954                 .proc_handler   = tracepoint_printk_sysctl,
1955         },
1956 #endif
1957 #ifdef CONFIG_KEXEC_CORE
1958         {
1959                 .procname       = "kexec_load_disabled",
1960                 .data           = &kexec_load_disabled,
1961                 .maxlen         = sizeof(int),
1962                 .mode           = 0644,
1963                 /* only handle a transition from default "0" to "1" */
1964                 .proc_handler   = proc_dointvec_minmax,
1965                 .extra1         = SYSCTL_ONE,
1966                 .extra2         = SYSCTL_ONE,
1967         },
1968 #endif
1969 #ifdef CONFIG_MODULES
1970         {
1971                 .procname       = "modprobe",
1972                 .data           = &modprobe_path,
1973                 .maxlen         = KMOD_PATH_LEN,
1974                 .mode           = 0644,
1975                 .proc_handler   = proc_dostring,
1976         },
1977         {
1978                 .procname       = "modules_disabled",
1979                 .data           = &modules_disabled,
1980                 .maxlen         = sizeof(int),
1981                 .mode           = 0644,
1982                 /* only handle a transition from default "0" to "1" */
1983                 .proc_handler   = proc_dointvec_minmax,
1984                 .extra1         = SYSCTL_ONE,
1985                 .extra2         = SYSCTL_ONE,
1986         },
1987 #endif
1988 #ifdef CONFIG_UEVENT_HELPER
1989         {
1990                 .procname       = "hotplug",
1991                 .data           = &uevent_helper,
1992                 .maxlen         = UEVENT_HELPER_PATH_LEN,
1993                 .mode           = 0644,
1994                 .proc_handler   = proc_dostring,
1995         },
1996 #endif
1997 #ifdef CONFIG_BSD_PROCESS_ACCT
1998         {
1999                 .procname       = "acct",
2000                 .data           = &acct_parm,
2001                 .maxlen         = 3*sizeof(int),
2002                 .mode           = 0644,
2003                 .proc_handler   = proc_dointvec,
2004         },
2005 #endif
2006 #ifdef CONFIG_MAGIC_SYSRQ
2007         {
2008                 .procname       = "sysrq",
2009                 .data           = NULL,
2010                 .maxlen         = sizeof (int),
2011                 .mode           = 0644,
2012                 .proc_handler   = sysrq_sysctl_handler,
2013         },
2014 #endif
2015 #ifdef CONFIG_PROC_SYSCTL
2016         {
2017                 .procname       = "cad_pid",
2018                 .data           = NULL,
2019                 .maxlen         = sizeof (int),
2020                 .mode           = 0600,
2021                 .proc_handler   = proc_do_cad_pid,
2022         },
2023 #endif
2024         {
2025                 .procname       = "threads-max",
2026                 .data           = NULL,
2027                 .maxlen         = sizeof(int),
2028                 .mode           = 0644,
2029                 .proc_handler   = sysctl_max_threads,
2030         },
2031         {
2032                 .procname       = "usermodehelper",
2033                 .mode           = 0555,
2034                 .child          = usermodehelper_table,
2035         },
2036         {
2037                 .procname       = "overflowuid",
2038                 .data           = &overflowuid,
2039                 .maxlen         = sizeof(int),
2040                 .mode           = 0644,
2041                 .proc_handler   = proc_dointvec_minmax,
2042                 .extra1         = SYSCTL_ZERO,
2043                 .extra2         = SYSCTL_MAXOLDUID,
2044         },
2045         {
2046                 .procname       = "overflowgid",
2047                 .data           = &overflowgid,
2048                 .maxlen         = sizeof(int),
2049                 .mode           = 0644,
2050                 .proc_handler   = proc_dointvec_minmax,
2051                 .extra1         = SYSCTL_ZERO,
2052                 .extra2         = SYSCTL_MAXOLDUID,
2053         },
2054 #ifdef CONFIG_S390
2055         {
2056                 .procname       = "userprocess_debug",
2057                 .data           = &show_unhandled_signals,
2058                 .maxlen         = sizeof(int),
2059                 .mode           = 0644,
2060                 .proc_handler   = proc_dointvec,
2061         },
2062 #endif
2063 #ifdef CONFIG_SMP
2064         {
2065                 .procname       = "oops_all_cpu_backtrace",
2066                 .data           = &sysctl_oops_all_cpu_backtrace,
2067                 .maxlen         = sizeof(int),
2068                 .mode           = 0644,
2069                 .proc_handler   = proc_dointvec_minmax,
2070                 .extra1         = SYSCTL_ZERO,
2071                 .extra2         = SYSCTL_ONE,
2072         },
2073 #endif /* CONFIG_SMP */
2074         {
2075                 .procname       = "pid_max",
2076                 .data           = &pid_max,
2077                 .maxlen         = sizeof (int),
2078                 .mode           = 0644,
2079                 .proc_handler   = proc_dointvec_minmax,
2080                 .extra1         = &pid_max_min,
2081                 .extra2         = &pid_max_max,
2082         },
2083         {
2084                 .procname       = "panic_on_oops",
2085                 .data           = &panic_on_oops,
2086                 .maxlen         = sizeof(int),
2087                 .mode           = 0644,
2088                 .proc_handler   = proc_dointvec,
2089         },
2090         {
2091                 .procname       = "panic_print",
2092                 .data           = &panic_print,
2093                 .maxlen         = sizeof(unsigned long),
2094                 .mode           = 0644,
2095                 .proc_handler   = proc_doulongvec_minmax,
2096         },
2097         {
2098                 .procname       = "ngroups_max",
2099                 .data           = (void *)&ngroups_max,
2100                 .maxlen         = sizeof (int),
2101                 .mode           = 0444,
2102                 .proc_handler   = proc_dointvec,
2103         },
2104         {
2105                 .procname       = "cap_last_cap",
2106                 .data           = (void *)&cap_last_cap,
2107                 .maxlen         = sizeof(int),
2108                 .mode           = 0444,
2109                 .proc_handler   = proc_dointvec,
2110         },
2111 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
2112         {
2113                 .procname       = "unknown_nmi_panic",
2114                 .data           = &unknown_nmi_panic,
2115                 .maxlen         = sizeof (int),
2116                 .mode           = 0644,
2117                 .proc_handler   = proc_dointvec,
2118         },
2119 #endif
2120
2121 #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
2122         defined(CONFIG_DEBUG_STACKOVERFLOW)
2123         {
2124                 .procname       = "panic_on_stackoverflow",
2125                 .data           = &sysctl_panic_on_stackoverflow,
2126                 .maxlen         = sizeof(int),
2127                 .mode           = 0644,
2128                 .proc_handler   = proc_dointvec,
2129         },
2130 #endif
2131 #if defined(CONFIG_X86)
2132         {
2133                 .procname       = "panic_on_unrecovered_nmi",
2134                 .data           = &panic_on_unrecovered_nmi,
2135                 .maxlen         = sizeof(int),
2136                 .mode           = 0644,
2137                 .proc_handler   = proc_dointvec,
2138         },
2139         {
2140                 .procname       = "panic_on_io_nmi",
2141                 .data           = &panic_on_io_nmi,
2142                 .maxlen         = sizeof(int),
2143                 .mode           = 0644,
2144                 .proc_handler   = proc_dointvec,
2145         },
2146         {
2147                 .procname       = "bootloader_type",
2148                 .data           = &bootloader_type,
2149                 .maxlen         = sizeof (int),
2150                 .mode           = 0444,
2151                 .proc_handler   = proc_dointvec,
2152         },
2153         {
2154                 .procname       = "bootloader_version",
2155                 .data           = &bootloader_version,
2156                 .maxlen         = sizeof (int),
2157                 .mode           = 0444,
2158                 .proc_handler   = proc_dointvec,
2159         },
2160         {
2161                 .procname       = "io_delay_type",
2162                 .data           = &io_delay_type,
2163                 .maxlen         = sizeof(int),
2164                 .mode           = 0644,
2165                 .proc_handler   = proc_dointvec,
2166         },
2167 #endif
2168 #if defined(CONFIG_MMU)
2169         {
2170                 .procname       = "randomize_va_space",
2171                 .data           = &randomize_va_space,
2172                 .maxlen         = sizeof(int),
2173                 .mode           = 0644,
2174                 .proc_handler   = proc_dointvec,
2175         },
2176 #endif
2177 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
2178         {
2179                 .procname       = "spin_retry",
2180                 .data           = &spin_retry,
2181                 .maxlen         = sizeof (int),
2182                 .mode           = 0644,
2183                 .proc_handler   = proc_dointvec,
2184         },
2185 #endif
2186 #if     defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
2187         {
2188                 .procname       = "acpi_video_flags",
2189                 .data           = &acpi_realmode_flags,
2190                 .maxlen         = sizeof (unsigned long),
2191                 .mode           = 0644,
2192                 .proc_handler   = proc_doulongvec_minmax,
2193         },
2194 #endif
2195 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
2196         {
2197                 .procname       = "ignore-unaligned-usertrap",
2198                 .data           = &no_unaligned_warning,
2199                 .maxlen         = sizeof (int),
2200                 .mode           = 0644,
2201                 .proc_handler   = proc_dointvec,
2202         },
2203 #endif
2204 #ifdef CONFIG_IA64
2205         {
2206                 .procname       = "unaligned-dump-stack",
2207                 .data           = &unaligned_dump_stack,
2208                 .maxlen         = sizeof (int),
2209                 .mode           = 0644,
2210                 .proc_handler   = proc_dointvec,
2211         },
2212 #endif
2213 #ifdef CONFIG_RT_MUTEXES
2214         {
2215                 .procname       = "max_lock_depth",
2216                 .data           = &max_lock_depth,
2217                 .maxlen         = sizeof(int),
2218                 .mode           = 0644,
2219                 .proc_handler   = proc_dointvec,
2220         },
2221 #endif
2222         {
2223                 .procname       = "poweroff_cmd",
2224                 .data           = &poweroff_cmd,
2225                 .maxlen         = POWEROFF_CMD_PATH_LEN,
2226                 .mode           = 0644,
2227                 .proc_handler   = proc_dostring,
2228         },
2229 #ifdef CONFIG_KEYS
2230         {
2231                 .procname       = "keys",
2232                 .mode           = 0555,
2233                 .child          = key_sysctls,
2234         },
2235 #endif
2236 #ifdef CONFIG_PERF_EVENTS
2237         /*
2238          * User-space scripts rely on the existence of this file
2239          * as a feature check for perf_events being enabled.
2240          *
2241          * So it's an ABI, do not remove!
2242          */
2243         {
2244                 .procname       = "perf_event_paranoid",
2245                 .data           = &sysctl_perf_event_paranoid,
2246                 .maxlen         = sizeof(sysctl_perf_event_paranoid),
2247                 .mode           = 0644,
2248                 .proc_handler   = proc_dointvec,
2249         },
2250         {
2251                 .procname       = "perf_event_mlock_kb",
2252                 .data           = &sysctl_perf_event_mlock,
2253                 .maxlen         = sizeof(sysctl_perf_event_mlock),
2254                 .mode           = 0644,
2255                 .proc_handler   = proc_dointvec,
2256         },
2257         {
2258                 .procname       = "perf_event_max_sample_rate",
2259                 .data           = &sysctl_perf_event_sample_rate,
2260                 .maxlen         = sizeof(sysctl_perf_event_sample_rate),
2261                 .mode           = 0644,
2262                 .proc_handler   = perf_proc_update_handler,
2263                 .extra1         = SYSCTL_ONE,
2264         },
2265         {
2266                 .procname       = "perf_cpu_time_max_percent",
2267                 .data           = &sysctl_perf_cpu_time_max_percent,
2268                 .maxlen         = sizeof(sysctl_perf_cpu_time_max_percent),
2269                 .mode           = 0644,
2270                 .proc_handler   = perf_cpu_time_max_percent_handler,
2271                 .extra1         = SYSCTL_ZERO,
2272                 .extra2         = SYSCTL_ONE_HUNDRED,
2273         },
2274         {
2275                 .procname       = "perf_event_max_stack",
2276                 .data           = &sysctl_perf_event_max_stack,
2277                 .maxlen         = sizeof(sysctl_perf_event_max_stack),
2278                 .mode           = 0644,
2279                 .proc_handler   = perf_event_max_stack_handler,
2280                 .extra1         = SYSCTL_ZERO,
2281                 .extra2         = (void *)&six_hundred_forty_kb,
2282         },
2283         {
2284                 .procname       = "perf_event_max_contexts_per_stack",
2285                 .data           = &sysctl_perf_event_max_contexts_per_stack,
2286                 .maxlen         = sizeof(sysctl_perf_event_max_contexts_per_stack),
2287                 .mode           = 0644,
2288                 .proc_handler   = perf_event_max_stack_handler,
2289                 .extra1         = SYSCTL_ZERO,
2290                 .extra2         = SYSCTL_ONE_THOUSAND,
2291         },
2292 #endif
2293         {
2294                 .procname       = "panic_on_warn",
2295                 .data           = &panic_on_warn,
2296                 .maxlen         = sizeof(int),
2297                 .mode           = 0644,
2298                 .proc_handler   = proc_dointvec_minmax,
2299                 .extra1         = SYSCTL_ZERO,
2300                 .extra2         = SYSCTL_ONE,
2301         },
2302 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
2303         {
2304                 .procname       = "timer_migration",
2305                 .data           = &sysctl_timer_migration,
2306                 .maxlen         = sizeof(unsigned int),
2307                 .mode           = 0644,
2308                 .proc_handler   = timer_migration_handler,
2309                 .extra1         = SYSCTL_ZERO,
2310                 .extra2         = SYSCTL_ONE,
2311         },
2312 #endif
2313 #ifdef CONFIG_BPF_SYSCALL
2314         {
2315                 .procname       = "unprivileged_bpf_disabled",
2316                 .data           = &sysctl_unprivileged_bpf_disabled,
2317                 .maxlen         = sizeof(sysctl_unprivileged_bpf_disabled),
2318                 .mode           = 0644,
2319                 .proc_handler   = bpf_unpriv_handler,
2320                 .extra1         = SYSCTL_ZERO,
2321                 .extra2         = SYSCTL_TWO,
2322         },
2323         {
2324                 .procname       = "bpf_stats_enabled",
2325                 .data           = &bpf_stats_enabled_key.key,
2326                 .maxlen         = sizeof(bpf_stats_enabled_key),
2327                 .mode           = 0644,
2328                 .proc_handler   = bpf_stats_handler,
2329         },
2330 #endif
2331 #if defined(CONFIG_TREE_RCU)
2332         {
2333                 .procname       = "panic_on_rcu_stall",
2334                 .data           = &sysctl_panic_on_rcu_stall,
2335                 .maxlen         = sizeof(sysctl_panic_on_rcu_stall),
2336                 .mode           = 0644,
2337                 .proc_handler   = proc_dointvec_minmax,
2338                 .extra1         = SYSCTL_ZERO,
2339                 .extra2         = SYSCTL_ONE,
2340         },
2341 #endif
2342 #if defined(CONFIG_TREE_RCU)
2343         {
2344                 .procname       = "max_rcu_stall_to_panic",
2345                 .data           = &sysctl_max_rcu_stall_to_panic,
2346                 .maxlen         = sizeof(sysctl_max_rcu_stall_to_panic),
2347                 .mode           = 0644,
2348                 .proc_handler   = proc_dointvec_minmax,
2349                 .extra1         = SYSCTL_ONE,
2350                 .extra2         = SYSCTL_INT_MAX,
2351         },
2352 #endif
2353         { }
2354 };
2355
2356 static struct ctl_table vm_table[] = {
2357         {
2358                 .procname       = "overcommit_memory",
2359                 .data           = &sysctl_overcommit_memory,
2360                 .maxlen         = sizeof(sysctl_overcommit_memory),
2361                 .mode           = 0644,
2362                 .proc_handler   = overcommit_policy_handler,
2363                 .extra1         = SYSCTL_ZERO,
2364                 .extra2         = SYSCTL_TWO,
2365         },
2366         {
2367                 .procname       = "panic_on_oom",
2368                 .data           = &sysctl_panic_on_oom,
2369                 .maxlen         = sizeof(sysctl_panic_on_oom),
2370                 .mode           = 0644,
2371                 .proc_handler   = proc_dointvec_minmax,
2372                 .extra1         = SYSCTL_ZERO,
2373                 .extra2         = SYSCTL_TWO,
2374         },
2375         {
2376                 .procname       = "oom_kill_allocating_task",
2377                 .data           = &sysctl_oom_kill_allocating_task,
2378                 .maxlen         = sizeof(sysctl_oom_kill_allocating_task),
2379                 .mode           = 0644,
2380                 .proc_handler   = proc_dointvec,
2381         },
2382         {
2383                 .procname       = "oom_dump_tasks",
2384                 .data           = &sysctl_oom_dump_tasks,
2385                 .maxlen         = sizeof(sysctl_oom_dump_tasks),
2386                 .mode           = 0644,
2387                 .proc_handler   = proc_dointvec,
2388         },
2389         {
2390                 .procname       = "overcommit_ratio",
2391                 .data           = &sysctl_overcommit_ratio,
2392                 .maxlen         = sizeof(sysctl_overcommit_ratio),
2393                 .mode           = 0644,
2394                 .proc_handler   = overcommit_ratio_handler,
2395         },
2396         {
2397                 .procname       = "overcommit_kbytes",
2398                 .data           = &sysctl_overcommit_kbytes,
2399                 .maxlen         = sizeof(sysctl_overcommit_kbytes),
2400                 .mode           = 0644,
2401                 .proc_handler   = overcommit_kbytes_handler,
2402         },
2403         {
2404                 .procname       = "page-cluster",
2405                 .data           = &page_cluster,
2406                 .maxlen         = sizeof(int),
2407                 .mode           = 0644,
2408                 .proc_handler   = proc_dointvec_minmax,
2409                 .extra1         = SYSCTL_ZERO,
2410         },
2411         {
2412                 .procname       = "dirty_background_ratio",
2413                 .data           = &dirty_background_ratio,
2414                 .maxlen         = sizeof(dirty_background_ratio),
2415                 .mode           = 0644,
2416                 .proc_handler   = dirty_background_ratio_handler,
2417                 .extra1         = SYSCTL_ZERO,
2418                 .extra2         = SYSCTL_ONE_HUNDRED,
2419         },
2420         {
2421                 .procname       = "dirty_background_bytes",
2422                 .data           = &dirty_background_bytes,
2423                 .maxlen         = sizeof(dirty_background_bytes),
2424                 .mode           = 0644,
2425                 .proc_handler   = dirty_background_bytes_handler,
2426                 .extra1         = SYSCTL_LONG_ONE,
2427         },
2428         {
2429                 .procname       = "dirty_ratio",
2430                 .data           = &vm_dirty_ratio,
2431                 .maxlen         = sizeof(vm_dirty_ratio),
2432                 .mode           = 0644,
2433                 .proc_handler   = dirty_ratio_handler,
2434                 .extra1         = SYSCTL_ZERO,
2435                 .extra2         = SYSCTL_ONE_HUNDRED,
2436         },
2437         {
2438                 .procname       = "dirty_bytes",
2439                 .data           = &vm_dirty_bytes,
2440                 .maxlen         = sizeof(vm_dirty_bytes),
2441                 .mode           = 0644,
2442                 .proc_handler   = dirty_bytes_handler,
2443                 .extra1         = (void *)&dirty_bytes_min,
2444         },
2445         {
2446                 .procname       = "dirty_writeback_centisecs",
2447                 .data           = &dirty_writeback_interval,
2448                 .maxlen         = sizeof(dirty_writeback_interval),
2449                 .mode           = 0644,
2450                 .proc_handler   = dirty_writeback_centisecs_handler,
2451         },
2452         {
2453                 .procname       = "dirty_expire_centisecs",
2454                 .data           = &dirty_expire_interval,
2455                 .maxlen         = sizeof(dirty_expire_interval),
2456                 .mode           = 0644,
2457                 .proc_handler   = proc_dointvec_minmax,
2458                 .extra1         = SYSCTL_ZERO,
2459         },
2460         {
2461                 .procname       = "dirtytime_expire_seconds",
2462                 .data           = &dirtytime_expire_interval,
2463                 .maxlen         = sizeof(dirtytime_expire_interval),
2464                 .mode           = 0644,
2465                 .proc_handler   = dirtytime_interval_handler,
2466                 .extra1         = SYSCTL_ZERO,
2467         },
2468         {
2469                 .procname       = "swappiness",
2470                 .data           = &vm_swappiness,
2471                 .maxlen         = sizeof(vm_swappiness),
2472                 .mode           = 0644,
2473                 .proc_handler   = proc_dointvec_minmax,
2474                 .extra1         = SYSCTL_ZERO,
2475                 .extra2         = SYSCTL_TWO_HUNDRED,
2476         },
2477 #ifdef CONFIG_HUGETLB_PAGE
2478         {
2479                 .procname       = "nr_hugepages",
2480                 .data           = NULL,
2481                 .maxlen         = sizeof(unsigned long),
2482                 .mode           = 0644,
2483                 .proc_handler   = hugetlb_sysctl_handler,
2484         },
2485 #ifdef CONFIG_NUMA
2486         {
2487                 .procname       = "nr_hugepages_mempolicy",
2488                 .data           = NULL,
2489                 .maxlen         = sizeof(unsigned long),
2490                 .mode           = 0644,
2491                 .proc_handler   = &hugetlb_mempolicy_sysctl_handler,
2492         },
2493         {
2494                 .procname               = "numa_stat",
2495                 .data                   = &sysctl_vm_numa_stat,
2496                 .maxlen                 = sizeof(int),
2497                 .mode                   = 0644,
2498                 .proc_handler   = sysctl_vm_numa_stat_handler,
2499                 .extra1                 = SYSCTL_ZERO,
2500                 .extra2                 = SYSCTL_ONE,
2501         },
2502 #endif
2503          {
2504                 .procname       = "hugetlb_shm_group",
2505                 .data           = &sysctl_hugetlb_shm_group,
2506                 .maxlen         = sizeof(gid_t),
2507                 .mode           = 0644,
2508                 .proc_handler   = proc_dointvec,
2509          },
2510         {
2511                 .procname       = "nr_overcommit_hugepages",
2512                 .data           = NULL,
2513                 .maxlen         = sizeof(unsigned long),
2514                 .mode           = 0644,
2515                 .proc_handler   = hugetlb_overcommit_handler,
2516         },
2517 #endif
2518         {
2519                 .procname       = "lowmem_reserve_ratio",
2520                 .data           = &sysctl_lowmem_reserve_ratio,
2521                 .maxlen         = sizeof(sysctl_lowmem_reserve_ratio),
2522                 .mode           = 0644,
2523                 .proc_handler   = lowmem_reserve_ratio_sysctl_handler,
2524         },
2525         {
2526                 .procname       = "drop_caches",
2527                 .data           = &sysctl_drop_caches,
2528                 .maxlen         = sizeof(int),
2529                 .mode           = 0200,
2530                 .proc_handler   = drop_caches_sysctl_handler,
2531                 .extra1         = SYSCTL_ONE,
2532                 .extra2         = SYSCTL_FOUR,
2533         },
2534 #ifdef CONFIG_COMPACTION
2535         {
2536                 .procname       = "compact_memory",
2537                 .data           = NULL,
2538                 .maxlen         = sizeof(int),
2539                 .mode           = 0200,
2540                 .proc_handler   = sysctl_compaction_handler,
2541         },
2542         {
2543                 .procname       = "compaction_proactiveness",
2544                 .data           = &sysctl_compaction_proactiveness,
2545                 .maxlen         = sizeof(sysctl_compaction_proactiveness),
2546                 .mode           = 0644,
2547                 .proc_handler   = compaction_proactiveness_sysctl_handler,
2548                 .extra1         = SYSCTL_ZERO,
2549                 .extra2         = SYSCTL_ONE_HUNDRED,
2550         },
2551         {
2552                 .procname       = "extfrag_threshold",
2553                 .data           = &sysctl_extfrag_threshold,
2554                 .maxlen         = sizeof(int),
2555                 .mode           = 0644,
2556                 .proc_handler   = proc_dointvec_minmax,
2557                 .extra1         = SYSCTL_ZERO,
2558                 .extra2         = (void *)&max_extfrag_threshold,
2559         },
2560         {
2561                 .procname       = "compact_unevictable_allowed",
2562                 .data           = &sysctl_compact_unevictable_allowed,
2563                 .maxlen         = sizeof(int),
2564                 .mode           = 0644,
2565                 .proc_handler   = proc_dointvec_minmax_warn_RT_change,
2566                 .extra1         = SYSCTL_ZERO,
2567                 .extra2         = SYSCTL_ONE,
2568         },
2569
2570 #endif /* CONFIG_COMPACTION */
2571         {
2572                 .procname       = "min_free_kbytes",
2573                 .data           = &min_free_kbytes,
2574                 .maxlen         = sizeof(min_free_kbytes),
2575                 .mode           = 0644,
2576                 .proc_handler   = min_free_kbytes_sysctl_handler,
2577                 .extra1         = SYSCTL_ZERO,
2578         },
2579         {
2580                 .procname       = "watermark_boost_factor",
2581                 .data           = &watermark_boost_factor,
2582                 .maxlen         = sizeof(watermark_boost_factor),
2583                 .mode           = 0644,
2584                 .proc_handler   = proc_dointvec_minmax,
2585                 .extra1         = SYSCTL_ZERO,
2586         },
2587         {
2588                 .procname       = "watermark_scale_factor",
2589                 .data           = &watermark_scale_factor,
2590                 .maxlen         = sizeof(watermark_scale_factor),
2591                 .mode           = 0644,
2592                 .proc_handler   = watermark_scale_factor_sysctl_handler,
2593                 .extra1         = SYSCTL_ONE,
2594                 .extra2         = SYSCTL_THREE_THOUSAND,
2595         },
2596         {
2597                 .procname       = "percpu_pagelist_high_fraction",
2598                 .data           = &percpu_pagelist_high_fraction,
2599                 .maxlen         = sizeof(percpu_pagelist_high_fraction),
2600                 .mode           = 0644,
2601                 .proc_handler   = percpu_pagelist_high_fraction_sysctl_handler,
2602                 .extra1         = SYSCTL_ZERO,
2603         },
2604         {
2605                 .procname       = "page_lock_unfairness",
2606                 .data           = &sysctl_page_lock_unfairness,
2607                 .maxlen         = sizeof(sysctl_page_lock_unfairness),
2608                 .mode           = 0644,
2609                 .proc_handler   = proc_dointvec_minmax,
2610                 .extra1         = SYSCTL_ZERO,
2611         },
2612 #ifdef CONFIG_MMU
2613         {
2614                 .procname       = "max_map_count",
2615                 .data           = &sysctl_max_map_count,
2616                 .maxlen         = sizeof(sysctl_max_map_count),
2617                 .mode           = 0644,
2618                 .proc_handler   = proc_dointvec_minmax,
2619                 .extra1         = SYSCTL_ZERO,
2620         },
2621 #else
2622         {
2623                 .procname       = "nr_trim_pages",
2624                 .data           = &sysctl_nr_trim_pages,
2625                 .maxlen         = sizeof(sysctl_nr_trim_pages),
2626                 .mode           = 0644,
2627                 .proc_handler   = proc_dointvec_minmax,
2628                 .extra1         = SYSCTL_ZERO,
2629         },
2630 #endif
2631         {
2632                 .procname       = "laptop_mode",
2633                 .data           = &laptop_mode,
2634                 .maxlen         = sizeof(laptop_mode),
2635                 .mode           = 0644,
2636                 .proc_handler   = proc_dointvec_jiffies,
2637         },
2638         {
2639                 .procname       = "vfs_cache_pressure",
2640                 .data           = &sysctl_vfs_cache_pressure,
2641                 .maxlen         = sizeof(sysctl_vfs_cache_pressure),
2642                 .mode           = 0644,
2643                 .proc_handler   = proc_dointvec_minmax,
2644                 .extra1         = SYSCTL_ZERO,
2645         },
2646 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
2647     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
2648         {
2649                 .procname       = "legacy_va_layout",
2650                 .data           = &sysctl_legacy_va_layout,
2651                 .maxlen         = sizeof(sysctl_legacy_va_layout),
2652                 .mode           = 0644,
2653                 .proc_handler   = proc_dointvec_minmax,
2654                 .extra1         = SYSCTL_ZERO,
2655         },
2656 #endif
2657 #ifdef CONFIG_NUMA
2658         {
2659                 .procname       = "zone_reclaim_mode",
2660                 .data           = &node_reclaim_mode,
2661                 .maxlen         = sizeof(node_reclaim_mode),
2662                 .mode           = 0644,
2663                 .proc_handler   = proc_dointvec_minmax,
2664                 .extra1         = SYSCTL_ZERO,
2665         },
2666         {
2667                 .procname       = "min_unmapped_ratio",
2668                 .data           = &sysctl_min_unmapped_ratio,
2669                 .maxlen         = sizeof(sysctl_min_unmapped_ratio),
2670                 .mode           = 0644,
2671                 .proc_handler   = sysctl_min_unmapped_ratio_sysctl_handler,
2672                 .extra1         = SYSCTL_ZERO,
2673                 .extra2         = SYSCTL_ONE_HUNDRED,
2674         },
2675         {
2676                 .procname       = "min_slab_ratio",
2677                 .data           = &sysctl_min_slab_ratio,
2678                 .maxlen         = sizeof(sysctl_min_slab_ratio),
2679                 .mode           = 0644,
2680                 .proc_handler   = sysctl_min_slab_ratio_sysctl_handler,
2681                 .extra1         = SYSCTL_ZERO,
2682                 .extra2         = SYSCTL_ONE_HUNDRED,
2683         },
2684 #endif
2685 #ifdef CONFIG_SMP
2686         {
2687                 .procname       = "stat_interval",
2688                 .data           = &sysctl_stat_interval,
2689                 .maxlen         = sizeof(sysctl_stat_interval),
2690                 .mode           = 0644,
2691                 .proc_handler   = proc_dointvec_jiffies,
2692         },
2693         {
2694                 .procname       = "stat_refresh",
2695                 .data           = NULL,
2696                 .maxlen         = 0,
2697                 .mode           = 0600,
2698                 .proc_handler   = vmstat_refresh,
2699         },
2700 #endif
2701 #ifdef CONFIG_MMU
2702         {
2703                 .procname       = "mmap_min_addr",
2704                 .data           = &dac_mmap_min_addr,
2705                 .maxlen         = sizeof(unsigned long),
2706                 .mode           = 0644,
2707                 .proc_handler   = mmap_min_addr_handler,
2708         },
2709 #endif
2710 #ifdef CONFIG_NUMA
2711         {
2712                 .procname       = "numa_zonelist_order",
2713                 .data           = &numa_zonelist_order,
2714                 .maxlen         = NUMA_ZONELIST_ORDER_LEN,
2715                 .mode           = 0644,
2716                 .proc_handler   = numa_zonelist_order_handler,
2717         },
2718 #endif
2719 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
2720    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
2721         {
2722                 .procname       = "vdso_enabled",
2723 #ifdef CONFIG_X86_32
2724                 .data           = &vdso32_enabled,
2725                 .maxlen         = sizeof(vdso32_enabled),
2726 #else
2727                 .data           = &vdso_enabled,
2728                 .maxlen         = sizeof(vdso_enabled),
2729 #endif
2730                 .mode           = 0644,
2731                 .proc_handler   = proc_dointvec,
2732                 .extra1         = SYSCTL_ZERO,
2733         },
2734 #endif
2735 #ifdef CONFIG_HIGHMEM
2736         {
2737                 .procname       = "highmem_is_dirtyable",
2738                 .data           = &vm_highmem_is_dirtyable,
2739                 .maxlen         = sizeof(vm_highmem_is_dirtyable),
2740                 .mode           = 0644,
2741                 .proc_handler   = proc_dointvec_minmax,
2742                 .extra1         = SYSCTL_ZERO,
2743                 .extra2         = SYSCTL_ONE,
2744         },
2745 #endif
2746 #ifdef CONFIG_MEMORY_FAILURE
2747         {
2748                 .procname       = "memory_failure_early_kill",
2749                 .data           = &sysctl_memory_failure_early_kill,
2750                 .maxlen         = sizeof(sysctl_memory_failure_early_kill),
2751                 .mode           = 0644,
2752                 .proc_handler   = proc_dointvec_minmax,
2753                 .extra1         = SYSCTL_ZERO,
2754                 .extra2         = SYSCTL_ONE,
2755         },
2756         {
2757                 .procname       = "memory_failure_recovery",
2758                 .data           = &sysctl_memory_failure_recovery,
2759                 .maxlen         = sizeof(sysctl_memory_failure_recovery),
2760                 .mode           = 0644,
2761                 .proc_handler   = proc_dointvec_minmax,
2762                 .extra1         = SYSCTL_ZERO,
2763                 .extra2         = SYSCTL_ONE,
2764         },
2765 #endif
2766         {
2767                 .procname       = "user_reserve_kbytes",
2768                 .data           = &sysctl_user_reserve_kbytes,
2769                 .maxlen         = sizeof(sysctl_user_reserve_kbytes),
2770                 .mode           = 0644,
2771                 .proc_handler   = proc_doulongvec_minmax,
2772         },
2773         {
2774                 .procname       = "admin_reserve_kbytes",
2775                 .data           = &sysctl_admin_reserve_kbytes,
2776                 .maxlen         = sizeof(sysctl_admin_reserve_kbytes),
2777                 .mode           = 0644,
2778                 .proc_handler   = proc_doulongvec_minmax,
2779         },
2780 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
2781         {
2782                 .procname       = "mmap_rnd_bits",
2783                 .data           = &mmap_rnd_bits,
2784                 .maxlen         = sizeof(mmap_rnd_bits),
2785                 .mode           = 0600,
2786                 .proc_handler   = proc_dointvec_minmax,
2787                 .extra1         = (void *)&mmap_rnd_bits_min,
2788                 .extra2         = (void *)&mmap_rnd_bits_max,
2789         },
2790 #endif
2791 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
2792         {
2793                 .procname       = "mmap_rnd_compat_bits",
2794                 .data           = &mmap_rnd_compat_bits,
2795                 .maxlen         = sizeof(mmap_rnd_compat_bits),
2796                 .mode           = 0600,
2797                 .proc_handler   = proc_dointvec_minmax,
2798                 .extra1         = (void *)&mmap_rnd_compat_bits_min,
2799                 .extra2         = (void *)&mmap_rnd_compat_bits_max,
2800         },
2801 #endif
2802 #ifdef CONFIG_USERFAULTFD
2803         {
2804                 .procname       = "unprivileged_userfaultfd",
2805                 .data           = &sysctl_unprivileged_userfaultfd,
2806                 .maxlen         = sizeof(sysctl_unprivileged_userfaultfd),
2807                 .mode           = 0644,
2808                 .proc_handler   = proc_dointvec_minmax,
2809                 .extra1         = SYSCTL_ZERO,
2810                 .extra2         = SYSCTL_ONE,
2811         },
2812 #endif
2813         { }
2814 };
2815
2816 static struct ctl_table debug_table[] = {
2817 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
2818         {
2819                 .procname       = "exception-trace",
2820                 .data           = &show_unhandled_signals,
2821                 .maxlen         = sizeof(int),
2822                 .mode           = 0644,
2823                 .proc_handler   = proc_dointvec
2824         },
2825 #endif
2826         { }
2827 };
2828
2829 static struct ctl_table dev_table[] = {
2830         { }
2831 };
2832
2833 DECLARE_SYSCTL_BASE(kernel, kern_table);
2834 DECLARE_SYSCTL_BASE(vm, vm_table);
2835 DECLARE_SYSCTL_BASE(debug, debug_table);
2836 DECLARE_SYSCTL_BASE(dev, dev_table);
2837
2838 int __init sysctl_init_bases(void)
2839 {
2840         register_sysctl_base(kernel);
2841         register_sysctl_base(vm);
2842         register_sysctl_base(debug);
2843         register_sysctl_base(dev);
2844
2845         return 0;
2846 }
2847 #endif /* CONFIG_SYSCTL */
2848 /*
2849  * No sense putting this after each symbol definition, twice,
2850  * exception granted :-)
2851  */
2852 EXPORT_SYMBOL(proc_dobool);
2853 EXPORT_SYMBOL(proc_dointvec);
2854 EXPORT_SYMBOL(proc_douintvec);
2855 EXPORT_SYMBOL(proc_dointvec_jiffies);
2856 EXPORT_SYMBOL(proc_dointvec_minmax);
2857 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
2858 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2859 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2860 EXPORT_SYMBOL(proc_dostring);
2861 EXPORT_SYMBOL(proc_doulongvec_minmax);
2862 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2863 EXPORT_SYMBOL(proc_do_large_bitmap);