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