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