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 int __maybe_unused neg_one = -1;
115 static int __maybe_unused two = 2;
116 static int __maybe_unused four = 4;
117 static unsigned long zero_ul;
118 static unsigned long one_ul = 1;
119 static unsigned long long_max = LONG_MAX;
120 static int one_hundred = 100;
121 static int two_hundred = 200;
122 static int one_thousand = 1000;
123 #ifdef CONFIG_PRINTK
124 static int ten_thousand = 10000;
125 #endif
126 #ifdef CONFIG_PERF_EVENTS
127 static int six_hundred_forty_kb = 640 * 1024;
128 #endif
129
130 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
131 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
132
133 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
134 static int maxolduid = 65535;
135 static int minolduid;
136
137 static int ngroups_max = NGROUPS_MAX;
138 static const int cap_last_cap = CAP_LAST_CAP;
139
140 /*
141 * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
142 * and hung_task_check_interval_secs
143 */
144 #ifdef CONFIG_DETECT_HUNG_TASK
145 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
146 #endif
147
148 #ifdef CONFIG_INOTIFY_USER
149 #include <linux/inotify.h>
150 #endif
151
152 #ifdef CONFIG_PROC_SYSCTL
153
154 /**
155 * enum sysctl_writes_mode - supported sysctl write modes
156 *
157 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
158 * to be written, and multiple writes on the same sysctl file descriptor
159 * will rewrite the sysctl value, regardless of file position. No warning
160 * is issued when the initial position is not 0.
161 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
162 * not 0.
163 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
164 * file position 0 and the value must be fully contained in the buffer
165 * sent to the write syscall. If dealing with strings respect the file
166 * position, but restrict this to the max length of the buffer, anything
167 * passed the max length will be ignored. Multiple writes will append
168 * to the buffer.
169 *
170 * These write modes control how current file position affects the behavior of
171 * updating sysctl values through the proc interface on each write.
172 */
173 enum sysctl_writes_mode {
174 SYSCTL_WRITES_LEGACY = -1,
175 SYSCTL_WRITES_WARN = 0,
176 SYSCTL_WRITES_STRICT = 1,
177 };
178
179 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
180 #endif /* CONFIG_PROC_SYSCTL */
181
182 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
183 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
184 int sysctl_legacy_va_layout;
185 #endif
186
187 #ifdef CONFIG_SCHED_DEBUG
188 static int min_sched_granularity_ns = 100000; /* 100 usecs */
189 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
190 static int min_wakeup_granularity_ns; /* 0 usecs */
191 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
192 #ifdef CONFIG_SMP
193 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
194 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
195 #endif /* CONFIG_SMP */
196 #endif /* CONFIG_SCHED_DEBUG */
197
198 #ifdef CONFIG_COMPACTION
199 static int min_extfrag_threshold;
200 static int max_extfrag_threshold = 1000;
201 #endif
202
203 #endif /* CONFIG_SYSCTL */
204
205 #if defined(CONFIG_BPF_SYSCALL) && defined(CONFIG_SYSCTL)
bpf_stats_handler(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)206 static int bpf_stats_handler(struct ctl_table *table, int write,
207 void *buffer, size_t *lenp, loff_t *ppos)
208 {
209 struct static_key *key = (struct static_key *)table->data;
210 static int saved_val;
211 int val, ret;
212 struct ctl_table tmp = {
213 .data = &val,
214 .maxlen = sizeof(val),
215 .mode = table->mode,
216 .extra1 = SYSCTL_ZERO,
217 .extra2 = SYSCTL_ONE,
218 };
219
220 if (write && !capable(CAP_SYS_ADMIN))
221 return -EPERM;
222
223 mutex_lock(&bpf_stats_enabled_mutex);
224 val = saved_val;
225 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
226 if (write && !ret && val != saved_val) {
227 if (val)
228 static_key_slow_inc(key);
229 else
230 static_key_slow_dec(key);
231 saved_val = val;
232 }
233 mutex_unlock(&bpf_stats_enabled_mutex);
234 return ret;
235 }
236
unpriv_ebpf_notify(int new_state)237 void __weak unpriv_ebpf_notify(int new_state)
238 {
239 }
240
bpf_unpriv_handler(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)241 static int bpf_unpriv_handler(struct ctl_table *table, int write,
242 void *buffer, size_t *lenp, loff_t *ppos)
243 {
244 int ret, unpriv_enable = *(int *)table->data;
245 bool locked_state = unpriv_enable == 1;
246 struct ctl_table tmp = *table;
247
248 if (write && !capable(CAP_SYS_ADMIN))
249 return -EPERM;
250
251 tmp.data = &unpriv_enable;
252 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
253 if (write && !ret) {
254 if (locked_state && unpriv_enable != 1)
255 return -EPERM;
256 *(int *)table->data = unpriv_enable;
257 }
258
259 unpriv_ebpf_notify(unpriv_enable);
260
261 return ret;
262 }
263 #endif /* CONFIG_BPF_SYSCALL && CONFIG_SYSCTL */
264
265 /*
266 * /proc/sys support
267 */
268
269 #ifdef CONFIG_PROC_SYSCTL
270
_proc_do_string(char * data,int maxlen,int write,char * buffer,size_t * lenp,loff_t * ppos)271 static int _proc_do_string(char *data, int maxlen, int write,
272 char *buffer, size_t *lenp, loff_t *ppos)
273 {
274 size_t len;
275 char c, *p;
276
277 if (!data || !maxlen || !*lenp) {
278 *lenp = 0;
279 return 0;
280 }
281
282 if (write) {
283 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
284 /* Only continue writes not past the end of buffer. */
285 len = strlen(data);
286 if (len > maxlen - 1)
287 len = maxlen - 1;
288
289 if (*ppos > len)
290 return 0;
291 len = *ppos;
292 } else {
293 /* Start writing from beginning of buffer. */
294 len = 0;
295 }
296
297 *ppos += *lenp;
298 p = buffer;
299 while ((p - buffer) < *lenp && len < maxlen - 1) {
300 c = *(p++);
301 if (c == 0 || c == '\n')
302 break;
303 data[len++] = c;
304 }
305 data[len] = 0;
306 } else {
307 len = strlen(data);
308 if (len > maxlen)
309 len = maxlen;
310
311 if (*ppos > len) {
312 *lenp = 0;
313 return 0;
314 }
315
316 data += *ppos;
317 len -= *ppos;
318
319 if (len > *lenp)
320 len = *lenp;
321 if (len)
322 memcpy(buffer, data, len);
323 if (len < *lenp) {
324 buffer[len] = '\n';
325 len++;
326 }
327 *lenp = len;
328 *ppos += len;
329 }
330 return 0;
331 }
332
warn_sysctl_write(struct ctl_table * table)333 static void warn_sysctl_write(struct ctl_table *table)
334 {
335 pr_warn_once("%s wrote to %s when file position was not 0!\n"
336 "This will not be supported in the future. To silence this\n"
337 "warning, set kernel.sysctl_writes_strict = -1\n",
338 current->comm, table->procname);
339 }
340
341 /**
342 * proc_first_pos_non_zero_ignore - check if first position is allowed
343 * @ppos: file position
344 * @table: the sysctl table
345 *
346 * Returns true if the first position is non-zero and the sysctl_writes_strict
347 * mode indicates this is not allowed for numeric input types. String proc
348 * handlers can ignore the return value.
349 */
proc_first_pos_non_zero_ignore(loff_t * ppos,struct ctl_table * table)350 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
351 struct ctl_table *table)
352 {
353 if (!*ppos)
354 return false;
355
356 switch (sysctl_writes_strict) {
357 case SYSCTL_WRITES_STRICT:
358 return true;
359 case SYSCTL_WRITES_WARN:
360 warn_sysctl_write(table);
361 return false;
362 default:
363 return false;
364 }
365 }
366
367 /**
368 * proc_dostring - read a string sysctl
369 * @table: the sysctl table
370 * @write: %TRUE if this is a write to the sysctl file
371 * @buffer: the user buffer
372 * @lenp: the size of the user buffer
373 * @ppos: file position
374 *
375 * Reads/writes a string from/to the user buffer. If the kernel
376 * buffer provided is not large enough to hold the string, the
377 * string is truncated. The copied string is %NULL-terminated.
378 * If the string is being read by the user process, it is copied
379 * and a newline '\n' is added. It is truncated if the buffer is
380 * not large enough.
381 *
382 * Returns 0 on success.
383 */
proc_dostring(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)384 int proc_dostring(struct ctl_table *table, int write,
385 void *buffer, size_t *lenp, loff_t *ppos)
386 {
387 if (write)
388 proc_first_pos_non_zero_ignore(ppos, table);
389
390 return _proc_do_string(table->data, table->maxlen, write, buffer, lenp,
391 ppos);
392 }
393
proc_skip_spaces(char ** buf,size_t * size)394 static void proc_skip_spaces(char **buf, size_t *size)
395 {
396 while (*size) {
397 if (!isspace(**buf))
398 break;
399 (*size)--;
400 (*buf)++;
401 }
402 }
403
proc_skip_char(char ** buf,size_t * size,const char v)404 static void proc_skip_char(char **buf, size_t *size, const char v)
405 {
406 while (*size) {
407 if (**buf != v)
408 break;
409 (*size)--;
410 (*buf)++;
411 }
412 }
413
414 /**
415 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
416 * fail on overflow
417 *
418 * @cp: kernel buffer containing the string to parse
419 * @endp: pointer to store the trailing characters
420 * @base: the base to use
421 * @res: where the parsed integer will be stored
422 *
423 * In case of success 0 is returned and @res will contain the parsed integer,
424 * @endp will hold any trailing characters.
425 * This function will fail the parse on overflow. If there wasn't an overflow
426 * the function will defer the decision what characters count as invalid to the
427 * caller.
428 */
strtoul_lenient(const char * cp,char ** endp,unsigned int base,unsigned long * res)429 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
430 unsigned long *res)
431 {
432 unsigned long long result;
433 unsigned int rv;
434
435 cp = _parse_integer_fixup_radix(cp, &base);
436 rv = _parse_integer(cp, base, &result);
437 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
438 return -ERANGE;
439
440 cp += rv;
441
442 if (endp)
443 *endp = (char *)cp;
444
445 *res = (unsigned long)result;
446 return 0;
447 }
448
449 #define TMPBUFLEN 22
450 /**
451 * proc_get_long - reads an ASCII formatted integer from a user buffer
452 *
453 * @buf: a kernel buffer
454 * @size: size of the kernel buffer
455 * @val: this is where the number will be stored
456 * @neg: set to %TRUE if number is negative
457 * @perm_tr: a vector which contains the allowed trailers
458 * @perm_tr_len: size of the perm_tr vector
459 * @tr: pointer to store the trailer character
460 *
461 * In case of success %0 is returned and @buf and @size are updated with
462 * the amount of bytes read. If @tr is non-NULL and a trailing
463 * character exists (size is non-zero after returning from this
464 * function), @tr is updated with the trailing character.
465 */
proc_get_long(char ** buf,size_t * size,unsigned long * val,bool * neg,const char * perm_tr,unsigned perm_tr_len,char * tr)466 static int proc_get_long(char **buf, size_t *size,
467 unsigned long *val, bool *neg,
468 const char *perm_tr, unsigned perm_tr_len, char *tr)
469 {
470 char *p, tmp[TMPBUFLEN];
471 ssize_t len = *size;
472
473 if (len <= 0)
474 return -EINVAL;
475
476 if (len > TMPBUFLEN - 1)
477 len = TMPBUFLEN - 1;
478
479 memcpy(tmp, *buf, len);
480
481 tmp[len] = 0;
482 p = tmp;
483 if (*p == '-' && *size > 1) {
484 *neg = true;
485 p++;
486 } else
487 *neg = false;
488 if (!isdigit(*p))
489 return -EINVAL;
490
491 if (strtoul_lenient(p, &p, 0, val))
492 return -EINVAL;
493
494 len = p - tmp;
495
496 /* We don't know if the next char is whitespace thus we may accept
497 * invalid integers (e.g. 1234...a) or two integers instead of one
498 * (e.g. 123...1). So lets not allow such large numbers. */
499 if (len == TMPBUFLEN - 1)
500 return -EINVAL;
501
502 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
503 return -EINVAL;
504
505 if (tr && (len < *size))
506 *tr = *p;
507
508 *buf += len;
509 *size -= len;
510
511 return 0;
512 }
513
514 /**
515 * proc_put_long - converts an integer to a decimal ASCII formatted string
516 *
517 * @buf: the user buffer
518 * @size: the size of the user buffer
519 * @val: the integer to be converted
520 * @neg: sign of the number, %TRUE for negative
521 *
522 * In case of success @buf and @size are updated with the amount of bytes
523 * written.
524 */
proc_put_long(void ** buf,size_t * size,unsigned long val,bool neg)525 static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg)
526 {
527 int len;
528 char tmp[TMPBUFLEN], *p = tmp;
529
530 sprintf(p, "%s%lu", neg ? "-" : "", val);
531 len = strlen(tmp);
532 if (len > *size)
533 len = *size;
534 memcpy(*buf, tmp, len);
535 *size -= len;
536 *buf += len;
537 }
538 #undef TMPBUFLEN
539
proc_put_char(void ** buf,size_t * size,char c)540 static void proc_put_char(void **buf, size_t *size, char c)
541 {
542 if (*size) {
543 char **buffer = (char **)buf;
544 **buffer = c;
545
546 (*size)--;
547 (*buffer)++;
548 *buf = *buffer;
549 }
550 }
551
do_proc_dointvec_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)552 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
553 int *valp,
554 int write, void *data)
555 {
556 if (write) {
557 if (*negp) {
558 if (*lvalp > (unsigned long) INT_MAX + 1)
559 return -EINVAL;
560 WRITE_ONCE(*valp, -*lvalp);
561 } else {
562 if (*lvalp > (unsigned long) INT_MAX)
563 return -EINVAL;
564 WRITE_ONCE(*valp, *lvalp);
565 }
566 } else {
567 int val = READ_ONCE(*valp);
568 if (val < 0) {
569 *negp = true;
570 *lvalp = -(unsigned long)val;
571 } else {
572 *negp = false;
573 *lvalp = (unsigned long)val;
574 }
575 }
576 return 0;
577 }
578
do_proc_douintvec_conv(unsigned long * lvalp,unsigned int * valp,int write,void * data)579 static int do_proc_douintvec_conv(unsigned long *lvalp,
580 unsigned int *valp,
581 int write, void *data)
582 {
583 if (write) {
584 if (*lvalp > UINT_MAX)
585 return -EINVAL;
586 WRITE_ONCE(*valp, *lvalp);
587 } else {
588 unsigned int val = READ_ONCE(*valp);
589 *lvalp = (unsigned long)val;
590 }
591 return 0;
592 }
593
594 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
595
__do_proc_dointvec(void * tbl_data,struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(bool * negp,unsigned long * lvalp,int * valp,int write,void * data),void * data)596 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
597 int write, void *buffer,
598 size_t *lenp, loff_t *ppos,
599 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
600 int write, void *data),
601 void *data)
602 {
603 int *i, vleft, first = 1, err = 0;
604 size_t left;
605 char *p;
606
607 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
608 *lenp = 0;
609 return 0;
610 }
611
612 i = (int *) tbl_data;
613 vleft = table->maxlen / sizeof(*i);
614 left = *lenp;
615
616 if (!conv)
617 conv = do_proc_dointvec_conv;
618
619 if (write) {
620 if (proc_first_pos_non_zero_ignore(ppos, table))
621 goto out;
622
623 if (left > PAGE_SIZE - 1)
624 left = PAGE_SIZE - 1;
625 p = buffer;
626 }
627
628 for (; left && vleft--; i++, first=0) {
629 unsigned long lval;
630 bool neg;
631
632 if (write) {
633 proc_skip_spaces(&p, &left);
634
635 if (!left)
636 break;
637 err = proc_get_long(&p, &left, &lval, &neg,
638 proc_wspace_sep,
639 sizeof(proc_wspace_sep), NULL);
640 if (err)
641 break;
642 if (conv(&neg, &lval, i, 1, data)) {
643 err = -EINVAL;
644 break;
645 }
646 } else {
647 if (conv(&neg, &lval, i, 0, data)) {
648 err = -EINVAL;
649 break;
650 }
651 if (!first)
652 proc_put_char(&buffer, &left, '\t');
653 proc_put_long(&buffer, &left, lval, neg);
654 }
655 }
656
657 if (!write && !first && left && !err)
658 proc_put_char(&buffer, &left, '\n');
659 if (write && !err && left)
660 proc_skip_spaces(&p, &left);
661 if (write && first)
662 return err ? : -EINVAL;
663 *lenp -= left;
664 out:
665 *ppos += *lenp;
666 return err;
667 }
668
do_proc_dointvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(bool * negp,unsigned long * lvalp,int * valp,int write,void * data),void * data)669 static int do_proc_dointvec(struct ctl_table *table, int write,
670 void *buffer, size_t *lenp, loff_t *ppos,
671 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
672 int write, void *data),
673 void *data)
674 {
675 return __do_proc_dointvec(table->data, table, write,
676 buffer, lenp, ppos, conv, data);
677 }
678
do_proc_douintvec_w(unsigned int * tbl_data,struct ctl_table * table,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(unsigned long * lvalp,unsigned int * valp,int write,void * data),void * data)679 static int do_proc_douintvec_w(unsigned int *tbl_data,
680 struct ctl_table *table,
681 void *buffer,
682 size_t *lenp, loff_t *ppos,
683 int (*conv)(unsigned long *lvalp,
684 unsigned int *valp,
685 int write, void *data),
686 void *data)
687 {
688 unsigned long lval;
689 int err = 0;
690 size_t left;
691 bool neg;
692 char *p = buffer;
693
694 left = *lenp;
695
696 if (proc_first_pos_non_zero_ignore(ppos, table))
697 goto bail_early;
698
699 if (left > PAGE_SIZE - 1)
700 left = PAGE_SIZE - 1;
701
702 proc_skip_spaces(&p, &left);
703 if (!left) {
704 err = -EINVAL;
705 goto out_free;
706 }
707
708 err = proc_get_long(&p, &left, &lval, &neg,
709 proc_wspace_sep,
710 sizeof(proc_wspace_sep), NULL);
711 if (err || neg) {
712 err = -EINVAL;
713 goto out_free;
714 }
715
716 if (conv(&lval, tbl_data, 1, data)) {
717 err = -EINVAL;
718 goto out_free;
719 }
720
721 if (!err && left)
722 proc_skip_spaces(&p, &left);
723
724 out_free:
725 if (err)
726 return -EINVAL;
727
728 return 0;
729
730 /* This is in keeping with old __do_proc_dointvec() */
731 bail_early:
732 *ppos += *lenp;
733 return err;
734 }
735
do_proc_douintvec_r(unsigned int * tbl_data,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(unsigned long * lvalp,unsigned int * valp,int write,void * data),void * data)736 static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
737 size_t *lenp, loff_t *ppos,
738 int (*conv)(unsigned long *lvalp,
739 unsigned int *valp,
740 int write, void *data),
741 void *data)
742 {
743 unsigned long lval;
744 int err = 0;
745 size_t left;
746
747 left = *lenp;
748
749 if (conv(&lval, tbl_data, 0, data)) {
750 err = -EINVAL;
751 goto out;
752 }
753
754 proc_put_long(&buffer, &left, lval, false);
755 if (!left)
756 goto out;
757
758 proc_put_char(&buffer, &left, '\n');
759
760 out:
761 *lenp -= left;
762 *ppos += *lenp;
763
764 return err;
765 }
766
__do_proc_douintvec(void * tbl_data,struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(unsigned long * lvalp,unsigned int * valp,int write,void * data),void * data)767 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
768 int write, void *buffer,
769 size_t *lenp, loff_t *ppos,
770 int (*conv)(unsigned long *lvalp,
771 unsigned int *valp,
772 int write, void *data),
773 void *data)
774 {
775 unsigned int *i, vleft;
776
777 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
778 *lenp = 0;
779 return 0;
780 }
781
782 i = (unsigned int *) tbl_data;
783 vleft = table->maxlen / sizeof(*i);
784
785 /*
786 * Arrays are not supported, keep this simple. *Do not* add
787 * support for them.
788 */
789 if (vleft != 1) {
790 *lenp = 0;
791 return -EINVAL;
792 }
793
794 if (!conv)
795 conv = do_proc_douintvec_conv;
796
797 if (write)
798 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
799 conv, data);
800 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
801 }
802
do_proc_douintvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,int (* conv)(unsigned long * lvalp,unsigned int * valp,int write,void * data),void * data)803 static int do_proc_douintvec(struct ctl_table *table, int write,
804 void *buffer, size_t *lenp, loff_t *ppos,
805 int (*conv)(unsigned long *lvalp,
806 unsigned int *valp,
807 int write, void *data),
808 void *data)
809 {
810 return __do_proc_douintvec(table->data, table, write,
811 buffer, lenp, ppos, conv, data);
812 }
813
814 /**
815 * proc_dointvec - read a vector of integers
816 * @table: the sysctl table
817 * @write: %TRUE if this is a write to the sysctl file
818 * @buffer: the user buffer
819 * @lenp: the size of the user buffer
820 * @ppos: file position
821 *
822 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
823 * values from/to the user buffer, treated as an ASCII string.
824 *
825 * Returns 0 on success.
826 */
proc_dointvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)827 int proc_dointvec(struct ctl_table *table, int write, void *buffer,
828 size_t *lenp, loff_t *ppos)
829 {
830 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
831 }
832
833 #ifdef CONFIG_COMPACTION
proc_dointvec_minmax_warn_RT_change(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)834 static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
835 int write, void *buffer, size_t *lenp, loff_t *ppos)
836 {
837 int ret, old;
838
839 if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
840 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
841
842 old = *(int *)table->data;
843 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
844 if (ret)
845 return ret;
846 if (old != *(int *)table->data)
847 pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
848 table->procname, current->comm,
849 task_pid_nr(current));
850 return ret;
851 }
852 #endif
853
854 /**
855 * proc_douintvec - read a vector of unsigned integers
856 * @table: the sysctl table
857 * @write: %TRUE if this is a write to the sysctl file
858 * @buffer: the user buffer
859 * @lenp: the size of the user buffer
860 * @ppos: file position
861 *
862 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
863 * values from/to the user buffer, treated as an ASCII string.
864 *
865 * Returns 0 on success.
866 */
proc_douintvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)867 int proc_douintvec(struct ctl_table *table, int write, void *buffer,
868 size_t *lenp, loff_t *ppos)
869 {
870 return do_proc_douintvec(table, write, buffer, lenp, ppos,
871 do_proc_douintvec_conv, NULL);
872 }
873
874 /*
875 * Taint values can only be increased
876 * This means we can safely use a temporary.
877 */
proc_taint(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)878 static int proc_taint(struct ctl_table *table, int write,
879 void *buffer, size_t *lenp, loff_t *ppos)
880 {
881 struct ctl_table t;
882 unsigned long tmptaint = get_taint();
883 int err;
884
885 if (write && !capable(CAP_SYS_ADMIN))
886 return -EPERM;
887
888 t = *table;
889 t.data = &tmptaint;
890 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
891 if (err < 0)
892 return err;
893
894 if (write) {
895 int i;
896
897 /*
898 * If we are relying on panic_on_taint not producing
899 * false positives due to userspace input, bail out
900 * before setting the requested taint flags.
901 */
902 if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint))
903 return -EINVAL;
904
905 /*
906 * Poor man's atomic or. Not worth adding a primitive
907 * to everyone's atomic.h for this
908 */
909 for (i = 0; i < TAINT_FLAGS_COUNT; i++)
910 if ((1UL << i) & tmptaint)
911 add_taint(i, LOCKDEP_STILL_OK);
912 }
913
914 return err;
915 }
916
917 #ifdef CONFIG_PRINTK
proc_dointvec_minmax_sysadmin(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)918 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
919 void *buffer, size_t *lenp, loff_t *ppos)
920 {
921 if (write && !capable(CAP_SYS_ADMIN))
922 return -EPERM;
923
924 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
925 }
926 #endif
927
928 /**
929 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
930 * @min: pointer to minimum allowable value
931 * @max: pointer to maximum allowable value
932 *
933 * The do_proc_dointvec_minmax_conv_param structure provides the
934 * minimum and maximum values for doing range checking for those sysctl
935 * parameters that use the proc_dointvec_minmax() handler.
936 */
937 struct do_proc_dointvec_minmax_conv_param {
938 int *min;
939 int *max;
940 };
941
do_proc_dointvec_minmax_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)942 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
943 int *valp,
944 int write, void *data)
945 {
946 int tmp, ret;
947 struct do_proc_dointvec_minmax_conv_param *param = data;
948 /*
949 * If writing, first do so via a temporary local int so we can
950 * bounds-check it before touching *valp.
951 */
952 int *ip = write ? &tmp : valp;
953
954 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
955 if (ret)
956 return ret;
957
958 if (write) {
959 if ((param->min && *param->min > tmp) ||
960 (param->max && *param->max < tmp))
961 return -EINVAL;
962 WRITE_ONCE(*valp, tmp);
963 }
964
965 return 0;
966 }
967
968 /**
969 * proc_dointvec_minmax - read a vector of integers with min/max values
970 * @table: the sysctl table
971 * @write: %TRUE if this is a write to the sysctl file
972 * @buffer: the user buffer
973 * @lenp: the size of the user buffer
974 * @ppos: file position
975 *
976 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
977 * values from/to the user buffer, treated as an ASCII string.
978 *
979 * This routine will ensure the values are within the range specified by
980 * table->extra1 (min) and table->extra2 (max).
981 *
982 * Returns 0 on success or -EINVAL on write when the range check fails.
983 */
proc_dointvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)984 int proc_dointvec_minmax(struct ctl_table *table, int write,
985 void *buffer, size_t *lenp, loff_t *ppos)
986 {
987 struct do_proc_dointvec_minmax_conv_param param = {
988 .min = (int *) table->extra1,
989 .max = (int *) table->extra2,
990 };
991 return do_proc_dointvec(table, write, buffer, lenp, ppos,
992 do_proc_dointvec_minmax_conv, ¶m);
993 }
994
995 /**
996 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
997 * @min: pointer to minimum allowable value
998 * @max: pointer to maximum allowable value
999 *
1000 * The do_proc_douintvec_minmax_conv_param structure provides the
1001 * minimum and maximum values for doing range checking for those sysctl
1002 * parameters that use the proc_douintvec_minmax() handler.
1003 */
1004 struct do_proc_douintvec_minmax_conv_param {
1005 unsigned int *min;
1006 unsigned int *max;
1007 };
1008
do_proc_douintvec_minmax_conv(unsigned long * lvalp,unsigned int * valp,int write,void * data)1009 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
1010 unsigned int *valp,
1011 int write, void *data)
1012 {
1013 int ret;
1014 unsigned int tmp;
1015 struct do_proc_douintvec_minmax_conv_param *param = data;
1016 /* write via temporary local uint for bounds-checking */
1017 unsigned int *up = write ? &tmp : valp;
1018
1019 ret = do_proc_douintvec_conv(lvalp, up, write, data);
1020 if (ret)
1021 return ret;
1022
1023 if (write) {
1024 if ((param->min && *param->min > tmp) ||
1025 (param->max && *param->max < tmp))
1026 return -ERANGE;
1027
1028 WRITE_ONCE(*valp, tmp);
1029 }
1030
1031 return 0;
1032 }
1033
1034 /**
1035 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
1036 * @table: the sysctl table
1037 * @write: %TRUE if this is a write to the sysctl file
1038 * @buffer: the user buffer
1039 * @lenp: the size of the user buffer
1040 * @ppos: file position
1041 *
1042 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
1043 * values from/to the user buffer, treated as an ASCII string. Negative
1044 * strings are not allowed.
1045 *
1046 * This routine will ensure the values are within the range specified by
1047 * table->extra1 (min) and table->extra2 (max). There is a final sanity
1048 * check for UINT_MAX to avoid having to support wrap around uses from
1049 * userspace.
1050 *
1051 * Returns 0 on success or -ERANGE on write when the range check fails.
1052 */
proc_douintvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1053 int proc_douintvec_minmax(struct ctl_table *table, int write,
1054 void *buffer, size_t *lenp, loff_t *ppos)
1055 {
1056 struct do_proc_douintvec_minmax_conv_param param = {
1057 .min = (unsigned int *) table->extra1,
1058 .max = (unsigned int *) table->extra2,
1059 };
1060 return do_proc_douintvec(table, write, buffer, lenp, ppos,
1061 do_proc_douintvec_minmax_conv, ¶m);
1062 }
1063
do_proc_dopipe_max_size_conv(unsigned long * lvalp,unsigned int * valp,int write,void * data)1064 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
1065 unsigned int *valp,
1066 int write, void *data)
1067 {
1068 if (write) {
1069 unsigned int val;
1070
1071 val = round_pipe_size(*lvalp);
1072 if (val == 0)
1073 return -EINVAL;
1074
1075 *valp = val;
1076 } else {
1077 unsigned int val = *valp;
1078 *lvalp = (unsigned long) val;
1079 }
1080
1081 return 0;
1082 }
1083
proc_dopipe_max_size(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1084 static int proc_dopipe_max_size(struct ctl_table *table, int write,
1085 void *buffer, size_t *lenp, loff_t *ppos)
1086 {
1087 return do_proc_douintvec(table, write, buffer, lenp, ppos,
1088 do_proc_dopipe_max_size_conv, NULL);
1089 }
1090
validate_coredump_safety(void)1091 static void validate_coredump_safety(void)
1092 {
1093 #ifdef CONFIG_COREDUMP
1094 if (suid_dumpable == SUID_DUMP_ROOT &&
1095 core_pattern[0] != '/' && core_pattern[0] != '|') {
1096 printk(KERN_WARNING
1097 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
1098 "Pipe handler or fully qualified core dump path required.\n"
1099 "Set kernel.core_pattern before fs.suid_dumpable.\n"
1100 );
1101 }
1102 #endif
1103 }
1104
proc_dointvec_minmax_coredump(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1105 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
1106 void *buffer, size_t *lenp, loff_t *ppos)
1107 {
1108 int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
1109 if (!error)
1110 validate_coredump_safety();
1111 return error;
1112 }
1113
1114 #ifdef CONFIG_COREDUMP
proc_dostring_coredump(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1115 static int proc_dostring_coredump(struct ctl_table *table, int write,
1116 void *buffer, size_t *lenp, loff_t *ppos)
1117 {
1118 int error = proc_dostring(table, write, buffer, lenp, ppos);
1119 if (!error)
1120 validate_coredump_safety();
1121 return error;
1122 }
1123 #endif
1124
1125 #ifdef CONFIG_MAGIC_SYSRQ
sysrq_sysctl_handler(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1126 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
1127 void *buffer, size_t *lenp, loff_t *ppos)
1128 {
1129 int tmp, ret;
1130
1131 tmp = sysrq_mask();
1132
1133 ret = __do_proc_dointvec(&tmp, table, write, buffer,
1134 lenp, ppos, NULL, NULL);
1135 if (ret || !write)
1136 return ret;
1137
1138 if (write)
1139 sysrq_toggle_support(tmp);
1140
1141 return 0;
1142 }
1143 #endif
1144
__do_proc_doulongvec_minmax(void * data,struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,unsigned long convmul,unsigned long convdiv)1145 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
1146 int write, void *buffer, size_t *lenp, loff_t *ppos,
1147 unsigned long convmul, unsigned long convdiv)
1148 {
1149 unsigned long *i, *min, *max;
1150 int vleft, first = 1, err = 0;
1151 size_t left;
1152 char *p;
1153
1154 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
1155 *lenp = 0;
1156 return 0;
1157 }
1158
1159 i = (unsigned long *) data;
1160 min = (unsigned long *) table->extra1;
1161 max = (unsigned long *) table->extra2;
1162 vleft = table->maxlen / sizeof(unsigned long);
1163 left = *lenp;
1164
1165 if (write) {
1166 if (proc_first_pos_non_zero_ignore(ppos, table))
1167 goto out;
1168
1169 if (left > PAGE_SIZE - 1)
1170 left = PAGE_SIZE - 1;
1171 p = buffer;
1172 }
1173
1174 for (; left && vleft--; i++, first = 0) {
1175 unsigned long val;
1176
1177 if (write) {
1178 bool neg;
1179
1180 proc_skip_spaces(&p, &left);
1181 if (!left)
1182 break;
1183
1184 err = proc_get_long(&p, &left, &val, &neg,
1185 proc_wspace_sep,
1186 sizeof(proc_wspace_sep), NULL);
1187 if (err)
1188 break;
1189 if (neg)
1190 continue;
1191 val = convmul * val / convdiv;
1192 if ((min && val < *min) || (max && val > *max)) {
1193 err = -EINVAL;
1194 break;
1195 }
1196 WRITE_ONCE(*i, val);
1197 } else {
1198 val = convdiv * READ_ONCE(*i) / convmul;
1199 if (!first)
1200 proc_put_char(&buffer, &left, '\t');
1201 proc_put_long(&buffer, &left, val, false);
1202 }
1203 }
1204
1205 if (!write && !first && left && !err)
1206 proc_put_char(&buffer, &left, '\n');
1207 if (write && !err)
1208 proc_skip_spaces(&p, &left);
1209 if (write && first)
1210 return err ? : -EINVAL;
1211 *lenp -= left;
1212 out:
1213 *ppos += *lenp;
1214 return err;
1215 }
1216
do_proc_doulongvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos,unsigned long convmul,unsigned long convdiv)1217 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
1218 void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
1219 unsigned long convdiv)
1220 {
1221 return __do_proc_doulongvec_minmax(table->data, table, write,
1222 buffer, lenp, ppos, convmul, convdiv);
1223 }
1224
1225 /**
1226 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1227 * @table: the sysctl table
1228 * @write: %TRUE if this is a write to the sysctl file
1229 * @buffer: the user buffer
1230 * @lenp: the size of the user buffer
1231 * @ppos: file position
1232 *
1233 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1234 * values from/to the user buffer, treated as an ASCII string.
1235 *
1236 * This routine will ensure the values are within the range specified by
1237 * table->extra1 (min) and table->extra2 (max).
1238 *
1239 * Returns 0 on success.
1240 */
proc_doulongvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1241 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1242 void *buffer, size_t *lenp, loff_t *ppos)
1243 {
1244 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
1245 }
1246
1247 /**
1248 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1249 * @table: the sysctl table
1250 * @write: %TRUE if this is a write to the sysctl file
1251 * @buffer: the user buffer
1252 * @lenp: the size of the user buffer
1253 * @ppos: file position
1254 *
1255 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1256 * values from/to the user buffer, treated as an ASCII string. The values
1257 * are treated as milliseconds, and converted to jiffies when they are stored.
1258 *
1259 * This routine will ensure the values are within the range specified by
1260 * table->extra1 (min) and table->extra2 (max).
1261 *
1262 * Returns 0 on success.
1263 */
proc_doulongvec_ms_jiffies_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1264 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1265 void *buffer, size_t *lenp, loff_t *ppos)
1266 {
1267 return do_proc_doulongvec_minmax(table, write, buffer,
1268 lenp, ppos, HZ, 1000l);
1269 }
1270
1271
do_proc_dointvec_jiffies_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)1272 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
1273 int *valp,
1274 int write, void *data)
1275 {
1276 if (write) {
1277 if (*lvalp > INT_MAX / HZ)
1278 return 1;
1279 if (*negp)
1280 WRITE_ONCE(*valp, -*lvalp * HZ);
1281 else
1282 WRITE_ONCE(*valp, *lvalp * HZ);
1283 } else {
1284 int val = READ_ONCE(*valp);
1285 unsigned long lval;
1286 if (val < 0) {
1287 *negp = true;
1288 lval = -(unsigned long)val;
1289 } else {
1290 *negp = false;
1291 lval = (unsigned long)val;
1292 }
1293 *lvalp = lval / HZ;
1294 }
1295 return 0;
1296 }
1297
do_proc_dointvec_userhz_jiffies_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)1298 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
1299 int *valp,
1300 int write, void *data)
1301 {
1302 if (write) {
1303 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
1304 return 1;
1305 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1306 } else {
1307 int val = *valp;
1308 unsigned long lval;
1309 if (val < 0) {
1310 *negp = true;
1311 lval = -(unsigned long)val;
1312 } else {
1313 *negp = false;
1314 lval = (unsigned long)val;
1315 }
1316 *lvalp = jiffies_to_clock_t(lval);
1317 }
1318 return 0;
1319 }
1320
do_proc_dointvec_ms_jiffies_conv(bool * negp,unsigned long * lvalp,int * valp,int write,void * data)1321 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
1322 int *valp,
1323 int write, void *data)
1324 {
1325 if (write) {
1326 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1327
1328 if (jif > INT_MAX)
1329 return 1;
1330 WRITE_ONCE(*valp, (int)jif);
1331 } else {
1332 int val = READ_ONCE(*valp);
1333 unsigned long lval;
1334 if (val < 0) {
1335 *negp = true;
1336 lval = -(unsigned long)val;
1337 } else {
1338 *negp = false;
1339 lval = (unsigned long)val;
1340 }
1341 *lvalp = jiffies_to_msecs(lval);
1342 }
1343 return 0;
1344 }
1345
1346 /**
1347 * proc_dointvec_jiffies - read a vector of integers as seconds
1348 * @table: the sysctl table
1349 * @write: %TRUE if this is a write to the sysctl file
1350 * @buffer: the user buffer
1351 * @lenp: the size of the user buffer
1352 * @ppos: file position
1353 *
1354 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1355 * values from/to the user buffer, treated as an ASCII string.
1356 * The values read are assumed to be in seconds, and are converted into
1357 * jiffies.
1358 *
1359 * Returns 0 on success.
1360 */
proc_dointvec_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1361 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1362 void *buffer, size_t *lenp, loff_t *ppos)
1363 {
1364 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1365 do_proc_dointvec_jiffies_conv,NULL);
1366 }
1367
1368 /**
1369 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1370 * @table: the sysctl table
1371 * @write: %TRUE if this is a write to the sysctl file
1372 * @buffer: the user buffer
1373 * @lenp: the size of the user buffer
1374 * @ppos: pointer to the file position
1375 *
1376 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1377 * values from/to the user buffer, treated as an ASCII string.
1378 * The values read are assumed to be in 1/USER_HZ seconds, and
1379 * are converted into jiffies.
1380 *
1381 * Returns 0 on success.
1382 */
proc_dointvec_userhz_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1383 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1384 void *buffer, size_t *lenp, loff_t *ppos)
1385 {
1386 return do_proc_dointvec(table,write,buffer,lenp,ppos,
1387 do_proc_dointvec_userhz_jiffies_conv,NULL);
1388 }
1389
1390 /**
1391 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1392 * @table: the sysctl table
1393 * @write: %TRUE if this is a write to the sysctl file
1394 * @buffer: the user buffer
1395 * @lenp: the size of the user buffer
1396 * @ppos: file position
1397 * @ppos: the current position in the file
1398 *
1399 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1400 * values from/to the user buffer, treated as an ASCII string.
1401 * The values read are assumed to be in 1/1000 seconds, and
1402 * are converted into jiffies.
1403 *
1404 * Returns 0 on success.
1405 */
proc_dointvec_ms_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1406 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer,
1407 size_t *lenp, loff_t *ppos)
1408 {
1409 return do_proc_dointvec(table, write, buffer, lenp, ppos,
1410 do_proc_dointvec_ms_jiffies_conv, NULL);
1411 }
1412
proc_do_cad_pid(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1413 static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer,
1414 size_t *lenp, loff_t *ppos)
1415 {
1416 struct pid *new_pid;
1417 pid_t tmp;
1418 int r;
1419
1420 tmp = pid_vnr(cad_pid);
1421
1422 r = __do_proc_dointvec(&tmp, table, write, buffer,
1423 lenp, ppos, NULL, NULL);
1424 if (r || !write)
1425 return r;
1426
1427 new_pid = find_get_pid(tmp);
1428 if (!new_pid)
1429 return -ESRCH;
1430
1431 put_pid(xchg(&cad_pid, new_pid));
1432 return 0;
1433 }
1434
1435 /**
1436 * proc_do_large_bitmap - read/write from/to a large bitmap
1437 * @table: the sysctl table
1438 * @write: %TRUE if this is a write to the sysctl file
1439 * @buffer: the user buffer
1440 * @lenp: the size of the user buffer
1441 * @ppos: file position
1442 *
1443 * The bitmap is stored at table->data and the bitmap length (in bits)
1444 * in table->maxlen.
1445 *
1446 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
1447 * large bitmaps may be represented in a compact manner. Writing into
1448 * the file will clear the bitmap then update it with the given input.
1449 *
1450 * Returns 0 on success.
1451 */
proc_do_large_bitmap(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1452 int proc_do_large_bitmap(struct ctl_table *table, int write,
1453 void *buffer, size_t *lenp, loff_t *ppos)
1454 {
1455 int err = 0;
1456 bool first = 1;
1457 size_t left = *lenp;
1458 unsigned long bitmap_len = table->maxlen;
1459 unsigned long *bitmap = *(unsigned long **) table->data;
1460 unsigned long *tmp_bitmap = NULL;
1461 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
1462
1463 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
1464 *lenp = 0;
1465 return 0;
1466 }
1467
1468 if (write) {
1469 char *p = buffer;
1470 size_t skipped = 0;
1471
1472 if (left > PAGE_SIZE - 1) {
1473 left = PAGE_SIZE - 1;
1474 /* How much of the buffer we'll skip this pass */
1475 skipped = *lenp - left;
1476 }
1477
1478 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
1479 if (!tmp_bitmap)
1480 return -ENOMEM;
1481 proc_skip_char(&p, &left, '\n');
1482 while (!err && left) {
1483 unsigned long val_a, val_b;
1484 bool neg;
1485 size_t saved_left;
1486
1487 /* In case we stop parsing mid-number, we can reset */
1488 saved_left = left;
1489 err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
1490 sizeof(tr_a), &c);
1491 /*
1492 * If we consumed the entirety of a truncated buffer or
1493 * only one char is left (may be a "-"), then stop here,
1494 * reset, & come back for more.
1495 */
1496 if ((left <= 1) && skipped) {
1497 left = saved_left;
1498 break;
1499 }
1500
1501 if (err)
1502 break;
1503 if (val_a >= bitmap_len || neg) {
1504 err = -EINVAL;
1505 break;
1506 }
1507
1508 val_b = val_a;
1509 if (left) {
1510 p++;
1511 left--;
1512 }
1513
1514 if (c == '-') {
1515 err = proc_get_long(&p, &left, &val_b,
1516 &neg, tr_b, sizeof(tr_b),
1517 &c);
1518 /*
1519 * If we consumed all of a truncated buffer or
1520 * then stop here, reset, & come back for more.
1521 */
1522 if (!left && skipped) {
1523 left = saved_left;
1524 break;
1525 }
1526
1527 if (err)
1528 break;
1529 if (val_b >= bitmap_len || neg ||
1530 val_a > val_b) {
1531 err = -EINVAL;
1532 break;
1533 }
1534 if (left) {
1535 p++;
1536 left--;
1537 }
1538 }
1539
1540 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
1541 first = 0;
1542 proc_skip_char(&p, &left, '\n');
1543 }
1544 left += skipped;
1545 } else {
1546 unsigned long bit_a, bit_b = 0;
1547
1548 while (left) {
1549 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
1550 if (bit_a >= bitmap_len)
1551 break;
1552 bit_b = find_next_zero_bit(bitmap, bitmap_len,
1553 bit_a + 1) - 1;
1554
1555 if (!first)
1556 proc_put_char(&buffer, &left, ',');
1557 proc_put_long(&buffer, &left, bit_a, false);
1558 if (bit_a != bit_b) {
1559 proc_put_char(&buffer, &left, '-');
1560 proc_put_long(&buffer, &left, bit_b, false);
1561 }
1562
1563 first = 0; bit_b++;
1564 }
1565 proc_put_char(&buffer, &left, '\n');
1566 }
1567
1568 if (!err) {
1569 if (write) {
1570 if (*ppos)
1571 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
1572 else
1573 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
1574 }
1575 *lenp -= left;
1576 *ppos += *lenp;
1577 }
1578
1579 bitmap_free(tmp_bitmap);
1580 return err;
1581 }
1582
1583 #else /* CONFIG_PROC_SYSCTL */
1584
proc_dostring(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1585 int proc_dostring(struct ctl_table *table, int write,
1586 void *buffer, size_t *lenp, loff_t *ppos)
1587 {
1588 return -ENOSYS;
1589 }
1590
proc_dointvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1591 int proc_dointvec(struct ctl_table *table, int write,
1592 void *buffer, size_t *lenp, loff_t *ppos)
1593 {
1594 return -ENOSYS;
1595 }
1596
proc_douintvec(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1597 int proc_douintvec(struct ctl_table *table, int write,
1598 void *buffer, size_t *lenp, loff_t *ppos)
1599 {
1600 return -ENOSYS;
1601 }
1602
proc_dointvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1603 int proc_dointvec_minmax(struct ctl_table *table, int write,
1604 void *buffer, size_t *lenp, loff_t *ppos)
1605 {
1606 return -ENOSYS;
1607 }
1608
proc_douintvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1609 int proc_douintvec_minmax(struct ctl_table *table, int write,
1610 void *buffer, size_t *lenp, loff_t *ppos)
1611 {
1612 return -ENOSYS;
1613 }
1614
proc_dointvec_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1615 int proc_dointvec_jiffies(struct ctl_table *table, int write,
1616 void *buffer, size_t *lenp, loff_t *ppos)
1617 {
1618 return -ENOSYS;
1619 }
1620
proc_dointvec_userhz_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1621 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
1622 void *buffer, size_t *lenp, loff_t *ppos)
1623 {
1624 return -ENOSYS;
1625 }
1626
proc_dointvec_ms_jiffies(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1627 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
1628 void *buffer, size_t *lenp, loff_t *ppos)
1629 {
1630 return -ENOSYS;
1631 }
1632
proc_doulongvec_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1633 int proc_doulongvec_minmax(struct ctl_table *table, int write,
1634 void *buffer, size_t *lenp, loff_t *ppos)
1635 {
1636 return -ENOSYS;
1637 }
1638
proc_doulongvec_ms_jiffies_minmax(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1639 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
1640 void *buffer, size_t *lenp, loff_t *ppos)
1641 {
1642 return -ENOSYS;
1643 }
1644
proc_do_large_bitmap(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1645 int proc_do_large_bitmap(struct ctl_table *table, int write,
1646 void *buffer, size_t *lenp, loff_t *ppos)
1647 {
1648 return -ENOSYS;
1649 }
1650
1651 #endif /* CONFIG_PROC_SYSCTL */
1652
1653 #if defined(CONFIG_SYSCTL)
proc_do_static_key(struct ctl_table * table,int write,void * buffer,size_t * lenp,loff_t * ppos)1654 int proc_do_static_key(struct ctl_table *table, int write,
1655 void *buffer, size_t *lenp, loff_t *ppos)
1656 {
1657 struct static_key *key = (struct static_key *)table->data;
1658 static DEFINE_MUTEX(static_key_mutex);
1659 int val, ret;
1660 struct ctl_table tmp = {
1661 .data = &val,
1662 .maxlen = sizeof(val),
1663 .mode = table->mode,
1664 .extra1 = SYSCTL_ZERO,
1665 .extra2 = SYSCTL_ONE,
1666 };
1667
1668 if (write && !capable(CAP_SYS_ADMIN))
1669 return -EPERM;
1670
1671 mutex_lock(&static_key_mutex);
1672 val = static_key_enabled(key);
1673 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
1674 if (write && !ret) {
1675 if (val)
1676 static_key_enable(key);
1677 else
1678 static_key_disable(key);
1679 }
1680 mutex_unlock(&static_key_mutex);
1681 return ret;
1682 }
1683
1684 static struct ctl_table kern_table[] = {
1685 {
1686 .procname = "sched_child_runs_first",
1687 .data = &sysctl_sched_child_runs_first,
1688 .maxlen = sizeof(unsigned int),
1689 .mode = 0644,
1690 .proc_handler = proc_dointvec,
1691 },
1692 #ifdef CONFIG_SCHED_RT_CAS
1693 {
1694 .procname = "sched_enable_rt_cas",
1695 .data = &sysctl_sched_enable_rt_cas,
1696 .maxlen = sizeof(unsigned int),
1697 .mode = 0644,
1698 .proc_handler = proc_dointvec,
1699 },
1700 #endif
1701 #ifdef CONFIG_SCHED_RT_ACTIVE_LB
1702 {
1703 .procname = "sched_enable_rt_active_lb",
1704 .data = &sysctl_sched_enable_rt_active_lb,
1705 .maxlen = sizeof(unsigned int),
1706 .mode = 0644,
1707 .proc_handler = proc_dointvec,
1708 },
1709 #endif
1710 #ifdef CONFIG_SCHED_WALT
1711 {
1712 .procname = "sched_use_walt_cpu_util",
1713 .data = &sysctl_sched_use_walt_cpu_util,
1714 .maxlen = sizeof(unsigned int),
1715 .mode = 0644,
1716 .proc_handler = proc_dointvec_minmax,
1717 .extra1 = SYSCTL_ZERO,
1718 .extra2 = SYSCTL_ONE,
1719 },
1720 {
1721 .procname = "sched_use_walt_task_util",
1722 .data = &sysctl_sched_use_walt_task_util,
1723 .maxlen = sizeof(unsigned int),
1724 .mode = 0644,
1725 .proc_handler = proc_dointvec_minmax,
1726 .extra1 = SYSCTL_ZERO,
1727 .extra2 = SYSCTL_ONE,
1728 },
1729 {
1730 .procname = "sched_walt_init_task_load_pct",
1731 .data = &sysctl_sched_walt_init_task_load_pct,
1732 .maxlen = sizeof(unsigned int),
1733 .mode = 0644,
1734 .proc_handler = sysctl_sched_walt_init_task_load_pct_sysctl_handler,
1735 },
1736 {
1737 .procname = "sched_cpu_high_irqload",
1738 .data = &sysctl_sched_cpu_high_irqload,
1739 .maxlen = sizeof(unsigned int),
1740 .mode = 0644,
1741 .proc_handler = proc_dointvec,
1742 },
1743 #endif
1744 #ifdef CONFIG_SCHED_DEBUG
1745 {
1746 .procname = "sched_min_granularity_ns",
1747 .data = &sysctl_sched_min_granularity,
1748 .maxlen = sizeof(unsigned int),
1749 .mode = 0644,
1750 .proc_handler = sched_proc_update_handler,
1751 .extra1 = &min_sched_granularity_ns,
1752 .extra2 = &max_sched_granularity_ns,
1753 },
1754 {
1755 .procname = "sched_latency_ns",
1756 .data = &sysctl_sched_latency,
1757 .maxlen = sizeof(unsigned int),
1758 .mode = 0644,
1759 .proc_handler = sched_proc_update_handler,
1760 .extra1 = &min_sched_granularity_ns,
1761 .extra2 = &max_sched_granularity_ns,
1762 },
1763 {
1764 .procname = "sched_wakeup_granularity_ns",
1765 .data = &sysctl_sched_wakeup_granularity,
1766 .maxlen = sizeof(unsigned int),
1767 .mode = 0644,
1768 .proc_handler = sched_proc_update_handler,
1769 .extra1 = &min_wakeup_granularity_ns,
1770 .extra2 = &max_wakeup_granularity_ns,
1771 },
1772 #ifdef CONFIG_SMP
1773 {
1774 .procname = "sched_tunable_scaling",
1775 .data = &sysctl_sched_tunable_scaling,
1776 .maxlen = sizeof(enum sched_tunable_scaling),
1777 .mode = 0644,
1778 .proc_handler = sched_proc_update_handler,
1779 .extra1 = &min_sched_tunable_scaling,
1780 .extra2 = &max_sched_tunable_scaling,
1781 },
1782 {
1783 .procname = "sched_migration_cost_ns",
1784 .data = &sysctl_sched_migration_cost,
1785 .maxlen = sizeof(unsigned int),
1786 .mode = 0644,
1787 .proc_handler = proc_dointvec,
1788 },
1789 {
1790 .procname = "sched_nr_migrate",
1791 .data = &sysctl_sched_nr_migrate,
1792 .maxlen = sizeof(unsigned int),
1793 .mode = 0644,
1794 .proc_handler = proc_dointvec,
1795 },
1796 #ifdef CONFIG_SCHEDSTATS
1797 {
1798 .procname = "sched_schedstats",
1799 .data = NULL,
1800 .maxlen = sizeof(unsigned int),
1801 .mode = 0644,
1802 .proc_handler = sysctl_schedstats,
1803 .extra1 = SYSCTL_ZERO,
1804 .extra2 = SYSCTL_ONE,
1805 },
1806 #endif /* CONFIG_SCHEDSTATS */
1807 #endif /* CONFIG_SMP */
1808 #ifdef CONFIG_NUMA_BALANCING
1809 {
1810 .procname = "numa_balancing_scan_delay_ms",
1811 .data = &sysctl_numa_balancing_scan_delay,
1812 .maxlen = sizeof(unsigned int),
1813 .mode = 0644,
1814 .proc_handler = proc_dointvec,
1815 },
1816 {
1817 .procname = "numa_balancing_scan_period_min_ms",
1818 .data = &sysctl_numa_balancing_scan_period_min,
1819 .maxlen = sizeof(unsigned int),
1820 .mode = 0644,
1821 .proc_handler = proc_dointvec,
1822 },
1823 {
1824 .procname = "numa_balancing_scan_period_max_ms",
1825 .data = &sysctl_numa_balancing_scan_period_max,
1826 .maxlen = sizeof(unsigned int),
1827 .mode = 0644,
1828 .proc_handler = proc_dointvec,
1829 },
1830 {
1831 .procname = "numa_balancing_scan_size_mb",
1832 .data = &sysctl_numa_balancing_scan_size,
1833 .maxlen = sizeof(unsigned int),
1834 .mode = 0644,
1835 .proc_handler = proc_dointvec_minmax,
1836 .extra1 = SYSCTL_ONE,
1837 },
1838 {
1839 .procname = "numa_balancing",
1840 .data = NULL, /* filled in by handler */
1841 .maxlen = sizeof(unsigned int),
1842 .mode = 0644,
1843 .proc_handler = sysctl_numa_balancing,
1844 .extra1 = SYSCTL_ZERO,
1845 .extra2 = SYSCTL_ONE,
1846 },
1847 #endif /* CONFIG_NUMA_BALANCING */
1848 #endif /* CONFIG_SCHED_DEBUG */
1849 {
1850 .procname = "sched_rt_period_us",
1851 .data = &sysctl_sched_rt_period,
1852 .maxlen = sizeof(unsigned int),
1853 .mode = 0644,
1854 .proc_handler = sched_rt_handler,
1855 },
1856 {
1857 .procname = "sched_rt_runtime_us",
1858 .data = &sysctl_sched_rt_runtime,
1859 .maxlen = sizeof(int),
1860 .mode = 0644,
1861 .proc_handler = sched_rt_handler,
1862 },
1863 {
1864 .procname = "sched_deadline_period_max_us",
1865 .data = &sysctl_sched_dl_period_max,
1866 .maxlen = sizeof(unsigned int),
1867 .mode = 0644,
1868 .proc_handler = proc_dointvec,
1869 },
1870 {
1871 .procname = "sched_deadline_period_min_us",
1872 .data = &sysctl_sched_dl_period_min,
1873 .maxlen = sizeof(unsigned int),
1874 .mode = 0644,
1875 .proc_handler = proc_dointvec,
1876 },
1877 {
1878 .procname = "sched_rr_timeslice_ms",
1879 .data = &sysctl_sched_rr_timeslice,
1880 .maxlen = sizeof(int),
1881 .mode = 0644,
1882 .proc_handler = sched_rr_handler,
1883 },
1884 #ifdef CONFIG_UCLAMP_TASK
1885 {
1886 .procname = "sched_util_clamp_min",
1887 .data = &sysctl_sched_uclamp_util_min,
1888 .maxlen = sizeof(unsigned int),
1889 .mode = 0644,
1890 .proc_handler = sysctl_sched_uclamp_handler,
1891 },
1892 {
1893 .procname = "sched_util_clamp_max",
1894 .data = &sysctl_sched_uclamp_util_max,
1895 .maxlen = sizeof(unsigned int),
1896 .mode = 0644,
1897 .proc_handler = sysctl_sched_uclamp_handler,
1898 },
1899 {
1900 .procname = "sched_util_clamp_min_rt_default",
1901 .data = &sysctl_sched_uclamp_util_min_rt_default,
1902 .maxlen = sizeof(unsigned int),
1903 .mode = 0644,
1904 .proc_handler = sysctl_sched_uclamp_handler,
1905 },
1906 #endif
1907 #ifdef CONFIG_SCHED_AUTOGROUP
1908 {
1909 .procname = "sched_autogroup_enabled",
1910 .data = &sysctl_sched_autogroup_enabled,
1911 .maxlen = sizeof(unsigned int),
1912 .mode = 0644,
1913 .proc_handler = proc_dointvec_minmax,
1914 .extra1 = SYSCTL_ZERO,
1915 .extra2 = SYSCTL_ONE,
1916 },
1917 #endif
1918 #ifdef CONFIG_CFS_BANDWIDTH
1919 {
1920 .procname = "sched_cfs_bandwidth_slice_us",
1921 .data = &sysctl_sched_cfs_bandwidth_slice,
1922 .maxlen = sizeof(unsigned int),
1923 .mode = 0644,
1924 .proc_handler = proc_dointvec_minmax,
1925 .extra1 = SYSCTL_ONE,
1926 },
1927 #endif
1928 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
1929 {
1930 .procname = "sched_energy_aware",
1931 .data = &sysctl_sched_energy_aware,
1932 .maxlen = sizeof(unsigned int),
1933 .mode = 0644,
1934 .proc_handler = sched_energy_aware_handler,
1935 .extra1 = SYSCTL_ZERO,
1936 .extra2 = SYSCTL_ONE,
1937 },
1938 #endif
1939 #ifdef CONFIG_PROVE_LOCKING
1940 {
1941 .procname = "prove_locking",
1942 .data = &prove_locking,
1943 .maxlen = sizeof(int),
1944 .mode = 0644,
1945 .proc_handler = proc_dointvec,
1946 },
1947 #endif
1948 #ifdef CONFIG_LOCK_STAT
1949 {
1950 .procname = "lock_stat",
1951 .data = &lock_stat,
1952 .maxlen = sizeof(int),
1953 .mode = 0644,
1954 .proc_handler = proc_dointvec,
1955 },
1956 #endif
1957 {
1958 .procname = "panic",
1959 .data = &panic_timeout,
1960 .maxlen = sizeof(int),
1961 .mode = 0644,
1962 .proc_handler = proc_dointvec,
1963 },
1964 #ifdef CONFIG_COREDUMP
1965 {
1966 .procname = "core_uses_pid",
1967 .data = &core_uses_pid,
1968 .maxlen = sizeof(int),
1969 .mode = 0644,
1970 .proc_handler = proc_dointvec,
1971 },
1972 {
1973 .procname = "core_pattern",
1974 .data = core_pattern,
1975 .maxlen = CORENAME_MAX_SIZE,
1976 .mode = 0644,
1977 .proc_handler = proc_dostring_coredump,
1978 },
1979 {
1980 .procname = "core_pipe_limit",
1981 .data = &core_pipe_limit,
1982 .maxlen = sizeof(unsigned int),
1983 .mode = 0644,
1984 .proc_handler = proc_dointvec,
1985 },
1986 #endif
1987 #ifdef CONFIG_PROC_SYSCTL
1988 {
1989 .procname = "tainted",
1990 .maxlen = sizeof(long),
1991 .mode = 0644,
1992 .proc_handler = proc_taint,
1993 },
1994 {
1995 .procname = "sysctl_writes_strict",
1996 .data = &sysctl_writes_strict,
1997 .maxlen = sizeof(int),
1998 .mode = 0644,
1999 .proc_handler = proc_dointvec_minmax,
2000 .extra1 = &neg_one,
2001 .extra2 = SYSCTL_ONE,
2002 },
2003 #endif
2004 #ifdef CONFIG_LATENCYTOP
2005 {
2006 .procname = "latencytop",
2007 .data = &latencytop_enabled,
2008 .maxlen = sizeof(int),
2009 .mode = 0644,
2010 .proc_handler = sysctl_latencytop,
2011 },
2012 #endif
2013 #ifdef CONFIG_BLK_DEV_INITRD
2014 {
2015 .procname = "real-root-dev",
2016 .data = &real_root_dev,
2017 .maxlen = sizeof(int),
2018 .mode = 0644,
2019 .proc_handler = proc_dointvec,
2020 },
2021 #endif
2022 {
2023 .procname = "print-fatal-signals",
2024 .data = &print_fatal_signals,
2025 .maxlen = sizeof(int),
2026 .mode = 0644,
2027 .proc_handler = proc_dointvec,
2028 },
2029 #ifdef CONFIG_SPARC
2030 {
2031 .procname = "reboot-cmd",
2032 .data = reboot_command,
2033 .maxlen = 256,
2034 .mode = 0644,
2035 .proc_handler = proc_dostring,
2036 },
2037 {
2038 .procname = "stop-a",
2039 .data = &stop_a_enabled,
2040 .maxlen = sizeof (int),
2041 .mode = 0644,
2042 .proc_handler = proc_dointvec,
2043 },
2044 {
2045 .procname = "scons-poweroff",
2046 .data = &scons_pwroff,
2047 .maxlen = sizeof (int),
2048 .mode = 0644,
2049 .proc_handler = proc_dointvec,
2050 },
2051 #endif
2052 #ifdef CONFIG_SPARC64
2053 {
2054 .procname = "tsb-ratio",
2055 .data = &sysctl_tsb_ratio,
2056 .maxlen = sizeof (int),
2057 .mode = 0644,
2058 .proc_handler = proc_dointvec,
2059 },
2060 #endif
2061 #ifdef CONFIG_PARISC
2062 {
2063 .procname = "soft-power",
2064 .data = &pwrsw_enabled,
2065 .maxlen = sizeof (int),
2066 .mode = 0644,
2067 .proc_handler = proc_dointvec,
2068 },
2069 #endif
2070 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
2071 {
2072 .procname = "unaligned-trap",
2073 .data = &unaligned_enabled,
2074 .maxlen = sizeof (int),
2075 .mode = 0644,
2076 .proc_handler = proc_dointvec,
2077 },
2078 #endif
2079 {
2080 .procname = "ctrl-alt-del",
2081 .data = &C_A_D,
2082 .maxlen = sizeof(int),
2083 .mode = 0644,
2084 .proc_handler = proc_dointvec,
2085 },
2086 #ifdef CONFIG_FUNCTION_TRACER
2087 {
2088 .procname = "ftrace_enabled",
2089 .data = &ftrace_enabled,
2090 .maxlen = sizeof(int),
2091 .mode = 0644,
2092 .proc_handler = ftrace_enable_sysctl,
2093 },
2094 #endif
2095 #ifdef CONFIG_STACK_TRACER
2096 {
2097 .procname = "stack_tracer_enabled",
2098 .data = &stack_tracer_enabled,
2099 .maxlen = sizeof(int),
2100 .mode = 0644,
2101 .proc_handler = stack_trace_sysctl,
2102 },
2103 #endif
2104 #ifdef CONFIG_TRACING
2105 {
2106 .procname = "ftrace_dump_on_oops",
2107 .data = &ftrace_dump_on_oops,
2108 .maxlen = sizeof(int),
2109 .mode = 0644,
2110 .proc_handler = proc_dointvec,
2111 },
2112 {
2113 .procname = "traceoff_on_warning",
2114 .data = &__disable_trace_on_warning,
2115 .maxlen = sizeof(__disable_trace_on_warning),
2116 .mode = 0644,
2117 .proc_handler = proc_dointvec,
2118 },
2119 {
2120 .procname = "tracepoint_printk",
2121 .data = &tracepoint_printk,
2122 .maxlen = sizeof(tracepoint_printk),
2123 .mode = 0644,
2124 .proc_handler = tracepoint_printk_sysctl,
2125 },
2126 #endif
2127 #ifdef CONFIG_KEXEC_CORE
2128 {
2129 .procname = "kexec_load_disabled",
2130 .data = &kexec_load_disabled,
2131 .maxlen = sizeof(int),
2132 .mode = 0644,
2133 /* only handle a transition from default "0" to "1" */
2134 .proc_handler = proc_dointvec_minmax,
2135 .extra1 = SYSCTL_ONE,
2136 .extra2 = SYSCTL_ONE,
2137 },
2138 #endif
2139 #ifdef CONFIG_MODULES
2140 {
2141 .procname = "modprobe",
2142 .data = &modprobe_path,
2143 .maxlen = KMOD_PATH_LEN,
2144 .mode = 0644,
2145 .proc_handler = proc_dostring,
2146 },
2147 {
2148 .procname = "modules_disabled",
2149 .data = &modules_disabled,
2150 .maxlen = sizeof(int),
2151 .mode = 0644,
2152 /* only handle a transition from default "0" to "1" */
2153 .proc_handler = proc_dointvec_minmax,
2154 .extra1 = SYSCTL_ONE,
2155 .extra2 = SYSCTL_ONE,
2156 },
2157 #endif
2158 #ifdef CONFIG_UEVENT_HELPER
2159 {
2160 .procname = "hotplug",
2161 .data = &uevent_helper,
2162 .maxlen = UEVENT_HELPER_PATH_LEN,
2163 .mode = 0644,
2164 .proc_handler = proc_dostring,
2165 },
2166 #endif
2167 #ifdef CONFIG_CHR_DEV_SG
2168 {
2169 .procname = "sg-big-buff",
2170 .data = &sg_big_buff,
2171 .maxlen = sizeof (int),
2172 .mode = 0444,
2173 .proc_handler = proc_dointvec,
2174 },
2175 #endif
2176 #ifdef CONFIG_BSD_PROCESS_ACCT
2177 {
2178 .procname = "acct",
2179 .data = &acct_parm,
2180 .maxlen = 3*sizeof(int),
2181 .mode = 0644,
2182 .proc_handler = proc_dointvec,
2183 },
2184 #endif
2185 #ifdef CONFIG_MAGIC_SYSRQ
2186 {
2187 .procname = "sysrq",
2188 .data = NULL,
2189 .maxlen = sizeof (int),
2190 .mode = 0644,
2191 .proc_handler = sysrq_sysctl_handler,
2192 },
2193 #endif
2194 #ifdef CONFIG_PROC_SYSCTL
2195 {
2196 .procname = "cad_pid",
2197 .data = NULL,
2198 .maxlen = sizeof (int),
2199 .mode = 0600,
2200 .proc_handler = proc_do_cad_pid,
2201 },
2202 #endif
2203 {
2204 .procname = "threads-max",
2205 .data = NULL,
2206 .maxlen = sizeof(int),
2207 .mode = 0644,
2208 .proc_handler = sysctl_max_threads,
2209 },
2210 {
2211 .procname = "random",
2212 .mode = 0555,
2213 .child = random_table,
2214 },
2215 {
2216 .procname = "usermodehelper",
2217 .mode = 0555,
2218 .child = usermodehelper_table,
2219 },
2220 #ifdef CONFIG_FW_LOADER_USER_HELPER
2221 {
2222 .procname = "firmware_config",
2223 .mode = 0555,
2224 .child = firmware_config_table,
2225 },
2226 #endif
2227 {
2228 .procname = "overflowuid",
2229 .data = &overflowuid,
2230 .maxlen = sizeof(int),
2231 .mode = 0644,
2232 .proc_handler = proc_dointvec_minmax,
2233 .extra1 = &minolduid,
2234 .extra2 = &maxolduid,
2235 },
2236 {
2237 .procname = "overflowgid",
2238 .data = &overflowgid,
2239 .maxlen = sizeof(int),
2240 .mode = 0644,
2241 .proc_handler = proc_dointvec_minmax,
2242 .extra1 = &minolduid,
2243 .extra2 = &maxolduid,
2244 },
2245 #ifdef CONFIG_S390
2246 {
2247 .procname = "userprocess_debug",
2248 .data = &show_unhandled_signals,
2249 .maxlen = sizeof(int),
2250 .mode = 0644,
2251 .proc_handler = proc_dointvec,
2252 },
2253 #endif
2254 #ifdef CONFIG_SMP
2255 {
2256 .procname = "oops_all_cpu_backtrace",
2257 .data = &sysctl_oops_all_cpu_backtrace,
2258 .maxlen = sizeof(int),
2259 .mode = 0644,
2260 .proc_handler = proc_dointvec_minmax,
2261 .extra1 = SYSCTL_ZERO,
2262 .extra2 = SYSCTL_ONE,
2263 },
2264 #endif /* CONFIG_SMP */
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 = &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 = &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 = &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 = &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 = &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 = &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 = &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 = &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 = &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 = &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 = &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 = &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 = &one_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 = "vfs_cache_pressure",
3034 .data = &sysctl_vfs_cache_pressure,
3035 .maxlen = sizeof(sysctl_vfs_cache_pressure),
3036 .mode = 0644,
3037 .proc_handler = proc_dointvec_minmax,
3038 .extra1 = SYSCTL_ZERO,
3039 },
3040 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
3041 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
3042 {
3043 .procname = "legacy_va_layout",
3044 .data = &sysctl_legacy_va_layout,
3045 .maxlen = sizeof(sysctl_legacy_va_layout),
3046 .mode = 0644,
3047 .proc_handler = proc_dointvec_minmax,
3048 .extra1 = SYSCTL_ZERO,
3049 },
3050 #endif
3051 #ifdef CONFIG_NUMA
3052 {
3053 .procname = "zone_reclaim_mode",
3054 .data = &node_reclaim_mode,
3055 .maxlen = sizeof(node_reclaim_mode),
3056 .mode = 0644,
3057 .proc_handler = proc_dointvec_minmax,
3058 .extra1 = SYSCTL_ZERO,
3059 },
3060 {
3061 .procname = "min_unmapped_ratio",
3062 .data = &sysctl_min_unmapped_ratio,
3063 .maxlen = sizeof(sysctl_min_unmapped_ratio),
3064 .mode = 0644,
3065 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
3066 .extra1 = SYSCTL_ZERO,
3067 .extra2 = &one_hundred,
3068 },
3069 {
3070 .procname = "min_slab_ratio",
3071 .data = &sysctl_min_slab_ratio,
3072 .maxlen = sizeof(sysctl_min_slab_ratio),
3073 .mode = 0644,
3074 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
3075 .extra1 = SYSCTL_ZERO,
3076 .extra2 = &one_hundred,
3077 },
3078 #endif
3079 #ifdef CONFIG_SMP
3080 {
3081 .procname = "stat_interval",
3082 .data = &sysctl_stat_interval,
3083 .maxlen = sizeof(sysctl_stat_interval),
3084 .mode = 0644,
3085 .proc_handler = proc_dointvec_jiffies,
3086 },
3087 {
3088 .procname = "stat_refresh",
3089 .data = NULL,
3090 .maxlen = 0,
3091 .mode = 0600,
3092 .proc_handler = vmstat_refresh,
3093 },
3094 #endif
3095 #ifdef CONFIG_MMU
3096 {
3097 .procname = "mmap_min_addr",
3098 .data = &dac_mmap_min_addr,
3099 .maxlen = sizeof(unsigned long),
3100 .mode = 0644,
3101 .proc_handler = mmap_min_addr_handler,
3102 },
3103 #endif
3104 #ifdef CONFIG_NUMA
3105 {
3106 .procname = "numa_zonelist_order",
3107 .data = &numa_zonelist_order,
3108 .maxlen = NUMA_ZONELIST_ORDER_LEN,
3109 .mode = 0644,
3110 .proc_handler = numa_zonelist_order_handler,
3111 },
3112 #endif
3113 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
3114 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
3115 {
3116 .procname = "vdso_enabled",
3117 #ifdef CONFIG_X86_32
3118 .data = &vdso32_enabled,
3119 .maxlen = sizeof(vdso32_enabled),
3120 #else
3121 .data = &vdso_enabled,
3122 .maxlen = sizeof(vdso_enabled),
3123 #endif
3124 .mode = 0644,
3125 .proc_handler = proc_dointvec,
3126 .extra1 = SYSCTL_ZERO,
3127 },
3128 #endif
3129 #ifdef CONFIG_HIGHMEM
3130 {
3131 .procname = "highmem_is_dirtyable",
3132 .data = &vm_highmem_is_dirtyable,
3133 .maxlen = sizeof(vm_highmem_is_dirtyable),
3134 .mode = 0644,
3135 .proc_handler = proc_dointvec_minmax,
3136 .extra1 = SYSCTL_ZERO,
3137 .extra2 = SYSCTL_ONE,
3138 },
3139 #endif
3140 #ifdef CONFIG_MEMORY_FAILURE
3141 {
3142 .procname = "memory_failure_early_kill",
3143 .data = &sysctl_memory_failure_early_kill,
3144 .maxlen = sizeof(sysctl_memory_failure_early_kill),
3145 .mode = 0644,
3146 .proc_handler = proc_dointvec_minmax,
3147 .extra1 = SYSCTL_ZERO,
3148 .extra2 = SYSCTL_ONE,
3149 },
3150 {
3151 .procname = "memory_failure_recovery",
3152 .data = &sysctl_memory_failure_recovery,
3153 .maxlen = sizeof(sysctl_memory_failure_recovery),
3154 .mode = 0644,
3155 .proc_handler = proc_dointvec_minmax,
3156 .extra1 = SYSCTL_ZERO,
3157 .extra2 = SYSCTL_ONE,
3158 },
3159 #endif
3160 {
3161 .procname = "user_reserve_kbytes",
3162 .data = &sysctl_user_reserve_kbytes,
3163 .maxlen = sizeof(sysctl_user_reserve_kbytes),
3164 .mode = 0644,
3165 .proc_handler = proc_doulongvec_minmax,
3166 },
3167 {
3168 .procname = "admin_reserve_kbytes",
3169 .data = &sysctl_admin_reserve_kbytes,
3170 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
3171 .mode = 0644,
3172 .proc_handler = proc_doulongvec_minmax,
3173 },
3174 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
3175 {
3176 .procname = "mmap_rnd_bits",
3177 .data = &mmap_rnd_bits,
3178 .maxlen = sizeof(mmap_rnd_bits),
3179 .mode = 0600,
3180 .proc_handler = proc_dointvec_minmax,
3181 .extra1 = (void *)&mmap_rnd_bits_min,
3182 .extra2 = (void *)&mmap_rnd_bits_max,
3183 },
3184 #endif
3185 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
3186 {
3187 .procname = "mmap_rnd_compat_bits",
3188 .data = &mmap_rnd_compat_bits,
3189 .maxlen = sizeof(mmap_rnd_compat_bits),
3190 .mode = 0600,
3191 .proc_handler = proc_dointvec_minmax,
3192 .extra1 = (void *)&mmap_rnd_compat_bits_min,
3193 .extra2 = (void *)&mmap_rnd_compat_bits_max,
3194 },
3195 #endif
3196 #ifdef CONFIG_USERFAULTFD
3197 {
3198 .procname = "unprivileged_userfaultfd",
3199 .data = &sysctl_unprivileged_userfaultfd,
3200 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
3201 .mode = 0644,
3202 .proc_handler = proc_dointvec_minmax,
3203 .extra1 = SYSCTL_ZERO,
3204 .extra2 = SYSCTL_ONE,
3205 },
3206 #endif
3207 { }
3208 };
3209
3210 static struct ctl_table fs_table[] = {
3211 {
3212 .procname = "inode-nr",
3213 .data = &inodes_stat,
3214 .maxlen = 2*sizeof(long),
3215 .mode = 0444,
3216 .proc_handler = proc_nr_inodes,
3217 },
3218 {
3219 .procname = "inode-state",
3220 .data = &inodes_stat,
3221 .maxlen = 7*sizeof(long),
3222 .mode = 0444,
3223 .proc_handler = proc_nr_inodes,
3224 },
3225 {
3226 .procname = "file-nr",
3227 .data = &files_stat,
3228 .maxlen = sizeof(files_stat),
3229 .mode = 0444,
3230 .proc_handler = proc_nr_files,
3231 },
3232 {
3233 .procname = "file-max",
3234 .data = &files_stat.max_files,
3235 .maxlen = sizeof(files_stat.max_files),
3236 .mode = 0644,
3237 .proc_handler = proc_doulongvec_minmax,
3238 .extra1 = &zero_ul,
3239 .extra2 = &long_max,
3240 },
3241 {
3242 .procname = "nr_open",
3243 .data = &sysctl_nr_open,
3244 .maxlen = sizeof(unsigned int),
3245 .mode = 0644,
3246 .proc_handler = proc_dointvec_minmax,
3247 .extra1 = &sysctl_nr_open_min,
3248 .extra2 = &sysctl_nr_open_max,
3249 },
3250 {
3251 .procname = "dentry-state",
3252 .data = &dentry_stat,
3253 .maxlen = 6*sizeof(long),
3254 .mode = 0444,
3255 .proc_handler = proc_nr_dentry,
3256 },
3257 {
3258 .procname = "overflowuid",
3259 .data = &fs_overflowuid,
3260 .maxlen = sizeof(int),
3261 .mode = 0644,
3262 .proc_handler = proc_dointvec_minmax,
3263 .extra1 = &minolduid,
3264 .extra2 = &maxolduid,
3265 },
3266 {
3267 .procname = "overflowgid",
3268 .data = &fs_overflowgid,
3269 .maxlen = sizeof(int),
3270 .mode = 0644,
3271 .proc_handler = proc_dointvec_minmax,
3272 .extra1 = &minolduid,
3273 .extra2 = &maxolduid,
3274 },
3275 #ifdef CONFIG_FILE_LOCKING
3276 {
3277 .procname = "leases-enable",
3278 .data = &leases_enable,
3279 .maxlen = sizeof(int),
3280 .mode = 0644,
3281 .proc_handler = proc_dointvec,
3282 },
3283 #endif
3284 #ifdef CONFIG_DNOTIFY
3285 {
3286 .procname = "dir-notify-enable",
3287 .data = &dir_notify_enable,
3288 .maxlen = sizeof(int),
3289 .mode = 0644,
3290 .proc_handler = proc_dointvec,
3291 },
3292 #endif
3293 #ifdef CONFIG_MMU
3294 #ifdef CONFIG_FILE_LOCKING
3295 {
3296 .procname = "lease-break-time",
3297 .data = &lease_break_time,
3298 .maxlen = sizeof(int),
3299 .mode = 0644,
3300 .proc_handler = proc_dointvec,
3301 },
3302 #endif
3303 #ifdef CONFIG_AIO
3304 {
3305 .procname = "aio-nr",
3306 .data = &aio_nr,
3307 .maxlen = sizeof(aio_nr),
3308 .mode = 0444,
3309 .proc_handler = proc_doulongvec_minmax,
3310 },
3311 {
3312 .procname = "aio-max-nr",
3313 .data = &aio_max_nr,
3314 .maxlen = sizeof(aio_max_nr),
3315 .mode = 0644,
3316 .proc_handler = proc_doulongvec_minmax,
3317 },
3318 #endif /* CONFIG_AIO */
3319 #ifdef CONFIG_INOTIFY_USER
3320 {
3321 .procname = "inotify",
3322 .mode = 0555,
3323 .child = inotify_table,
3324 },
3325 #endif
3326 #ifdef CONFIG_EPOLL
3327 {
3328 .procname = "epoll",
3329 .mode = 0555,
3330 .child = epoll_table,
3331 },
3332 #endif
3333 #endif
3334 {
3335 .procname = "protected_symlinks",
3336 .data = &sysctl_protected_symlinks,
3337 .maxlen = sizeof(int),
3338 .mode = 0600,
3339 .proc_handler = proc_dointvec_minmax,
3340 .extra1 = SYSCTL_ZERO,
3341 .extra2 = SYSCTL_ONE,
3342 },
3343 {
3344 .procname = "protected_hardlinks",
3345 .data = &sysctl_protected_hardlinks,
3346 .maxlen = sizeof(int),
3347 .mode = 0600,
3348 .proc_handler = proc_dointvec_minmax,
3349 .extra1 = SYSCTL_ZERO,
3350 .extra2 = SYSCTL_ONE,
3351 },
3352 {
3353 .procname = "protected_fifos",
3354 .data = &sysctl_protected_fifos,
3355 .maxlen = sizeof(int),
3356 .mode = 0600,
3357 .proc_handler = proc_dointvec_minmax,
3358 .extra1 = SYSCTL_ZERO,
3359 .extra2 = &two,
3360 },
3361 {
3362 .procname = "protected_regular",
3363 .data = &sysctl_protected_regular,
3364 .maxlen = sizeof(int),
3365 .mode = 0600,
3366 .proc_handler = proc_dointvec_minmax,
3367 .extra1 = SYSCTL_ZERO,
3368 .extra2 = &two,
3369 },
3370 {
3371 .procname = "suid_dumpable",
3372 .data = &suid_dumpable,
3373 .maxlen = sizeof(int),
3374 .mode = 0644,
3375 .proc_handler = proc_dointvec_minmax_coredump,
3376 .extra1 = SYSCTL_ZERO,
3377 .extra2 = &two,
3378 },
3379 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
3380 {
3381 .procname = "binfmt_misc",
3382 .mode = 0555,
3383 .child = sysctl_mount_point,
3384 },
3385 #endif
3386 {
3387 .procname = "pipe-max-size",
3388 .data = &pipe_max_size,
3389 .maxlen = sizeof(pipe_max_size),
3390 .mode = 0644,
3391 .proc_handler = proc_dopipe_max_size,
3392 },
3393 {
3394 .procname = "pipe-user-pages-hard",
3395 .data = &pipe_user_pages_hard,
3396 .maxlen = sizeof(pipe_user_pages_hard),
3397 .mode = 0644,
3398 .proc_handler = proc_doulongvec_minmax,
3399 },
3400 {
3401 .procname = "pipe-user-pages-soft",
3402 .data = &pipe_user_pages_soft,
3403 .maxlen = sizeof(pipe_user_pages_soft),
3404 .mode = 0644,
3405 .proc_handler = proc_doulongvec_minmax,
3406 },
3407 {
3408 .procname = "mount-max",
3409 .data = &sysctl_mount_max,
3410 .maxlen = sizeof(unsigned int),
3411 .mode = 0644,
3412 .proc_handler = proc_dointvec_minmax,
3413 .extra1 = SYSCTL_ONE,
3414 },
3415 { }
3416 };
3417
3418 static struct ctl_table debug_table[] = {
3419 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
3420 {
3421 .procname = "exception-trace",
3422 .data = &show_unhandled_signals,
3423 .maxlen = sizeof(int),
3424 .mode = 0644,
3425 .proc_handler = proc_dointvec
3426 },
3427 #endif
3428 #if defined(CONFIG_OPTPROBES)
3429 {
3430 .procname = "kprobes-optimization",
3431 .data = &sysctl_kprobes_optimization,
3432 .maxlen = sizeof(int),
3433 .mode = 0644,
3434 .proc_handler = proc_kprobes_optimization_handler,
3435 .extra1 = SYSCTL_ZERO,
3436 .extra2 = SYSCTL_ONE,
3437 },
3438 #endif
3439 { }
3440 };
3441
3442 static struct ctl_table dev_table[] = {
3443 { }
3444 };
3445
3446 static struct ctl_table sysctl_base_table[] = {
3447 {
3448 .procname = "kernel",
3449 .mode = 0555,
3450 .child = kern_table,
3451 },
3452 {
3453 .procname = "vm",
3454 .mode = 0555,
3455 .child = vm_table,
3456 },
3457 {
3458 .procname = "fs",
3459 .mode = 0555,
3460 .child = fs_table,
3461 },
3462 {
3463 .procname = "debug",
3464 .mode = 0555,
3465 .child = debug_table,
3466 },
3467 {
3468 .procname = "dev",
3469 .mode = 0555,
3470 .child = dev_table,
3471 },
3472 { }
3473 };
3474
sysctl_init(void)3475 int __init sysctl_init(void)
3476 {
3477 struct ctl_table_header *hdr;
3478
3479 hdr = register_sysctl_table(sysctl_base_table);
3480 kmemleak_not_leak(hdr);
3481 return 0;
3482 }
3483 #endif /* CONFIG_SYSCTL */
3484 /*
3485 * No sense putting this after each symbol definition, twice,
3486 * exception granted :-)
3487 */
3488 EXPORT_SYMBOL(proc_dointvec);
3489 EXPORT_SYMBOL(proc_douintvec);
3490 EXPORT_SYMBOL(proc_dointvec_jiffies);
3491 EXPORT_SYMBOL(proc_dointvec_minmax);
3492 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3493 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3494 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3495 EXPORT_SYMBOL(proc_dostring);
3496 EXPORT_SYMBOL(proc_doulongvec_minmax);
3497 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3498 EXPORT_SYMBOL(proc_do_large_bitmap);
3499