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