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