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