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