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