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