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 .extra1 = SYSCTL_ONE,
1825 .extra2 = SYSCTL_INT_MAX,
1826 },
1827 {
1828 .procname = "sched_rt_runtime_us",
1829 .data = &sysctl_sched_rt_runtime,
1830 .maxlen = sizeof(int),
1831 .mode = 0644,
1832 .proc_handler = sched_rt_handler,
1833 .extra1 = SYSCTL_NEG_ONE,
1834 .extra2 = SYSCTL_INT_MAX,
1835 },
1836 {
1837 .procname = "sched_deadline_period_max_us",
1838 .data = &sysctl_sched_dl_period_max,
1839 .maxlen = sizeof(unsigned int),
1840 .mode = 0644,
1841 .proc_handler = proc_dointvec,
1842 },
1843 {
1844 .procname = "sched_deadline_period_min_us",
1845 .data = &sysctl_sched_dl_period_min,
1846 .maxlen = sizeof(unsigned int),
1847 .mode = 0644,
1848 .proc_handler = proc_dointvec,
1849 },
1850 {
1851 .procname = "sched_rr_timeslice_ms",
1852 .data = &sysctl_sched_rr_timeslice,
1853 .maxlen = sizeof(int),
1854 .mode = 0644,
1855 .proc_handler = sched_rr_handler,
1856 },
1857 #ifdef CONFIG_SMP
1858 {
1859 .procname = "sched_pelt_multiplier",
1860 .data = &sysctl_sched_pelt_multiplier,
1861 .maxlen = sizeof(unsigned int),
1862 .mode = 0644,
1863 .proc_handler = sched_pelt_multiplier,
1864 },
1865 #endif
1866 #ifdef CONFIG_UCLAMP_TASK
1867 {
1868 .procname = "sched_util_clamp_min",
1869 .data = &sysctl_sched_uclamp_util_min,
1870 .maxlen = sizeof(unsigned int),
1871 .mode = 0644,
1872 .proc_handler = sysctl_sched_uclamp_handler,
1873 },
1874 {
1875 .procname = "sched_util_clamp_max",
1876 .data = &sysctl_sched_uclamp_util_max,
1877 .maxlen = sizeof(unsigned int),
1878 .mode = 0644,
1879 .proc_handler = sysctl_sched_uclamp_handler,
1880 },
1881 {
1882 .procname = "sched_util_clamp_min_rt_default",
1883 .data = &sysctl_sched_uclamp_util_min_rt_default,
1884 .maxlen = sizeof(unsigned int),
1885 .mode = 0644,
1886 .proc_handler = sysctl_sched_uclamp_handler,
1887 },
1888 #endif
1889 #ifdef CONFIG_SCHED_AUTOGROUP
1890 {
1891 .procname = "sched_autogroup_enabled",
1892 .data = &sysctl_sched_autogroup_enabled,
1893 .maxlen = sizeof(unsigned int),
1894 .mode = 0644,
1895 .proc_handler = proc_dointvec_minmax,
1896 .extra1 = SYSCTL_ZERO,
1897 .extra2 = SYSCTL_ONE,
1898 },
1899 #endif
1900 #ifdef CONFIG_CFS_BANDWIDTH
1901 {
1902 .procname = "sched_cfs_bandwidth_slice_us",
1903 .data = &sysctl_sched_cfs_bandwidth_slice,
1904 .maxlen = sizeof(unsigned int),
1905 .mode = 0644,
1906 .proc_handler = proc_dointvec_minmax,
1907 .extra1 = SYSCTL_ONE,
1908 },
1909 #endif
1910 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
1911 {
1912 .procname = "sched_energy_aware",
1913 .data = &sysctl_sched_energy_aware,
1914 .maxlen = sizeof(unsigned int),
1915 .mode = 0644,
1916 .proc_handler = sched_energy_aware_handler,
1917 .extra1 = SYSCTL_ZERO,
1918 .extra2 = SYSCTL_ONE,
1919 },
1920 #endif
1921 #ifdef CONFIG_PROVE_LOCKING
1922 {
1923 .procname = "prove_locking",
1924 .data = &prove_locking,
1925 .maxlen = sizeof(int),
1926 .mode = 0644,
1927 .proc_handler = proc_dointvec,
1928 },
1929 #endif
1930 #ifdef CONFIG_LOCK_STAT
1931 {
1932 .procname = "lock_stat",
1933 .data = &lock_stat,
1934 .maxlen = sizeof(int),
1935 .mode = 0644,
1936 .proc_handler = proc_dointvec,
1937 },
1938 #endif
1939 {
1940 .procname = "panic",
1941 .data = &panic_timeout,
1942 .maxlen = sizeof(int),
1943 .mode = 0644,
1944 .proc_handler = proc_dointvec,
1945 },
1946 #ifdef CONFIG_COREDUMP
1947 {
1948 .procname = "core_uses_pid",
1949 .data = &core_uses_pid,
1950 .maxlen = sizeof(int),
1951 .mode = 0644,
1952 .proc_handler = proc_dointvec,
1953 },
1954 {
1955 .procname = "core_pattern",
1956 .data = core_pattern,
1957 .maxlen = CORENAME_MAX_SIZE,
1958 .mode = 0644,
1959 .proc_handler = proc_dostring_coredump,
1960 },
1961 {
1962 .procname = "core_pipe_limit",
1963 .data = &core_pipe_limit,
1964 .maxlen = sizeof(unsigned int),
1965 .mode = 0644,
1966 .proc_handler = proc_dointvec,
1967 },
1968 #endif
1969 #ifdef CONFIG_PROC_SYSCTL
1970 {
1971 .procname = "tainted",
1972 .maxlen = sizeof(long),
1973 .mode = 0644,
1974 .proc_handler = proc_taint,
1975 },
1976 {
1977 .procname = "sysctl_writes_strict",
1978 .data = &sysctl_writes_strict,
1979 .maxlen = sizeof(int),
1980 .mode = 0644,
1981 .proc_handler = proc_dointvec_minmax,
1982 .extra1 = SYSCTL_NEG_ONE,
1983 .extra2 = SYSCTL_ONE,
1984 },
1985 #endif
1986 #ifdef CONFIG_LATENCYTOP
1987 {
1988 .procname = "latencytop",
1989 .data = &latencytop_enabled,
1990 .maxlen = sizeof(int),
1991 .mode = 0644,
1992 .proc_handler = sysctl_latencytop,
1993 },
1994 #endif
1995 #ifdef CONFIG_BLK_DEV_INITRD
1996 {
1997 .procname = "real-root-dev",
1998 .data = &real_root_dev,
1999 .maxlen = sizeof(int),
2000 .mode = 0644,
2001 .proc_handler = proc_dointvec,
2002 },
2003 #endif
2004 {
2005 .procname = "print-fatal-signals",
2006 .data = &print_fatal_signals,
2007 .maxlen = sizeof(int),
2008 .mode = 0644,
2009 .proc_handler = proc_dointvec,
2010 },
2011 #ifdef CONFIG_SPARC
2012 {
2013 .procname = "reboot-cmd",
2014 .data = reboot_command,
2015 .maxlen = 256,
2016 .mode = 0644,
2017 .proc_handler = proc_dostring,
2018 },
2019 {
2020 .procname = "stop-a",
2021 .data = &stop_a_enabled,
2022 .maxlen = sizeof (int),
2023 .mode = 0644,
2024 .proc_handler = proc_dointvec,
2025 },
2026 {
2027 .procname = "scons-poweroff",
2028 .data = &scons_pwroff,
2029 .maxlen = sizeof (int),
2030 .mode = 0644,
2031 .proc_handler = proc_dointvec,
2032 },
2033 #endif
2034 #ifdef CONFIG_SPARC64
2035 {
2036 .procname = "tsb-ratio",
2037 .data = &sysctl_tsb_ratio,
2038 .maxlen = sizeof (int),
2039 .mode = 0644,
2040 .proc_handler = proc_dointvec,
2041 },
2042 #endif
2043 #ifdef CONFIG_PARISC
2044 {
2045 .procname = "soft-power",
2046 .data = &pwrsw_enabled,
2047 .maxlen = sizeof (int),
2048 .mode = 0644,
2049 .proc_handler = proc_dointvec,
2050 },
2051 #endif
2052 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
2053 {
2054 .procname = "unaligned-trap",
2055 .data = &unaligned_enabled,
2056 .maxlen = sizeof (int),
2057 .mode = 0644,
2058 .proc_handler = proc_dointvec,
2059 },
2060 #endif
2061 {
2062 .procname = "ctrl-alt-del",
2063 .data = &C_A_D,
2064 .maxlen = sizeof(int),
2065 .mode = 0644,
2066 .proc_handler = proc_dointvec,
2067 },
2068 #ifdef CONFIG_FUNCTION_TRACER
2069 {
2070 .procname = "ftrace_enabled",
2071 .data = &ftrace_enabled,
2072 .maxlen = sizeof(int),
2073 .mode = 0644,
2074 .proc_handler = ftrace_enable_sysctl,
2075 },
2076 #endif
2077 #ifdef CONFIG_STACK_TRACER
2078 {
2079 .procname = "stack_tracer_enabled",
2080 .data = &stack_tracer_enabled,
2081 .maxlen = sizeof(int),
2082 .mode = 0644,
2083 .proc_handler = stack_trace_sysctl,
2084 },
2085 #endif
2086 #ifdef CONFIG_TRACING
2087 {
2088 .procname = "ftrace_dump_on_oops",
2089 .data = &ftrace_dump_on_oops,
2090 .maxlen = sizeof(int),
2091 .mode = 0644,
2092 .proc_handler = proc_dointvec,
2093 },
2094 {
2095 .procname = "traceoff_on_warning",
2096 .data = &__disable_trace_on_warning,
2097 .maxlen = sizeof(__disable_trace_on_warning),
2098 .mode = 0644,
2099 .proc_handler = proc_dointvec,
2100 },
2101 {
2102 .procname = "tracepoint_printk",
2103 .data = &tracepoint_printk,
2104 .maxlen = sizeof(tracepoint_printk),
2105 .mode = 0644,
2106 .proc_handler = tracepoint_printk_sysctl,
2107 },
2108 #endif
2109 #ifdef CONFIG_KEXEC_CORE
2110 {
2111 .procname = "kexec_load_disabled",
2112 .data = &kexec_load_disabled,
2113 .maxlen = sizeof(int),
2114 .mode = 0644,
2115 /* only handle a transition from default "0" to "1" */
2116 .proc_handler = proc_dointvec_minmax,
2117 .extra1 = SYSCTL_ONE,
2118 .extra2 = SYSCTL_ONE,
2119 },
2120 #endif
2121 #ifdef CONFIG_MODULES
2122 {
2123 .procname = "modprobe",
2124 .data = &modprobe_path,
2125 .maxlen = KMOD_PATH_LEN,
2126 .mode = 0644,
2127 .proc_handler = proc_dostring,
2128 },
2129 {
2130 .procname = "modules_disabled",
2131 .data = &modules_disabled,
2132 .maxlen = sizeof(int),
2133 .mode = 0644,
2134 /* only handle a transition from default "0" to "1" */
2135 .proc_handler = proc_dointvec_minmax,
2136 .extra1 = SYSCTL_ONE,
2137 .extra2 = SYSCTL_ONE,
2138 },
2139 #endif
2140 #ifdef CONFIG_UEVENT_HELPER
2141 {
2142 .procname = "hotplug",
2143 .data = &uevent_helper,
2144 .maxlen = UEVENT_HELPER_PATH_LEN,
2145 .mode = 0644,
2146 .proc_handler = proc_dostring,
2147 },
2148 #endif
2149 #ifdef CONFIG_CHR_DEV_SG
2150 {
2151 .procname = "sg-big-buff",
2152 .data = &sg_big_buff,
2153 .maxlen = sizeof (int),
2154 .mode = 0444,
2155 .proc_handler = proc_dointvec,
2156 },
2157 #endif
2158 #ifdef CONFIG_BSD_PROCESS_ACCT
2159 {
2160 .procname = "acct",
2161 .data = &acct_parm,
2162 .maxlen = 3*sizeof(int),
2163 .mode = 0644,
2164 .proc_handler = proc_dointvec,
2165 },
2166 #endif
2167 #ifdef CONFIG_MAGIC_SYSRQ
2168 {
2169 .procname = "sysrq",
2170 .data = NULL,
2171 .maxlen = sizeof (int),
2172 .mode = 0644,
2173 .proc_handler = sysrq_sysctl_handler,
2174 },
2175 #endif
2176 #ifdef CONFIG_PROC_SYSCTL
2177 {
2178 .procname = "cad_pid",
2179 .data = NULL,
2180 .maxlen = sizeof (int),
2181 .mode = 0600,
2182 .proc_handler = proc_do_cad_pid,
2183 },
2184 #endif
2185 {
2186 .procname = "threads-max",
2187 .data = NULL,
2188 .maxlen = sizeof(int),
2189 .mode = 0644,
2190 .proc_handler = sysctl_max_threads,
2191 },
2192 {
2193 .procname = "random",
2194 .mode = 0555,
2195 .child = random_table,
2196 },
2197 {
2198 .procname = "usermodehelper",
2199 .mode = 0555,
2200 .child = usermodehelper_table,
2201 },
2202 #ifdef CONFIG_FW_LOADER_USER_HELPER
2203 {
2204 .procname = "firmware_config",
2205 .mode = 0555,
2206 .child = firmware_config_table,
2207 },
2208 #endif
2209 {
2210 .procname = "overflowuid",
2211 .data = &overflowuid,
2212 .maxlen = sizeof(int),
2213 .mode = 0644,
2214 .proc_handler = proc_dointvec_minmax,
2215 .extra1 = &minolduid,
2216 .extra2 = &maxolduid,
2217 },
2218 {
2219 .procname = "overflowgid",
2220 .data = &overflowgid,
2221 .maxlen = sizeof(int),
2222 .mode = 0644,
2223 .proc_handler = proc_dointvec_minmax,
2224 .extra1 = &minolduid,
2225 .extra2 = &maxolduid,
2226 },
2227 #ifdef CONFIG_S390
2228 {
2229 .procname = "userprocess_debug",
2230 .data = &show_unhandled_signals,
2231 .maxlen = sizeof(int),
2232 .mode = 0644,
2233 .proc_handler = proc_dointvec,
2234 },
2235 #endif
2236 {
2237 .procname = "pid_max",
2238 .data = &pid_max,
2239 .maxlen = sizeof (int),
2240 .mode = 0644,
2241 .proc_handler = proc_dointvec_minmax,
2242 .extra1 = &pid_max_min,
2243 .extra2 = &pid_max_max,
2244 },
2245 {
2246 .procname = "panic_on_oops",
2247 .data = &panic_on_oops,
2248 .maxlen = sizeof(int),
2249 .mode = 0644,
2250 .proc_handler = proc_dointvec,
2251 },
2252 {
2253 .procname = "panic_print",
2254 .data = &panic_print,
2255 .maxlen = sizeof(unsigned long),
2256 .mode = 0644,
2257 .proc_handler = proc_doulongvec_minmax,
2258 },
2259 #if defined CONFIG_PRINTK
2260 {
2261 .procname = "printk",
2262 .data = &console_loglevel,
2263 .maxlen = 4*sizeof(int),
2264 .mode = 0644,
2265 .proc_handler = proc_dointvec,
2266 },
2267 {
2268 .procname = "printk_ratelimit",
2269 .data = &printk_ratelimit_state.interval,
2270 .maxlen = sizeof(int),
2271 .mode = 0644,
2272 .proc_handler = proc_dointvec_jiffies,
2273 },
2274 {
2275 .procname = "printk_ratelimit_burst",
2276 .data = &printk_ratelimit_state.burst,
2277 .maxlen = sizeof(int),
2278 .mode = 0644,
2279 .proc_handler = proc_dointvec,
2280 },
2281 {
2282 .procname = "printk_delay",
2283 .data = &printk_delay_msec,
2284 .maxlen = sizeof(int),
2285 .mode = 0644,
2286 .proc_handler = proc_dointvec_minmax,
2287 .extra1 = SYSCTL_ZERO,
2288 .extra2 = &ten_thousand,
2289 },
2290 {
2291 .procname = "printk_devkmsg",
2292 .data = devkmsg_log_str,
2293 .maxlen = DEVKMSG_STR_MAX_SIZE,
2294 .mode = 0644,
2295 .proc_handler = devkmsg_sysctl_set_loglvl,
2296 },
2297 {
2298 .procname = "dmesg_restrict",
2299 .data = &dmesg_restrict,
2300 .maxlen = sizeof(int),
2301 .mode = 0644,
2302 .proc_handler = proc_dointvec_minmax_sysadmin,
2303 .extra1 = SYSCTL_ZERO,
2304 .extra2 = SYSCTL_ONE,
2305 },
2306 {
2307 .procname = "kptr_restrict",
2308 .data = &kptr_restrict,
2309 .maxlen = sizeof(int),
2310 .mode = 0644,
2311 .proc_handler = proc_dointvec_minmax_sysadmin,
2312 .extra1 = SYSCTL_ZERO,
2313 .extra2 = SYSCTL_TWO,
2314 },
2315 #endif
2316 {
2317 .procname = "ngroups_max",
2318 .data = &ngroups_max,
2319 .maxlen = sizeof (int),
2320 .mode = 0444,
2321 .proc_handler = proc_dointvec,
2322 },
2323 {
2324 .procname = "cap_last_cap",
2325 .data = (void *)&cap_last_cap,
2326 .maxlen = sizeof(int),
2327 .mode = 0444,
2328 .proc_handler = proc_dointvec,
2329 },
2330 #if defined(CONFIG_LOCKUP_DETECTOR)
2331 {
2332 .procname = "watchdog",
2333 .data = &watchdog_user_enabled,
2334 .maxlen = sizeof(int),
2335 .mode = 0644,
2336 .proc_handler = proc_watchdog,
2337 .extra1 = SYSCTL_ZERO,
2338 .extra2 = SYSCTL_ONE,
2339 },
2340 {
2341 .procname = "watchdog_thresh",
2342 .data = &watchdog_thresh,
2343 .maxlen = sizeof(int),
2344 .mode = 0644,
2345 .proc_handler = proc_watchdog_thresh,
2346 .extra1 = SYSCTL_ZERO,
2347 .extra2 = &sixty,
2348 },
2349 {
2350 .procname = "nmi_watchdog",
2351 .data = &nmi_watchdog_user_enabled,
2352 .maxlen = sizeof(int),
2353 .mode = NMI_WATCHDOG_SYSCTL_PERM,
2354 .proc_handler = proc_nmi_watchdog,
2355 .extra1 = SYSCTL_ZERO,
2356 .extra2 = SYSCTL_ONE,
2357 },
2358 {
2359 .procname = "watchdog_cpumask",
2360 .data = &watchdog_cpumask_bits,
2361 .maxlen = NR_CPUS,
2362 .mode = 0644,
2363 .proc_handler = proc_watchdog_cpumask,
2364 },
2365 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
2366 {
2367 .procname = "soft_watchdog",
2368 .data = &soft_watchdog_user_enabled,
2369 .maxlen = sizeof(int),
2370 .mode = 0644,
2371 .proc_handler = proc_soft_watchdog,
2372 .extra1 = SYSCTL_ZERO,
2373 .extra2 = SYSCTL_ONE,
2374 },
2375 {
2376 .procname = "softlockup_panic",
2377 .data = &softlockup_panic,
2378 .maxlen = sizeof(int),
2379 .mode = 0644,
2380 .proc_handler = proc_dointvec_minmax,
2381 .extra1 = SYSCTL_ZERO,
2382 .extra2 = SYSCTL_ONE,
2383 },
2384 #ifdef CONFIG_SMP
2385 {
2386 .procname = "softlockup_all_cpu_backtrace",
2387 .data = &sysctl_softlockup_all_cpu_backtrace,
2388 .maxlen = sizeof(int),
2389 .mode = 0644,
2390 .proc_handler = proc_dointvec_minmax,
2391 .extra1 = SYSCTL_ZERO,
2392 .extra2 = SYSCTL_ONE,
2393 },
2394 #endif /* CONFIG_SMP */
2395 #endif
2396 #ifdef CONFIG_HARDLOCKUP_DETECTOR
2397 {
2398 .procname = "hardlockup_panic",
2399 .data = &hardlockup_panic,
2400 .maxlen = sizeof(int),
2401 .mode = 0644,
2402 .proc_handler = proc_dointvec_minmax,
2403 .extra1 = SYSCTL_ZERO,
2404 .extra2 = SYSCTL_ONE,
2405 },
2406 #ifdef CONFIG_SMP
2407 {
2408 .procname = "hardlockup_all_cpu_backtrace",
2409 .data = &sysctl_hardlockup_all_cpu_backtrace,
2410 .maxlen = sizeof(int),
2411 .mode = 0644,
2412 .proc_handler = proc_dointvec_minmax,
2413 .extra1 = SYSCTL_ZERO,
2414 .extra2 = SYSCTL_ONE,
2415 },
2416 #endif /* CONFIG_SMP */
2417 #endif
2418 #endif
2419
2420 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
2421 {
2422 .procname = "unknown_nmi_panic",
2423 .data = &unknown_nmi_panic,
2424 .maxlen = sizeof (int),
2425 .mode = 0644,
2426 .proc_handler = proc_dointvec,
2427 },
2428 #endif
2429
2430 #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \
2431 defined(CONFIG_DEBUG_STACKOVERFLOW)
2432 {
2433 .procname = "panic_on_stackoverflow",
2434 .data = &sysctl_panic_on_stackoverflow,
2435 .maxlen = sizeof(int),
2436 .mode = 0644,
2437 .proc_handler = proc_dointvec,
2438 },
2439 #endif
2440 #if defined(CONFIG_X86)
2441 {
2442 .procname = "panic_on_unrecovered_nmi",
2443 .data = &panic_on_unrecovered_nmi,
2444 .maxlen = sizeof(int),
2445 .mode = 0644,
2446 .proc_handler = proc_dointvec,
2447 },
2448 {
2449 .procname = "panic_on_io_nmi",
2450 .data = &panic_on_io_nmi,
2451 .maxlen = sizeof(int),
2452 .mode = 0644,
2453 .proc_handler = proc_dointvec,
2454 },
2455 {
2456 .procname = "bootloader_type",
2457 .data = &bootloader_type,
2458 .maxlen = sizeof (int),
2459 .mode = 0444,
2460 .proc_handler = proc_dointvec,
2461 },
2462 {
2463 .procname = "bootloader_version",
2464 .data = &bootloader_version,
2465 .maxlen = sizeof (int),
2466 .mode = 0444,
2467 .proc_handler = proc_dointvec,
2468 },
2469 {
2470 .procname = "io_delay_type",
2471 .data = &io_delay_type,
2472 .maxlen = sizeof(int),
2473 .mode = 0644,
2474 .proc_handler = proc_dointvec,
2475 },
2476 #endif
2477 #if defined(CONFIG_MMU)
2478 {
2479 .procname = "randomize_va_space",
2480 .data = &randomize_va_space,
2481 .maxlen = sizeof(int),
2482 .mode = 0644,
2483 .proc_handler = proc_dointvec,
2484 },
2485 #endif
2486 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
2487 {
2488 .procname = "spin_retry",
2489 .data = &spin_retry,
2490 .maxlen = sizeof (int),
2491 .mode = 0644,
2492 .proc_handler = proc_dointvec,
2493 },
2494 #endif
2495 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
2496 {
2497 .procname = "acpi_video_flags",
2498 .data = &acpi_realmode_flags,
2499 .maxlen = sizeof (unsigned long),
2500 .mode = 0644,
2501 .proc_handler = proc_doulongvec_minmax,
2502 },
2503 #endif
2504 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
2505 {
2506 .procname = "ignore-unaligned-usertrap",
2507 .data = &no_unaligned_warning,
2508 .maxlen = sizeof (int),
2509 .mode = 0644,
2510 .proc_handler = proc_dointvec,
2511 },
2512 #endif
2513 #ifdef CONFIG_IA64
2514 {
2515 .procname = "unaligned-dump-stack",
2516 .data = &unaligned_dump_stack,
2517 .maxlen = sizeof (int),
2518 .mode = 0644,
2519 .proc_handler = proc_dointvec,
2520 },
2521 #endif
2522 #ifdef CONFIG_DETECT_HUNG_TASK
2523 #ifdef CONFIG_SMP
2524 {
2525 .procname = "hung_task_all_cpu_backtrace",
2526 .data = &sysctl_hung_task_all_cpu_backtrace,
2527 .maxlen = sizeof(int),
2528 .mode = 0644,
2529 .proc_handler = proc_dointvec_minmax,
2530 .extra1 = SYSCTL_ZERO,
2531 .extra2 = SYSCTL_ONE,
2532 },
2533 #endif /* CONFIG_SMP */
2534 {
2535 .procname = "hung_task_panic",
2536 .data = &sysctl_hung_task_panic,
2537 .maxlen = sizeof(int),
2538 .mode = 0644,
2539 .proc_handler = proc_dointvec_minmax,
2540 .extra1 = SYSCTL_ZERO,
2541 .extra2 = SYSCTL_ONE,
2542 },
2543 {
2544 .procname = "hung_task_check_count",
2545 .data = &sysctl_hung_task_check_count,
2546 .maxlen = sizeof(int),
2547 .mode = 0644,
2548 .proc_handler = proc_dointvec_minmax,
2549 .extra1 = SYSCTL_ZERO,
2550 },
2551 {
2552 .procname = "hung_task_timeout_secs",
2553 .data = &sysctl_hung_task_timeout_secs,
2554 .maxlen = sizeof(unsigned long),
2555 .mode = 0644,
2556 .proc_handler = proc_dohung_task_timeout_secs,
2557 .extra2 = &hung_task_timeout_max,
2558 },
2559 {
2560 .procname = "hung_task_check_interval_secs",
2561 .data = &sysctl_hung_task_check_interval_secs,
2562 .maxlen = sizeof(unsigned long),
2563 .mode = 0644,
2564 .proc_handler = proc_dohung_task_timeout_secs,
2565 .extra2 = &hung_task_timeout_max,
2566 },
2567 {
2568 .procname = "hung_task_warnings",
2569 .data = &sysctl_hung_task_warnings,
2570 .maxlen = sizeof(int),
2571 .mode = 0644,
2572 .proc_handler = proc_dointvec_minmax,
2573 .extra1 = SYSCTL_NEG_ONE,
2574 },
2575 #endif
2576 #ifdef CONFIG_RT_MUTEXES
2577 {
2578 .procname = "max_lock_depth",
2579 .data = &max_lock_depth,
2580 .maxlen = sizeof(int),
2581 .mode = 0644,
2582 .proc_handler = proc_dointvec,
2583 },
2584 #endif
2585 {
2586 .procname = "poweroff_cmd",
2587 .data = &poweroff_cmd,
2588 .maxlen = POWEROFF_CMD_PATH_LEN,
2589 .mode = 0644,
2590 .proc_handler = proc_dostring,
2591 },
2592 #ifdef CONFIG_KEYS
2593 {
2594 .procname = "keys",
2595 .mode = 0555,
2596 .child = key_sysctls,
2597 },
2598 #endif
2599 #ifdef CONFIG_PERF_EVENTS
2600 /*
2601 * User-space scripts rely on the existence of this file
2602 * as a feature check for perf_events being enabled.
2603 *
2604 * So it's an ABI, do not remove!
2605 */
2606 {
2607 .procname = "perf_event_paranoid",
2608 .data = &sysctl_perf_event_paranoid,
2609 .maxlen = sizeof(sysctl_perf_event_paranoid),
2610 .mode = 0644,
2611 .proc_handler = proc_dointvec,
2612 },
2613 {
2614 .procname = "perf_event_mlock_kb",
2615 .data = &sysctl_perf_event_mlock,
2616 .maxlen = sizeof(sysctl_perf_event_mlock),
2617 .mode = 0644,
2618 .proc_handler = proc_dointvec,
2619 },
2620 {
2621 .procname = "perf_event_max_sample_rate",
2622 .data = &sysctl_perf_event_sample_rate,
2623 .maxlen = sizeof(sysctl_perf_event_sample_rate),
2624 .mode = 0644,
2625 .proc_handler = perf_proc_update_handler,
2626 .extra1 = SYSCTL_ONE,
2627 },
2628 {
2629 .procname = "perf_cpu_time_max_percent",
2630 .data = &sysctl_perf_cpu_time_max_percent,
2631 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent),
2632 .mode = 0644,
2633 .proc_handler = perf_cpu_time_max_percent_handler,
2634 .extra1 = SYSCTL_ZERO,
2635 .extra2 = SYSCTL_ONE_HUNDRED,
2636 },
2637 {
2638 .procname = "perf_event_max_stack",
2639 .data = &sysctl_perf_event_max_stack,
2640 .maxlen = sizeof(sysctl_perf_event_max_stack),
2641 .mode = 0644,
2642 .proc_handler = perf_event_max_stack_handler,
2643 .extra1 = SYSCTL_ZERO,
2644 .extra2 = &six_hundred_forty_kb,
2645 },
2646 {
2647 .procname = "perf_event_max_contexts_per_stack",
2648 .data = &sysctl_perf_event_max_contexts_per_stack,
2649 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack),
2650 .mode = 0644,
2651 .proc_handler = perf_event_max_stack_handler,
2652 .extra1 = SYSCTL_ZERO,
2653 .extra2 = SYSCTL_ONE_THOUSAND,
2654 },
2655 #endif
2656 {
2657 .procname = "panic_on_warn",
2658 .data = &panic_on_warn,
2659 .maxlen = sizeof(int),
2660 .mode = 0644,
2661 .proc_handler = proc_dointvec_minmax,
2662 .extra1 = SYSCTL_ZERO,
2663 .extra2 = SYSCTL_ONE,
2664 },
2665 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
2666 {
2667 .procname = "timer_migration",
2668 .data = &sysctl_timer_migration,
2669 .maxlen = sizeof(unsigned int),
2670 .mode = 0644,
2671 .proc_handler = timer_migration_handler,
2672 .extra1 = SYSCTL_ZERO,
2673 .extra2 = SYSCTL_ONE,
2674 },
2675 #endif
2676 #ifdef CONFIG_BPF_SYSCALL
2677 {
2678 .procname = "unprivileged_bpf_disabled",
2679 .data = &sysctl_unprivileged_bpf_disabled,
2680 .maxlen = sizeof(sysctl_unprivileged_bpf_disabled),
2681 .mode = 0644,
2682 .proc_handler = bpf_unpriv_handler,
2683 .extra1 = SYSCTL_ZERO,
2684 .extra2 = SYSCTL_TWO,
2685 },
2686 {
2687 .procname = "bpf_stats_enabled",
2688 .data = &bpf_stats_enabled_key.key,
2689 .maxlen = sizeof(bpf_stats_enabled_key),
2690 .mode = 0644,
2691 .proc_handler = bpf_stats_handler,
2692 },
2693 #endif
2694 #if defined(CONFIG_TREE_RCU)
2695 {
2696 .procname = "panic_on_rcu_stall",
2697 .data = &sysctl_panic_on_rcu_stall,
2698 .maxlen = sizeof(sysctl_panic_on_rcu_stall),
2699 .mode = 0644,
2700 .proc_handler = proc_dointvec_minmax,
2701 .extra1 = SYSCTL_ZERO,
2702 .extra2 = SYSCTL_ONE,
2703 },
2704 #endif
2705 #if defined(CONFIG_TREE_RCU)
2706 {
2707 .procname = "max_rcu_stall_to_panic",
2708 .data = &sysctl_max_rcu_stall_to_panic,
2709 .maxlen = sizeof(sysctl_max_rcu_stall_to_panic),
2710 .mode = 0644,
2711 .proc_handler = proc_dointvec_minmax,
2712 .extra1 = SYSCTL_ONE,
2713 .extra2 = SYSCTL_INT_MAX,
2714 },
2715 #endif
2716 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
2717 {
2718 .procname = "stack_erasing",
2719 .data = NULL,
2720 .maxlen = sizeof(int),
2721 .mode = 0600,
2722 .proc_handler = stack_erasing_sysctl,
2723 .extra1 = SYSCTL_ZERO,
2724 .extra2 = SYSCTL_ONE,
2725 },
2726 #endif
2727 { }
2728 };
2729
2730 static struct ctl_table vm_table[] = {
2731 {
2732 .procname = "overcommit_memory",
2733 .data = &sysctl_overcommit_memory,
2734 .maxlen = sizeof(sysctl_overcommit_memory),
2735 .mode = 0644,
2736 .proc_handler = overcommit_policy_handler,
2737 .extra1 = SYSCTL_ZERO,
2738 .extra2 = SYSCTL_TWO,
2739 },
2740 {
2741 .procname = "panic_on_oom",
2742 .data = &sysctl_panic_on_oom,
2743 .maxlen = sizeof(sysctl_panic_on_oom),
2744 .mode = 0644,
2745 .proc_handler = proc_dointvec_minmax,
2746 .extra1 = SYSCTL_ZERO,
2747 .extra2 = SYSCTL_TWO,
2748 },
2749 {
2750 .procname = "oom_kill_allocating_task",
2751 .data = &sysctl_oom_kill_allocating_task,
2752 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
2753 .mode = 0644,
2754 .proc_handler = proc_dointvec,
2755 },
2756 {
2757 .procname = "oom_dump_tasks",
2758 .data = &sysctl_oom_dump_tasks,
2759 .maxlen = sizeof(sysctl_oom_dump_tasks),
2760 .mode = 0644,
2761 .proc_handler = proc_dointvec,
2762 },
2763 {
2764 .procname = "overcommit_ratio",
2765 .data = &sysctl_overcommit_ratio,
2766 .maxlen = sizeof(sysctl_overcommit_ratio),
2767 .mode = 0644,
2768 .proc_handler = overcommit_ratio_handler,
2769 },
2770 {
2771 .procname = "overcommit_kbytes",
2772 .data = &sysctl_overcommit_kbytes,
2773 .maxlen = sizeof(sysctl_overcommit_kbytes),
2774 .mode = 0644,
2775 .proc_handler = overcommit_kbytes_handler,
2776 },
2777 {
2778 .procname = "page-cluster",
2779 .data = &page_cluster,
2780 .maxlen = sizeof(int),
2781 .mode = 0644,
2782 .proc_handler = proc_dointvec_minmax,
2783 .extra1 = SYSCTL_ZERO,
2784 },
2785 {
2786 .procname = "dirty_background_ratio",
2787 .data = &dirty_background_ratio,
2788 .maxlen = sizeof(dirty_background_ratio),
2789 .mode = 0644,
2790 .proc_handler = dirty_background_ratio_handler,
2791 .extra1 = SYSCTL_ZERO,
2792 .extra2 = SYSCTL_ONE_HUNDRED,
2793 },
2794 {
2795 .procname = "dirty_background_bytes",
2796 .data = &dirty_background_bytes,
2797 .maxlen = sizeof(dirty_background_bytes),
2798 .mode = 0644,
2799 .proc_handler = dirty_background_bytes_handler,
2800 .extra1 = &one_ul,
2801 },
2802 {
2803 .procname = "dirty_ratio",
2804 .data = &vm_dirty_ratio,
2805 .maxlen = sizeof(vm_dirty_ratio),
2806 .mode = 0644,
2807 .proc_handler = dirty_ratio_handler,
2808 .extra1 = SYSCTL_ZERO,
2809 .extra2 = SYSCTL_ONE_HUNDRED,
2810 },
2811 {
2812 .procname = "dirty_bytes",
2813 .data = &vm_dirty_bytes,
2814 .maxlen = sizeof(vm_dirty_bytes),
2815 .mode = 0644,
2816 .proc_handler = dirty_bytes_handler,
2817 .extra1 = &dirty_bytes_min,
2818 },
2819 {
2820 .procname = "dirty_writeback_centisecs",
2821 .data = &dirty_writeback_interval,
2822 .maxlen = sizeof(dirty_writeback_interval),
2823 .mode = 0644,
2824 .proc_handler = dirty_writeback_centisecs_handler,
2825 },
2826 {
2827 .procname = "dirty_expire_centisecs",
2828 .data = &dirty_expire_interval,
2829 .maxlen = sizeof(dirty_expire_interval),
2830 .mode = 0644,
2831 .proc_handler = proc_dointvec_minmax,
2832 .extra1 = SYSCTL_ZERO,
2833 },
2834 {
2835 .procname = "dirtytime_expire_seconds",
2836 .data = &dirtytime_expire_interval,
2837 .maxlen = sizeof(dirtytime_expire_interval),
2838 .mode = 0644,
2839 .proc_handler = dirtytime_interval_handler,
2840 .extra1 = SYSCTL_ZERO,
2841 },
2842 {
2843 .procname = "swappiness",
2844 .data = &vm_swappiness,
2845 .maxlen = sizeof(vm_swappiness),
2846 .mode = 0644,
2847 .proc_handler = proc_dointvec_minmax,
2848 .extra1 = SYSCTL_ZERO,
2849 .extra2 = SYSCTL_TWO_HUNDRED,
2850 },
2851 #ifdef CONFIG_NUMA
2852 {
2853 .procname = "numa_stat",
2854 .data = &sysctl_vm_numa_stat,
2855 .maxlen = sizeof(int),
2856 .mode = 0644,
2857 .proc_handler = sysctl_vm_numa_stat_handler,
2858 .extra1 = SYSCTL_ZERO,
2859 .extra2 = SYSCTL_ONE,
2860 },
2861 #endif
2862 #ifdef CONFIG_HUGETLB_PAGE
2863 {
2864 .procname = "nr_hugepages",
2865 .data = NULL,
2866 .maxlen = sizeof(unsigned long),
2867 .mode = 0644,
2868 .proc_handler = hugetlb_sysctl_handler,
2869 },
2870 #ifdef CONFIG_NUMA
2871 {
2872 .procname = "nr_hugepages_mempolicy",
2873 .data = NULL,
2874 .maxlen = sizeof(unsigned long),
2875 .mode = 0644,
2876 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
2877 },
2878 #endif
2879 {
2880 .procname = "hugetlb_shm_group",
2881 .data = &sysctl_hugetlb_shm_group,
2882 .maxlen = sizeof(gid_t),
2883 .mode = 0644,
2884 .proc_handler = proc_dointvec,
2885 },
2886 {
2887 .procname = "nr_overcommit_hugepages",
2888 .data = NULL,
2889 .maxlen = sizeof(unsigned long),
2890 .mode = 0644,
2891 .proc_handler = hugetlb_overcommit_handler,
2892 },
2893 #endif
2894 {
2895 .procname = "lowmem_reserve_ratio",
2896 .data = &sysctl_lowmem_reserve_ratio,
2897 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
2898 .mode = 0644,
2899 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
2900 },
2901 {
2902 .procname = "drop_caches",
2903 .data = &sysctl_drop_caches,
2904 .maxlen = sizeof(int),
2905 .mode = 0200,
2906 .proc_handler = drop_caches_sysctl_handler,
2907 .extra1 = SYSCTL_ONE,
2908 .extra2 = SYSCTL_FOUR,
2909 },
2910 #ifdef CONFIG_COMPACTION
2911 {
2912 .procname = "compact_memory",
2913 .data = NULL,
2914 .maxlen = sizeof(int),
2915 .mode = 0200,
2916 .proc_handler = sysctl_compaction_handler,
2917 },
2918 {
2919 .procname = "compaction_proactiveness",
2920 .data = &sysctl_compaction_proactiveness,
2921 .maxlen = sizeof(sysctl_compaction_proactiveness),
2922 .mode = 0644,
2923 .proc_handler = compaction_proactiveness_sysctl_handler,
2924 .extra1 = SYSCTL_ZERO,
2925 .extra2 = SYSCTL_ONE_HUNDRED,
2926 },
2927 {
2928 .procname = "extfrag_threshold",
2929 .data = &sysctl_extfrag_threshold,
2930 .maxlen = sizeof(int),
2931 .mode = 0644,
2932 .proc_handler = proc_dointvec_minmax,
2933 .extra1 = &min_extfrag_threshold,
2934 .extra2 = &max_extfrag_threshold,
2935 },
2936 {
2937 .procname = "compact_unevictable_allowed",
2938 .data = &sysctl_compact_unevictable_allowed,
2939 .maxlen = sizeof(int),
2940 .mode = 0644,
2941 .proc_handler = proc_dointvec_minmax_warn_RT_change,
2942 .extra1 = SYSCTL_ZERO,
2943 .extra2 = SYSCTL_ONE,
2944 },
2945
2946 #endif /* CONFIG_COMPACTION */
2947 {
2948 .procname = "min_free_kbytes",
2949 .data = &min_free_kbytes,
2950 .maxlen = sizeof(min_free_kbytes),
2951 .mode = 0644,
2952 .proc_handler = min_free_kbytes_sysctl_handler,
2953 .extra1 = SYSCTL_ZERO,
2954 },
2955 {
2956 .procname = "watermark_boost_factor",
2957 .data = &watermark_boost_factor,
2958 .maxlen = sizeof(watermark_boost_factor),
2959 .mode = 0644,
2960 .proc_handler = proc_dointvec_minmax,
2961 .extra1 = SYSCTL_ZERO,
2962 },
2963 {
2964 .procname = "watermark_scale_factor",
2965 .data = &watermark_scale_factor,
2966 .maxlen = sizeof(watermark_scale_factor),
2967 .mode = 0644,
2968 .proc_handler = watermark_scale_factor_sysctl_handler,
2969 .extra1 = SYSCTL_ONE,
2970 .extra2 = SYSCTL_THREE_THOUSAND,
2971 },
2972 {
2973 .procname = "percpu_pagelist_high_fraction",
2974 .data = &percpu_pagelist_high_fraction,
2975 .maxlen = sizeof(percpu_pagelist_high_fraction),
2976 .mode = 0644,
2977 .proc_handler = percpu_pagelist_high_fraction_sysctl_handler,
2978 .extra1 = SYSCTL_ZERO,
2979 },
2980 {
2981 .procname = "page_lock_unfairness",
2982 .data = &sysctl_page_lock_unfairness,
2983 .maxlen = sizeof(sysctl_page_lock_unfairness),
2984 .mode = 0644,
2985 .proc_handler = proc_dointvec_minmax,
2986 .extra1 = SYSCTL_ZERO,
2987 },
2988 #ifdef CONFIG_MMU
2989 {
2990 .procname = "max_map_count",
2991 .data = &sysctl_max_map_count,
2992 .maxlen = sizeof(sysctl_max_map_count),
2993 .mode = 0644,
2994 .proc_handler = proc_dointvec_minmax,
2995 .extra1 = SYSCTL_ZERO,
2996 },
2997 #else
2998 {
2999 .procname = "nr_trim_pages",
3000 .data = &sysctl_nr_trim_pages,
3001 .maxlen = sizeof(sysctl_nr_trim_pages),
3002 .mode = 0644,
3003 .proc_handler = proc_dointvec_minmax,
3004 .extra1 = SYSCTL_ZERO,
3005 },
3006 #endif
3007 {
3008 .procname = "laptop_mode",
3009 .data = &laptop_mode,
3010 .maxlen = sizeof(laptop_mode),
3011 .mode = 0644,
3012 .proc_handler = proc_dointvec_jiffies,
3013 },
3014 {
3015 .procname = "vfs_cache_pressure",
3016 .data = &sysctl_vfs_cache_pressure,
3017 .maxlen = sizeof(sysctl_vfs_cache_pressure),
3018 .mode = 0644,
3019 .proc_handler = proc_dointvec_minmax,
3020 .extra1 = SYSCTL_ZERO,
3021 },
3022 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
3023 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
3024 {
3025 .procname = "legacy_va_layout",
3026 .data = &sysctl_legacy_va_layout,
3027 .maxlen = sizeof(sysctl_legacy_va_layout),
3028 .mode = 0644,
3029 .proc_handler = proc_dointvec_minmax,
3030 .extra1 = SYSCTL_ZERO,
3031 },
3032 #endif
3033 #ifdef CONFIG_NUMA
3034 {
3035 .procname = "zone_reclaim_mode",
3036 .data = &node_reclaim_mode,
3037 .maxlen = sizeof(node_reclaim_mode),
3038 .mode = 0644,
3039 .proc_handler = proc_dointvec_minmax,
3040 .extra1 = SYSCTL_ZERO,
3041 },
3042 {
3043 .procname = "min_unmapped_ratio",
3044 .data = &sysctl_min_unmapped_ratio,
3045 .maxlen = sizeof(sysctl_min_unmapped_ratio),
3046 .mode = 0644,
3047 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
3048 .extra1 = SYSCTL_ZERO,
3049 .extra2 = SYSCTL_ONE_HUNDRED,
3050 },
3051 {
3052 .procname = "min_slab_ratio",
3053 .data = &sysctl_min_slab_ratio,
3054 .maxlen = sizeof(sysctl_min_slab_ratio),
3055 .mode = 0644,
3056 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
3057 .extra1 = SYSCTL_ZERO,
3058 .extra2 = SYSCTL_ONE_HUNDRED,
3059 },
3060 #endif
3061 #ifdef CONFIG_SMP
3062 {
3063 .procname = "stat_interval",
3064 .data = &sysctl_stat_interval,
3065 .maxlen = sizeof(sysctl_stat_interval),
3066 .mode = 0644,
3067 .proc_handler = proc_dointvec_jiffies,
3068 },
3069 {
3070 .procname = "stat_refresh",
3071 .data = NULL,
3072 .maxlen = 0,
3073 .mode = 0600,
3074 .proc_handler = vmstat_refresh,
3075 },
3076 #endif
3077 #ifdef CONFIG_MMU
3078 {
3079 .procname = "mmap_min_addr",
3080 .data = &dac_mmap_min_addr,
3081 .maxlen = sizeof(unsigned long),
3082 .mode = 0644,
3083 .proc_handler = mmap_min_addr_handler,
3084 },
3085 #endif
3086 #ifdef CONFIG_NUMA
3087 {
3088 .procname = "numa_zonelist_order",
3089 .data = &numa_zonelist_order,
3090 .maxlen = NUMA_ZONELIST_ORDER_LEN,
3091 .mode = 0644,
3092 .proc_handler = numa_zonelist_order_handler,
3093 },
3094 #endif
3095 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
3096 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
3097 {
3098 .procname = "vdso_enabled",
3099 #ifdef CONFIG_X86_32
3100 .data = &vdso32_enabled,
3101 .maxlen = sizeof(vdso32_enabled),
3102 #else
3103 .data = &vdso_enabled,
3104 .maxlen = sizeof(vdso_enabled),
3105 #endif
3106 .mode = 0644,
3107 .proc_handler = proc_dointvec,
3108 .extra1 = SYSCTL_ZERO,
3109 },
3110 #endif
3111 #ifdef CONFIG_HIGHMEM
3112 {
3113 .procname = "highmem_is_dirtyable",
3114 .data = &vm_highmem_is_dirtyable,
3115 .maxlen = sizeof(vm_highmem_is_dirtyable),
3116 .mode = 0644,
3117 .proc_handler = proc_dointvec_minmax,
3118 .extra1 = SYSCTL_ZERO,
3119 .extra2 = SYSCTL_ONE,
3120 },
3121 #endif
3122 #ifdef CONFIG_MEMORY_FAILURE
3123 {
3124 .procname = "memory_failure_early_kill",
3125 .data = &sysctl_memory_failure_early_kill,
3126 .maxlen = sizeof(sysctl_memory_failure_early_kill),
3127 .mode = 0644,
3128 .proc_handler = proc_dointvec_minmax,
3129 .extra1 = SYSCTL_ZERO,
3130 .extra2 = SYSCTL_ONE,
3131 },
3132 {
3133 .procname = "memory_failure_recovery",
3134 .data = &sysctl_memory_failure_recovery,
3135 .maxlen = sizeof(sysctl_memory_failure_recovery),
3136 .mode = 0644,
3137 .proc_handler = proc_dointvec_minmax,
3138 .extra1 = SYSCTL_ZERO,
3139 .extra2 = SYSCTL_ONE,
3140 },
3141 #endif
3142 {
3143 .procname = "user_reserve_kbytes",
3144 .data = &sysctl_user_reserve_kbytes,
3145 .maxlen = sizeof(sysctl_user_reserve_kbytes),
3146 .mode = 0644,
3147 .proc_handler = proc_doulongvec_minmax,
3148 },
3149 {
3150 .procname = "admin_reserve_kbytes",
3151 .data = &sysctl_admin_reserve_kbytes,
3152 .maxlen = sizeof(sysctl_admin_reserve_kbytes),
3153 .mode = 0644,
3154 .proc_handler = proc_doulongvec_minmax,
3155 },
3156 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
3157 {
3158 .procname = "mmap_rnd_bits",
3159 .data = &mmap_rnd_bits,
3160 .maxlen = sizeof(mmap_rnd_bits),
3161 .mode = 0600,
3162 .proc_handler = proc_dointvec_minmax,
3163 .extra1 = (void *)&mmap_rnd_bits_min,
3164 .extra2 = (void *)&mmap_rnd_bits_max,
3165 },
3166 #endif
3167 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
3168 {
3169 .procname = "mmap_rnd_compat_bits",
3170 .data = &mmap_rnd_compat_bits,
3171 .maxlen = sizeof(mmap_rnd_compat_bits),
3172 .mode = 0600,
3173 .proc_handler = proc_dointvec_minmax,
3174 .extra1 = (void *)&mmap_rnd_compat_bits_min,
3175 .extra2 = (void *)&mmap_rnd_compat_bits_max,
3176 },
3177 #endif
3178 #ifdef CONFIG_USERFAULTFD
3179 {
3180 .procname = "unprivileged_userfaultfd",
3181 .data = &sysctl_unprivileged_userfaultfd,
3182 .maxlen = sizeof(sysctl_unprivileged_userfaultfd),
3183 .mode = 0644,
3184 .proc_handler = proc_dointvec_minmax,
3185 .extra1 = SYSCTL_ZERO,
3186 .extra2 = SYSCTL_ONE,
3187 },
3188 #endif
3189 { }
3190 };
3191
3192 static struct ctl_table fs_table[] = {
3193 {
3194 .procname = "inode-nr",
3195 .data = &inodes_stat,
3196 .maxlen = 2*sizeof(long),
3197 .mode = 0444,
3198 .proc_handler = proc_nr_inodes,
3199 },
3200 {
3201 .procname = "inode-state",
3202 .data = &inodes_stat,
3203 .maxlen = 7*sizeof(long),
3204 .mode = 0444,
3205 .proc_handler = proc_nr_inodes,
3206 },
3207 {
3208 .procname = "file-nr",
3209 .data = &files_stat,
3210 .maxlen = sizeof(files_stat),
3211 .mode = 0444,
3212 .proc_handler = proc_nr_files,
3213 },
3214 {
3215 .procname = "file-max",
3216 .data = &files_stat.max_files,
3217 .maxlen = sizeof(files_stat.max_files),
3218 .mode = 0644,
3219 .proc_handler = proc_doulongvec_minmax,
3220 .extra1 = &zero_ul,
3221 .extra2 = &long_max,
3222 },
3223 {
3224 .procname = "nr_open",
3225 .data = &sysctl_nr_open,
3226 .maxlen = sizeof(unsigned int),
3227 .mode = 0644,
3228 .proc_handler = proc_dointvec_minmax,
3229 .extra1 = &sysctl_nr_open_min,
3230 .extra2 = &sysctl_nr_open_max,
3231 },
3232 {
3233 .procname = "dentry-state",
3234 .data = &dentry_stat,
3235 .maxlen = 6*sizeof(long),
3236 .mode = 0444,
3237 .proc_handler = proc_nr_dentry,
3238 },
3239 {
3240 .procname = "overflowuid",
3241 .data = &fs_overflowuid,
3242 .maxlen = sizeof(int),
3243 .mode = 0644,
3244 .proc_handler = proc_dointvec_minmax,
3245 .extra1 = &minolduid,
3246 .extra2 = &maxolduid,
3247 },
3248 {
3249 .procname = "overflowgid",
3250 .data = &fs_overflowgid,
3251 .maxlen = sizeof(int),
3252 .mode = 0644,
3253 .proc_handler = proc_dointvec_minmax,
3254 .extra1 = &minolduid,
3255 .extra2 = &maxolduid,
3256 },
3257 #ifdef CONFIG_FILE_LOCKING
3258 {
3259 .procname = "leases-enable",
3260 .data = &leases_enable,
3261 .maxlen = sizeof(int),
3262 .mode = 0644,
3263 .proc_handler = proc_dointvec,
3264 },
3265 #endif
3266 #ifdef CONFIG_DNOTIFY
3267 {
3268 .procname = "dir-notify-enable",
3269 .data = &dir_notify_enable,
3270 .maxlen = sizeof(int),
3271 .mode = 0644,
3272 .proc_handler = proc_dointvec,
3273 },
3274 #endif
3275 #ifdef CONFIG_MMU
3276 #ifdef CONFIG_FILE_LOCKING
3277 {
3278 .procname = "lease-break-time",
3279 .data = &lease_break_time,
3280 .maxlen = sizeof(int),
3281 .mode = 0644,
3282 .proc_handler = proc_dointvec,
3283 },
3284 #endif
3285 #ifdef CONFIG_AIO
3286 {
3287 .procname = "aio-nr",
3288 .data = &aio_nr,
3289 .maxlen = sizeof(aio_nr),
3290 .mode = 0444,
3291 .proc_handler = proc_doulongvec_minmax,
3292 },
3293 {
3294 .procname = "aio-max-nr",
3295 .data = &aio_max_nr,
3296 .maxlen = sizeof(aio_max_nr),
3297 .mode = 0644,
3298 .proc_handler = proc_doulongvec_minmax,
3299 },
3300 #endif /* CONFIG_AIO */
3301 #ifdef CONFIG_INOTIFY_USER
3302 {
3303 .procname = "inotify",
3304 .mode = 0555,
3305 .child = inotify_table,
3306 },
3307 #endif
3308 #ifdef CONFIG_FANOTIFY
3309 {
3310 .procname = "fanotify",
3311 .mode = 0555,
3312 .child = fanotify_table,
3313 },
3314 #endif
3315 #ifdef CONFIG_EPOLL
3316 {
3317 .procname = "epoll",
3318 .mode = 0555,
3319 .child = epoll_table,
3320 },
3321 #endif
3322 #endif
3323 {
3324 .procname = "protected_symlinks",
3325 .data = &sysctl_protected_symlinks,
3326 .maxlen = sizeof(int),
3327 .mode = 0600,
3328 .proc_handler = proc_dointvec_minmax,
3329 .extra1 = SYSCTL_ZERO,
3330 .extra2 = SYSCTL_ONE,
3331 },
3332 {
3333 .procname = "protected_hardlinks",
3334 .data = &sysctl_protected_hardlinks,
3335 .maxlen = sizeof(int),
3336 .mode = 0600,
3337 .proc_handler = proc_dointvec_minmax,
3338 .extra1 = SYSCTL_ZERO,
3339 .extra2 = SYSCTL_ONE,
3340 },
3341 {
3342 .procname = "protected_fifos",
3343 .data = &sysctl_protected_fifos,
3344 .maxlen = sizeof(int),
3345 .mode = 0600,
3346 .proc_handler = proc_dointvec_minmax,
3347 .extra1 = SYSCTL_ZERO,
3348 .extra2 = SYSCTL_TWO,
3349 },
3350 {
3351 .procname = "protected_regular",
3352 .data = &sysctl_protected_regular,
3353 .maxlen = sizeof(int),
3354 .mode = 0600,
3355 .proc_handler = proc_dointvec_minmax,
3356 .extra1 = SYSCTL_ZERO,
3357 .extra2 = SYSCTL_TWO,
3358 },
3359 {
3360 .procname = "suid_dumpable",
3361 .data = &suid_dumpable,
3362 .maxlen = sizeof(int),
3363 .mode = 0644,
3364 .proc_handler = proc_dointvec_minmax_coredump,
3365 .extra1 = SYSCTL_ZERO,
3366 .extra2 = SYSCTL_TWO,
3367 },
3368 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
3369 {
3370 .procname = "binfmt_misc",
3371 .mode = 0555,
3372 .child = sysctl_mount_point,
3373 },
3374 #endif
3375 {
3376 .procname = "pipe-max-size",
3377 .data = &pipe_max_size,
3378 .maxlen = sizeof(pipe_max_size),
3379 .mode = 0644,
3380 .proc_handler = proc_dopipe_max_size,
3381 },
3382 {
3383 .procname = "pipe-user-pages-hard",
3384 .data = &pipe_user_pages_hard,
3385 .maxlen = sizeof(pipe_user_pages_hard),
3386 .mode = 0644,
3387 .proc_handler = proc_doulongvec_minmax,
3388 },
3389 {
3390 .procname = "pipe-user-pages-soft",
3391 .data = &pipe_user_pages_soft,
3392 .maxlen = sizeof(pipe_user_pages_soft),
3393 .mode = 0644,
3394 .proc_handler = proc_doulongvec_minmax,
3395 },
3396 {
3397 .procname = "mount-max",
3398 .data = &sysctl_mount_max,
3399 .maxlen = sizeof(unsigned int),
3400 .mode = 0644,
3401 .proc_handler = proc_dointvec_minmax,
3402 .extra1 = SYSCTL_ONE,
3403 },
3404 { }
3405 };
3406
3407 static struct ctl_table debug_table[] = {
3408 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
3409 {
3410 .procname = "exception-trace",
3411 .data = &show_unhandled_signals,
3412 .maxlen = sizeof(int),
3413 .mode = 0644,
3414 .proc_handler = proc_dointvec
3415 },
3416 #endif
3417 #if defined(CONFIG_OPTPROBES)
3418 {
3419 .procname = "kprobes-optimization",
3420 .data = &sysctl_kprobes_optimization,
3421 .maxlen = sizeof(int),
3422 .mode = 0644,
3423 .proc_handler = proc_kprobes_optimization_handler,
3424 .extra1 = SYSCTL_ZERO,
3425 .extra2 = SYSCTL_ONE,
3426 },
3427 #endif
3428 { }
3429 };
3430
3431 static struct ctl_table dev_table[] = {
3432 { }
3433 };
3434
3435 static struct ctl_table sysctl_base_table[] = {
3436 {
3437 .procname = "kernel",
3438 .mode = 0555,
3439 .child = kern_table,
3440 },
3441 {
3442 .procname = "vm",
3443 .mode = 0555,
3444 .child = vm_table,
3445 },
3446 {
3447 .procname = "fs",
3448 .mode = 0555,
3449 .child = fs_table,
3450 },
3451 {
3452 .procname = "debug",
3453 .mode = 0555,
3454 .child = debug_table,
3455 },
3456 {
3457 .procname = "dev",
3458 .mode = 0555,
3459 .child = dev_table,
3460 },
3461 { }
3462 };
3463
sysctl_init(void)3464 int __init sysctl_init(void)
3465 {
3466 struct ctl_table_header *hdr;
3467
3468 hdr = register_sysctl_table(sysctl_base_table);
3469 kmemleak_not_leak(hdr);
3470 return 0;
3471 }
3472 #endif /* CONFIG_SYSCTL */
3473 /*
3474 * No sense putting this after each symbol definition, twice,
3475 * exception granted :-)
3476 */
3477 EXPORT_SYMBOL(proc_dobool);
3478 EXPORT_SYMBOL(proc_dointvec);
3479 EXPORT_SYMBOL(proc_douintvec);
3480 EXPORT_SYMBOL(proc_dointvec_jiffies);
3481 EXPORT_SYMBOL(proc_dointvec_minmax);
3482 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3483 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3484 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3485 EXPORT_SYMBOL(proc_dostring);
3486 EXPORT_SYMBOL(proc_doulongvec_minmax);
3487 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3488 EXPORT_SYMBOL(proc_do_large_bitmap);
3489