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