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