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