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