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