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