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