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