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