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