MIPS: Use single define for pending work on syscall exit
[linux-2.6/linux-mips.git] / kernel / sysctl.c
blobc0bb32414b174d575f836c9eb779f2e30cb793dd
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 int __maybe_unused three = 3;
121 static unsigned long one_ul = 1;
122 static int one_hundred = 100;
123 #ifdef CONFIG_PRINTK
124 static int ten_thousand = 10000;
125 #endif
127 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
128 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
130 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
131 static int maxolduid = 65535;
132 static int minolduid;
133 static int min_percpu_pagelist_fract = 8;
135 static int ngroups_max = NGROUPS_MAX;
137 #ifdef CONFIG_INOTIFY_USER
138 #include <linux/inotify.h>
139 #endif
140 #ifdef CONFIG_SPARC
141 #include <asm/system.h>
142 #endif
144 #ifdef CONFIG_SPARC64
145 extern int sysctl_tsb_ratio;
146 #endif
148 #ifdef __hppa__
149 extern int pwrsw_enabled;
150 extern int unaligned_enabled;
151 #endif
153 #ifdef CONFIG_S390
154 #ifdef CONFIG_MATHEMU
155 extern int sysctl_ieee_emulation_warnings;
156 #endif
157 extern int sysctl_userprocess_debug;
158 extern int spin_retry;
159 #endif
161 #ifdef CONFIG_IA64
162 extern int no_unaligned_warning;
163 extern int unaligned_dump_stack;
164 #endif
166 #ifdef CONFIG_PROC_SYSCTL
167 static int proc_do_cad_pid(struct ctl_table *table, int write,
168 void __user *buffer, size_t *lenp, loff_t *ppos);
169 static int proc_taint(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
171 #endif
173 #ifdef CONFIG_PRINTK
174 static int proc_dmesg_restrict(struct ctl_table *table, int write,
175 void __user *buffer, size_t *lenp, loff_t *ppos);
176 #endif
178 #ifdef CONFIG_MAGIC_SYSRQ
179 /* Note: sysrq code uses it's own private copy */
180 static int __sysrq_enabled = SYSRQ_DEFAULT_ENABLE;
182 static int sysrq_sysctl_handler(ctl_table *table, int write,
183 void __user *buffer, size_t *lenp,
184 loff_t *ppos)
186 int error;
188 error = proc_dointvec(table, write, buffer, lenp, ppos);
189 if (error)
190 return error;
192 if (write)
193 sysrq_toggle_support(__sysrq_enabled);
195 return 0;
198 #endif
200 static struct ctl_table root_table[];
201 static struct ctl_table_root sysctl_table_root;
202 static struct ctl_table_header root_table_header = {
203 {{.count = 1,
204 .ctl_table = root_table,
205 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),}},
206 .root = &sysctl_table_root,
207 .set = &sysctl_table_root.default_set,
209 static struct ctl_table_root sysctl_table_root = {
210 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
211 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
214 static struct ctl_table kern_table[];
215 static struct ctl_table vm_table[];
216 static struct ctl_table fs_table[];
217 static struct ctl_table debug_table[];
218 static struct ctl_table dev_table[];
219 extern struct ctl_table random_table[];
220 #ifdef CONFIG_EPOLL
221 extern struct ctl_table epoll_table[];
222 #endif
224 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
225 int sysctl_legacy_va_layout;
226 #endif
228 /* The default sysctl tables: */
230 static struct ctl_table root_table[] = {
232 .procname = "kernel",
233 .mode = 0555,
234 .child = kern_table,
237 .procname = "vm",
238 .mode = 0555,
239 .child = vm_table,
242 .procname = "fs",
243 .mode = 0555,
244 .child = fs_table,
247 .procname = "debug",
248 .mode = 0555,
249 .child = debug_table,
252 .procname = "dev",
253 .mode = 0555,
254 .child = dev_table,
259 #ifdef CONFIG_SCHED_DEBUG
260 static int min_sched_granularity_ns = 100000; /* 100 usecs */
261 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
262 static int min_wakeup_granularity_ns; /* 0 usecs */
263 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
264 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
265 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
266 #endif
268 #ifdef CONFIG_COMPACTION
269 static int min_extfrag_threshold;
270 static int max_extfrag_threshold = 1000;
271 #endif
273 static struct ctl_table kern_table[] = {
275 .procname = "sched_child_runs_first",
276 .data = &sysctl_sched_child_runs_first,
277 .maxlen = sizeof(unsigned int),
278 .mode = 0644,
279 .proc_handler = proc_dointvec,
281 #ifdef CONFIG_SCHED_DEBUG
283 .procname = "sched_min_granularity_ns",
284 .data = &sysctl_sched_min_granularity,
285 .maxlen = sizeof(unsigned int),
286 .mode = 0644,
287 .proc_handler = sched_proc_update_handler,
288 .extra1 = &min_sched_granularity_ns,
289 .extra2 = &max_sched_granularity_ns,
292 .procname = "sched_latency_ns",
293 .data = &sysctl_sched_latency,
294 .maxlen = sizeof(unsigned int),
295 .mode = 0644,
296 .proc_handler = sched_proc_update_handler,
297 .extra1 = &min_sched_granularity_ns,
298 .extra2 = &max_sched_granularity_ns,
301 .procname = "sched_wakeup_granularity_ns",
302 .data = &sysctl_sched_wakeup_granularity,
303 .maxlen = sizeof(unsigned int),
304 .mode = 0644,
305 .proc_handler = sched_proc_update_handler,
306 .extra1 = &min_wakeup_granularity_ns,
307 .extra2 = &max_wakeup_granularity_ns,
310 .procname = "sched_tunable_scaling",
311 .data = &sysctl_sched_tunable_scaling,
312 .maxlen = sizeof(enum sched_tunable_scaling),
313 .mode = 0644,
314 .proc_handler = sched_proc_update_handler,
315 .extra1 = &min_sched_tunable_scaling,
316 .extra2 = &max_sched_tunable_scaling,
319 .procname = "sched_migration_cost",
320 .data = &sysctl_sched_migration_cost,
321 .maxlen = sizeof(unsigned int),
322 .mode = 0644,
323 .proc_handler = proc_dointvec,
326 .procname = "sched_nr_migrate",
327 .data = &sysctl_sched_nr_migrate,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
330 .proc_handler = proc_dointvec,
333 .procname = "sched_time_avg",
334 .data = &sysctl_sched_time_avg,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
337 .proc_handler = proc_dointvec,
340 .procname = "sched_shares_window",
341 .data = &sysctl_sched_shares_window,
342 .maxlen = sizeof(unsigned int),
343 .mode = 0644,
344 .proc_handler = proc_dointvec,
347 .procname = "timer_migration",
348 .data = &sysctl_timer_migration,
349 .maxlen = sizeof(unsigned int),
350 .mode = 0644,
351 .proc_handler = proc_dointvec_minmax,
352 .extra1 = &zero,
353 .extra2 = &one,
355 #endif
357 .procname = "sched_rt_period_us",
358 .data = &sysctl_sched_rt_period,
359 .maxlen = sizeof(unsigned int),
360 .mode = 0644,
361 .proc_handler = sched_rt_handler,
364 .procname = "sched_rt_runtime_us",
365 .data = &sysctl_sched_rt_runtime,
366 .maxlen = sizeof(int),
367 .mode = 0644,
368 .proc_handler = sched_rt_handler,
370 #ifdef CONFIG_SCHED_AUTOGROUP
372 .procname = "sched_autogroup_enabled",
373 .data = &sysctl_sched_autogroup_enabled,
374 .maxlen = sizeof(unsigned int),
375 .mode = 0644,
376 .proc_handler = proc_dointvec_minmax,
377 .extra1 = &zero,
378 .extra2 = &one,
380 #endif
381 #ifdef CONFIG_PROVE_LOCKING
383 .procname = "prove_locking",
384 .data = &prove_locking,
385 .maxlen = sizeof(int),
386 .mode = 0644,
387 .proc_handler = proc_dointvec,
389 #endif
390 #ifdef CONFIG_LOCK_STAT
392 .procname = "lock_stat",
393 .data = &lock_stat,
394 .maxlen = sizeof(int),
395 .mode = 0644,
396 .proc_handler = proc_dointvec,
398 #endif
400 .procname = "panic",
401 .data = &panic_timeout,
402 .maxlen = sizeof(int),
403 .mode = 0644,
404 .proc_handler = proc_dointvec,
407 .procname = "core_uses_pid",
408 .data = &core_uses_pid,
409 .maxlen = sizeof(int),
410 .mode = 0644,
411 .proc_handler = proc_dointvec,
414 .procname = "core_pattern",
415 .data = core_pattern,
416 .maxlen = CORENAME_MAX_SIZE,
417 .mode = 0644,
418 .proc_handler = proc_dostring,
421 .procname = "core_pipe_limit",
422 .data = &core_pipe_limit,
423 .maxlen = sizeof(unsigned int),
424 .mode = 0644,
425 .proc_handler = proc_dointvec,
427 #ifdef CONFIG_PROC_SYSCTL
429 .procname = "tainted",
430 .maxlen = sizeof(long),
431 .mode = 0644,
432 .proc_handler = proc_taint,
434 #endif
435 #ifdef CONFIG_LATENCYTOP
437 .procname = "latencytop",
438 .data = &latencytop_enabled,
439 .maxlen = sizeof(int),
440 .mode = 0644,
441 .proc_handler = proc_dointvec,
443 #endif
444 #ifdef CONFIG_BLK_DEV_INITRD
446 .procname = "real-root-dev",
447 .data = &real_root_dev,
448 .maxlen = sizeof(int),
449 .mode = 0644,
450 .proc_handler = proc_dointvec,
452 #endif
454 .procname = "print-fatal-signals",
455 .data = &print_fatal_signals,
456 .maxlen = sizeof(int),
457 .mode = 0644,
458 .proc_handler = proc_dointvec,
460 #ifdef CONFIG_SPARC
462 .procname = "reboot-cmd",
463 .data = reboot_command,
464 .maxlen = 256,
465 .mode = 0644,
466 .proc_handler = proc_dostring,
469 .procname = "stop-a",
470 .data = &stop_a_enabled,
471 .maxlen = sizeof (int),
472 .mode = 0644,
473 .proc_handler = proc_dointvec,
476 .procname = "scons-poweroff",
477 .data = &scons_pwroff,
478 .maxlen = sizeof (int),
479 .mode = 0644,
480 .proc_handler = proc_dointvec,
482 #endif
483 #ifdef CONFIG_SPARC64
485 .procname = "tsb-ratio",
486 .data = &sysctl_tsb_ratio,
487 .maxlen = sizeof (int),
488 .mode = 0644,
489 .proc_handler = proc_dointvec,
491 #endif
492 #ifdef __hppa__
494 .procname = "soft-power",
495 .data = &pwrsw_enabled,
496 .maxlen = sizeof (int),
497 .mode = 0644,
498 .proc_handler = proc_dointvec,
501 .procname = "unaligned-trap",
502 .data = &unaligned_enabled,
503 .maxlen = sizeof (int),
504 .mode = 0644,
505 .proc_handler = proc_dointvec,
507 #endif
509 .procname = "ctrl-alt-del",
510 .data = &C_A_D,
511 .maxlen = sizeof(int),
512 .mode = 0644,
513 .proc_handler = proc_dointvec,
515 #ifdef CONFIG_FUNCTION_TRACER
517 .procname = "ftrace_enabled",
518 .data = &ftrace_enabled,
519 .maxlen = sizeof(int),
520 .mode = 0644,
521 .proc_handler = ftrace_enable_sysctl,
523 #endif
524 #ifdef CONFIG_STACK_TRACER
526 .procname = "stack_tracer_enabled",
527 .data = &stack_tracer_enabled,
528 .maxlen = sizeof(int),
529 .mode = 0644,
530 .proc_handler = stack_trace_sysctl,
532 #endif
533 #ifdef CONFIG_TRACING
535 .procname = "ftrace_dump_on_oops",
536 .data = &ftrace_dump_on_oops,
537 .maxlen = sizeof(int),
538 .mode = 0644,
539 .proc_handler = proc_dointvec,
541 #endif
542 #ifdef CONFIG_MODULES
544 .procname = "modprobe",
545 .data = &modprobe_path,
546 .maxlen = KMOD_PATH_LEN,
547 .mode = 0644,
548 .proc_handler = proc_dostring,
551 .procname = "modules_disabled",
552 .data = &modules_disabled,
553 .maxlen = sizeof(int),
554 .mode = 0644,
555 /* only handle a transition from default "0" to "1" */
556 .proc_handler = proc_dointvec_minmax,
557 .extra1 = &one,
558 .extra2 = &one,
560 #endif
561 #ifdef CONFIG_HOTPLUG
563 .procname = "hotplug",
564 .data = &uevent_helper,
565 .maxlen = UEVENT_HELPER_PATH_LEN,
566 .mode = 0644,
567 .proc_handler = proc_dostring,
569 #endif
570 #ifdef CONFIG_CHR_DEV_SG
572 .procname = "sg-big-buff",
573 .data = &sg_big_buff,
574 .maxlen = sizeof (int),
575 .mode = 0444,
576 .proc_handler = proc_dointvec,
578 #endif
579 #ifdef CONFIG_BSD_PROCESS_ACCT
581 .procname = "acct",
582 .data = &acct_parm,
583 .maxlen = 3*sizeof(int),
584 .mode = 0644,
585 .proc_handler = proc_dointvec,
587 #endif
588 #ifdef CONFIG_MAGIC_SYSRQ
590 .procname = "sysrq",
591 .data = &__sysrq_enabled,
592 .maxlen = sizeof (int),
593 .mode = 0644,
594 .proc_handler = sysrq_sysctl_handler,
596 #endif
597 #ifdef CONFIG_PROC_SYSCTL
599 .procname = "cad_pid",
600 .data = NULL,
601 .maxlen = sizeof (int),
602 .mode = 0600,
603 .proc_handler = proc_do_cad_pid,
605 #endif
607 .procname = "threads-max",
608 .data = &max_threads,
609 .maxlen = sizeof(int),
610 .mode = 0644,
611 .proc_handler = proc_dointvec,
614 .procname = "random",
615 .mode = 0555,
616 .child = random_table,
619 .procname = "overflowuid",
620 .data = &overflowuid,
621 .maxlen = sizeof(int),
622 .mode = 0644,
623 .proc_handler = proc_dointvec_minmax,
624 .extra1 = &minolduid,
625 .extra2 = &maxolduid,
628 .procname = "overflowgid",
629 .data = &overflowgid,
630 .maxlen = sizeof(int),
631 .mode = 0644,
632 .proc_handler = proc_dointvec_minmax,
633 .extra1 = &minolduid,
634 .extra2 = &maxolduid,
636 #ifdef CONFIG_S390
637 #ifdef CONFIG_MATHEMU
639 .procname = "ieee_emulation_warnings",
640 .data = &sysctl_ieee_emulation_warnings,
641 .maxlen = sizeof(int),
642 .mode = 0644,
643 .proc_handler = proc_dointvec,
645 #endif
647 .procname = "userprocess_debug",
648 .data = &show_unhandled_signals,
649 .maxlen = sizeof(int),
650 .mode = 0644,
651 .proc_handler = proc_dointvec,
653 #endif
655 .procname = "pid_max",
656 .data = &pid_max,
657 .maxlen = sizeof (int),
658 .mode = 0644,
659 .proc_handler = proc_dointvec_minmax,
660 .extra1 = &pid_max_min,
661 .extra2 = &pid_max_max,
664 .procname = "panic_on_oops",
665 .data = &panic_on_oops,
666 .maxlen = sizeof(int),
667 .mode = 0644,
668 .proc_handler = proc_dointvec,
670 #if defined CONFIG_PRINTK
672 .procname = "printk",
673 .data = &console_loglevel,
674 .maxlen = 4*sizeof(int),
675 .mode = 0644,
676 .proc_handler = proc_dointvec,
679 .procname = "printk_ratelimit",
680 .data = &printk_ratelimit_state.interval,
681 .maxlen = sizeof(int),
682 .mode = 0644,
683 .proc_handler = proc_dointvec_jiffies,
686 .procname = "printk_ratelimit_burst",
687 .data = &printk_ratelimit_state.burst,
688 .maxlen = sizeof(int),
689 .mode = 0644,
690 .proc_handler = proc_dointvec,
693 .procname = "printk_delay",
694 .data = &printk_delay_msec,
695 .maxlen = sizeof(int),
696 .mode = 0644,
697 .proc_handler = proc_dointvec_minmax,
698 .extra1 = &zero,
699 .extra2 = &ten_thousand,
702 .procname = "dmesg_restrict",
703 .data = &dmesg_restrict,
704 .maxlen = sizeof(int),
705 .mode = 0644,
706 .proc_handler = proc_dointvec_minmax,
707 .extra1 = &zero,
708 .extra2 = &one,
711 .procname = "kptr_restrict",
712 .data = &kptr_restrict,
713 .maxlen = sizeof(int),
714 .mode = 0644,
715 .proc_handler = proc_dmesg_restrict,
716 .extra1 = &zero,
717 .extra2 = &two,
719 #endif
721 .procname = "ngroups_max",
722 .data = &ngroups_max,
723 .maxlen = sizeof (int),
724 .mode = 0444,
725 .proc_handler = proc_dointvec,
727 #if defined(CONFIG_LOCKUP_DETECTOR)
729 .procname = "watchdog",
730 .data = &watchdog_enabled,
731 .maxlen = sizeof (int),
732 .mode = 0644,
733 .proc_handler = proc_dowatchdog_enabled,
736 .procname = "watchdog_thresh",
737 .data = &softlockup_thresh,
738 .maxlen = sizeof(int),
739 .mode = 0644,
740 .proc_handler = proc_dowatchdog_thresh,
741 .extra1 = &neg_one,
742 .extra2 = &sixty,
745 .procname = "softlockup_panic",
746 .data = &softlockup_panic,
747 .maxlen = sizeof(int),
748 .mode = 0644,
749 .proc_handler = proc_dointvec_minmax,
750 .extra1 = &zero,
751 .extra2 = &one,
754 .procname = "nmi_watchdog",
755 .data = &watchdog_enabled,
756 .maxlen = sizeof (int),
757 .mode = 0644,
758 .proc_handler = proc_dowatchdog_enabled,
760 #endif
761 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
763 .procname = "unknown_nmi_panic",
764 .data = &unknown_nmi_panic,
765 .maxlen = sizeof (int),
766 .mode = 0644,
767 .proc_handler = proc_dointvec,
769 #endif
770 #if defined(CONFIG_X86)
772 .procname = "panic_on_unrecovered_nmi",
773 .data = &panic_on_unrecovered_nmi,
774 .maxlen = sizeof(int),
775 .mode = 0644,
776 .proc_handler = proc_dointvec,
779 .procname = "panic_on_io_nmi",
780 .data = &panic_on_io_nmi,
781 .maxlen = sizeof(int),
782 .mode = 0644,
783 .proc_handler = proc_dointvec,
786 .procname = "bootloader_type",
787 .data = &bootloader_type,
788 .maxlen = sizeof (int),
789 .mode = 0444,
790 .proc_handler = proc_dointvec,
793 .procname = "bootloader_version",
794 .data = &bootloader_version,
795 .maxlen = sizeof (int),
796 .mode = 0444,
797 .proc_handler = proc_dointvec,
800 .procname = "kstack_depth_to_print",
801 .data = &kstack_depth_to_print,
802 .maxlen = sizeof(int),
803 .mode = 0644,
804 .proc_handler = proc_dointvec,
807 .procname = "io_delay_type",
808 .data = &io_delay_type,
809 .maxlen = sizeof(int),
810 .mode = 0644,
811 .proc_handler = proc_dointvec,
813 #endif
814 #if defined(CONFIG_MMU)
816 .procname = "randomize_va_space",
817 .data = &randomize_va_space,
818 .maxlen = sizeof(int),
819 .mode = 0644,
820 .proc_handler = proc_dointvec,
822 #endif
823 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
825 .procname = "spin_retry",
826 .data = &spin_retry,
827 .maxlen = sizeof (int),
828 .mode = 0644,
829 .proc_handler = proc_dointvec,
831 #endif
832 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
834 .procname = "acpi_video_flags",
835 .data = &acpi_realmode_flags,
836 .maxlen = sizeof (unsigned long),
837 .mode = 0644,
838 .proc_handler = proc_doulongvec_minmax,
840 #endif
841 #ifdef CONFIG_IA64
843 .procname = "ignore-unaligned-usertrap",
844 .data = &no_unaligned_warning,
845 .maxlen = sizeof (int),
846 .mode = 0644,
847 .proc_handler = proc_dointvec,
850 .procname = "unaligned-dump-stack",
851 .data = &unaligned_dump_stack,
852 .maxlen = sizeof (int),
853 .mode = 0644,
854 .proc_handler = proc_dointvec,
856 #endif
857 #ifdef CONFIG_DETECT_HUNG_TASK
859 .procname = "hung_task_panic",
860 .data = &sysctl_hung_task_panic,
861 .maxlen = sizeof(int),
862 .mode = 0644,
863 .proc_handler = proc_dointvec_minmax,
864 .extra1 = &zero,
865 .extra2 = &one,
868 .procname = "hung_task_check_count",
869 .data = &sysctl_hung_task_check_count,
870 .maxlen = sizeof(unsigned long),
871 .mode = 0644,
872 .proc_handler = proc_doulongvec_minmax,
875 .procname = "hung_task_timeout_secs",
876 .data = &sysctl_hung_task_timeout_secs,
877 .maxlen = sizeof(unsigned long),
878 .mode = 0644,
879 .proc_handler = proc_dohung_task_timeout_secs,
882 .procname = "hung_task_warnings",
883 .data = &sysctl_hung_task_warnings,
884 .maxlen = sizeof(unsigned long),
885 .mode = 0644,
886 .proc_handler = proc_doulongvec_minmax,
888 #endif
889 #ifdef CONFIG_COMPAT
891 .procname = "compat-log",
892 .data = &compat_log,
893 .maxlen = sizeof (int),
894 .mode = 0644,
895 .proc_handler = proc_dointvec,
897 #endif
898 #ifdef CONFIG_RT_MUTEXES
900 .procname = "max_lock_depth",
901 .data = &max_lock_depth,
902 .maxlen = sizeof(int),
903 .mode = 0644,
904 .proc_handler = proc_dointvec,
906 #endif
908 .procname = "poweroff_cmd",
909 .data = &poweroff_cmd,
910 .maxlen = POWEROFF_CMD_PATH_LEN,
911 .mode = 0644,
912 .proc_handler = proc_dostring,
914 #ifdef CONFIG_KEYS
916 .procname = "keys",
917 .mode = 0555,
918 .child = key_sysctls,
920 #endif
921 #ifdef CONFIG_RCU_TORTURE_TEST
923 .procname = "rcutorture_runnable",
924 .data = &rcutorture_runnable,
925 .maxlen = sizeof(int),
926 .mode = 0644,
927 .proc_handler = proc_dointvec,
929 #endif
930 #ifdef CONFIG_PERF_EVENTS
932 .procname = "perf_event_paranoid",
933 .data = &sysctl_perf_event_paranoid,
934 .maxlen = sizeof(sysctl_perf_event_paranoid),
935 .mode = 0644,
936 .proc_handler = proc_dointvec,
939 .procname = "perf_event_mlock_kb",
940 .data = &sysctl_perf_event_mlock,
941 .maxlen = sizeof(sysctl_perf_event_mlock),
942 .mode = 0644,
943 .proc_handler = proc_dointvec,
946 .procname = "perf_event_max_sample_rate",
947 .data = &sysctl_perf_event_sample_rate,
948 .maxlen = sizeof(sysctl_perf_event_sample_rate),
949 .mode = 0644,
950 .proc_handler = perf_proc_update_handler,
952 #endif
953 #ifdef CONFIG_KMEMCHECK
955 .procname = "kmemcheck",
956 .data = &kmemcheck_enabled,
957 .maxlen = sizeof(int),
958 .mode = 0644,
959 .proc_handler = proc_dointvec,
961 #endif
962 #ifdef CONFIG_BLOCK
964 .procname = "blk_iopoll",
965 .data = &blk_iopoll_enabled,
966 .maxlen = sizeof(int),
967 .mode = 0644,
968 .proc_handler = proc_dointvec,
970 #endif
974 static struct ctl_table vm_table[] = {
976 .procname = "overcommit_memory",
977 .data = &sysctl_overcommit_memory,
978 .maxlen = sizeof(sysctl_overcommit_memory),
979 .mode = 0644,
980 .proc_handler = proc_dointvec_minmax,
981 .extra1 = &zero,
982 .extra2 = &two,
985 .procname = "panic_on_oom",
986 .data = &sysctl_panic_on_oom,
987 .maxlen = sizeof(sysctl_panic_on_oom),
988 .mode = 0644,
989 .proc_handler = proc_dointvec_minmax,
990 .extra1 = &zero,
991 .extra2 = &two,
994 .procname = "oom_kill_allocating_task",
995 .data = &sysctl_oom_kill_allocating_task,
996 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
997 .mode = 0644,
998 .proc_handler = proc_dointvec,
1001 .procname = "oom_dump_tasks",
1002 .data = &sysctl_oom_dump_tasks,
1003 .maxlen = sizeof(sysctl_oom_dump_tasks),
1004 .mode = 0644,
1005 .proc_handler = proc_dointvec,
1008 .procname = "overcommit_ratio",
1009 .data = &sysctl_overcommit_ratio,
1010 .maxlen = sizeof(sysctl_overcommit_ratio),
1011 .mode = 0644,
1012 .proc_handler = proc_dointvec,
1015 .procname = "page-cluster",
1016 .data = &page_cluster,
1017 .maxlen = sizeof(int),
1018 .mode = 0644,
1019 .proc_handler = proc_dointvec_minmax,
1020 .extra1 = &zero,
1023 .procname = "dirty_background_ratio",
1024 .data = &dirty_background_ratio,
1025 .maxlen = sizeof(dirty_background_ratio),
1026 .mode = 0644,
1027 .proc_handler = dirty_background_ratio_handler,
1028 .extra1 = &zero,
1029 .extra2 = &one_hundred,
1032 .procname = "dirty_background_bytes",
1033 .data = &dirty_background_bytes,
1034 .maxlen = sizeof(dirty_background_bytes),
1035 .mode = 0644,
1036 .proc_handler = dirty_background_bytes_handler,
1037 .extra1 = &one_ul,
1040 .procname = "dirty_ratio",
1041 .data = &vm_dirty_ratio,
1042 .maxlen = sizeof(vm_dirty_ratio),
1043 .mode = 0644,
1044 .proc_handler = dirty_ratio_handler,
1045 .extra1 = &zero,
1046 .extra2 = &one_hundred,
1049 .procname = "dirty_bytes",
1050 .data = &vm_dirty_bytes,
1051 .maxlen = sizeof(vm_dirty_bytes),
1052 .mode = 0644,
1053 .proc_handler = dirty_bytes_handler,
1054 .extra1 = &dirty_bytes_min,
1057 .procname = "dirty_writeback_centisecs",
1058 .data = &dirty_writeback_interval,
1059 .maxlen = sizeof(dirty_writeback_interval),
1060 .mode = 0644,
1061 .proc_handler = dirty_writeback_centisecs_handler,
1064 .procname = "dirty_expire_centisecs",
1065 .data = &dirty_expire_interval,
1066 .maxlen = sizeof(dirty_expire_interval),
1067 .mode = 0644,
1068 .proc_handler = proc_dointvec_minmax,
1069 .extra1 = &zero,
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,
1145 .extra1 = &one,
1146 .extra2 = &three,
1148 #ifdef CONFIG_COMPACTION
1150 .procname = "compact_memory",
1151 .data = &sysctl_compact_memory,
1152 .maxlen = sizeof(int),
1153 .mode = 0200,
1154 .proc_handler = sysctl_compaction_handler,
1157 .procname = "extfrag_threshold",
1158 .data = &sysctl_extfrag_threshold,
1159 .maxlen = sizeof(int),
1160 .mode = 0644,
1161 .proc_handler = sysctl_extfrag_handler,
1162 .extra1 = &min_extfrag_threshold,
1163 .extra2 = &max_extfrag_threshold,
1166 #endif /* CONFIG_COMPACTION */
1168 .procname = "min_free_kbytes",
1169 .data = &min_free_kbytes,
1170 .maxlen = sizeof(min_free_kbytes),
1171 .mode = 0644,
1172 .proc_handler = min_free_kbytes_sysctl_handler,
1173 .extra1 = &zero,
1176 .procname = "percpu_pagelist_fraction",
1177 .data = &percpu_pagelist_fraction,
1178 .maxlen = sizeof(percpu_pagelist_fraction),
1179 .mode = 0644,
1180 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1181 .extra1 = &min_percpu_pagelist_fract,
1183 #ifdef CONFIG_MMU
1185 .procname = "max_map_count",
1186 .data = &sysctl_max_map_count,
1187 .maxlen = sizeof(sysctl_max_map_count),
1188 .mode = 0644,
1189 .proc_handler = proc_dointvec_minmax,
1190 .extra1 = &zero,
1192 #else
1194 .procname = "nr_trim_pages",
1195 .data = &sysctl_nr_trim_pages,
1196 .maxlen = sizeof(sysctl_nr_trim_pages),
1197 .mode = 0644,
1198 .proc_handler = proc_dointvec_minmax,
1199 .extra1 = &zero,
1201 #endif
1203 .procname = "laptop_mode",
1204 .data = &laptop_mode,
1205 .maxlen = sizeof(laptop_mode),
1206 .mode = 0644,
1207 .proc_handler = proc_dointvec_jiffies,
1210 .procname = "block_dump",
1211 .data = &block_dump,
1212 .maxlen = sizeof(block_dump),
1213 .mode = 0644,
1214 .proc_handler = proc_dointvec,
1215 .extra1 = &zero,
1218 .procname = "vfs_cache_pressure",
1219 .data = &sysctl_vfs_cache_pressure,
1220 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1221 .mode = 0644,
1222 .proc_handler = proc_dointvec,
1223 .extra1 = &zero,
1225 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1227 .procname = "legacy_va_layout",
1228 .data = &sysctl_legacy_va_layout,
1229 .maxlen = sizeof(sysctl_legacy_va_layout),
1230 .mode = 0644,
1231 .proc_handler = proc_dointvec,
1232 .extra1 = &zero,
1234 #endif
1235 #ifdef CONFIG_NUMA
1237 .procname = "zone_reclaim_mode",
1238 .data = &zone_reclaim_mode,
1239 .maxlen = sizeof(zone_reclaim_mode),
1240 .mode = 0644,
1241 .proc_handler = proc_dointvec,
1242 .extra1 = &zero,
1245 .procname = "min_unmapped_ratio",
1246 .data = &sysctl_min_unmapped_ratio,
1247 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1248 .mode = 0644,
1249 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1250 .extra1 = &zero,
1251 .extra2 = &one_hundred,
1254 .procname = "min_slab_ratio",
1255 .data = &sysctl_min_slab_ratio,
1256 .maxlen = sizeof(sysctl_min_slab_ratio),
1257 .mode = 0644,
1258 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1259 .extra1 = &zero,
1260 .extra2 = &one_hundred,
1262 #endif
1263 #ifdef CONFIG_SMP
1265 .procname = "stat_interval",
1266 .data = &sysctl_stat_interval,
1267 .maxlen = sizeof(sysctl_stat_interval),
1268 .mode = 0644,
1269 .proc_handler = proc_dointvec_jiffies,
1271 #endif
1272 #ifdef CONFIG_MMU
1274 .procname = "mmap_min_addr",
1275 .data = &dac_mmap_min_addr,
1276 .maxlen = sizeof(unsigned long),
1277 .mode = 0644,
1278 .proc_handler = mmap_min_addr_handler,
1280 #endif
1281 #ifdef CONFIG_NUMA
1283 .procname = "numa_zonelist_order",
1284 .data = &numa_zonelist_order,
1285 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1286 .mode = 0644,
1287 .proc_handler = numa_zonelist_order_handler,
1289 #endif
1290 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1291 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1293 .procname = "vdso_enabled",
1294 .data = &vdso_enabled,
1295 .maxlen = sizeof(vdso_enabled),
1296 .mode = 0644,
1297 .proc_handler = proc_dointvec,
1298 .extra1 = &zero,
1300 #endif
1301 #ifdef CONFIG_HIGHMEM
1303 .procname = "highmem_is_dirtyable",
1304 .data = &vm_highmem_is_dirtyable,
1305 .maxlen = sizeof(vm_highmem_is_dirtyable),
1306 .mode = 0644,
1307 .proc_handler = proc_dointvec_minmax,
1308 .extra1 = &zero,
1309 .extra2 = &one,
1311 #endif
1313 .procname = "scan_unevictable_pages",
1314 .data = &scan_unevictable_pages,
1315 .maxlen = sizeof(scan_unevictable_pages),
1316 .mode = 0644,
1317 .proc_handler = scan_unevictable_handler,
1319 #ifdef CONFIG_MEMORY_FAILURE
1321 .procname = "memory_failure_early_kill",
1322 .data = &sysctl_memory_failure_early_kill,
1323 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1324 .mode = 0644,
1325 .proc_handler = proc_dointvec_minmax,
1326 .extra1 = &zero,
1327 .extra2 = &one,
1330 .procname = "memory_failure_recovery",
1331 .data = &sysctl_memory_failure_recovery,
1332 .maxlen = sizeof(sysctl_memory_failure_recovery),
1333 .mode = 0644,
1334 .proc_handler = proc_dointvec_minmax,
1335 .extra1 = &zero,
1336 .extra2 = &one,
1338 #endif
1342 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1343 static struct ctl_table binfmt_misc_table[] = {
1346 #endif
1348 static struct ctl_table fs_table[] = {
1350 .procname = "inode-nr",
1351 .data = &inodes_stat,
1352 .maxlen = 2*sizeof(int),
1353 .mode = 0444,
1354 .proc_handler = proc_nr_inodes,
1357 .procname = "inode-state",
1358 .data = &inodes_stat,
1359 .maxlen = 7*sizeof(int),
1360 .mode = 0444,
1361 .proc_handler = proc_nr_inodes,
1364 .procname = "file-nr",
1365 .data = &files_stat,
1366 .maxlen = sizeof(files_stat),
1367 .mode = 0444,
1368 .proc_handler = proc_nr_files,
1371 .procname = "file-max",
1372 .data = &files_stat.max_files,
1373 .maxlen = sizeof(files_stat.max_files),
1374 .mode = 0644,
1375 .proc_handler = proc_doulongvec_minmax,
1378 .procname = "nr_open",
1379 .data = &sysctl_nr_open,
1380 .maxlen = sizeof(int),
1381 .mode = 0644,
1382 .proc_handler = proc_dointvec_minmax,
1383 .extra1 = &sysctl_nr_open_min,
1384 .extra2 = &sysctl_nr_open_max,
1387 .procname = "dentry-state",
1388 .data = &dentry_stat,
1389 .maxlen = 6*sizeof(int),
1390 .mode = 0444,
1391 .proc_handler = proc_nr_dentry,
1394 .procname = "overflowuid",
1395 .data = &fs_overflowuid,
1396 .maxlen = sizeof(int),
1397 .mode = 0644,
1398 .proc_handler = proc_dointvec_minmax,
1399 .extra1 = &minolduid,
1400 .extra2 = &maxolduid,
1403 .procname = "overflowgid",
1404 .data = &fs_overflowgid,
1405 .maxlen = sizeof(int),
1406 .mode = 0644,
1407 .proc_handler = proc_dointvec_minmax,
1408 .extra1 = &minolduid,
1409 .extra2 = &maxolduid,
1411 #ifdef CONFIG_FILE_LOCKING
1413 .procname = "leases-enable",
1414 .data = &leases_enable,
1415 .maxlen = sizeof(int),
1416 .mode = 0644,
1417 .proc_handler = proc_dointvec,
1419 #endif
1420 #ifdef CONFIG_DNOTIFY
1422 .procname = "dir-notify-enable",
1423 .data = &dir_notify_enable,
1424 .maxlen = sizeof(int),
1425 .mode = 0644,
1426 .proc_handler = proc_dointvec,
1428 #endif
1429 #ifdef CONFIG_MMU
1430 #ifdef CONFIG_FILE_LOCKING
1432 .procname = "lease-break-time",
1433 .data = &lease_break_time,
1434 .maxlen = sizeof(int),
1435 .mode = 0644,
1436 .proc_handler = proc_dointvec,
1438 #endif
1439 #ifdef CONFIG_AIO
1441 .procname = "aio-nr",
1442 .data = &aio_nr,
1443 .maxlen = sizeof(aio_nr),
1444 .mode = 0444,
1445 .proc_handler = proc_doulongvec_minmax,
1448 .procname = "aio-max-nr",
1449 .data = &aio_max_nr,
1450 .maxlen = sizeof(aio_max_nr),
1451 .mode = 0644,
1452 .proc_handler = proc_doulongvec_minmax,
1454 #endif /* CONFIG_AIO */
1455 #ifdef CONFIG_INOTIFY_USER
1457 .procname = "inotify",
1458 .mode = 0555,
1459 .child = inotify_table,
1461 #endif
1462 #ifdef CONFIG_EPOLL
1464 .procname = "epoll",
1465 .mode = 0555,
1466 .child = epoll_table,
1468 #endif
1469 #endif
1471 .procname = "suid_dumpable",
1472 .data = &suid_dumpable,
1473 .maxlen = sizeof(int),
1474 .mode = 0644,
1475 .proc_handler = proc_dointvec_minmax,
1476 .extra1 = &zero,
1477 .extra2 = &two,
1479 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1481 .procname = "binfmt_misc",
1482 .mode = 0555,
1483 .child = binfmt_misc_table,
1485 #endif
1487 .procname = "pipe-max-size",
1488 .data = &pipe_max_size,
1489 .maxlen = sizeof(int),
1490 .mode = 0644,
1491 .proc_handler = &pipe_proc_fn,
1492 .extra1 = &pipe_min_size,
1497 static struct ctl_table debug_table[] = {
1498 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1499 defined(CONFIG_S390)
1501 .procname = "exception-trace",
1502 .data = &show_unhandled_signals,
1503 .maxlen = sizeof(int),
1504 .mode = 0644,
1505 .proc_handler = proc_dointvec
1507 #endif
1508 #if defined(CONFIG_OPTPROBES)
1510 .procname = "kprobes-optimization",
1511 .data = &sysctl_kprobes_optimization,
1512 .maxlen = sizeof(int),
1513 .mode = 0644,
1514 .proc_handler = proc_kprobes_optimization_handler,
1515 .extra1 = &zero,
1516 .extra2 = &one,
1518 #endif
1522 static struct ctl_table dev_table[] = {
1526 static DEFINE_SPINLOCK(sysctl_lock);
1528 /* called under sysctl_lock */
1529 static int use_table(struct ctl_table_header *p)
1531 if (unlikely(p->unregistering))
1532 return 0;
1533 p->used++;
1534 return 1;
1537 /* called under sysctl_lock */
1538 static void unuse_table(struct ctl_table_header *p)
1540 if (!--p->used)
1541 if (unlikely(p->unregistering))
1542 complete(p->unregistering);
1545 /* called under sysctl_lock, will reacquire if has to wait */
1546 static void start_unregistering(struct ctl_table_header *p)
1549 * if p->used is 0, nobody will ever touch that entry again;
1550 * we'll eliminate all paths to it before dropping sysctl_lock
1552 if (unlikely(p->used)) {
1553 struct completion wait;
1554 init_completion(&wait);
1555 p->unregistering = &wait;
1556 spin_unlock(&sysctl_lock);
1557 wait_for_completion(&wait);
1558 spin_lock(&sysctl_lock);
1559 } else {
1560 /* anything non-NULL; we'll never dereference it */
1561 p->unregistering = ERR_PTR(-EINVAL);
1564 * do not remove from the list until nobody holds it; walking the
1565 * list in do_sysctl() relies on that.
1567 list_del_init(&p->ctl_entry);
1570 void sysctl_head_get(struct ctl_table_header *head)
1572 spin_lock(&sysctl_lock);
1573 head->count++;
1574 spin_unlock(&sysctl_lock);
1577 static void free_head(struct rcu_head *rcu)
1579 kfree(container_of(rcu, struct ctl_table_header, rcu));
1582 void sysctl_head_put(struct ctl_table_header *head)
1584 spin_lock(&sysctl_lock);
1585 if (!--head->count)
1586 call_rcu(&head->rcu, free_head);
1587 spin_unlock(&sysctl_lock);
1590 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1592 if (!head)
1593 BUG();
1594 spin_lock(&sysctl_lock);
1595 if (!use_table(head))
1596 head = ERR_PTR(-ENOENT);
1597 spin_unlock(&sysctl_lock);
1598 return head;
1601 void sysctl_head_finish(struct ctl_table_header *head)
1603 if (!head)
1604 return;
1605 spin_lock(&sysctl_lock);
1606 unuse_table(head);
1607 spin_unlock(&sysctl_lock);
1610 static struct ctl_table_set *
1611 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1613 struct ctl_table_set *set = &root->default_set;
1614 if (root->lookup)
1615 set = root->lookup(root, namespaces);
1616 return set;
1619 static struct list_head *
1620 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1622 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1623 return &set->list;
1626 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1627 struct ctl_table_header *prev)
1629 struct ctl_table_root *root;
1630 struct list_head *header_list;
1631 struct ctl_table_header *head;
1632 struct list_head *tmp;
1634 spin_lock(&sysctl_lock);
1635 if (prev) {
1636 head = prev;
1637 tmp = &prev->ctl_entry;
1638 unuse_table(prev);
1639 goto next;
1641 tmp = &root_table_header.ctl_entry;
1642 for (;;) {
1643 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1645 if (!use_table(head))
1646 goto next;
1647 spin_unlock(&sysctl_lock);
1648 return head;
1649 next:
1650 root = head->root;
1651 tmp = tmp->next;
1652 header_list = lookup_header_list(root, namespaces);
1653 if (tmp != header_list)
1654 continue;
1656 do {
1657 root = list_entry(root->root_list.next,
1658 struct ctl_table_root, root_list);
1659 if (root == &sysctl_table_root)
1660 goto out;
1661 header_list = lookup_header_list(root, namespaces);
1662 } while (list_empty(header_list));
1663 tmp = header_list->next;
1665 out:
1666 spin_unlock(&sysctl_lock);
1667 return NULL;
1670 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1672 return __sysctl_head_next(current->nsproxy, prev);
1675 void register_sysctl_root(struct ctl_table_root *root)
1677 spin_lock(&sysctl_lock);
1678 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1679 spin_unlock(&sysctl_lock);
1683 * sysctl_perm does NOT grant the superuser all rights automatically, because
1684 * some sysctl variables are readonly even to root.
1687 static int test_perm(int mode, int op)
1689 if (!current_euid())
1690 mode >>= 6;
1691 else if (in_egroup_p(0))
1692 mode >>= 3;
1693 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1694 return 0;
1695 return -EACCES;
1698 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1700 int mode;
1702 if (root->permissions)
1703 mode = root->permissions(root, current->nsproxy, table);
1704 else
1705 mode = table->mode;
1707 return test_perm(mode, op);
1710 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1712 for (; table->procname; table++) {
1713 table->parent = parent;
1714 if (table->child)
1715 sysctl_set_parent(table, table->child);
1719 static __init int sysctl_init(void)
1721 sysctl_set_parent(NULL, root_table);
1722 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1723 sysctl_check_table(current->nsproxy, root_table);
1724 #endif
1725 return 0;
1728 core_initcall(sysctl_init);
1730 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1731 struct ctl_table *table)
1733 struct ctl_table *p;
1734 const char *s = branch->procname;
1736 /* branch should have named subdirectory as its first element */
1737 if (!s || !branch->child)
1738 return NULL;
1740 /* ... and nothing else */
1741 if (branch[1].procname)
1742 return NULL;
1744 /* table should contain subdirectory with the same name */
1745 for (p = table; p->procname; p++) {
1746 if (!p->child)
1747 continue;
1748 if (p->procname && strcmp(p->procname, s) == 0)
1749 return p;
1751 return NULL;
1754 /* see if attaching q to p would be an improvement */
1755 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1757 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1758 struct ctl_table *next;
1759 int is_better = 0;
1760 int not_in_parent = !p->attached_by;
1762 while ((next = is_branch_in(by, to)) != NULL) {
1763 if (by == q->attached_by)
1764 is_better = 1;
1765 if (to == p->attached_by)
1766 not_in_parent = 1;
1767 by = by->child;
1768 to = next->child;
1771 if (is_better && not_in_parent) {
1772 q->attached_by = by;
1773 q->attached_to = to;
1774 q->parent = p;
1779 * __register_sysctl_paths - register a sysctl hierarchy
1780 * @root: List of sysctl headers to register on
1781 * @namespaces: Data to compute which lists of sysctl entries are visible
1782 * @path: The path to the directory the sysctl table is in.
1783 * @table: the top-level table structure
1785 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1786 * array. A completely 0 filled entry terminates the table.
1788 * The members of the &struct ctl_table structure are used as follows:
1790 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1791 * enter a sysctl file
1793 * data - a pointer to data for use by proc_handler
1795 * maxlen - the maximum size in bytes of the data
1797 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1799 * child - a pointer to the child sysctl table if this entry is a directory, or
1800 * %NULL.
1802 * proc_handler - the text handler routine (described below)
1804 * de - for internal use by the sysctl routines
1806 * extra1, extra2 - extra pointers usable by the proc handler routines
1808 * Leaf nodes in the sysctl tree will be represented by a single file
1809 * under /proc; non-leaf nodes will be represented by directories.
1811 * sysctl(2) can automatically manage read and write requests through
1812 * the sysctl table. The data and maxlen fields of the ctl_table
1813 * struct enable minimal validation of the values being written to be
1814 * performed, and the mode field allows minimal authentication.
1816 * There must be a proc_handler routine for any terminal nodes
1817 * mirrored under /proc/sys (non-terminals are handled by a built-in
1818 * directory handler). Several default handlers are available to
1819 * cover common cases -
1821 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1822 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1823 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1825 * It is the handler's job to read the input buffer from user memory
1826 * and process it. The handler should return 0 on success.
1828 * This routine returns %NULL on a failure to register, and a pointer
1829 * to the table header on success.
1831 struct ctl_table_header *__register_sysctl_paths(
1832 struct ctl_table_root *root,
1833 struct nsproxy *namespaces,
1834 const struct ctl_path *path, struct ctl_table *table)
1836 struct ctl_table_header *header;
1837 struct ctl_table *new, **prevp;
1838 unsigned int n, npath;
1839 struct ctl_table_set *set;
1841 /* Count the path components */
1842 for (npath = 0; path[npath].procname; ++npath)
1846 * For each path component, allocate a 2-element ctl_table array.
1847 * The first array element will be filled with the sysctl entry
1848 * for this, the second will be the sentinel (procname == 0).
1850 * We allocate everything in one go so that we don't have to
1851 * worry about freeing additional memory in unregister_sysctl_table.
1853 header = kzalloc(sizeof(struct ctl_table_header) +
1854 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1855 if (!header)
1856 return NULL;
1858 new = (struct ctl_table *) (header + 1);
1860 /* Now connect the dots */
1861 prevp = &header->ctl_table;
1862 for (n = 0; n < npath; ++n, ++path) {
1863 /* Copy the procname */
1864 new->procname = path->procname;
1865 new->mode = 0555;
1867 *prevp = new;
1868 prevp = &new->child;
1870 new += 2;
1872 *prevp = table;
1873 header->ctl_table_arg = table;
1875 INIT_LIST_HEAD(&header->ctl_entry);
1876 header->used = 0;
1877 header->unregistering = NULL;
1878 header->root = root;
1879 sysctl_set_parent(NULL, header->ctl_table);
1880 header->count = 1;
1881 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1882 if (sysctl_check_table(namespaces, header->ctl_table)) {
1883 kfree(header);
1884 return NULL;
1886 #endif
1887 spin_lock(&sysctl_lock);
1888 header->set = lookup_header_set(root, namespaces);
1889 header->attached_by = header->ctl_table;
1890 header->attached_to = root_table;
1891 header->parent = &root_table_header;
1892 for (set = header->set; set; set = set->parent) {
1893 struct ctl_table_header *p;
1894 list_for_each_entry(p, &set->list, ctl_entry) {
1895 if (p->unregistering)
1896 continue;
1897 try_attach(p, header);
1900 header->parent->count++;
1901 list_add_tail(&header->ctl_entry, &header->set->list);
1902 spin_unlock(&sysctl_lock);
1904 return header;
1908 * register_sysctl_table_path - register a sysctl table hierarchy
1909 * @path: The path to the directory the sysctl table is in.
1910 * @table: the top-level table structure
1912 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1913 * array. A completely 0 filled entry terminates the table.
1915 * See __register_sysctl_paths for more details.
1917 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1918 struct ctl_table *table)
1920 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1921 path, table);
1925 * register_sysctl_table - register a sysctl table hierarchy
1926 * @table: the top-level table structure
1928 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1929 * array. A completely 0 filled entry terminates the table.
1931 * See register_sysctl_paths for more details.
1933 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1935 static const struct ctl_path null_path[] = { {} };
1937 return register_sysctl_paths(null_path, table);
1941 * unregister_sysctl_table - unregister a sysctl table hierarchy
1942 * @header: the header returned from register_sysctl_table
1944 * Unregisters the sysctl table and all children. proc entries may not
1945 * actually be removed until they are no longer used by anyone.
1947 void unregister_sysctl_table(struct ctl_table_header * header)
1949 might_sleep();
1951 if (header == NULL)
1952 return;
1954 spin_lock(&sysctl_lock);
1955 start_unregistering(header);
1956 if (!--header->parent->count) {
1957 WARN_ON(1);
1958 call_rcu(&header->parent->rcu, free_head);
1960 if (!--header->count)
1961 call_rcu(&header->rcu, free_head);
1962 spin_unlock(&sysctl_lock);
1965 int sysctl_is_seen(struct ctl_table_header *p)
1967 struct ctl_table_set *set = p->set;
1968 int res;
1969 spin_lock(&sysctl_lock);
1970 if (p->unregistering)
1971 res = 0;
1972 else if (!set->is_seen)
1973 res = 1;
1974 else
1975 res = set->is_seen(set);
1976 spin_unlock(&sysctl_lock);
1977 return res;
1980 void setup_sysctl_set(struct ctl_table_set *p,
1981 struct ctl_table_set *parent,
1982 int (*is_seen)(struct ctl_table_set *))
1984 INIT_LIST_HEAD(&p->list);
1985 p->parent = parent ? parent : &sysctl_table_root.default_set;
1986 p->is_seen = is_seen;
1989 #else /* !CONFIG_SYSCTL */
1990 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1992 return NULL;
1995 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1996 struct ctl_table *table)
1998 return NULL;
2001 void unregister_sysctl_table(struct ctl_table_header * table)
2005 void setup_sysctl_set(struct ctl_table_set *p,
2006 struct ctl_table_set *parent,
2007 int (*is_seen)(struct ctl_table_set *))
2011 void sysctl_head_put(struct ctl_table_header *head)
2015 #endif /* CONFIG_SYSCTL */
2018 * /proc/sys support
2021 #ifdef CONFIG_PROC_SYSCTL
2023 static int _proc_do_string(void* data, int maxlen, int write,
2024 void __user *buffer,
2025 size_t *lenp, loff_t *ppos)
2027 size_t len;
2028 char __user *p;
2029 char c;
2031 if (!data || !maxlen || !*lenp) {
2032 *lenp = 0;
2033 return 0;
2036 if (write) {
2037 len = 0;
2038 p = buffer;
2039 while (len < *lenp) {
2040 if (get_user(c, p++))
2041 return -EFAULT;
2042 if (c == 0 || c == '\n')
2043 break;
2044 len++;
2046 if (len >= maxlen)
2047 len = maxlen-1;
2048 if(copy_from_user(data, buffer, len))
2049 return -EFAULT;
2050 ((char *) data)[len] = 0;
2051 *ppos += *lenp;
2052 } else {
2053 len = strlen(data);
2054 if (len > maxlen)
2055 len = maxlen;
2057 if (*ppos > len) {
2058 *lenp = 0;
2059 return 0;
2062 data += *ppos;
2063 len -= *ppos;
2065 if (len > *lenp)
2066 len = *lenp;
2067 if (len)
2068 if(copy_to_user(buffer, data, len))
2069 return -EFAULT;
2070 if (len < *lenp) {
2071 if(put_user('\n', ((char __user *) buffer) + len))
2072 return -EFAULT;
2073 len++;
2075 *lenp = len;
2076 *ppos += len;
2078 return 0;
2082 * proc_dostring - read a string sysctl
2083 * @table: the sysctl table
2084 * @write: %TRUE if this is a write to the sysctl file
2085 * @buffer: the user buffer
2086 * @lenp: the size of the user buffer
2087 * @ppos: file position
2089 * Reads/writes a string from/to the user buffer. If the kernel
2090 * buffer provided is not large enough to hold the string, the
2091 * string is truncated. The copied string is %NULL-terminated.
2092 * If the string is being read by the user process, it is copied
2093 * and a newline '\n' is added. It is truncated if the buffer is
2094 * not large enough.
2096 * Returns 0 on success.
2098 int proc_dostring(struct ctl_table *table, int write,
2099 void __user *buffer, size_t *lenp, loff_t *ppos)
2101 return _proc_do_string(table->data, table->maxlen, write,
2102 buffer, lenp, ppos);
2105 static size_t proc_skip_spaces(char **buf)
2107 size_t ret;
2108 char *tmp = skip_spaces(*buf);
2109 ret = tmp - *buf;
2110 *buf = tmp;
2111 return ret;
2114 static void proc_skip_char(char **buf, size_t *size, const char v)
2116 while (*size) {
2117 if (**buf != v)
2118 break;
2119 (*size)--;
2120 (*buf)++;
2124 #define TMPBUFLEN 22
2126 * proc_get_long - reads an ASCII formatted integer from a user buffer
2128 * @buf: a kernel buffer
2129 * @size: size of the kernel buffer
2130 * @val: this is where the number will be stored
2131 * @neg: set to %TRUE if number is negative
2132 * @perm_tr: a vector which contains the allowed trailers
2133 * @perm_tr_len: size of the perm_tr vector
2134 * @tr: pointer to store the trailer character
2136 * In case of success %0 is returned and @buf and @size are updated with
2137 * the amount of bytes read. If @tr is non-NULL and a trailing
2138 * character exists (size is non-zero after returning from this
2139 * function), @tr is updated with the trailing character.
2141 static int proc_get_long(char **buf, size_t *size,
2142 unsigned long *val, bool *neg,
2143 const char *perm_tr, unsigned perm_tr_len, char *tr)
2145 int len;
2146 char *p, tmp[TMPBUFLEN];
2148 if (!*size)
2149 return -EINVAL;
2151 len = *size;
2152 if (len > TMPBUFLEN - 1)
2153 len = TMPBUFLEN - 1;
2155 memcpy(tmp, *buf, len);
2157 tmp[len] = 0;
2158 p = tmp;
2159 if (*p == '-' && *size > 1) {
2160 *neg = true;
2161 p++;
2162 } else
2163 *neg = false;
2164 if (!isdigit(*p))
2165 return -EINVAL;
2167 *val = simple_strtoul(p, &p, 0);
2169 len = p - tmp;
2171 /* We don't know if the next char is whitespace thus we may accept
2172 * invalid integers (e.g. 1234...a) or two integers instead of one
2173 * (e.g. 123...1). So lets not allow such large numbers. */
2174 if (len == TMPBUFLEN - 1)
2175 return -EINVAL;
2177 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2178 return -EINVAL;
2180 if (tr && (len < *size))
2181 *tr = *p;
2183 *buf += len;
2184 *size -= len;
2186 return 0;
2190 * proc_put_long - converts an integer to a decimal ASCII formatted string
2192 * @buf: the user buffer
2193 * @size: the size of the user buffer
2194 * @val: the integer to be converted
2195 * @neg: sign of the number, %TRUE for negative
2197 * In case of success %0 is returned and @buf and @size are updated with
2198 * the amount of bytes written.
2200 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2201 bool neg)
2203 int len;
2204 char tmp[TMPBUFLEN], *p = tmp;
2206 sprintf(p, "%s%lu", neg ? "-" : "", val);
2207 len = strlen(tmp);
2208 if (len > *size)
2209 len = *size;
2210 if (copy_to_user(*buf, tmp, len))
2211 return -EFAULT;
2212 *size -= len;
2213 *buf += len;
2214 return 0;
2216 #undef TMPBUFLEN
2218 static int proc_put_char(void __user **buf, size_t *size, char c)
2220 if (*size) {
2221 char __user **buffer = (char __user **)buf;
2222 if (put_user(c, *buffer))
2223 return -EFAULT;
2224 (*size)--, (*buffer)++;
2225 *buf = *buffer;
2227 return 0;
2230 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2231 int *valp,
2232 int write, void *data)
2234 if (write) {
2235 *valp = *negp ? -*lvalp : *lvalp;
2236 } else {
2237 int val = *valp;
2238 if (val < 0) {
2239 *negp = true;
2240 *lvalp = (unsigned long)-val;
2241 } else {
2242 *negp = false;
2243 *lvalp = (unsigned long)val;
2246 return 0;
2249 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2251 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2252 int write, void __user *buffer,
2253 size_t *lenp, loff_t *ppos,
2254 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2255 int write, void *data),
2256 void *data)
2258 int *i, vleft, first = 1, err = 0;
2259 unsigned long page = 0;
2260 size_t left;
2261 char *kbuf;
2263 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2264 *lenp = 0;
2265 return 0;
2268 i = (int *) tbl_data;
2269 vleft = table->maxlen / sizeof(*i);
2270 left = *lenp;
2272 if (!conv)
2273 conv = do_proc_dointvec_conv;
2275 if (write) {
2276 if (left > PAGE_SIZE - 1)
2277 left = PAGE_SIZE - 1;
2278 page = __get_free_page(GFP_TEMPORARY);
2279 kbuf = (char *) page;
2280 if (!kbuf)
2281 return -ENOMEM;
2282 if (copy_from_user(kbuf, buffer, left)) {
2283 err = -EFAULT;
2284 goto free;
2286 kbuf[left] = 0;
2289 for (; left && vleft--; i++, first=0) {
2290 unsigned long lval;
2291 bool neg;
2293 if (write) {
2294 left -= proc_skip_spaces(&kbuf);
2296 if (!left)
2297 break;
2298 err = proc_get_long(&kbuf, &left, &lval, &neg,
2299 proc_wspace_sep,
2300 sizeof(proc_wspace_sep), NULL);
2301 if (err)
2302 break;
2303 if (conv(&neg, &lval, i, 1, data)) {
2304 err = -EINVAL;
2305 break;
2307 } else {
2308 if (conv(&neg, &lval, i, 0, data)) {
2309 err = -EINVAL;
2310 break;
2312 if (!first)
2313 err = proc_put_char(&buffer, &left, '\t');
2314 if (err)
2315 break;
2316 err = proc_put_long(&buffer, &left, lval, neg);
2317 if (err)
2318 break;
2322 if (!write && !first && left && !err)
2323 err = proc_put_char(&buffer, &left, '\n');
2324 if (write && !err && left)
2325 left -= proc_skip_spaces(&kbuf);
2326 free:
2327 if (write) {
2328 free_page(page);
2329 if (first)
2330 return err ? : -EINVAL;
2332 *lenp -= left;
2333 *ppos += *lenp;
2334 return err;
2337 static int do_proc_dointvec(struct ctl_table *table, int write,
2338 void __user *buffer, size_t *lenp, loff_t *ppos,
2339 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2340 int write, void *data),
2341 void *data)
2343 return __do_proc_dointvec(table->data, table, write,
2344 buffer, lenp, ppos, conv, data);
2348 * proc_dointvec - read a vector of integers
2349 * @table: the sysctl table
2350 * @write: %TRUE if this is a write to the sysctl file
2351 * @buffer: the user buffer
2352 * @lenp: the size of the user buffer
2353 * @ppos: file position
2355 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2356 * values from/to the user buffer, treated as an ASCII string.
2358 * Returns 0 on success.
2360 int proc_dointvec(struct ctl_table *table, int write,
2361 void __user *buffer, size_t *lenp, loff_t *ppos)
2363 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2364 NULL,NULL);
2368 * Taint values can only be increased
2369 * This means we can safely use a temporary.
2371 static int proc_taint(struct ctl_table *table, int write,
2372 void __user *buffer, size_t *lenp, loff_t *ppos)
2374 struct ctl_table t;
2375 unsigned long tmptaint = get_taint();
2376 int err;
2378 if (write && !capable(CAP_SYS_ADMIN))
2379 return -EPERM;
2381 t = *table;
2382 t.data = &tmptaint;
2383 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2384 if (err < 0)
2385 return err;
2387 if (write) {
2389 * Poor man's atomic or. Not worth adding a primitive
2390 * to everyone's atomic.h for this
2392 int i;
2393 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2394 if ((tmptaint >> i) & 1)
2395 add_taint(i);
2399 return err;
2402 #ifdef CONFIG_PRINTK
2403 static int proc_dmesg_restrict(struct ctl_table *table, int write,
2404 void __user *buffer, size_t *lenp, loff_t *ppos)
2406 if (write && !capable(CAP_SYS_ADMIN))
2407 return -EPERM;
2409 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2411 #endif
2413 struct do_proc_dointvec_minmax_conv_param {
2414 int *min;
2415 int *max;
2418 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2419 int *valp,
2420 int write, void *data)
2422 struct do_proc_dointvec_minmax_conv_param *param = data;
2423 if (write) {
2424 int val = *negp ? -*lvalp : *lvalp;
2425 if ((param->min && *param->min > val) ||
2426 (param->max && *param->max < val))
2427 return -EINVAL;
2428 *valp = val;
2429 } else {
2430 int val = *valp;
2431 if (val < 0) {
2432 *negp = true;
2433 *lvalp = (unsigned long)-val;
2434 } else {
2435 *negp = false;
2436 *lvalp = (unsigned long)val;
2439 return 0;
2443 * proc_dointvec_minmax - read a vector of integers with min/max values
2444 * @table: the sysctl table
2445 * @write: %TRUE if this is a write to the sysctl file
2446 * @buffer: the user buffer
2447 * @lenp: the size of the user buffer
2448 * @ppos: file position
2450 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2451 * values from/to the user buffer, treated as an ASCII string.
2453 * This routine will ensure the values are within the range specified by
2454 * table->extra1 (min) and table->extra2 (max).
2456 * Returns 0 on success.
2458 int proc_dointvec_minmax(struct ctl_table *table, int write,
2459 void __user *buffer, size_t *lenp, loff_t *ppos)
2461 struct do_proc_dointvec_minmax_conv_param param = {
2462 .min = (int *) table->extra1,
2463 .max = (int *) table->extra2,
2465 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2466 do_proc_dointvec_minmax_conv, &param);
2469 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2470 void __user *buffer,
2471 size_t *lenp, loff_t *ppos,
2472 unsigned long convmul,
2473 unsigned long convdiv)
2475 unsigned long *i, *min, *max;
2476 int vleft, first = 1, err = 0;
2477 unsigned long page = 0;
2478 size_t left;
2479 char *kbuf;
2481 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2482 *lenp = 0;
2483 return 0;
2486 i = (unsigned long *) data;
2487 min = (unsigned long *) table->extra1;
2488 max = (unsigned long *) table->extra2;
2489 vleft = table->maxlen / sizeof(unsigned long);
2490 left = *lenp;
2492 if (write) {
2493 if (left > PAGE_SIZE - 1)
2494 left = PAGE_SIZE - 1;
2495 page = __get_free_page(GFP_TEMPORARY);
2496 kbuf = (char *) page;
2497 if (!kbuf)
2498 return -ENOMEM;
2499 if (copy_from_user(kbuf, buffer, left)) {
2500 err = -EFAULT;
2501 goto free;
2503 kbuf[left] = 0;
2506 for (; left && vleft--; i++, first = 0) {
2507 unsigned long val;
2509 if (write) {
2510 bool neg;
2512 left -= proc_skip_spaces(&kbuf);
2514 err = proc_get_long(&kbuf, &left, &val, &neg,
2515 proc_wspace_sep,
2516 sizeof(proc_wspace_sep), NULL);
2517 if (err)
2518 break;
2519 if (neg)
2520 continue;
2521 if ((min && val < *min) || (max && val > *max))
2522 continue;
2523 *i = val;
2524 } else {
2525 val = convdiv * (*i) / convmul;
2526 if (!first)
2527 err = proc_put_char(&buffer, &left, '\t');
2528 err = proc_put_long(&buffer, &left, val, false);
2529 if (err)
2530 break;
2534 if (!write && !first && left && !err)
2535 err = proc_put_char(&buffer, &left, '\n');
2536 if (write && !err)
2537 left -= proc_skip_spaces(&kbuf);
2538 free:
2539 if (write) {
2540 free_page(page);
2541 if (first)
2542 return err ? : -EINVAL;
2544 *lenp -= left;
2545 *ppos += *lenp;
2546 return err;
2549 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2550 void __user *buffer,
2551 size_t *lenp, loff_t *ppos,
2552 unsigned long convmul,
2553 unsigned long convdiv)
2555 return __do_proc_doulongvec_minmax(table->data, table, write,
2556 buffer, lenp, ppos, convmul, convdiv);
2560 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2561 * @table: the sysctl table
2562 * @write: %TRUE if this is a write to the sysctl file
2563 * @buffer: the user buffer
2564 * @lenp: the size of the user buffer
2565 * @ppos: file position
2567 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2568 * values from/to the user buffer, treated as an ASCII string.
2570 * This routine will ensure the values are within the range specified by
2571 * table->extra1 (min) and table->extra2 (max).
2573 * Returns 0 on success.
2575 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2576 void __user *buffer, size_t *lenp, loff_t *ppos)
2578 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2582 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2583 * @table: the sysctl table
2584 * @write: %TRUE if this is a write to the sysctl file
2585 * @buffer: the user buffer
2586 * @lenp: the size of the user buffer
2587 * @ppos: file position
2589 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2590 * values from/to the user buffer, treated as an ASCII string. The values
2591 * are treated as milliseconds, and converted to jiffies when they are stored.
2593 * This routine will ensure the values are within the range specified by
2594 * table->extra1 (min) and table->extra2 (max).
2596 * Returns 0 on success.
2598 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2599 void __user *buffer,
2600 size_t *lenp, loff_t *ppos)
2602 return do_proc_doulongvec_minmax(table, write, buffer,
2603 lenp, ppos, HZ, 1000l);
2607 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2608 int *valp,
2609 int write, void *data)
2611 if (write) {
2612 if (*lvalp > LONG_MAX / HZ)
2613 return 1;
2614 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2615 } else {
2616 int val = *valp;
2617 unsigned long lval;
2618 if (val < 0) {
2619 *negp = true;
2620 lval = (unsigned long)-val;
2621 } else {
2622 *negp = false;
2623 lval = (unsigned long)val;
2625 *lvalp = lval / HZ;
2627 return 0;
2630 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2631 int *valp,
2632 int write, void *data)
2634 if (write) {
2635 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2636 return 1;
2637 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2638 } else {
2639 int val = *valp;
2640 unsigned long lval;
2641 if (val < 0) {
2642 *negp = true;
2643 lval = (unsigned long)-val;
2644 } else {
2645 *negp = false;
2646 lval = (unsigned long)val;
2648 *lvalp = jiffies_to_clock_t(lval);
2650 return 0;
2653 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2654 int *valp,
2655 int write, void *data)
2657 if (write) {
2658 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2659 } else {
2660 int val = *valp;
2661 unsigned long lval;
2662 if (val < 0) {
2663 *negp = true;
2664 lval = (unsigned long)-val;
2665 } else {
2666 *negp = false;
2667 lval = (unsigned long)val;
2669 *lvalp = jiffies_to_msecs(lval);
2671 return 0;
2675 * proc_dointvec_jiffies - read a vector of integers as seconds
2676 * @table: the sysctl table
2677 * @write: %TRUE if this is a write to the sysctl file
2678 * @buffer: the user buffer
2679 * @lenp: the size of the user buffer
2680 * @ppos: file position
2682 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2683 * values from/to the user buffer, treated as an ASCII string.
2684 * The values read are assumed to be in seconds, and are converted into
2685 * jiffies.
2687 * Returns 0 on success.
2689 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2690 void __user *buffer, size_t *lenp, loff_t *ppos)
2692 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2693 do_proc_dointvec_jiffies_conv,NULL);
2697 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2698 * @table: the sysctl table
2699 * @write: %TRUE if this is a write to the sysctl file
2700 * @buffer: the user buffer
2701 * @lenp: the size of the user buffer
2702 * @ppos: pointer to the file position
2704 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2705 * values from/to the user buffer, treated as an ASCII string.
2706 * The values read are assumed to be in 1/USER_HZ seconds, and
2707 * are converted into jiffies.
2709 * Returns 0 on success.
2711 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2712 void __user *buffer, size_t *lenp, loff_t *ppos)
2714 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2715 do_proc_dointvec_userhz_jiffies_conv,NULL);
2719 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2720 * @table: the sysctl table
2721 * @write: %TRUE if this is a write to the sysctl file
2722 * @buffer: the user buffer
2723 * @lenp: the size of the user buffer
2724 * @ppos: file position
2725 * @ppos: the current position in the file
2727 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2728 * values from/to the user buffer, treated as an ASCII string.
2729 * The values read are assumed to be in 1/1000 seconds, and
2730 * are converted into jiffies.
2732 * Returns 0 on success.
2734 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2735 void __user *buffer, size_t *lenp, loff_t *ppos)
2737 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2738 do_proc_dointvec_ms_jiffies_conv, NULL);
2741 static int proc_do_cad_pid(struct ctl_table *table, int write,
2742 void __user *buffer, size_t *lenp, loff_t *ppos)
2744 struct pid *new_pid;
2745 pid_t tmp;
2746 int r;
2748 tmp = pid_vnr(cad_pid);
2750 r = __do_proc_dointvec(&tmp, table, write, buffer,
2751 lenp, ppos, NULL, NULL);
2752 if (r || !write)
2753 return r;
2755 new_pid = find_get_pid(tmp);
2756 if (!new_pid)
2757 return -ESRCH;
2759 put_pid(xchg(&cad_pid, new_pid));
2760 return 0;
2764 * proc_do_large_bitmap - read/write from/to a large bitmap
2765 * @table: the sysctl table
2766 * @write: %TRUE if this is a write to the sysctl file
2767 * @buffer: the user buffer
2768 * @lenp: the size of the user buffer
2769 * @ppos: file position
2771 * The bitmap is stored at table->data and the bitmap length (in bits)
2772 * in table->maxlen.
2774 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2775 * large bitmaps may be represented in a compact manner. Writing into
2776 * the file will clear the bitmap then update it with the given input.
2778 * Returns 0 on success.
2780 int proc_do_large_bitmap(struct ctl_table *table, int write,
2781 void __user *buffer, size_t *lenp, loff_t *ppos)
2783 int err = 0;
2784 bool first = 1;
2785 size_t left = *lenp;
2786 unsigned long bitmap_len = table->maxlen;
2787 unsigned long *bitmap = (unsigned long *) table->data;
2788 unsigned long *tmp_bitmap = NULL;
2789 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2791 if (!bitmap_len || !left || (*ppos && !write)) {
2792 *lenp = 0;
2793 return 0;
2796 if (write) {
2797 unsigned long page = 0;
2798 char *kbuf;
2800 if (left > PAGE_SIZE - 1)
2801 left = PAGE_SIZE - 1;
2803 page = __get_free_page(GFP_TEMPORARY);
2804 kbuf = (char *) page;
2805 if (!kbuf)
2806 return -ENOMEM;
2807 if (copy_from_user(kbuf, buffer, left)) {
2808 free_page(page);
2809 return -EFAULT;
2811 kbuf[left] = 0;
2813 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2814 GFP_KERNEL);
2815 if (!tmp_bitmap) {
2816 free_page(page);
2817 return -ENOMEM;
2819 proc_skip_char(&kbuf, &left, '\n');
2820 while (!err && left) {
2821 unsigned long val_a, val_b;
2822 bool neg;
2824 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2825 sizeof(tr_a), &c);
2826 if (err)
2827 break;
2828 if (val_a >= bitmap_len || neg) {
2829 err = -EINVAL;
2830 break;
2833 val_b = val_a;
2834 if (left) {
2835 kbuf++;
2836 left--;
2839 if (c == '-') {
2840 err = proc_get_long(&kbuf, &left, &val_b,
2841 &neg, tr_b, sizeof(tr_b),
2842 &c);
2843 if (err)
2844 break;
2845 if (val_b >= bitmap_len || neg ||
2846 val_a > val_b) {
2847 err = -EINVAL;
2848 break;
2850 if (left) {
2851 kbuf++;
2852 left--;
2856 while (val_a <= val_b)
2857 set_bit(val_a++, tmp_bitmap);
2859 first = 0;
2860 proc_skip_char(&kbuf, &left, '\n');
2862 free_page(page);
2863 } else {
2864 unsigned long bit_a, bit_b = 0;
2866 while (left) {
2867 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2868 if (bit_a >= bitmap_len)
2869 break;
2870 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2871 bit_a + 1) - 1;
2873 if (!first) {
2874 err = proc_put_char(&buffer, &left, ',');
2875 if (err)
2876 break;
2878 err = proc_put_long(&buffer, &left, bit_a, false);
2879 if (err)
2880 break;
2881 if (bit_a != bit_b) {
2882 err = proc_put_char(&buffer, &left, '-');
2883 if (err)
2884 break;
2885 err = proc_put_long(&buffer, &left, bit_b, false);
2886 if (err)
2887 break;
2890 first = 0; bit_b++;
2892 if (!err)
2893 err = proc_put_char(&buffer, &left, '\n');
2896 if (!err) {
2897 if (write) {
2898 if (*ppos)
2899 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2900 else
2901 memcpy(bitmap, tmp_bitmap,
2902 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2904 kfree(tmp_bitmap);
2905 *lenp -= left;
2906 *ppos += *lenp;
2907 return 0;
2908 } else {
2909 kfree(tmp_bitmap);
2910 return err;
2914 #else /* CONFIG_PROC_SYSCTL */
2916 int proc_dostring(struct ctl_table *table, int write,
2917 void __user *buffer, size_t *lenp, loff_t *ppos)
2919 return -ENOSYS;
2922 int proc_dointvec(struct ctl_table *table, int write,
2923 void __user *buffer, size_t *lenp, loff_t *ppos)
2925 return -ENOSYS;
2928 int proc_dointvec_minmax(struct ctl_table *table, int write,
2929 void __user *buffer, size_t *lenp, loff_t *ppos)
2931 return -ENOSYS;
2934 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2935 void __user *buffer, size_t *lenp, loff_t *ppos)
2937 return -ENOSYS;
2940 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2941 void __user *buffer, size_t *lenp, loff_t *ppos)
2943 return -ENOSYS;
2946 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2947 void __user *buffer, size_t *lenp, loff_t *ppos)
2949 return -ENOSYS;
2952 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2953 void __user *buffer, size_t *lenp, loff_t *ppos)
2955 return -ENOSYS;
2958 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2959 void __user *buffer,
2960 size_t *lenp, loff_t *ppos)
2962 return -ENOSYS;
2966 #endif /* CONFIG_PROC_SYSCTL */
2969 * No sense putting this after each symbol definition, twice,
2970 * exception granted :-)
2972 EXPORT_SYMBOL(proc_dointvec);
2973 EXPORT_SYMBOL(proc_dointvec_jiffies);
2974 EXPORT_SYMBOL(proc_dointvec_minmax);
2975 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2976 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2977 EXPORT_SYMBOL(proc_dostring);
2978 EXPORT_SYMBOL(proc_doulongvec_minmax);
2979 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2980 EXPORT_SYMBOL(register_sysctl_table);
2981 EXPORT_SYMBOL(register_sysctl_paths);
2982 EXPORT_SYMBOL(unregister_sysctl_table);