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