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