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