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