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