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