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