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