pch_gbe: support ML7223 IOH
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / kernel / sysctl.c
blob443fd2081a74a848e53eb7adb3d09a38a9edf796
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/signal.h>
27 #include <linux/printk.h>
28 #include <linux/proc_fs.h>
29 #include <linux/security.h>
30 #include <linux/ctype.h>
31 #include <linux/kmemcheck.h>
32 #include <linux/fs.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/ratelimit.h>
41 #include <linux/compaction.h>
42 #include <linux/hugetlb.h>
43 #include <linux/initrd.h>
44 #include <linux/key.h>
45 #include <linux/times.h>
46 #include <linux/limits.h>
47 #include <linux/dcache.h>
48 #include <linux/dnotify.h>
49 #include <linux/syscalls.h>
50 #include <linux/vmstat.h>
51 #include <linux/nfs_fs.h>
52 #include <linux/acpi.h>
53 #include <linux/reboot.h>
54 #include <linux/ftrace.h>
55 #include <linux/perf_event.h>
56 #include <linux/kprobes.h>
57 #include <linux/pipe_fs_i.h>
58 #include <linux/oom.h>
60 #include <asm/uaccess.h>
61 #include <asm/processor.h>
63 #ifdef CONFIG_X86
64 #include <asm/nmi.h>
65 #include <asm/stacktrace.h>
66 #include <asm/io.h>
67 #endif
68 #ifdef CONFIG_BSD_PROCESS_ACCT
69 #include <linux/acct.h>
70 #endif
71 #ifdef CONFIG_RT_MUTEXES
72 #include <linux/rtmutex.h>
73 #endif
74 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
75 #include <linux/lockdep.h>
76 #endif
77 #ifdef CONFIG_CHR_DEV_SG
78 #include <scsi/sg.h>
79 #endif
81 #ifdef CONFIG_LOCKUP_DETECTOR
82 #include <linux/nmi.h>
83 #endif
86 #if defined(CONFIG_SYSCTL)
88 /* External variables not in a header file. */
89 extern int sysctl_overcommit_memory;
90 extern int sysctl_overcommit_ratio;
91 extern int max_threads;
92 extern int core_uses_pid;
93 extern int suid_dumpable;
94 extern char core_pattern[];
95 extern unsigned int core_pipe_limit;
96 extern int pid_max;
97 extern int min_free_kbytes;
98 extern int pid_max_min, pid_max_max;
99 extern int sysctl_drop_caches;
100 extern int percpu_pagelist_fraction;
101 extern int compat_log;
102 extern int latencytop_enabled;
103 extern int sysctl_nr_open_min, sysctl_nr_open_max;
104 #ifndef CONFIG_MMU
105 extern int sysctl_nr_trim_pages;
106 #endif
107 #ifdef CONFIG_BLOCK
108 extern int blk_iopoll_enabled;
109 #endif
111 /* Constants used for minimum and maximum */
112 #ifdef CONFIG_LOCKUP_DETECTOR
113 static int sixty = 60;
114 static int neg_one = -1;
115 #endif
117 static int zero;
118 static int __maybe_unused one = 1;
119 static int __maybe_unused two = 2;
120 static unsigned long one_ul = 1;
121 static int one_hundred = 100;
122 #ifdef CONFIG_PRINTK
123 static int ten_thousand = 10000;
124 #endif
126 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
127 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
129 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
130 static int maxolduid = 65535;
131 static int minolduid;
132 static int min_percpu_pagelist_fract = 8;
134 static int ngroups_max = NGROUPS_MAX;
136 #ifdef CONFIG_INOTIFY_USER
137 #include <linux/inotify.h>
138 #endif
139 #ifdef CONFIG_SPARC
140 #include <asm/system.h>
141 #endif
143 #ifdef CONFIG_SPARC64
144 extern int sysctl_tsb_ratio;
145 #endif
147 #ifdef __hppa__
148 extern int pwrsw_enabled;
149 extern int unaligned_enabled;
150 #endif
152 #ifdef CONFIG_S390
153 #ifdef CONFIG_MATHEMU
154 extern int sysctl_ieee_emulation_warnings;
155 #endif
156 extern int sysctl_userprocess_debug;
157 extern int spin_retry;
158 #endif
160 #ifdef CONFIG_IA64
161 extern int no_unaligned_warning;
162 extern int unaligned_dump_stack;
163 #endif
165 #ifdef CONFIG_PROC_SYSCTL
166 static int proc_do_cad_pid(struct ctl_table *table, int write,
167 void __user *buffer, size_t *lenp, loff_t *ppos);
168 static int proc_taint(struct ctl_table *table, int write,
169 void __user *buffer, size_t *lenp, loff_t *ppos);
170 #endif
172 #ifdef CONFIG_PRINTK
173 static int proc_dmesg_restrict(struct ctl_table *table, int write,
174 void __user *buffer, size_t *lenp, loff_t *ppos);
175 #endif
177 #ifdef CONFIG_MAGIC_SYSRQ
178 /* Note: sysrq code uses it's own private copy */
179 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
181 static int sysrq_sysctl_handler(ctl_table *table, int write,
182 void __user *buffer, size_t *lenp,
183 loff_t *ppos)
185 int error;
187 error = proc_dointvec(table, write, buffer, lenp, ppos);
188 if (error)
189 return error;
191 if (write)
192 sysrq_toggle_support(__sysrq_enabled);
194 return 0;
197 #endif
199 static struct ctl_table root_table[];
200 static struct ctl_table_root sysctl_table_root;
201 static struct ctl_table_header root_table_header = {
202 {{.count = 1,
203 .ctl_table = root_table,
204 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}},
205 .root = &sysctl_table_root,
206 .set = &sysctl_table_root.default_set,
208 static struct ctl_table_root sysctl_table_root = {
209 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
210 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
213 static struct ctl_table kern_table[];
214 static struct ctl_table vm_table[];
215 static struct ctl_table fs_table[];
216 static struct ctl_table debug_table[];
217 static struct ctl_table dev_table[];
218 extern struct ctl_table random_table[];
219 #ifdef CONFIG_EPOLL
220 extern struct ctl_table epoll_table[];
221 #endif
223 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
224 int sysctl_legacy_va_layout;
225 #endif
227 /* The default sysctl tables: */
229 static struct ctl_table root_table[] = {
231 .procname = "kernel",
232 .mode = 0555,
233 .child = kern_table,
236 .procname = "vm",
237 .mode = 0555,
238 .child = vm_table,
241 .procname = "fs",
242 .mode = 0555,
243 .child = fs_table,
246 .procname = "debug",
247 .mode = 0555,
248 .child = debug_table,
251 .procname = "dev",
252 .mode = 0555,
253 .child = dev_table,
258 #ifdef CONFIG_SCHED_DEBUG
259 static int min_sched_granularity_ns = 100000; /* 100 usecs */
260 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
261 static int min_wakeup_granularity_ns; /* 0 usecs */
262 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
263 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
264 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
265 #endif
267 #ifdef CONFIG_COMPACTION
268 static int min_extfrag_threshold;
269 static int max_extfrag_threshold = 1000;
270 #endif
272 static struct ctl_table kern_table[] = {
274 .procname = "sched_child_runs_first",
275 .data = &sysctl_sched_child_runs_first,
276 .maxlen = sizeof(unsigned int),
277 .mode = 0644,
278 .proc_handler = proc_dointvec,
280 #ifdef CONFIG_SCHED_DEBUG
282 .procname = "sched_min_granularity_ns",
283 .data = &sysctl_sched_min_granularity,
284 .maxlen = sizeof(unsigned int),
285 .mode = 0644,
286 .proc_handler = sched_proc_update_handler,
287 .extra1 = &min_sched_granularity_ns,
288 .extra2 = &max_sched_granularity_ns,
291 .procname = "sched_latency_ns",
292 .data = &sysctl_sched_latency,
293 .maxlen = sizeof(unsigned int),
294 .mode = 0644,
295 .proc_handler = sched_proc_update_handler,
296 .extra1 = &min_sched_granularity_ns,
297 .extra2 = &max_sched_granularity_ns,
300 .procname = "sched_wakeup_granularity_ns",
301 .data = &sysctl_sched_wakeup_granularity,
302 .maxlen = sizeof(unsigned int),
303 .mode = 0644,
304 .proc_handler = sched_proc_update_handler,
305 .extra1 = &min_wakeup_granularity_ns,
306 .extra2 = &max_wakeup_granularity_ns,
309 .procname = "sched_tunable_scaling",
310 .data = &sysctl_sched_tunable_scaling,
311 .maxlen = sizeof(enum sched_tunable_scaling),
312 .mode = 0644,
313 .proc_handler = sched_proc_update_handler,
314 .extra1 = &min_sched_tunable_scaling,
315 .extra2 = &max_sched_tunable_scaling,
318 .procname = "sched_migration_cost",
319 .data = &sysctl_sched_migration_cost,
320 .maxlen = sizeof(unsigned int),
321 .mode = 0644,
322 .proc_handler = proc_dointvec,
325 .procname = "sched_nr_migrate",
326 .data = &sysctl_sched_nr_migrate,
327 .maxlen = sizeof(unsigned int),
328 .mode = 0644,
329 .proc_handler = proc_dointvec,
332 .procname = "sched_time_avg",
333 .data = &sysctl_sched_time_avg,
334 .maxlen = sizeof(unsigned int),
335 .mode = 0644,
336 .proc_handler = proc_dointvec,
339 .procname = "sched_shares_window",
340 .data = &sysctl_sched_shares_window,
341 .maxlen = sizeof(unsigned int),
342 .mode = 0644,
343 .proc_handler = proc_dointvec,
346 .procname = "timer_migration",
347 .data = &sysctl_timer_migration,
348 .maxlen = sizeof(unsigned int),
349 .mode = 0644,
350 .proc_handler = proc_dointvec_minmax,
351 .extra1 = &zero,
352 .extra2 = &one,
354 #endif
356 .procname = "sched_rt_period_us",
357 .data = &sysctl_sched_rt_period,
358 .maxlen = sizeof(unsigned int),
359 .mode = 0644,
360 .proc_handler = sched_rt_handler,
363 .procname = "sched_rt_runtime_us",
364 .data = &sysctl_sched_rt_runtime,
365 .maxlen = sizeof(int),
366 .mode = 0644,
367 .proc_handler = sched_rt_handler,
370 .procname = "sched_compat_yield",
371 .data = &sysctl_sched_compat_yield,
372 .maxlen = sizeof(unsigned int),
373 .mode = 0644,
374 .proc_handler = proc_dointvec,
376 #ifdef CONFIG_SCHED_AUTOGROUP
378 .procname = "sched_autogroup_enabled",
379 .data = &sysctl_sched_autogroup_enabled,
380 .maxlen = sizeof(unsigned int),
381 .mode = 0644,
382 .proc_handler = proc_dointvec,
383 .extra1 = &zero,
384 .extra2 = &one,
386 #endif
387 #ifdef CONFIG_PROVE_LOCKING
389 .procname = "prove_locking",
390 .data = &prove_locking,
391 .maxlen = sizeof(int),
392 .mode = 0644,
393 .proc_handler = proc_dointvec,
395 #endif
396 #ifdef CONFIG_LOCK_STAT
398 .procname = "lock_stat",
399 .data = &lock_stat,
400 .maxlen = sizeof(int),
401 .mode = 0644,
402 .proc_handler = proc_dointvec,
404 #endif
406 .procname = "panic",
407 .data = &panic_timeout,
408 .maxlen = sizeof(int),
409 .mode = 0644,
410 .proc_handler = proc_dointvec,
413 .procname = "core_uses_pid",
414 .data = &core_uses_pid,
415 .maxlen = sizeof(int),
416 .mode = 0644,
417 .proc_handler = proc_dointvec,
420 .procname = "core_pattern",
421 .data = core_pattern,
422 .maxlen = CORENAME_MAX_SIZE,
423 .mode = 0644,
424 .proc_handler = proc_dostring,
427 .procname = "core_pipe_limit",
428 .data = &core_pipe_limit,
429 .maxlen = sizeof(unsigned int),
430 .mode = 0644,
431 .proc_handler = proc_dointvec,
433 #ifdef CONFIG_PROC_SYSCTL
435 .procname = "tainted",
436 .maxlen = sizeof(long),
437 .mode = 0644,
438 .proc_handler = proc_taint,
440 #endif
441 #ifdef CONFIG_LATENCYTOP
443 .procname = "latencytop",
444 .data = &latencytop_enabled,
445 .maxlen = sizeof(int),
446 .mode = 0644,
447 .proc_handler = proc_dointvec,
449 #endif
450 #ifdef CONFIG_BLK_DEV_INITRD
452 .procname = "real-root-dev",
453 .data = &real_root_dev,
454 .maxlen = sizeof(int),
455 .mode = 0644,
456 .proc_handler = proc_dointvec,
458 #endif
460 .procname = "print-fatal-signals",
461 .data = &print_fatal_signals,
462 .maxlen = sizeof(int),
463 .mode = 0644,
464 .proc_handler = proc_dointvec,
466 #ifdef CONFIG_SPARC
468 .procname = "reboot-cmd",
469 .data = reboot_command,
470 .maxlen = 256,
471 .mode = 0644,
472 .proc_handler = proc_dostring,
475 .procname = "stop-a",
476 .data = &stop_a_enabled,
477 .maxlen = sizeof (int),
478 .mode = 0644,
479 .proc_handler = proc_dointvec,
482 .procname = "scons-poweroff",
483 .data = &scons_pwroff,
484 .maxlen = sizeof (int),
485 .mode = 0644,
486 .proc_handler = proc_dointvec,
488 #endif
489 #ifdef CONFIG_SPARC64
491 .procname = "tsb-ratio",
492 .data = &sysctl_tsb_ratio,
493 .maxlen = sizeof (int),
494 .mode = 0644,
495 .proc_handler = proc_dointvec,
497 #endif
498 #ifdef __hppa__
500 .procname = "soft-power",
501 .data = &pwrsw_enabled,
502 .maxlen = sizeof (int),
503 .mode = 0644,
504 .proc_handler = proc_dointvec,
507 .procname = "unaligned-trap",
508 .data = &unaligned_enabled,
509 .maxlen = sizeof (int),
510 .mode = 0644,
511 .proc_handler = proc_dointvec,
513 #endif
515 .procname = "ctrl-alt-del",
516 .data = &C_A_D,
517 .maxlen = sizeof(int),
518 .mode = 0644,
519 .proc_handler = proc_dointvec,
521 #ifdef CONFIG_FUNCTION_TRACER
523 .procname = "ftrace_enabled",
524 .data = &ftrace_enabled,
525 .maxlen = sizeof(int),
526 .mode = 0644,
527 .proc_handler = ftrace_enable_sysctl,
529 #endif
530 #ifdef CONFIG_STACK_TRACER
532 .procname = "stack_tracer_enabled",
533 .data = &stack_tracer_enabled,
534 .maxlen = sizeof(int),
535 .mode = 0644,
536 .proc_handler = stack_trace_sysctl,
538 #endif
539 #ifdef CONFIG_TRACING
541 .procname = "ftrace_dump_on_oops",
542 .data = &ftrace_dump_on_oops,
543 .maxlen = sizeof(int),
544 .mode = 0644,
545 .proc_handler = proc_dointvec,
547 #endif
548 #ifdef CONFIG_MODULES
550 .procname = "modprobe",
551 .data = &modprobe_path,
552 .maxlen = KMOD_PATH_LEN,
553 .mode = 0644,
554 .proc_handler = proc_dostring,
557 .procname = "modules_disabled",
558 .data = &modules_disabled,
559 .maxlen = sizeof(int),
560 .mode = 0644,
561 /* only handle a transition from default "0" to "1" */
562 .proc_handler = proc_dointvec_minmax,
563 .extra1 = &one,
564 .extra2 = &one,
566 #endif
567 #ifdef CONFIG_HOTPLUG
569 .procname = "hotplug",
570 .data = &uevent_helper,
571 .maxlen = UEVENT_HELPER_PATH_LEN,
572 .mode = 0644,
573 .proc_handler = proc_dostring,
575 #endif
576 #ifdef CONFIG_CHR_DEV_SG
578 .procname = "sg-big-buff",
579 .data = &sg_big_buff,
580 .maxlen = sizeof (int),
581 .mode = 0444,
582 .proc_handler = proc_dointvec,
584 #endif
585 #ifdef CONFIG_BSD_PROCESS_ACCT
587 .procname = "acct",
588 .data = &acct_parm,
589 .maxlen = 3*sizeof(int),
590 .mode = 0644,
591 .proc_handler = proc_dointvec,
593 #endif
594 #ifdef CONFIG_MAGIC_SYSRQ
596 .procname = "sysrq",
597 .data = &__sysrq_enabled,
598 .maxlen = sizeof (int),
599 .mode = 0644,
600 .proc_handler = sysrq_sysctl_handler,
602 #endif
603 #ifdef CONFIG_PROC_SYSCTL
605 .procname = "cad_pid",
606 .data = NULL,
607 .maxlen = sizeof (int),
608 .mode = 0600,
609 .proc_handler = proc_do_cad_pid,
611 #endif
613 .procname = "threads-max",
614 .data = &max_threads,
615 .maxlen = sizeof(int),
616 .mode = 0644,
617 .proc_handler = proc_dointvec,
620 .procname = "random",
621 .mode = 0555,
622 .child = random_table,
625 .procname = "overflowuid",
626 .data = &overflowuid,
627 .maxlen = sizeof(int),
628 .mode = 0644,
629 .proc_handler = proc_dointvec_minmax,
630 .extra1 = &minolduid,
631 .extra2 = &maxolduid,
634 .procname = "overflowgid",
635 .data = &overflowgid,
636 .maxlen = sizeof(int),
637 .mode = 0644,
638 .proc_handler = proc_dointvec_minmax,
639 .extra1 = &minolduid,
640 .extra2 = &maxolduid,
642 #ifdef CONFIG_S390
643 #ifdef CONFIG_MATHEMU
645 .procname = "ieee_emulation_warnings",
646 .data = &sysctl_ieee_emulation_warnings,
647 .maxlen = sizeof(int),
648 .mode = 0644,
649 .proc_handler = proc_dointvec,
651 #endif
653 .procname = "userprocess_debug",
654 .data = &show_unhandled_signals,
655 .maxlen = sizeof(int),
656 .mode = 0644,
657 .proc_handler = proc_dointvec,
659 #endif
661 .procname = "pid_max",
662 .data = &pid_max,
663 .maxlen = sizeof (int),
664 .mode = 0644,
665 .proc_handler = proc_dointvec_minmax,
666 .extra1 = &pid_max_min,
667 .extra2 = &pid_max_max,
670 .procname = "panic_on_oops",
671 .data = &panic_on_oops,
672 .maxlen = sizeof(int),
673 .mode = 0644,
674 .proc_handler = proc_dointvec,
676 #if defined CONFIG_PRINTK
678 .procname = "printk",
679 .data = &console_loglevel,
680 .maxlen = 4*sizeof(int),
681 .mode = 0644,
682 .proc_handler = proc_dointvec,
685 .procname = "printk_ratelimit",
686 .data = &printk_ratelimit_state.interval,
687 .maxlen = sizeof(int),
688 .mode = 0644,
689 .proc_handler = proc_dointvec_jiffies,
692 .procname = "printk_ratelimit_burst",
693 .data = &printk_ratelimit_state.burst,
694 .maxlen = sizeof(int),
695 .mode = 0644,
696 .proc_handler = proc_dointvec,
699 .procname = "printk_delay",
700 .data = &printk_delay_msec,
701 .maxlen = sizeof(int),
702 .mode = 0644,
703 .proc_handler = proc_dointvec_minmax,
704 .extra1 = &zero,
705 .extra2 = &ten_thousand,
708 .procname = "dmesg_restrict",
709 .data = &dmesg_restrict,
710 .maxlen = sizeof(int),
711 .mode = 0644,
712 .proc_handler = proc_dointvec_minmax,
713 .extra1 = &zero,
714 .extra2 = &one,
717 .procname = "kptr_restrict",
718 .data = &kptr_restrict,
719 .maxlen = sizeof(int),
720 .mode = 0644,
721 .proc_handler = proc_dmesg_restrict,
722 .extra1 = &zero,
723 .extra2 = &two,
725 #endif
727 .procname = "ngroups_max",
728 .data = &ngroups_max,
729 .maxlen = sizeof (int),
730 .mode = 0444,
731 .proc_handler = proc_dointvec,
733 #if defined(CONFIG_LOCKUP_DETECTOR)
735 .procname = "watchdog",
736 .data = &watchdog_enabled,
737 .maxlen = sizeof (int),
738 .mode = 0644,
739 .proc_handler = proc_dowatchdog_enabled,
742 .procname = "watchdog_thresh",
743 .data = &softlockup_thresh,
744 .maxlen = sizeof(int),
745 .mode = 0644,
746 .proc_handler = proc_dowatchdog_thresh,
747 .extra1 = &neg_one,
748 .extra2 = &sixty,
751 .procname = "softlockup_panic",
752 .data = &softlockup_panic,
753 .maxlen = sizeof(int),
754 .mode = 0644,
755 .proc_handler = proc_dointvec_minmax,
756 .extra1 = &zero,
757 .extra2 = &one,
760 .procname = "nmi_watchdog",
761 .data = &watchdog_enabled,
762 .maxlen = sizeof (int),
763 .mode = 0644,
764 .proc_handler = proc_dowatchdog_enabled,
766 #endif
767 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
769 .procname = "unknown_nmi_panic",
770 .data = &unknown_nmi_panic,
771 .maxlen = sizeof (int),
772 .mode = 0644,
773 .proc_handler = proc_dointvec,
775 #endif
776 #if defined(CONFIG_X86)
778 .procname = "panic_on_unrecovered_nmi",
779 .data = &panic_on_unrecovered_nmi,
780 .maxlen = sizeof(int),
781 .mode = 0644,
782 .proc_handler = proc_dointvec,
785 .procname = "panic_on_io_nmi",
786 .data = &panic_on_io_nmi,
787 .maxlen = sizeof(int),
788 .mode = 0644,
789 .proc_handler = proc_dointvec,
792 .procname = "bootloader_type",
793 .data = &bootloader_type,
794 .maxlen = sizeof (int),
795 .mode = 0444,
796 .proc_handler = proc_dointvec,
799 .procname = "bootloader_version",
800 .data = &bootloader_version,
801 .maxlen = sizeof (int),
802 .mode = 0444,
803 .proc_handler = proc_dointvec,
806 .procname = "kstack_depth_to_print",
807 .data = &kstack_depth_to_print,
808 .maxlen = sizeof(int),
809 .mode = 0644,
810 .proc_handler = proc_dointvec,
813 .procname = "io_delay_type",
814 .data = &io_delay_type,
815 .maxlen = sizeof(int),
816 .mode = 0644,
817 .proc_handler = proc_dointvec,
819 #endif
820 #if defined(CONFIG_MMU)
822 .procname = "randomize_va_space",
823 .data = &randomize_va_space,
824 .maxlen = sizeof(int),
825 .mode = 0644,
826 .proc_handler = proc_dointvec,
828 #endif
829 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
831 .procname = "spin_retry",
832 .data = &spin_retry,
833 .maxlen = sizeof (int),
834 .mode = 0644,
835 .proc_handler = proc_dointvec,
837 #endif
838 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
840 .procname = "acpi_video_flags",
841 .data = &acpi_realmode_flags,
842 .maxlen = sizeof (unsigned long),
843 .mode = 0644,
844 .proc_handler = proc_doulongvec_minmax,
846 #endif
847 #ifdef CONFIG_IA64
849 .procname = "ignore-unaligned-usertrap",
850 .data = &no_unaligned_warning,
851 .maxlen = sizeof (int),
852 .mode = 0644,
853 .proc_handler = proc_dointvec,
856 .procname = "unaligned-dump-stack",
857 .data = &unaligned_dump_stack,
858 .maxlen = sizeof (int),
859 .mode = 0644,
860 .proc_handler = proc_dointvec,
862 #endif
863 #ifdef CONFIG_DETECT_HUNG_TASK
865 .procname = "hung_task_panic",
866 .data = &sysctl_hung_task_panic,
867 .maxlen = sizeof(int),
868 .mode = 0644,
869 .proc_handler = proc_dointvec_minmax,
870 .extra1 = &zero,
871 .extra2 = &one,
874 .procname = "hung_task_check_count",
875 .data = &sysctl_hung_task_check_count,
876 .maxlen = sizeof(unsigned long),
877 .mode = 0644,
878 .proc_handler = proc_doulongvec_minmax,
881 .procname = "hung_task_timeout_secs",
882 .data = &sysctl_hung_task_timeout_secs,
883 .maxlen = sizeof(unsigned long),
884 .mode = 0644,
885 .proc_handler = proc_dohung_task_timeout_secs,
888 .procname = "hung_task_warnings",
889 .data = &sysctl_hung_task_warnings,
890 .maxlen = sizeof(unsigned long),
891 .mode = 0644,
892 .proc_handler = proc_doulongvec_minmax,
894 #endif
895 #ifdef CONFIG_COMPAT
897 .procname = "compat-log",
898 .data = &compat_log,
899 .maxlen = sizeof (int),
900 .mode = 0644,
901 .proc_handler = proc_dointvec,
903 #endif
904 #ifdef CONFIG_RT_MUTEXES
906 .procname = "max_lock_depth",
907 .data = &max_lock_depth,
908 .maxlen = sizeof(int),
909 .mode = 0644,
910 .proc_handler = proc_dointvec,
912 #endif
914 .procname = "poweroff_cmd",
915 .data = &poweroff_cmd,
916 .maxlen = POWEROFF_CMD_PATH_LEN,
917 .mode = 0644,
918 .proc_handler = proc_dostring,
920 #ifdef CONFIG_KEYS
922 .procname = "keys",
923 .mode = 0555,
924 .child = key_sysctls,
926 #endif
927 #ifdef CONFIG_RCU_TORTURE_TEST
929 .procname = "rcutorture_runnable",
930 .data = &rcutorture_runnable,
931 .maxlen = sizeof(int),
932 .mode = 0644,
933 .proc_handler = proc_dointvec,
935 #endif
936 #ifdef CONFIG_PERF_EVENTS
938 .procname = "perf_event_paranoid",
939 .data = &sysctl_perf_event_paranoid,
940 .maxlen = sizeof(sysctl_perf_event_paranoid),
941 .mode = 0644,
942 .proc_handler = proc_dointvec,
945 .procname = "perf_event_mlock_kb",
946 .data = &sysctl_perf_event_mlock,
947 .maxlen = sizeof(sysctl_perf_event_mlock),
948 .mode = 0644,
949 .proc_handler = proc_dointvec,
952 .procname = "perf_event_max_sample_rate",
953 .data = &sysctl_perf_event_sample_rate,
954 .maxlen = sizeof(sysctl_perf_event_sample_rate),
955 .mode = 0644,
956 .proc_handler = proc_dointvec,
958 #endif
959 #ifdef CONFIG_KMEMCHECK
961 .procname = "kmemcheck",
962 .data = &kmemcheck_enabled,
963 .maxlen = sizeof(int),
964 .mode = 0644,
965 .proc_handler = proc_dointvec,
967 #endif
968 #ifdef CONFIG_BLOCK
970 .procname = "blk_iopoll",
971 .data = &blk_iopoll_enabled,
972 .maxlen = sizeof(int),
973 .mode = 0644,
974 .proc_handler = proc_dointvec,
976 #endif
980 static struct ctl_table vm_table[] = {
982 .procname = "overcommit_memory",
983 .data = &sysctl_overcommit_memory,
984 .maxlen = sizeof(sysctl_overcommit_memory),
985 .mode = 0644,
986 .proc_handler = proc_dointvec,
989 .procname = "panic_on_oom",
990 .data = &sysctl_panic_on_oom,
991 .maxlen = sizeof(sysctl_panic_on_oom),
992 .mode = 0644,
993 .proc_handler = proc_dointvec,
996 .procname = "oom_kill_allocating_task",
997 .data = &sysctl_oom_kill_allocating_task,
998 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
999 .mode = 0644,
1000 .proc_handler = proc_dointvec,
1003 .procname = "oom_dump_tasks",
1004 .data = &sysctl_oom_dump_tasks,
1005 .maxlen = sizeof(sysctl_oom_dump_tasks),
1006 .mode = 0644,
1007 .proc_handler = proc_dointvec,
1010 .procname = "overcommit_ratio",
1011 .data = &sysctl_overcommit_ratio,
1012 .maxlen = sizeof(sysctl_overcommit_ratio),
1013 .mode = 0644,
1014 .proc_handler = proc_dointvec,
1017 .procname = "page-cluster",
1018 .data = &page_cluster,
1019 .maxlen = sizeof(int),
1020 .mode = 0644,
1021 .proc_handler = proc_dointvec,
1024 .procname = "dirty_background_ratio",
1025 .data = &dirty_background_ratio,
1026 .maxlen = sizeof(dirty_background_ratio),
1027 .mode = 0644,
1028 .proc_handler = dirty_background_ratio_handler,
1029 .extra1 = &zero,
1030 .extra2 = &one_hundred,
1033 .procname = "dirty_background_bytes",
1034 .data = &dirty_background_bytes,
1035 .maxlen = sizeof(dirty_background_bytes),
1036 .mode = 0644,
1037 .proc_handler = dirty_background_bytes_handler,
1038 .extra1 = &one_ul,
1041 .procname = "dirty_ratio",
1042 .data = &vm_dirty_ratio,
1043 .maxlen = sizeof(vm_dirty_ratio),
1044 .mode = 0644,
1045 .proc_handler = dirty_ratio_handler,
1046 .extra1 = &zero,
1047 .extra2 = &one_hundred,
1050 .procname = "dirty_bytes",
1051 .data = &vm_dirty_bytes,
1052 .maxlen = sizeof(vm_dirty_bytes),
1053 .mode = 0644,
1054 .proc_handler = dirty_bytes_handler,
1055 .extra1 = &dirty_bytes_min,
1058 .procname = "dirty_writeback_centisecs",
1059 .data = &dirty_writeback_interval,
1060 .maxlen = sizeof(dirty_writeback_interval),
1061 .mode = 0644,
1062 .proc_handler = dirty_writeback_centisecs_handler,
1065 .procname = "dirty_expire_centisecs",
1066 .data = &dirty_expire_interval,
1067 .maxlen = sizeof(dirty_expire_interval),
1068 .mode = 0644,
1069 .proc_handler = proc_dointvec,
1072 .procname = "nr_pdflush_threads",
1073 .data = &nr_pdflush_threads,
1074 .maxlen = sizeof nr_pdflush_threads,
1075 .mode = 0444 /* read-only*/,
1076 .proc_handler = proc_dointvec,
1079 .procname = "swappiness",
1080 .data = &vm_swappiness,
1081 .maxlen = sizeof(vm_swappiness),
1082 .mode = 0644,
1083 .proc_handler = proc_dointvec_minmax,
1084 .extra1 = &zero,
1085 .extra2 = &one_hundred,
1087 #ifdef CONFIG_HUGETLB_PAGE
1089 .procname = "nr_hugepages",
1090 .data = NULL,
1091 .maxlen = sizeof(unsigned long),
1092 .mode = 0644,
1093 .proc_handler = hugetlb_sysctl_handler,
1094 .extra1 = (void *)&hugetlb_zero,
1095 .extra2 = (void *)&hugetlb_infinity,
1097 #ifdef CONFIG_NUMA
1099 .procname = "nr_hugepages_mempolicy",
1100 .data = NULL,
1101 .maxlen = sizeof(unsigned long),
1102 .mode = 0644,
1103 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1104 .extra1 = (void *)&hugetlb_zero,
1105 .extra2 = (void *)&hugetlb_infinity,
1107 #endif
1109 .procname = "hugetlb_shm_group",
1110 .data = &sysctl_hugetlb_shm_group,
1111 .maxlen = sizeof(gid_t),
1112 .mode = 0644,
1113 .proc_handler = proc_dointvec,
1116 .procname = "hugepages_treat_as_movable",
1117 .data = &hugepages_treat_as_movable,
1118 .maxlen = sizeof(int),
1119 .mode = 0644,
1120 .proc_handler = hugetlb_treat_movable_handler,
1123 .procname = "nr_overcommit_hugepages",
1124 .data = NULL,
1125 .maxlen = sizeof(unsigned long),
1126 .mode = 0644,
1127 .proc_handler = hugetlb_overcommit_handler,
1128 .extra1 = (void *)&hugetlb_zero,
1129 .extra2 = (void *)&hugetlb_infinity,
1131 #endif
1133 .procname = "lowmem_reserve_ratio",
1134 .data = &sysctl_lowmem_reserve_ratio,
1135 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1136 .mode = 0644,
1137 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1140 .procname = "drop_caches",
1141 .data = &sysctl_drop_caches,
1142 .maxlen = sizeof(int),
1143 .mode = 0644,
1144 .proc_handler = drop_caches_sysctl_handler,
1146 #ifdef CONFIG_COMPACTION
1148 .procname = "compact_memory",
1149 .data = &sysctl_compact_memory,
1150 .maxlen = sizeof(int),
1151 .mode = 0200,
1152 .proc_handler = sysctl_compaction_handler,
1155 .procname = "extfrag_threshold",
1156 .data = &sysctl_extfrag_threshold,
1157 .maxlen = sizeof(int),
1158 .mode = 0644,
1159 .proc_handler = sysctl_extfrag_handler,
1160 .extra1 = &min_extfrag_threshold,
1161 .extra2 = &max_extfrag_threshold,
1164 #endif /* CONFIG_COMPACTION */
1166 .procname = "min_free_kbytes",
1167 .data = &min_free_kbytes,
1168 .maxlen = sizeof(min_free_kbytes),
1169 .mode = 0644,
1170 .proc_handler = min_free_kbytes_sysctl_handler,
1171 .extra1 = &zero,
1174 .procname = "percpu_pagelist_fraction",
1175 .data = &percpu_pagelist_fraction,
1176 .maxlen = sizeof(percpu_pagelist_fraction),
1177 .mode = 0644,
1178 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1179 .extra1 = &min_percpu_pagelist_fract,
1181 #ifdef CONFIG_MMU
1183 .procname = "max_map_count",
1184 .data = &sysctl_max_map_count,
1185 .maxlen = sizeof(sysctl_max_map_count),
1186 .mode = 0644,
1187 .proc_handler = proc_dointvec_minmax,
1188 .extra1 = &zero,
1190 #else
1192 .procname = "nr_trim_pages",
1193 .data = &sysctl_nr_trim_pages,
1194 .maxlen = sizeof(sysctl_nr_trim_pages),
1195 .mode = 0644,
1196 .proc_handler = proc_dointvec_minmax,
1197 .extra1 = &zero,
1199 #endif
1201 .procname = "laptop_mode",
1202 .data = &laptop_mode,
1203 .maxlen = sizeof(laptop_mode),
1204 .mode = 0644,
1205 .proc_handler = proc_dointvec_jiffies,
1208 .procname = "block_dump",
1209 .data = &block_dump,
1210 .maxlen = sizeof(block_dump),
1211 .mode = 0644,
1212 .proc_handler = proc_dointvec,
1213 .extra1 = &zero,
1216 .procname = "vfs_cache_pressure",
1217 .data = &sysctl_vfs_cache_pressure,
1218 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1219 .mode = 0644,
1220 .proc_handler = proc_dointvec,
1221 .extra1 = &zero,
1223 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1225 .procname = "legacy_va_layout",
1226 .data = &sysctl_legacy_va_layout,
1227 .maxlen = sizeof(sysctl_legacy_va_layout),
1228 .mode = 0644,
1229 .proc_handler = proc_dointvec,
1230 .extra1 = &zero,
1232 #endif
1233 #ifdef CONFIG_NUMA
1235 .procname = "zone_reclaim_mode",
1236 .data = &zone_reclaim_mode,
1237 .maxlen = sizeof(zone_reclaim_mode),
1238 .mode = 0644,
1239 .proc_handler = proc_dointvec,
1240 .extra1 = &zero,
1243 .procname = "min_unmapped_ratio",
1244 .data = &sysctl_min_unmapped_ratio,
1245 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1246 .mode = 0644,
1247 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1248 .extra1 = &zero,
1249 .extra2 = &one_hundred,
1252 .procname = "min_slab_ratio",
1253 .data = &sysctl_min_slab_ratio,
1254 .maxlen = sizeof(sysctl_min_slab_ratio),
1255 .mode = 0644,
1256 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1257 .extra1 = &zero,
1258 .extra2 = &one_hundred,
1260 #endif
1261 #ifdef CONFIG_SMP
1263 .procname = "stat_interval",
1264 .data = &sysctl_stat_interval,
1265 .maxlen = sizeof(sysctl_stat_interval),
1266 .mode = 0644,
1267 .proc_handler = proc_dointvec_jiffies,
1269 #endif
1270 #ifdef CONFIG_MMU
1272 .procname = "mmap_min_addr",
1273 .data = &dac_mmap_min_addr,
1274 .maxlen = sizeof(unsigned long),
1275 .mode = 0644,
1276 .proc_handler = mmap_min_addr_handler,
1278 #endif
1279 #ifdef CONFIG_NUMA
1281 .procname = "numa_zonelist_order",
1282 .data = &numa_zonelist_order,
1283 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1284 .mode = 0644,
1285 .proc_handler = numa_zonelist_order_handler,
1287 #endif
1288 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1289 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1291 .procname = "vdso_enabled",
1292 .data = &vdso_enabled,
1293 .maxlen = sizeof(vdso_enabled),
1294 .mode = 0644,
1295 .proc_handler = proc_dointvec,
1296 .extra1 = &zero,
1298 #endif
1299 #ifdef CONFIG_HIGHMEM
1301 .procname = "highmem_is_dirtyable",
1302 .data = &vm_highmem_is_dirtyable,
1303 .maxlen = sizeof(vm_highmem_is_dirtyable),
1304 .mode = 0644,
1305 .proc_handler = proc_dointvec_minmax,
1306 .extra1 = &zero,
1307 .extra2 = &one,
1309 #endif
1311 .procname = "scan_unevictable_pages",
1312 .data = &scan_unevictable_pages,
1313 .maxlen = sizeof(scan_unevictable_pages),
1314 .mode = 0644,
1315 .proc_handler = scan_unevictable_handler,
1317 #ifdef CONFIG_MEMORY_FAILURE
1319 .procname = "memory_failure_early_kill",
1320 .data = &sysctl_memory_failure_early_kill,
1321 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1322 .mode = 0644,
1323 .proc_handler = proc_dointvec_minmax,
1324 .extra1 = &zero,
1325 .extra2 = &one,
1328 .procname = "memory_failure_recovery",
1329 .data = &sysctl_memory_failure_recovery,
1330 .maxlen = sizeof(sysctl_memory_failure_recovery),
1331 .mode = 0644,
1332 .proc_handler = proc_dointvec_minmax,
1333 .extra1 = &zero,
1334 .extra2 = &one,
1336 #endif
1340 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1341 static struct ctl_table binfmt_misc_table[] = {
1344 #endif
1346 static struct ctl_table fs_table[] = {
1348 .procname = "inode-nr",
1349 .data = &inodes_stat,
1350 .maxlen = 2*sizeof(int),
1351 .mode = 0444,
1352 .proc_handler = proc_nr_inodes,
1355 .procname = "inode-state",
1356 .data = &inodes_stat,
1357 .maxlen = 7*sizeof(int),
1358 .mode = 0444,
1359 .proc_handler = proc_nr_inodes,
1362 .procname = "file-nr",
1363 .data = &files_stat,
1364 .maxlen = sizeof(files_stat),
1365 .mode = 0444,
1366 .proc_handler = proc_nr_files,
1369 .procname = "file-max",
1370 .data = &files_stat.max_files,
1371 .maxlen = sizeof(files_stat.max_files),
1372 .mode = 0644,
1373 .proc_handler = proc_doulongvec_minmax,
1376 .procname = "nr_open",
1377 .data = &sysctl_nr_open,
1378 .maxlen = sizeof(int),
1379 .mode = 0644,
1380 .proc_handler = proc_dointvec_minmax,
1381 .extra1 = &sysctl_nr_open_min,
1382 .extra2 = &sysctl_nr_open_max,
1385 .procname = "dentry-state",
1386 .data = &dentry_stat,
1387 .maxlen = 6*sizeof(int),
1388 .mode = 0444,
1389 .proc_handler = proc_nr_dentry,
1392 .procname = "overflowuid",
1393 .data = &fs_overflowuid,
1394 .maxlen = sizeof(int),
1395 .mode = 0644,
1396 .proc_handler = proc_dointvec_minmax,
1397 .extra1 = &minolduid,
1398 .extra2 = &maxolduid,
1401 .procname = "overflowgid",
1402 .data = &fs_overflowgid,
1403 .maxlen = sizeof(int),
1404 .mode = 0644,
1405 .proc_handler = proc_dointvec_minmax,
1406 .extra1 = &minolduid,
1407 .extra2 = &maxolduid,
1409 #ifdef CONFIG_FILE_LOCKING
1411 .procname = "leases-enable",
1412 .data = &leases_enable,
1413 .maxlen = sizeof(int),
1414 .mode = 0644,
1415 .proc_handler = proc_dointvec,
1417 #endif
1418 #ifdef CONFIG_DNOTIFY
1420 .procname = "dir-notify-enable",
1421 .data = &dir_notify_enable,
1422 .maxlen = sizeof(int),
1423 .mode = 0644,
1424 .proc_handler = proc_dointvec,
1426 #endif
1427 #ifdef CONFIG_MMU
1428 #ifdef CONFIG_FILE_LOCKING
1430 .procname = "lease-break-time",
1431 .data = &lease_break_time,
1432 .maxlen = sizeof(int),
1433 .mode = 0644,
1434 .proc_handler = proc_dointvec,
1436 #endif
1437 #ifdef CONFIG_AIO
1439 .procname = "aio-nr",
1440 .data = &aio_nr,
1441 .maxlen = sizeof(aio_nr),
1442 .mode = 0444,
1443 .proc_handler = proc_doulongvec_minmax,
1446 .procname = "aio-max-nr",
1447 .data = &aio_max_nr,
1448 .maxlen = sizeof(aio_max_nr),
1449 .mode = 0644,
1450 .proc_handler = proc_doulongvec_minmax,
1452 #endif /* CONFIG_AIO */
1453 #ifdef CONFIG_INOTIFY_USER
1455 .procname = "inotify",
1456 .mode = 0555,
1457 .child = inotify_table,
1459 #endif
1460 #ifdef CONFIG_EPOLL
1462 .procname = "epoll",
1463 .mode = 0555,
1464 .child = epoll_table,
1466 #endif
1467 #endif
1469 .procname = "suid_dumpable",
1470 .data = &suid_dumpable,
1471 .maxlen = sizeof(int),
1472 .mode = 0644,
1473 .proc_handler = proc_dointvec_minmax,
1474 .extra1 = &zero,
1475 .extra2 = &two,
1477 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1479 .procname = "binfmt_misc",
1480 .mode = 0555,
1481 .child = binfmt_misc_table,
1483 #endif
1485 .procname = "pipe-max-size",
1486 .data = &pipe_max_size,
1487 .maxlen = sizeof(int),
1488 .mode = 0644,
1489 .proc_handler = &pipe_proc_fn,
1490 .extra1 = &pipe_min_size,
1495 static struct ctl_table debug_table[] = {
1496 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1497 defined(CONFIG_S390)
1499 .procname = "exception-trace",
1500 .data = &show_unhandled_signals,
1501 .maxlen = sizeof(int),
1502 .mode = 0644,
1503 .proc_handler = proc_dointvec
1505 #endif
1506 #if defined(CONFIG_OPTPROBES)
1508 .procname = "kprobes-optimization",
1509 .data = &sysctl_kprobes_optimization,
1510 .maxlen = sizeof(int),
1511 .mode = 0644,
1512 .proc_handler = proc_kprobes_optimization_handler,
1513 .extra1 = &zero,
1514 .extra2 = &one,
1516 #endif
1520 static struct ctl_table dev_table[] = {
1524 static DEFINE_SPINLOCK(sysctl_lock);
1526 /* called under sysctl_lock */
1527 static int use_table(struct ctl_table_header *p)
1529 if (unlikely(p->unregistering))
1530 return 0;
1531 p->used++;
1532 return 1;
1535 /* called under sysctl_lock */
1536 static void unuse_table(struct ctl_table_header *p)
1538 if (!--p->used)
1539 if (unlikely(p->unregistering))
1540 complete(p->unregistering);
1543 /* called under sysctl_lock, will reacquire if has to wait */
1544 static void start_unregistering(struct ctl_table_header *p)
1547 * if p->used is 0, nobody will ever touch that entry again;
1548 * we'll eliminate all paths to it before dropping sysctl_lock
1550 if (unlikely(p->used)) {
1551 struct completion wait;
1552 init_completion(&wait);
1553 p->unregistering = &wait;
1554 spin_unlock(&sysctl_lock);
1555 wait_for_completion(&wait);
1556 spin_lock(&sysctl_lock);
1557 } else {
1558 /* anything non-NULL; we'll never dereference it */
1559 p->unregistering = ERR_PTR(-EINVAL);
1562 * do not remove from the list until nobody holds it; walking the
1563 * list in do_sysctl() relies on that.
1565 list_del_init(&p->ctl_entry);
1568 void sysctl_head_get(struct ctl_table_header *head)
1570 spin_lock(&sysctl_lock);
1571 head->count++;
1572 spin_unlock(&sysctl_lock);
1575 static void free_head(struct rcu_head *rcu)
1577 kfree(container_of(rcu, struct ctl_table_header, rcu));
1580 void sysctl_head_put(struct ctl_table_header *head)
1582 spin_lock(&sysctl_lock);
1583 if (!--head->count)
1584 call_rcu(&head->rcu, free_head);
1585 spin_unlock(&sysctl_lock);
1588 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1590 if (!head)
1591 BUG();
1592 spin_lock(&sysctl_lock);
1593 if (!use_table(head))
1594 head = ERR_PTR(-ENOENT);
1595 spin_unlock(&sysctl_lock);
1596 return head;
1599 void sysctl_head_finish(struct ctl_table_header *head)
1601 if (!head)
1602 return;
1603 spin_lock(&sysctl_lock);
1604 unuse_table(head);
1605 spin_unlock(&sysctl_lock);
1608 static struct ctl_table_set *
1609 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1611 struct ctl_table_set *set = &root->default_set;
1612 if (root->lookup)
1613 set = root->lookup(root, namespaces);
1614 return set;
1617 static struct list_head *
1618 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1620 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1621 return &set->list;
1624 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1625 struct ctl_table_header *prev)
1627 struct ctl_table_root *root;
1628 struct list_head *header_list;
1629 struct ctl_table_header *head;
1630 struct list_head *tmp;
1632 spin_lock(&sysctl_lock);
1633 if (prev) {
1634 head = prev;
1635 tmp = &prev->ctl_entry;
1636 unuse_table(prev);
1637 goto next;
1639 tmp = &root_table_header.ctl_entry;
1640 for (;;) {
1641 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1643 if (!use_table(head))
1644 goto next;
1645 spin_unlock(&sysctl_lock);
1646 return head;
1647 next:
1648 root = head->root;
1649 tmp = tmp->next;
1650 header_list = lookup_header_list(root, namespaces);
1651 if (tmp != header_list)
1652 continue;
1654 do {
1655 root = list_entry(root->root_list.next,
1656 struct ctl_table_root, root_list);
1657 if (root == &sysctl_table_root)
1658 goto out;
1659 header_list = lookup_header_list(root, namespaces);
1660 } while (list_empty(header_list));
1661 tmp = header_list->next;
1663 out:
1664 spin_unlock(&sysctl_lock);
1665 return NULL;
1668 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1670 return __sysctl_head_next(current->nsproxy, prev);
1673 void register_sysctl_root(struct ctl_table_root *root)
1675 spin_lock(&sysctl_lock);
1676 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1677 spin_unlock(&sysctl_lock);
1681 * sysctl_perm does NOT grant the superuser all rights automatically, because
1682 * some sysctl variables are readonly even to root.
1685 static int test_perm(int mode, int op)
1687 if (!current_euid())
1688 mode >>= 6;
1689 else if (in_egroup_p(0))
1690 mode >>= 3;
1691 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1692 return 0;
1693 return -EACCES;
1696 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1698 int error;
1699 int mode;
1701 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1702 if (error)
1703 return error;
1705 if (root->permissions)
1706 mode = root->permissions(root, current->nsproxy, table);
1707 else
1708 mode = table->mode;
1710 return test_perm(mode, op);
1713 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1715 for (; table->procname; table++) {
1716 table->parent = parent;
1717 if (table->child)
1718 sysctl_set_parent(table, table->child);
1722 static __init int sysctl_init(void)
1724 sysctl_set_parent(NULL, root_table);
1725 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1726 sysctl_check_table(current->nsproxy, root_table);
1727 #endif
1728 return 0;
1731 core_initcall(sysctl_init);
1733 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1734 struct ctl_table *table)
1736 struct ctl_table *p;
1737 const char *s = branch->procname;
1739 /* branch should have named subdirectory as its first element */
1740 if (!s || !branch->child)
1741 return NULL;
1743 /* ... and nothing else */
1744 if (branch[1].procname)
1745 return NULL;
1747 /* table should contain subdirectory with the same name */
1748 for (p = table; p->procname; p++) {
1749 if (!p->child)
1750 continue;
1751 if (p->procname && strcmp(p->procname, s) == 0)
1752 return p;
1754 return NULL;
1757 /* see if attaching q to p would be an improvement */
1758 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1760 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1761 struct ctl_table *next;
1762 int is_better = 0;
1763 int not_in_parent = !p->attached_by;
1765 while ((next = is_branch_in(by, to)) != NULL) {
1766 if (by == q->attached_by)
1767 is_better = 1;
1768 if (to == p->attached_by)
1769 not_in_parent = 1;
1770 by = by->child;
1771 to = next->child;
1774 if (is_better && not_in_parent) {
1775 q->attached_by = by;
1776 q->attached_to = to;
1777 q->parent = p;
1782 * __register_sysctl_paths - register a sysctl hierarchy
1783 * @root: List of sysctl headers to register on
1784 * @namespaces: Data to compute which lists of sysctl entries are visible
1785 * @path: The path to the directory the sysctl table is in.
1786 * @table: the top-level table structure
1788 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1789 * array. A completely 0 filled entry terminates the table.
1791 * The members of the &struct ctl_table structure are used as follows:
1793 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1794 * enter a sysctl file
1796 * data - a pointer to data for use by proc_handler
1798 * maxlen - the maximum size in bytes of the data
1800 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1802 * child - a pointer to the child sysctl table if this entry is a directory, or
1803 * %NULL.
1805 * proc_handler - the text handler routine (described below)
1807 * de - for internal use by the sysctl routines
1809 * extra1, extra2 - extra pointers usable by the proc handler routines
1811 * Leaf nodes in the sysctl tree will be represented by a single file
1812 * under /proc; non-leaf nodes will be represented by directories.
1814 * sysctl(2) can automatically manage read and write requests through
1815 * the sysctl table. The data and maxlen fields of the ctl_table
1816 * struct enable minimal validation of the values being written to be
1817 * performed, and the mode field allows minimal authentication.
1819 * There must be a proc_handler routine for any terminal nodes
1820 * mirrored under /proc/sys (non-terminals are handled by a built-in
1821 * directory handler). Several default handlers are available to
1822 * cover common cases -
1824 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1825 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1826 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1828 * It is the handler's job to read the input buffer from user memory
1829 * and process it. The handler should return 0 on success.
1831 * This routine returns %NULL on a failure to register, and a pointer
1832 * to the table header on success.
1834 struct ctl_table_header *__register_sysctl_paths(
1835 struct ctl_table_root *root,
1836 struct nsproxy *namespaces,
1837 const struct ctl_path *path, struct ctl_table *table)
1839 struct ctl_table_header *header;
1840 struct ctl_table *new, **prevp;
1841 unsigned int n, npath;
1842 struct ctl_table_set *set;
1844 /* Count the path components */
1845 for (npath = 0; path[npath].procname; ++npath)
1849 * For each path component, allocate a 2-element ctl_table array.
1850 * The first array element will be filled with the sysctl entry
1851 * for this, the second will be the sentinel (procname == 0).
1853 * We allocate everything in one go so that we don't have to
1854 * worry about freeing additional memory in unregister_sysctl_table.
1856 header = kzalloc(sizeof(struct ctl_table_header) +
1857 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1858 if (!header)
1859 return NULL;
1861 new = (struct ctl_table *) (header + 1);
1863 /* Now connect the dots */
1864 prevp = &header->ctl_table;
1865 for (n = 0; n < npath; ++n, ++path) {
1866 /* Copy the procname */
1867 new->procname = path->procname;
1868 new->mode = 0555;
1870 *prevp = new;
1871 prevp = &new->child;
1873 new += 2;
1875 *prevp = table;
1876 header->ctl_table_arg = table;
1878 INIT_LIST_HEAD(&header->ctl_entry);
1879 header->used = 0;
1880 header->unregistering = NULL;
1881 header->root = root;
1882 sysctl_set_parent(NULL, header->ctl_table);
1883 header->count = 1;
1884 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1885 if (sysctl_check_table(namespaces, header->ctl_table)) {
1886 kfree(header);
1887 return NULL;
1889 #endif
1890 spin_lock(&sysctl_lock);
1891 header->set = lookup_header_set(root, namespaces);
1892 header->attached_by = header->ctl_table;
1893 header->attached_to = root_table;
1894 header->parent = &root_table_header;
1895 for (set = header->set; set; set = set->parent) {
1896 struct ctl_table_header *p;
1897 list_for_each_entry(p, &set->list, ctl_entry) {
1898 if (p->unregistering)
1899 continue;
1900 try_attach(p, header);
1903 header->parent->count++;
1904 list_add_tail(&header->ctl_entry, &header->set->list);
1905 spin_unlock(&sysctl_lock);
1907 return header;
1911 * register_sysctl_table_path - register a sysctl table hierarchy
1912 * @path: The path to the directory the sysctl table is in.
1913 * @table: the top-level table structure
1915 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1916 * array. A completely 0 filled entry terminates the table.
1918 * See __register_sysctl_paths for more details.
1920 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1921 struct ctl_table *table)
1923 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1924 path, table);
1928 * register_sysctl_table - register a sysctl table hierarchy
1929 * @table: the top-level table structure
1931 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1932 * array. A completely 0 filled entry terminates the table.
1934 * See register_sysctl_paths for more details.
1936 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1938 static const struct ctl_path null_path[] = { {} };
1940 return register_sysctl_paths(null_path, table);
1944 * unregister_sysctl_table - unregister a sysctl table hierarchy
1945 * @header: the header returned from register_sysctl_table
1947 * Unregisters the sysctl table and all children. proc entries may not
1948 * actually be removed until they are no longer used by anyone.
1950 void unregister_sysctl_table(struct ctl_table_header * header)
1952 might_sleep();
1954 if (header == NULL)
1955 return;
1957 spin_lock(&sysctl_lock);
1958 start_unregistering(header);
1959 if (!--header->parent->count) {
1960 WARN_ON(1);
1961 call_rcu(&header->parent->rcu, free_head);
1963 if (!--header->count)
1964 call_rcu(&header->rcu, free_head);
1965 spin_unlock(&sysctl_lock);
1968 int sysctl_is_seen(struct ctl_table_header *p)
1970 struct ctl_table_set *set = p->set;
1971 int res;
1972 spin_lock(&sysctl_lock);
1973 if (p->unregistering)
1974 res = 0;
1975 else if (!set->is_seen)
1976 res = 1;
1977 else
1978 res = set->is_seen(set);
1979 spin_unlock(&sysctl_lock);
1980 return res;
1983 void setup_sysctl_set(struct ctl_table_set *p,
1984 struct ctl_table_set *parent,
1985 int (*is_seen)(struct ctl_table_set *))
1987 INIT_LIST_HEAD(&p->list);
1988 p->parent = parent ? parent : &sysctl_table_root.default_set;
1989 p->is_seen = is_seen;
1992 #else /* !CONFIG_SYSCTL */
1993 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1995 return NULL;
1998 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1999 struct ctl_table *table)
2001 return NULL;
2004 void unregister_sysctl_table(struct ctl_table_header * table)
2008 void setup_sysctl_set(struct ctl_table_set *p,
2009 struct ctl_table_set *parent,
2010 int (*is_seen)(struct ctl_table_set *))
2014 void sysctl_head_put(struct ctl_table_header *head)
2018 #endif /* CONFIG_SYSCTL */
2021 * /proc/sys support
2024 #ifdef CONFIG_PROC_SYSCTL
2026 static int _proc_do_string(void* data, int maxlen, int write,
2027 void __user *buffer,
2028 size_t *lenp, loff_t *ppos)
2030 size_t len;
2031 char __user *p;
2032 char c;
2034 if (!data || !maxlen || !*lenp) {
2035 *lenp = 0;
2036 return 0;
2039 if (write) {
2040 len = 0;
2041 p = buffer;
2042 while (len < *lenp) {
2043 if (get_user(c, p++))
2044 return -EFAULT;
2045 if (c == 0 || c == '\n')
2046 break;
2047 len++;
2049 if (len >= maxlen)
2050 len = maxlen-1;
2051 if(copy_from_user(data, buffer, len))
2052 return -EFAULT;
2053 ((char *) data)[len] = 0;
2054 *ppos += *lenp;
2055 } else {
2056 len = strlen(data);
2057 if (len > maxlen)
2058 len = maxlen;
2060 if (*ppos > len) {
2061 *lenp = 0;
2062 return 0;
2065 data += *ppos;
2066 len -= *ppos;
2068 if (len > *lenp)
2069 len = *lenp;
2070 if (len)
2071 if(copy_to_user(buffer, data, len))
2072 return -EFAULT;
2073 if (len < *lenp) {
2074 if(put_user('\n', ((char __user *) buffer) + len))
2075 return -EFAULT;
2076 len++;
2078 *lenp = len;
2079 *ppos += len;
2081 return 0;
2085 * proc_dostring - read a string sysctl
2086 * @table: the sysctl table
2087 * @write: %TRUE if this is a write to the sysctl file
2088 * @buffer: the user buffer
2089 * @lenp: the size of the user buffer
2090 * @ppos: file position
2092 * Reads/writes a string from/to the user buffer. If the kernel
2093 * buffer provided is not large enough to hold the string, the
2094 * string is truncated. The copied string is %NULL-terminated.
2095 * If the string is being read by the user process, it is copied
2096 * and a newline '\n' is added. It is truncated if the buffer is
2097 * not large enough.
2099 * Returns 0 on success.
2101 int proc_dostring(struct ctl_table *table, int write,
2102 void __user *buffer, size_t *lenp, loff_t *ppos)
2104 return _proc_do_string(table->data, table->maxlen, write,
2105 buffer, lenp, ppos);
2108 static size_t proc_skip_spaces(char **buf)
2110 size_t ret;
2111 char *tmp = skip_spaces(*buf);
2112 ret = tmp - *buf;
2113 *buf = tmp;
2114 return ret;
2117 static void proc_skip_char(char **buf, size_t *size, const char v)
2119 while (*size) {
2120 if (**buf != v)
2121 break;
2122 (*size)--;
2123 (*buf)++;
2127 #define TMPBUFLEN 22
2129 * proc_get_long - reads an ASCII formatted integer from a user buffer
2131 * @buf: a kernel buffer
2132 * @size: size of the kernel buffer
2133 * @val: this is where the number will be stored
2134 * @neg: set to %TRUE if number is negative
2135 * @perm_tr: a vector which contains the allowed trailers
2136 * @perm_tr_len: size of the perm_tr vector
2137 * @tr: pointer to store the trailer character
2139 * In case of success %0 is returned and @buf and @size are updated with
2140 * the amount of bytes read. If @tr is non-NULL and a trailing
2141 * character exists (size is non-zero after returning from this
2142 * function), @tr is updated with the trailing character.
2144 static int proc_get_long(char **buf, size_t *size,
2145 unsigned long *val, bool *neg,
2146 const char *perm_tr, unsigned perm_tr_len, char *tr)
2148 int len;
2149 char *p, tmp[TMPBUFLEN];
2151 if (!*size)
2152 return -EINVAL;
2154 len = *size;
2155 if (len > TMPBUFLEN - 1)
2156 len = TMPBUFLEN - 1;
2158 memcpy(tmp, *buf, len);
2160 tmp[len] = 0;
2161 p = tmp;
2162 if (*p == '-' && *size > 1) {
2163 *neg = true;
2164 p++;
2165 } else
2166 *neg = false;
2167 if (!isdigit(*p))
2168 return -EINVAL;
2170 *val = simple_strtoul(p, &p, 0);
2172 len = p - tmp;
2174 /* We don't know if the next char is whitespace thus we may accept
2175 * invalid integers (e.g. 1234...a) or two integers instead of one
2176 * (e.g. 123...1). So lets not allow such large numbers. */
2177 if (len == TMPBUFLEN - 1)
2178 return -EINVAL;
2180 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2181 return -EINVAL;
2183 if (tr && (len < *size))
2184 *tr = *p;
2186 *buf += len;
2187 *size -= len;
2189 return 0;
2193 * proc_put_long - converts an integer to a decimal ASCII formatted string
2195 * @buf: the user buffer
2196 * @size: the size of the user buffer
2197 * @val: the integer to be converted
2198 * @neg: sign of the number, %TRUE for negative
2200 * In case of success %0 is returned and @buf and @size are updated with
2201 * the amount of bytes written.
2203 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2204 bool neg)
2206 int len;
2207 char tmp[TMPBUFLEN], *p = tmp;
2209 sprintf(p, "%s%lu", neg ? "-" : "", val);
2210 len = strlen(tmp);
2211 if (len > *size)
2212 len = *size;
2213 if (copy_to_user(*buf, tmp, len))
2214 return -EFAULT;
2215 *size -= len;
2216 *buf += len;
2217 return 0;
2219 #undef TMPBUFLEN
2221 static int proc_put_char(void __user **buf, size_t *size, char c)
2223 if (*size) {
2224 char __user **buffer = (char __user **)buf;
2225 if (put_user(c, *buffer))
2226 return -EFAULT;
2227 (*size)--, (*buffer)++;
2228 *buf = *buffer;
2230 return 0;
2233 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2234 int *valp,
2235 int write, void *data)
2237 if (write) {
2238 *valp = *negp ? -*lvalp : *lvalp;
2239 } else {
2240 int val = *valp;
2241 if (val < 0) {
2242 *negp = true;
2243 *lvalp = (unsigned long)-val;
2244 } else {
2245 *negp = false;
2246 *lvalp = (unsigned long)val;
2249 return 0;
2252 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2254 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2255 int write, void __user *buffer,
2256 size_t *lenp, loff_t *ppos,
2257 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2258 int write, void *data),
2259 void *data)
2261 int *i, vleft, first = 1, err = 0;
2262 unsigned long page = 0;
2263 size_t left;
2264 char *kbuf;
2266 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2267 *lenp = 0;
2268 return 0;
2271 i = (int *) tbl_data;
2272 vleft = table->maxlen / sizeof(*i);
2273 left = *lenp;
2275 if (!conv)
2276 conv = do_proc_dointvec_conv;
2278 if (write) {
2279 if (left > PAGE_SIZE - 1)
2280 left = PAGE_SIZE - 1;
2281 page = __get_free_page(GFP_TEMPORARY);
2282 kbuf = (char *) page;
2283 if (!kbuf)
2284 return -ENOMEM;
2285 if (copy_from_user(kbuf, buffer, left)) {
2286 err = -EFAULT;
2287 goto free;
2289 kbuf[left] = 0;
2292 for (; left && vleft--; i++, first=0) {
2293 unsigned long lval;
2294 bool neg;
2296 if (write) {
2297 left -= proc_skip_spaces(&kbuf);
2299 if (!left)
2300 break;
2301 err = proc_get_long(&kbuf, &left, &lval, &neg,
2302 proc_wspace_sep,
2303 sizeof(proc_wspace_sep), NULL);
2304 if (err)
2305 break;
2306 if (conv(&neg, &lval, i, 1, data)) {
2307 err = -EINVAL;
2308 break;
2310 } else {
2311 if (conv(&neg, &lval, i, 0, data)) {
2312 err = -EINVAL;
2313 break;
2315 if (!first)
2316 err = proc_put_char(&buffer, &left, '\t');
2317 if (err)
2318 break;
2319 err = proc_put_long(&buffer, &left, lval, neg);
2320 if (err)
2321 break;
2325 if (!write && !first && left && !err)
2326 err = proc_put_char(&buffer, &left, '\n');
2327 if (write && !err && left)
2328 left -= proc_skip_spaces(&kbuf);
2329 free:
2330 if (write) {
2331 free_page(page);
2332 if (first)
2333 return err ? : -EINVAL;
2335 *lenp -= left;
2336 *ppos += *lenp;
2337 return err;
2340 static int do_proc_dointvec(struct ctl_table *table, int write,
2341 void __user *buffer, size_t *lenp, loff_t *ppos,
2342 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2343 int write, void *data),
2344 void *data)
2346 return __do_proc_dointvec(table->data, table, write,
2347 buffer, lenp, ppos, conv, data);
2351 * proc_dointvec - read a vector of integers
2352 * @table: the sysctl table
2353 * @write: %TRUE if this is a write to the sysctl file
2354 * @buffer: the user buffer
2355 * @lenp: the size of the user buffer
2356 * @ppos: file position
2358 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2359 * values from/to the user buffer, treated as an ASCII string.
2361 * Returns 0 on success.
2363 int proc_dointvec(struct ctl_table *table, int write,
2364 void __user *buffer, size_t *lenp, loff_t *ppos)
2366 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2367 NULL,NULL);
2371 * Taint values can only be increased
2372 * This means we can safely use a temporary.
2374 static int proc_taint(struct ctl_table *table, int write,
2375 void __user *buffer, size_t *lenp, loff_t *ppos)
2377 struct ctl_table t;
2378 unsigned long tmptaint = get_taint();
2379 int err;
2381 if (write && !capable(CAP_SYS_ADMIN))
2382 return -EPERM;
2384 t = *table;
2385 t.data = &tmptaint;
2386 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2387 if (err < 0)
2388 return err;
2390 if (write) {
2392 * Poor man's atomic or. Not worth adding a primitive
2393 * to everyone's atomic.h for this
2395 int i;
2396 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2397 if ((tmptaint >> i) & 1)
2398 add_taint(i);
2402 return err;
2405 #ifdef CONFIG_PRINTK
2406 static int proc_dmesg_restrict(struct ctl_table *table, int write,
2407 void __user *buffer, size_t *lenp, loff_t *ppos)
2409 if (write && !capable(CAP_SYS_ADMIN))
2410 return -EPERM;
2412 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2414 #endif
2416 struct do_proc_dointvec_minmax_conv_param {
2417 int *min;
2418 int *max;
2421 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2422 int *valp,
2423 int write, void *data)
2425 struct do_proc_dointvec_minmax_conv_param *param = data;
2426 if (write) {
2427 int val = *negp ? -*lvalp : *lvalp;
2428 if ((param->min && *param->min > val) ||
2429 (param->max && *param->max < val))
2430 return -EINVAL;
2431 *valp = val;
2432 } else {
2433 int val = *valp;
2434 if (val < 0) {
2435 *negp = true;
2436 *lvalp = (unsigned long)-val;
2437 } else {
2438 *negp = false;
2439 *lvalp = (unsigned long)val;
2442 return 0;
2446 * proc_dointvec_minmax - read a vector of integers with min/max values
2447 * @table: the sysctl table
2448 * @write: %TRUE if this is a write to the sysctl file
2449 * @buffer: the user buffer
2450 * @lenp: the size of the user buffer
2451 * @ppos: file position
2453 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2454 * values from/to the user buffer, treated as an ASCII string.
2456 * This routine will ensure the values are within the range specified by
2457 * table->extra1 (min) and table->extra2 (max).
2459 * Returns 0 on success.
2461 int proc_dointvec_minmax(struct ctl_table *table, int write,
2462 void __user *buffer, size_t *lenp, loff_t *ppos)
2464 struct do_proc_dointvec_minmax_conv_param param = {
2465 .min = (int *) table->extra1,
2466 .max = (int *) table->extra2,
2468 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2469 do_proc_dointvec_minmax_conv, &param);
2472 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2473 void __user *buffer,
2474 size_t *lenp, loff_t *ppos,
2475 unsigned long convmul,
2476 unsigned long convdiv)
2478 unsigned long *i, *min, *max;
2479 int vleft, first = 1, err = 0;
2480 unsigned long page = 0;
2481 size_t left;
2482 char *kbuf;
2484 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2485 *lenp = 0;
2486 return 0;
2489 i = (unsigned long *) data;
2490 min = (unsigned long *) table->extra1;
2491 max = (unsigned long *) table->extra2;
2492 vleft = table->maxlen / sizeof(unsigned long);
2493 left = *lenp;
2495 if (write) {
2496 if (left > PAGE_SIZE - 1)
2497 left = PAGE_SIZE - 1;
2498 page = __get_free_page(GFP_TEMPORARY);
2499 kbuf = (char *) page;
2500 if (!kbuf)
2501 return -ENOMEM;
2502 if (copy_from_user(kbuf, buffer, left)) {
2503 err = -EFAULT;
2504 goto free;
2506 kbuf[left] = 0;
2509 for (; left && vleft--; i++, first = 0) {
2510 unsigned long val;
2512 if (write) {
2513 bool neg;
2515 left -= proc_skip_spaces(&kbuf);
2517 err = proc_get_long(&kbuf, &left, &val, &neg,
2518 proc_wspace_sep,
2519 sizeof(proc_wspace_sep), NULL);
2520 if (err)
2521 break;
2522 if (neg)
2523 continue;
2524 if ((min && val < *min) || (max && val > *max))
2525 continue;
2526 *i = val;
2527 } else {
2528 val = convdiv * (*i) / convmul;
2529 if (!first)
2530 err = proc_put_char(&buffer, &left, '\t');
2531 err = proc_put_long(&buffer, &left, val, false);
2532 if (err)
2533 break;
2537 if (!write && !first && left && !err)
2538 err = proc_put_char(&buffer, &left, '\n');
2539 if (write && !err)
2540 left -= proc_skip_spaces(&kbuf);
2541 free:
2542 if (write) {
2543 free_page(page);
2544 if (first)
2545 return err ? : -EINVAL;
2547 *lenp -= left;
2548 *ppos += *lenp;
2549 return err;
2552 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2553 void __user *buffer,
2554 size_t *lenp, loff_t *ppos,
2555 unsigned long convmul,
2556 unsigned long convdiv)
2558 return __do_proc_doulongvec_minmax(table->data, table, write,
2559 buffer, lenp, ppos, convmul, convdiv);
2563 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2564 * @table: the sysctl table
2565 * @write: %TRUE if this is a write to the sysctl file
2566 * @buffer: the user buffer
2567 * @lenp: the size of the user buffer
2568 * @ppos: file position
2570 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2571 * values from/to the user buffer, treated as an ASCII string.
2573 * This routine will ensure the values are within the range specified by
2574 * table->extra1 (min) and table->extra2 (max).
2576 * Returns 0 on success.
2578 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2579 void __user *buffer, size_t *lenp, loff_t *ppos)
2581 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2585 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2586 * @table: the sysctl table
2587 * @write: %TRUE if this is a write to the sysctl file
2588 * @buffer: the user buffer
2589 * @lenp: the size of the user buffer
2590 * @ppos: file position
2592 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2593 * values from/to the user buffer, treated as an ASCII string. The values
2594 * are treated as milliseconds, and converted to jiffies when they are stored.
2596 * This routine will ensure the values are within the range specified by
2597 * table->extra1 (min) and table->extra2 (max).
2599 * Returns 0 on success.
2601 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2602 void __user *buffer,
2603 size_t *lenp, loff_t *ppos)
2605 return do_proc_doulongvec_minmax(table, write, buffer,
2606 lenp, ppos, HZ, 1000l);
2610 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2611 int *valp,
2612 int write, void *data)
2614 if (write) {
2615 if (*lvalp > LONG_MAX / HZ)
2616 return 1;
2617 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2618 } else {
2619 int val = *valp;
2620 unsigned long lval;
2621 if (val < 0) {
2622 *negp = true;
2623 lval = (unsigned long)-val;
2624 } else {
2625 *negp = false;
2626 lval = (unsigned long)val;
2628 *lvalp = lval / HZ;
2630 return 0;
2633 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2634 int *valp,
2635 int write, void *data)
2637 if (write) {
2638 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2639 return 1;
2640 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2641 } else {
2642 int val = *valp;
2643 unsigned long lval;
2644 if (val < 0) {
2645 *negp = true;
2646 lval = (unsigned long)-val;
2647 } else {
2648 *negp = false;
2649 lval = (unsigned long)val;
2651 *lvalp = jiffies_to_clock_t(lval);
2653 return 0;
2656 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2657 int *valp,
2658 int write, void *data)
2660 if (write) {
2661 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2662 } else {
2663 int val = *valp;
2664 unsigned long lval;
2665 if (val < 0) {
2666 *negp = true;
2667 lval = (unsigned long)-val;
2668 } else {
2669 *negp = false;
2670 lval = (unsigned long)val;
2672 *lvalp = jiffies_to_msecs(lval);
2674 return 0;
2678 * proc_dointvec_jiffies - read a vector of integers as seconds
2679 * @table: the sysctl table
2680 * @write: %TRUE if this is a write to the sysctl file
2681 * @buffer: the user buffer
2682 * @lenp: the size of the user buffer
2683 * @ppos: file position
2685 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2686 * values from/to the user buffer, treated as an ASCII string.
2687 * The values read are assumed to be in seconds, and are converted into
2688 * jiffies.
2690 * Returns 0 on success.
2692 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2693 void __user *buffer, size_t *lenp, loff_t *ppos)
2695 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2696 do_proc_dointvec_jiffies_conv,NULL);
2700 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2701 * @table: the sysctl table
2702 * @write: %TRUE if this is a write to the sysctl file
2703 * @buffer: the user buffer
2704 * @lenp: the size of the user buffer
2705 * @ppos: pointer to the file position
2707 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2708 * values from/to the user buffer, treated as an ASCII string.
2709 * The values read are assumed to be in 1/USER_HZ seconds, and
2710 * are converted into jiffies.
2712 * Returns 0 on success.
2714 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2715 void __user *buffer, size_t *lenp, loff_t *ppos)
2717 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2718 do_proc_dointvec_userhz_jiffies_conv,NULL);
2722 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2723 * @table: the sysctl table
2724 * @write: %TRUE if this is a write to the sysctl file
2725 * @buffer: the user buffer
2726 * @lenp: the size of the user buffer
2727 * @ppos: file position
2728 * @ppos: the current position in the file
2730 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2731 * values from/to the user buffer, treated as an ASCII string.
2732 * The values read are assumed to be in 1/1000 seconds, and
2733 * are converted into jiffies.
2735 * Returns 0 on success.
2737 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2738 void __user *buffer, size_t *lenp, loff_t *ppos)
2740 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2741 do_proc_dointvec_ms_jiffies_conv, NULL);
2744 static int proc_do_cad_pid(struct ctl_table *table, int write,
2745 void __user *buffer, size_t *lenp, loff_t *ppos)
2747 struct pid *new_pid;
2748 pid_t tmp;
2749 int r;
2751 tmp = pid_vnr(cad_pid);
2753 r = __do_proc_dointvec(&tmp, table, write, buffer,
2754 lenp, ppos, NULL, NULL);
2755 if (r || !write)
2756 return r;
2758 new_pid = find_get_pid(tmp);
2759 if (!new_pid)
2760 return -ESRCH;
2762 put_pid(xchg(&cad_pid, new_pid));
2763 return 0;
2767 * proc_do_large_bitmap - read/write from/to a large bitmap
2768 * @table: the sysctl table
2769 * @write: %TRUE if this is a write to the sysctl file
2770 * @buffer: the user buffer
2771 * @lenp: the size of the user buffer
2772 * @ppos: file position
2774 * The bitmap is stored at table->data and the bitmap length (in bits)
2775 * in table->maxlen.
2777 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2778 * large bitmaps may be represented in a compact manner. Writing into
2779 * the file will clear the bitmap then update it with the given input.
2781 * Returns 0 on success.
2783 int proc_do_large_bitmap(struct ctl_table *table, int write,
2784 void __user *buffer, size_t *lenp, loff_t *ppos)
2786 int err = 0;
2787 bool first = 1;
2788 size_t left = *lenp;
2789 unsigned long bitmap_len = table->maxlen;
2790 unsigned long *bitmap = (unsigned long *) table->data;
2791 unsigned long *tmp_bitmap = NULL;
2792 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2794 if (!bitmap_len || !left || (*ppos && !write)) {
2795 *lenp = 0;
2796 return 0;
2799 if (write) {
2800 unsigned long page = 0;
2801 char *kbuf;
2803 if (left > PAGE_SIZE - 1)
2804 left = PAGE_SIZE - 1;
2806 page = __get_free_page(GFP_TEMPORARY);
2807 kbuf = (char *) page;
2808 if (!kbuf)
2809 return -ENOMEM;
2810 if (copy_from_user(kbuf, buffer, left)) {
2811 free_page(page);
2812 return -EFAULT;
2814 kbuf[left] = 0;
2816 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2817 GFP_KERNEL);
2818 if (!tmp_bitmap) {
2819 free_page(page);
2820 return -ENOMEM;
2822 proc_skip_char(&kbuf, &left, '\n');
2823 while (!err && left) {
2824 unsigned long val_a, val_b;
2825 bool neg;
2827 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2828 sizeof(tr_a), &c);
2829 if (err)
2830 break;
2831 if (val_a >= bitmap_len || neg) {
2832 err = -EINVAL;
2833 break;
2836 val_b = val_a;
2837 if (left) {
2838 kbuf++;
2839 left--;
2842 if (c == '-') {
2843 err = proc_get_long(&kbuf, &left, &val_b,
2844 &neg, tr_b, sizeof(tr_b),
2845 &c);
2846 if (err)
2847 break;
2848 if (val_b >= bitmap_len || neg ||
2849 val_a > val_b) {
2850 err = -EINVAL;
2851 break;
2853 if (left) {
2854 kbuf++;
2855 left--;
2859 while (val_a <= val_b)
2860 set_bit(val_a++, tmp_bitmap);
2862 first = 0;
2863 proc_skip_char(&kbuf, &left, '\n');
2865 free_page(page);
2866 } else {
2867 unsigned long bit_a, bit_b = 0;
2869 while (left) {
2870 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2871 if (bit_a >= bitmap_len)
2872 break;
2873 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2874 bit_a + 1) - 1;
2876 if (!first) {
2877 err = proc_put_char(&buffer, &left, ',');
2878 if (err)
2879 break;
2881 err = proc_put_long(&buffer, &left, bit_a, false);
2882 if (err)
2883 break;
2884 if (bit_a != bit_b) {
2885 err = proc_put_char(&buffer, &left, '-');
2886 if (err)
2887 break;
2888 err = proc_put_long(&buffer, &left, bit_b, false);
2889 if (err)
2890 break;
2893 first = 0; bit_b++;
2895 if (!err)
2896 err = proc_put_char(&buffer, &left, '\n');
2899 if (!err) {
2900 if (write) {
2901 if (*ppos)
2902 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2903 else
2904 memcpy(bitmap, tmp_bitmap,
2905 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2907 kfree(tmp_bitmap);
2908 *lenp -= left;
2909 *ppos += *lenp;
2910 return 0;
2911 } else {
2912 kfree(tmp_bitmap);
2913 return err;
2917 #else /* CONFIG_PROC_SYSCTL */
2919 int proc_dostring(struct ctl_table *table, int write,
2920 void __user *buffer, size_t *lenp, loff_t *ppos)
2922 return -ENOSYS;
2925 int proc_dointvec(struct ctl_table *table, int write,
2926 void __user *buffer, size_t *lenp, loff_t *ppos)
2928 return -ENOSYS;
2931 int proc_dointvec_minmax(struct ctl_table *table, int write,
2932 void __user *buffer, size_t *lenp, loff_t *ppos)
2934 return -ENOSYS;
2937 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2938 void __user *buffer, size_t *lenp, loff_t *ppos)
2940 return -ENOSYS;
2943 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2944 void __user *buffer, size_t *lenp, loff_t *ppos)
2946 return -ENOSYS;
2949 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2950 void __user *buffer, size_t *lenp, loff_t *ppos)
2952 return -ENOSYS;
2955 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2956 void __user *buffer, size_t *lenp, loff_t *ppos)
2958 return -ENOSYS;
2961 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2962 void __user *buffer,
2963 size_t *lenp, loff_t *ppos)
2965 return -ENOSYS;
2969 #endif /* CONFIG_PROC_SYSCTL */
2972 * No sense putting this after each symbol definition, twice,
2973 * exception granted :-)
2975 EXPORT_SYMBOL(proc_dointvec);
2976 EXPORT_SYMBOL(proc_dointvec_jiffies);
2977 EXPORT_SYMBOL(proc_dointvec_minmax);
2978 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2979 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2980 EXPORT_SYMBOL(proc_dostring);
2981 EXPORT_SYMBOL(proc_doulongvec_minmax);
2982 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2983 EXPORT_SYMBOL(register_sysctl_table);
2984 EXPORT_SYMBOL(register_sysctl_paths);
2985 EXPORT_SYMBOL(unregister_sysctl_table);