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