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