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