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