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