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