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