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