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