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