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