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