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