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