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