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