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