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