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