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