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