fs: move shared sysctls to fs/sysctls.c
[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 static void validate_coredump_safety(void)
1121 {
1122 #ifdef CONFIG_COREDUMP
1123         if (suid_dumpable == SUID_DUMP_ROOT &&
1124             core_pattern[0] != '/' && core_pattern[0] != '|') {
1125                 printk(KERN_WARNING
1126 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
1127 "Pipe handler or fully qualified core dump path required.\n"
1128 "Set kernel.core_pattern before fs.suid_dumpable.\n"
1129                 );
1130         }
1131 #endif
1132 }
1133
1134 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
1135                 void *buffer, size_t *lenp, loff_t *ppos)
1136 {
1137         int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1138         if (!error)
1139                 validate_coredump_safety();
1140         return error;
1141 }
1142
1143 #ifdef CONFIG_COREDUMP
1144 static int proc_dostring_coredump(struct ctl_table *table, int write,
1145                   void *buffer, size_t *lenp, loff_t *ppos)
1146 {
1147         int error = proc_dostring(table, write, buffer, lenp, ppos);
1148         if (!error)
1149                 validate_coredump_safety();
1150         return error;
1151 }
1152 #endif
1153
1154 #ifdef CONFIG_MAGIC_SYSRQ
1155 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
1156                                 void *buffer, size_t *lenp, loff_t *ppos)
1157 {
1158         int tmp, ret;
1159
1160         tmp = sysrq_mask();
1161
1162         ret = __do_proc_dointvec(&tmp, table, write, buffer,
1163                                lenp, ppos, NULL, NULL);
1164         if (ret || !write)
1165                 return ret;
1166
1167         if (write)
1168                 sysrq_toggle_support(tmp);
1169
1170         return 0;
1171 }
1172 #endif
1173
1174 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
1175                 int write, void *buffer, size_t *lenp, loff_t *ppos,
1176                 unsigned long convmul, unsigned long convdiv)
1177 {
1178         unsigned long *i, *min, *max;
1179         int vleft, first = 1, err = 0;
1180         size_t left;
1181         char *p;
1182
1183         if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1184                 *lenp = 0;
1185                 return 0;
1186         }
1187
1188         i = (unsigned long *) data;
1189         min = (unsigned long *) table->extra1;
1190         max = (unsigned long *) table->extra2;
1191         vleft = table->maxlen / sizeof(unsigned long);
1192         left = *lenp;
1193
1194         if (write) {
1195                 if (proc_first_pos_non_zero_ignore(ppos, table))
1196                         goto out;
1197
1198                 if (left > PAGE_SIZE - 1)
1199                         left = PAGE_SIZE - 1;
1200                 p = buffer;
1201         }
1202
1203         for (; left && vleft--; i++, first = 0) {
1204                 unsigned long val;
1205
1206                 if (write) {
1207                         bool neg;
1208
1209                         left -= proc_skip_spaces(&p);
1210                         if (!left)
1211                                 break;
1212
1213                         err = proc_get_long(&p, &left, &val, &neg,
1214                                              proc_wspace_sep,
1215                                              sizeof(proc_wspace_sep), NULL);
1216                         if (err)
1217                                 break;
1218                         if (neg)
1219                                 continue;
1220                         val = convmul * val / convdiv;
1221                         if ((min && val < *min) || (max && val > *max)) {
1222                                 err = -EINVAL;
1223                                 break;
1224                         }
1225                         *i = val;
1226                 } else {
1227                         val = convdiv * (*i) / convmul;
1228                         if (!first)
1229                                 proc_put_char(&buffer, &left, '\t');
1230                         proc_put_long(&buffer, &left, val, false);
1231                 }
1232         }
1233
1234         if (!write && !first && left && !err)
1235                 proc_put_char(&buffer, &left, '\n');
1236         if (write && !err)
1237                 left -= proc_skip_spaces(&p);
1238         if (write && first)
1239                 return err ? : -EINVAL;
1240         *lenp -= left;
1241 out:
1242         *ppos += *lenp;
1243         return err;
1244 }
1245
1246 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
1247                 void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1248                 unsigned long convdiv)
1249 {
1250         return __do_proc_doulongvec_minmax(table->data, table, write,
1251                         buffer, lenp, ppos, convmul, convdiv);
1252 }
1253
1254 /**
1255  * proc_doulongvec_minmax - read a vector of long integers with min/max values
1256  * @table: the sysctl table
1257  * @write: %TRUE if this is a write to the sysctl file
1258  * @buffer: the user buffer
1259  * @lenp: the size of the user buffer
1260  * @ppos: file position
1261  *
1262  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1263  * values from/to the user buffer, treated as an ASCII string.
1264  *
1265  * This routine will ensure the values are within the range specified by
1266  * table->extra1 (min) and table->extra2 (max).
1267  *
1268  * Returns 0 on success.
1269  */
1270 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1271                            void *buffer, size_t *lenp, loff_t *ppos)
1272 {
1273     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1274 }
1275
1276 /**
1277  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1278  * @table: the sysctl table
1279  * @write: %TRUE if this is a write to the sysctl file
1280  * @buffer: the user buffer
1281  * @lenp: the size of the user buffer
1282  * @ppos: file position
1283  *
1284  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1285  * values from/to the user buffer, treated as an ASCII string. The values
1286  * are treated as milliseconds, and converted to jiffies when they are stored.
1287  *
1288  * This routine will ensure the values are within the range specified by
1289  * table->extra1 (min) and table->extra2 (max).
1290  *
1291  * Returns 0 on success.
1292  */
1293 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1294                                       void *buffer, size_t *lenp, loff_t *ppos)
1295 {
1296     return do_proc_doulongvec_minmax(table, write, buffer,
1297                                      lenp, ppos, HZ, 1000l);
1298 }
1299
1300
1301 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1302                                          int *valp,
1303                                          int write, void *data)
1304 {
1305         if (write) {
1306                 if (*lvalp > INT_MAX / HZ)
1307                         return 1;
1308                 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1309         } else {
1310                 int val = *valp;
1311                 unsigned long lval;
1312                 if (val < 0) {
1313                         *negp = true;
1314                         lval = -(unsigned long)val;
1315                 } else {
1316                         *negp = false;
1317                         lval = (unsigned long)val;
1318                 }
1319                 *lvalp = lval / HZ;
1320         }
1321         return 0;
1322 }
1323
1324 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1325                                                 int *valp,
1326                                                 int write, void *data)
1327 {
1328         if (write) {
1329                 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1330                         return 1;
1331                 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1332         } else {
1333                 int val = *valp;
1334                 unsigned long lval;
1335                 if (val < 0) {
1336                         *negp = true;
1337                         lval = -(unsigned long)val;
1338                 } else {
1339                         *negp = false;
1340                         lval = (unsigned long)val;
1341                 }
1342                 *lvalp = jiffies_to_clock_t(lval);
1343         }
1344         return 0;
1345 }
1346
1347 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1348                                             int *valp,
1349                                             int write, void *data)
1350 {
1351         if (write) {
1352                 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1353
1354                 if (jif > INT_MAX)
1355                         return 1;
1356                 *valp = (int)jif;
1357         } else {
1358                 int val = *valp;
1359                 unsigned long lval;
1360                 if (val < 0) {
1361                         *negp = true;
1362                         lval = -(unsigned long)val;
1363                 } else {
1364                         *negp = false;
1365                         lval = (unsigned long)val;
1366                 }
1367                 *lvalp = jiffies_to_msecs(lval);
1368         }
1369         return 0;
1370 }
1371
1372 /**
1373  * proc_dointvec_jiffies - read a vector of integers as seconds
1374  * @table: the sysctl table
1375  * @write: %TRUE if this is a write to the sysctl file
1376  * @buffer: the user buffer
1377  * @lenp: the size of the user buffer
1378  * @ppos: file position
1379  *
1380  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1381  * values from/to the user buffer, treated as an ASCII string. 
1382  * The values read are assumed to be in seconds, and are converted into
1383  * jiffies.
1384  *
1385  * Returns 0 on success.
1386  */
1387 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1388                           void *buffer, size_t *lenp, loff_t *ppos)
1389 {
1390     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1391                             do_proc_dointvec_jiffies_conv,NULL);
1392 }
1393
1394 /**
1395  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1396  * @table: the sysctl table
1397  * @write: %TRUE if this is a write to the sysctl file
1398  * @buffer: the user buffer
1399  * @lenp: the size of the user buffer
1400  * @ppos: pointer to the file position
1401  *
1402  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1403  * values from/to the user buffer, treated as an ASCII string. 
1404  * The values read are assumed to be in 1/USER_HZ seconds, and 
1405  * are converted into jiffies.
1406  *
1407  * Returns 0 on success.
1408  */
1409 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1410                                  void *buffer, size_t *lenp, loff_t *ppos)
1411 {
1412     return do_proc_dointvec(table,write,buffer,lenp,ppos,
1413                             do_proc_dointvec_userhz_jiffies_conv,NULL);
1414 }
1415
1416 /**
1417  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1418  * @table: the sysctl table
1419  * @write: %TRUE if this is a write to the sysctl file
1420  * @buffer: the user buffer
1421  * @lenp: the size of the user buffer
1422  * @ppos: file position
1423  * @ppos: the current position in the file
1424  *
1425  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1426  * values from/to the user buffer, treated as an ASCII string. 
1427  * The values read are assumed to be in 1/1000 seconds, and 
1428  * are converted into jiffies.
1429  *
1430  * Returns 0 on success.
1431  */
1432 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
1433                 size_t *lenp, loff_t *ppos)
1434 {
1435         return do_proc_dointvec(table, write, buffer, lenp, ppos,
1436                                 do_proc_dointvec_ms_jiffies_conv, NULL);
1437 }
1438
1439 static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
1440                 size_t *lenp, loff_t *ppos)
1441 {
1442         struct pid *new_pid;
1443         pid_t tmp;
1444         int r;
1445
1446         tmp = pid_vnr(cad_pid);
1447
1448         r = __do_proc_dointvec(&tmp, table, write, buffer,
1449                                lenp, ppos, NULL, NULL);
1450         if (r || !write)
1451                 return r;
1452
1453         new_pid = find_get_pid(tmp);
1454         if (!new_pid)
1455                 return -ESRCH;
1456
1457         put_pid(xchg(&cad_pid, new_pid));
1458         return 0;
1459 }
1460
1461 /**
1462  * proc_do_large_bitmap - read/write from/to a large bitmap
1463  * @table: the sysctl table
1464  * @write: %TRUE if this is a write to the sysctl file
1465  * @buffer: the user buffer
1466  * @lenp: the size of the user buffer
1467  * @ppos: file position
1468  *
1469  * The bitmap is stored at table->data and the bitmap length (in bits)
1470  * in table->maxlen.
1471  *
1472  * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1473  * large bitmaps may be represented in a compact manner. Writing into
1474  * the file will clear the bitmap then update it with the given input.
1475  *
1476  * Returns 0 on success.
1477  */
1478 int proc_do_large_bitmap(struct ctl_table *table, int write,
1479                          void *buffer, size_t *lenp, loff_t *ppos)
1480 {
1481         int err = 0;
1482         size_t left = *lenp;
1483         unsigned long bitmap_len = table->maxlen;
1484         unsigned long *bitmap = *(unsigned long **) table->data;
1485         unsigned long *tmp_bitmap = NULL;
1486         char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1487
1488         if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1489                 *lenp = 0;
1490                 return 0;
1491         }
1492
1493         if (write) {
1494                 char *p = buffer;
1495                 size_t skipped = 0;
1496
1497                 if (left > PAGE_SIZE - 1) {
1498                         left = PAGE_SIZE - 1;
1499                         /* How much of the buffer we'll skip this pass */
1500                         skipped = *lenp - left;
1501                 }
1502
1503                 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
1504                 if (!tmp_bitmap)
1505                         return -ENOMEM;
1506                 proc_skip_char(&p, &left, '\n');
1507                 while (!err && left) {
1508                         unsigned long val_a, val_b;
1509                         bool neg;
1510                         size_t saved_left;
1511
1512                         /* In case we stop parsing mid-number, we can reset */
1513                         saved_left = left;
1514                         err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1515                                              sizeof(tr_a), &c);
1516                         /*
1517                          * If we consumed the entirety of a truncated buffer or
1518                          * only one char is left (may be a "-"), then stop here,
1519                          * reset, & come back for more.
1520                          */
1521                         if ((left <= 1) && skipped) {
1522                                 left = saved_left;
1523                                 break;
1524                         }
1525
1526                         if (err)
1527                                 break;
1528                         if (val_a >= bitmap_len || neg) {
1529                                 err = -EINVAL;
1530                                 break;
1531                         }
1532
1533                         val_b = val_a;
1534                         if (left) {
1535                                 p++;
1536                                 left--;
1537                         }
1538
1539                         if (c == '-') {
1540                                 err = proc_get_long(&p, &left, &val_b,
1541                                                      &neg, tr_b, sizeof(tr_b),
1542                                                      &c);
1543                                 /*
1544                                  * If we consumed all of a truncated buffer or
1545                                  * then stop here, reset, & come back for more.
1546                                  */
1547                                 if (!left && skipped) {
1548                                         left = saved_left;
1549                                         break;
1550                                 }
1551
1552                                 if (err)
1553                                         break;
1554                                 if (val_b >= bitmap_len || neg ||
1555                                     val_a > val_b) {
1556                                         err = -EINVAL;
1557                                         break;
1558                                 }
1559                                 if (left) {
1560                                         p++;
1561                                         left--;
1562                                 }
1563                         }
1564
1565                         bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1566                         proc_skip_char(&p, &left, '\n');
1567                 }
1568                 left += skipped;
1569         } else {
1570                 unsigned long bit_a, bit_b = 0;
1571                 bool first = 1;
1572
1573                 while (left) {
1574                         bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1575                         if (bit_a >= bitmap_len)
1576                                 break;
1577                         bit_b = find_next_zero_bit(bitmap, bitmap_len,
1578                                                    bit_a + 1) - 1;
1579
1580                         if (!first)
1581                                 proc_put_char(&buffer, &left, ',');
1582                         proc_put_long(&buffer, &left, bit_a, false);
1583                         if (bit_a != bit_b) {
1584                                 proc_put_char(&buffer, &left, '-');
1585                                 proc_put_long(&buffer, &left, bit_b, false);
1586                         }
1587
1588                         first = 0; bit_b++;
1589                 }
1590                 proc_put_char(&buffer, &left, '\n');
1591         }
1592
1593         if (!err) {
1594                 if (write) {
1595                         if (*ppos)
1596                                 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1597                         else
1598                                 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1599                 }
1600                 *lenp -= left;
1601                 *ppos += *lenp;
1602         }
1603
1604         bitmap_free(tmp_bitmap);
1605         return err;
1606 }
1607
1608 #else /* CONFIG_PROC_SYSCTL */
1609
1610 int proc_dostring(struct ctl_table *table, int write,
1611                   void *buffer, size_t *lenp, loff_t *ppos)
1612 {
1613         return -ENOSYS;
1614 }
1615
1616 int proc_dobool(struct ctl_table *table, int write,
1617                 void *buffer, size_t *lenp, loff_t *ppos)
1618 {
1619         return -ENOSYS;
1620 }
1621
1622 int proc_dointvec(struct ctl_table *table, int write,
1623                   void *buffer, size_t *lenp, loff_t *ppos)
1624 {
1625         return -ENOSYS;
1626 }
1627
1628 int proc_douintvec(struct ctl_table *table, int write,
1629                   void *buffer, size_t *lenp, loff_t *ppos)
1630 {
1631         return -ENOSYS;
1632 }
1633
1634 int proc_dointvec_minmax(struct ctl_table *table, int write,
1635                     void *buffer, size_t *lenp, loff_t *ppos)
1636 {
1637         return -ENOSYS;
1638 }
1639
1640 int proc_douintvec_minmax(struct ctl_table *table, int write,
1641                           void *buffer, size_t *lenp, loff_t *ppos)
1642 {
1643         return -ENOSYS;
1644 }
1645
1646 int proc_dou8vec_minmax(struct ctl_table *table, int write,
1647                         void *buffer, size_t *lenp, loff_t *ppos)
1648 {
1649         return -ENOSYS;
1650 }
1651
1652 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1653                     void *buffer, size_t *lenp, loff_t *ppos)
1654 {
1655         return -ENOSYS;
1656 }
1657
1658 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1659                     void *buffer, size_t *lenp, loff_t *ppos)
1660 {
1661         return -ENOSYS;
1662 }
1663
1664 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1665                              void *buffer, size_t *lenp, loff_t *ppos)
1666 {
1667         return -ENOSYS;
1668 }
1669
1670 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1671                     void *buffer, size_t *lenp, loff_t *ppos)
1672 {
1673         return -ENOSYS;
1674 }
1675
1676 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1677                                       void *buffer, size_t *lenp, loff_t *ppos)
1678 {
1679         return -ENOSYS;
1680 }
1681
1682 int proc_do_large_bitmap(struct ctl_table *table, int write,
1683                          void *buffer, size_t *lenp, loff_t *ppos)
1684 {
1685         return -ENOSYS;
1686 }
1687
1688 #endif /* CONFIG_PROC_SYSCTL */
1689
1690 #if defined(CONFIG_SYSCTL)
1691 int proc_do_static_key(struct ctl_table *table, int write,
1692                        void *buffer, size_t *lenp, loff_t *ppos)
1693 {
1694         struct static_key *key = (struct static_key *)table->data;
1695         static DEFINE_MUTEX(static_key_mutex);
1696         int val, ret;
1697         struct ctl_table tmp = {
1698                 .data   = &val,
1699                 .maxlen = sizeof(val),
1700                 .mode   = table->mode,
1701                 .extra1 = SYSCTL_ZERO,
1702                 .extra2 = SYSCTL_ONE,
1703         };
1704
1705         if (write && !capable(CAP_SYS_ADMIN))
1706                 return -EPERM;
1707
1708         mutex_lock(&static_key_mutex);
1709         val = static_key_enabled(key);
1710         ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1711         if (write && !ret) {
1712                 if (val)
1713                         static_key_enable(key);
1714                 else
1715                         static_key_disable(key);
1716         }
1717         mutex_unlock(&static_key_mutex);
1718         return ret;
1719 }
1720
1721 static struct ctl_table kern_table[] = {
1722         {
1723                 .procname       = "sched_child_runs_first",
1724                 .data           = &sysctl_sched_child_runs_first,
1725                 .maxlen         = sizeof(unsigned int),
1726                 .mode           = 0644,
1727                 .proc_handler   = proc_dointvec,
1728         },
1729 #ifdef CONFIG_SCHEDSTATS
1730         {
1731                 .procname       = "sched_schedstats",
1732                 .data           = NULL,
1733                 .maxlen         = sizeof(unsigned int),
1734                 .mode           = 0644,
1735                 .proc_handler   = sysctl_schedstats,
1736                 .extra1         = SYSCTL_ZERO,
1737                 .extra2         = SYSCTL_ONE,
1738         },
1739 #endif /* CONFIG_SCHEDSTATS */
1740 #ifdef CONFIG_TASK_DELAY_ACCT
1741         {
1742                 .procname       = "task_delayacct",
1743                 .data           = NULL,
1744                 .maxlen         = sizeof(unsigned int),
1745                 .mode           = 0644,
1746                 .proc_handler   = sysctl_delayacct,
1747                 .extra1         = SYSCTL_ZERO,
1748                 .extra2         = SYSCTL_ONE,
1749         },
1750 #endif /* CONFIG_TASK_DELAY_ACCT */
1751 #ifdef CONFIG_NUMA_BALANCING
1752         {
1753                 .procname       = "numa_balancing",
1754                 .data           = NULL, /* filled in by handler */
1755                 .maxlen         = sizeof(unsigned int),
1756                 .mode           = 0644,
1757                 .proc_handler   = sysctl_numa_balancing,
1758                 .extra1         = SYSCTL_ZERO,
1759                 .extra2         = SYSCTL_ONE,
1760         },
1761 #endif /* CONFIG_NUMA_BALANCING */
1762         {
1763                 .procname       = "sched_rt_period_us",
1764                 .data           = &sysctl_sched_rt_period,
1765                 .maxlen         = sizeof(unsigned int),
1766                 .mode           = 0644,
1767                 .proc_handler   = sched_rt_handler,
1768         },
1769         {
1770                 .procname       = "sched_rt_runtime_us",
1771                 .data           = &sysctl_sched_rt_runtime,
1772                 .maxlen         = sizeof(int),
1773                 .mode           = 0644,
1774                 .proc_handler   = sched_rt_handler,
1775         },
1776         {
1777                 .procname       = "sched_deadline_period_max_us",
1778                 .data           = &sysctl_sched_dl_period_max,
1779                 .maxlen         = sizeof(unsigned int),
1780                 .mode           = 0644,
1781                 .proc_handler   = proc_dointvec,
1782         },
1783         {
1784                 .procname       = "sched_deadline_period_min_us",
1785                 .data           = &sysctl_sched_dl_period_min,
1786                 .maxlen         = sizeof(unsigned int),
1787                 .mode           = 0644,
1788                 .proc_handler   = proc_dointvec,
1789         },
1790         {
1791                 .procname       = "sched_rr_timeslice_ms",
1792                 .data           = &sysctl_sched_rr_timeslice,
1793                 .maxlen         = sizeof(int),
1794                 .mode           = 0644,
1795                 .proc_handler   = sched_rr_handler,
1796         },
1797 #ifdef CONFIG_UCLAMP_TASK
1798         {
1799                 .procname       = "sched_util_clamp_min",
1800                 .data           = &sysctl_sched_uclamp_util_min,
1801                 .maxlen         = sizeof(unsigned int),
1802                 .mode           = 0644,
1803                 .proc_handler   = sysctl_sched_uclamp_handler,
1804         },
1805         {
1806                 .procname       = "sched_util_clamp_max",
1807                 .data           = &sysctl_sched_uclamp_util_max,
1808                 .maxlen         = sizeof(unsigned int),
1809                 .mode           = 0644,
1810                 .proc_handler   = sysctl_sched_uclamp_handler,
1811         },
1812         {
1813                 .procname       = "sched_util_clamp_min_rt_default",
1814                 .data           = &sysctl_sched_uclamp_util_min_rt_default,
1815                 .maxlen         = sizeof(unsigned int),
1816                 .mode           = 0644,
1817                 .proc_handler   = sysctl_sched_uclamp_handler,
1818         },
1819 #endif
1820 #ifdef CONFIG_SCHED_AUTOGROUP
1821         {
1822                 .procname       = "sched_autogroup_enabled",
1823                 .data           = &sysctl_sched_autogroup_enabled,
1824                 .maxlen         = sizeof(unsigned int),
1825                 .mode           = 0644,
1826                 .proc_handler   = proc_dointvec_minmax,
1827                 .extra1         = SYSCTL_ZERO,
1828                 .extra2         = SYSCTL_ONE,
1829         },
1830 #endif
1831 #ifdef CONFIG_CFS_BANDWIDTH
1832         {
1833                 .procname       = "sched_cfs_bandwidth_slice_us",
1834                 .data           = &sysctl_sched_cfs_bandwidth_slice,
1835                 .maxlen         = sizeof(unsigned int),
1836                 .mode           = 0644,
1837                 .proc_handler   = proc_dointvec_minmax,
1838                 .extra1         = SYSCTL_ONE,
1839         },
1840 #endif
1841 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
1842         {
1843                 .procname       = "sched_energy_aware",
1844                 .data           = &sysctl_sched_energy_aware,
1845                 .maxlen         = sizeof(unsigned int),
1846                 .mode           = 0644,
1847                 .proc_handler   = sched_energy_aware_handler,
1848                 .extra1         = SYSCTL_ZERO,
1849                 .extra2         = SYSCTL_ONE,
1850         },
1851 #endif
1852 #ifdef CONFIG_PROVE_LOCKING
1853         {
1854                 .procname       = "prove_locking",
1855                 .data           = &prove_locking,
1856                 .maxlen         = sizeof(int),
1857                 .mode           = 0644,
1858                 .proc_handler   = proc_dointvec,
1859         },
1860 #endif
1861 #ifdef CONFIG_LOCK_STAT
1862         {
1863                 .procname       = "lock_stat",
1864                 .data           = &lock_stat,
1865                 .maxlen         = sizeof(int),
1866                 .mode           = 0644,
1867                 .proc_handler   = proc_dointvec,
1868         },
1869 #endif
1870         {
1871                 .procname       = "panic",
1872                 .data           = &panic_timeout,
1873                 .maxlen         = sizeof(int),
1874                 .mode           = 0644,
1875                 .proc_handler   = proc_dointvec,
1876         },
1877 #ifdef CONFIG_COREDUMP
1878         {
1879                 .procname       = "core_uses_pid",
1880                 .data           = &core_uses_pid,
1881                 .maxlen         = sizeof(int),
1882                 .mode           = 0644,
1883                 .proc_handler   = proc_dointvec,
1884         },
1885         {
1886                 .procname       = "core_pattern",
1887                 .data           = core_pattern,
1888                 .maxlen         = CORENAME_MAX_SIZE,
1889                 .mode           = 0644,
1890                 .proc_handler   = proc_dostring_coredump,
1891         },
1892         {
1893                 .procname       = "core_pipe_limit",
1894                 .data           = &core_pipe_limit,
1895                 .maxlen         = sizeof(unsigned int),
1896                 .mode           = 0644,
1897                 .proc_handler   = proc_dointvec,
1898         },
1899 #endif
1900 #ifdef CONFIG_PROC_SYSCTL
1901         {
1902                 .procname       = "tainted",
1903                 .maxlen         = sizeof(long),
1904                 .mode           = 0644,
1905                 .proc_handler   = proc_taint,
1906         },
1907         {
1908                 .procname       = "sysctl_writes_strict",
1909                 .data           = &sysctl_writes_strict,
1910                 .maxlen         = sizeof(int),
1911                 .mode           = 0644,
1912                 .proc_handler   = proc_dointvec_minmax,
1913                 .extra1         = SYSCTL_NEG_ONE,
1914                 .extra2         = SYSCTL_ONE,
1915         },
1916 #endif
1917 #ifdef CONFIG_LATENCYTOP
1918         {
1919                 .procname       = "latencytop",
1920                 .data           = &latencytop_enabled,
1921                 .maxlen         = sizeof(int),
1922                 .mode           = 0644,
1923                 .proc_handler   = sysctl_latencytop,
1924         },
1925 #endif
1926 #ifdef CONFIG_BLK_DEV_INITRD
1927         {
1928                 .procname       = "real-root-dev",
1929                 .data           = &real_root_dev,
1930                 .maxlen         = sizeof(int),
1931                 .mode           = 0644,
1932                 .proc_handler   = proc_dointvec,
1933         },
1934 #endif
1935         {
1936                 .procname       = "print-fatal-signals",
1937                 .data           = &print_fatal_signals,
1938                 .maxlen         = sizeof(int),
1939                 .mode           = 0644,
1940                 .proc_handler   = proc_dointvec,
1941         },
1942 #ifdef CONFIG_SPARC
1943         {
1944                 .procname       = "reboot-cmd",
1945                 .data           = reboot_command,
1946                 .maxlen         = 256,
1947                 .mode           = 0644,
1948                 .proc_handler   = proc_dostring,
1949         },
1950         {
1951                 .procname       = "stop-a",
1952                 .data           = &stop_a_enabled,
1953                 .maxlen         = sizeof (int),
1954                 .mode           = 0644,
1955                 .proc_handler   = proc_dointvec,
1956         },
1957         {
1958                 .procname       = "scons-poweroff",
1959                 .data           = &scons_pwroff,
1960                 .maxlen         = sizeof (int),
1961                 .mode           = 0644,
1962                 .proc_handler   = proc_dointvec,
1963         },
1964 #endif
1965 #ifdef CONFIG_SPARC64
1966         {
1967                 .procname       = "tsb-ratio",
1968                 .data           = &sysctl_tsb_ratio,
1969                 .maxlen         = sizeof (int),
1970                 .mode           = 0644,
1971                 .proc_handler   = proc_dointvec,
1972         },
1973 #endif
1974 #ifdef CONFIG_PARISC
1975         {
1976                 .procname       = "soft-power",
1977                 .data           = &pwrsw_enabled,
1978                 .maxlen         = sizeof (int),
1979                 .mode           = 0644,
1980                 .proc_handler   = proc_dointvec,
1981         },
1982 #endif
1983 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
1984         {
1985                 .procname       = "unaligned-trap",
1986                 .data           = &unaligned_enabled,
1987                 .maxlen         = sizeof (int),
1988                 .mode           = 0644,
1989                 .proc_handler   = proc_dointvec,
1990         },
1991 #endif
1992         {
1993                 .procname       = "ctrl-alt-del",
1994                 .data           = &C_A_D,
1995                 .maxlen         = sizeof(int),
1996                 .mode           = 0644,
1997                 .proc_handler   = proc_dointvec,
1998         },
1999 #ifdef CONFIG_FUNCTION_TRACER
2000         {
2001                 .procname       = "ftrace_enabled",
2002                 .data           = &ftrace_enabled,
2003                 .maxlen         = sizeof(int),
2004                 .mode           = 0644,
2005                 .proc_handler   = ftrace_enable_sysctl,
2006         },
2007 #endif
2008 #ifdef CONFIG_STACK_TRACER
2009         {
2010                 .procname       = "stack_tracer_enabled",
2011                 .data           = &stack_tracer_enabled,
2012                 .maxlen         = sizeof(int),
2013                 .mode           = 0644,
2014                 .proc_handler   = stack_trace_sysctl,
2015         },
2016 #endif
2017 #ifdef CONFIG_TRACING
2018         {
2019                 .procname       = "ftrace_dump_on_oops",
2020                 .data           = &ftrace_dump_on_oops,
2021                 .maxlen         = sizeof(int),
2022                 .mode           = 0644,
2023                 .proc_handler   = proc_dointvec,
2024         },
2025         {
2026                 .procname       = "traceoff_on_warning",
2027                 .data           = &__disable_trace_on_warning,
2028                 .maxlen         = sizeof(__disable_trace_on_warning),
2029                 .mode           = 0644,
2030                 .proc_handler   = proc_dointvec,
2031         },
2032         {
2033                 .procname       = "tracepoint_printk",
2034                 .data           = &tracepoint_printk,
2035                 .maxlen         = sizeof(tracepoint_printk),
2036                 .mode           = 0644,
2037                 .proc_handler   = tracepoint_printk_sysctl,
2038         },
2039 #endif
2040 #ifdef CONFIG_KEXEC_CORE
2041         {
2042                 .procname       = "kexec_load_disabled",
2043                 .data           = &kexec_load_disabled,
2044                 .maxlen         = sizeof(int),
2045                 .mode           = 0644,
2046                 /* only handle a transition from default "0" to "1" */
2047                 .proc_handler   = proc_dointvec_minmax,
2048                 .extra1         = SYSCTL_ONE,
2049                 .extra2         = SYSCTL_ONE,
2050         },
2051 #endif
2052 #ifdef CONFIG_MODULES
2053         {
2054                 .procname       = "modprobe",
2055                 .data           = &modprobe_path,
2056                 .maxlen         = KMOD_PATH_LEN,
2057                 .mode           = 0644,
2058                 .proc_handler   = proc_dostring,
2059         },
2060         {
2061                 .procname       = "modules_disabled",
2062                 .data           = &modules_disabled,
2063                 .maxlen         = sizeof(int),
2064                 .mode           = 0644,
2065                 /* only handle a transition from default "0" to "1" */
2066                 .proc_handler   = proc_dointvec_minmax,
2067                 .extra1         = SYSCTL_ONE,
2068                 .extra2         = SYSCTL_ONE,
2069         },
2070 #endif
2071 #ifdef CONFIG_UEVENT_HELPER
2072         {
2073                 .procname       = "hotplug",
2074                 .data           = &uevent_helper,
2075                 .maxlen         = UEVENT_HELPER_PATH_LEN,
2076                 .mode           = 0644,
2077                 .proc_handler   = proc_dostring,
2078         },
2079 #endif
2080 #ifdef CONFIG_BSD_PROCESS_ACCT
2081         {
2082                 .procname       = "acct",
2083                 .data           = &acct_parm,
2084                 .maxlen         = 3*sizeof(int),
2085                 .mode           = 0644,
2086                 .proc_handler   = proc_dointvec,
2087         },
2088 #endif
2089 #ifdef CONFIG_MAGIC_SYSRQ
2090         {
2091                 .procname       = "sysrq",
2092                 .data           = NULL,
2093                 .maxlen         = sizeof (int),
2094                 .mode           = 0644,
2095                 .proc_handler   = sysrq_sysctl_handler,
2096         },
2097 #endif
2098 #ifdef CONFIG_PROC_SYSCTL
2099         {
2100                 .procname       = "cad_pid",
2101                 .data           = NULL,
2102                 .maxlen         = sizeof (int),
2103                 .mode           = 0600,
2104                 .proc_handler   = proc_do_cad_pid,
2105         },
2106 #endif
2107         {
2108                 .procname       = "threads-max",
2109                 .data           = NULL,
2110                 .maxlen         = sizeof(int),
2111                 .mode           = 0644,
2112                 .proc_handler   = sysctl_max_threads,
2113         },
2114         {
2115                 .procname       = "usermodehelper",
2116                 .mode           = 0555,
2117                 .child          = usermodehelper_table,
2118         },
2119         {
2120                 .procname       = "overflowuid",
2121                 .data           = &overflowuid,
2122                 .maxlen         = sizeof(int),
2123                 .mode           = 0644,
2124                 .proc_handler   = proc_dointvec_minmax,
2125                 .extra1         = SYSCTL_ZERO,
2126                 .extra2         = SYSCTL_MAXOLDUID,
2127         },
2128         {
2129                 .procname       = "overflowgid",
2130                 .data           = &overflowgid,
2131                 .maxlen         = sizeof(int),
2132                 .mode           = 0644,
2133                 .proc_handler   = proc_dointvec_minmax,
2134                 .extra1         = SYSCTL_ZERO,
2135                 .extra2         = SYSCTL_MAXOLDUID,
2136         },
2137 #ifdef CONFIG_S390
2138         {
2139                 .procname       = "userprocess_debug",
2140                 .data           = &show_unhandled_signals,
2141                 .maxlen         = sizeof(int),
2142                 .mode           = 0644,
2143                 .proc_handler   = proc_dointvec,
2144         },
2145 #endif
2146 #ifdef CONFIG_SMP
2147         {
2148                 .procname       = "oops_all_cpu_backtrace",
2149                 .data           = &sysctl_oops_all_cpu_backtrace,
2150                 .maxlen         = sizeof(int),
2151                 .mode           = 0644,
2152                 .proc_handler   = proc_dointvec_minmax,
2153                 .extra1         = SYSCTL_ZERO,
2154                 .extra2         = SYSCTL_ONE,
2155         },
2156 #endif /* CONFIG_SMP */
2157         {
2158                 .procname       = "pid_max",
2159                 .data           = &pid_max,
2160                 .maxlen         = sizeof (int),
2161                 .mode           = 0644,
2162                 .proc_handler   = proc_dointvec_minmax,
2163                 .extra1         = &pid_max_min,
2164                 .extra2         = &pid_max_max,
2165         },
2166         {
2167                 .procname       = "panic_on_oops",
2168                 .data           = &panic_on_oops,
2169                 .maxlen         = sizeof(int),
2170                 .mode           = 0644,
2171                 .proc_handler   = proc_dointvec,
2172         },
2173         {
2174                 .procname       = "panic_print",
2175                 .data           = &panic_print,
2176                 .maxlen         = sizeof(unsigned long),
2177                 .mode           = 0644,
2178                 .proc_handler   = proc_doulongvec_minmax,
2179         },
2180         {
2181                 .procname       = "ngroups_max",
2182                 .data           = (void *)&ngroups_max,
2183                 .maxlen         = sizeof (int),
2184                 .mode           = 0444,
2185                 .proc_handler   = proc_dointvec,
2186         },
2187         {
2188                 .procname       = "cap_last_cap",
2189                 .data           = (void *)&cap_last_cap,
2190                 .maxlen         = sizeof(int),
2191                 .mode           = 0444,
2192                 .proc_handler   = proc_dointvec,
2193         },
2194 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
2195         {
2196                 .procname       = "unknown_nmi_panic",
2197                 .data           = &unknown_nmi_panic,
2198                 .maxlen         = sizeof (int),
2199                 .mode           = 0644,
2200                 .proc_handler   = proc_dointvec,
2201         },
2202 #endif
2203
2204 #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
2205         defined(CONFIG_DEBUG_STACKOVERFLOW)
2206         {
2207                 .procname       = "panic_on_stackoverflow",
2208                 .data           = &sysctl_panic_on_stackoverflow,
2209                 .maxlen         = sizeof(int),
2210                 .mode           = 0644,
2211                 .proc_handler   = proc_dointvec,
2212         },
2213 #endif
2214 #if defined(CONFIG_X86)
2215         {
2216                 .procname       = "panic_on_unrecovered_nmi",
2217                 .data           = &panic_on_unrecovered_nmi,
2218                 .maxlen         = sizeof(int),
2219                 .mode           = 0644,
2220                 .proc_handler   = proc_dointvec,
2221         },
2222         {
2223                 .procname       = "panic_on_io_nmi",
2224                 .data           = &panic_on_io_nmi,
2225                 .maxlen         = sizeof(int),
2226                 .mode           = 0644,
2227                 .proc_handler   = proc_dointvec,
2228         },
2229         {
2230                 .procname       = "bootloader_type",
2231                 .data           = &bootloader_type,
2232                 .maxlen         = sizeof (int),
2233                 .mode           = 0444,
2234                 .proc_handler   = proc_dointvec,
2235         },
2236         {
2237                 .procname       = "bootloader_version",
2238                 .data           = &bootloader_version,
2239                 .maxlen         = sizeof (int),
2240                 .mode           = 0444,
2241                 .proc_handler   = proc_dointvec,
2242         },
2243         {
2244                 .procname       = "io_delay_type",
2245                 .data           = &io_delay_type,
2246                 .maxlen         = sizeof(int),
2247                 .mode           = 0644,
2248                 .proc_handler   = proc_dointvec,
2249         },
2250 #endif
2251 #if defined(CONFIG_MMU)
2252         {
2253                 .procname       = "randomize_va_space",
2254                 .data           = &randomize_va_space,
2255                 .maxlen         = sizeof(int),
2256                 .mode           = 0644,
2257                 .proc_handler   = proc_dointvec,
2258         },
2259 #endif
2260 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
2261         {
2262                 .procname       = "spin_retry",
2263                 .data           = &spin_retry,
2264                 .maxlen         = sizeof (int),
2265                 .mode           = 0644,
2266                 .proc_handler   = proc_dointvec,
2267         },
2268 #endif
2269 #if     defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
2270         {
2271                 .procname       = "acpi_video_flags",
2272                 .data           = &acpi_realmode_flags,
2273                 .maxlen         = sizeof (unsigned long),
2274                 .mode           = 0644,
2275                 .proc_handler   = proc_doulongvec_minmax,
2276         },
2277 #endif
2278 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
2279         {
2280                 .procname       = "ignore-unaligned-usertrap",
2281                 .data           = &no_unaligned_warning,
2282                 .maxlen         = sizeof (int),
2283                 .mode           = 0644,
2284                 .proc_handler   = proc_dointvec,
2285         },
2286 #endif
2287 #ifdef CONFIG_IA64
2288         {
2289                 .procname       = "unaligned-dump-stack",
2290                 .data           = &unaligned_dump_stack,
2291                 .maxlen         = sizeof (int),
2292                 .mode           = 0644,
2293                 .proc_handler   = proc_dointvec,
2294         },
2295 #endif
2296 #ifdef CONFIG_RT_MUTEXES
2297         {
2298                 .procname       = "max_lock_depth",
2299                 .data           = &max_lock_depth,
2300                 .maxlen         = sizeof(int),
2301                 .mode           = 0644,
2302                 .proc_handler   = proc_dointvec,
2303         },
2304 #endif
2305         {
2306                 .procname       = "poweroff_cmd",
2307                 .data           = &poweroff_cmd,
2308                 .maxlen         = POWEROFF_CMD_PATH_LEN,
2309                 .mode           = 0644,
2310                 .proc_handler   = proc_dostring,
2311         },
2312 #ifdef CONFIG_KEYS
2313         {
2314                 .procname       = "keys",
2315                 .mode           = 0555,
2316                 .child          = key_sysctls,
2317         },
2318 #endif
2319 #ifdef CONFIG_PERF_EVENTS
2320         /*
2321          * User-space scripts rely on the existence of this file
2322          * as a feature check for perf_events being enabled.
2323          *
2324          * So it's an ABI, do not remove!
2325          */
2326         {
2327                 .procname       = "perf_event_paranoid",
2328                 .data           = &sysctl_perf_event_paranoid,
2329                 .maxlen         = sizeof(sysctl_perf_event_paranoid),
2330                 .mode           = 0644,
2331                 .proc_handler   = proc_dointvec,
2332         },
2333         {
2334                 .procname       = "perf_event_mlock_kb",
2335                 .data           = &sysctl_perf_event_mlock,
2336                 .maxlen         = sizeof(sysctl_perf_event_mlock),
2337                 .mode           = 0644,
2338                 .proc_handler   = proc_dointvec,
2339         },
2340         {
2341                 .procname       = "perf_event_max_sample_rate",
2342                 .data           = &sysctl_perf_event_sample_rate,
2343                 .maxlen         = sizeof(sysctl_perf_event_sample_rate),
2344                 .mode           = 0644,
2345                 .proc_handler   = perf_proc_update_handler,
2346                 .extra1         = SYSCTL_ONE,
2347         },
2348         {
2349                 .procname       = "perf_cpu_time_max_percent",
2350                 .data           = &sysctl_perf_cpu_time_max_percent,
2351                 .maxlen         = sizeof(sysctl_perf_cpu_time_max_percent),
2352                 .mode           = 0644,
2353                 .proc_handler   = perf_cpu_time_max_percent_handler,
2354                 .extra1         = SYSCTL_ZERO,
2355                 .extra2         = SYSCTL_ONE_HUNDRED,
2356         },
2357         {
2358                 .procname       = "perf_event_max_stack",
2359                 .data           = &sysctl_perf_event_max_stack,
2360                 .maxlen         = sizeof(sysctl_perf_event_max_stack),
2361                 .mode           = 0644,
2362                 .proc_handler   = perf_event_max_stack_handler,
2363                 .extra1         = SYSCTL_ZERO,
2364                 .extra2         = (void *)&six_hundred_forty_kb,
2365         },
2366         {
2367                 .procname       = "perf_event_max_contexts_per_stack",
2368                 .data           = &sysctl_perf_event_max_contexts_per_stack,
2369                 .maxlen         = sizeof(sysctl_perf_event_max_contexts_per_stack),
2370                 .mode           = 0644,
2371                 .proc_handler   = perf_event_max_stack_handler,
2372                 .extra1         = SYSCTL_ZERO,
2373                 .extra2         = SYSCTL_ONE_THOUSAND,
2374         },
2375 #endif
2376         {
2377                 .procname       = "panic_on_warn",
2378                 .data           = &panic_on_warn,
2379                 .maxlen         = sizeof(int),
2380                 .mode           = 0644,
2381                 .proc_handler   = proc_dointvec_minmax,
2382                 .extra1         = SYSCTL_ZERO,
2383                 .extra2         = SYSCTL_ONE,
2384         },
2385 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
2386         {
2387                 .procname       = "timer_migration",
2388                 .data           = &sysctl_timer_migration,
2389                 .maxlen         = sizeof(unsigned int),
2390                 .mode           = 0644,
2391                 .proc_handler   = timer_migration_handler,
2392                 .extra1         = SYSCTL_ZERO,
2393                 .extra2         = SYSCTL_ONE,
2394         },
2395 #endif
2396 #ifdef CONFIG_BPF_SYSCALL
2397         {
2398                 .procname       = "unprivileged_bpf_disabled",
2399                 .data           = &sysctl_unprivileged_bpf_disabled,
2400                 .maxlen         = sizeof(sysctl_unprivileged_bpf_disabled),
2401                 .mode           = 0644,
2402                 .proc_handler   = bpf_unpriv_handler,
2403                 .extra1         = SYSCTL_ZERO,
2404                 .extra2         = SYSCTL_TWO,
2405         },
2406         {
2407                 .procname       = "bpf_stats_enabled",
2408                 .data           = &bpf_stats_enabled_key.key,
2409                 .maxlen         = sizeof(bpf_stats_enabled_key),
2410                 .mode           = 0644,
2411                 .proc_handler   = bpf_stats_handler,
2412         },
2413 #endif
2414 #if defined(CONFIG_TREE_RCU)
2415         {
2416                 .procname       = "panic_on_rcu_stall",
2417                 .data           = &sysctl_panic_on_rcu_stall,
2418                 .maxlen         = sizeof(sysctl_panic_on_rcu_stall),
2419                 .mode           = 0644,
2420                 .proc_handler   = proc_dointvec_minmax,
2421                 .extra1         = SYSCTL_ZERO,
2422                 .extra2         = SYSCTL_ONE,
2423         },
2424 #endif
2425 #if defined(CONFIG_TREE_RCU)
2426         {
2427                 .procname       = "max_rcu_stall_to_panic",
2428                 .data           = &sysctl_max_rcu_stall_to_panic,
2429                 .maxlen         = sizeof(sysctl_max_rcu_stall_to_panic),
2430                 .mode           = 0644,
2431                 .proc_handler   = proc_dointvec_minmax,
2432                 .extra1         = SYSCTL_ONE,
2433                 .extra2         = SYSCTL_INT_MAX,
2434         },
2435 #endif
2436         { }
2437 };
2438
2439 static struct ctl_table vm_table[] = {
2440         {
2441                 .procname       = "overcommit_memory",
2442                 .data           = &sysctl_overcommit_memory,
2443                 .maxlen         = sizeof(sysctl_overcommit_memory),
2444                 .mode           = 0644,
2445                 .proc_handler   = overcommit_policy_handler,
2446                 .extra1         = SYSCTL_ZERO,
2447                 .extra2         = SYSCTL_TWO,
2448         },
2449         {
2450                 .procname       = "panic_on_oom",
2451                 .data           = &sysctl_panic_on_oom,
2452                 .maxlen         = sizeof(sysctl_panic_on_oom),
2453                 .mode           = 0644,
2454                 .proc_handler   = proc_dointvec_minmax,
2455                 .extra1         = SYSCTL_ZERO,
2456                 .extra2         = SYSCTL_TWO,
2457         },
2458         {
2459                 .procname       = "oom_kill_allocating_task",
2460                 .data           = &sysctl_oom_kill_allocating_task,
2461                 .maxlen         = sizeof(sysctl_oom_kill_allocating_task),
2462                 .mode           = 0644,
2463                 .proc_handler   = proc_dointvec,
2464         },
2465         {
2466                 .procname       = "oom_dump_tasks",
2467                 .data           = &sysctl_oom_dump_tasks,
2468                 .maxlen         = sizeof(sysctl_oom_dump_tasks),
2469                 .mode           = 0644,
2470                 .proc_handler   = proc_dointvec,
2471         },
2472         {
2473                 .procname       = "overcommit_ratio",
2474                 .data           = &sysctl_overcommit_ratio,
2475                 .maxlen         = sizeof(sysctl_overcommit_ratio),
2476                 .mode           = 0644,
2477                 .proc_handler   = overcommit_ratio_handler,
2478         },
2479         {
2480                 .procname       = "overcommit_kbytes",
2481                 .data           = &sysctl_overcommit_kbytes,
2482                 .maxlen         = sizeof(sysctl_overcommit_kbytes),
2483                 .mode           = 0644,
2484                 .proc_handler   = overcommit_kbytes_handler,
2485         },
2486         {
2487                 .procname       = "page-cluster",
2488                 .data           = &page_cluster,
2489                 .maxlen         = sizeof(int),
2490                 .mode           = 0644,
2491                 .proc_handler   = proc_dointvec_minmax,
2492                 .extra1         = SYSCTL_ZERO,
2493         },
2494         {
2495                 .procname       = "dirty_background_ratio",
2496                 .data           = &dirty_background_ratio,
2497                 .maxlen         = sizeof(dirty_background_ratio),
2498                 .mode           = 0644,
2499                 .proc_handler   = dirty_background_ratio_handler,
2500                 .extra1         = SYSCTL_ZERO,
2501                 .extra2         = SYSCTL_ONE_HUNDRED,
2502         },
2503         {
2504                 .procname       = "dirty_background_bytes",
2505                 .data           = &dirty_background_bytes,
2506                 .maxlen         = sizeof(dirty_background_bytes),
2507                 .mode           = 0644,
2508                 .proc_handler   = dirty_background_bytes_handler,
2509                 .extra1         = SYSCTL_LONG_ONE,
2510         },
2511         {
2512                 .procname       = "dirty_ratio",
2513                 .data           = &vm_dirty_ratio,
2514                 .maxlen         = sizeof(vm_dirty_ratio),
2515                 .mode           = 0644,
2516                 .proc_handler   = dirty_ratio_handler,
2517                 .extra1         = SYSCTL_ZERO,
2518                 .extra2         = SYSCTL_ONE_HUNDRED,
2519         },
2520         {
2521                 .procname       = "dirty_bytes",
2522                 .data           = &vm_dirty_bytes,
2523                 .maxlen         = sizeof(vm_dirty_bytes),
2524                 .mode           = 0644,
2525                 .proc_handler   = dirty_bytes_handler,
2526                 .extra1         = (void *)&dirty_bytes_min,
2527         },
2528         {
2529                 .procname       = "dirty_writeback_centisecs",
2530                 .data           = &dirty_writeback_interval,
2531                 .maxlen         = sizeof(dirty_writeback_interval),
2532                 .mode           = 0644,
2533                 .proc_handler   = dirty_writeback_centisecs_handler,
2534         },
2535         {
2536                 .procname       = "dirty_expire_centisecs",
2537                 .data           = &dirty_expire_interval,
2538                 .maxlen         = sizeof(dirty_expire_interval),
2539                 .mode           = 0644,
2540                 .proc_handler   = proc_dointvec_minmax,
2541                 .extra1         = SYSCTL_ZERO,
2542         },
2543         {
2544                 .procname       = "dirtytime_expire_seconds",
2545                 .data           = &dirtytime_expire_interval,
2546                 .maxlen         = sizeof(dirtytime_expire_interval),
2547                 .mode           = 0644,
2548                 .proc_handler   = dirtytime_interval_handler,
2549                 .extra1         = SYSCTL_ZERO,
2550         },
2551         {
2552                 .procname       = "swappiness",
2553                 .data           = &vm_swappiness,
2554                 .maxlen         = sizeof(vm_swappiness),
2555                 .mode           = 0644,
2556                 .proc_handler   = proc_dointvec_minmax,
2557                 .extra1         = SYSCTL_ZERO,
2558                 .extra2         = SYSCTL_TWO_HUNDRED,
2559         },
2560 #ifdef CONFIG_HUGETLB_PAGE
2561         {
2562                 .procname       = "nr_hugepages",
2563                 .data           = NULL,
2564                 .maxlen         = sizeof(unsigned long),
2565                 .mode           = 0644,
2566                 .proc_handler   = hugetlb_sysctl_handler,
2567         },
2568 #ifdef CONFIG_NUMA
2569         {
2570                 .procname       = "nr_hugepages_mempolicy",
2571                 .data           = NULL,
2572                 .maxlen         = sizeof(unsigned long),
2573                 .mode           = 0644,
2574                 .proc_handler   = &hugetlb_mempolicy_sysctl_handler,
2575         },
2576         {
2577                 .procname               = "numa_stat",
2578                 .data                   = &sysctl_vm_numa_stat,
2579                 .maxlen                 = sizeof(int),
2580                 .mode                   = 0644,
2581                 .proc_handler   = sysctl_vm_numa_stat_handler,
2582                 .extra1                 = SYSCTL_ZERO,
2583                 .extra2                 = SYSCTL_ONE,
2584         },
2585 #endif
2586          {
2587                 .procname       = "hugetlb_shm_group",
2588                 .data           = &sysctl_hugetlb_shm_group,
2589                 .maxlen         = sizeof(gid_t),
2590                 .mode           = 0644,
2591                 .proc_handler   = proc_dointvec,
2592          },
2593         {
2594                 .procname       = "nr_overcommit_hugepages",
2595                 .data           = NULL,
2596                 .maxlen         = sizeof(unsigned long),
2597                 .mode           = 0644,
2598                 .proc_handler   = hugetlb_overcommit_handler,
2599         },
2600 #endif
2601         {
2602                 .procname       = "lowmem_reserve_ratio",
2603                 .data           = &sysctl_lowmem_reserve_ratio,
2604                 .maxlen         = sizeof(sysctl_lowmem_reserve_ratio),
2605                 .mode           = 0644,
2606                 .proc_handler   = lowmem_reserve_ratio_sysctl_handler,
2607         },
2608         {
2609                 .procname       = "drop_caches",
2610                 .data           = &sysctl_drop_caches,
2611                 .maxlen         = sizeof(int),
2612                 .mode           = 0200,
2613                 .proc_handler   = drop_caches_sysctl_handler,
2614                 .extra1         = SYSCTL_ONE,
2615                 .extra2         = SYSCTL_FOUR,
2616         },
2617 #ifdef CONFIG_COMPACTION
2618         {
2619                 .procname       = "compact_memory",
2620                 .data           = NULL,
2621                 .maxlen         = sizeof(int),
2622                 .mode           = 0200,
2623                 .proc_handler   = sysctl_compaction_handler,
2624         },
2625         {
2626                 .procname       = "compaction_proactiveness",
2627                 .data           = &sysctl_compaction_proactiveness,
2628                 .maxlen         = sizeof(sysctl_compaction_proactiveness),
2629                 .mode           = 0644,
2630                 .proc_handler   = compaction_proactiveness_sysctl_handler,
2631                 .extra1         = SYSCTL_ZERO,
2632                 .extra2         = SYSCTL_ONE_HUNDRED,
2633         },
2634         {
2635                 .procname       = "extfrag_threshold",
2636                 .data           = &sysctl_extfrag_threshold,
2637                 .maxlen         = sizeof(int),
2638                 .mode           = 0644,
2639                 .proc_handler   = proc_dointvec_minmax,
2640                 .extra1         = SYSCTL_ZERO,
2641                 .extra2         = (void *)&max_extfrag_threshold,
2642         },
2643         {
2644                 .procname       = "compact_unevictable_allowed",
2645                 .data           = &sysctl_compact_unevictable_allowed,
2646                 .maxlen         = sizeof(int),
2647                 .mode           = 0644,
2648                 .proc_handler   = proc_dointvec_minmax_warn_RT_change,
2649                 .extra1         = SYSCTL_ZERO,
2650                 .extra2         = SYSCTL_ONE,
2651         },
2652
2653 #endif /* CONFIG_COMPACTION */
2654         {
2655                 .procname       = "min_free_kbytes",
2656                 .data           = &min_free_kbytes,
2657                 .maxlen         = sizeof(min_free_kbytes),
2658                 .mode           = 0644,
2659                 .proc_handler   = min_free_kbytes_sysctl_handler,
2660                 .extra1         = SYSCTL_ZERO,
2661         },
2662         {
2663                 .procname       = "watermark_boost_factor",
2664                 .data           = &watermark_boost_factor,
2665                 .maxlen         = sizeof(watermark_boost_factor),
2666                 .mode           = 0644,
2667                 .proc_handler   = proc_dointvec_minmax,
2668                 .extra1         = SYSCTL_ZERO,
2669         },
2670         {
2671                 .procname       = "watermark_scale_factor",
2672                 .data           = &watermark_scale_factor,
2673                 .maxlen         = sizeof(watermark_scale_factor),
2674                 .mode           = 0644,
2675                 .proc_handler   = watermark_scale_factor_sysctl_handler,
2676                 .extra1         = SYSCTL_ONE,
2677                 .extra2         = SYSCTL_THREE_THOUSAND,
2678         },
2679         {
2680                 .procname       = "percpu_pagelist_high_fraction",
2681                 .data           = &percpu_pagelist_high_fraction,
2682                 .maxlen         = sizeof(percpu_pagelist_high_fraction),
2683                 .mode           = 0644,
2684                 .proc_handler   = percpu_pagelist_high_fraction_sysctl_handler,
2685                 .extra1         = SYSCTL_ZERO,
2686         },
2687         {
2688                 .procname       = "page_lock_unfairness",
2689                 .data           = &sysctl_page_lock_unfairness,
2690                 .maxlen         = sizeof(sysctl_page_lock_unfairness),
2691                 .mode           = 0644,
2692                 .proc_handler   = proc_dointvec_minmax,
2693                 .extra1         = SYSCTL_ZERO,
2694         },
2695 #ifdef CONFIG_MMU
2696         {
2697                 .procname       = "max_map_count",
2698                 .data           = &sysctl_max_map_count,
2699                 .maxlen         = sizeof(sysctl_max_map_count),
2700                 .mode           = 0644,
2701                 .proc_handler   = proc_dointvec_minmax,
2702                 .extra1         = SYSCTL_ZERO,
2703         },
2704 #else
2705         {
2706                 .procname       = "nr_trim_pages",
2707                 .data           = &sysctl_nr_trim_pages,
2708                 .maxlen         = sizeof(sysctl_nr_trim_pages),
2709                 .mode           = 0644,
2710                 .proc_handler   = proc_dointvec_minmax,
2711                 .extra1         = SYSCTL_ZERO,
2712         },
2713 #endif
2714         {
2715                 .procname       = "laptop_mode",
2716                 .data           = &laptop_mode,
2717                 .maxlen         = sizeof(laptop_mode),
2718                 .mode           = 0644,
2719                 .proc_handler   = proc_dointvec_jiffies,
2720         },
2721         {
2722                 .procname       = "vfs_cache_pressure",
2723                 .data           = &sysctl_vfs_cache_pressure,
2724                 .maxlen         = sizeof(sysctl_vfs_cache_pressure),
2725                 .mode           = 0644,
2726                 .proc_handler   = proc_dointvec_minmax,
2727                 .extra1         = SYSCTL_ZERO,
2728         },
2729 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
2730     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
2731         {
2732                 .procname       = "legacy_va_layout",
2733                 .data           = &sysctl_legacy_va_layout,
2734                 .maxlen         = sizeof(sysctl_legacy_va_layout),
2735                 .mode           = 0644,
2736                 .proc_handler   = proc_dointvec_minmax,
2737                 .extra1         = SYSCTL_ZERO,
2738         },
2739 #endif
2740 #ifdef CONFIG_NUMA
2741         {
2742                 .procname       = "zone_reclaim_mode",
2743                 .data           = &node_reclaim_mode,
2744                 .maxlen         = sizeof(node_reclaim_mode),
2745                 .mode           = 0644,
2746                 .proc_handler   = proc_dointvec_minmax,
2747                 .extra1         = SYSCTL_ZERO,
2748         },
2749         {
2750                 .procname       = "min_unmapped_ratio",
2751                 .data           = &sysctl_min_unmapped_ratio,
2752                 .maxlen         = sizeof(sysctl_min_unmapped_ratio),
2753                 .mode           = 0644,
2754                 .proc_handler   = sysctl_min_unmapped_ratio_sysctl_handler,
2755                 .extra1         = SYSCTL_ZERO,
2756                 .extra2         = SYSCTL_ONE_HUNDRED,
2757         },
2758         {
2759                 .procname       = "min_slab_ratio",
2760                 .data           = &sysctl_min_slab_ratio,
2761                 .maxlen         = sizeof(sysctl_min_slab_ratio),
2762                 .mode           = 0644,
2763                 .proc_handler   = sysctl_min_slab_ratio_sysctl_handler,
2764                 .extra1         = SYSCTL_ZERO,
2765                 .extra2         = SYSCTL_ONE_HUNDRED,
2766         },
2767 #endif
2768 #ifdef CONFIG_SMP
2769         {
2770                 .procname       = "stat_interval",
2771                 .data           = &sysctl_stat_interval,
2772                 .maxlen         = sizeof(sysctl_stat_interval),
2773                 .mode           = 0644,
2774                 .proc_handler   = proc_dointvec_jiffies,
2775         },
2776         {
2777                 .procname       = "stat_refresh",
2778                 .data           = NULL,
2779                 .maxlen         = 0,
2780                 .mode           = 0600,
2781                 .proc_handler   = vmstat_refresh,
2782         },
2783 #endif
2784 #ifdef CONFIG_MMU
2785         {
2786                 .procname       = "mmap_min_addr",
2787                 .data           = &dac_mmap_min_addr,
2788                 .maxlen         = sizeof(unsigned long),
2789                 .mode           = 0644,
2790                 .proc_handler   = mmap_min_addr_handler,
2791         },
2792 #endif
2793 #ifdef CONFIG_NUMA
2794         {
2795                 .procname       = "numa_zonelist_order",
2796                 .data           = &numa_zonelist_order,
2797                 .maxlen         = NUMA_ZONELIST_ORDER_LEN,
2798                 .mode           = 0644,
2799                 .proc_handler   = numa_zonelist_order_handler,
2800         },
2801 #endif
2802 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
2803    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
2804         {
2805                 .procname       = "vdso_enabled",
2806 #ifdef CONFIG_X86_32
2807                 .data           = &vdso32_enabled,
2808                 .maxlen         = sizeof(vdso32_enabled),
2809 #else
2810                 .data           = &vdso_enabled,
2811                 .maxlen         = sizeof(vdso_enabled),
2812 #endif
2813                 .mode           = 0644,
2814                 .proc_handler   = proc_dointvec,
2815                 .extra1         = SYSCTL_ZERO,
2816         },
2817 #endif
2818 #ifdef CONFIG_HIGHMEM
2819         {
2820                 .procname       = "highmem_is_dirtyable",
2821                 .data           = &vm_highmem_is_dirtyable,
2822                 .maxlen         = sizeof(vm_highmem_is_dirtyable),
2823                 .mode           = 0644,
2824                 .proc_handler   = proc_dointvec_minmax,
2825                 .extra1         = SYSCTL_ZERO,
2826                 .extra2         = SYSCTL_ONE,
2827         },
2828 #endif
2829 #ifdef CONFIG_MEMORY_FAILURE
2830         {
2831                 .procname       = "memory_failure_early_kill",
2832                 .data           = &sysctl_memory_failure_early_kill,
2833                 .maxlen         = sizeof(sysctl_memory_failure_early_kill),
2834                 .mode           = 0644,
2835                 .proc_handler   = proc_dointvec_minmax,
2836                 .extra1         = SYSCTL_ZERO,
2837                 .extra2         = SYSCTL_ONE,
2838         },
2839         {
2840                 .procname       = "memory_failure_recovery",
2841                 .data           = &sysctl_memory_failure_recovery,
2842                 .maxlen         = sizeof(sysctl_memory_failure_recovery),
2843                 .mode           = 0644,
2844                 .proc_handler   = proc_dointvec_minmax,
2845                 .extra1         = SYSCTL_ZERO,
2846                 .extra2         = SYSCTL_ONE,
2847         },
2848 #endif
2849         {
2850                 .procname       = "user_reserve_kbytes",
2851                 .data           = &sysctl_user_reserve_kbytes,
2852                 .maxlen         = sizeof(sysctl_user_reserve_kbytes),
2853                 .mode           = 0644,
2854                 .proc_handler   = proc_doulongvec_minmax,
2855         },
2856         {
2857                 .procname       = "admin_reserve_kbytes",
2858                 .data           = &sysctl_admin_reserve_kbytes,
2859                 .maxlen         = sizeof(sysctl_admin_reserve_kbytes),
2860                 .mode           = 0644,
2861                 .proc_handler   = proc_doulongvec_minmax,
2862         },
2863 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
2864         {
2865                 .procname       = "mmap_rnd_bits",
2866                 .data           = &mmap_rnd_bits,
2867                 .maxlen         = sizeof(mmap_rnd_bits),
2868                 .mode           = 0600,
2869                 .proc_handler   = proc_dointvec_minmax,
2870                 .extra1         = (void *)&mmap_rnd_bits_min,
2871                 .extra2         = (void *)&mmap_rnd_bits_max,
2872         },
2873 #endif
2874 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
2875         {
2876                 .procname       = "mmap_rnd_compat_bits",
2877                 .data           = &mmap_rnd_compat_bits,
2878                 .maxlen         = sizeof(mmap_rnd_compat_bits),
2879                 .mode           = 0600,
2880                 .proc_handler   = proc_dointvec_minmax,
2881                 .extra1         = (void *)&mmap_rnd_compat_bits_min,
2882                 .extra2         = (void *)&mmap_rnd_compat_bits_max,
2883         },
2884 #endif
2885 #ifdef CONFIG_USERFAULTFD
2886         {
2887                 .procname       = "unprivileged_userfaultfd",
2888                 .data           = &sysctl_unprivileged_userfaultfd,
2889                 .maxlen         = sizeof(sysctl_unprivileged_userfaultfd),
2890                 .mode           = 0644,
2891                 .proc_handler   = proc_dointvec_minmax,
2892                 .extra1         = SYSCTL_ZERO,
2893                 .extra2         = SYSCTL_ONE,
2894         },
2895 #endif
2896         { }
2897 };
2898
2899 static struct ctl_table fs_table[] = {
2900 #ifdef CONFIG_FILE_LOCKING
2901         {
2902                 .procname       = "leases-enable",
2903                 .data           = &leases_enable,
2904                 .maxlen         = sizeof(int),
2905                 .mode           = 0644,
2906                 .proc_handler   = proc_dointvec,
2907         },
2908 #endif
2909 #ifdef CONFIG_MMU
2910 #ifdef CONFIG_FILE_LOCKING
2911         {
2912                 .procname       = "lease-break-time",
2913                 .data           = &lease_break_time,
2914                 .maxlen         = sizeof(int),
2915                 .mode           = 0644,
2916                 .proc_handler   = proc_dointvec,
2917         },
2918 #endif
2919 #endif
2920         {
2921                 .procname       = "protected_symlinks",
2922                 .data           = &sysctl_protected_symlinks,
2923                 .maxlen         = sizeof(int),
2924                 .mode           = 0600,
2925                 .proc_handler   = proc_dointvec_minmax,
2926                 .extra1         = SYSCTL_ZERO,
2927                 .extra2         = SYSCTL_ONE,
2928         },
2929         {
2930                 .procname       = "protected_hardlinks",
2931                 .data           = &sysctl_protected_hardlinks,
2932                 .maxlen         = sizeof(int),
2933                 .mode           = 0600,
2934                 .proc_handler   = proc_dointvec_minmax,
2935                 .extra1         = SYSCTL_ZERO,
2936                 .extra2         = SYSCTL_ONE,
2937         },
2938         {
2939                 .procname       = "protected_fifos",
2940                 .data           = &sysctl_protected_fifos,
2941                 .maxlen         = sizeof(int),
2942                 .mode           = 0600,
2943                 .proc_handler   = proc_dointvec_minmax,
2944                 .extra1         = SYSCTL_ZERO,
2945                 .extra2         = SYSCTL_TWO,
2946         },
2947         {
2948                 .procname       = "protected_regular",
2949                 .data           = &sysctl_protected_regular,
2950                 .maxlen         = sizeof(int),
2951                 .mode           = 0600,
2952                 .proc_handler   = proc_dointvec_minmax,
2953                 .extra1         = SYSCTL_ZERO,
2954                 .extra2         = SYSCTL_TWO,
2955         },
2956         {
2957                 .procname       = "suid_dumpable",
2958                 .data           = &suid_dumpable,
2959                 .maxlen         = sizeof(int),
2960                 .mode           = 0644,
2961                 .proc_handler   = proc_dointvec_minmax_coredump,
2962                 .extra1         = SYSCTL_ZERO,
2963                 .extra2         = SYSCTL_TWO,
2964         },
2965         {
2966                 .procname       = "pipe-max-size",
2967                 .data           = &pipe_max_size,
2968                 .maxlen         = sizeof(pipe_max_size),
2969                 .mode           = 0644,
2970                 .proc_handler   = proc_dopipe_max_size,
2971         },
2972         {
2973                 .procname       = "pipe-user-pages-hard",
2974                 .data           = &pipe_user_pages_hard,
2975                 .maxlen         = sizeof(pipe_user_pages_hard),
2976                 .mode           = 0644,
2977                 .proc_handler   = proc_doulongvec_minmax,
2978         },
2979         {
2980                 .procname       = "pipe-user-pages-soft",
2981                 .data           = &pipe_user_pages_soft,
2982                 .maxlen         = sizeof(pipe_user_pages_soft),
2983                 .mode           = 0644,
2984                 .proc_handler   = proc_doulongvec_minmax,
2985         },
2986         {
2987                 .procname       = "mount-max",
2988                 .data           = &sysctl_mount_max,
2989                 .maxlen         = sizeof(unsigned int),
2990                 .mode           = 0644,
2991                 .proc_handler   = proc_dointvec_minmax,
2992                 .extra1         = SYSCTL_ONE,
2993         },
2994         { }
2995 };
2996
2997 static struct ctl_table debug_table[] = {
2998 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
2999         {
3000                 .procname       = "exception-trace",
3001                 .data           = &show_unhandled_signals,
3002                 .maxlen         = sizeof(int),
3003                 .mode           = 0644,
3004                 .proc_handler   = proc_dointvec
3005         },
3006 #endif
3007 #if defined(CONFIG_OPTPROBES)
3008         {
3009                 .procname       = "kprobes-optimization",
3010                 .data           = &sysctl_kprobes_optimization,
3011                 .maxlen         = sizeof(int),
3012                 .mode           = 0644,
3013                 .proc_handler   = proc_kprobes_optimization_handler,
3014                 .extra1         = SYSCTL_ZERO,
3015                 .extra2         = SYSCTL_ONE,
3016         },
3017 #endif
3018         { }
3019 };
3020
3021 static struct ctl_table dev_table[] = {
3022         { }
3023 };
3024
3025 static struct ctl_table sysctl_base_table[] = {
3026         {
3027                 .procname       = "kernel",
3028                 .mode           = 0555,
3029                 .child          = kern_table,
3030         },
3031         {
3032                 .procname       = "vm",
3033                 .mode           = 0555,
3034                 .child          = vm_table,
3035         },
3036         {
3037                 .procname       = "fs",
3038                 .mode           = 0555,
3039                 .child          = fs_table,
3040         },
3041         {
3042                 .procname       = "debug",
3043                 .mode           = 0555,
3044                 .child          = debug_table,
3045         },
3046         {
3047                 .procname       = "dev",
3048                 .mode           = 0555,
3049                 .child          = dev_table,
3050         },
3051         { }
3052 };
3053
3054 int __init sysctl_init(void)
3055 {
3056         struct ctl_table_header *hdr;
3057
3058         hdr = register_sysctl_table(sysctl_base_table);
3059         kmemleak_not_leak(hdr);
3060         return 0;
3061 }
3062 #endif /* CONFIG_SYSCTL */
3063 /*
3064  * No sense putting this after each symbol definition, twice,
3065  * exception granted :-)
3066  */
3067 EXPORT_SYMBOL(proc_dobool);
3068 EXPORT_SYMBOL(proc_dointvec);
3069 EXPORT_SYMBOL(proc_douintvec);
3070 EXPORT_SYMBOL(proc_dointvec_jiffies);
3071 EXPORT_SYMBOL(proc_dointvec_minmax);
3072 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3073 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3074 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3075 EXPORT_SYMBOL(proc_dostring);
3076 EXPORT_SYMBOL(proc_doulongvec_minmax);
3077 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3078 EXPORT_SYMBOL(proc_do_large_bitmap);