USB: musb: enable low level DMA operation for Blackfin
[linux-2.6/mini2440.git] / kernel / sysctl.c
blob92f6e5bc3c24f2700b88e31a689f642a83a29a4b
1 /*
2 * sysctl.c: General linux system control interface
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
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>
27 #include <linux/security.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
31 #include <linux/fs.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/initrd.h>
41 #include <linux/key.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/vmstat.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/reboot.h>
50 #include <linux/ftrace.h>
52 #include <asm/uaccess.h>
53 #include <asm/processor.h>
55 #ifdef CONFIG_X86
56 #include <asm/nmi.h>
57 #include <asm/stacktrace.h>
58 #include <asm/io.h>
59 #endif
61 static int deprecated_sysctl_warning(struct __sysctl_args *args);
63 #if defined(CONFIG_SYSCTL)
65 /* External variables not in a header file. */
66 extern int C_A_D;
67 extern int print_fatal_signals;
68 extern int sysctl_overcommit_memory;
69 extern int sysctl_overcommit_ratio;
70 extern int sysctl_panic_on_oom;
71 extern int sysctl_oom_kill_allocating_task;
72 extern int sysctl_oom_dump_tasks;
73 extern int max_threads;
74 extern int core_uses_pid;
75 extern int suid_dumpable;
76 extern char core_pattern[];
77 extern int pid_max;
78 extern int min_free_kbytes;
79 extern int pid_max_min, pid_max_max;
80 extern int sysctl_drop_caches;
81 extern int percpu_pagelist_fraction;
82 extern int compat_log;
83 extern int latencytop_enabled;
84 extern int sysctl_nr_open_min, sysctl_nr_open_max;
85 #ifdef CONFIG_RCU_TORTURE_TEST
86 extern int rcutorture_runnable;
87 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
89 /* Constants used for minimum and maximum */
90 #ifdef CONFIG_DETECT_SOFTLOCKUP
91 static int sixty = 60;
92 static int neg_one = -1;
93 #endif
95 #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
96 static int two = 2;
97 #endif
99 static int zero;
100 static int one = 1;
101 static int one_hundred = 100;
103 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
104 static int maxolduid = 65535;
105 static int minolduid;
106 static int min_percpu_pagelist_fract = 8;
108 static int ngroups_max = NGROUPS_MAX;
110 #ifdef CONFIG_MODULES
111 extern char modprobe_path[];
112 #endif
113 #ifdef CONFIG_CHR_DEV_SG
114 extern int sg_big_buff;
115 #endif
117 #ifdef CONFIG_SPARC
118 #include <asm/system.h>
119 #endif
121 #ifdef CONFIG_SPARC64
122 extern int sysctl_tsb_ratio;
123 #endif
125 #ifdef __hppa__
126 extern int pwrsw_enabled;
127 extern int unaligned_enabled;
128 #endif
130 #ifdef CONFIG_S390
131 #ifdef CONFIG_MATHEMU
132 extern int sysctl_ieee_emulation_warnings;
133 #endif
134 extern int sysctl_userprocess_debug;
135 extern int spin_retry;
136 #endif
138 #ifdef CONFIG_BSD_PROCESS_ACCT
139 extern int acct_parm[];
140 #endif
142 #ifdef CONFIG_IA64
143 extern int no_unaligned_warning;
144 #endif
146 #ifdef CONFIG_RT_MUTEXES
147 extern int max_lock_depth;
148 #endif
150 #ifdef CONFIG_PROC_SYSCTL
151 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
152 void __user *buffer, size_t *lenp, loff_t *ppos);
153 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
154 void __user *buffer, size_t *lenp, loff_t *ppos);
155 #endif
157 static struct ctl_table root_table[];
158 static struct ctl_table_root sysctl_table_root;
159 static struct ctl_table_header root_table_header = {
160 .count = 1,
161 .ctl_table = root_table,
162 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
163 .root = &sysctl_table_root,
164 .set = &sysctl_table_root.default_set,
166 static struct ctl_table_root sysctl_table_root = {
167 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
168 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
171 static struct ctl_table kern_table[];
172 static struct ctl_table vm_table[];
173 static struct ctl_table fs_table[];
174 static struct ctl_table debug_table[];
175 static struct ctl_table dev_table[];
176 extern struct ctl_table random_table[];
177 #ifdef CONFIG_INOTIFY_USER
178 extern struct ctl_table inotify_table[];
179 #endif
180 #ifdef CONFIG_EPOLL
181 extern struct ctl_table epoll_table[];
182 #endif
184 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
185 int sysctl_legacy_va_layout;
186 #endif
188 extern int prove_locking;
189 extern int lock_stat;
191 /* The default sysctl tables: */
193 static struct ctl_table root_table[] = {
195 .ctl_name = CTL_KERN,
196 .procname = "kernel",
197 .mode = 0555,
198 .child = kern_table,
201 .ctl_name = CTL_VM,
202 .procname = "vm",
203 .mode = 0555,
204 .child = vm_table,
207 .ctl_name = CTL_FS,
208 .procname = "fs",
209 .mode = 0555,
210 .child = fs_table,
213 .ctl_name = CTL_DEBUG,
214 .procname = "debug",
215 .mode = 0555,
216 .child = debug_table,
219 .ctl_name = CTL_DEV,
220 .procname = "dev",
221 .mode = 0555,
222 .child = dev_table,
225 * NOTE: do not add new entries to this table unless you have read
226 * Documentation/sysctl/ctl_unnumbered.txt
228 { .ctl_name = 0 }
231 #ifdef CONFIG_SCHED_DEBUG
232 static int min_sched_granularity_ns = 100000; /* 100 usecs */
233 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
234 static int min_wakeup_granularity_ns; /* 0 usecs */
235 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
236 #endif
238 static struct ctl_table kern_table[] = {
239 #ifdef CONFIG_SCHED_DEBUG
241 .ctl_name = CTL_UNNUMBERED,
242 .procname = "sched_min_granularity_ns",
243 .data = &sysctl_sched_min_granularity,
244 .maxlen = sizeof(unsigned int),
245 .mode = 0644,
246 .proc_handler = &sched_nr_latency_handler,
247 .strategy = &sysctl_intvec,
248 .extra1 = &min_sched_granularity_ns,
249 .extra2 = &max_sched_granularity_ns,
252 .ctl_name = CTL_UNNUMBERED,
253 .procname = "sched_latency_ns",
254 .data = &sysctl_sched_latency,
255 .maxlen = sizeof(unsigned int),
256 .mode = 0644,
257 .proc_handler = &sched_nr_latency_handler,
258 .strategy = &sysctl_intvec,
259 .extra1 = &min_sched_granularity_ns,
260 .extra2 = &max_sched_granularity_ns,
263 .ctl_name = CTL_UNNUMBERED,
264 .procname = "sched_wakeup_granularity_ns",
265 .data = &sysctl_sched_wakeup_granularity,
266 .maxlen = sizeof(unsigned int),
267 .mode = 0644,
268 .proc_handler = &proc_dointvec_minmax,
269 .strategy = &sysctl_intvec,
270 .extra1 = &min_wakeup_granularity_ns,
271 .extra2 = &max_wakeup_granularity_ns,
274 .ctl_name = CTL_UNNUMBERED,
275 .procname = "sched_shares_ratelimit",
276 .data = &sysctl_sched_shares_ratelimit,
277 .maxlen = sizeof(unsigned int),
278 .mode = 0644,
279 .proc_handler = &proc_dointvec,
282 .ctl_name = CTL_UNNUMBERED,
283 .procname = "sched_shares_thresh",
284 .data = &sysctl_sched_shares_thresh,
285 .maxlen = sizeof(unsigned int),
286 .mode = 0644,
287 .proc_handler = &proc_dointvec_minmax,
288 .strategy = &sysctl_intvec,
289 .extra1 = &zero,
292 .ctl_name = CTL_UNNUMBERED,
293 .procname = "sched_child_runs_first",
294 .data = &sysctl_sched_child_runs_first,
295 .maxlen = sizeof(unsigned int),
296 .mode = 0644,
297 .proc_handler = &proc_dointvec,
300 .ctl_name = CTL_UNNUMBERED,
301 .procname = "sched_features",
302 .data = &sysctl_sched_features,
303 .maxlen = sizeof(unsigned int),
304 .mode = 0644,
305 .proc_handler = &proc_dointvec,
308 .ctl_name = CTL_UNNUMBERED,
309 .procname = "sched_migration_cost",
310 .data = &sysctl_sched_migration_cost,
311 .maxlen = sizeof(unsigned int),
312 .mode = 0644,
313 .proc_handler = &proc_dointvec,
316 .ctl_name = CTL_UNNUMBERED,
317 .procname = "sched_nr_migrate",
318 .data = &sysctl_sched_nr_migrate,
319 .maxlen = sizeof(unsigned int),
320 .mode = 0644,
321 .proc_handler = &proc_dointvec,
323 #endif
325 .ctl_name = CTL_UNNUMBERED,
326 .procname = "sched_rt_period_us",
327 .data = &sysctl_sched_rt_period,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
330 .proc_handler = &sched_rt_handler,
333 .ctl_name = CTL_UNNUMBERED,
334 .procname = "sched_rt_runtime_us",
335 .data = &sysctl_sched_rt_runtime,
336 .maxlen = sizeof(int),
337 .mode = 0644,
338 .proc_handler = &sched_rt_handler,
341 .ctl_name = CTL_UNNUMBERED,
342 .procname = "sched_compat_yield",
343 .data = &sysctl_sched_compat_yield,
344 .maxlen = sizeof(unsigned int),
345 .mode = 0644,
346 .proc_handler = &proc_dointvec,
348 #ifdef CONFIG_PROVE_LOCKING
350 .ctl_name = CTL_UNNUMBERED,
351 .procname = "prove_locking",
352 .data = &prove_locking,
353 .maxlen = sizeof(int),
354 .mode = 0644,
355 .proc_handler = &proc_dointvec,
357 #endif
358 #ifdef CONFIG_LOCK_STAT
360 .ctl_name = CTL_UNNUMBERED,
361 .procname = "lock_stat",
362 .data = &lock_stat,
363 .maxlen = sizeof(int),
364 .mode = 0644,
365 .proc_handler = &proc_dointvec,
367 #endif
369 .ctl_name = KERN_PANIC,
370 .procname = "panic",
371 .data = &panic_timeout,
372 .maxlen = sizeof(int),
373 .mode = 0644,
374 .proc_handler = &proc_dointvec,
377 .ctl_name = KERN_CORE_USES_PID,
378 .procname = "core_uses_pid",
379 .data = &core_uses_pid,
380 .maxlen = sizeof(int),
381 .mode = 0644,
382 .proc_handler = &proc_dointvec,
385 .ctl_name = KERN_CORE_PATTERN,
386 .procname = "core_pattern",
387 .data = core_pattern,
388 .maxlen = CORENAME_MAX_SIZE,
389 .mode = 0644,
390 .proc_handler = &proc_dostring,
391 .strategy = &sysctl_string,
393 #ifdef CONFIG_PROC_SYSCTL
395 .procname = "tainted",
396 .maxlen = sizeof(long),
397 .mode = 0644,
398 .proc_handler = &proc_taint,
400 #endif
401 #ifdef CONFIG_LATENCYTOP
403 .procname = "latencytop",
404 .data = &latencytop_enabled,
405 .maxlen = sizeof(int),
406 .mode = 0644,
407 .proc_handler = &proc_dointvec,
409 #endif
410 #ifdef CONFIG_BLK_DEV_INITRD
412 .ctl_name = KERN_REALROOTDEV,
413 .procname = "real-root-dev",
414 .data = &real_root_dev,
415 .maxlen = sizeof(int),
416 .mode = 0644,
417 .proc_handler = &proc_dointvec,
419 #endif
421 .ctl_name = CTL_UNNUMBERED,
422 .procname = "print-fatal-signals",
423 .data = &print_fatal_signals,
424 .maxlen = sizeof(int),
425 .mode = 0644,
426 .proc_handler = &proc_dointvec,
428 #ifdef CONFIG_SPARC
430 .ctl_name = KERN_SPARC_REBOOT,
431 .procname = "reboot-cmd",
432 .data = reboot_command,
433 .maxlen = 256,
434 .mode = 0644,
435 .proc_handler = &proc_dostring,
436 .strategy = &sysctl_string,
439 .ctl_name = KERN_SPARC_STOP_A,
440 .procname = "stop-a",
441 .data = &stop_a_enabled,
442 .maxlen = sizeof (int),
443 .mode = 0644,
444 .proc_handler = &proc_dointvec,
447 .ctl_name = KERN_SPARC_SCONS_PWROFF,
448 .procname = "scons-poweroff",
449 .data = &scons_pwroff,
450 .maxlen = sizeof (int),
451 .mode = 0644,
452 .proc_handler = &proc_dointvec,
454 #endif
455 #ifdef CONFIG_SPARC64
457 .ctl_name = CTL_UNNUMBERED,
458 .procname = "tsb-ratio",
459 .data = &sysctl_tsb_ratio,
460 .maxlen = sizeof (int),
461 .mode = 0644,
462 .proc_handler = &proc_dointvec,
464 #endif
465 #ifdef __hppa__
467 .ctl_name = KERN_HPPA_PWRSW,
468 .procname = "soft-power",
469 .data = &pwrsw_enabled,
470 .maxlen = sizeof (int),
471 .mode = 0644,
472 .proc_handler = &proc_dointvec,
475 .ctl_name = KERN_HPPA_UNALIGNED,
476 .procname = "unaligned-trap",
477 .data = &unaligned_enabled,
478 .maxlen = sizeof (int),
479 .mode = 0644,
480 .proc_handler = &proc_dointvec,
482 #endif
484 .ctl_name = KERN_CTLALTDEL,
485 .procname = "ctrl-alt-del",
486 .data = &C_A_D,
487 .maxlen = sizeof(int),
488 .mode = 0644,
489 .proc_handler = &proc_dointvec,
491 #ifdef CONFIG_FUNCTION_TRACER
493 .ctl_name = CTL_UNNUMBERED,
494 .procname = "ftrace_enabled",
495 .data = &ftrace_enabled,
496 .maxlen = sizeof(int),
497 .mode = 0644,
498 .proc_handler = &ftrace_enable_sysctl,
500 #endif
501 #ifdef CONFIG_STACK_TRACER
503 .ctl_name = CTL_UNNUMBERED,
504 .procname = "stack_tracer_enabled",
505 .data = &stack_tracer_enabled,
506 .maxlen = sizeof(int),
507 .mode = 0644,
508 .proc_handler = &stack_trace_sysctl,
510 #endif
511 #ifdef CONFIG_TRACING
513 .ctl_name = CTL_UNNUMBERED,
514 .procname = "ftrace_dump_on_oops",
515 .data = &ftrace_dump_on_oops,
516 .maxlen = sizeof(int),
517 .mode = 0644,
518 .proc_handler = &proc_dointvec,
520 #endif
521 #ifdef CONFIG_MODULES
523 .ctl_name = KERN_MODPROBE,
524 .procname = "modprobe",
525 .data = &modprobe_path,
526 .maxlen = KMOD_PATH_LEN,
527 .mode = 0644,
528 .proc_handler = &proc_dostring,
529 .strategy = &sysctl_string,
531 #endif
532 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
534 .ctl_name = KERN_HOTPLUG,
535 .procname = "hotplug",
536 .data = &uevent_helper,
537 .maxlen = UEVENT_HELPER_PATH_LEN,
538 .mode = 0644,
539 .proc_handler = &proc_dostring,
540 .strategy = &sysctl_string,
542 #endif
543 #ifdef CONFIG_CHR_DEV_SG
545 .ctl_name = KERN_SG_BIG_BUFF,
546 .procname = "sg-big-buff",
547 .data = &sg_big_buff,
548 .maxlen = sizeof (int),
549 .mode = 0444,
550 .proc_handler = &proc_dointvec,
552 #endif
553 #ifdef CONFIG_BSD_PROCESS_ACCT
555 .ctl_name = KERN_ACCT,
556 .procname = "acct",
557 .data = &acct_parm,
558 .maxlen = 3*sizeof(int),
559 .mode = 0644,
560 .proc_handler = &proc_dointvec,
562 #endif
563 #ifdef CONFIG_MAGIC_SYSRQ
565 .ctl_name = KERN_SYSRQ,
566 .procname = "sysrq",
567 .data = &__sysrq_enabled,
568 .maxlen = sizeof (int),
569 .mode = 0644,
570 .proc_handler = &proc_dointvec,
572 #endif
573 #ifdef CONFIG_PROC_SYSCTL
575 .procname = "cad_pid",
576 .data = NULL,
577 .maxlen = sizeof (int),
578 .mode = 0600,
579 .proc_handler = &proc_do_cad_pid,
581 #endif
583 .ctl_name = KERN_MAX_THREADS,
584 .procname = "threads-max",
585 .data = &max_threads,
586 .maxlen = sizeof(int),
587 .mode = 0644,
588 .proc_handler = &proc_dointvec,
591 .ctl_name = KERN_RANDOM,
592 .procname = "random",
593 .mode = 0555,
594 .child = random_table,
597 .ctl_name = KERN_OVERFLOWUID,
598 .procname = "overflowuid",
599 .data = &overflowuid,
600 .maxlen = sizeof(int),
601 .mode = 0644,
602 .proc_handler = &proc_dointvec_minmax,
603 .strategy = &sysctl_intvec,
604 .extra1 = &minolduid,
605 .extra2 = &maxolduid,
608 .ctl_name = KERN_OVERFLOWGID,
609 .procname = "overflowgid",
610 .data = &overflowgid,
611 .maxlen = sizeof(int),
612 .mode = 0644,
613 .proc_handler = &proc_dointvec_minmax,
614 .strategy = &sysctl_intvec,
615 .extra1 = &minolduid,
616 .extra2 = &maxolduid,
618 #ifdef CONFIG_S390
619 #ifdef CONFIG_MATHEMU
621 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
622 .procname = "ieee_emulation_warnings",
623 .data = &sysctl_ieee_emulation_warnings,
624 .maxlen = sizeof(int),
625 .mode = 0644,
626 .proc_handler = &proc_dointvec,
628 #endif
630 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
631 .procname = "userprocess_debug",
632 .data = &sysctl_userprocess_debug,
633 .maxlen = sizeof(int),
634 .mode = 0644,
635 .proc_handler = &proc_dointvec,
637 #endif
639 .ctl_name = KERN_PIDMAX,
640 .procname = "pid_max",
641 .data = &pid_max,
642 .maxlen = sizeof (int),
643 .mode = 0644,
644 .proc_handler = &proc_dointvec_minmax,
645 .strategy = sysctl_intvec,
646 .extra1 = &pid_max_min,
647 .extra2 = &pid_max_max,
650 .ctl_name = KERN_PANIC_ON_OOPS,
651 .procname = "panic_on_oops",
652 .data = &panic_on_oops,
653 .maxlen = sizeof(int),
654 .mode = 0644,
655 .proc_handler = &proc_dointvec,
657 #if defined CONFIG_PRINTK
659 .ctl_name = KERN_PRINTK,
660 .procname = "printk",
661 .data = &console_loglevel,
662 .maxlen = 4*sizeof(int),
663 .mode = 0644,
664 .proc_handler = &proc_dointvec,
667 .ctl_name = KERN_PRINTK_RATELIMIT,
668 .procname = "printk_ratelimit",
669 .data = &printk_ratelimit_state.interval,
670 .maxlen = sizeof(int),
671 .mode = 0644,
672 .proc_handler = &proc_dointvec_jiffies,
673 .strategy = &sysctl_jiffies,
676 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
677 .procname = "printk_ratelimit_burst",
678 .data = &printk_ratelimit_state.burst,
679 .maxlen = sizeof(int),
680 .mode = 0644,
681 .proc_handler = &proc_dointvec,
683 #endif
685 .ctl_name = KERN_NGROUPS_MAX,
686 .procname = "ngroups_max",
687 .data = &ngroups_max,
688 .maxlen = sizeof (int),
689 .mode = 0444,
690 .proc_handler = &proc_dointvec,
692 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
694 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
695 .procname = "unknown_nmi_panic",
696 .data = &unknown_nmi_panic,
697 .maxlen = sizeof (int),
698 .mode = 0644,
699 .proc_handler = &proc_dointvec,
702 .procname = "nmi_watchdog",
703 .data = &nmi_watchdog_enabled,
704 .maxlen = sizeof (int),
705 .mode = 0644,
706 .proc_handler = &proc_nmi_enabled,
708 #endif
709 #if defined(CONFIG_X86)
711 .ctl_name = KERN_PANIC_ON_NMI,
712 .procname = "panic_on_unrecovered_nmi",
713 .data = &panic_on_unrecovered_nmi,
714 .maxlen = sizeof(int),
715 .mode = 0644,
716 .proc_handler = &proc_dointvec,
719 .ctl_name = KERN_BOOTLOADER_TYPE,
720 .procname = "bootloader_type",
721 .data = &bootloader_type,
722 .maxlen = sizeof (int),
723 .mode = 0444,
724 .proc_handler = &proc_dointvec,
727 .ctl_name = CTL_UNNUMBERED,
728 .procname = "kstack_depth_to_print",
729 .data = &kstack_depth_to_print,
730 .maxlen = sizeof(int),
731 .mode = 0644,
732 .proc_handler = &proc_dointvec,
735 .ctl_name = CTL_UNNUMBERED,
736 .procname = "io_delay_type",
737 .data = &io_delay_type,
738 .maxlen = sizeof(int),
739 .mode = 0644,
740 .proc_handler = &proc_dointvec,
742 #endif
743 #if defined(CONFIG_MMU)
745 .ctl_name = KERN_RANDOMIZE,
746 .procname = "randomize_va_space",
747 .data = &randomize_va_space,
748 .maxlen = sizeof(int),
749 .mode = 0644,
750 .proc_handler = &proc_dointvec,
752 #endif
753 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
755 .ctl_name = KERN_SPIN_RETRY,
756 .procname = "spin_retry",
757 .data = &spin_retry,
758 .maxlen = sizeof (int),
759 .mode = 0644,
760 .proc_handler = &proc_dointvec,
762 #endif
763 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
765 .procname = "acpi_video_flags",
766 .data = &acpi_realmode_flags,
767 .maxlen = sizeof (unsigned long),
768 .mode = 0644,
769 .proc_handler = &proc_doulongvec_minmax,
771 #endif
772 #ifdef CONFIG_IA64
774 .ctl_name = KERN_IA64_UNALIGNED,
775 .procname = "ignore-unaligned-usertrap",
776 .data = &no_unaligned_warning,
777 .maxlen = sizeof (int),
778 .mode = 0644,
779 .proc_handler = &proc_dointvec,
781 #endif
782 #ifdef CONFIG_DETECT_SOFTLOCKUP
784 .ctl_name = CTL_UNNUMBERED,
785 .procname = "softlockup_panic",
786 .data = &softlockup_panic,
787 .maxlen = sizeof(int),
788 .mode = 0644,
789 .proc_handler = &proc_dointvec_minmax,
790 .strategy = &sysctl_intvec,
791 .extra1 = &zero,
792 .extra2 = &one,
795 .ctl_name = CTL_UNNUMBERED,
796 .procname = "softlockup_thresh",
797 .data = &softlockup_thresh,
798 .maxlen = sizeof(int),
799 .mode = 0644,
800 .proc_handler = &proc_dointvec_minmax,
801 .strategy = &sysctl_intvec,
802 .extra1 = &neg_one,
803 .extra2 = &sixty,
806 .ctl_name = CTL_UNNUMBERED,
807 .procname = "hung_task_check_count",
808 .data = &sysctl_hung_task_check_count,
809 .maxlen = sizeof(unsigned long),
810 .mode = 0644,
811 .proc_handler = &proc_doulongvec_minmax,
812 .strategy = &sysctl_intvec,
815 .ctl_name = CTL_UNNUMBERED,
816 .procname = "hung_task_timeout_secs",
817 .data = &sysctl_hung_task_timeout_secs,
818 .maxlen = sizeof(unsigned long),
819 .mode = 0644,
820 .proc_handler = &proc_doulongvec_minmax,
821 .strategy = &sysctl_intvec,
824 .ctl_name = CTL_UNNUMBERED,
825 .procname = "hung_task_warnings",
826 .data = &sysctl_hung_task_warnings,
827 .maxlen = sizeof(unsigned long),
828 .mode = 0644,
829 .proc_handler = &proc_doulongvec_minmax,
830 .strategy = &sysctl_intvec,
832 #endif
833 #ifdef CONFIG_COMPAT
835 .ctl_name = KERN_COMPAT_LOG,
836 .procname = "compat-log",
837 .data = &compat_log,
838 .maxlen = sizeof (int),
839 .mode = 0644,
840 .proc_handler = &proc_dointvec,
842 #endif
843 #ifdef CONFIG_RT_MUTEXES
845 .ctl_name = KERN_MAX_LOCK_DEPTH,
846 .procname = "max_lock_depth",
847 .data = &max_lock_depth,
848 .maxlen = sizeof(int),
849 .mode = 0644,
850 .proc_handler = &proc_dointvec,
852 #endif
854 .ctl_name = CTL_UNNUMBERED,
855 .procname = "poweroff_cmd",
856 .data = &poweroff_cmd,
857 .maxlen = POWEROFF_CMD_PATH_LEN,
858 .mode = 0644,
859 .proc_handler = &proc_dostring,
860 .strategy = &sysctl_string,
862 #ifdef CONFIG_KEYS
864 .ctl_name = CTL_UNNUMBERED,
865 .procname = "keys",
866 .mode = 0555,
867 .child = key_sysctls,
869 #endif
870 #ifdef CONFIG_RCU_TORTURE_TEST
872 .ctl_name = CTL_UNNUMBERED,
873 .procname = "rcutorture_runnable",
874 .data = &rcutorture_runnable,
875 .maxlen = sizeof(int),
876 .mode = 0644,
877 .proc_handler = &proc_dointvec,
879 #endif
880 #ifdef CONFIG_UNEVICTABLE_LRU
882 .ctl_name = CTL_UNNUMBERED,
883 .procname = "scan_unevictable_pages",
884 .data = &scan_unevictable_pages,
885 .maxlen = sizeof(scan_unevictable_pages),
886 .mode = 0644,
887 .proc_handler = &scan_unevictable_handler,
889 #endif
891 * NOTE: do not add new entries to this table unless you have read
892 * Documentation/sysctl/ctl_unnumbered.txt
894 { .ctl_name = 0 }
897 static struct ctl_table vm_table[] = {
899 .ctl_name = VM_OVERCOMMIT_MEMORY,
900 .procname = "overcommit_memory",
901 .data = &sysctl_overcommit_memory,
902 .maxlen = sizeof(sysctl_overcommit_memory),
903 .mode = 0644,
904 .proc_handler = &proc_dointvec,
907 .ctl_name = VM_PANIC_ON_OOM,
908 .procname = "panic_on_oom",
909 .data = &sysctl_panic_on_oom,
910 .maxlen = sizeof(sysctl_panic_on_oom),
911 .mode = 0644,
912 .proc_handler = &proc_dointvec,
915 .ctl_name = CTL_UNNUMBERED,
916 .procname = "oom_kill_allocating_task",
917 .data = &sysctl_oom_kill_allocating_task,
918 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
919 .mode = 0644,
920 .proc_handler = &proc_dointvec,
923 .ctl_name = CTL_UNNUMBERED,
924 .procname = "oom_dump_tasks",
925 .data = &sysctl_oom_dump_tasks,
926 .maxlen = sizeof(sysctl_oom_dump_tasks),
927 .mode = 0644,
928 .proc_handler = &proc_dointvec,
931 .ctl_name = VM_OVERCOMMIT_RATIO,
932 .procname = "overcommit_ratio",
933 .data = &sysctl_overcommit_ratio,
934 .maxlen = sizeof(sysctl_overcommit_ratio),
935 .mode = 0644,
936 .proc_handler = &proc_dointvec,
939 .ctl_name = VM_PAGE_CLUSTER,
940 .procname = "page-cluster",
941 .data = &page_cluster,
942 .maxlen = sizeof(int),
943 .mode = 0644,
944 .proc_handler = &proc_dointvec,
947 .ctl_name = VM_DIRTY_BACKGROUND,
948 .procname = "dirty_background_ratio",
949 .data = &dirty_background_ratio,
950 .maxlen = sizeof(dirty_background_ratio),
951 .mode = 0644,
952 .proc_handler = &dirty_background_ratio_handler,
953 .strategy = &sysctl_intvec,
954 .extra1 = &zero,
955 .extra2 = &one_hundred,
958 .ctl_name = CTL_UNNUMBERED,
959 .procname = "dirty_background_bytes",
960 .data = &dirty_background_bytes,
961 .maxlen = sizeof(dirty_background_bytes),
962 .mode = 0644,
963 .proc_handler = &dirty_background_bytes_handler,
964 .strategy = &sysctl_intvec,
965 .extra1 = &one,
968 .ctl_name = VM_DIRTY_RATIO,
969 .procname = "dirty_ratio",
970 .data = &vm_dirty_ratio,
971 .maxlen = sizeof(vm_dirty_ratio),
972 .mode = 0644,
973 .proc_handler = &dirty_ratio_handler,
974 .strategy = &sysctl_intvec,
975 .extra1 = &zero,
976 .extra2 = &one_hundred,
979 .ctl_name = CTL_UNNUMBERED,
980 .procname = "dirty_bytes",
981 .data = &vm_dirty_bytes,
982 .maxlen = sizeof(vm_dirty_bytes),
983 .mode = 0644,
984 .proc_handler = &dirty_bytes_handler,
985 .strategy = &sysctl_intvec,
986 .extra1 = &one,
989 .procname = "dirty_writeback_centisecs",
990 .data = &dirty_writeback_interval,
991 .maxlen = sizeof(dirty_writeback_interval),
992 .mode = 0644,
993 .proc_handler = &dirty_writeback_centisecs_handler,
996 .procname = "dirty_expire_centisecs",
997 .data = &dirty_expire_interval,
998 .maxlen = sizeof(dirty_expire_interval),
999 .mode = 0644,
1000 .proc_handler = &proc_dointvec_userhz_jiffies,
1003 .ctl_name = VM_NR_PDFLUSH_THREADS,
1004 .procname = "nr_pdflush_threads",
1005 .data = &nr_pdflush_threads,
1006 .maxlen = sizeof nr_pdflush_threads,
1007 .mode = 0444 /* read-only*/,
1008 .proc_handler = &proc_dointvec,
1011 .ctl_name = VM_SWAPPINESS,
1012 .procname = "swappiness",
1013 .data = &vm_swappiness,
1014 .maxlen = sizeof(vm_swappiness),
1015 .mode = 0644,
1016 .proc_handler = &proc_dointvec_minmax,
1017 .strategy = &sysctl_intvec,
1018 .extra1 = &zero,
1019 .extra2 = &one_hundred,
1021 #ifdef CONFIG_HUGETLB_PAGE
1023 .procname = "nr_hugepages",
1024 .data = NULL,
1025 .maxlen = sizeof(unsigned long),
1026 .mode = 0644,
1027 .proc_handler = &hugetlb_sysctl_handler,
1028 .extra1 = (void *)&hugetlb_zero,
1029 .extra2 = (void *)&hugetlb_infinity,
1032 .ctl_name = VM_HUGETLB_GROUP,
1033 .procname = "hugetlb_shm_group",
1034 .data = &sysctl_hugetlb_shm_group,
1035 .maxlen = sizeof(gid_t),
1036 .mode = 0644,
1037 .proc_handler = &proc_dointvec,
1040 .ctl_name = CTL_UNNUMBERED,
1041 .procname = "hugepages_treat_as_movable",
1042 .data = &hugepages_treat_as_movable,
1043 .maxlen = sizeof(int),
1044 .mode = 0644,
1045 .proc_handler = &hugetlb_treat_movable_handler,
1048 .ctl_name = CTL_UNNUMBERED,
1049 .procname = "nr_overcommit_hugepages",
1050 .data = NULL,
1051 .maxlen = sizeof(unsigned long),
1052 .mode = 0644,
1053 .proc_handler = &hugetlb_overcommit_handler,
1054 .extra1 = (void *)&hugetlb_zero,
1055 .extra2 = (void *)&hugetlb_infinity,
1057 #endif
1059 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1060 .procname = "lowmem_reserve_ratio",
1061 .data = &sysctl_lowmem_reserve_ratio,
1062 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1063 .mode = 0644,
1064 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1065 .strategy = &sysctl_intvec,
1068 .ctl_name = VM_DROP_PAGECACHE,
1069 .procname = "drop_caches",
1070 .data = &sysctl_drop_caches,
1071 .maxlen = sizeof(int),
1072 .mode = 0644,
1073 .proc_handler = drop_caches_sysctl_handler,
1074 .strategy = &sysctl_intvec,
1077 .ctl_name = VM_MIN_FREE_KBYTES,
1078 .procname = "min_free_kbytes",
1079 .data = &min_free_kbytes,
1080 .maxlen = sizeof(min_free_kbytes),
1081 .mode = 0644,
1082 .proc_handler = &min_free_kbytes_sysctl_handler,
1083 .strategy = &sysctl_intvec,
1084 .extra1 = &zero,
1087 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1088 .procname = "percpu_pagelist_fraction",
1089 .data = &percpu_pagelist_fraction,
1090 .maxlen = sizeof(percpu_pagelist_fraction),
1091 .mode = 0644,
1092 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1093 .strategy = &sysctl_intvec,
1094 .extra1 = &min_percpu_pagelist_fract,
1096 #ifdef CONFIG_MMU
1098 .ctl_name = VM_MAX_MAP_COUNT,
1099 .procname = "max_map_count",
1100 .data = &sysctl_max_map_count,
1101 .maxlen = sizeof(sysctl_max_map_count),
1102 .mode = 0644,
1103 .proc_handler = &proc_dointvec
1105 #endif
1107 .ctl_name = VM_LAPTOP_MODE,
1108 .procname = "laptop_mode",
1109 .data = &laptop_mode,
1110 .maxlen = sizeof(laptop_mode),
1111 .mode = 0644,
1112 .proc_handler = &proc_dointvec_jiffies,
1113 .strategy = &sysctl_jiffies,
1116 .ctl_name = VM_BLOCK_DUMP,
1117 .procname = "block_dump",
1118 .data = &block_dump,
1119 .maxlen = sizeof(block_dump),
1120 .mode = 0644,
1121 .proc_handler = &proc_dointvec,
1122 .strategy = &sysctl_intvec,
1123 .extra1 = &zero,
1126 .ctl_name = VM_VFS_CACHE_PRESSURE,
1127 .procname = "vfs_cache_pressure",
1128 .data = &sysctl_vfs_cache_pressure,
1129 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1130 .mode = 0644,
1131 .proc_handler = &proc_dointvec,
1132 .strategy = &sysctl_intvec,
1133 .extra1 = &zero,
1135 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1137 .ctl_name = VM_LEGACY_VA_LAYOUT,
1138 .procname = "legacy_va_layout",
1139 .data = &sysctl_legacy_va_layout,
1140 .maxlen = sizeof(sysctl_legacy_va_layout),
1141 .mode = 0644,
1142 .proc_handler = &proc_dointvec,
1143 .strategy = &sysctl_intvec,
1144 .extra1 = &zero,
1146 #endif
1147 #ifdef CONFIG_NUMA
1149 .ctl_name = VM_ZONE_RECLAIM_MODE,
1150 .procname = "zone_reclaim_mode",
1151 .data = &zone_reclaim_mode,
1152 .maxlen = sizeof(zone_reclaim_mode),
1153 .mode = 0644,
1154 .proc_handler = &proc_dointvec,
1155 .strategy = &sysctl_intvec,
1156 .extra1 = &zero,
1159 .ctl_name = VM_MIN_UNMAPPED,
1160 .procname = "min_unmapped_ratio",
1161 .data = &sysctl_min_unmapped_ratio,
1162 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1163 .mode = 0644,
1164 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1165 .strategy = &sysctl_intvec,
1166 .extra1 = &zero,
1167 .extra2 = &one_hundred,
1170 .ctl_name = VM_MIN_SLAB,
1171 .procname = "min_slab_ratio",
1172 .data = &sysctl_min_slab_ratio,
1173 .maxlen = sizeof(sysctl_min_slab_ratio),
1174 .mode = 0644,
1175 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1176 .strategy = &sysctl_intvec,
1177 .extra1 = &zero,
1178 .extra2 = &one_hundred,
1180 #endif
1181 #ifdef CONFIG_SMP
1183 .ctl_name = CTL_UNNUMBERED,
1184 .procname = "stat_interval",
1185 .data = &sysctl_stat_interval,
1186 .maxlen = sizeof(sysctl_stat_interval),
1187 .mode = 0644,
1188 .proc_handler = &proc_dointvec_jiffies,
1189 .strategy = &sysctl_jiffies,
1191 #endif
1192 #ifdef CONFIG_SECURITY
1194 .ctl_name = CTL_UNNUMBERED,
1195 .procname = "mmap_min_addr",
1196 .data = &mmap_min_addr,
1197 .maxlen = sizeof(unsigned long),
1198 .mode = 0644,
1199 .proc_handler = &proc_doulongvec_minmax,
1201 #endif
1202 #ifdef CONFIG_NUMA
1204 .ctl_name = CTL_UNNUMBERED,
1205 .procname = "numa_zonelist_order",
1206 .data = &numa_zonelist_order,
1207 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1208 .mode = 0644,
1209 .proc_handler = &numa_zonelist_order_handler,
1210 .strategy = &sysctl_string,
1212 #endif
1213 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1214 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1216 .ctl_name = VM_VDSO_ENABLED,
1217 .procname = "vdso_enabled",
1218 .data = &vdso_enabled,
1219 .maxlen = sizeof(vdso_enabled),
1220 .mode = 0644,
1221 .proc_handler = &proc_dointvec,
1222 .strategy = &sysctl_intvec,
1223 .extra1 = &zero,
1225 #endif
1226 #ifdef CONFIG_HIGHMEM
1228 .ctl_name = CTL_UNNUMBERED,
1229 .procname = "highmem_is_dirtyable",
1230 .data = &vm_highmem_is_dirtyable,
1231 .maxlen = sizeof(vm_highmem_is_dirtyable),
1232 .mode = 0644,
1233 .proc_handler = &proc_dointvec_minmax,
1234 .strategy = &sysctl_intvec,
1235 .extra1 = &zero,
1236 .extra2 = &one,
1238 #endif
1240 * NOTE: do not add new entries to this table unless you have read
1241 * Documentation/sysctl/ctl_unnumbered.txt
1243 { .ctl_name = 0 }
1246 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1247 static struct ctl_table binfmt_misc_table[] = {
1248 { .ctl_name = 0 }
1250 #endif
1252 static struct ctl_table fs_table[] = {
1254 .ctl_name = FS_NRINODE,
1255 .procname = "inode-nr",
1256 .data = &inodes_stat,
1257 .maxlen = 2*sizeof(int),
1258 .mode = 0444,
1259 .proc_handler = &proc_dointvec,
1262 .ctl_name = FS_STATINODE,
1263 .procname = "inode-state",
1264 .data = &inodes_stat,
1265 .maxlen = 7*sizeof(int),
1266 .mode = 0444,
1267 .proc_handler = &proc_dointvec,
1270 .procname = "file-nr",
1271 .data = &files_stat,
1272 .maxlen = 3*sizeof(int),
1273 .mode = 0444,
1274 .proc_handler = &proc_nr_files,
1277 .ctl_name = FS_MAXFILE,
1278 .procname = "file-max",
1279 .data = &files_stat.max_files,
1280 .maxlen = sizeof(int),
1281 .mode = 0644,
1282 .proc_handler = &proc_dointvec,
1285 .ctl_name = CTL_UNNUMBERED,
1286 .procname = "nr_open",
1287 .data = &sysctl_nr_open,
1288 .maxlen = sizeof(int),
1289 .mode = 0644,
1290 .proc_handler = &proc_dointvec_minmax,
1291 .extra1 = &sysctl_nr_open_min,
1292 .extra2 = &sysctl_nr_open_max,
1295 .ctl_name = FS_DENTRY,
1296 .procname = "dentry-state",
1297 .data = &dentry_stat,
1298 .maxlen = 6*sizeof(int),
1299 .mode = 0444,
1300 .proc_handler = &proc_dointvec,
1303 .ctl_name = FS_OVERFLOWUID,
1304 .procname = "overflowuid",
1305 .data = &fs_overflowuid,
1306 .maxlen = sizeof(int),
1307 .mode = 0644,
1308 .proc_handler = &proc_dointvec_minmax,
1309 .strategy = &sysctl_intvec,
1310 .extra1 = &minolduid,
1311 .extra2 = &maxolduid,
1314 .ctl_name = FS_OVERFLOWGID,
1315 .procname = "overflowgid",
1316 .data = &fs_overflowgid,
1317 .maxlen = sizeof(int),
1318 .mode = 0644,
1319 .proc_handler = &proc_dointvec_minmax,
1320 .strategy = &sysctl_intvec,
1321 .extra1 = &minolduid,
1322 .extra2 = &maxolduid,
1324 #ifdef CONFIG_FILE_LOCKING
1326 .ctl_name = FS_LEASES,
1327 .procname = "leases-enable",
1328 .data = &leases_enable,
1329 .maxlen = sizeof(int),
1330 .mode = 0644,
1331 .proc_handler = &proc_dointvec,
1333 #endif
1334 #ifdef CONFIG_DNOTIFY
1336 .ctl_name = FS_DIR_NOTIFY,
1337 .procname = "dir-notify-enable",
1338 .data = &dir_notify_enable,
1339 .maxlen = sizeof(int),
1340 .mode = 0644,
1341 .proc_handler = &proc_dointvec,
1343 #endif
1344 #ifdef CONFIG_MMU
1345 #ifdef CONFIG_FILE_LOCKING
1347 .ctl_name = FS_LEASE_TIME,
1348 .procname = "lease-break-time",
1349 .data = &lease_break_time,
1350 .maxlen = sizeof(int),
1351 .mode = 0644,
1352 .proc_handler = &proc_dointvec_minmax,
1353 .strategy = &sysctl_intvec,
1354 .extra1 = &zero,
1355 .extra2 = &two,
1357 #endif
1358 #ifdef CONFIG_AIO
1360 .procname = "aio-nr",
1361 .data = &aio_nr,
1362 .maxlen = sizeof(aio_nr),
1363 .mode = 0444,
1364 .proc_handler = &proc_doulongvec_minmax,
1367 .procname = "aio-max-nr",
1368 .data = &aio_max_nr,
1369 .maxlen = sizeof(aio_max_nr),
1370 .mode = 0644,
1371 .proc_handler = &proc_doulongvec_minmax,
1373 #endif /* CONFIG_AIO */
1374 #ifdef CONFIG_INOTIFY_USER
1376 .ctl_name = FS_INOTIFY,
1377 .procname = "inotify",
1378 .mode = 0555,
1379 .child = inotify_table,
1381 #endif
1382 #ifdef CONFIG_EPOLL
1384 .procname = "epoll",
1385 .mode = 0555,
1386 .child = epoll_table,
1388 #endif
1389 #endif
1391 .ctl_name = KERN_SETUID_DUMPABLE,
1392 .procname = "suid_dumpable",
1393 .data = &suid_dumpable,
1394 .maxlen = sizeof(int),
1395 .mode = 0644,
1396 .proc_handler = &proc_dointvec,
1398 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1400 .ctl_name = CTL_UNNUMBERED,
1401 .procname = "binfmt_misc",
1402 .mode = 0555,
1403 .child = binfmt_misc_table,
1405 #endif
1407 * NOTE: do not add new entries to this table unless you have read
1408 * Documentation/sysctl/ctl_unnumbered.txt
1410 { .ctl_name = 0 }
1413 static struct ctl_table debug_table[] = {
1414 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1416 .ctl_name = CTL_UNNUMBERED,
1417 .procname = "exception-trace",
1418 .data = &show_unhandled_signals,
1419 .maxlen = sizeof(int),
1420 .mode = 0644,
1421 .proc_handler = proc_dointvec
1423 #endif
1424 { .ctl_name = 0 }
1427 static struct ctl_table dev_table[] = {
1428 { .ctl_name = 0 }
1431 static DEFINE_SPINLOCK(sysctl_lock);
1433 /* called under sysctl_lock */
1434 static int use_table(struct ctl_table_header *p)
1436 if (unlikely(p->unregistering))
1437 return 0;
1438 p->used++;
1439 return 1;
1442 /* called under sysctl_lock */
1443 static void unuse_table(struct ctl_table_header *p)
1445 if (!--p->used)
1446 if (unlikely(p->unregistering))
1447 complete(p->unregistering);
1450 /* called under sysctl_lock, will reacquire if has to wait */
1451 static void start_unregistering(struct ctl_table_header *p)
1454 * if p->used is 0, nobody will ever touch that entry again;
1455 * we'll eliminate all paths to it before dropping sysctl_lock
1457 if (unlikely(p->used)) {
1458 struct completion wait;
1459 init_completion(&wait);
1460 p->unregistering = &wait;
1461 spin_unlock(&sysctl_lock);
1462 wait_for_completion(&wait);
1463 spin_lock(&sysctl_lock);
1464 } else {
1465 /* anything non-NULL; we'll never dereference it */
1466 p->unregistering = ERR_PTR(-EINVAL);
1469 * do not remove from the list until nobody holds it; walking the
1470 * list in do_sysctl() relies on that.
1472 list_del_init(&p->ctl_entry);
1475 void sysctl_head_get(struct ctl_table_header *head)
1477 spin_lock(&sysctl_lock);
1478 head->count++;
1479 spin_unlock(&sysctl_lock);
1482 void sysctl_head_put(struct ctl_table_header *head)
1484 spin_lock(&sysctl_lock);
1485 if (!--head->count)
1486 kfree(head);
1487 spin_unlock(&sysctl_lock);
1490 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1492 if (!head)
1493 BUG();
1494 spin_lock(&sysctl_lock);
1495 if (!use_table(head))
1496 head = ERR_PTR(-ENOENT);
1497 spin_unlock(&sysctl_lock);
1498 return head;
1501 void sysctl_head_finish(struct ctl_table_header *head)
1503 if (!head)
1504 return;
1505 spin_lock(&sysctl_lock);
1506 unuse_table(head);
1507 spin_unlock(&sysctl_lock);
1510 static struct ctl_table_set *
1511 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1513 struct ctl_table_set *set = &root->default_set;
1514 if (root->lookup)
1515 set = root->lookup(root, namespaces);
1516 return set;
1519 static struct list_head *
1520 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1522 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1523 return &set->list;
1526 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1527 struct ctl_table_header *prev)
1529 struct ctl_table_root *root;
1530 struct list_head *header_list;
1531 struct ctl_table_header *head;
1532 struct list_head *tmp;
1534 spin_lock(&sysctl_lock);
1535 if (prev) {
1536 head = prev;
1537 tmp = &prev->ctl_entry;
1538 unuse_table(prev);
1539 goto next;
1541 tmp = &root_table_header.ctl_entry;
1542 for (;;) {
1543 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1545 if (!use_table(head))
1546 goto next;
1547 spin_unlock(&sysctl_lock);
1548 return head;
1549 next:
1550 root = head->root;
1551 tmp = tmp->next;
1552 header_list = lookup_header_list(root, namespaces);
1553 if (tmp != header_list)
1554 continue;
1556 do {
1557 root = list_entry(root->root_list.next,
1558 struct ctl_table_root, root_list);
1559 if (root == &sysctl_table_root)
1560 goto out;
1561 header_list = lookup_header_list(root, namespaces);
1562 } while (list_empty(header_list));
1563 tmp = header_list->next;
1565 out:
1566 spin_unlock(&sysctl_lock);
1567 return NULL;
1570 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1572 return __sysctl_head_next(current->nsproxy, prev);
1575 void register_sysctl_root(struct ctl_table_root *root)
1577 spin_lock(&sysctl_lock);
1578 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1579 spin_unlock(&sysctl_lock);
1582 #ifdef CONFIG_SYSCTL_SYSCALL
1583 /* Perform the actual read/write of a sysctl table entry. */
1584 static int do_sysctl_strategy(struct ctl_table_root *root,
1585 struct ctl_table *table,
1586 void __user *oldval, size_t __user *oldlenp,
1587 void __user *newval, size_t newlen)
1589 int op = 0, rc;
1591 if (oldval)
1592 op |= MAY_READ;
1593 if (newval)
1594 op |= MAY_WRITE;
1595 if (sysctl_perm(root, table, op))
1596 return -EPERM;
1598 if (table->strategy) {
1599 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1600 if (rc < 0)
1601 return rc;
1602 if (rc > 0)
1603 return 0;
1606 /* If there is no strategy routine, or if the strategy returns
1607 * zero, proceed with automatic r/w */
1608 if (table->data && table->maxlen) {
1609 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1610 if (rc < 0)
1611 return rc;
1613 return 0;
1616 static int parse_table(int __user *name, int nlen,
1617 void __user *oldval, size_t __user *oldlenp,
1618 void __user *newval, size_t newlen,
1619 struct ctl_table_root *root,
1620 struct ctl_table *table)
1622 int n;
1623 repeat:
1624 if (!nlen)
1625 return -ENOTDIR;
1626 if (get_user(n, name))
1627 return -EFAULT;
1628 for ( ; table->ctl_name || table->procname; table++) {
1629 if (!table->ctl_name)
1630 continue;
1631 if (n == table->ctl_name) {
1632 int error;
1633 if (table->child) {
1634 if (sysctl_perm(root, table, MAY_EXEC))
1635 return -EPERM;
1636 name++;
1637 nlen--;
1638 table = table->child;
1639 goto repeat;
1641 error = do_sysctl_strategy(root, table,
1642 oldval, oldlenp,
1643 newval, newlen);
1644 return error;
1647 return -ENOTDIR;
1650 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1651 void __user *newval, size_t newlen)
1653 struct ctl_table_header *head;
1654 int error = -ENOTDIR;
1656 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1657 return -ENOTDIR;
1658 if (oldval) {
1659 int old_len;
1660 if (!oldlenp || get_user(old_len, oldlenp))
1661 return -EFAULT;
1664 for (head = sysctl_head_next(NULL); head;
1665 head = sysctl_head_next(head)) {
1666 error = parse_table(name, nlen, oldval, oldlenp,
1667 newval, newlen,
1668 head->root, head->ctl_table);
1669 if (error != -ENOTDIR) {
1670 sysctl_head_finish(head);
1671 break;
1674 return error;
1677 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1679 struct __sysctl_args tmp;
1680 int error;
1682 if (copy_from_user(&tmp, args, sizeof(tmp)))
1683 return -EFAULT;
1685 error = deprecated_sysctl_warning(&tmp);
1686 if (error)
1687 goto out;
1689 lock_kernel();
1690 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1691 tmp.newval, tmp.newlen);
1692 unlock_kernel();
1693 out:
1694 return error;
1696 #endif /* CONFIG_SYSCTL_SYSCALL */
1699 * sysctl_perm does NOT grant the superuser all rights automatically, because
1700 * some sysctl variables are readonly even to root.
1703 static int test_perm(int mode, int op)
1705 if (!current_euid())
1706 mode >>= 6;
1707 else if (in_egroup_p(0))
1708 mode >>= 3;
1709 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1710 return 0;
1711 return -EACCES;
1714 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1716 int error;
1717 int mode;
1719 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1720 if (error)
1721 return error;
1723 if (root->permissions)
1724 mode = root->permissions(root, current->nsproxy, table);
1725 else
1726 mode = table->mode;
1728 return test_perm(mode, op);
1731 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1733 for (; table->ctl_name || table->procname; table++) {
1734 table->parent = parent;
1735 if (table->child)
1736 sysctl_set_parent(table, table->child);
1740 static __init int sysctl_init(void)
1742 sysctl_set_parent(NULL, root_table);
1743 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1745 int err;
1746 err = sysctl_check_table(current->nsproxy, root_table);
1748 #endif
1749 return 0;
1752 core_initcall(sysctl_init);
1754 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1755 struct ctl_table *table)
1757 struct ctl_table *p;
1758 const char *s = branch->procname;
1760 /* branch should have named subdirectory as its first element */
1761 if (!s || !branch->child)
1762 return NULL;
1764 /* ... and nothing else */
1765 if (branch[1].procname || branch[1].ctl_name)
1766 return NULL;
1768 /* table should contain subdirectory with the same name */
1769 for (p = table; p->procname || p->ctl_name; p++) {
1770 if (!p->child)
1771 continue;
1772 if (p->procname && strcmp(p->procname, s) == 0)
1773 return p;
1775 return NULL;
1778 /* see if attaching q to p would be an improvement */
1779 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1781 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1782 struct ctl_table *next;
1783 int is_better = 0;
1784 int not_in_parent = !p->attached_by;
1786 while ((next = is_branch_in(by, to)) != NULL) {
1787 if (by == q->attached_by)
1788 is_better = 1;
1789 if (to == p->attached_by)
1790 not_in_parent = 1;
1791 by = by->child;
1792 to = next->child;
1795 if (is_better && not_in_parent) {
1796 q->attached_by = by;
1797 q->attached_to = to;
1798 q->parent = p;
1803 * __register_sysctl_paths - register a sysctl hierarchy
1804 * @root: List of sysctl headers to register on
1805 * @namespaces: Data to compute which lists of sysctl entries are visible
1806 * @path: The path to the directory the sysctl table is in.
1807 * @table: the top-level table structure
1809 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1810 * array. A completely 0 filled entry terminates the table.
1812 * The members of the &struct ctl_table structure are used as follows:
1814 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1815 * must be unique within that level of sysctl
1817 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1818 * enter a sysctl file
1820 * data - a pointer to data for use by proc_handler
1822 * maxlen - the maximum size in bytes of the data
1824 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1826 * child - a pointer to the child sysctl table if this entry is a directory, or
1827 * %NULL.
1829 * proc_handler - the text handler routine (described below)
1831 * strategy - the strategy routine (described below)
1833 * de - for internal use by the sysctl routines
1835 * extra1, extra2 - extra pointers usable by the proc handler routines
1837 * Leaf nodes in the sysctl tree will be represented by a single file
1838 * under /proc; non-leaf nodes will be represented by directories.
1840 * sysctl(2) can automatically manage read and write requests through
1841 * the sysctl table. The data and maxlen fields of the ctl_table
1842 * struct enable minimal validation of the values being written to be
1843 * performed, and the mode field allows minimal authentication.
1845 * More sophisticated management can be enabled by the provision of a
1846 * strategy routine with the table entry. This will be called before
1847 * any automatic read or write of the data is performed.
1849 * The strategy routine may return
1851 * < 0 - Error occurred (error is passed to user process)
1853 * 0 - OK - proceed with automatic read or write.
1855 * > 0 - OK - read or write has been done by the strategy routine, so
1856 * return immediately.
1858 * There must be a proc_handler routine for any terminal nodes
1859 * mirrored under /proc/sys (non-terminals are handled by a built-in
1860 * directory handler). Several default handlers are available to
1861 * cover common cases -
1863 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1864 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1865 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1867 * It is the handler's job to read the input buffer from user memory
1868 * and process it. The handler should return 0 on success.
1870 * This routine returns %NULL on a failure to register, and a pointer
1871 * to the table header on success.
1873 struct ctl_table_header *__register_sysctl_paths(
1874 struct ctl_table_root *root,
1875 struct nsproxy *namespaces,
1876 const struct ctl_path *path, struct ctl_table *table)
1878 struct ctl_table_header *header;
1879 struct ctl_table *new, **prevp;
1880 unsigned int n, npath;
1881 struct ctl_table_set *set;
1883 /* Count the path components */
1884 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1888 * For each path component, allocate a 2-element ctl_table array.
1889 * The first array element will be filled with the sysctl entry
1890 * for this, the second will be the sentinel (ctl_name == 0).
1892 * We allocate everything in one go so that we don't have to
1893 * worry about freeing additional memory in unregister_sysctl_table.
1895 header = kzalloc(sizeof(struct ctl_table_header) +
1896 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1897 if (!header)
1898 return NULL;
1900 new = (struct ctl_table *) (header + 1);
1902 /* Now connect the dots */
1903 prevp = &header->ctl_table;
1904 for (n = 0; n < npath; ++n, ++path) {
1905 /* Copy the procname */
1906 new->procname = path->procname;
1907 new->ctl_name = path->ctl_name;
1908 new->mode = 0555;
1910 *prevp = new;
1911 prevp = &new->child;
1913 new += 2;
1915 *prevp = table;
1916 header->ctl_table_arg = table;
1918 INIT_LIST_HEAD(&header->ctl_entry);
1919 header->used = 0;
1920 header->unregistering = NULL;
1921 header->root = root;
1922 sysctl_set_parent(NULL, header->ctl_table);
1923 header->count = 1;
1924 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1925 if (sysctl_check_table(namespaces, header->ctl_table)) {
1926 kfree(header);
1927 return NULL;
1929 #endif
1930 spin_lock(&sysctl_lock);
1931 header->set = lookup_header_set(root, namespaces);
1932 header->attached_by = header->ctl_table;
1933 header->attached_to = root_table;
1934 header->parent = &root_table_header;
1935 for (set = header->set; set; set = set->parent) {
1936 struct ctl_table_header *p;
1937 list_for_each_entry(p, &set->list, ctl_entry) {
1938 if (p->unregistering)
1939 continue;
1940 try_attach(p, header);
1943 header->parent->count++;
1944 list_add_tail(&header->ctl_entry, &header->set->list);
1945 spin_unlock(&sysctl_lock);
1947 return header;
1951 * register_sysctl_table_path - register a sysctl table hierarchy
1952 * @path: The path to the directory the sysctl table is in.
1953 * @table: the top-level table structure
1955 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1956 * array. A completely 0 filled entry terminates the table.
1958 * See __register_sysctl_paths for more details.
1960 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1961 struct ctl_table *table)
1963 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1964 path, table);
1968 * register_sysctl_table - register a sysctl table hierarchy
1969 * @table: the top-level table structure
1971 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1972 * array. A completely 0 filled entry terminates the table.
1974 * See register_sysctl_paths for more details.
1976 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1978 static const struct ctl_path null_path[] = { {} };
1980 return register_sysctl_paths(null_path, table);
1984 * unregister_sysctl_table - unregister a sysctl table hierarchy
1985 * @header: the header returned from register_sysctl_table
1987 * Unregisters the sysctl table and all children. proc entries may not
1988 * actually be removed until they are no longer used by anyone.
1990 void unregister_sysctl_table(struct ctl_table_header * header)
1992 might_sleep();
1994 if (header == NULL)
1995 return;
1997 spin_lock(&sysctl_lock);
1998 start_unregistering(header);
1999 if (!--header->parent->count) {
2000 WARN_ON(1);
2001 kfree(header->parent);
2003 if (!--header->count)
2004 kfree(header);
2005 spin_unlock(&sysctl_lock);
2008 int sysctl_is_seen(struct ctl_table_header *p)
2010 struct ctl_table_set *set = p->set;
2011 int res;
2012 spin_lock(&sysctl_lock);
2013 if (p->unregistering)
2014 res = 0;
2015 else if (!set->is_seen)
2016 res = 1;
2017 else
2018 res = set->is_seen(set);
2019 spin_unlock(&sysctl_lock);
2020 return res;
2023 void setup_sysctl_set(struct ctl_table_set *p,
2024 struct ctl_table_set *parent,
2025 int (*is_seen)(struct ctl_table_set *))
2027 INIT_LIST_HEAD(&p->list);
2028 p->parent = parent ? parent : &sysctl_table_root.default_set;
2029 p->is_seen = is_seen;
2032 #else /* !CONFIG_SYSCTL */
2033 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2035 return NULL;
2038 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2039 struct ctl_table *table)
2041 return NULL;
2044 void unregister_sysctl_table(struct ctl_table_header * table)
2048 void setup_sysctl_set(struct ctl_table_set *p,
2049 struct ctl_table_set *parent,
2050 int (*is_seen)(struct ctl_table_set *))
2054 void sysctl_head_put(struct ctl_table_header *head)
2058 #endif /* CONFIG_SYSCTL */
2061 * /proc/sys support
2064 #ifdef CONFIG_PROC_SYSCTL
2066 static int _proc_do_string(void* data, int maxlen, int write,
2067 struct file *filp, void __user *buffer,
2068 size_t *lenp, loff_t *ppos)
2070 size_t len;
2071 char __user *p;
2072 char c;
2074 if (!data || !maxlen || !*lenp) {
2075 *lenp = 0;
2076 return 0;
2079 if (write) {
2080 len = 0;
2081 p = buffer;
2082 while (len < *lenp) {
2083 if (get_user(c, p++))
2084 return -EFAULT;
2085 if (c == 0 || c == '\n')
2086 break;
2087 len++;
2089 if (len >= maxlen)
2090 len = maxlen-1;
2091 if(copy_from_user(data, buffer, len))
2092 return -EFAULT;
2093 ((char *) data)[len] = 0;
2094 *ppos += *lenp;
2095 } else {
2096 len = strlen(data);
2097 if (len > maxlen)
2098 len = maxlen;
2100 if (*ppos > len) {
2101 *lenp = 0;
2102 return 0;
2105 data += *ppos;
2106 len -= *ppos;
2108 if (len > *lenp)
2109 len = *lenp;
2110 if (len)
2111 if(copy_to_user(buffer, data, len))
2112 return -EFAULT;
2113 if (len < *lenp) {
2114 if(put_user('\n', ((char __user *) buffer) + len))
2115 return -EFAULT;
2116 len++;
2118 *lenp = len;
2119 *ppos += len;
2121 return 0;
2125 * proc_dostring - read a string sysctl
2126 * @table: the sysctl table
2127 * @write: %TRUE if this is a write to the sysctl file
2128 * @filp: the file structure
2129 * @buffer: the user buffer
2130 * @lenp: the size of the user buffer
2131 * @ppos: file position
2133 * Reads/writes a string from/to the user buffer. If the kernel
2134 * buffer provided is not large enough to hold the string, the
2135 * string is truncated. The copied string is %NULL-terminated.
2136 * If the string is being read by the user process, it is copied
2137 * and a newline '\n' is added. It is truncated if the buffer is
2138 * not large enough.
2140 * Returns 0 on success.
2142 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2143 void __user *buffer, size_t *lenp, loff_t *ppos)
2145 return _proc_do_string(table->data, table->maxlen, write, filp,
2146 buffer, lenp, ppos);
2150 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2151 int *valp,
2152 int write, void *data)
2154 if (write) {
2155 *valp = *negp ? -*lvalp : *lvalp;
2156 } else {
2157 int val = *valp;
2158 if (val < 0) {
2159 *negp = -1;
2160 *lvalp = (unsigned long)-val;
2161 } else {
2162 *negp = 0;
2163 *lvalp = (unsigned long)val;
2166 return 0;
2169 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2170 int write, struct file *filp, void __user *buffer,
2171 size_t *lenp, loff_t *ppos,
2172 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2173 int write, void *data),
2174 void *data)
2176 #define TMPBUFLEN 21
2177 int *i, vleft, first=1, neg, val;
2178 unsigned long lval;
2179 size_t left, len;
2181 char buf[TMPBUFLEN], *p;
2182 char __user *s = buffer;
2184 if (!tbl_data || !table->maxlen || !*lenp ||
2185 (*ppos && !write)) {
2186 *lenp = 0;
2187 return 0;
2190 i = (int *) tbl_data;
2191 vleft = table->maxlen / sizeof(*i);
2192 left = *lenp;
2194 if (!conv)
2195 conv = do_proc_dointvec_conv;
2197 for (; left && vleft--; i++, first=0) {
2198 if (write) {
2199 while (left) {
2200 char c;
2201 if (get_user(c, s))
2202 return -EFAULT;
2203 if (!isspace(c))
2204 break;
2205 left--;
2206 s++;
2208 if (!left)
2209 break;
2210 neg = 0;
2211 len = left;
2212 if (len > sizeof(buf) - 1)
2213 len = sizeof(buf) - 1;
2214 if (copy_from_user(buf, s, len))
2215 return -EFAULT;
2216 buf[len] = 0;
2217 p = buf;
2218 if (*p == '-' && left > 1) {
2219 neg = 1;
2220 p++;
2222 if (*p < '0' || *p > '9')
2223 break;
2225 lval = simple_strtoul(p, &p, 0);
2227 len = p-buf;
2228 if ((len < left) && *p && !isspace(*p))
2229 break;
2230 if (neg)
2231 val = -val;
2232 s += len;
2233 left -= len;
2235 if (conv(&neg, &lval, i, 1, data))
2236 break;
2237 } else {
2238 p = buf;
2239 if (!first)
2240 *p++ = '\t';
2242 if (conv(&neg, &lval, i, 0, data))
2243 break;
2245 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2246 len = strlen(buf);
2247 if (len > left)
2248 len = left;
2249 if(copy_to_user(s, buf, len))
2250 return -EFAULT;
2251 left -= len;
2252 s += len;
2256 if (!write && !first && left) {
2257 if(put_user('\n', s))
2258 return -EFAULT;
2259 left--, s++;
2261 if (write) {
2262 while (left) {
2263 char c;
2264 if (get_user(c, s++))
2265 return -EFAULT;
2266 if (!isspace(c))
2267 break;
2268 left--;
2271 if (write && first)
2272 return -EINVAL;
2273 *lenp -= left;
2274 *ppos += *lenp;
2275 return 0;
2276 #undef TMPBUFLEN
2279 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2280 void __user *buffer, size_t *lenp, loff_t *ppos,
2281 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2282 int write, void *data),
2283 void *data)
2285 return __do_proc_dointvec(table->data, table, write, filp,
2286 buffer, lenp, ppos, conv, data);
2290 * proc_dointvec - read a vector of integers
2291 * @table: the sysctl table
2292 * @write: %TRUE if this is a write to the sysctl file
2293 * @filp: the file structure
2294 * @buffer: the user buffer
2295 * @lenp: the size of the user buffer
2296 * @ppos: file position
2298 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2299 * values from/to the user buffer, treated as an ASCII string.
2301 * Returns 0 on success.
2303 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2304 void __user *buffer, size_t *lenp, loff_t *ppos)
2306 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2307 NULL,NULL);
2311 * Taint values can only be increased
2312 * This means we can safely use a temporary.
2314 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2315 void __user *buffer, size_t *lenp, loff_t *ppos)
2317 struct ctl_table t;
2318 unsigned long tmptaint = get_taint();
2319 int err;
2321 if (write && !capable(CAP_SYS_ADMIN))
2322 return -EPERM;
2324 t = *table;
2325 t.data = &tmptaint;
2326 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2327 if (err < 0)
2328 return err;
2330 if (write) {
2332 * Poor man's atomic or. Not worth adding a primitive
2333 * to everyone's atomic.h for this
2335 int i;
2336 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2337 if ((tmptaint >> i) & 1)
2338 add_taint(i);
2342 return err;
2345 struct do_proc_dointvec_minmax_conv_param {
2346 int *min;
2347 int *max;
2350 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2351 int *valp,
2352 int write, void *data)
2354 struct do_proc_dointvec_minmax_conv_param *param = data;
2355 if (write) {
2356 int val = *negp ? -*lvalp : *lvalp;
2357 if ((param->min && *param->min > val) ||
2358 (param->max && *param->max < val))
2359 return -EINVAL;
2360 *valp = val;
2361 } else {
2362 int val = *valp;
2363 if (val < 0) {
2364 *negp = -1;
2365 *lvalp = (unsigned long)-val;
2366 } else {
2367 *negp = 0;
2368 *lvalp = (unsigned long)val;
2371 return 0;
2375 * proc_dointvec_minmax - read a vector of integers with min/max values
2376 * @table: the sysctl table
2377 * @write: %TRUE if this is a write to the sysctl file
2378 * @filp: the file structure
2379 * @buffer: the user buffer
2380 * @lenp: the size of the user buffer
2381 * @ppos: file position
2383 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2384 * values from/to the user buffer, treated as an ASCII string.
2386 * This routine will ensure the values are within the range specified by
2387 * table->extra1 (min) and table->extra2 (max).
2389 * Returns 0 on success.
2391 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2392 void __user *buffer, size_t *lenp, loff_t *ppos)
2394 struct do_proc_dointvec_minmax_conv_param param = {
2395 .min = (int *) table->extra1,
2396 .max = (int *) table->extra2,
2398 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2399 do_proc_dointvec_minmax_conv, &param);
2402 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2403 struct file *filp,
2404 void __user *buffer,
2405 size_t *lenp, loff_t *ppos,
2406 unsigned long convmul,
2407 unsigned long convdiv)
2409 #define TMPBUFLEN 21
2410 unsigned long *i, *min, *max, val;
2411 int vleft, first=1, neg;
2412 size_t len, left;
2413 char buf[TMPBUFLEN], *p;
2414 char __user *s = buffer;
2416 if (!data || !table->maxlen || !*lenp ||
2417 (*ppos && !write)) {
2418 *lenp = 0;
2419 return 0;
2422 i = (unsigned long *) data;
2423 min = (unsigned long *) table->extra1;
2424 max = (unsigned long *) table->extra2;
2425 vleft = table->maxlen / sizeof(unsigned long);
2426 left = *lenp;
2428 for (; left && vleft--; i++, min++, max++, first=0) {
2429 if (write) {
2430 while (left) {
2431 char c;
2432 if (get_user(c, s))
2433 return -EFAULT;
2434 if (!isspace(c))
2435 break;
2436 left--;
2437 s++;
2439 if (!left)
2440 break;
2441 neg = 0;
2442 len = left;
2443 if (len > TMPBUFLEN-1)
2444 len = TMPBUFLEN-1;
2445 if (copy_from_user(buf, s, len))
2446 return -EFAULT;
2447 buf[len] = 0;
2448 p = buf;
2449 if (*p == '-' && left > 1) {
2450 neg = 1;
2451 p++;
2453 if (*p < '0' || *p > '9')
2454 break;
2455 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2456 len = p-buf;
2457 if ((len < left) && *p && !isspace(*p))
2458 break;
2459 if (neg)
2460 val = -val;
2461 s += len;
2462 left -= len;
2464 if(neg)
2465 continue;
2466 if ((min && val < *min) || (max && val > *max))
2467 continue;
2468 *i = val;
2469 } else {
2470 p = buf;
2471 if (!first)
2472 *p++ = '\t';
2473 sprintf(p, "%lu", convdiv * (*i) / convmul);
2474 len = strlen(buf);
2475 if (len > left)
2476 len = left;
2477 if(copy_to_user(s, buf, len))
2478 return -EFAULT;
2479 left -= len;
2480 s += len;
2484 if (!write && !first && left) {
2485 if(put_user('\n', s))
2486 return -EFAULT;
2487 left--, s++;
2489 if (write) {
2490 while (left) {
2491 char c;
2492 if (get_user(c, s++))
2493 return -EFAULT;
2494 if (!isspace(c))
2495 break;
2496 left--;
2499 if (write && first)
2500 return -EINVAL;
2501 *lenp -= left;
2502 *ppos += *lenp;
2503 return 0;
2504 #undef TMPBUFLEN
2507 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2508 struct file *filp,
2509 void __user *buffer,
2510 size_t *lenp, loff_t *ppos,
2511 unsigned long convmul,
2512 unsigned long convdiv)
2514 return __do_proc_doulongvec_minmax(table->data, table, write,
2515 filp, buffer, lenp, ppos, convmul, convdiv);
2519 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2520 * @table: the sysctl table
2521 * @write: %TRUE if this is a write to the sysctl file
2522 * @filp: the file structure
2523 * @buffer: the user buffer
2524 * @lenp: the size of the user buffer
2525 * @ppos: file position
2527 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2528 * values from/to the user buffer, treated as an ASCII string.
2530 * This routine will ensure the values are within the range specified by
2531 * table->extra1 (min) and table->extra2 (max).
2533 * Returns 0 on success.
2535 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2536 void __user *buffer, size_t *lenp, loff_t *ppos)
2538 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2542 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2543 * @table: the sysctl table
2544 * @write: %TRUE if this is a write to the sysctl file
2545 * @filp: the file structure
2546 * @buffer: the user buffer
2547 * @lenp: the size of the user buffer
2548 * @ppos: file position
2550 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2551 * values from/to the user buffer, treated as an ASCII string. The values
2552 * are treated as milliseconds, and converted to jiffies when they are stored.
2554 * This routine will ensure the values are within the range specified by
2555 * table->extra1 (min) and table->extra2 (max).
2557 * Returns 0 on success.
2559 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2560 struct file *filp,
2561 void __user *buffer,
2562 size_t *lenp, loff_t *ppos)
2564 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2565 lenp, ppos, HZ, 1000l);
2569 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2570 int *valp,
2571 int write, void *data)
2573 if (write) {
2574 if (*lvalp > LONG_MAX / HZ)
2575 return 1;
2576 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2577 } else {
2578 int val = *valp;
2579 unsigned long lval;
2580 if (val < 0) {
2581 *negp = -1;
2582 lval = (unsigned long)-val;
2583 } else {
2584 *negp = 0;
2585 lval = (unsigned long)val;
2587 *lvalp = lval / HZ;
2589 return 0;
2592 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2593 int *valp,
2594 int write, void *data)
2596 if (write) {
2597 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2598 return 1;
2599 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2600 } else {
2601 int val = *valp;
2602 unsigned long lval;
2603 if (val < 0) {
2604 *negp = -1;
2605 lval = (unsigned long)-val;
2606 } else {
2607 *negp = 0;
2608 lval = (unsigned long)val;
2610 *lvalp = jiffies_to_clock_t(lval);
2612 return 0;
2615 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2616 int *valp,
2617 int write, void *data)
2619 if (write) {
2620 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2621 } else {
2622 int val = *valp;
2623 unsigned long lval;
2624 if (val < 0) {
2625 *negp = -1;
2626 lval = (unsigned long)-val;
2627 } else {
2628 *negp = 0;
2629 lval = (unsigned long)val;
2631 *lvalp = jiffies_to_msecs(lval);
2633 return 0;
2637 * proc_dointvec_jiffies - read a vector of integers as seconds
2638 * @table: the sysctl table
2639 * @write: %TRUE if this is a write to the sysctl file
2640 * @filp: the file structure
2641 * @buffer: the user buffer
2642 * @lenp: the size of the user buffer
2643 * @ppos: file position
2645 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2646 * values from/to the user buffer, treated as an ASCII string.
2647 * The values read are assumed to be in seconds, and are converted into
2648 * jiffies.
2650 * Returns 0 on success.
2652 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2653 void __user *buffer, size_t *lenp, loff_t *ppos)
2655 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2656 do_proc_dointvec_jiffies_conv,NULL);
2660 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2661 * @table: the sysctl table
2662 * @write: %TRUE if this is a write to the sysctl file
2663 * @filp: the file structure
2664 * @buffer: the user buffer
2665 * @lenp: the size of the user buffer
2666 * @ppos: pointer to the file position
2668 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2669 * values from/to the user buffer, treated as an ASCII string.
2670 * The values read are assumed to be in 1/USER_HZ seconds, and
2671 * are converted into jiffies.
2673 * Returns 0 on success.
2675 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2676 void __user *buffer, size_t *lenp, loff_t *ppos)
2678 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2679 do_proc_dointvec_userhz_jiffies_conv,NULL);
2683 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2684 * @table: the sysctl table
2685 * @write: %TRUE if this is a write to the sysctl file
2686 * @filp: the file structure
2687 * @buffer: the user buffer
2688 * @lenp: the size of the user buffer
2689 * @ppos: file position
2690 * @ppos: the current position in the file
2692 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2693 * values from/to the user buffer, treated as an ASCII string.
2694 * The values read are assumed to be in 1/1000 seconds, and
2695 * are converted into jiffies.
2697 * Returns 0 on success.
2699 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2700 void __user *buffer, size_t *lenp, loff_t *ppos)
2702 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2703 do_proc_dointvec_ms_jiffies_conv, NULL);
2706 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2707 void __user *buffer, size_t *lenp, loff_t *ppos)
2709 struct pid *new_pid;
2710 pid_t tmp;
2711 int r;
2713 tmp = pid_vnr(cad_pid);
2715 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2716 lenp, ppos, NULL, NULL);
2717 if (r || !write)
2718 return r;
2720 new_pid = find_get_pid(tmp);
2721 if (!new_pid)
2722 return -ESRCH;
2724 put_pid(xchg(&cad_pid, new_pid));
2725 return 0;
2728 #else /* CONFIG_PROC_FS */
2730 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2731 void __user *buffer, size_t *lenp, loff_t *ppos)
2733 return -ENOSYS;
2736 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2737 void __user *buffer, size_t *lenp, loff_t *ppos)
2739 return -ENOSYS;
2742 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2743 void __user *buffer, size_t *lenp, loff_t *ppos)
2745 return -ENOSYS;
2748 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2749 void __user *buffer, size_t *lenp, loff_t *ppos)
2751 return -ENOSYS;
2754 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2755 void __user *buffer, size_t *lenp, loff_t *ppos)
2757 return -ENOSYS;
2760 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2761 void __user *buffer, size_t *lenp, loff_t *ppos)
2763 return -ENOSYS;
2766 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2767 void __user *buffer, size_t *lenp, loff_t *ppos)
2769 return -ENOSYS;
2772 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2773 struct file *filp,
2774 void __user *buffer,
2775 size_t *lenp, loff_t *ppos)
2777 return -ENOSYS;
2781 #endif /* CONFIG_PROC_FS */
2784 #ifdef CONFIG_SYSCTL_SYSCALL
2786 * General sysctl support routines
2789 /* The generic sysctl data routine (used if no strategy routine supplied) */
2790 int sysctl_data(struct ctl_table *table,
2791 void __user *oldval, size_t __user *oldlenp,
2792 void __user *newval, size_t newlen)
2794 size_t len;
2796 /* Get out of I don't have a variable */
2797 if (!table->data || !table->maxlen)
2798 return -ENOTDIR;
2800 if (oldval && oldlenp) {
2801 if (get_user(len, oldlenp))
2802 return -EFAULT;
2803 if (len) {
2804 if (len > table->maxlen)
2805 len = table->maxlen;
2806 if (copy_to_user(oldval, table->data, len))
2807 return -EFAULT;
2808 if (put_user(len, oldlenp))
2809 return -EFAULT;
2813 if (newval && newlen) {
2814 if (newlen > table->maxlen)
2815 newlen = table->maxlen;
2817 if (copy_from_user(table->data, newval, newlen))
2818 return -EFAULT;
2820 return 1;
2823 /* The generic string strategy routine: */
2824 int sysctl_string(struct ctl_table *table,
2825 void __user *oldval, size_t __user *oldlenp,
2826 void __user *newval, size_t newlen)
2828 if (!table->data || !table->maxlen)
2829 return -ENOTDIR;
2831 if (oldval && oldlenp) {
2832 size_t bufsize;
2833 if (get_user(bufsize, oldlenp))
2834 return -EFAULT;
2835 if (bufsize) {
2836 size_t len = strlen(table->data), copied;
2838 /* This shouldn't trigger for a well-formed sysctl */
2839 if (len > table->maxlen)
2840 len = table->maxlen;
2842 /* Copy up to a max of bufsize-1 bytes of the string */
2843 copied = (len >= bufsize) ? bufsize - 1 : len;
2845 if (copy_to_user(oldval, table->data, copied) ||
2846 put_user(0, (char __user *)(oldval + copied)))
2847 return -EFAULT;
2848 if (put_user(len, oldlenp))
2849 return -EFAULT;
2852 if (newval && newlen) {
2853 size_t len = newlen;
2854 if (len > table->maxlen)
2855 len = table->maxlen;
2856 if(copy_from_user(table->data, newval, len))
2857 return -EFAULT;
2858 if (len == table->maxlen)
2859 len--;
2860 ((char *) table->data)[len] = 0;
2862 return 1;
2866 * This function makes sure that all of the integers in the vector
2867 * are between the minimum and maximum values given in the arrays
2868 * table->extra1 and table->extra2, respectively.
2870 int sysctl_intvec(struct ctl_table *table,
2871 void __user *oldval, size_t __user *oldlenp,
2872 void __user *newval, size_t newlen)
2875 if (newval && newlen) {
2876 int __user *vec = (int __user *) newval;
2877 int *min = (int *) table->extra1;
2878 int *max = (int *) table->extra2;
2879 size_t length;
2880 int i;
2882 if (newlen % sizeof(int) != 0)
2883 return -EINVAL;
2885 if (!table->extra1 && !table->extra2)
2886 return 0;
2888 if (newlen > table->maxlen)
2889 newlen = table->maxlen;
2890 length = newlen / sizeof(int);
2892 for (i = 0; i < length; i++) {
2893 int value;
2894 if (get_user(value, vec + i))
2895 return -EFAULT;
2896 if (min && value < min[i])
2897 return -EINVAL;
2898 if (max && value > max[i])
2899 return -EINVAL;
2902 return 0;
2905 /* Strategy function to convert jiffies to seconds */
2906 int sysctl_jiffies(struct ctl_table *table,
2907 void __user *oldval, size_t __user *oldlenp,
2908 void __user *newval, size_t newlen)
2910 if (oldval && oldlenp) {
2911 size_t olen;
2913 if (get_user(olen, oldlenp))
2914 return -EFAULT;
2915 if (olen) {
2916 int val;
2918 if (olen < sizeof(int))
2919 return -EINVAL;
2921 val = *(int *)(table->data) / HZ;
2922 if (put_user(val, (int __user *)oldval))
2923 return -EFAULT;
2924 if (put_user(sizeof(int), oldlenp))
2925 return -EFAULT;
2928 if (newval && newlen) {
2929 int new;
2930 if (newlen != sizeof(int))
2931 return -EINVAL;
2932 if (get_user(new, (int __user *)newval))
2933 return -EFAULT;
2934 *(int *)(table->data) = new*HZ;
2936 return 1;
2939 /* Strategy function to convert jiffies to seconds */
2940 int sysctl_ms_jiffies(struct ctl_table *table,
2941 void __user *oldval, size_t __user *oldlenp,
2942 void __user *newval, size_t newlen)
2944 if (oldval && oldlenp) {
2945 size_t olen;
2947 if (get_user(olen, oldlenp))
2948 return -EFAULT;
2949 if (olen) {
2950 int val;
2952 if (olen < sizeof(int))
2953 return -EINVAL;
2955 val = jiffies_to_msecs(*(int *)(table->data));
2956 if (put_user(val, (int __user *)oldval))
2957 return -EFAULT;
2958 if (put_user(sizeof(int), oldlenp))
2959 return -EFAULT;
2962 if (newval && newlen) {
2963 int new;
2964 if (newlen != sizeof(int))
2965 return -EINVAL;
2966 if (get_user(new, (int __user *)newval))
2967 return -EFAULT;
2968 *(int *)(table->data) = msecs_to_jiffies(new);
2970 return 1;
2975 #else /* CONFIG_SYSCTL_SYSCALL */
2978 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2980 struct __sysctl_args tmp;
2981 int error;
2983 if (copy_from_user(&tmp, args, sizeof(tmp)))
2984 return -EFAULT;
2986 error = deprecated_sysctl_warning(&tmp);
2988 /* If no error reading the parameters then just -ENOSYS ... */
2989 if (!error)
2990 error = -ENOSYS;
2992 return error;
2995 int sysctl_data(struct ctl_table *table,
2996 void __user *oldval, size_t __user *oldlenp,
2997 void __user *newval, size_t newlen)
2999 return -ENOSYS;
3002 int sysctl_string(struct ctl_table *table,
3003 void __user *oldval, size_t __user *oldlenp,
3004 void __user *newval, size_t newlen)
3006 return -ENOSYS;
3009 int sysctl_intvec(struct ctl_table *table,
3010 void __user *oldval, size_t __user *oldlenp,
3011 void __user *newval, size_t newlen)
3013 return -ENOSYS;
3016 int sysctl_jiffies(struct ctl_table *table,
3017 void __user *oldval, size_t __user *oldlenp,
3018 void __user *newval, size_t newlen)
3020 return -ENOSYS;
3023 int sysctl_ms_jiffies(struct ctl_table *table,
3024 void __user *oldval, size_t __user *oldlenp,
3025 void __user *newval, size_t newlen)
3027 return -ENOSYS;
3030 #endif /* CONFIG_SYSCTL_SYSCALL */
3032 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3034 static int msg_count;
3035 int name[CTL_MAXNAME];
3036 int i;
3038 /* Check args->nlen. */
3039 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3040 return -ENOTDIR;
3042 /* Read in the sysctl name for better debug message logging */
3043 for (i = 0; i < args->nlen; i++)
3044 if (get_user(name[i], args->name + i))
3045 return -EFAULT;
3047 /* Ignore accesses to kernel.version */
3048 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3049 return 0;
3051 if (msg_count < 5) {
3052 msg_count++;
3053 printk(KERN_INFO
3054 "warning: process `%s' used the deprecated sysctl "
3055 "system call with ", current->comm);
3056 for (i = 0; i < args->nlen; i++)
3057 printk("%d.", name[i]);
3058 printk("\n");
3060 return 0;
3064 * No sense putting this after each symbol definition, twice,
3065 * exception granted :-)
3067 EXPORT_SYMBOL(proc_dointvec);
3068 EXPORT_SYMBOL(proc_dointvec_jiffies);
3069 EXPORT_SYMBOL(proc_dointvec_minmax);
3070 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3071 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3072 EXPORT_SYMBOL(proc_dostring);
3073 EXPORT_SYMBOL(proc_doulongvec_minmax);
3074 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3075 EXPORT_SYMBOL(register_sysctl_table);
3076 EXPORT_SYMBOL(register_sysctl_paths);
3077 EXPORT_SYMBOL(sysctl_intvec);
3078 EXPORT_SYMBOL(sysctl_jiffies);
3079 EXPORT_SYMBOL(sysctl_ms_jiffies);
3080 EXPORT_SYMBOL(sysctl_string);
3081 EXPORT_SYMBOL(sysctl_data);
3082 EXPORT_SYMBOL(unregister_sysctl_table);