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