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