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