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