xfs: introduce new logging API.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / kernel / sysctl.c
blobbc86bb32e12620c463699c9e461c836ce37733c1
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_MAGIC_SYSRQ
173 static int __sysrq_enabled; /* Note: sysrq code ises it's own private copy */
175 static int sysrq_sysctl_handler(ctl_table *table, int write,
176 void __user *buffer, size_t *lenp,
177 loff_t *ppos)
179 int error;
181 error = proc_dointvec(table, write, buffer, lenp, ppos);
182 if (error)
183 return error;
185 if (write)
186 sysrq_toggle_support(__sysrq_enabled);
188 return 0;
191 #endif
193 static struct ctl_table root_table[];
194 static struct ctl_table_root sysctl_table_root;
195 static struct ctl_table_header root_table_header = {
196 .count = 1,
197 .ctl_table = root_table,
198 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
199 .root = &sysctl_table_root,
200 .set = &sysctl_table_root.default_set,
202 static struct ctl_table_root sysctl_table_root = {
203 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
204 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
207 static struct ctl_table kern_table[];
208 static struct ctl_table vm_table[];
209 static struct ctl_table fs_table[];
210 static struct ctl_table debug_table[];
211 static struct ctl_table dev_table[];
212 extern struct ctl_table random_table[];
213 #ifdef CONFIG_EPOLL
214 extern struct ctl_table epoll_table[];
215 #endif
217 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
218 int sysctl_legacy_va_layout;
219 #endif
221 /* The default sysctl tables: */
223 static struct ctl_table root_table[] = {
225 .procname = "kernel",
226 .mode = 0555,
227 .child = kern_table,
230 .procname = "vm",
231 .mode = 0555,
232 .child = vm_table,
235 .procname = "fs",
236 .mode = 0555,
237 .child = fs_table,
240 .procname = "debug",
241 .mode = 0555,
242 .child = debug_table,
245 .procname = "dev",
246 .mode = 0555,
247 .child = dev_table,
252 #ifdef CONFIG_SCHED_DEBUG
253 static int min_sched_granularity_ns = 100000; /* 100 usecs */
254 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
255 static int min_wakeup_granularity_ns; /* 0 usecs */
256 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
257 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
258 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
259 #endif
261 #ifdef CONFIG_COMPACTION
262 static int min_extfrag_threshold;
263 static int max_extfrag_threshold = 1000;
264 #endif
266 static struct ctl_table kern_table[] = {
268 .procname = "sched_child_runs_first",
269 .data = &sysctl_sched_child_runs_first,
270 .maxlen = sizeof(unsigned int),
271 .mode = 0644,
272 .proc_handler = proc_dointvec,
274 #ifdef CONFIG_SCHED_DEBUG
276 .procname = "sched_min_granularity_ns",
277 .data = &sysctl_sched_min_granularity,
278 .maxlen = sizeof(unsigned int),
279 .mode = 0644,
280 .proc_handler = sched_proc_update_handler,
281 .extra1 = &min_sched_granularity_ns,
282 .extra2 = &max_sched_granularity_ns,
285 .procname = "sched_latency_ns",
286 .data = &sysctl_sched_latency,
287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
289 .proc_handler = sched_proc_update_handler,
290 .extra1 = &min_sched_granularity_ns,
291 .extra2 = &max_sched_granularity_ns,
294 .procname = "sched_wakeup_granularity_ns",
295 .data = &sysctl_sched_wakeup_granularity,
296 .maxlen = sizeof(unsigned int),
297 .mode = 0644,
298 .proc_handler = sched_proc_update_handler,
299 .extra1 = &min_wakeup_granularity_ns,
300 .extra2 = &max_wakeup_granularity_ns,
303 .procname = "sched_tunable_scaling",
304 .data = &sysctl_sched_tunable_scaling,
305 .maxlen = sizeof(enum sched_tunable_scaling),
306 .mode = 0644,
307 .proc_handler = sched_proc_update_handler,
308 .extra1 = &min_sched_tunable_scaling,
309 .extra2 = &max_sched_tunable_scaling,
312 .procname = "sched_migration_cost",
313 .data = &sysctl_sched_migration_cost,
314 .maxlen = sizeof(unsigned int),
315 .mode = 0644,
316 .proc_handler = proc_dointvec,
319 .procname = "sched_nr_migrate",
320 .data = &sysctl_sched_nr_migrate,
321 .maxlen = sizeof(unsigned int),
322 .mode = 0644,
323 .proc_handler = proc_dointvec,
326 .procname = "sched_time_avg",
327 .data = &sysctl_sched_time_avg,
328 .maxlen = sizeof(unsigned int),
329 .mode = 0644,
330 .proc_handler = proc_dointvec,
333 .procname = "sched_shares_window",
334 .data = &sysctl_sched_shares_window,
335 .maxlen = sizeof(unsigned int),
336 .mode = 0644,
337 .proc_handler = proc_dointvec,
340 .procname = "timer_migration",
341 .data = &sysctl_timer_migration,
342 .maxlen = sizeof(unsigned int),
343 .mode = 0644,
344 .proc_handler = proc_dointvec_minmax,
345 .extra1 = &zero,
346 .extra2 = &one,
348 #endif
350 .procname = "sched_rt_period_us",
351 .data = &sysctl_sched_rt_period,
352 .maxlen = sizeof(unsigned int),
353 .mode = 0644,
354 .proc_handler = sched_rt_handler,
357 .procname = "sched_rt_runtime_us",
358 .data = &sysctl_sched_rt_runtime,
359 .maxlen = sizeof(int),
360 .mode = 0644,
361 .proc_handler = sched_rt_handler,
364 .procname = "sched_compat_yield",
365 .data = &sysctl_sched_compat_yield,
366 .maxlen = sizeof(unsigned int),
367 .mode = 0644,
368 .proc_handler = proc_dointvec,
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,
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_dointvec_minmax,
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 = proc_dointvec,
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,
983 .procname = "panic_on_oom",
984 .data = &sysctl_panic_on_oom,
985 .maxlen = sizeof(sysctl_panic_on_oom),
986 .mode = 0644,
987 .proc_handler = proc_dointvec,
990 .procname = "oom_kill_allocating_task",
991 .data = &sysctl_oom_kill_allocating_task,
992 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
993 .mode = 0644,
994 .proc_handler = proc_dointvec,
997 .procname = "oom_dump_tasks",
998 .data = &sysctl_oom_dump_tasks,
999 .maxlen = sizeof(sysctl_oom_dump_tasks),
1000 .mode = 0644,
1001 .proc_handler = proc_dointvec,
1004 .procname = "overcommit_ratio",
1005 .data = &sysctl_overcommit_ratio,
1006 .maxlen = sizeof(sysctl_overcommit_ratio),
1007 .mode = 0644,
1008 .proc_handler = proc_dointvec,
1011 .procname = "page-cluster",
1012 .data = &page_cluster,
1013 .maxlen = sizeof(int),
1014 .mode = 0644,
1015 .proc_handler = proc_dointvec,
1018 .procname = "dirty_background_ratio",
1019 .data = &dirty_background_ratio,
1020 .maxlen = sizeof(dirty_background_ratio),
1021 .mode = 0644,
1022 .proc_handler = dirty_background_ratio_handler,
1023 .extra1 = &zero,
1024 .extra2 = &one_hundred,
1027 .procname = "dirty_background_bytes",
1028 .data = &dirty_background_bytes,
1029 .maxlen = sizeof(dirty_background_bytes),
1030 .mode = 0644,
1031 .proc_handler = dirty_background_bytes_handler,
1032 .extra1 = &one_ul,
1035 .procname = "dirty_ratio",
1036 .data = &vm_dirty_ratio,
1037 .maxlen = sizeof(vm_dirty_ratio),
1038 .mode = 0644,
1039 .proc_handler = dirty_ratio_handler,
1040 .extra1 = &zero,
1041 .extra2 = &one_hundred,
1044 .procname = "dirty_bytes",
1045 .data = &vm_dirty_bytes,
1046 .maxlen = sizeof(vm_dirty_bytes),
1047 .mode = 0644,
1048 .proc_handler = dirty_bytes_handler,
1049 .extra1 = &dirty_bytes_min,
1052 .procname = "dirty_writeback_centisecs",
1053 .data = &dirty_writeback_interval,
1054 .maxlen = sizeof(dirty_writeback_interval),
1055 .mode = 0644,
1056 .proc_handler = dirty_writeback_centisecs_handler,
1059 .procname = "dirty_expire_centisecs",
1060 .data = &dirty_expire_interval,
1061 .maxlen = sizeof(dirty_expire_interval),
1062 .mode = 0644,
1063 .proc_handler = proc_dointvec,
1066 .procname = "nr_pdflush_threads",
1067 .data = &nr_pdflush_threads,
1068 .maxlen = sizeof nr_pdflush_threads,
1069 .mode = 0444 /* read-only*/,
1070 .proc_handler = proc_dointvec,
1073 .procname = "swappiness",
1074 .data = &vm_swappiness,
1075 .maxlen = sizeof(vm_swappiness),
1076 .mode = 0644,
1077 .proc_handler = proc_dointvec_minmax,
1078 .extra1 = &zero,
1079 .extra2 = &one_hundred,
1081 #ifdef CONFIG_HUGETLB_PAGE
1083 .procname = "nr_hugepages",
1084 .data = NULL,
1085 .maxlen = sizeof(unsigned long),
1086 .mode = 0644,
1087 .proc_handler = hugetlb_sysctl_handler,
1088 .extra1 = (void *)&hugetlb_zero,
1089 .extra2 = (void *)&hugetlb_infinity,
1091 #ifdef CONFIG_NUMA
1093 .procname = "nr_hugepages_mempolicy",
1094 .data = NULL,
1095 .maxlen = sizeof(unsigned long),
1096 .mode = 0644,
1097 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1098 .extra1 = (void *)&hugetlb_zero,
1099 .extra2 = (void *)&hugetlb_infinity,
1101 #endif
1103 .procname = "hugetlb_shm_group",
1104 .data = &sysctl_hugetlb_shm_group,
1105 .maxlen = sizeof(gid_t),
1106 .mode = 0644,
1107 .proc_handler = proc_dointvec,
1110 .procname = "hugepages_treat_as_movable",
1111 .data = &hugepages_treat_as_movable,
1112 .maxlen = sizeof(int),
1113 .mode = 0644,
1114 .proc_handler = hugetlb_treat_movable_handler,
1117 .procname = "nr_overcommit_hugepages",
1118 .data = NULL,
1119 .maxlen = sizeof(unsigned long),
1120 .mode = 0644,
1121 .proc_handler = hugetlb_overcommit_handler,
1122 .extra1 = (void *)&hugetlb_zero,
1123 .extra2 = (void *)&hugetlb_infinity,
1125 #endif
1127 .procname = "lowmem_reserve_ratio",
1128 .data = &sysctl_lowmem_reserve_ratio,
1129 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1130 .mode = 0644,
1131 .proc_handler = lowmem_reserve_ratio_sysctl_handler,
1134 .procname = "drop_caches",
1135 .data = &sysctl_drop_caches,
1136 .maxlen = sizeof(int),
1137 .mode = 0644,
1138 .proc_handler = drop_caches_sysctl_handler,
1140 #ifdef CONFIG_COMPACTION
1142 .procname = "compact_memory",
1143 .data = &sysctl_compact_memory,
1144 .maxlen = sizeof(int),
1145 .mode = 0200,
1146 .proc_handler = sysctl_compaction_handler,
1149 .procname = "extfrag_threshold",
1150 .data = &sysctl_extfrag_threshold,
1151 .maxlen = sizeof(int),
1152 .mode = 0644,
1153 .proc_handler = sysctl_extfrag_handler,
1154 .extra1 = &min_extfrag_threshold,
1155 .extra2 = &max_extfrag_threshold,
1158 #endif /* CONFIG_COMPACTION */
1160 .procname = "min_free_kbytes",
1161 .data = &min_free_kbytes,
1162 .maxlen = sizeof(min_free_kbytes),
1163 .mode = 0644,
1164 .proc_handler = min_free_kbytes_sysctl_handler,
1165 .extra1 = &zero,
1168 .procname = "percpu_pagelist_fraction",
1169 .data = &percpu_pagelist_fraction,
1170 .maxlen = sizeof(percpu_pagelist_fraction),
1171 .mode = 0644,
1172 .proc_handler = percpu_pagelist_fraction_sysctl_handler,
1173 .extra1 = &min_percpu_pagelist_fract,
1175 #ifdef CONFIG_MMU
1177 .procname = "max_map_count",
1178 .data = &sysctl_max_map_count,
1179 .maxlen = sizeof(sysctl_max_map_count),
1180 .mode = 0644,
1181 .proc_handler = proc_dointvec_minmax,
1182 .extra1 = &zero,
1184 #else
1186 .procname = "nr_trim_pages",
1187 .data = &sysctl_nr_trim_pages,
1188 .maxlen = sizeof(sysctl_nr_trim_pages),
1189 .mode = 0644,
1190 .proc_handler = proc_dointvec_minmax,
1191 .extra1 = &zero,
1193 #endif
1195 .procname = "laptop_mode",
1196 .data = &laptop_mode,
1197 .maxlen = sizeof(laptop_mode),
1198 .mode = 0644,
1199 .proc_handler = proc_dointvec_jiffies,
1202 .procname = "block_dump",
1203 .data = &block_dump,
1204 .maxlen = sizeof(block_dump),
1205 .mode = 0644,
1206 .proc_handler = proc_dointvec,
1207 .extra1 = &zero,
1210 .procname = "vfs_cache_pressure",
1211 .data = &sysctl_vfs_cache_pressure,
1212 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1213 .mode = 0644,
1214 .proc_handler = proc_dointvec,
1215 .extra1 = &zero,
1217 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1219 .procname = "legacy_va_layout",
1220 .data = &sysctl_legacy_va_layout,
1221 .maxlen = sizeof(sysctl_legacy_va_layout),
1222 .mode = 0644,
1223 .proc_handler = proc_dointvec,
1224 .extra1 = &zero,
1226 #endif
1227 #ifdef CONFIG_NUMA
1229 .procname = "zone_reclaim_mode",
1230 .data = &zone_reclaim_mode,
1231 .maxlen = sizeof(zone_reclaim_mode),
1232 .mode = 0644,
1233 .proc_handler = proc_dointvec,
1234 .extra1 = &zero,
1237 .procname = "min_unmapped_ratio",
1238 .data = &sysctl_min_unmapped_ratio,
1239 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1240 .mode = 0644,
1241 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler,
1242 .extra1 = &zero,
1243 .extra2 = &one_hundred,
1246 .procname = "min_slab_ratio",
1247 .data = &sysctl_min_slab_ratio,
1248 .maxlen = sizeof(sysctl_min_slab_ratio),
1249 .mode = 0644,
1250 .proc_handler = sysctl_min_slab_ratio_sysctl_handler,
1251 .extra1 = &zero,
1252 .extra2 = &one_hundred,
1254 #endif
1255 #ifdef CONFIG_SMP
1257 .procname = "stat_interval",
1258 .data = &sysctl_stat_interval,
1259 .maxlen = sizeof(sysctl_stat_interval),
1260 .mode = 0644,
1261 .proc_handler = proc_dointvec_jiffies,
1263 #endif
1264 #ifdef CONFIG_MMU
1266 .procname = "mmap_min_addr",
1267 .data = &dac_mmap_min_addr,
1268 .maxlen = sizeof(unsigned long),
1269 .mode = 0644,
1270 .proc_handler = mmap_min_addr_handler,
1272 #endif
1273 #ifdef CONFIG_NUMA
1275 .procname = "numa_zonelist_order",
1276 .data = &numa_zonelist_order,
1277 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1278 .mode = 0644,
1279 .proc_handler = numa_zonelist_order_handler,
1281 #endif
1282 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1283 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1285 .procname = "vdso_enabled",
1286 .data = &vdso_enabled,
1287 .maxlen = sizeof(vdso_enabled),
1288 .mode = 0644,
1289 .proc_handler = proc_dointvec,
1290 .extra1 = &zero,
1292 #endif
1293 #ifdef CONFIG_HIGHMEM
1295 .procname = "highmem_is_dirtyable",
1296 .data = &vm_highmem_is_dirtyable,
1297 .maxlen = sizeof(vm_highmem_is_dirtyable),
1298 .mode = 0644,
1299 .proc_handler = proc_dointvec_minmax,
1300 .extra1 = &zero,
1301 .extra2 = &one,
1303 #endif
1305 .procname = "scan_unevictable_pages",
1306 .data = &scan_unevictable_pages,
1307 .maxlen = sizeof(scan_unevictable_pages),
1308 .mode = 0644,
1309 .proc_handler = scan_unevictable_handler,
1311 #ifdef CONFIG_MEMORY_FAILURE
1313 .procname = "memory_failure_early_kill",
1314 .data = &sysctl_memory_failure_early_kill,
1315 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1316 .mode = 0644,
1317 .proc_handler = proc_dointvec_minmax,
1318 .extra1 = &zero,
1319 .extra2 = &one,
1322 .procname = "memory_failure_recovery",
1323 .data = &sysctl_memory_failure_recovery,
1324 .maxlen = sizeof(sysctl_memory_failure_recovery),
1325 .mode = 0644,
1326 .proc_handler = proc_dointvec_minmax,
1327 .extra1 = &zero,
1328 .extra2 = &one,
1330 #endif
1334 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1335 static struct ctl_table binfmt_misc_table[] = {
1338 #endif
1340 static struct ctl_table fs_table[] = {
1342 .procname = "inode-nr",
1343 .data = &inodes_stat,
1344 .maxlen = 2*sizeof(int),
1345 .mode = 0444,
1346 .proc_handler = proc_nr_inodes,
1349 .procname = "inode-state",
1350 .data = &inodes_stat,
1351 .maxlen = 7*sizeof(int),
1352 .mode = 0444,
1353 .proc_handler = proc_nr_inodes,
1356 .procname = "file-nr",
1357 .data = &files_stat,
1358 .maxlen = sizeof(files_stat),
1359 .mode = 0444,
1360 .proc_handler = proc_nr_files,
1363 .procname = "file-max",
1364 .data = &files_stat.max_files,
1365 .maxlen = sizeof(files_stat.max_files),
1366 .mode = 0644,
1367 .proc_handler = proc_doulongvec_minmax,
1370 .procname = "nr_open",
1371 .data = &sysctl_nr_open,
1372 .maxlen = sizeof(int),
1373 .mode = 0644,
1374 .proc_handler = proc_dointvec_minmax,
1375 .extra1 = &sysctl_nr_open_min,
1376 .extra2 = &sysctl_nr_open_max,
1379 .procname = "dentry-state",
1380 .data = &dentry_stat,
1381 .maxlen = 6*sizeof(int),
1382 .mode = 0444,
1383 .proc_handler = proc_nr_dentry,
1386 .procname = "overflowuid",
1387 .data = &fs_overflowuid,
1388 .maxlen = sizeof(int),
1389 .mode = 0644,
1390 .proc_handler = proc_dointvec_minmax,
1391 .extra1 = &minolduid,
1392 .extra2 = &maxolduid,
1395 .procname = "overflowgid",
1396 .data = &fs_overflowgid,
1397 .maxlen = sizeof(int),
1398 .mode = 0644,
1399 .proc_handler = proc_dointvec_minmax,
1400 .extra1 = &minolduid,
1401 .extra2 = &maxolduid,
1403 #ifdef CONFIG_FILE_LOCKING
1405 .procname = "leases-enable",
1406 .data = &leases_enable,
1407 .maxlen = sizeof(int),
1408 .mode = 0644,
1409 .proc_handler = proc_dointvec,
1411 #endif
1412 #ifdef CONFIG_DNOTIFY
1414 .procname = "dir-notify-enable",
1415 .data = &dir_notify_enable,
1416 .maxlen = sizeof(int),
1417 .mode = 0644,
1418 .proc_handler = proc_dointvec,
1420 #endif
1421 #ifdef CONFIG_MMU
1422 #ifdef CONFIG_FILE_LOCKING
1424 .procname = "lease-break-time",
1425 .data = &lease_break_time,
1426 .maxlen = sizeof(int),
1427 .mode = 0644,
1428 .proc_handler = proc_dointvec,
1430 #endif
1431 #ifdef CONFIG_AIO
1433 .procname = "aio-nr",
1434 .data = &aio_nr,
1435 .maxlen = sizeof(aio_nr),
1436 .mode = 0444,
1437 .proc_handler = proc_doulongvec_minmax,
1440 .procname = "aio-max-nr",
1441 .data = &aio_max_nr,
1442 .maxlen = sizeof(aio_max_nr),
1443 .mode = 0644,
1444 .proc_handler = proc_doulongvec_minmax,
1446 #endif /* CONFIG_AIO */
1447 #ifdef CONFIG_INOTIFY_USER
1449 .procname = "inotify",
1450 .mode = 0555,
1451 .child = inotify_table,
1453 #endif
1454 #ifdef CONFIG_EPOLL
1456 .procname = "epoll",
1457 .mode = 0555,
1458 .child = epoll_table,
1460 #endif
1461 #endif
1463 .procname = "suid_dumpable",
1464 .data = &suid_dumpable,
1465 .maxlen = sizeof(int),
1466 .mode = 0644,
1467 .proc_handler = proc_dointvec_minmax,
1468 .extra1 = &zero,
1469 .extra2 = &two,
1471 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1473 .procname = "binfmt_misc",
1474 .mode = 0555,
1475 .child = binfmt_misc_table,
1477 #endif
1479 .procname = "pipe-max-size",
1480 .data = &pipe_max_size,
1481 .maxlen = sizeof(int),
1482 .mode = 0644,
1483 .proc_handler = &pipe_proc_fn,
1484 .extra1 = &pipe_min_size,
1489 static struct ctl_table debug_table[] = {
1490 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1491 defined(CONFIG_S390)
1493 .procname = "exception-trace",
1494 .data = &show_unhandled_signals,
1495 .maxlen = sizeof(int),
1496 .mode = 0644,
1497 .proc_handler = proc_dointvec
1499 #endif
1500 #if defined(CONFIG_OPTPROBES)
1502 .procname = "kprobes-optimization",
1503 .data = &sysctl_kprobes_optimization,
1504 .maxlen = sizeof(int),
1505 .mode = 0644,
1506 .proc_handler = proc_kprobes_optimization_handler,
1507 .extra1 = &zero,
1508 .extra2 = &one,
1510 #endif
1514 static struct ctl_table dev_table[] = {
1518 static DEFINE_SPINLOCK(sysctl_lock);
1520 /* called under sysctl_lock */
1521 static int use_table(struct ctl_table_header *p)
1523 if (unlikely(p->unregistering))
1524 return 0;
1525 p->used++;
1526 return 1;
1529 /* called under sysctl_lock */
1530 static void unuse_table(struct ctl_table_header *p)
1532 if (!--p->used)
1533 if (unlikely(p->unregistering))
1534 complete(p->unregistering);
1537 /* called under sysctl_lock, will reacquire if has to wait */
1538 static void start_unregistering(struct ctl_table_header *p)
1541 * if p->used is 0, nobody will ever touch that entry again;
1542 * we'll eliminate all paths to it before dropping sysctl_lock
1544 if (unlikely(p->used)) {
1545 struct completion wait;
1546 init_completion(&wait);
1547 p->unregistering = &wait;
1548 spin_unlock(&sysctl_lock);
1549 wait_for_completion(&wait);
1550 spin_lock(&sysctl_lock);
1551 } else {
1552 /* anything non-NULL; we'll never dereference it */
1553 p->unregistering = ERR_PTR(-EINVAL);
1556 * do not remove from the list until nobody holds it; walking the
1557 * list in do_sysctl() relies on that.
1559 list_del_init(&p->ctl_entry);
1562 void sysctl_head_get(struct ctl_table_header *head)
1564 spin_lock(&sysctl_lock);
1565 head->count++;
1566 spin_unlock(&sysctl_lock);
1569 void sysctl_head_put(struct ctl_table_header *head)
1571 spin_lock(&sysctl_lock);
1572 if (!--head->count)
1573 kfree(head);
1574 spin_unlock(&sysctl_lock);
1577 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1579 if (!head)
1580 BUG();
1581 spin_lock(&sysctl_lock);
1582 if (!use_table(head))
1583 head = ERR_PTR(-ENOENT);
1584 spin_unlock(&sysctl_lock);
1585 return head;
1588 void sysctl_head_finish(struct ctl_table_header *head)
1590 if (!head)
1591 return;
1592 spin_lock(&sysctl_lock);
1593 unuse_table(head);
1594 spin_unlock(&sysctl_lock);
1597 static struct ctl_table_set *
1598 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1600 struct ctl_table_set *set = &root->default_set;
1601 if (root->lookup)
1602 set = root->lookup(root, namespaces);
1603 return set;
1606 static struct list_head *
1607 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1609 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1610 return &set->list;
1613 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1614 struct ctl_table_header *prev)
1616 struct ctl_table_root *root;
1617 struct list_head *header_list;
1618 struct ctl_table_header *head;
1619 struct list_head *tmp;
1621 spin_lock(&sysctl_lock);
1622 if (prev) {
1623 head = prev;
1624 tmp = &prev->ctl_entry;
1625 unuse_table(prev);
1626 goto next;
1628 tmp = &root_table_header.ctl_entry;
1629 for (;;) {
1630 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1632 if (!use_table(head))
1633 goto next;
1634 spin_unlock(&sysctl_lock);
1635 return head;
1636 next:
1637 root = head->root;
1638 tmp = tmp->next;
1639 header_list = lookup_header_list(root, namespaces);
1640 if (tmp != header_list)
1641 continue;
1643 do {
1644 root = list_entry(root->root_list.next,
1645 struct ctl_table_root, root_list);
1646 if (root == &sysctl_table_root)
1647 goto out;
1648 header_list = lookup_header_list(root, namespaces);
1649 } while (list_empty(header_list));
1650 tmp = header_list->next;
1652 out:
1653 spin_unlock(&sysctl_lock);
1654 return NULL;
1657 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1659 return __sysctl_head_next(current->nsproxy, prev);
1662 void register_sysctl_root(struct ctl_table_root *root)
1664 spin_lock(&sysctl_lock);
1665 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1666 spin_unlock(&sysctl_lock);
1670 * sysctl_perm does NOT grant the superuser all rights automatically, because
1671 * some sysctl variables are readonly even to root.
1674 static int test_perm(int mode, int op)
1676 if (!current_euid())
1677 mode >>= 6;
1678 else if (in_egroup_p(0))
1679 mode >>= 3;
1680 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1681 return 0;
1682 return -EACCES;
1685 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1687 int error;
1688 int mode;
1690 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1691 if (error)
1692 return error;
1694 if (root->permissions)
1695 mode = root->permissions(root, current->nsproxy, table);
1696 else
1697 mode = table->mode;
1699 return test_perm(mode, op);
1702 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1704 for (; table->procname; table++) {
1705 table->parent = parent;
1706 if (table->child)
1707 sysctl_set_parent(table, table->child);
1711 static __init int sysctl_init(void)
1713 sysctl_set_parent(NULL, root_table);
1714 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1715 sysctl_check_table(current->nsproxy, root_table);
1716 #endif
1717 return 0;
1720 core_initcall(sysctl_init);
1722 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1723 struct ctl_table *table)
1725 struct ctl_table *p;
1726 const char *s = branch->procname;
1728 /* branch should have named subdirectory as its first element */
1729 if (!s || !branch->child)
1730 return NULL;
1732 /* ... and nothing else */
1733 if (branch[1].procname)
1734 return NULL;
1736 /* table should contain subdirectory with the same name */
1737 for (p = table; p->procname; p++) {
1738 if (!p->child)
1739 continue;
1740 if (p->procname && strcmp(p->procname, s) == 0)
1741 return p;
1743 return NULL;
1746 /* see if attaching q to p would be an improvement */
1747 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1749 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1750 struct ctl_table *next;
1751 int is_better = 0;
1752 int not_in_parent = !p->attached_by;
1754 while ((next = is_branch_in(by, to)) != NULL) {
1755 if (by == q->attached_by)
1756 is_better = 1;
1757 if (to == p->attached_by)
1758 not_in_parent = 1;
1759 by = by->child;
1760 to = next->child;
1763 if (is_better && not_in_parent) {
1764 q->attached_by = by;
1765 q->attached_to = to;
1766 q->parent = p;
1771 * __register_sysctl_paths - register a sysctl hierarchy
1772 * @root: List of sysctl headers to register on
1773 * @namespaces: Data to compute which lists of sysctl entries are visible
1774 * @path: The path to the directory the sysctl table is in.
1775 * @table: the top-level table structure
1777 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1778 * array. A completely 0 filled entry terminates the table.
1780 * The members of the &struct ctl_table structure are used as follows:
1782 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1783 * enter a sysctl file
1785 * data - a pointer to data for use by proc_handler
1787 * maxlen - the maximum size in bytes of the data
1789 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1791 * child - a pointer to the child sysctl table if this entry is a directory, or
1792 * %NULL.
1794 * proc_handler - the text handler routine (described below)
1796 * de - for internal use by the sysctl routines
1798 * extra1, extra2 - extra pointers usable by the proc handler routines
1800 * Leaf nodes in the sysctl tree will be represented by a single file
1801 * under /proc; non-leaf nodes will be represented by directories.
1803 * sysctl(2) can automatically manage read and write requests through
1804 * the sysctl table. The data and maxlen fields of the ctl_table
1805 * struct enable minimal validation of the values being written to be
1806 * performed, and the mode field allows minimal authentication.
1808 * There must be a proc_handler routine for any terminal nodes
1809 * mirrored under /proc/sys (non-terminals are handled by a built-in
1810 * directory handler). Several default handlers are available to
1811 * cover common cases -
1813 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1814 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1815 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1817 * It is the handler's job to read the input buffer from user memory
1818 * and process it. The handler should return 0 on success.
1820 * This routine returns %NULL on a failure to register, and a pointer
1821 * to the table header on success.
1823 struct ctl_table_header *__register_sysctl_paths(
1824 struct ctl_table_root *root,
1825 struct nsproxy *namespaces,
1826 const struct ctl_path *path, struct ctl_table *table)
1828 struct ctl_table_header *header;
1829 struct ctl_table *new, **prevp;
1830 unsigned int n, npath;
1831 struct ctl_table_set *set;
1833 /* Count the path components */
1834 for (npath = 0; path[npath].procname; ++npath)
1838 * For each path component, allocate a 2-element ctl_table array.
1839 * The first array element will be filled with the sysctl entry
1840 * for this, the second will be the sentinel (procname == 0).
1842 * We allocate everything in one go so that we don't have to
1843 * worry about freeing additional memory in unregister_sysctl_table.
1845 header = kzalloc(sizeof(struct ctl_table_header) +
1846 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1847 if (!header)
1848 return NULL;
1850 new = (struct ctl_table *) (header + 1);
1852 /* Now connect the dots */
1853 prevp = &header->ctl_table;
1854 for (n = 0; n < npath; ++n, ++path) {
1855 /* Copy the procname */
1856 new->procname = path->procname;
1857 new->mode = 0555;
1859 *prevp = new;
1860 prevp = &new->child;
1862 new += 2;
1864 *prevp = table;
1865 header->ctl_table_arg = table;
1867 INIT_LIST_HEAD(&header->ctl_entry);
1868 header->used = 0;
1869 header->unregistering = NULL;
1870 header->root = root;
1871 sysctl_set_parent(NULL, header->ctl_table);
1872 header->count = 1;
1873 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1874 if (sysctl_check_table(namespaces, header->ctl_table)) {
1875 kfree(header);
1876 return NULL;
1878 #endif
1879 spin_lock(&sysctl_lock);
1880 header->set = lookup_header_set(root, namespaces);
1881 header->attached_by = header->ctl_table;
1882 header->attached_to = root_table;
1883 header->parent = &root_table_header;
1884 for (set = header->set; set; set = set->parent) {
1885 struct ctl_table_header *p;
1886 list_for_each_entry(p, &set->list, ctl_entry) {
1887 if (p->unregistering)
1888 continue;
1889 try_attach(p, header);
1892 header->parent->count++;
1893 list_add_tail(&header->ctl_entry, &header->set->list);
1894 spin_unlock(&sysctl_lock);
1896 return header;
1900 * register_sysctl_table_path - register a sysctl table hierarchy
1901 * @path: The path to the directory the sysctl table is in.
1902 * @table: the top-level table structure
1904 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1905 * array. A completely 0 filled entry terminates the table.
1907 * See __register_sysctl_paths for more details.
1909 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1910 struct ctl_table *table)
1912 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1913 path, table);
1917 * register_sysctl_table - register a sysctl table hierarchy
1918 * @table: the top-level table structure
1920 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1921 * array. A completely 0 filled entry terminates the table.
1923 * See register_sysctl_paths for more details.
1925 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1927 static const struct ctl_path null_path[] = { {} };
1929 return register_sysctl_paths(null_path, table);
1933 * unregister_sysctl_table - unregister a sysctl table hierarchy
1934 * @header: the header returned from register_sysctl_table
1936 * Unregisters the sysctl table and all children. proc entries may not
1937 * actually be removed until they are no longer used by anyone.
1939 void unregister_sysctl_table(struct ctl_table_header * header)
1941 might_sleep();
1943 if (header == NULL)
1944 return;
1946 spin_lock(&sysctl_lock);
1947 start_unregistering(header);
1948 if (!--header->parent->count) {
1949 WARN_ON(1);
1950 kfree(header->parent);
1952 if (!--header->count)
1953 kfree(header);
1954 spin_unlock(&sysctl_lock);
1957 int sysctl_is_seen(struct ctl_table_header *p)
1959 struct ctl_table_set *set = p->set;
1960 int res;
1961 spin_lock(&sysctl_lock);
1962 if (p->unregistering)
1963 res = 0;
1964 else if (!set->is_seen)
1965 res = 1;
1966 else
1967 res = set->is_seen(set);
1968 spin_unlock(&sysctl_lock);
1969 return res;
1972 void setup_sysctl_set(struct ctl_table_set *p,
1973 struct ctl_table_set *parent,
1974 int (*is_seen)(struct ctl_table_set *))
1976 INIT_LIST_HEAD(&p->list);
1977 p->parent = parent ? parent : &sysctl_table_root.default_set;
1978 p->is_seen = is_seen;
1981 #else /* !CONFIG_SYSCTL */
1982 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1984 return NULL;
1987 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1988 struct ctl_table *table)
1990 return NULL;
1993 void unregister_sysctl_table(struct ctl_table_header * table)
1997 void setup_sysctl_set(struct ctl_table_set *p,
1998 struct ctl_table_set *parent,
1999 int (*is_seen)(struct ctl_table_set *))
2003 void sysctl_head_put(struct ctl_table_header *head)
2007 #endif /* CONFIG_SYSCTL */
2010 * /proc/sys support
2013 #ifdef CONFIG_PROC_SYSCTL
2015 static int _proc_do_string(void* data, int maxlen, int write,
2016 void __user *buffer,
2017 size_t *lenp, loff_t *ppos)
2019 size_t len;
2020 char __user *p;
2021 char c;
2023 if (!data || !maxlen || !*lenp) {
2024 *lenp = 0;
2025 return 0;
2028 if (write) {
2029 len = 0;
2030 p = buffer;
2031 while (len < *lenp) {
2032 if (get_user(c, p++))
2033 return -EFAULT;
2034 if (c == 0 || c == '\n')
2035 break;
2036 len++;
2038 if (len >= maxlen)
2039 len = maxlen-1;
2040 if(copy_from_user(data, buffer, len))
2041 return -EFAULT;
2042 ((char *) data)[len] = 0;
2043 *ppos += *lenp;
2044 } else {
2045 len = strlen(data);
2046 if (len > maxlen)
2047 len = maxlen;
2049 if (*ppos > len) {
2050 *lenp = 0;
2051 return 0;
2054 data += *ppos;
2055 len -= *ppos;
2057 if (len > *lenp)
2058 len = *lenp;
2059 if (len)
2060 if(copy_to_user(buffer, data, len))
2061 return -EFAULT;
2062 if (len < *lenp) {
2063 if(put_user('\n', ((char __user *) buffer) + len))
2064 return -EFAULT;
2065 len++;
2067 *lenp = len;
2068 *ppos += len;
2070 return 0;
2074 * proc_dostring - read a string sysctl
2075 * @table: the sysctl table
2076 * @write: %TRUE if this is a write to the sysctl file
2077 * @buffer: the user buffer
2078 * @lenp: the size of the user buffer
2079 * @ppos: file position
2081 * Reads/writes a string from/to the user buffer. If the kernel
2082 * buffer provided is not large enough to hold the string, the
2083 * string is truncated. The copied string is %NULL-terminated.
2084 * If the string is being read by the user process, it is copied
2085 * and a newline '\n' is added. It is truncated if the buffer is
2086 * not large enough.
2088 * Returns 0 on success.
2090 int proc_dostring(struct ctl_table *table, int write,
2091 void __user *buffer, size_t *lenp, loff_t *ppos)
2093 return _proc_do_string(table->data, table->maxlen, write,
2094 buffer, lenp, ppos);
2097 static size_t proc_skip_spaces(char **buf)
2099 size_t ret;
2100 char *tmp = skip_spaces(*buf);
2101 ret = tmp - *buf;
2102 *buf = tmp;
2103 return ret;
2106 static void proc_skip_char(char **buf, size_t *size, const char v)
2108 while (*size) {
2109 if (**buf != v)
2110 break;
2111 (*size)--;
2112 (*buf)++;
2116 #define TMPBUFLEN 22
2118 * proc_get_long - reads an ASCII formatted integer from a user buffer
2120 * @buf: a kernel buffer
2121 * @size: size of the kernel buffer
2122 * @val: this is where the number will be stored
2123 * @neg: set to %TRUE if number is negative
2124 * @perm_tr: a vector which contains the allowed trailers
2125 * @perm_tr_len: size of the perm_tr vector
2126 * @tr: pointer to store the trailer character
2128 * In case of success %0 is returned and @buf and @size are updated with
2129 * the amount of bytes read. If @tr is non-NULL and a trailing
2130 * character exists (size is non-zero after returning from this
2131 * function), @tr is updated with the trailing character.
2133 static int proc_get_long(char **buf, size_t *size,
2134 unsigned long *val, bool *neg,
2135 const char *perm_tr, unsigned perm_tr_len, char *tr)
2137 int len;
2138 char *p, tmp[TMPBUFLEN];
2140 if (!*size)
2141 return -EINVAL;
2143 len = *size;
2144 if (len > TMPBUFLEN - 1)
2145 len = TMPBUFLEN - 1;
2147 memcpy(tmp, *buf, len);
2149 tmp[len] = 0;
2150 p = tmp;
2151 if (*p == '-' && *size > 1) {
2152 *neg = true;
2153 p++;
2154 } else
2155 *neg = false;
2156 if (!isdigit(*p))
2157 return -EINVAL;
2159 *val = simple_strtoul(p, &p, 0);
2161 len = p - tmp;
2163 /* We don't know if the next char is whitespace thus we may accept
2164 * invalid integers (e.g. 1234...a) or two integers instead of one
2165 * (e.g. 123...1). So lets not allow such large numbers. */
2166 if (len == TMPBUFLEN - 1)
2167 return -EINVAL;
2169 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2170 return -EINVAL;
2172 if (tr && (len < *size))
2173 *tr = *p;
2175 *buf += len;
2176 *size -= len;
2178 return 0;
2182 * proc_put_long - converts an integer to a decimal ASCII formatted string
2184 * @buf: the user buffer
2185 * @size: the size of the user buffer
2186 * @val: the integer to be converted
2187 * @neg: sign of the number, %TRUE for negative
2189 * In case of success %0 is returned and @buf and @size are updated with
2190 * the amount of bytes written.
2192 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2193 bool neg)
2195 int len;
2196 char tmp[TMPBUFLEN], *p = tmp;
2198 sprintf(p, "%s%lu", neg ? "-" : "", val);
2199 len = strlen(tmp);
2200 if (len > *size)
2201 len = *size;
2202 if (copy_to_user(*buf, tmp, len))
2203 return -EFAULT;
2204 *size -= len;
2205 *buf += len;
2206 return 0;
2208 #undef TMPBUFLEN
2210 static int proc_put_char(void __user **buf, size_t *size, char c)
2212 if (*size) {
2213 char __user **buffer = (char __user **)buf;
2214 if (put_user(c, *buffer))
2215 return -EFAULT;
2216 (*size)--, (*buffer)++;
2217 *buf = *buffer;
2219 return 0;
2222 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2223 int *valp,
2224 int write, void *data)
2226 if (write) {
2227 *valp = *negp ? -*lvalp : *lvalp;
2228 } else {
2229 int val = *valp;
2230 if (val < 0) {
2231 *negp = true;
2232 *lvalp = (unsigned long)-val;
2233 } else {
2234 *negp = false;
2235 *lvalp = (unsigned long)val;
2238 return 0;
2241 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2243 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2244 int write, void __user *buffer,
2245 size_t *lenp, loff_t *ppos,
2246 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2247 int write, void *data),
2248 void *data)
2250 int *i, vleft, first = 1, err = 0;
2251 unsigned long page = 0;
2252 size_t left;
2253 char *kbuf;
2255 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2256 *lenp = 0;
2257 return 0;
2260 i = (int *) tbl_data;
2261 vleft = table->maxlen / sizeof(*i);
2262 left = *lenp;
2264 if (!conv)
2265 conv = do_proc_dointvec_conv;
2267 if (write) {
2268 if (left > PAGE_SIZE - 1)
2269 left = PAGE_SIZE - 1;
2270 page = __get_free_page(GFP_TEMPORARY);
2271 kbuf = (char *) page;
2272 if (!kbuf)
2273 return -ENOMEM;
2274 if (copy_from_user(kbuf, buffer, left)) {
2275 err = -EFAULT;
2276 goto free;
2278 kbuf[left] = 0;
2281 for (; left && vleft--; i++, first=0) {
2282 unsigned long lval;
2283 bool neg;
2285 if (write) {
2286 left -= proc_skip_spaces(&kbuf);
2288 if (!left)
2289 break;
2290 err = proc_get_long(&kbuf, &left, &lval, &neg,
2291 proc_wspace_sep,
2292 sizeof(proc_wspace_sep), NULL);
2293 if (err)
2294 break;
2295 if (conv(&neg, &lval, i, 1, data)) {
2296 err = -EINVAL;
2297 break;
2299 } else {
2300 if (conv(&neg, &lval, i, 0, data)) {
2301 err = -EINVAL;
2302 break;
2304 if (!first)
2305 err = proc_put_char(&buffer, &left, '\t');
2306 if (err)
2307 break;
2308 err = proc_put_long(&buffer, &left, lval, neg);
2309 if (err)
2310 break;
2314 if (!write && !first && left && !err)
2315 err = proc_put_char(&buffer, &left, '\n');
2316 if (write && !err && left)
2317 left -= proc_skip_spaces(&kbuf);
2318 free:
2319 if (write) {
2320 free_page(page);
2321 if (first)
2322 return err ? : -EINVAL;
2324 *lenp -= left;
2325 *ppos += *lenp;
2326 return err;
2329 static int do_proc_dointvec(struct ctl_table *table, int write,
2330 void __user *buffer, size_t *lenp, loff_t *ppos,
2331 int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2332 int write, void *data),
2333 void *data)
2335 return __do_proc_dointvec(table->data, table, write,
2336 buffer, lenp, ppos, conv, data);
2340 * proc_dointvec - read a vector of integers
2341 * @table: the sysctl table
2342 * @write: %TRUE if this is a write to the sysctl file
2343 * @buffer: the user buffer
2344 * @lenp: the size of the user buffer
2345 * @ppos: file position
2347 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2348 * values from/to the user buffer, treated as an ASCII string.
2350 * Returns 0 on success.
2352 int proc_dointvec(struct ctl_table *table, int write,
2353 void __user *buffer, size_t *lenp, loff_t *ppos)
2355 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2356 NULL,NULL);
2360 * Taint values can only be increased
2361 * This means we can safely use a temporary.
2363 static int proc_taint(struct ctl_table *table, int write,
2364 void __user *buffer, size_t *lenp, loff_t *ppos)
2366 struct ctl_table t;
2367 unsigned long tmptaint = get_taint();
2368 int err;
2370 if (write && !capable(CAP_SYS_ADMIN))
2371 return -EPERM;
2373 t = *table;
2374 t.data = &tmptaint;
2375 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2376 if (err < 0)
2377 return err;
2379 if (write) {
2381 * Poor man's atomic or. Not worth adding a primitive
2382 * to everyone's atomic.h for this
2384 int i;
2385 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2386 if ((tmptaint >> i) & 1)
2387 add_taint(i);
2391 return err;
2394 struct do_proc_dointvec_minmax_conv_param {
2395 int *min;
2396 int *max;
2399 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2400 int *valp,
2401 int write, void *data)
2403 struct do_proc_dointvec_minmax_conv_param *param = data;
2404 if (write) {
2405 int val = *negp ? -*lvalp : *lvalp;
2406 if ((param->min && *param->min > val) ||
2407 (param->max && *param->max < val))
2408 return -EINVAL;
2409 *valp = val;
2410 } else {
2411 int val = *valp;
2412 if (val < 0) {
2413 *negp = true;
2414 *lvalp = (unsigned long)-val;
2415 } else {
2416 *negp = false;
2417 *lvalp = (unsigned long)val;
2420 return 0;
2424 * proc_dointvec_minmax - read a vector of integers with min/max values
2425 * @table: the sysctl table
2426 * @write: %TRUE if this is a write to the sysctl file
2427 * @buffer: the user buffer
2428 * @lenp: the size of the user buffer
2429 * @ppos: file position
2431 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2432 * values from/to the user buffer, treated as an ASCII string.
2434 * This routine will ensure the values are within the range specified by
2435 * table->extra1 (min) and table->extra2 (max).
2437 * Returns 0 on success.
2439 int proc_dointvec_minmax(struct ctl_table *table, int write,
2440 void __user *buffer, size_t *lenp, loff_t *ppos)
2442 struct do_proc_dointvec_minmax_conv_param param = {
2443 .min = (int *) table->extra1,
2444 .max = (int *) table->extra2,
2446 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2447 do_proc_dointvec_minmax_conv, &param);
2450 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2451 void __user *buffer,
2452 size_t *lenp, loff_t *ppos,
2453 unsigned long convmul,
2454 unsigned long convdiv)
2456 unsigned long *i, *min, *max;
2457 int vleft, first = 1, err = 0;
2458 unsigned long page = 0;
2459 size_t left;
2460 char *kbuf;
2462 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2463 *lenp = 0;
2464 return 0;
2467 i = (unsigned long *) data;
2468 min = (unsigned long *) table->extra1;
2469 max = (unsigned long *) table->extra2;
2470 vleft = table->maxlen / sizeof(unsigned long);
2471 left = *lenp;
2473 if (write) {
2474 if (left > PAGE_SIZE - 1)
2475 left = PAGE_SIZE - 1;
2476 page = __get_free_page(GFP_TEMPORARY);
2477 kbuf = (char *) page;
2478 if (!kbuf)
2479 return -ENOMEM;
2480 if (copy_from_user(kbuf, buffer, left)) {
2481 err = -EFAULT;
2482 goto free;
2484 kbuf[left] = 0;
2487 for (; left && vleft--; i++, first = 0) {
2488 unsigned long val;
2490 if (write) {
2491 bool neg;
2493 left -= proc_skip_spaces(&kbuf);
2495 err = proc_get_long(&kbuf, &left, &val, &neg,
2496 proc_wspace_sep,
2497 sizeof(proc_wspace_sep), NULL);
2498 if (err)
2499 break;
2500 if (neg)
2501 continue;
2502 if ((min && val < *min) || (max && val > *max))
2503 continue;
2504 *i = val;
2505 } else {
2506 val = convdiv * (*i) / convmul;
2507 if (!first)
2508 err = proc_put_char(&buffer, &left, '\t');
2509 err = proc_put_long(&buffer, &left, val, false);
2510 if (err)
2511 break;
2515 if (!write && !first && left && !err)
2516 err = proc_put_char(&buffer, &left, '\n');
2517 if (write && !err)
2518 left -= proc_skip_spaces(&kbuf);
2519 free:
2520 if (write) {
2521 free_page(page);
2522 if (first)
2523 return err ? : -EINVAL;
2525 *lenp -= left;
2526 *ppos += *lenp;
2527 return err;
2530 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2531 void __user *buffer,
2532 size_t *lenp, loff_t *ppos,
2533 unsigned long convmul,
2534 unsigned long convdiv)
2536 return __do_proc_doulongvec_minmax(table->data, table, write,
2537 buffer, lenp, ppos, convmul, convdiv);
2541 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2542 * @table: the sysctl table
2543 * @write: %TRUE if this is a write to the sysctl file
2544 * @buffer: the user buffer
2545 * @lenp: the size of the user buffer
2546 * @ppos: file position
2548 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2549 * values from/to the user buffer, treated as an ASCII string.
2551 * This routine will ensure the values are within the range specified by
2552 * table->extra1 (min) and table->extra2 (max).
2554 * Returns 0 on success.
2556 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2557 void __user *buffer, size_t *lenp, loff_t *ppos)
2559 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2563 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values 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. The values
2572 * are treated as milliseconds, and converted to jiffies when they are stored.
2574 * This routine will ensure the values are within the range specified by
2575 * table->extra1 (min) and table->extra2 (max).
2577 * Returns 0 on success.
2579 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2580 void __user *buffer,
2581 size_t *lenp, loff_t *ppos)
2583 return do_proc_doulongvec_minmax(table, write, buffer,
2584 lenp, ppos, HZ, 1000l);
2588 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2589 int *valp,
2590 int write, void *data)
2592 if (write) {
2593 if (*lvalp > LONG_MAX / HZ)
2594 return 1;
2595 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2596 } else {
2597 int val = *valp;
2598 unsigned long lval;
2599 if (val < 0) {
2600 *negp = true;
2601 lval = (unsigned long)-val;
2602 } else {
2603 *negp = false;
2604 lval = (unsigned long)val;
2606 *lvalp = lval / HZ;
2608 return 0;
2611 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2612 int *valp,
2613 int write, void *data)
2615 if (write) {
2616 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2617 return 1;
2618 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2619 } else {
2620 int val = *valp;
2621 unsigned long lval;
2622 if (val < 0) {
2623 *negp = true;
2624 lval = (unsigned long)-val;
2625 } else {
2626 *negp = false;
2627 lval = (unsigned long)val;
2629 *lvalp = jiffies_to_clock_t(lval);
2631 return 0;
2634 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2635 int *valp,
2636 int write, void *data)
2638 if (write) {
2639 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2640 } else {
2641 int val = *valp;
2642 unsigned long lval;
2643 if (val < 0) {
2644 *negp = true;
2645 lval = (unsigned long)-val;
2646 } else {
2647 *negp = false;
2648 lval = (unsigned long)val;
2650 *lvalp = jiffies_to_msecs(lval);
2652 return 0;
2656 * proc_dointvec_jiffies - read a vector of integers as seconds
2657 * @table: the sysctl table
2658 * @write: %TRUE if this is a write to the sysctl file
2659 * @buffer: the user buffer
2660 * @lenp: the size of the user buffer
2661 * @ppos: file position
2663 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2664 * values from/to the user buffer, treated as an ASCII string.
2665 * The values read are assumed to be in seconds, and are converted into
2666 * jiffies.
2668 * Returns 0 on success.
2670 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2671 void __user *buffer, size_t *lenp, loff_t *ppos)
2673 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2674 do_proc_dointvec_jiffies_conv,NULL);
2678 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ 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: pointer to the 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 1/USER_HZ seconds, and
2688 * are converted into jiffies.
2690 * Returns 0 on success.
2692 int proc_dointvec_userhz_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_userhz_jiffies_conv,NULL);
2700 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
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: file position
2706 * @ppos: the current position in the file
2708 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2709 * values from/to the user buffer, treated as an ASCII string.
2710 * The values read are assumed to be in 1/1000 seconds, and
2711 * are converted into jiffies.
2713 * Returns 0 on success.
2715 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2716 void __user *buffer, size_t *lenp, loff_t *ppos)
2718 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2719 do_proc_dointvec_ms_jiffies_conv, NULL);
2722 static int proc_do_cad_pid(struct ctl_table *table, int write,
2723 void __user *buffer, size_t *lenp, loff_t *ppos)
2725 struct pid *new_pid;
2726 pid_t tmp;
2727 int r;
2729 tmp = pid_vnr(cad_pid);
2731 r = __do_proc_dointvec(&tmp, table, write, buffer,
2732 lenp, ppos, NULL, NULL);
2733 if (r || !write)
2734 return r;
2736 new_pid = find_get_pid(tmp);
2737 if (!new_pid)
2738 return -ESRCH;
2740 put_pid(xchg(&cad_pid, new_pid));
2741 return 0;
2745 * proc_do_large_bitmap - read/write from/to a large bitmap
2746 * @table: the sysctl table
2747 * @write: %TRUE if this is a write to the sysctl file
2748 * @buffer: the user buffer
2749 * @lenp: the size of the user buffer
2750 * @ppos: file position
2752 * The bitmap is stored at table->data and the bitmap length (in bits)
2753 * in table->maxlen.
2755 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2756 * large bitmaps may be represented in a compact manner. Writing into
2757 * the file will clear the bitmap then update it with the given input.
2759 * Returns 0 on success.
2761 int proc_do_large_bitmap(struct ctl_table *table, int write,
2762 void __user *buffer, size_t *lenp, loff_t *ppos)
2764 int err = 0;
2765 bool first = 1;
2766 size_t left = *lenp;
2767 unsigned long bitmap_len = table->maxlen;
2768 unsigned long *bitmap = (unsigned long *) table->data;
2769 unsigned long *tmp_bitmap = NULL;
2770 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2772 if (!bitmap_len || !left || (*ppos && !write)) {
2773 *lenp = 0;
2774 return 0;
2777 if (write) {
2778 unsigned long page = 0;
2779 char *kbuf;
2781 if (left > PAGE_SIZE - 1)
2782 left = PAGE_SIZE - 1;
2784 page = __get_free_page(GFP_TEMPORARY);
2785 kbuf = (char *) page;
2786 if (!kbuf)
2787 return -ENOMEM;
2788 if (copy_from_user(kbuf, buffer, left)) {
2789 free_page(page);
2790 return -EFAULT;
2792 kbuf[left] = 0;
2794 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2795 GFP_KERNEL);
2796 if (!tmp_bitmap) {
2797 free_page(page);
2798 return -ENOMEM;
2800 proc_skip_char(&kbuf, &left, '\n');
2801 while (!err && left) {
2802 unsigned long val_a, val_b;
2803 bool neg;
2805 err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2806 sizeof(tr_a), &c);
2807 if (err)
2808 break;
2809 if (val_a >= bitmap_len || neg) {
2810 err = -EINVAL;
2811 break;
2814 val_b = val_a;
2815 if (left) {
2816 kbuf++;
2817 left--;
2820 if (c == '-') {
2821 err = proc_get_long(&kbuf, &left, &val_b,
2822 &neg, tr_b, sizeof(tr_b),
2823 &c);
2824 if (err)
2825 break;
2826 if (val_b >= bitmap_len || neg ||
2827 val_a > val_b) {
2828 err = -EINVAL;
2829 break;
2831 if (left) {
2832 kbuf++;
2833 left--;
2837 while (val_a <= val_b)
2838 set_bit(val_a++, tmp_bitmap);
2840 first = 0;
2841 proc_skip_char(&kbuf, &left, '\n');
2843 free_page(page);
2844 } else {
2845 unsigned long bit_a, bit_b = 0;
2847 while (left) {
2848 bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2849 if (bit_a >= bitmap_len)
2850 break;
2851 bit_b = find_next_zero_bit(bitmap, bitmap_len,
2852 bit_a + 1) - 1;
2854 if (!first) {
2855 err = proc_put_char(&buffer, &left, ',');
2856 if (err)
2857 break;
2859 err = proc_put_long(&buffer, &left, bit_a, false);
2860 if (err)
2861 break;
2862 if (bit_a != bit_b) {
2863 err = proc_put_char(&buffer, &left, '-');
2864 if (err)
2865 break;
2866 err = proc_put_long(&buffer, &left, bit_b, false);
2867 if (err)
2868 break;
2871 first = 0; bit_b++;
2873 if (!err)
2874 err = proc_put_char(&buffer, &left, '\n');
2877 if (!err) {
2878 if (write) {
2879 if (*ppos)
2880 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2881 else
2882 memcpy(bitmap, tmp_bitmap,
2883 BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2885 kfree(tmp_bitmap);
2886 *lenp -= left;
2887 *ppos += *lenp;
2888 return 0;
2889 } else {
2890 kfree(tmp_bitmap);
2891 return err;
2895 #else /* CONFIG_PROC_SYSCTL */
2897 int proc_dostring(struct ctl_table *table, int write,
2898 void __user *buffer, size_t *lenp, loff_t *ppos)
2900 return -ENOSYS;
2903 int proc_dointvec(struct ctl_table *table, int write,
2904 void __user *buffer, size_t *lenp, loff_t *ppos)
2906 return -ENOSYS;
2909 int proc_dointvec_minmax(struct ctl_table *table, int write,
2910 void __user *buffer, size_t *lenp, loff_t *ppos)
2912 return -ENOSYS;
2915 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2916 void __user *buffer, size_t *lenp, loff_t *ppos)
2918 return -ENOSYS;
2921 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2922 void __user *buffer, size_t *lenp, loff_t *ppos)
2924 return -ENOSYS;
2927 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2928 void __user *buffer, size_t *lenp, loff_t *ppos)
2930 return -ENOSYS;
2933 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2934 void __user *buffer, size_t *lenp, loff_t *ppos)
2936 return -ENOSYS;
2939 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2940 void __user *buffer,
2941 size_t *lenp, loff_t *ppos)
2943 return -ENOSYS;
2947 #endif /* CONFIG_PROC_SYSCTL */
2950 * No sense putting this after each symbol definition, twice,
2951 * exception granted :-)
2953 EXPORT_SYMBOL(proc_dointvec);
2954 EXPORT_SYMBOL(proc_dointvec_jiffies);
2955 EXPORT_SYMBOL(proc_dointvec_minmax);
2956 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2957 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2958 EXPORT_SYMBOL(proc_dostring);
2959 EXPORT_SYMBOL(proc_doulongvec_minmax);
2960 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2961 EXPORT_SYMBOL(register_sysctl_table);
2962 EXPORT_SYMBOL(register_sysctl_paths);
2963 EXPORT_SYMBOL(unregister_sysctl_table);